DBA Data[Home] [Help]

PACKAGE BODY: APPS.XLA_08901_AAD_S_000002_BC_PKG

Source


1 PACKAGE BODY XLA_08901_AAD_S_000002_BC_PKG AS
2 --
3 /*======================================================================+
4 |                Copyright (c) 1997 Oracle Corporation                  |
5 |                       Redwood Shores, CA, USA                         |
6 |                         All rights reserved.                          |
7 +=======================================================================+
8 | Package Name                                                          |
9 |     XLA_08901_AAD_S_000002_BC_PKG                                     |
10 |                                                                       |
11 | DESCRIPTION                                                           |
12 |     Package generated From Product Accounting Definition              |
13 |      Name    : Federal Financials AAD                                 |
14 |      Code    : FV_STANDARD_AAD                                        |
15 |      Owner   : PRODUCT                                                |
16 |      Version :                                                        |
17 |      AMB Context Code: DEFAULT                                        |
18 | HISTORY                                                               |
19 |     Generated at 04-01-2007 at 02:01:59 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_08901_AAD_S_000002_BC_PKG';
82 
83 C_CHAR                CONSTANT       VARCHAR2(30) := fnd_global.local_chr(12); -- 4219869 Business flow
84 C_NUM                 CONSTANT       NUMBER       := 9.99E125;                 -- 4219869 Business flow
85 
86 g_log_level           NUMBER;
87 g_log_enabled         BOOLEAN;
88 
89 PROCEDURE trace
90            (p_msg                        IN VARCHAR2
91            ,p_level                      IN NUMBER
92            ,p_module                     IN VARCHAR2 ) IS
93 BEGIN
94 ----------------------------------------------------------------------------
95 -- Following is for FND log.
96 ----------------------------------------------------------------------------
97 IF (p_msg IS NULL AND p_level >= g_log_level) THEN
98           fnd_log.message(p_level, p_module);
99 ELSIF p_level >= g_log_level THEN
100           fnd_log.string(p_level, p_module, p_msg);
101 END IF;
102 
103 EXCEPTION
104        WHEN xla_exceptions_pkg.application_exception THEN
105           RAISE;
106        WHEN OTHERS THEN
107           xla_exceptions_pkg.raise_message
108              (p_location   => 'XLA_08901_AAD_S_000002_BC_PKG.trace');
109 END trace;
110 
111 --
112 --+============================================+
113 --|                                            |
114 --|  PRIVATE  PROCEDURES/FUNCTIONS             |
115 --|                                            |
116 --+============================================+
117 --
118 
119 --
120 /*======================================================================+
121 |                                                                       |
122 | Private Function                                                      |
123 |    ValidateLookupMeaning                                              |
124 |                                                                       |
125 +======================================================================*/
126 FUNCTION ValidateLookupMeaning(
127   p_meaning                IN VARCHAR2
128 , p_lookup_code            IN VARCHAR2
129 , p_lookup_type            IN VARCHAR2
130 , p_source_code            IN VARCHAR2
131 , p_source_type_code       IN VARCHAR2
132 , p_source_application_id  IN INTEGER
133 )
134 RETURN VARCHAR2
135 IS
136 l_log_module         VARCHAR2(240);
137 BEGIN
138 IF g_log_enabled THEN
139       l_log_module := C_DEFAULT_MODULE||'.ValidateLookupMeaning';
140 END IF;
141 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
142       trace
143          (p_msg      => 'BEGIN of ValidateLookupMeaning'
144          ,p_level    => C_LEVEL_PROCEDURE
145          ,p_module   => l_log_module);
146 END IF;
147 --
148 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
149     trace
150          (p_msg      => 'p_source_code = '|| p_source_code||
151                         ' - p_source_type_code = '|| p_source_type_code||
152                         ' - p_source_application_id = '|| p_source_application_id||
153                         ' - p_lookup_code = '|| p_lookup_code||
154                         ' - p_lookup_type = '|| p_lookup_type||
155                         ' - p_meaning = '|| p_meaning
156          ,p_level    => C_LEVEL_PROCEDURE
157          ,p_module   => l_log_module);
158 
159 END IF;
160 
161 IF p_lookup_code IS NOT NULL AND p_meaning IS NULL THEN
162    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
163    xla_accounting_err_pkg. build_message
164                (p_appli_s_name            => 'XLA'
165                ,p_msg_name                => 'XLA_AP_NO_LOOKUP_MEANING'
166                ,p_token_1                 => 'SOURCE_NAME'
167                ,p_value_1                 =>  xla_ae_sources_pkg.GetSourceName(
168                                                            p_source_code
169                                                          , p_source_type_code
170                                                          , p_source_application_id
171                                                          )
172                ,p_token_2                 => 'LOOKUP_CODE'
173                ,p_value_2                 =>  p_lookup_code
174                ,p_token_3                 => 'LOOKUP_TYPE'
175                ,p_value_3                 =>  p_lookup_type
176                ,p_token_4                 => 'PRODUCT_NAME'
177                ,p_value_4                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
178                ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
179                ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
180                ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
181        );
182 
183    IF (C_LEVEL_ERROR >= g_log_level) THEN
184            trace
185                 (p_msg      => 'ERROR: XLA_AP_NO_LOOKUP_MEANING'
186                 ,p_level    => C_LEVEL_ERROR
187                 ,p_module   => l_log_module);
188    END IF;
189 END IF;
190 
191 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
192         trace
193           (p_msg      => 'END of ValidateLookupMeaning'
194           ,p_level    => C_LEVEL_PROCEDURE
195           ,p_module   => l_log_module);
196 END IF;
197 RETURN p_meaning;
198 EXCEPTION
199 WHEN xla_exceptions_pkg.application_exception THEN
200   RETURN p_meaning;
201 WHEN OTHERS  THEN
202    xla_exceptions_pkg.raise_message
203            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.ValidateLookupMeaning');
204        --
205 END ValidateLookupMeaning;
206 --
207 --
208 
209 FUNCTION GetMeaning (
210   p_flex_value_set_id               IN INTEGER
211 , p_flex_value                      IN VARCHAR2
212 , p_source_code                     IN VARCHAR2
213 , p_source_type_code                IN VARCHAR2
214 , p_source_application_id           IN INTEGER
215 )
216 RETURN VARCHAR2
217 IS
218 BEGIN
219 --
220 RETURN NULL ;
221 --
222 EXCEPTION
223   WHEN xla_exceptions_pkg.application_exception THEN
224       RAISE;
225   WHEN OTHERS THEN
226        xla_exceptions_pkg.raise_message
227            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.GetMeaning');
228 END GetMeaning;
229 --
230 
231 ---------------------------------------
232 --
233 -- PRIVATE FUNCTION
234 --         Description_1
235 --
236 ---------------------------------------
237 FUNCTION Description_1 (
238   p_application_id      IN NUMBER
239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
240 --DOC_NUMBER
241  , p_source_1            IN VARCHAR2
242 --BUDGET_LEVEL_ID
243  , p_source_2            IN NUMBER
244 )
245 RETURN VARCHAR2
246 IS
247 l_component_type        VARCHAR2(80)   ;
248 l_component_code        VARCHAR2(30)   ;
249 l_component_type_code   VARCHAR2(1)    ;
250 l_component_appl_id     INTEGER        ;
251 l_amb_context_code      VARCHAR2(30)   ;
252 l_ledger_language       VARCHAR2(30)   ;
253 l_source                VARCHAR2(1996) ;
254 l_description           VARCHAR2(2000) ;
255 l_log_module            VARCHAR2(240)  ;
256 BEGIN
257 IF g_log_enabled THEN
258       l_log_module := C_DEFAULT_MODULE||'.Description_1';
259 END IF;
260 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
261       trace
262          (p_msg      => 'BEGIN of Description_1'
263          ,p_level    => C_LEVEL_PROCEDURE
264          ,p_module   => l_log_module);
265 END IF;
266 
267 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
268 l_component_type        := 'AMB_DESCRIPTION';
269 l_component_code        := 'FV_BE_LINE_DESC';
273 l_source                := NULL;
270 l_component_type_code   := 'S';
271 l_component_appl_id     :=  8901;
272 l_amb_context_code      := 'DEFAULT';
274 l_description           := NULL;
275 
276 
277  IF p_source_2  >=  1
278  THEN 
279  
280  IF 
281 l_ledger_language = 'US' THEN
282     l_description :=  SUBSTR(CONCAT(l_description,'Budget Execution Transaction Line for the document number:'),1,2000);
283     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
284  END IF;   
285   l_source := SUBSTR(p_source_1,1,1996);
286   IF l_source IS NOT NULL THEN
287     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
288     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
289   END IF;  
290  IF 
291 l_ledger_language = 'US' THEN
292     l_description :=  SUBSTR(CONCAT(l_description,'and for the budget level:'),1,2000);
293     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
294  END IF;   
295   l_source := SUBSTR(TO_CHAR(p_source_2),1,1996);
296   IF l_source IS NOT NULL THEN
297     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
298     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
299   END IF; 
300  l_description := SUBSTR(l_description,1,1996);
301   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
302         trace
303            (p_msg      => 'END of Description_1'
304            ,p_level    => C_LEVEL_PROCEDURE
305            ,p_module   => l_log_module);
306 
307   END IF;
308   RETURN l_description;
309 
310  END IF;
311 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
312       trace
313          (p_msg      => 'END of Description_1'
314          ,p_level    => C_LEVEL_PROCEDURE
315          ,p_module   => l_log_module);
316 END IF;
317 RETURN NULL;
318 EXCEPTION
319   WHEN VALUE_ERROR THEN
320      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
321             trace
322                (p_msg      => 'ERROR: '||sqlerrm
323                ,p_level    => C_LEVEL_EXCEPTION
324                ,p_module   => l_log_module);
325      END IF;
326      RAISE;
327  WHEN xla_exceptions_pkg.application_exception THEN
328       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
329       trace
330          (p_msg      => 'ERROR: '||sqlerrm
331          ,p_level    => C_LEVEL_EXCEPTION
332          ,p_module   => l_log_module);
333       END IF;
334       RAISE;
335  WHEN OTHERS THEN
336        xla_exceptions_pkg.raise_message
337            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.Description_1');
338 END Description_1;
339 
340 ---------------------------------------
341 --
342 -- PRIVATE FUNCTION
343 --         AcctDerRule_2
344 --
345 ---------------------------------------
346 FUNCTION AcctDerRule_2 (
347   p_application_id             IN NUMBER
348 , p_ae_header_id               IN NUMBER
349 , p_side                       IN VARCHAR2
350 , p_override_seg_flag          IN VARCHAR2 
351 --CR_ACCOUNT_SEGMENT_VALUE
352  , p_source_3            IN VARCHAR2
353 , x_transaction_coa_id         OUT NOCOPY NUMBER
354 , x_accounting_coa_id          OUT NOCOPY NUMBER
355 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
356 , x_flex_value_set_id          OUT NOCOPY NUMBER
357 , x_value_type_code            OUT NOCOPY VARCHAR2
358 , x_value_combination_id       OUT NOCOPY NUMBER
359 , x_value_segment_code         OUT NOCOPY VARCHAR2
360 )
361 RETURN VARCHAR2
362 IS
363 l_component_type       VARCHAR2(80)  ;
364 l_component_code       VARCHAR2(30)  ;
365 l_component_type_code  VARCHAR2(1)   ;
366 l_component_appl_id    INTEGER       ;
367 l_amb_context_code     VARCHAR2(30)  ;
368 l_log_module           VARCHAR2(240) ;
369 l_output_value         VARCHAR2(30)  ;
370 BEGIN
371 IF g_log_enabled THEN
372       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_2';
373 END IF;
374 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
375 
376       trace
377          (p_msg      => 'BEGIN of AcctDerRule_2'
378          ,p_level    => C_LEVEL_PROCEDURE
379          ,p_module   => l_log_module);
380 
381 END IF;
382 
383 l_component_type         := 'AMB_ADR';
384 l_component_code         := 'FV_BE_RPR_TRX_CR_NATURAL_SEG';
385 l_component_type_code    := 'S';
386 l_component_appl_id      :=  8901;
387 l_amb_context_code       := 'DEFAULT';
388 x_transaction_coa_id     :=  null;
389 x_accounting_coa_id      :=  null;
390 x_flexfield_segment_code := 'GL_ACCOUNT';
391 x_flex_value_set_id      :=  null ;
392 
393 
394 --
395   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
396 
397       trace
398          (p_msg      => 'END of AcctDerRule_2'
399          ,p_level    => C_LEVEL_PROCEDURE
400          ,p_module   => l_log_module);
401 
402   END IF;
403   x_value_combination_id  :=  null ;
404   x_value_segment_code    :=  null ;
405   x_value_type_code       := 'S';
406   l_output_value          := TO_CHAR(p_source_3);
407   RETURN l_output_value;
408 
409 
410 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
411 
412       trace
413          (p_msg      => 'END of AcctDerRule_2(invalid)'
414          ,p_level    => C_LEVEL_PROCEDURE
415          ,p_module   => l_log_module);
416 
417 END IF;
418 
419 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
420 x_value_combination_id  := null;
421 x_value_segment_code    := null;
422 x_value_type_code       := null;
423 l_output_value          := null;
424 xla_accounting_err_pkg.build_message
425                  (p_appli_s_name            => 'XLA'
426                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
430                                                           , l_component_code
427                  ,p_token_1                 => 'COMPONENT_NAME'
428                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
429                                                             l_component_type
431                                                           , l_component_type_code
432                                                           , l_component_appl_id
433                                                           , l_amb_context_code
434                                                           )
435                  ,p_token_2                 => 'OWNER'
436                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
437                                                         'XLA_OWNER_TYPE'
438                                                         ,l_component_type_code
439                                                         )
440                  ,p_token_3                 => 'PAD_NAME'
441                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
442                  ,p_token_4                 => 'PAD_OWNER'
443                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
444                                                         'XLA_OWNER_TYPE'
445                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
446                                                         )
447                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
448                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
449                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
450                  ,p_ae_header_id            => NULL
451 );
452 RETURN l_output_value;
453 EXCEPTION
454   WHEN xla_exceptions_pkg.application_exception THEN
455       RAISE;
456   WHEN OTHERS THEN
457        xla_exceptions_pkg.raise_message
458            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.AcctDerRule_2');
459 END AcctDerRule_2;
460 --
461 
462 ---------------------------------------
463 --
464 -- PRIVATE FUNCTION
465 --         AcctDerRule_3
466 --
467 ---------------------------------------
468 FUNCTION AcctDerRule_3 (
469   p_application_id             IN NUMBER
470 , p_ae_header_id               IN NUMBER
471 , p_side                       IN VARCHAR2
472 , p_override_seg_flag          IN VARCHAR2 
473 --DR_ACCOUNT_SEGMENT_VALUE
474  , p_source_4            IN VARCHAR2
475 , x_transaction_coa_id         OUT NOCOPY NUMBER
476 , x_accounting_coa_id          OUT NOCOPY NUMBER
477 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
478 , x_flex_value_set_id          OUT NOCOPY NUMBER
479 , x_value_type_code            OUT NOCOPY VARCHAR2
480 , x_value_combination_id       OUT NOCOPY NUMBER
481 , x_value_segment_code         OUT NOCOPY VARCHAR2
482 )
483 RETURN VARCHAR2
484 IS
485 l_component_type       VARCHAR2(80)  ;
486 l_component_code       VARCHAR2(30)  ;
487 l_component_type_code  VARCHAR2(1)   ;
488 l_component_appl_id    INTEGER       ;
489 l_amb_context_code     VARCHAR2(30)  ;
490 l_log_module           VARCHAR2(240) ;
491 l_output_value         VARCHAR2(30)  ;
492 BEGIN
493 IF g_log_enabled THEN
494       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_3';
495 END IF;
496 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
497 
498       trace
499          (p_msg      => 'BEGIN of AcctDerRule_3'
500          ,p_level    => C_LEVEL_PROCEDURE
501          ,p_module   => l_log_module);
502 
503 END IF;
504 
505 l_component_type         := 'AMB_ADR';
506 l_component_code         := 'FV_BE_RPR_TRX_DR_NATURAL_SEG';
507 l_component_type_code    := 'S';
508 l_component_appl_id      :=  8901;
509 l_amb_context_code       := 'DEFAULT';
510 x_transaction_coa_id     :=  null;
511 x_accounting_coa_id      :=  null;
512 x_flexfield_segment_code := 'GL_ACCOUNT';
513 x_flex_value_set_id      :=  null ;
514 
515 
516 --
517   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
518 
519       trace
520          (p_msg      => 'END of AcctDerRule_3'
521          ,p_level    => C_LEVEL_PROCEDURE
522          ,p_module   => l_log_module);
523 
524   END IF;
525   x_value_combination_id  :=  null ;
526   x_value_segment_code    :=  null ;
527   x_value_type_code       := 'S';
528   l_output_value          := TO_CHAR(p_source_4);
529   RETURN l_output_value;
530 
531 
532 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
533 
534       trace
535          (p_msg      => 'END of AcctDerRule_3(invalid)'
536          ,p_level    => C_LEVEL_PROCEDURE
537          ,p_module   => l_log_module);
538 
539 END IF;
540 
541 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
542 x_value_combination_id  := null;
543 x_value_segment_code    := null;
544 x_value_type_code       := null;
545 l_output_value          := null;
546 xla_accounting_err_pkg.build_message
547                  (p_appli_s_name            => 'XLA'
548                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
549                  ,p_token_1                 => 'COMPONENT_NAME'
550                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
551                                                             l_component_type
552                                                           , l_component_code
553                                                           , l_component_type_code
554                                                           , l_component_appl_id
555                                                           , l_amb_context_code
559                                                         'XLA_OWNER_TYPE'
556                                                           )
557                  ,p_token_2                 => 'OWNER'
558                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
560                                                         ,l_component_type_code
561                                                         )
562                  ,p_token_3                 => 'PAD_NAME'
563                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
564                  ,p_token_4                 => 'PAD_OWNER'
565                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
566                                                         'XLA_OWNER_TYPE'
567                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
568                                                         )
569                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
570                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
571                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
572                  ,p_ae_header_id            => NULL
573 );
574 RETURN l_output_value;
575 EXCEPTION
576   WHEN xla_exceptions_pkg.application_exception THEN
577       RAISE;
578   WHEN OTHERS THEN
579        xla_exceptions_pkg.raise_message
580            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.AcctDerRule_3');
581 END AcctDerRule_3;
582 --
583 
584 ---------------------------------------
585 --
586 -- PRIVATE FUNCTION
587 --         AcctDerRule_4
588 --
589 ---------------------------------------
590 FUNCTION AcctDerRule_4 (
591   p_application_id             IN NUMBER
592 , p_ae_header_id               IN NUMBER
593 , p_side                       IN VARCHAR2
594 , p_override_seg_flag          IN VARCHAR2 
595 --CR_ACCOUNT_SEGMENT_VALUE
596  , p_source_3            IN VARCHAR2
597 --DR_ACCOUNT_SEGMENT_VALUE
598  , p_source_4            IN VARCHAR2
599 --INCREASE_DECREASE_FLAG
600  , p_source_5            IN VARCHAR2
601 , x_transaction_coa_id         OUT NOCOPY NUMBER
602 , x_accounting_coa_id          OUT NOCOPY NUMBER
603 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
604 , x_flex_value_set_id          OUT NOCOPY NUMBER
605 , x_value_type_code            OUT NOCOPY VARCHAR2
606 , x_value_combination_id       OUT NOCOPY NUMBER
607 , x_value_segment_code         OUT NOCOPY VARCHAR2
608 )
609 RETURN VARCHAR2
610 IS
611 l_component_type       VARCHAR2(80)  ;
612 l_component_code       VARCHAR2(30)  ;
613 l_component_type_code  VARCHAR2(1)   ;
614 l_component_appl_id    INTEGER       ;
615 l_amb_context_code     VARCHAR2(30)  ;
616 l_log_module           VARCHAR2(240) ;
617 l_output_value         VARCHAR2(30)  ;
618 BEGIN
619 IF g_log_enabled THEN
620       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_4';
621 END IF;
622 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
623 
624       trace
625          (p_msg      => 'BEGIN of AcctDerRule_4'
626          ,p_level    => C_LEVEL_PROCEDURE
627          ,p_module   => l_log_module);
628 
629 END IF;
630 
631 l_component_type         := 'AMB_ADR';
632 l_component_code         := 'FV_BE_TRX_CR_NATURAL_SEGMENT';
633 l_component_type_code    := 'S';
634 l_component_appl_id      :=  8901;
635 l_amb_context_code       := 'DEFAULT';
636 x_transaction_coa_id     :=  null;
637 x_accounting_coa_id      :=  null;
638 x_flexfield_segment_code := 'GL_ACCOUNT';
639 x_flex_value_set_id      :=  null ;
640 
641 
642  IF NVL(p_source_5,'
643 ')  =  'I'
644  THEN 
645 --
646   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
647 
648       trace
649          (p_msg      => 'END of AcctDerRule_4'
650          ,p_level    => C_LEVEL_PROCEDURE
651          ,p_module   => l_log_module);
652 
653   END IF;
654   x_value_combination_id  :=  null ;
655   x_value_segment_code    :=  null ;
656   x_value_type_code       := 'S';
657   l_output_value          := TO_CHAR(p_source_3);
658   RETURN l_output_value;
659 
660  ELSIF NVL(p_source_5,'
661 ')  =  'D'
662  THEN 
663 --
664   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
665 
666       trace
667          (p_msg      => 'END of AcctDerRule_4'
668          ,p_level    => C_LEVEL_PROCEDURE
669          ,p_module   => l_log_module);
670 
671   END IF;
672   x_value_combination_id  :=  null ;
673   x_value_segment_code    :=  null ;
674   x_value_type_code       := 'S';
675   l_output_value          := TO_CHAR(p_source_4);
676   RETURN l_output_value;
677 
678  ELSE 
679     IF p_override_seg_flag = 'Y' THEN 
680        RETURN '#$NO_OVERRIDE#$';
681     END IF;
682  END IF;
683 
684 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
685 
686       trace
687          (p_msg      => 'END of AcctDerRule_4(invalid)'
688          ,p_level    => C_LEVEL_PROCEDURE
689          ,p_module   => l_log_module);
690 
691 END IF;
692 
693 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
694 x_value_combination_id  := null;
695 x_value_segment_code    := null;
696 x_value_type_code       := null;
697 l_output_value          := null;
698 xla_accounting_err_pkg.build_message
699                  (p_appli_s_name            => 'XLA'
700                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
701                  ,p_token_1                 => 'COMPONENT_NAME'
702                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
706                                                           , l_component_appl_id
703                                                             l_component_type
704                                                           , l_component_code
705                                                           , l_component_type_code
707                                                           , l_amb_context_code
708                                                           )
709                  ,p_token_2                 => 'OWNER'
710                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
711                                                         'XLA_OWNER_TYPE'
712                                                         ,l_component_type_code
713                                                         )
714                  ,p_token_3                 => 'PAD_NAME'
715                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
716                  ,p_token_4                 => 'PAD_OWNER'
717                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
718                                                         'XLA_OWNER_TYPE'
719                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
720                                                         )
721                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
722                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
723                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
724                  ,p_ae_header_id            => NULL
725 );
726 RETURN l_output_value;
727 EXCEPTION
728   WHEN xla_exceptions_pkg.application_exception THEN
729       RAISE;
730   WHEN OTHERS THEN
731        xla_exceptions_pkg.raise_message
732            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.AcctDerRule_4');
733 END AcctDerRule_4;
734 --
735 
736 ---------------------------------------
737 --
738 -- PRIVATE FUNCTION
739 --         AcctDerRule_5
740 --
741 ---------------------------------------
742 FUNCTION AcctDerRule_5 (
743   p_application_id             IN NUMBER
744 , p_ae_header_id               IN NUMBER
745 , p_side                       IN VARCHAR2
746 , p_override_seg_flag          IN VARCHAR2 
747 --CR_ACCOUNT_SEGMENT_VALUE
748  , p_source_3            IN VARCHAR2
749 --DR_ACCOUNT_SEGMENT_VALUE
750  , p_source_4            IN VARCHAR2
751 --INCREASE_DECREASE_FLAG
752  , p_source_5            IN VARCHAR2
753 , x_transaction_coa_id         OUT NOCOPY NUMBER
754 , x_accounting_coa_id          OUT NOCOPY NUMBER
755 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
756 , x_flex_value_set_id          OUT NOCOPY NUMBER
757 , x_value_type_code            OUT NOCOPY VARCHAR2
758 , x_value_combination_id       OUT NOCOPY NUMBER
759 , x_value_segment_code         OUT NOCOPY VARCHAR2
760 )
761 RETURN VARCHAR2
762 IS
763 l_component_type       VARCHAR2(80)  ;
764 l_component_code       VARCHAR2(30)  ;
765 l_component_type_code  VARCHAR2(1)   ;
766 l_component_appl_id    INTEGER       ;
767 l_amb_context_code     VARCHAR2(30)  ;
768 l_log_module           VARCHAR2(240) ;
769 l_output_value         VARCHAR2(30)  ;
770 BEGIN
771 IF g_log_enabled THEN
772       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_5';
773 END IF;
774 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
775 
776       trace
777          (p_msg      => 'BEGIN of AcctDerRule_5'
778          ,p_level    => C_LEVEL_PROCEDURE
779          ,p_module   => l_log_module);
780 
781 END IF;
782 
783 l_component_type         := 'AMB_ADR';
784 l_component_code         := 'FV_BE_TRX_DR_NATURAL_SEGMENT';
785 l_component_type_code    := 'S';
786 l_component_appl_id      :=  8901;
787 l_amb_context_code       := 'DEFAULT';
788 x_transaction_coa_id     :=  null;
789 x_accounting_coa_id      :=  null;
790 x_flexfield_segment_code := 'GL_ACCOUNT';
791 x_flex_value_set_id      :=  null ;
792 
793 
794  IF NVL(p_source_5,'
795 ')  =  'I'
796  THEN 
797 --
798   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
799 
800       trace
801          (p_msg      => 'END of AcctDerRule_5'
802          ,p_level    => C_LEVEL_PROCEDURE
803          ,p_module   => l_log_module);
804 
805   END IF;
806   x_value_combination_id  :=  null ;
807   x_value_segment_code    :=  null ;
808   x_value_type_code       := 'S';
809   l_output_value          := TO_CHAR(p_source_4);
810   RETURN l_output_value;
811 
812  ELSIF NVL(p_source_5,'
813 ')  =  'D'
814  THEN 
815 --
816   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
817 
818       trace
819          (p_msg      => 'END of AcctDerRule_5'
820          ,p_level    => C_LEVEL_PROCEDURE
821          ,p_module   => l_log_module);
822 
823   END IF;
824   x_value_combination_id  :=  null ;
825   x_value_segment_code    :=  null ;
826   x_value_type_code       := 'S';
827   l_output_value          := TO_CHAR(p_source_3);
828   RETURN l_output_value;
829 
830  ELSE 
831     IF p_override_seg_flag = 'Y' THEN 
832        RETURN '#$NO_OVERRIDE#$';
833     END IF;
834  END IF;
835 
836 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
837 
838       trace
839          (p_msg      => 'END of AcctDerRule_5(invalid)'
840          ,p_level    => C_LEVEL_PROCEDURE
841          ,p_module   => l_log_module);
842 
843 END IF;
844 
845 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
846 x_value_combination_id  := null;
850 xla_accounting_err_pkg.build_message
847 x_value_segment_code    := null;
848 x_value_type_code       := null;
849 l_output_value          := null;
851                  (p_appli_s_name            => 'XLA'
852                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
853                  ,p_token_1                 => 'COMPONENT_NAME'
854                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
855                                                             l_component_type
856                                                           , l_component_code
857                                                           , l_component_type_code
858                                                           , l_component_appl_id
859                                                           , l_amb_context_code
860                                                           )
861                  ,p_token_2                 => 'OWNER'
862                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
863                                                         'XLA_OWNER_TYPE'
864                                                         ,l_component_type_code
865                                                         )
866                  ,p_token_3                 => 'PAD_NAME'
867                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
868                  ,p_token_4                 => 'PAD_OWNER'
869                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
870                                                         'XLA_OWNER_TYPE'
871                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
872                                                         )
873                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
874                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
875                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
876                  ,p_ae_header_id            => NULL
877 );
878 RETURN l_output_value;
879 EXCEPTION
880   WHEN xla_exceptions_pkg.application_exception THEN
881       RAISE;
882   WHEN OTHERS THEN
883        xla_exceptions_pkg.raise_message
884            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.AcctDerRule_5');
885 END AcctDerRule_5;
886 --
887 
888 ---------------------------------------
889 --
890 -- PRIVATE FUNCTION
891 --         AcctDerRule_6
892 --
893 ---------------------------------------
894 FUNCTION AcctDerRule_6 (
895   p_application_id              IN NUMBER
896 , p_ae_header_id                IN NUMBER
897 , p_side                        IN VARCHAR2 
898 --DISTRIBUTION_FROM_ACCOUNT
899  , p_source_6            IN NUMBER
900 , x_transaction_coa_id         OUT NOCOPY NUMBER
901 , x_accounting_coa_id          OUT NOCOPY NUMBER
902 , x_value_type_code            OUT NOCOPY VARCHAR2
903 )
904 RETURN NUMBER
905 IS
906 l_component_type       VARCHAR2(80)  ;
907 l_component_code       VARCHAR2(30)  ;
908 l_component_type_code  VARCHAR2(1)   ;
909 l_component_appl_id    INTEGER       ;
910 l_amb_context_code     VARCHAR2(30)  ;
911 l_log_module           VARCHAR2(240) ;
912 l_output_value         NUMBER        ;
913 BEGIN
914 IF g_log_enabled THEN
915       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_6';
916 END IF;
917 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
918       trace
919          (p_msg      => 'BEGIN of AcctDerRule_6'
920          ,p_level    => C_LEVEL_PROCEDURE
921          ,p_module   => l_log_module);
922 END IF;
923 --
924 l_component_type         := 'AMB_ADR';
925 l_component_code         := 'FV_BE_RPR_FROM_TRX_CCID';
926 l_component_type_code    := 'S';
927 l_component_appl_id      :=  8901;
928 l_amb_context_code       := 'DEFAULT';
929 x_transaction_coa_id     :=  null;
930 x_accounting_coa_id      :=  null;
931 --
932 
933  --
934   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
935       trace
936          (p_msg      => 'END of AcctDerRule_6'
937          ,p_level    => C_LEVEL_PROCEDURE
938          ,p_module   => l_log_module);
939   END IF;
940   x_value_type_code := 'S';
941   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_6));
942   RETURN l_output_value;
943 
944 --
945 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
946       trace
947          (p_msg      => 'END of AcctDerRule_6(invalid)'
948          ,p_level    => C_LEVEL_PROCEDURE
949          ,p_module   => l_log_module);
950 END IF;
951 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
952 x_value_type_code := null;
953 l_output_value    := null;
954 xla_accounting_err_pkg.build_message
955                  (p_appli_s_name            => 'XLA'
956                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
957                  ,p_token_1                 => 'COMPONENT_NAME'
958                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
959                                                             l_component_type
960                                                           , l_component_code
961                                                           , l_component_type_code
962                                                           , l_component_appl_id
963                                                           , l_amb_context_code
964                                                           )
965                  ,p_token_2                 => 'OWNER'
966                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
970                  ,p_token_3                 => 'PAD_NAME'
967                                                         'XLA_OWNER_TYPE'
968                                                         ,l_component_type_code
969                                                         )
971                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
972                  ,p_token_4                 => 'PAD_OWNER'
973                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
974                                                         'XLA_OWNER_TYPE'
975                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
976                                                         )
977                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
978                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
979                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
980                  ,p_ae_header_id            => NULL
981 );
982 RETURN l_output_value;
983 EXCEPTION
984   WHEN xla_exceptions_pkg.application_exception THEN
985       RAISE;
986   WHEN OTHERS THEN
987        xla_exceptions_pkg.raise_message
988            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.AcctDerRule_6');
989 END AcctDerRule_6;
990 --
991 
992 ---------------------------------------
993 --
994 -- PRIVATE FUNCTION
995 --         AcctDerRule_7
996 --
997 ---------------------------------------
998 FUNCTION AcctDerRule_7 (
999   p_application_id              IN NUMBER
1000 , p_ae_header_id                IN NUMBER
1001 , p_side                        IN VARCHAR2 
1002 --DISTRIBUTION_TO_ACCOUNT
1003  , p_source_7            IN NUMBER
1004 , x_transaction_coa_id         OUT NOCOPY NUMBER
1005 , x_accounting_coa_id          OUT NOCOPY NUMBER
1006 , x_value_type_code            OUT NOCOPY VARCHAR2
1007 )
1008 RETURN NUMBER
1009 IS
1010 l_component_type       VARCHAR2(80)  ;
1011 l_component_code       VARCHAR2(30)  ;
1012 l_component_type_code  VARCHAR2(1)   ;
1013 l_component_appl_id    INTEGER       ;
1014 l_amb_context_code     VARCHAR2(30)  ;
1015 l_log_module           VARCHAR2(240) ;
1016 l_output_value         NUMBER        ;
1017 BEGIN
1018 IF g_log_enabled THEN
1019       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_7';
1020 END IF;
1021 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1022       trace
1023          (p_msg      => 'BEGIN of AcctDerRule_7'
1024          ,p_level    => C_LEVEL_PROCEDURE
1025          ,p_module   => l_log_module);
1026 END IF;
1027 --
1028 l_component_type         := 'AMB_ADR';
1029 l_component_code         := 'FV_BE_RPR_TO_TRX_CCID';
1030 l_component_type_code    := 'S';
1031 l_component_appl_id      :=  8901;
1032 l_amb_context_code       := 'DEFAULT';
1033 x_transaction_coa_id     :=  null;
1034 x_accounting_coa_id      :=  null;
1035 --
1036 
1037  --
1038   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1039       trace
1040          (p_msg      => 'END of AcctDerRule_7'
1041          ,p_level    => C_LEVEL_PROCEDURE
1042          ,p_module   => l_log_module);
1043   END IF;
1044   x_value_type_code := 'S';
1045   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_7));
1046   RETURN l_output_value;
1047 
1048 --
1049 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1050       trace
1051          (p_msg      => 'END of AcctDerRule_7(invalid)'
1052          ,p_level    => C_LEVEL_PROCEDURE
1053          ,p_module   => l_log_module);
1054 END IF;
1055 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1056 x_value_type_code := null;
1057 l_output_value    := null;
1058 xla_accounting_err_pkg.build_message
1059                  (p_appli_s_name            => 'XLA'
1060                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1061                  ,p_token_1                 => 'COMPONENT_NAME'
1062                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1063                                                             l_component_type
1064                                                           , l_component_code
1065                                                           , l_component_type_code
1066                                                           , l_component_appl_id
1067                                                           , l_amb_context_code
1068                                                           )
1069                  ,p_token_2                 => 'OWNER'
1070                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1071                                                         'XLA_OWNER_TYPE'
1072                                                         ,l_component_type_code
1073                                                         )
1074                  ,p_token_3                 => 'PAD_NAME'
1075                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1076                  ,p_token_4                 => 'PAD_OWNER'
1077                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1078                                                         'XLA_OWNER_TYPE'
1079                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1080                                                         )
1081                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1082                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1083                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1087 EXCEPTION
1084                  ,p_ae_header_id            => NULL
1085 );
1086 RETURN l_output_value;
1088   WHEN xla_exceptions_pkg.application_exception THEN
1089       RAISE;
1090   WHEN OTHERS THEN
1091        xla_exceptions_pkg.raise_message
1092            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.AcctDerRule_7');
1093 END AcctDerRule_7;
1094 --
1095 
1096 ---------------------------------------
1097 --
1098 -- PRIVATE FUNCTION
1099 --         AcctDerRule_8
1100 --
1101 ---------------------------------------
1102 FUNCTION AcctDerRule_8 (
1103   p_application_id              IN NUMBER
1104 , p_ae_header_id                IN NUMBER
1105 , p_side                        IN VARCHAR2 
1106 --BUDGET_LEVEL_ID
1107  , p_source_2            IN NUMBER
1108 --DISTRIBUTION_ACCOUNT
1109  , p_source_8            IN NUMBER
1110 --FUND_DISTRIBUTION_ACCOUNT
1111  , p_source_9            IN NUMBER
1112 , x_transaction_coa_id         OUT NOCOPY NUMBER
1113 , x_accounting_coa_id          OUT NOCOPY NUMBER
1114 , x_value_type_code            OUT NOCOPY VARCHAR2
1115 )
1116 RETURN NUMBER
1117 IS
1118 l_component_type       VARCHAR2(80)  ;
1119 l_component_code       VARCHAR2(30)  ;
1120 l_component_type_code  VARCHAR2(1)   ;
1121 l_component_appl_id    INTEGER       ;
1122 l_amb_context_code     VARCHAR2(30)  ;
1123 l_log_module           VARCHAR2(240) ;
1124 l_output_value         NUMBER        ;
1125 BEGIN
1126 IF g_log_enabled THEN
1127       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_8';
1128 END IF;
1129 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1130       trace
1131          (p_msg      => 'BEGIN of AcctDerRule_8'
1132          ,p_level    => C_LEVEL_PROCEDURE
1133          ,p_module   => l_log_module);
1134 END IF;
1135 --
1136 l_component_type         := 'AMB_ADR';
1137 l_component_code         := 'FV_BE_TRANSACTION_CCID';
1138 l_component_type_code    := 'S';
1139 l_component_appl_id      :=  8901;
1140 l_amb_context_code       := 'DEFAULT';
1141 x_transaction_coa_id     :=  null;
1142 x_accounting_coa_id      :=  null;
1143 --
1144 
1145  IF NVL(p_source_2,9E125)  =  1
1146  THEN 
1147  --
1148   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1149       trace
1150          (p_msg      => 'END of AcctDerRule_8'
1151          ,p_level    => C_LEVEL_PROCEDURE
1152          ,p_module   => l_log_module);
1153   END IF;
1154   x_value_type_code := 'S';
1155   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_8));
1156   RETURN l_output_value;
1157 
1158  ELSIF p_source_2  >  1
1159  THEN 
1160  --
1161   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1162       trace
1163          (p_msg      => 'END of AcctDerRule_8'
1164          ,p_level    => C_LEVEL_PROCEDURE
1165          ,p_module   => l_log_module);
1166   END IF;
1167   x_value_type_code := 'S';
1168   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_9));
1169   RETURN l_output_value;
1170 
1171  END IF;
1172 --
1173 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1174       trace
1175          (p_msg      => 'END of AcctDerRule_8(invalid)'
1176          ,p_level    => C_LEVEL_PROCEDURE
1177          ,p_module   => l_log_module);
1178 END IF;
1179 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1180 x_value_type_code := null;
1181 l_output_value    := null;
1182 xla_accounting_err_pkg.build_message
1183                  (p_appli_s_name            => 'XLA'
1184                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1185                  ,p_token_1                 => 'COMPONENT_NAME'
1186                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1187                                                             l_component_type
1188                                                           , l_component_code
1189                                                           , l_component_type_code
1190                                                           , l_component_appl_id
1191                                                           , l_amb_context_code
1192                                                           )
1193                  ,p_token_2                 => 'OWNER'
1194                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1195                                                         'XLA_OWNER_TYPE'
1196                                                         ,l_component_type_code
1197                                                         )
1198                  ,p_token_3                 => 'PAD_NAME'
1199                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1200                  ,p_token_4                 => 'PAD_OWNER'
1201                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1202                                                         'XLA_OWNER_TYPE'
1203                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1204                                                         )
1205                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1206                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1207                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1208                  ,p_ae_header_id            => NULL
1209 );
1210 RETURN l_output_value;
1211 EXCEPTION
1212   WHEN xla_exceptions_pkg.application_exception THEN
1213       RAISE;
1214   WHEN OTHERS THEN
1215        xla_exceptions_pkg.raise_message
1216            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.AcctDerRule_8');
1217 END AcctDerRule_8;
1218 --
1219 
1220 ---------------------------------------
1221 --
1222 -- PRIVATE FUNCTION
1223 --         AcctLineType_9
1224 --
1228  ,p_event_id              IN NUMBER
1225 ---------------------------------------
1226 PROCEDURE AcctLineType_9 (
1227   p_application_id        IN NUMBER
1229  ,p_calculate_acctd_flag  IN VARCHAR2
1230  ,p_calculate_g_l_flag    IN VARCHAR2
1231  ,p_actual_flag           IN OUT VARCHAR2
1232  ,p_balance_type_code     OUT VARCHAR2
1233  ,p_gain_or_loss_ref      OUT VARCHAR2
1234  
1235 --DOC_NUMBER
1236  , p_source_1            IN VARCHAR2
1237 --BUDGET_LEVEL_ID
1238  , p_source_2            IN NUMBER
1239 --DR_ACCOUNT_SEGMENT_VALUE
1240  , p_source_4            IN VARCHAR2
1241 --DISTRIBUTION_FROM_ACCOUNT
1242  , p_source_6            IN NUMBER
1243 --SOURCE
1244  , p_source_10            IN VARCHAR2
1245 --TRANSACTION_ID
1246  , p_source_11            IN NUMBER
1247 --TRANSACTION_TYPE
1248  , p_source_12            IN VARCHAR2
1249 --TRANSACTION_TYPE_ID
1250  , p_source_13            IN NUMBER
1251 --Accounted Amount
1252  , p_source_14            IN NUMBER
1253 --CURRENCY_CODE
1254  , p_source_15            IN VARCHAR2
1255 )
1256 IS
1257 
1258 l_component_type              VARCHAR2(80);
1259 l_component_code              VARCHAR2(30);
1260 l_component_type_code         VARCHAR2(1);
1261 l_component_appl_id           INTEGER;
1262 l_amb_context_code            VARCHAR2(30);
1263 l_entity_code                 VARCHAR2(30);
1264 l_event_class_code            VARCHAR2(30);
1265 l_ae_header_id                NUMBER;
1266 l_event_type_code             VARCHAR2(30);
1267 l_line_definition_code        VARCHAR2(30);
1268 l_line_definition_owner_code  VARCHAR2(1);
1269 --
1270 -- adr variables
1271 l_segment                     VARCHAR2(30);
1272 l_ccid                        NUMBER;
1273 l_adr_transaction_coa_id      NUMBER;
1274 l_adr_accounting_coa_id       NUMBER;
1275 l_adr_flexfield_segment_code  VARCHAR2(30);
1276 l_adr_flex_value_set_id       NUMBER;
1277 l_adr_value_type_code         VARCHAR2(30);
1278 l_adr_value_combination_id    NUMBER;
1279 l_adr_value_segment_code      VARCHAR2(30);
1280 
1281 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
1282 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
1283 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
1284 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
1285 
1286 -- 4262811 Variables ------------------------------------------------------------------------------------------
1287 l_entered_amt_idx             NUMBER;
1288 l_accted_amt_idx              NUMBER;
1289 l_acc_rev_flag                VARCHAR2(1);
1290 l_accrual_line_num            NUMBER;
1291 l_tmp_amt                     NUMBER;
1292 l_acc_rev_natural_side_code   VARCHAR2(1);
1293 
1294 l_num_entries                 NUMBER;
1295 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
1296 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
1297 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
1298 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
1299 l_recog_line_1                NUMBER;
1300 l_recog_line_2                NUMBER;
1301 
1302 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
1303 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
1304 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
1305 
1306 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
1307 
1308 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
1309 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
1310 
1311 ---------------------------------------------------------------------------------------------------------------
1312 
1313 
1314 --
1315 -- bulk performance
1316 --
1317 l_balance_type_code           VARCHAR2(1);
1318 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
1319 l_log_module                  VARCHAR2(240);
1320 
1321 --
1322 -- Upgrade strategy
1323 --
1324 l_actual_upg_option           VARCHAR2(1);
1325 l_enc_upg_option           VARCHAR2(1);
1326 
1327 --
1328 BEGIN
1329 --
1330 IF g_log_enabled THEN
1331       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_9';
1332 END IF;
1333 --
1334 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1335 
1336       trace
1337          (p_msg      => 'BEGIN of AcctLineType_9'
1338          ,p_level    => C_LEVEL_PROCEDURE
1339          ,p_module   => l_log_module);
1340 
1341 END IF;
1342 --
1343 l_component_type             := 'AMB_JLT';
1344 l_component_code             := 'FV_BE_RPR_FROM_TRX_CR';
1345 l_component_type_code        := 'S';
1346 l_component_appl_id          :=  8901;
1347 l_amb_context_code           := 'DEFAULT';
1348 l_entity_code                := 'BE_RPR_TRANSACTIONS';
1349 l_event_class_code           := 'RPR_BUDGET_EXECUTION';
1350 l_event_type_code            := 'RPR_BUDGET_EXECUTION_ALL';
1351 l_line_definition_owner_code := 'S';
1352 l_line_definition_code       := 'FV_BE_RPR_TRX_JLD';
1353 --
1354 l_balance_type_code          := 'A';
1355 l_segment                     := NULL;
1356 l_ccid                        := NULL;
1357 l_adr_transaction_coa_id      := NULL;
1358 l_adr_accounting_coa_id       := NULL;
1359 l_adr_flexfield_segment_code  := NULL;
1360 l_adr_flex_value_set_id       := NULL;
1361 l_adr_value_type_code         := NULL;
1362 l_adr_value_combination_id    := NULL;
1363 l_adr_value_segment_code      := NULL;
1364 
1365 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
1366 l_bflow_class_code           := '';    -- 4219869 Business Flow
1367 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
1368 l_budgetary_control_flag     := 'Y';
1369 
1373 l_accted_amt_idx             := NULL;          -- 4262811
1370 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
1371 l_bflow_applied_to_amt       := NULL; -- 5132302
1372 l_entered_amt_idx            := NULL;          -- 4262811
1374 l_acc_rev_flag               := NULL;          -- 4262811
1375 l_accrual_line_num           := NULL;          -- 4262811
1376 l_tmp_amt                    := NULL;          -- 4262811
1377 --
1378  
1379 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
1380     l_balance_type_code <> 'B' THEN
1381 IF (p_source_2  >=  1 AND 
1382 NVL(p_source_10,'
1383 ')  =  'RPR')
1384  THEN 
1385 
1386    --
1387    XLA_AE_LINES_PKG.SetNewLine;
1388 
1389    p_balance_type_code          := l_balance_type_code;
1390    -- set the flag so later we will know whether the gain loss line needs to be created
1391    
1392    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
1393      p_actual_flag :='A';
1394    END IF;
1395 
1396    --
1397    -- bulk performance
1398    --
1399    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
1400                                       p_header_num   => 0); -- 4262811
1401    --
1402    -- set accounting line options
1403    --
1404    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
1405            p_natural_side_code          => 'C'
1406          , p_gain_or_loss_flag          => 'N'
1407          , p_gl_transfer_mode_code      => 'S'
1408          , p_acct_entry_type_code       => 'A'
1409          , p_switch_side_flag           => 'N'
1410          , p_merge_duplicate_code       => 'N'
1411          );
1412    --
1413    l_acc_rev_natural_side_code := 'D';  -- 4262811
1414    -- 
1415    --
1416    -- set accounting line type info
1417    --
1418    xla_ae_lines_pkg.SetAcctLineType
1419       (p_component_type             => l_component_type
1420       ,p_event_type_code            => l_event_type_code
1421       ,p_line_definition_owner_code => l_line_definition_owner_code
1422       ,p_line_definition_code       => l_line_definition_code
1423       ,p_accounting_line_code       => l_component_code
1424       ,p_accounting_line_type_code  => l_component_type_code
1425       ,p_accounting_line_appl_id    => l_component_appl_id
1426       ,p_amb_context_code           => l_amb_context_code
1427       ,p_entity_code                => l_entity_code
1428       ,p_event_class_code           => l_event_class_code);
1429    --
1430    -- set accounting class
1431    --
1432    xla_ae_lines_pkg.SetAcctClass(
1433            p_accounting_class_code  => 'BE_RESERVE_CR'
1434          , p_ae_header_id           => l_ae_header_id
1435          );
1436 
1437    --
1438    -- set rounding class
1439    --
1440    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
1441                       'BE_RESERVE_CR';
1442 
1443    --
1444    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
1445    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
1446    --
1447    -- bulk performance
1448    --
1449    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
1450 
1451    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
1452       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
1453 
1454    -- 4955764
1455    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1456       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
1457 
1458    -- 4458381 Public Sector Enh
1459    
1460    --
1461    -- set accounting attributes for the line type
1462    --
1463    l_entered_amt_idx := 4;
1464    l_accted_amt_idx  := 6;
1465    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
1466    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
1467    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_11);
1468    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
1469    l_rec_acct_attrs.array_char_value(2)  := p_source_12;
1470    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
1471    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_13);
1472    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
1473    l_rec_acct_attrs.array_num_value(4)  := p_source_14;
1474    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
1475    l_rec_acct_attrs.array_char_value(5)  := p_source_15;
1476    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
1477    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
1478 
1479    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
1480    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
1481 
1482    ---------------------------------------------------------------------------------------------------------------
1483    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
1484    ---------------------------------------------------------------------------------------------------------------
1485    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
1486 
1487    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1488    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1489 
1490    IF xla_accounting_cache_pkg.GetValueChar
1491          (p_source_code         => 'LEDGER_CATEGORY_CODE'
1492          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
1496          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
1493    AND l_bflow_method_code = 'PRIOR_ENTRY'
1494 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
1495    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
1497        )
1498    THEN
1499          xla_ae_lines_pkg.BflowUpgEntry
1500            (p_business_method_code    => l_bflow_method_code
1501            ,p_business_class_code     => l_bflow_class_code
1502            ,p_balance_type            => l_balance_type_code);
1503    ELSE
1504       NULL;
1505 -- No business flow processing for business flow method of NONE.
1506    END IF;
1507 
1508    --
1509    -- call description
1510    --
1511    
1512 xla_ae_lines_pkg.SetLineDescription(
1513    p_ae_header_id => l_ae_header_id
1514   ,p_description  => Description_1 (
1515      p_application_id         => p_application_id
1516    , p_ae_header_id           => l_ae_header_id 
1517 , p_source_1 => p_source_1
1518 , p_source_2 => p_source_2
1519    )
1520 );
1521 
1522 
1523    --
1524    -- call ADRs
1525    -- Bug 4922099
1526    --
1527    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
1528         (NVL(l_actual_upg_option, 'N') = 'O') OR
1529         (NVL(l_enc_upg_option, 'N') = 'O')
1530       )
1531    THEN
1532    NULL;
1533    --
1534    --
1535    
1536   l_ccid := AcctDerRule_6(
1537            p_application_id           => p_application_id
1538          , p_ae_header_id             => l_ae_header_id 
1539 , p_source_6 => p_source_6
1540          , x_transaction_coa_id       => l_adr_transaction_coa_id
1541          , x_accounting_coa_id        => l_adr_accounting_coa_id
1542          , x_value_type_code          => l_adr_value_type_code
1543          , p_side                     => 'NA'
1544    );
1545 
1546    xla_ae_lines_pkg.set_ccid(
1547     p_code_combination_id          => l_ccid
1548   , p_value_type_code              => l_adr_value_type_code
1549   , p_transaction_coa_id           => l_adr_transaction_coa_id
1550   , p_accounting_coa_id            => l_adr_accounting_coa_id
1551   , p_adr_code                     => 'FV_BE_RPR_FROM_TRX_CCID'
1552   , p_adr_type_code                => 'S'
1553   , p_component_type               => l_component_type
1554   , p_component_code               => l_component_code
1555   , p_component_type_code          => l_component_type_code
1556   , p_component_appl_id            => l_component_appl_id
1557   , p_amb_context_code             => l_amb_context_code
1558   , p_side                         => 'NA'
1559   );
1560 
1561 
1562    l_segment := AcctDerRule_3(
1563            p_application_id           => p_application_id
1564          , p_ae_header_id             => l_ae_header_id 
1565 , p_source_4 => p_source_4
1566          , x_transaction_coa_id       => l_adr_transaction_coa_id
1567          , x_accounting_coa_id        => l_adr_accounting_coa_id
1568          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
1569          , x_flex_value_set_id        => l_adr_flex_value_set_id
1570          , x_value_type_code          => l_adr_value_type_code
1571          , x_value_combination_id     => l_adr_value_combination_id
1572          , x_value_segment_code       => l_adr_value_segment_code
1573          , p_side                     => 'NA'
1574          , p_override_seg_flag        => 'Y'
1575    );
1576 
1577    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
1578 
1579       xla_ae_lines_pkg.set_segment(
1580           p_to_segment_code         => 'GL_ACCOUNT'
1581         , p_segment_value           => l_segment
1582         , p_from_segment_code       => l_adr_value_segment_code
1583         , p_from_combination_id     => l_adr_value_combination_id
1584         , p_value_type_code         => l_adr_value_type_code
1585         , p_transaction_coa_id      => l_adr_transaction_coa_id
1586         , p_accounting_coa_id       => l_adr_accounting_coa_id
1587         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
1588         , p_flex_value_set_id       => l_adr_flex_value_set_id
1589         , p_adr_code                => 'FV_BE_RPR_TRX_DR_NATURAL_SEG'
1590         , p_adr_type_code           => 'S'
1591         , p_component_type          => l_component_type
1592         , p_component_code          => l_component_code
1593         , p_component_type_code     => l_component_type_code
1594         , p_component_appl_id       => l_component_appl_id
1595         , p_amb_context_code        => l_amb_context_code
1596         , p_entity_code             => 'BE_RPR_TRANSACTIONS'
1597         , p_event_class_code        => 'RPR_BUDGET_EXECUTION'
1598         , p_side                    => 'NA'
1599         );
1600 
1601   END IF;
1602 
1603    --
1604    --
1605    END IF;
1606    --
1607    -- Bug 4922099
1608    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
1609           (NVL(l_enc_upg_option, 'N') = 'O')
1610         ) AND
1611         (l_bflow_method_code = 'PRIOR_ENTRY')
1612       )
1613    THEN
1614       IF
1615       --
1616       1 = 2
1617       --
1618       THEN
1619       xla_accounting_err_pkg.build_message
1620                                     (p_appli_s_name            => 'XLA'
1621                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1622                                     ,p_token_1                 => 'LINE_NUMBER'
1623                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
1624                                     ,p_token_2                 => 'LINE_TYPE_NAME'
1625                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
1626                                                                              l_component_type
1630                                                                             ,l_amb_context_code
1627                                                                             ,l_component_code
1628                                                                             ,l_component_type_code
1629                                                                             ,l_component_appl_id
1631                                                                             ,l_entity_code
1632                                                                             ,l_event_class_code
1633                                                                            )
1634                                     ,p_token_3                 => 'OWNER'
1635                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
1636                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
1637                                                                           ,p_lookup_code    => l_component_type_code
1638                                                                          )
1639                                     ,p_token_4                 => 'PRODUCT_NAME'
1640                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
1641                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
1642                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
1643                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
1644                                     ,p_ae_header_id            =>  NULL
1645                                        );
1646 
1647         IF (C_LEVEL_ERROR>= g_log_level) THEN
1648                  trace
1649                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1650                       ,p_level    => C_LEVEL_ERROR
1651                       ,p_module   => l_log_module);
1652         END IF;
1653       END IF;
1654    END IF;
1655    --
1656    --
1657    ------------------------------------------------------------------------------------------------
1658    -- 4219869 Business Flow
1659    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
1660    -- Prior Entry.  Currently, the following code is always generated.
1661    ------------------------------------------------------------------------------------------------
1662    XLA_AE_LINES_PKG.ValidateCurrentLine;
1663 
1664    ------------------------------------------------------------------------------------
1665    -- 4219869 Business Flow
1666    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
1667    ------------------------------------------------------------------------------------
1668    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1669 
1670    ----------------------------------------------------------------------------------
1671    -- 4219869 Business Flow
1672    -- Update journal entry status -- Need to generate this within IF <condition>
1673    ----------------------------------------------------------------------------------
1674    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1675          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
1676          ,p_balance_type_code => l_balance_type_code
1677          );
1678 
1679    -------------------------------------------------------------------------------------------
1680    -- 4262811 - Generate the Accrual Reversal lines
1681    -------------------------------------------------------------------------------------------
1682    BEGIN
1683       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
1684                               (g_array_event(p_event_id).array_value_num('header_index'));
1685       IF l_acc_rev_flag IS NULL THEN
1686          l_acc_rev_flag := 'N';
1687       END IF;
1688    EXCEPTION
1689       WHEN OTHERS THEN
1690          l_acc_rev_flag := 'N';
1691    END;
1692    --
1693    IF (l_acc_rev_flag = 'Y') THEN
1694 
1695        -- 4645092  ------------------------------------------------------------------------------
1696        -- To allow MPA report to determine if it should generate report process
1697        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
1698        ------------------------------------------------------------------------------------------
1699 
1700        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
1701        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
1702 
1703        --
1704        -- Update the line information that should be overwritten
1705        --
1706        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
1707                                          p_header_num   => 1);
1708        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
1709 
1710        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
1711 
1712        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
1713           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
1714        END IF;
1715 
1716       --
1717       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
1718       --
1719       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
1720           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
1721       ELSE
1722           ---------------------------------------------------------------------------------------------------
1723           -- 4262811a Switch Sign
1724           ---------------------------------------------------------------------------------------------------
1728           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1725           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
1726           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1727                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1729                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1730           -- 5132302
1731           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
1732                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1733 
1734       END IF;
1735 
1736       -- 4955764
1737       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1738       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
1739 
1740 
1741       XLA_AE_LINES_PKG.ValidateCurrentLine;
1742       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1743 
1744       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1745                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
1746                ,p_balance_type_code => l_balance_type_code);
1747 
1748    END IF;
1749 
1750    -----------------------------------------------------------------------------------------
1751    -- 4262811 Multiperiod Accounting
1752    -----------------------------------------------------------------------------------------
1753      -- No MPA option is assigned.
1754 
1755 
1756 END IF;
1757 END IF;
1758 --
1759 
1760 --
1761 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1762    trace
1763       (p_msg      => 'END of AcctLineType_9'
1764       ,p_level    => C_LEVEL_PROCEDURE
1765       ,p_module   => l_log_module);
1766 END IF;
1767 --
1768 EXCEPTION
1769   WHEN xla_exceptions_pkg.application_exception THEN
1770       RAISE;
1771   WHEN OTHERS THEN
1772        xla_exceptions_pkg.raise_message
1773            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.AcctLineType_9');
1774 END AcctLineType_9;
1775 --
1776 
1777 ---------------------------------------
1778 --
1779 -- PRIVATE FUNCTION
1780 --         AcctLineType_10
1781 --
1782 ---------------------------------------
1783 PROCEDURE AcctLineType_10 (
1784   p_application_id        IN NUMBER
1785  ,p_event_id              IN NUMBER
1786  ,p_calculate_acctd_flag  IN VARCHAR2
1787  ,p_calculate_g_l_flag    IN VARCHAR2
1788  ,p_actual_flag           IN OUT VARCHAR2
1789  ,p_balance_type_code     OUT VARCHAR2
1790  ,p_gain_or_loss_ref      OUT VARCHAR2
1791  
1792 --DOC_NUMBER
1793  , p_source_1            IN VARCHAR2
1794 --BUDGET_LEVEL_ID
1795  , p_source_2            IN NUMBER
1796 --CR_ACCOUNT_SEGMENT_VALUE
1797  , p_source_3            IN VARCHAR2
1798 --DISTRIBUTION_FROM_ACCOUNT
1799  , p_source_6            IN NUMBER
1800 --SOURCE
1801  , p_source_10            IN VARCHAR2
1802 --TRANSACTION_ID
1803  , p_source_11            IN NUMBER
1804 --TRANSACTION_TYPE
1805  , p_source_12            IN VARCHAR2
1806 --TRANSACTION_TYPE_ID
1807  , p_source_13            IN NUMBER
1808 --Accounted Amount
1809  , p_source_14            IN NUMBER
1810 --CURRENCY_CODE
1811  , p_source_15            IN VARCHAR2
1812 )
1813 IS
1814 
1815 l_component_type              VARCHAR2(80);
1816 l_component_code              VARCHAR2(30);
1817 l_component_type_code         VARCHAR2(1);
1818 l_component_appl_id           INTEGER;
1819 l_amb_context_code            VARCHAR2(30);
1820 l_entity_code                 VARCHAR2(30);
1821 l_event_class_code            VARCHAR2(30);
1822 l_ae_header_id                NUMBER;
1823 l_event_type_code             VARCHAR2(30);
1824 l_line_definition_code        VARCHAR2(30);
1825 l_line_definition_owner_code  VARCHAR2(1);
1826 --
1827 -- adr variables
1828 l_segment                     VARCHAR2(30);
1829 l_ccid                        NUMBER;
1830 l_adr_transaction_coa_id      NUMBER;
1831 l_adr_accounting_coa_id       NUMBER;
1832 l_adr_flexfield_segment_code  VARCHAR2(30);
1833 l_adr_flex_value_set_id       NUMBER;
1834 l_adr_value_type_code         VARCHAR2(30);
1835 l_adr_value_combination_id    NUMBER;
1836 l_adr_value_segment_code      VARCHAR2(30);
1837 
1838 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
1839 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
1840 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
1841 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
1842 
1843 -- 4262811 Variables ------------------------------------------------------------------------------------------
1844 l_entered_amt_idx             NUMBER;
1845 l_accted_amt_idx              NUMBER;
1846 l_acc_rev_flag                VARCHAR2(1);
1847 l_accrual_line_num            NUMBER;
1848 l_tmp_amt                     NUMBER;
1849 l_acc_rev_natural_side_code   VARCHAR2(1);
1850 
1851 l_num_entries                 NUMBER;
1852 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
1853 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
1854 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
1855 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
1856 l_recog_line_1                NUMBER;
1857 l_recog_line_2                NUMBER;
1858 
1859 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
1860 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
1864 
1861 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
1862 
1863 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
1865 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
1866 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
1867 
1868 ---------------------------------------------------------------------------------------------------------------
1869 
1870 
1871 --
1872 -- bulk performance
1873 --
1874 l_balance_type_code           VARCHAR2(1);
1875 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
1876 l_log_module                  VARCHAR2(240);
1877 
1878 --
1879 -- Upgrade strategy
1880 --
1881 l_actual_upg_option           VARCHAR2(1);
1882 l_enc_upg_option           VARCHAR2(1);
1883 
1884 --
1885 BEGIN
1886 --
1887 IF g_log_enabled THEN
1888       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_10';
1889 END IF;
1890 --
1891 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1892 
1893       trace
1894          (p_msg      => 'BEGIN of AcctLineType_10'
1895          ,p_level    => C_LEVEL_PROCEDURE
1896          ,p_module   => l_log_module);
1897 
1898 END IF;
1899 --
1900 l_component_type             := 'AMB_JLT';
1901 l_component_code             := 'FV_BE_RPR_FROM_TRX_DR';
1902 l_component_type_code        := 'S';
1903 l_component_appl_id          :=  8901;
1904 l_amb_context_code           := 'DEFAULT';
1905 l_entity_code                := 'BE_RPR_TRANSACTIONS';
1906 l_event_class_code           := 'RPR_BUDGET_EXECUTION';
1907 l_event_type_code            := 'RPR_BUDGET_EXECUTION_ALL';
1908 l_line_definition_owner_code := 'S';
1909 l_line_definition_code       := 'FV_BE_RPR_TRX_JLD';
1910 --
1911 l_balance_type_code          := 'A';
1912 l_segment                     := NULL;
1913 l_ccid                        := NULL;
1914 l_adr_transaction_coa_id      := NULL;
1915 l_adr_accounting_coa_id       := NULL;
1916 l_adr_flexfield_segment_code  := NULL;
1917 l_adr_flex_value_set_id       := NULL;
1918 l_adr_value_type_code         := NULL;
1919 l_adr_value_combination_id    := NULL;
1920 l_adr_value_segment_code      := NULL;
1921 
1922 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
1923 l_bflow_class_code           := '';    -- 4219869 Business Flow
1924 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
1925 l_budgetary_control_flag     := 'Y';
1926 
1927 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
1928 l_bflow_applied_to_amt       := NULL; -- 5132302
1929 l_entered_amt_idx            := NULL;          -- 4262811
1930 l_accted_amt_idx             := NULL;          -- 4262811
1931 l_acc_rev_flag               := NULL;          -- 4262811
1932 l_accrual_line_num           := NULL;          -- 4262811
1933 l_tmp_amt                    := NULL;          -- 4262811
1934 --
1935  
1936 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
1937     l_balance_type_code <> 'B' THEN
1938 IF (p_source_2  >=  1 AND 
1939 NVL(p_source_10,'
1940 ')  =  'RPR')
1941  THEN 
1942 
1943    --
1944    XLA_AE_LINES_PKG.SetNewLine;
1945 
1946    p_balance_type_code          := l_balance_type_code;
1947    -- set the flag so later we will know whether the gain loss line needs to be created
1948    
1949    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
1950      p_actual_flag :='A';
1951    END IF;
1952 
1953    --
1954    -- bulk performance
1955    --
1956    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
1957                                       p_header_num   => 0); -- 4262811
1958    --
1959    -- set accounting line options
1960    --
1961    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
1962            p_natural_side_code          => 'D'
1963          , p_gain_or_loss_flag          => 'N'
1964          , p_gl_transfer_mode_code      => 'S'
1965          , p_acct_entry_type_code       => 'A'
1966          , p_switch_side_flag           => 'N'
1967          , p_merge_duplicate_code       => 'N'
1968          );
1969    --
1970    l_acc_rev_natural_side_code := 'C';  -- 4262811
1971    -- 
1972    --
1973    -- set accounting line type info
1974    --
1975    xla_ae_lines_pkg.SetAcctLineType
1976       (p_component_type             => l_component_type
1977       ,p_event_type_code            => l_event_type_code
1978       ,p_line_definition_owner_code => l_line_definition_owner_code
1979       ,p_line_definition_code       => l_line_definition_code
1980       ,p_accounting_line_code       => l_component_code
1981       ,p_accounting_line_type_code  => l_component_type_code
1982       ,p_accounting_line_appl_id    => l_component_appl_id
1983       ,p_amb_context_code           => l_amb_context_code
1984       ,p_entity_code                => l_entity_code
1985       ,p_event_class_code           => l_event_class_code);
1986    --
1987    -- set accounting class
1988    --
1989    xla_ae_lines_pkg.SetAcctClass(
1990            p_accounting_class_code  => 'BE_RESERVE_DR'
1991          , p_ae_header_id           => l_ae_header_id
1992          );
1993 
1994    --
1995    -- set rounding class
1996    --
1997    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
1998                       'BE_RESERVE_DR';
1999 
2000    --
2001    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
2005    --
2002    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
2003    --
2004    -- bulk performance
2006    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
2007 
2008    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
2009       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
2010 
2011    -- 4955764
2012    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2013       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
2014 
2015    -- 4458381 Public Sector Enh
2016    
2017    --
2018    -- set accounting attributes for the line type
2019    --
2020    l_entered_amt_idx := 4;
2021    l_accted_amt_idx  := 6;
2022    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
2023    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
2024    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_11);
2025    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
2026    l_rec_acct_attrs.array_char_value(2)  := p_source_12;
2027    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
2028    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_13);
2029    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
2030    l_rec_acct_attrs.array_num_value(4)  := p_source_14;
2031    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
2032    l_rec_acct_attrs.array_char_value(5)  := p_source_15;
2033    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
2034    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
2035 
2036    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
2037    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
2038 
2039    ---------------------------------------------------------------------------------------------------------------
2040    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
2041    ---------------------------------------------------------------------------------------------------------------
2042    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
2043 
2044    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2045    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2046 
2047    IF xla_accounting_cache_pkg.GetValueChar
2048          (p_source_code         => 'LEDGER_CATEGORY_CODE'
2049          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
2050    AND l_bflow_method_code = 'PRIOR_ENTRY'
2051 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
2052    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
2053          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
2054        )
2055    THEN
2056          xla_ae_lines_pkg.BflowUpgEntry
2057            (p_business_method_code    => l_bflow_method_code
2058            ,p_business_class_code     => l_bflow_class_code
2059            ,p_balance_type            => l_balance_type_code);
2060    ELSE
2061       NULL;
2062 -- No business flow processing for business flow method of NONE.
2063    END IF;
2064 
2065    --
2066    -- call description
2067    --
2068    
2069 xla_ae_lines_pkg.SetLineDescription(
2070    p_ae_header_id => l_ae_header_id
2071   ,p_description  => Description_1 (
2072      p_application_id         => p_application_id
2073    , p_ae_header_id           => l_ae_header_id 
2074 , p_source_1 => p_source_1
2075 , p_source_2 => p_source_2
2076    )
2077 );
2078 
2079 
2080    --
2081    -- call ADRs
2082    -- Bug 4922099
2083    --
2084    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
2085         (NVL(l_actual_upg_option, 'N') = 'O') OR
2086         (NVL(l_enc_upg_option, 'N') = 'O')
2087       )
2088    THEN
2089    NULL;
2090    --
2091    --
2092    
2093   l_ccid := AcctDerRule_6(
2094            p_application_id           => p_application_id
2095          , p_ae_header_id             => l_ae_header_id 
2096 , p_source_6 => p_source_6
2097          , x_transaction_coa_id       => l_adr_transaction_coa_id
2098          , x_accounting_coa_id        => l_adr_accounting_coa_id
2099          , x_value_type_code          => l_adr_value_type_code
2100          , p_side                     => 'NA'
2101    );
2102 
2103    xla_ae_lines_pkg.set_ccid(
2104     p_code_combination_id          => l_ccid
2105   , p_value_type_code              => l_adr_value_type_code
2106   , p_transaction_coa_id           => l_adr_transaction_coa_id
2107   , p_accounting_coa_id            => l_adr_accounting_coa_id
2108   , p_adr_code                     => 'FV_BE_RPR_FROM_TRX_CCID'
2109   , p_adr_type_code                => 'S'
2110   , p_component_type               => l_component_type
2111   , p_component_code               => l_component_code
2112   , p_component_type_code          => l_component_type_code
2113   , p_component_appl_id            => l_component_appl_id
2114   , p_amb_context_code             => l_amb_context_code
2115   , p_side                         => 'NA'
2116   );
2117 
2118 
2119    l_segment := AcctDerRule_2(
2120            p_application_id           => p_application_id
2121          , p_ae_header_id             => l_ae_header_id 
2122 , p_source_3 => p_source_3
2123          , x_transaction_coa_id       => l_adr_transaction_coa_id
2124          , x_accounting_coa_id        => l_adr_accounting_coa_id
2125          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
2126          , x_flex_value_set_id        => l_adr_flex_value_set_id
2127          , x_value_type_code          => l_adr_value_type_code
2131          , p_override_seg_flag        => 'Y'
2128          , x_value_combination_id     => l_adr_value_combination_id
2129          , x_value_segment_code       => l_adr_value_segment_code
2130          , p_side                     => 'NA'
2132    );
2133 
2134    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
2135 
2136       xla_ae_lines_pkg.set_segment(
2137           p_to_segment_code         => 'GL_ACCOUNT'
2138         , p_segment_value           => l_segment
2139         , p_from_segment_code       => l_adr_value_segment_code
2140         , p_from_combination_id     => l_adr_value_combination_id
2141         , p_value_type_code         => l_adr_value_type_code
2142         , p_transaction_coa_id      => l_adr_transaction_coa_id
2143         , p_accounting_coa_id       => l_adr_accounting_coa_id
2144         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
2145         , p_flex_value_set_id       => l_adr_flex_value_set_id
2146         , p_adr_code                => 'FV_BE_RPR_TRX_CR_NATURAL_SEG'
2147         , p_adr_type_code           => 'S'
2148         , p_component_type          => l_component_type
2149         , p_component_code          => l_component_code
2150         , p_component_type_code     => l_component_type_code
2151         , p_component_appl_id       => l_component_appl_id
2152         , p_amb_context_code        => l_amb_context_code
2153         , p_entity_code             => 'BE_RPR_TRANSACTIONS'
2154         , p_event_class_code        => 'RPR_BUDGET_EXECUTION'
2155         , p_side                    => 'NA'
2156         );
2157 
2158   END IF;
2159 
2160    --
2161    --
2162    END IF;
2163    --
2164    -- Bug 4922099
2165    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
2166           (NVL(l_enc_upg_option, 'N') = 'O')
2167         ) AND
2168         (l_bflow_method_code = 'PRIOR_ENTRY')
2169       )
2170    THEN
2171       IF
2172       --
2173       1 = 2
2174       --
2175       THEN
2176       xla_accounting_err_pkg.build_message
2177                                     (p_appli_s_name            => 'XLA'
2178                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2179                                     ,p_token_1                 => 'LINE_NUMBER'
2180                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
2181                                     ,p_token_2                 => 'LINE_TYPE_NAME'
2182                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
2183                                                                              l_component_type
2184                                                                             ,l_component_code
2185                                                                             ,l_component_type_code
2186                                                                             ,l_component_appl_id
2187                                                                             ,l_amb_context_code
2188                                                                             ,l_entity_code
2189                                                                             ,l_event_class_code
2190                                                                            )
2191                                     ,p_token_3                 => 'OWNER'
2192                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
2193                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
2194                                                                           ,p_lookup_code    => l_component_type_code
2195                                                                          )
2196                                     ,p_token_4                 => 'PRODUCT_NAME'
2197                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
2198                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
2199                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
2200                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
2201                                     ,p_ae_header_id            =>  NULL
2202                                        );
2203 
2204         IF (C_LEVEL_ERROR>= g_log_level) THEN
2205                  trace
2206                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2207                       ,p_level    => C_LEVEL_ERROR
2208                       ,p_module   => l_log_module);
2209         END IF;
2210       END IF;
2211    END IF;
2212    --
2213    --
2214    ------------------------------------------------------------------------------------------------
2215    -- 4219869 Business Flow
2216    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
2217    -- Prior Entry.  Currently, the following code is always generated.
2218    ------------------------------------------------------------------------------------------------
2219    XLA_AE_LINES_PKG.ValidateCurrentLine;
2220 
2221    ------------------------------------------------------------------------------------
2222    -- 4219869 Business Flow
2223    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
2224    ------------------------------------------------------------------------------------
2225    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2226 
2227    ----------------------------------------------------------------------------------
2228    -- 4219869 Business Flow
2229    -- Update journal entry status -- Need to generate this within IF <condition>
2230    ----------------------------------------------------------------------------------
2231    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2235 
2232          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
2233          ,p_balance_type_code => l_balance_type_code
2234          );
2236    -------------------------------------------------------------------------------------------
2237    -- 4262811 - Generate the Accrual Reversal lines
2238    -------------------------------------------------------------------------------------------
2239    BEGIN
2240       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
2241                               (g_array_event(p_event_id).array_value_num('header_index'));
2242       IF l_acc_rev_flag IS NULL THEN
2243          l_acc_rev_flag := 'N';
2244       END IF;
2245    EXCEPTION
2246       WHEN OTHERS THEN
2247          l_acc_rev_flag := 'N';
2248    END;
2249    --
2250    IF (l_acc_rev_flag = 'Y') THEN
2251 
2252        -- 4645092  ------------------------------------------------------------------------------
2253        -- To allow MPA report to determine if it should generate report process
2254        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
2255        ------------------------------------------------------------------------------------------
2256 
2257        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
2258        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
2259 
2260        --
2261        -- Update the line information that should be overwritten
2262        --
2263        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
2264                                          p_header_num   => 1);
2265        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
2266 
2267        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
2268 
2269        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
2270           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
2271        END IF;
2272 
2273       --
2274       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
2275       --
2276       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
2277           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
2278       ELSE
2279           ---------------------------------------------------------------------------------------------------
2280           -- 4262811a Switch Sign
2281           ---------------------------------------------------------------------------------------------------
2282           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
2283           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2284                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2285           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2286                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2287           -- 5132302
2288           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
2289                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2290 
2291       END IF;
2292 
2293       -- 4955764
2294       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2295       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
2296 
2297 
2298       XLA_AE_LINES_PKG.ValidateCurrentLine;
2299       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2300 
2301       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2302                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
2303                ,p_balance_type_code => l_balance_type_code);
2304 
2305    END IF;
2306 
2307    -----------------------------------------------------------------------------------------
2308    -- 4262811 Multiperiod Accounting
2309    -----------------------------------------------------------------------------------------
2310      -- No MPA option is assigned.
2311 
2312 
2313 END IF;
2314 END IF;
2315 --
2316 
2317 --
2318 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2319    trace
2320       (p_msg      => 'END of AcctLineType_10'
2321       ,p_level    => C_LEVEL_PROCEDURE
2322       ,p_module   => l_log_module);
2323 END IF;
2324 --
2325 EXCEPTION
2326   WHEN xla_exceptions_pkg.application_exception THEN
2327       RAISE;
2328   WHEN OTHERS THEN
2329        xla_exceptions_pkg.raise_message
2330            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.AcctLineType_10');
2331 END AcctLineType_10;
2332 --
2333 
2334 ---------------------------------------
2335 --
2336 -- PRIVATE FUNCTION
2337 --         AcctLineType_11
2338 --
2339 ---------------------------------------
2340 PROCEDURE AcctLineType_11 (
2341   p_application_id        IN NUMBER
2342  ,p_event_id              IN NUMBER
2343  ,p_calculate_acctd_flag  IN VARCHAR2
2344  ,p_calculate_g_l_flag    IN VARCHAR2
2345  ,p_actual_flag           IN OUT VARCHAR2
2346  ,p_balance_type_code     OUT VARCHAR2
2347  ,p_gain_or_loss_ref      OUT VARCHAR2
2348  
2349 --DOC_NUMBER
2350  , p_source_1            IN VARCHAR2
2351 --BUDGET_LEVEL_ID
2352  , p_source_2            IN NUMBER
2353 --CR_ACCOUNT_SEGMENT_VALUE
2354  , p_source_3            IN VARCHAR2
2355 --DISTRIBUTION_TO_ACCOUNT
2356  , p_source_7            IN NUMBER
2357 --SOURCE
2358  , p_source_10            IN VARCHAR2
2359 --TRANSACTION_ID
2360  , p_source_11            IN NUMBER
2361 --TRANSACTION_TYPE
2365 --Accounted Amount
2362  , p_source_12            IN VARCHAR2
2363 --TRANSACTION_TYPE_ID
2364  , p_source_13            IN NUMBER
2366  , p_source_14            IN NUMBER
2367 --CURRENCY_CODE
2368  , p_source_15            IN VARCHAR2
2369 )
2370 IS
2371 
2372 l_component_type              VARCHAR2(80);
2373 l_component_code              VARCHAR2(30);
2374 l_component_type_code         VARCHAR2(1);
2375 l_component_appl_id           INTEGER;
2376 l_amb_context_code            VARCHAR2(30);
2377 l_entity_code                 VARCHAR2(30);
2378 l_event_class_code            VARCHAR2(30);
2379 l_ae_header_id                NUMBER;
2380 l_event_type_code             VARCHAR2(30);
2381 l_line_definition_code        VARCHAR2(30);
2382 l_line_definition_owner_code  VARCHAR2(1);
2383 --
2384 -- adr variables
2385 l_segment                     VARCHAR2(30);
2386 l_ccid                        NUMBER;
2387 l_adr_transaction_coa_id      NUMBER;
2388 l_adr_accounting_coa_id       NUMBER;
2389 l_adr_flexfield_segment_code  VARCHAR2(30);
2390 l_adr_flex_value_set_id       NUMBER;
2391 l_adr_value_type_code         VARCHAR2(30);
2392 l_adr_value_combination_id    NUMBER;
2393 l_adr_value_segment_code      VARCHAR2(30);
2394 
2395 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
2396 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
2397 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
2398 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
2399 
2400 -- 4262811 Variables ------------------------------------------------------------------------------------------
2401 l_entered_amt_idx             NUMBER;
2402 l_accted_amt_idx              NUMBER;
2403 l_acc_rev_flag                VARCHAR2(1);
2404 l_accrual_line_num            NUMBER;
2405 l_tmp_amt                     NUMBER;
2406 l_acc_rev_natural_side_code   VARCHAR2(1);
2407 
2408 l_num_entries                 NUMBER;
2409 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
2410 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
2411 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
2412 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
2413 l_recog_line_1                NUMBER;
2414 l_recog_line_2                NUMBER;
2415 
2416 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
2417 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
2418 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
2419 
2420 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
2421 
2422 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
2423 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
2424 
2425 ---------------------------------------------------------------------------------------------------------------
2426 
2427 
2428 --
2429 -- bulk performance
2430 --
2431 l_balance_type_code           VARCHAR2(1);
2432 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
2433 l_log_module                  VARCHAR2(240);
2434 
2435 --
2436 -- Upgrade strategy
2437 --
2438 l_actual_upg_option           VARCHAR2(1);
2439 l_enc_upg_option           VARCHAR2(1);
2440 
2441 --
2442 BEGIN
2443 --
2444 IF g_log_enabled THEN
2445       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_11';
2446 END IF;
2447 --
2448 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2449 
2450       trace
2451          (p_msg      => 'BEGIN of AcctLineType_11'
2452          ,p_level    => C_LEVEL_PROCEDURE
2453          ,p_module   => l_log_module);
2454 
2455 END IF;
2456 --
2457 l_component_type             := 'AMB_JLT';
2458 l_component_code             := 'FV_BE_RPR_TO_TRX_CR';
2459 l_component_type_code        := 'S';
2460 l_component_appl_id          :=  8901;
2461 l_amb_context_code           := 'DEFAULT';
2462 l_entity_code                := 'BE_RPR_TRANSACTIONS';
2463 l_event_class_code           := 'RPR_BUDGET_EXECUTION';
2464 l_event_type_code            := 'RPR_BUDGET_EXECUTION_ALL';
2465 l_line_definition_owner_code := 'S';
2466 l_line_definition_code       := 'FV_BE_RPR_TRX_JLD';
2467 --
2468 l_balance_type_code          := 'A';
2469 l_segment                     := NULL;
2470 l_ccid                        := NULL;
2471 l_adr_transaction_coa_id      := NULL;
2472 l_adr_accounting_coa_id       := NULL;
2473 l_adr_flexfield_segment_code  := NULL;
2474 l_adr_flex_value_set_id       := NULL;
2475 l_adr_value_type_code         := NULL;
2476 l_adr_value_combination_id    := NULL;
2477 l_adr_value_segment_code      := NULL;
2478 
2479 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
2480 l_bflow_class_code           := '';    -- 4219869 Business Flow
2481 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
2482 l_budgetary_control_flag     := 'Y';
2483 
2484 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
2485 l_bflow_applied_to_amt       := NULL; -- 5132302
2486 l_entered_amt_idx            := NULL;          -- 4262811
2487 l_accted_amt_idx             := NULL;          -- 4262811
2488 l_acc_rev_flag               := NULL;          -- 4262811
2489 l_accrual_line_num           := NULL;          -- 4262811
2490 l_tmp_amt                    := NULL;          -- 4262811
2491 --
2492  
2493 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
2494     l_balance_type_code <> 'B' THEN
2495 IF (p_source_2  >=  1 AND 
2496 NVL(p_source_10,'
2497 ')  =  'RPR')
2498  THEN 
2499 
2500    --
2501    XLA_AE_LINES_PKG.SetNewLine;
2502 
2503    p_balance_type_code          := l_balance_type_code;
2507      p_actual_flag :='A';
2504    -- set the flag so later we will know whether the gain loss line needs to be created
2505    
2506    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
2508    END IF;
2509 
2510    --
2511    -- bulk performance
2512    --
2513    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
2514                                       p_header_num   => 0); -- 4262811
2515    --
2516    -- set accounting line options
2517    --
2518    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
2519            p_natural_side_code          => 'C'
2520          , p_gain_or_loss_flag          => 'N'
2521          , p_gl_transfer_mode_code      => 'S'
2522          , p_acct_entry_type_code       => 'A'
2523          , p_switch_side_flag           => 'N'
2524          , p_merge_duplicate_code       => 'N'
2525          );
2526    --
2527    l_acc_rev_natural_side_code := 'D';  -- 4262811
2528    -- 
2529    --
2530    -- set accounting line type info
2531    --
2532    xla_ae_lines_pkg.SetAcctLineType
2533       (p_component_type             => l_component_type
2534       ,p_event_type_code            => l_event_type_code
2535       ,p_line_definition_owner_code => l_line_definition_owner_code
2536       ,p_line_definition_code       => l_line_definition_code
2537       ,p_accounting_line_code       => l_component_code
2538       ,p_accounting_line_type_code  => l_component_type_code
2539       ,p_accounting_line_appl_id    => l_component_appl_id
2540       ,p_amb_context_code           => l_amb_context_code
2541       ,p_entity_code                => l_entity_code
2542       ,p_event_class_code           => l_event_class_code);
2543    --
2544    -- set accounting class
2545    --
2546    xla_ae_lines_pkg.SetAcctClass(
2547            p_accounting_class_code  => 'BE_RESERVE_CR'
2548          , p_ae_header_id           => l_ae_header_id
2549          );
2550 
2551    --
2552    -- set rounding class
2553    --
2554    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
2555                       'BE_RESERVE_CR';
2556 
2557    --
2558    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
2559    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
2560    --
2561    -- bulk performance
2562    --
2563    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
2564 
2565    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
2566       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
2567 
2568    -- 4955764
2569    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2570       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
2571 
2572    -- 4458381 Public Sector Enh
2573    
2574    --
2575    -- set accounting attributes for the line type
2576    --
2577    l_entered_amt_idx := 4;
2578    l_accted_amt_idx  := 6;
2579    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
2580    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
2581    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_11);
2582    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
2583    l_rec_acct_attrs.array_char_value(2)  := p_source_12;
2584    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
2585    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_13);
2586    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
2587    l_rec_acct_attrs.array_num_value(4)  := p_source_14;
2588    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
2589    l_rec_acct_attrs.array_char_value(5)  := p_source_15;
2590    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
2591    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
2592 
2593    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
2594    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
2595 
2596    ---------------------------------------------------------------------------------------------------------------
2597    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
2598    ---------------------------------------------------------------------------------------------------------------
2599    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
2600 
2601    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2602    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2603 
2604    IF xla_accounting_cache_pkg.GetValueChar
2605          (p_source_code         => 'LEDGER_CATEGORY_CODE'
2606          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
2607    AND l_bflow_method_code = 'PRIOR_ENTRY'
2608 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
2609    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
2610          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
2611        )
2612    THEN
2613          xla_ae_lines_pkg.BflowUpgEntry
2614            (p_business_method_code    => l_bflow_method_code
2615            ,p_business_class_code     => l_bflow_class_code
2616            ,p_balance_type            => l_balance_type_code);
2617    ELSE
2618       NULL;
2619 -- No business flow processing for business flow method of NONE.
2620    END IF;
2621 
2622    --
2623    -- call description
2624    --
2625    
2626 xla_ae_lines_pkg.SetLineDescription(
2627    p_ae_header_id => l_ae_header_id
2628   ,p_description  => Description_1 (
2632 , p_source_2 => p_source_2
2629      p_application_id         => p_application_id
2630    , p_ae_header_id           => l_ae_header_id 
2631 , p_source_1 => p_source_1
2633    )
2634 );
2635 
2636 
2637    --
2638    -- call ADRs
2639    -- Bug 4922099
2640    --
2641    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
2642         (NVL(l_actual_upg_option, 'N') = 'O') OR
2643         (NVL(l_enc_upg_option, 'N') = 'O')
2644       )
2645    THEN
2646    NULL;
2647    --
2648    --
2649    
2650   l_ccid := AcctDerRule_7(
2651            p_application_id           => p_application_id
2652          , p_ae_header_id             => l_ae_header_id 
2653 , p_source_7 => p_source_7
2654          , x_transaction_coa_id       => l_adr_transaction_coa_id
2655          , x_accounting_coa_id        => l_adr_accounting_coa_id
2656          , x_value_type_code          => l_adr_value_type_code
2657          , p_side                     => 'NA'
2658    );
2659 
2660    xla_ae_lines_pkg.set_ccid(
2661     p_code_combination_id          => l_ccid
2662   , p_value_type_code              => l_adr_value_type_code
2663   , p_transaction_coa_id           => l_adr_transaction_coa_id
2664   , p_accounting_coa_id            => l_adr_accounting_coa_id
2665   , p_adr_code                     => 'FV_BE_RPR_TO_TRX_CCID'
2666   , p_adr_type_code                => 'S'
2667   , p_component_type               => l_component_type
2668   , p_component_code               => l_component_code
2669   , p_component_type_code          => l_component_type_code
2670   , p_component_appl_id            => l_component_appl_id
2671   , p_amb_context_code             => l_amb_context_code
2672   , p_side                         => 'NA'
2673   );
2674 
2675 
2676    l_segment := AcctDerRule_2(
2677            p_application_id           => p_application_id
2678          , p_ae_header_id             => l_ae_header_id 
2679 , p_source_3 => p_source_3
2680          , x_transaction_coa_id       => l_adr_transaction_coa_id
2681          , x_accounting_coa_id        => l_adr_accounting_coa_id
2682          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
2683          , x_flex_value_set_id        => l_adr_flex_value_set_id
2684          , x_value_type_code          => l_adr_value_type_code
2685          , x_value_combination_id     => l_adr_value_combination_id
2686          , x_value_segment_code       => l_adr_value_segment_code
2687          , p_side                     => 'NA'
2688          , p_override_seg_flag        => 'Y'
2689    );
2690 
2691    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
2692 
2693       xla_ae_lines_pkg.set_segment(
2694           p_to_segment_code         => 'GL_ACCOUNT'
2695         , p_segment_value           => l_segment
2696         , p_from_segment_code       => l_adr_value_segment_code
2697         , p_from_combination_id     => l_adr_value_combination_id
2698         , p_value_type_code         => l_adr_value_type_code
2699         , p_transaction_coa_id      => l_adr_transaction_coa_id
2700         , p_accounting_coa_id       => l_adr_accounting_coa_id
2701         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
2702         , p_flex_value_set_id       => l_adr_flex_value_set_id
2703         , p_adr_code                => 'FV_BE_RPR_TRX_CR_NATURAL_SEG'
2704         , p_adr_type_code           => 'S'
2705         , p_component_type          => l_component_type
2706         , p_component_code          => l_component_code
2707         , p_component_type_code     => l_component_type_code
2708         , p_component_appl_id       => l_component_appl_id
2709         , p_amb_context_code        => l_amb_context_code
2710         , p_entity_code             => 'BE_RPR_TRANSACTIONS'
2711         , p_event_class_code        => 'RPR_BUDGET_EXECUTION'
2712         , p_side                    => 'NA'
2713         );
2714 
2715   END IF;
2716 
2717    --
2718    --
2719    END IF;
2720    --
2721    -- Bug 4922099
2722    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
2723           (NVL(l_enc_upg_option, 'N') = 'O')
2724         ) AND
2725         (l_bflow_method_code = 'PRIOR_ENTRY')
2726       )
2727    THEN
2728       IF
2729       --
2730       1 = 2
2731       --
2732       THEN
2733       xla_accounting_err_pkg.build_message
2734                                     (p_appli_s_name            => 'XLA'
2735                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2736                                     ,p_token_1                 => 'LINE_NUMBER'
2737                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
2738                                     ,p_token_2                 => 'LINE_TYPE_NAME'
2739                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
2740                                                                              l_component_type
2741                                                                             ,l_component_code
2742                                                                             ,l_component_type_code
2743                                                                             ,l_component_appl_id
2744                                                                             ,l_amb_context_code
2745                                                                             ,l_entity_code
2746                                                                             ,l_event_class_code
2747                                                                            )
2748                                     ,p_token_3                 => 'OWNER'
2749                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
2750                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
2754                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
2751                                                                           ,p_lookup_code    => l_component_type_code
2752                                                                          )
2753                                     ,p_token_4                 => 'PRODUCT_NAME'
2755                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
2756                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
2757                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
2758                                     ,p_ae_header_id            =>  NULL
2759                                        );
2760 
2761         IF (C_LEVEL_ERROR>= g_log_level) THEN
2762                  trace
2763                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2764                       ,p_level    => C_LEVEL_ERROR
2765                       ,p_module   => l_log_module);
2766         END IF;
2767       END IF;
2768    END IF;
2769    --
2770    --
2771    ------------------------------------------------------------------------------------------------
2772    -- 4219869 Business Flow
2773    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
2774    -- Prior Entry.  Currently, the following code is always generated.
2775    ------------------------------------------------------------------------------------------------
2776    XLA_AE_LINES_PKG.ValidateCurrentLine;
2777 
2778    ------------------------------------------------------------------------------------
2779    -- 4219869 Business Flow
2780    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
2781    ------------------------------------------------------------------------------------
2782    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2783 
2784    ----------------------------------------------------------------------------------
2785    -- 4219869 Business Flow
2786    -- Update journal entry status -- Need to generate this within IF <condition>
2787    ----------------------------------------------------------------------------------
2788    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2789          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
2790          ,p_balance_type_code => l_balance_type_code
2791          );
2792 
2793    -------------------------------------------------------------------------------------------
2794    -- 4262811 - Generate the Accrual Reversal lines
2795    -------------------------------------------------------------------------------------------
2796    BEGIN
2797       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
2798                               (g_array_event(p_event_id).array_value_num('header_index'));
2799       IF l_acc_rev_flag IS NULL THEN
2800          l_acc_rev_flag := 'N';
2801       END IF;
2802    EXCEPTION
2803       WHEN OTHERS THEN
2804          l_acc_rev_flag := 'N';
2805    END;
2806    --
2807    IF (l_acc_rev_flag = 'Y') THEN
2808 
2809        -- 4645092  ------------------------------------------------------------------------------
2810        -- To allow MPA report to determine if it should generate report process
2811        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
2812        ------------------------------------------------------------------------------------------
2813 
2814        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
2815        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
2816 
2817        --
2818        -- Update the line information that should be overwritten
2819        --
2820        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
2821                                          p_header_num   => 1);
2822        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
2823 
2824        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
2825 
2826        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
2827           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
2828        END IF;
2829 
2830       --
2831       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
2832       --
2833       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
2834           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
2835       ELSE
2836           ---------------------------------------------------------------------------------------------------
2837           -- 4262811a Switch Sign
2838           ---------------------------------------------------------------------------------------------------
2839           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
2840           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2841                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2842           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2843                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2844           -- 5132302
2845           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
2846                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2847 
2848       END IF;
2849 
2850       -- 4955764
2851       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2852       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
2853 
2857 
2854 
2855       XLA_AE_LINES_PKG.ValidateCurrentLine;
2856       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2858       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2859                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
2860                ,p_balance_type_code => l_balance_type_code);
2861 
2862    END IF;
2863 
2864    -----------------------------------------------------------------------------------------
2865    -- 4262811 Multiperiod Accounting
2866    -----------------------------------------------------------------------------------------
2867      -- No MPA option is assigned.
2868 
2869 
2870 END IF;
2871 END IF;
2872 --
2873 
2874 --
2875 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2876    trace
2877       (p_msg      => 'END of AcctLineType_11'
2878       ,p_level    => C_LEVEL_PROCEDURE
2879       ,p_module   => l_log_module);
2880 END IF;
2881 --
2882 EXCEPTION
2883   WHEN xla_exceptions_pkg.application_exception THEN
2884       RAISE;
2885   WHEN OTHERS THEN
2886        xla_exceptions_pkg.raise_message
2887            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.AcctLineType_11');
2888 END AcctLineType_11;
2889 --
2890 
2891 ---------------------------------------
2892 --
2893 -- PRIVATE FUNCTION
2894 --         AcctLineType_12
2895 --
2896 ---------------------------------------
2897 PROCEDURE AcctLineType_12 (
2898   p_application_id        IN NUMBER
2899  ,p_event_id              IN NUMBER
2900  ,p_calculate_acctd_flag  IN VARCHAR2
2901  ,p_calculate_g_l_flag    IN VARCHAR2
2902  ,p_actual_flag           IN OUT VARCHAR2
2903  ,p_balance_type_code     OUT VARCHAR2
2904  ,p_gain_or_loss_ref      OUT VARCHAR2
2905  
2906 --DOC_NUMBER
2907  , p_source_1            IN VARCHAR2
2908 --BUDGET_LEVEL_ID
2909  , p_source_2            IN NUMBER
2910 --DR_ACCOUNT_SEGMENT_VALUE
2911  , p_source_4            IN VARCHAR2
2912 --DISTRIBUTION_TO_ACCOUNT
2913  , p_source_7            IN NUMBER
2914 --SOURCE
2915  , p_source_10            IN VARCHAR2
2916 --TRANSACTION_ID
2917  , p_source_11            IN NUMBER
2918 --TRANSACTION_TYPE
2919  , p_source_12            IN VARCHAR2
2920 --TRANSACTION_TYPE_ID
2921  , p_source_13            IN NUMBER
2922 --Accounted Amount
2923  , p_source_14            IN NUMBER
2924 --CURRENCY_CODE
2925  , p_source_15            IN VARCHAR2
2926 )
2927 IS
2928 
2929 l_component_type              VARCHAR2(80);
2930 l_component_code              VARCHAR2(30);
2931 l_component_type_code         VARCHAR2(1);
2932 l_component_appl_id           INTEGER;
2933 l_amb_context_code            VARCHAR2(30);
2934 l_entity_code                 VARCHAR2(30);
2935 l_event_class_code            VARCHAR2(30);
2936 l_ae_header_id                NUMBER;
2937 l_event_type_code             VARCHAR2(30);
2938 l_line_definition_code        VARCHAR2(30);
2939 l_line_definition_owner_code  VARCHAR2(1);
2940 --
2941 -- adr variables
2942 l_segment                     VARCHAR2(30);
2943 l_ccid                        NUMBER;
2944 l_adr_transaction_coa_id      NUMBER;
2945 l_adr_accounting_coa_id       NUMBER;
2946 l_adr_flexfield_segment_code  VARCHAR2(30);
2947 l_adr_flex_value_set_id       NUMBER;
2948 l_adr_value_type_code         VARCHAR2(30);
2949 l_adr_value_combination_id    NUMBER;
2950 l_adr_value_segment_code      VARCHAR2(30);
2951 
2952 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
2953 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
2954 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
2955 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
2956 
2957 -- 4262811 Variables ------------------------------------------------------------------------------------------
2958 l_entered_amt_idx             NUMBER;
2959 l_accted_amt_idx              NUMBER;
2960 l_acc_rev_flag                VARCHAR2(1);
2961 l_accrual_line_num            NUMBER;
2962 l_tmp_amt                     NUMBER;
2963 l_acc_rev_natural_side_code   VARCHAR2(1);
2964 
2965 l_num_entries                 NUMBER;
2966 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
2967 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
2968 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
2969 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
2970 l_recog_line_1                NUMBER;
2971 l_recog_line_2                NUMBER;
2972 
2973 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
2974 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
2975 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
2976 
2977 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
2978 
2979 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
2980 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
2981 
2982 ---------------------------------------------------------------------------------------------------------------
2983 
2984 
2985 --
2986 -- bulk performance
2987 --
2988 l_balance_type_code           VARCHAR2(1);
2989 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
2990 l_log_module                  VARCHAR2(240);
2991 
2992 --
2993 -- Upgrade strategy
2994 --
2995 l_actual_upg_option           VARCHAR2(1);
2996 l_enc_upg_option           VARCHAR2(1);
2997 
2998 --
2999 BEGIN
3000 --
3001 IF g_log_enabled THEN
3002       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_12';
3003 END IF;
3004 --
3005 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3006 
3010          ,p_module   => l_log_module);
3007       trace
3008          (p_msg      => 'BEGIN of AcctLineType_12'
3009          ,p_level    => C_LEVEL_PROCEDURE
3011 
3012 END IF;
3013 --
3014 l_component_type             := 'AMB_JLT';
3015 l_component_code             := 'FV_BE_RPR_TO_TRX_DR';
3016 l_component_type_code        := 'S';
3017 l_component_appl_id          :=  8901;
3018 l_amb_context_code           := 'DEFAULT';
3019 l_entity_code                := 'BE_RPR_TRANSACTIONS';
3020 l_event_class_code           := 'RPR_BUDGET_EXECUTION';
3021 l_event_type_code            := 'RPR_BUDGET_EXECUTION_ALL';
3022 l_line_definition_owner_code := 'S';
3023 l_line_definition_code       := 'FV_BE_RPR_TRX_JLD';
3024 --
3025 l_balance_type_code          := 'A';
3026 l_segment                     := NULL;
3027 l_ccid                        := NULL;
3028 l_adr_transaction_coa_id      := NULL;
3029 l_adr_accounting_coa_id       := NULL;
3030 l_adr_flexfield_segment_code  := NULL;
3031 l_adr_flex_value_set_id       := NULL;
3032 l_adr_value_type_code         := NULL;
3033 l_adr_value_combination_id    := NULL;
3034 l_adr_value_segment_code      := NULL;
3035 
3036 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
3037 l_bflow_class_code           := '';    -- 4219869 Business Flow
3038 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
3039 l_budgetary_control_flag     := 'Y';
3040 
3041 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
3042 l_bflow_applied_to_amt       := NULL; -- 5132302
3043 l_entered_amt_idx            := NULL;          -- 4262811
3044 l_accted_amt_idx             := NULL;          -- 4262811
3045 l_acc_rev_flag               := NULL;          -- 4262811
3046 l_accrual_line_num           := NULL;          -- 4262811
3047 l_tmp_amt                    := NULL;          -- 4262811
3048 --
3049  
3050 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
3051     l_balance_type_code <> 'B' THEN
3052 IF (p_source_2  >=  1 AND 
3053 NVL(p_source_10,'
3054 ')  =  'RPR')
3055  THEN 
3056 
3057    --
3058    XLA_AE_LINES_PKG.SetNewLine;
3059 
3060    p_balance_type_code          := l_balance_type_code;
3061    -- set the flag so later we will know whether the gain loss line needs to be created
3062    
3063    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
3064      p_actual_flag :='A';
3065    END IF;
3066 
3067    --
3068    -- bulk performance
3069    --
3070    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
3071                                       p_header_num   => 0); -- 4262811
3072    --
3073    -- set accounting line options
3074    --
3075    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
3076            p_natural_side_code          => 'D'
3077          , p_gain_or_loss_flag          => 'N'
3078          , p_gl_transfer_mode_code      => 'S'
3079          , p_acct_entry_type_code       => 'A'
3080          , p_switch_side_flag           => 'N'
3081          , p_merge_duplicate_code       => 'N'
3082          );
3083    --
3084    l_acc_rev_natural_side_code := 'C';  -- 4262811
3085    -- 
3086    --
3087    -- set accounting line type info
3088    --
3089    xla_ae_lines_pkg.SetAcctLineType
3090       (p_component_type             => l_component_type
3091       ,p_event_type_code            => l_event_type_code
3092       ,p_line_definition_owner_code => l_line_definition_owner_code
3093       ,p_line_definition_code       => l_line_definition_code
3094       ,p_accounting_line_code       => l_component_code
3095       ,p_accounting_line_type_code  => l_component_type_code
3096       ,p_accounting_line_appl_id    => l_component_appl_id
3097       ,p_amb_context_code           => l_amb_context_code
3098       ,p_entity_code                => l_entity_code
3099       ,p_event_class_code           => l_event_class_code);
3100    --
3101    -- set accounting class
3102    --
3103    xla_ae_lines_pkg.SetAcctClass(
3104            p_accounting_class_code  => 'BE_RESERVE_DR'
3105          , p_ae_header_id           => l_ae_header_id
3106          );
3107 
3108    --
3109    -- set rounding class
3110    --
3111    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
3112                       'BE_RESERVE_DR';
3113 
3114    --
3115    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
3116    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
3117    --
3118    -- bulk performance
3119    --
3120    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
3121 
3122    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
3123       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
3124 
3125    -- 4955764
3126    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3127       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
3128 
3129    -- 4458381 Public Sector Enh
3130    
3131    --
3132    -- set accounting attributes for the line type
3133    --
3134    l_entered_amt_idx := 4;
3135    l_accted_amt_idx  := 6;
3136    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
3137    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
3138    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_11);
3139    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
3140    l_rec_acct_attrs.array_char_value(2)  := p_source_12;
3141    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
3142    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_13);
3146    l_rec_acct_attrs.array_char_value(5)  := p_source_15;
3143    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
3144    l_rec_acct_attrs.array_num_value(4)  := p_source_14;
3145    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
3147    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
3148    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
3149 
3150    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
3151    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
3152 
3153    ---------------------------------------------------------------------------------------------------------------
3154    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
3155    ---------------------------------------------------------------------------------------------------------------
3156    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
3157 
3158    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3159    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3160 
3161    IF xla_accounting_cache_pkg.GetValueChar
3162          (p_source_code         => 'LEDGER_CATEGORY_CODE'
3163          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
3164    AND l_bflow_method_code = 'PRIOR_ENTRY'
3165 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
3166    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
3167          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
3168        )
3169    THEN
3170          xla_ae_lines_pkg.BflowUpgEntry
3171            (p_business_method_code    => l_bflow_method_code
3172            ,p_business_class_code     => l_bflow_class_code
3173            ,p_balance_type            => l_balance_type_code);
3174    ELSE
3175       NULL;
3176 -- No business flow processing for business flow method of NONE.
3177    END IF;
3178 
3179    --
3180    -- call description
3181    --
3182    
3183 xla_ae_lines_pkg.SetLineDescription(
3184    p_ae_header_id => l_ae_header_id
3185   ,p_description  => Description_1 (
3186      p_application_id         => p_application_id
3187    , p_ae_header_id           => l_ae_header_id 
3188 , p_source_1 => p_source_1
3189 , p_source_2 => p_source_2
3190    )
3191 );
3192 
3193 
3194    --
3195    -- call ADRs
3196    -- Bug 4922099
3197    --
3198    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
3199         (NVL(l_actual_upg_option, 'N') = 'O') OR
3200         (NVL(l_enc_upg_option, 'N') = 'O')
3201       )
3202    THEN
3203    NULL;
3204    --
3205    --
3206    
3207   l_ccid := AcctDerRule_7(
3208            p_application_id           => p_application_id
3209          , p_ae_header_id             => l_ae_header_id 
3210 , p_source_7 => p_source_7
3211          , x_transaction_coa_id       => l_adr_transaction_coa_id
3212          , x_accounting_coa_id        => l_adr_accounting_coa_id
3213          , x_value_type_code          => l_adr_value_type_code
3214          , p_side                     => 'NA'
3215    );
3216 
3217    xla_ae_lines_pkg.set_ccid(
3218     p_code_combination_id          => l_ccid
3219   , p_value_type_code              => l_adr_value_type_code
3220   , p_transaction_coa_id           => l_adr_transaction_coa_id
3221   , p_accounting_coa_id            => l_adr_accounting_coa_id
3222   , p_adr_code                     => 'FV_BE_RPR_TO_TRX_CCID'
3223   , p_adr_type_code                => 'S'
3224   , p_component_type               => l_component_type
3225   , p_component_code               => l_component_code
3226   , p_component_type_code          => l_component_type_code
3227   , p_component_appl_id            => l_component_appl_id
3228   , p_amb_context_code             => l_amb_context_code
3229   , p_side                         => 'NA'
3230   );
3231 
3232 
3233    l_segment := AcctDerRule_3(
3234            p_application_id           => p_application_id
3235          , p_ae_header_id             => l_ae_header_id 
3236 , p_source_4 => p_source_4
3237          , x_transaction_coa_id       => l_adr_transaction_coa_id
3238          , x_accounting_coa_id        => l_adr_accounting_coa_id
3239          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
3240          , x_flex_value_set_id        => l_adr_flex_value_set_id
3241          , x_value_type_code          => l_adr_value_type_code
3242          , x_value_combination_id     => l_adr_value_combination_id
3243          , x_value_segment_code       => l_adr_value_segment_code
3244          , p_side                     => 'NA'
3245          , p_override_seg_flag        => 'Y'
3246    );
3247 
3248    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
3249 
3250       xla_ae_lines_pkg.set_segment(
3251           p_to_segment_code         => 'GL_ACCOUNT'
3252         , p_segment_value           => l_segment
3253         , p_from_segment_code       => l_adr_value_segment_code
3254         , p_from_combination_id     => l_adr_value_combination_id
3255         , p_value_type_code         => l_adr_value_type_code
3256         , p_transaction_coa_id      => l_adr_transaction_coa_id
3257         , p_accounting_coa_id       => l_adr_accounting_coa_id
3258         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
3259         , p_flex_value_set_id       => l_adr_flex_value_set_id
3260         , p_adr_code                => 'FV_BE_RPR_TRX_DR_NATURAL_SEG'
3261         , p_adr_type_code           => 'S'
3262         , p_component_type          => l_component_type
3263         , p_component_code          => l_component_code
3264         , p_component_type_code     => l_component_type_code
3265         , p_component_appl_id       => l_component_appl_id
3269         , p_side                    => 'NA'
3266         , p_amb_context_code        => l_amb_context_code
3267         , p_entity_code             => 'BE_RPR_TRANSACTIONS'
3268         , p_event_class_code        => 'RPR_BUDGET_EXECUTION'
3270         );
3271 
3272   END IF;
3273 
3274    --
3275    --
3276    END IF;
3277    --
3278    -- Bug 4922099
3279    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
3280           (NVL(l_enc_upg_option, 'N') = 'O')
3281         ) AND
3282         (l_bflow_method_code = 'PRIOR_ENTRY')
3283       )
3284    THEN
3285       IF
3286       --
3287       1 = 2
3288       --
3289       THEN
3290       xla_accounting_err_pkg.build_message
3291                                     (p_appli_s_name            => 'XLA'
3292                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3293                                     ,p_token_1                 => 'LINE_NUMBER'
3294                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
3295                                     ,p_token_2                 => 'LINE_TYPE_NAME'
3296                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
3297                                                                              l_component_type
3298                                                                             ,l_component_code
3299                                                                             ,l_component_type_code
3300                                                                             ,l_component_appl_id
3301                                                                             ,l_amb_context_code
3302                                                                             ,l_entity_code
3303                                                                             ,l_event_class_code
3304                                                                            )
3305                                     ,p_token_3                 => 'OWNER'
3306                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
3307                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
3308                                                                           ,p_lookup_code    => l_component_type_code
3309                                                                          )
3310                                     ,p_token_4                 => 'PRODUCT_NAME'
3311                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
3312                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
3313                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
3314                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
3315                                     ,p_ae_header_id            =>  NULL
3316                                        );
3317 
3318         IF (C_LEVEL_ERROR>= g_log_level) THEN
3319                  trace
3320                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3321                       ,p_level    => C_LEVEL_ERROR
3322                       ,p_module   => l_log_module);
3323         END IF;
3324       END IF;
3325    END IF;
3326    --
3327    --
3328    ------------------------------------------------------------------------------------------------
3329    -- 4219869 Business Flow
3330    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
3331    -- Prior Entry.  Currently, the following code is always generated.
3332    ------------------------------------------------------------------------------------------------
3333    XLA_AE_LINES_PKG.ValidateCurrentLine;
3334 
3335    ------------------------------------------------------------------------------------
3336    -- 4219869 Business Flow
3337    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
3338    ------------------------------------------------------------------------------------
3339    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3340 
3341    ----------------------------------------------------------------------------------
3342    -- 4219869 Business Flow
3343    -- Update journal entry status -- Need to generate this within IF <condition>
3344    ----------------------------------------------------------------------------------
3345    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3346          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
3347          ,p_balance_type_code => l_balance_type_code
3348          );
3349 
3350    -------------------------------------------------------------------------------------------
3351    -- 4262811 - Generate the Accrual Reversal lines
3352    -------------------------------------------------------------------------------------------
3353    BEGIN
3354       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
3355                               (g_array_event(p_event_id).array_value_num('header_index'));
3356       IF l_acc_rev_flag IS NULL THEN
3357          l_acc_rev_flag := 'N';
3358       END IF;
3359    EXCEPTION
3360       WHEN OTHERS THEN
3361          l_acc_rev_flag := 'N';
3362    END;
3363    --
3364    IF (l_acc_rev_flag = 'Y') THEN
3365 
3366        -- 4645092  ------------------------------------------------------------------------------
3367        -- To allow MPA report to determine if it should generate report process
3368        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
3369        ------------------------------------------------------------------------------------------
3370 
3371        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
3372        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
3373 
3374        --
3378                                          p_header_num   => 1);
3375        -- Update the line information that should be overwritten
3376        --
3377        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
3379        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
3380 
3381        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
3382 
3383        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
3384           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
3385        END IF;
3386 
3387       --
3388       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
3389       --
3390       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
3391           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
3392       ELSE
3393           ---------------------------------------------------------------------------------------------------
3394           -- 4262811a Switch Sign
3395           ---------------------------------------------------------------------------------------------------
3396           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
3397           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3398                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3399           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3400                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3401           -- 5132302
3402           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
3403                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3404 
3405       END IF;
3406 
3407       -- 4955764
3408       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3409       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
3410 
3411 
3412       XLA_AE_LINES_PKG.ValidateCurrentLine;
3413       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3414 
3415       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3416                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
3417                ,p_balance_type_code => l_balance_type_code);
3418 
3419    END IF;
3420 
3421    -----------------------------------------------------------------------------------------
3422    -- 4262811 Multiperiod Accounting
3423    -----------------------------------------------------------------------------------------
3424      -- No MPA option is assigned.
3425 
3426 
3427 END IF;
3428 END IF;
3429 --
3430 
3431 --
3432 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3433    trace
3434       (p_msg      => 'END of AcctLineType_12'
3435       ,p_level    => C_LEVEL_PROCEDURE
3436       ,p_module   => l_log_module);
3437 END IF;
3438 --
3439 EXCEPTION
3440   WHEN xla_exceptions_pkg.application_exception THEN
3441       RAISE;
3442   WHEN OTHERS THEN
3443        xla_exceptions_pkg.raise_message
3444            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.AcctLineType_12');
3445 END AcctLineType_12;
3446 --
3447 
3448 ---------------------------------------
3449 --
3450 -- PRIVATE FUNCTION
3451 --         AcctLineType_13
3452 --
3453 ---------------------------------------
3454 PROCEDURE AcctLineType_13 (
3455   p_application_id        IN NUMBER
3456  ,p_event_id              IN NUMBER
3457  ,p_calculate_acctd_flag  IN VARCHAR2
3458  ,p_calculate_g_l_flag    IN VARCHAR2
3459  ,p_actual_flag           IN OUT VARCHAR2
3460  ,p_balance_type_code     OUT VARCHAR2
3461  ,p_gain_or_loss_ref      OUT VARCHAR2
3462  
3463 --DOC_NUMBER
3464  , p_source_1            IN VARCHAR2
3465 --BUDGET_LEVEL_ID
3466  , p_source_2            IN NUMBER
3467 --CR_ACCOUNT_SEGMENT_VALUE
3468  , p_source_3            IN VARCHAR2
3469 --DR_ACCOUNT_SEGMENT_VALUE
3470  , p_source_4            IN VARCHAR2
3471 --INCREASE_DECREASE_FLAG
3472  , p_source_5            IN VARCHAR2
3473 --DISTRIBUTION_ACCOUNT
3474  , p_source_8            IN NUMBER
3475 --FUND_DISTRIBUTION_ACCOUNT
3476  , p_source_9            IN NUMBER
3477 --SOURCE
3478  , p_source_10            IN VARCHAR2
3479 --TRANSACTION_TYPE
3480  , p_source_12            IN VARCHAR2
3481 --TRANSACTION_TYPE_ID
3482  , p_source_13            IN NUMBER
3483 --Accounted Amount
3484  , p_source_14            IN NUMBER
3485 --CURRENCY_CODE
3486  , p_source_15            IN VARCHAR2
3487 --DOC_ID
3488  , p_source_16            IN NUMBER
3489 )
3490 IS
3491 
3492 l_component_type              VARCHAR2(80);
3493 l_component_code              VARCHAR2(30);
3494 l_component_type_code         VARCHAR2(1);
3495 l_component_appl_id           INTEGER;
3496 l_amb_context_code            VARCHAR2(30);
3497 l_entity_code                 VARCHAR2(30);
3498 l_event_class_code            VARCHAR2(30);
3499 l_ae_header_id                NUMBER;
3500 l_event_type_code             VARCHAR2(30);
3501 l_line_definition_code        VARCHAR2(30);
3502 l_line_definition_owner_code  VARCHAR2(1);
3503 --
3504 -- adr variables
3505 l_segment                     VARCHAR2(30);
3506 l_ccid                        NUMBER;
3507 l_adr_transaction_coa_id      NUMBER;
3508 l_adr_accounting_coa_id       NUMBER;
3512 l_adr_value_combination_id    NUMBER;
3509 l_adr_flexfield_segment_code  VARCHAR2(30);
3510 l_adr_flex_value_set_id       NUMBER;
3511 l_adr_value_type_code         VARCHAR2(30);
3513 l_adr_value_segment_code      VARCHAR2(30);
3514 
3515 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
3516 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
3517 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
3518 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
3519 
3520 -- 4262811 Variables ------------------------------------------------------------------------------------------
3521 l_entered_amt_idx             NUMBER;
3522 l_accted_amt_idx              NUMBER;
3523 l_acc_rev_flag                VARCHAR2(1);
3524 l_accrual_line_num            NUMBER;
3525 l_tmp_amt                     NUMBER;
3526 l_acc_rev_natural_side_code   VARCHAR2(1);
3527 
3528 l_num_entries                 NUMBER;
3529 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
3530 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
3531 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
3532 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
3533 l_recog_line_1                NUMBER;
3534 l_recog_line_2                NUMBER;
3535 
3536 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
3537 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
3538 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
3539 
3540 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
3541 
3542 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
3543 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
3544 
3545 ---------------------------------------------------------------------------------------------------------------
3546 
3547 
3548 --
3549 -- bulk performance
3550 --
3551 l_balance_type_code           VARCHAR2(1);
3552 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
3553 l_log_module                  VARCHAR2(240);
3554 
3555 --
3556 -- Upgrade strategy
3557 --
3558 l_actual_upg_option           VARCHAR2(1);
3559 l_enc_upg_option           VARCHAR2(1);
3560 
3561 --
3562 BEGIN
3563 --
3564 IF g_log_enabled THEN
3565       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_13';
3566 END IF;
3567 --
3568 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3569 
3570       trace
3571          (p_msg      => 'BEGIN of AcctLineType_13'
3572          ,p_level    => C_LEVEL_PROCEDURE
3573          ,p_module   => l_log_module);
3574 
3575 END IF;
3576 --
3577 l_component_type             := 'AMB_JLT';
3578 l_component_code             := 'FV_BE_TRX_CR';
3579 l_component_type_code        := 'S';
3580 l_component_appl_id          :=  8901;
3581 l_amb_context_code           := 'DEFAULT';
3582 l_entity_code                := 'BE_TRANSACTIONS';
3583 l_event_class_code           := 'BUDGET_EXECUTION';
3584 l_event_type_code            := 'BUDGET_EXECUTION_ALL';
3585 l_line_definition_owner_code := 'S';
3586 l_line_definition_code       := 'FV_BE_TRX_JLD';
3587 --
3588 l_balance_type_code          := 'A';
3589 l_segment                     := NULL;
3590 l_ccid                        := NULL;
3591 l_adr_transaction_coa_id      := NULL;
3592 l_adr_accounting_coa_id       := NULL;
3593 l_adr_flexfield_segment_code  := NULL;
3594 l_adr_flex_value_set_id       := NULL;
3595 l_adr_value_type_code         := NULL;
3596 l_adr_value_combination_id    := NULL;
3597 l_adr_value_segment_code      := NULL;
3598 
3599 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
3600 l_bflow_class_code           := '';    -- 4219869 Business Flow
3601 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
3602 l_budgetary_control_flag     := 'Y';
3603 
3604 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
3605 l_bflow_applied_to_amt       := NULL; -- 5132302
3606 l_entered_amt_idx            := NULL;          -- 4262811
3607 l_accted_amt_idx             := NULL;          -- 4262811
3608 l_acc_rev_flag               := NULL;          -- 4262811
3609 l_accrual_line_num           := NULL;          -- 4262811
3610 l_tmp_amt                    := NULL;          -- 4262811
3611 --
3612  
3613 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
3614     l_balance_type_code <> 'B' THEN
3615 IF (p_source_2  >=  1 AND 
3616 NVL(p_source_10,'
3617 ')  <>  'RPR')
3618  THEN 
3619 
3620    --
3621    XLA_AE_LINES_PKG.SetNewLine;
3622 
3623    p_balance_type_code          := l_balance_type_code;
3624    -- set the flag so later we will know whether the gain loss line needs to be created
3625    
3626    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
3627      p_actual_flag :='A';
3628    END IF;
3629 
3630    --
3631    -- bulk performance
3632    --
3633    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
3634                                       p_header_num   => 0); -- 4262811
3635    --
3636    -- set accounting line options
3637    --
3638    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
3639            p_natural_side_code          => 'C'
3640          , p_gain_or_loss_flag          => 'N'
3641          , p_gl_transfer_mode_code      => 'S'
3642          , p_acct_entry_type_code       => 'A'
3643          , p_switch_side_flag           => 'N'
3644          , p_merge_duplicate_code       => 'N'
3645          );
3649    --
3646    --
3647    l_acc_rev_natural_side_code := 'D';  -- 4262811
3648    -- 
3650    -- set accounting line type info
3651    --
3652    xla_ae_lines_pkg.SetAcctLineType
3653       (p_component_type             => l_component_type
3654       ,p_event_type_code            => l_event_type_code
3655       ,p_line_definition_owner_code => l_line_definition_owner_code
3656       ,p_line_definition_code       => l_line_definition_code
3657       ,p_accounting_line_code       => l_component_code
3658       ,p_accounting_line_type_code  => l_component_type_code
3659       ,p_accounting_line_appl_id    => l_component_appl_id
3660       ,p_amb_context_code           => l_amb_context_code
3661       ,p_entity_code                => l_entity_code
3662       ,p_event_class_code           => l_event_class_code);
3663    --
3664    -- set accounting class
3665    --
3666    xla_ae_lines_pkg.SetAcctClass(
3667            p_accounting_class_code  => 'BE_RESERVE_CR'
3668          , p_ae_header_id           => l_ae_header_id
3669          );
3670 
3671    --
3672    -- set rounding class
3673    --
3674    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
3675                       'BE_RESERVE_CR';
3676 
3677    --
3678    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
3679    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
3680    --
3681    -- bulk performance
3682    --
3683    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
3684 
3685    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
3686       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
3687 
3688    -- 4955764
3689    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3690       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
3691 
3692    -- 4458381 Public Sector Enh
3693    
3694    --
3695    -- set accounting attributes for the line type
3696    --
3697    l_entered_amt_idx := 4;
3698    l_accted_amt_idx  := 6;
3699    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
3700    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
3701    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_16);
3702    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
3703    l_rec_acct_attrs.array_char_value(2)  := p_source_12;
3704    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
3705    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_13);
3706    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
3707    l_rec_acct_attrs.array_num_value(4)  := p_source_14;
3708    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
3709    l_rec_acct_attrs.array_char_value(5)  := p_source_15;
3710    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
3711    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
3712 
3713    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
3714    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
3715 
3716    ---------------------------------------------------------------------------------------------------------------
3717    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
3718    ---------------------------------------------------------------------------------------------------------------
3719    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
3720 
3721    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3722    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3723 
3724    IF xla_accounting_cache_pkg.GetValueChar
3725          (p_source_code         => 'LEDGER_CATEGORY_CODE'
3726          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
3727    AND l_bflow_method_code = 'PRIOR_ENTRY'
3728 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
3729    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
3730          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
3731        )
3732    THEN
3733          xla_ae_lines_pkg.BflowUpgEntry
3734            (p_business_method_code    => l_bflow_method_code
3735            ,p_business_class_code     => l_bflow_class_code
3736            ,p_balance_type            => l_balance_type_code);
3737    ELSE
3738       NULL;
3739 -- No business flow processing for business flow method of NONE.
3740    END IF;
3741 
3742    --
3743    -- call description
3744    --
3745    
3746 xla_ae_lines_pkg.SetLineDescription(
3747    p_ae_header_id => l_ae_header_id
3748   ,p_description  => Description_1 (
3749      p_application_id         => p_application_id
3750    , p_ae_header_id           => l_ae_header_id 
3751 , p_source_1 => p_source_1
3752 , p_source_2 => p_source_2
3753    )
3754 );
3755 
3756 
3757    --
3758    -- call ADRs
3759    -- Bug 4922099
3760    --
3761    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
3762         (NVL(l_actual_upg_option, 'N') = 'O') OR
3763         (NVL(l_enc_upg_option, 'N') = 'O')
3764       )
3765    THEN
3766    NULL;
3767    --
3768    --
3769    
3770   l_ccid := AcctDerRule_8(
3771            p_application_id           => p_application_id
3772          , p_ae_header_id             => l_ae_header_id 
3773 , p_source_2 => p_source_2
3774 , p_source_8 => p_source_8
3775 , p_source_9 => p_source_9
3776          , x_transaction_coa_id       => l_adr_transaction_coa_id
3780    );
3777          , x_accounting_coa_id        => l_adr_accounting_coa_id
3778          , x_value_type_code          => l_adr_value_type_code
3779          , p_side                     => 'NA'
3781 
3782    xla_ae_lines_pkg.set_ccid(
3783     p_code_combination_id          => l_ccid
3784   , p_value_type_code              => l_adr_value_type_code
3785   , p_transaction_coa_id           => l_adr_transaction_coa_id
3786   , p_accounting_coa_id            => l_adr_accounting_coa_id
3787   , p_adr_code                     => 'FV_BE_TRANSACTION_CCID'
3788   , p_adr_type_code                => 'S'
3789   , p_component_type               => l_component_type
3790   , p_component_code               => l_component_code
3791   , p_component_type_code          => l_component_type_code
3792   , p_component_appl_id            => l_component_appl_id
3793   , p_amb_context_code             => l_amb_context_code
3794   , p_side                         => 'NA'
3795   );
3796 
3797 
3798    l_segment := AcctDerRule_4(
3799            p_application_id           => p_application_id
3800          , p_ae_header_id             => l_ae_header_id 
3801 , p_source_3 => p_source_3
3802 , p_source_4 => p_source_4
3803 , p_source_5 => p_source_5
3804          , x_transaction_coa_id       => l_adr_transaction_coa_id
3805          , x_accounting_coa_id        => l_adr_accounting_coa_id
3806          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
3807          , x_flex_value_set_id        => l_adr_flex_value_set_id
3808          , x_value_type_code          => l_adr_value_type_code
3809          , x_value_combination_id     => l_adr_value_combination_id
3810          , x_value_segment_code       => l_adr_value_segment_code
3811          , p_side                     => 'NA'
3812          , p_override_seg_flag        => 'Y'
3813    );
3814 
3815    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
3816 
3817       xla_ae_lines_pkg.set_segment(
3818           p_to_segment_code         => 'GL_ACCOUNT'
3819         , p_segment_value           => l_segment
3820         , p_from_segment_code       => l_adr_value_segment_code
3821         , p_from_combination_id     => l_adr_value_combination_id
3822         , p_value_type_code         => l_adr_value_type_code
3823         , p_transaction_coa_id      => l_adr_transaction_coa_id
3824         , p_accounting_coa_id       => l_adr_accounting_coa_id
3825         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
3826         , p_flex_value_set_id       => l_adr_flex_value_set_id
3827         , p_adr_code                => 'FV_BE_TRX_CR_NATURAL_SEGMENT'
3828         , p_adr_type_code           => 'S'
3829         , p_component_type          => l_component_type
3830         , p_component_code          => l_component_code
3831         , p_component_type_code     => l_component_type_code
3832         , p_component_appl_id       => l_component_appl_id
3833         , p_amb_context_code        => l_amb_context_code
3834         , p_entity_code             => 'BE_TRANSACTIONS'
3835         , p_event_class_code        => 'BUDGET_EXECUTION'
3836         , p_side                    => 'NA'
3837         );
3838 
3839   END IF;
3840 
3841    --
3842    --
3843    END IF;
3844    --
3845    -- Bug 4922099
3846    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
3847           (NVL(l_enc_upg_option, 'N') = 'O')
3848         ) AND
3849         (l_bflow_method_code = 'PRIOR_ENTRY')
3850       )
3851    THEN
3852       IF
3853       --
3854       1 = 2
3855       --
3856       THEN
3857       xla_accounting_err_pkg.build_message
3858                                     (p_appli_s_name            => 'XLA'
3859                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3860                                     ,p_token_1                 => 'LINE_NUMBER'
3861                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
3862                                     ,p_token_2                 => 'LINE_TYPE_NAME'
3863                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
3864                                                                              l_component_type
3865                                                                             ,l_component_code
3866                                                                             ,l_component_type_code
3867                                                                             ,l_component_appl_id
3868                                                                             ,l_amb_context_code
3869                                                                             ,l_entity_code
3873                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
3870                                                                             ,l_event_class_code
3871                                                                            )
3872                                     ,p_token_3                 => 'OWNER'
3874                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
3875                                                                           ,p_lookup_code    => l_component_type_code
3876                                                                          )
3877                                     ,p_token_4                 => 'PRODUCT_NAME'
3878                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
3879                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
3880                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
3881                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
3882                                     ,p_ae_header_id            =>  NULL
3883                                        );
3884 
3885         IF (C_LEVEL_ERROR>= g_log_level) THEN
3886                  trace
3887                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3888                       ,p_level    => C_LEVEL_ERROR
3889                       ,p_module   => l_log_module);
3890         END IF;
3891       END IF;
3892    END IF;
3893    --
3894    --
3895    ------------------------------------------------------------------------------------------------
3896    -- 4219869 Business Flow
3897    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
3898    -- Prior Entry.  Currently, the following code is always generated.
3899    ------------------------------------------------------------------------------------------------
3900    XLA_AE_LINES_PKG.ValidateCurrentLine;
3901 
3902    ------------------------------------------------------------------------------------
3903    -- 4219869 Business Flow
3904    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
3905    ------------------------------------------------------------------------------------
3906    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3907 
3908    ----------------------------------------------------------------------------------
3909    -- 4219869 Business Flow
3910    -- Update journal entry status -- Need to generate this within IF <condition>
3911    ----------------------------------------------------------------------------------
3912    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3913          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
3914          ,p_balance_type_code => l_balance_type_code
3915          );
3916 
3917    -------------------------------------------------------------------------------------------
3918    -- 4262811 - Generate the Accrual Reversal lines
3919    -------------------------------------------------------------------------------------------
3920    BEGIN
3921       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
3922                               (g_array_event(p_event_id).array_value_num('header_index'));
3923       IF l_acc_rev_flag IS NULL THEN
3924          l_acc_rev_flag := 'N';
3925       END IF;
3926    EXCEPTION
3927       WHEN OTHERS THEN
3928          l_acc_rev_flag := 'N';
3929    END;
3930    --
3931    IF (l_acc_rev_flag = 'Y') THEN
3932 
3933        -- 4645092  ------------------------------------------------------------------------------
3934        -- To allow MPA report to determine if it should generate report process
3935        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
3936        ------------------------------------------------------------------------------------------
3937 
3938        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
3939        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
3940 
3941        --
3942        -- Update the line information that should be overwritten
3943        --
3944        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
3945                                          p_header_num   => 1);
3946        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
3947 
3948        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
3949 
3950        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
3954       --
3951           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
3952        END IF;
3953 
3955       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
3956       --
3957       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
3958           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
3959       ELSE
3960           ---------------------------------------------------------------------------------------------------
3961           -- 4262811a Switch Sign
3962           ---------------------------------------------------------------------------------------------------
3963           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
3964           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3965                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3966           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3967                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3968           -- 5132302
3969           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
3970                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3971 
3972       END IF;
3973 
3974       -- 4955764
3975       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3976       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
3977 
3978 
3979       XLA_AE_LINES_PKG.ValidateCurrentLine;
3980       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3981 
3982       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3983                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
3984                ,p_balance_type_code => l_balance_type_code);
3985 
3986    END IF;
3987 
3988    -----------------------------------------------------------------------------------------
3989    -- 4262811 Multiperiod Accounting
3990    -----------------------------------------------------------------------------------------
3991      -- No MPA option is assigned.
3992 
3993 
3994 END IF;
3995 END IF;
3996 --
3997 
3998 --
3999 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4000    trace
4001       (p_msg      => 'END of AcctLineType_13'
4002       ,p_level    => C_LEVEL_PROCEDURE
4003       ,p_module   => l_log_module);
4004 END IF;
4005 --
4006 EXCEPTION
4007   WHEN xla_exceptions_pkg.application_exception THEN
4008       RAISE;
4009   WHEN OTHERS THEN
4010        xla_exceptions_pkg.raise_message
4011            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.AcctLineType_13');
4012 END AcctLineType_13;
4013 --
4014 
4015 ---------------------------------------
4016 --
4017 -- PRIVATE FUNCTION
4018 --         AcctLineType_14
4019 --
4020 ---------------------------------------
4021 PROCEDURE AcctLineType_14 (
4022   p_application_id        IN NUMBER
4023  ,p_event_id              IN NUMBER
4024  ,p_calculate_acctd_flag  IN VARCHAR2
4025  ,p_calculate_g_l_flag    IN VARCHAR2
4026  ,p_actual_flag           IN OUT VARCHAR2
4027  ,p_balance_type_code     OUT VARCHAR2
4028  ,p_gain_or_loss_ref      OUT VARCHAR2
4029  
4030 --DOC_NUMBER
4031  , p_source_1            IN VARCHAR2
4032 --BUDGET_LEVEL_ID
4033  , p_source_2            IN NUMBER
4034 --CR_ACCOUNT_SEGMENT_VALUE
4035  , p_source_3            IN VARCHAR2
4036 --DR_ACCOUNT_SEGMENT_VALUE
4037  , p_source_4            IN VARCHAR2
4038 --INCREASE_DECREASE_FLAG
4039  , p_source_5            IN VARCHAR2
4040 --DISTRIBUTION_ACCOUNT
4041  , p_source_8            IN NUMBER
4042 --FUND_DISTRIBUTION_ACCOUNT
4043  , p_source_9            IN NUMBER
4044 --SOURCE
4045  , p_source_10            IN VARCHAR2
4046 --TRANSACTION_TYPE
4047  , p_source_12            IN VARCHAR2
4048 --TRANSACTION_TYPE_ID
4049  , p_source_13            IN NUMBER
4050 --Accounted Amount
4051  , p_source_14            IN NUMBER
4052 --CURRENCY_CODE
4053  , p_source_15            IN VARCHAR2
4054 --DOC_ID
4055  , p_source_16            IN NUMBER
4056 )
4057 IS
4058 
4059 l_component_type              VARCHAR2(80);
4060 l_component_code              VARCHAR2(30);
4061 l_component_type_code         VARCHAR2(1);
4065 l_event_class_code            VARCHAR2(30);
4062 l_component_appl_id           INTEGER;
4063 l_amb_context_code            VARCHAR2(30);
4064 l_entity_code                 VARCHAR2(30);
4066 l_ae_header_id                NUMBER;
4067 l_event_type_code             VARCHAR2(30);
4068 l_line_definition_code        VARCHAR2(30);
4069 l_line_definition_owner_code  VARCHAR2(1);
4070 --
4071 -- adr variables
4072 l_segment                     VARCHAR2(30);
4073 l_ccid                        NUMBER;
4074 l_adr_transaction_coa_id      NUMBER;
4075 l_adr_accounting_coa_id       NUMBER;
4076 l_adr_flexfield_segment_code  VARCHAR2(30);
4077 l_adr_flex_value_set_id       NUMBER;
4078 l_adr_value_type_code         VARCHAR2(30);
4079 l_adr_value_combination_id    NUMBER;
4080 l_adr_value_segment_code      VARCHAR2(30);
4081 
4082 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
4083 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
4084 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
4085 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
4086 
4087 -- 4262811 Variables ------------------------------------------------------------------------------------------
4088 l_entered_amt_idx             NUMBER;
4089 l_accted_amt_idx              NUMBER;
4090 l_acc_rev_flag                VARCHAR2(1);
4091 l_accrual_line_num            NUMBER;
4092 l_tmp_amt                     NUMBER;
4093 l_acc_rev_natural_side_code   VARCHAR2(1);
4094 
4095 l_num_entries                 NUMBER;
4096 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
4097 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
4098 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
4099 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
4100 l_recog_line_1                NUMBER;
4101 l_recog_line_2                NUMBER;
4102 
4103 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
4104 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
4105 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
4106 
4107 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
4108 
4109 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
4110 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
4111 
4112 ---------------------------------------------------------------------------------------------------------------
4113 
4114 
4115 --
4116 -- bulk performance
4117 --
4118 l_balance_type_code           VARCHAR2(1);
4119 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
4120 l_log_module                  VARCHAR2(240);
4121 
4122 --
4123 -- Upgrade strategy
4124 --
4125 l_actual_upg_option           VARCHAR2(1);
4126 l_enc_upg_option           VARCHAR2(1);
4127 
4128 --
4129 BEGIN
4130 --
4131 IF g_log_enabled THEN
4132       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_14';
4133 END IF;
4134 --
4135 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4136 
4137       trace
4138          (p_msg      => 'BEGIN of AcctLineType_14'
4139          ,p_level    => C_LEVEL_PROCEDURE
4140          ,p_module   => l_log_module);
4141 
4142 END IF;
4143 --
4144 l_component_type             := 'AMB_JLT';
4145 l_component_code             := 'FV_BE_TRX_DR';
4146 l_component_type_code        := 'S';
4147 l_component_appl_id          :=  8901;
4148 l_amb_context_code           := 'DEFAULT';
4149 l_entity_code                := 'BE_TRANSACTIONS';
4150 l_event_class_code           := 'BUDGET_EXECUTION';
4151 l_event_type_code            := 'BUDGET_EXECUTION_ALL';
4152 l_line_definition_owner_code := 'S';
4153 l_line_definition_code       := 'FV_BE_TRX_JLD';
4154 --
4155 l_balance_type_code          := 'A';
4156 l_segment                     := NULL;
4157 l_ccid                        := NULL;
4158 l_adr_transaction_coa_id      := NULL;
4159 l_adr_accounting_coa_id       := NULL;
4160 l_adr_flexfield_segment_code  := NULL;
4161 l_adr_flex_value_set_id       := NULL;
4162 l_adr_value_type_code         := NULL;
4163 l_adr_value_combination_id    := NULL;
4164 l_adr_value_segment_code      := NULL;
4165 
4166 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
4167 l_bflow_class_code           := '';    -- 4219869 Business Flow
4168 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
4169 l_budgetary_control_flag     := 'Y';
4170 
4171 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
4172 l_bflow_applied_to_amt       := NULL; -- 5132302
4173 l_entered_amt_idx            := NULL;          -- 4262811
4174 l_accted_amt_idx             := NULL;          -- 4262811
4175 l_acc_rev_flag               := NULL;          -- 4262811
4176 l_accrual_line_num           := NULL;          -- 4262811
4177 l_tmp_amt                    := NULL;          -- 4262811
4178 --
4179  
4180 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
4181     l_balance_type_code <> 'B' THEN
4182 IF (p_source_2  >=  1 AND 
4183 NVL(p_source_10,'
4184 ')  <>  'RPR')
4185  THEN 
4186 
4187    --
4188    XLA_AE_LINES_PKG.SetNewLine;
4189 
4190    p_balance_type_code          := l_balance_type_code;
4191    -- set the flag so later we will know whether the gain loss line needs to be created
4192    
4193    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
4194      p_actual_flag :='A';
4195    END IF;
4196 
4197    --
4198    -- bulk performance
4199    --
4200    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
4201                                       p_header_num   => 0); -- 4262811
4202    --
4206            p_natural_side_code          => 'D'
4203    -- set accounting line options
4204    --
4205    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
4207          , p_gain_or_loss_flag          => 'N'
4208          , p_gl_transfer_mode_code      => 'S'
4209          , p_acct_entry_type_code       => 'A'
4210          , p_switch_side_flag           => 'N'
4211          , p_merge_duplicate_code       => 'N'
4212          );
4213    --
4214    l_acc_rev_natural_side_code := 'C';  -- 4262811
4215    -- 
4216    --
4217    -- set accounting line type info
4218    --
4219    xla_ae_lines_pkg.SetAcctLineType
4220       (p_component_type             => l_component_type
4221       ,p_event_type_code            => l_event_type_code
4222       ,p_line_definition_owner_code => l_line_definition_owner_code
4223       ,p_line_definition_code       => l_line_definition_code
4224       ,p_accounting_line_code       => l_component_code
4225       ,p_accounting_line_type_code  => l_component_type_code
4226       ,p_accounting_line_appl_id    => l_component_appl_id
4227       ,p_amb_context_code           => l_amb_context_code
4228       ,p_entity_code                => l_entity_code
4229       ,p_event_class_code           => l_event_class_code);
4230    --
4231    -- set accounting class
4232    --
4233    xla_ae_lines_pkg.SetAcctClass(
4234            p_accounting_class_code  => 'BE_RESERVE_DR'
4235          , p_ae_header_id           => l_ae_header_id
4236          );
4237 
4238    --
4239    -- set rounding class
4240    --
4241    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
4242                       'BE_RESERVE_DR';
4243 
4244    --
4245    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
4246    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
4247    --
4248    -- bulk performance
4249    --
4250    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
4251 
4252    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
4253       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
4254 
4255    -- 4955764
4256    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4257       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
4258 
4259    -- 4458381 Public Sector Enh
4260    
4261    --
4262    -- set accounting attributes for the line type
4263    --
4264    l_entered_amt_idx := 4;
4265    l_accted_amt_idx  := 6;
4266    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
4267    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
4268    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_16);
4269    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
4270    l_rec_acct_attrs.array_char_value(2)  := p_source_12;
4271    l_rec_acct_attrs.array_acct_attr_code(3) := 'DISTRIBUTION_TYPE';
4272    l_rec_acct_attrs.array_num_value(3)  :=  to_char(p_source_13);
4273    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_AMOUNT';
4274    l_rec_acct_attrs.array_num_value(4)  := p_source_14;
4275    l_rec_acct_attrs.array_acct_attr_code(5) := 'ENTERED_CURRENCY_CODE';
4276    l_rec_acct_attrs.array_char_value(5)  := p_source_15;
4277    l_rec_acct_attrs.array_acct_attr_code(6) := 'LEDGER_AMOUNT';
4278    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
4279 
4280    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
4281    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
4282 
4283    ---------------------------------------------------------------------------------------------------------------
4284    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
4285    ---------------------------------------------------------------------------------------------------------------
4286    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
4287 
4288    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4289    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4290 
4291    IF xla_accounting_cache_pkg.GetValueChar
4292          (p_source_code         => 'LEDGER_CATEGORY_CODE'
4293          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
4294    AND l_bflow_method_code = 'PRIOR_ENTRY'
4295 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
4296    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
4297          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
4298        )
4299    THEN
4300          xla_ae_lines_pkg.BflowUpgEntry
4301            (p_business_method_code    => l_bflow_method_code
4302            ,p_business_class_code     => l_bflow_class_code
4303            ,p_balance_type            => l_balance_type_code);
4304    ELSE
4305       NULL;
4306 -- No business flow processing for business flow method of NONE.
4307    END IF;
4308 
4309    --
4310    -- call description
4311    --
4312    
4313 xla_ae_lines_pkg.SetLineDescription(
4314    p_ae_header_id => l_ae_header_id
4315   ,p_description  => Description_1 (
4316      p_application_id         => p_application_id
4317    , p_ae_header_id           => l_ae_header_id 
4318 , p_source_1 => p_source_1
4319 , p_source_2 => p_source_2
4320    )
4321 );
4322 
4323 
4324    --
4325    -- call ADRs
4326    -- Bug 4922099
4327    --
4328    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4329         (NVL(l_actual_upg_option, 'N') = 'O') OR
4330         (NVL(l_enc_upg_option, 'N') = 'O')
4331       )
4335    --
4332    THEN
4333    NULL;
4334    --
4336    
4337   l_ccid := AcctDerRule_8(
4338            p_application_id           => p_application_id
4339          , p_ae_header_id             => l_ae_header_id 
4340 , p_source_2 => p_source_2
4341 , p_source_8 => p_source_8
4342 , p_source_9 => p_source_9
4343          , x_transaction_coa_id       => l_adr_transaction_coa_id
4344          , x_accounting_coa_id        => l_adr_accounting_coa_id
4345          , x_value_type_code          => l_adr_value_type_code
4346          , p_side                     => 'NA'
4347    );
4348 
4349    xla_ae_lines_pkg.set_ccid(
4350     p_code_combination_id          => l_ccid
4351   , p_value_type_code              => l_adr_value_type_code
4352   , p_transaction_coa_id           => l_adr_transaction_coa_id
4353   , p_accounting_coa_id            => l_adr_accounting_coa_id
4354   , p_adr_code                     => 'FV_BE_TRANSACTION_CCID'
4355   , p_adr_type_code                => 'S'
4356   , p_component_type               => l_component_type
4357   , p_component_code               => l_component_code
4358   , p_component_type_code          => l_component_type_code
4359   , p_component_appl_id            => l_component_appl_id
4360   , p_amb_context_code             => l_amb_context_code
4361   , p_side                         => 'NA'
4362   );
4363 
4364 
4365    l_segment := AcctDerRule_5(
4366            p_application_id           => p_application_id
4367          , p_ae_header_id             => l_ae_header_id 
4368 , p_source_3 => p_source_3
4369 , p_source_4 => p_source_4
4370 , p_source_5 => p_source_5
4371          , x_transaction_coa_id       => l_adr_transaction_coa_id
4372          , x_accounting_coa_id        => l_adr_accounting_coa_id
4373          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
4374          , x_flex_value_set_id        => l_adr_flex_value_set_id
4375          , x_value_type_code          => l_adr_value_type_code
4376          , x_value_combination_id     => l_adr_value_combination_id
4377          , x_value_segment_code       => l_adr_value_segment_code
4378          , p_side                     => 'NA'
4379          , p_override_seg_flag        => 'Y'
4380    );
4381 
4382    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
4383 
4384       xla_ae_lines_pkg.set_segment(
4385           p_to_segment_code         => 'GL_ACCOUNT'
4386         , p_segment_value           => l_segment
4387         , p_from_segment_code       => l_adr_value_segment_code
4388         , p_from_combination_id     => l_adr_value_combination_id
4389         , p_value_type_code         => l_adr_value_type_code
4390         , p_transaction_coa_id      => l_adr_transaction_coa_id
4391         , p_accounting_coa_id       => l_adr_accounting_coa_id
4392         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
4393         , p_flex_value_set_id       => l_adr_flex_value_set_id
4394         , p_adr_code                => 'FV_BE_TRX_DR_NATURAL_SEGMENT'
4395         , p_adr_type_code           => 'S'
4396         , p_component_type          => l_component_type
4397         , p_component_code          => l_component_code
4398         , p_component_type_code     => l_component_type_code
4399         , p_component_appl_id       => l_component_appl_id
4400         , p_amb_context_code        => l_amb_context_code
4401         , p_entity_code             => 'BE_TRANSACTIONS'
4402         , p_event_class_code        => 'BUDGET_EXECUTION'
4403         , p_side                    => 'NA'
4404         );
4405 
4406   END IF;
4407 
4408    --
4409    --
4410    END IF;
4411    --
4412    -- Bug 4922099
4413    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
4414           (NVL(l_enc_upg_option, 'N') = 'O')
4415         ) AND
4416         (l_bflow_method_code = 'PRIOR_ENTRY')
4417       )
4418    THEN
4419       IF
4420       --
4421       1 = 2
4422       --
4423       THEN
4424       xla_accounting_err_pkg.build_message
4425                                     (p_appli_s_name            => 'XLA'
4426                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4427                                     ,p_token_1                 => 'LINE_NUMBER'
4428                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
4429                                     ,p_token_2                 => 'LINE_TYPE_NAME'
4430                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
4431                                                                              l_component_type
4432                                                                             ,l_component_code
4433                                                                             ,l_component_type_code
4434                                                                             ,l_component_appl_id
4435                                                                             ,l_amb_context_code
4436                                                                             ,l_entity_code
4437                                                                             ,l_event_class_code
4438                                                                            )
4439                                     ,p_token_3                 => 'OWNER'
4440                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
4441                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
4442                                                                           ,p_lookup_code    => l_component_type_code
4443                                                                          )
4444                                     ,p_token_4                 => 'PRODUCT_NAME'
4445                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
4449                                     ,p_ae_header_id            =>  NULL
4446                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
4447                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
4448                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
4450                                        );
4451 
4452         IF (C_LEVEL_ERROR>= g_log_level) THEN
4453                  trace
4454                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4455                       ,p_level    => C_LEVEL_ERROR
4456                       ,p_module   => l_log_module);
4457         END IF;
4458       END IF;
4459    END IF;
4460    --
4461    --
4462    ------------------------------------------------------------------------------------------------
4463    -- 4219869 Business Flow
4464    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
4465    -- Prior Entry.  Currently, the following code is always generated.
4466    ------------------------------------------------------------------------------------------------
4467    XLA_AE_LINES_PKG.ValidateCurrentLine;
4468 
4469    ------------------------------------------------------------------------------------
4470    -- 4219869 Business Flow
4471    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
4472    ------------------------------------------------------------------------------------
4473    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4474 
4475    ----------------------------------------------------------------------------------
4476    -- 4219869 Business Flow
4477    -- Update journal entry status -- Need to generate this within IF <condition>
4478    ----------------------------------------------------------------------------------
4479    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4480          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
4481          ,p_balance_type_code => l_balance_type_code
4482          );
4483 
4484    -------------------------------------------------------------------------------------------
4485    -- 4262811 - Generate the Accrual Reversal lines
4486    -------------------------------------------------------------------------------------------
4487    BEGIN
4488       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
4489                               (g_array_event(p_event_id).array_value_num('header_index'));
4490       IF l_acc_rev_flag IS NULL THEN
4491          l_acc_rev_flag := 'N';
4492       END IF;
4493    EXCEPTION
4494       WHEN OTHERS THEN
4495          l_acc_rev_flag := 'N';
4496    END;
4497    --
4498    IF (l_acc_rev_flag = 'Y') THEN
4499 
4500        -- 4645092  ------------------------------------------------------------------------------
4501        -- To allow MPA report to determine if it should generate report process
4502        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
4503        ------------------------------------------------------------------------------------------
4504 
4505        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
4506        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
4507 
4508        --
4509        -- Update the line information that should be overwritten
4510        --
4511        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
4512                                          p_header_num   => 1);
4513        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
4514 
4515        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
4516 
4517        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
4518           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
4519        END IF;
4520 
4521       --
4522       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
4523       --
4524       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
4525           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
4526       ELSE
4527           ---------------------------------------------------------------------------------------------------
4528           -- 4262811a Switch Sign
4529           ---------------------------------------------------------------------------------------------------
4530           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
4531           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4532                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4533           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4534                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4535           -- 5132302
4536           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
4537                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4538 
4539       END IF;
4540 
4541       -- 4955764
4542       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4543       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
4544 
4545 
4546       XLA_AE_LINES_PKG.ValidateCurrentLine;
4547       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4548 
4549       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4550                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
4551                ,p_balance_type_code => l_balance_type_code);
4552 
4553    END IF;
4554 
4558      -- No MPA option is assigned.
4555    -----------------------------------------------------------------------------------------
4556    -- 4262811 Multiperiod Accounting
4557    -----------------------------------------------------------------------------------------
4559 
4560 
4561 END IF;
4562 END IF;
4563 --
4564 
4565 --
4566 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4567    trace
4568       (p_msg      => 'END of AcctLineType_14'
4569       ,p_level    => C_LEVEL_PROCEDURE
4570       ,p_module   => l_log_module);
4571 END IF;
4572 --
4573 EXCEPTION
4574   WHEN xla_exceptions_pkg.application_exception THEN
4575       RAISE;
4576   WHEN OTHERS THEN
4577        xla_exceptions_pkg.raise_message
4578            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.AcctLineType_14');
4579 END AcctLineType_14;
4580 --
4581 
4582 ---------------------------------------
4583 --
4584 -- PRIVATE PROCEDURE
4585 --         insert_sources_15
4586 --
4587 ----------------------------------------
4588 --
4589 PROCEDURE insert_sources_15(
4590                                 p_target_ledger_id       IN NUMBER
4591                               , p_language               IN VARCHAR2
4592                               , p_sla_ledger_id          IN NUMBER
4593                               , p_pad_start_date         IN DATE
4594                               , p_pad_end_date           IN DATE
4595                          )
4596 IS
4597 
4598 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'BUDGET_EXECUTION_ALL';
4599 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'BUDGET_EXECUTION';
4600 p_apps_owner                   VARCHAR2(30);
4601 l_log_module                   VARCHAR2(240);
4602 BEGIN
4603 IF g_log_enabled THEN
4604       l_log_module := C_DEFAULT_MODULE||'.insert_sources_15';
4605 END IF;
4606 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4607 
4608       trace
4609          (p_msg      => 'BEGIN of insert_sources_15'
4610          ,p_level    => C_LEVEL_PROCEDURE
4611          ,p_module   => l_log_module);
4612 
4613 END IF;
4614 
4615 -- select APPS owner
4616 SELECT oracle_username
4617   INTO p_apps_owner
4618   FROM fnd_oracle_userid
4619  WHERE read_only_flag = 'U'
4620 ;
4621 
4622 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4623       trace
4624          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
4625                         ' - p_language = '||p_language||
4626                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
4627                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
4628                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
4629                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
4630          ,p_level    => C_LEVEL_STATEMENT
4631          ,p_module   => l_log_module);
4632 END IF;
4633 
4634 
4635 --
4636 INSERT INTO xla_diag_sources --hdr2
4637 (
4638         event_id
4639       , ledger_id
4640       , sla_ledger_id
4641       , description_language
4642       , object_name
4643       , object_type_code
4644       , line_number
4645       , source_application_id
4646       , source_type_code
4647       , source_code
4648       , source_value
4649       , source_meaning
4650       , created_by
4651       , creation_date
4652       , last_update_date
4653       , last_updated_by
4654       , last_update_login
4655       , program_update_date
4656       , program_application_id
4657       , program_id
4658       , request_id
4659 )
4660 SELECT
4661         event_id
4662       , p_target_ledger_id
4663       , p_sla_ledger_id
4664       , p_language
4665       , object_name
4666       , object_type_code
4667       , line_number
4668       , source_application_id
4669       , source_type_code
4670       , source_code
4671       , SUBSTR(source_value ,1,1996)
4672       , SUBSTR(source_meaning ,1,200)
4673       , xla_environment_pkg.g_Usr_Id
4674       , TRUNC(SYSDATE)
4675       , TRUNC(SYSDATE)
4676       , xla_environment_pkg.g_Usr_Id
4677       , xla_environment_pkg.g_Login_Id
4678       , TRUNC(SYSDATE)
4679       , xla_environment_pkg.g_Prog_Appl_Id
4680       , xla_environment_pkg.g_Prog_Id
4681       , xla_environment_pkg.g_Req_Id
4682   FROM (
4683        SELECT xet.event_id                  event_id
4684             , 0                          line_number
4685             , CASE r
4686                WHEN 1 THEN 'FV_BE_BA_FD_HDR_V' 
4687                 WHEN 2 THEN 'FV_BE_BA_FD_HDR_V' 
4688                 WHEN 3 THEN 'FV_BE_BA_FD_HDR_V' 
4689                 WHEN 4 THEN 'FV_BE_BA_FD_HDR_V' 
4690                 WHEN 5 THEN 'FV_BE_BA_FD_HDR_V' 
4691                 WHEN 6 THEN 'FV_BE_BA_FD_HDR_V' 
4692                 WHEN 7 THEN 'FV_BE_BA_FD_HDR_V' 
4693                 
4694                ELSE null
4695               END                           object_name
4696             , CASE r
4697                 WHEN 1 THEN 'HEADER' 
4698                 WHEN 2 THEN 'HEADER' 
4699                 WHEN 3 THEN 'HEADER' 
4700                 WHEN 4 THEN 'HEADER' 
4701                 WHEN 5 THEN 'HEADER' 
4702                 WHEN 6 THEN 'HEADER' 
4703                 WHEN 7 THEN 'HEADER' 
4704                 
4705                 ELSE null
4706               END                           object_type_code
4707             , CASE r
4708                 WHEN 1 THEN '8901' 
4709                 WHEN 2 THEN '8901' 
4710                 WHEN 3 THEN '8901' 
4711                 WHEN 4 THEN '8901' 
4712                 WHEN 5 THEN '8901' 
4713                 WHEN 6 THEN '8901' 
4714                 WHEN 7 THEN '8901' 
4715                 
4716                 ELSE null
4720                 WHEN 1 THEN 'DOC_NUMBER' 
4717               END                           source_application_id
4718             , 'S'             source_type_code
4719             , CASE r
4721                 WHEN 2 THEN 'BUDGET_LEVEL_ID' 
4722                 WHEN 3 THEN 'DISTRIBUTION_ACCOUNT' 
4723                 WHEN 4 THEN 'SOURCE' 
4724                 WHEN 5 THEN 'CURRENCY_CODE' 
4725                 WHEN 6 THEN 'DOC_ID' 
4726                 WHEN 7 THEN 'GL_DATE' 
4727                 
4728                 ELSE null
4729               END                           source_code
4730             , CASE r
4731                 WHEN 1 THEN TO_CHAR(h2.DOC_NUMBER)
4732                 WHEN 2 THEN TO_CHAR(h2.BUDGET_LEVEL_ID)
4733                 WHEN 3 THEN TO_CHAR(h2.DISTRIBUTION_ACCOUNT)
4734                 WHEN 4 THEN TO_CHAR(h2.SOURCE)
4735                 WHEN 5 THEN TO_CHAR(h2.CURRENCY_CODE)
4736                 WHEN 6 THEN TO_CHAR(h2.DOC_ID)
4737                 WHEN 7 THEN TO_CHAR(h2.GL_DATE)
4738                 
4739                 ELSE null
4740               END                           source_value
4741             , null              source_meaning
4742          FROM xla_events_gt     xet  
4743       , FV_BE_BA_FD_HDR_V  h2
4744              ,(select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
4745          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
4746            AND xet.event_class_code = C_EVENT_CLASS_CODE
4747               AND h2.event_id = xet.event_id
4748 
4749 )
4750 ;
4751 --
4752 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4753 
4754       trace
4755          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
4756          ,p_level    => C_LEVEL_STATEMENT
4757          ,p_module   => l_log_module);
4758 
4759 END IF;
4760 --
4761 
4762 
4763 
4764 --
4765 INSERT INTO xla_diag_sources  --line2
4766 (
4767         event_id
4768       , ledger_id
4769       , sla_ledger_id
4770       , description_language
4771       , object_name
4772       , object_type_code
4773       , line_number
4774       , source_application_id
4775       , source_type_code
4776       , source_code
4777       , source_value
4778       , source_meaning
4779       , created_by
4780       , creation_date
4781       , last_update_date
4782       , last_updated_by
4783       , last_update_login
4784       , program_update_date
4785       , program_application_id
4786       , program_id
4787       , request_id
4788 )
4789 SELECT  event_id
4790       , p_target_ledger_id
4791       , p_sla_ledger_id
4792       , p_language
4793       , object_name
4794       , object_type_code
4795       , line_number
4796       , source_application_id
4797       , source_type_code
4798       , source_code
4799       , SUBSTR(source_value,1,1996)
4800       , SUBSTR(source_meaning ,1,200)
4801       , xla_environment_pkg.g_Usr_Id
4802       , TRUNC(SYSDATE)
4803       , TRUNC(SYSDATE)
4804       , xla_environment_pkg.g_Usr_Id
4805       , xla_environment_pkg.g_Login_Id
4806       , TRUNC(SYSDATE)
4807       , xla_environment_pkg.g_Prog_Appl_Id
4808       , xla_environment_pkg.g_Prog_Id
4809       , xla_environment_pkg.g_Req_Id
4810   FROM (
4811        SELECT xet.event_id                  event_id
4812             , l1.line_number                 line_number
4813             , CASE r
4814                WHEN 1 THEN 'FV_BE_BA_FD_DTL_V' 
4815                 WHEN 2 THEN 'FV_BE_BA_FD_DTL_V' 
4816                 WHEN 3 THEN 'FV_BE_BA_FD_DTL_V' 
4817                 WHEN 4 THEN 'FV_BE_BA_FD_DTL_V' 
4818                 WHEN 5 THEN 'FV_BE_BA_FD_DTL_V' 
4819                 WHEN 6 THEN 'FV_BE_BA_FD_DTL_V' 
4820                 WHEN 7 THEN 'FV_BE_BA_FD_DTL_V' 
4821                 
4822                ELSE null
4823               END                           object_name
4824             , CASE r
4825                 WHEN 1 THEN 'LINE' 
4826                 WHEN 2 THEN 'LINE' 
4827                 WHEN 3 THEN 'LINE' 
4828                 WHEN 4 THEN 'LINE' 
4829                 WHEN 5 THEN 'LINE' 
4830                 WHEN 6 THEN 'LINE' 
4831                 WHEN 7 THEN 'LINE' 
4832                 
4833                 ELSE null
4834               END                           object_type_code
4835             , CASE r
4836                 WHEN 1 THEN '8901' 
4837                 WHEN 2 THEN '8901' 
4838                 WHEN 3 THEN '8901' 
4839                 WHEN 4 THEN '8901' 
4840                 WHEN 5 THEN '8901' 
4841                 WHEN 6 THEN '8901' 
4842                 WHEN 7 THEN '8901' 
4843                 
4844                 ELSE null
4845               END                           source_application_id
4846             , 'S'             source_type_code
4847             , CASE r
4848                 WHEN 1 THEN 'CR_ACCOUNT_SEGMENT_VALUE' 
4849                 WHEN 2 THEN 'DR_ACCOUNT_SEGMENT_VALUE' 
4850                 WHEN 3 THEN 'INCREASE_DECREASE_FLAG' 
4851                 WHEN 4 THEN 'FUND_DISTRIBUTION_ACCOUNT' 
4852                 WHEN 5 THEN 'TRANSACTION_TYPE' 
4853                 WHEN 6 THEN 'TRANSACTION_TYPE_ID' 
4854                 WHEN 7 THEN 'ACCOUNTED_AMOUNT' 
4855                 
4856                 ELSE null
4857               END                           source_code
4858             , CASE r
4859                 WHEN 1 THEN TO_CHAR(l1.CR_ACCOUNT_SEGMENT_VALUE)
4860                 WHEN 2 THEN TO_CHAR(l1.DR_ACCOUNT_SEGMENT_VALUE)
4864                 WHEN 6 THEN TO_CHAR(l1.TRANSACTION_TYPE_ID)
4861                 WHEN 3 THEN TO_CHAR(l1.INCREASE_DECREASE_FLAG)
4862                 WHEN 4 THEN TO_CHAR(l1.FUND_DISTRIBUTION_ACCOUNT)
4863                 WHEN 5 THEN TO_CHAR(l1.TRANSACTION_TYPE)
4865                 WHEN 7 THEN TO_CHAR(l1.ACCOUNTED_AMOUNT)
4866                 
4867                 ELSE null
4868               END                           source_value
4869             , null              source_meaning
4870          FROM  xla_events_gt     xet  
4871         , FV_BE_BA_FD_DTL_V  l1
4872             , (select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
4873         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
4874           AND xet.event_class_code = C_EVENT_CLASS_CODE
4875             AND l1.event_id          = xet.event_id
4876 
4877 )
4878 ;
4879 --
4880 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
4881 
4882       trace
4883          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
4884          ,p_level    => C_LEVEL_STATEMENT
4885          ,p_module   => l_log_module);
4886 
4887 END IF;
4888 
4889 
4890 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4891       trace
4892          (p_msg      => 'END of insert_sources_15'
4893          ,p_level    => C_LEVEL_PROCEDURE
4894          ,p_module   => l_log_module);
4895 END IF;
4896 EXCEPTION
4897   WHEN xla_exceptions_pkg.application_exception THEN
4898       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4899             trace
4900                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
4901                ,p_level    => C_LEVEL_EXCEPTION
4902                ,p_module   => l_log_module);
4903       END IF;
4904       RAISE;
4905   WHEN OTHERS THEN
4906       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
4907             trace
4908                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
4909                ,p_level    => C_LEVEL_EXCEPTION
4910                ,p_module   => l_log_module);
4911        END IF;
4912        xla_exceptions_pkg.raise_message
4913            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.insert_sources_15');
4914 END insert_sources_15;
4915 --
4916 
4917 ---------------------------------------
4918 --
4919 -- PRIVATE FUNCTION
4920 --         EventClass_15
4921 --
4922 ----------------------------------------
4923 --
4924 FUNCTION EventClass_15
4925        (p_application_id         IN NUMBER
4926        ,p_base_ledger_id         IN NUMBER
4927        ,p_target_ledger_id       IN NUMBER
4928        ,p_language               IN VARCHAR2
4929        ,p_currency_code          IN VARCHAR2
4930        ,p_sla_ledger_id          IN NUMBER
4931        ,p_pad_start_date         IN DATE
4932        ,p_pad_end_date           IN DATE
4933        ,p_primary_ledger_id      IN NUMBER)
4934 RETURN BOOLEAN IS
4935 --
4936 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'BUDGET_EXECUTION_ALL';
4937 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'BUDGET_EXECUTION';
4938 
4939 l_calculate_acctd_flag   VARCHAR2(1) :='N';
4940 l_calculate_g_l_flag     VARCHAR2(1) :='N';
4941 --
4942 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
4943 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
4944 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
4945 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
4946 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
4947 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
4948 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
4949 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
4950 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
4951 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
4952 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
4953 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
4954 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
4955 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
4956 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
4957 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
4958 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
4959 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
4960 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
4961 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
4962 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
4963 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
4964 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
4965 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
4966 
4967 l_event_id                             NUMBER;
4968 l_previous_event_id                    NUMBER;
4969 l_first_event_id                       NUMBER;
4970 l_last_event_id                        NUMBER;
4971 
4972 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
4973 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
4974 --
4975 --
4976 l_result                    BOOLEAN := TRUE;
4977 l_rows                      NUMBER  := 1000;
4978 l_event_type_name           VARCHAR2(80) := 'All';
4979 l_event_class_name          VARCHAR2(80) := 'Budget Execution Transactions';
4980 l_description               VARCHAR2(4000);
4981 l_transaction_reversal      NUMBER;
4982 l_ae_header_id              NUMBER;
4983 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
4984 l_log_module                VARCHAR2(240);
4985 --
4989 l_continue_with_lines       BOOLEAN := TRUE;
4986 l_acct_reversal_source      VARCHAR2(30);
4987 l_trx_reversal_source       VARCHAR2(30);
4988 
4990 --
4991 l_acc_rev_gl_date_source    DATE;                      -- 4262811
4992 --
4993 type t_array_event_id is table of number index by binary_integer;
4994 
4995 l_rec_array_event                    t_rec_array_event;
4996 l_null_rec_array_event               t_rec_array_event;
4997 l_array_ae_header_id                 xla_number_array_type;
4998 l_actual_flag                        VARCHAR2(1) := NULL;
4999 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
5000 l_balance_type_code                  VARCHAR2(1) :=NULL;
5001 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
5002 
5003 --
5004 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
5005 --
5006 
5007 TYPE t_array_source_1 IS TABLE OF FV_BE_BA_FD_HDR_V.DOC_NUMBER%TYPE INDEX BY BINARY_INTEGER;
5008 TYPE t_array_source_2 IS TABLE OF FV_BE_BA_FD_HDR_V.BUDGET_LEVEL_ID%TYPE INDEX BY BINARY_INTEGER;
5009 TYPE t_array_source_8 IS TABLE OF FV_BE_BA_FD_HDR_V.DISTRIBUTION_ACCOUNT%TYPE INDEX BY BINARY_INTEGER;
5010 TYPE t_array_source_10 IS TABLE OF FV_BE_BA_FD_HDR_V.SOURCE%TYPE INDEX BY BINARY_INTEGER;
5011 TYPE t_array_source_15 IS TABLE OF FV_BE_BA_FD_HDR_V.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
5012 TYPE t_array_source_16 IS TABLE OF FV_BE_BA_FD_HDR_V.DOC_ID%TYPE INDEX BY BINARY_INTEGER;
5013 TYPE t_array_source_17 IS TABLE OF FV_BE_BA_FD_HDR_V.GL_DATE%TYPE INDEX BY BINARY_INTEGER;
5014 
5015 TYPE t_array_source_3 IS TABLE OF FV_BE_BA_FD_DTL_V.CR_ACCOUNT_SEGMENT_VALUE%TYPE INDEX BY BINARY_INTEGER;
5016 TYPE t_array_source_4 IS TABLE OF FV_BE_BA_FD_DTL_V.DR_ACCOUNT_SEGMENT_VALUE%TYPE INDEX BY BINARY_INTEGER;
5017 TYPE t_array_source_5 IS TABLE OF FV_BE_BA_FD_DTL_V.INCREASE_DECREASE_FLAG%TYPE INDEX BY BINARY_INTEGER;
5018 TYPE t_array_source_9 IS TABLE OF FV_BE_BA_FD_DTL_V.FUND_DISTRIBUTION_ACCOUNT%TYPE INDEX BY BINARY_INTEGER;
5019 TYPE t_array_source_12 IS TABLE OF FV_BE_BA_FD_DTL_V.TRANSACTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
5020 TYPE t_array_source_13 IS TABLE OF FV_BE_BA_FD_DTL_V.TRANSACTION_TYPE_ID%TYPE INDEX BY BINARY_INTEGER;
5021 TYPE t_array_source_14 IS TABLE OF FV_BE_BA_FD_DTL_V.ACCOUNTED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
5022 
5023 l_array_source_1              t_array_source_1;
5024 l_array_source_2              t_array_source_2;
5025 l_array_source_8              t_array_source_8;
5026 l_array_source_10              t_array_source_10;
5027 l_array_source_15              t_array_source_15;
5028 l_array_source_16              t_array_source_16;
5029 l_array_source_17              t_array_source_17;
5030 
5031 l_array_source_3      t_array_source_3;
5032 l_array_source_4      t_array_source_4;
5033 l_array_source_5      t_array_source_5;
5034 l_array_source_9      t_array_source_9;
5035 l_array_source_12      t_array_source_12;
5036 l_array_source_13      t_array_source_13;
5037 l_array_source_14      t_array_source_14;
5038 
5039 --
5040 CURSOR header_cur
5041 IS
5042 SELECT /*+ leading(xet) cardinality(xet,1) */
5043 -- Event Class Code: BUDGET_EXECUTION
5044     xet.entity_id
5045    ,xet.legal_entity_id
5046    ,xet.entity_code
5047    ,xet.transaction_number
5048    ,xet.event_id
5049    ,xet.event_class_code
5050    ,xet.event_type_code
5051    ,xet.event_number
5052    ,xet.event_date
5053    ,xet.transaction_date
5054    ,xet.reference_num_1
5055    ,xet.reference_num_2
5056    ,xet.reference_num_3
5057    ,xet.reference_num_4
5058    ,xet.reference_char_1
5059    ,xet.reference_char_2
5060    ,xet.reference_char_3
5061    ,xet.reference_char_4
5062    ,xet.reference_date_1
5063    ,xet.reference_date_2
5064    ,xet.reference_date_3
5065    ,xet.reference_date_4
5066    ,xet.event_created_by
5067    ,xet.budgetary_control_flag 
5068   , h2.DOC_NUMBER    source_1
5069   , h2.BUDGET_LEVEL_ID    source_2
5070   , h2.DISTRIBUTION_ACCOUNT    source_8
5071   , h2.SOURCE    source_10
5072   , h2.CURRENCY_CODE    source_15
5073   , h2.DOC_ID    source_16
5074   , h2.GL_DATE    source_17
5075   FROM xla_events_gt     xet 
5076   , FV_BE_BA_FD_HDR_V  h2
5077  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
5078    and xet.event_class_code = C_EVENT_CLASS_CODE
5079    and xet.event_status_code <> 'N'  AND h2.event_id = xet.event_id
5080 
5081  ORDER BY event_id
5082 ;
5083 
5084 
5085 --
5086 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
5087 IS
5088 SELECT  /*+ leading(xet) cardinality(xet,1) */
5089 -- Event Class Code: BUDGET_EXECUTION
5090     xet.entity_id
5091    ,xet.legal_entity_id
5092    ,xet.entity_code
5093    ,xet.transaction_number
5094    ,xet.event_id
5095    ,xet.event_class_code
5096    ,xet.event_type_code
5097    ,xet.event_number
5098    ,xet.event_date
5099    ,xet.transaction_date
5100    ,xet.reference_num_1
5101    ,xet.reference_num_2
5102    ,xet.reference_num_3
5103    ,xet.reference_num_4
5104    ,xet.reference_char_1
5105    ,xet.reference_char_2
5106    ,xet.reference_char_3
5107    ,xet.reference_char_4
5108    ,xet.reference_date_1
5109    ,xet.reference_date_2
5110    ,xet.reference_date_3
5111    ,xet.reference_date_4
5112    ,xet.event_created_by
5113    ,xet.budgetary_control_flag
5114  , l1.LINE_NUMBER  
5115   , l1.CR_ACCOUNT_SEGMENT_VALUE    source_3
5116   , l1.DR_ACCOUNT_SEGMENT_VALUE    source_4
5117   , l1.INCREASE_DECREASE_FLAG    source_5
5118   , l1.FUND_DISTRIBUTION_ACCOUNT    source_9
5119   , l1.TRANSACTION_TYPE    source_12
5120   , l1.TRANSACTION_TYPE_ID    source_13
5121   , l1.ACCOUNTED_AMOUNT    source_14
5122   FROM xla_events_gt     xet 
5123   , FV_BE_BA_FD_DTL_V  l1
5124  WHERE xet.event_id between x_first_event_id and x_last_event_id
5128 ;
5125    and xet.event_date between p_pad_start_date and p_pad_end_date
5126    and xet.event_class_code = C_EVENT_CLASS_CODE
5127    and xet.event_status_code <> 'N'   AND l1.event_id      = xet.event_id
5129 
5130 --
5131 BEGIN
5132 IF g_log_enabled THEN
5133    l_log_module := C_DEFAULT_MODULE||'.EventClass_15';
5134 END IF;
5135 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5136    trace
5137       (p_msg      => 'BEGIN of EventClass_15'
5138       ,p_level    => C_LEVEL_PROCEDURE
5139       ,p_module   => l_log_module);
5140 END IF;
5141 
5142 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5143    trace
5144       (p_msg      => 'p_application_id = '||p_application_id||
5145                      ' - p_base_ledger_id = '||p_base_ledger_id||
5146                      ' - p_target_ledger_id  = '||p_target_ledger_id||
5147                      ' - p_language = '||p_language||
5148                      ' - p_currency_code = '||p_currency_code||
5149                      ' - p_sla_ledger_id = '||p_sla_ledger_id
5150       ,p_level    => C_LEVEL_STATEMENT
5151       ,p_module   => l_log_module);
5152 END IF;
5153 --
5154 -- initialze arrays
5155 --
5156 g_array_event.DELETE;
5157 l_rec_array_event := l_null_rec_array_event;
5158 --
5159 --------------------------------------
5160 -- 4262811 Initialze MPA Line Number
5161 --------------------------------------
5162 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
5163 
5164 --
5165 
5166 --
5167 OPEN header_cur;
5168 --
5169 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5170    trace
5171    (p_msg      => 'SQL - FETCH header_cur'
5172    ,p_level    => C_LEVEL_STATEMENT
5173    ,p_module   => l_log_module);
5174 END IF;
5175 --
5176 LOOP
5177 FETCH header_cur BULK COLLECT INTO
5178         l_array_entity_id
5179       , l_array_legal_entity_id
5180       , l_array_entity_code
5181       , l_array_transaction_num
5182       , l_array_event_id
5183       , l_array_class_code
5184       , l_array_event_type
5185       , l_array_event_number
5186       , l_array_event_date
5187       , l_array_transaction_date
5188       , l_array_reference_num_1
5189       , l_array_reference_num_2
5190       , l_array_reference_num_3
5191       , l_array_reference_num_4
5192       , l_array_reference_char_1
5193       , l_array_reference_char_2
5194       , l_array_reference_char_3
5195       , l_array_reference_char_4
5196       , l_array_reference_date_1
5197       , l_array_reference_date_2
5198       , l_array_reference_date_3
5199       , l_array_reference_date_4
5200       , l_array_event_created_by
5201       , l_array_budgetary_control_flag 
5202       , l_array_source_1
5203       , l_array_source_2
5204       , l_array_source_8
5205       , l_array_source_10
5206       , l_array_source_15
5207       , l_array_source_16
5208       , l_array_source_17
5209       LIMIT l_rows;
5210 --
5211 IF (C_LEVEL_EVENT >= g_log_level) THEN
5212    trace
5213    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
5214    ,p_level    => C_LEVEL_EVENT
5215    ,p_module   => l_log_module);
5216 END IF;
5217 --
5218 EXIT WHEN l_array_entity_id.COUNT = 0;
5219 
5220 -- initialize arrays
5221 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
5222 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
5223 
5224 --
5225 -- Bug 4458708
5226 --
5227 XLA_AE_LINES_PKG.g_LineNumber := 0;
5228 
5229 
5230 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
5231 g_last_hdr_idx := l_array_event_id.LAST;
5232 --
5233 -- loop for the headers. Each iteration is for each header extract row
5234 -- fetched in header cursor
5235 --
5236 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
5237 
5238 --
5239 -- set event info as cache for other routines to refer event attributes
5240 --
5241 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
5242    (p_application_id           => p_application_id
5243    ,p_primary_ledger_id        => p_primary_ledger_id
5244    ,p_base_ledger_id           => p_base_ledger_id
5245    ,p_target_ledger_id         => p_target_ledger_id
5246    ,p_entity_id                => l_array_entity_id(hdr_idx)
5247    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
5248    ,p_entity_code              => l_array_entity_code(hdr_idx)
5249    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
5250    ,p_event_id                 => l_array_event_id(hdr_idx)
5251    ,p_event_class_code         => l_array_class_code(hdr_idx)
5252    ,p_event_type_code          => l_array_event_type(hdr_idx)
5253    ,p_event_number             => l_array_event_number(hdr_idx)
5254    ,p_event_date               => l_array_event_date(hdr_idx)
5255    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
5256    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
5257    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
5258    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
5259    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
5260    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
5261    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
5262    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
5263    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
5264    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
5265    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
5266    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
5267    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
5268    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
5269    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
5273 --
5270 
5271 --
5272 -- set the status of entry to C_VALID (0)
5274 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
5275 
5276 --
5277 -- initialize a row for ae header
5278 --
5279 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
5280 
5281 l_event_id := l_array_event_id(hdr_idx);
5282 
5283 --
5284 -- storing the hdr_idx for event. May be used by line cursor.
5285 --
5286 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
5287 
5288 --
5289 -- store sources from header extract. This can be improved to
5290 -- store only those sources from header extract that may be used in lines
5291 --
5292 
5293 g_array_event(l_event_id).array_value_char('source_1') := l_array_source_1(hdr_idx);
5294 g_array_event(l_event_id).array_value_num('source_2') := l_array_source_2(hdr_idx);
5295 g_array_event(l_event_id).array_value_num('source_8') := l_array_source_8(hdr_idx);
5296 g_array_event(l_event_id).array_value_char('source_10') := l_array_source_10(hdr_idx);
5297 g_array_event(l_event_id).array_value_char('source_15') := l_array_source_15(hdr_idx);
5298 g_array_event(l_event_id).array_value_num('source_16') := l_array_source_16(hdr_idx);
5299 g_array_event(l_event_id).array_value_date('source_17') := l_array_source_17(hdr_idx);
5300 
5301 --
5302 -- initilaize the status of ae headers for diffrent balance types
5303 -- the status is initialised to C_NOT_CREATED (2)
5304 --
5305 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
5306 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
5307 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
5308 
5309 --
5310 -- call api to validate and store accounting attributes for header
5311 --
5312 
5313 ------------------------------------------------------------
5314 -- Accrual Reversal : to get date for Standard Source (NONE)
5315 ------------------------------------------------------------
5316 l_acc_rev_gl_date_source := NULL;
5317 
5318      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
5319       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_17');
5320 
5321 
5322 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
5323 
5324 XLA_AE_HEADER_PKG.SetJeCategoryName;
5325 
5326 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
5327 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
5328 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
5329 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
5330 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
5331 
5332 
5333 
5334 
5335 --
5336 --accounting attribute enhancement, bug 3612931
5337 --
5338 l_trx_reversal_source := SUBSTR(NULL, 1,30);
5339 
5340 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
5341    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
5342 
5343    xla_accounting_err_pkg.build_message
5344       (p_appli_s_name            => 'XLA'
5345       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
5346       ,p_token_1                 => 'ACCT_ATTR_NAME'
5347       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
5348       ,p_token_2                 => 'PRODUCT_NAME'
5349       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
5350       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
5351       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
5352       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
5353 
5354 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
5355    --
5356    -- following sets the accounting attributes needed to reverse
5357    -- accounting for a distributeion
5358    --
5359    xla_ae_lines_pkg.SetTrxReversalAttrs
5360       (p_event_id              => l_event_id
5361       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
5362       ,p_trx_reversal_source   => l_trx_reversal_source);
5363 
5364 END IF;
5365 
5366 
5367 ----------------------------------------------------------------
5368 -- 4262811 -  update the header statuses to invalid in need be
5369 ----------------------------------------------------------------
5370 --
5371 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
5372 
5373 
5374   -----------------------------------------------
5375   -- No accrual reversal for the event class/type
5376   -----------------------------------------------
5377 ----------------------------------------------------------------
5378 
5379 --
5380 -- this ends the header loop iteration for one bulk fetch
5381 --
5382 END LOOP;
5383 
5384 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
5385 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
5386 
5387 --
5388 -- insert dummy rows into lines gt table that were created due to
5389 -- transaction reversals
5390 --
5391 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
5392    l_result := XLA_AE_LINES_PKG.InsertLines;
5393 END IF;
5394 
5395 --
5396 -- reset the temp_line_num for each set of events fetched from header
5397 -- cursor rather than doing it for each new event in line cursor
5398 -- Bug 3939231
5402 
5399 --
5400 xla_ae_lines_pkg.g_temp_line_num := 0;
5401 
5403 
5404 --
5405 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
5406 --
5407 --
5408 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5409 
5410       trace
5411          (p_msg      => 'SQL - FETCH line_cur'
5412          ,p_level    => C_LEVEL_STATEMENT
5413          ,p_module   => l_log_module);
5414 
5415 END IF;
5416 --
5417 --
5418 LOOP
5419   --
5420   FETCH line_cur BULK COLLECT INTO
5421         l_array_entity_id
5422       , l_array_legal_entity_id
5423       , l_array_entity_code
5424       , l_array_transaction_num
5425       , l_array_event_id
5426       , l_array_class_code
5427       , l_array_event_type
5428       , l_array_event_number
5429       , l_array_event_date
5430       , l_array_transaction_date
5431       , l_array_reference_num_1
5432       , l_array_reference_num_2
5433       , l_array_reference_num_3
5434       , l_array_reference_num_4
5435       , l_array_reference_char_1
5436       , l_array_reference_char_2
5437       , l_array_reference_char_3
5438       , l_array_reference_char_4
5439       , l_array_reference_date_1
5440       , l_array_reference_date_2
5441       , l_array_reference_date_3
5442       , l_array_reference_date_4
5443       , l_array_event_created_by
5444       , l_array_budgetary_control_flag
5445       , l_array_extract_line_num 
5446       , l_array_source_3
5447       , l_array_source_4
5448       , l_array_source_5
5449       , l_array_source_9
5450       , l_array_source_12
5451       , l_array_source_13
5452       , l_array_source_14
5453       LIMIT l_rows;
5454 
5455   --
5456   IF (C_LEVEL_EVENT >= g_log_level) THEN
5457             trace
5458                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
5459                ,p_level    => C_LEVEL_EVENT
5460                ,p_module   => l_log_module);
5461   END IF;
5462   --
5463   EXIT WHEN l_array_entity_id.count = 0;
5464 
5465   XLA_AE_LINES_PKG.g_rec_lines := null;
5466 
5467 --
5468 -- Bug 4458708
5469 --
5470 XLA_AE_LINES_PKG.g_LineNumber := 0;
5471 --
5472 --
5473 
5474 FOR Idx IN 1..l_array_event_id.count LOOP
5475    --
5476    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
5477    --
5478    l_event_id := l_array_event_id(idx);  -- 5648433
5479 
5480    --
5481    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
5482    --
5483 
5484    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
5485              (g_array_event(l_event_id).array_value_num('header_index'))
5486          ,'N'
5487          ) <> 'Y'
5488    THEN
5489       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5490          trace
5491             (p_msg      => 'Trancaction revesal option is not Y '
5492             ,p_level    => C_LEVEL_STATEMENT
5493             ,p_module   => l_log_module);
5494       END IF;
5495 
5496 --
5497 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
5498 --
5499 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
5500 --
5501 -- set event info as cache for other routines to refer event attributes
5502 --
5503 
5504 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
5505    l_previous_event_id := l_event_id;
5506 
5507    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
5508       (p_application_id           => p_application_id
5509       ,p_primary_ledger_id        => p_primary_ledger_id
5510       ,p_base_ledger_id           => p_base_ledger_id
5511       ,p_target_ledger_id         => p_target_ledger_id
5512       ,p_entity_id                => l_array_entity_id(Idx)
5513       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
5514       ,p_entity_code              => l_array_entity_code(Idx)
5515       ,p_transaction_num          => l_array_transaction_num(Idx)
5516       ,p_event_id                 => l_array_event_id(Idx)
5517       ,p_event_class_code         => l_array_class_code(Idx)
5518       ,p_event_type_code          => l_array_event_type(Idx)
5519       ,p_event_number             => l_array_event_number(Idx)
5520       ,p_event_date               => l_array_event_date(Idx)
5521       ,p_transaction_date         => l_array_transaction_date(Idx)
5522       ,p_reference_num_1          => l_array_reference_num_1(Idx)
5523       ,p_reference_num_2          => l_array_reference_num_2(Idx)
5524       ,p_reference_num_3          => l_array_reference_num_3(Idx)
5525       ,p_reference_num_4          => l_array_reference_num_4(Idx)
5526       ,p_reference_char_1         => l_array_reference_char_1(Idx)
5527       ,p_reference_char_2         => l_array_reference_char_2(Idx)
5528       ,p_reference_char_3         => l_array_reference_char_3(Idx)
5529       ,p_reference_char_4         => l_array_reference_char_4(Idx)
5530       ,p_reference_date_1         => l_array_reference_date_1(Idx)
5531       ,p_reference_date_2         => l_array_reference_date_2(Idx)
5532       ,p_reference_date_3         => l_array_reference_date_3(Idx)
5533       ,p_reference_date_4         => l_array_reference_date_4(Idx)
5534       ,p_event_created_by         => l_array_event_created_by(Idx)
5535       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
5536        --
5537 END IF;
5538 
5539 
5540 
5541 --
5542 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
5543 
5544 l_acct_reversal_source := SUBSTR(NULL, 1,30);
5545 
5546 IF l_continue_with_lines THEN
5550       xla_accounting_err_pkg.build_message
5547    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
5548       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
5549 
5551          (p_appli_s_name            => 'XLA'
5552          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
5553          ,p_token_1                 => 'LINE_NUMBER'
5554          ,p_value_1                 => l_array_extract_line_num(Idx)
5555          ,p_token_2                 => 'PRODUCT_NAME'
5556          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
5557          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
5558          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
5559          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
5560 
5561    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
5562       --
5563       -- following sets the accounting attributes needed to reverse
5564       -- accounting for a distributeion
5565       --
5566 
5567       --
5568       -- 5217187
5569       --
5570       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
5571       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
5572                                        g_array_event(l_event_id).array_value_num('header_index'));
5573       --
5574       --
5575 
5576       -- No reversal code generated
5577 
5578       xla_ae_lines_pkg.SetAcctReversalAttrs
5579          (p_event_id             => l_event_id
5580          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
5581          ,p_calculate_acctd_flag => l_calculate_acctd_flag
5582          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
5583    END IF;
5584 
5585    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
5586        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
5587 
5588 --
5589 AcctLineType_13 (
5590  p_application_id  => p_application_id
5591  ,p_event_id     => l_event_id
5592  ,p_calculate_acctd_flag => l_calculate_acctd_flag
5593  ,p_calculate_g_l_flag => l_calculate_g_l_flag
5594  ,p_actual_flag => l_actual_flag
5595  ,p_balance_type_code => l_balance_type_code
5596  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
5597  
5598  , p_source_1 => g_array_event(l_event_id).array_value_char('source_1')
5599  , p_source_2 => g_array_event(l_event_id).array_value_num('source_2')
5600  , p_source_3 => l_array_source_3(Idx)
5601  , p_source_4 => l_array_source_4(Idx)
5602  , p_source_5 => l_array_source_5(Idx)
5603  , p_source_8 => g_array_event(l_event_id).array_value_num('source_8')
5604  , p_source_9 => l_array_source_9(Idx)
5605  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
5606  , p_source_12 => l_array_source_12(Idx)
5607  , p_source_13 => l_array_source_13(Idx)
5608  , p_source_14 => l_array_source_14(Idx)
5609  , p_source_15 => g_array_event(l_event_id).array_value_char('source_15')
5610  , p_source_16 => g_array_event(l_event_id).array_value_num('source_16')
5611  );
5612 If(l_balance_type_code = 'A') THEN
5613   l_actual_gain_loss_ref := l_gain_or_loss_ref;
5614 END IF;
5615 
5616 --
5617 
5618 
5619 --
5620 AcctLineType_14 (
5621  p_application_id  => p_application_id
5622  ,p_event_id     => l_event_id
5623  ,p_calculate_acctd_flag => l_calculate_acctd_flag
5624  ,p_calculate_g_l_flag => l_calculate_g_l_flag
5625  ,p_actual_flag => l_actual_flag
5626  ,p_balance_type_code => l_balance_type_code
5627  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
5628  
5629  , p_source_1 => g_array_event(l_event_id).array_value_char('source_1')
5630  , p_source_2 => g_array_event(l_event_id).array_value_num('source_2')
5631  , p_source_3 => l_array_source_3(Idx)
5632  , p_source_4 => l_array_source_4(Idx)
5633  , p_source_5 => l_array_source_5(Idx)
5634  , p_source_8 => g_array_event(l_event_id).array_value_num('source_8')
5635  , p_source_9 => l_array_source_9(Idx)
5636  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
5637  , p_source_12 => l_array_source_12(Idx)
5638  , p_source_13 => l_array_source_13(Idx)
5639  , p_source_14 => l_array_source_14(Idx)
5640  , p_source_15 => g_array_event(l_event_id).array_value_char('source_15')
5641  , p_source_16 => g_array_event(l_event_id).array_value_num('source_16')
5642  );
5643 If(l_balance_type_code = 'A') THEN
5644   l_actual_gain_loss_ref := l_gain_or_loss_ref;
5645 END IF;
5646 
5647 --
5648 
5649       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
5653             (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'))
5650       -- or secondary ledger that has different currency with primary
5651       -- or alc that is calculated by sla
5652       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
5654 
5655 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
5656 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
5657           AND (l_actual_flag = 'A')) THEN
5658         XLA_AE_LINES_PKG.CreateGainOrLossLines(
5659           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
5660          ,p_application_id   => p_application_id
5661          ,p_amb_context_code => 'DEFAULT'
5662          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
5663          ,p_event_class_code => C_EVENT_CLASS_CODE
5664          ,p_event_type_code  => C_EVENT_TYPE_CODE
5665          
5666          ,p_gain_ccid        => -1
5667          ,p_loss_ccid        => -1
5668 
5669          ,p_actual_flag      => l_actual_flag
5670          ,p_enc_flag         => null
5671          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
5672          ,p_enc_g_l_ref      => null
5673          );
5674       END IF;
5675    END IF;
5676 END IF;
5677 
5678    ELSE
5679       --
5680       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
5681       --
5682       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5683          trace
5684             (p_msg      => 'Trancaction revesal option is Y'
5685             ,p_level    => C_LEVEL_STATEMENT
5686             ,p_module   => l_log_module);
5687       END IF;
5688    END IF;
5689 
5690 END LOOP;
5691 l_result := XLA_AE_LINES_PKG.InsertLines ;
5692 end loop;
5693 close line_cur;
5694 
5695 
5696 --
5697 -- insert headers into xla_ae_headers_gt table
5698 --
5699 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
5700 
5701 -- insert into errors table here.
5702 
5703 END LOOP;
5704 
5705 --
5706 -- 4865292
5707 --
5708 -- Compare g_hdr_extract_count with event count in
5709 -- CreateHeadersAndLines.
5710 --
5711 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
5712 
5713 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5714    trace (p_msg     => '# rows extracted from header extract objects '
5715                     || ' (running total): '
5716                     || g_hdr_extract_count
5717          ,p_level   => C_LEVEL_STATEMENT
5718          ,p_module  => l_log_module);
5719 END IF;
5720 
5721 CLOSE header_cur;
5722 --
5723 
5724 --
5725 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5726    trace
5727       (p_msg      => 'END of EventClass_15'
5728       ,p_level    => C_LEVEL_PROCEDURE
5729       ,p_module   => l_log_module);
5730 END IF;
5731 --
5732 RETURN l_result;
5733 EXCEPTION
5734 WHEN xla_exceptions_pkg.application_exception THEN
5735    
5736 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
5737 
5738    
5739 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
5740 
5741    RAISE;
5742 WHEN OTHERS THEN
5743    xla_exceptions_pkg.raise_message
5744       (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.EventClass_15');
5745 END EventClass_15;
5746 --
5747 
5748 ---------------------------------------
5749 --
5750 -- PRIVATE PROCEDURE
5751 --         insert_sources_16
5752 --
5753 ----------------------------------------
5754 --
5755 PROCEDURE insert_sources_16(
5756                                 p_target_ledger_id       IN NUMBER
5757                               , p_language               IN VARCHAR2
5758                               , p_sla_ledger_id          IN NUMBER
5759                               , p_pad_start_date         IN DATE
5760                               , p_pad_end_date           IN DATE
5761                          )
5762 IS
5763 
5764 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'RPR_BUDGET_EXECUTION_ALL';
5765 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'RPR_BUDGET_EXECUTION';
5766 p_apps_owner                   VARCHAR2(30);
5767 l_log_module                   VARCHAR2(240);
5768 BEGIN
5769 IF g_log_enabled THEN
5770       l_log_module := C_DEFAULT_MODULE||'.insert_sources_16';
5771 END IF;
5772 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5773 
5774       trace
5775          (p_msg      => 'BEGIN of insert_sources_16'
5779 END IF;
5776          ,p_level    => C_LEVEL_PROCEDURE
5777          ,p_module   => l_log_module);
5778 
5780 
5781 -- select APPS owner
5782 SELECT oracle_username
5783   INTO p_apps_owner
5784   FROM fnd_oracle_userid
5785  WHERE read_only_flag = 'U'
5786 ;
5787 
5788 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5789       trace
5790          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
5791                         ' - p_language = '||p_language||
5792                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
5793                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
5794                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
5795                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
5796          ,p_level    => C_LEVEL_STATEMENT
5797          ,p_module   => l_log_module);
5798 END IF;
5799 
5800 
5801 --
5802 INSERT INTO xla_diag_sources --hdr2
5803 (
5804         event_id
5805       , ledger_id
5806       , sla_ledger_id
5807       , description_language
5808       , object_name
5809       , object_type_code
5810       , line_number
5811       , source_application_id
5812       , source_type_code
5813       , source_code
5814       , source_value
5815       , source_meaning
5816       , created_by
5817       , creation_date
5818       , last_update_date
5819       , last_updated_by
5820       , last_update_login
5821       , program_update_date
5822       , program_application_id
5823       , program_id
5824       , request_id
5825 )
5826 SELECT
5827         event_id
5828       , p_target_ledger_id
5829       , p_sla_ledger_id
5830       , p_language
5831       , object_name
5832       , object_type_code
5833       , line_number
5834       , source_application_id
5835       , source_type_code
5836       , source_code
5837       , SUBSTR(source_value ,1,1996)
5838       , SUBSTR(source_meaning ,1,200)
5839       , xla_environment_pkg.g_Usr_Id
5840       , TRUNC(SYSDATE)
5841       , TRUNC(SYSDATE)
5842       , xla_environment_pkg.g_Usr_Id
5843       , xla_environment_pkg.g_Login_Id
5844       , TRUNC(SYSDATE)
5845       , xla_environment_pkg.g_Prog_Appl_Id
5846       , xla_environment_pkg.g_Prog_Id
5847       , xla_environment_pkg.g_Req_Id
5848   FROM (
5849        SELECT xet.event_id                  event_id
5850             , 0                          line_number
5851             , CASE r
5852                WHEN 1 THEN 'FV_BE_RPR_HDR_V' 
5853                 WHEN 2 THEN 'FV_BE_RPR_HDR_V' 
5854                 WHEN 3 THEN 'FV_BE_RPR_HDR_V' 
5855                 WHEN 4 THEN 'FV_BE_RPR_HDR_V' 
5856                 WHEN 5 THEN 'FV_BE_RPR_HDR_V' 
5857                 WHEN 6 THEN 'FV_BE_RPR_HDR_V' 
5858                 
5859                ELSE null
5860               END                           object_name
5861             , CASE r
5862                 WHEN 1 THEN 'HEADER' 
5863                 WHEN 2 THEN 'HEADER' 
5864                 WHEN 3 THEN 'HEADER' 
5865                 WHEN 4 THEN 'HEADER' 
5866                 WHEN 5 THEN 'HEADER' 
5867                 WHEN 6 THEN 'HEADER' 
5868                 
5869                 ELSE null
5870               END                           object_type_code
5871             , CASE r
5872                 WHEN 1 THEN '8901' 
5873                 WHEN 2 THEN '8901' 
5874                 WHEN 3 THEN '8901' 
5875                 WHEN 4 THEN '8901' 
5876                 WHEN 5 THEN '8901' 
5877                 WHEN 6 THEN '8901' 
5878                 
5879                 ELSE null
5880               END                           source_application_id
5881             , 'S'             source_type_code
5882             , CASE r
5883                 WHEN 1 THEN 'DOC_NUMBER' 
5884                 WHEN 2 THEN 'BUDGET_LEVEL_ID' 
5885                 WHEN 3 THEN 'SOURCE' 
5886                 WHEN 4 THEN 'TRANSACTION_ID' 
5887                 WHEN 5 THEN 'CURRENCY_CODE' 
5888                 WHEN 6 THEN 'GL_DATE' 
5889                 
5890                 ELSE null
5891               END                           source_code
5892             , CASE r
5893                 WHEN 1 THEN TO_CHAR(h2.DOC_NUMBER)
5894                 WHEN 2 THEN TO_CHAR(h2.BUDGET_LEVEL_ID)
5895                 WHEN 3 THEN TO_CHAR(h2.SOURCE)
5896                 WHEN 4 THEN TO_CHAR(h2.TRANSACTION_ID)
5897                 WHEN 5 THEN TO_CHAR(h2.CURRENCY_CODE)
5898                 WHEN 6 THEN TO_CHAR(h2.GL_DATE)
5899                 
5903          FROM xla_events_gt     xet  
5900                 ELSE null
5901               END                           source_value
5902             , null              source_meaning
5904       , FV_BE_RPR_HDR_V  h2
5905              ,(select rownum r from all_objects where rownum <= 6 and owner = p_apps_owner)
5906          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
5907            AND xet.event_class_code = C_EVENT_CLASS_CODE
5908               AND h2.event_id = xet.event_id
5909 
5910 )
5911 ;
5912 --
5913 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
5914 
5915       trace
5916          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
5917          ,p_level    => C_LEVEL_STATEMENT
5918          ,p_module   => l_log_module);
5919 
5920 END IF;
5921 --
5922 
5923 
5924 
5925 --
5926 INSERT INTO xla_diag_sources  --line2
5927 (
5928         event_id
5929       , ledger_id
5930       , sla_ledger_id
5931       , description_language
5932       , object_name
5933       , object_type_code
5934       , line_number
5935       , source_application_id
5936       , source_type_code
5937       , source_code
5938       , source_value
5939       , source_meaning
5940       , created_by
5941       , creation_date
5942       , last_update_date
5943       , last_updated_by
5944       , last_update_login
5945       , program_update_date
5946       , program_application_id
5947       , program_id
5948       , request_id
5949 )
5950 SELECT  event_id
5951       , p_target_ledger_id
5952       , p_sla_ledger_id
5953       , p_language
5954       , object_name
5955       , object_type_code
5956       , line_number
5957       , source_application_id
5958       , source_type_code
5959       , source_code
5960       , SUBSTR(source_value,1,1996)
5961       , SUBSTR(source_meaning ,1,200)
5962       , xla_environment_pkg.g_Usr_Id
5963       , TRUNC(SYSDATE)
5964       , TRUNC(SYSDATE)
5965       , xla_environment_pkg.g_Usr_Id
5966       , xla_environment_pkg.g_Login_Id
5967       , TRUNC(SYSDATE)
5968       , xla_environment_pkg.g_Prog_Appl_Id
5969       , xla_environment_pkg.g_Prog_Id
5970       , xla_environment_pkg.g_Req_Id
5971   FROM (
5972        SELECT xet.event_id                  event_id
5973             , l1.line_number                 line_number
5974             , CASE r
5975                WHEN 1 THEN 'FV_BE_RPR_DTL_V' 
5976                 WHEN 2 THEN 'FV_BE_RPR_DTL_V' 
5977                 WHEN 3 THEN 'FV_BE_RPR_DTL_V' 
5978                 WHEN 4 THEN 'FV_BE_RPR_DTL_V' 
5979                 WHEN 5 THEN 'FV_BE_RPR_DTL_V' 
5980                 WHEN 6 THEN 'FV_BE_RPR_DTL_V' 
5981                 WHEN 7 THEN 'FV_BE_RPR_DTL_V' 
5982                 
5983                ELSE null
5984               END                           object_name
5985             , CASE r
5986                 WHEN 1 THEN 'LINE' 
5987                 WHEN 2 THEN 'LINE' 
5988                 WHEN 3 THEN 'LINE' 
5989                 WHEN 4 THEN 'LINE' 
5990                 WHEN 5 THEN 'LINE' 
5991                 WHEN 6 THEN 'LINE' 
5992                 WHEN 7 THEN 'LINE' 
5993                 
5994                 ELSE null
5995               END                           object_type_code
5996             , CASE r
5997                 WHEN 1 THEN '8901' 
5998                 WHEN 2 THEN '8901' 
5999                 WHEN 3 THEN '8901' 
6000                 WHEN 4 THEN '8901' 
6001                 WHEN 5 THEN '8901' 
6002                 WHEN 6 THEN '8901' 
6003                 WHEN 7 THEN '8901' 
6004                 
6005                 ELSE null
6006               END                           source_application_id
6007             , 'S'             source_type_code
6008             , CASE r
6009                 WHEN 1 THEN 'CR_ACCOUNT_SEGMENT_VALUE' 
6010                 WHEN 2 THEN 'DR_ACCOUNT_SEGMENT_VALUE' 
6011                 WHEN 3 THEN 'DISTRIBUTION_FROM_ACCOUNT' 
6012                 WHEN 4 THEN 'DISTRIBUTION_TO_ACCOUNT' 
6013                 WHEN 5 THEN 'TRANSACTION_TYPE' 
6014                 WHEN 6 THEN 'TRANSACTION_TYPE_ID' 
6015                 WHEN 7 THEN 'ACCOUNTED_AMOUNT' 
6016                 
6017                 ELSE null
6018               END                           source_code
6019             , CASE r
6023                 WHEN 4 THEN TO_CHAR(l1.DISTRIBUTION_TO_ACCOUNT)
6020                 WHEN 1 THEN TO_CHAR(l1.CR_ACCOUNT_SEGMENT_VALUE)
6021                 WHEN 2 THEN TO_CHAR(l1.DR_ACCOUNT_SEGMENT_VALUE)
6022                 WHEN 3 THEN TO_CHAR(l1.DISTRIBUTION_FROM_ACCOUNT)
6024                 WHEN 5 THEN TO_CHAR(l1.TRANSACTION_TYPE)
6025                 WHEN 6 THEN TO_CHAR(l1.TRANSACTION_TYPE_ID)
6026                 WHEN 7 THEN TO_CHAR(l1.ACCOUNTED_AMOUNT)
6027                 
6028                 ELSE null
6029               END                           source_value
6030             , null              source_meaning
6031          FROM  xla_events_gt     xet  
6032         , FV_BE_RPR_DTL_V  l1
6033             , (select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
6034         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
6035           AND xet.event_class_code = C_EVENT_CLASS_CODE
6036             AND l1.event_id          = xet.event_id
6037 
6038 )
6039 ;
6040 --
6041 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6042 
6043       trace
6044          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
6045          ,p_level    => C_LEVEL_STATEMENT
6046          ,p_module   => l_log_module);
6047 
6048 END IF;
6049 
6050 
6051 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6052       trace
6053          (p_msg      => 'END of insert_sources_16'
6054          ,p_level    => C_LEVEL_PROCEDURE
6055          ,p_module   => l_log_module);
6056 END IF;
6057 EXCEPTION
6058   WHEN xla_exceptions_pkg.application_exception THEN
6059       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6060             trace
6061                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
6062                ,p_level    => C_LEVEL_EXCEPTION
6063                ,p_module   => l_log_module);
6064       END IF;
6065       RAISE;
6066   WHEN OTHERS THEN
6067       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6068             trace
6069                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
6070                ,p_level    => C_LEVEL_EXCEPTION
6071                ,p_module   => l_log_module);
6072        END IF;
6073        xla_exceptions_pkg.raise_message
6074            (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.insert_sources_16');
6075 END insert_sources_16;
6076 --
6077 
6078 ---------------------------------------
6079 --
6080 -- PRIVATE FUNCTION
6081 --         EventClass_16
6082 --
6083 ----------------------------------------
6084 --
6085 FUNCTION EventClass_16
6086        (p_application_id         IN NUMBER
6087        ,p_base_ledger_id         IN NUMBER
6088        ,p_target_ledger_id       IN NUMBER
6089        ,p_language               IN VARCHAR2
6090        ,p_currency_code          IN VARCHAR2
6091        ,p_sla_ledger_id          IN NUMBER
6092        ,p_pad_start_date         IN DATE
6093        ,p_pad_end_date           IN DATE
6094        ,p_primary_ledger_id      IN NUMBER)
6095 RETURN BOOLEAN IS
6096 --
6097 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'RPR_BUDGET_EXECUTION_ALL';
6098 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'RPR_BUDGET_EXECUTION';
6099 
6100 l_calculate_acctd_flag   VARCHAR2(1) :='N';
6101 l_calculate_g_l_flag     VARCHAR2(1) :='N';
6102 --
6103 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6104 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6105 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
6106 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
6107 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6108 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
6109 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
6110 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6111 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
6112 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
6113 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6114 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6115 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6116 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6117 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
6118 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
6122 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
6119 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
6120 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
6121 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
6123 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
6124 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
6125 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
6126 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
6127 
6128 l_event_id                             NUMBER;
6129 l_previous_event_id                    NUMBER;
6130 l_first_event_id                       NUMBER;
6131 l_last_event_id                        NUMBER;
6132 
6133 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
6134 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
6135 --
6136 --
6137 l_result                    BOOLEAN := TRUE;
6138 l_rows                      NUMBER  := 1000;
6139 l_event_type_name           VARCHAR2(80) := 'All';
6140 l_event_class_name          VARCHAR2(80) := 'Reprogram Budget Execution Transactions';
6141 l_description               VARCHAR2(4000);
6142 l_transaction_reversal      NUMBER;
6143 l_ae_header_id              NUMBER;
6144 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
6145 l_log_module                VARCHAR2(240);
6146 --
6147 l_acct_reversal_source      VARCHAR2(30);
6148 l_trx_reversal_source       VARCHAR2(30);
6149 
6150 l_continue_with_lines       BOOLEAN := TRUE;
6151 --
6152 l_acc_rev_gl_date_source    DATE;                      -- 4262811
6153 --
6154 type t_array_event_id is table of number index by binary_integer;
6155 
6156 l_rec_array_event                    t_rec_array_event;
6157 l_null_rec_array_event               t_rec_array_event;
6158 l_array_ae_header_id                 xla_number_array_type;
6159 l_actual_flag                        VARCHAR2(1) := NULL;
6160 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
6161 l_balance_type_code                  VARCHAR2(1) :=NULL;
6162 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
6163 
6164 --
6165 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
6166 --
6167 
6168 TYPE t_array_source_1 IS TABLE OF FV_BE_RPR_HDR_V.DOC_NUMBER%TYPE INDEX BY BINARY_INTEGER;
6169 TYPE t_array_source_2 IS TABLE OF FV_BE_RPR_HDR_V.BUDGET_LEVEL_ID%TYPE INDEX BY BINARY_INTEGER;
6170 TYPE t_array_source_10 IS TABLE OF FV_BE_RPR_HDR_V.SOURCE%TYPE INDEX BY BINARY_INTEGER;
6171 TYPE t_array_source_11 IS TABLE OF FV_BE_RPR_HDR_V.TRANSACTION_ID%TYPE INDEX BY BINARY_INTEGER;
6172 TYPE t_array_source_15 IS TABLE OF FV_BE_RPR_HDR_V.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
6173 TYPE t_array_source_17 IS TABLE OF FV_BE_RPR_HDR_V.GL_DATE%TYPE INDEX BY BINARY_INTEGER;
6174 
6175 TYPE t_array_source_3 IS TABLE OF FV_BE_RPR_DTL_V.CR_ACCOUNT_SEGMENT_VALUE%TYPE INDEX BY BINARY_INTEGER;
6176 TYPE t_array_source_4 IS TABLE OF FV_BE_RPR_DTL_V.DR_ACCOUNT_SEGMENT_VALUE%TYPE INDEX BY BINARY_INTEGER;
6177 TYPE t_array_source_6 IS TABLE OF FV_BE_RPR_DTL_V.DISTRIBUTION_FROM_ACCOUNT%TYPE INDEX BY BINARY_INTEGER;
6178 TYPE t_array_source_7 IS TABLE OF FV_BE_RPR_DTL_V.DISTRIBUTION_TO_ACCOUNT%TYPE INDEX BY BINARY_INTEGER;
6179 TYPE t_array_source_12 IS TABLE OF FV_BE_RPR_DTL_V.TRANSACTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
6180 TYPE t_array_source_13 IS TABLE OF FV_BE_RPR_DTL_V.TRANSACTION_TYPE_ID%TYPE INDEX BY BINARY_INTEGER;
6181 TYPE t_array_source_14 IS TABLE OF FV_BE_RPR_DTL_V.ACCOUNTED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
6182 
6183 l_array_source_1              t_array_source_1;
6184 l_array_source_2              t_array_source_2;
6185 l_array_source_10              t_array_source_10;
6186 l_array_source_11              t_array_source_11;
6187 l_array_source_15              t_array_source_15;
6188 l_array_source_17              t_array_source_17;
6189 
6190 l_array_source_3      t_array_source_3;
6191 l_array_source_4      t_array_source_4;
6192 l_array_source_6      t_array_source_6;
6193 l_array_source_7      t_array_source_7;
6194 l_array_source_12      t_array_source_12;
6195 l_array_source_13      t_array_source_13;
6196 l_array_source_14      t_array_source_14;
6197 
6198 --
6199 CURSOR header_cur
6200 IS
6201 SELECT /*+ leading(xet) cardinality(xet,1) */
6202 -- Event Class Code: RPR_BUDGET_EXECUTION
6203     xet.entity_id
6204    ,xet.legal_entity_id
6205    ,xet.entity_code
6206    ,xet.transaction_number
6207    ,xet.event_id
6208    ,xet.event_class_code
6209    ,xet.event_type_code
6213    ,xet.reference_num_1
6210    ,xet.event_number
6211    ,xet.event_date
6212    ,xet.transaction_date
6214    ,xet.reference_num_2
6215    ,xet.reference_num_3
6216    ,xet.reference_num_4
6217    ,xet.reference_char_1
6218    ,xet.reference_char_2
6219    ,xet.reference_char_3
6220    ,xet.reference_char_4
6221    ,xet.reference_date_1
6222    ,xet.reference_date_2
6223    ,xet.reference_date_3
6224    ,xet.reference_date_4
6225    ,xet.event_created_by
6226    ,xet.budgetary_control_flag 
6227   , h2.DOC_NUMBER    source_1
6228   , h2.BUDGET_LEVEL_ID    source_2
6229   , h2.SOURCE    source_10
6230   , h2.TRANSACTION_ID    source_11
6231   , h2.CURRENCY_CODE    source_15
6232   , h2.GL_DATE    source_17
6233   FROM xla_events_gt     xet 
6234   , FV_BE_RPR_HDR_V  h2
6235  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
6236    and xet.event_class_code = C_EVENT_CLASS_CODE
6237    and xet.event_status_code <> 'N'  AND h2.event_id = xet.event_id
6238 
6239  ORDER BY event_id
6240 ;
6241 
6242 
6243 --
6244 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
6245 IS
6246 SELECT  /*+ leading(xet) cardinality(xet,1) */
6247 -- Event Class Code: RPR_BUDGET_EXECUTION
6248     xet.entity_id
6249    ,xet.legal_entity_id
6250    ,xet.entity_code
6251    ,xet.transaction_number
6252    ,xet.event_id
6253    ,xet.event_class_code
6254    ,xet.event_type_code
6255    ,xet.event_number
6256    ,xet.event_date
6257    ,xet.transaction_date
6258    ,xet.reference_num_1
6259    ,xet.reference_num_2
6260    ,xet.reference_num_3
6261    ,xet.reference_num_4
6262    ,xet.reference_char_1
6263    ,xet.reference_char_2
6264    ,xet.reference_char_3
6265    ,xet.reference_char_4
6266    ,xet.reference_date_1
6267    ,xet.reference_date_2
6268    ,xet.reference_date_3
6269    ,xet.reference_date_4
6270    ,xet.event_created_by
6271    ,xet.budgetary_control_flag
6272  , l1.LINE_NUMBER  
6273   , l1.CR_ACCOUNT_SEGMENT_VALUE    source_3
6274   , l1.DR_ACCOUNT_SEGMENT_VALUE    source_4
6275   , l1.DISTRIBUTION_FROM_ACCOUNT    source_6
6276   , l1.DISTRIBUTION_TO_ACCOUNT    source_7
6277   , l1.TRANSACTION_TYPE    source_12
6278   , l1.TRANSACTION_TYPE_ID    source_13
6279   , l1.ACCOUNTED_AMOUNT    source_14
6280   FROM xla_events_gt     xet 
6281   , FV_BE_RPR_DTL_V  l1
6282  WHERE xet.event_id between x_first_event_id and x_last_event_id
6283    and xet.event_date between p_pad_start_date and p_pad_end_date
6284    and xet.event_class_code = C_EVENT_CLASS_CODE
6285    and xet.event_status_code <> 'N'   AND l1.event_id      = xet.event_id
6286 ;
6287 
6288 --
6289 BEGIN
6290 IF g_log_enabled THEN
6291    l_log_module := C_DEFAULT_MODULE||'.EventClass_16';
6292 END IF;
6293 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6294    trace
6295       (p_msg      => 'BEGIN of EventClass_16'
6296       ,p_level    => C_LEVEL_PROCEDURE
6297       ,p_module   => l_log_module);
6298 END IF;
6299 
6300 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6301    trace
6302       (p_msg      => 'p_application_id = '||p_application_id||
6303                      ' - p_base_ledger_id = '||p_base_ledger_id||
6304                      ' - p_target_ledger_id  = '||p_target_ledger_id||
6305                      ' - p_language = '||p_language||
6306                      ' - p_currency_code = '||p_currency_code||
6307                      ' - p_sla_ledger_id = '||p_sla_ledger_id
6308       ,p_level    => C_LEVEL_STATEMENT
6309       ,p_module   => l_log_module);
6310 END IF;
6311 --
6312 -- initialze arrays
6313 --
6314 g_array_event.DELETE;
6315 l_rec_array_event := l_null_rec_array_event;
6316 --
6317 --------------------------------------
6318 -- 4262811 Initialze MPA Line Number
6319 --------------------------------------
6320 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
6321 
6322 --
6323 
6324 --
6325 OPEN header_cur;
6326 --
6327 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6328    trace
6329    (p_msg      => 'SQL - FETCH header_cur'
6330    ,p_level    => C_LEVEL_STATEMENT
6331    ,p_module   => l_log_module);
6332 END IF;
6333 --
6334 LOOP
6335 FETCH header_cur BULK COLLECT INTO
6336         l_array_entity_id
6337       , l_array_legal_entity_id
6338       , l_array_entity_code
6339       , l_array_transaction_num
6340       , l_array_event_id
6341       , l_array_class_code
6342       , l_array_event_type
6346       , l_array_reference_num_1
6343       , l_array_event_number
6344       , l_array_event_date
6345       , l_array_transaction_date
6347       , l_array_reference_num_2
6348       , l_array_reference_num_3
6349       , l_array_reference_num_4
6350       , l_array_reference_char_1
6351       , l_array_reference_char_2
6352       , l_array_reference_char_3
6353       , l_array_reference_char_4
6354       , l_array_reference_date_1
6355       , l_array_reference_date_2
6356       , l_array_reference_date_3
6357       , l_array_reference_date_4
6358       , l_array_event_created_by
6359       , l_array_budgetary_control_flag 
6360       , l_array_source_1
6361       , l_array_source_2
6362       , l_array_source_10
6363       , l_array_source_11
6364       , l_array_source_15
6365       , l_array_source_17
6366       LIMIT l_rows;
6367 --
6368 IF (C_LEVEL_EVENT >= g_log_level) THEN
6369    trace
6370    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
6371    ,p_level    => C_LEVEL_EVENT
6372    ,p_module   => l_log_module);
6373 END IF;
6374 --
6375 EXIT WHEN l_array_entity_id.COUNT = 0;
6376 
6377 -- initialize arrays
6378 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
6379 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
6380 
6381 --
6382 -- Bug 4458708
6383 --
6384 XLA_AE_LINES_PKG.g_LineNumber := 0;
6385 
6386 
6387 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
6388 g_last_hdr_idx := l_array_event_id.LAST;
6389 --
6390 -- loop for the headers. Each iteration is for each header extract row
6391 -- fetched in header cursor
6392 --
6393 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
6394 
6395 --
6396 -- set event info as cache for other routines to refer event attributes
6397 --
6398 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
6399    (p_application_id           => p_application_id
6400    ,p_primary_ledger_id        => p_primary_ledger_id
6401    ,p_base_ledger_id           => p_base_ledger_id
6402    ,p_target_ledger_id         => p_target_ledger_id
6403    ,p_entity_id                => l_array_entity_id(hdr_idx)
6404    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
6405    ,p_entity_code              => l_array_entity_code(hdr_idx)
6406    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
6407    ,p_event_id                 => l_array_event_id(hdr_idx)
6408    ,p_event_class_code         => l_array_class_code(hdr_idx)
6409    ,p_event_type_code          => l_array_event_type(hdr_idx)
6410    ,p_event_number             => l_array_event_number(hdr_idx)
6411    ,p_event_date               => l_array_event_date(hdr_idx)
6412    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
6413    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
6414    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
6415    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
6416    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
6417    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
6418    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
6419    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
6420    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
6421    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
6422    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
6423    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
6424    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
6425    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
6426    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
6427 
6428 --
6429 -- set the status of entry to C_VALID (0)
6430 --
6431 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
6432 
6433 --
6434 -- initialize a row for ae header
6435 --
6436 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
6437 
6438 l_event_id := l_array_event_id(hdr_idx);
6439 
6440 --
6441 -- storing the hdr_idx for event. May be used by line cursor.
6442 --
6443 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
6444 
6445 --
6446 -- store sources from header extract. This can be improved to
6447 -- store only those sources from header extract that may be used in lines
6448 --
6449 
6450 g_array_event(l_event_id).array_value_char('source_1') := l_array_source_1(hdr_idx);
6451 g_array_event(l_event_id).array_value_num('source_2') := l_array_source_2(hdr_idx);
6455 g_array_event(l_event_id).array_value_date('source_17') := l_array_source_17(hdr_idx);
6452 g_array_event(l_event_id).array_value_char('source_10') := l_array_source_10(hdr_idx);
6453 g_array_event(l_event_id).array_value_num('source_11') := l_array_source_11(hdr_idx);
6454 g_array_event(l_event_id).array_value_char('source_15') := l_array_source_15(hdr_idx);
6456 
6457 --
6458 -- initilaize the status of ae headers for diffrent balance types
6459 -- the status is initialised to C_NOT_CREATED (2)
6460 --
6461 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
6462 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
6463 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
6464 
6465 --
6466 -- call api to validate and store accounting attributes for header
6467 --
6468 
6469 ------------------------------------------------------------
6470 -- Accrual Reversal : to get date for Standard Source (NONE)
6471 ------------------------------------------------------------
6472 l_acc_rev_gl_date_source := NULL;
6473 
6474      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
6475       l_rec_acct_attrs.array_date_value(1) := g_array_event(l_event_id).array_value_date('source_17');
6476 
6477 
6478 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
6479 
6480 XLA_AE_HEADER_PKG.SetJeCategoryName;
6481 
6482 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
6483 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
6484 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
6485 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
6486 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
6487 
6488 
6489 
6490 
6491 --
6492 --accounting attribute enhancement, bug 3612931
6493 --
6494 l_trx_reversal_source := SUBSTR(NULL, 1,30);
6495 
6496 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
6497    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
6498 
6499    xla_accounting_err_pkg.build_message
6500       (p_appli_s_name            => 'XLA'
6501       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
6502       ,p_token_1                 => 'ACCT_ATTR_NAME'
6503       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
6504       ,p_token_2                 => 'PRODUCT_NAME'
6505       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
6506       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
6507       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
6508       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
6509 
6510 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
6511    --
6512    -- following sets the accounting attributes needed to reverse
6513    -- accounting for a distributeion
6514    --
6515    xla_ae_lines_pkg.SetTrxReversalAttrs
6516       (p_event_id              => l_event_id
6517       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
6518       ,p_trx_reversal_source   => l_trx_reversal_source);
6519 
6520 END IF;
6521 
6522 
6523 ----------------------------------------------------------------
6524 -- 4262811 -  update the header statuses to invalid in need be
6525 ----------------------------------------------------------------
6526 --
6527 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
6528 
6529 
6530   -----------------------------------------------
6531   -- No accrual reversal for the event class/type
6532   -----------------------------------------------
6533 ----------------------------------------------------------------
6534 
6535 --
6536 -- this ends the header loop iteration for one bulk fetch
6537 --
6538 END LOOP;
6539 
6540 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
6541 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
6542 
6543 --
6544 -- insert dummy rows into lines gt table that were created due to
6545 -- transaction reversals
6546 --
6547 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
6548    l_result := XLA_AE_LINES_PKG.InsertLines;
6549 END IF;
6550 
6551 --
6552 -- reset the temp_line_num for each set of events fetched from header
6556 xla_ae_lines_pkg.g_temp_line_num := 0;
6553 -- cursor rather than doing it for each new event in line cursor
6554 -- Bug 3939231
6555 --
6557 
6558 
6559 
6560 --
6561 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
6562 --
6563 --
6564 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6565 
6566       trace
6567          (p_msg      => 'SQL - FETCH line_cur'
6568          ,p_level    => C_LEVEL_STATEMENT
6569          ,p_module   => l_log_module);
6570 
6571 END IF;
6572 --
6573 --
6574 LOOP
6575   --
6576   FETCH line_cur BULK COLLECT INTO
6577         l_array_entity_id
6578       , l_array_legal_entity_id
6579       , l_array_entity_code
6580       , l_array_transaction_num
6581       , l_array_event_id
6582       , l_array_class_code
6583       , l_array_event_type
6584       , l_array_event_number
6585       , l_array_event_date
6586       , l_array_transaction_date
6587       , l_array_reference_num_1
6588       , l_array_reference_num_2
6589       , l_array_reference_num_3
6590       , l_array_reference_num_4
6591       , l_array_reference_char_1
6592       , l_array_reference_char_2
6593       , l_array_reference_char_3
6594       , l_array_reference_char_4
6595       , l_array_reference_date_1
6596       , l_array_reference_date_2
6597       , l_array_reference_date_3
6598       , l_array_reference_date_4
6599       , l_array_event_created_by
6600       , l_array_budgetary_control_flag
6601       , l_array_extract_line_num 
6602       , l_array_source_3
6603       , l_array_source_4
6604       , l_array_source_6
6605       , l_array_source_7
6606       , l_array_source_12
6607       , l_array_source_13
6608       , l_array_source_14
6609       LIMIT l_rows;
6610 
6611   --
6612   IF (C_LEVEL_EVENT >= g_log_level) THEN
6613             trace
6614                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
6615                ,p_level    => C_LEVEL_EVENT
6616                ,p_module   => l_log_module);
6617   END IF;
6618   --
6619   EXIT WHEN l_array_entity_id.count = 0;
6620 
6621   XLA_AE_LINES_PKG.g_rec_lines := null;
6622 
6623 --
6624 -- Bug 4458708
6625 --
6626 XLA_AE_LINES_PKG.g_LineNumber := 0;
6627 --
6628 --
6629 
6630 FOR Idx IN 1..l_array_event_id.count LOOP
6631    --
6632    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
6633    --
6634    l_event_id := l_array_event_id(idx);  -- 5648433
6635 
6636    --
6637    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
6638    --
6639 
6640    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
6641              (g_array_event(l_event_id).array_value_num('header_index'))
6642          ,'N'
6643          ) <> 'Y'
6644    THEN
6645       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6646          trace
6647             (p_msg      => 'Trancaction revesal option is not Y '
6648             ,p_level    => C_LEVEL_STATEMENT
6649             ,p_module   => l_log_module);
6650       END IF;
6651 
6652 --
6653 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
6654 --
6655 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
6656 --
6657 -- set event info as cache for other routines to refer event attributes
6658 --
6659 
6660 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
6661    l_previous_event_id := l_event_id;
6662 
6663    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
6664       (p_application_id           => p_application_id
6665       ,p_primary_ledger_id        => p_primary_ledger_id
6666       ,p_base_ledger_id           => p_base_ledger_id
6667       ,p_target_ledger_id         => p_target_ledger_id
6668       ,p_entity_id                => l_array_entity_id(Idx)
6669       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
6670       ,p_entity_code              => l_array_entity_code(Idx)
6671       ,p_transaction_num          => l_array_transaction_num(Idx)
6672       ,p_event_id                 => l_array_event_id(Idx)
6673       ,p_event_class_code         => l_array_class_code(Idx)
6674       ,p_event_type_code          => l_array_event_type(Idx)
6675       ,p_event_number             => l_array_event_number(Idx)
6676       ,p_event_date               => l_array_event_date(Idx)
6677       ,p_transaction_date         => l_array_transaction_date(Idx)
6678       ,p_reference_num_1          => l_array_reference_num_1(Idx)
6682       ,p_reference_char_1         => l_array_reference_char_1(Idx)
6679       ,p_reference_num_2          => l_array_reference_num_2(Idx)
6680       ,p_reference_num_3          => l_array_reference_num_3(Idx)
6681       ,p_reference_num_4          => l_array_reference_num_4(Idx)
6683       ,p_reference_char_2         => l_array_reference_char_2(Idx)
6684       ,p_reference_char_3         => l_array_reference_char_3(Idx)
6685       ,p_reference_char_4         => l_array_reference_char_4(Idx)
6686       ,p_reference_date_1         => l_array_reference_date_1(Idx)
6687       ,p_reference_date_2         => l_array_reference_date_2(Idx)
6688       ,p_reference_date_3         => l_array_reference_date_3(Idx)
6689       ,p_reference_date_4         => l_array_reference_date_4(Idx)
6690       ,p_event_created_by         => l_array_event_created_by(Idx)
6691       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
6692        --
6693 END IF;
6694 
6695 
6696 
6697 --
6698 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
6699 
6700 l_acct_reversal_source := SUBSTR(NULL, 1,30);
6701 
6702 IF l_continue_with_lines THEN
6703    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
6704       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
6705 
6706       xla_accounting_err_pkg.build_message
6707          (p_appli_s_name            => 'XLA'
6708          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
6709          ,p_token_1                 => 'LINE_NUMBER'
6710          ,p_value_1                 => l_array_extract_line_num(Idx)
6711          ,p_token_2                 => 'PRODUCT_NAME'
6712          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
6713          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
6714          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
6715          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
6716 
6717    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
6718       --
6719       -- following sets the accounting attributes needed to reverse
6720       -- accounting for a distributeion
6721       --
6722 
6723       --
6724       -- 5217187
6725       --
6726       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
6727       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
6728                                        g_array_event(l_event_id).array_value_num('header_index'));
6729       --
6730       --
6731 
6732       -- No reversal code generated
6733 
6734       xla_ae_lines_pkg.SetAcctReversalAttrs
6735          (p_event_id             => l_event_id
6736          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
6737          ,p_calculate_acctd_flag => l_calculate_acctd_flag
6738          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
6739    END IF;
6740 
6741    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
6742        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
6743 
6744 --
6745 AcctLineType_9 (
6746  p_application_id  => p_application_id
6747  ,p_event_id     => l_event_id
6748  ,p_calculate_acctd_flag => l_calculate_acctd_flag
6749  ,p_calculate_g_l_flag => l_calculate_g_l_flag
6750  ,p_actual_flag => l_actual_flag
6751  ,p_balance_type_code => l_balance_type_code
6752  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
6753  
6754  , p_source_1 => g_array_event(l_event_id).array_value_char('source_1')
6755  , p_source_2 => g_array_event(l_event_id).array_value_num('source_2')
6756  , p_source_4 => l_array_source_4(Idx)
6757  , p_source_6 => l_array_source_6(Idx)
6758  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
6759  , p_source_11 => g_array_event(l_event_id).array_value_num('source_11')
6760  , p_source_12 => l_array_source_12(Idx)
6761  , p_source_13 => l_array_source_13(Idx)
6762  , p_source_14 => l_array_source_14(Idx)
6763  , p_source_15 => g_array_event(l_event_id).array_value_char('source_15')
6764  );
6765 If(l_balance_type_code = 'A') THEN
6766   l_actual_gain_loss_ref := l_gain_or_loss_ref;
6767 END IF;
6768 
6769 --
6770 
6771 
6772 --
6773 AcctLineType_10 (
6774  p_application_id  => p_application_id
6775  ,p_event_id     => l_event_id
6776  ,p_calculate_acctd_flag => l_calculate_acctd_flag
6777  ,p_calculate_g_l_flag => l_calculate_g_l_flag
6778  ,p_actual_flag => l_actual_flag
6779  ,p_balance_type_code => l_balance_type_code
6780  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
6781  
6782  , p_source_1 => g_array_event(l_event_id).array_value_char('source_1')
6786  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
6783  , p_source_2 => g_array_event(l_event_id).array_value_num('source_2')
6784  , p_source_3 => l_array_source_3(Idx)
6785  , p_source_6 => l_array_source_6(Idx)
6787  , p_source_11 => g_array_event(l_event_id).array_value_num('source_11')
6788  , p_source_12 => l_array_source_12(Idx)
6789  , p_source_13 => l_array_source_13(Idx)
6790  , p_source_14 => l_array_source_14(Idx)
6791  , p_source_15 => g_array_event(l_event_id).array_value_char('source_15')
6792  );
6793 If(l_balance_type_code = 'A') THEN
6794   l_actual_gain_loss_ref := l_gain_or_loss_ref;
6795 END IF;
6796 
6797 --
6798 
6799 
6800 --
6801 AcctLineType_11 (
6802  p_application_id  => p_application_id
6803  ,p_event_id     => l_event_id
6804  ,p_calculate_acctd_flag => l_calculate_acctd_flag
6805  ,p_calculate_g_l_flag => l_calculate_g_l_flag
6806  ,p_actual_flag => l_actual_flag
6807  ,p_balance_type_code => l_balance_type_code
6808  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
6809  
6810  , p_source_1 => g_array_event(l_event_id).array_value_char('source_1')
6811  , p_source_2 => g_array_event(l_event_id).array_value_num('source_2')
6812  , p_source_3 => l_array_source_3(Idx)
6813  , p_source_7 => l_array_source_7(Idx)
6814  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
6815  , p_source_11 => g_array_event(l_event_id).array_value_num('source_11')
6816  , p_source_12 => l_array_source_12(Idx)
6817  , p_source_13 => l_array_source_13(Idx)
6818  , p_source_14 => l_array_source_14(Idx)
6819  , p_source_15 => g_array_event(l_event_id).array_value_char('source_15')
6820  );
6821 If(l_balance_type_code = 'A') THEN
6822   l_actual_gain_loss_ref := l_gain_or_loss_ref;
6823 END IF;
6824 
6825 --
6826 
6827 
6828 --
6829 AcctLineType_12 (
6830  p_application_id  => p_application_id
6831  ,p_event_id     => l_event_id
6832  ,p_calculate_acctd_flag => l_calculate_acctd_flag
6833  ,p_calculate_g_l_flag => l_calculate_g_l_flag
6834  ,p_actual_flag => l_actual_flag
6835  ,p_balance_type_code => l_balance_type_code
6836  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
6837  
6838  , p_source_1 => g_array_event(l_event_id).array_value_char('source_1')
6839  , p_source_2 => g_array_event(l_event_id).array_value_num('source_2')
6840  , p_source_4 => l_array_source_4(Idx)
6841  , p_source_7 => l_array_source_7(Idx)
6842  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
6843  , p_source_11 => g_array_event(l_event_id).array_value_num('source_11')
6844  , p_source_12 => l_array_source_12(Idx)
6845  , p_source_13 => l_array_source_13(Idx)
6846  , p_source_14 => l_array_source_14(Idx)
6847  , p_source_15 => g_array_event(l_event_id).array_value_char('source_15')
6848  );
6849 If(l_balance_type_code = 'A') THEN
6850   l_actual_gain_loss_ref := l_gain_or_loss_ref;
6851 END IF;
6852 
6853 --
6854 
6855       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
6856       -- or secondary ledger that has different currency with primary
6857       -- or alc that is calculated by sla
6858       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
6859             (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'))
6860 
6861 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
6862 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
6863           AND (l_actual_flag = 'A')) THEN
6864         XLA_AE_LINES_PKG.CreateGainOrLossLines(
6865           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
6866          ,p_application_id   => p_application_id
6867          ,p_amb_context_code => 'DEFAULT'
6868          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
6869          ,p_event_class_code => C_EVENT_CLASS_CODE
6870          ,p_event_type_code  => C_EVENT_TYPE_CODE
6871          
6872          ,p_gain_ccid        => -1
6873          ,p_loss_ccid        => -1
6874 
6875          ,p_actual_flag      => l_actual_flag
6876          ,p_enc_flag         => null
6877          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
6878          ,p_enc_g_l_ref      => null
6879          );
6880       END IF;
6881    END IF;
6882 END IF;
6883 
6884    ELSE
6885       --
6886       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
6887       --
6888       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6889          trace
6890             (p_msg      => 'Trancaction revesal option is Y'
6891             ,p_level    => C_LEVEL_STATEMENT
6892             ,p_module   => l_log_module);
6893       END IF;
6894    END IF;
6895 
6896 END LOOP;
6897 l_result := XLA_AE_LINES_PKG.InsertLines ;
6898 end loop;
6899 close line_cur;
6900 
6901 
6902 --
6903 -- insert headers into xla_ae_headers_gt table
6904 --
6905 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
6906 
6907 -- insert into errors table here.
6908 
6909 END LOOP;
6910 
6911 --
6912 -- 4865292
6913 --
6914 -- Compare g_hdr_extract_count with event count in
6915 -- CreateHeadersAndLines.
6916 --
6917 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
6918 
6919 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6920    trace (p_msg     => '# rows extracted from header extract objects '
6921                     || ' (running total): '
6922                     || g_hdr_extract_count
6923          ,p_level   => C_LEVEL_STATEMENT
6924          ,p_module  => l_log_module);
6925 END IF;
6926 
6927 CLOSE header_cur;
6928 --
6929 
6930 --
6931 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6932    trace
6933       (p_msg      => 'END of EventClass_16'
6934       ,p_level    => C_LEVEL_PROCEDURE
6935       ,p_module   => l_log_module);
6936 END IF;
6937 --
6938 RETURN l_result;
6939 EXCEPTION
6940 WHEN xla_exceptions_pkg.application_exception THEN
6941    
6942 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
6943 
6944    
6945 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
6946 
6947    RAISE;
6948 WHEN OTHERS THEN
6949    xla_exceptions_pkg.raise_message
6950       (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.EventClass_16');
6951 END EventClass_16;
6952 --
6953 
6954 --
6955 --+============================================+
6956 --|                                            |
6957 --|  PRIVATE FUNCTION                          |
6958 --|                                            |
6959 --+============================================+
6960 --
6961 FUNCTION CreateHeadersAndLines
6962        (p_application_id         IN NUMBER
6963        ,p_base_ledger_id         IN NUMBER
6964        ,p_target_ledger_id       IN NUMBER
6965        ,p_pad_start_date         IN DATE
6966        ,p_pad_end_date           IN DATE
6967        ,p_primary_ledger_id      IN NUMBER)
6968 RETURN BOOLEAN IS
6969 l_created                   BOOLEAN:=FALSE;
6970 l_event_id                  NUMBER;
6971 l_event_date                DATE;
6972 l_language                  VARCHAR2(30);
6973 l_currency_code             VARCHAR2(30);
6974 l_sla_ledger_id             NUMBER;
6975 l_log_module                VARCHAR2(240);
6976 
6977 BEGIN
6978 --
6979 IF g_log_enabled THEN
6980    l_log_module := C_DEFAULT_MODULE||'.CreateHeadersAndLines';
6981 END IF;
6982 --
6983 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6984    trace
6985       (p_msg      => 'BEGIN of CreateHeadersAndLines'
6986       ,p_level    => C_LEVEL_PROCEDURE
6987       ,p_module   => l_log_module);
6988 END IF;
6989 
6990 l_language         := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
6991 l_currency_code    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.currency_code;
6992 l_sla_ledger_id    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.sla_ledger_id;
6993 
6994 --
6995 -- initialize array of lines with NULL
6996 --
6997 xla_ae_lines_pkg.SetNullLine;
6998 
6999 --
7000 -- initialize header extract count -- Bug 4865292
7001 --
7002 g_hdr_extract_count:= 0;
7003 
7004 
7005 l_created := EventClass_15(
7006    p_application_id         => p_application_id
7007  , p_base_ledger_id         => p_base_ledger_id
7008  , p_target_ledger_id       => p_target_ledger_id
7009  , p_language               => l_language
7010  , p_currency_code          => l_currency_code
7011  , p_sla_ledger_id          => l_sla_ledger_id
7012  , p_pad_start_date         => p_pad_start_date
7013  , p_pad_end_date           => p_pad_end_date
7014  , p_primary_ledger_id      => p_primary_ledger_id
7015 );
7016 
7017 
7018 
7019      IF ( g_diagnostics_mode ='Y' ) THEN
7020 
7021          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7022           trace
7023               (p_msg      => 'CALL Transaction Objects Diagnostics'
7024               ,p_level    => C_LEVEL_STATEMENT
7025               ,p_module   => l_log_module);
7026 
7027          END IF;
7028 
7029          insert_sources_15(
7030                           p_target_ledger_id => p_target_ledger_id
7031                         , p_language         => l_language
7032                         , p_sla_ledger_id    => l_sla_ledger_id
7033                         , p_pad_start_date   => p_pad_start_date
7034                         , p_pad_end_date     => p_pad_end_date
7035                           );
7036 
7037      END IF;
7038 
7039 l_created := EventClass_16(
7040    p_application_id         => p_application_id
7041  , p_base_ledger_id         => p_base_ledger_id
7042  , p_target_ledger_id       => p_target_ledger_id
7043  , p_language               => l_language
7044  , p_currency_code          => l_currency_code
7045  , p_sla_ledger_id          => l_sla_ledger_id
7046  , p_pad_start_date         => p_pad_start_date
7047  , p_pad_end_date           => p_pad_end_date
7048  , p_primary_ledger_id      => p_primary_ledger_id
7049 );
7050 
7051 
7052 
7053      IF ( g_diagnostics_mode ='Y' ) THEN
7054 
7055          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7056           trace
7057               (p_msg      => 'CALL Transaction Objects Diagnostics'
7058               ,p_level    => C_LEVEL_STATEMENT
7059               ,p_module   => l_log_module);
7060 
7061          END IF;
7062 
7063          insert_sources_16(
7064                           p_target_ledger_id => p_target_ledger_id
7065                         , p_language         => l_language
7066                         , p_sla_ledger_id    => l_sla_ledger_id
7067                         , p_pad_start_date   => p_pad_start_date
7068                         , p_pad_end_date     => p_pad_end_date
7069                           );
7070 
7071      END IF;
7072 
7073 
7074  --
7075  -- Bug 4865292
7076  -- When the number of events and that of header extract do not match,
7077  -- set the no header extract flag to indicate there are some issues
7078  -- in header extract.
7079  --
7080  -- Event count context is set in xla_accounting_pkg.unit_processor.
7081  -- Build_Message for this error is called in xla_accounting_pkg.post_accounting
7082  -- to report it as a general error.
7083  --
7084  IF  xla_context_pkg.get_event_count_context <> g_hdr_extract_count
7085  AND xla_context_pkg.get_event_nohdr_context <> 'Y' THEN
7086 
7087      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7088         trace
7089           (p_msg      => '# of extracted headers and events does not match'
7090           ,p_level    => C_LEVEL_STATEMENT
7091           ,p_module   => l_log_module);
7092 
7093         trace
7094           (p_msg      => '# of extracted headers: '
7095                          ||g_hdr_extract_count
7096           ,p_level    => C_LEVEL_STATEMENT
7097           ,p_module   => l_log_module);
7098 
7099         trace
7100           (p_msg      => '# of events in xla_events_gt: '
7101                          ||xla_context_pkg.get_event_count_context
7102           ,p_level    => C_LEVEL_STATEMENT
7103           ,p_module   => l_log_module);
7104 
7105         trace
7106           (p_msg      => 'Event No Header Extract Context: '
7107                          ||xla_context_pkg.get_event_nohdr_context
7108           ,p_level    => C_LEVEL_STATEMENT
7109           ,p_module   => l_log_module);
7110 
7111      END IF;
7112 
7113 
7114      xla_context_pkg.set_event_nohdr_context
7115        (p_nohdr_extract_flag => 'Y'
7116        ,p_client_id => sys_context('USERENV','CLIENT_IDENTIFIER'));
7117 
7118      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7119         trace
7120           (p_msg      => 'No Header Extract Flag is set to Y'
7121           ,p_level    => C_LEVEL_STATEMENT
7122           ,p_module   => l_log_module);
7123      END IF;
7124 
7125  END IF;
7126 
7127 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7128    trace
7129       (p_msg      => 'END of CreateHeadersAndLines'
7130       ,p_level    => C_LEVEL_PROCEDURE
7131       ,p_module   => l_log_module);
7132 END IF;
7133 
7134 RETURN l_created;
7135 EXCEPTION
7136 WHEN xla_exceptions_pkg.application_exception THEN
7137    RAISE;
7138 WHEN OTHERS THEN
7139    xla_exceptions_pkg.raise_message
7140       (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.CreateHeadersAndLines');
7141 END CreateHeadersAndLines;
7142 --
7143 --
7144 
7145 --
7146 --+============================================+
7147 --|                                            |
7148 --|  PUBLIC FUNCTION                           |
7149 --|                                            |
7150 --+============================================+
7151 --
7152 FUNCTION CreateJournalEntries
7153        (p_application_id         IN NUMBER
7154        ,p_base_ledger_id         IN NUMBER
7155        ,p_pad_start_date         IN DATE
7156        ,p_pad_end_date           IN DATE
7157        ,p_primary_ledger_id      IN NUMBER)
7158 RETURN NUMBER IS
7159 l_log_module                   VARCHAR2(240);
7160 l_array_ledgers                xla_accounting_cache_pkg.t_array_ledger_id;
7161 l_temp_result                  BOOLEAN;
7162 l_result                       NUMBER;
7163 BEGIN
7164 --
7165 IF g_log_enabled THEN
7166    l_log_module := C_DEFAULT_MODULE||'.CreateJournalEntries';
7167 END IF;
7168 --
7169 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7170    trace
7171       (p_msg      => 'BEGIN of CreateJournalEntries'||
7172                      ' - p_base_ledger_id = '||TO_CHAR(p_base_ledger_id)
7173       ,p_level    => C_LEVEL_PROCEDURE
7174       ,p_module   => l_log_module);
7175 
7176 END IF;
7177 
7178 --
7179 g_diagnostics_mode:= xla_accounting_engine_pkg.g_diagnostics_mode;
7180 
7181 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7182    trace
7183       (p_msg      => 'g_diagnostics_mode = '||g_diagnostics_mode
7184       ,p_level    => C_LEVEL_STATEMENT
7185       ,p_module   => l_log_module);
7186 END IF;
7187 --
7188 xla_ae_journal_entry_pkg.SetProductAcctDefinition
7189    (p_product_rule_code      => 'FV_STANDARD_AAD'
7190    ,p_product_rule_type_code => 'S'
7191    ,p_product_rule_version   => ''
7192    ,p_product_rule_name      => 'Federal Financials AAD'
7193    ,p_amb_context_code       => 'DEFAULT'
7194    );
7195 
7196 l_array_ledgers :=
7197    xla_ae_journal_entry_pkg.GetAlternateCurrencyLedger
7198       (p_base_ledger_id  => p_base_ledger_id);
7199 
7200 FOR Idx IN 1 .. l_array_ledgers.COUNT LOOP
7201    l_temp_result :=
7202       XLA_AE_JOURNAL_ENTRY_PKG.GetLedgersInfo
7203          (p_application_id           => p_application_id
7204          ,p_base_ledger_id           => p_base_ledger_id
7205          ,p_target_ledger_id         => l_array_ledgers(Idx)
7206          ,p_primary_ledger_id        => p_primary_ledger_id
7207          ,p_pad_start_date           => p_pad_start_date
7208          ,p_pad_end_date             => p_pad_end_date);
7209 
7210    l_temp_result :=
7211       l_temp_result AND
7212       CreateHeadersAndLines
7216          ,p_pad_start_date             => p_pad_start_date
7213          (p_application_id             => p_application_id
7214          ,p_base_ledger_id             => p_base_ledger_id
7215          ,p_target_ledger_id           => l_array_ledgers(Idx)
7217          ,p_pad_end_date               => p_pad_end_date
7218          ,p_primary_ledger_id          => p_primary_ledger_id
7219          );
7220 END LOOP;
7221 
7222 
7223 IF (g_diagnostics_mode = 'Y' AND
7224     C_LEVEL_UNEXPECTED >= g_log_level AND
7225     xla_environment_pkg.g_Req_Id IS NOT NULL ) THEN
7226 
7227    xla_accounting_dump_pkg.acctg_event_extract_log(
7228     p_application_id  => p_application_id
7229     ,p_request_id     => xla_environment_pkg.g_Req_Id
7230    );
7231 
7232 END IF;
7233 
7234 CASE l_temp_result
7235   WHEN TRUE THEN l_result := 0;
7236   ELSE l_result := 2;
7237 END CASE;
7238 
7239 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7240    trace
7241       (p_msg      => 'return value. = '||TO_CHAR(l_result)
7242       ,p_level    => C_LEVEL_PROCEDURE
7243       ,p_module   => l_log_module);
7244    trace
7245       (p_msg      => 'END of CreateJournalEntries '
7246       ,p_level    => C_LEVEL_PROCEDURE
7247       ,p_module   => l_log_module);
7248 END IF;
7249 
7250 RETURN l_result;
7251 EXCEPTION
7252 WHEN xla_exceptions_pkg.application_exception THEN
7253    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7254    trace
7255       (p_msg      => 'ERROR. = '||sqlerrm
7256       ,p_level    => C_LEVEL_PROCEDURE
7257       ,p_module   => l_log_module);
7258    END IF;
7259    RAISE;
7260 WHEN OTHERS THEN
7261    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7262    trace
7263       (p_msg      => 'ERROR. = '||sqlerrm
7264       ,p_level    => C_LEVEL_PROCEDURE
7265       ,p_module   => l_log_module);
7266    END IF;
7267    xla_exceptions_pkg.raise_message
7268       (p_location => 'XLA_08901_AAD_S_000002_BC_PKG.CreateJournalEntries');
7269 END CreateJournalEntries;
7270 --
7271 --=============================================================================
7272 --
7273 --
7274 --
7275 --
7276 --
7277 --
7278 --
7279 --
7280 --
7281 --
7282 --
7283 --
7284 --
7285 --
7286 --
7287 --
7288 --
7289 --
7290 --
7291 --
7292 --
7293 --
7294 --=============================================================================
7295 --=============================================================================
7296 --          *********** Initialization routine **********
7297 --=============================================================================
7298 
7299 BEGIN
7300    g_log_level      := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
7301    g_log_enabled    := fnd_log.test
7302                           (log_level  => g_log_level
7303                           ,module     => C_DEFAULT_MODULE);
7304 
7305    IF NOT g_log_enabled  THEN
7306       g_log_level := C_LEVEL_LOG_DISABLED;
7307    END IF;
7308 --
7309 END XLA_08901_AAD_S_000002_BC_PKG;
7310 --