DBA Data[Home] [Help]

PACKAGE BODY: APPS.XLA_00222_AAD_S_000006_PKG

Source


1 PACKAGE BODY XLA_00222_AAD_S_000006_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_00222_AAD_S_000006_PKG                                        |
10 |                                                                       |
11 | DESCRIPTION                                                           |
12 |     Package generated From Product Accounting Definition              |
13 |      Name    : Multi-Fund Federal Receivables Accrual - Balancing Meth|
14 |      Code    : MFAR_FED_AR_ACCRUAL_BALANCING                          |
15 |      Owner   : PRODUCT                                                |
16 |      Version :                                                        |
17 |      AMB Context Code: DEFAULT                                        |
18 | HISTORY                                                               |
19 |     Generated at 30-03-2009 at 05:03:54 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_00222_AAD_S_000006_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_00222_AAD_S_000006_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_00222_AAD_S_000006_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_00222_AAD_S_000006_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 )
241 RETURN VARCHAR2
242 IS
243 l_component_type        VARCHAR2(80)   ;
244 l_component_code        VARCHAR2(30)   ;
245 l_component_type_code   VARCHAR2(1)    ;
246 l_component_appl_id     INTEGER        ;
247 l_amb_context_code      VARCHAR2(30)   ;
248 l_ledger_language       VARCHAR2(30)   ;
249 l_source                VARCHAR2(1996) ;
250 l_description           VARCHAR2(2000) ;
251 l_log_module            VARCHAR2(240)  ;
252 BEGIN
253 IF g_log_enabled THEN
254       l_log_module := C_DEFAULT_MODULE||'.Description_1';
255 END IF;
256 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
257       trace
258          (p_msg      => 'BEGIN of Description_1'
259          ,p_level    => C_LEVEL_PROCEDURE
260          ,p_module   => l_log_module);
261 END IF;
262 
263 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
264 l_component_type        := 'AMB_DESCRIPTION';
265 l_component_code        := 'MFAR_JE_DESCRIPTION_BALANCING';
266 l_component_type_code   := 'S';
267 l_component_appl_id     :=  222;
268 l_amb_context_code      := 'DEFAULT';
269 l_source                := NULL;
270 l_description           := NULL;
271 
272 
273  
274  IF 
275 l_ledger_language = 'US' THEN
276     l_description :=  SUBSTR(CONCAT(l_description,'Multi-Fund Balancing'),1,2000);
277     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
278  END IF; 
279  l_description := SUBSTR(l_description,1,1996);
280   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
281         trace
282            (p_msg      => 'END of Description_1'
283            ,p_level    => C_LEVEL_PROCEDURE
284            ,p_module   => l_log_module);
285 
286   END IF;
287   RETURN l_description;
288 
289 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
290       trace
291          (p_msg      => 'END of Description_1'
292          ,p_level    => C_LEVEL_PROCEDURE
293          ,p_module   => l_log_module);
294 END IF;
295 RETURN NULL;
296 EXCEPTION
297   WHEN VALUE_ERROR THEN
298      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
299             trace
300                (p_msg      => 'ERROR: '||sqlerrm
301                ,p_level    => C_LEVEL_EXCEPTION
302                ,p_module   => l_log_module);
303      END IF;
304      RAISE;
305  WHEN xla_exceptions_pkg.application_exception THEN
306       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
307       trace
308          (p_msg      => 'ERROR: '||sqlerrm
309          ,p_level    => C_LEVEL_EXCEPTION
310          ,p_module   => l_log_module);
311       END IF;
312       RAISE;
313  WHEN OTHERS THEN
314        xla_exceptions_pkg.raise_message
315            (p_location => 'XLA_00222_AAD_S_000006_PKG.Description_1');
316 END Description_1;
317 
318 ---------------------------------------
319 --
320 -- PRIVATE FUNCTION
321 --         AcctDerRule_2
322 --
323 ---------------------------------------
324 FUNCTION AcctDerRule_2 (
325   p_application_id             IN NUMBER
326 , p_ae_header_id               IN NUMBER
327 , p_side                       IN VARCHAR2
328 , p_override_seg_flag          IN VARCHAR2 
329 --Remittance Bank Account Bank Charges Acount
330  , p_source_1            IN NUMBER
331 , x_transaction_coa_id         OUT NOCOPY NUMBER
332 , x_accounting_coa_id          OUT NOCOPY NUMBER
333 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
334 , x_flex_value_set_id          OUT NOCOPY NUMBER
335 , x_value_type_code            OUT NOCOPY VARCHAR2
336 , x_value_combination_id       OUT NOCOPY NUMBER
337 , x_value_segment_code         OUT NOCOPY VARCHAR2
338 )
339 RETURN VARCHAR2
340 IS
341 l_component_type       VARCHAR2(80)  ;
342 l_component_code       VARCHAR2(30)  ;
343 l_component_type_code  VARCHAR2(1)   ;
344 l_component_appl_id    INTEGER       ;
345 l_amb_context_code     VARCHAR2(30)  ;
346 l_log_module           VARCHAR2(240) ;
347 l_output_value         VARCHAR2(30)  ;
348 BEGIN
349 IF g_log_enabled THEN
350       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_2';
351 END IF;
352 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
353 
354       trace
355          (p_msg      => 'BEGIN of AcctDerRule_2'
356          ,p_level    => C_LEVEL_PROCEDURE
357          ,p_module   => l_log_module);
358 
359 END IF;
360 
361 l_component_type         := 'AMB_ADR';
362 l_component_code         := 'MFAR_BNK_CHARGES_BALANCING_SEG';
363 l_component_type_code    := 'S';
364 l_component_appl_id      :=  222;
365 l_amb_context_code       := 'DEFAULT';
366 x_transaction_coa_id     :=  null;
367 x_accounting_coa_id      :=  null;
371 
368 x_flexfield_segment_code := 'GL_BALANCING';
369 x_flex_value_set_id      :=  null ;
370 
372 --
373   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
374 
375       trace
376          (p_msg      => 'END of AcctDerRule_2'
377          ,p_level    => C_LEVEL_PROCEDURE
378          ,p_module   => l_log_module);
379 
380   END IF;
381   x_value_combination_id  := TO_NUMBER(p_source_1) ;
382   x_value_segment_code    := 'GL_BALANCING' ;
383   x_value_type_code       := 'S';
384   l_output_value          :=  null;
385   RETURN l_output_value;
386 
387 
388 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
389 
390       trace
391          (p_msg      => 'END of AcctDerRule_2(invalid)'
392          ,p_level    => C_LEVEL_PROCEDURE
393          ,p_module   => l_log_module);
394 
395 END IF;
396 
397 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
398 x_value_combination_id  := null;
399 x_value_segment_code    := null;
400 x_value_type_code       := null;
401 l_output_value          := null;
402 xla_accounting_err_pkg.build_message
403                  (p_appli_s_name            => 'XLA'
404                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
405                  ,p_token_1                 => 'COMPONENT_NAME'
406                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
407                                                             l_component_type
408                                                           , l_component_code
409                                                           , l_component_type_code
410                                                           , l_component_appl_id
411                                                           , l_amb_context_code
412                                                           )
413                  ,p_token_2                 => 'OWNER'
414                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
415                                                         'XLA_OWNER_TYPE'
416                                                         ,l_component_type_code
417                                                         )
418                  ,p_token_3                 => 'PAD_NAME'
419                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
420                  ,p_token_4                 => 'PAD_OWNER'
421                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
422                                                         'XLA_OWNER_TYPE'
423                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
424                                                         )
425                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
426                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
427                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
428                  ,p_ae_header_id            => NULL
429 );
430 RETURN l_output_value;
431 EXCEPTION
432   WHEN xla_exceptions_pkg.application_exception THEN
433       RAISE;
434   WHEN OTHERS THEN
435        xla_exceptions_pkg.raise_message
436            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_2');
437 END AcctDerRule_2;
438 --
439 
440 ---------------------------------------
441 --
442 -- PRIVATE FUNCTION
443 --         AcctDerRule_3
444 --
445 ---------------------------------------
446 FUNCTION AcctDerRule_3 (
447   p_application_id             IN NUMBER
448 , p_ae_header_id               IN NUMBER
449 , p_side                       IN VARCHAR2
450 , p_override_seg_flag          IN VARCHAR2 
451 --Credit Memo Distribution GL Account
452  , p_source_2            IN NUMBER
453 , x_transaction_coa_id         OUT NOCOPY NUMBER
454 , x_accounting_coa_id          OUT NOCOPY NUMBER
455 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
456 , x_flex_value_set_id          OUT NOCOPY NUMBER
457 , x_value_type_code            OUT NOCOPY VARCHAR2
458 , x_value_combination_id       OUT NOCOPY NUMBER
459 , x_value_segment_code         OUT NOCOPY VARCHAR2
460 )
461 RETURN VARCHAR2
462 IS
463 l_component_type       VARCHAR2(80)  ;
464 l_component_code       VARCHAR2(30)  ;
465 l_component_type_code  VARCHAR2(1)   ;
466 l_component_appl_id    INTEGER       ;
467 l_amb_context_code     VARCHAR2(30)  ;
468 l_log_module           VARCHAR2(240) ;
469 l_output_value         VARCHAR2(30)  ;
470 BEGIN
471 IF g_log_enabled THEN
472       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_3';
473 END IF;
474 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
475 
476       trace
477          (p_msg      => 'BEGIN of AcctDerRule_3'
478          ,p_level    => C_LEVEL_PROCEDURE
479          ,p_module   => l_log_module);
480 
481 END IF;
482 
483 l_component_type         := 'AMB_ADR';
484 l_component_code         := 'MFAR_CM_BALANCING_SEGMENT';
485 l_component_type_code    := 'S';
486 l_component_appl_id      :=  222;
487 l_amb_context_code       := 'DEFAULT';
488 x_transaction_coa_id     :=  null;
489 x_accounting_coa_id      :=  null;
493 
490 x_flexfield_segment_code := 'GL_BALANCING';
491 x_flex_value_set_id      :=  null ;
492 
494 --
495   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
496 
497       trace
498          (p_msg      => 'END of AcctDerRule_3'
499          ,p_level    => C_LEVEL_PROCEDURE
500          ,p_module   => l_log_module);
501 
502   END IF;
503   x_value_combination_id  := TO_NUMBER(p_source_2) ;
504   x_value_segment_code    := 'GL_BALANCING' ;
505   x_value_type_code       := 'S';
506   l_output_value          :=  null;
507   RETURN l_output_value;
508 
509 
510 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
511 
512       trace
513          (p_msg      => 'END of AcctDerRule_3(invalid)'
514          ,p_level    => C_LEVEL_PROCEDURE
515          ,p_module   => l_log_module);
516 
517 END IF;
518 
519 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
520 x_value_combination_id  := null;
521 x_value_segment_code    := null;
522 x_value_type_code       := null;
523 l_output_value          := null;
524 xla_accounting_err_pkg.build_message
525                  (p_appli_s_name            => 'XLA'
526                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
527                  ,p_token_1                 => 'COMPONENT_NAME'
528                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
529                                                             l_component_type
530                                                           , l_component_code
531                                                           , l_component_type_code
532                                                           , l_component_appl_id
533                                                           , l_amb_context_code
534                                                           )
535                  ,p_token_2                 => 'OWNER'
536                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
537                                                         'XLA_OWNER_TYPE'
538                                                         ,l_component_type_code
539                                                         )
540                  ,p_token_3                 => 'PAD_NAME'
541                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
542                  ,p_token_4                 => 'PAD_OWNER'
543                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
544                                                         'XLA_OWNER_TYPE'
545                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
546                                                         )
547                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
548                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
549                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
550                  ,p_ae_header_id            => NULL
551 );
552 RETURN l_output_value;
553 EXCEPTION
554   WHEN xla_exceptions_pkg.application_exception THEN
555       RAISE;
556   WHEN OTHERS THEN
557        xla_exceptions_pkg.raise_message
558            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_3');
559 END AcctDerRule_3;
560 --
561 
562 ---------------------------------------
563 --
564 -- PRIVATE FUNCTION
565 --         AcctDerRule_4
566 --
567 ---------------------------------------
568 FUNCTION AcctDerRule_4 (
569   p_application_id             IN NUMBER
570 , p_ae_header_id               IN NUMBER
571 , p_side                       IN VARCHAR2
572 , p_override_seg_flag          IN VARCHAR2 
573 --Distribution GL Account
574  , p_source_3            IN NUMBER
575 , x_transaction_coa_id         OUT NOCOPY NUMBER
576 , x_accounting_coa_id          OUT NOCOPY NUMBER
577 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
578 , x_flex_value_set_id          OUT NOCOPY NUMBER
579 , x_value_type_code            OUT NOCOPY VARCHAR2
580 , x_value_combination_id       OUT NOCOPY NUMBER
581 , x_value_segment_code         OUT NOCOPY VARCHAR2
582 )
583 RETURN VARCHAR2
584 IS
585 l_component_type       VARCHAR2(80)  ;
586 l_component_code       VARCHAR2(30)  ;
587 l_component_type_code  VARCHAR2(1)   ;
588 l_component_appl_id    INTEGER       ;
589 l_amb_context_code     VARCHAR2(30)  ;
590 l_log_module           VARCHAR2(240) ;
591 l_output_value         VARCHAR2(30)  ;
592 BEGIN
593 IF g_log_enabled THEN
594       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_4';
595 END IF;
596 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
597 
598       trace
599          (p_msg      => 'BEGIN of AcctDerRule_4'
600          ,p_level    => C_LEVEL_PROCEDURE
601          ,p_module   => l_log_module);
602 
603 END IF;
604 
605 l_component_type         := 'AMB_ADR';
606 l_component_code         := 'MFAR_DIST_BALANCING_SEGMENT';
607 l_component_type_code    := 'S';
608 l_component_appl_id      :=  222;
609 l_amb_context_code       := 'DEFAULT';
610 x_transaction_coa_id     :=  null;
611 x_accounting_coa_id      :=  null;
612 x_flexfield_segment_code := 'GL_BALANCING';
613 x_flex_value_set_id      :=  null ;
614 
615 
616 --
620          (p_msg      => 'END of AcctDerRule_4'
617   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
618 
619       trace
621          ,p_level    => C_LEVEL_PROCEDURE
622          ,p_module   => l_log_module);
623 
624   END IF;
625   x_value_combination_id  := TO_NUMBER(p_source_3) ;
626   x_value_segment_code    := 'GL_BALANCING' ;
627   x_value_type_code       := 'S';
628   l_output_value          :=  null;
629   RETURN l_output_value;
630 
631 
632 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
633 
634       trace
635          (p_msg      => 'END of AcctDerRule_4(invalid)'
636          ,p_level    => C_LEVEL_PROCEDURE
637          ,p_module   => l_log_module);
638 
639 END IF;
640 
641 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
642 x_value_combination_id  := null;
643 x_value_segment_code    := null;
644 x_value_type_code       := null;
645 l_output_value          := null;
646 xla_accounting_err_pkg.build_message
647                  (p_appli_s_name            => 'XLA'
648                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
649                  ,p_token_1                 => 'COMPONENT_NAME'
650                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
651                                                             l_component_type
652                                                           , l_component_code
653                                                           , l_component_type_code
654                                                           , l_component_appl_id
655                                                           , l_amb_context_code
656                                                           )
657                  ,p_token_2                 => 'OWNER'
658                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
659                                                         'XLA_OWNER_TYPE'
660                                                         ,l_component_type_code
661                                                         )
662                  ,p_token_3                 => 'PAD_NAME'
663                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
664                  ,p_token_4                 => 'PAD_OWNER'
665                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
666                                                         'XLA_OWNER_TYPE'
667                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
668                                                         )
669                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
670                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
671                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
672                  ,p_ae_header_id            => NULL
673 );
674 RETURN l_output_value;
675 EXCEPTION
676   WHEN xla_exceptions_pkg.application_exception THEN
677       RAISE;
678   WHEN OTHERS THEN
679        xla_exceptions_pkg.raise_message
680            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_4');
681 END AcctDerRule_4;
682 --
683 
684 ---------------------------------------
685 --
686 -- PRIVATE FUNCTION
687 --         AcctDerRule_5
688 --
689 ---------------------------------------
690 FUNCTION AcctDerRule_5 (
691   p_application_id             IN NUMBER
692 , p_ae_header_id               IN NUMBER
693 , p_side                       IN VARCHAR2
694 , p_override_seg_flag          IN VARCHAR2 
695 --Transaction Distribution GL Account
696  , p_source_4            IN NUMBER
697 , x_transaction_coa_id         OUT NOCOPY NUMBER
698 , x_accounting_coa_id          OUT NOCOPY NUMBER
699 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
700 , x_flex_value_set_id          OUT NOCOPY NUMBER
701 , x_value_type_code            OUT NOCOPY VARCHAR2
702 , x_value_combination_id       OUT NOCOPY NUMBER
703 , x_value_segment_code         OUT NOCOPY VARCHAR2
704 )
705 RETURN VARCHAR2
706 IS
707 l_component_type       VARCHAR2(80)  ;
708 l_component_code       VARCHAR2(30)  ;
709 l_component_type_code  VARCHAR2(1)   ;
710 l_component_appl_id    INTEGER       ;
711 l_amb_context_code     VARCHAR2(30)  ;
712 l_log_module           VARCHAR2(240) ;
713 l_output_value         VARCHAR2(30)  ;
714 BEGIN
715 IF g_log_enabled THEN
716       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_5';
717 END IF;
718 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
719 
720       trace
721          (p_msg      => 'BEGIN of AcctDerRule_5'
722          ,p_level    => C_LEVEL_PROCEDURE
723          ,p_module   => l_log_module);
724 
725 END IF;
726 
727 l_component_type         := 'AMB_ADR';
728 l_component_code         := 'MFAR_TRX_BALANCING_SEGMENT';
729 l_component_type_code    := 'S';
730 l_component_appl_id      :=  222;
731 l_amb_context_code       := 'DEFAULT';
732 x_transaction_coa_id     :=  null;
733 x_accounting_coa_id      :=  null;
734 x_flexfield_segment_code := 'GL_BALANCING';
735 x_flex_value_set_id      :=  null ;
736 
737 
738 --
739   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
740 
741       trace
745 
742          (p_msg      => 'END of AcctDerRule_5'
743          ,p_level    => C_LEVEL_PROCEDURE
744          ,p_module   => l_log_module);
746   END IF;
747   x_value_combination_id  := TO_NUMBER(p_source_4) ;
748   x_value_segment_code    := 'GL_BALANCING' ;
749   x_value_type_code       := 'S';
750   l_output_value          :=  null;
751   RETURN l_output_value;
752 
753 
754 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
755 
756       trace
757          (p_msg      => 'END of AcctDerRule_5(invalid)'
758          ,p_level    => C_LEVEL_PROCEDURE
759          ,p_module   => l_log_module);
760 
761 END IF;
762 
763 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
764 x_value_combination_id  := null;
765 x_value_segment_code    := null;
766 x_value_type_code       := null;
767 l_output_value          := null;
768 xla_accounting_err_pkg.build_message
769                  (p_appli_s_name            => 'XLA'
770                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
771                  ,p_token_1                 => 'COMPONENT_NAME'
772                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
773                                                             l_component_type
774                                                           , l_component_code
775                                                           , l_component_type_code
776                                                           , l_component_appl_id
777                                                           , l_amb_context_code
778                                                           )
779                  ,p_token_2                 => 'OWNER'
780                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
781                                                         'XLA_OWNER_TYPE'
782                                                         ,l_component_type_code
783                                                         )
784                  ,p_token_3                 => 'PAD_NAME'
785                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
786                  ,p_token_4                 => 'PAD_OWNER'
787                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
788                                                         'XLA_OWNER_TYPE'
789                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
790                                                         )
791                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
792                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
793                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
794                  ,p_ae_header_id            => NULL
795 );
796 RETURN l_output_value;
797 EXCEPTION
798   WHEN xla_exceptions_pkg.application_exception THEN
799       RAISE;
800   WHEN OTHERS THEN
801        xla_exceptions_pkg.raise_message
802            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_5');
803 END AcctDerRule_5;
804 --
805 
806 ---------------------------------------
807 --
808 -- PRIVATE FUNCTION
809 --         AcctDerRule_6
810 --
811 ---------------------------------------
812 FUNCTION AcctDerRule_6 (
813   p_application_id              IN NUMBER
814 , p_ae_header_id                IN NUMBER
815 , p_side                        IN VARCHAR2 
816 --Credit Memo Distribution GL Account
817  , p_source_2            IN NUMBER
818 , x_transaction_coa_id         OUT NOCOPY NUMBER
819 , x_accounting_coa_id          OUT NOCOPY NUMBER
820 , x_value_type_code            OUT NOCOPY VARCHAR2
821 )
822 RETURN NUMBER
823 IS
824 l_component_type       VARCHAR2(80)  ;
825 l_component_code       VARCHAR2(30)  ;
826 l_component_type_code  VARCHAR2(1)   ;
827 l_component_appl_id    INTEGER       ;
828 l_amb_context_code     VARCHAR2(30)  ;
829 l_log_module           VARCHAR2(240) ;
830 l_output_value         NUMBER        ;
831 BEGIN
832 IF g_log_enabled THEN
833       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_6';
834 END IF;
835 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
836       trace
837          (p_msg      => 'BEGIN of AcctDerRule_6'
838          ,p_level    => C_LEVEL_PROCEDURE
839          ,p_module   => l_log_module);
840 END IF;
841 --
842 l_component_type         := 'AMB_ADR';
843 l_component_code         := 'CM_DIST_CCID';
844 l_component_type_code    := 'S';
845 l_component_appl_id      :=  222;
846 l_amb_context_code       := 'DEFAULT';
847 x_transaction_coa_id     :=  null;
848 x_accounting_coa_id      :=  null;
849 --
850 
851  --
852   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
853       trace
854          (p_msg      => 'END of AcctDerRule_6'
855          ,p_level    => C_LEVEL_PROCEDURE
856          ,p_module   => l_log_module);
857   END IF;
858   x_value_type_code := 'S';
859   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_2));
860   RETURN l_output_value;
861 
862 --
863 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
864       trace
865          (p_msg      => 'END of AcctDerRule_6(invalid)'
866          ,p_level    => C_LEVEL_PROCEDURE
870 x_value_type_code := null;
867          ,p_module   => l_log_module);
868 END IF;
869 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
871 l_output_value    := null;
872 xla_accounting_err_pkg.build_message
873                  (p_appli_s_name            => 'XLA'
874                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
875                  ,p_token_1                 => 'COMPONENT_NAME'
876                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
877                                                             l_component_type
878                                                           , l_component_code
879                                                           , l_component_type_code
880                                                           , l_component_appl_id
881                                                           , l_amb_context_code
882                                                           )
883                  ,p_token_2                 => 'OWNER'
884                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
885                                                         'XLA_OWNER_TYPE'
886                                                         ,l_component_type_code
887                                                         )
888                  ,p_token_3                 => 'PAD_NAME'
889                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
890                  ,p_token_4                 => 'PAD_OWNER'
891                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
892                                                         'XLA_OWNER_TYPE'
893                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
894                                                         )
895                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
896                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
897                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
898                  ,p_ae_header_id            => NULL
899 );
900 RETURN l_output_value;
901 EXCEPTION
902   WHEN xla_exceptions_pkg.application_exception THEN
903       RAISE;
904   WHEN OTHERS THEN
905        xla_exceptions_pkg.raise_message
906            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_6');
907 END AcctDerRule_6;
908 --
909 
910 ---------------------------------------
911 --
912 -- PRIVATE FUNCTION
913 --         AcctDerRule_7
914 --
915 ---------------------------------------
916 FUNCTION AcctDerRule_7 (
917   p_application_id              IN NUMBER
918 , p_ae_header_id                IN NUMBER
919 , p_side                        IN VARCHAR2 
920 --Distribution GL Account
921  , p_source_3            IN NUMBER
922 , x_transaction_coa_id         OUT NOCOPY NUMBER
923 , x_accounting_coa_id          OUT NOCOPY NUMBER
924 , x_value_type_code            OUT NOCOPY VARCHAR2
925 )
926 RETURN NUMBER
927 IS
928 l_component_type       VARCHAR2(80)  ;
929 l_component_code       VARCHAR2(30)  ;
930 l_component_type_code  VARCHAR2(1)   ;
931 l_component_appl_id    INTEGER       ;
932 l_amb_context_code     VARCHAR2(30)  ;
933 l_log_module           VARCHAR2(240) ;
934 l_output_value         NUMBER        ;
935 BEGIN
936 IF g_log_enabled THEN
937       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_7';
938 END IF;
939 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
940       trace
941          (p_msg      => 'BEGIN of AcctDerRule_7'
942          ,p_level    => C_LEVEL_PROCEDURE
943          ,p_module   => l_log_module);
944 END IF;
945 --
946 l_component_type         := 'AMB_ADR';
947 l_component_code         := 'DIST_CCID';
948 l_component_type_code    := 'S';
949 l_component_appl_id      :=  222;
950 l_amb_context_code       := 'DEFAULT';
951 x_transaction_coa_id     :=  null;
952 x_accounting_coa_id      :=  null;
953 --
954 
955  --
956   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
957       trace
958          (p_msg      => 'END of AcctDerRule_7'
959          ,p_level    => C_LEVEL_PROCEDURE
960          ,p_module   => l_log_module);
961   END IF;
962   x_value_type_code := 'S';
963   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_3));
964   RETURN l_output_value;
965 
966 --
967 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
968       trace
969          (p_msg      => 'END of AcctDerRule_7(invalid)'
970          ,p_level    => C_LEVEL_PROCEDURE
971          ,p_module   => l_log_module);
972 END IF;
973 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
974 x_value_type_code := null;
975 l_output_value    := null;
976 xla_accounting_err_pkg.build_message
977                  (p_appli_s_name            => 'XLA'
978                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
979                  ,p_token_1                 => 'COMPONENT_NAME'
980                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
981                                                             l_component_type
982                                                           , l_component_code
986                                                           )
983                                                           , l_component_type_code
984                                                           , l_component_appl_id
985                                                           , l_amb_context_code
987                  ,p_token_2                 => 'OWNER'
988                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
989                                                         'XLA_OWNER_TYPE'
990                                                         ,l_component_type_code
991                                                         )
992                  ,p_token_3                 => 'PAD_NAME'
993                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
994                  ,p_token_4                 => 'PAD_OWNER'
995                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
996                                                         'XLA_OWNER_TYPE'
997                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
998                                                         )
999                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1000                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1001                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1002                  ,p_ae_header_id            => NULL
1003 );
1004 RETURN l_output_value;
1005 EXCEPTION
1006   WHEN xla_exceptions_pkg.application_exception THEN
1007       RAISE;
1008   WHEN OTHERS THEN
1009        xla_exceptions_pkg.raise_message
1010            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_7');
1011 END AcctDerRule_7;
1012 --
1013 
1014 ---------------------------------------
1015 --
1016 -- PRIVATE FUNCTION
1017 --         AcctDerRule_8
1018 --
1019 ---------------------------------------
1020 FUNCTION AcctDerRule_8 (
1021   p_application_id             IN NUMBER
1022 , p_ae_header_id               IN NUMBER
1023 , p_side                       IN VARCHAR2
1024 , p_override_seg_flag          IN VARCHAR2 
1025 --Federal Fund Category
1026  , p_source_5            IN VARCHAR2
1027 , x_transaction_coa_id         OUT NOCOPY NUMBER
1028 , x_accounting_coa_id          OUT NOCOPY NUMBER
1029 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
1030 , x_flex_value_set_id          OUT NOCOPY NUMBER
1031 , x_value_type_code            OUT NOCOPY VARCHAR2
1032 , x_value_combination_id       OUT NOCOPY NUMBER
1033 , x_value_segment_code         OUT NOCOPY VARCHAR2
1034 )
1035 RETURN VARCHAR2
1036 IS
1037 l_component_type       VARCHAR2(80)  ;
1038 l_component_code       VARCHAR2(30)  ;
1039 l_component_type_code  VARCHAR2(1)   ;
1040 l_component_appl_id    INTEGER       ;
1041 l_amb_context_code     VARCHAR2(30)  ;
1042 l_log_module           VARCHAR2(240) ;
1043 l_output_value         VARCHAR2(30)  ;
1044 BEGIN
1045 IF g_log_enabled THEN
1046       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_8';
1047 END IF;
1048 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1049 
1050       trace
1051          (p_msg      => 'BEGIN of AcctDerRule_8'
1052          ,p_level    => C_LEVEL_PROCEDURE
1053          ,p_module   => l_log_module);
1054 
1055 END IF;
1056 
1057 l_component_type         := 'AMB_ADR';
1058 l_component_code         := 'FV_AR_422101_MISC_RCT_CR';
1059 l_component_type_code    := 'S';
1060 l_component_appl_id      :=  222;
1061 l_amb_context_code       := 'DEFAULT';
1062 x_transaction_coa_id     :=  null;
1063 x_accounting_coa_id      :=  null;
1064 x_flexfield_segment_code :=  null;
1065 x_flex_value_set_id      := 1009988 ;
1066 
1067 
1068  IF NVL(p_source_5,'
1069 ') =  'Reimbursable'
1070  THEN 
1071 --
1072   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1073 
1074       trace
1075          (p_msg      => 'END of AcctDerRule_8'
1076          ,p_level    => C_LEVEL_PROCEDURE
1077          ,p_module   => l_log_module);
1078 
1079   END IF;
1080   x_value_combination_id  :=  null ;
1081   x_value_segment_code    :=  null ;
1082   x_value_type_code       := 'C';
1083   l_output_value          := '422101';
1084   RETURN l_output_value;
1085 
1086  ELSE 
1087     IF p_override_seg_flag = 'Y' THEN 
1088        RETURN '#$NO_OVERRIDE#$';
1089     END IF;
1090  END IF;
1091 
1092 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1093 
1094       trace
1095          (p_msg      => 'END of AcctDerRule_8(invalid)'
1096          ,p_level    => C_LEVEL_PROCEDURE
1097          ,p_module   => l_log_module);
1098 
1099 END IF;
1100 
1101 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1102 x_value_combination_id  := null;
1103 x_value_segment_code    := null;
1104 x_value_type_code       := null;
1105 l_output_value          := null;
1106 xla_accounting_err_pkg.build_message
1107                  (p_appli_s_name            => 'XLA'
1108                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1109                  ,p_token_1                 => 'COMPONENT_NAME'
1110                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1114                                                           , l_component_appl_id
1111                                                             l_component_type
1112                                                           , l_component_code
1113                                                           , l_component_type_code
1115                                                           , l_amb_context_code
1116                                                           )
1117                  ,p_token_2                 => 'OWNER'
1118                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1119                                                         'XLA_OWNER_TYPE'
1120                                                         ,l_component_type_code
1121                                                         )
1122                  ,p_token_3                 => 'PAD_NAME'
1123                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1124                  ,p_token_4                 => 'PAD_OWNER'
1125                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1126                                                         'XLA_OWNER_TYPE'
1127                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1128                                                         )
1129                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1130                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1131                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1132                  ,p_ae_header_id            => NULL
1133 );
1134 RETURN l_output_value;
1135 EXCEPTION
1136   WHEN xla_exceptions_pkg.application_exception THEN
1137       RAISE;
1138   WHEN OTHERS THEN
1139        xla_exceptions_pkg.raise_message
1140            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_8');
1141 END AcctDerRule_8;
1142 --
1143 
1144 ---------------------------------------
1145 --
1146 -- PRIVATE FUNCTION
1147 --         AcctDerRule_9
1148 --
1149 ---------------------------------------
1150 FUNCTION AcctDerRule_9 (
1151   p_application_id             IN NUMBER
1152 , p_ae_header_id               IN NUMBER
1153 , p_side                       IN VARCHAR2
1154 , p_override_seg_flag          IN VARCHAR2 
1155 --Federal Fund Category
1156  , p_source_5            IN VARCHAR2
1157 --Bill To Customer Classification
1158  , p_source_6            IN VARCHAR2
1159 , x_transaction_coa_id         OUT NOCOPY NUMBER
1160 , x_accounting_coa_id          OUT NOCOPY NUMBER
1161 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
1162 , x_flex_value_set_id          OUT NOCOPY NUMBER
1163 , x_value_type_code            OUT NOCOPY VARCHAR2
1164 , x_value_combination_id       OUT NOCOPY NUMBER
1165 , x_value_segment_code         OUT NOCOPY VARCHAR2
1166 )
1167 RETURN VARCHAR2
1168 IS
1169 l_component_type       VARCHAR2(80)  ;
1170 l_component_code       VARCHAR2(30)  ;
1171 l_component_type_code  VARCHAR2(1)   ;
1172 l_component_appl_id    INTEGER       ;
1173 l_amb_context_code     VARCHAR2(30)  ;
1174 l_log_module           VARCHAR2(240) ;
1175 l_output_value         VARCHAR2(30)  ;
1176 BEGIN
1177 IF g_log_enabled THEN
1178       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_9';
1179 END IF;
1180 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1181 
1182       trace
1183          (p_msg      => 'BEGIN of AcctDerRule_9'
1184          ,p_level    => C_LEVEL_PROCEDURE
1185          ,p_module   => l_log_module);
1186 
1187 END IF;
1188 
1189 l_component_type         := 'AMB_ADR';
1190 l_component_code         := 'FV_AR_422X0X_INV_REIM_CR';
1191 l_component_type_code    := 'S';
1192 l_component_appl_id      :=  222;
1193 l_amb_context_code       := 'DEFAULT';
1194 x_transaction_coa_id     :=  null;
1195 x_accounting_coa_id      :=  null;
1196 x_flexfield_segment_code :=  null;
1197 x_flex_value_set_id      := 1009988 ;
1198 
1199 
1200  IF NVL(p_source_6,'
1201 ') =  'FEDERAL' AND 
1202 NVL(p_source_5,'
1203 ') =  'Reimbursable'
1204  THEN 
1205 --
1206   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1207 
1208       trace
1209          (p_msg      => 'END of AcctDerRule_9'
1210          ,p_level    => C_LEVEL_PROCEDURE
1211          ,p_module   => l_log_module);
1212 
1213   END IF;
1214   x_value_combination_id  :=  null ;
1215   x_value_segment_code    :=  null ;
1216   x_value_type_code       := 'C';
1217   l_output_value          := '422101';
1218   RETURN l_output_value;
1219 
1220  ELSIF NVL(p_source_6,'
1221 ') <>  'FEDERAL' AND 
1222 NVL(p_source_5,'
1223 ') =  'Reimbursable'
1224  THEN 
1225 --
1226   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1227 
1228       trace
1229          (p_msg      => 'END of AcctDerRule_9'
1230          ,p_level    => C_LEVEL_PROCEDURE
1231          ,p_module   => l_log_module);
1232 
1233   END IF;
1234   x_value_combination_id  :=  null ;
1235   x_value_segment_code    :=  null ;
1236   x_value_type_code       := 'C';
1237   l_output_value          := '422202';
1238   RETURN l_output_value;
1239 
1240  ELSE 
1241     IF p_override_seg_flag = 'Y' THEN 
1242        RETURN '#$NO_OVERRIDE#$';
1243     END IF;
1247 
1244  END IF;
1245 
1246 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1248       trace
1249          (p_msg      => 'END of AcctDerRule_9(invalid)'
1250          ,p_level    => C_LEVEL_PROCEDURE
1251          ,p_module   => l_log_module);
1252 
1253 END IF;
1254 
1255 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1256 x_value_combination_id  := null;
1257 x_value_segment_code    := null;
1258 x_value_type_code       := null;
1259 l_output_value          := null;
1260 xla_accounting_err_pkg.build_message
1261                  (p_appli_s_name            => 'XLA'
1262                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1263                  ,p_token_1                 => 'COMPONENT_NAME'
1264                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1265                                                             l_component_type
1266                                                           , l_component_code
1267                                                           , l_component_type_code
1268                                                           , l_component_appl_id
1269                                                           , l_amb_context_code
1270                                                           )
1271                  ,p_token_2                 => 'OWNER'
1272                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1273                                                         'XLA_OWNER_TYPE'
1274                                                         ,l_component_type_code
1275                                                         )
1276                  ,p_token_3                 => 'PAD_NAME'
1277                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1278                  ,p_token_4                 => 'PAD_OWNER'
1279                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1280                                                         'XLA_OWNER_TYPE'
1281                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1282                                                         )
1283                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1284                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1285                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1286                  ,p_ae_header_id            => NULL
1287 );
1288 RETURN l_output_value;
1289 EXCEPTION
1290   WHEN xla_exceptions_pkg.application_exception THEN
1291       RAISE;
1292   WHEN OTHERS THEN
1293        xla_exceptions_pkg.raise_message
1294            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_9');
1295 END AcctDerRule_9;
1296 --
1297 
1298 ---------------------------------------
1299 --
1300 -- PRIVATE FUNCTION
1301 --         AcctDerRule_10
1302 --
1303 ---------------------------------------
1304 FUNCTION AcctDerRule_10 (
1305   p_application_id             IN NUMBER
1306 , p_ae_header_id               IN NUMBER
1307 , p_side                       IN VARCHAR2
1308 , p_override_seg_flag          IN VARCHAR2 
1309 --Federal Account Rule
1310  , p_source_7            IN VARCHAR2
1311 , x_transaction_coa_id         OUT NOCOPY NUMBER
1312 , x_accounting_coa_id          OUT NOCOPY NUMBER
1313 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
1314 , x_flex_value_set_id          OUT NOCOPY NUMBER
1315 , x_value_type_code            OUT NOCOPY VARCHAR2
1316 , x_value_combination_id       OUT NOCOPY NUMBER
1317 , x_value_segment_code         OUT NOCOPY VARCHAR2
1318 )
1319 RETURN VARCHAR2
1320 IS
1321 l_component_type       VARCHAR2(80)  ;
1322 l_component_code       VARCHAR2(30)  ;
1323 l_component_type_code  VARCHAR2(1)   ;
1324 l_component_appl_id    INTEGER       ;
1325 l_amb_context_code     VARCHAR2(30)  ;
1326 l_log_module           VARCHAR2(240) ;
1327 l_output_value         VARCHAR2(30)  ;
1328 BEGIN
1329 IF g_log_enabled THEN
1330       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_10';
1331 END IF;
1332 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1333 
1334       trace
1335          (p_msg      => 'BEGIN of AcctDerRule_10'
1336          ,p_level    => C_LEVEL_PROCEDURE
1337          ,p_module   => l_log_module);
1338 
1339 END IF;
1340 
1341 l_component_type         := 'AMB_ADR';
1342 l_component_code         := 'FV_AR_425101_RCT_CR';
1343 l_component_type_code    := 'S';
1344 l_component_appl_id      :=  222;
1345 l_amb_context_code       := 'DEFAULT';
1346 x_transaction_coa_id     :=  null;
1347 x_accounting_coa_id      :=  null;
1348 x_flexfield_segment_code :=  null;
1349 x_flex_value_set_id      := 1009988 ;
1350 
1351 
1352  IF NVL(p_source_7,'
1353 ') =  'Order No Advance'
1354  THEN 
1355 --
1356   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1357 
1358       trace
1359          (p_msg      => 'END of AcctDerRule_10'
1360          ,p_level    => C_LEVEL_PROCEDURE
1361          ,p_module   => l_log_module);
1362 
1363   END IF;
1364   x_value_combination_id  :=  null ;
1365   x_value_segment_code    :=  null ;
1366   x_value_type_code       := 'C';
1367   l_output_value          := '425101';
1368   RETURN l_output_value;
1369 
1370  ELSE 
1374  END IF;
1371     IF p_override_seg_flag = 'Y' THEN 
1372        RETURN '#$NO_OVERRIDE#$';
1373     END IF;
1375 
1376 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1377 
1378       trace
1379          (p_msg      => 'END of AcctDerRule_10(invalid)'
1380          ,p_level    => C_LEVEL_PROCEDURE
1381          ,p_module   => l_log_module);
1382 
1383 END IF;
1384 
1385 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1386 x_value_combination_id  := null;
1387 x_value_segment_code    := null;
1388 x_value_type_code       := null;
1389 l_output_value          := null;
1390 xla_accounting_err_pkg.build_message
1391                  (p_appli_s_name            => 'XLA'
1392                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1393                  ,p_token_1                 => 'COMPONENT_NAME'
1394                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1395                                                             l_component_type
1396                                                           , l_component_code
1397                                                           , l_component_type_code
1398                                                           , l_component_appl_id
1399                                                           , l_amb_context_code
1400                                                           )
1401                  ,p_token_2                 => 'OWNER'
1402                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1403                                                         'XLA_OWNER_TYPE'
1404                                                         ,l_component_type_code
1405                                                         )
1406                  ,p_token_3                 => 'PAD_NAME'
1407                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1408                  ,p_token_4                 => 'PAD_OWNER'
1409                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1410                                                         'XLA_OWNER_TYPE'
1411                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1412                                                         )
1413                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1414                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1415                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1416                  ,p_ae_header_id            => NULL
1417 );
1418 RETURN l_output_value;
1419 EXCEPTION
1420   WHEN xla_exceptions_pkg.application_exception THEN
1421       RAISE;
1422   WHEN OTHERS THEN
1423        xla_exceptions_pkg.raise_message
1424            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_10');
1425 END AcctDerRule_10;
1426 --
1427 
1428 ---------------------------------------
1429 --
1430 -- PRIVATE FUNCTION
1431 --         AcctDerRule_11
1432 --
1433 ---------------------------------------
1434 FUNCTION AcctDerRule_11 (
1435   p_application_id             IN NUMBER
1436 , p_ae_header_id               IN NUMBER
1437 , p_side                       IN VARCHAR2
1438 , p_override_seg_flag          IN VARCHAR2 
1439 --Federal Fund Category
1440  , p_source_5            IN VARCHAR2
1441 , x_transaction_coa_id         OUT NOCOPY NUMBER
1442 , x_accounting_coa_id          OUT NOCOPY NUMBER
1443 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
1444 , x_flex_value_set_id          OUT NOCOPY NUMBER
1445 , x_value_type_code            OUT NOCOPY VARCHAR2
1446 , x_value_combination_id       OUT NOCOPY NUMBER
1447 , x_value_segment_code         OUT NOCOPY VARCHAR2
1448 )
1449 RETURN VARCHAR2
1450 IS
1451 l_component_type       VARCHAR2(80)  ;
1452 l_component_code       VARCHAR2(30)  ;
1453 l_component_type_code  VARCHAR2(1)   ;
1454 l_component_appl_id    INTEGER       ;
1455 l_amb_context_code     VARCHAR2(30)  ;
1456 l_log_module           VARCHAR2(240) ;
1457 l_output_value         VARCHAR2(30)  ;
1458 BEGIN
1459 IF g_log_enabled THEN
1460       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_11';
1461 END IF;
1462 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1463 
1464       trace
1465          (p_msg      => 'BEGIN of AcctDerRule_11'
1466          ,p_level    => C_LEVEL_PROCEDURE
1467          ,p_module   => l_log_module);
1468 
1469 END IF;
1470 
1471 l_component_type         := 'AMB_ADR';
1472 l_component_code         := 'FV_AR_425201_MISC_RCT_DR';
1473 l_component_type_code    := 'S';
1474 l_component_appl_id      :=  222;
1475 l_amb_context_code       := 'DEFAULT';
1476 x_transaction_coa_id     :=  null;
1477 x_accounting_coa_id      :=  null;
1478 x_flexfield_segment_code :=  null;
1479 x_flex_value_set_id      := 1009988 ;
1480 
1481 
1482  IF NVL(p_source_5,'
1483 ') =  'Reimbursable'
1484  THEN 
1485 --
1486   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1487 
1488       trace
1489          (p_msg      => 'END of AcctDerRule_11'
1490          ,p_level    => C_LEVEL_PROCEDURE
1491          ,p_module   => l_log_module);
1492 
1493   END IF;
1494   x_value_combination_id  :=  null ;
1495   x_value_segment_code    :=  null ;
1496   x_value_type_code       := 'C';
1500  ELSE 
1497   l_output_value          := '425201';
1498   RETURN l_output_value;
1499 
1501     IF p_override_seg_flag = 'Y' THEN 
1502        RETURN '#$NO_OVERRIDE#$';
1503     END IF;
1504  END IF;
1505 
1506 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1507 
1508       trace
1509          (p_msg      => 'END of AcctDerRule_11(invalid)'
1510          ,p_level    => C_LEVEL_PROCEDURE
1511          ,p_module   => l_log_module);
1512 
1513 END IF;
1514 
1515 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1516 x_value_combination_id  := null;
1517 x_value_segment_code    := null;
1518 x_value_type_code       := null;
1519 l_output_value          := null;
1520 xla_accounting_err_pkg.build_message
1521                  (p_appli_s_name            => 'XLA'
1522                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1523                  ,p_token_1                 => 'COMPONENT_NAME'
1524                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1525                                                             l_component_type
1526                                                           , l_component_code
1527                                                           , l_component_type_code
1528                                                           , l_component_appl_id
1529                                                           , l_amb_context_code
1530                                                           )
1531                  ,p_token_2                 => 'OWNER'
1532                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1533                                                         'XLA_OWNER_TYPE'
1534                                                         ,l_component_type_code
1535                                                         )
1536                  ,p_token_3                 => 'PAD_NAME'
1537                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1538                  ,p_token_4                 => 'PAD_OWNER'
1539                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1540                                                         'XLA_OWNER_TYPE'
1541                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1542                                                         )
1543                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1544                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1545                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1546                  ,p_ae_header_id            => NULL
1547 );
1548 RETURN l_output_value;
1549 EXCEPTION
1550   WHEN xla_exceptions_pkg.application_exception THEN
1551       RAISE;
1552   WHEN OTHERS THEN
1553        xla_exceptions_pkg.raise_message
1554            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_11');
1555 END AcctDerRule_11;
1556 --
1557 
1558 ---------------------------------------
1559 --
1560 -- PRIVATE FUNCTION
1561 --         AcctDerRule_12
1562 --
1563 ---------------------------------------
1564 FUNCTION AcctDerRule_12 (
1565   p_application_id             IN NUMBER
1566 , p_ae_header_id               IN NUMBER
1567 , p_side                       IN VARCHAR2
1568 , p_override_seg_flag          IN VARCHAR2 
1569 --Federal Account Rule
1570  , p_source_7            IN VARCHAR2
1571 , x_transaction_coa_id         OUT NOCOPY NUMBER
1572 , x_accounting_coa_id          OUT NOCOPY NUMBER
1573 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
1574 , x_flex_value_set_id          OUT NOCOPY NUMBER
1575 , x_value_type_code            OUT NOCOPY VARCHAR2
1576 , x_value_combination_id       OUT NOCOPY NUMBER
1577 , x_value_segment_code         OUT NOCOPY VARCHAR2
1578 )
1579 RETURN VARCHAR2
1580 IS
1581 l_component_type       VARCHAR2(80)  ;
1582 l_component_code       VARCHAR2(30)  ;
1583 l_component_type_code  VARCHAR2(1)   ;
1584 l_component_appl_id    INTEGER       ;
1585 l_amb_context_code     VARCHAR2(30)  ;
1586 l_log_module           VARCHAR2(240) ;
1587 l_output_value         VARCHAR2(30)  ;
1588 BEGIN
1589 IF g_log_enabled THEN
1590       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_12';
1591 END IF;
1592 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1593 
1594       trace
1595          (p_msg      => 'BEGIN of AcctDerRule_12'
1596          ,p_level    => C_LEVEL_PROCEDURE
1597          ,p_module   => l_log_module);
1598 
1599 END IF;
1600 
1601 l_component_type         := 'AMB_ADR';
1602 l_component_code         := 'FV_AR_425201_RCT_DR';
1603 l_component_type_code    := 'S';
1604 l_component_appl_id      :=  222;
1605 l_amb_context_code       := 'DEFAULT';
1606 x_transaction_coa_id     :=  null;
1607 x_accounting_coa_id      :=  null;
1608 x_flexfield_segment_code :=  null;
1609 x_flex_value_set_id      := 1009988 ;
1610 
1611 
1612  IF NVL(p_source_7,'
1613 ') =  'Order No Advance'
1614  THEN 
1615 --
1616   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1617 
1618       trace
1619          (p_msg      => 'END of AcctDerRule_12'
1620          ,p_level    => C_LEVEL_PROCEDURE
1621          ,p_module   => l_log_module);
1622 
1623   END IF;
1624   x_value_combination_id  :=  null ;
1628   RETURN l_output_value;
1625   x_value_segment_code    :=  null ;
1626   x_value_type_code       := 'C';
1627   l_output_value          := '425201';
1629 
1630  ELSE 
1631     IF p_override_seg_flag = 'Y' THEN 
1632        RETURN '#$NO_OVERRIDE#$';
1633     END IF;
1634  END IF;
1635 
1636 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1637 
1638       trace
1639          (p_msg      => 'END of AcctDerRule_12(invalid)'
1640          ,p_level    => C_LEVEL_PROCEDURE
1641          ,p_module   => l_log_module);
1642 
1643 END IF;
1644 
1645 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1646 x_value_combination_id  := null;
1647 x_value_segment_code    := null;
1648 x_value_type_code       := null;
1649 l_output_value          := null;
1650 xla_accounting_err_pkg.build_message
1651                  (p_appli_s_name            => 'XLA'
1652                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1653                  ,p_token_1                 => 'COMPONENT_NAME'
1654                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1655                                                             l_component_type
1656                                                           , l_component_code
1657                                                           , l_component_type_code
1658                                                           , l_component_appl_id
1659                                                           , l_amb_context_code
1660                                                           )
1661                  ,p_token_2                 => 'OWNER'
1662                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1663                                                         'XLA_OWNER_TYPE'
1664                                                         ,l_component_type_code
1665                                                         )
1666                  ,p_token_3                 => 'PAD_NAME'
1667                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1668                  ,p_token_4                 => 'PAD_OWNER'
1669                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1670                                                         'XLA_OWNER_TYPE'
1671                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1672                                                         )
1673                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1674                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1675                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1676                  ,p_ae_header_id            => NULL
1677 );
1678 RETURN l_output_value;
1679 EXCEPTION
1680   WHEN xla_exceptions_pkg.application_exception THEN
1681       RAISE;
1682   WHEN OTHERS THEN
1683        xla_exceptions_pkg.raise_message
1684            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_12');
1685 END AcctDerRule_12;
1686 --
1687 
1688 ---------------------------------------
1689 --
1690 -- PRIVATE FUNCTION
1691 --         AcctDerRule_13
1692 --
1693 ---------------------------------------
1694 FUNCTION AcctDerRule_13 (
1695   p_application_id             IN NUMBER
1696 , p_ae_header_id               IN NUMBER
1697 , p_side                       IN VARCHAR2
1698 , p_override_seg_flag          IN VARCHAR2 
1699 --Federal Fund Category
1700  , p_source_5            IN VARCHAR2
1701 --Bill To Customer Classification
1702  , p_source_6            IN VARCHAR2
1703 , x_transaction_coa_id         OUT NOCOPY NUMBER
1704 , x_accounting_coa_id          OUT NOCOPY NUMBER
1705 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
1706 , x_flex_value_set_id          OUT NOCOPY NUMBER
1707 , x_value_type_code            OUT NOCOPY VARCHAR2
1708 , x_value_combination_id       OUT NOCOPY NUMBER
1709 , x_value_segment_code         OUT NOCOPY VARCHAR2
1710 )
1711 RETURN VARCHAR2
1712 IS
1713 l_component_type       VARCHAR2(80)  ;
1714 l_component_code       VARCHAR2(30)  ;
1715 l_component_type_code  VARCHAR2(1)   ;
1716 l_component_appl_id    INTEGER       ;
1717 l_amb_context_code     VARCHAR2(30)  ;
1718 l_log_module           VARCHAR2(240) ;
1719 l_output_value         VARCHAR2(30)  ;
1720 BEGIN
1721 IF g_log_enabled THEN
1722       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_13';
1723 END IF;
1724 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1725 
1726       trace
1727          (p_msg      => 'BEGIN of AcctDerRule_13'
1728          ,p_level    => C_LEVEL_PROCEDURE
1729          ,p_module   => l_log_module);
1730 
1731 END IF;
1732 
1733 l_component_type         := 'AMB_ADR';
1734 l_component_code         := 'FV_AR_425X0X_INV_REIM_DR';
1735 l_component_type_code    := 'S';
1736 l_component_appl_id      :=  222;
1737 l_amb_context_code       := 'DEFAULT';
1738 x_transaction_coa_id     :=  null;
1739 x_accounting_coa_id      :=  null;
1740 x_flexfield_segment_code :=  null;
1741 x_flex_value_set_id      := 1009988 ;
1742 
1743 
1744  IF NVL(p_source_6,'
1745 ') =  'FEDERAL' AND 
1746 NVL(p_source_5,'
1747 ') =  'Reimbursable'
1748  THEN 
1749 --
1750   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1751 
1755          ,p_module   => l_log_module);
1752       trace
1753          (p_msg      => 'END of AcctDerRule_13'
1754          ,p_level    => C_LEVEL_PROCEDURE
1756 
1757   END IF;
1758   x_value_combination_id  :=  null ;
1759   x_value_segment_code    :=  null ;
1760   x_value_type_code       := 'C';
1761   l_output_value          := '425101';
1762   RETURN l_output_value;
1763 
1764  ELSIF NVL(p_source_6,'
1765 ') <>  'FEDERAL' AND 
1766 NVL(p_source_5,'
1767 ') =  'Reimbursable'
1768  THEN 
1769 --
1770   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1771 
1772       trace
1773          (p_msg      => 'END of AcctDerRule_13'
1774          ,p_level    => C_LEVEL_PROCEDURE
1775          ,p_module   => l_log_module);
1776 
1777   END IF;
1778   x_value_combination_id  :=  null ;
1779   x_value_segment_code    :=  null ;
1780   x_value_type_code       := 'C';
1781   l_output_value          := '425202';
1782   RETURN l_output_value;
1783 
1784  ELSE 
1785     IF p_override_seg_flag = 'Y' THEN 
1786        RETURN '#$NO_OVERRIDE#$';
1787     END IF;
1788  END IF;
1789 
1790 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1791 
1792       trace
1793          (p_msg      => 'END of AcctDerRule_13(invalid)'
1794          ,p_level    => C_LEVEL_PROCEDURE
1795          ,p_module   => l_log_module);
1796 
1797 END IF;
1798 
1799 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1800 x_value_combination_id  := null;
1801 x_value_segment_code    := null;
1802 x_value_type_code       := null;
1803 l_output_value          := null;
1804 xla_accounting_err_pkg.build_message
1805                  (p_appli_s_name            => 'XLA'
1806                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1807                  ,p_token_1                 => 'COMPONENT_NAME'
1808                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1809                                                             l_component_type
1810                                                           , l_component_code
1811                                                           , l_component_type_code
1812                                                           , l_component_appl_id
1813                                                           , l_amb_context_code
1814                                                           )
1815                  ,p_token_2                 => 'OWNER'
1816                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1817                                                         'XLA_OWNER_TYPE'
1818                                                         ,l_component_type_code
1819                                                         )
1820                  ,p_token_3                 => 'PAD_NAME'
1821                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1822                  ,p_token_4                 => 'PAD_OWNER'
1823                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1824                                                         'XLA_OWNER_TYPE'
1825                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1826                                                         )
1827                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1828                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1829                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1830                  ,p_ae_header_id            => NULL
1831 );
1832 RETURN l_output_value;
1833 EXCEPTION
1834   WHEN xla_exceptions_pkg.application_exception THEN
1835       RAISE;
1836   WHEN OTHERS THEN
1837        xla_exceptions_pkg.raise_message
1838            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_13');
1839 END AcctDerRule_13;
1840 --
1841 
1842 ---------------------------------------
1843 --
1844 -- PRIVATE FUNCTION
1845 --         AcctDerRule_14
1846 --
1847 ---------------------------------------
1848 FUNCTION AcctDerRule_14 (
1849   p_application_id             IN NUMBER
1850 , p_ae_header_id               IN NUMBER
1851 , p_side                       IN VARCHAR2
1852 , p_override_seg_flag          IN VARCHAR2 
1853 --Federal Fund Expired Status
1854  , p_source_8            IN VARCHAR2
1855 --Federal Prior Year Flag
1856  , p_source_9            IN VARCHAR2
1857 --Federal Fund Time Frame
1858  , p_source_10            IN VARCHAR2
1859 , x_transaction_coa_id         OUT NOCOPY NUMBER
1860 , x_accounting_coa_id          OUT NOCOPY NUMBER
1861 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
1862 , x_flex_value_set_id          OUT NOCOPY NUMBER
1863 , x_value_type_code            OUT NOCOPY VARCHAR2
1864 , x_value_combination_id       OUT NOCOPY NUMBER
1865 , x_value_segment_code         OUT NOCOPY VARCHAR2
1866 )
1867 RETURN VARCHAR2
1868 IS
1869 l_component_type       VARCHAR2(80)  ;
1870 l_component_code       VARCHAR2(30)  ;
1871 l_component_type_code  VARCHAR2(1)   ;
1872 l_component_appl_id    INTEGER       ;
1873 l_amb_context_code     VARCHAR2(30)  ;
1874 l_log_module           VARCHAR2(240) ;
1875 l_output_value         VARCHAR2(30)  ;
1876 BEGIN
1877 IF g_log_enabled THEN
1878       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_14';
1882       trace
1879 END IF;
1880 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1881 
1883          (p_msg      => 'BEGIN of AcctDerRule_14'
1884          ,p_level    => C_LEVEL_PROCEDURE
1885          ,p_module   => l_log_module);
1886 
1887 END IF;
1888 
1889 l_component_type         := 'AMB_ADR';
1890 l_component_code         := 'FV_AR_445001_MISC_RCT_CR';
1891 l_component_type_code    := 'S';
1892 l_component_appl_id      :=  222;
1893 l_amb_context_code       := 'DEFAULT';
1894 x_transaction_coa_id     :=  null;
1895 x_accounting_coa_id      :=  null;
1896 x_flexfield_segment_code :=  null;
1897 x_flex_value_set_id      := 1009988 ;
1898 
1899 
1900  IF NVL(p_source_8,'
1901 ') =  'Unexpired' AND 
1902 NVL(p_source_9,'
1903 ') =  'Y' AND 
1904 (NVL(p_source_10,'
1905 ') =  'MULTIPLE' OR 
1906 NVL(p_source_10,'
1907 ') =  'NO_YEAR')
1908  THEN 
1909 --
1910   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1911 
1912       trace
1913          (p_msg      => 'END of AcctDerRule_14'
1914          ,p_level    => C_LEVEL_PROCEDURE
1915          ,p_module   => l_log_module);
1916 
1917   END IF;
1918   x_value_combination_id  :=  null ;
1919   x_value_segment_code    :=  null ;
1920   x_value_type_code       := 'C';
1921   l_output_value          := '445001';
1922   RETURN l_output_value;
1923 
1924  ELSE 
1925     IF p_override_seg_flag = 'Y' THEN 
1926        RETURN '#$NO_OVERRIDE#$';
1927     END IF;
1928  END IF;
1929 
1930 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1931 
1932       trace
1933          (p_msg      => 'END of AcctDerRule_14(invalid)'
1934          ,p_level    => C_LEVEL_PROCEDURE
1935          ,p_module   => l_log_module);
1936 
1937 END IF;
1938 
1939 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1940 x_value_combination_id  := null;
1941 x_value_segment_code    := null;
1942 x_value_type_code       := null;
1943 l_output_value          := null;
1944 xla_accounting_err_pkg.build_message
1945                  (p_appli_s_name            => 'XLA'
1946                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1947                  ,p_token_1                 => 'COMPONENT_NAME'
1948                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1949                                                             l_component_type
1950                                                           , l_component_code
1951                                                           , l_component_type_code
1952                                                           , l_component_appl_id
1953                                                           , l_amb_context_code
1954                                                           )
1955                  ,p_token_2                 => 'OWNER'
1956                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1957                                                         'XLA_OWNER_TYPE'
1958                                                         ,l_component_type_code
1959                                                         )
1960                  ,p_token_3                 => 'PAD_NAME'
1961                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1962                  ,p_token_4                 => 'PAD_OWNER'
1963                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1964                                                         'XLA_OWNER_TYPE'
1965                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1966                                                         )
1967                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1968                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1969                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1970                  ,p_ae_header_id            => NULL
1971 );
1972 RETURN l_output_value;
1973 EXCEPTION
1974   WHEN xla_exceptions_pkg.application_exception THEN
1975       RAISE;
1976   WHEN OTHERS THEN
1977        xla_exceptions_pkg.raise_message
1978            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_14');
1979 END AcctDerRule_14;
1980 --
1981 
1982 ---------------------------------------
1983 --
1984 -- PRIVATE FUNCTION
1985 --         AcctDerRule_15
1986 --
1987 ---------------------------------------
1988 FUNCTION AcctDerRule_15 (
1989   p_application_id             IN NUMBER
1990 , p_ae_header_id               IN NUMBER
1991 , p_side                       IN VARCHAR2
1992 , p_override_seg_flag          IN VARCHAR2 
1993 --Federal Fund Expired Status
1994  , p_source_8            IN VARCHAR2
1995 --Federal Prior Year Flag
1996  , p_source_9            IN VARCHAR2
1997 --Federal Fund Time Frame
1998  , p_source_10            IN VARCHAR2
1999 , x_transaction_coa_id         OUT NOCOPY NUMBER
2000 , x_accounting_coa_id          OUT NOCOPY NUMBER
2001 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
2002 , x_flex_value_set_id          OUT NOCOPY NUMBER
2003 , x_value_type_code            OUT NOCOPY VARCHAR2
2004 , x_value_combination_id       OUT NOCOPY NUMBER
2005 , x_value_segment_code         OUT NOCOPY VARCHAR2
2006 )
2007 RETURN VARCHAR2
2008 IS
2012 l_component_appl_id    INTEGER       ;
2009 l_component_type       VARCHAR2(80)  ;
2010 l_component_code       VARCHAR2(30)  ;
2011 l_component_type_code  VARCHAR2(1)   ;
2013 l_amb_context_code     VARCHAR2(30)  ;
2014 l_log_module           VARCHAR2(240) ;
2015 l_output_value         VARCHAR2(30)  ;
2016 BEGIN
2017 IF g_log_enabled THEN
2018       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_15';
2019 END IF;
2020 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2021 
2022       trace
2023          (p_msg      => 'BEGIN of AcctDerRule_15'
2024          ,p_level    => C_LEVEL_PROCEDURE
2025          ,p_module   => l_log_module);
2026 
2027 END IF;
2028 
2029 l_component_type         := 'AMB_ADR';
2030 l_component_code         := 'FV_AR_445001_RCT_CR';
2031 l_component_type_code    := 'S';
2032 l_component_appl_id      :=  222;
2033 l_amb_context_code       := 'DEFAULT';
2034 x_transaction_coa_id     :=  null;
2035 x_accounting_coa_id      :=  null;
2036 x_flexfield_segment_code :=  null;
2037 x_flex_value_set_id      := 1009988 ;
2038 
2039 
2040  IF NVL(p_source_8,'
2041 ') =  'Unexpired' AND 
2042 NVL(p_source_9,'
2043 ') =  'Y' AND 
2044 (NVL(p_source_10,'
2045 ') =  'MULTIPLE' OR 
2046 NVL(p_source_10,'
2047 ') =  'NO_YEAR')
2048  THEN 
2049 --
2050   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2051 
2052       trace
2053          (p_msg      => 'END of AcctDerRule_15'
2054          ,p_level    => C_LEVEL_PROCEDURE
2055          ,p_module   => l_log_module);
2056 
2057   END IF;
2058   x_value_combination_id  :=  null ;
2059   x_value_segment_code    :=  null ;
2060   x_value_type_code       := 'C';
2061   l_output_value          := '445001';
2062   RETURN l_output_value;
2063 
2064  ELSE 
2065     IF p_override_seg_flag = 'Y' THEN 
2066        RETURN '#$NO_OVERRIDE#$';
2067     END IF;
2068  END IF;
2069 
2070 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2071 
2072       trace
2073          (p_msg      => 'END of AcctDerRule_15(invalid)'
2074          ,p_level    => C_LEVEL_PROCEDURE
2075          ,p_module   => l_log_module);
2076 
2077 END IF;
2078 
2079 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
2080 x_value_combination_id  := null;
2081 x_value_segment_code    := null;
2082 x_value_type_code       := null;
2083 l_output_value          := null;
2084 xla_accounting_err_pkg.build_message
2085                  (p_appli_s_name            => 'XLA'
2086                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
2087                  ,p_token_1                 => 'COMPONENT_NAME'
2088                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
2089                                                             l_component_type
2090                                                           , l_component_code
2091                                                           , l_component_type_code
2092                                                           , l_component_appl_id
2093                                                           , l_amb_context_code
2094                                                           )
2095                  ,p_token_2                 => 'OWNER'
2096                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
2097                                                         'XLA_OWNER_TYPE'
2098                                                         ,l_component_type_code
2099                                                         )
2100                  ,p_token_3                 => 'PAD_NAME'
2101                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
2102                  ,p_token_4                 => 'PAD_OWNER'
2103                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
2104                                                         'XLA_OWNER_TYPE'
2105                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
2106                                                         )
2107                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
2108                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
2109                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
2110                  ,p_ae_header_id            => NULL
2111 );
2112 RETURN l_output_value;
2113 EXCEPTION
2114   WHEN xla_exceptions_pkg.application_exception THEN
2115       RAISE;
2116   WHEN OTHERS THEN
2117        xla_exceptions_pkg.raise_message
2118            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_15');
2119 END AcctDerRule_15;
2120 --
2121 
2122 ---------------------------------------
2123 --
2124 -- PRIVATE FUNCTION
2125 --         AcctDerRule_16
2126 --
2127 ---------------------------------------
2128 FUNCTION AcctDerRule_16 (
2129   p_application_id             IN NUMBER
2130 , p_ae_header_id               IN NUMBER
2131 , p_side                       IN VARCHAR2
2132 , p_override_seg_flag          IN VARCHAR2 
2133 --Federal Fund Expired Status
2134  , p_source_8            IN VARCHAR2
2135 --Federal Prior Year Flag
2136  , p_source_9            IN VARCHAR2
2137 --Federal Fund Time Frame
2138  , p_source_10            IN VARCHAR2
2139 , x_transaction_coa_id         OUT NOCOPY NUMBER
2143 , x_value_type_code            OUT NOCOPY VARCHAR2
2140 , x_accounting_coa_id          OUT NOCOPY NUMBER
2141 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
2142 , x_flex_value_set_id          OUT NOCOPY NUMBER
2144 , x_value_combination_id       OUT NOCOPY NUMBER
2145 , x_value_segment_code         OUT NOCOPY VARCHAR2
2146 )
2147 RETURN VARCHAR2
2148 IS
2149 l_component_type       VARCHAR2(80)  ;
2150 l_component_code       VARCHAR2(30)  ;
2151 l_component_type_code  VARCHAR2(1)   ;
2152 l_component_appl_id    INTEGER       ;
2153 l_amb_context_code     VARCHAR2(30)  ;
2154 l_log_module           VARCHAR2(240) ;
2155 l_output_value         VARCHAR2(30)  ;
2156 BEGIN
2157 IF g_log_enabled THEN
2158       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_16';
2159 END IF;
2160 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2161 
2162       trace
2163          (p_msg      => 'BEGIN of AcctDerRule_16'
2164          ,p_level    => C_LEVEL_PROCEDURE
2165          ,p_module   => l_log_module);
2166 
2167 END IF;
2168 
2169 l_component_type         := 'AMB_ADR';
2170 l_component_code         := 'FV_AR_465002_MISC_RCT_CR';
2171 l_component_type_code    := 'S';
2172 l_component_appl_id      :=  222;
2173 l_amb_context_code       := 'DEFAULT';
2174 x_transaction_coa_id     :=  null;
2175 x_accounting_coa_id      :=  null;
2176 x_flexfield_segment_code :=  null;
2177 x_flex_value_set_id      := 1009988 ;
2178 
2179 
2180  IF NVL(p_source_8,'
2181 ') =  'Expired' AND 
2182 NVL(p_source_9,'
2183 ') =  'Y' AND 
2184 (NVL(p_source_10,'
2185 ') =  'SINGLE' OR 
2186 NVL(p_source_10,'
2187 ') =  'MULTIPLE' OR 
2188 NVL(p_source_10,'
2189 ') =  'NO_YEAR')
2190  THEN 
2191 --
2192   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2193 
2194       trace
2195          (p_msg      => 'END of AcctDerRule_16'
2196          ,p_level    => C_LEVEL_PROCEDURE
2197          ,p_module   => l_log_module);
2198 
2199   END IF;
2200   x_value_combination_id  :=  null ;
2201   x_value_segment_code    :=  null ;
2202   x_value_type_code       := 'C';
2203   l_output_value          := '465002';
2204   RETURN l_output_value;
2205 
2206  ELSE 
2207     IF p_override_seg_flag = 'Y' THEN 
2208        RETURN '#$NO_OVERRIDE#$';
2209     END IF;
2210  END IF;
2211 
2212 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2213 
2214       trace
2215          (p_msg      => 'END of AcctDerRule_16(invalid)'
2216          ,p_level    => C_LEVEL_PROCEDURE
2217          ,p_module   => l_log_module);
2218 
2219 END IF;
2220 
2221 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
2222 x_value_combination_id  := null;
2223 x_value_segment_code    := null;
2224 x_value_type_code       := null;
2225 l_output_value          := null;
2226 xla_accounting_err_pkg.build_message
2227                  (p_appli_s_name            => 'XLA'
2228                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
2229                  ,p_token_1                 => 'COMPONENT_NAME'
2230                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
2231                                                             l_component_type
2232                                                           , l_component_code
2233                                                           , l_component_type_code
2234                                                           , l_component_appl_id
2235                                                           , l_amb_context_code
2236                                                           )
2237                  ,p_token_2                 => 'OWNER'
2238                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
2239                                                         'XLA_OWNER_TYPE'
2240                                                         ,l_component_type_code
2241                                                         )
2242                  ,p_token_3                 => 'PAD_NAME'
2243                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
2244                  ,p_token_4                 => 'PAD_OWNER'
2245                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
2246                                                         'XLA_OWNER_TYPE'
2247                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
2248                                                         )
2249                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
2250                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
2251                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
2252                  ,p_ae_header_id            => NULL
2253 );
2254 RETURN l_output_value;
2255 EXCEPTION
2256   WHEN xla_exceptions_pkg.application_exception THEN
2257       RAISE;
2258   WHEN OTHERS THEN
2259        xla_exceptions_pkg.raise_message
2260            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_16');
2261 END AcctDerRule_16;
2262 --
2263 
2264 ---------------------------------------
2265 --
2266 -- PRIVATE FUNCTION
2267 --         AcctDerRule_17
2268 --
2269 ---------------------------------------
2270 FUNCTION AcctDerRule_17 (
2274 , p_override_seg_flag          IN VARCHAR2 
2271   p_application_id             IN NUMBER
2272 , p_ae_header_id               IN NUMBER
2273 , p_side                       IN VARCHAR2
2275 --Federal Fund Expired Status
2276  , p_source_8            IN VARCHAR2
2277 --Federal Prior Year Flag
2278  , p_source_9            IN VARCHAR2
2279 --Federal Fund Time Frame
2280  , p_source_10            IN VARCHAR2
2281 , x_transaction_coa_id         OUT NOCOPY NUMBER
2282 , x_accounting_coa_id          OUT NOCOPY NUMBER
2283 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
2284 , x_flex_value_set_id          OUT NOCOPY NUMBER
2285 , x_value_type_code            OUT NOCOPY VARCHAR2
2286 , x_value_combination_id       OUT NOCOPY NUMBER
2287 , x_value_segment_code         OUT NOCOPY VARCHAR2
2288 )
2289 RETURN VARCHAR2
2290 IS
2291 l_component_type       VARCHAR2(80)  ;
2292 l_component_code       VARCHAR2(30)  ;
2293 l_component_type_code  VARCHAR2(1)   ;
2294 l_component_appl_id    INTEGER       ;
2295 l_amb_context_code     VARCHAR2(30)  ;
2296 l_log_module           VARCHAR2(240) ;
2297 l_output_value         VARCHAR2(30)  ;
2298 BEGIN
2299 IF g_log_enabled THEN
2300       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_17';
2301 END IF;
2302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2303 
2304       trace
2305          (p_msg      => 'BEGIN of AcctDerRule_17'
2306          ,p_level    => C_LEVEL_PROCEDURE
2307          ,p_module   => l_log_module);
2308 
2309 END IF;
2310 
2311 l_component_type         := 'AMB_ADR';
2312 l_component_code         := 'FV_AR_465002_RCT_CR';
2313 l_component_type_code    := 'S';
2314 l_component_appl_id      :=  222;
2315 l_amb_context_code       := 'DEFAULT';
2316 x_transaction_coa_id     :=  null;
2317 x_accounting_coa_id      :=  null;
2318 x_flexfield_segment_code :=  null;
2319 x_flex_value_set_id      := 1009988 ;
2320 
2321 
2322  IF NVL(p_source_8,'
2323 ') =  'Expired' AND 
2324 NVL(p_source_9,'
2325 ') =  'Y' AND 
2326 (NVL(p_source_10,'
2327 ') =  'SINGLE' OR 
2328 NVL(p_source_10,'
2329 ') =  'MULTIPLE' OR 
2330 NVL(p_source_10,'
2331 ') =  'NO_YEAR')
2332  THEN 
2333 --
2334   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2335 
2336       trace
2337          (p_msg      => 'END of AcctDerRule_17'
2338          ,p_level    => C_LEVEL_PROCEDURE
2339          ,p_module   => l_log_module);
2340 
2341   END IF;
2342   x_value_combination_id  :=  null ;
2343   x_value_segment_code    :=  null ;
2344   x_value_type_code       := 'C';
2345   l_output_value          := '465002';
2346   RETURN l_output_value;
2347 
2348  ELSE 
2349     IF p_override_seg_flag = 'Y' THEN 
2350        RETURN '#$NO_OVERRIDE#$';
2351     END IF;
2352  END IF;
2353 
2354 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2355 
2356       trace
2357          (p_msg      => 'END of AcctDerRule_17(invalid)'
2358          ,p_level    => C_LEVEL_PROCEDURE
2359          ,p_module   => l_log_module);
2360 
2361 END IF;
2362 
2363 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
2364 x_value_combination_id  := null;
2365 x_value_segment_code    := null;
2366 x_value_type_code       := null;
2367 l_output_value          := null;
2368 xla_accounting_err_pkg.build_message
2369                  (p_appli_s_name            => 'XLA'
2370                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
2371                  ,p_token_1                 => 'COMPONENT_NAME'
2372                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
2373                                                             l_component_type
2374                                                           , l_component_code
2375                                                           , l_component_type_code
2376                                                           , l_component_appl_id
2377                                                           , l_amb_context_code
2378                                                           )
2379                  ,p_token_2                 => 'OWNER'
2380                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
2381                                                         'XLA_OWNER_TYPE'
2382                                                         ,l_component_type_code
2383                                                         )
2384                  ,p_token_3                 => 'PAD_NAME'
2385                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
2386                  ,p_token_4                 => 'PAD_OWNER'
2387                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
2388                                                         'XLA_OWNER_TYPE'
2389                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
2390                                                         )
2391                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
2392                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
2393                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
2394                  ,p_ae_header_id            => NULL
2395 );
2396 RETURN l_output_value;
2397 EXCEPTION
2398   WHEN xla_exceptions_pkg.application_exception THEN
2399       RAISE;
2400   WHEN OTHERS THEN
2404 --
2401        xla_exceptions_pkg.raise_message
2402            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_17');
2403 END AcctDerRule_17;
2405 
2406 ---------------------------------------
2407 --
2408 -- PRIVATE FUNCTION
2409 --         AcctDerRule_18
2410 --
2411 ---------------------------------------
2412 FUNCTION AcctDerRule_18 (
2413   p_application_id             IN NUMBER
2414 , p_ae_header_id               IN NUMBER
2415 , p_side                       IN VARCHAR2
2416 , p_override_seg_flag          IN VARCHAR2 
2417 --Federal Fund Expired Status
2418  , p_source_8            IN VARCHAR2
2419 --Federal Prior Year Flag
2420  , p_source_9            IN VARCHAR2
2421 --Federal Fund Time Frame
2422  , p_source_10            IN VARCHAR2
2423 --Federal Apportionment Category
2424  , p_source_11            IN VARCHAR2
2425 , x_transaction_coa_id         OUT NOCOPY NUMBER
2426 , x_accounting_coa_id          OUT NOCOPY NUMBER
2427 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
2428 , x_flex_value_set_id          OUT NOCOPY NUMBER
2429 , x_value_type_code            OUT NOCOPY VARCHAR2
2430 , x_value_combination_id       OUT NOCOPY NUMBER
2431 , x_value_segment_code         OUT NOCOPY VARCHAR2
2432 )
2433 RETURN VARCHAR2
2434 IS
2435 l_component_type       VARCHAR2(80)  ;
2436 l_component_code       VARCHAR2(30)  ;
2437 l_component_type_code  VARCHAR2(1)   ;
2438 l_component_appl_id    INTEGER       ;
2439 l_amb_context_code     VARCHAR2(30)  ;
2440 l_log_module           VARCHAR2(240) ;
2441 l_output_value         VARCHAR2(30)  ;
2442 BEGIN
2443 IF g_log_enabled THEN
2444       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_18';
2445 END IF;
2446 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2447 
2448       trace
2449          (p_msg      => 'BEGIN of AcctDerRule_18'
2450          ,p_level    => C_LEVEL_PROCEDURE
2451          ,p_module   => l_log_module);
2452 
2453 END IF;
2454 
2455 l_component_type         := 'AMB_ADR';
2456 l_component_code         := 'FV_AR_46X002_MISC_RCT_CR';
2457 l_component_type_code    := 'S';
2458 l_component_appl_id      :=  222;
2459 l_amb_context_code       := 'DEFAULT';
2460 x_transaction_coa_id     :=  null;
2461 x_accounting_coa_id      :=  null;
2462 x_flexfield_segment_code :=  null;
2463 x_flex_value_set_id      := 1009988 ;
2464 
2465 
2466  IF NVL(p_source_8,'
2467 ') =  'Unexpired' AND 
2468 NVL(p_source_9,'
2469 ') =  'N' AND 
2470 (NVL(p_source_11,'
2471 ') =  'A' OR 
2472 NVL(p_source_11,'
2473 ') =  'B') AND 
2474 (NVL(p_source_10,'
2475 ') =  'SINGLE' OR 
2476 NVL(p_source_10,'
2477 ') =  'MULTIPLE' OR 
2478 NVL(p_source_10,'
2479 ') =  'NO_YEAR')
2480  THEN 
2481 --
2482   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2483 
2484       trace
2485          (p_msg      => 'END of AcctDerRule_18'
2486          ,p_level    => C_LEVEL_PROCEDURE
2487          ,p_module   => l_log_module);
2488 
2489   END IF;
2490   x_value_combination_id  :=  null ;
2491   x_value_segment_code    :=  null ;
2492   x_value_type_code       := 'C';
2493   l_output_value          := '461002';
2494   RETURN l_output_value;
2495 
2496  ELSIF NVL(p_source_8,'
2497 ') =  'Unexpired' AND 
2498 NVL(p_source_9,'
2499 ') =  'N' AND 
2500 NVL(p_source_11,'
2501 ') =  'C' AND 
2502 (NVL(p_source_10,'
2503 ') =  'SINGLE' OR 
2504 NVL(p_source_10,'
2505 ') =  'MULTIPLE' OR 
2506 NVL(p_source_10,'
2507 ') =  'NO_YEAR')
2508  THEN 
2509 --
2510   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2511 
2512       trace
2513          (p_msg      => 'END of AcctDerRule_18'
2514          ,p_level    => C_LEVEL_PROCEDURE
2515          ,p_module   => l_log_module);
2516 
2517   END IF;
2518   x_value_combination_id  :=  null ;
2519   x_value_segment_code    :=  null ;
2520   x_value_type_code       := 'C';
2521   l_output_value          := '462002';
2522   RETURN l_output_value;
2523 
2524  ELSE 
2525     IF p_override_seg_flag = 'Y' THEN 
2526        RETURN '#$NO_OVERRIDE#$';
2527     END IF;
2528  END IF;
2529 
2530 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2531 
2532       trace
2533          (p_msg      => 'END of AcctDerRule_18(invalid)'
2534          ,p_level    => C_LEVEL_PROCEDURE
2535          ,p_module   => l_log_module);
2536 
2537 END IF;
2538 
2539 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
2540 x_value_combination_id  := null;
2541 x_value_segment_code    := null;
2542 x_value_type_code       := null;
2543 l_output_value          := null;
2544 xla_accounting_err_pkg.build_message
2545                  (p_appli_s_name            => 'XLA'
2546                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
2547                  ,p_token_1                 => 'COMPONENT_NAME'
2548                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
2549                                                             l_component_type
2550                                                           , l_component_code
2551                                                           , l_component_type_code
2552                                                           , l_component_appl_id
2556                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
2553                                                           , l_amb_context_code
2554                                                           )
2555                  ,p_token_2                 => 'OWNER'
2557                                                         'XLA_OWNER_TYPE'
2558                                                         ,l_component_type_code
2559                                                         )
2560                  ,p_token_3                 => 'PAD_NAME'
2561                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
2562                  ,p_token_4                 => 'PAD_OWNER'
2563                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
2564                                                         'XLA_OWNER_TYPE'
2565                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
2566                                                         )
2567                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
2568                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
2569                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
2570                  ,p_ae_header_id            => NULL
2571 );
2572 RETURN l_output_value;
2573 EXCEPTION
2574   WHEN xla_exceptions_pkg.application_exception THEN
2575       RAISE;
2576   WHEN OTHERS THEN
2577        xla_exceptions_pkg.raise_message
2578            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_18');
2579 END AcctDerRule_18;
2580 --
2581 
2582 ---------------------------------------
2583 --
2584 -- PRIVATE FUNCTION
2585 --         AcctDerRule_19
2586 --
2587 ---------------------------------------
2588 FUNCTION AcctDerRule_19 (
2589   p_application_id             IN NUMBER
2590 , p_ae_header_id               IN NUMBER
2591 , p_side                       IN VARCHAR2
2592 , p_override_seg_flag          IN VARCHAR2 
2593 --Federal Fund Expired Status
2594  , p_source_8            IN VARCHAR2
2595 --Federal Prior Year Flag
2596  , p_source_9            IN VARCHAR2
2597 --Federal Fund Time Frame
2598  , p_source_10            IN VARCHAR2
2599 --Federal Apportionment Category
2600  , p_source_11            IN VARCHAR2
2601 , x_transaction_coa_id         OUT NOCOPY NUMBER
2602 , x_accounting_coa_id          OUT NOCOPY NUMBER
2603 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
2604 , x_flex_value_set_id          OUT NOCOPY NUMBER
2605 , x_value_type_code            OUT NOCOPY VARCHAR2
2606 , x_value_combination_id       OUT NOCOPY NUMBER
2607 , x_value_segment_code         OUT NOCOPY VARCHAR2
2608 )
2609 RETURN VARCHAR2
2610 IS
2611 l_component_type       VARCHAR2(80)  ;
2612 l_component_code       VARCHAR2(30)  ;
2613 l_component_type_code  VARCHAR2(1)   ;
2614 l_component_appl_id    INTEGER       ;
2615 l_amb_context_code     VARCHAR2(30)  ;
2616 l_log_module           VARCHAR2(240) ;
2617 l_output_value         VARCHAR2(30)  ;
2618 BEGIN
2619 IF g_log_enabled THEN
2620       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_19';
2621 END IF;
2622 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2623 
2624       trace
2625          (p_msg      => 'BEGIN of AcctDerRule_19'
2626          ,p_level    => C_LEVEL_PROCEDURE
2627          ,p_module   => l_log_module);
2628 
2629 END IF;
2630 
2631 l_component_type         := 'AMB_ADR';
2632 l_component_code         := 'FV_AR_46X002_RCT_CR';
2633 l_component_type_code    := 'S';
2634 l_component_appl_id      :=  222;
2635 l_amb_context_code       := 'DEFAULT';
2636 x_transaction_coa_id     :=  null;
2637 x_accounting_coa_id      :=  null;
2638 x_flexfield_segment_code :=  null;
2639 x_flex_value_set_id      := 1009988 ;
2640 
2641 
2642  IF NVL(p_source_8,'
2643 ') =  'Unexpired' AND 
2644 NVL(p_source_9,'
2645 ') =  'N' AND 
2646 (NVL(p_source_11,'
2647 ') =  'A' OR 
2648 NVL(p_source_11,'
2649 ') =  'B') AND 
2650 (NVL(p_source_10,'
2651 ') =  'SINGLE' OR 
2652 NVL(p_source_10,'
2653 ') =  'MULTIPLE' OR 
2654 NVL(p_source_10,'
2655 ') =  'NO_YEAR')
2656  THEN 
2657 --
2658   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2659 
2660       trace
2661          (p_msg      => 'END of AcctDerRule_19'
2662          ,p_level    => C_LEVEL_PROCEDURE
2663          ,p_module   => l_log_module);
2664 
2665   END IF;
2666   x_value_combination_id  :=  null ;
2667   x_value_segment_code    :=  null ;
2668   x_value_type_code       := 'C';
2669   l_output_value          := '461002';
2670   RETURN l_output_value;
2671 
2672  ELSIF NVL(p_source_8,'
2673 ') =  'Unexpired' AND 
2674 NVL(p_source_9,'
2675 ') =  'N' AND 
2676 NVL(p_source_11,'
2677 ') =  'C' AND 
2678 (NVL(p_source_10,'
2679 ') =  'SINGLE' OR 
2680 NVL(p_source_10,'
2681 ') =  'MULTIPLE' OR 
2682 NVL(p_source_10,'
2683 ') =  'NO_YEAR')
2684  THEN 
2685 --
2686   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2687 
2688       trace
2689          (p_msg      => 'END of AcctDerRule_19'
2690          ,p_level    => C_LEVEL_PROCEDURE
2691          ,p_module   => l_log_module);
2692 
2693   END IF;
2697   l_output_value          := '462002';
2694   x_value_combination_id  :=  null ;
2695   x_value_segment_code    :=  null ;
2696   x_value_type_code       := 'C';
2698   RETURN l_output_value;
2699 
2700  ELSE 
2701     IF p_override_seg_flag = 'Y' THEN 
2702        RETURN '#$NO_OVERRIDE#$';
2703     END IF;
2704  END IF;
2705 
2706 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2707 
2708       trace
2709          (p_msg      => 'END of AcctDerRule_19(invalid)'
2710          ,p_level    => C_LEVEL_PROCEDURE
2711          ,p_module   => l_log_module);
2712 
2713 END IF;
2714 
2715 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
2716 x_value_combination_id  := null;
2717 x_value_segment_code    := null;
2718 x_value_type_code       := null;
2719 l_output_value          := null;
2720 xla_accounting_err_pkg.build_message
2721                  (p_appli_s_name            => 'XLA'
2722                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
2723                  ,p_token_1                 => 'COMPONENT_NAME'
2724                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
2725                                                             l_component_type
2726                                                           , l_component_code
2727                                                           , l_component_type_code
2728                                                           , l_component_appl_id
2729                                                           , l_amb_context_code
2730                                                           )
2731                  ,p_token_2                 => 'OWNER'
2732                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
2733                                                         'XLA_OWNER_TYPE'
2734                                                         ,l_component_type_code
2735                                                         )
2736                  ,p_token_3                 => 'PAD_NAME'
2737                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
2738                  ,p_token_4                 => 'PAD_OWNER'
2739                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
2740                                                         'XLA_OWNER_TYPE'
2741                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
2742                                                         )
2743                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
2744                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
2745                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
2746                  ,p_ae_header_id            => NULL
2747 );
2748 RETURN l_output_value;
2749 EXCEPTION
2750   WHEN xla_exceptions_pkg.application_exception THEN
2751       RAISE;
2752   WHEN OTHERS THEN
2753        xla_exceptions_pkg.raise_message
2754            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_19');
2755 END AcctDerRule_19;
2756 --
2757 
2758 ---------------------------------------
2759 --
2760 -- PRIVATE FUNCTION
2761 --         AcctDerRule_20
2762 --
2763 ---------------------------------------
2764 FUNCTION AcctDerRule_20 (
2765   p_application_id             IN NUMBER
2766 , p_ae_header_id               IN NUMBER
2767 , p_side                       IN VARCHAR2
2768 , p_override_seg_flag          IN VARCHAR2 
2769 --Federal Fund Expired Status
2770  , p_source_8            IN VARCHAR2
2771 --Federal Prior Year Flag
2772  , p_source_9            IN VARCHAR2
2773 --Federal Fund Time Frame
2774  , p_source_10            IN VARCHAR2
2775 --Federal Apportionment Category
2776  , p_source_11            IN VARCHAR2
2777 , x_transaction_coa_id         OUT NOCOPY NUMBER
2778 , x_accounting_coa_id          OUT NOCOPY NUMBER
2779 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
2780 , x_flex_value_set_id          OUT NOCOPY NUMBER
2781 , x_value_type_code            OUT NOCOPY VARCHAR2
2782 , x_value_combination_id       OUT NOCOPY NUMBER
2783 , x_value_segment_code         OUT NOCOPY VARCHAR2
2784 )
2785 RETURN VARCHAR2
2786 IS
2787 l_component_type       VARCHAR2(80)  ;
2788 l_component_code       VARCHAR2(30)  ;
2789 l_component_type_code  VARCHAR2(1)   ;
2790 l_component_appl_id    INTEGER       ;
2791 l_amb_context_code     VARCHAR2(30)  ;
2792 l_log_module           VARCHAR2(240) ;
2793 l_output_value         VARCHAR2(30)  ;
2794 BEGIN
2795 IF g_log_enabled THEN
2796       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_20';
2797 END IF;
2798 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2799 
2800       trace
2801          (p_msg      => 'BEGIN of AcctDerRule_20'
2802          ,p_level    => C_LEVEL_PROCEDURE
2803          ,p_module   => l_log_module);
2804 
2805 END IF;
2806 
2807 l_component_type         := 'AMB_ADR';
2808 l_component_code         := 'FV_AR_490201_MISC_RCT_DR';
2809 l_component_type_code    := 'S';
2810 l_component_appl_id      :=  222;
2811 l_amb_context_code       := 'DEFAULT';
2812 x_transaction_coa_id     :=  null;
2813 x_accounting_coa_id      :=  null;
2814 x_flexfield_segment_code :=  null;
2815 x_flex_value_set_id      := 1009988 ;
2816 
2817 
2818  IF NVL(p_source_8,'
2819 ') =  'Unexpired' AND 
2820 NVL(p_source_9,'
2821 ') =  'N' AND 
2822 (NVL(p_source_11,'
2823 ') =  'A' OR 
2824 NVL(p_source_11,'
2825 ') =  'B' OR 
2826 NVL(p_source_11,'
2827 ') =  'C') AND 
2831 ') =  'MULTIPLE' OR 
2828 (NVL(p_source_10,'
2829 ') =  'SINGLE' OR 
2830 NVL(p_source_10,'
2832 NVL(p_source_10,'
2833 ') =  'NO_YEAR')
2834  THEN 
2835 --
2836   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2837 
2838       trace
2839          (p_msg      => 'END of AcctDerRule_20'
2840          ,p_level    => C_LEVEL_PROCEDURE
2841          ,p_module   => l_log_module);
2842 
2843   END IF;
2844   x_value_combination_id  :=  null ;
2845   x_value_segment_code    :=  null ;
2846   x_value_type_code       := 'C';
2847   l_output_value          := '490201';
2848   RETURN l_output_value;
2849 
2850  ELSE 
2851     IF p_override_seg_flag = 'Y' THEN 
2852        RETURN '#$NO_OVERRIDE#$';
2853     END IF;
2854  END IF;
2855 
2856 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2857 
2858       trace
2859          (p_msg      => 'END of AcctDerRule_20(invalid)'
2860          ,p_level    => C_LEVEL_PROCEDURE
2861          ,p_module   => l_log_module);
2862 
2863 END IF;
2864 
2865 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
2866 x_value_combination_id  := null;
2867 x_value_segment_code    := null;
2868 x_value_type_code       := null;
2869 l_output_value          := null;
2870 xla_accounting_err_pkg.build_message
2871                  (p_appli_s_name            => 'XLA'
2872                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
2873                  ,p_token_1                 => 'COMPONENT_NAME'
2874                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
2875                                                             l_component_type
2876                                                           , l_component_code
2877                                                           , l_component_type_code
2878                                                           , l_component_appl_id
2879                                                           , l_amb_context_code
2880                                                           )
2881                  ,p_token_2                 => 'OWNER'
2882                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
2883                                                         'XLA_OWNER_TYPE'
2884                                                         ,l_component_type_code
2885                                                         )
2886                  ,p_token_3                 => 'PAD_NAME'
2887                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
2888                  ,p_token_4                 => 'PAD_OWNER'
2889                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
2890                                                         'XLA_OWNER_TYPE'
2891                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
2892                                                         )
2893                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
2894                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
2895                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
2896                  ,p_ae_header_id            => NULL
2897 );
2898 RETURN l_output_value;
2899 EXCEPTION
2900   WHEN xla_exceptions_pkg.application_exception THEN
2901       RAISE;
2902   WHEN OTHERS THEN
2903        xla_exceptions_pkg.raise_message
2904            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_20');
2905 END AcctDerRule_20;
2906 --
2907 
2908 ---------------------------------------
2909 --
2910 -- PRIVATE FUNCTION
2911 --         AcctDerRule_21
2912 --
2913 ---------------------------------------
2914 FUNCTION AcctDerRule_21 (
2915   p_application_id             IN NUMBER
2916 , p_ae_header_id               IN NUMBER
2917 , p_side                       IN VARCHAR2
2918 , p_override_seg_flag          IN VARCHAR2 
2919 --Federal Fund Expired Status
2920  , p_source_8            IN VARCHAR2
2921 --Federal Prior Year Flag
2922  , p_source_9            IN VARCHAR2
2923 --Federal Fund Time Frame
2924  , p_source_10            IN VARCHAR2
2925 , x_transaction_coa_id         OUT NOCOPY NUMBER
2926 , x_accounting_coa_id          OUT NOCOPY NUMBER
2927 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
2928 , x_flex_value_set_id          OUT NOCOPY NUMBER
2929 , x_value_type_code            OUT NOCOPY VARCHAR2
2930 , x_value_combination_id       OUT NOCOPY NUMBER
2931 , x_value_segment_code         OUT NOCOPY VARCHAR2
2932 )
2933 RETURN VARCHAR2
2934 IS
2935 l_component_type       VARCHAR2(80)  ;
2936 l_component_code       VARCHAR2(30)  ;
2937 l_component_type_code  VARCHAR2(1)   ;
2938 l_component_appl_id    INTEGER       ;
2939 l_amb_context_code     VARCHAR2(30)  ;
2940 l_log_module           VARCHAR2(240) ;
2941 l_output_value         VARCHAR2(30)  ;
2942 BEGIN
2943 IF g_log_enabled THEN
2944       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_21';
2945 END IF;
2946 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2947 
2948       trace
2949          (p_msg      => 'BEGIN of AcctDerRule_21'
2950          ,p_level    => C_LEVEL_PROCEDURE
2951          ,p_module   => l_log_module);
2952 
2953 END IF;
2954 
2955 l_component_type         := 'AMB_ADR';
2956 l_component_code         := 'FV_AR_497201_MISC_RCT_DR';
2957 l_component_type_code    := 'S';
2958 l_component_appl_id      :=  222;
2962 x_flexfield_segment_code :=  null;
2959 l_amb_context_code       := 'DEFAULT';
2960 x_transaction_coa_id     :=  null;
2961 x_accounting_coa_id      :=  null;
2963 x_flex_value_set_id      := 1009988 ;
2964 
2965 
2966  IF ((NVL(p_source_8,'
2967 ') =  'Expired' AND 
2968 NVL(p_source_9,'
2969 ') =  'Y' AND 
2970 (NVL(p_source_10,'
2971 ') =  'SINGLE' OR 
2972 NVL(p_source_10,'
2973 ') =  'MULTIPLE' OR 
2974 NVL(p_source_10,'
2975 ') =  'NO_YEAR')
2976 ) OR (NVL(p_source_8,'
2977 ') =  'Unexpired' AND 
2978 NVL(p_source_9,'
2979 ') =  'Y' AND 
2980 (NVL(p_source_10,'
2981 ') =  'MULTIPLE' OR 
2982 NVL(p_source_10,'
2983 ') =  'NO_YEAR')
2984 )) THEN 
2985 --
2986   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2987 
2988       trace
2989          (p_msg      => 'END of AcctDerRule_21'
2990          ,p_level    => C_LEVEL_PROCEDURE
2991          ,p_module   => l_log_module);
2992 
2993   END IF;
2994   x_value_combination_id  :=  null ;
2995   x_value_segment_code    :=  null ;
2996   x_value_type_code       := 'C';
2997   l_output_value          := '497201';
2998   RETURN l_output_value;
2999 
3000  ELSE 
3001     IF p_override_seg_flag = 'Y' THEN 
3002        RETURN '#$NO_OVERRIDE#$';
3003     END IF;
3004  END IF;
3005 
3006 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3007 
3008       trace
3009          (p_msg      => 'END of AcctDerRule_21(invalid)'
3010          ,p_level    => C_LEVEL_PROCEDURE
3011          ,p_module   => l_log_module);
3012 
3013 END IF;
3014 
3015 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
3016 x_value_combination_id  := null;
3017 x_value_segment_code    := null;
3018 x_value_type_code       := null;
3019 l_output_value          := null;
3020 xla_accounting_err_pkg.build_message
3021                  (p_appli_s_name            => 'XLA'
3022                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
3023                  ,p_token_1                 => 'COMPONENT_NAME'
3024                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
3025                                                             l_component_type
3026                                                           , l_component_code
3027                                                           , l_component_type_code
3028                                                           , l_component_appl_id
3029                                                           , l_amb_context_code
3030                                                           )
3031                  ,p_token_2                 => 'OWNER'
3032                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
3033                                                         'XLA_OWNER_TYPE'
3034                                                         ,l_component_type_code
3035                                                         )
3036                  ,p_token_3                 => 'PAD_NAME'
3037                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
3038                  ,p_token_4                 => 'PAD_OWNER'
3039                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
3040                                                         'XLA_OWNER_TYPE'
3041                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
3042                                                         )
3043                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
3044                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
3045                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
3046                  ,p_ae_header_id            => NULL
3047 );
3048 RETURN l_output_value;
3049 EXCEPTION
3050   WHEN xla_exceptions_pkg.application_exception THEN
3051       RAISE;
3052   WHEN OTHERS THEN
3053        xla_exceptions_pkg.raise_message
3054            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_21');
3055 END AcctDerRule_21;
3056 --
3057 
3058 ---------------------------------------
3059 --
3060 -- PRIVATE FUNCTION
3061 --         AcctDerRule_22
3062 --
3063 ---------------------------------------
3064 FUNCTION AcctDerRule_22 (
3065   p_application_id             IN NUMBER
3066 , p_ae_header_id               IN NUMBER
3067 , p_side                       IN VARCHAR2
3068 , p_override_seg_flag          IN VARCHAR2 
3069 --Federal Account Rule
3070  , p_source_7            IN VARCHAR2
3071 --Federal Fund Expired Status
3072  , p_source_8            IN VARCHAR2
3073 --Federal Prior Year Flag
3074  , p_source_9            IN VARCHAR2
3075 --Federal Fund Time Frame
3076  , p_source_10            IN VARCHAR2
3077 --Federal Apportionment Category
3078  , p_source_11            IN VARCHAR2
3079 , x_transaction_coa_id         OUT NOCOPY NUMBER
3080 , x_accounting_coa_id          OUT NOCOPY NUMBER
3081 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
3082 , x_flex_value_set_id          OUT NOCOPY NUMBER
3083 , x_value_type_code            OUT NOCOPY VARCHAR2
3084 , x_value_combination_id       OUT NOCOPY NUMBER
3085 , x_value_segment_code         OUT NOCOPY VARCHAR2
3086 )
3087 RETURN VARCHAR2
3088 IS
3089 l_component_type       VARCHAR2(80)  ;
3090 l_component_code       VARCHAR2(30)  ;
3091 l_component_type_code  VARCHAR2(1)   ;
3095 l_output_value         VARCHAR2(30)  ;
3092 l_component_appl_id    INTEGER       ;
3093 l_amb_context_code     VARCHAR2(30)  ;
3094 l_log_module           VARCHAR2(240) ;
3096 BEGIN
3097 IF g_log_enabled THEN
3098       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_22';
3099 END IF;
3100 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3101 
3102       trace
3103          (p_msg      => 'BEGIN of AcctDerRule_22'
3104          ,p_level    => C_LEVEL_PROCEDURE
3105          ,p_module   => l_log_module);
3106 
3107 END IF;
3108 
3109 l_component_type         := 'AMB_ADR';
3110 l_component_code         := 'FV_AR_4X0201_RCT_DR';
3111 l_component_type_code    := 'S';
3112 l_component_appl_id      :=  222;
3113 l_amb_context_code       := 'DEFAULT';
3114 x_transaction_coa_id     :=  null;
3115 x_accounting_coa_id      :=  null;
3116 x_flexfield_segment_code :=  null;
3117 x_flex_value_set_id      := 1009988 ;
3118 
3119 
3120  IF NVL(p_source_8,'
3121 ') =  'Unexpired' AND 
3122 NVL(p_source_9,'
3123 ') =  'N' AND 
3124 (NVL(p_source_11,'
3125 ') =  'A' OR 
3126 NVL(p_source_11,'
3127 ') =  'B' OR 
3128 NVL(p_source_11,'
3129 ') =  'C') AND 
3130 (NVL(p_source_10,'
3131 ') =  'SINGLE' OR 
3132 NVL(p_source_10,'
3133 ') =  'MULTIPLE' OR 
3134 NVL(p_source_10,'
3135 ') =  'NO_YEAR') AND 
3136 NVL(p_source_7,'
3137 ') =  'Overpayment Refund'
3138  THEN 
3139 --
3140   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3141 
3142       trace
3143          (p_msg      => 'END of AcctDerRule_22'
3144          ,p_level    => C_LEVEL_PROCEDURE
3145          ,p_module   => l_log_module);
3146 
3147   END IF;
3148   x_value_combination_id  :=  null ;
3149   x_value_segment_code    :=  null ;
3150   x_value_type_code       := 'C';
3151   l_output_value          := '490201';
3152   RETURN l_output_value;
3153 
3154  ELSIF NVL(p_source_8,'
3155 ') =  'Unexpired' AND 
3156 NVL(p_source_9,'
3157 ') =  'N' AND 
3158 (NVL(p_source_11,'
3159 ') =  'A' OR 
3160 NVL(p_source_11,'
3161 ') =  'B' OR 
3162 NVL(p_source_11,'
3163 ') =  'C') AND 
3164 (NVL(p_source_10,'
3165 ') =  'SINGLE' OR 
3166 NVL(p_source_10,'
3167 ') =  'MULTIPLE' OR 
3168 NVL(p_source_10,'
3169 ') =  'NO_YEAR') AND 
3170 NVL(p_source_7,'
3171 ') =  'Advance Refund'
3172  THEN 
3173 --
3174   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3175 
3176       trace
3177          (p_msg      => 'END of AcctDerRule_22'
3178          ,p_level    => C_LEVEL_PROCEDURE
3179          ,p_module   => l_log_module);
3180 
3181   END IF;
3182   x_value_combination_id  :=  null ;
3183   x_value_segment_code    :=  null ;
3184   x_value_type_code       := 'C';
3185   l_output_value          := '480201';
3186   RETURN l_output_value;
3187 
3188  ELSE 
3189     IF p_override_seg_flag = 'Y' THEN 
3190        RETURN '#$NO_OVERRIDE#$';
3191     END IF;
3192  END IF;
3193 
3194 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3195 
3196       trace
3197          (p_msg      => 'END of AcctDerRule_22(invalid)'
3198          ,p_level    => C_LEVEL_PROCEDURE
3199          ,p_module   => l_log_module);
3200 
3201 END IF;
3202 
3203 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
3204 x_value_combination_id  := null;
3205 x_value_segment_code    := null;
3206 x_value_type_code       := null;
3207 l_output_value          := null;
3208 xla_accounting_err_pkg.build_message
3209                  (p_appli_s_name            => 'XLA'
3210                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
3211                  ,p_token_1                 => 'COMPONENT_NAME'
3212                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
3213                                                             l_component_type
3214                                                           , l_component_code
3215                                                           , l_component_type_code
3216                                                           , l_component_appl_id
3217                                                           , l_amb_context_code
3218                                                           )
3219                  ,p_token_2                 => 'OWNER'
3220                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
3221                                                         'XLA_OWNER_TYPE'
3222                                                         ,l_component_type_code
3223                                                         )
3224                  ,p_token_3                 => 'PAD_NAME'
3225                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
3226                  ,p_token_4                 => 'PAD_OWNER'
3227                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
3228                                                         'XLA_OWNER_TYPE'
3229                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
3230                                                         )
3231                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
3232                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
3233                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
3237 EXCEPTION
3234                  ,p_ae_header_id            => NULL
3235 );
3236 RETURN l_output_value;
3238   WHEN xla_exceptions_pkg.application_exception THEN
3239       RAISE;
3240   WHEN OTHERS THEN
3241        xla_exceptions_pkg.raise_message
3242            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_22');
3243 END AcctDerRule_22;
3244 --
3245 
3246 ---------------------------------------
3247 --
3248 -- PRIVATE FUNCTION
3249 --         AcctDerRule_23
3250 --
3251 ---------------------------------------
3252 FUNCTION AcctDerRule_23 (
3253   p_application_id             IN NUMBER
3254 , p_ae_header_id               IN NUMBER
3255 , p_side                       IN VARCHAR2
3256 , p_override_seg_flag          IN VARCHAR2 
3257 --Federal Account Rule
3258  , p_source_7            IN VARCHAR2
3259 --Federal Fund Expired Status
3260  , p_source_8            IN VARCHAR2
3261 --Federal Prior Year Flag
3262  , p_source_9            IN VARCHAR2
3263 --Federal Fund Time Frame
3264  , p_source_10            IN VARCHAR2
3265 , x_transaction_coa_id         OUT NOCOPY NUMBER
3266 , x_accounting_coa_id          OUT NOCOPY NUMBER
3267 , x_flexfield_segment_code     OUT NOCOPY VARCHAR2
3268 , x_flex_value_set_id          OUT NOCOPY NUMBER
3269 , x_value_type_code            OUT NOCOPY VARCHAR2
3270 , x_value_combination_id       OUT NOCOPY NUMBER
3271 , x_value_segment_code         OUT NOCOPY VARCHAR2
3272 )
3273 RETURN VARCHAR2
3274 IS
3275 l_component_type       VARCHAR2(80)  ;
3276 l_component_code       VARCHAR2(30)  ;
3277 l_component_type_code  VARCHAR2(1)   ;
3278 l_component_appl_id    INTEGER       ;
3279 l_amb_context_code     VARCHAR2(30)  ;
3280 l_log_module           VARCHAR2(240) ;
3281 l_output_value         VARCHAR2(30)  ;
3282 BEGIN
3283 IF g_log_enabled THEN
3284       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_23';
3285 END IF;
3286 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3287 
3288       trace
3289          (p_msg      => 'BEGIN of AcctDerRule_23'
3290          ,p_level    => C_LEVEL_PROCEDURE
3291          ,p_module   => l_log_module);
3292 
3293 END IF;
3294 
3295 l_component_type         := 'AMB_ADR';
3296 l_component_code         := 'FV_AR_4X7201_RCT_DR';
3297 l_component_type_code    := 'S';
3298 l_component_appl_id      :=  222;
3299 l_amb_context_code       := 'DEFAULT';
3300 x_transaction_coa_id     :=  null;
3301 x_accounting_coa_id      :=  null;
3302 x_flexfield_segment_code :=  null;
3303 x_flex_value_set_id      := 1009988 ;
3304 
3305 
3306  IF ((NVL(p_source_8,'
3307 ') =  'Expired' AND 
3308 NVL(p_source_9,'
3309 ') =  'Y' AND 
3310 (NVL(p_source_10,'
3311 ') =  'SINGLE' OR 
3312 NVL(p_source_10,'
3313 ') =  'MULTIPLE' OR 
3314 NVL(p_source_10,'
3315 ') =  'NO_YEAR')
3316 ) OR (NVL(p_source_8,'
3317 ') =  'Unexpired' AND 
3318 NVL(p_source_9,'
3319 ') =  'Y' AND 
3320 (NVL(p_source_10,'
3321 ') =  'MULTIPLE' OR 
3322 NVL(p_source_10,'
3323 ') =  'NO_YEAR')
3324 )) AND NVL(p_source_7,'
3325 ') =  'Overpayment Refund'
3326  THEN 
3327 --
3328   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3329 
3330       trace
3331          (p_msg      => 'END of AcctDerRule_23'
3332          ,p_level    => C_LEVEL_PROCEDURE
3333          ,p_module   => l_log_module);
3334 
3335   END IF;
3336   x_value_combination_id  :=  null ;
3337   x_value_segment_code    :=  null ;
3338   x_value_type_code       := 'C';
3339   l_output_value          := '497201';
3340   RETURN l_output_value;
3341 
3342  ELSIF ((NVL(p_source_8,'
3343 ') =  'Expired' AND 
3344 NVL(p_source_9,'
3345 ') =  'Y' AND 
3346 (NVL(p_source_10,'
3347 ') =  'SINGLE' OR 
3348 NVL(p_source_10,'
3349 ') =  'MUTIPLE' OR 
3350 NVL(p_source_10,'
3351 ') =  'NO_YEAR')
3352 ) OR (NVL(p_source_8,'
3353 ') =  'Unexpired' AND 
3354 NVL(p_source_9,'
3355 ') =  'Y' AND 
3356 (NVL(p_source_10,'
3357 ') =  'MUTIPLE' OR 
3358 NVL(p_source_10,'
3359 ') =  'NO_YEAR')
3360 )) AND NVL(p_source_7,'
3361 ') =  'Advance Refund'
3362  THEN 
3363 --
3364   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3365 
3366       trace
3367          (p_msg      => 'END of AcctDerRule_23'
3368          ,p_level    => C_LEVEL_PROCEDURE
3369          ,p_module   => l_log_module);
3370 
3371   END IF;
3372   x_value_combination_id  :=  null ;
3373   x_value_segment_code    :=  null ;
3374   x_value_type_code       := 'C';
3375   l_output_value          := '487201';
3376   RETURN l_output_value;
3377 
3378  ELSE 
3379     IF p_override_seg_flag = 'Y' THEN 
3380        RETURN '#$NO_OVERRIDE#$';
3381     END IF;
3382  END IF;
3383 
3384 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3385 
3386       trace
3387          (p_msg      => 'END of AcctDerRule_23(invalid)'
3388          ,p_level    => C_LEVEL_PROCEDURE
3389          ,p_module   => l_log_module);
3390 
3391 END IF;
3392 
3393 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
3394 x_value_combination_id  := null;
3395 x_value_segment_code    := null;
3396 x_value_type_code       := null;
3397 l_output_value          := null;
3398 xla_accounting_err_pkg.build_message
3402                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
3399                  (p_appli_s_name            => 'XLA'
3400                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
3401                  ,p_token_1                 => 'COMPONENT_NAME'
3403                                                             l_component_type
3404                                                           , l_component_code
3405                                                           , l_component_type_code
3406                                                           , l_component_appl_id
3407                                                           , l_amb_context_code
3408                                                           )
3409                  ,p_token_2                 => 'OWNER'
3410                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
3411                                                         'XLA_OWNER_TYPE'
3412                                                         ,l_component_type_code
3413                                                         )
3414                  ,p_token_3                 => 'PAD_NAME'
3415                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
3416                  ,p_token_4                 => 'PAD_OWNER'
3417                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
3418                                                         'XLA_OWNER_TYPE'
3419                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
3420                                                         )
3421                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
3422                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
3423                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
3424                  ,p_ae_header_id            => NULL
3425 );
3426 RETURN l_output_value;
3427 EXCEPTION
3428   WHEN xla_exceptions_pkg.application_exception THEN
3429       RAISE;
3430   WHEN OTHERS THEN
3431        xla_exceptions_pkg.raise_message
3432            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_23');
3433 END AcctDerRule_23;
3434 --
3435 
3436 ---------------------------------------
3437 --
3438 -- PRIVATE FUNCTION
3439 --         AcctDerRule_24
3440 --
3441 ---------------------------------------
3442 FUNCTION AcctDerRule_24 (
3443   p_application_id              IN NUMBER
3444 , p_ae_header_id                IN NUMBER
3445 , p_side                        IN VARCHAR2 
3446 --Credit Memo Default Receivable Account
3447  , p_source_12            IN NUMBER
3448 , x_transaction_coa_id         OUT NOCOPY NUMBER
3449 , x_accounting_coa_id          OUT NOCOPY NUMBER
3450 , x_value_type_code            OUT NOCOPY VARCHAR2
3451 )
3452 RETURN NUMBER
3453 IS
3454 l_component_type       VARCHAR2(80)  ;
3455 l_component_code       VARCHAR2(30)  ;
3456 l_component_type_code  VARCHAR2(1)   ;
3457 l_component_appl_id    INTEGER       ;
3458 l_amb_context_code     VARCHAR2(30)  ;
3459 l_log_module           VARCHAR2(240) ;
3460 l_output_value         NUMBER        ;
3461 BEGIN
3462 IF g_log_enabled THEN
3463       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_24';
3464 END IF;
3465 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3466       trace
3467          (p_msg      => 'BEGIN of AcctDerRule_24'
3468          ,p_level    => C_LEVEL_PROCEDURE
3469          ,p_module   => l_log_module);
3470 END IF;
3471 --
3472 l_component_type         := 'AMB_ADR';
3473 l_component_code         := 'MFAR_CM_DEF_REC_CCID';
3474 l_component_type_code    := 'S';
3475 l_component_appl_id      :=  222;
3476 l_amb_context_code       := 'DEFAULT';
3477 x_transaction_coa_id     :=  null;
3478 x_accounting_coa_id      :=  null;
3479 --
3480 
3481  --
3482   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3483       trace
3484          (p_msg      => 'END of AcctDerRule_24'
3485          ,p_level    => C_LEVEL_PROCEDURE
3486          ,p_module   => l_log_module);
3487   END IF;
3488   x_value_type_code := 'S';
3489   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_12));
3490   RETURN l_output_value;
3491 
3492 --
3493 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3494       trace
3495          (p_msg      => 'END of AcctDerRule_24(invalid)'
3496          ,p_level    => C_LEVEL_PROCEDURE
3497          ,p_module   => l_log_module);
3498 END IF;
3499 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
3500 x_value_type_code := null;
3501 l_output_value    := null;
3502 xla_accounting_err_pkg.build_message
3503                  (p_appli_s_name            => 'XLA'
3504                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
3505                  ,p_token_1                 => 'COMPONENT_NAME'
3506                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
3507                                                             l_component_type
3508                                                           , l_component_code
3509                                                           , l_component_type_code
3510                                                           , l_component_appl_id
3511                                                           , l_amb_context_code
3512                                                           )
3516                                                         ,l_component_type_code
3513                  ,p_token_2                 => 'OWNER'
3514                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
3515                                                         'XLA_OWNER_TYPE'
3517                                                         )
3518                  ,p_token_3                 => 'PAD_NAME'
3519                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
3520                  ,p_token_4                 => 'PAD_OWNER'
3521                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
3522                                                         'XLA_OWNER_TYPE'
3523                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
3524                                                         )
3525                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
3526                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
3527                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
3528                  ,p_ae_header_id            => NULL
3529 );
3530 RETURN l_output_value;
3531 EXCEPTION
3532   WHEN xla_exceptions_pkg.application_exception THEN
3533       RAISE;
3534   WHEN OTHERS THEN
3535        xla_exceptions_pkg.raise_message
3536            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_24');
3537 END AcctDerRule_24;
3538 --
3539 
3540 ---------------------------------------
3541 --
3542 -- PRIVATE FUNCTION
3543 --         AcctDerRule_25
3544 --
3545 ---------------------------------------
3546 FUNCTION AcctDerRule_25 (
3547   p_application_id              IN NUMBER
3548 , p_ae_header_id                IN NUMBER
3549 , p_side                        IN VARCHAR2 
3550 --Remittance Bank Account Cash Account
3551  , p_source_13            IN NUMBER
3552 , x_transaction_coa_id         OUT NOCOPY NUMBER
3553 , x_accounting_coa_id          OUT NOCOPY NUMBER
3554 , x_value_type_code            OUT NOCOPY VARCHAR2
3555 )
3556 RETURN NUMBER
3557 IS
3558 l_component_type       VARCHAR2(80)  ;
3559 l_component_code       VARCHAR2(30)  ;
3560 l_component_type_code  VARCHAR2(1)   ;
3561 l_component_appl_id    INTEGER       ;
3562 l_amb_context_code     VARCHAR2(30)  ;
3563 l_log_module           VARCHAR2(240) ;
3564 l_output_value         NUMBER        ;
3565 BEGIN
3566 IF g_log_enabled THEN
3567       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_25';
3568 END IF;
3569 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3570       trace
3571          (p_msg      => 'BEGIN of AcctDerRule_25'
3572          ,p_level    => C_LEVEL_PROCEDURE
3573          ,p_module   => l_log_module);
3574 END IF;
3575 --
3576 l_component_type         := 'AMB_ADR';
3577 l_component_code         := 'MFAR_RCT_DEF_CASH_CCID';
3578 l_component_type_code    := 'S';
3579 l_component_appl_id      :=  222;
3580 l_amb_context_code       := 'DEFAULT';
3581 x_transaction_coa_id     :=  null;
3582 x_accounting_coa_id      :=  null;
3583 --
3584 
3585  --
3586   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3587       trace
3588          (p_msg      => 'END of AcctDerRule_25'
3589          ,p_level    => C_LEVEL_PROCEDURE
3590          ,p_module   => l_log_module);
3591   END IF;
3592   x_value_type_code := 'S';
3593   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_13));
3594   RETURN l_output_value;
3595 
3596 --
3597 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3598       trace
3599          (p_msg      => 'END of AcctDerRule_25(invalid)'
3600          ,p_level    => C_LEVEL_PROCEDURE
3601          ,p_module   => l_log_module);
3602 END IF;
3603 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
3604 x_value_type_code := null;
3605 l_output_value    := null;
3606 xla_accounting_err_pkg.build_message
3607                  (p_appli_s_name            => 'XLA'
3608                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
3609                  ,p_token_1                 => 'COMPONENT_NAME'
3610                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
3611                                                             l_component_type
3612                                                           , l_component_code
3613                                                           , l_component_type_code
3614                                                           , l_component_appl_id
3615                                                           , l_amb_context_code
3616                                                           )
3617                  ,p_token_2                 => 'OWNER'
3618                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
3619                                                         'XLA_OWNER_TYPE'
3620                                                         ,l_component_type_code
3621                                                         )
3622                  ,p_token_3                 => 'PAD_NAME'
3623                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
3624                  ,p_token_4                 => 'PAD_OWNER'
3625                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
3629                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
3626                                                         'XLA_OWNER_TYPE'
3627                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
3628                                                         )
3630                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
3631                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
3632                  ,p_ae_header_id            => NULL
3633 );
3634 RETURN l_output_value;
3635 EXCEPTION
3636   WHEN xla_exceptions_pkg.application_exception THEN
3637       RAISE;
3638   WHEN OTHERS THEN
3639        xla_exceptions_pkg.raise_message
3640            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_25');
3641 END AcctDerRule_25;
3642 --
3643 
3644 ---------------------------------------
3645 --
3646 -- PRIVATE FUNCTION
3647 --         AcctDerRule_26
3648 --
3649 ---------------------------------------
3650 FUNCTION AcctDerRule_26 (
3651   p_application_id              IN NUMBER
3652 , p_ae_header_id                IN NUMBER
3653 , p_side                        IN VARCHAR2 
3654 --Remittance Bank Account Confirmation Account
3655  , p_source_14            IN NUMBER
3656 , x_transaction_coa_id         OUT NOCOPY NUMBER
3657 , x_accounting_coa_id          OUT NOCOPY NUMBER
3658 , x_value_type_code            OUT NOCOPY VARCHAR2
3659 )
3660 RETURN NUMBER
3661 IS
3662 l_component_type       VARCHAR2(80)  ;
3663 l_component_code       VARCHAR2(30)  ;
3664 l_component_type_code  VARCHAR2(1)   ;
3665 l_component_appl_id    INTEGER       ;
3666 l_amb_context_code     VARCHAR2(30)  ;
3667 l_log_module           VARCHAR2(240) ;
3668 l_output_value         NUMBER        ;
3669 BEGIN
3670 IF g_log_enabled THEN
3671       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_26';
3672 END IF;
3673 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3674       trace
3675          (p_msg      => 'BEGIN of AcctDerRule_26'
3676          ,p_level    => C_LEVEL_PROCEDURE
3677          ,p_module   => l_log_module);
3678 END IF;
3679 --
3680 l_component_type         := 'AMB_ADR';
3681 l_component_code         := 'MFAR_RCT_DEF_CONFIRMATION_CCID';
3682 l_component_type_code    := 'S';
3683 l_component_appl_id      :=  222;
3684 l_amb_context_code       := 'DEFAULT';
3685 x_transaction_coa_id     :=  null;
3686 x_accounting_coa_id      :=  null;
3687 --
3688 
3689  --
3690   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3691       trace
3692          (p_msg      => 'END of AcctDerRule_26'
3693          ,p_level    => C_LEVEL_PROCEDURE
3694          ,p_module   => l_log_module);
3695   END IF;
3696   x_value_type_code := 'S';
3697   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_14));
3698   RETURN l_output_value;
3699 
3700 --
3701 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3702       trace
3703          (p_msg      => 'END of AcctDerRule_26(invalid)'
3704          ,p_level    => C_LEVEL_PROCEDURE
3705          ,p_module   => l_log_module);
3706 END IF;
3707 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
3708 x_value_type_code := null;
3709 l_output_value    := null;
3710 xla_accounting_err_pkg.build_message
3711                  (p_appli_s_name            => 'XLA'
3712                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
3713                  ,p_token_1                 => 'COMPONENT_NAME'
3714                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
3715                                                             l_component_type
3716                                                           , l_component_code
3717                                                           , l_component_type_code
3718                                                           , l_component_appl_id
3719                                                           , l_amb_context_code
3720                                                           )
3721                  ,p_token_2                 => 'OWNER'
3722                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
3723                                                         'XLA_OWNER_TYPE'
3724                                                         ,l_component_type_code
3725                                                         )
3726                  ,p_token_3                 => 'PAD_NAME'
3727                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
3728                  ,p_token_4                 => 'PAD_OWNER'
3729                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
3730                                                         'XLA_OWNER_TYPE'
3731                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
3732                                                         )
3733                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
3734                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
3735                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
3736                  ,p_ae_header_id            => NULL
3737 );
3738 RETURN l_output_value;
3739 EXCEPTION
3743        xla_exceptions_pkg.raise_message
3740   WHEN xla_exceptions_pkg.application_exception THEN
3741       RAISE;
3742   WHEN OTHERS THEN
3744            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_26');
3745 END AcctDerRule_26;
3746 --
3747 
3748 ---------------------------------------
3749 --
3750 -- PRIVATE FUNCTION
3751 --         AcctDerRule_27
3752 --
3753 ---------------------------------------
3754 FUNCTION AcctDerRule_27 (
3755   p_application_id              IN NUMBER
3756 , p_ae_header_id                IN NUMBER
3757 , p_side                        IN VARCHAR2 
3758 --Remittance Bank Account Remittance Account
3759  , p_source_15            IN NUMBER
3760 , x_transaction_coa_id         OUT NOCOPY NUMBER
3761 , x_accounting_coa_id          OUT NOCOPY NUMBER
3762 , x_value_type_code            OUT NOCOPY VARCHAR2
3763 )
3764 RETURN NUMBER
3765 IS
3766 l_component_type       VARCHAR2(80)  ;
3767 l_component_code       VARCHAR2(30)  ;
3768 l_component_type_code  VARCHAR2(1)   ;
3769 l_component_appl_id    INTEGER       ;
3770 l_amb_context_code     VARCHAR2(30)  ;
3771 l_log_module           VARCHAR2(240) ;
3772 l_output_value         NUMBER        ;
3773 BEGIN
3774 IF g_log_enabled THEN
3775       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_27';
3776 END IF;
3777 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3778       trace
3779          (p_msg      => 'BEGIN of AcctDerRule_27'
3780          ,p_level    => C_LEVEL_PROCEDURE
3781          ,p_module   => l_log_module);
3782 END IF;
3783 --
3784 l_component_type         := 'AMB_ADR';
3785 l_component_code         := 'MFAR_RCT_DEF_REMITTANCE_CCID';
3786 l_component_type_code    := 'S';
3787 l_component_appl_id      :=  222;
3788 l_amb_context_code       := 'DEFAULT';
3789 x_transaction_coa_id     :=  null;
3790 x_accounting_coa_id      :=  null;
3791 --
3792 
3793  --
3794   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3795       trace
3796          (p_msg      => 'END of AcctDerRule_27'
3797          ,p_level    => C_LEVEL_PROCEDURE
3798          ,p_module   => l_log_module);
3799   END IF;
3800   x_value_type_code := 'S';
3801   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_15));
3802   RETURN l_output_value;
3803 
3804 --
3805 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3806       trace
3807          (p_msg      => 'END of AcctDerRule_27(invalid)'
3808          ,p_level    => C_LEVEL_PROCEDURE
3809          ,p_module   => l_log_module);
3810 END IF;
3811 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
3812 x_value_type_code := null;
3813 l_output_value    := null;
3814 xla_accounting_err_pkg.build_message
3815                  (p_appli_s_name            => 'XLA'
3816                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
3817                  ,p_token_1                 => 'COMPONENT_NAME'
3818                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
3819                                                             l_component_type
3820                                                           , l_component_code
3821                                                           , l_component_type_code
3822                                                           , l_component_appl_id
3823                                                           , l_amb_context_code
3824                                                           )
3825                  ,p_token_2                 => 'OWNER'
3826                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
3827                                                         'XLA_OWNER_TYPE'
3828                                                         ,l_component_type_code
3829                                                         )
3830                  ,p_token_3                 => 'PAD_NAME'
3831                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
3832                  ,p_token_4                 => 'PAD_OWNER'
3833                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
3834                                                         'XLA_OWNER_TYPE'
3835                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
3836                                                         )
3837                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
3838                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
3839                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
3840                  ,p_ae_header_id            => NULL
3841 );
3842 RETURN l_output_value;
3843 EXCEPTION
3844   WHEN xla_exceptions_pkg.application_exception THEN
3845       RAISE;
3846   WHEN OTHERS THEN
3847        xla_exceptions_pkg.raise_message
3848            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_27');
3849 END AcctDerRule_27;
3850 --
3851 
3852 ---------------------------------------
3853 --
3854 -- PRIVATE FUNCTION
3855 --         AcctDerRule_28
3856 --
3857 ---------------------------------------
3858 FUNCTION AcctDerRule_28 (
3859   p_application_id              IN NUMBER
3860 , p_ae_header_id                IN NUMBER
3861 , p_side                        IN VARCHAR2 
3862 --Transaction Default Receivable Account
3866 , x_value_type_code            OUT NOCOPY VARCHAR2
3863  , p_source_16            IN NUMBER
3864 , x_transaction_coa_id         OUT NOCOPY NUMBER
3865 , x_accounting_coa_id          OUT NOCOPY NUMBER
3867 )
3868 RETURN NUMBER
3869 IS
3870 l_component_type       VARCHAR2(80)  ;
3871 l_component_code       VARCHAR2(30)  ;
3872 l_component_type_code  VARCHAR2(1)   ;
3873 l_component_appl_id    INTEGER       ;
3874 l_amb_context_code     VARCHAR2(30)  ;
3875 l_log_module           VARCHAR2(240) ;
3876 l_output_value         NUMBER        ;
3877 BEGIN
3878 IF g_log_enabled THEN
3879       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_28';
3880 END IF;
3881 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3882       trace
3883          (p_msg      => 'BEGIN of AcctDerRule_28'
3884          ,p_level    => C_LEVEL_PROCEDURE
3885          ,p_module   => l_log_module);
3886 END IF;
3887 --
3888 l_component_type         := 'AMB_ADR';
3889 l_component_code         := 'MFAR_TRX_DEF_REC_CCID';
3890 l_component_type_code    := 'S';
3891 l_component_appl_id      :=  222;
3892 l_amb_context_code       := 'DEFAULT';
3893 x_transaction_coa_id     :=  null;
3894 x_accounting_coa_id      :=  null;
3895 --
3896 
3897  --
3898   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3899       trace
3900          (p_msg      => 'END of AcctDerRule_28'
3901          ,p_level    => C_LEVEL_PROCEDURE
3902          ,p_module   => l_log_module);
3903   END IF;
3904   x_value_type_code := 'S';
3905   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_16));
3906   RETURN l_output_value;
3907 
3908 --
3909 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3910       trace
3911          (p_msg      => 'END of AcctDerRule_28(invalid)'
3912          ,p_level    => C_LEVEL_PROCEDURE
3913          ,p_module   => l_log_module);
3914 END IF;
3915 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
3916 x_value_type_code := null;
3917 l_output_value    := null;
3918 xla_accounting_err_pkg.build_message
3919                  (p_appli_s_name            => 'XLA'
3920                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
3921                  ,p_token_1                 => 'COMPONENT_NAME'
3922                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
3923                                                             l_component_type
3924                                                           , l_component_code
3925                                                           , l_component_type_code
3926                                                           , l_component_appl_id
3927                                                           , l_amb_context_code
3928                                                           )
3929                  ,p_token_2                 => 'OWNER'
3930                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
3931                                                         'XLA_OWNER_TYPE'
3932                                                         ,l_component_type_code
3933                                                         )
3934                  ,p_token_3                 => 'PAD_NAME'
3935                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
3936                  ,p_token_4                 => 'PAD_OWNER'
3937                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
3938                                                         'XLA_OWNER_TYPE'
3939                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
3940                                                         )
3941                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
3942                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
3943                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
3944                  ,p_ae_header_id            => NULL
3945 );
3946 RETURN l_output_value;
3947 EXCEPTION
3948   WHEN xla_exceptions_pkg.application_exception THEN
3949       RAISE;
3950   WHEN OTHERS THEN
3951        xla_exceptions_pkg.raise_message
3952            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_28');
3953 END AcctDerRule_28;
3954 --
3955 
3956 ---------------------------------------
3957 --
3958 -- PRIVATE FUNCTION
3959 --         AcctDerRule_29
3960 --
3961 ---------------------------------------
3962 FUNCTION AcctDerRule_29 (
3963   p_application_id              IN NUMBER
3964 , p_ae_header_id                IN NUMBER
3965 , p_side                        IN VARCHAR2 
3966 --Remittance Bank Account Unapplied Account
3967  , p_source_17            IN NUMBER
3968 , x_transaction_coa_id         OUT NOCOPY NUMBER
3969 , x_accounting_coa_id          OUT NOCOPY NUMBER
3970 , x_value_type_code            OUT NOCOPY VARCHAR2
3971 )
3972 RETURN NUMBER
3973 IS
3974 l_component_type       VARCHAR2(80)  ;
3975 l_component_code       VARCHAR2(30)  ;
3976 l_component_type_code  VARCHAR2(1)   ;
3977 l_component_appl_id    INTEGER       ;
3978 l_amb_context_code     VARCHAR2(30)  ;
3979 l_log_module           VARCHAR2(240) ;
3980 l_output_value         NUMBER        ;
3981 BEGIN
3982 IF g_log_enabled THEN
3983       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_29';
3987          (p_msg      => 'BEGIN of AcctDerRule_29'
3984 END IF;
3985 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3986       trace
3988          ,p_level    => C_LEVEL_PROCEDURE
3989          ,p_module   => l_log_module);
3990 END IF;
3991 --
3992 l_component_type         := 'AMB_ADR';
3993 l_component_code         := 'RMT_BNK_UNAPP_CCID';
3994 l_component_type_code    := 'S';
3995 l_component_appl_id      :=  222;
3996 l_amb_context_code       := 'DEFAULT';
3997 x_transaction_coa_id     :=  null;
3998 x_accounting_coa_id      :=  null;
3999 --
4000 
4001  --
4002   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4003       trace
4004          (p_msg      => 'END of AcctDerRule_29'
4005          ,p_level    => C_LEVEL_PROCEDURE
4006          ,p_module   => l_log_module);
4007   END IF;
4008   x_value_type_code := 'S';
4009   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_17));
4010   RETURN l_output_value;
4011 
4012 --
4013 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4014       trace
4015          (p_msg      => 'END of AcctDerRule_29(invalid)'
4016          ,p_level    => C_LEVEL_PROCEDURE
4017          ,p_module   => l_log_module);
4018 END IF;
4019 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
4020 x_value_type_code := null;
4021 l_output_value    := null;
4022 xla_accounting_err_pkg.build_message
4023                  (p_appli_s_name            => 'XLA'
4024                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
4025                  ,p_token_1                 => 'COMPONENT_NAME'
4026                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
4027                                                             l_component_type
4028                                                           , l_component_code
4029                                                           , l_component_type_code
4030                                                           , l_component_appl_id
4031                                                           , l_amb_context_code
4032                                                           )
4033                  ,p_token_2                 => 'OWNER'
4034                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
4035                                                         'XLA_OWNER_TYPE'
4036                                                         ,l_component_type_code
4037                                                         )
4038                  ,p_token_3                 => 'PAD_NAME'
4039                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
4040                  ,p_token_4                 => 'PAD_OWNER'
4041                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
4042                                                         'XLA_OWNER_TYPE'
4043                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
4044                                                         )
4045                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
4046                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
4047                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
4048                  ,p_ae_header_id            => NULL
4049 );
4050 RETURN l_output_value;
4051 EXCEPTION
4052   WHEN xla_exceptions_pkg.application_exception THEN
4053       RAISE;
4054   WHEN OTHERS THEN
4055        xla_exceptions_pkg.raise_message
4056            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_29');
4057 END AcctDerRule_29;
4058 --
4059 
4060 ---------------------------------------
4061 --
4062 -- PRIVATE FUNCTION
4063 --         AcctDerRule_30
4064 --
4065 ---------------------------------------
4066 FUNCTION AcctDerRule_30 (
4067   p_application_id              IN NUMBER
4068 , p_ae_header_id                IN NUMBER
4069 , p_side                        IN VARCHAR2 
4070 --System Gain Account
4071  , p_source_18            IN NUMBER
4072 , x_transaction_coa_id         OUT NOCOPY NUMBER
4073 , x_accounting_coa_id          OUT NOCOPY NUMBER
4074 , x_value_type_code            OUT NOCOPY VARCHAR2
4075 )
4076 RETURN NUMBER
4077 IS
4078 l_component_type       VARCHAR2(80)  ;
4079 l_component_code       VARCHAR2(30)  ;
4080 l_component_type_code  VARCHAR2(1)   ;
4081 l_component_appl_id    INTEGER       ;
4082 l_amb_context_code     VARCHAR2(30)  ;
4083 l_log_module           VARCHAR2(240) ;
4084 l_output_value         NUMBER        ;
4085 BEGIN
4086 IF g_log_enabled THEN
4087       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_30';
4088 END IF;
4089 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4090       trace
4091          (p_msg      => 'BEGIN of AcctDerRule_30'
4092          ,p_level    => C_LEVEL_PROCEDURE
4093          ,p_module   => l_log_module);
4094 END IF;
4095 --
4096 l_component_type         := 'AMB_ADR';
4097 l_component_code         := 'SYS_GAIN_CCID';
4098 l_component_type_code    := 'S';
4099 l_component_appl_id      :=  222;
4100 l_amb_context_code       := 'DEFAULT';
4101 x_transaction_coa_id     :=  null;
4102 x_accounting_coa_id      :=  null;
4103 --
4104 
4105  --
4106   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4107       trace
4108          (p_msg      => 'END of AcctDerRule_30'
4112   x_value_type_code := 'S';
4109          ,p_level    => C_LEVEL_PROCEDURE
4110          ,p_module   => l_log_module);
4111   END IF;
4113   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_18));
4114   RETURN l_output_value;
4115 
4116 --
4117 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4118       trace
4119          (p_msg      => 'END of AcctDerRule_30(invalid)'
4120          ,p_level    => C_LEVEL_PROCEDURE
4121          ,p_module   => l_log_module);
4122 END IF;
4123 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
4124 x_value_type_code := null;
4125 l_output_value    := null;
4126 xla_accounting_err_pkg.build_message
4127                  (p_appli_s_name            => 'XLA'
4128                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
4129                  ,p_token_1                 => 'COMPONENT_NAME'
4130                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
4131                                                             l_component_type
4132                                                           , l_component_code
4133                                                           , l_component_type_code
4134                                                           , l_component_appl_id
4135                                                           , l_amb_context_code
4136                                                           )
4137                  ,p_token_2                 => 'OWNER'
4138                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
4139                                                         'XLA_OWNER_TYPE'
4140                                                         ,l_component_type_code
4141                                                         )
4142                  ,p_token_3                 => 'PAD_NAME'
4143                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
4144                  ,p_token_4                 => 'PAD_OWNER'
4145                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
4146                                                         'XLA_OWNER_TYPE'
4147                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
4148                                                         )
4149                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
4150                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
4151                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
4152                  ,p_ae_header_id            => NULL
4153 );
4154 RETURN l_output_value;
4155 EXCEPTION
4156   WHEN xla_exceptions_pkg.application_exception THEN
4157       RAISE;
4158   WHEN OTHERS THEN
4159        xla_exceptions_pkg.raise_message
4160            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_30');
4161 END AcctDerRule_30;
4162 --
4163 
4164 ---------------------------------------
4165 --
4166 -- PRIVATE FUNCTION
4167 --         AcctDerRule_31
4168 --
4169 ---------------------------------------
4170 FUNCTION AcctDerRule_31 (
4171   p_application_id              IN NUMBER
4172 , p_ae_header_id                IN NUMBER
4173 , p_side                        IN VARCHAR2 
4174 --System Loss Account
4175  , p_source_19            IN NUMBER
4176 , x_transaction_coa_id         OUT NOCOPY NUMBER
4177 , x_accounting_coa_id          OUT NOCOPY NUMBER
4178 , x_value_type_code            OUT NOCOPY VARCHAR2
4179 )
4180 RETURN NUMBER
4181 IS
4182 l_component_type       VARCHAR2(80)  ;
4183 l_component_code       VARCHAR2(30)  ;
4184 l_component_type_code  VARCHAR2(1)   ;
4185 l_component_appl_id    INTEGER       ;
4186 l_amb_context_code     VARCHAR2(30)  ;
4187 l_log_module           VARCHAR2(240) ;
4188 l_output_value         NUMBER        ;
4189 BEGIN
4190 IF g_log_enabled THEN
4191       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_31';
4192 END IF;
4193 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4194       trace
4195          (p_msg      => 'BEGIN of AcctDerRule_31'
4196          ,p_level    => C_LEVEL_PROCEDURE
4197          ,p_module   => l_log_module);
4198 END IF;
4199 --
4200 l_component_type         := 'AMB_ADR';
4201 l_component_code         := 'SYS_LOSS_CCID';
4202 l_component_type_code    := 'S';
4203 l_component_appl_id      :=  222;
4204 l_amb_context_code       := 'DEFAULT';
4205 x_transaction_coa_id     :=  null;
4206 x_accounting_coa_id      :=  null;
4207 --
4208 
4209  --
4210   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4211       trace
4212          (p_msg      => 'END of AcctDerRule_31'
4213          ,p_level    => C_LEVEL_PROCEDURE
4214          ,p_module   => l_log_module);
4215   END IF;
4216   x_value_type_code := 'S';
4217   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_19));
4218   RETURN l_output_value;
4219 
4220 --
4221 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4222       trace
4223          (p_msg      => 'END of AcctDerRule_31(invalid)'
4224          ,p_level    => C_LEVEL_PROCEDURE
4225          ,p_module   => l_log_module);
4226 END IF;
4227 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
4228 x_value_type_code := null;
4229 l_output_value    := null;
4230 xla_accounting_err_pkg.build_message
4231                  (p_appli_s_name            => 'XLA'
4235                                                             l_component_type
4232                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
4233                  ,p_token_1                 => 'COMPONENT_NAME'
4234                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
4236                                                           , l_component_code
4237                                                           , l_component_type_code
4238                                                           , l_component_appl_id
4239                                                           , l_amb_context_code
4240                                                           )
4241                  ,p_token_2                 => 'OWNER'
4242                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
4243                                                         'XLA_OWNER_TYPE'
4244                                                         ,l_component_type_code
4245                                                         )
4246                  ,p_token_3                 => 'PAD_NAME'
4247                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
4248                  ,p_token_4                 => 'PAD_OWNER'
4249                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
4250                                                         'XLA_OWNER_TYPE'
4251                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
4252                                                         )
4253                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
4254                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
4255                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
4256                  ,p_ae_header_id            => NULL
4257 );
4258 RETURN l_output_value;
4259 EXCEPTION
4260   WHEN xla_exceptions_pkg.application_exception THEN
4261       RAISE;
4262   WHEN OTHERS THEN
4263        xla_exceptions_pkg.raise_message
4264            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_31');
4265 END AcctDerRule_31;
4266 --
4267 
4268 ---------------------------------------
4269 --
4270 -- PRIVATE FUNCTION
4271 --         AcctDerRule_32
4272 --
4273 ---------------------------------------
4274 FUNCTION AcctDerRule_32 (
4275   p_application_id              IN NUMBER
4276 , p_ae_header_id                IN NUMBER
4277 , p_side                        IN VARCHAR2 
4278 --Transaction Distribution GL Account
4279  , p_source_4            IN NUMBER
4280 , x_transaction_coa_id         OUT NOCOPY NUMBER
4281 , x_accounting_coa_id          OUT NOCOPY NUMBER
4282 , x_value_type_code            OUT NOCOPY VARCHAR2
4283 )
4284 RETURN NUMBER
4285 IS
4286 l_component_type       VARCHAR2(80)  ;
4287 l_component_code       VARCHAR2(30)  ;
4288 l_component_type_code  VARCHAR2(1)   ;
4289 l_component_appl_id    INTEGER       ;
4290 l_amb_context_code     VARCHAR2(30)  ;
4291 l_log_module           VARCHAR2(240) ;
4292 l_output_value         NUMBER        ;
4293 BEGIN
4294 IF g_log_enabled THEN
4295       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_32';
4296 END IF;
4297 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4298       trace
4299          (p_msg      => 'BEGIN of AcctDerRule_32'
4300          ,p_level    => C_LEVEL_PROCEDURE
4301          ,p_module   => l_log_module);
4302 END IF;
4303 --
4304 l_component_type         := 'AMB_ADR';
4305 l_component_code         := 'TRX_DIST_CCID';
4306 l_component_type_code    := 'S';
4307 l_component_appl_id      :=  222;
4308 l_amb_context_code       := 'DEFAULT';
4309 x_transaction_coa_id     :=  null;
4310 x_accounting_coa_id      :=  null;
4311 --
4312 
4313  --
4314   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4315       trace
4316          (p_msg      => 'END of AcctDerRule_32'
4317          ,p_level    => C_LEVEL_PROCEDURE
4318          ,p_module   => l_log_module);
4319   END IF;
4320   x_value_type_code := 'S';
4321   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_4));
4322   RETURN l_output_value;
4323 
4324 --
4325 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4326       trace
4327          (p_msg      => 'END of AcctDerRule_32(invalid)'
4328          ,p_level    => C_LEVEL_PROCEDURE
4329          ,p_module   => l_log_module);
4330 END IF;
4331 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
4332 x_value_type_code := null;
4333 l_output_value    := null;
4334 xla_accounting_err_pkg.build_message
4335                  (p_appli_s_name            => 'XLA'
4336                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
4337                  ,p_token_1                 => 'COMPONENT_NAME'
4338                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
4339                                                             l_component_type
4340                                                           , l_component_code
4341                                                           , l_component_type_code
4342                                                           , l_component_appl_id
4343                                                           , l_amb_context_code
4344                                                           )
4348                                                         ,l_component_type_code
4345                  ,p_token_2                 => 'OWNER'
4346                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
4347                                                         'XLA_OWNER_TYPE'
4349                                                         )
4350                  ,p_token_3                 => 'PAD_NAME'
4351                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
4352                  ,p_token_4                 => 'PAD_OWNER'
4353                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
4354                                                         'XLA_OWNER_TYPE'
4355                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
4356                                                         )
4357                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
4358                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
4359                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
4360                  ,p_ae_header_id            => NULL
4361 );
4362 RETURN l_output_value;
4363 EXCEPTION
4364   WHEN xla_exceptions_pkg.application_exception THEN
4365       RAISE;
4366   WHEN OTHERS THEN
4367        xla_exceptions_pkg.raise_message
4368            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctDerRule_32');
4369 END AcctDerRule_32;
4370 --
4371 
4372 ---------------------------------------
4373 --
4374 -- PRIVATE FUNCTION
4375 --         AcctLineType_33
4376 --
4377 ---------------------------------------
4378 PROCEDURE AcctLineType_33 (
4379   p_application_id        IN NUMBER
4380  ,p_event_id              IN NUMBER
4381  ,p_calculate_acctd_flag  IN VARCHAR2
4382  ,p_calculate_g_l_flag    IN VARCHAR2
4383  ,p_actual_flag           IN OUT VARCHAR2
4384  ,p_balance_type_code     OUT VARCHAR2
4385  ,p_gain_or_loss_ref      OUT VARCHAR2
4386  
4387 --Distribution GL Account
4388  , p_source_3            IN NUMBER
4389 --Distribution Source Type
4390  , p_source_20            IN VARCHAR2
4391 --Receivable Activity Type
4392  , p_source_21            IN VARCHAR2
4393 --Distribution Line Identifier
4394  , p_source_22            IN NUMBER
4395 --Distribution Type
4396  , p_source_23            IN VARCHAR2
4397 --Entered Amount
4398  , p_source_24            IN NUMBER
4399 --Currency Code
4400  , p_source_25            IN VARCHAR2
4401 --Exchange Date
4402  , p_source_26            IN DATE
4403 --Exchange Rate
4404  , p_source_27            IN NUMBER
4405 --Exchange Rate Type
4406  , p_source_28            IN VARCHAR2
4407 --Applied To Document Accounting Amount
4408  , p_source_29            IN NUMBER
4409 --Bill To Customer Account Identifier
4410  , p_source_30            IN NUMBER
4411 --Bill To Customer Site Use Identifier
4412  , p_source_31            IN NUMBER
4413 --SLA Party Type
4414  , p_source_32            IN VARCHAR2
4415 )
4416 IS
4417 
4418 l_component_type              VARCHAR2(80);
4419 l_component_code              VARCHAR2(30);
4420 l_component_type_code         VARCHAR2(1);
4421 l_component_appl_id           INTEGER;
4422 l_amb_context_code            VARCHAR2(30);
4423 l_entity_code                 VARCHAR2(30);
4424 l_event_class_code            VARCHAR2(30);
4425 l_ae_header_id                NUMBER;
4426 l_event_type_code             VARCHAR2(30);
4427 l_line_definition_code        VARCHAR2(30);
4428 l_line_definition_owner_code  VARCHAR2(1);
4429 --
4430 -- adr variables
4431 l_segment                     VARCHAR2(30);
4432 l_ccid                        NUMBER;
4433 l_adr_transaction_coa_id      NUMBER;
4434 l_adr_accounting_coa_id       NUMBER;
4435 l_adr_flexfield_segment_code  VARCHAR2(30);
4436 l_adr_flex_value_set_id       NUMBER;
4437 l_adr_value_type_code         VARCHAR2(30);
4438 l_adr_value_combination_id    NUMBER;
4439 l_adr_value_segment_code      VARCHAR2(30);
4440 
4441 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
4442 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
4443 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
4444 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
4445 
4446 -- 4262811 Variables ------------------------------------------------------------------------------------------
4447 l_entered_amt_idx             NUMBER;
4448 l_accted_amt_idx              NUMBER;
4449 l_acc_rev_flag                VARCHAR2(1);
4450 l_accrual_line_num            NUMBER;
4451 l_tmp_amt                     NUMBER;
4452 l_acc_rev_natural_side_code   VARCHAR2(1);
4453 
4454 l_num_entries                 NUMBER;
4455 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
4456 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
4457 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
4458 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
4459 l_recog_line_1                NUMBER;
4460 l_recog_line_2                NUMBER;
4461 
4462 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
4463 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
4464 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
4465 
4466 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
4470 
4467 
4468 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
4469 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
4471 ---------------------------------------------------------------------------------------------------------------
4472 
4473 
4474 --
4475 -- bulk performance
4476 --
4477 l_balance_type_code           VARCHAR2(1);
4478 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
4479 l_log_module                  VARCHAR2(240);
4480 
4481 --
4482 -- Upgrade strategy
4483 --
4484 l_actual_upg_option           VARCHAR2(1);
4485 l_enc_upg_option           VARCHAR2(1);
4486 
4487 --
4488 BEGIN
4489 --
4490 IF g_log_enabled THEN
4491       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_33';
4492 END IF;
4493 --
4494 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4495 
4496       trace
4497          (p_msg      => 'BEGIN of AcctLineType_33'
4498          ,p_level    => C_LEVEL_PROCEDURE
4499          ,p_module   => l_log_module);
4500 
4501 END IF;
4502 --
4503 l_component_type             := 'AMB_JLT';
4504 l_component_code             := 'ADJ';
4505 l_component_type_code        := 'S';
4506 l_component_appl_id          :=  222;
4507 l_amb_context_code           := 'DEFAULT';
4508 l_entity_code                := 'ADJUSTMENTS';
4509 l_event_class_code           := 'ADJUSTMENT';
4510 l_event_type_code            := 'ADJUSTMENT_ALL';
4511 l_line_definition_owner_code := 'S';
4512 l_line_definition_code       := 'MFAR_ADJ_ACCRUAL_BALANCING';
4513 --
4514 l_balance_type_code          := 'A';
4515 l_segment                     := NULL;
4516 l_ccid                        := NULL;
4517 l_adr_transaction_coa_id      := NULL;
4518 l_adr_accounting_coa_id       := NULL;
4519 l_adr_flexfield_segment_code  := NULL;
4520 l_adr_flex_value_set_id       := NULL;
4521 l_adr_value_type_code         := NULL;
4522 l_adr_value_combination_id    := NULL;
4523 l_adr_value_segment_code      := NULL;
4524 
4525 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
4526 l_bflow_class_code           := '';    -- 4219869 Business Flow
4527 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
4528 l_budgetary_control_flag     := 'N';
4529 
4530 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
4531 l_bflow_applied_to_amt       := NULL; -- 5132302
4532 l_entered_amt_idx            := NULL;          -- 4262811
4533 l_accted_amt_idx             := NULL;          -- 4262811
4534 l_acc_rev_flag               := NULL;          -- 4262811
4535 l_accrual_line_num           := NULL;          -- 4262811
4536 l_tmp_amt                    := NULL;          -- 4262811
4537 --
4538  
4539 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
4540     l_balance_type_code <> 'B' THEN
4541 IF NVL(p_source_20,'
4542 ') =  'ADJ' AND 
4543 NVL(p_source_21,'
4544 ') <>  'ENDORSEMENT'
4545  THEN 
4546 
4547    --
4548    XLA_AE_LINES_PKG.SetNewLine;
4549 
4550    p_balance_type_code          := l_balance_type_code;
4551    -- set the flag so later we will know whether the gain loss line needs to be created
4552    
4553    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
4554      p_actual_flag :='A';
4555    END IF;
4556 
4557    --
4558    -- bulk performance
4559    --
4560    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
4561                                       p_header_num   => 0); -- 4262811
4562    --
4563    -- set accounting line options
4564    --
4565    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
4566            p_natural_side_code          => 'C'
4567          , p_gain_or_loss_flag          => 'N'
4568          , p_gl_transfer_mode_code      => 'S'
4569          , p_acct_entry_type_code       => 'A'
4570          , p_switch_side_flag           => 'Y'
4571          , p_merge_duplicate_code       => 'A'
4572          );
4573    --
4574    l_acc_rev_natural_side_code := 'D';  -- 4262811
4575    -- 
4576    --
4577    -- set accounting line type info
4578    --
4579    xla_ae_lines_pkg.SetAcctLineType
4580       (p_component_type             => l_component_type
4581       ,p_event_type_code            => l_event_type_code
4582       ,p_line_definition_owner_code => l_line_definition_owner_code
4583       ,p_line_definition_code       => l_line_definition_code
4584       ,p_accounting_line_code       => l_component_code
4585       ,p_accounting_line_type_code  => l_component_type_code
4586       ,p_accounting_line_appl_id    => l_component_appl_id
4587       ,p_amb_context_code           => l_amb_context_code
4588       ,p_entity_code                => l_entity_code
4589       ,p_event_class_code           => l_event_class_code);
4590    --
4591    -- set accounting class
4592    --
4593    xla_ae_lines_pkg.SetAcctClass(
4594            p_accounting_class_code  => 'ADJ'
4595          , p_ae_header_id           => l_ae_header_id
4596          );
4597 
4598    --
4599    -- set rounding class
4600    --
4601    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
4602                       'RECEIVABLE';
4603 
4604    --
4608    -- bulk performance
4605    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
4606    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
4607    --
4609    --
4610    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
4611 
4612    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
4613       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
4614 
4615    -- 4955764
4616    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4617       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
4618 
4619    -- 4458381 Public Sector Enh
4620    
4621    --
4622    -- set accounting attributes for the line type
4623    --
4624    l_entered_amt_idx := 3;
4625    l_accted_amt_idx  := 8;
4626    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
4627    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
4628    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
4629    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
4630    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
4631    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
4632    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
4633    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
4634    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
4635    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
4636    l_rec_acct_attrs.array_date_value(5)  := p_source_26;
4637    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
4638    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
4639    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
4640    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
4641    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
4642    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
4643    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
4644    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
4645    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
4646    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
4647    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
4648    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
4649 
4650    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
4651    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
4652 
4653    ---------------------------------------------------------------------------------------------------------------
4654    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
4655    ---------------------------------------------------------------------------------------------------------------
4656    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
4657 
4658    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4659    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4660 
4661    IF xla_accounting_cache_pkg.GetValueChar
4662          (p_source_code         => 'LEDGER_CATEGORY_CODE'
4663          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
4664    AND l_bflow_method_code = 'PRIOR_ENTRY'
4665 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
4666    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
4667          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
4668        )
4669    THEN
4670          xla_ae_lines_pkg.BflowUpgEntry
4671            (p_business_method_code    => l_bflow_method_code
4672            ,p_business_class_code     => l_bflow_class_code
4673            ,p_balance_type            => l_balance_type_code);
4674    ELSE
4675       NULL;
4676 -- No business flow processing for business flow method of NONE.
4677    END IF;
4678 
4679    --
4680    -- call analytical criteria
4681    --
4682    
4683    --
4684    -- call description
4685    --
4686    -- No description or it is inherited.
4687    --
4688    -- call ADRs
4689    -- Bug 4922099
4690    --
4691    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4692         (NVL(l_actual_upg_option, 'N') = 'O') OR
4693         (NVL(l_enc_upg_option, 'N') = 'O')
4694       )
4695    THEN
4696    NULL;
4697    --
4698    --
4699    
4700   l_ccid := AcctDerRule_7(
4701            p_application_id           => p_application_id
4702          , p_ae_header_id             => l_ae_header_id 
4703 , p_source_3 => p_source_3
4704          , x_transaction_coa_id       => l_adr_transaction_coa_id
4705          , x_accounting_coa_id        => l_adr_accounting_coa_id
4706          , x_value_type_code          => l_adr_value_type_code
4707          , p_side                     => 'NA'
4708    );
4709 
4710    xla_ae_lines_pkg.set_ccid(
4711     p_code_combination_id          => l_ccid
4712   , p_value_type_code              => l_adr_value_type_code
4713   , p_transaction_coa_id           => l_adr_transaction_coa_id
4714   , p_accounting_coa_id            => l_adr_accounting_coa_id
4715   , p_adr_code                     => 'DIST_CCID'
4719   , p_component_type_code          => l_component_type_code
4716   , p_adr_type_code                => 'S'
4717   , p_component_type               => l_component_type
4718   , p_component_code               => l_component_code
4720   , p_component_appl_id            => l_component_appl_id
4721   , p_amb_context_code             => l_amb_context_code
4722   , p_side                         => 'NA'
4723   );
4724 
4725 
4726    --
4727    --
4728    END IF;
4729    --
4730    -- Bug 4922099
4731    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
4732           (NVL(l_enc_upg_option, 'N') = 'O')
4733         ) AND
4734         (l_bflow_method_code = 'PRIOR_ENTRY')
4735       )
4736    THEN
4737       IF
4738       --
4739       1 = 2
4740       --
4741       THEN
4742       xla_accounting_err_pkg.build_message
4743                                     (p_appli_s_name            => 'XLA'
4744                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4745                                     ,p_token_1                 => 'LINE_NUMBER'
4746                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
4747                                     ,p_token_2                 => 'LINE_TYPE_NAME'
4748                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
4749                                                                              l_component_type
4750                                                                             ,l_component_code
4751                                                                             ,l_component_type_code
4752                                                                             ,l_component_appl_id
4753                                                                             ,l_amb_context_code
4754                                                                             ,l_entity_code
4755                                                                             ,l_event_class_code
4756                                                                            )
4757                                     ,p_token_3                 => 'OWNER'
4758                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
4759                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
4760                                                                           ,p_lookup_code    => l_component_type_code
4761                                                                          )
4762                                     ,p_token_4                 => 'PRODUCT_NAME'
4763                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
4764                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
4765                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
4766                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
4767                                     ,p_ae_header_id            =>  NULL
4768                                        );
4769 
4770         IF (C_LEVEL_ERROR>= g_log_level) THEN
4771                  trace
4772                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4773                       ,p_level    => C_LEVEL_ERROR
4774                       ,p_module   => l_log_module);
4775         END IF;
4776       END IF;
4777    END IF;
4778    --
4779    --
4780    ------------------------------------------------------------------------------------------------
4781    -- 4219869 Business Flow
4782    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
4783    -- Prior Entry.  Currently, the following code is always generated.
4784    ------------------------------------------------------------------------------------------------
4785    XLA_AE_LINES_PKG.ValidateCurrentLine;
4786 
4787    ------------------------------------------------------------------------------------
4788    -- 4219869 Business Flow
4789    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
4790    ------------------------------------------------------------------------------------
4791    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4792 
4793    ----------------------------------------------------------------------------------
4794    -- 4219869 Business Flow
4795    -- Update journal entry status -- Need to generate this within IF <condition>
4796    ----------------------------------------------------------------------------------
4797    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4798          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
4799          ,p_balance_type_code => l_balance_type_code
4800          );
4801 
4802    -------------------------------------------------------------------------------------------
4803    -- 4262811 - Generate the Accrual Reversal lines
4804    -------------------------------------------------------------------------------------------
4805    BEGIN
4806       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
4807                               (g_array_event(p_event_id).array_value_num('header_index'));
4808       IF l_acc_rev_flag IS NULL THEN
4809          l_acc_rev_flag := 'N';
4810       END IF;
4811    EXCEPTION
4812       WHEN OTHERS THEN
4813          l_acc_rev_flag := 'N';
4814    END;
4815    --
4816    IF (l_acc_rev_flag = 'Y') THEN
4817 
4821        ------------------------------------------------------------------------------------------
4818        -- 4645092  ------------------------------------------------------------------------------
4819        -- To allow MPA report to determine if it should generate report process
4820        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
4822 
4823        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
4824        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
4825    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
4826    -- call ADRs
4827    -- Bug 4922099
4828    --
4829    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4830         (NVL(l_actual_upg_option, 'N') = 'O') OR
4831         (NVL(l_enc_upg_option, 'N') = 'O')
4832       )
4833    THEN
4834    NULL;
4835    --
4836    --
4837    
4838   l_ccid := AcctDerRule_7(
4839            p_application_id           => p_application_id
4840          , p_ae_header_id             => l_ae_header_id 
4841 , p_source_3 => p_source_3
4842          , x_transaction_coa_id       => l_adr_transaction_coa_id
4843          , x_accounting_coa_id        => l_adr_accounting_coa_id
4844          , x_value_type_code          => l_adr_value_type_code
4845          , p_side                     => 'NA'
4846    );
4847 
4848    xla_ae_lines_pkg.set_ccid(
4849     p_code_combination_id          => l_ccid
4850   , p_value_type_code              => l_adr_value_type_code
4851   , p_transaction_coa_id           => l_adr_transaction_coa_id
4852   , p_accounting_coa_id            => l_adr_accounting_coa_id
4853   , p_adr_code                     => 'DIST_CCID'
4854   , p_adr_type_code                => 'S'
4855   , p_component_type               => l_component_type
4856   , p_component_code               => l_component_code
4857   , p_component_type_code          => l_component_type_code
4858   , p_component_appl_id            => l_component_appl_id
4859   , p_amb_context_code             => l_amb_context_code
4860   , p_side                         => 'NA'
4861   );
4862 
4863 
4864    --
4865    --
4866    END IF;
4867 
4868        --
4869        -- Update the line information that should be overwritten
4870        --
4871        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
4872                                          p_header_num   => 1);
4873        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
4874 
4875        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
4876 
4877        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
4878           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
4879        END IF;
4880 
4881       --
4882       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
4883       --
4884       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
4885           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
4886       ELSE
4887           ---------------------------------------------------------------------------------------------------
4888           -- 4262811a Switch Sign
4889           ---------------------------------------------------------------------------------------------------
4890           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
4891           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4892                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4893           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4894                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4895           -- 5132302
4896           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
4897                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4898 
4899       END IF;
4900 
4901       -- 4955764
4902       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4903       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
4904 
4905 
4906       XLA_AE_LINES_PKG.ValidateCurrentLine;
4907       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4908 
4909       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4910                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
4911                ,p_balance_type_code => l_balance_type_code);
4912 
4913    END IF;
4914 
4915    -----------------------------------------------------------------------------------------
4916    -- 4262811 Multiperiod Accounting
4917    -----------------------------------------------------------------------------------------
4918      -- No MPA option is assigned.
4919 
4920 
4921 END IF;
4922 END IF;
4923 --
4924 
4925 --
4926 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4927    trace
4928       (p_msg      => 'END of AcctLineType_33'
4929       ,p_level    => C_LEVEL_PROCEDURE
4930       ,p_module   => l_log_module);
4931 END IF;
4932 --
4933 EXCEPTION
4934   WHEN xla_exceptions_pkg.application_exception THEN
4935       RAISE;
4939 END AcctLineType_33;
4936   WHEN OTHERS THEN
4937        xla_exceptions_pkg.raise_message
4938            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_33');
4940 --
4941 
4942 ---------------------------------------
4943 --
4944 -- PRIVATE FUNCTION
4945 --         AcctLineType_34
4946 --
4947 ---------------------------------------
4948 PROCEDURE AcctLineType_34 (
4949   p_application_id        IN NUMBER
4950  ,p_event_id              IN NUMBER
4951  ,p_calculate_acctd_flag  IN VARCHAR2
4952  ,p_calculate_g_l_flag    IN VARCHAR2
4953  ,p_actual_flag           IN OUT VARCHAR2
4954  ,p_balance_type_code     OUT VARCHAR2
4955  ,p_gain_or_loss_ref      OUT VARCHAR2
4956  
4957 --Distribution GL Account
4958  , p_source_3            IN NUMBER
4959 --Distribution Source Type
4960  , p_source_20            IN VARCHAR2
4961 --Receivable Activity Type
4962  , p_source_21            IN VARCHAR2
4963 --Distribution Line Identifier
4964  , p_source_22            IN NUMBER
4965 --Distribution Type
4966  , p_source_23            IN VARCHAR2
4967 --Entered Amount
4968  , p_source_24            IN NUMBER
4969 --Currency Code
4970  , p_source_25            IN VARCHAR2
4971 --Exchange Date
4972  , p_source_26            IN DATE
4973 --Exchange Rate
4974  , p_source_27            IN NUMBER
4975 --Exchange Rate Type
4976  , p_source_28            IN VARCHAR2
4977 --Applied To Document Accounting Amount
4978  , p_source_29            IN NUMBER
4979 --Bill To Customer Account Identifier
4980  , p_source_30            IN NUMBER
4981 --Bill To Customer Site Use Identifier
4982  , p_source_31            IN NUMBER
4983 --SLA Party Type
4984  , p_source_32            IN VARCHAR2
4985 )
4986 IS
4987 
4988 l_component_type              VARCHAR2(80);
4989 l_component_code              VARCHAR2(30);
4990 l_component_type_code         VARCHAR2(1);
4991 l_component_appl_id           INTEGER;
4992 l_amb_context_code            VARCHAR2(30);
4993 l_entity_code                 VARCHAR2(30);
4994 l_event_class_code            VARCHAR2(30);
4995 l_ae_header_id                NUMBER;
4996 l_event_type_code             VARCHAR2(30);
4997 l_line_definition_code        VARCHAR2(30);
4998 l_line_definition_owner_code  VARCHAR2(1);
4999 --
5000 -- adr variables
5001 l_segment                     VARCHAR2(30);
5002 l_ccid                        NUMBER;
5003 l_adr_transaction_coa_id      NUMBER;
5004 l_adr_accounting_coa_id       NUMBER;
5005 l_adr_flexfield_segment_code  VARCHAR2(30);
5006 l_adr_flex_value_set_id       NUMBER;
5007 l_adr_value_type_code         VARCHAR2(30);
5008 l_adr_value_combination_id    NUMBER;
5009 l_adr_value_segment_code      VARCHAR2(30);
5010 
5011 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
5012 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
5013 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
5014 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
5015 
5016 -- 4262811 Variables ------------------------------------------------------------------------------------------
5017 l_entered_amt_idx             NUMBER;
5018 l_accted_amt_idx              NUMBER;
5019 l_acc_rev_flag                VARCHAR2(1);
5020 l_accrual_line_num            NUMBER;
5021 l_tmp_amt                     NUMBER;
5022 l_acc_rev_natural_side_code   VARCHAR2(1);
5023 
5024 l_num_entries                 NUMBER;
5025 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
5026 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
5027 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
5028 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
5029 l_recog_line_1                NUMBER;
5030 l_recog_line_2                NUMBER;
5031 
5032 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
5033 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
5034 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
5035 
5036 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
5037 
5038 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
5039 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
5040 
5041 ---------------------------------------------------------------------------------------------------------------
5042 
5043 
5044 --
5045 -- bulk performance
5046 --
5047 l_balance_type_code           VARCHAR2(1);
5048 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
5049 l_log_module                  VARCHAR2(240);
5050 
5051 --
5052 -- Upgrade strategy
5053 --
5054 l_actual_upg_option           VARCHAR2(1);
5055 l_enc_upg_option           VARCHAR2(1);
5056 
5057 --
5058 BEGIN
5059 --
5060 IF g_log_enabled THEN
5061       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_34';
5062 END IF;
5063 --
5064 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5065 
5066       trace
5067          (p_msg      => 'BEGIN of AcctLineType_34'
5068          ,p_level    => C_LEVEL_PROCEDURE
5069          ,p_module   => l_log_module);
5070 
5071 END IF;
5072 --
5073 l_component_type             := 'AMB_JLT';
5077 l_amb_context_code           := 'DEFAULT';
5074 l_component_code             := 'ADJ_BR_ENDORSE';
5075 l_component_type_code        := 'S';
5076 l_component_appl_id          :=  222;
5078 l_entity_code                := 'ADJUSTMENTS';
5079 l_event_class_code           := 'ADJUSTMENT';
5080 l_event_type_code            := 'ADJUSTMENT_ALL';
5081 l_line_definition_owner_code := 'S';
5082 l_line_definition_code       := 'MFAR_ADJ_ACCRUAL_BALANCING';
5083 --
5084 l_balance_type_code          := 'A';
5085 l_segment                     := NULL;
5086 l_ccid                        := NULL;
5087 l_adr_transaction_coa_id      := NULL;
5088 l_adr_accounting_coa_id       := NULL;
5089 l_adr_flexfield_segment_code  := NULL;
5090 l_adr_flex_value_set_id       := NULL;
5091 l_adr_value_type_code         := NULL;
5092 l_adr_value_combination_id    := NULL;
5093 l_adr_value_segment_code      := NULL;
5094 
5095 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
5096 l_bflow_class_code           := '';    -- 4219869 Business Flow
5097 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
5098 l_budgetary_control_flag     := 'N';
5099 
5100 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
5101 l_bflow_applied_to_amt       := NULL; -- 5132302
5102 l_entered_amt_idx            := NULL;          -- 4262811
5103 l_accted_amt_idx             := NULL;          -- 4262811
5104 l_acc_rev_flag               := NULL;          -- 4262811
5105 l_accrual_line_num           := NULL;          -- 4262811
5106 l_tmp_amt                    := NULL;          -- 4262811
5107 --
5108  
5109 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
5110     l_balance_type_code <> 'B' THEN
5111 IF NVL(p_source_20,'
5112 ') =  'ADJ' AND 
5113 NVL(p_source_21,'
5114 ') =  'ENDORSEMENT'
5115  THEN 
5116 
5117    --
5118    XLA_AE_LINES_PKG.SetNewLine;
5119 
5120    p_balance_type_code          := l_balance_type_code;
5121    -- set the flag so later we will know whether the gain loss line needs to be created
5122    
5123    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
5124      p_actual_flag :='A';
5125    END IF;
5126 
5127    --
5128    -- bulk performance
5129    --
5130    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
5131                                       p_header_num   => 0); -- 4262811
5132    --
5133    -- set accounting line options
5134    --
5135    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
5136            p_natural_side_code          => 'C'
5137          , p_gain_or_loss_flag          => 'N'
5138          , p_gl_transfer_mode_code      => 'S'
5139          , p_acct_entry_type_code       => 'A'
5140          , p_switch_side_flag           => 'Y'
5141          , p_merge_duplicate_code       => 'A'
5142          );
5143    --
5144    l_acc_rev_natural_side_code := 'D';  -- 4262811
5145    -- 
5146    --
5147    -- set accounting line type info
5148    --
5149    xla_ae_lines_pkg.SetAcctLineType
5150       (p_component_type             => l_component_type
5151       ,p_event_type_code            => l_event_type_code
5152       ,p_line_definition_owner_code => l_line_definition_owner_code
5153       ,p_line_definition_code       => l_line_definition_code
5154       ,p_accounting_line_code       => l_component_code
5155       ,p_accounting_line_type_code  => l_component_type_code
5156       ,p_accounting_line_appl_id    => l_component_appl_id
5157       ,p_amb_context_code           => l_amb_context_code
5158       ,p_entity_code                => l_entity_code
5159       ,p_event_class_code           => l_event_class_code);
5160    --
5161    -- set accounting class
5162    --
5163    xla_ae_lines_pkg.SetAcctClass(
5164            p_accounting_class_code  => 'ENDORSEMENT'
5165          , p_ae_header_id           => l_ae_header_id
5166          );
5167 
5168    --
5169    -- set rounding class
5170    --
5171    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
5172                       'RECEIVABLE';
5173 
5174    --
5175    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
5176    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
5177    --
5178    -- bulk performance
5179    --
5180    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
5181 
5182    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
5183       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
5184 
5185    -- 4955764
5186    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5187       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
5188 
5189    -- 4458381 Public Sector Enh
5190    
5191    --
5192    -- set accounting attributes for the line type
5193    --
5194    l_entered_amt_idx := 3;
5195    l_accted_amt_idx  := 8;
5196    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
5197    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
5198    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
5199    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
5200    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
5204    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
5201    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
5202    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
5203    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
5205    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
5206    l_rec_acct_attrs.array_date_value(5)  := p_source_26;
5207    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
5208    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
5209    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
5210    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
5211    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
5212    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
5213    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
5214    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
5215    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
5216    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
5217    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
5218    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
5219 
5220    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
5221    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
5222 
5223    ---------------------------------------------------------------------------------------------------------------
5224    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
5225    ---------------------------------------------------------------------------------------------------------------
5226    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
5227 
5228    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5229    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5230 
5231    IF xla_accounting_cache_pkg.GetValueChar
5232          (p_source_code         => 'LEDGER_CATEGORY_CODE'
5233          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
5234    AND l_bflow_method_code = 'PRIOR_ENTRY'
5235 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
5236    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
5237          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
5238        )
5239    THEN
5240          xla_ae_lines_pkg.BflowUpgEntry
5241            (p_business_method_code    => l_bflow_method_code
5242            ,p_business_class_code     => l_bflow_class_code
5243            ,p_balance_type            => l_balance_type_code);
5244    ELSE
5245       NULL;
5246 -- No business flow processing for business flow method of NONE.
5247    END IF;
5248 
5249    --
5250    -- call analytical criteria
5251    --
5252    
5253    --
5254    -- call description
5255    --
5256    -- No description or it is inherited.
5257    --
5258    -- call ADRs
5259    -- Bug 4922099
5260    --
5261    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5262         (NVL(l_actual_upg_option, 'N') = 'O') OR
5263         (NVL(l_enc_upg_option, 'N') = 'O')
5264       )
5265    THEN
5266    NULL;
5267    --
5268    --
5269    
5270   l_ccid := AcctDerRule_7(
5271            p_application_id           => p_application_id
5272          , p_ae_header_id             => l_ae_header_id 
5273 , p_source_3 => p_source_3
5274          , x_transaction_coa_id       => l_adr_transaction_coa_id
5275          , x_accounting_coa_id        => l_adr_accounting_coa_id
5276          , x_value_type_code          => l_adr_value_type_code
5277          , p_side                     => 'NA'
5278    );
5279 
5280    xla_ae_lines_pkg.set_ccid(
5281     p_code_combination_id          => l_ccid
5282   , p_value_type_code              => l_adr_value_type_code
5283   , p_transaction_coa_id           => l_adr_transaction_coa_id
5284   , p_accounting_coa_id            => l_adr_accounting_coa_id
5285   , p_adr_code                     => 'DIST_CCID'
5286   , p_adr_type_code                => 'S'
5287   , p_component_type               => l_component_type
5288   , p_component_code               => l_component_code
5289   , p_component_type_code          => l_component_type_code
5290   , p_component_appl_id            => l_component_appl_id
5291   , p_amb_context_code             => l_amb_context_code
5292   , p_side                         => 'NA'
5293   );
5294 
5295 
5296    --
5297    --
5298    END IF;
5299    --
5300    -- Bug 4922099
5301    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
5302           (NVL(l_enc_upg_option, 'N') = 'O')
5303         ) AND
5304         (l_bflow_method_code = 'PRIOR_ENTRY')
5305       )
5306    THEN
5307       IF
5308       --
5309       1 = 2
5310       --
5311       THEN
5312       xla_accounting_err_pkg.build_message
5313                                     (p_appli_s_name            => 'XLA'
5314                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5315                                     ,p_token_1                 => 'LINE_NUMBER'
5316                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
5320                                                                             ,l_component_code
5317                                     ,p_token_2                 => 'LINE_TYPE_NAME'
5318                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
5319                                                                              l_component_type
5321                                                                             ,l_component_type_code
5322                                                                             ,l_component_appl_id
5323                                                                             ,l_amb_context_code
5324                                                                             ,l_entity_code
5325                                                                             ,l_event_class_code
5326                                                                            )
5327                                     ,p_token_3                 => 'OWNER'
5328                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
5329                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
5330                                                                           ,p_lookup_code    => l_component_type_code
5331                                                                          )
5332                                     ,p_token_4                 => 'PRODUCT_NAME'
5333                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
5334                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
5335                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
5336                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
5337                                     ,p_ae_header_id            =>  NULL
5338                                        );
5339 
5340         IF (C_LEVEL_ERROR>= g_log_level) THEN
5341                  trace
5342                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5343                       ,p_level    => C_LEVEL_ERROR
5344                       ,p_module   => l_log_module);
5345         END IF;
5346       END IF;
5347    END IF;
5348    --
5349    --
5350    ------------------------------------------------------------------------------------------------
5351    -- 4219869 Business Flow
5352    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
5353    -- Prior Entry.  Currently, the following code is always generated.
5354    ------------------------------------------------------------------------------------------------
5355    XLA_AE_LINES_PKG.ValidateCurrentLine;
5356 
5357    ------------------------------------------------------------------------------------
5358    -- 4219869 Business Flow
5359    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
5360    ------------------------------------------------------------------------------------
5361    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5362 
5363    ----------------------------------------------------------------------------------
5364    -- 4219869 Business Flow
5365    -- Update journal entry status -- Need to generate this within IF <condition>
5366    ----------------------------------------------------------------------------------
5367    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5368          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
5369          ,p_balance_type_code => l_balance_type_code
5370          );
5371 
5372    -------------------------------------------------------------------------------------------
5373    -- 4262811 - Generate the Accrual Reversal lines
5374    -------------------------------------------------------------------------------------------
5375    BEGIN
5376       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
5377                               (g_array_event(p_event_id).array_value_num('header_index'));
5378       IF l_acc_rev_flag IS NULL THEN
5379          l_acc_rev_flag := 'N';
5380       END IF;
5381    EXCEPTION
5382       WHEN OTHERS THEN
5383          l_acc_rev_flag := 'N';
5384    END;
5385    --
5386    IF (l_acc_rev_flag = 'Y') THEN
5387 
5388        -- 4645092  ------------------------------------------------------------------------------
5389        -- To allow MPA report to determine if it should generate report process
5390        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
5391        ------------------------------------------------------------------------------------------
5392 
5393        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
5394        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
5395    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
5396    -- call ADRs
5397    -- Bug 4922099
5398    --
5399    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5400         (NVL(l_actual_upg_option, 'N') = 'O') OR
5401         (NVL(l_enc_upg_option, 'N') = 'O')
5402       )
5403    THEN
5404    NULL;
5405    --
5406    --
5407    
5408   l_ccid := AcctDerRule_7(
5409            p_application_id           => p_application_id
5410          , p_ae_header_id             => l_ae_header_id 
5411 , p_source_3 => p_source_3
5415          , p_side                     => 'NA'
5412          , x_transaction_coa_id       => l_adr_transaction_coa_id
5413          , x_accounting_coa_id        => l_adr_accounting_coa_id
5414          , x_value_type_code          => l_adr_value_type_code
5416    );
5417 
5418    xla_ae_lines_pkg.set_ccid(
5419     p_code_combination_id          => l_ccid
5420   , p_value_type_code              => l_adr_value_type_code
5421   , p_transaction_coa_id           => l_adr_transaction_coa_id
5422   , p_accounting_coa_id            => l_adr_accounting_coa_id
5423   , p_adr_code                     => 'DIST_CCID'
5424   , p_adr_type_code                => 'S'
5425   , p_component_type               => l_component_type
5426   , p_component_code               => l_component_code
5427   , p_component_type_code          => l_component_type_code
5428   , p_component_appl_id            => l_component_appl_id
5429   , p_amb_context_code             => l_amb_context_code
5430   , p_side                         => 'NA'
5431   );
5432 
5433 
5434    --
5435    --
5436    END IF;
5437 
5438        --
5439        -- Update the line information that should be overwritten
5440        --
5441        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
5442                                          p_header_num   => 1);
5443        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
5444 
5445        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
5446 
5447        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
5448           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
5449        END IF;
5450 
5451       --
5452       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
5453       --
5454       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
5455           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
5456       ELSE
5457           ---------------------------------------------------------------------------------------------------
5458           -- 4262811a Switch Sign
5459           ---------------------------------------------------------------------------------------------------
5460           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
5461           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5462                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5463           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5464                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5465           -- 5132302
5466           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
5467                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5468 
5469       END IF;
5470 
5471       -- 4955764
5472       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5473       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
5474 
5475 
5476       XLA_AE_LINES_PKG.ValidateCurrentLine;
5477       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5478 
5479       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5480                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
5481                ,p_balance_type_code => l_balance_type_code);
5482 
5483    END IF;
5484 
5485    -----------------------------------------------------------------------------------------
5486    -- 4262811 Multiperiod Accounting
5487    -----------------------------------------------------------------------------------------
5488      -- No MPA option is assigned.
5489 
5490 
5491 END IF;
5492 END IF;
5493 --
5494 
5495 --
5496 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5497    trace
5498       (p_msg      => 'END of AcctLineType_34'
5499       ,p_level    => C_LEVEL_PROCEDURE
5500       ,p_module   => l_log_module);
5501 END IF;
5502 --
5503 EXCEPTION
5504   WHEN xla_exceptions_pkg.application_exception THEN
5505       RAISE;
5506   WHEN OTHERS THEN
5507        xla_exceptions_pkg.raise_message
5508            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_34');
5509 END AcctLineType_34;
5510 --
5511 
5512 ---------------------------------------
5513 --
5514 -- PRIVATE FUNCTION
5515 --         AcctLineType_35
5516 --
5517 ---------------------------------------
5518 PROCEDURE AcctLineType_35 (
5519   p_application_id        IN NUMBER
5520  ,p_event_id              IN NUMBER
5521  ,p_calculate_acctd_flag  IN VARCHAR2
5522  ,p_calculate_g_l_flag    IN VARCHAR2
5523  ,p_actual_flag           IN OUT VARCHAR2
5524  ,p_balance_type_code     OUT VARCHAR2
5525  ,p_gain_or_loss_ref      OUT VARCHAR2
5526  
5527 --Distribution GL Account
5528  , p_source_3            IN NUMBER
5529 --Distribution Source Type
5530  , p_source_20            IN VARCHAR2
5531 --Distribution Line Identifier
5532  , p_source_22            IN NUMBER
5533 --Distribution Type
5534  , p_source_23            IN VARCHAR2
5538  , p_source_25            IN VARCHAR2
5535 --Entered Amount
5536  , p_source_24            IN NUMBER
5537 --Currency Code
5539 --Exchange Date
5540  , p_source_26            IN DATE
5541 --Exchange Rate
5542  , p_source_27            IN NUMBER
5543 --Exchange Rate Type
5544  , p_source_28            IN VARCHAR2
5545 --Applied To Document Accounting Amount
5546  , p_source_29            IN NUMBER
5547 --Bill To Customer Account Identifier
5548  , p_source_30            IN NUMBER
5549 --Bill To Customer Site Use Identifier
5550  , p_source_31            IN NUMBER
5551 --SLA Party Type
5552  , p_source_32            IN VARCHAR2
5553 )
5554 IS
5555 
5556 l_component_type              VARCHAR2(80);
5557 l_component_code              VARCHAR2(30);
5558 l_component_type_code         VARCHAR2(1);
5559 l_component_appl_id           INTEGER;
5560 l_amb_context_code            VARCHAR2(30);
5561 l_entity_code                 VARCHAR2(30);
5562 l_event_class_code            VARCHAR2(30);
5563 l_ae_header_id                NUMBER;
5564 l_event_type_code             VARCHAR2(30);
5565 l_line_definition_code        VARCHAR2(30);
5566 l_line_definition_owner_code  VARCHAR2(1);
5567 --
5568 -- adr variables
5569 l_segment                     VARCHAR2(30);
5570 l_ccid                        NUMBER;
5571 l_adr_transaction_coa_id      NUMBER;
5572 l_adr_accounting_coa_id       NUMBER;
5573 l_adr_flexfield_segment_code  VARCHAR2(30);
5574 l_adr_flex_value_set_id       NUMBER;
5575 l_adr_value_type_code         VARCHAR2(30);
5576 l_adr_value_combination_id    NUMBER;
5577 l_adr_value_segment_code      VARCHAR2(30);
5578 
5579 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
5580 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
5581 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
5582 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
5583 
5584 -- 4262811 Variables ------------------------------------------------------------------------------------------
5585 l_entered_amt_idx             NUMBER;
5586 l_accted_amt_idx              NUMBER;
5587 l_acc_rev_flag                VARCHAR2(1);
5588 l_accrual_line_num            NUMBER;
5589 l_tmp_amt                     NUMBER;
5590 l_acc_rev_natural_side_code   VARCHAR2(1);
5591 
5592 l_num_entries                 NUMBER;
5593 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
5594 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
5595 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
5596 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
5597 l_recog_line_1                NUMBER;
5598 l_recog_line_2                NUMBER;
5599 
5600 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
5601 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
5602 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
5603 
5604 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
5605 
5606 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
5607 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
5608 
5609 ---------------------------------------------------------------------------------------------------------------
5610 
5611 
5612 --
5613 -- bulk performance
5614 --
5615 l_balance_type_code           VARCHAR2(1);
5616 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
5617 l_log_module                  VARCHAR2(240);
5618 
5619 --
5620 -- Upgrade strategy
5621 --
5622 l_actual_upg_option           VARCHAR2(1);
5623 l_enc_upg_option           VARCHAR2(1);
5624 
5625 --
5626 BEGIN
5627 --
5628 IF g_log_enabled THEN
5629       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_35';
5630 END IF;
5631 --
5632 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5633 
5634       trace
5635          (p_msg      => 'BEGIN of AcctLineType_35'
5636          ,p_level    => C_LEVEL_PROCEDURE
5637          ,p_module   => l_log_module);
5638 
5639 END IF;
5640 --
5641 l_component_type             := 'AMB_JLT';
5642 l_component_code             := 'ADJ_CHRG';
5643 l_component_type_code        := 'S';
5644 l_component_appl_id          :=  222;
5645 l_amb_context_code           := 'DEFAULT';
5646 l_entity_code                := 'ADJUSTMENTS';
5647 l_event_class_code           := 'ADJUSTMENT';
5648 l_event_type_code            := 'ADJUSTMENT_ALL';
5649 l_line_definition_owner_code := 'S';
5650 l_line_definition_code       := 'MFAR_ADJ_ACCRUAL_BALANCING';
5651 --
5652 l_balance_type_code          := 'A';
5653 l_segment                     := NULL;
5654 l_ccid                        := NULL;
5655 l_adr_transaction_coa_id      := NULL;
5656 l_adr_accounting_coa_id       := NULL;
5657 l_adr_flexfield_segment_code  := NULL;
5658 l_adr_flex_value_set_id       := NULL;
5659 l_adr_value_type_code         := NULL;
5660 l_adr_value_combination_id    := NULL;
5661 l_adr_value_segment_code      := NULL;
5662 
5663 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
5664 l_bflow_class_code           := '';    -- 4219869 Business Flow
5665 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
5666 l_budgetary_control_flag     := 'N';
5667 
5671 l_accted_amt_idx             := NULL;          -- 4262811
5668 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
5669 l_bflow_applied_to_amt       := NULL; -- 5132302
5670 l_entered_amt_idx            := NULL;          -- 4262811
5672 l_acc_rev_flag               := NULL;          -- 4262811
5673 l_accrual_line_num           := NULL;          -- 4262811
5674 l_tmp_amt                    := NULL;          -- 4262811
5675 --
5676  
5677 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
5678     l_balance_type_code <> 'B' THEN
5679 IF NVL(p_source_20,'
5680 ') =  'FINCHRG' OR 
5681 NVL(p_source_20,'
5682 ') =  'FINCHRG_NON_REC_TAX'
5683  THEN 
5684 
5685    --
5686    XLA_AE_LINES_PKG.SetNewLine;
5687 
5688    p_balance_type_code          := l_balance_type_code;
5689    -- set the flag so later we will know whether the gain loss line needs to be created
5690    
5691    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
5692      p_actual_flag :='A';
5693    END IF;
5694 
5695    --
5696    -- bulk performance
5697    --
5698    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
5699                                       p_header_num   => 0); -- 4262811
5700    --
5701    -- set accounting line options
5702    --
5703    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
5704            p_natural_side_code          => 'C'
5705          , p_gain_or_loss_flag          => 'N'
5706          , p_gl_transfer_mode_code      => 'S'
5707          , p_acct_entry_type_code       => 'A'
5708          , p_switch_side_flag           => 'Y'
5709          , p_merge_duplicate_code       => 'A'
5710          );
5711    --
5712    l_acc_rev_natural_side_code := 'D';  -- 4262811
5713    -- 
5714    --
5715    -- set accounting line type info
5716    --
5717    xla_ae_lines_pkg.SetAcctLineType
5718       (p_component_type             => l_component_type
5719       ,p_event_type_code            => l_event_type_code
5720       ,p_line_definition_owner_code => l_line_definition_owner_code
5721       ,p_line_definition_code       => l_line_definition_code
5722       ,p_accounting_line_code       => l_component_code
5723       ,p_accounting_line_type_code  => l_component_type_code
5724       ,p_accounting_line_appl_id    => l_component_appl_id
5725       ,p_amb_context_code           => l_amb_context_code
5726       ,p_entity_code                => l_entity_code
5727       ,p_event_class_code           => l_event_class_code);
5728    --
5729    -- set accounting class
5730    --
5731    xla_ae_lines_pkg.SetAcctClass(
5732            p_accounting_class_code  => 'CHARGES'
5733          , p_ae_header_id           => l_ae_header_id
5734          );
5735 
5736    --
5737    -- set rounding class
5738    --
5739    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
5740                       'RECEIVABLE';
5741 
5742    --
5743    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
5744    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
5745    --
5746    -- bulk performance
5747    --
5748    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
5749 
5750    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
5751       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
5752 
5753    -- 4955764
5754    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5755       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
5756 
5757    -- 4458381 Public Sector Enh
5758    
5759    --
5760    -- set accounting attributes for the line type
5761    --
5762    l_entered_amt_idx := 3;
5763    l_accted_amt_idx  := 8;
5764    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
5765    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
5766    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
5767    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
5768    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
5769    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
5770    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
5771    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
5772    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
5773    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
5774    l_rec_acct_attrs.array_date_value(5)  := p_source_26;
5775    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
5776    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
5777    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
5778    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
5779    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
5780    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
5781    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
5782    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
5783    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
5784    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
5785    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
5786    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
5787 
5791    ---------------------------------------------------------------------------------------------------------------
5788    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
5789    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
5790 
5792    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
5793    ---------------------------------------------------------------------------------------------------------------
5794    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
5795 
5796    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5797    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5798 
5799    IF xla_accounting_cache_pkg.GetValueChar
5800          (p_source_code         => 'LEDGER_CATEGORY_CODE'
5801          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
5802    AND l_bflow_method_code = 'PRIOR_ENTRY'
5803 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
5804    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
5805          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
5806        )
5807    THEN
5808          xla_ae_lines_pkg.BflowUpgEntry
5809            (p_business_method_code    => l_bflow_method_code
5810            ,p_business_class_code     => l_bflow_class_code
5811            ,p_balance_type            => l_balance_type_code);
5812    ELSE
5813       NULL;
5814 -- No business flow processing for business flow method of NONE.
5815    END IF;
5816 
5817    --
5818    -- call analytical criteria
5819    --
5820    
5821    --
5822    -- call description
5823    --
5824    -- No description or it is inherited.
5825    --
5826    -- call ADRs
5827    -- Bug 4922099
5828    --
5829    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5830         (NVL(l_actual_upg_option, 'N') = 'O') OR
5831         (NVL(l_enc_upg_option, 'N') = 'O')
5832       )
5833    THEN
5834    NULL;
5835    --
5836    --
5837    
5838   l_ccid := AcctDerRule_7(
5839            p_application_id           => p_application_id
5840          , p_ae_header_id             => l_ae_header_id 
5841 , p_source_3 => p_source_3
5842          , x_transaction_coa_id       => l_adr_transaction_coa_id
5843          , x_accounting_coa_id        => l_adr_accounting_coa_id
5844          , x_value_type_code          => l_adr_value_type_code
5845          , p_side                     => 'NA'
5846    );
5847 
5848    xla_ae_lines_pkg.set_ccid(
5849     p_code_combination_id          => l_ccid
5850   , p_value_type_code              => l_adr_value_type_code
5851   , p_transaction_coa_id           => l_adr_transaction_coa_id
5852   , p_accounting_coa_id            => l_adr_accounting_coa_id
5853   , p_adr_code                     => 'DIST_CCID'
5854   , p_adr_type_code                => 'S'
5855   , p_component_type               => l_component_type
5856   , p_component_code               => l_component_code
5857   , p_component_type_code          => l_component_type_code
5858   , p_component_appl_id            => l_component_appl_id
5859   , p_amb_context_code             => l_amb_context_code
5860   , p_side                         => 'NA'
5861   );
5862 
5863 
5864    --
5865    --
5866    END IF;
5867    --
5868    -- Bug 4922099
5869    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
5870           (NVL(l_enc_upg_option, 'N') = 'O')
5871         ) AND
5872         (l_bflow_method_code = 'PRIOR_ENTRY')
5873       )
5874    THEN
5875       IF
5876       --
5877       1 = 2
5878       --
5879       THEN
5880       xla_accounting_err_pkg.build_message
5881                                     (p_appli_s_name            => 'XLA'
5882                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5883                                     ,p_token_1                 => 'LINE_NUMBER'
5884                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
5885                                     ,p_token_2                 => 'LINE_TYPE_NAME'
5886                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
5887                                                                              l_component_type
5888                                                                             ,l_component_code
5889                                                                             ,l_component_type_code
5890                                                                             ,l_component_appl_id
5891                                                                             ,l_amb_context_code
5892                                                                             ,l_entity_code
5893                                                                             ,l_event_class_code
5894                                                                            )
5895                                     ,p_token_3                 => 'OWNER'
5896                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
5897                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
5898                                                                           ,p_lookup_code    => l_component_type_code
5902                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
5899                                                                          )
5900                                     ,p_token_4                 => 'PRODUCT_NAME'
5901                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
5903                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
5904                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
5905                                     ,p_ae_header_id            =>  NULL
5906                                        );
5907 
5908         IF (C_LEVEL_ERROR>= g_log_level) THEN
5909                  trace
5910                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5911                       ,p_level    => C_LEVEL_ERROR
5912                       ,p_module   => l_log_module);
5913         END IF;
5914       END IF;
5915    END IF;
5916    --
5917    --
5918    ------------------------------------------------------------------------------------------------
5919    -- 4219869 Business Flow
5920    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
5921    -- Prior Entry.  Currently, the following code is always generated.
5922    ------------------------------------------------------------------------------------------------
5923    XLA_AE_LINES_PKG.ValidateCurrentLine;
5924 
5925    ------------------------------------------------------------------------------------
5926    -- 4219869 Business Flow
5927    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
5928    ------------------------------------------------------------------------------------
5929    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5930 
5931    ----------------------------------------------------------------------------------
5932    -- 4219869 Business Flow
5933    -- Update journal entry status -- Need to generate this within IF <condition>
5934    ----------------------------------------------------------------------------------
5935    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5936          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
5937          ,p_balance_type_code => l_balance_type_code
5938          );
5939 
5940    -------------------------------------------------------------------------------------------
5941    -- 4262811 - Generate the Accrual Reversal lines
5942    -------------------------------------------------------------------------------------------
5943    BEGIN
5944       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
5945                               (g_array_event(p_event_id).array_value_num('header_index'));
5946       IF l_acc_rev_flag IS NULL THEN
5947          l_acc_rev_flag := 'N';
5948       END IF;
5949    EXCEPTION
5950       WHEN OTHERS THEN
5951          l_acc_rev_flag := 'N';
5952    END;
5953    --
5954    IF (l_acc_rev_flag = 'Y') THEN
5955 
5956        -- 4645092  ------------------------------------------------------------------------------
5957        -- To allow MPA report to determine if it should generate report process
5958        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
5959        ------------------------------------------------------------------------------------------
5960 
5961        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
5962        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
5963    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
5964    -- call ADRs
5965    -- Bug 4922099
5966    --
5967    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5968         (NVL(l_actual_upg_option, 'N') = 'O') OR
5969         (NVL(l_enc_upg_option, 'N') = 'O')
5970       )
5971    THEN
5972    NULL;
5973    --
5974    --
5975    
5976   l_ccid := AcctDerRule_7(
5977            p_application_id           => p_application_id
5978          , p_ae_header_id             => l_ae_header_id 
5979 , p_source_3 => p_source_3
5980          , x_transaction_coa_id       => l_adr_transaction_coa_id
5981          , x_accounting_coa_id        => l_adr_accounting_coa_id
5982          , x_value_type_code          => l_adr_value_type_code
5983          , p_side                     => 'NA'
5984    );
5985 
5986    xla_ae_lines_pkg.set_ccid(
5987     p_code_combination_id          => l_ccid
5988   , p_value_type_code              => l_adr_value_type_code
5989   , p_transaction_coa_id           => l_adr_transaction_coa_id
5990   , p_accounting_coa_id            => l_adr_accounting_coa_id
5991   , p_adr_code                     => 'DIST_CCID'
5992   , p_adr_type_code                => 'S'
5993   , p_component_type               => l_component_type
5994   , p_component_code               => l_component_code
5995   , p_component_type_code          => l_component_type_code
5996   , p_component_appl_id            => l_component_appl_id
5997   , p_amb_context_code             => l_amb_context_code
5998   , p_side                         => 'NA'
5999   );
6000 
6001 
6002    --
6003    --
6004    END IF;
6005 
6006        --
6007        -- Update the line information that should be overwritten
6008        --
6009        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
6010                                          p_header_num   => 1);
6014 
6011        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
6012 
6013        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
6015        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
6016           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
6017        END IF;
6018 
6019       --
6020       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
6021       --
6022       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
6023           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
6024       ELSE
6025           ---------------------------------------------------------------------------------------------------
6026           -- 4262811a Switch Sign
6027           ---------------------------------------------------------------------------------------------------
6028           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
6029           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6030                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6031           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6032                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6033           -- 5132302
6034           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
6035                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6036 
6037       END IF;
6038 
6039       -- 4955764
6040       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6041       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
6042 
6043 
6044       XLA_AE_LINES_PKG.ValidateCurrentLine;
6045       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6046 
6047       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6048                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
6049                ,p_balance_type_code => l_balance_type_code);
6050 
6051    END IF;
6052 
6053    -----------------------------------------------------------------------------------------
6054    -- 4262811 Multiperiod Accounting
6055    -----------------------------------------------------------------------------------------
6056      -- No MPA option is assigned.
6057 
6058 
6059 END IF;
6060 END IF;
6061 --
6062 
6063 --
6064 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6065    trace
6066       (p_msg      => 'END of AcctLineType_35'
6067       ,p_level    => C_LEVEL_PROCEDURE
6068       ,p_module   => l_log_module);
6069 END IF;
6070 --
6071 EXCEPTION
6072   WHEN xla_exceptions_pkg.application_exception THEN
6073       RAISE;
6074   WHEN OTHERS THEN
6075        xla_exceptions_pkg.raise_message
6076            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_35');
6077 END AcctLineType_35;
6078 --
6079 
6080 ---------------------------------------
6081 --
6082 -- PRIVATE FUNCTION
6083 --         AcctLineType_36
6084 --
6085 ---------------------------------------
6086 PROCEDURE AcctLineType_36 (
6087   p_application_id        IN NUMBER
6088  ,p_event_id              IN NUMBER
6089  ,p_calculate_acctd_flag  IN VARCHAR2
6090  ,p_calculate_g_l_flag    IN VARCHAR2
6091  ,p_actual_flag           IN OUT VARCHAR2
6092  ,p_balance_type_code     OUT VARCHAR2
6093  ,p_gain_or_loss_ref      OUT VARCHAR2
6094  
6095 --Distribution GL Account
6096  , p_source_3            IN NUMBER
6097 --Distribution Source Type
6098  , p_source_20            IN VARCHAR2
6099 --Distribution Line Identifier
6100  , p_source_22            IN NUMBER
6101 --Distribution Type
6102  , p_source_23            IN VARCHAR2
6103 --Entered Amount
6104  , p_source_24            IN NUMBER
6105 --Currency Code
6106  , p_source_25            IN VARCHAR2
6107 --Exchange Date
6108  , p_source_26            IN DATE
6109 --Exchange Rate
6110  , p_source_27            IN NUMBER
6111 --Exchange Rate Type
6112  , p_source_28            IN VARCHAR2
6113 --Applied To Document Accounting Amount
6114  , p_source_29            IN NUMBER
6115 --Bill To Customer Account Identifier
6116  , p_source_30            IN NUMBER
6117 --Bill To Customer Site Use Identifier
6118  , p_source_31            IN NUMBER
6119 --SLA Party Type
6120  , p_source_32            IN VARCHAR2
6121 )
6122 IS
6123 
6124 l_component_type              VARCHAR2(80);
6125 l_component_code              VARCHAR2(30);
6126 l_component_type_code         VARCHAR2(1);
6127 l_component_appl_id           INTEGER;
6128 l_amb_context_code            VARCHAR2(30);
6129 l_entity_code                 VARCHAR2(30);
6130 l_event_class_code            VARCHAR2(30);
6131 l_ae_header_id                NUMBER;
6132 l_event_type_code             VARCHAR2(30);
6133 l_line_definition_code        VARCHAR2(30);
6134 l_line_definition_owner_code  VARCHAR2(1);
6135 --
6136 -- adr variables
6140 l_adr_accounting_coa_id       NUMBER;
6137 l_segment                     VARCHAR2(30);
6138 l_ccid                        NUMBER;
6139 l_adr_transaction_coa_id      NUMBER;
6141 l_adr_flexfield_segment_code  VARCHAR2(30);
6142 l_adr_flex_value_set_id       NUMBER;
6143 l_adr_value_type_code         VARCHAR2(30);
6144 l_adr_value_combination_id    NUMBER;
6145 l_adr_value_segment_code      VARCHAR2(30);
6146 
6147 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
6148 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
6149 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
6150 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
6151 
6152 -- 4262811 Variables ------------------------------------------------------------------------------------------
6153 l_entered_amt_idx             NUMBER;
6154 l_accted_amt_idx              NUMBER;
6155 l_acc_rev_flag                VARCHAR2(1);
6156 l_accrual_line_num            NUMBER;
6157 l_tmp_amt                     NUMBER;
6158 l_acc_rev_natural_side_code   VARCHAR2(1);
6159 
6160 l_num_entries                 NUMBER;
6161 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
6162 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
6163 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
6164 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
6165 l_recog_line_1                NUMBER;
6166 l_recog_line_2                NUMBER;
6167 
6168 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
6169 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
6170 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
6171 
6172 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
6173 
6174 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
6175 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
6176 
6177 ---------------------------------------------------------------------------------------------------------------
6178 
6179 
6180 --
6181 -- bulk performance
6182 --
6183 l_balance_type_code           VARCHAR2(1);
6184 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
6185 l_log_module                  VARCHAR2(240);
6186 
6187 --
6188 -- Upgrade strategy
6189 --
6190 l_actual_upg_option           VARCHAR2(1);
6191 l_enc_upg_option           VARCHAR2(1);
6192 
6193 --
6194 BEGIN
6195 --
6196 IF g_log_enabled THEN
6197       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_36';
6198 END IF;
6199 --
6200 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6201 
6202       trace
6203          (p_msg      => 'BEGIN of AcctLineType_36'
6204          ,p_level    => C_LEVEL_PROCEDURE
6205          ,p_module   => l_log_module);
6206 
6207 END IF;
6208 --
6209 l_component_type             := 'AMB_JLT';
6210 l_component_code             := 'ADJ_DEFERRED_TAX';
6211 l_component_type_code        := 'S';
6212 l_component_appl_id          :=  222;
6213 l_amb_context_code           := 'DEFAULT';
6214 l_entity_code                := 'ADJUSTMENTS';
6215 l_event_class_code           := 'ADJUSTMENT';
6216 l_event_type_code            := 'ADJUSTMENT_ALL';
6217 l_line_definition_owner_code := 'S';
6218 l_line_definition_code       := 'MFAR_ADJ_ACCRUAL_BALANCING';
6219 --
6220 l_balance_type_code          := 'A';
6221 l_segment                     := NULL;
6222 l_ccid                        := NULL;
6223 l_adr_transaction_coa_id      := NULL;
6224 l_adr_accounting_coa_id       := NULL;
6225 l_adr_flexfield_segment_code  := NULL;
6226 l_adr_flex_value_set_id       := NULL;
6227 l_adr_value_type_code         := NULL;
6228 l_adr_value_combination_id    := NULL;
6229 l_adr_value_segment_code      := NULL;
6230 
6231 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
6232 l_bflow_class_code           := '';    -- 4219869 Business Flow
6233 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
6234 l_budgetary_control_flag     := 'N';
6235 
6236 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
6237 l_bflow_applied_to_amt       := NULL; -- 5132302
6238 l_entered_amt_idx            := NULL;          -- 4262811
6239 l_accted_amt_idx             := NULL;          -- 4262811
6240 l_acc_rev_flag               := NULL;          -- 4262811
6241 l_accrual_line_num           := NULL;          -- 4262811
6242 l_tmp_amt                    := NULL;          -- 4262811
6243 --
6244  
6245 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
6246     l_balance_type_code <> 'B' THEN
6247 IF NVL(p_source_20,'
6248 ') =  'DEFERRED_TAX'
6249  THEN 
6250 
6251    --
6252    XLA_AE_LINES_PKG.SetNewLine;
6253 
6254    p_balance_type_code          := l_balance_type_code;
6255    -- set the flag so later we will know whether the gain loss line needs to be created
6256    
6257    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
6258      p_actual_flag :='A';
6259    END IF;
6260 
6261    --
6262    -- bulk performance
6263    --
6264    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
6265                                       p_header_num   => 0); -- 4262811
6266    --
6267    -- set accounting line options
6268    --
6269    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
6273          , p_acct_entry_type_code       => 'A'
6270            p_natural_side_code          => 'C'
6271          , p_gain_or_loss_flag          => 'N'
6272          , p_gl_transfer_mode_code      => 'S'
6274          , p_switch_side_flag           => 'Y'
6275          , p_merge_duplicate_code       => 'A'
6276          );
6277    --
6278    l_acc_rev_natural_side_code := 'D';  -- 4262811
6279    -- 
6280    --
6281    -- set accounting line type info
6282    --
6283    xla_ae_lines_pkg.SetAcctLineType
6284       (p_component_type             => l_component_type
6285       ,p_event_type_code            => l_event_type_code
6286       ,p_line_definition_owner_code => l_line_definition_owner_code
6287       ,p_line_definition_code       => l_line_definition_code
6288       ,p_accounting_line_code       => l_component_code
6289       ,p_accounting_line_type_code  => l_component_type_code
6290       ,p_accounting_line_appl_id    => l_component_appl_id
6291       ,p_amb_context_code           => l_amb_context_code
6292       ,p_entity_code                => l_entity_code
6293       ,p_event_class_code           => l_event_class_code);
6294    --
6295    -- set accounting class
6296    --
6297    xla_ae_lines_pkg.SetAcctClass(
6298            p_accounting_class_code  => 'DEFERRED_TAX'
6299          , p_ae_header_id           => l_ae_header_id
6300          );
6301 
6302    --
6303    -- set rounding class
6304    --
6305    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
6306                       'RECEIVABLE';
6307 
6308    --
6309    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
6310    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
6311    --
6312    -- bulk performance
6313    --
6314    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
6315 
6316    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
6317       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
6318 
6319    -- 4955764
6320    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6321       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
6322 
6323    -- 4458381 Public Sector Enh
6324    
6325    --
6326    -- set accounting attributes for the line type
6327    --
6328    l_entered_amt_idx := 3;
6329    l_accted_amt_idx  := 8;
6330    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
6331    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
6332    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
6333    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
6334    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
6335    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
6336    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
6337    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
6338    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
6339    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
6340    l_rec_acct_attrs.array_date_value(5)  := p_source_26;
6341    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
6342    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
6343    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
6344    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
6345    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
6346    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
6347    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
6348    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
6349    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
6350    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
6351    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
6352    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
6353 
6354    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
6355    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
6356 
6357    ---------------------------------------------------------------------------------------------------------------
6358    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
6359    ---------------------------------------------------------------------------------------------------------------
6360    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
6361 
6362    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6363    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6364 
6365    IF xla_accounting_cache_pkg.GetValueChar
6366          (p_source_code         => 'LEDGER_CATEGORY_CODE'
6367          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
6368    AND l_bflow_method_code = 'PRIOR_ENTRY'
6369 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
6370    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
6371          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
6372        )
6373    THEN
6374          xla_ae_lines_pkg.BflowUpgEntry
6375            (p_business_method_code    => l_bflow_method_code
6376            ,p_business_class_code     => l_bflow_class_code
6380 -- No business flow processing for business flow method of NONE.
6377            ,p_balance_type            => l_balance_type_code);
6378    ELSE
6379       NULL;
6381    END IF;
6382 
6383    --
6384    -- call analytical criteria
6385    --
6386    
6387    --
6388    -- call description
6389    --
6390    -- No description or it is inherited.
6391    --
6392    -- call ADRs
6393    -- Bug 4922099
6394    --
6395    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
6396         (NVL(l_actual_upg_option, 'N') = 'O') OR
6397         (NVL(l_enc_upg_option, 'N') = 'O')
6398       )
6399    THEN
6400    NULL;
6401    --
6402    --
6403    
6404   l_ccid := AcctDerRule_7(
6405            p_application_id           => p_application_id
6406          , p_ae_header_id             => l_ae_header_id 
6407 , p_source_3 => p_source_3
6408          , x_transaction_coa_id       => l_adr_transaction_coa_id
6409          , x_accounting_coa_id        => l_adr_accounting_coa_id
6410          , x_value_type_code          => l_adr_value_type_code
6411          , p_side                     => 'NA'
6412    );
6413 
6414    xla_ae_lines_pkg.set_ccid(
6415     p_code_combination_id          => l_ccid
6416   , p_value_type_code              => l_adr_value_type_code
6417   , p_transaction_coa_id           => l_adr_transaction_coa_id
6418   , p_accounting_coa_id            => l_adr_accounting_coa_id
6419   , p_adr_code                     => 'DIST_CCID'
6420   , p_adr_type_code                => 'S'
6421   , p_component_type               => l_component_type
6422   , p_component_code               => l_component_code
6423   , p_component_type_code          => l_component_type_code
6424   , p_component_appl_id            => l_component_appl_id
6425   , p_amb_context_code             => l_amb_context_code
6426   , p_side                         => 'NA'
6427   );
6428 
6429 
6430    --
6431    --
6432    END IF;
6433    --
6434    -- Bug 4922099
6435    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
6436           (NVL(l_enc_upg_option, 'N') = 'O')
6437         ) AND
6438         (l_bflow_method_code = 'PRIOR_ENTRY')
6439       )
6440    THEN
6441       IF
6442       --
6443       1 = 2
6444       --
6445       THEN
6446       xla_accounting_err_pkg.build_message
6447                                     (p_appli_s_name            => 'XLA'
6448                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6449                                     ,p_token_1                 => 'LINE_NUMBER'
6450                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
6451                                     ,p_token_2                 => 'LINE_TYPE_NAME'
6452                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
6453                                                                              l_component_type
6454                                                                             ,l_component_code
6455                                                                             ,l_component_type_code
6456                                                                             ,l_component_appl_id
6457                                                                             ,l_amb_context_code
6458                                                                             ,l_entity_code
6459                                                                             ,l_event_class_code
6460                                                                            )
6461                                     ,p_token_3                 => 'OWNER'
6462                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
6463                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
6464                                                                           ,p_lookup_code    => l_component_type_code
6465                                                                          )
6466                                     ,p_token_4                 => 'PRODUCT_NAME'
6467                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
6468                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
6469                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
6470                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
6471                                     ,p_ae_header_id            =>  NULL
6472                                        );
6473 
6474         IF (C_LEVEL_ERROR>= g_log_level) THEN
6475                  trace
6476                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6477                       ,p_level    => C_LEVEL_ERROR
6478                       ,p_module   => l_log_module);
6479         END IF;
6480       END IF;
6481    END IF;
6482    --
6483    --
6484    ------------------------------------------------------------------------------------------------
6485    -- 4219869 Business Flow
6486    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
6487    -- Prior Entry.  Currently, the following code is always generated.
6488    ------------------------------------------------------------------------------------------------
6489    XLA_AE_LINES_PKG.ValidateCurrentLine;
6493    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
6490 
6491    ------------------------------------------------------------------------------------
6492    -- 4219869 Business Flow
6494    ------------------------------------------------------------------------------------
6495    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6496 
6497    ----------------------------------------------------------------------------------
6498    -- 4219869 Business Flow
6499    -- Update journal entry status -- Need to generate this within IF <condition>
6500    ----------------------------------------------------------------------------------
6501    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6502          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
6503          ,p_balance_type_code => l_balance_type_code
6504          );
6505 
6506    -------------------------------------------------------------------------------------------
6507    -- 4262811 - Generate the Accrual Reversal lines
6508    -------------------------------------------------------------------------------------------
6509    BEGIN
6510       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
6511                               (g_array_event(p_event_id).array_value_num('header_index'));
6512       IF l_acc_rev_flag IS NULL THEN
6513          l_acc_rev_flag := 'N';
6514       END IF;
6515    EXCEPTION
6516       WHEN OTHERS THEN
6517          l_acc_rev_flag := 'N';
6518    END;
6519    --
6520    IF (l_acc_rev_flag = 'Y') THEN
6521 
6522        -- 4645092  ------------------------------------------------------------------------------
6523        -- To allow MPA report to determine if it should generate report process
6524        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
6525        ------------------------------------------------------------------------------------------
6526 
6527        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
6528        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
6529    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
6530    -- call ADRs
6531    -- Bug 4922099
6532    --
6533    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
6534         (NVL(l_actual_upg_option, 'N') = 'O') OR
6535         (NVL(l_enc_upg_option, 'N') = 'O')
6536       )
6537    THEN
6538    NULL;
6539    --
6540    --
6541    
6542   l_ccid := AcctDerRule_7(
6543            p_application_id           => p_application_id
6544          , p_ae_header_id             => l_ae_header_id 
6545 , p_source_3 => p_source_3
6546          , x_transaction_coa_id       => l_adr_transaction_coa_id
6547          , x_accounting_coa_id        => l_adr_accounting_coa_id
6548          , x_value_type_code          => l_adr_value_type_code
6549          , p_side                     => 'NA'
6550    );
6551 
6552    xla_ae_lines_pkg.set_ccid(
6553     p_code_combination_id          => l_ccid
6554   , p_value_type_code              => l_adr_value_type_code
6555   , p_transaction_coa_id           => l_adr_transaction_coa_id
6556   , p_accounting_coa_id            => l_adr_accounting_coa_id
6557   , p_adr_code                     => 'DIST_CCID'
6558   , p_adr_type_code                => 'S'
6559   , p_component_type               => l_component_type
6560   , p_component_code               => l_component_code
6561   , p_component_type_code          => l_component_type_code
6562   , p_component_appl_id            => l_component_appl_id
6563   , p_amb_context_code             => l_amb_context_code
6564   , p_side                         => 'NA'
6565   );
6566 
6567 
6568    --
6569    --
6570    END IF;
6571 
6572        --
6573        -- Update the line information that should be overwritten
6574        --
6575        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
6576                                          p_header_num   => 1);
6577        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
6578 
6579        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
6580 
6581        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
6582           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
6583        END IF;
6584 
6585       --
6586       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
6587       --
6588       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
6589           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
6590       ELSE
6591           ---------------------------------------------------------------------------------------------------
6592           -- 4262811a Switch Sign
6593           ---------------------------------------------------------------------------------------------------
6594           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
6595           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6596                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6597           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6601                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6598                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6599           -- 5132302
6600           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
6602 
6603       END IF;
6604 
6605       -- 4955764
6606       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6607       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
6608 
6609 
6610       XLA_AE_LINES_PKG.ValidateCurrentLine;
6611       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6612 
6613       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6614                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
6615                ,p_balance_type_code => l_balance_type_code);
6616 
6617    END IF;
6618 
6619    -----------------------------------------------------------------------------------------
6620    -- 4262811 Multiperiod Accounting
6621    -----------------------------------------------------------------------------------------
6622      -- No MPA option is assigned.
6623 
6624 
6625 END IF;
6626 END IF;
6627 --
6628 
6629 --
6630 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6631    trace
6632       (p_msg      => 'END of AcctLineType_36'
6633       ,p_level    => C_LEVEL_PROCEDURE
6634       ,p_module   => l_log_module);
6635 END IF;
6636 --
6637 EXCEPTION
6638   WHEN xla_exceptions_pkg.application_exception THEN
6639       RAISE;
6640   WHEN OTHERS THEN
6641        xla_exceptions_pkg.raise_message
6642            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_36');
6643 END AcctLineType_36;
6644 --
6645 
6646 ---------------------------------------
6647 --
6648 -- PRIVATE FUNCTION
6649 --         AcctLineType_37
6650 --
6651 ---------------------------------------
6652 PROCEDURE AcctLineType_37 (
6653   p_application_id        IN NUMBER
6654  ,p_event_id              IN NUMBER
6655  ,p_calculate_acctd_flag  IN VARCHAR2
6656  ,p_calculate_g_l_flag    IN VARCHAR2
6657  ,p_actual_flag           IN OUT VARCHAR2
6658  ,p_balance_type_code     OUT VARCHAR2
6659  ,p_gain_or_loss_ref      OUT VARCHAR2
6660  
6661 --Distribution GL Account
6662  , p_source_3            IN NUMBER
6663 --Distribution Source Type
6664  , p_source_20            IN VARCHAR2
6665 --Distribution Line Identifier
6666  , p_source_22            IN NUMBER
6667 --Distribution Type
6668  , p_source_23            IN VARCHAR2
6669 --Entered Amount
6670  , p_source_24            IN NUMBER
6671 --Currency Code
6672  , p_source_25            IN VARCHAR2
6673 --Exchange Date
6674  , p_source_26            IN DATE
6675 --Exchange Rate
6676  , p_source_27            IN NUMBER
6677 --Exchange Rate Type
6678  , p_source_28            IN VARCHAR2
6679 --Applied To Document Accounting Amount
6680  , p_source_29            IN NUMBER
6681 --Bill To Customer Account Identifier
6682  , p_source_30            IN NUMBER
6683 --Bill To Customer Site Use Identifier
6684  , p_source_31            IN NUMBER
6685 --SLA Party Type
6686  , p_source_32            IN VARCHAR2
6687 )
6688 IS
6689 
6690 l_component_type              VARCHAR2(80);
6691 l_component_code              VARCHAR2(30);
6692 l_component_type_code         VARCHAR2(1);
6693 l_component_appl_id           INTEGER;
6694 l_amb_context_code            VARCHAR2(30);
6695 l_entity_code                 VARCHAR2(30);
6696 l_event_class_code            VARCHAR2(30);
6697 l_ae_header_id                NUMBER;
6698 l_event_type_code             VARCHAR2(30);
6699 l_line_definition_code        VARCHAR2(30);
6700 l_line_definition_owner_code  VARCHAR2(1);
6701 --
6702 -- adr variables
6703 l_segment                     VARCHAR2(30);
6704 l_ccid                        NUMBER;
6705 l_adr_transaction_coa_id      NUMBER;
6706 l_adr_accounting_coa_id       NUMBER;
6707 l_adr_flexfield_segment_code  VARCHAR2(30);
6708 l_adr_flex_value_set_id       NUMBER;
6709 l_adr_value_type_code         VARCHAR2(30);
6710 l_adr_value_combination_id    NUMBER;
6711 l_adr_value_segment_code      VARCHAR2(30);
6712 
6713 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
6714 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
6715 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
6716 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
6717 
6718 -- 4262811 Variables ------------------------------------------------------------------------------------------
6719 l_entered_amt_idx             NUMBER;
6720 l_accted_amt_idx              NUMBER;
6721 l_acc_rev_flag                VARCHAR2(1);
6722 l_accrual_line_num            NUMBER;
6723 l_tmp_amt                     NUMBER;
6724 l_acc_rev_natural_side_code   VARCHAR2(1);
6725 
6726 l_num_entries                 NUMBER;
6727 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
6728 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
6729 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
6733 
6730 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
6731 l_recog_line_1                NUMBER;
6732 l_recog_line_2                NUMBER;
6734 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
6735 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
6736 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
6737 
6738 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
6739 
6740 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
6741 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
6742 
6743 ---------------------------------------------------------------------------------------------------------------
6744 
6745 
6746 --
6747 -- bulk performance
6748 --
6749 l_balance_type_code           VARCHAR2(1);
6750 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
6751 l_log_module                  VARCHAR2(240);
6752 
6753 --
6754 -- Upgrade strategy
6755 --
6756 l_actual_upg_option           VARCHAR2(1);
6757 l_enc_upg_option           VARCHAR2(1);
6758 
6759 --
6760 BEGIN
6761 --
6762 IF g_log_enabled THEN
6763       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_37';
6764 END IF;
6765 --
6766 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6767 
6768       trace
6769          (p_msg      => 'BEGIN of AcctLineType_37'
6770          ,p_level    => C_LEVEL_PROCEDURE
6771          ,p_module   => l_log_module);
6772 
6773 END IF;
6774 --
6775 l_component_type             := 'AMB_JLT';
6776 l_component_code             := 'ADJ_TAX';
6777 l_component_type_code        := 'S';
6778 l_component_appl_id          :=  222;
6779 l_amb_context_code           := 'DEFAULT';
6780 l_entity_code                := 'ADJUSTMENTS';
6781 l_event_class_code           := 'ADJUSTMENT';
6782 l_event_type_code            := 'ADJUSTMENT_ALL';
6783 l_line_definition_owner_code := 'S';
6784 l_line_definition_code       := 'MFAR_ADJ_ACCRUAL_BALANCING';
6785 --
6786 l_balance_type_code          := 'A';
6787 l_segment                     := NULL;
6788 l_ccid                        := NULL;
6789 l_adr_transaction_coa_id      := NULL;
6790 l_adr_accounting_coa_id       := NULL;
6791 l_adr_flexfield_segment_code  := NULL;
6792 l_adr_flex_value_set_id       := NULL;
6793 l_adr_value_type_code         := NULL;
6794 l_adr_value_combination_id    := NULL;
6795 l_adr_value_segment_code      := NULL;
6796 
6797 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
6798 l_bflow_class_code           := '';    -- 4219869 Business Flow
6799 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
6800 l_budgetary_control_flag     := 'N';
6801 
6802 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
6803 l_bflow_applied_to_amt       := NULL; -- 5132302
6804 l_entered_amt_idx            := NULL;          -- 4262811
6805 l_accted_amt_idx             := NULL;          -- 4262811
6806 l_acc_rev_flag               := NULL;          -- 4262811
6807 l_accrual_line_num           := NULL;          -- 4262811
6808 l_tmp_amt                    := NULL;          -- 4262811
6809 --
6810  
6811 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
6812     l_balance_type_code <> 'B' THEN
6813 IF NVL(p_source_20,'
6814 ') =  'TAX'
6815  THEN 
6816 
6817    --
6818    XLA_AE_LINES_PKG.SetNewLine;
6819 
6820    p_balance_type_code          := l_balance_type_code;
6821    -- set the flag so later we will know whether the gain loss line needs to be created
6822    
6823    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
6824      p_actual_flag :='A';
6825    END IF;
6826 
6827    --
6828    -- bulk performance
6829    --
6830    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
6831                                       p_header_num   => 0); -- 4262811
6832    --
6833    -- set accounting line options
6834    --
6835    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
6836            p_natural_side_code          => 'C'
6837          , p_gain_or_loss_flag          => 'N'
6838          , p_gl_transfer_mode_code      => 'S'
6839          , p_acct_entry_type_code       => 'A'
6840          , p_switch_side_flag           => 'Y'
6841          , p_merge_duplicate_code       => 'A'
6842          );
6843    --
6844    l_acc_rev_natural_side_code := 'D';  -- 4262811
6845    -- 
6846    --
6847    -- set accounting line type info
6848    --
6849    xla_ae_lines_pkg.SetAcctLineType
6850       (p_component_type             => l_component_type
6851       ,p_event_type_code            => l_event_type_code
6852       ,p_line_definition_owner_code => l_line_definition_owner_code
6853       ,p_line_definition_code       => l_line_definition_code
6854       ,p_accounting_line_code       => l_component_code
6855       ,p_accounting_line_type_code  => l_component_type_code
6856       ,p_accounting_line_appl_id    => l_component_appl_id
6857       ,p_amb_context_code           => l_amb_context_code
6858       ,p_entity_code                => l_entity_code
6859       ,p_event_class_code           => l_event_class_code);
6860    --
6861    -- set accounting class
6862    --
6863    xla_ae_lines_pkg.SetAcctClass(
6864            p_accounting_class_code  => 'TAX'
6868    --
6865          , p_ae_header_id           => l_ae_header_id
6866          );
6867 
6869    -- set rounding class
6870    --
6871    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
6872                       'RECEIVABLE';
6873 
6874    --
6875    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
6876    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
6877    --
6878    -- bulk performance
6879    --
6880    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
6881 
6882    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
6883       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
6884 
6885    -- 4955764
6886    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6887       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
6888 
6889    -- 4458381 Public Sector Enh
6890    
6891    --
6892    -- set accounting attributes for the line type
6893    --
6894    l_entered_amt_idx := 3;
6895    l_accted_amt_idx  := 8;
6896    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
6897    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
6898    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
6899    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
6900    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
6901    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
6902    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
6903    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
6904    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
6905    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
6906    l_rec_acct_attrs.array_date_value(5)  := p_source_26;
6907    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
6908    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
6909    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
6910    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
6911    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
6912    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
6913    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
6914    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
6915    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
6916    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
6917    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
6918    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
6919 
6920    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
6921    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
6922 
6923    ---------------------------------------------------------------------------------------------------------------
6924    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
6925    ---------------------------------------------------------------------------------------------------------------
6926    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
6927 
6928    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6929    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6930 
6931    IF xla_accounting_cache_pkg.GetValueChar
6932          (p_source_code         => 'LEDGER_CATEGORY_CODE'
6933          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
6934    AND l_bflow_method_code = 'PRIOR_ENTRY'
6935 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
6936    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
6937          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
6938        )
6939    THEN
6940          xla_ae_lines_pkg.BflowUpgEntry
6941            (p_business_method_code    => l_bflow_method_code
6942            ,p_business_class_code     => l_bflow_class_code
6943            ,p_balance_type            => l_balance_type_code);
6944    ELSE
6945       NULL;
6946 -- No business flow processing for business flow method of NONE.
6947    END IF;
6948 
6949    --
6950    -- call analytical criteria
6951    --
6952    
6953    --
6954    -- call description
6955    --
6956    -- No description or it is inherited.
6957    --
6958    -- call ADRs
6959    -- Bug 4922099
6960    --
6961    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
6962         (NVL(l_actual_upg_option, 'N') = 'O') OR
6963         (NVL(l_enc_upg_option, 'N') = 'O')
6964       )
6965    THEN
6966    NULL;
6967    --
6968    --
6969    
6970   l_ccid := AcctDerRule_7(
6971            p_application_id           => p_application_id
6972          , p_ae_header_id             => l_ae_header_id 
6973 , p_source_3 => p_source_3
6974          , x_transaction_coa_id       => l_adr_transaction_coa_id
6975          , x_accounting_coa_id        => l_adr_accounting_coa_id
6976          , x_value_type_code          => l_adr_value_type_code
6977          , p_side                     => 'NA'
6978    );
6979 
6980    xla_ae_lines_pkg.set_ccid(
6981     p_code_combination_id          => l_ccid
6985   , p_adr_code                     => 'DIST_CCID'
6982   , p_value_type_code              => l_adr_value_type_code
6983   , p_transaction_coa_id           => l_adr_transaction_coa_id
6984   , p_accounting_coa_id            => l_adr_accounting_coa_id
6986   , p_adr_type_code                => 'S'
6987   , p_component_type               => l_component_type
6988   , p_component_code               => l_component_code
6989   , p_component_type_code          => l_component_type_code
6990   , p_component_appl_id            => l_component_appl_id
6991   , p_amb_context_code             => l_amb_context_code
6992   , p_side                         => 'NA'
6993   );
6994 
6995 
6996    --
6997    --
6998    END IF;
6999    --
7000    -- Bug 4922099
7001    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
7002           (NVL(l_enc_upg_option, 'N') = 'O')
7003         ) AND
7004         (l_bflow_method_code = 'PRIOR_ENTRY')
7005       )
7006    THEN
7007       IF
7008       --
7009       1 = 2
7010       --
7011       THEN
7012       xla_accounting_err_pkg.build_message
7013                                     (p_appli_s_name            => 'XLA'
7014                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
7015                                     ,p_token_1                 => 'LINE_NUMBER'
7016                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
7017                                     ,p_token_2                 => 'LINE_TYPE_NAME'
7018                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
7019                                                                              l_component_type
7020                                                                             ,l_component_code
7021                                                                             ,l_component_type_code
7022                                                                             ,l_component_appl_id
7023                                                                             ,l_amb_context_code
7024                                                                             ,l_entity_code
7025                                                                             ,l_event_class_code
7026                                                                            )
7027                                     ,p_token_3                 => 'OWNER'
7028                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
7029                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
7030                                                                           ,p_lookup_code    => l_component_type_code
7031                                                                          )
7032                                     ,p_token_4                 => 'PRODUCT_NAME'
7033                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
7034                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
7035                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
7036                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
7037                                     ,p_ae_header_id            =>  NULL
7038                                        );
7039 
7040         IF (C_LEVEL_ERROR>= g_log_level) THEN
7041                  trace
7042                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
7043                       ,p_level    => C_LEVEL_ERROR
7044                       ,p_module   => l_log_module);
7045         END IF;
7046       END IF;
7047    END IF;
7048    --
7049    --
7050    ------------------------------------------------------------------------------------------------
7051    -- 4219869 Business Flow
7052    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
7053    -- Prior Entry.  Currently, the following code is always generated.
7054    ------------------------------------------------------------------------------------------------
7055    XLA_AE_LINES_PKG.ValidateCurrentLine;
7056 
7057    ------------------------------------------------------------------------------------
7058    -- 4219869 Business Flow
7059    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
7060    ------------------------------------------------------------------------------------
7061    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
7062 
7063    ----------------------------------------------------------------------------------
7064    -- 4219869 Business Flow
7065    -- Update journal entry status -- Need to generate this within IF <condition>
7066    ----------------------------------------------------------------------------------
7067    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
7068          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
7069          ,p_balance_type_code => l_balance_type_code
7070          );
7071 
7072    -------------------------------------------------------------------------------------------
7073    -- 4262811 - Generate the Accrual Reversal lines
7074    -------------------------------------------------------------------------------------------
7075    BEGIN
7076       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
7080       END IF;
7077                               (g_array_event(p_event_id).array_value_num('header_index'));
7078       IF l_acc_rev_flag IS NULL THEN
7079          l_acc_rev_flag := 'N';
7081    EXCEPTION
7082       WHEN OTHERS THEN
7083          l_acc_rev_flag := 'N';
7084    END;
7085    --
7086    IF (l_acc_rev_flag = 'Y') THEN
7087 
7088        -- 4645092  ------------------------------------------------------------------------------
7089        -- To allow MPA report to determine if it should generate report process
7090        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
7091        ------------------------------------------------------------------------------------------
7092 
7093        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
7094        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
7095    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
7096    -- call ADRs
7097    -- Bug 4922099
7098    --
7099    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
7100         (NVL(l_actual_upg_option, 'N') = 'O') OR
7101         (NVL(l_enc_upg_option, 'N') = 'O')
7102       )
7103    THEN
7104    NULL;
7105    --
7106    --
7107    
7108   l_ccid := AcctDerRule_7(
7109            p_application_id           => p_application_id
7110          , p_ae_header_id             => l_ae_header_id 
7111 , p_source_3 => p_source_3
7112          , x_transaction_coa_id       => l_adr_transaction_coa_id
7113          , x_accounting_coa_id        => l_adr_accounting_coa_id
7114          , x_value_type_code          => l_adr_value_type_code
7115          , p_side                     => 'NA'
7116    );
7117 
7118    xla_ae_lines_pkg.set_ccid(
7119     p_code_combination_id          => l_ccid
7120   , p_value_type_code              => l_adr_value_type_code
7121   , p_transaction_coa_id           => l_adr_transaction_coa_id
7122   , p_accounting_coa_id            => l_adr_accounting_coa_id
7123   , p_adr_code                     => 'DIST_CCID'
7124   , p_adr_type_code                => 'S'
7125   , p_component_type               => l_component_type
7126   , p_component_code               => l_component_code
7127   , p_component_type_code          => l_component_type_code
7128   , p_component_appl_id            => l_component_appl_id
7129   , p_amb_context_code             => l_amb_context_code
7130   , p_side                         => 'NA'
7131   );
7132 
7133 
7134    --
7135    --
7136    END IF;
7137 
7138        --
7139        -- Update the line information that should be overwritten
7140        --
7141        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
7142                                          p_header_num   => 1);
7143        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
7144 
7145        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
7146 
7147        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
7148           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
7149        END IF;
7150 
7151       --
7152       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
7153       --
7154       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
7155           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
7156       ELSE
7157           ---------------------------------------------------------------------------------------------------
7158           -- 4262811a Switch Sign
7159           ---------------------------------------------------------------------------------------------------
7160           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
7161           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
7162                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7163           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
7164                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7165           -- 5132302
7166           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
7167                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7168 
7169       END IF;
7170 
7171       -- 4955764
7172       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
7173       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
7174 
7175 
7176       XLA_AE_LINES_PKG.ValidateCurrentLine;
7177       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
7178 
7179       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
7180                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
7181                ,p_balance_type_code => l_balance_type_code);
7182 
7183    END IF;
7184 
7185    -----------------------------------------------------------------------------------------
7186    -- 4262811 Multiperiod Accounting
7187    -----------------------------------------------------------------------------------------
7188      -- No MPA option is assigned.
7189 
7190 
7191 END IF;
7192 END IF;
7193 --
7197    trace
7194 
7195 --
7196 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7198       (p_msg      => 'END of AcctLineType_37'
7199       ,p_level    => C_LEVEL_PROCEDURE
7200       ,p_module   => l_log_module);
7201 END IF;
7202 --
7203 EXCEPTION
7204   WHEN xla_exceptions_pkg.application_exception THEN
7205       RAISE;
7206   WHEN OTHERS THEN
7207        xla_exceptions_pkg.raise_message
7208            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_37');
7209 END AcctLineType_37;
7210 --
7211 
7212 ---------------------------------------
7213 --
7214 -- PRIVATE FUNCTION
7215 --         AcctLineType_38
7216 --
7217 ---------------------------------------
7218 PROCEDURE AcctLineType_38 (
7219   p_application_id        IN NUMBER
7220  ,p_event_id              IN NUMBER
7221  ,p_calculate_acctd_flag  IN VARCHAR2
7222  ,p_calculate_g_l_flag    IN VARCHAR2
7223  ,p_actual_flag           IN OUT VARCHAR2
7224  ,p_balance_type_code     OUT VARCHAR2
7225  ,p_gain_or_loss_ref      OUT VARCHAR2
7226  
7227 --Transaction Distribution GL Account
7228  , p_source_4            IN NUMBER
7229 --Bill To Customer Account Identifier
7230  , p_source_30            IN NUMBER
7231 --Bill To Customer Site Use Identifier
7232  , p_source_31            IN NUMBER
7233 --SLA Party Type
7234  , p_source_32            IN VARCHAR2
7235 --Transaction Distribution Account Class
7236  , p_source_33            IN VARCHAR2
7237 --Transaction Distribution Identifier
7238  , p_source_34            IN NUMBER
7239 --Transaction Distribution Type
7240  , p_source_35            IN VARCHAR2
7241 --Transaction Distribution Entered Amount
7242  , p_source_36            IN NUMBER
7243 --Transaction Currency Code
7244  , p_source_37            IN VARCHAR2
7245 --Transaction Exchange Date
7246  , p_source_38            IN DATE
7247 --Transaction Exchange Rate
7248  , p_source_39            IN NUMBER
7249 --Transaction Exchange Rate Type
7250  , p_source_40            IN VARCHAR2
7251 --Transaction Accounting Amount
7252  , p_source_41            IN NUMBER
7253 )
7254 IS
7255 
7256 l_component_type              VARCHAR2(80);
7257 l_component_code              VARCHAR2(30);
7258 l_component_type_code         VARCHAR2(1);
7259 l_component_appl_id           INTEGER;
7260 l_amb_context_code            VARCHAR2(30);
7261 l_entity_code                 VARCHAR2(30);
7262 l_event_class_code            VARCHAR2(30);
7263 l_ae_header_id                NUMBER;
7264 l_event_type_code             VARCHAR2(30);
7265 l_line_definition_code        VARCHAR2(30);
7266 l_line_definition_owner_code  VARCHAR2(1);
7267 --
7268 -- adr variables
7269 l_segment                     VARCHAR2(30);
7270 l_ccid                        NUMBER;
7271 l_adr_transaction_coa_id      NUMBER;
7272 l_adr_accounting_coa_id       NUMBER;
7273 l_adr_flexfield_segment_code  VARCHAR2(30);
7274 l_adr_flex_value_set_id       NUMBER;
7275 l_adr_value_type_code         VARCHAR2(30);
7276 l_adr_value_combination_id    NUMBER;
7277 l_adr_value_segment_code      VARCHAR2(30);
7278 
7279 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
7280 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
7281 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
7282 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
7283 
7284 -- 4262811 Variables ------------------------------------------------------------------------------------------
7285 l_entered_amt_idx             NUMBER;
7286 l_accted_amt_idx              NUMBER;
7287 l_acc_rev_flag                VARCHAR2(1);
7288 l_accrual_line_num            NUMBER;
7289 l_tmp_amt                     NUMBER;
7290 l_acc_rev_natural_side_code   VARCHAR2(1);
7291 
7292 l_num_entries                 NUMBER;
7293 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
7294 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
7295 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
7296 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
7297 l_recog_line_1                NUMBER;
7298 l_recog_line_2                NUMBER;
7299 
7300 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
7301 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
7302 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
7303 
7304 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
7305 
7306 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
7307 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
7308 
7309 ---------------------------------------------------------------------------------------------------------------
7310 
7311 
7312 --
7313 -- bulk performance
7314 --
7315 l_balance_type_code           VARCHAR2(1);
7316 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
7317 l_log_module                  VARCHAR2(240);
7318 
7319 --
7320 -- Upgrade strategy
7321 --
7322 l_actual_upg_option           VARCHAR2(1);
7323 l_enc_upg_option           VARCHAR2(1);
7324 
7325 --
7326 BEGIN
7327 --
7328 IF g_log_enabled THEN
7332 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7329       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_38';
7330 END IF;
7331 --
7333 
7334       trace
7335          (p_msg      => 'BEGIN of AcctLineType_38'
7336          ,p_level    => C_LEVEL_PROCEDURE
7337          ,p_module   => l_log_module);
7338 
7339 END IF;
7340 --
7341 l_component_type             := 'AMB_JLT';
7342 l_component_code             := 'CB_DEFAULT_REC';
7343 l_component_type_code        := 'S';
7344 l_component_appl_id          :=  222;
7345 l_amb_context_code           := 'DEFAULT';
7346 l_entity_code                := 'TRANSACTIONS';
7347 l_event_class_code           := 'CHARGEBACK';
7348 l_event_type_code            := 'CHARGEBACK_ALL';
7349 l_line_definition_owner_code := 'S';
7350 l_line_definition_code       := 'AR_CB_DEFAULT_ACCRUAL';
7351 --
7352 l_balance_type_code          := 'A';
7353 l_segment                     := NULL;
7354 l_ccid                        := NULL;
7355 l_adr_transaction_coa_id      := NULL;
7356 l_adr_accounting_coa_id       := NULL;
7357 l_adr_flexfield_segment_code  := NULL;
7358 l_adr_flex_value_set_id       := NULL;
7359 l_adr_value_type_code         := NULL;
7360 l_adr_value_combination_id    := NULL;
7361 l_adr_value_segment_code      := NULL;
7362 
7363 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
7364 l_bflow_class_code           := '';    -- 4219869 Business Flow
7365 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
7366 l_budgetary_control_flag     := 'N';
7367 
7368 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
7369 l_bflow_applied_to_amt       := NULL; -- 5132302
7370 l_entered_amt_idx            := NULL;          -- 4262811
7371 l_accted_amt_idx             := NULL;          -- 4262811
7372 l_acc_rev_flag               := NULL;          -- 4262811
7373 l_accrual_line_num           := NULL;          -- 4262811
7374 l_tmp_amt                    := NULL;          -- 4262811
7375 --
7376  
7377 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
7378     l_balance_type_code <> 'B' THEN
7379 IF NVL(p_source_33,'
7380 ') =  'REC'
7381  THEN 
7382 
7383    --
7384    XLA_AE_LINES_PKG.SetNewLine;
7385 
7386    p_balance_type_code          := l_balance_type_code;
7387    -- set the flag so later we will know whether the gain loss line needs to be created
7388    
7389    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
7390      p_actual_flag :='A';
7391    END IF;
7392 
7393    --
7394    -- bulk performance
7395    --
7396    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
7397                                       p_header_num   => 0); -- 4262811
7398    --
7399    -- set accounting line options
7400    --
7401    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
7402            p_natural_side_code          => 'D'
7403          , p_gain_or_loss_flag          => 'N'
7404          , p_gl_transfer_mode_code      => 'S'
7405          , p_acct_entry_type_code       => 'A'
7406          , p_switch_side_flag           => 'Y'
7407          , p_merge_duplicate_code       => 'A'
7408          );
7409    --
7410    l_acc_rev_natural_side_code := 'C';  -- 4262811
7411    -- 
7412    --
7413    -- set accounting line type info
7414    --
7415    xla_ae_lines_pkg.SetAcctLineType
7416       (p_component_type             => l_component_type
7417       ,p_event_type_code            => l_event_type_code
7418       ,p_line_definition_owner_code => l_line_definition_owner_code
7419       ,p_line_definition_code       => l_line_definition_code
7420       ,p_accounting_line_code       => l_component_code
7421       ,p_accounting_line_type_code  => l_component_type_code
7422       ,p_accounting_line_appl_id    => l_component_appl_id
7423       ,p_amb_context_code           => l_amb_context_code
7424       ,p_entity_code                => l_entity_code
7425       ,p_event_class_code           => l_event_class_code);
7426    --
7427    -- set accounting class
7428    --
7429    xla_ae_lines_pkg.SetAcctClass(
7430            p_accounting_class_code  => 'RECEIVABLE'
7431          , p_ae_header_id           => l_ae_header_id
7432          );
7433 
7434    --
7435    -- set rounding class
7436    --
7437    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
7438                       'RECEIVABLE';
7439 
7440    --
7441    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
7442    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
7443    --
7444    -- bulk performance
7445    --
7446    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
7447 
7448    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
7449       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
7450 
7451    -- 4955764
7452    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
7453       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
7454 
7455    -- 4458381 Public Sector Enh
7456    
7457    --
7458    -- set accounting attributes for the line type
7459    --
7460    l_entered_amt_idx := 3;
7461    l_accted_amt_idx  := 8;
7462    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
7466    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
7463    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
7464    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
7465    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
7467    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
7468    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
7469    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
7470    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
7471    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
7472    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
7473    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
7474    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
7475    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
7476    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
7477    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
7478    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
7479    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
7480    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
7481    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
7482    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
7483    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
7484    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
7485 
7486    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
7487    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
7488 
7489    ---------------------------------------------------------------------------------------------------------------
7490    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
7491    ---------------------------------------------------------------------------------------------------------------
7492    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
7493 
7494    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
7495    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
7496 
7497    IF xla_accounting_cache_pkg.GetValueChar
7498          (p_source_code         => 'LEDGER_CATEGORY_CODE'
7499          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
7500    AND l_bflow_method_code = 'PRIOR_ENTRY'
7501 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
7502    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
7503          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
7504        )
7505    THEN
7506          xla_ae_lines_pkg.BflowUpgEntry
7507            (p_business_method_code    => l_bflow_method_code
7508            ,p_business_class_code     => l_bflow_class_code
7509            ,p_balance_type            => l_balance_type_code);
7510    ELSE
7511       NULL;
7512 -- No business flow processing for business flow method of NONE.
7513    END IF;
7514 
7515    --
7516    -- call analytical criteria
7517    --
7518    
7519    --
7520    -- call description
7521    --
7522    -- No description or it is inherited.
7523    --
7524    -- call ADRs
7525    -- Bug 4922099
7526    --
7527    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
7528         (NVL(l_actual_upg_option, 'N') = 'O') OR
7529         (NVL(l_enc_upg_option, 'N') = 'O')
7530       )
7531    THEN
7532    NULL;
7533    --
7534    --
7535    
7536   l_ccid := AcctDerRule_32(
7537            p_application_id           => p_application_id
7538          , p_ae_header_id             => l_ae_header_id 
7539 , p_source_4 => p_source_4
7540          , x_transaction_coa_id       => l_adr_transaction_coa_id
7541          , x_accounting_coa_id        => l_adr_accounting_coa_id
7542          , x_value_type_code          => l_adr_value_type_code
7543          , p_side                     => 'NA'
7544    );
7545 
7546    xla_ae_lines_pkg.set_ccid(
7547     p_code_combination_id          => l_ccid
7548   , p_value_type_code              => l_adr_value_type_code
7549   , p_transaction_coa_id           => l_adr_transaction_coa_id
7550   , p_accounting_coa_id            => l_adr_accounting_coa_id
7551   , p_adr_code                     => 'TRX_DIST_CCID'
7552   , p_adr_type_code                => 'S'
7553   , p_component_type               => l_component_type
7554   , p_component_code               => l_component_code
7555   , p_component_type_code          => l_component_type_code
7556   , p_component_appl_id            => l_component_appl_id
7557   , p_amb_context_code             => l_amb_context_code
7558   , p_side                         => 'NA'
7559   );
7560 
7561 
7562    --
7563    --
7564    END IF;
7565    --
7566    -- Bug 4922099
7567    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
7568           (NVL(l_enc_upg_option, 'N') = 'O')
7569         ) AND
7570         (l_bflow_method_code = 'PRIOR_ENTRY')
7571       )
7572    THEN
7573       IF
7574       --
7575       1 = 2
7576       --
7577       THEN
7578       xla_accounting_err_pkg.build_message
7579                                     (p_appli_s_name            => 'XLA'
7580                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
7584                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
7581                                     ,p_token_1                 => 'LINE_NUMBER'
7582                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
7583                                     ,p_token_2                 => 'LINE_TYPE_NAME'
7585                                                                              l_component_type
7586                                                                             ,l_component_code
7587                                                                             ,l_component_type_code
7588                                                                             ,l_component_appl_id
7589                                                                             ,l_amb_context_code
7590                                                                             ,l_entity_code
7591                                                                             ,l_event_class_code
7592                                                                            )
7593                                     ,p_token_3                 => 'OWNER'
7594                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
7595                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
7596                                                                           ,p_lookup_code    => l_component_type_code
7597                                                                          )
7598                                     ,p_token_4                 => 'PRODUCT_NAME'
7599                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
7600                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
7601                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
7602                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
7603                                     ,p_ae_header_id            =>  NULL
7604                                        );
7605 
7606         IF (C_LEVEL_ERROR>= g_log_level) THEN
7607                  trace
7608                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
7609                       ,p_level    => C_LEVEL_ERROR
7610                       ,p_module   => l_log_module);
7611         END IF;
7612       END IF;
7613    END IF;
7614    --
7615    --
7616    ------------------------------------------------------------------------------------------------
7617    -- 4219869 Business Flow
7618    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
7619    -- Prior Entry.  Currently, the following code is always generated.
7620    ------------------------------------------------------------------------------------------------
7621    XLA_AE_LINES_PKG.ValidateCurrentLine;
7622 
7623    ------------------------------------------------------------------------------------
7624    -- 4219869 Business Flow
7625    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
7626    ------------------------------------------------------------------------------------
7627    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
7628 
7629    ----------------------------------------------------------------------------------
7630    -- 4219869 Business Flow
7631    -- Update journal entry status -- Need to generate this within IF <condition>
7632    ----------------------------------------------------------------------------------
7633    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
7634          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
7635          ,p_balance_type_code => l_balance_type_code
7636          );
7637 
7638    -------------------------------------------------------------------------------------------
7639    -- 4262811 - Generate the Accrual Reversal lines
7640    -------------------------------------------------------------------------------------------
7641    BEGIN
7642       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
7643                               (g_array_event(p_event_id).array_value_num('header_index'));
7644       IF l_acc_rev_flag IS NULL THEN
7645          l_acc_rev_flag := 'N';
7646       END IF;
7647    EXCEPTION
7648       WHEN OTHERS THEN
7649          l_acc_rev_flag := 'N';
7650    END;
7651    --
7652    IF (l_acc_rev_flag = 'Y') THEN
7653 
7654        -- 4645092  ------------------------------------------------------------------------------
7655        -- To allow MPA report to determine if it should generate report process
7656        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
7657        ------------------------------------------------------------------------------------------
7658 
7659        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
7660        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
7661    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
7662    -- call ADRs
7663    -- Bug 4922099
7664    --
7665    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
7666         (NVL(l_actual_upg_option, 'N') = 'O') OR
7667         (NVL(l_enc_upg_option, 'N') = 'O')
7668       )
7669    THEN
7670    NULL;
7671    --
7672    --
7673    
7677 , p_source_4 => p_source_4
7674   l_ccid := AcctDerRule_32(
7675            p_application_id           => p_application_id
7676          , p_ae_header_id             => l_ae_header_id 
7678          , x_transaction_coa_id       => l_adr_transaction_coa_id
7679          , x_accounting_coa_id        => l_adr_accounting_coa_id
7680          , x_value_type_code          => l_adr_value_type_code
7681          , p_side                     => 'NA'
7682    );
7683 
7684    xla_ae_lines_pkg.set_ccid(
7685     p_code_combination_id          => l_ccid
7686   , p_value_type_code              => l_adr_value_type_code
7687   , p_transaction_coa_id           => l_adr_transaction_coa_id
7688   , p_accounting_coa_id            => l_adr_accounting_coa_id
7689   , p_adr_code                     => 'TRX_DIST_CCID'
7690   , p_adr_type_code                => 'S'
7691   , p_component_type               => l_component_type
7692   , p_component_code               => l_component_code
7693   , p_component_type_code          => l_component_type_code
7694   , p_component_appl_id            => l_component_appl_id
7695   , p_amb_context_code             => l_amb_context_code
7696   , p_side                         => 'NA'
7697   );
7698 
7699 
7700    --
7701    --
7702    END IF;
7703 
7704        --
7705        -- Update the line information that should be overwritten
7706        --
7707        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
7708                                          p_header_num   => 1);
7709        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
7710 
7711        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
7712 
7713        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
7714           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
7715        END IF;
7716 
7717       --
7718       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
7719       --
7720       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
7721           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
7722       ELSE
7723           ---------------------------------------------------------------------------------------------------
7724           -- 4262811a Switch Sign
7725           ---------------------------------------------------------------------------------------------------
7726           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
7727           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
7728                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7729           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
7730                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7731           -- 5132302
7732           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
7733                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7734 
7735       END IF;
7736 
7737       -- 4955764
7738       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
7739       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
7740 
7741 
7742       XLA_AE_LINES_PKG.ValidateCurrentLine;
7743       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
7744 
7745       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
7746                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
7747                ,p_balance_type_code => l_balance_type_code);
7748 
7749    END IF;
7750 
7751    -----------------------------------------------------------------------------------------
7752    -- 4262811 Multiperiod Accounting
7753    -----------------------------------------------------------------------------------------
7754      -- No MPA option is assigned.
7755 
7756 
7757 END IF;
7758 END IF;
7759 --
7760 
7761 --
7762 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7763    trace
7764       (p_msg      => 'END of AcctLineType_38'
7765       ,p_level    => C_LEVEL_PROCEDURE
7766       ,p_module   => l_log_module);
7767 END IF;
7768 --
7769 EXCEPTION
7770   WHEN xla_exceptions_pkg.application_exception THEN
7771       RAISE;
7772   WHEN OTHERS THEN
7773        xla_exceptions_pkg.raise_message
7774            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_38');
7775 END AcctLineType_38;
7776 --
7777 
7778 ---------------------------------------
7779 --
7780 -- PRIVATE FUNCTION
7781 --         AcctLineType_39
7782 --
7783 ---------------------------------------
7784 PROCEDURE AcctLineType_39 (
7785   p_application_id        IN NUMBER
7786  ,p_event_id              IN NUMBER
7787  ,p_calculate_acctd_flag  IN VARCHAR2
7788  ,p_calculate_g_l_flag    IN VARCHAR2
7789  ,p_actual_flag           IN OUT VARCHAR2
7790  ,p_balance_type_code     OUT VARCHAR2
7791  ,p_gain_or_loss_ref      OUT VARCHAR2
7792  
7793 --Transaction Distribution GL Account
7794  , p_source_4            IN NUMBER
7798  , p_source_31            IN NUMBER
7795 --Bill To Customer Account Identifier
7796  , p_source_30            IN NUMBER
7797 --Bill To Customer Site Use Identifier
7799 --SLA Party Type
7800  , p_source_32            IN VARCHAR2
7801 --Transaction Distribution Account Class
7802  , p_source_33            IN VARCHAR2
7803 --Transaction Distribution Identifier
7804  , p_source_34            IN NUMBER
7805 --Transaction Distribution Type
7806  , p_source_35            IN VARCHAR2
7807 --Transaction Distribution Entered Amount
7808  , p_source_36            IN NUMBER
7809 --Transaction Currency Code
7810  , p_source_37            IN VARCHAR2
7811 --Transaction Exchange Date
7812  , p_source_38            IN DATE
7813 --Transaction Exchange Rate
7814  , p_source_39            IN NUMBER
7815 --Transaction Exchange Rate Type
7816  , p_source_40            IN VARCHAR2
7817 --Transaction Accounting Amount
7818  , p_source_41            IN NUMBER
7819 )
7820 IS
7821 
7822 l_component_type              VARCHAR2(80);
7823 l_component_code              VARCHAR2(30);
7824 l_component_type_code         VARCHAR2(1);
7825 l_component_appl_id           INTEGER;
7826 l_amb_context_code            VARCHAR2(30);
7827 l_entity_code                 VARCHAR2(30);
7828 l_event_class_code            VARCHAR2(30);
7829 l_ae_header_id                NUMBER;
7830 l_event_type_code             VARCHAR2(30);
7831 l_line_definition_code        VARCHAR2(30);
7832 l_line_definition_owner_code  VARCHAR2(1);
7833 --
7834 -- adr variables
7835 l_segment                     VARCHAR2(30);
7836 l_ccid                        NUMBER;
7837 l_adr_transaction_coa_id      NUMBER;
7838 l_adr_accounting_coa_id       NUMBER;
7839 l_adr_flexfield_segment_code  VARCHAR2(30);
7840 l_adr_flex_value_set_id       NUMBER;
7841 l_adr_value_type_code         VARCHAR2(30);
7842 l_adr_value_combination_id    NUMBER;
7843 l_adr_value_segment_code      VARCHAR2(30);
7844 
7845 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
7846 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
7847 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
7848 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
7849 
7850 -- 4262811 Variables ------------------------------------------------------------------------------------------
7851 l_entered_amt_idx             NUMBER;
7852 l_accted_amt_idx              NUMBER;
7853 l_acc_rev_flag                VARCHAR2(1);
7854 l_accrual_line_num            NUMBER;
7855 l_tmp_amt                     NUMBER;
7856 l_acc_rev_natural_side_code   VARCHAR2(1);
7857 
7858 l_num_entries                 NUMBER;
7859 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
7860 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
7861 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
7862 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
7863 l_recog_line_1                NUMBER;
7864 l_recog_line_2                NUMBER;
7865 
7866 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
7867 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
7868 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
7869 
7870 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
7871 
7872 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
7873 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
7874 
7875 ---------------------------------------------------------------------------------------------------------------
7876 
7877 
7878 --
7879 -- bulk performance
7880 --
7881 l_balance_type_code           VARCHAR2(1);
7882 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
7883 l_log_module                  VARCHAR2(240);
7884 
7885 --
7886 -- Upgrade strategy
7887 --
7888 l_actual_upg_option           VARCHAR2(1);
7889 l_enc_upg_option           VARCHAR2(1);
7890 
7891 --
7892 BEGIN
7893 --
7894 IF g_log_enabled THEN
7895       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_39';
7896 END IF;
7897 --
7898 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7899 
7900       trace
7901          (p_msg      => 'BEGIN of AcctLineType_39'
7902          ,p_level    => C_LEVEL_PROCEDURE
7903          ,p_module   => l_log_module);
7904 
7905 END IF;
7906 --
7907 l_component_type             := 'AMB_JLT';
7908 l_component_code             := 'CB_REV';
7909 l_component_type_code        := 'S';
7910 l_component_appl_id          :=  222;
7911 l_amb_context_code           := 'DEFAULT';
7912 l_entity_code                := 'TRANSACTIONS';
7913 l_event_class_code           := 'CHARGEBACK';
7914 l_event_type_code            := 'CHARGEBACK_ALL';
7915 l_line_definition_owner_code := 'S';
7916 l_line_definition_code       := 'AR_CB_DEFAULT_ACCRUAL';
7917 --
7918 l_balance_type_code          := 'A';
7919 l_segment                     := NULL;
7920 l_ccid                        := NULL;
7921 l_adr_transaction_coa_id      := NULL;
7922 l_adr_accounting_coa_id       := NULL;
7923 l_adr_flexfield_segment_code  := NULL;
7924 l_adr_flex_value_set_id       := NULL;
7925 l_adr_value_type_code         := NULL;
7926 l_adr_value_combination_id    := NULL;
7930 l_bflow_class_code           := '';    -- 4219869 Business Flow
7927 l_adr_value_segment_code      := NULL;
7928 
7929 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
7931 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
7932 l_budgetary_control_flag     := 'N';
7933 
7934 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
7935 l_bflow_applied_to_amt       := NULL; -- 5132302
7936 l_entered_amt_idx            := NULL;          -- 4262811
7937 l_accted_amt_idx             := NULL;          -- 4262811
7938 l_acc_rev_flag               := NULL;          -- 4262811
7939 l_accrual_line_num           := NULL;          -- 4262811
7940 l_tmp_amt                    := NULL;          -- 4262811
7941 --
7942  
7943 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
7944     l_balance_type_code <> 'B' THEN
7945 IF NVL(p_source_33,'
7946 ') =  'REV'
7947  THEN 
7948 
7949    --
7950    XLA_AE_LINES_PKG.SetNewLine;
7951 
7952    p_balance_type_code          := l_balance_type_code;
7953    -- set the flag so later we will know whether the gain loss line needs to be created
7954    
7955    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
7956      p_actual_flag :='A';
7957    END IF;
7958 
7959    --
7960    -- bulk performance
7961    --
7962    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
7963                                       p_header_num   => 0); -- 4262811
7964    --
7965    -- set accounting line options
7966    --
7967    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
7968            p_natural_side_code          => 'C'
7969          , p_gain_or_loss_flag          => 'N'
7970          , p_gl_transfer_mode_code      => 'S'
7971          , p_acct_entry_type_code       => 'A'
7972          , p_switch_side_flag           => 'Y'
7973          , p_merge_duplicate_code       => 'A'
7974          );
7975    --
7976    l_acc_rev_natural_side_code := 'D';  -- 4262811
7977    -- 
7978    --
7979    -- set accounting line type info
7980    --
7981    xla_ae_lines_pkg.SetAcctLineType
7982       (p_component_type             => l_component_type
7983       ,p_event_type_code            => l_event_type_code
7984       ,p_line_definition_owner_code => l_line_definition_owner_code
7985       ,p_line_definition_code       => l_line_definition_code
7986       ,p_accounting_line_code       => l_component_code
7987       ,p_accounting_line_type_code  => l_component_type_code
7988       ,p_accounting_line_appl_id    => l_component_appl_id
7989       ,p_amb_context_code           => l_amb_context_code
7990       ,p_entity_code                => l_entity_code
7991       ,p_event_class_code           => l_event_class_code);
7992    --
7993    -- set accounting class
7994    --
7995    xla_ae_lines_pkg.SetAcctClass(
7996            p_accounting_class_code  => 'REVENUE'
7997          , p_ae_header_id           => l_ae_header_id
7998          );
7999 
8000    --
8001    -- set rounding class
8002    --
8003    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
8004                       'RECEIVABLE';
8005 
8006    --
8007    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
8008    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
8009    --
8010    -- bulk performance
8011    --
8012    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
8013 
8014    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
8015       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
8016 
8017    -- 4955764
8018    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
8019       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
8020 
8021    -- 4458381 Public Sector Enh
8022    
8023    --
8024    -- set accounting attributes for the line type
8025    --
8026    l_entered_amt_idx := 3;
8027    l_accted_amt_idx  := 8;
8028    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
8029    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
8030    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
8031    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
8032    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
8033    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
8034    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
8035    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
8036    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
8037    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
8038    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
8039    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
8040    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
8041    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
8042    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
8043    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
8044    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
8045    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
8046    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
8047    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
8051 
8048    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
8049    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
8050    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
8052    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
8053    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
8054 
8055    ---------------------------------------------------------------------------------------------------------------
8056    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
8057    ---------------------------------------------------------------------------------------------------------------
8058    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
8059 
8060    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
8061    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
8062 
8063    IF xla_accounting_cache_pkg.GetValueChar
8064          (p_source_code         => 'LEDGER_CATEGORY_CODE'
8065          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
8066    AND l_bflow_method_code = 'PRIOR_ENTRY'
8067 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
8068    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
8069          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
8070        )
8071    THEN
8072          xla_ae_lines_pkg.BflowUpgEntry
8073            (p_business_method_code    => l_bflow_method_code
8074            ,p_business_class_code     => l_bflow_class_code
8075            ,p_balance_type            => l_balance_type_code);
8076    ELSE
8077       NULL;
8078 -- No business flow processing for business flow method of NONE.
8079    END IF;
8080 
8081    --
8082    -- call analytical criteria
8083    --
8084    
8085    --
8086    -- call description
8087    --
8088    -- No description or it is inherited.
8089    --
8090    -- call ADRs
8091    -- Bug 4922099
8092    --
8093    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
8094         (NVL(l_actual_upg_option, 'N') = 'O') OR
8095         (NVL(l_enc_upg_option, 'N') = 'O')
8096       )
8097    THEN
8098    NULL;
8099    --
8100    --
8101    
8102   l_ccid := AcctDerRule_32(
8103            p_application_id           => p_application_id
8104          , p_ae_header_id             => l_ae_header_id 
8105 , p_source_4 => p_source_4
8106          , x_transaction_coa_id       => l_adr_transaction_coa_id
8107          , x_accounting_coa_id        => l_adr_accounting_coa_id
8108          , x_value_type_code          => l_adr_value_type_code
8109          , p_side                     => 'NA'
8110    );
8111 
8112    xla_ae_lines_pkg.set_ccid(
8113     p_code_combination_id          => l_ccid
8114   , p_value_type_code              => l_adr_value_type_code
8115   , p_transaction_coa_id           => l_adr_transaction_coa_id
8116   , p_accounting_coa_id            => l_adr_accounting_coa_id
8117   , p_adr_code                     => 'TRX_DIST_CCID'
8118   , p_adr_type_code                => 'S'
8119   , p_component_type               => l_component_type
8120   , p_component_code               => l_component_code
8121   , p_component_type_code          => l_component_type_code
8122   , p_component_appl_id            => l_component_appl_id
8123   , p_amb_context_code             => l_amb_context_code
8124   , p_side                         => 'NA'
8125   );
8126 
8127 
8128    --
8129    --
8130    END IF;
8131    --
8132    -- Bug 4922099
8133    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
8134           (NVL(l_enc_upg_option, 'N') = 'O')
8135         ) AND
8136         (l_bflow_method_code = 'PRIOR_ENTRY')
8137       )
8138    THEN
8139       IF
8140       --
8141       1 = 2
8142       --
8143       THEN
8144       xla_accounting_err_pkg.build_message
8145                                     (p_appli_s_name            => 'XLA'
8146                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
8147                                     ,p_token_1                 => 'LINE_NUMBER'
8148                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
8149                                     ,p_token_2                 => 'LINE_TYPE_NAME'
8150                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
8151                                                                              l_component_type
8152                                                                             ,l_component_code
8153                                                                             ,l_component_type_code
8154                                                                             ,l_component_appl_id
8155                                                                             ,l_amb_context_code
8156                                                                             ,l_entity_code
8157                                                                             ,l_event_class_code
8158                                                                            )
8159                                     ,p_token_3                 => 'OWNER'
8163                                                                          )
8160                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
8161                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
8162                                                                           ,p_lookup_code    => l_component_type_code
8164                                     ,p_token_4                 => 'PRODUCT_NAME'
8165                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
8166                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
8167                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
8168                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
8169                                     ,p_ae_header_id            =>  NULL
8170                                        );
8171 
8172         IF (C_LEVEL_ERROR>= g_log_level) THEN
8173                  trace
8174                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
8175                       ,p_level    => C_LEVEL_ERROR
8176                       ,p_module   => l_log_module);
8177         END IF;
8178       END IF;
8179    END IF;
8180    --
8181    --
8182    ------------------------------------------------------------------------------------------------
8183    -- 4219869 Business Flow
8184    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
8185    -- Prior Entry.  Currently, the following code is always generated.
8186    ------------------------------------------------------------------------------------------------
8187    XLA_AE_LINES_PKG.ValidateCurrentLine;
8188 
8189    ------------------------------------------------------------------------------------
8190    -- 4219869 Business Flow
8191    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
8192    ------------------------------------------------------------------------------------
8193    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
8194 
8195    ----------------------------------------------------------------------------------
8196    -- 4219869 Business Flow
8197    -- Update journal entry status -- Need to generate this within IF <condition>
8198    ----------------------------------------------------------------------------------
8199    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
8200          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
8201          ,p_balance_type_code => l_balance_type_code
8202          );
8203 
8204    -------------------------------------------------------------------------------------------
8205    -- 4262811 - Generate the Accrual Reversal lines
8206    -------------------------------------------------------------------------------------------
8207    BEGIN
8208       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
8209                               (g_array_event(p_event_id).array_value_num('header_index'));
8210       IF l_acc_rev_flag IS NULL THEN
8211          l_acc_rev_flag := 'N';
8212       END IF;
8213    EXCEPTION
8214       WHEN OTHERS THEN
8215          l_acc_rev_flag := 'N';
8216    END;
8217    --
8218    IF (l_acc_rev_flag = 'Y') THEN
8219 
8220        -- 4645092  ------------------------------------------------------------------------------
8221        -- To allow MPA report to determine if it should generate report process
8222        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
8223        ------------------------------------------------------------------------------------------
8224 
8225        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
8226        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
8227    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
8228    -- call ADRs
8229    -- Bug 4922099
8230    --
8231    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
8232         (NVL(l_actual_upg_option, 'N') = 'O') OR
8233         (NVL(l_enc_upg_option, 'N') = 'O')
8234       )
8235    THEN
8236    NULL;
8237    --
8238    --
8239    
8240   l_ccid := AcctDerRule_32(
8241            p_application_id           => p_application_id
8242          , p_ae_header_id             => l_ae_header_id 
8243 , p_source_4 => p_source_4
8244          , x_transaction_coa_id       => l_adr_transaction_coa_id
8245          , x_accounting_coa_id        => l_adr_accounting_coa_id
8246          , x_value_type_code          => l_adr_value_type_code
8247          , p_side                     => 'NA'
8248    );
8249 
8250    xla_ae_lines_pkg.set_ccid(
8251     p_code_combination_id          => l_ccid
8252   , p_value_type_code              => l_adr_value_type_code
8253   , p_transaction_coa_id           => l_adr_transaction_coa_id
8254   , p_accounting_coa_id            => l_adr_accounting_coa_id
8255   , p_adr_code                     => 'TRX_DIST_CCID'
8256   , p_adr_type_code                => 'S'
8257   , p_component_type               => l_component_type
8258   , p_component_code               => l_component_code
8259   , p_component_type_code          => l_component_type_code
8260   , p_component_appl_id            => l_component_appl_id
8261   , p_amb_context_code             => l_amb_context_code
8262   , p_side                         => 'NA'
8263   );
8264 
8265 
8266    --
8267    --
8268    END IF;
8269 
8270        --
8274                                          p_header_num   => 1);
8271        -- Update the line information that should be overwritten
8272        --
8273        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
8275        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
8276 
8277        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
8278 
8279        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
8280           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
8281        END IF;
8282 
8283       --
8284       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
8285       --
8286       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
8287           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
8288       ELSE
8289           ---------------------------------------------------------------------------------------------------
8290           -- 4262811a Switch Sign
8291           ---------------------------------------------------------------------------------------------------
8292           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
8293           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
8294                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8295           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
8296                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8297           -- 5132302
8298           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
8299                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8300 
8301       END IF;
8302 
8303       -- 4955764
8304       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
8305       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
8306 
8307 
8308       XLA_AE_LINES_PKG.ValidateCurrentLine;
8309       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
8310 
8311       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
8312                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
8313                ,p_balance_type_code => l_balance_type_code);
8314 
8315    END IF;
8316 
8317    -----------------------------------------------------------------------------------------
8318    -- 4262811 Multiperiod Accounting
8319    -----------------------------------------------------------------------------------------
8320      -- No MPA option is assigned.
8321 
8322 
8323 END IF;
8324 END IF;
8325 --
8326 
8327 --
8328 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8329    trace
8330       (p_msg      => 'END of AcctLineType_39'
8331       ,p_level    => C_LEVEL_PROCEDURE
8332       ,p_module   => l_log_module);
8333 END IF;
8334 --
8335 EXCEPTION
8336   WHEN xla_exceptions_pkg.application_exception THEN
8337       RAISE;
8338   WHEN OTHERS THEN
8339        xla_exceptions_pkg.raise_message
8340            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_39');
8341 END AcctLineType_39;
8342 --
8343 
8344 ---------------------------------------
8345 --
8346 -- PRIVATE FUNCTION
8347 --         AcctLineType_40
8348 --
8349 ---------------------------------------
8350 PROCEDURE AcctLineType_40 (
8351   p_application_id        IN NUMBER
8352  ,p_event_id              IN NUMBER
8353  ,p_calculate_acctd_flag  IN VARCHAR2
8354  ,p_calculate_g_l_flag    IN VARCHAR2
8355  ,p_actual_flag           IN OUT VARCHAR2
8356  ,p_balance_type_code     OUT VARCHAR2
8357  ,p_gain_or_loss_ref      OUT VARCHAR2
8358  
8359 --Distribution GL Account
8360  , p_source_3            IN NUMBER
8361 --Distribution Source Type
8362  , p_source_20            IN VARCHAR2
8363 --Entered Amount
8364  , p_source_24            IN NUMBER
8365 --SLA Party Type
8366  , p_source_32            IN VARCHAR2
8367 --Credit Memo Distribution Identifier
8368  , p_source_42            IN NUMBER
8369 --Credit memo distributions type
8370  , p_source_43            IN VARCHAR2
8371 --Credit Memo Currency Code
8372  , p_source_44            IN VARCHAR2
8373 --Credit Memo Exchange Date
8374  , p_source_45            IN DATE
8375 --Credit Memo Exchange Rate
8376  , p_source_46            IN NUMBER
8377 --Credit Memo Exchange Rate Type
8378  , p_source_47            IN VARCHAR2
8379 --Gain Loss Reference
8380  , p_source_48            IN VARCHAR2
8381 --Credit Memo Accounting Amount
8382  , p_source_49            IN NUMBER
8383 --Credit Memo Bill To Customer Account Identifier
8384  , p_source_50            IN NUMBER
8385 --Credit Memo Bill To Customer Site Use Identifier
8386  , p_source_51            IN NUMBER
8387 --Credit Memo Tax Line Identifier
8388  , p_source_52            IN NUMBER
8389 )
8390 IS
8391 
8392 l_component_type              VARCHAR2(80);
8393 l_component_code              VARCHAR2(30);
8394 l_component_type_code         VARCHAR2(1);
8398 l_event_class_code            VARCHAR2(30);
8395 l_component_appl_id           INTEGER;
8396 l_amb_context_code            VARCHAR2(30);
8397 l_entity_code                 VARCHAR2(30);
8399 l_ae_header_id                NUMBER;
8400 l_event_type_code             VARCHAR2(30);
8401 l_line_definition_code        VARCHAR2(30);
8402 l_line_definition_owner_code  VARCHAR2(1);
8403 --
8404 -- adr variables
8405 l_segment                     VARCHAR2(30);
8406 l_ccid                        NUMBER;
8407 l_adr_transaction_coa_id      NUMBER;
8408 l_adr_accounting_coa_id       NUMBER;
8409 l_adr_flexfield_segment_code  VARCHAR2(30);
8410 l_adr_flex_value_set_id       NUMBER;
8411 l_adr_value_type_code         VARCHAR2(30);
8412 l_adr_value_combination_id    NUMBER;
8413 l_adr_value_segment_code      VARCHAR2(30);
8414 
8415 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
8416 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
8417 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
8418 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
8419 
8420 -- 4262811 Variables ------------------------------------------------------------------------------------------
8421 l_entered_amt_idx             NUMBER;
8422 l_accted_amt_idx              NUMBER;
8423 l_acc_rev_flag                VARCHAR2(1);
8424 l_accrual_line_num            NUMBER;
8425 l_tmp_amt                     NUMBER;
8426 l_acc_rev_natural_side_code   VARCHAR2(1);
8427 
8428 l_num_entries                 NUMBER;
8429 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
8430 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
8431 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
8432 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
8433 l_recog_line_1                NUMBER;
8434 l_recog_line_2                NUMBER;
8435 
8436 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
8437 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
8438 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
8439 
8440 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
8441 
8442 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
8443 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
8444 
8445 ---------------------------------------------------------------------------------------------------------------
8446 
8447 
8448 --
8449 -- bulk performance
8450 --
8451 l_balance_type_code           VARCHAR2(1);
8452 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
8453 l_log_module                  VARCHAR2(240);
8454 
8455 --
8456 -- Upgrade strategy
8457 --
8458 l_actual_upg_option           VARCHAR2(1);
8459 l_enc_upg_option           VARCHAR2(1);
8460 
8461 --
8462 BEGIN
8463 --
8464 IF g_log_enabled THEN
8465       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_40';
8466 END IF;
8467 --
8468 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8469 
8470       trace
8471          (p_msg      => 'BEGIN of AcctLineType_40'
8472          ,p_level    => C_LEVEL_PROCEDURE
8473          ,p_module   => l_log_module);
8474 
8475 END IF;
8476 --
8477 l_component_type             := 'AMB_JLT';
8478 l_component_code             := 'CM_APP_DEFAULT_REC';
8479 l_component_type_code        := 'S';
8480 l_component_appl_id          :=  222;
8481 l_amb_context_code           := 'DEFAULT';
8482 l_entity_code                := 'TRANSACTIONS';
8483 l_event_class_code           := 'CREDIT_MEMO';
8484 l_event_type_code            := 'CREDIT_MEMO_ALL';
8485 l_line_definition_owner_code := 'S';
8486 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
8487 --
8488 l_balance_type_code          := 'A';
8489 l_segment                     := NULL;
8490 l_ccid                        := NULL;
8491 l_adr_transaction_coa_id      := NULL;
8492 l_adr_accounting_coa_id       := NULL;
8493 l_adr_flexfield_segment_code  := NULL;
8494 l_adr_flex_value_set_id       := NULL;
8495 l_adr_value_type_code         := NULL;
8496 l_adr_value_combination_id    := NULL;
8497 l_adr_value_segment_code      := NULL;
8498 
8499 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
8500 l_bflow_class_code           := '';    -- 4219869 Business Flow
8501 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
8502 l_budgetary_control_flag     := 'N';
8503 
8504 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
8505 l_bflow_applied_to_amt       := NULL; -- 5132302
8506 l_entered_amt_idx            := NULL;          -- 4262811
8507 l_accted_amt_idx             := NULL;          -- 4262811
8508 l_acc_rev_flag               := NULL;          -- 4262811
8509 l_accrual_line_num           := NULL;          -- 4262811
8510 l_tmp_amt                    := NULL;          -- 4262811
8511 --
8512  
8513 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
8514     l_balance_type_code <> 'B' THEN
8515 IF NVL(p_source_20,'
8516 ') =  'REC'
8517  THEN 
8518 
8519    --
8520    XLA_AE_LINES_PKG.SetNewLine;
8521 
8522    p_balance_type_code          := l_balance_type_code;
8523    -- set the flag so later we will know whether the gain loss line needs to be created
8524    
8528 
8525    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
8526      p_actual_flag :='A';
8527    END IF;
8529    --
8530    -- bulk performance
8531    --
8532    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
8533                                       p_header_num   => 0); -- 4262811
8534    --
8535    -- set accounting line options
8536    --
8537    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
8538            p_natural_side_code          => 'C'
8539          , p_gain_or_loss_flag          => 'N'
8540          , p_gl_transfer_mode_code      => 'S'
8541          , p_acct_entry_type_code       => 'A'
8542          , p_switch_side_flag           => 'Y'
8543          , p_merge_duplicate_code       => 'A'
8544          );
8545    --
8546    l_acc_rev_natural_side_code := 'D';  -- 4262811
8547    -- 
8548    --
8549    -- set accounting line type info
8550    --
8551    xla_ae_lines_pkg.SetAcctLineType
8552       (p_component_type             => l_component_type
8553       ,p_event_type_code            => l_event_type_code
8554       ,p_line_definition_owner_code => l_line_definition_owner_code
8555       ,p_line_definition_code       => l_line_definition_code
8556       ,p_accounting_line_code       => l_component_code
8557       ,p_accounting_line_type_code  => l_component_type_code
8558       ,p_accounting_line_appl_id    => l_component_appl_id
8559       ,p_amb_context_code           => l_amb_context_code
8560       ,p_entity_code                => l_entity_code
8561       ,p_event_class_code           => l_event_class_code);
8562    --
8563    -- set accounting class
8564    --
8565    xla_ae_lines_pkg.SetAcctClass(
8566            p_accounting_class_code  => 'RECEIVABLE'
8567          , p_ae_header_id           => l_ae_header_id
8568          );
8569 
8570    --
8571    -- set rounding class
8572    --
8573    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
8574                       'RECEIVABLE';
8575 
8576    --
8577    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
8578    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
8579    --
8580    -- bulk performance
8581    --
8582    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
8583 
8584    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
8585       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
8586 
8587    -- 4955764
8588    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
8589       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
8590 
8591    -- 4458381 Public Sector Enh
8592    
8593    --
8594    -- set accounting attributes for the line type
8595    --
8596    l_entered_amt_idx := 3;
8597    l_accted_amt_idx  := 9;
8598    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
8599    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
8600    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_42);
8601    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
8602    l_rec_acct_attrs.array_char_value(2)  := p_source_43;
8603    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
8604    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
8605    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
8606    l_rec_acct_attrs.array_char_value(4)  := p_source_44;
8607    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
8608    l_rec_acct_attrs.array_date_value(5)  := p_source_45;
8609    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
8610    l_rec_acct_attrs.array_num_value(6)  := p_source_46;
8611    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
8612    l_rec_acct_attrs.array_char_value(7)  := p_source_47;
8613    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
8614    l_rec_acct_attrs.array_char_value(8)  := p_source_48;
8615    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
8616    l_rec_acct_attrs.array_num_value(9)  := p_source_49;
8617    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
8618    l_rec_acct_attrs.array_num_value(10)  := p_source_50;
8619    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
8620    l_rec_acct_attrs.array_num_value(11)  := p_source_51;
8621    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
8622    l_rec_acct_attrs.array_char_value(12)  := p_source_32;
8623    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
8624    l_rec_acct_attrs.array_num_value(13)  := p_source_52;
8625 
8626    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
8627    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
8628 
8629    ---------------------------------------------------------------------------------------------------------------
8630    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
8631    ---------------------------------------------------------------------------------------------------------------
8632    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
8633 
8634    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
8638          (p_source_code         => 'LEDGER_CATEGORY_CODE'
8635    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
8636 
8637    IF xla_accounting_cache_pkg.GetValueChar
8639          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
8640    AND l_bflow_method_code = 'PRIOR_ENTRY'
8641 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
8642    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
8643          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
8644        )
8645    THEN
8646          xla_ae_lines_pkg.BflowUpgEntry
8647            (p_business_method_code    => l_bflow_method_code
8648            ,p_business_class_code     => l_bflow_class_code
8649            ,p_balance_type            => l_balance_type_code);
8650    ELSE
8651       NULL;
8652 -- No business flow processing for business flow method of NONE.
8653    END IF;
8654 
8655    --
8656    -- call analytical criteria
8657    --
8658    
8659    --
8660    -- call description
8661    --
8662    -- No description or it is inherited.
8663    --
8664    -- call ADRs
8665    -- Bug 4922099
8666    --
8667    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
8668         (NVL(l_actual_upg_option, 'N') = 'O') OR
8669         (NVL(l_enc_upg_option, 'N') = 'O')
8670       )
8671    THEN
8672    NULL;
8673    --
8674    --
8675    
8676   l_ccid := AcctDerRule_7(
8677            p_application_id           => p_application_id
8678          , p_ae_header_id             => l_ae_header_id 
8679 , p_source_3 => p_source_3
8680          , x_transaction_coa_id       => l_adr_transaction_coa_id
8681          , x_accounting_coa_id        => l_adr_accounting_coa_id
8682          , x_value_type_code          => l_adr_value_type_code
8683          , p_side                     => 'NA'
8684    );
8685 
8686    xla_ae_lines_pkg.set_ccid(
8687     p_code_combination_id          => l_ccid
8688   , p_value_type_code              => l_adr_value_type_code
8689   , p_transaction_coa_id           => l_adr_transaction_coa_id
8690   , p_accounting_coa_id            => l_adr_accounting_coa_id
8691   , p_adr_code                     => 'DIST_CCID'
8692   , p_adr_type_code                => 'S'
8693   , p_component_type               => l_component_type
8694   , p_component_code               => l_component_code
8695   , p_component_type_code          => l_component_type_code
8696   , p_component_appl_id            => l_component_appl_id
8697   , p_amb_context_code             => l_amb_context_code
8698   , p_side                         => 'NA'
8699   );
8700 
8701 
8702    --
8703    --
8704    END IF;
8705    --
8706    -- Bug 4922099
8707    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
8708           (NVL(l_enc_upg_option, 'N') = 'O')
8709         ) AND
8710         (l_bflow_method_code = 'PRIOR_ENTRY')
8711       )
8712    THEN
8713       IF
8714       --
8715       1 = 2
8716       --
8717       THEN
8718       xla_accounting_err_pkg.build_message
8719                                     (p_appli_s_name            => 'XLA'
8720                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
8721                                     ,p_token_1                 => 'LINE_NUMBER'
8722                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
8723                                     ,p_token_2                 => 'LINE_TYPE_NAME'
8724                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
8725                                                                              l_component_type
8726                                                                             ,l_component_code
8727                                                                             ,l_component_type_code
8728                                                                             ,l_component_appl_id
8729                                                                             ,l_amb_context_code
8730                                                                             ,l_entity_code
8731                                                                             ,l_event_class_code
8732                                                                            )
8733                                     ,p_token_3                 => 'OWNER'
8734                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
8735                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
8736                                                                           ,p_lookup_code    => l_component_type_code
8737                                                                          )
8738                                     ,p_token_4                 => 'PRODUCT_NAME'
8739                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
8740                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
8741                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
8742                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
8743                                     ,p_ae_header_id            =>  NULL
8744                                        );
8748                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
8745 
8746         IF (C_LEVEL_ERROR>= g_log_level) THEN
8747                  trace
8749                       ,p_level    => C_LEVEL_ERROR
8750                       ,p_module   => l_log_module);
8751         END IF;
8752       END IF;
8753    END IF;
8754    --
8755    --
8756    ------------------------------------------------------------------------------------------------
8757    -- 4219869 Business Flow
8758    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
8759    -- Prior Entry.  Currently, the following code is always generated.
8760    ------------------------------------------------------------------------------------------------
8761    XLA_AE_LINES_PKG.ValidateCurrentLine;
8762 
8763    ------------------------------------------------------------------------------------
8764    -- 4219869 Business Flow
8765    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
8766    ------------------------------------------------------------------------------------
8767    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
8768 
8769    ----------------------------------------------------------------------------------
8770    -- 4219869 Business Flow
8771    -- Update journal entry status -- Need to generate this within IF <condition>
8772    ----------------------------------------------------------------------------------
8773    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
8774          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
8775          ,p_balance_type_code => l_balance_type_code
8776          );
8777 
8778    -------------------------------------------------------------------------------------------
8779    -- 4262811 - Generate the Accrual Reversal lines
8780    -------------------------------------------------------------------------------------------
8781    BEGIN
8782       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
8783                               (g_array_event(p_event_id).array_value_num('header_index'));
8784       IF l_acc_rev_flag IS NULL THEN
8785          l_acc_rev_flag := 'N';
8786       END IF;
8787    EXCEPTION
8788       WHEN OTHERS THEN
8789          l_acc_rev_flag := 'N';
8790    END;
8791    --
8792    IF (l_acc_rev_flag = 'Y') THEN
8793 
8794        -- 4645092  ------------------------------------------------------------------------------
8795        -- To allow MPA report to determine if it should generate report process
8796        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
8797        ------------------------------------------------------------------------------------------
8798 
8799        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
8800        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
8801    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
8802    -- call ADRs
8803    -- Bug 4922099
8804    --
8805    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
8806         (NVL(l_actual_upg_option, 'N') = 'O') OR
8807         (NVL(l_enc_upg_option, 'N') = 'O')
8808       )
8809    THEN
8810    NULL;
8811    --
8812    --
8813    
8814   l_ccid := AcctDerRule_7(
8815            p_application_id           => p_application_id
8816          , p_ae_header_id             => l_ae_header_id 
8817 , p_source_3 => p_source_3
8818          , x_transaction_coa_id       => l_adr_transaction_coa_id
8819          , x_accounting_coa_id        => l_adr_accounting_coa_id
8820          , x_value_type_code          => l_adr_value_type_code
8821          , p_side                     => 'NA'
8822    );
8823 
8824    xla_ae_lines_pkg.set_ccid(
8825     p_code_combination_id          => l_ccid
8826   , p_value_type_code              => l_adr_value_type_code
8827   , p_transaction_coa_id           => l_adr_transaction_coa_id
8828   , p_accounting_coa_id            => l_adr_accounting_coa_id
8829   , p_adr_code                     => 'DIST_CCID'
8830   , p_adr_type_code                => 'S'
8831   , p_component_type               => l_component_type
8832   , p_component_code               => l_component_code
8833   , p_component_type_code          => l_component_type_code
8834   , p_component_appl_id            => l_component_appl_id
8835   , p_amb_context_code             => l_amb_context_code
8836   , p_side                         => 'NA'
8837   );
8838 
8839 
8840    --
8841    --
8842    END IF;
8843 
8844        --
8845        -- Update the line information that should be overwritten
8846        --
8847        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
8848                                          p_header_num   => 1);
8849        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
8850 
8851        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
8852 
8853        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
8854           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
8855        END IF;
8856 
8857       --
8858       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
8859       --
8860       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
8864           -- 4262811a Switch Sign
8861           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
8862       ELSE
8863           ---------------------------------------------------------------------------------------------------
8865           ---------------------------------------------------------------------------------------------------
8866           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
8867           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
8868                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8869           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
8870                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8871           -- 5132302
8872           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
8873                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8874 
8875       END IF;
8876 
8877       -- 4955764
8878       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
8879       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
8880 
8881 
8882       XLA_AE_LINES_PKG.ValidateCurrentLine;
8883       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
8884 
8885       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
8886                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
8887                ,p_balance_type_code => l_balance_type_code);
8888 
8889    END IF;
8890 
8891    -----------------------------------------------------------------------------------------
8892    -- 4262811 Multiperiod Accounting
8893    -----------------------------------------------------------------------------------------
8894      -- No MPA option is assigned.
8895 
8896 
8897 END IF;
8898 END IF;
8899 --
8900 
8901 --
8902 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8903    trace
8904       (p_msg      => 'END of AcctLineType_40'
8905       ,p_level    => C_LEVEL_PROCEDURE
8906       ,p_module   => l_log_module);
8907 END IF;
8908 --
8909 EXCEPTION
8910   WHEN xla_exceptions_pkg.application_exception THEN
8911       RAISE;
8912   WHEN OTHERS THEN
8913        xla_exceptions_pkg.raise_message
8914            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_40');
8915 END AcctLineType_40;
8916 --
8917 
8918 ---------------------------------------
8919 --
8920 -- PRIVATE FUNCTION
8921 --         AcctLineType_41
8922 --
8923 ---------------------------------------
8924 PROCEDURE AcctLineType_41 (
8925   p_application_id        IN NUMBER
8926  ,p_event_id              IN NUMBER
8927  ,p_calculate_acctd_flag  IN VARCHAR2
8928  ,p_calculate_g_l_flag    IN VARCHAR2
8929  ,p_actual_flag           IN OUT VARCHAR2
8930  ,p_balance_type_code     OUT VARCHAR2
8931  ,p_gain_or_loss_ref      OUT VARCHAR2
8932  
8933 --Distribution GL Account
8934  , p_source_3            IN NUMBER
8935 --Distribution Source Type
8936  , p_source_20            IN VARCHAR2
8937 --Receivable Activity Type
8938  , p_source_21            IN VARCHAR2
8939 --Entered Amount
8940  , p_source_24            IN NUMBER
8941 --SLA Party Type
8942  , p_source_32            IN VARCHAR2
8943 --Credit Memo Distribution Identifier
8944  , p_source_42            IN NUMBER
8945 --Credit memo distributions type
8946  , p_source_43            IN VARCHAR2
8947 --Credit Memo Currency Code
8948  , p_source_44            IN VARCHAR2
8949 --Credit Memo Exchange Date
8950  , p_source_45            IN DATE
8951 --Credit Memo Exchange Rate
8952  , p_source_46            IN NUMBER
8953 --Credit Memo Exchange Rate Type
8954  , p_source_47            IN VARCHAR2
8955 --Gain Loss Reference
8956  , p_source_48            IN VARCHAR2
8957 --Credit Memo Accounting Amount
8958  , p_source_49            IN NUMBER
8959 --Credit Memo Bill To Customer Account Identifier
8960  , p_source_50            IN NUMBER
8961 --Credit Memo Bill To Customer Site Use Identifier
8962  , p_source_51            IN NUMBER
8963 --Credit Memo Tax Line Identifier
8964  , p_source_52            IN NUMBER
8965 )
8966 IS
8967 
8968 l_component_type              VARCHAR2(80);
8969 l_component_code              VARCHAR2(30);
8970 l_component_type_code         VARCHAR2(1);
8971 l_component_appl_id           INTEGER;
8972 l_amb_context_code            VARCHAR2(30);
8973 l_entity_code                 VARCHAR2(30);
8974 l_event_class_code            VARCHAR2(30);
8975 l_ae_header_id                NUMBER;
8976 l_event_type_code             VARCHAR2(30);
8977 l_line_definition_code        VARCHAR2(30);
8978 l_line_definition_owner_code  VARCHAR2(1);
8979 --
8980 -- adr variables
8981 l_segment                     VARCHAR2(30);
8982 l_ccid                        NUMBER;
8983 l_adr_transaction_coa_id      NUMBER;
8984 l_adr_accounting_coa_id       NUMBER;
8985 l_adr_flexfield_segment_code  VARCHAR2(30);
8986 l_adr_flex_value_set_id       NUMBER;
8987 l_adr_value_type_code         VARCHAR2(30);
8988 l_adr_value_combination_id    NUMBER;
8992 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
8989 l_adr_value_segment_code      VARCHAR2(30);
8990 
8991 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
8993 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
8994 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
8995 
8996 -- 4262811 Variables ------------------------------------------------------------------------------------------
8997 l_entered_amt_idx             NUMBER;
8998 l_accted_amt_idx              NUMBER;
8999 l_acc_rev_flag                VARCHAR2(1);
9000 l_accrual_line_num            NUMBER;
9001 l_tmp_amt                     NUMBER;
9002 l_acc_rev_natural_side_code   VARCHAR2(1);
9003 
9004 l_num_entries                 NUMBER;
9005 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
9006 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
9007 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
9008 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
9009 l_recog_line_1                NUMBER;
9010 l_recog_line_2                NUMBER;
9011 
9012 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
9013 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
9014 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
9015 
9016 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
9017 
9018 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
9019 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
9020 
9021 ---------------------------------------------------------------------------------------------------------------
9022 
9023 
9024 --
9025 -- bulk performance
9026 --
9027 l_balance_type_code           VARCHAR2(1);
9028 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
9029 l_log_module                  VARCHAR2(240);
9030 
9031 --
9032 -- Upgrade strategy
9033 --
9034 l_actual_upg_option           VARCHAR2(1);
9035 l_enc_upg_option           VARCHAR2(1);
9036 
9037 --
9038 BEGIN
9039 --
9040 IF g_log_enabled THEN
9041       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_41';
9042 END IF;
9043 --
9044 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9045 
9046       trace
9047          (p_msg      => 'BEGIN of AcctLineType_41'
9048          ,p_level    => C_LEVEL_PROCEDURE
9049          ,p_module   => l_log_module);
9050 
9051 END IF;
9052 --
9053 l_component_type             := 'AMB_JLT';
9054 l_component_code             := 'CM_APP_REFUND';
9055 l_component_type_code        := 'S';
9056 l_component_appl_id          :=  222;
9057 l_amb_context_code           := 'DEFAULT';
9058 l_entity_code                := 'TRANSACTIONS';
9059 l_event_class_code           := 'CREDIT_MEMO';
9060 l_event_type_code            := 'CREDIT_MEMO_ALL';
9061 l_line_definition_owner_code := 'S';
9062 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
9063 --
9064 l_balance_type_code          := 'A';
9065 l_segment                     := NULL;
9066 l_ccid                        := NULL;
9067 l_adr_transaction_coa_id      := NULL;
9068 l_adr_accounting_coa_id       := NULL;
9069 l_adr_flexfield_segment_code  := NULL;
9070 l_adr_flex_value_set_id       := NULL;
9071 l_adr_value_type_code         := NULL;
9072 l_adr_value_combination_id    := NULL;
9073 l_adr_value_segment_code      := NULL;
9074 
9075 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
9076 l_bflow_class_code           := '';    -- 4219869 Business Flow
9077 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
9078 l_budgetary_control_flag     := 'N';
9079 
9080 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
9081 l_bflow_applied_to_amt       := NULL; -- 5132302
9082 l_entered_amt_idx            := NULL;          -- 4262811
9083 l_accted_amt_idx             := NULL;          -- 4262811
9084 l_acc_rev_flag               := NULL;          -- 4262811
9085 l_accrual_line_num           := NULL;          -- 4262811
9086 l_tmp_amt                    := NULL;          -- 4262811
9087 --
9088  
9089 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
9090     l_balance_type_code <> 'B' THEN
9091 IF (NVL(p_source_20,'
9092 ') =  'ACTIVITY' AND 
9093 NVL(p_source_21,'
9094 ') =  'REFUND') OR 
9095 (NVL(p_source_20,'
9096 ') =  'ACTIVITY' AND 
9097 NVL(p_source_21,'
9098 ') =  'CM_REFUND')
9099  THEN 
9100 
9101    --
9102    XLA_AE_LINES_PKG.SetNewLine;
9103 
9104    p_balance_type_code          := l_balance_type_code;
9105    -- set the flag so later we will know whether the gain loss line needs to be created
9106    
9107    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
9108      p_actual_flag :='A';
9109    END IF;
9110 
9111    --
9112    -- bulk performance
9113    --
9114    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
9115                                       p_header_num   => 0); -- 4262811
9116    --
9117    -- set accounting line options
9118    --
9119    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
9120            p_natural_side_code          => 'C'
9121          , p_gain_or_loss_flag          => 'N'
9125          , p_merge_duplicate_code       => 'A'
9122          , p_gl_transfer_mode_code      => 'S'
9123          , p_acct_entry_type_code       => 'A'
9124          , p_switch_side_flag           => 'Y'
9126          );
9127    --
9128    l_acc_rev_natural_side_code := 'D';  -- 4262811
9129    -- 
9130    --
9131    -- set accounting line type info
9132    --
9133    xla_ae_lines_pkg.SetAcctLineType
9134       (p_component_type             => l_component_type
9135       ,p_event_type_code            => l_event_type_code
9136       ,p_line_definition_owner_code => l_line_definition_owner_code
9137       ,p_line_definition_code       => l_line_definition_code
9138       ,p_accounting_line_code       => l_component_code
9139       ,p_accounting_line_type_code  => l_component_type_code
9140       ,p_accounting_line_appl_id    => l_component_appl_id
9141       ,p_amb_context_code           => l_amb_context_code
9142       ,p_entity_code                => l_entity_code
9143       ,p_event_class_code           => l_event_class_code);
9144    --
9145    -- set accounting class
9146    --
9147    xla_ae_lines_pkg.SetAcctClass(
9148            p_accounting_class_code  => 'REFUND'
9149          , p_ae_header_id           => l_ae_header_id
9150          );
9151 
9152    --
9153    -- set rounding class
9154    --
9155    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
9156                       'REFUND';
9157 
9158    --
9159    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
9160    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
9161    --
9162    -- bulk performance
9163    --
9164    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
9165 
9166    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
9167       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
9168 
9169    -- 4955764
9170    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
9171       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
9172 
9173    -- 4458381 Public Sector Enh
9174    
9175    --
9176    -- set accounting attributes for the line type
9177    --
9178    l_entered_amt_idx := 3;
9179    l_accted_amt_idx  := 9;
9180    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
9181    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
9182    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_42);
9183    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
9184    l_rec_acct_attrs.array_char_value(2)  := p_source_43;
9185    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
9186    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
9187    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
9188    l_rec_acct_attrs.array_char_value(4)  := p_source_44;
9189    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
9190    l_rec_acct_attrs.array_date_value(5)  := p_source_45;
9191    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
9192    l_rec_acct_attrs.array_num_value(6)  := p_source_46;
9193    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
9194    l_rec_acct_attrs.array_char_value(7)  := p_source_47;
9195    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
9196    l_rec_acct_attrs.array_char_value(8)  := p_source_48;
9197    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
9198    l_rec_acct_attrs.array_num_value(9)  := p_source_49;
9199    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
9200    l_rec_acct_attrs.array_num_value(10)  := p_source_50;
9201    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
9202    l_rec_acct_attrs.array_num_value(11)  := p_source_51;
9203    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
9204    l_rec_acct_attrs.array_char_value(12)  := p_source_32;
9205    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
9206    l_rec_acct_attrs.array_num_value(13)  := p_source_52;
9207 
9208    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
9209    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
9210 
9211    ---------------------------------------------------------------------------------------------------------------
9212    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
9213    ---------------------------------------------------------------------------------------------------------------
9214    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
9215 
9216    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
9217    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
9218 
9219    IF xla_accounting_cache_pkg.GetValueChar
9220          (p_source_code         => 'LEDGER_CATEGORY_CODE'
9221          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
9222    AND l_bflow_method_code = 'PRIOR_ENTRY'
9223 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
9224    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
9225          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
9226        )
9227    THEN
9231            ,p_balance_type            => l_balance_type_code);
9228          xla_ae_lines_pkg.BflowUpgEntry
9229            (p_business_method_code    => l_bflow_method_code
9230            ,p_business_class_code     => l_bflow_class_code
9232    ELSE
9233       NULL;
9234 -- No business flow processing for business flow method of NONE.
9235    END IF;
9236 
9237    --
9238    -- call analytical criteria
9239    --
9240    
9241    --
9242    -- call description
9243    --
9244    -- No description or it is inherited.
9245    --
9246    -- call ADRs
9247    -- Bug 4922099
9248    --
9249    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
9250         (NVL(l_actual_upg_option, 'N') = 'O') OR
9251         (NVL(l_enc_upg_option, 'N') = 'O')
9252       )
9253    THEN
9254    NULL;
9255    --
9256    --
9257    
9258   l_ccid := AcctDerRule_7(
9259            p_application_id           => p_application_id
9260          , p_ae_header_id             => l_ae_header_id 
9261 , p_source_3 => p_source_3
9262          , x_transaction_coa_id       => l_adr_transaction_coa_id
9263          , x_accounting_coa_id        => l_adr_accounting_coa_id
9264          , x_value_type_code          => l_adr_value_type_code
9265          , p_side                     => 'NA'
9266    );
9267 
9268    xla_ae_lines_pkg.set_ccid(
9269     p_code_combination_id          => l_ccid
9270   , p_value_type_code              => l_adr_value_type_code
9271   , p_transaction_coa_id           => l_adr_transaction_coa_id
9272   , p_accounting_coa_id            => l_adr_accounting_coa_id
9273   , p_adr_code                     => 'DIST_CCID'
9274   , p_adr_type_code                => 'S'
9275   , p_component_type               => l_component_type
9276   , p_component_code               => l_component_code
9277   , p_component_type_code          => l_component_type_code
9278   , p_component_appl_id            => l_component_appl_id
9279   , p_amb_context_code             => l_amb_context_code
9280   , p_side                         => 'NA'
9281   );
9282 
9283 
9284    --
9285    --
9286    END IF;
9287    --
9288    -- Bug 4922099
9289    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
9290           (NVL(l_enc_upg_option, 'N') = 'O')
9291         ) AND
9292         (l_bflow_method_code = 'PRIOR_ENTRY')
9293       )
9294    THEN
9295       IF
9296       --
9297       1 = 2
9298       --
9299       THEN
9300       xla_accounting_err_pkg.build_message
9301                                     (p_appli_s_name            => 'XLA'
9302                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
9303                                     ,p_token_1                 => 'LINE_NUMBER'
9304                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
9305                                     ,p_token_2                 => 'LINE_TYPE_NAME'
9306                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
9307                                                                              l_component_type
9308                                                                             ,l_component_code
9309                                                                             ,l_component_type_code
9310                                                                             ,l_component_appl_id
9311                                                                             ,l_amb_context_code
9312                                                                             ,l_entity_code
9313                                                                             ,l_event_class_code
9314                                                                            )
9315                                     ,p_token_3                 => 'OWNER'
9316                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
9317                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
9318                                                                           ,p_lookup_code    => l_component_type_code
9319                                                                          )
9320                                     ,p_token_4                 => 'PRODUCT_NAME'
9321                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
9322                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
9323                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
9324                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
9325                                     ,p_ae_header_id            =>  NULL
9326                                        );
9327 
9328         IF (C_LEVEL_ERROR>= g_log_level) THEN
9329                  trace
9330                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
9331                       ,p_level    => C_LEVEL_ERROR
9332                       ,p_module   => l_log_module);
9333         END IF;
9334       END IF;
9335    END IF;
9336    --
9337    --
9338    ------------------------------------------------------------------------------------------------
9339    -- 4219869 Business Flow
9340    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
9344 
9341    -- Prior Entry.  Currently, the following code is always generated.
9342    ------------------------------------------------------------------------------------------------
9343    XLA_AE_LINES_PKG.ValidateCurrentLine;
9345    ------------------------------------------------------------------------------------
9346    -- 4219869 Business Flow
9347    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
9348    ------------------------------------------------------------------------------------
9349    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
9350 
9351    ----------------------------------------------------------------------------------
9352    -- 4219869 Business Flow
9353    -- Update journal entry status -- Need to generate this within IF <condition>
9354    ----------------------------------------------------------------------------------
9355    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
9356          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
9357          ,p_balance_type_code => l_balance_type_code
9358          );
9359 
9360    -------------------------------------------------------------------------------------------
9361    -- 4262811 - Generate the Accrual Reversal lines
9362    -------------------------------------------------------------------------------------------
9363    BEGIN
9364       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
9365                               (g_array_event(p_event_id).array_value_num('header_index'));
9366       IF l_acc_rev_flag IS NULL THEN
9367          l_acc_rev_flag := 'N';
9368       END IF;
9369    EXCEPTION
9370       WHEN OTHERS THEN
9371          l_acc_rev_flag := 'N';
9372    END;
9373    --
9374    IF (l_acc_rev_flag = 'Y') THEN
9375 
9376        -- 4645092  ------------------------------------------------------------------------------
9377        -- To allow MPA report to determine if it should generate report process
9378        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
9379        ------------------------------------------------------------------------------------------
9380 
9381        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
9382        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
9383    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
9384    -- call ADRs
9385    -- Bug 4922099
9386    --
9387    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
9388         (NVL(l_actual_upg_option, 'N') = 'O') OR
9389         (NVL(l_enc_upg_option, 'N') = 'O')
9390       )
9391    THEN
9392    NULL;
9393    --
9394    --
9395    
9396   l_ccid := AcctDerRule_7(
9397            p_application_id           => p_application_id
9398          , p_ae_header_id             => l_ae_header_id 
9399 , p_source_3 => p_source_3
9400          , x_transaction_coa_id       => l_adr_transaction_coa_id
9401          , x_accounting_coa_id        => l_adr_accounting_coa_id
9402          , x_value_type_code          => l_adr_value_type_code
9403          , p_side                     => 'NA'
9404    );
9405 
9406    xla_ae_lines_pkg.set_ccid(
9407     p_code_combination_id          => l_ccid
9408   , p_value_type_code              => l_adr_value_type_code
9409   , p_transaction_coa_id           => l_adr_transaction_coa_id
9410   , p_accounting_coa_id            => l_adr_accounting_coa_id
9411   , p_adr_code                     => 'DIST_CCID'
9412   , p_adr_type_code                => 'S'
9413   , p_component_type               => l_component_type
9414   , p_component_code               => l_component_code
9415   , p_component_type_code          => l_component_type_code
9416   , p_component_appl_id            => l_component_appl_id
9417   , p_amb_context_code             => l_amb_context_code
9418   , p_side                         => 'NA'
9419   );
9420 
9421 
9422    --
9423    --
9424    END IF;
9425 
9426        --
9427        -- Update the line information that should be overwritten
9428        --
9429        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
9430                                          p_header_num   => 1);
9431        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
9432 
9433        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
9434 
9435        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
9436           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
9437        END IF;
9438 
9439       --
9440       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
9441       --
9442       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
9443           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
9444       ELSE
9445           ---------------------------------------------------------------------------------------------------
9446           -- 4262811a Switch Sign
9447           ---------------------------------------------------------------------------------------------------
9448           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
9449           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
9453           -- 5132302
9450                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
9451           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
9452                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
9454           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
9455                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
9456 
9457       END IF;
9458 
9459       -- 4955764
9460       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
9461       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
9462 
9463 
9464       XLA_AE_LINES_PKG.ValidateCurrentLine;
9465       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
9466 
9467       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
9468                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
9469                ,p_balance_type_code => l_balance_type_code);
9470 
9471    END IF;
9472 
9473    -----------------------------------------------------------------------------------------
9474    -- 4262811 Multiperiod Accounting
9475    -----------------------------------------------------------------------------------------
9476      -- No MPA option is assigned.
9477 
9478 
9479 END IF;
9480 END IF;
9481 --
9482 
9483 --
9484 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9485    trace
9486       (p_msg      => 'END of AcctLineType_41'
9487       ,p_level    => C_LEVEL_PROCEDURE
9488       ,p_module   => l_log_module);
9489 END IF;
9490 --
9491 EXCEPTION
9492   WHEN xla_exceptions_pkg.application_exception THEN
9493       RAISE;
9494   WHEN OTHERS THEN
9495        xla_exceptions_pkg.raise_message
9496            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_41');
9497 END AcctLineType_41;
9498 --
9499 
9500 ---------------------------------------
9501 --
9502 -- PRIVATE FUNCTION
9503 --         AcctLineType_42
9504 --
9505 ---------------------------------------
9506 PROCEDURE AcctLineType_42 (
9507   p_application_id        IN NUMBER
9508  ,p_event_id              IN NUMBER
9509  ,p_calculate_acctd_flag  IN VARCHAR2
9510  ,p_calculate_g_l_flag    IN VARCHAR2
9511  ,p_actual_flag           IN OUT VARCHAR2
9512  ,p_balance_type_code     OUT VARCHAR2
9513  ,p_gain_or_loss_ref      OUT VARCHAR2
9514  
9515 --Credit Memo Distribution GL Account
9516  , p_source_2            IN NUMBER
9517 --SLA Party Type
9518  , p_source_32            IN VARCHAR2
9519 --Credit Memo Distribution Identifier
9520  , p_source_42            IN NUMBER
9521 --Credit memo distributions type
9522  , p_source_43            IN VARCHAR2
9523 --Credit Memo Currency Code
9524  , p_source_44            IN VARCHAR2
9525 --Credit Memo Exchange Date
9526  , p_source_45            IN DATE
9527 --Credit Memo Exchange Rate
9528  , p_source_46            IN NUMBER
9529 --Credit Memo Exchange Rate Type
9530  , p_source_47            IN VARCHAR2
9531 --Gain Loss Reference
9532  , p_source_48            IN VARCHAR2
9533 --Credit Memo Accounting Amount
9534  , p_source_49            IN NUMBER
9535 --Credit Memo Bill To Customer Account Identifier
9536  , p_source_50            IN NUMBER
9537 --Credit Memo Bill To Customer Site Use Identifier
9538  , p_source_51            IN NUMBER
9539 --Credit Memo Tax Line Identifier
9540  , p_source_52            IN NUMBER
9541 --Credit Memo Distribution Account Class
9542  , p_source_53            IN VARCHAR2
9543 --Credit Memo Distribution Entered Amount
9544  , p_source_54            IN NUMBER
9545 )
9546 IS
9547 
9548 l_component_type              VARCHAR2(80);
9549 l_component_code              VARCHAR2(30);
9550 l_component_type_code         VARCHAR2(1);
9551 l_component_appl_id           INTEGER;
9552 l_amb_context_code            VARCHAR2(30);
9553 l_entity_code                 VARCHAR2(30);
9554 l_event_class_code            VARCHAR2(30);
9555 l_ae_header_id                NUMBER;
9556 l_event_type_code             VARCHAR2(30);
9557 l_line_definition_code        VARCHAR2(30);
9558 l_line_definition_owner_code  VARCHAR2(1);
9559 --
9560 -- adr variables
9561 l_segment                     VARCHAR2(30);
9562 l_ccid                        NUMBER;
9563 l_adr_transaction_coa_id      NUMBER;
9564 l_adr_accounting_coa_id       NUMBER;
9565 l_adr_flexfield_segment_code  VARCHAR2(30);
9566 l_adr_flex_value_set_id       NUMBER;
9567 l_adr_value_type_code         VARCHAR2(30);
9568 l_adr_value_combination_id    NUMBER;
9569 l_adr_value_segment_code      VARCHAR2(30);
9570 
9571 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
9572 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
9573 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
9574 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
9575 
9576 -- 4262811 Variables ------------------------------------------------------------------------------------------
9577 l_entered_amt_idx             NUMBER;
9578 l_accted_amt_idx              NUMBER;
9579 l_acc_rev_flag                VARCHAR2(1);
9580 l_accrual_line_num            NUMBER;
9581 l_tmp_amt                     NUMBER;
9582 l_acc_rev_natural_side_code   VARCHAR2(1);
9583 
9587 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
9584 l_num_entries                 NUMBER;
9585 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
9586 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
9588 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
9589 l_recog_line_1                NUMBER;
9590 l_recog_line_2                NUMBER;
9591 
9592 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
9593 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
9594 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
9595 
9596 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
9597 
9598 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
9599 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
9600 
9601 ---------------------------------------------------------------------------------------------------------------
9602 
9603 
9604 --
9605 -- bulk performance
9606 --
9607 l_balance_type_code           VARCHAR2(1);
9608 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
9609 l_log_module                  VARCHAR2(240);
9610 
9611 --
9612 -- Upgrade strategy
9613 --
9614 l_actual_upg_option           VARCHAR2(1);
9615 l_enc_upg_option           VARCHAR2(1);
9616 
9617 --
9618 BEGIN
9619 --
9620 IF g_log_enabled THEN
9621       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_42';
9622 END IF;
9623 --
9624 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9625 
9626       trace
9627          (p_msg      => 'BEGIN of AcctLineType_42'
9628          ,p_level    => C_LEVEL_PROCEDURE
9629          ,p_module   => l_log_module);
9630 
9631 END IF;
9632 --
9633 l_component_type             := 'AMB_JLT';
9634 l_component_code             := 'CM_CHARGES';
9635 l_component_type_code        := 'S';
9636 l_component_appl_id          :=  222;
9637 l_amb_context_code           := 'DEFAULT';
9638 l_entity_code                := 'TRANSACTIONS';
9639 l_event_class_code           := 'CREDIT_MEMO';
9640 l_event_type_code            := 'CREDIT_MEMO_ALL';
9641 l_line_definition_owner_code := 'S';
9642 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
9643 --
9644 l_balance_type_code          := 'A';
9645 l_segment                     := NULL;
9646 l_ccid                        := NULL;
9647 l_adr_transaction_coa_id      := NULL;
9648 l_adr_accounting_coa_id       := NULL;
9649 l_adr_flexfield_segment_code  := NULL;
9650 l_adr_flex_value_set_id       := NULL;
9651 l_adr_value_type_code         := NULL;
9652 l_adr_value_combination_id    := NULL;
9653 l_adr_value_segment_code      := NULL;
9654 
9655 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
9656 l_bflow_class_code           := '';    -- 4219869 Business Flow
9657 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
9658 l_budgetary_control_flag     := 'N';
9659 
9660 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
9661 l_bflow_applied_to_amt       := NULL; -- 5132302
9662 l_entered_amt_idx            := NULL;          -- 4262811
9663 l_accted_amt_idx             := NULL;          -- 4262811
9664 l_acc_rev_flag               := NULL;          -- 4262811
9665 l_accrual_line_num           := NULL;          -- 4262811
9666 l_tmp_amt                    := NULL;          -- 4262811
9667 --
9668  
9669 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
9670     l_balance_type_code <> 'B' THEN
9671 IF NVL(p_source_53,'
9672 ') =  'CHARGES'
9673  THEN 
9674 
9675    --
9676    XLA_AE_LINES_PKG.SetNewLine;
9677 
9678    p_balance_type_code          := l_balance_type_code;
9679    -- set the flag so later we will know whether the gain loss line needs to be created
9680    
9681    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
9682      p_actual_flag :='A';
9683    END IF;
9684 
9685    --
9686    -- bulk performance
9687    --
9688    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
9689                                       p_header_num   => 0); -- 4262811
9690    --
9691    -- set accounting line options
9692    --
9693    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
9694            p_natural_side_code          => 'C'
9695          , p_gain_or_loss_flag          => 'N'
9696          , p_gl_transfer_mode_code      => 'S'
9697          , p_acct_entry_type_code       => 'A'
9698          , p_switch_side_flag           => 'Y'
9699          , p_merge_duplicate_code       => 'A'
9700          );
9701    --
9702    l_acc_rev_natural_side_code := 'D';  -- 4262811
9703    -- 
9704    --
9705    -- set accounting line type info
9706    --
9707    xla_ae_lines_pkg.SetAcctLineType
9708       (p_component_type             => l_component_type
9709       ,p_event_type_code            => l_event_type_code
9710       ,p_line_definition_owner_code => l_line_definition_owner_code
9711       ,p_line_definition_code       => l_line_definition_code
9712       ,p_accounting_line_code       => l_component_code
9713       ,p_accounting_line_type_code  => l_component_type_code
9714       ,p_accounting_line_appl_id    => l_component_appl_id
9718    --
9715       ,p_amb_context_code           => l_amb_context_code
9716       ,p_entity_code                => l_entity_code
9717       ,p_event_class_code           => l_event_class_code);
9719    -- set accounting class
9720    --
9721    xla_ae_lines_pkg.SetAcctClass(
9722            p_accounting_class_code  => 'CHARGES'
9723          , p_ae_header_id           => l_ae_header_id
9724          );
9725 
9726    --
9727    -- set rounding class
9728    --
9729    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
9730                       'RECEIVABLE';
9731 
9732    --
9733    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
9734    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
9735    --
9736    -- bulk performance
9737    --
9738    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
9739 
9740    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
9741       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
9742 
9743    -- 4955764
9744    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
9745       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
9746 
9747    -- 4458381 Public Sector Enh
9748    
9749    --
9750    -- set accounting attributes for the line type
9751    --
9752    l_entered_amt_idx := 3;
9753    l_accted_amt_idx  := 9;
9754    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
9755    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
9756    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_42);
9757    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
9758    l_rec_acct_attrs.array_char_value(2)  := p_source_43;
9759    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
9760    l_rec_acct_attrs.array_num_value(3)  := p_source_54;
9761    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
9762    l_rec_acct_attrs.array_char_value(4)  := p_source_44;
9763    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
9764    l_rec_acct_attrs.array_date_value(5)  := p_source_45;
9765    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
9766    l_rec_acct_attrs.array_num_value(6)  := p_source_46;
9767    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
9768    l_rec_acct_attrs.array_char_value(7)  := p_source_47;
9769    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
9770    l_rec_acct_attrs.array_char_value(8)  := p_source_48;
9771    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
9772    l_rec_acct_attrs.array_num_value(9)  := p_source_49;
9773    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
9774    l_rec_acct_attrs.array_num_value(10)  := p_source_50;
9775    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
9776    l_rec_acct_attrs.array_num_value(11)  := p_source_51;
9777    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
9778    l_rec_acct_attrs.array_char_value(12)  := p_source_32;
9779    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
9780    l_rec_acct_attrs.array_num_value(13)  := p_source_52;
9781 
9782    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
9783    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
9784 
9785    ---------------------------------------------------------------------------------------------------------------
9786    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
9787    ---------------------------------------------------------------------------------------------------------------
9788    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
9789 
9790    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
9791    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
9792 
9793    IF xla_accounting_cache_pkg.GetValueChar
9794          (p_source_code         => 'LEDGER_CATEGORY_CODE'
9795          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
9796    AND l_bflow_method_code = 'PRIOR_ENTRY'
9797 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
9798    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
9799          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
9800        )
9801    THEN
9802          xla_ae_lines_pkg.BflowUpgEntry
9803            (p_business_method_code    => l_bflow_method_code
9804            ,p_business_class_code     => l_bflow_class_code
9805            ,p_balance_type            => l_balance_type_code);
9806    ELSE
9807       NULL;
9808 -- No business flow processing for business flow method of NONE.
9809    END IF;
9810 
9811    --
9812    -- call analytical criteria
9813    --
9814    
9815    --
9816    -- call description
9817    --
9818    -- No description or it is inherited.
9819    --
9820    -- call ADRs
9821    -- Bug 4922099
9822    --
9823    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
9824         (NVL(l_actual_upg_option, 'N') = 'O') OR
9825         (NVL(l_enc_upg_option, 'N') = 'O')
9826       )
9827    THEN
9828    NULL;
9829    --
9830    --
9831    
9832   l_ccid := AcctDerRule_6(
9836          , x_transaction_coa_id       => l_adr_transaction_coa_id
9833            p_application_id           => p_application_id
9834          , p_ae_header_id             => l_ae_header_id 
9835 , p_source_2 => p_source_2
9837          , x_accounting_coa_id        => l_adr_accounting_coa_id
9838          , x_value_type_code          => l_adr_value_type_code
9839          , p_side                     => 'NA'
9840    );
9841 
9842    xla_ae_lines_pkg.set_ccid(
9843     p_code_combination_id          => l_ccid
9844   , p_value_type_code              => l_adr_value_type_code
9845   , p_transaction_coa_id           => l_adr_transaction_coa_id
9846   , p_accounting_coa_id            => l_adr_accounting_coa_id
9847   , p_adr_code                     => 'CM_DIST_CCID'
9848   , p_adr_type_code                => 'S'
9849   , p_component_type               => l_component_type
9850   , p_component_code               => l_component_code
9851   , p_component_type_code          => l_component_type_code
9852   , p_component_appl_id            => l_component_appl_id
9853   , p_amb_context_code             => l_amb_context_code
9854   , p_side                         => 'NA'
9855   );
9856 
9857 
9858    --
9859    --
9860    END IF;
9861    --
9862    -- Bug 4922099
9863    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
9864           (NVL(l_enc_upg_option, 'N') = 'O')
9865         ) AND
9866         (l_bflow_method_code = 'PRIOR_ENTRY')
9867       )
9868    THEN
9869       IF
9870       --
9871       1 = 2
9872       --
9873       THEN
9874       xla_accounting_err_pkg.build_message
9875                                     (p_appli_s_name            => 'XLA'
9876                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
9877                                     ,p_token_1                 => 'LINE_NUMBER'
9878                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
9879                                     ,p_token_2                 => 'LINE_TYPE_NAME'
9880                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
9881                                                                              l_component_type
9882                                                                             ,l_component_code
9883                                                                             ,l_component_type_code
9884                                                                             ,l_component_appl_id
9885                                                                             ,l_amb_context_code
9886                                                                             ,l_entity_code
9887                                                                             ,l_event_class_code
9888                                                                            )
9889                                     ,p_token_3                 => 'OWNER'
9890                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
9891                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
9892                                                                           ,p_lookup_code    => l_component_type_code
9893                                                                          )
9894                                     ,p_token_4                 => 'PRODUCT_NAME'
9895                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
9896                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
9897                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
9898                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
9899                                     ,p_ae_header_id            =>  NULL
9900                                        );
9901 
9902         IF (C_LEVEL_ERROR>= g_log_level) THEN
9903                  trace
9904                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
9905                       ,p_level    => C_LEVEL_ERROR
9906                       ,p_module   => l_log_module);
9907         END IF;
9908       END IF;
9909    END IF;
9910    --
9911    --
9912    ------------------------------------------------------------------------------------------------
9913    -- 4219869 Business Flow
9914    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
9915    -- Prior Entry.  Currently, the following code is always generated.
9916    ------------------------------------------------------------------------------------------------
9917    XLA_AE_LINES_PKG.ValidateCurrentLine;
9918 
9919    ------------------------------------------------------------------------------------
9920    -- 4219869 Business Flow
9921    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
9922    ------------------------------------------------------------------------------------
9923    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
9924 
9925    ----------------------------------------------------------------------------------
9926    -- 4219869 Business Flow
9927    -- Update journal entry status -- Need to generate this within IF <condition>
9928    ----------------------------------------------------------------------------------
9929    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
9933 
9930          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
9931          ,p_balance_type_code => l_balance_type_code
9932          );
9934    -------------------------------------------------------------------------------------------
9935    -- 4262811 - Generate the Accrual Reversal lines
9936    -------------------------------------------------------------------------------------------
9937    BEGIN
9938       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
9939                               (g_array_event(p_event_id).array_value_num('header_index'));
9940       IF l_acc_rev_flag IS NULL THEN
9941          l_acc_rev_flag := 'N';
9942       END IF;
9943    EXCEPTION
9944       WHEN OTHERS THEN
9945          l_acc_rev_flag := 'N';
9946    END;
9947    --
9948    IF (l_acc_rev_flag = 'Y') THEN
9949 
9950        -- 4645092  ------------------------------------------------------------------------------
9951        -- To allow MPA report to determine if it should generate report process
9952        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
9953        ------------------------------------------------------------------------------------------
9954 
9955        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
9956        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
9957    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
9958    -- call ADRs
9959    -- Bug 4922099
9960    --
9961    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
9962         (NVL(l_actual_upg_option, 'N') = 'O') OR
9963         (NVL(l_enc_upg_option, 'N') = 'O')
9964       )
9965    THEN
9966    NULL;
9967    --
9968    --
9969    
9970   l_ccid := AcctDerRule_6(
9971            p_application_id           => p_application_id
9972          , p_ae_header_id             => l_ae_header_id 
9973 , p_source_2 => p_source_2
9974          , x_transaction_coa_id       => l_adr_transaction_coa_id
9975          , x_accounting_coa_id        => l_adr_accounting_coa_id
9976          , x_value_type_code          => l_adr_value_type_code
9977          , p_side                     => 'NA'
9978    );
9979 
9980    xla_ae_lines_pkg.set_ccid(
9981     p_code_combination_id          => l_ccid
9982   , p_value_type_code              => l_adr_value_type_code
9983   , p_transaction_coa_id           => l_adr_transaction_coa_id
9984   , p_accounting_coa_id            => l_adr_accounting_coa_id
9985   , p_adr_code                     => 'CM_DIST_CCID'
9986   , p_adr_type_code                => 'S'
9987   , p_component_type               => l_component_type
9988   , p_component_code               => l_component_code
9989   , p_component_type_code          => l_component_type_code
9990   , p_component_appl_id            => l_component_appl_id
9991   , p_amb_context_code             => l_amb_context_code
9992   , p_side                         => 'NA'
9993   );
9994 
9995 
9996    --
9997    --
9998    END IF;
9999 
10000        --
10001        -- Update the line information that should be overwritten
10002        --
10003        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
10004                                          p_header_num   => 1);
10005        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
10006 
10007        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
10008 
10009        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
10010           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
10011        END IF;
10012 
10013       --
10014       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
10015       --
10016       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
10017           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
10018       ELSE
10019           ---------------------------------------------------------------------------------------------------
10020           -- 4262811a Switch Sign
10021           ---------------------------------------------------------------------------------------------------
10022           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
10023           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
10024                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
10025           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
10026                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
10027           -- 5132302
10028           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
10029                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
10030 
10031       END IF;
10032 
10033       -- 4955764
10034       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
10035       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
10036 
10037 
10038       XLA_AE_LINES_PKG.ValidateCurrentLine;
10039       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
10040 
10044 
10041       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
10042                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
10043                ,p_balance_type_code => l_balance_type_code);
10045    END IF;
10046 
10047    -----------------------------------------------------------------------------------------
10048    -- 4262811 Multiperiod Accounting
10049    -----------------------------------------------------------------------------------------
10050      -- No MPA option is assigned.
10051 
10052 
10053 END IF;
10054 END IF;
10055 --
10056 
10057 --
10058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10059    trace
10060       (p_msg      => 'END of AcctLineType_42'
10061       ,p_level    => C_LEVEL_PROCEDURE
10062       ,p_module   => l_log_module);
10063 END IF;
10064 --
10065 EXCEPTION
10066   WHEN xla_exceptions_pkg.application_exception THEN
10067       RAISE;
10068   WHEN OTHERS THEN
10069        xla_exceptions_pkg.raise_message
10070            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_42');
10071 END AcctLineType_42;
10072 --
10073 
10074 ---------------------------------------
10075 --
10076 -- PRIVATE FUNCTION
10077 --         AcctLineType_43
10078 --
10079 ---------------------------------------
10080 PROCEDURE AcctLineType_43 (
10081   p_application_id        IN NUMBER
10082  ,p_event_id              IN NUMBER
10083  ,p_calculate_acctd_flag  IN VARCHAR2
10084  ,p_calculate_g_l_flag    IN VARCHAR2
10085  ,p_actual_flag           IN OUT VARCHAR2
10086  ,p_balance_type_code     OUT VARCHAR2
10087  ,p_gain_or_loss_ref      OUT VARCHAR2
10088  
10089 --Credit Memo Distribution GL Account
10090  , p_source_2            IN NUMBER
10091 --SLA Party Type
10092  , p_source_32            IN VARCHAR2
10093 --Credit Memo Distribution Identifier
10094  , p_source_42            IN NUMBER
10095 --Credit memo distributions type
10096  , p_source_43            IN VARCHAR2
10097 --Credit Memo Currency Code
10098  , p_source_44            IN VARCHAR2
10099 --Credit Memo Exchange Date
10100  , p_source_45            IN DATE
10101 --Credit Memo Exchange Rate
10102  , p_source_46            IN NUMBER
10103 --Credit Memo Exchange Rate Type
10104  , p_source_47            IN VARCHAR2
10105 --Gain Loss Reference
10106  , p_source_48            IN VARCHAR2
10107 --Credit Memo Accounting Amount
10108  , p_source_49            IN NUMBER
10109 --Credit Memo Bill To Customer Account Identifier
10110  , p_source_50            IN NUMBER
10111 --Credit Memo Bill To Customer Site Use Identifier
10112  , p_source_51            IN NUMBER
10113 --Credit Memo Tax Line Identifier
10114  , p_source_52            IN NUMBER
10115 --Credit Memo Distribution Account Class
10116  , p_source_53            IN VARCHAR2
10117 --Credit Memo Distribution Entered Amount
10118  , p_source_54            IN NUMBER
10119 )
10120 IS
10121 
10122 l_component_type              VARCHAR2(80);
10123 l_component_code              VARCHAR2(30);
10124 l_component_type_code         VARCHAR2(1);
10125 l_component_appl_id           INTEGER;
10126 l_amb_context_code            VARCHAR2(30);
10127 l_entity_code                 VARCHAR2(30);
10128 l_event_class_code            VARCHAR2(30);
10129 l_ae_header_id                NUMBER;
10130 l_event_type_code             VARCHAR2(30);
10131 l_line_definition_code        VARCHAR2(30);
10132 l_line_definition_owner_code  VARCHAR2(1);
10133 --
10134 -- adr variables
10135 l_segment                     VARCHAR2(30);
10136 l_ccid                        NUMBER;
10137 l_adr_transaction_coa_id      NUMBER;
10138 l_adr_accounting_coa_id       NUMBER;
10139 l_adr_flexfield_segment_code  VARCHAR2(30);
10140 l_adr_flex_value_set_id       NUMBER;
10141 l_adr_value_type_code         VARCHAR2(30);
10142 l_adr_value_combination_id    NUMBER;
10143 l_adr_value_segment_code      VARCHAR2(30);
10144 
10145 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
10146 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
10147 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
10148 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
10149 
10150 -- 4262811 Variables ------------------------------------------------------------------------------------------
10151 l_entered_amt_idx             NUMBER;
10152 l_accted_amt_idx              NUMBER;
10153 l_acc_rev_flag                VARCHAR2(1);
10154 l_accrual_line_num            NUMBER;
10155 l_tmp_amt                     NUMBER;
10156 l_acc_rev_natural_side_code   VARCHAR2(1);
10157 
10158 l_num_entries                 NUMBER;
10159 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
10160 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
10161 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
10162 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
10163 l_recog_line_1                NUMBER;
10164 l_recog_line_2                NUMBER;
10165 
10166 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
10167 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
10168 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
10169 
10170 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
10171 
10175 ---------------------------------------------------------------------------------------------------------------
10172 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
10173 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
10174 
10176 
10177 
10178 --
10179 -- bulk performance
10180 --
10181 l_balance_type_code           VARCHAR2(1);
10182 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
10183 l_log_module                  VARCHAR2(240);
10184 
10185 --
10186 -- Upgrade strategy
10187 --
10188 l_actual_upg_option           VARCHAR2(1);
10189 l_enc_upg_option           VARCHAR2(1);
10190 
10191 --
10192 BEGIN
10193 --
10194 IF g_log_enabled THEN
10195       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_43';
10196 END IF;
10197 --
10198 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10199 
10200       trace
10201          (p_msg      => 'BEGIN of AcctLineType_43'
10202          ,p_level    => C_LEVEL_PROCEDURE
10203          ,p_module   => l_log_module);
10204 
10205 END IF;
10206 --
10207 l_component_type             := 'AMB_JLT';
10208 l_component_code             := 'CM_DEFAULT_FREIGHT';
10209 l_component_type_code        := 'S';
10210 l_component_appl_id          :=  222;
10211 l_amb_context_code           := 'DEFAULT';
10212 l_entity_code                := 'TRANSACTIONS';
10213 l_event_class_code           := 'CREDIT_MEMO';
10214 l_event_type_code            := 'CREDIT_MEMO_ALL';
10215 l_line_definition_owner_code := 'S';
10216 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
10217 --
10218 l_balance_type_code          := 'A';
10219 l_segment                     := NULL;
10220 l_ccid                        := NULL;
10221 l_adr_transaction_coa_id      := NULL;
10222 l_adr_accounting_coa_id       := NULL;
10223 l_adr_flexfield_segment_code  := NULL;
10224 l_adr_flex_value_set_id       := NULL;
10225 l_adr_value_type_code         := NULL;
10226 l_adr_value_combination_id    := NULL;
10227 l_adr_value_segment_code      := NULL;
10228 
10229 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
10230 l_bflow_class_code           := '';    -- 4219869 Business Flow
10231 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
10232 l_budgetary_control_flag     := 'N';
10233 
10234 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
10235 l_bflow_applied_to_amt       := NULL; -- 5132302
10236 l_entered_amt_idx            := NULL;          -- 4262811
10237 l_accted_amt_idx             := NULL;          -- 4262811
10238 l_acc_rev_flag               := NULL;          -- 4262811
10239 l_accrual_line_num           := NULL;          -- 4262811
10240 l_tmp_amt                    := NULL;          -- 4262811
10241 --
10242  
10243 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
10244     l_balance_type_code <> 'B' THEN
10245 IF NVL(p_source_53,'
10246 ') =  'FREIGHT'
10247  THEN 
10248 
10249    --
10250    XLA_AE_LINES_PKG.SetNewLine;
10251 
10252    p_balance_type_code          := l_balance_type_code;
10253    -- set the flag so later we will know whether the gain loss line needs to be created
10254    
10255    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
10256      p_actual_flag :='A';
10257    END IF;
10258 
10259    --
10260    -- bulk performance
10261    --
10262    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
10263                                       p_header_num   => 0); -- 4262811
10264    --
10265    -- set accounting line options
10266    --
10267    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
10268            p_natural_side_code          => 'C'
10269          , p_gain_or_loss_flag          => 'N'
10270          , p_gl_transfer_mode_code      => 'S'
10271          , p_acct_entry_type_code       => 'A'
10272          , p_switch_side_flag           => 'Y'
10273          , p_merge_duplicate_code       => 'A'
10274          );
10275    --
10276    l_acc_rev_natural_side_code := 'D';  -- 4262811
10277    -- 
10278    --
10279    -- set accounting line type info
10280    --
10281    xla_ae_lines_pkg.SetAcctLineType
10282       (p_component_type             => l_component_type
10283       ,p_event_type_code            => l_event_type_code
10284       ,p_line_definition_owner_code => l_line_definition_owner_code
10285       ,p_line_definition_code       => l_line_definition_code
10286       ,p_accounting_line_code       => l_component_code
10287       ,p_accounting_line_type_code  => l_component_type_code
10288       ,p_accounting_line_appl_id    => l_component_appl_id
10289       ,p_amb_context_code           => l_amb_context_code
10290       ,p_entity_code                => l_entity_code
10291       ,p_event_class_code           => l_event_class_code);
10292    --
10293    -- set accounting class
10294    --
10295    xla_ae_lines_pkg.SetAcctClass(
10296            p_accounting_class_code  => 'FREIGHT'
10297          , p_ae_header_id           => l_ae_header_id
10298          );
10299 
10300    --
10301    -- set rounding class
10302    --
10303    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
10304                       'RECEIVABLE';
10305 
10306    --
10310    -- bulk performance
10307    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
10308    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
10309    --
10311    --
10312    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
10313 
10314    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
10315       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
10316 
10317    -- 4955764
10318    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
10319       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
10320 
10321    -- 4458381 Public Sector Enh
10322    
10323    --
10324    -- set accounting attributes for the line type
10325    --
10326    l_entered_amt_idx := 3;
10327    l_accted_amt_idx  := 9;
10328    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
10329    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
10330    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_42);
10331    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
10332    l_rec_acct_attrs.array_char_value(2)  := p_source_43;
10333    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
10334    l_rec_acct_attrs.array_num_value(3)  := p_source_54;
10335    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
10336    l_rec_acct_attrs.array_char_value(4)  := p_source_44;
10337    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
10338    l_rec_acct_attrs.array_date_value(5)  := p_source_45;
10339    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
10340    l_rec_acct_attrs.array_num_value(6)  := p_source_46;
10341    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
10342    l_rec_acct_attrs.array_char_value(7)  := p_source_47;
10343    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
10344    l_rec_acct_attrs.array_char_value(8)  := p_source_48;
10345    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
10346    l_rec_acct_attrs.array_num_value(9)  := p_source_49;
10347    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
10348    l_rec_acct_attrs.array_num_value(10)  := p_source_50;
10349    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
10350    l_rec_acct_attrs.array_num_value(11)  := p_source_51;
10351    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
10352    l_rec_acct_attrs.array_char_value(12)  := p_source_32;
10353    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
10354    l_rec_acct_attrs.array_num_value(13)  := p_source_52;
10355 
10356    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
10357    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
10358 
10359    ---------------------------------------------------------------------------------------------------------------
10360    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
10361    ---------------------------------------------------------------------------------------------------------------
10362    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
10363 
10364    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
10365    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
10366 
10367    IF xla_accounting_cache_pkg.GetValueChar
10368          (p_source_code         => 'LEDGER_CATEGORY_CODE'
10369          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
10370    AND l_bflow_method_code = 'PRIOR_ENTRY'
10371 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
10372    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
10373          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
10374        )
10375    THEN
10376          xla_ae_lines_pkg.BflowUpgEntry
10377            (p_business_method_code    => l_bflow_method_code
10378            ,p_business_class_code     => l_bflow_class_code
10379            ,p_balance_type            => l_balance_type_code);
10380    ELSE
10381       NULL;
10382 -- No business flow processing for business flow method of NONE.
10383    END IF;
10384 
10385    --
10386    -- call analytical criteria
10387    --
10388    
10389    --
10390    -- call description
10391    --
10392    -- No description or it is inherited.
10393    --
10394    -- call ADRs
10395    -- Bug 4922099
10396    --
10397    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
10398         (NVL(l_actual_upg_option, 'N') = 'O') OR
10399         (NVL(l_enc_upg_option, 'N') = 'O')
10400       )
10401    THEN
10402    NULL;
10403    --
10404    --
10405    
10406   l_ccid := AcctDerRule_6(
10407            p_application_id           => p_application_id
10408          , p_ae_header_id             => l_ae_header_id 
10409 , p_source_2 => p_source_2
10410          , x_transaction_coa_id       => l_adr_transaction_coa_id
10411          , x_accounting_coa_id        => l_adr_accounting_coa_id
10412          , x_value_type_code          => l_adr_value_type_code
10413          , p_side                     => 'NA'
10414    );
10415 
10416    xla_ae_lines_pkg.set_ccid(
10420   , p_accounting_coa_id            => l_adr_accounting_coa_id
10417     p_code_combination_id          => l_ccid
10418   , p_value_type_code              => l_adr_value_type_code
10419   , p_transaction_coa_id           => l_adr_transaction_coa_id
10421   , p_adr_code                     => 'CM_DIST_CCID'
10422   , p_adr_type_code                => 'S'
10423   , p_component_type               => l_component_type
10424   , p_component_code               => l_component_code
10425   , p_component_type_code          => l_component_type_code
10426   , p_component_appl_id            => l_component_appl_id
10427   , p_amb_context_code             => l_amb_context_code
10428   , p_side                         => 'NA'
10429   );
10430 
10431 
10432    --
10433    --
10434    END IF;
10435    --
10436    -- Bug 4922099
10437    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
10438           (NVL(l_enc_upg_option, 'N') = 'O')
10439         ) AND
10440         (l_bflow_method_code = 'PRIOR_ENTRY')
10441       )
10442    THEN
10443       IF
10444       --
10445       1 = 2
10446       --
10447       THEN
10448       xla_accounting_err_pkg.build_message
10449                                     (p_appli_s_name            => 'XLA'
10450                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
10451                                     ,p_token_1                 => 'LINE_NUMBER'
10452                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
10453                                     ,p_token_2                 => 'LINE_TYPE_NAME'
10454                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
10455                                                                              l_component_type
10456                                                                             ,l_component_code
10457                                                                             ,l_component_type_code
10458                                                                             ,l_component_appl_id
10459                                                                             ,l_amb_context_code
10460                                                                             ,l_entity_code
10461                                                                             ,l_event_class_code
10462                                                                            )
10463                                     ,p_token_3                 => 'OWNER'
10464                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
10465                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
10466                                                                           ,p_lookup_code    => l_component_type_code
10467                                                                          )
10468                                     ,p_token_4                 => 'PRODUCT_NAME'
10469                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
10470                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
10471                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
10472                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
10473                                     ,p_ae_header_id            =>  NULL
10474                                        );
10475 
10476         IF (C_LEVEL_ERROR>= g_log_level) THEN
10477                  trace
10478                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
10479                       ,p_level    => C_LEVEL_ERROR
10480                       ,p_module   => l_log_module);
10481         END IF;
10482       END IF;
10483    END IF;
10484    --
10485    --
10486    ------------------------------------------------------------------------------------------------
10487    -- 4219869 Business Flow
10488    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
10489    -- Prior Entry.  Currently, the following code is always generated.
10490    ------------------------------------------------------------------------------------------------
10491    XLA_AE_LINES_PKG.ValidateCurrentLine;
10492 
10493    ------------------------------------------------------------------------------------
10494    -- 4219869 Business Flow
10495    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
10496    ------------------------------------------------------------------------------------
10497    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
10498 
10499    ----------------------------------------------------------------------------------
10500    -- 4219869 Business Flow
10501    -- Update journal entry status -- Need to generate this within IF <condition>
10502    ----------------------------------------------------------------------------------
10503    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
10504          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
10505          ,p_balance_type_code => l_balance_type_code
10506          );
10507 
10508    -------------------------------------------------------------------------------------------
10509    -- 4262811 - Generate the Accrual Reversal lines
10513                               (g_array_event(p_event_id).array_value_num('header_index'));
10510    -------------------------------------------------------------------------------------------
10511    BEGIN
10512       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
10514       IF l_acc_rev_flag IS NULL THEN
10515          l_acc_rev_flag := 'N';
10516       END IF;
10517    EXCEPTION
10518       WHEN OTHERS THEN
10519          l_acc_rev_flag := 'N';
10520    END;
10521    --
10522    IF (l_acc_rev_flag = 'Y') THEN
10523 
10524        -- 4645092  ------------------------------------------------------------------------------
10525        -- To allow MPA report to determine if it should generate report process
10526        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
10527        ------------------------------------------------------------------------------------------
10528 
10529        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
10530        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
10531    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
10532    -- call ADRs
10533    -- Bug 4922099
10534    --
10535    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
10536         (NVL(l_actual_upg_option, 'N') = 'O') OR
10537         (NVL(l_enc_upg_option, 'N') = 'O')
10538       )
10539    THEN
10540    NULL;
10541    --
10542    --
10543    
10544   l_ccid := AcctDerRule_6(
10545            p_application_id           => p_application_id
10546          , p_ae_header_id             => l_ae_header_id 
10547 , p_source_2 => p_source_2
10548          , x_transaction_coa_id       => l_adr_transaction_coa_id
10549          , x_accounting_coa_id        => l_adr_accounting_coa_id
10550          , x_value_type_code          => l_adr_value_type_code
10551          , p_side                     => 'NA'
10552    );
10553 
10554    xla_ae_lines_pkg.set_ccid(
10555     p_code_combination_id          => l_ccid
10556   , p_value_type_code              => l_adr_value_type_code
10557   , p_transaction_coa_id           => l_adr_transaction_coa_id
10558   , p_accounting_coa_id            => l_adr_accounting_coa_id
10559   , p_adr_code                     => 'CM_DIST_CCID'
10560   , p_adr_type_code                => 'S'
10561   , p_component_type               => l_component_type
10562   , p_component_code               => l_component_code
10563   , p_component_type_code          => l_component_type_code
10564   , p_component_appl_id            => l_component_appl_id
10565   , p_amb_context_code             => l_amb_context_code
10566   , p_side                         => 'NA'
10567   );
10568 
10569 
10570    --
10571    --
10572    END IF;
10573 
10574        --
10575        -- Update the line information that should be overwritten
10576        --
10577        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
10578                                          p_header_num   => 1);
10579        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
10580 
10581        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
10582 
10583        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
10584           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
10585        END IF;
10586 
10587       --
10588       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
10589       --
10590       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
10591           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
10592       ELSE
10593           ---------------------------------------------------------------------------------------------------
10594           -- 4262811a Switch Sign
10595           ---------------------------------------------------------------------------------------------------
10596           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
10597           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
10598                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
10599           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
10600                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
10601           -- 5132302
10602           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
10603                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
10604 
10605       END IF;
10606 
10607       -- 4955764
10608       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
10609       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
10610 
10611 
10612       XLA_AE_LINES_PKG.ValidateCurrentLine;
10613       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
10614 
10615       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
10616                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
10617                ,p_balance_type_code => l_balance_type_code);
10618 
10619    END IF;
10620 
10624      -- No MPA option is assigned.
10621    -----------------------------------------------------------------------------------------
10622    -- 4262811 Multiperiod Accounting
10623    -----------------------------------------------------------------------------------------
10625 
10626 
10627 END IF;
10628 END IF;
10629 --
10630 
10631 --
10632 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10633    trace
10634       (p_msg      => 'END of AcctLineType_43'
10635       ,p_level    => C_LEVEL_PROCEDURE
10636       ,p_module   => l_log_module);
10637 END IF;
10638 --
10639 EXCEPTION
10640   WHEN xla_exceptions_pkg.application_exception THEN
10641       RAISE;
10642   WHEN OTHERS THEN
10643        xla_exceptions_pkg.raise_message
10644            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_43');
10645 END AcctLineType_43;
10646 --
10647 
10648 ---------------------------------------
10649 --
10650 -- PRIVATE FUNCTION
10651 --         AcctLineType_44
10652 --
10653 ---------------------------------------
10654 PROCEDURE AcctLineType_44 (
10655   p_application_id        IN NUMBER
10656  ,p_event_id              IN NUMBER
10657  ,p_calculate_acctd_flag  IN VARCHAR2
10658  ,p_calculate_g_l_flag    IN VARCHAR2
10659  ,p_actual_flag           IN OUT VARCHAR2
10660  ,p_balance_type_code     OUT VARCHAR2
10661  ,p_gain_or_loss_ref      OUT VARCHAR2
10662  
10663 --Credit Memo Distribution GL Account
10664  , p_source_2            IN NUMBER
10665 --SLA Party Type
10666  , p_source_32            IN VARCHAR2
10667 --Credit Memo Distribution Identifier
10668  , p_source_42            IN NUMBER
10669 --Credit memo distributions type
10670  , p_source_43            IN VARCHAR2
10671 --Credit Memo Currency Code
10672  , p_source_44            IN VARCHAR2
10673 --Credit Memo Exchange Date
10674  , p_source_45            IN DATE
10675 --Credit Memo Exchange Rate
10676  , p_source_46            IN NUMBER
10677 --Credit Memo Exchange Rate Type
10678  , p_source_47            IN VARCHAR2
10679 --Gain Loss Reference
10680  , p_source_48            IN VARCHAR2
10681 --Credit Memo Accounting Amount
10682  , p_source_49            IN NUMBER
10683 --Credit Memo Bill To Customer Account Identifier
10684  , p_source_50            IN NUMBER
10685 --Credit Memo Bill To Customer Site Use Identifier
10686  , p_source_51            IN NUMBER
10687 --Credit Memo Tax Line Identifier
10688  , p_source_52            IN NUMBER
10689 --Credit Memo Distribution Account Class
10690  , p_source_53            IN VARCHAR2
10691 --Credit Memo Distribution Entered Amount
10692  , p_source_54            IN NUMBER
10693 )
10694 IS
10695 
10696 l_component_type              VARCHAR2(80);
10697 l_component_code              VARCHAR2(30);
10698 l_component_type_code         VARCHAR2(1);
10699 l_component_appl_id           INTEGER;
10700 l_amb_context_code            VARCHAR2(30);
10701 l_entity_code                 VARCHAR2(30);
10702 l_event_class_code            VARCHAR2(30);
10703 l_ae_header_id                NUMBER;
10704 l_event_type_code             VARCHAR2(30);
10705 l_line_definition_code        VARCHAR2(30);
10706 l_line_definition_owner_code  VARCHAR2(1);
10707 --
10708 -- adr variables
10709 l_segment                     VARCHAR2(30);
10710 l_ccid                        NUMBER;
10711 l_adr_transaction_coa_id      NUMBER;
10712 l_adr_accounting_coa_id       NUMBER;
10713 l_adr_flexfield_segment_code  VARCHAR2(30);
10714 l_adr_flex_value_set_id       NUMBER;
10715 l_adr_value_type_code         VARCHAR2(30);
10716 l_adr_value_combination_id    NUMBER;
10717 l_adr_value_segment_code      VARCHAR2(30);
10718 
10719 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
10720 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
10721 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
10722 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
10723 
10724 -- 4262811 Variables ------------------------------------------------------------------------------------------
10725 l_entered_amt_idx             NUMBER;
10726 l_accted_amt_idx              NUMBER;
10727 l_acc_rev_flag                VARCHAR2(1);
10728 l_accrual_line_num            NUMBER;
10729 l_tmp_amt                     NUMBER;
10730 l_acc_rev_natural_side_code   VARCHAR2(1);
10731 
10732 l_num_entries                 NUMBER;
10733 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
10734 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
10735 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
10736 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
10737 l_recog_line_1                NUMBER;
10738 l_recog_line_2                NUMBER;
10739 
10740 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
10741 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
10742 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
10743 
10744 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
10745 
10746 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
10747 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
10748 
10752 --
10749 ---------------------------------------------------------------------------------------------------------------
10750 
10751 
10753 -- bulk performance
10754 --
10755 l_balance_type_code           VARCHAR2(1);
10756 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
10757 l_log_module                  VARCHAR2(240);
10758 
10759 --
10760 -- Upgrade strategy
10761 --
10762 l_actual_upg_option           VARCHAR2(1);
10763 l_enc_upg_option           VARCHAR2(1);
10764 
10765 --
10766 BEGIN
10767 --
10768 IF g_log_enabled THEN
10769       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_44';
10770 END IF;
10771 --
10772 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10773 
10774       trace
10775          (p_msg      => 'BEGIN of AcctLineType_44'
10776          ,p_level    => C_LEVEL_PROCEDURE
10777          ,p_module   => l_log_module);
10778 
10779 END IF;
10780 --
10781 l_component_type             := 'AMB_JLT';
10782 l_component_code             := 'CM_DEFAULT_REV';
10783 l_component_type_code        := 'S';
10784 l_component_appl_id          :=  222;
10785 l_amb_context_code           := 'DEFAULT';
10786 l_entity_code                := 'TRANSACTIONS';
10787 l_event_class_code           := 'CREDIT_MEMO';
10788 l_event_type_code            := 'CREDIT_MEMO_ALL';
10789 l_line_definition_owner_code := 'S';
10790 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
10791 --
10792 l_balance_type_code          := 'A';
10793 l_segment                     := NULL;
10794 l_ccid                        := NULL;
10795 l_adr_transaction_coa_id      := NULL;
10796 l_adr_accounting_coa_id       := NULL;
10797 l_adr_flexfield_segment_code  := NULL;
10798 l_adr_flex_value_set_id       := NULL;
10799 l_adr_value_type_code         := NULL;
10800 l_adr_value_combination_id    := NULL;
10801 l_adr_value_segment_code      := NULL;
10802 
10803 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
10804 l_bflow_class_code           := '';    -- 4219869 Business Flow
10805 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
10806 l_budgetary_control_flag     := 'N';
10807 
10808 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
10809 l_bflow_applied_to_amt       := NULL; -- 5132302
10810 l_entered_amt_idx            := NULL;          -- 4262811
10811 l_accted_amt_idx             := NULL;          -- 4262811
10812 l_acc_rev_flag               := NULL;          -- 4262811
10813 l_accrual_line_num           := NULL;          -- 4262811
10814 l_tmp_amt                    := NULL;          -- 4262811
10815 --
10816  
10817 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
10818     l_balance_type_code <> 'B' THEN
10819 IF NVL(p_source_53,'
10820 ') =  'REV'
10821  THEN 
10822 
10823    --
10824    XLA_AE_LINES_PKG.SetNewLine;
10825 
10826    p_balance_type_code          := l_balance_type_code;
10827    -- set the flag so later we will know whether the gain loss line needs to be created
10828    
10829    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
10830      p_actual_flag :='A';
10831    END IF;
10832 
10833    --
10834    -- bulk performance
10835    --
10836    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
10837                                       p_header_num   => 0); -- 4262811
10838    --
10839    -- set accounting line options
10840    --
10841    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
10842            p_natural_side_code          => 'C'
10843          , p_gain_or_loss_flag          => 'N'
10844          , p_gl_transfer_mode_code      => 'S'
10845          , p_acct_entry_type_code       => 'A'
10846          , p_switch_side_flag           => 'Y'
10847          , p_merge_duplicate_code       => 'A'
10848          );
10849    --
10850    l_acc_rev_natural_side_code := 'D';  -- 4262811
10851    -- 
10852    --
10853    -- set accounting line type info
10854    --
10855    xla_ae_lines_pkg.SetAcctLineType
10856       (p_component_type             => l_component_type
10857       ,p_event_type_code            => l_event_type_code
10858       ,p_line_definition_owner_code => l_line_definition_owner_code
10859       ,p_line_definition_code       => l_line_definition_code
10860       ,p_accounting_line_code       => l_component_code
10861       ,p_accounting_line_type_code  => l_component_type_code
10862       ,p_accounting_line_appl_id    => l_component_appl_id
10863       ,p_amb_context_code           => l_amb_context_code
10864       ,p_entity_code                => l_entity_code
10865       ,p_event_class_code           => l_event_class_code);
10866    --
10867    -- set accounting class
10868    --
10869    xla_ae_lines_pkg.SetAcctClass(
10870            p_accounting_class_code  => 'REVENUE'
10871          , p_ae_header_id           => l_ae_header_id
10872          );
10873 
10874    --
10875    -- set rounding class
10876    --
10877    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
10878                       'RECEIVABLE';
10879 
10880    --
10881    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
10882    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
10883    --
10884    -- bulk performance
10885    --
10889       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
10886    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
10887 
10888    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
10890 
10891    -- 4955764
10892    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
10893       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
10894 
10895    -- 4458381 Public Sector Enh
10896    
10897    --
10898    -- set accounting attributes for the line type
10899    --
10900    l_entered_amt_idx := 3;
10901    l_accted_amt_idx  := 9;
10902    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
10903    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
10904    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_42);
10905    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
10906    l_rec_acct_attrs.array_char_value(2)  := p_source_43;
10907    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
10908    l_rec_acct_attrs.array_num_value(3)  := p_source_54;
10909    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
10910    l_rec_acct_attrs.array_char_value(4)  := p_source_44;
10911    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
10912    l_rec_acct_attrs.array_date_value(5)  := p_source_45;
10913    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
10914    l_rec_acct_attrs.array_num_value(6)  := p_source_46;
10915    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
10916    l_rec_acct_attrs.array_char_value(7)  := p_source_47;
10917    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
10918    l_rec_acct_attrs.array_char_value(8)  := p_source_48;
10919    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
10920    l_rec_acct_attrs.array_num_value(9)  := p_source_49;
10921    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
10922    l_rec_acct_attrs.array_num_value(10)  := p_source_50;
10923    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
10924    l_rec_acct_attrs.array_num_value(11)  := p_source_51;
10925    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
10926    l_rec_acct_attrs.array_char_value(12)  := p_source_32;
10927    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
10928    l_rec_acct_attrs.array_num_value(13)  := p_source_52;
10929 
10930    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
10931    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
10932 
10933    ---------------------------------------------------------------------------------------------------------------
10934    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
10935    ---------------------------------------------------------------------------------------------------------------
10936    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
10937 
10938    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
10939    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
10940 
10941    IF xla_accounting_cache_pkg.GetValueChar
10942          (p_source_code         => 'LEDGER_CATEGORY_CODE'
10943          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
10944    AND l_bflow_method_code = 'PRIOR_ENTRY'
10945 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
10946    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
10947          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
10948        )
10949    THEN
10950          xla_ae_lines_pkg.BflowUpgEntry
10951            (p_business_method_code    => l_bflow_method_code
10952            ,p_business_class_code     => l_bflow_class_code
10953            ,p_balance_type            => l_balance_type_code);
10954    ELSE
10955       NULL;
10956 -- No business flow processing for business flow method of NONE.
10957    END IF;
10958 
10959    --
10960    -- call analytical criteria
10961    --
10962    
10963    --
10964    -- call description
10965    --
10966    -- No description or it is inherited.
10967    --
10968    -- call ADRs
10969    -- Bug 4922099
10970    --
10971    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
10972         (NVL(l_actual_upg_option, 'N') = 'O') OR
10973         (NVL(l_enc_upg_option, 'N') = 'O')
10974       )
10975    THEN
10976    NULL;
10977    --
10978    --
10979    
10980   l_ccid := AcctDerRule_6(
10981            p_application_id           => p_application_id
10982          , p_ae_header_id             => l_ae_header_id 
10983 , p_source_2 => p_source_2
10984          , x_transaction_coa_id       => l_adr_transaction_coa_id
10985          , x_accounting_coa_id        => l_adr_accounting_coa_id
10986          , x_value_type_code          => l_adr_value_type_code
10987          , p_side                     => 'NA'
10988    );
10989 
10990    xla_ae_lines_pkg.set_ccid(
10991     p_code_combination_id          => l_ccid
10992   , p_value_type_code              => l_adr_value_type_code
10993   , p_transaction_coa_id           => l_adr_transaction_coa_id
10997   , p_component_type               => l_component_type
10994   , p_accounting_coa_id            => l_adr_accounting_coa_id
10995   , p_adr_code                     => 'CM_DIST_CCID'
10996   , p_adr_type_code                => 'S'
10998   , p_component_code               => l_component_code
10999   , p_component_type_code          => l_component_type_code
11000   , p_component_appl_id            => l_component_appl_id
11001   , p_amb_context_code             => l_amb_context_code
11002   , p_side                         => 'NA'
11003   );
11004 
11005 
11006    --
11007    --
11008    END IF;
11009    --
11010    -- Bug 4922099
11011    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
11012           (NVL(l_enc_upg_option, 'N') = 'O')
11013         ) AND
11014         (l_bflow_method_code = 'PRIOR_ENTRY')
11015       )
11016    THEN
11017       IF
11018       --
11019       1 = 2
11020       --
11021       THEN
11022       xla_accounting_err_pkg.build_message
11023                                     (p_appli_s_name            => 'XLA'
11024                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
11025                                     ,p_token_1                 => 'LINE_NUMBER'
11026                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
11027                                     ,p_token_2                 => 'LINE_TYPE_NAME'
11028                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
11029                                                                              l_component_type
11030                                                                             ,l_component_code
11031                                                                             ,l_component_type_code
11032                                                                             ,l_component_appl_id
11033                                                                             ,l_amb_context_code
11034                                                                             ,l_entity_code
11035                                                                             ,l_event_class_code
11036                                                                            )
11037                                     ,p_token_3                 => 'OWNER'
11038                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
11039                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
11040                                                                           ,p_lookup_code    => l_component_type_code
11041                                                                          )
11042                                     ,p_token_4                 => 'PRODUCT_NAME'
11043                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
11044                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
11045                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
11046                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
11047                                     ,p_ae_header_id            =>  NULL
11048                                        );
11049 
11050         IF (C_LEVEL_ERROR>= g_log_level) THEN
11051                  trace
11052                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
11053                       ,p_level    => C_LEVEL_ERROR
11054                       ,p_module   => l_log_module);
11055         END IF;
11056       END IF;
11057    END IF;
11058    --
11059    --
11060    ------------------------------------------------------------------------------------------------
11061    -- 4219869 Business Flow
11062    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
11063    -- Prior Entry.  Currently, the following code is always generated.
11064    ------------------------------------------------------------------------------------------------
11065    XLA_AE_LINES_PKG.ValidateCurrentLine;
11066 
11067    ------------------------------------------------------------------------------------
11068    -- 4219869 Business Flow
11069    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
11070    ------------------------------------------------------------------------------------
11071    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
11072 
11073    ----------------------------------------------------------------------------------
11074    -- 4219869 Business Flow
11075    -- Update journal entry status -- Need to generate this within IF <condition>
11076    ----------------------------------------------------------------------------------
11077    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
11078          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
11079          ,p_balance_type_code => l_balance_type_code
11080          );
11081 
11082    -------------------------------------------------------------------------------------------
11083    -- 4262811 - Generate the Accrual Reversal lines
11084    -------------------------------------------------------------------------------------------
11085    BEGIN
11086       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
11087                               (g_array_event(p_event_id).array_value_num('header_index'));
11091    EXCEPTION
11088       IF l_acc_rev_flag IS NULL THEN
11089          l_acc_rev_flag := 'N';
11090       END IF;
11092       WHEN OTHERS THEN
11093          l_acc_rev_flag := 'N';
11094    END;
11095    --
11096    IF (l_acc_rev_flag = 'Y') THEN
11097 
11098        -- 4645092  ------------------------------------------------------------------------------
11099        -- To allow MPA report to determine if it should generate report process
11100        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
11101        ------------------------------------------------------------------------------------------
11102 
11103        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
11104        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
11105    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
11106    -- call ADRs
11107    -- Bug 4922099
11108    --
11109    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
11110         (NVL(l_actual_upg_option, 'N') = 'O') OR
11111         (NVL(l_enc_upg_option, 'N') = 'O')
11112       )
11113    THEN
11114    NULL;
11115    --
11116    --
11117    
11118   l_ccid := AcctDerRule_6(
11119            p_application_id           => p_application_id
11120          , p_ae_header_id             => l_ae_header_id 
11121 , p_source_2 => p_source_2
11122          , x_transaction_coa_id       => l_adr_transaction_coa_id
11123          , x_accounting_coa_id        => l_adr_accounting_coa_id
11124          , x_value_type_code          => l_adr_value_type_code
11125          , p_side                     => 'NA'
11126    );
11127 
11128    xla_ae_lines_pkg.set_ccid(
11129     p_code_combination_id          => l_ccid
11130   , p_value_type_code              => l_adr_value_type_code
11131   , p_transaction_coa_id           => l_adr_transaction_coa_id
11132   , p_accounting_coa_id            => l_adr_accounting_coa_id
11133   , p_adr_code                     => 'CM_DIST_CCID'
11134   , p_adr_type_code                => 'S'
11135   , p_component_type               => l_component_type
11136   , p_component_code               => l_component_code
11137   , p_component_type_code          => l_component_type_code
11138   , p_component_appl_id            => l_component_appl_id
11139   , p_amb_context_code             => l_amb_context_code
11140   , p_side                         => 'NA'
11141   );
11142 
11143 
11144    --
11145    --
11146    END IF;
11147 
11148        --
11149        -- Update the line information that should be overwritten
11150        --
11151        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
11152                                          p_header_num   => 1);
11153        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
11154 
11155        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
11156 
11157        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
11158           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
11159        END IF;
11160 
11161       --
11162       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
11163       --
11164       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
11165           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
11166       ELSE
11167           ---------------------------------------------------------------------------------------------------
11168           -- 4262811a Switch Sign
11169           ---------------------------------------------------------------------------------------------------
11170           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
11171           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
11172                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11173           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
11174                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11175           -- 5132302
11176           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
11177                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11178 
11179       END IF;
11180 
11181       -- 4955764
11182       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
11183       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
11184 
11185 
11186       XLA_AE_LINES_PKG.ValidateCurrentLine;
11187       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
11188 
11189       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
11190                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
11191                ,p_balance_type_code => l_balance_type_code);
11192 
11193    END IF;
11194 
11195    -----------------------------------------------------------------------------------------
11196    -- 4262811 Multiperiod Accounting
11197    -----------------------------------------------------------------------------------------
11198      -- No MPA option is assigned.
11199 
11200 
11201 END IF;
11202 END IF;
11203 --
11204 
11208       (p_msg      => 'END of AcctLineType_44'
11205 --
11206 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11207    trace
11209       ,p_level    => C_LEVEL_PROCEDURE
11210       ,p_module   => l_log_module);
11211 END IF;
11212 --
11213 EXCEPTION
11214   WHEN xla_exceptions_pkg.application_exception THEN
11215       RAISE;
11216   WHEN OTHERS THEN
11217        xla_exceptions_pkg.raise_message
11218            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_44');
11219 END AcctLineType_44;
11220 --
11221 
11222 ---------------------------------------
11223 --
11224 -- PRIVATE FUNCTION
11225 --         AcctLineType_45
11226 --
11227 ---------------------------------------
11228 PROCEDURE AcctLineType_45 (
11229   p_application_id        IN NUMBER
11230  ,p_event_id              IN NUMBER
11231  ,p_calculate_acctd_flag  IN VARCHAR2
11232  ,p_calculate_g_l_flag    IN VARCHAR2
11233  ,p_actual_flag           IN OUT VARCHAR2
11234  ,p_balance_type_code     OUT VARCHAR2
11235  ,p_gain_or_loss_ref      OUT VARCHAR2
11236  
11237 --Credit Memo Distribution GL Account
11238  , p_source_2            IN NUMBER
11239 --SLA Party Type
11240  , p_source_32            IN VARCHAR2
11241 --Credit Memo Distribution Identifier
11242  , p_source_42            IN NUMBER
11243 --Credit memo distributions type
11244  , p_source_43            IN VARCHAR2
11245 --Credit Memo Currency Code
11246  , p_source_44            IN VARCHAR2
11247 --Credit Memo Exchange Date
11248  , p_source_45            IN DATE
11249 --Credit Memo Exchange Rate
11250  , p_source_46            IN NUMBER
11251 --Credit Memo Exchange Rate Type
11252  , p_source_47            IN VARCHAR2
11253 --Gain Loss Reference
11254  , p_source_48            IN VARCHAR2
11255 --Credit Memo Accounting Amount
11256  , p_source_49            IN NUMBER
11257 --Credit Memo Bill To Customer Account Identifier
11258  , p_source_50            IN NUMBER
11259 --Credit Memo Bill To Customer Site Use Identifier
11260  , p_source_51            IN NUMBER
11261 --Credit Memo Tax Line Identifier
11262  , p_source_52            IN NUMBER
11263 --Credit Memo Distribution Account Class
11264  , p_source_53            IN VARCHAR2
11265 --Credit Memo Distribution Entered Amount
11266  , p_source_54            IN NUMBER
11267 )
11268 IS
11269 
11270 l_component_type              VARCHAR2(80);
11271 l_component_code              VARCHAR2(30);
11272 l_component_type_code         VARCHAR2(1);
11273 l_component_appl_id           INTEGER;
11274 l_amb_context_code            VARCHAR2(30);
11275 l_entity_code                 VARCHAR2(30);
11276 l_event_class_code            VARCHAR2(30);
11277 l_ae_header_id                NUMBER;
11278 l_event_type_code             VARCHAR2(30);
11279 l_line_definition_code        VARCHAR2(30);
11280 l_line_definition_owner_code  VARCHAR2(1);
11281 --
11282 -- adr variables
11283 l_segment                     VARCHAR2(30);
11284 l_ccid                        NUMBER;
11285 l_adr_transaction_coa_id      NUMBER;
11286 l_adr_accounting_coa_id       NUMBER;
11287 l_adr_flexfield_segment_code  VARCHAR2(30);
11288 l_adr_flex_value_set_id       NUMBER;
11289 l_adr_value_type_code         VARCHAR2(30);
11290 l_adr_value_combination_id    NUMBER;
11291 l_adr_value_segment_code      VARCHAR2(30);
11292 
11293 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
11294 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
11295 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
11296 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
11297 
11298 -- 4262811 Variables ------------------------------------------------------------------------------------------
11299 l_entered_amt_idx             NUMBER;
11300 l_accted_amt_idx              NUMBER;
11301 l_acc_rev_flag                VARCHAR2(1);
11302 l_accrual_line_num            NUMBER;
11303 l_tmp_amt                     NUMBER;
11304 l_acc_rev_natural_side_code   VARCHAR2(1);
11305 
11306 l_num_entries                 NUMBER;
11307 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
11308 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
11309 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
11310 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
11311 l_recog_line_1                NUMBER;
11312 l_recog_line_2                NUMBER;
11313 
11314 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
11315 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
11316 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
11317 
11318 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
11319 
11320 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
11321 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
11322 
11323 ---------------------------------------------------------------------------------------------------------------
11324 
11325 
11326 --
11327 -- bulk performance
11328 --
11329 l_balance_type_code           VARCHAR2(1);
11330 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
11331 l_log_module                  VARCHAR2(240);
11332 
11333 --
11334 -- Upgrade strategy
11335 --
11339 --
11336 l_actual_upg_option           VARCHAR2(1);
11337 l_enc_upg_option           VARCHAR2(1);
11338 
11340 BEGIN
11341 --
11342 IF g_log_enabled THEN
11343       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_45';
11344 END IF;
11345 --
11346 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11347 
11348       trace
11349          (p_msg      => 'BEGIN of AcctLineType_45'
11350          ,p_level    => C_LEVEL_PROCEDURE
11351          ,p_module   => l_log_module);
11352 
11353 END IF;
11354 --
11355 l_component_type             := 'AMB_JLT';
11356 l_component_code             := 'CM_DEFAULT_TAX';
11357 l_component_type_code        := 'S';
11358 l_component_appl_id          :=  222;
11359 l_amb_context_code           := 'DEFAULT';
11360 l_entity_code                := 'TRANSACTIONS';
11361 l_event_class_code           := 'CREDIT_MEMO';
11362 l_event_type_code            := 'CREDIT_MEMO_ALL';
11363 l_line_definition_owner_code := 'S';
11364 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
11365 --
11366 l_balance_type_code          := 'A';
11367 l_segment                     := NULL;
11368 l_ccid                        := NULL;
11369 l_adr_transaction_coa_id      := NULL;
11370 l_adr_accounting_coa_id       := NULL;
11371 l_adr_flexfield_segment_code  := NULL;
11372 l_adr_flex_value_set_id       := NULL;
11373 l_adr_value_type_code         := NULL;
11374 l_adr_value_combination_id    := NULL;
11375 l_adr_value_segment_code      := NULL;
11376 
11377 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
11378 l_bflow_class_code           := '';    -- 4219869 Business Flow
11379 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
11380 l_budgetary_control_flag     := 'N';
11381 
11382 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
11383 l_bflow_applied_to_amt       := NULL; -- 5132302
11384 l_entered_amt_idx            := NULL;          -- 4262811
11385 l_accted_amt_idx             := NULL;          -- 4262811
11386 l_acc_rev_flag               := NULL;          -- 4262811
11387 l_accrual_line_num           := NULL;          -- 4262811
11388 l_tmp_amt                    := NULL;          -- 4262811
11389 --
11390  
11391 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
11392     l_balance_type_code <> 'B' THEN
11393 IF NVL(p_source_53,'
11394 ') =  'TAX'
11395  THEN 
11396 
11397    --
11398    XLA_AE_LINES_PKG.SetNewLine;
11399 
11400    p_balance_type_code          := l_balance_type_code;
11401    -- set the flag so later we will know whether the gain loss line needs to be created
11402    
11403    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
11404      p_actual_flag :='A';
11405    END IF;
11406 
11407    --
11408    -- bulk performance
11409    --
11410    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
11411                                       p_header_num   => 0); -- 4262811
11412    --
11413    -- set accounting line options
11414    --
11415    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
11416            p_natural_side_code          => 'C'
11417          , p_gain_or_loss_flag          => 'N'
11418          , p_gl_transfer_mode_code      => 'S'
11419          , p_acct_entry_type_code       => 'A'
11420          , p_switch_side_flag           => 'Y'
11421          , p_merge_duplicate_code       => 'A'
11422          );
11423    --
11424    l_acc_rev_natural_side_code := 'D';  -- 4262811
11425    -- 
11426    --
11427    -- set accounting line type info
11428    --
11429    xla_ae_lines_pkg.SetAcctLineType
11430       (p_component_type             => l_component_type
11431       ,p_event_type_code            => l_event_type_code
11432       ,p_line_definition_owner_code => l_line_definition_owner_code
11433       ,p_line_definition_code       => l_line_definition_code
11434       ,p_accounting_line_code       => l_component_code
11435       ,p_accounting_line_type_code  => l_component_type_code
11436       ,p_accounting_line_appl_id    => l_component_appl_id
11437       ,p_amb_context_code           => l_amb_context_code
11438       ,p_entity_code                => l_entity_code
11439       ,p_event_class_code           => l_event_class_code);
11440    --
11441    -- set accounting class
11442    --
11443    xla_ae_lines_pkg.SetAcctClass(
11444            p_accounting_class_code  => 'TAX'
11445          , p_ae_header_id           => l_ae_header_id
11446          );
11447 
11448    --
11449    -- set rounding class
11450    --
11451    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
11452                       'RECEIVABLE';
11453 
11454    --
11455    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
11456    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
11457    --
11458    -- bulk performance
11459    --
11460    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
11461 
11462    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
11463       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
11464 
11465    -- 4955764
11469    -- 4458381 Public Sector Enh
11466    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
11467       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
11468 
11470    
11471    --
11472    -- set accounting attributes for the line type
11473    --
11474    l_entered_amt_idx := 3;
11475    l_accted_amt_idx  := 9;
11476    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
11477    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
11478    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_42);
11479    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
11480    l_rec_acct_attrs.array_char_value(2)  := p_source_43;
11481    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
11482    l_rec_acct_attrs.array_num_value(3)  := p_source_54;
11483    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
11484    l_rec_acct_attrs.array_char_value(4)  := p_source_44;
11485    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
11486    l_rec_acct_attrs.array_date_value(5)  := p_source_45;
11487    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
11488    l_rec_acct_attrs.array_num_value(6)  := p_source_46;
11489    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
11490    l_rec_acct_attrs.array_char_value(7)  := p_source_47;
11491    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
11492    l_rec_acct_attrs.array_char_value(8)  := p_source_48;
11493    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
11494    l_rec_acct_attrs.array_num_value(9)  := p_source_49;
11495    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
11496    l_rec_acct_attrs.array_num_value(10)  := p_source_50;
11497    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
11498    l_rec_acct_attrs.array_num_value(11)  := p_source_51;
11499    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
11500    l_rec_acct_attrs.array_char_value(12)  := p_source_32;
11501    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
11502    l_rec_acct_attrs.array_num_value(13)  := p_source_52;
11503 
11504    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
11505    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
11506 
11507    ---------------------------------------------------------------------------------------------------------------
11508    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
11509    ---------------------------------------------------------------------------------------------------------------
11510    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
11511 
11512    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
11513    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
11514 
11515    IF xla_accounting_cache_pkg.GetValueChar
11516          (p_source_code         => 'LEDGER_CATEGORY_CODE'
11517          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
11518    AND l_bflow_method_code = 'PRIOR_ENTRY'
11519 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
11520    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
11521          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
11522        )
11523    THEN
11524          xla_ae_lines_pkg.BflowUpgEntry
11525            (p_business_method_code    => l_bflow_method_code
11526            ,p_business_class_code     => l_bflow_class_code
11527            ,p_balance_type            => l_balance_type_code);
11528    ELSE
11529       NULL;
11530 -- No business flow processing for business flow method of NONE.
11531    END IF;
11532 
11533    --
11534    -- call analytical criteria
11535    --
11536    
11537    --
11538    -- call description
11539    --
11540    -- No description or it is inherited.
11541    --
11542    -- call ADRs
11543    -- Bug 4922099
11544    --
11545    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
11546         (NVL(l_actual_upg_option, 'N') = 'O') OR
11547         (NVL(l_enc_upg_option, 'N') = 'O')
11548       )
11549    THEN
11550    NULL;
11551    --
11552    --
11553    
11554   l_ccid := AcctDerRule_6(
11555            p_application_id           => p_application_id
11556          , p_ae_header_id             => l_ae_header_id 
11557 , p_source_2 => p_source_2
11558          , x_transaction_coa_id       => l_adr_transaction_coa_id
11559          , x_accounting_coa_id        => l_adr_accounting_coa_id
11560          , x_value_type_code          => l_adr_value_type_code
11561          , p_side                     => 'NA'
11562    );
11563 
11564    xla_ae_lines_pkg.set_ccid(
11565     p_code_combination_id          => l_ccid
11566   , p_value_type_code              => l_adr_value_type_code
11567   , p_transaction_coa_id           => l_adr_transaction_coa_id
11568   , p_accounting_coa_id            => l_adr_accounting_coa_id
11569   , p_adr_code                     => 'CM_DIST_CCID'
11570   , p_adr_type_code                => 'S'
11571   , p_component_type               => l_component_type
11572   , p_component_code               => l_component_code
11576   , p_side                         => 'NA'
11573   , p_component_type_code          => l_component_type_code
11574   , p_component_appl_id            => l_component_appl_id
11575   , p_amb_context_code             => l_amb_context_code
11577   );
11578 
11579 
11580    --
11581    --
11582    END IF;
11583    --
11584    -- Bug 4922099
11585    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
11586           (NVL(l_enc_upg_option, 'N') = 'O')
11587         ) AND
11588         (l_bflow_method_code = 'PRIOR_ENTRY')
11589       )
11590    THEN
11591       IF
11592       --
11593       1 = 2
11594       --
11595       THEN
11596       xla_accounting_err_pkg.build_message
11597                                     (p_appli_s_name            => 'XLA'
11598                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
11599                                     ,p_token_1                 => 'LINE_NUMBER'
11600                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
11601                                     ,p_token_2                 => 'LINE_TYPE_NAME'
11602                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
11603                                                                              l_component_type
11604                                                                             ,l_component_code
11605                                                                             ,l_component_type_code
11606                                                                             ,l_component_appl_id
11607                                                                             ,l_amb_context_code
11608                                                                             ,l_entity_code
11609                                                                             ,l_event_class_code
11610                                                                            )
11611                                     ,p_token_3                 => 'OWNER'
11612                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
11613                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
11614                                                                           ,p_lookup_code    => l_component_type_code
11615                                                                          )
11616                                     ,p_token_4                 => 'PRODUCT_NAME'
11617                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
11618                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
11619                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
11620                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
11621                                     ,p_ae_header_id            =>  NULL
11622                                        );
11623 
11624         IF (C_LEVEL_ERROR>= g_log_level) THEN
11625                  trace
11626                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
11627                       ,p_level    => C_LEVEL_ERROR
11628                       ,p_module   => l_log_module);
11629         END IF;
11630       END IF;
11631    END IF;
11632    --
11633    --
11634    ------------------------------------------------------------------------------------------------
11635    -- 4219869 Business Flow
11636    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
11637    -- Prior Entry.  Currently, the following code is always generated.
11638    ------------------------------------------------------------------------------------------------
11639    XLA_AE_LINES_PKG.ValidateCurrentLine;
11640 
11641    ------------------------------------------------------------------------------------
11642    -- 4219869 Business Flow
11643    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
11644    ------------------------------------------------------------------------------------
11645    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
11646 
11647    ----------------------------------------------------------------------------------
11648    -- 4219869 Business Flow
11649    -- Update journal entry status -- Need to generate this within IF <condition>
11650    ----------------------------------------------------------------------------------
11651    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
11652          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
11653          ,p_balance_type_code => l_balance_type_code
11654          );
11655 
11656    -------------------------------------------------------------------------------------------
11657    -- 4262811 - Generate the Accrual Reversal lines
11658    -------------------------------------------------------------------------------------------
11659    BEGIN
11660       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
11661                               (g_array_event(p_event_id).array_value_num('header_index'));
11662       IF l_acc_rev_flag IS NULL THEN
11663          l_acc_rev_flag := 'N';
11664       END IF;
11665    EXCEPTION
11666       WHEN OTHERS THEN
11667          l_acc_rev_flag := 'N';
11668    END;
11669    --
11670    IF (l_acc_rev_flag = 'Y') THEN
11671 
11675        ------------------------------------------------------------------------------------------
11672        -- 4645092  ------------------------------------------------------------------------------
11673        -- To allow MPA report to determine if it should generate report process
11674        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
11676 
11677        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
11678        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
11679    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
11680    -- call ADRs
11681    -- Bug 4922099
11682    --
11683    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
11684         (NVL(l_actual_upg_option, 'N') = 'O') OR
11685         (NVL(l_enc_upg_option, 'N') = 'O')
11686       )
11687    THEN
11688    NULL;
11689    --
11690    --
11691    
11692   l_ccid := AcctDerRule_6(
11693            p_application_id           => p_application_id
11694          , p_ae_header_id             => l_ae_header_id 
11695 , p_source_2 => p_source_2
11696          , x_transaction_coa_id       => l_adr_transaction_coa_id
11697          , x_accounting_coa_id        => l_adr_accounting_coa_id
11698          , x_value_type_code          => l_adr_value_type_code
11699          , p_side                     => 'NA'
11700    );
11701 
11702    xla_ae_lines_pkg.set_ccid(
11703     p_code_combination_id          => l_ccid
11704   , p_value_type_code              => l_adr_value_type_code
11705   , p_transaction_coa_id           => l_adr_transaction_coa_id
11706   , p_accounting_coa_id            => l_adr_accounting_coa_id
11707   , p_adr_code                     => 'CM_DIST_CCID'
11708   , p_adr_type_code                => 'S'
11709   , p_component_type               => l_component_type
11710   , p_component_code               => l_component_code
11711   , p_component_type_code          => l_component_type_code
11712   , p_component_appl_id            => l_component_appl_id
11713   , p_amb_context_code             => l_amb_context_code
11714   , p_side                         => 'NA'
11715   );
11716 
11717 
11718    --
11719    --
11720    END IF;
11721 
11722        --
11723        -- Update the line information that should be overwritten
11724        --
11725        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
11726                                          p_header_num   => 1);
11727        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
11728 
11729        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
11730 
11731        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
11732           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
11733        END IF;
11734 
11735       --
11736       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
11737       --
11738       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
11739           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
11740       ELSE
11741           ---------------------------------------------------------------------------------------------------
11742           -- 4262811a Switch Sign
11743           ---------------------------------------------------------------------------------------------------
11744           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
11745           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
11746                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11747           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
11748                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11749           -- 5132302
11750           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
11751                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11752 
11753       END IF;
11754 
11755       -- 4955764
11756       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
11757       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
11758 
11759 
11760       XLA_AE_LINES_PKG.ValidateCurrentLine;
11761       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
11762 
11763       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
11764                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
11765                ,p_balance_type_code => l_balance_type_code);
11766 
11767    END IF;
11768 
11769    -----------------------------------------------------------------------------------------
11770    -- 4262811 Multiperiod Accounting
11771    -----------------------------------------------------------------------------------------
11772      -- No MPA option is assigned.
11773 
11774 
11775 END IF;
11776 END IF;
11777 --
11778 
11779 --
11780 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11781    trace
11782       (p_msg      => 'END of AcctLineType_45'
11783       ,p_level    => C_LEVEL_PROCEDURE
11784       ,p_module   => l_log_module);
11788   WHEN xla_exceptions_pkg.application_exception THEN
11785 END IF;
11786 --
11787 EXCEPTION
11789       RAISE;
11790   WHEN OTHERS THEN
11791        xla_exceptions_pkg.raise_message
11792            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_45');
11793 END AcctLineType_45;
11794 --
11795 
11796 ---------------------------------------
11797 --
11798 -- PRIVATE FUNCTION
11799 --         AcctLineType_46
11800 --
11801 ---------------------------------------
11802 PROCEDURE AcctLineType_46 (
11803   p_application_id        IN NUMBER
11804  ,p_event_id              IN NUMBER
11805  ,p_calculate_acctd_flag  IN VARCHAR2
11806  ,p_calculate_g_l_flag    IN VARCHAR2
11807  ,p_actual_flag           IN OUT VARCHAR2
11808  ,p_balance_type_code     OUT VARCHAR2
11809  ,p_gain_or_loss_ref      OUT VARCHAR2
11810  
11811 --System Gain Account
11812  , p_source_18            IN NUMBER
11813 --System Loss Account
11814  , p_source_19            IN NUMBER
11815 --SLA Party Type
11816  , p_source_32            IN VARCHAR2
11817 --Credit Memo Distribution Identifier
11818  , p_source_42            IN NUMBER
11819 --Credit memo distributions type
11820  , p_source_43            IN VARCHAR2
11821 --Gain Loss Reference
11822  , p_source_48            IN VARCHAR2
11823 --Credit Memo Accounting Amount
11824  , p_source_49            IN NUMBER
11825 --Credit Memo Bill To Customer Account Identifier
11826  , p_source_50            IN NUMBER
11827 --Credit Memo Bill To Customer Site Use Identifier
11828  , p_source_51            IN NUMBER
11829 --Credit Memo Tax Line Identifier
11830  , p_source_52            IN NUMBER
11831 )
11832 IS
11833 
11834 l_component_type              VARCHAR2(80);
11835 l_component_code              VARCHAR2(30);
11836 l_component_type_code         VARCHAR2(1);
11837 l_component_appl_id           INTEGER;
11838 l_amb_context_code            VARCHAR2(30);
11839 l_entity_code                 VARCHAR2(30);
11840 l_event_class_code            VARCHAR2(30);
11841 l_ae_header_id                NUMBER;
11842 l_event_type_code             VARCHAR2(30);
11843 l_line_definition_code        VARCHAR2(30);
11844 l_line_definition_owner_code  VARCHAR2(1);
11845 --
11846 -- adr variables
11847 l_segment                     VARCHAR2(30);
11848 l_ccid                        NUMBER;
11849 l_adr_transaction_coa_id      NUMBER;
11850 l_adr_accounting_coa_id       NUMBER;
11851 l_adr_flexfield_segment_code  VARCHAR2(30);
11852 l_adr_flex_value_set_id       NUMBER;
11853 l_adr_value_type_code         VARCHAR2(30);
11854 l_adr_value_combination_id    NUMBER;
11855 l_adr_value_segment_code      VARCHAR2(30);
11856 
11857 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
11858 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
11859 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
11860 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
11861 
11862 -- 4262811 Variables ------------------------------------------------------------------------------------------
11863 l_entered_amt_idx             NUMBER;
11864 l_accted_amt_idx              NUMBER;
11865 l_acc_rev_flag                VARCHAR2(1);
11866 l_accrual_line_num            NUMBER;
11867 l_tmp_amt                     NUMBER;
11868 l_acc_rev_natural_side_code   VARCHAR2(1);
11869 
11870 l_num_entries                 NUMBER;
11871 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
11872 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
11873 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
11874 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
11875 l_recog_line_1                NUMBER;
11876 l_recog_line_2                NUMBER;
11877 
11878 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
11879 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
11880 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
11881 
11882 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
11883 
11884 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
11885 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
11886 
11887 ---------------------------------------------------------------------------------------------------------------
11888 
11889 
11890 --
11891 -- bulk performance
11892 --
11893 l_balance_type_code           VARCHAR2(1);
11894 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
11895 l_log_module                  VARCHAR2(240);
11896 
11897 --
11898 -- Upgrade strategy
11899 --
11900 l_actual_upg_option           VARCHAR2(1);
11901 l_enc_upg_option           VARCHAR2(1);
11902 
11903 --
11904 BEGIN
11905 --
11906 IF g_log_enabled THEN
11907       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_46';
11908 END IF;
11909 --
11910 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11911 
11912       trace
11913          (p_msg      => 'BEGIN of AcctLineType_46'
11914          ,p_level    => C_LEVEL_PROCEDURE
11915          ,p_module   => l_log_module);
11916 
11917 END IF;
11918 --
11919 l_component_type             := 'AMB_JLT';
11920 l_component_code             := 'CM_EXCH_GAIN_LOSS';
11921 l_component_type_code        := 'S';
11925 l_event_class_code           := 'CREDIT_MEMO';
11922 l_component_appl_id          :=  222;
11923 l_amb_context_code           := 'DEFAULT';
11924 l_entity_code                := 'TRANSACTIONS';
11926 l_event_type_code            := 'CREDIT_MEMO_ALL';
11927 l_line_definition_owner_code := 'S';
11928 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
11929 --
11930 l_balance_type_code          := 'A';
11931 l_segment                     := NULL;
11932 l_ccid                        := NULL;
11933 l_adr_transaction_coa_id      := NULL;
11934 l_adr_accounting_coa_id       := NULL;
11935 l_adr_flexfield_segment_code  := NULL;
11936 l_adr_flex_value_set_id       := NULL;
11937 l_adr_value_type_code         := NULL;
11938 l_adr_value_combination_id    := NULL;
11939 l_adr_value_segment_code      := NULL;
11940 
11941 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
11942 l_bflow_class_code           := '';    -- 4219869 Business Flow
11943 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
11944 l_budgetary_control_flag     := 'N';
11945 
11946 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
11947 l_bflow_applied_to_amt       := NULL; -- 5132302
11948 l_entered_amt_idx            := NULL;          -- 4262811
11949 l_accted_amt_idx             := NULL;          -- 4262811
11950 l_acc_rev_flag               := NULL;          -- 4262811
11951 l_accrual_line_num           := NULL;          -- 4262811
11952 l_tmp_amt                    := NULL;          -- 4262811
11953 --
11954 IF NOT ((p_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
11955             (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')) THEN
11956                return;
11957   END IF;
11958   
11959 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
11960     l_balance_type_code <> 'B' THEN
11961 
11962    --
11963    XLA_AE_LINES_PKG.SetNewLine;
11964 
11965    p_balance_type_code          := l_balance_type_code;
11966    -- set the flag so later we will know whether the gain loss line needs to be created
11967    
11968    IF(l_balance_type_code = 'A' ) THEN
11969      p_actual_flag :='G';
11970    END IF;
11971 
11972    --
11973    -- bulk performance
11974    --
11975    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
11976                                       p_header_num   => 0); -- 4262811
11977    --
11978    -- set accounting line options
11979    --
11980    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
11981            p_natural_side_code          => 'G'
11982          , p_gain_or_loss_flag          => 'N'
11983          , p_gl_transfer_mode_code      => 'S'
11984          , p_acct_entry_type_code       => 'A'
11985          , p_switch_side_flag           => ''
11986          , p_merge_duplicate_code       => 'A'
11987          );
11988    --
11989    l_acc_rev_natural_side_code := 'C';  -- 4262811
11990    -- 
11991    --
11992    -- set accounting line type info
11993    --
11994    xla_ae_lines_pkg.SetAcctLineType
11995       (p_component_type             => l_component_type
11996       ,p_event_type_code            => l_event_type_code
11997       ,p_line_definition_owner_code => l_line_definition_owner_code
11998       ,p_line_definition_code       => l_line_definition_code
11999       ,p_accounting_line_code       => l_component_code
12000       ,p_accounting_line_type_code  => l_component_type_code
12001       ,p_accounting_line_appl_id    => l_component_appl_id
12002       ,p_amb_context_code           => l_amb_context_code
12003       ,p_entity_code                => l_entity_code
12004       ,p_event_class_code           => l_event_class_code);
12005    --
12006    -- set accounting class
12007    --
12008    xla_ae_lines_pkg.SetAcctClass(
12009            p_accounting_class_code  => 'EXCHANGE_GAIN_LOSS'
12010          , p_ae_header_id           => l_ae_header_id
12011          );
12012 
12013    --
12014    -- set rounding class
12015    --
12016    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
12017                       'EXCHANGE_GAIN_LOSS';
12018 
12019    --
12020    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
12021    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
12022    --
12023    -- bulk performance
12024    --
12025    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
12026 
12027    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
12028       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
12029 
12030    -- 4955764
12031    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
12032       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
12033 
12034    -- 4458381 Public Sector Enh
12035    
12036    --
12037    -- set accounting attributes for the line type
12038    --
12039    l_entered_amt_idx := NULL;
12040    l_accted_amt_idx  := 4;
12041    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
12045    l_rec_acct_attrs.array_char_value(2)  := p_source_43;
12042    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
12043    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_42);
12044    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
12046    l_rec_acct_attrs.array_acct_attr_code(3) := 'GAIN_LOSS_REFERENCE';
12047    l_rec_acct_attrs.array_char_value(3)  := p_source_48;
12048    l_rec_acct_attrs.array_acct_attr_code(4) := 'LEDGER_AMOUNT';
12049    l_rec_acct_attrs.array_num_value(4)  := p_source_49;
12050    l_rec_acct_attrs.array_acct_attr_code(5) := 'PARTY_ID';
12051    l_rec_acct_attrs.array_num_value(5)  := p_source_50;
12052    l_rec_acct_attrs.array_acct_attr_code(6) := 'PARTY_SITE_ID';
12053    l_rec_acct_attrs.array_num_value(6)  := p_source_51;
12054    l_rec_acct_attrs.array_acct_attr_code(7) := 'PARTY_TYPE';
12055    l_rec_acct_attrs.array_char_value(7)  := p_source_32;
12056    l_rec_acct_attrs.array_acct_attr_code(8) := 'TAX_LINE_REF_ID';
12057    l_rec_acct_attrs.array_num_value(8)  := p_source_52;
12058 
12059    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
12060    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
12061 
12062    ---------------------------------------------------------------------------------------------------------------
12063    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
12064    ---------------------------------------------------------------------------------------------------------------
12065    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
12066 
12067    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
12068    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
12069 
12070    IF xla_accounting_cache_pkg.GetValueChar
12071          (p_source_code         => 'LEDGER_CATEGORY_CODE'
12072          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
12073    AND l_bflow_method_code = 'PRIOR_ENTRY'
12074 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
12075    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
12076          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
12077        )
12078    THEN
12079          xla_ae_lines_pkg.BflowUpgEntry
12080            (p_business_method_code    => l_bflow_method_code
12081            ,p_business_class_code     => l_bflow_class_code
12082            ,p_balance_type            => l_balance_type_code);
12083    ELSE
12084       NULL;
12085 -- No business flow processing for business flow method of NONE.
12086    END IF;
12087 
12088    --
12089    -- call analytical criteria
12090    --
12091    
12092    --
12093    -- call description
12094    --
12095    -- No description or it is inherited.
12096    --
12097    -- call ADRs
12098    -- Bug 4922099
12099    --
12100    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
12101         (NVL(l_actual_upg_option, 'N') = 'O') OR
12102         (NVL(l_enc_upg_option, 'N') = 'O')
12103       )
12104    THEN
12105    NULL;
12106    --
12107    --
12108    
12109   l_ccid := AcctDerRule_30(
12110            p_application_id           => p_application_id
12111          , p_ae_header_id             => l_ae_header_id 
12112 , p_source_18 => p_source_18
12113          , x_transaction_coa_id       => l_adr_transaction_coa_id
12114          , x_accounting_coa_id        => l_adr_accounting_coa_id
12115          , x_value_type_code          => l_adr_value_type_code
12116          , p_side                     => 'CREDIT'
12117    );
12118 
12119    xla_ae_lines_pkg.set_ccid(
12120     p_code_combination_id          => l_ccid
12121   , p_value_type_code              => l_adr_value_type_code
12122   , p_transaction_coa_id           => l_adr_transaction_coa_id
12123   , p_accounting_coa_id            => l_adr_accounting_coa_id
12124   , p_adr_code                     => 'SYS_GAIN_CCID'
12125   , p_adr_type_code                => 'S'
12126   , p_component_type               => l_component_type
12127   , p_component_code               => l_component_code
12128   , p_component_type_code          => l_component_type_code
12129   , p_component_appl_id            => l_component_appl_id
12130   , p_amb_context_code             => l_amb_context_code
12131   , p_side                         => 'CREDIT'
12132   );
12133 
12134 
12135   l_ccid := AcctDerRule_31(
12136            p_application_id           => p_application_id
12137          , p_ae_header_id             => l_ae_header_id 
12138 , p_source_19 => p_source_19
12139          , x_transaction_coa_id       => l_adr_transaction_coa_id
12140          , x_accounting_coa_id        => l_adr_accounting_coa_id
12141          , x_value_type_code          => l_adr_value_type_code
12142          , p_side                     => 'DEBIT'
12143    );
12144 
12145    xla_ae_lines_pkg.set_ccid(
12146     p_code_combination_id          => l_ccid
12147   , p_value_type_code              => l_adr_value_type_code
12148   , p_transaction_coa_id           => l_adr_transaction_coa_id
12149   , p_accounting_coa_id            => l_adr_accounting_coa_id
12150   , p_adr_code                     => 'SYS_LOSS_CCID'
12151   , p_adr_type_code                => 'S'
12152   , p_component_type               => l_component_type
12156   , p_amb_context_code             => l_amb_context_code
12153   , p_component_code               => l_component_code
12154   , p_component_type_code          => l_component_type_code
12155   , p_component_appl_id            => l_component_appl_id
12157   , p_side                         => 'DEBIT'
12158   );
12159 
12160 
12161    --
12162    --
12163    END IF;
12164    --
12165    -- Bug 4922099
12166    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
12167           (NVL(l_enc_upg_option, 'N') = 'O')
12168         ) AND
12169         (l_bflow_method_code = 'PRIOR_ENTRY')
12170       )
12171    THEN
12172       IF
12173       --
12174       1 = 2
12175       --
12176       THEN
12177       xla_accounting_err_pkg.build_message
12178                                     (p_appli_s_name            => 'XLA'
12179                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
12180                                     ,p_token_1                 => 'LINE_NUMBER'
12181                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
12182                                     ,p_token_2                 => 'LINE_TYPE_NAME'
12183                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
12184                                                                              l_component_type
12185                                                                             ,l_component_code
12186                                                                             ,l_component_type_code
12187                                                                             ,l_component_appl_id
12188                                                                             ,l_amb_context_code
12189                                                                             ,l_entity_code
12190                                                                             ,l_event_class_code
12191                                                                            )
12192                                     ,p_token_3                 => 'OWNER'
12193                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
12194                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
12195                                                                           ,p_lookup_code    => l_component_type_code
12196                                                                          )
12197                                     ,p_token_4                 => 'PRODUCT_NAME'
12198                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
12199                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
12200                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
12201                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
12202                                     ,p_ae_header_id            =>  NULL
12203                                        );
12204 
12205         IF (C_LEVEL_ERROR>= g_log_level) THEN
12206                  trace
12207                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
12208                       ,p_level    => C_LEVEL_ERROR
12209                       ,p_module   => l_log_module);
12210         END IF;
12211       END IF;
12212    END IF;
12213    --
12214    --
12215    ------------------------------------------------------------------------------------------------
12216    -- 4219869 Business Flow
12217    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
12218    -- Prior Entry.  Currently, the following code is always generated.
12219    ------------------------------------------------------------------------------------------------
12220    XLA_AE_LINES_PKG.ValidateCurrentLine;
12221 
12222    ------------------------------------------------------------------------------------
12223    -- 4219869 Business Flow
12224    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
12225    ------------------------------------------------------------------------------------
12226    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
12227 
12228    ----------------------------------------------------------------------------------
12229    -- 4219869 Business Flow
12230    -- Update journal entry status -- Need to generate this within IF <condition>
12231    ----------------------------------------------------------------------------------
12232    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
12233          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
12234          ,p_balance_type_code => l_balance_type_code
12235          );
12236 
12237    -------------------------------------------------------------------------------------------
12238    -- 4262811 - Generate the Accrual Reversal lines
12239    -------------------------------------------------------------------------------------------
12240    BEGIN
12241       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
12242                               (g_array_event(p_event_id).array_value_num('header_index'));
12243       IF l_acc_rev_flag IS NULL THEN
12244          l_acc_rev_flag := 'N';
12245       END IF;
12246    EXCEPTION
12247       WHEN OTHERS THEN
12248          l_acc_rev_flag := 'N';
12249    END;
12250    --
12251    IF (l_acc_rev_flag = 'Y') THEN
12252 
12253        -- 4645092  ------------------------------------------------------------------------------
12257 
12254        -- To allow MPA report to determine if it should generate report process
12255        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
12256        ------------------------------------------------------------------------------------------
12258        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
12259        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
12260    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
12261    -- call ADRs
12262    -- Bug 4922099
12263    --
12264    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
12265         (NVL(l_actual_upg_option, 'N') = 'O') OR
12266         (NVL(l_enc_upg_option, 'N') = 'O')
12267       )
12268    THEN
12269    NULL;
12270    --
12271    --
12272    
12273   l_ccid := AcctDerRule_30(
12274            p_application_id           => p_application_id
12275          , p_ae_header_id             => l_ae_header_id 
12276 , p_source_18 => p_source_18
12277          , x_transaction_coa_id       => l_adr_transaction_coa_id
12278          , x_accounting_coa_id        => l_adr_accounting_coa_id
12279          , x_value_type_code          => l_adr_value_type_code
12280          , p_side                     => 'CREDIT'
12281    );
12282 
12283    xla_ae_lines_pkg.set_ccid(
12284     p_code_combination_id          => l_ccid
12285   , p_value_type_code              => l_adr_value_type_code
12286   , p_transaction_coa_id           => l_adr_transaction_coa_id
12287   , p_accounting_coa_id            => l_adr_accounting_coa_id
12288   , p_adr_code                     => 'SYS_GAIN_CCID'
12289   , p_adr_type_code                => 'S'
12290   , p_component_type               => l_component_type
12291   , p_component_code               => l_component_code
12292   , p_component_type_code          => l_component_type_code
12293   , p_component_appl_id            => l_component_appl_id
12294   , p_amb_context_code             => l_amb_context_code
12295   , p_side                         => 'CREDIT'
12296   );
12297 
12298 
12299   l_ccid := AcctDerRule_31(
12300            p_application_id           => p_application_id
12301          , p_ae_header_id             => l_ae_header_id 
12302 , p_source_19 => p_source_19
12303          , x_transaction_coa_id       => l_adr_transaction_coa_id
12304          , x_accounting_coa_id        => l_adr_accounting_coa_id
12305          , x_value_type_code          => l_adr_value_type_code
12306          , p_side                     => 'DEBIT'
12307    );
12308 
12309    xla_ae_lines_pkg.set_ccid(
12310     p_code_combination_id          => l_ccid
12311   , p_value_type_code              => l_adr_value_type_code
12312   , p_transaction_coa_id           => l_adr_transaction_coa_id
12313   , p_accounting_coa_id            => l_adr_accounting_coa_id
12314   , p_adr_code                     => 'SYS_LOSS_CCID'
12315   , p_adr_type_code                => 'S'
12316   , p_component_type               => l_component_type
12317   , p_component_code               => l_component_code
12318   , p_component_type_code          => l_component_type_code
12319   , p_component_appl_id            => l_component_appl_id
12320   , p_amb_context_code             => l_amb_context_code
12321   , p_side                         => 'DEBIT'
12322   );
12323 
12324 
12325    --
12326    --
12327    END IF;
12328 
12329        --
12330        -- Update the line information that should be overwritten
12331        --
12332        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
12333                                          p_header_num   => 1);
12334        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
12335 
12336        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
12337 
12338        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
12339           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
12340        END IF;
12341 
12342       --
12343       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
12344       --
12345       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
12346           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
12347       ELSE
12348           ---------------------------------------------------------------------------------------------------
12349           -- 4262811a Switch Sign
12350           ---------------------------------------------------------------------------------------------------
12351           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
12352           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
12353                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12354           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
12355                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12356           -- 5132302
12357           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
12358                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12359 
12360       END IF;
12361 
12362       -- 4955764
12366 
12363       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
12364       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
12365 
12367       XLA_AE_LINES_PKG.ValidateCurrentLine;
12368       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
12369 
12370       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
12371                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
12372                ,p_balance_type_code => l_balance_type_code);
12373 
12374    END IF;
12375 
12376    -----------------------------------------------------------------------------------------
12377    -- 4262811 Multiperiod Accounting
12378    -----------------------------------------------------------------------------------------
12379      -- No MPA option is assigned.
12380 
12381 
12382 END IF;
12383 --
12384 
12385 --
12386 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12387    trace
12388       (p_msg      => 'END of AcctLineType_46'
12389       ,p_level    => C_LEVEL_PROCEDURE
12390       ,p_module   => l_log_module);
12391 END IF;
12392 --
12393 EXCEPTION
12394   WHEN xla_exceptions_pkg.application_exception THEN
12395       RAISE;
12396   WHEN OTHERS THEN
12397        xla_exceptions_pkg.raise_message
12398            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_46');
12399 END AcctLineType_46;
12400 --
12401 
12402 ---------------------------------------
12403 --
12404 -- PRIVATE FUNCTION
12405 --         AcctLineType_47
12406 --
12407 ---------------------------------------
12408 PROCEDURE AcctLineType_47 (
12409   p_application_id        IN NUMBER
12410  ,p_event_id              IN NUMBER
12411  ,p_calculate_acctd_flag  IN VARCHAR2
12412  ,p_calculate_g_l_flag    IN VARCHAR2
12413  ,p_actual_flag           IN OUT VARCHAR2
12414  ,p_balance_type_code     OUT VARCHAR2
12415  ,p_gain_or_loss_ref      OUT VARCHAR2
12416  
12417 --Credit Memo Distribution GL Account
12418  , p_source_2            IN NUMBER
12419 --SLA Party Type
12420  , p_source_32            IN VARCHAR2
12421 --Credit Memo Distribution Identifier
12422  , p_source_42            IN NUMBER
12423 --Credit memo distributions type
12424  , p_source_43            IN VARCHAR2
12425 --Credit Memo Currency Code
12426  , p_source_44            IN VARCHAR2
12427 --Credit Memo Exchange Date
12428  , p_source_45            IN DATE
12429 --Credit Memo Exchange Rate
12430  , p_source_46            IN NUMBER
12431 --Credit Memo Exchange Rate Type
12432  , p_source_47            IN VARCHAR2
12433 --Gain Loss Reference
12434  , p_source_48            IN VARCHAR2
12435 --Credit Memo Accounting Amount
12436  , p_source_49            IN NUMBER
12437 --Credit Memo Bill To Customer Account Identifier
12438  , p_source_50            IN NUMBER
12439 --Credit Memo Bill To Customer Site Use Identifier
12440  , p_source_51            IN NUMBER
12441 --Credit Memo Tax Line Identifier
12442  , p_source_52            IN NUMBER
12443 --Credit Memo Distribution Account Class
12444  , p_source_53            IN VARCHAR2
12445 --Credit Memo Distribution Entered Amount
12446  , p_source_54            IN NUMBER
12447 )
12448 IS
12449 
12450 l_component_type              VARCHAR2(80);
12451 l_component_code              VARCHAR2(30);
12452 l_component_type_code         VARCHAR2(1);
12453 l_component_appl_id           INTEGER;
12454 l_amb_context_code            VARCHAR2(30);
12455 l_entity_code                 VARCHAR2(30);
12456 l_event_class_code            VARCHAR2(30);
12457 l_ae_header_id                NUMBER;
12458 l_event_type_code             VARCHAR2(30);
12459 l_line_definition_code        VARCHAR2(30);
12460 l_line_definition_owner_code  VARCHAR2(1);
12461 --
12462 -- adr variables
12463 l_segment                     VARCHAR2(30);
12464 l_ccid                        NUMBER;
12465 l_adr_transaction_coa_id      NUMBER;
12466 l_adr_accounting_coa_id       NUMBER;
12467 l_adr_flexfield_segment_code  VARCHAR2(30);
12468 l_adr_flex_value_set_id       NUMBER;
12469 l_adr_value_type_code         VARCHAR2(30);
12470 l_adr_value_combination_id    NUMBER;
12471 l_adr_value_segment_code      VARCHAR2(30);
12472 
12473 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
12474 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
12475 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
12476 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
12477 
12478 -- 4262811 Variables ------------------------------------------------------------------------------------------
12479 l_entered_amt_idx             NUMBER;
12480 l_accted_amt_idx              NUMBER;
12481 l_acc_rev_flag                VARCHAR2(1);
12482 l_accrual_line_num            NUMBER;
12483 l_tmp_amt                     NUMBER;
12484 l_acc_rev_natural_side_code   VARCHAR2(1);
12485 
12486 l_num_entries                 NUMBER;
12487 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
12488 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
12489 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
12490 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
12491 l_recog_line_1                NUMBER;
12492 l_recog_line_2                NUMBER;
12493 
12497 
12494 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
12495 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
12496 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
12498 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
12499 
12500 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
12501 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
12502 
12503 ---------------------------------------------------------------------------------------------------------------
12504 
12505 
12506 --
12507 -- bulk performance
12508 --
12509 l_balance_type_code           VARCHAR2(1);
12510 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
12511 l_log_module                  VARCHAR2(240);
12512 
12513 --
12514 -- Upgrade strategy
12515 --
12516 l_actual_upg_option           VARCHAR2(1);
12517 l_enc_upg_option           VARCHAR2(1);
12518 
12519 --
12520 BEGIN
12521 --
12522 IF g_log_enabled THEN
12523       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_47';
12524 END IF;
12525 --
12526 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12527 
12528       trace
12529          (p_msg      => 'BEGIN of AcctLineType_47'
12530          ,p_level    => C_LEVEL_PROCEDURE
12531          ,p_module   => l_log_module);
12532 
12533 END IF;
12534 --
12535 l_component_type             := 'AMB_JLT';
12536 l_component_code             := 'CM_ROUND';
12537 l_component_type_code        := 'S';
12538 l_component_appl_id          :=  222;
12539 l_amb_context_code           := 'DEFAULT';
12540 l_entity_code                := 'TRANSACTIONS';
12541 l_event_class_code           := 'CREDIT_MEMO';
12542 l_event_type_code            := 'CREDIT_MEMO_ALL';
12543 l_line_definition_owner_code := 'S';
12544 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
12545 --
12546 l_balance_type_code          := 'A';
12547 l_segment                     := NULL;
12548 l_ccid                        := NULL;
12549 l_adr_transaction_coa_id      := NULL;
12550 l_adr_accounting_coa_id       := NULL;
12551 l_adr_flexfield_segment_code  := NULL;
12552 l_adr_flex_value_set_id       := NULL;
12553 l_adr_value_type_code         := NULL;
12554 l_adr_value_combination_id    := NULL;
12555 l_adr_value_segment_code      := NULL;
12556 
12557 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
12558 l_bflow_class_code           := '';    -- 4219869 Business Flow
12559 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
12560 l_budgetary_control_flag     := 'N';
12561 
12562 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
12563 l_bflow_applied_to_amt       := NULL; -- 5132302
12564 l_entered_amt_idx            := NULL;          -- 4262811
12565 l_accted_amt_idx             := NULL;          -- 4262811
12566 l_acc_rev_flag               := NULL;          -- 4262811
12567 l_accrual_line_num           := NULL;          -- 4262811
12568 l_tmp_amt                    := NULL;          -- 4262811
12569 --
12570  
12571 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
12572     l_balance_type_code <> 'B' THEN
12573 IF NVL(p_source_53,'
12574 ') =  'ROUND'
12575  THEN 
12576 
12577    --
12578    XLA_AE_LINES_PKG.SetNewLine;
12579 
12580    p_balance_type_code          := l_balance_type_code;
12581    -- set the flag so later we will know whether the gain loss line needs to be created
12582    
12583    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
12584      p_actual_flag :='A';
12585    END IF;
12586 
12587    --
12588    -- bulk performance
12589    --
12590    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
12591                                       p_header_num   => 0); -- 4262811
12592    --
12593    -- set accounting line options
12594    --
12595    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
12596            p_natural_side_code          => 'C'
12597          , p_gain_or_loss_flag          => 'N'
12598          , p_gl_transfer_mode_code      => 'S'
12599          , p_acct_entry_type_code       => 'A'
12600          , p_switch_side_flag           => 'Y'
12601          , p_merge_duplicate_code       => 'A'
12602          );
12603    --
12604    l_acc_rev_natural_side_code := 'D';  -- 4262811
12605    -- 
12606    --
12607    -- set accounting line type info
12608    --
12609    xla_ae_lines_pkg.SetAcctLineType
12610       (p_component_type             => l_component_type
12611       ,p_event_type_code            => l_event_type_code
12612       ,p_line_definition_owner_code => l_line_definition_owner_code
12613       ,p_line_definition_code       => l_line_definition_code
12614       ,p_accounting_line_code       => l_component_code
12615       ,p_accounting_line_type_code  => l_component_type_code
12616       ,p_accounting_line_appl_id    => l_component_appl_id
12617       ,p_amb_context_code           => l_amb_context_code
12618       ,p_entity_code                => l_entity_code
12619       ,p_event_class_code           => l_event_class_code);
12620    --
12621    -- set accounting class
12622    --
12626          );
12623    xla_ae_lines_pkg.SetAcctClass(
12624            p_accounting_class_code  => 'ROUNDING'
12625          , p_ae_header_id           => l_ae_header_id
12627 
12628    --
12629    -- set rounding class
12630    --
12631    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
12632                       'RECEIVABLE';
12633 
12634    --
12635    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
12636    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
12637    --
12638    -- bulk performance
12639    --
12640    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
12641 
12642    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
12643       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
12644 
12645    -- 4955764
12646    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
12647       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
12648 
12649    -- 4458381 Public Sector Enh
12650    
12651    --
12652    -- set accounting attributes for the line type
12653    --
12654    l_entered_amt_idx := 3;
12655    l_accted_amt_idx  := 9;
12656    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
12657    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
12658    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_42);
12659    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
12660    l_rec_acct_attrs.array_char_value(2)  := p_source_43;
12661    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
12662    l_rec_acct_attrs.array_num_value(3)  := p_source_54;
12663    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
12664    l_rec_acct_attrs.array_char_value(4)  := p_source_44;
12665    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
12666    l_rec_acct_attrs.array_date_value(5)  := p_source_45;
12667    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
12668    l_rec_acct_attrs.array_num_value(6)  := p_source_46;
12669    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
12670    l_rec_acct_attrs.array_char_value(7)  := p_source_47;
12671    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
12672    l_rec_acct_attrs.array_char_value(8)  := p_source_48;
12673    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
12674    l_rec_acct_attrs.array_num_value(9)  := p_source_49;
12675    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
12676    l_rec_acct_attrs.array_num_value(10)  := p_source_50;
12677    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
12678    l_rec_acct_attrs.array_num_value(11)  := p_source_51;
12679    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
12680    l_rec_acct_attrs.array_char_value(12)  := p_source_32;
12681    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
12682    l_rec_acct_attrs.array_num_value(13)  := p_source_52;
12683 
12684    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
12685    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
12686 
12687    ---------------------------------------------------------------------------------------------------------------
12688    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
12689    ---------------------------------------------------------------------------------------------------------------
12690    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
12691 
12692    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
12693    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
12694 
12695    IF xla_accounting_cache_pkg.GetValueChar
12696          (p_source_code         => 'LEDGER_CATEGORY_CODE'
12697          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
12698    AND l_bflow_method_code = 'PRIOR_ENTRY'
12699 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
12700    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
12701          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
12702        )
12703    THEN
12704          xla_ae_lines_pkg.BflowUpgEntry
12705            (p_business_method_code    => l_bflow_method_code
12706            ,p_business_class_code     => l_bflow_class_code
12707            ,p_balance_type            => l_balance_type_code);
12708    ELSE
12709       NULL;
12710 -- No business flow processing for business flow method of NONE.
12711    END IF;
12712 
12713    --
12714    -- call analytical criteria
12715    --
12716    
12717    --
12718    -- call description
12719    --
12720    -- No description or it is inherited.
12721    --
12722    -- call ADRs
12723    -- Bug 4922099
12724    --
12725    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
12726         (NVL(l_actual_upg_option, 'N') = 'O') OR
12727         (NVL(l_enc_upg_option, 'N') = 'O')
12728       )
12729    THEN
12730    NULL;
12731    --
12732    --
12733    
12734   l_ccid := AcctDerRule_6(
12735            p_application_id           => p_application_id
12739          , x_accounting_coa_id        => l_adr_accounting_coa_id
12736          , p_ae_header_id             => l_ae_header_id 
12737 , p_source_2 => p_source_2
12738          , x_transaction_coa_id       => l_adr_transaction_coa_id
12740          , x_value_type_code          => l_adr_value_type_code
12741          , p_side                     => 'NA'
12742    );
12743 
12744    xla_ae_lines_pkg.set_ccid(
12745     p_code_combination_id          => l_ccid
12746   , p_value_type_code              => l_adr_value_type_code
12747   , p_transaction_coa_id           => l_adr_transaction_coa_id
12748   , p_accounting_coa_id            => l_adr_accounting_coa_id
12749   , p_adr_code                     => 'CM_DIST_CCID'
12750   , p_adr_type_code                => 'S'
12751   , p_component_type               => l_component_type
12752   , p_component_code               => l_component_code
12753   , p_component_type_code          => l_component_type_code
12754   , p_component_appl_id            => l_component_appl_id
12755   , p_amb_context_code             => l_amb_context_code
12756   , p_side                         => 'NA'
12757   );
12758 
12759 
12760    --
12761    --
12762    END IF;
12763    --
12764    -- Bug 4922099
12765    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
12766           (NVL(l_enc_upg_option, 'N') = 'O')
12767         ) AND
12768         (l_bflow_method_code = 'PRIOR_ENTRY')
12769       )
12770    THEN
12771       IF
12772       --
12773       1 = 2
12774       --
12775       THEN
12776       xla_accounting_err_pkg.build_message
12777                                     (p_appli_s_name            => 'XLA'
12778                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
12779                                     ,p_token_1                 => 'LINE_NUMBER'
12780                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
12781                                     ,p_token_2                 => 'LINE_TYPE_NAME'
12782                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
12783                                                                              l_component_type
12784                                                                             ,l_component_code
12785                                                                             ,l_component_type_code
12786                                                                             ,l_component_appl_id
12787                                                                             ,l_amb_context_code
12788                                                                             ,l_entity_code
12789                                                                             ,l_event_class_code
12790                                                                            )
12791                                     ,p_token_3                 => 'OWNER'
12792                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
12793                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
12794                                                                           ,p_lookup_code    => l_component_type_code
12795                                                                          )
12796                                     ,p_token_4                 => 'PRODUCT_NAME'
12797                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
12798                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
12799                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
12800                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
12801                                     ,p_ae_header_id            =>  NULL
12802                                        );
12803 
12804         IF (C_LEVEL_ERROR>= g_log_level) THEN
12805                  trace
12806                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
12807                       ,p_level    => C_LEVEL_ERROR
12808                       ,p_module   => l_log_module);
12809         END IF;
12810       END IF;
12811    END IF;
12812    --
12813    --
12814    ------------------------------------------------------------------------------------------------
12815    -- 4219869 Business Flow
12816    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
12817    -- Prior Entry.  Currently, the following code is always generated.
12818    ------------------------------------------------------------------------------------------------
12819    XLA_AE_LINES_PKG.ValidateCurrentLine;
12820 
12821    ------------------------------------------------------------------------------------
12822    -- 4219869 Business Flow
12823    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
12824    ------------------------------------------------------------------------------------
12825    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
12826 
12827    ----------------------------------------------------------------------------------
12828    -- 4219869 Business Flow
12829    -- Update journal entry status -- Need to generate this within IF <condition>
12830    ----------------------------------------------------------------------------------
12831    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
12835 
12832          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
12833          ,p_balance_type_code => l_balance_type_code
12834          );
12836    -------------------------------------------------------------------------------------------
12837    -- 4262811 - Generate the Accrual Reversal lines
12838    -------------------------------------------------------------------------------------------
12839    BEGIN
12840       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
12841                               (g_array_event(p_event_id).array_value_num('header_index'));
12842       IF l_acc_rev_flag IS NULL THEN
12843          l_acc_rev_flag := 'N';
12844       END IF;
12845    EXCEPTION
12846       WHEN OTHERS THEN
12847          l_acc_rev_flag := 'N';
12848    END;
12849    --
12850    IF (l_acc_rev_flag = 'Y') THEN
12851 
12852        -- 4645092  ------------------------------------------------------------------------------
12853        -- To allow MPA report to determine if it should generate report process
12854        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
12855        ------------------------------------------------------------------------------------------
12856 
12857        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
12858        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
12859    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
12860    -- call ADRs
12861    -- Bug 4922099
12862    --
12863    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
12864         (NVL(l_actual_upg_option, 'N') = 'O') OR
12865         (NVL(l_enc_upg_option, 'N') = 'O')
12866       )
12867    THEN
12868    NULL;
12869    --
12870    --
12871    
12872   l_ccid := AcctDerRule_6(
12873            p_application_id           => p_application_id
12874          , p_ae_header_id             => l_ae_header_id 
12875 , p_source_2 => p_source_2
12876          , x_transaction_coa_id       => l_adr_transaction_coa_id
12877          , x_accounting_coa_id        => l_adr_accounting_coa_id
12878          , x_value_type_code          => l_adr_value_type_code
12879          , p_side                     => 'NA'
12880    );
12881 
12882    xla_ae_lines_pkg.set_ccid(
12883     p_code_combination_id          => l_ccid
12884   , p_value_type_code              => l_adr_value_type_code
12885   , p_transaction_coa_id           => l_adr_transaction_coa_id
12886   , p_accounting_coa_id            => l_adr_accounting_coa_id
12887   , p_adr_code                     => 'CM_DIST_CCID'
12888   , p_adr_type_code                => 'S'
12889   , p_component_type               => l_component_type
12890   , p_component_code               => l_component_code
12891   , p_component_type_code          => l_component_type_code
12892   , p_component_appl_id            => l_component_appl_id
12893   , p_amb_context_code             => l_amb_context_code
12894   , p_side                         => 'NA'
12895   );
12896 
12897 
12898    --
12899    --
12900    END IF;
12901 
12902        --
12903        -- Update the line information that should be overwritten
12904        --
12905        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
12906                                          p_header_num   => 1);
12907        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
12908 
12909        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
12910 
12911        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
12912           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
12913        END IF;
12914 
12915       --
12916       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
12917       --
12918       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
12919           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
12920       ELSE
12921           ---------------------------------------------------------------------------------------------------
12922           -- 4262811a Switch Sign
12923           ---------------------------------------------------------------------------------------------------
12924           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
12925           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
12926                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12927           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
12928                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12929           -- 5132302
12930           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
12931                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12932 
12933       END IF;
12934 
12935       -- 4955764
12936       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
12937       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
12938 
12939 
12943       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
12940       XLA_AE_LINES_PKG.ValidateCurrentLine;
12941       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
12942 
12944                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
12945                ,p_balance_type_code => l_balance_type_code);
12946 
12947    END IF;
12948 
12949    -----------------------------------------------------------------------------------------
12950    -- 4262811 Multiperiod Accounting
12951    -----------------------------------------------------------------------------------------
12952      -- No MPA option is assigned.
12953 
12954 
12955 END IF;
12956 END IF;
12957 --
12958 
12959 --
12960 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12961    trace
12962       (p_msg      => 'END of AcctLineType_47'
12963       ,p_level    => C_LEVEL_PROCEDURE
12964       ,p_module   => l_log_module);
12965 END IF;
12966 --
12967 EXCEPTION
12968   WHEN xla_exceptions_pkg.application_exception THEN
12969       RAISE;
12970   WHEN OTHERS THEN
12971        xla_exceptions_pkg.raise_message
12972            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_47');
12973 END AcctLineType_47;
12974 --
12975 
12976 ---------------------------------------
12977 --
12978 -- PRIVATE FUNCTION
12979 --         AcctLineType_48
12980 --
12981 ---------------------------------------
12982 PROCEDURE AcctLineType_48 (
12983   p_application_id        IN NUMBER
12984  ,p_event_id              IN NUMBER
12985  ,p_calculate_acctd_flag  IN VARCHAR2
12986  ,p_calculate_g_l_flag    IN VARCHAR2
12987  ,p_actual_flag           IN OUT VARCHAR2
12988  ,p_balance_type_code     OUT VARCHAR2
12989  ,p_gain_or_loss_ref      OUT VARCHAR2
12990  
12991 --Credit Memo Distribution GL Account
12992  , p_source_2            IN NUMBER
12993 --SLA Party Type
12994  , p_source_32            IN VARCHAR2
12995 --Credit Memo Distribution Identifier
12996  , p_source_42            IN NUMBER
12997 --Credit memo distributions type
12998  , p_source_43            IN VARCHAR2
12999 --Credit Memo Currency Code
13000  , p_source_44            IN VARCHAR2
13001 --Credit Memo Exchange Date
13002  , p_source_45            IN DATE
13003 --Credit Memo Exchange Rate
13004  , p_source_46            IN NUMBER
13005 --Credit Memo Exchange Rate Type
13006  , p_source_47            IN VARCHAR2
13007 --Gain Loss Reference
13008  , p_source_48            IN VARCHAR2
13009 --Credit Memo Accounting Amount
13010  , p_source_49            IN NUMBER
13011 --Credit Memo Bill To Customer Account Identifier
13012  , p_source_50            IN NUMBER
13013 --Credit Memo Bill To Customer Site Use Identifier
13014  , p_source_51            IN NUMBER
13015 --Credit Memo Tax Line Identifier
13016  , p_source_52            IN NUMBER
13017 --Credit Memo Distribution Account Class
13018  , p_source_53            IN VARCHAR2
13019 --Credit Memo Distribution Entered Amount
13020  , p_source_54            IN NUMBER
13021 )
13022 IS
13023 
13024 l_component_type              VARCHAR2(80);
13025 l_component_code              VARCHAR2(30);
13026 l_component_type_code         VARCHAR2(1);
13027 l_component_appl_id           INTEGER;
13028 l_amb_context_code            VARCHAR2(30);
13029 l_entity_code                 VARCHAR2(30);
13030 l_event_class_code            VARCHAR2(30);
13031 l_ae_header_id                NUMBER;
13032 l_event_type_code             VARCHAR2(30);
13033 l_line_definition_code        VARCHAR2(30);
13034 l_line_definition_owner_code  VARCHAR2(1);
13035 --
13036 -- adr variables
13037 l_segment                     VARCHAR2(30);
13038 l_ccid                        NUMBER;
13039 l_adr_transaction_coa_id      NUMBER;
13040 l_adr_accounting_coa_id       NUMBER;
13041 l_adr_flexfield_segment_code  VARCHAR2(30);
13042 l_adr_flex_value_set_id       NUMBER;
13043 l_adr_value_type_code         VARCHAR2(30);
13044 l_adr_value_combination_id    NUMBER;
13045 l_adr_value_segment_code      VARCHAR2(30);
13046 
13047 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
13048 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
13049 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
13050 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
13051 
13052 -- 4262811 Variables ------------------------------------------------------------------------------------------
13053 l_entered_amt_idx             NUMBER;
13054 l_accted_amt_idx              NUMBER;
13055 l_acc_rev_flag                VARCHAR2(1);
13056 l_accrual_line_num            NUMBER;
13057 l_tmp_amt                     NUMBER;
13058 l_acc_rev_natural_side_code   VARCHAR2(1);
13059 
13060 l_num_entries                 NUMBER;
13061 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
13062 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
13063 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
13064 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
13065 l_recog_line_1                NUMBER;
13066 l_recog_line_2                NUMBER;
13067 
13068 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
13069 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
13070 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
13071 
13075 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
13072 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
13073 
13074 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
13076 
13077 ---------------------------------------------------------------------------------------------------------------
13078 
13079 
13080 --
13081 -- bulk performance
13082 --
13083 l_balance_type_code           VARCHAR2(1);
13084 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
13085 l_log_module                  VARCHAR2(240);
13086 
13087 --
13088 -- Upgrade strategy
13089 --
13090 l_actual_upg_option           VARCHAR2(1);
13091 l_enc_upg_option           VARCHAR2(1);
13092 
13093 --
13094 BEGIN
13095 --
13096 IF g_log_enabled THEN
13097       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_48';
13098 END IF;
13099 --
13100 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13101 
13102       trace
13103          (p_msg      => 'BEGIN of AcctLineType_48'
13104          ,p_level    => C_LEVEL_PROCEDURE
13105          ,p_module   => l_log_module);
13106 
13107 END IF;
13108 --
13109 l_component_type             := 'AMB_JLT';
13110 l_component_code             := 'CM_UNBILL';
13111 l_component_type_code        := 'S';
13112 l_component_appl_id          :=  222;
13113 l_amb_context_code           := 'DEFAULT';
13114 l_entity_code                := 'TRANSACTIONS';
13115 l_event_class_code           := 'CREDIT_MEMO';
13116 l_event_type_code            := 'CREDIT_MEMO_ALL';
13117 l_line_definition_owner_code := 'S';
13118 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
13119 --
13120 l_balance_type_code          := 'A';
13121 l_segment                     := NULL;
13122 l_ccid                        := NULL;
13123 l_adr_transaction_coa_id      := NULL;
13124 l_adr_accounting_coa_id       := NULL;
13125 l_adr_flexfield_segment_code  := NULL;
13126 l_adr_flex_value_set_id       := NULL;
13127 l_adr_value_type_code         := NULL;
13128 l_adr_value_combination_id    := NULL;
13129 l_adr_value_segment_code      := NULL;
13130 
13131 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
13132 l_bflow_class_code           := '';    -- 4219869 Business Flow
13133 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
13134 l_budgetary_control_flag     := 'N';
13135 
13136 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
13137 l_bflow_applied_to_amt       := NULL; -- 5132302
13138 l_entered_amt_idx            := NULL;          -- 4262811
13139 l_accted_amt_idx             := NULL;          -- 4262811
13140 l_acc_rev_flag               := NULL;          -- 4262811
13141 l_accrual_line_num           := NULL;          -- 4262811
13142 l_tmp_amt                    := NULL;          -- 4262811
13143 --
13144  
13145 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
13146     l_balance_type_code <> 'B' THEN
13147 IF NVL(p_source_53,'
13148 ') =  'UNBILL'
13149  THEN 
13150 
13151    --
13152    XLA_AE_LINES_PKG.SetNewLine;
13153 
13154    p_balance_type_code          := l_balance_type_code;
13155    -- set the flag so later we will know whether the gain loss line needs to be created
13156    
13157    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
13158      p_actual_flag :='A';
13159    END IF;
13160 
13161    --
13162    -- bulk performance
13163    --
13164    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
13165                                       p_header_num   => 0); -- 4262811
13166    --
13167    -- set accounting line options
13168    --
13169    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
13170            p_natural_side_code          => 'C'
13171          , p_gain_or_loss_flag          => 'N'
13172          , p_gl_transfer_mode_code      => 'S'
13173          , p_acct_entry_type_code       => 'A'
13174          , p_switch_side_flag           => 'Y'
13175          , p_merge_duplicate_code       => 'A'
13176          );
13177    --
13178    l_acc_rev_natural_side_code := 'D';  -- 4262811
13179    -- 
13180    --
13181    -- set accounting line type info
13182    --
13183    xla_ae_lines_pkg.SetAcctLineType
13184       (p_component_type             => l_component_type
13185       ,p_event_type_code            => l_event_type_code
13186       ,p_line_definition_owner_code => l_line_definition_owner_code
13187       ,p_line_definition_code       => l_line_definition_code
13188       ,p_accounting_line_code       => l_component_code
13189       ,p_accounting_line_type_code  => l_component_type_code
13190       ,p_accounting_line_appl_id    => l_component_appl_id
13191       ,p_amb_context_code           => l_amb_context_code
13192       ,p_entity_code                => l_entity_code
13193       ,p_event_class_code           => l_event_class_code);
13194    --
13195    -- set accounting class
13196    --
13197    xla_ae_lines_pkg.SetAcctClass(
13198            p_accounting_class_code  => 'UNBILL'
13199          , p_ae_header_id           => l_ae_header_id
13200          );
13201 
13202    --
13203    -- set rounding class
13204    --
13205    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
13209    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
13206                       'RECEIVABLE';
13207 
13208    --
13210    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
13211    --
13212    -- bulk performance
13213    --
13214    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
13215 
13216    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
13217       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
13218 
13219    -- 4955764
13220    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
13221       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
13222 
13223    -- 4458381 Public Sector Enh
13224    
13225    --
13226    -- set accounting attributes for the line type
13227    --
13228    l_entered_amt_idx := 3;
13229    l_accted_amt_idx  := 9;
13230    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
13231    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
13232    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_42);
13233    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
13234    l_rec_acct_attrs.array_char_value(2)  := p_source_43;
13235    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
13236    l_rec_acct_attrs.array_num_value(3)  := p_source_54;
13237    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
13238    l_rec_acct_attrs.array_char_value(4)  := p_source_44;
13239    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
13240    l_rec_acct_attrs.array_date_value(5)  := p_source_45;
13241    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
13242    l_rec_acct_attrs.array_num_value(6)  := p_source_46;
13243    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
13244    l_rec_acct_attrs.array_char_value(7)  := p_source_47;
13245    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
13246    l_rec_acct_attrs.array_char_value(8)  := p_source_48;
13247    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
13248    l_rec_acct_attrs.array_num_value(9)  := p_source_49;
13249    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
13250    l_rec_acct_attrs.array_num_value(10)  := p_source_50;
13251    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
13252    l_rec_acct_attrs.array_num_value(11)  := p_source_51;
13253    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
13254    l_rec_acct_attrs.array_char_value(12)  := p_source_32;
13255    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
13256    l_rec_acct_attrs.array_num_value(13)  := p_source_52;
13257 
13258    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
13259    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
13260 
13261    ---------------------------------------------------------------------------------------------------------------
13262    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
13263    ---------------------------------------------------------------------------------------------------------------
13264    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
13265 
13266    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
13267    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
13268 
13269    IF xla_accounting_cache_pkg.GetValueChar
13270          (p_source_code         => 'LEDGER_CATEGORY_CODE'
13271          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
13272    AND l_bflow_method_code = 'PRIOR_ENTRY'
13273 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
13274    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
13275          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
13276        )
13277    THEN
13278          xla_ae_lines_pkg.BflowUpgEntry
13279            (p_business_method_code    => l_bflow_method_code
13280            ,p_business_class_code     => l_bflow_class_code
13281            ,p_balance_type            => l_balance_type_code);
13282    ELSE
13283       NULL;
13284 -- No business flow processing for business flow method of NONE.
13285    END IF;
13286 
13287    --
13288    -- call analytical criteria
13289    --
13290    
13291    --
13292    -- call description
13293    --
13294    -- No description or it is inherited.
13295    --
13296    -- call ADRs
13297    -- Bug 4922099
13298    --
13299    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
13300         (NVL(l_actual_upg_option, 'N') = 'O') OR
13301         (NVL(l_enc_upg_option, 'N') = 'O')
13302       )
13303    THEN
13304    NULL;
13305    --
13306    --
13307    
13308   l_ccid := AcctDerRule_6(
13309            p_application_id           => p_application_id
13310          , p_ae_header_id             => l_ae_header_id 
13311 , p_source_2 => p_source_2
13312          , x_transaction_coa_id       => l_adr_transaction_coa_id
13313          , x_accounting_coa_id        => l_adr_accounting_coa_id
13317 
13314          , x_value_type_code          => l_adr_value_type_code
13315          , p_side                     => 'NA'
13316    );
13318    xla_ae_lines_pkg.set_ccid(
13319     p_code_combination_id          => l_ccid
13320   , p_value_type_code              => l_adr_value_type_code
13321   , p_transaction_coa_id           => l_adr_transaction_coa_id
13322   , p_accounting_coa_id            => l_adr_accounting_coa_id
13323   , p_adr_code                     => 'CM_DIST_CCID'
13324   , p_adr_type_code                => 'S'
13325   , p_component_type               => l_component_type
13326   , p_component_code               => l_component_code
13327   , p_component_type_code          => l_component_type_code
13328   , p_component_appl_id            => l_component_appl_id
13329   , p_amb_context_code             => l_amb_context_code
13330   , p_side                         => 'NA'
13331   );
13332 
13333 
13334    --
13335    --
13336    END IF;
13337    --
13338    -- Bug 4922099
13339    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
13340           (NVL(l_enc_upg_option, 'N') = 'O')
13341         ) AND
13342         (l_bflow_method_code = 'PRIOR_ENTRY')
13343       )
13344    THEN
13345       IF
13346       --
13347       1 = 2
13348       --
13349       THEN
13350       xla_accounting_err_pkg.build_message
13351                                     (p_appli_s_name            => 'XLA'
13352                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
13353                                     ,p_token_1                 => 'LINE_NUMBER'
13354                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
13355                                     ,p_token_2                 => 'LINE_TYPE_NAME'
13356                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
13357                                                                              l_component_type
13358                                                                             ,l_component_code
13359                                                                             ,l_component_type_code
13360                                                                             ,l_component_appl_id
13361                                                                             ,l_amb_context_code
13362                                                                             ,l_entity_code
13363                                                                             ,l_event_class_code
13364                                                                            )
13365                                     ,p_token_3                 => 'OWNER'
13366                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
13367                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
13368                                                                           ,p_lookup_code    => l_component_type_code
13369                                                                          )
13370                                     ,p_token_4                 => 'PRODUCT_NAME'
13371                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
13372                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
13373                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
13374                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
13375                                     ,p_ae_header_id            =>  NULL
13376                                        );
13377 
13378         IF (C_LEVEL_ERROR>= g_log_level) THEN
13379                  trace
13380                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
13381                       ,p_level    => C_LEVEL_ERROR
13382                       ,p_module   => l_log_module);
13383         END IF;
13384       END IF;
13385    END IF;
13386    --
13387    --
13388    ------------------------------------------------------------------------------------------------
13389    -- 4219869 Business Flow
13390    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
13391    -- Prior Entry.  Currently, the following code is always generated.
13392    ------------------------------------------------------------------------------------------------
13393    XLA_AE_LINES_PKG.ValidateCurrentLine;
13394 
13395    ------------------------------------------------------------------------------------
13396    -- 4219869 Business Flow
13397    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
13398    ------------------------------------------------------------------------------------
13399    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
13400 
13401    ----------------------------------------------------------------------------------
13402    -- 4219869 Business Flow
13403    -- Update journal entry status -- Need to generate this within IF <condition>
13404    ----------------------------------------------------------------------------------
13405    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
13406          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
13407          ,p_balance_type_code => l_balance_type_code
13408          );
13409 
13410    -------------------------------------------------------------------------------------------
13411    -- 4262811 - Generate the Accrual Reversal lines
13415                               (g_array_event(p_event_id).array_value_num('header_index'));
13412    -------------------------------------------------------------------------------------------
13413    BEGIN
13414       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
13416       IF l_acc_rev_flag IS NULL THEN
13417          l_acc_rev_flag := 'N';
13418       END IF;
13419    EXCEPTION
13420       WHEN OTHERS THEN
13421          l_acc_rev_flag := 'N';
13422    END;
13423    --
13424    IF (l_acc_rev_flag = 'Y') THEN
13425 
13426        -- 4645092  ------------------------------------------------------------------------------
13427        -- To allow MPA report to determine if it should generate report process
13428        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
13429        ------------------------------------------------------------------------------------------
13430 
13431        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
13432        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
13433    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
13434    -- call ADRs
13435    -- Bug 4922099
13436    --
13437    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
13438         (NVL(l_actual_upg_option, 'N') = 'O') OR
13439         (NVL(l_enc_upg_option, 'N') = 'O')
13440       )
13441    THEN
13442    NULL;
13443    --
13444    --
13445    
13446   l_ccid := AcctDerRule_6(
13447            p_application_id           => p_application_id
13448          , p_ae_header_id             => l_ae_header_id 
13449 , p_source_2 => p_source_2
13450          , x_transaction_coa_id       => l_adr_transaction_coa_id
13451          , x_accounting_coa_id        => l_adr_accounting_coa_id
13452          , x_value_type_code          => l_adr_value_type_code
13453          , p_side                     => 'NA'
13454    );
13455 
13456    xla_ae_lines_pkg.set_ccid(
13457     p_code_combination_id          => l_ccid
13458   , p_value_type_code              => l_adr_value_type_code
13459   , p_transaction_coa_id           => l_adr_transaction_coa_id
13460   , p_accounting_coa_id            => l_adr_accounting_coa_id
13461   , p_adr_code                     => 'CM_DIST_CCID'
13462   , p_adr_type_code                => 'S'
13463   , p_component_type               => l_component_type
13464   , p_component_code               => l_component_code
13465   , p_component_type_code          => l_component_type_code
13466   , p_component_appl_id            => l_component_appl_id
13467   , p_amb_context_code             => l_amb_context_code
13468   , p_side                         => 'NA'
13469   );
13470 
13471 
13472    --
13473    --
13474    END IF;
13475 
13476        --
13477        -- Update the line information that should be overwritten
13478        --
13479        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
13480                                          p_header_num   => 1);
13481        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
13482 
13483        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
13484 
13485        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
13486           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
13487        END IF;
13488 
13489       --
13490       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
13491       --
13492       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
13493           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
13494       ELSE
13495           ---------------------------------------------------------------------------------------------------
13496           -- 4262811a Switch Sign
13497           ---------------------------------------------------------------------------------------------------
13498           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
13499           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
13500                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
13501           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
13502                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
13503           -- 5132302
13504           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
13505                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
13506 
13507       END IF;
13508 
13509       -- 4955764
13510       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
13511       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
13512 
13513 
13514       XLA_AE_LINES_PKG.ValidateCurrentLine;
13515       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
13516 
13517       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
13518                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
13519                ,p_balance_type_code => l_balance_type_code);
13520 
13521    END IF;
13522 
13526      -- No MPA option is assigned.
13523    -----------------------------------------------------------------------------------------
13524    -- 4262811 Multiperiod Accounting
13525    -----------------------------------------------------------------------------------------
13527 
13528 
13529 END IF;
13530 END IF;
13531 --
13532 
13533 --
13534 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13535    trace
13536       (p_msg      => 'END of AcctLineType_48'
13537       ,p_level    => C_LEVEL_PROCEDURE
13538       ,p_module   => l_log_module);
13539 END IF;
13540 --
13541 EXCEPTION
13542   WHEN xla_exceptions_pkg.application_exception THEN
13543       RAISE;
13544   WHEN OTHERS THEN
13545        xla_exceptions_pkg.raise_message
13546            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_48');
13547 END AcctLineType_48;
13548 --
13549 
13550 ---------------------------------------
13551 --
13552 -- PRIVATE FUNCTION
13553 --         AcctLineType_49
13554 --
13555 ---------------------------------------
13556 PROCEDURE AcctLineType_49 (
13557   p_application_id        IN NUMBER
13558  ,p_event_id              IN NUMBER
13559  ,p_calculate_acctd_flag  IN VARCHAR2
13560  ,p_calculate_g_l_flag    IN VARCHAR2
13561  ,p_actual_flag           IN OUT VARCHAR2
13562  ,p_balance_type_code     OUT VARCHAR2
13563  ,p_gain_or_loss_ref      OUT VARCHAR2
13564  
13565 --Credit Memo Distribution GL Account
13566  , p_source_2            IN NUMBER
13567 --SLA Party Type
13568  , p_source_32            IN VARCHAR2
13569 --Credit Memo Distribution Identifier
13570  , p_source_42            IN NUMBER
13571 --Credit memo distributions type
13572  , p_source_43            IN VARCHAR2
13573 --Credit Memo Currency Code
13574  , p_source_44            IN VARCHAR2
13575 --Credit Memo Exchange Date
13576  , p_source_45            IN DATE
13577 --Credit Memo Exchange Rate
13578  , p_source_46            IN NUMBER
13579 --Credit Memo Exchange Rate Type
13580  , p_source_47            IN VARCHAR2
13581 --Gain Loss Reference
13582  , p_source_48            IN VARCHAR2
13583 --Credit Memo Accounting Amount
13584  , p_source_49            IN NUMBER
13585 --Credit Memo Bill To Customer Account Identifier
13586  , p_source_50            IN NUMBER
13587 --Credit Memo Bill To Customer Site Use Identifier
13588  , p_source_51            IN NUMBER
13589 --Credit Memo Tax Line Identifier
13590  , p_source_52            IN NUMBER
13591 --Credit Memo Distribution Account Class
13592  , p_source_53            IN VARCHAR2
13593 --Credit Memo Distribution Entered Amount
13594  , p_source_54            IN NUMBER
13595 )
13596 IS
13597 
13598 l_component_type              VARCHAR2(80);
13599 l_component_code              VARCHAR2(30);
13600 l_component_type_code         VARCHAR2(1);
13601 l_component_appl_id           INTEGER;
13602 l_amb_context_code            VARCHAR2(30);
13603 l_entity_code                 VARCHAR2(30);
13604 l_event_class_code            VARCHAR2(30);
13605 l_ae_header_id                NUMBER;
13606 l_event_type_code             VARCHAR2(30);
13607 l_line_definition_code        VARCHAR2(30);
13608 l_line_definition_owner_code  VARCHAR2(1);
13609 --
13610 -- adr variables
13611 l_segment                     VARCHAR2(30);
13612 l_ccid                        NUMBER;
13613 l_adr_transaction_coa_id      NUMBER;
13614 l_adr_accounting_coa_id       NUMBER;
13615 l_adr_flexfield_segment_code  VARCHAR2(30);
13616 l_adr_flex_value_set_id       NUMBER;
13617 l_adr_value_type_code         VARCHAR2(30);
13618 l_adr_value_combination_id    NUMBER;
13619 l_adr_value_segment_code      VARCHAR2(30);
13620 
13621 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
13622 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
13623 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
13624 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
13625 
13626 -- 4262811 Variables ------------------------------------------------------------------------------------------
13627 l_entered_amt_idx             NUMBER;
13628 l_accted_amt_idx              NUMBER;
13629 l_acc_rev_flag                VARCHAR2(1);
13630 l_accrual_line_num            NUMBER;
13631 l_tmp_amt                     NUMBER;
13632 l_acc_rev_natural_side_code   VARCHAR2(1);
13633 
13634 l_num_entries                 NUMBER;
13635 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
13636 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
13637 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
13638 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
13639 l_recog_line_1                NUMBER;
13640 l_recog_line_2                NUMBER;
13641 
13642 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
13643 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
13644 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
13645 
13646 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
13647 
13648 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
13649 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
13650 
13654 --
13651 ---------------------------------------------------------------------------------------------------------------
13652 
13653 
13655 -- bulk performance
13656 --
13657 l_balance_type_code           VARCHAR2(1);
13658 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
13659 l_log_module                  VARCHAR2(240);
13660 
13661 --
13662 -- Upgrade strategy
13663 --
13664 l_actual_upg_option           VARCHAR2(1);
13665 l_enc_upg_option           VARCHAR2(1);
13666 
13667 --
13668 BEGIN
13669 --
13670 IF g_log_enabled THEN
13671       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_49';
13672 END IF;
13673 --
13674 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13675 
13676       trace
13677          (p_msg      => 'BEGIN of AcctLineType_49'
13678          ,p_level    => C_LEVEL_PROCEDURE
13679          ,p_module   => l_log_module);
13680 
13681 END IF;
13682 --
13683 l_component_type             := 'AMB_JLT';
13684 l_component_code             := 'CM_UNEARN';
13685 l_component_type_code        := 'S';
13686 l_component_appl_id          :=  222;
13687 l_amb_context_code           := 'DEFAULT';
13688 l_entity_code                := 'TRANSACTIONS';
13689 l_event_class_code           := 'CREDIT_MEMO';
13690 l_event_type_code            := 'CREDIT_MEMO_ALL';
13691 l_line_definition_owner_code := 'S';
13692 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
13693 --
13694 l_balance_type_code          := 'A';
13695 l_segment                     := NULL;
13696 l_ccid                        := NULL;
13697 l_adr_transaction_coa_id      := NULL;
13698 l_adr_accounting_coa_id       := NULL;
13699 l_adr_flexfield_segment_code  := NULL;
13700 l_adr_flex_value_set_id       := NULL;
13701 l_adr_value_type_code         := NULL;
13702 l_adr_value_combination_id    := NULL;
13703 l_adr_value_segment_code      := NULL;
13704 
13705 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
13706 l_bflow_class_code           := '';    -- 4219869 Business Flow
13707 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
13708 l_budgetary_control_flag     := 'N';
13709 
13710 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
13711 l_bflow_applied_to_amt       := NULL; -- 5132302
13712 l_entered_amt_idx            := NULL;          -- 4262811
13713 l_accted_amt_idx             := NULL;          -- 4262811
13714 l_acc_rev_flag               := NULL;          -- 4262811
13715 l_accrual_line_num           := NULL;          -- 4262811
13716 l_tmp_amt                    := NULL;          -- 4262811
13717 --
13718  
13719 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
13720     l_balance_type_code <> 'B' THEN
13721 IF NVL(p_source_53,'
13722 ') =  'UNEARN'
13723  THEN 
13724 
13725    --
13726    XLA_AE_LINES_PKG.SetNewLine;
13727 
13728    p_balance_type_code          := l_balance_type_code;
13729    -- set the flag so later we will know whether the gain loss line needs to be created
13730    
13731    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
13732      p_actual_flag :='A';
13733    END IF;
13734 
13735    --
13736    -- bulk performance
13737    --
13738    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
13739                                       p_header_num   => 0); -- 4262811
13740    --
13741    -- set accounting line options
13742    --
13743    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
13744            p_natural_side_code          => 'C'
13745          , p_gain_or_loss_flag          => 'N'
13746          , p_gl_transfer_mode_code      => 'S'
13747          , p_acct_entry_type_code       => 'A'
13748          , p_switch_side_flag           => 'Y'
13749          , p_merge_duplicate_code       => 'A'
13750          );
13751    --
13752    l_acc_rev_natural_side_code := 'D';  -- 4262811
13753    -- 
13754    --
13755    -- set accounting line type info
13756    --
13757    xla_ae_lines_pkg.SetAcctLineType
13758       (p_component_type             => l_component_type
13759       ,p_event_type_code            => l_event_type_code
13760       ,p_line_definition_owner_code => l_line_definition_owner_code
13761       ,p_line_definition_code       => l_line_definition_code
13762       ,p_accounting_line_code       => l_component_code
13763       ,p_accounting_line_type_code  => l_component_type_code
13764       ,p_accounting_line_appl_id    => l_component_appl_id
13765       ,p_amb_context_code           => l_amb_context_code
13766       ,p_entity_code                => l_entity_code
13767       ,p_event_class_code           => l_event_class_code);
13768    --
13769    -- set accounting class
13770    --
13771    xla_ae_lines_pkg.SetAcctClass(
13772            p_accounting_class_code  => 'UNEARNED_REVENUE'
13773          , p_ae_header_id           => l_ae_header_id
13774          );
13775 
13776    --
13777    -- set rounding class
13778    --
13779    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
13780                       'RECEIVABLE';
13781 
13782    --
13783    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
13787    --
13784    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
13785    --
13786    -- bulk performance
13788    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
13789 
13790    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
13791       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
13792 
13793    -- 4955764
13794    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
13795       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
13796 
13797    -- 4458381 Public Sector Enh
13798    
13799    --
13800    -- set accounting attributes for the line type
13801    --
13802    l_entered_amt_idx := 3;
13803    l_accted_amt_idx  := 9;
13804    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
13805    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
13806    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_42);
13807    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
13808    l_rec_acct_attrs.array_char_value(2)  := p_source_43;
13809    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
13810    l_rec_acct_attrs.array_num_value(3)  := p_source_54;
13811    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
13812    l_rec_acct_attrs.array_char_value(4)  := p_source_44;
13813    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
13814    l_rec_acct_attrs.array_date_value(5)  := p_source_45;
13815    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
13816    l_rec_acct_attrs.array_num_value(6)  := p_source_46;
13817    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
13818    l_rec_acct_attrs.array_char_value(7)  := p_source_47;
13819    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
13820    l_rec_acct_attrs.array_char_value(8)  := p_source_48;
13821    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
13822    l_rec_acct_attrs.array_num_value(9)  := p_source_49;
13823    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
13824    l_rec_acct_attrs.array_num_value(10)  := p_source_50;
13825    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
13826    l_rec_acct_attrs.array_num_value(11)  := p_source_51;
13827    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
13828    l_rec_acct_attrs.array_char_value(12)  := p_source_32;
13829    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
13830    l_rec_acct_attrs.array_num_value(13)  := p_source_52;
13831 
13832    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
13833    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
13834 
13835    ---------------------------------------------------------------------------------------------------------------
13836    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
13837    ---------------------------------------------------------------------------------------------------------------
13838    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
13839 
13840    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
13841    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
13842 
13843    IF xla_accounting_cache_pkg.GetValueChar
13844          (p_source_code         => 'LEDGER_CATEGORY_CODE'
13845          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
13846    AND l_bflow_method_code = 'PRIOR_ENTRY'
13847 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
13848    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
13849          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
13850        )
13851    THEN
13852          xla_ae_lines_pkg.BflowUpgEntry
13853            (p_business_method_code    => l_bflow_method_code
13854            ,p_business_class_code     => l_bflow_class_code
13855            ,p_balance_type            => l_balance_type_code);
13856    ELSE
13857       NULL;
13858 -- No business flow processing for business flow method of NONE.
13859    END IF;
13860 
13861    --
13862    -- call analytical criteria
13863    --
13864    
13865    --
13866    -- call description
13867    --
13868    -- No description or it is inherited.
13869    --
13870    -- call ADRs
13871    -- Bug 4922099
13872    --
13873    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
13874         (NVL(l_actual_upg_option, 'N') = 'O') OR
13875         (NVL(l_enc_upg_option, 'N') = 'O')
13876       )
13877    THEN
13878    NULL;
13879    --
13880    --
13881    
13882   l_ccid := AcctDerRule_6(
13883            p_application_id           => p_application_id
13884          , p_ae_header_id             => l_ae_header_id 
13885 , p_source_2 => p_source_2
13886          , x_transaction_coa_id       => l_adr_transaction_coa_id
13887          , x_accounting_coa_id        => l_adr_accounting_coa_id
13888          , x_value_type_code          => l_adr_value_type_code
13889          , p_side                     => 'NA'
13890    );
13891 
13892    xla_ae_lines_pkg.set_ccid(
13893     p_code_combination_id          => l_ccid
13894   , p_value_type_code              => l_adr_value_type_code
13895   , p_transaction_coa_id           => l_adr_transaction_coa_id
13899   , p_component_type               => l_component_type
13896   , p_accounting_coa_id            => l_adr_accounting_coa_id
13897   , p_adr_code                     => 'CM_DIST_CCID'
13898   , p_adr_type_code                => 'S'
13900   , p_component_code               => l_component_code
13901   , p_component_type_code          => l_component_type_code
13902   , p_component_appl_id            => l_component_appl_id
13903   , p_amb_context_code             => l_amb_context_code
13904   , p_side                         => 'NA'
13905   );
13906 
13907 
13908    --
13909    --
13910    END IF;
13911    --
13912    -- Bug 4922099
13913    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
13914           (NVL(l_enc_upg_option, 'N') = 'O')
13915         ) AND
13916         (l_bflow_method_code = 'PRIOR_ENTRY')
13917       )
13918    THEN
13919       IF
13920       --
13921       1 = 2
13922       --
13923       THEN
13924       xla_accounting_err_pkg.build_message
13925                                     (p_appli_s_name            => 'XLA'
13926                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
13927                                     ,p_token_1                 => 'LINE_NUMBER'
13928                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
13929                                     ,p_token_2                 => 'LINE_TYPE_NAME'
13930                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
13931                                                                              l_component_type
13932                                                                             ,l_component_code
13933                                                                             ,l_component_type_code
13934                                                                             ,l_component_appl_id
13935                                                                             ,l_amb_context_code
13936                                                                             ,l_entity_code
13937                                                                             ,l_event_class_code
13938                                                                            )
13939                                     ,p_token_3                 => 'OWNER'
13940                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
13941                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
13942                                                                           ,p_lookup_code    => l_component_type_code
13943                                                                          )
13944                                     ,p_token_4                 => 'PRODUCT_NAME'
13945                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
13946                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
13947                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
13948                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
13949                                     ,p_ae_header_id            =>  NULL
13950                                        );
13951 
13952         IF (C_LEVEL_ERROR>= g_log_level) THEN
13953                  trace
13954                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
13955                       ,p_level    => C_LEVEL_ERROR
13956                       ,p_module   => l_log_module);
13957         END IF;
13958       END IF;
13959    END IF;
13960    --
13961    --
13962    ------------------------------------------------------------------------------------------------
13963    -- 4219869 Business Flow
13964    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
13965    -- Prior Entry.  Currently, the following code is always generated.
13966    ------------------------------------------------------------------------------------------------
13967    XLA_AE_LINES_PKG.ValidateCurrentLine;
13968 
13969    ------------------------------------------------------------------------------------
13970    -- 4219869 Business Flow
13971    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
13972    ------------------------------------------------------------------------------------
13973    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
13974 
13975    ----------------------------------------------------------------------------------
13976    -- 4219869 Business Flow
13977    -- Update journal entry status -- Need to generate this within IF <condition>
13978    ----------------------------------------------------------------------------------
13979    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
13980          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
13981          ,p_balance_type_code => l_balance_type_code
13982          );
13983 
13984    -------------------------------------------------------------------------------------------
13985    -- 4262811 - Generate the Accrual Reversal lines
13986    -------------------------------------------------------------------------------------------
13987    BEGIN
13988       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
13989                               (g_array_event(p_event_id).array_value_num('header_index'));
13993    EXCEPTION
13990       IF l_acc_rev_flag IS NULL THEN
13991          l_acc_rev_flag := 'N';
13992       END IF;
13994       WHEN OTHERS THEN
13995          l_acc_rev_flag := 'N';
13996    END;
13997    --
13998    IF (l_acc_rev_flag = 'Y') THEN
13999 
14000        -- 4645092  ------------------------------------------------------------------------------
14001        -- To allow MPA report to determine if it should generate report process
14002        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
14003        ------------------------------------------------------------------------------------------
14004 
14005        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
14006        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
14007    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
14008    -- call ADRs
14009    -- Bug 4922099
14010    --
14011    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
14012         (NVL(l_actual_upg_option, 'N') = 'O') OR
14013         (NVL(l_enc_upg_option, 'N') = 'O')
14014       )
14015    THEN
14016    NULL;
14017    --
14018    --
14019    
14020   l_ccid := AcctDerRule_6(
14021            p_application_id           => p_application_id
14022          , p_ae_header_id             => l_ae_header_id 
14023 , p_source_2 => p_source_2
14024          , x_transaction_coa_id       => l_adr_transaction_coa_id
14025          , x_accounting_coa_id        => l_adr_accounting_coa_id
14026          , x_value_type_code          => l_adr_value_type_code
14027          , p_side                     => 'NA'
14028    );
14029 
14030    xla_ae_lines_pkg.set_ccid(
14031     p_code_combination_id          => l_ccid
14032   , p_value_type_code              => l_adr_value_type_code
14033   , p_transaction_coa_id           => l_adr_transaction_coa_id
14034   , p_accounting_coa_id            => l_adr_accounting_coa_id
14035   , p_adr_code                     => 'CM_DIST_CCID'
14036   , p_adr_type_code                => 'S'
14037   , p_component_type               => l_component_type
14038   , p_component_code               => l_component_code
14039   , p_component_type_code          => l_component_type_code
14040   , p_component_appl_id            => l_component_appl_id
14041   , p_amb_context_code             => l_amb_context_code
14042   , p_side                         => 'NA'
14043   );
14044 
14045 
14046    --
14047    --
14048    END IF;
14049 
14050        --
14051        -- Update the line information that should be overwritten
14052        --
14053        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
14054                                          p_header_num   => 1);
14055        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
14056 
14057        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
14058 
14059        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
14060           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
14061        END IF;
14062 
14063       --
14064       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
14065       --
14066       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
14067           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
14068       ELSE
14069           ---------------------------------------------------------------------------------------------------
14070           -- 4262811a Switch Sign
14071           ---------------------------------------------------------------------------------------------------
14072           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
14073           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
14074                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
14075           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
14076                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
14077           -- 5132302
14078           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
14079                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
14080 
14081       END IF;
14082 
14083       -- 4955764
14084       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
14085       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
14086 
14087 
14088       XLA_AE_LINES_PKG.ValidateCurrentLine;
14089       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
14090 
14091       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
14092                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
14093                ,p_balance_type_code => l_balance_type_code);
14094 
14095    END IF;
14096 
14097    -----------------------------------------------------------------------------------------
14098    -- 4262811 Multiperiod Accounting
14099    -----------------------------------------------------------------------------------------
14100      -- No MPA option is assigned.
14101 
14102 
14103 END IF;
14104 END IF;
14105 --
14106 
14107 --
14111       ,p_level    => C_LEVEL_PROCEDURE
14108 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14109    trace
14110       (p_msg      => 'END of AcctLineType_49'
14112       ,p_module   => l_log_module);
14113 END IF;
14114 --
14115 EXCEPTION
14116   WHEN xla_exceptions_pkg.application_exception THEN
14117       RAISE;
14118   WHEN OTHERS THEN
14119        xla_exceptions_pkg.raise_message
14120            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_49');
14121 END AcctLineType_49;
14122 --
14123 
14124 ---------------------------------------
14125 --
14126 -- PRIVATE FUNCTION
14127 --         AcctLineType_50
14128 --
14129 ---------------------------------------
14130 PROCEDURE AcctLineType_50 (
14131   p_application_id        IN NUMBER
14132  ,p_event_id              IN NUMBER
14133  ,p_calculate_acctd_flag  IN VARCHAR2
14134  ,p_calculate_g_l_flag    IN VARCHAR2
14135  ,p_actual_flag           IN OUT VARCHAR2
14136  ,p_balance_type_code     OUT VARCHAR2
14137  ,p_gain_or_loss_ref      OUT VARCHAR2
14138  
14139 --Transaction Distribution GL Account
14140  , p_source_4            IN NUMBER
14141 --Bill To Customer Account Identifier
14142  , p_source_30            IN NUMBER
14143 --Bill To Customer Site Use Identifier
14144  , p_source_31            IN NUMBER
14145 --SLA Party Type
14146  , p_source_32            IN VARCHAR2
14147 --Transaction Distribution Account Class
14148  , p_source_33            IN VARCHAR2
14149 --Transaction Distribution Identifier
14150  , p_source_34            IN NUMBER
14151 --Transaction Distribution Type
14152  , p_source_35            IN VARCHAR2
14153 --Transaction Distribution Entered Amount
14154  , p_source_36            IN NUMBER
14155 --Transaction Currency Code
14156  , p_source_37            IN VARCHAR2
14157 --Transaction Exchange Date
14158  , p_source_38            IN DATE
14159 --Transaction Exchange Rate
14160  , p_source_39            IN NUMBER
14161 --Transaction Exchange Rate Type
14162  , p_source_40            IN VARCHAR2
14163 --Transaction Accounting Amount
14164  , p_source_41            IN NUMBER
14165 )
14166 IS
14167 
14168 l_component_type              VARCHAR2(80);
14169 l_component_code              VARCHAR2(30);
14170 l_component_type_code         VARCHAR2(1);
14171 l_component_appl_id           INTEGER;
14172 l_amb_context_code            VARCHAR2(30);
14173 l_entity_code                 VARCHAR2(30);
14174 l_event_class_code            VARCHAR2(30);
14175 l_ae_header_id                NUMBER;
14176 l_event_type_code             VARCHAR2(30);
14177 l_line_definition_code        VARCHAR2(30);
14178 l_line_definition_owner_code  VARCHAR2(1);
14179 --
14180 -- adr variables
14181 l_segment                     VARCHAR2(30);
14182 l_ccid                        NUMBER;
14183 l_adr_transaction_coa_id      NUMBER;
14184 l_adr_accounting_coa_id       NUMBER;
14185 l_adr_flexfield_segment_code  VARCHAR2(30);
14186 l_adr_flex_value_set_id       NUMBER;
14187 l_adr_value_type_code         VARCHAR2(30);
14188 l_adr_value_combination_id    NUMBER;
14189 l_adr_value_segment_code      VARCHAR2(30);
14190 
14191 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
14192 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
14193 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
14194 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
14195 
14196 -- 4262811 Variables ------------------------------------------------------------------------------------------
14197 l_entered_amt_idx             NUMBER;
14198 l_accted_amt_idx              NUMBER;
14199 l_acc_rev_flag                VARCHAR2(1);
14200 l_accrual_line_num            NUMBER;
14201 l_tmp_amt                     NUMBER;
14202 l_acc_rev_natural_side_code   VARCHAR2(1);
14203 
14204 l_num_entries                 NUMBER;
14205 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
14206 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
14207 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
14208 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
14209 l_recog_line_1                NUMBER;
14210 l_recog_line_2                NUMBER;
14211 
14212 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
14213 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
14214 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
14215 
14216 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
14217 
14218 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
14219 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
14220 
14221 ---------------------------------------------------------------------------------------------------------------
14222 
14223 
14224 --
14225 -- bulk performance
14226 --
14227 l_balance_type_code           VARCHAR2(1);
14228 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
14229 l_log_module                  VARCHAR2(240);
14230 
14231 --
14232 -- Upgrade strategy
14233 --
14234 l_actual_upg_option           VARCHAR2(1);
14235 l_enc_upg_option           VARCHAR2(1);
14236 
14237 --
14238 BEGIN
14239 --
14243 --
14240 IF g_log_enabled THEN
14241       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_50';
14242 END IF;
14244 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14245 
14246       trace
14247          (p_msg      => 'BEGIN of AcctLineType_50'
14248          ,p_level    => C_LEVEL_PROCEDURE
14249          ,p_module   => l_log_module);
14250 
14251 END IF;
14252 --
14253 l_component_type             := 'AMB_JLT';
14254 l_component_code             := 'DEP_DEFAULT_REC';
14255 l_component_type_code        := 'S';
14256 l_component_appl_id          :=  222;
14257 l_amb_context_code           := 'DEFAULT';
14258 l_entity_code                := 'TRANSACTIONS';
14259 l_event_class_code           := 'DEPOSIT';
14260 l_event_type_code            := 'DEPOSIT_ALL';
14261 l_line_definition_owner_code := 'S';
14262 l_line_definition_code       := 'AR_DEP_DEFAULT_ACCRUAL';
14263 --
14264 l_balance_type_code          := 'A';
14265 l_segment                     := NULL;
14266 l_ccid                        := NULL;
14267 l_adr_transaction_coa_id      := NULL;
14268 l_adr_accounting_coa_id       := NULL;
14269 l_adr_flexfield_segment_code  := NULL;
14270 l_adr_flex_value_set_id       := NULL;
14271 l_adr_value_type_code         := NULL;
14272 l_adr_value_combination_id    := NULL;
14273 l_adr_value_segment_code      := NULL;
14274 
14275 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
14276 l_bflow_class_code           := '';    -- 4219869 Business Flow
14277 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
14278 l_budgetary_control_flag     := 'N';
14279 
14280 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
14281 l_bflow_applied_to_amt       := NULL; -- 5132302
14282 l_entered_amt_idx            := NULL;          -- 4262811
14283 l_accted_amt_idx             := NULL;          -- 4262811
14284 l_acc_rev_flag               := NULL;          -- 4262811
14285 l_accrual_line_num           := NULL;          -- 4262811
14286 l_tmp_amt                    := NULL;          -- 4262811
14287 --
14288  
14289 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
14290     l_balance_type_code <> 'B' THEN
14291 IF NVL(p_source_33,'
14292 ') =  'REC'
14293  THEN 
14294 
14295    --
14296    XLA_AE_LINES_PKG.SetNewLine;
14297 
14298    p_balance_type_code          := l_balance_type_code;
14299    -- set the flag so later we will know whether the gain loss line needs to be created
14300    
14301    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
14302      p_actual_flag :='A';
14303    END IF;
14304 
14305    --
14306    -- bulk performance
14307    --
14308    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
14309                                       p_header_num   => 0); -- 4262811
14310    --
14311    -- set accounting line options
14312    --
14313    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
14314            p_natural_side_code          => 'D'
14315          , p_gain_or_loss_flag          => 'N'
14316          , p_gl_transfer_mode_code      => 'S'
14317          , p_acct_entry_type_code       => 'A'
14318          , p_switch_side_flag           => 'Y'
14319          , p_merge_duplicate_code       => 'A'
14320          );
14321    --
14322    l_acc_rev_natural_side_code := 'C';  -- 4262811
14323    -- 
14324    --
14325    -- set accounting line type info
14326    --
14327    xla_ae_lines_pkg.SetAcctLineType
14328       (p_component_type             => l_component_type
14329       ,p_event_type_code            => l_event_type_code
14330       ,p_line_definition_owner_code => l_line_definition_owner_code
14331       ,p_line_definition_code       => l_line_definition_code
14332       ,p_accounting_line_code       => l_component_code
14333       ,p_accounting_line_type_code  => l_component_type_code
14334       ,p_accounting_line_appl_id    => l_component_appl_id
14335       ,p_amb_context_code           => l_amb_context_code
14336       ,p_entity_code                => l_entity_code
14337       ,p_event_class_code           => l_event_class_code);
14338    --
14339    -- set accounting class
14340    --
14341    xla_ae_lines_pkg.SetAcctClass(
14342            p_accounting_class_code  => 'RECEIVABLE'
14343          , p_ae_header_id           => l_ae_header_id
14344          );
14345 
14346    --
14347    -- set rounding class
14348    --
14349    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
14350                       'RECEIVABLE';
14351 
14352    --
14353    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
14354    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
14355    --
14356    -- bulk performance
14357    --
14358    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
14359 
14360    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
14361       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
14362 
14363    -- 4955764
14364    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
14365       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
14366 
14367    -- 4458381 Public Sector Enh
14368    
14372    l_entered_amt_idx := 3;
14369    --
14370    -- set accounting attributes for the line type
14371    --
14373    l_accted_amt_idx  := 8;
14374    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
14375    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
14376    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
14377    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
14378    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
14379    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
14380    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
14381    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
14382    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
14383    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
14384    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
14385    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
14386    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
14387    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
14388    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
14389    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
14390    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
14391    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
14392    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
14393    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
14394    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
14395    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
14396    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
14397 
14398    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
14399    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
14400 
14401    ---------------------------------------------------------------------------------------------------------------
14402    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
14403    ---------------------------------------------------------------------------------------------------------------
14404    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
14405 
14406    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
14407    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
14408 
14409    IF xla_accounting_cache_pkg.GetValueChar
14410          (p_source_code         => 'LEDGER_CATEGORY_CODE'
14411          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
14412    AND l_bflow_method_code = 'PRIOR_ENTRY'
14413 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
14414    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
14415          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
14416        )
14417    THEN
14418          xla_ae_lines_pkg.BflowUpgEntry
14419            (p_business_method_code    => l_bflow_method_code
14420            ,p_business_class_code     => l_bflow_class_code
14421            ,p_balance_type            => l_balance_type_code);
14422    ELSE
14423       NULL;
14424 -- No business flow processing for business flow method of NONE.
14425    END IF;
14426 
14427    --
14428    -- call analytical criteria
14429    --
14430    
14431    --
14432    -- call description
14433    --
14434    -- No description or it is inherited.
14435    --
14436    -- call ADRs
14437    -- Bug 4922099
14438    --
14439    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
14440         (NVL(l_actual_upg_option, 'N') = 'O') OR
14441         (NVL(l_enc_upg_option, 'N') = 'O')
14442       )
14443    THEN
14444    NULL;
14445    --
14446    --
14447    
14448   l_ccid := AcctDerRule_32(
14449            p_application_id           => p_application_id
14450          , p_ae_header_id             => l_ae_header_id 
14451 , p_source_4 => p_source_4
14452          , x_transaction_coa_id       => l_adr_transaction_coa_id
14453          , x_accounting_coa_id        => l_adr_accounting_coa_id
14454          , x_value_type_code          => l_adr_value_type_code
14455          , p_side                     => 'NA'
14456    );
14457 
14458    xla_ae_lines_pkg.set_ccid(
14459     p_code_combination_id          => l_ccid
14460   , p_value_type_code              => l_adr_value_type_code
14461   , p_transaction_coa_id           => l_adr_transaction_coa_id
14462   , p_accounting_coa_id            => l_adr_accounting_coa_id
14463   , p_adr_code                     => 'TRX_DIST_CCID'
14464   , p_adr_type_code                => 'S'
14465   , p_component_type               => l_component_type
14466   , p_component_code               => l_component_code
14467   , p_component_type_code          => l_component_type_code
14468   , p_component_appl_id            => l_component_appl_id
14469   , p_amb_context_code             => l_amb_context_code
14470   , p_side                         => 'NA'
14471   );
14472 
14473 
14474    --
14475    --
14476    END IF;
14477    --
14478    -- Bug 4922099
14479    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
14480           (NVL(l_enc_upg_option, 'N') = 'O')
14481         ) AND
14482         (l_bflow_method_code = 'PRIOR_ENTRY')
14483       )
14484    THEN
14485       IF
14486       --
14487       1 = 2
14488       --
14489       THEN
14490       xla_accounting_err_pkg.build_message
14494                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
14491                                     (p_appli_s_name            => 'XLA'
14492                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
14493                                     ,p_token_1                 => 'LINE_NUMBER'
14495                                     ,p_token_2                 => 'LINE_TYPE_NAME'
14496                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
14497                                                                              l_component_type
14498                                                                             ,l_component_code
14499                                                                             ,l_component_type_code
14500                                                                             ,l_component_appl_id
14501                                                                             ,l_amb_context_code
14502                                                                             ,l_entity_code
14503                                                                             ,l_event_class_code
14504                                                                            )
14505                                     ,p_token_3                 => 'OWNER'
14506                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
14507                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
14508                                                                           ,p_lookup_code    => l_component_type_code
14509                                                                          )
14510                                     ,p_token_4                 => 'PRODUCT_NAME'
14511                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
14512                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
14513                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
14514                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
14515                                     ,p_ae_header_id            =>  NULL
14516                                        );
14517 
14518         IF (C_LEVEL_ERROR>= g_log_level) THEN
14519                  trace
14520                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
14521                       ,p_level    => C_LEVEL_ERROR
14522                       ,p_module   => l_log_module);
14523         END IF;
14524       END IF;
14525    END IF;
14526    --
14527    --
14528    ------------------------------------------------------------------------------------------------
14529    -- 4219869 Business Flow
14530    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
14531    -- Prior Entry.  Currently, the following code is always generated.
14532    ------------------------------------------------------------------------------------------------
14533    XLA_AE_LINES_PKG.ValidateCurrentLine;
14534 
14535    ------------------------------------------------------------------------------------
14536    -- 4219869 Business Flow
14537    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
14538    ------------------------------------------------------------------------------------
14539    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
14540 
14541    ----------------------------------------------------------------------------------
14542    -- 4219869 Business Flow
14543    -- Update journal entry status -- Need to generate this within IF <condition>
14544    ----------------------------------------------------------------------------------
14545    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
14546          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
14547          ,p_balance_type_code => l_balance_type_code
14548          );
14549 
14550    -------------------------------------------------------------------------------------------
14551    -- 4262811 - Generate the Accrual Reversal lines
14552    -------------------------------------------------------------------------------------------
14553    BEGIN
14554       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
14555                               (g_array_event(p_event_id).array_value_num('header_index'));
14556       IF l_acc_rev_flag IS NULL THEN
14557          l_acc_rev_flag := 'N';
14558       END IF;
14559    EXCEPTION
14560       WHEN OTHERS THEN
14561          l_acc_rev_flag := 'N';
14562    END;
14563    --
14564    IF (l_acc_rev_flag = 'Y') THEN
14565 
14566        -- 4645092  ------------------------------------------------------------------------------
14567        -- To allow MPA report to determine if it should generate report process
14568        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
14569        ------------------------------------------------------------------------------------------
14570 
14571        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
14572        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
14573    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
14574    -- call ADRs
14575    -- Bug 4922099
14576    --
14577    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
14578         (NVL(l_actual_upg_option, 'N') = 'O') OR
14579         (NVL(l_enc_upg_option, 'N') = 'O')
14580       )
14584    --
14581    THEN
14582    NULL;
14583    --
14585    
14586   l_ccid := AcctDerRule_32(
14587            p_application_id           => p_application_id
14588          , p_ae_header_id             => l_ae_header_id 
14589 , p_source_4 => p_source_4
14590          , x_transaction_coa_id       => l_adr_transaction_coa_id
14591          , x_accounting_coa_id        => l_adr_accounting_coa_id
14592          , x_value_type_code          => l_adr_value_type_code
14593          , p_side                     => 'NA'
14594    );
14595 
14596    xla_ae_lines_pkg.set_ccid(
14597     p_code_combination_id          => l_ccid
14598   , p_value_type_code              => l_adr_value_type_code
14599   , p_transaction_coa_id           => l_adr_transaction_coa_id
14600   , p_accounting_coa_id            => l_adr_accounting_coa_id
14601   , p_adr_code                     => 'TRX_DIST_CCID'
14602   , p_adr_type_code                => 'S'
14603   , p_component_type               => l_component_type
14604   , p_component_code               => l_component_code
14605   , p_component_type_code          => l_component_type_code
14606   , p_component_appl_id            => l_component_appl_id
14607   , p_amb_context_code             => l_amb_context_code
14608   , p_side                         => 'NA'
14609   );
14610 
14611 
14612    --
14613    --
14614    END IF;
14615 
14616        --
14617        -- Update the line information that should be overwritten
14618        --
14619        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
14620                                          p_header_num   => 1);
14621        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
14622 
14623        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
14624 
14625        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
14626           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
14627        END IF;
14628 
14629       --
14630       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
14631       --
14632       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
14633           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
14634       ELSE
14635           ---------------------------------------------------------------------------------------------------
14636           -- 4262811a Switch Sign
14637           ---------------------------------------------------------------------------------------------------
14638           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
14639           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
14640                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
14641           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
14642                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
14643           -- 5132302
14644           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
14645                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
14646 
14647       END IF;
14648 
14649       -- 4955764
14650       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
14651       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
14652 
14653 
14654       XLA_AE_LINES_PKG.ValidateCurrentLine;
14655       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
14656 
14657       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
14658                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
14659                ,p_balance_type_code => l_balance_type_code);
14660 
14661    END IF;
14662 
14663    -----------------------------------------------------------------------------------------
14664    -- 4262811 Multiperiod Accounting
14665    -----------------------------------------------------------------------------------------
14666      -- No MPA option is assigned.
14667 
14668 
14669 END IF;
14670 END IF;
14671 --
14672 
14673 --
14674 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14675    trace
14676       (p_msg      => 'END of AcctLineType_50'
14677       ,p_level    => C_LEVEL_PROCEDURE
14678       ,p_module   => l_log_module);
14679 END IF;
14680 --
14681 EXCEPTION
14682   WHEN xla_exceptions_pkg.application_exception THEN
14683       RAISE;
14684   WHEN OTHERS THEN
14685        xla_exceptions_pkg.raise_message
14686            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_50');
14687 END AcctLineType_50;
14688 --
14689 
14690 ---------------------------------------
14691 --
14692 -- PRIVATE FUNCTION
14693 --         AcctLineType_51
14694 --
14695 ---------------------------------------
14696 PROCEDURE AcctLineType_51 (
14697   p_application_id        IN NUMBER
14698  ,p_event_id              IN NUMBER
14699  ,p_calculate_acctd_flag  IN VARCHAR2
14700  ,p_calculate_g_l_flag    IN VARCHAR2
14701  ,p_actual_flag           IN OUT VARCHAR2
14702  ,p_balance_type_code     OUT VARCHAR2
14706  , p_source_4            IN NUMBER
14703  ,p_gain_or_loss_ref      OUT VARCHAR2
14704  
14705 --Transaction Distribution GL Account
14707 --Bill To Customer Account Identifier
14708  , p_source_30            IN NUMBER
14709 --Bill To Customer Site Use Identifier
14710  , p_source_31            IN NUMBER
14711 --SLA Party Type
14712  , p_source_32            IN VARCHAR2
14713 --Transaction Distribution Account Class
14714  , p_source_33            IN VARCHAR2
14715 --Transaction Distribution Identifier
14716  , p_source_34            IN NUMBER
14717 --Transaction Distribution Type
14718  , p_source_35            IN VARCHAR2
14719 --Transaction Distribution Entered Amount
14720  , p_source_36            IN NUMBER
14721 --Transaction Currency Code
14722  , p_source_37            IN VARCHAR2
14723 --Transaction Exchange Date
14724  , p_source_38            IN DATE
14725 --Transaction Exchange Rate
14726  , p_source_39            IN NUMBER
14727 --Transaction Exchange Rate Type
14728  , p_source_40            IN VARCHAR2
14729 --Transaction Accounting Amount
14730  , p_source_41            IN NUMBER
14731 )
14732 IS
14733 
14734 l_component_type              VARCHAR2(80);
14735 l_component_code              VARCHAR2(30);
14736 l_component_type_code         VARCHAR2(1);
14737 l_component_appl_id           INTEGER;
14738 l_amb_context_code            VARCHAR2(30);
14739 l_entity_code                 VARCHAR2(30);
14740 l_event_class_code            VARCHAR2(30);
14741 l_ae_header_id                NUMBER;
14742 l_event_type_code             VARCHAR2(30);
14743 l_line_definition_code        VARCHAR2(30);
14744 l_line_definition_owner_code  VARCHAR2(1);
14745 --
14746 -- adr variables
14747 l_segment                     VARCHAR2(30);
14748 l_ccid                        NUMBER;
14749 l_adr_transaction_coa_id      NUMBER;
14750 l_adr_accounting_coa_id       NUMBER;
14751 l_adr_flexfield_segment_code  VARCHAR2(30);
14752 l_adr_flex_value_set_id       NUMBER;
14753 l_adr_value_type_code         VARCHAR2(30);
14754 l_adr_value_combination_id    NUMBER;
14755 l_adr_value_segment_code      VARCHAR2(30);
14756 
14757 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
14758 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
14759 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
14760 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
14761 
14762 -- 4262811 Variables ------------------------------------------------------------------------------------------
14763 l_entered_amt_idx             NUMBER;
14764 l_accted_amt_idx              NUMBER;
14765 l_acc_rev_flag                VARCHAR2(1);
14766 l_accrual_line_num            NUMBER;
14767 l_tmp_amt                     NUMBER;
14768 l_acc_rev_natural_side_code   VARCHAR2(1);
14769 
14770 l_num_entries                 NUMBER;
14771 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
14772 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
14773 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
14774 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
14775 l_recog_line_1                NUMBER;
14776 l_recog_line_2                NUMBER;
14777 
14778 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
14779 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
14780 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
14781 
14782 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
14783 
14784 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
14785 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
14786 
14787 ---------------------------------------------------------------------------------------------------------------
14788 
14789 
14790 --
14791 -- bulk performance
14792 --
14793 l_balance_type_code           VARCHAR2(1);
14794 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
14795 l_log_module                  VARCHAR2(240);
14796 
14797 --
14798 -- Upgrade strategy
14799 --
14800 l_actual_upg_option           VARCHAR2(1);
14801 l_enc_upg_option           VARCHAR2(1);
14802 
14803 --
14804 BEGIN
14805 --
14806 IF g_log_enabled THEN
14807       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_51';
14808 END IF;
14809 --
14810 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14811 
14812       trace
14813          (p_msg      => 'BEGIN of AcctLineType_51'
14814          ,p_level    => C_LEVEL_PROCEDURE
14815          ,p_module   => l_log_module);
14816 
14817 END IF;
14818 --
14819 l_component_type             := 'AMB_JLT';
14820 l_component_code             := 'DEP_OFFSET';
14821 l_component_type_code        := 'S';
14822 l_component_appl_id          :=  222;
14823 l_amb_context_code           := 'DEFAULT';
14824 l_entity_code                := 'TRANSACTIONS';
14825 l_event_class_code           := 'DEPOSIT';
14826 l_event_type_code            := 'DEPOSIT_ALL';
14827 l_line_definition_owner_code := 'S';
14828 l_line_definition_code       := 'AR_DEP_DEFAULT_ACCRUAL';
14829 --
14830 l_balance_type_code          := 'A';
14831 l_segment                     := NULL;
14832 l_ccid                        := NULL;
14833 l_adr_transaction_coa_id      := NULL;
14837 l_adr_value_type_code         := NULL;
14834 l_adr_accounting_coa_id       := NULL;
14835 l_adr_flexfield_segment_code  := NULL;
14836 l_adr_flex_value_set_id       := NULL;
14838 l_adr_value_combination_id    := NULL;
14839 l_adr_value_segment_code      := NULL;
14840 
14841 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
14842 l_bflow_class_code           := '';    -- 4219869 Business Flow
14843 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
14844 l_budgetary_control_flag     := 'N';
14845 
14846 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
14847 l_bflow_applied_to_amt       := NULL; -- 5132302
14848 l_entered_amt_idx            := NULL;          -- 4262811
14849 l_accted_amt_idx             := NULL;          -- 4262811
14850 l_acc_rev_flag               := NULL;          -- 4262811
14851 l_accrual_line_num           := NULL;          -- 4262811
14852 l_tmp_amt                    := NULL;          -- 4262811
14853 --
14854  
14855 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
14856     l_balance_type_code <> 'B' THEN
14857 IF NVL(p_source_33,'
14858 ') =  'REV'
14859  THEN 
14860 
14861    --
14862    XLA_AE_LINES_PKG.SetNewLine;
14863 
14864    p_balance_type_code          := l_balance_type_code;
14865    -- set the flag so later we will know whether the gain loss line needs to be created
14866    
14867    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
14868      p_actual_flag :='A';
14869    END IF;
14870 
14871    --
14872    -- bulk performance
14873    --
14874    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
14875                                       p_header_num   => 0); -- 4262811
14876    --
14877    -- set accounting line options
14878    --
14879    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
14880            p_natural_side_code          => 'C'
14881          , p_gain_or_loss_flag          => 'N'
14882          , p_gl_transfer_mode_code      => 'S'
14883          , p_acct_entry_type_code       => 'A'
14884          , p_switch_side_flag           => 'Y'
14885          , p_merge_duplicate_code       => 'A'
14886          );
14887    --
14888    l_acc_rev_natural_side_code := 'D';  -- 4262811
14889    -- 
14890    --
14891    -- set accounting line type info
14892    --
14893    xla_ae_lines_pkg.SetAcctLineType
14894       (p_component_type             => l_component_type
14895       ,p_event_type_code            => l_event_type_code
14896       ,p_line_definition_owner_code => l_line_definition_owner_code
14897       ,p_line_definition_code       => l_line_definition_code
14898       ,p_accounting_line_code       => l_component_code
14899       ,p_accounting_line_type_code  => l_component_type_code
14900       ,p_accounting_line_appl_id    => l_component_appl_id
14901       ,p_amb_context_code           => l_amb_context_code
14902       ,p_entity_code                => l_entity_code
14903       ,p_event_class_code           => l_event_class_code);
14904    --
14905    -- set accounting class
14906    --
14907    xla_ae_lines_pkg.SetAcctClass(
14908            p_accounting_class_code  => 'ACCRUAL'
14909          , p_ae_header_id           => l_ae_header_id
14910          );
14911 
14912    --
14913    -- set rounding class
14914    --
14915    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
14916                       'RECEIVABLE';
14917 
14918    --
14919    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
14920    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
14921    --
14922    -- bulk performance
14923    --
14924    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
14925 
14926    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
14927       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
14928 
14929    -- 4955764
14930    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
14931       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
14932 
14933    -- 4458381 Public Sector Enh
14934    
14935    --
14936    -- set accounting attributes for the line type
14937    --
14938    l_entered_amt_idx := 3;
14939    l_accted_amt_idx  := 8;
14940    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
14941    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
14942    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
14943    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
14944    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
14945    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
14946    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
14947    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
14948    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
14949    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
14950    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
14951    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
14952    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
14953    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
14954    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
14958    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
14955    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
14956    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
14957    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
14959    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
14960    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
14961    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
14962    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
14963 
14964    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
14965    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
14966 
14967    ---------------------------------------------------------------------------------------------------------------
14968    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
14969    ---------------------------------------------------------------------------------------------------------------
14970    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
14971 
14972    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
14973    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
14974 
14975    IF xla_accounting_cache_pkg.GetValueChar
14976          (p_source_code         => 'LEDGER_CATEGORY_CODE'
14977          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
14978    AND l_bflow_method_code = 'PRIOR_ENTRY'
14979 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
14980    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
14981          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
14982        )
14983    THEN
14984          xla_ae_lines_pkg.BflowUpgEntry
14985            (p_business_method_code    => l_bflow_method_code
14986            ,p_business_class_code     => l_bflow_class_code
14987            ,p_balance_type            => l_balance_type_code);
14988    ELSE
14989       NULL;
14990 -- No business flow processing for business flow method of NONE.
14991    END IF;
14992 
14993    --
14994    -- call analytical criteria
14995    --
14996    
14997    --
14998    -- call description
14999    --
15000    -- No description or it is inherited.
15001    --
15002    -- call ADRs
15003    -- Bug 4922099
15004    --
15005    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
15006         (NVL(l_actual_upg_option, 'N') = 'O') OR
15007         (NVL(l_enc_upg_option, 'N') = 'O')
15008       )
15009    THEN
15010    NULL;
15011    --
15012    --
15013    
15014   l_ccid := AcctDerRule_32(
15015            p_application_id           => p_application_id
15016          , p_ae_header_id             => l_ae_header_id 
15017 , p_source_4 => p_source_4
15018          , x_transaction_coa_id       => l_adr_transaction_coa_id
15019          , x_accounting_coa_id        => l_adr_accounting_coa_id
15020          , x_value_type_code          => l_adr_value_type_code
15021          , p_side                     => 'NA'
15022    );
15023 
15024    xla_ae_lines_pkg.set_ccid(
15025     p_code_combination_id          => l_ccid
15026   , p_value_type_code              => l_adr_value_type_code
15027   , p_transaction_coa_id           => l_adr_transaction_coa_id
15028   , p_accounting_coa_id            => l_adr_accounting_coa_id
15029   , p_adr_code                     => 'TRX_DIST_CCID'
15030   , p_adr_type_code                => 'S'
15031   , p_component_type               => l_component_type
15032   , p_component_code               => l_component_code
15033   , p_component_type_code          => l_component_type_code
15034   , p_component_appl_id            => l_component_appl_id
15035   , p_amb_context_code             => l_amb_context_code
15036   , p_side                         => 'NA'
15037   );
15038 
15039 
15040    --
15041    --
15042    END IF;
15043    --
15044    -- Bug 4922099
15045    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
15046           (NVL(l_enc_upg_option, 'N') = 'O')
15047         ) AND
15048         (l_bflow_method_code = 'PRIOR_ENTRY')
15049       )
15050    THEN
15051       IF
15052       --
15053       1 = 2
15054       --
15055       THEN
15056       xla_accounting_err_pkg.build_message
15057                                     (p_appli_s_name            => 'XLA'
15058                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
15059                                     ,p_token_1                 => 'LINE_NUMBER'
15060                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
15061                                     ,p_token_2                 => 'LINE_TYPE_NAME'
15062                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
15063                                                                              l_component_type
15064                                                                             ,l_component_code
15065                                                                             ,l_component_type_code
15066                                                                             ,l_component_appl_id
15067                                                                             ,l_amb_context_code
15068                                                                             ,l_entity_code
15072                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
15069                                                                             ,l_event_class_code
15070                                                                            )
15071                                     ,p_token_3                 => 'OWNER'
15073                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
15074                                                                           ,p_lookup_code    => l_component_type_code
15075                                                                          )
15076                                     ,p_token_4                 => 'PRODUCT_NAME'
15077                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
15078                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
15079                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
15080                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
15081                                     ,p_ae_header_id            =>  NULL
15082                                        );
15083 
15084         IF (C_LEVEL_ERROR>= g_log_level) THEN
15085                  trace
15086                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
15087                       ,p_level    => C_LEVEL_ERROR
15088                       ,p_module   => l_log_module);
15089         END IF;
15090       END IF;
15091    END IF;
15092    --
15093    --
15094    ------------------------------------------------------------------------------------------------
15095    -- 4219869 Business Flow
15096    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
15097    -- Prior Entry.  Currently, the following code is always generated.
15098    ------------------------------------------------------------------------------------------------
15099    XLA_AE_LINES_PKG.ValidateCurrentLine;
15100 
15101    ------------------------------------------------------------------------------------
15102    -- 4219869 Business Flow
15103    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
15104    ------------------------------------------------------------------------------------
15105    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
15106 
15107    ----------------------------------------------------------------------------------
15108    -- 4219869 Business Flow
15109    -- Update journal entry status -- Need to generate this within IF <condition>
15110    ----------------------------------------------------------------------------------
15111    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
15112          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
15113          ,p_balance_type_code => l_balance_type_code
15114          );
15115 
15116    -------------------------------------------------------------------------------------------
15117    -- 4262811 - Generate the Accrual Reversal lines
15118    -------------------------------------------------------------------------------------------
15119    BEGIN
15120       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
15121                               (g_array_event(p_event_id).array_value_num('header_index'));
15122       IF l_acc_rev_flag IS NULL THEN
15123          l_acc_rev_flag := 'N';
15124       END IF;
15125    EXCEPTION
15126       WHEN OTHERS THEN
15127          l_acc_rev_flag := 'N';
15128    END;
15129    --
15130    IF (l_acc_rev_flag = 'Y') THEN
15131 
15132        -- 4645092  ------------------------------------------------------------------------------
15133        -- To allow MPA report to determine if it should generate report process
15134        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
15135        ------------------------------------------------------------------------------------------
15136 
15137        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
15138        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
15139    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
15140    -- call ADRs
15141    -- Bug 4922099
15142    --
15143    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
15144         (NVL(l_actual_upg_option, 'N') = 'O') OR
15145         (NVL(l_enc_upg_option, 'N') = 'O')
15146       )
15147    THEN
15148    NULL;
15149    --
15150    --
15151    
15152   l_ccid := AcctDerRule_32(
15153            p_application_id           => p_application_id
15154          , p_ae_header_id             => l_ae_header_id 
15155 , p_source_4 => p_source_4
15156          , x_transaction_coa_id       => l_adr_transaction_coa_id
15157          , x_accounting_coa_id        => l_adr_accounting_coa_id
15158          , x_value_type_code          => l_adr_value_type_code
15159          , p_side                     => 'NA'
15160    );
15161 
15162    xla_ae_lines_pkg.set_ccid(
15163     p_code_combination_id          => l_ccid
15164   , p_value_type_code              => l_adr_value_type_code
15165   , p_transaction_coa_id           => l_adr_transaction_coa_id
15166   , p_accounting_coa_id            => l_adr_accounting_coa_id
15167   , p_adr_code                     => 'TRX_DIST_CCID'
15168   , p_adr_type_code                => 'S'
15169   , p_component_type               => l_component_type
15170   , p_component_code               => l_component_code
15174   , p_side                         => 'NA'
15171   , p_component_type_code          => l_component_type_code
15172   , p_component_appl_id            => l_component_appl_id
15173   , p_amb_context_code             => l_amb_context_code
15175   );
15176 
15177 
15178    --
15179    --
15180    END IF;
15181 
15182        --
15183        -- Update the line information that should be overwritten
15184        --
15185        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
15186                                          p_header_num   => 1);
15187        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
15188 
15189        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
15190 
15191        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
15192           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
15193        END IF;
15194 
15195       --
15196       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
15197       --
15198       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
15199           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
15200       ELSE
15201           ---------------------------------------------------------------------------------------------------
15202           -- 4262811a Switch Sign
15203           ---------------------------------------------------------------------------------------------------
15204           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
15205           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
15206                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15207           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
15208                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15209           -- 5132302
15210           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
15211                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15212 
15213       END IF;
15214 
15215       -- 4955764
15216       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
15217       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
15218 
15219 
15220       XLA_AE_LINES_PKG.ValidateCurrentLine;
15221       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
15222 
15223       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
15224                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
15225                ,p_balance_type_code => l_balance_type_code);
15226 
15227    END IF;
15228 
15229    -----------------------------------------------------------------------------------------
15230    -- 4262811 Multiperiod Accounting
15231    -----------------------------------------------------------------------------------------
15232      -- No MPA option is assigned.
15233 
15234 
15235 END IF;
15236 END IF;
15237 --
15238 
15239 --
15240 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15241    trace
15242       (p_msg      => 'END of AcctLineType_51'
15243       ,p_level    => C_LEVEL_PROCEDURE
15244       ,p_module   => l_log_module);
15245 END IF;
15246 --
15247 EXCEPTION
15248   WHEN xla_exceptions_pkg.application_exception THEN
15249       RAISE;
15250   WHEN OTHERS THEN
15251        xla_exceptions_pkg.raise_message
15252            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_51');
15253 END AcctLineType_51;
15254 --
15255 
15256 ---------------------------------------
15257 --
15258 -- PRIVATE FUNCTION
15259 --         AcctLineType_52
15260 --
15261 ---------------------------------------
15262 PROCEDURE AcctLineType_52 (
15263   p_application_id        IN NUMBER
15264  ,p_event_id              IN NUMBER
15265  ,p_calculate_acctd_flag  IN VARCHAR2
15266  ,p_calculate_g_l_flag    IN VARCHAR2
15267  ,p_actual_flag           IN OUT VARCHAR2
15268  ,p_balance_type_code     OUT VARCHAR2
15269  ,p_gain_or_loss_ref      OUT VARCHAR2
15270  
15271 --Transaction Distribution GL Account
15272  , p_source_4            IN NUMBER
15273 --Bill To Customer Account Identifier
15274  , p_source_30            IN NUMBER
15275 --Bill To Customer Site Use Identifier
15276  , p_source_31            IN NUMBER
15277 --SLA Party Type
15278  , p_source_32            IN VARCHAR2
15279 --Transaction Distribution Account Class
15280  , p_source_33            IN VARCHAR2
15281 --Transaction Distribution Identifier
15282  , p_source_34            IN NUMBER
15283 --Transaction Distribution Type
15284  , p_source_35            IN VARCHAR2
15285 --Transaction Distribution Entered Amount
15286  , p_source_36            IN NUMBER
15287 --Transaction Currency Code
15288  , p_source_37            IN VARCHAR2
15289 --Transaction Exchange Date
15290  , p_source_38            IN DATE
15291 --Transaction Exchange Rate
15292  , p_source_39            IN NUMBER
15293 --Transaction Exchange Rate Type
15294  , p_source_40            IN VARCHAR2
15295 --Transaction Accounting Amount
15299 )
15296  , p_source_41            IN NUMBER
15297 --Transaction Tax Line Identifier
15298  , p_source_55            IN NUMBER
15300 IS
15301 
15302 l_component_type              VARCHAR2(80);
15303 l_component_code              VARCHAR2(30);
15304 l_component_type_code         VARCHAR2(1);
15305 l_component_appl_id           INTEGER;
15306 l_amb_context_code            VARCHAR2(30);
15307 l_entity_code                 VARCHAR2(30);
15308 l_event_class_code            VARCHAR2(30);
15309 l_ae_header_id                NUMBER;
15310 l_event_type_code             VARCHAR2(30);
15311 l_line_definition_code        VARCHAR2(30);
15312 l_line_definition_owner_code  VARCHAR2(1);
15313 --
15314 -- adr variables
15315 l_segment                     VARCHAR2(30);
15316 l_ccid                        NUMBER;
15317 l_adr_transaction_coa_id      NUMBER;
15318 l_adr_accounting_coa_id       NUMBER;
15319 l_adr_flexfield_segment_code  VARCHAR2(30);
15320 l_adr_flex_value_set_id       NUMBER;
15321 l_adr_value_type_code         VARCHAR2(30);
15322 l_adr_value_combination_id    NUMBER;
15323 l_adr_value_segment_code      VARCHAR2(30);
15324 
15325 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
15326 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
15327 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
15328 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
15329 
15330 -- 4262811 Variables ------------------------------------------------------------------------------------------
15331 l_entered_amt_idx             NUMBER;
15332 l_accted_amt_idx              NUMBER;
15333 l_acc_rev_flag                VARCHAR2(1);
15334 l_accrual_line_num            NUMBER;
15335 l_tmp_amt                     NUMBER;
15336 l_acc_rev_natural_side_code   VARCHAR2(1);
15337 
15338 l_num_entries                 NUMBER;
15339 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
15340 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
15341 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
15342 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
15343 l_recog_line_1                NUMBER;
15344 l_recog_line_2                NUMBER;
15345 
15346 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
15347 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
15348 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
15349 
15350 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
15351 
15352 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
15353 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
15354 
15355 ---------------------------------------------------------------------------------------------------------------
15356 
15357 
15358 --
15359 -- bulk performance
15360 --
15361 l_balance_type_code           VARCHAR2(1);
15362 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
15363 l_log_module                  VARCHAR2(240);
15364 
15365 --
15366 -- Upgrade strategy
15367 --
15368 l_actual_upg_option           VARCHAR2(1);
15369 l_enc_upg_option           VARCHAR2(1);
15370 
15371 --
15372 BEGIN
15373 --
15374 IF g_log_enabled THEN
15375       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_52';
15376 END IF;
15377 --
15378 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15379 
15380       trace
15381          (p_msg      => 'BEGIN of AcctLineType_52'
15382          ,p_level    => C_LEVEL_PROCEDURE
15383          ,p_module   => l_log_module);
15384 
15385 END IF;
15386 --
15387 l_component_type             := 'AMB_JLT';
15388 l_component_code             := 'DM_CHARGES';
15389 l_component_type_code        := 'S';
15390 l_component_appl_id          :=  222;
15391 l_amb_context_code           := 'DEFAULT';
15392 l_entity_code                := 'TRANSACTIONS';
15393 l_event_class_code           := 'DEBIT_MEMO';
15394 l_event_type_code            := 'DEBIT_MEMO_ALL';
15395 l_line_definition_owner_code := 'S';
15396 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
15397 --
15398 l_balance_type_code          := 'A';
15399 l_segment                     := NULL;
15400 l_ccid                        := NULL;
15401 l_adr_transaction_coa_id      := NULL;
15402 l_adr_accounting_coa_id       := NULL;
15403 l_adr_flexfield_segment_code  := NULL;
15404 l_adr_flex_value_set_id       := NULL;
15405 l_adr_value_type_code         := NULL;
15406 l_adr_value_combination_id    := NULL;
15407 l_adr_value_segment_code      := NULL;
15408 
15409 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
15410 l_bflow_class_code           := '';    -- 4219869 Business Flow
15411 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
15412 l_budgetary_control_flag     := 'N';
15413 
15414 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
15415 l_bflow_applied_to_amt       := NULL; -- 5132302
15416 l_entered_amt_idx            := NULL;          -- 4262811
15417 l_accted_amt_idx             := NULL;          -- 4262811
15418 l_acc_rev_flag               := NULL;          -- 4262811
15419 l_accrual_line_num           := NULL;          -- 4262811
15420 l_tmp_amt                    := NULL;          -- 4262811
15421 --
15422  
15426 ') =  'CHARGES'
15423 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
15424     l_balance_type_code <> 'B' THEN
15425 IF NVL(p_source_33,'
15427  THEN 
15428 
15429    --
15430    XLA_AE_LINES_PKG.SetNewLine;
15431 
15432    p_balance_type_code          := l_balance_type_code;
15433    -- set the flag so later we will know whether the gain loss line needs to be created
15434    
15435    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
15436      p_actual_flag :='A';
15437    END IF;
15438 
15439    --
15440    -- bulk performance
15441    --
15442    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
15443                                       p_header_num   => 0); -- 4262811
15444    --
15445    -- set accounting line options
15446    --
15447    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
15448            p_natural_side_code          => 'C'
15449          , p_gain_or_loss_flag          => 'N'
15450          , p_gl_transfer_mode_code      => 'S'
15451          , p_acct_entry_type_code       => 'A'
15452          , p_switch_side_flag           => 'Y'
15453          , p_merge_duplicate_code       => 'A'
15454          );
15455    --
15456    l_acc_rev_natural_side_code := 'D';  -- 4262811
15457    -- 
15458    --
15459    -- set accounting line type info
15460    --
15461    xla_ae_lines_pkg.SetAcctLineType
15462       (p_component_type             => l_component_type
15463       ,p_event_type_code            => l_event_type_code
15464       ,p_line_definition_owner_code => l_line_definition_owner_code
15465       ,p_line_definition_code       => l_line_definition_code
15466       ,p_accounting_line_code       => l_component_code
15467       ,p_accounting_line_type_code  => l_component_type_code
15468       ,p_accounting_line_appl_id    => l_component_appl_id
15469       ,p_amb_context_code           => l_amb_context_code
15470       ,p_entity_code                => l_entity_code
15471       ,p_event_class_code           => l_event_class_code);
15472    --
15473    -- set accounting class
15474    --
15475    xla_ae_lines_pkg.SetAcctClass(
15476            p_accounting_class_code  => 'CHARGES'
15477          , p_ae_header_id           => l_ae_header_id
15478          );
15479 
15480    --
15481    -- set rounding class
15482    --
15483    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
15484                       'RECEIVABLE';
15485 
15486    --
15487    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
15488    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
15489    --
15490    -- bulk performance
15491    --
15492    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
15493 
15494    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
15495       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
15496 
15497    -- 4955764
15498    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
15499       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
15500 
15501    -- 4458381 Public Sector Enh
15502    
15503    --
15504    -- set accounting attributes for the line type
15505    --
15506    l_entered_amt_idx := 3;
15507    l_accted_amt_idx  := 8;
15508    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
15509    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
15510    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
15511    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
15512    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
15513    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
15514    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
15515    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
15516    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
15517    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
15518    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
15519    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
15520    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
15521    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
15522    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
15523    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
15524    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
15525    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
15526    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
15527    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
15528    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
15529    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
15530    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
15531    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
15532    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
15533 
15534    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
15535    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
15536 
15537    ---------------------------------------------------------------------------------------------------------------
15541 
15538    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
15539    ---------------------------------------------------------------------------------------------------------------
15540    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
15542    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
15543    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
15544 
15545    IF xla_accounting_cache_pkg.GetValueChar
15546          (p_source_code         => 'LEDGER_CATEGORY_CODE'
15547          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
15548    AND l_bflow_method_code = 'PRIOR_ENTRY'
15549 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
15550    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
15551          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
15552        )
15553    THEN
15554          xla_ae_lines_pkg.BflowUpgEntry
15555            (p_business_method_code    => l_bflow_method_code
15556            ,p_business_class_code     => l_bflow_class_code
15557            ,p_balance_type            => l_balance_type_code);
15558    ELSE
15559       NULL;
15560 -- No business flow processing for business flow method of NONE.
15561    END IF;
15562 
15563    --
15564    -- call analytical criteria
15565    --
15566    
15567    --
15568    -- call description
15569    --
15570    -- No description or it is inherited.
15571    --
15572    -- call ADRs
15573    -- Bug 4922099
15574    --
15575    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
15576         (NVL(l_actual_upg_option, 'N') = 'O') OR
15577         (NVL(l_enc_upg_option, 'N') = 'O')
15578       )
15579    THEN
15580    NULL;
15581    --
15582    --
15583    
15584   l_ccid := AcctDerRule_32(
15585            p_application_id           => p_application_id
15586          , p_ae_header_id             => l_ae_header_id 
15587 , p_source_4 => p_source_4
15588          , x_transaction_coa_id       => l_adr_transaction_coa_id
15589          , x_accounting_coa_id        => l_adr_accounting_coa_id
15590          , x_value_type_code          => l_adr_value_type_code
15591          , p_side                     => 'NA'
15592    );
15593 
15594    xla_ae_lines_pkg.set_ccid(
15595     p_code_combination_id          => l_ccid
15596   , p_value_type_code              => l_adr_value_type_code
15597   , p_transaction_coa_id           => l_adr_transaction_coa_id
15598   , p_accounting_coa_id            => l_adr_accounting_coa_id
15599   , p_adr_code                     => 'TRX_DIST_CCID'
15600   , p_adr_type_code                => 'S'
15601   , p_component_type               => l_component_type
15602   , p_component_code               => l_component_code
15603   , p_component_type_code          => l_component_type_code
15604   , p_component_appl_id            => l_component_appl_id
15605   , p_amb_context_code             => l_amb_context_code
15606   , p_side                         => 'NA'
15607   );
15608 
15609 
15610    --
15611    --
15612    END IF;
15613    --
15614    -- Bug 4922099
15615    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
15616           (NVL(l_enc_upg_option, 'N') = 'O')
15617         ) AND
15618         (l_bflow_method_code = 'PRIOR_ENTRY')
15619       )
15620    THEN
15621       IF
15622       --
15623       1 = 2
15624       --
15625       THEN
15626       xla_accounting_err_pkg.build_message
15627                                     (p_appli_s_name            => 'XLA'
15628                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
15629                                     ,p_token_1                 => 'LINE_NUMBER'
15630                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
15631                                     ,p_token_2                 => 'LINE_TYPE_NAME'
15632                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
15633                                                                              l_component_type
15634                                                                             ,l_component_code
15635                                                                             ,l_component_type_code
15636                                                                             ,l_component_appl_id
15637                                                                             ,l_amb_context_code
15638                                                                             ,l_entity_code
15639                                                                             ,l_event_class_code
15640                                                                            )
15641                                     ,p_token_3                 => 'OWNER'
15642                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
15643                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
15644                                                                           ,p_lookup_code    => l_component_type_code
15645                                                                          )
15646                                     ,p_token_4                 => 'PRODUCT_NAME'
15647                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
15651                                     ,p_ae_header_id            =>  NULL
15648                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
15649                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
15650                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
15652                                        );
15653 
15654         IF (C_LEVEL_ERROR>= g_log_level) THEN
15655                  trace
15656                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
15657                       ,p_level    => C_LEVEL_ERROR
15658                       ,p_module   => l_log_module);
15659         END IF;
15660       END IF;
15661    END IF;
15662    --
15663    --
15664    ------------------------------------------------------------------------------------------------
15665    -- 4219869 Business Flow
15666    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
15667    -- Prior Entry.  Currently, the following code is always generated.
15668    ------------------------------------------------------------------------------------------------
15669    XLA_AE_LINES_PKG.ValidateCurrentLine;
15670 
15671    ------------------------------------------------------------------------------------
15672    -- 4219869 Business Flow
15673    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
15674    ------------------------------------------------------------------------------------
15675    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
15676 
15677    ----------------------------------------------------------------------------------
15678    -- 4219869 Business Flow
15679    -- Update journal entry status -- Need to generate this within IF <condition>
15680    ----------------------------------------------------------------------------------
15681    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
15682          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
15683          ,p_balance_type_code => l_balance_type_code
15684          );
15685 
15686    -------------------------------------------------------------------------------------------
15687    -- 4262811 - Generate the Accrual Reversal lines
15688    -------------------------------------------------------------------------------------------
15689    BEGIN
15690       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
15691                               (g_array_event(p_event_id).array_value_num('header_index'));
15692       IF l_acc_rev_flag IS NULL THEN
15693          l_acc_rev_flag := 'N';
15694       END IF;
15695    EXCEPTION
15696       WHEN OTHERS THEN
15697          l_acc_rev_flag := 'N';
15698    END;
15699    --
15700    IF (l_acc_rev_flag = 'Y') THEN
15701 
15702        -- 4645092  ------------------------------------------------------------------------------
15703        -- To allow MPA report to determine if it should generate report process
15704        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
15705        ------------------------------------------------------------------------------------------
15706 
15707        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
15708        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
15709    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
15710    -- call ADRs
15711    -- Bug 4922099
15712    --
15713    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
15714         (NVL(l_actual_upg_option, 'N') = 'O') OR
15715         (NVL(l_enc_upg_option, 'N') = 'O')
15716       )
15717    THEN
15718    NULL;
15719    --
15720    --
15721    
15722   l_ccid := AcctDerRule_32(
15723            p_application_id           => p_application_id
15724          , p_ae_header_id             => l_ae_header_id 
15725 , p_source_4 => p_source_4
15726          , x_transaction_coa_id       => l_adr_transaction_coa_id
15727          , x_accounting_coa_id        => l_adr_accounting_coa_id
15728          , x_value_type_code          => l_adr_value_type_code
15729          , p_side                     => 'NA'
15730    );
15731 
15732    xla_ae_lines_pkg.set_ccid(
15733     p_code_combination_id          => l_ccid
15734   , p_value_type_code              => l_adr_value_type_code
15735   , p_transaction_coa_id           => l_adr_transaction_coa_id
15736   , p_accounting_coa_id            => l_adr_accounting_coa_id
15737   , p_adr_code                     => 'TRX_DIST_CCID'
15738   , p_adr_type_code                => 'S'
15739   , p_component_type               => l_component_type
15740   , p_component_code               => l_component_code
15741   , p_component_type_code          => l_component_type_code
15742   , p_component_appl_id            => l_component_appl_id
15743   , p_amb_context_code             => l_amb_context_code
15744   , p_side                         => 'NA'
15745   );
15746 
15747 
15748    --
15749    --
15750    END IF;
15751 
15752        --
15753        -- Update the line information that should be overwritten
15754        --
15755        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
15756                                          p_header_num   => 1);
15757        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
15758 
15759        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
15760 
15764 
15761        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
15762           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
15763        END IF;
15765       --
15766       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
15767       --
15768       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
15769           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
15770       ELSE
15771           ---------------------------------------------------------------------------------------------------
15772           -- 4262811a Switch Sign
15773           ---------------------------------------------------------------------------------------------------
15774           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
15775           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
15776                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15777           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
15778                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15779           -- 5132302
15780           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
15781                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15782 
15783       END IF;
15784 
15785       -- 4955764
15786       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
15787       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
15788 
15789 
15790       XLA_AE_LINES_PKG.ValidateCurrentLine;
15791       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
15792 
15793       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
15794                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
15795                ,p_balance_type_code => l_balance_type_code);
15796 
15797    END IF;
15798 
15799    -----------------------------------------------------------------------------------------
15800    -- 4262811 Multiperiod Accounting
15801    -----------------------------------------------------------------------------------------
15802      -- No MPA option is assigned.
15803 
15804 
15805 END IF;
15806 END IF;
15807 --
15808 
15809 --
15810 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15811    trace
15812       (p_msg      => 'END of AcctLineType_52'
15813       ,p_level    => C_LEVEL_PROCEDURE
15814       ,p_module   => l_log_module);
15815 END IF;
15816 --
15817 EXCEPTION
15818   WHEN xla_exceptions_pkg.application_exception THEN
15819       RAISE;
15820   WHEN OTHERS THEN
15821        xla_exceptions_pkg.raise_message
15822            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_52');
15823 END AcctLineType_52;
15824 --
15825 
15826 ---------------------------------------
15827 --
15828 -- PRIVATE FUNCTION
15829 --         AcctLineType_53
15830 --
15831 ---------------------------------------
15832 PROCEDURE AcctLineType_53 (
15833   p_application_id        IN NUMBER
15834  ,p_event_id              IN NUMBER
15835  ,p_calculate_acctd_flag  IN VARCHAR2
15836  ,p_calculate_g_l_flag    IN VARCHAR2
15837  ,p_actual_flag           IN OUT VARCHAR2
15838  ,p_balance_type_code     OUT VARCHAR2
15839  ,p_gain_or_loss_ref      OUT VARCHAR2
15840  
15841 --Transaction Distribution GL Account
15842  , p_source_4            IN NUMBER
15843 --Bill To Customer Account Identifier
15844  , p_source_30            IN NUMBER
15845 --Bill To Customer Site Use Identifier
15846  , p_source_31            IN NUMBER
15847 --SLA Party Type
15848  , p_source_32            IN VARCHAR2
15849 --Transaction Distribution Account Class
15850  , p_source_33            IN VARCHAR2
15851 --Transaction Distribution Identifier
15852  , p_source_34            IN NUMBER
15853 --Transaction Distribution Type
15854  , p_source_35            IN VARCHAR2
15855 --Transaction Distribution Entered Amount
15856  , p_source_36            IN NUMBER
15857 --Transaction Currency Code
15858  , p_source_37            IN VARCHAR2
15859 --Transaction Exchange Date
15860  , p_source_38            IN DATE
15861 --Transaction Exchange Rate
15862  , p_source_39            IN NUMBER
15863 --Transaction Exchange Rate Type
15864  , p_source_40            IN VARCHAR2
15865 --Transaction Accounting Amount
15866  , p_source_41            IN NUMBER
15867 --Transaction Tax Line Identifier
15868  , p_source_55            IN NUMBER
15869 )
15870 IS
15871 
15872 l_component_type              VARCHAR2(80);
15873 l_component_code              VARCHAR2(30);
15874 l_component_type_code         VARCHAR2(1);
15875 l_component_appl_id           INTEGER;
15876 l_amb_context_code            VARCHAR2(30);
15877 l_entity_code                 VARCHAR2(30);
15878 l_event_class_code            VARCHAR2(30);
15879 l_ae_header_id                NUMBER;
15880 l_event_type_code             VARCHAR2(30);
15881 l_line_definition_code        VARCHAR2(30);
15882 l_line_definition_owner_code  VARCHAR2(1);
15883 --
15884 -- adr variables
15888 l_adr_accounting_coa_id       NUMBER;
15885 l_segment                     VARCHAR2(30);
15886 l_ccid                        NUMBER;
15887 l_adr_transaction_coa_id      NUMBER;
15889 l_adr_flexfield_segment_code  VARCHAR2(30);
15890 l_adr_flex_value_set_id       NUMBER;
15891 l_adr_value_type_code         VARCHAR2(30);
15892 l_adr_value_combination_id    NUMBER;
15893 l_adr_value_segment_code      VARCHAR2(30);
15894 
15895 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
15896 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
15897 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
15898 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
15899 
15900 -- 4262811 Variables ------------------------------------------------------------------------------------------
15901 l_entered_amt_idx             NUMBER;
15902 l_accted_amt_idx              NUMBER;
15903 l_acc_rev_flag                VARCHAR2(1);
15904 l_accrual_line_num            NUMBER;
15905 l_tmp_amt                     NUMBER;
15906 l_acc_rev_natural_side_code   VARCHAR2(1);
15907 
15908 l_num_entries                 NUMBER;
15909 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
15910 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
15911 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
15912 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
15913 l_recog_line_1                NUMBER;
15914 l_recog_line_2                NUMBER;
15915 
15916 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
15917 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
15918 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
15919 
15920 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
15921 
15922 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
15923 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
15924 
15925 ---------------------------------------------------------------------------------------------------------------
15926 
15927 
15928 --
15929 -- bulk performance
15930 --
15931 l_balance_type_code           VARCHAR2(1);
15932 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
15933 l_log_module                  VARCHAR2(240);
15934 
15935 --
15936 -- Upgrade strategy
15937 --
15938 l_actual_upg_option           VARCHAR2(1);
15939 l_enc_upg_option           VARCHAR2(1);
15940 
15941 --
15942 BEGIN
15943 --
15944 IF g_log_enabled THEN
15945       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_53';
15946 END IF;
15947 --
15948 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15949 
15950       trace
15951          (p_msg      => 'BEGIN of AcctLineType_53'
15952          ,p_level    => C_LEVEL_PROCEDURE
15953          ,p_module   => l_log_module);
15954 
15955 END IF;
15956 --
15957 l_component_type             := 'AMB_JLT';
15958 l_component_code             := 'DM_FREIGHT';
15959 l_component_type_code        := 'S';
15960 l_component_appl_id          :=  222;
15961 l_amb_context_code           := 'DEFAULT';
15962 l_entity_code                := 'TRANSACTIONS';
15963 l_event_class_code           := 'DEBIT_MEMO';
15964 l_event_type_code            := 'DEBIT_MEMO_ALL';
15965 l_line_definition_owner_code := 'S';
15966 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
15967 --
15968 l_balance_type_code          := 'A';
15969 l_segment                     := NULL;
15970 l_ccid                        := NULL;
15971 l_adr_transaction_coa_id      := NULL;
15972 l_adr_accounting_coa_id       := NULL;
15973 l_adr_flexfield_segment_code  := NULL;
15974 l_adr_flex_value_set_id       := NULL;
15975 l_adr_value_type_code         := NULL;
15976 l_adr_value_combination_id    := NULL;
15977 l_adr_value_segment_code      := NULL;
15978 
15979 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
15980 l_bflow_class_code           := '';    -- 4219869 Business Flow
15981 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
15982 l_budgetary_control_flag     := 'N';
15983 
15984 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
15985 l_bflow_applied_to_amt       := NULL; -- 5132302
15986 l_entered_amt_idx            := NULL;          -- 4262811
15987 l_accted_amt_idx             := NULL;          -- 4262811
15988 l_acc_rev_flag               := NULL;          -- 4262811
15989 l_accrual_line_num           := NULL;          -- 4262811
15990 l_tmp_amt                    := NULL;          -- 4262811
15991 --
15992  
15993 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
15994     l_balance_type_code <> 'B' THEN
15995 IF NVL(p_source_33,'
15996 ') =  'FREIGHT'
15997  THEN 
15998 
15999    --
16000    XLA_AE_LINES_PKG.SetNewLine;
16001 
16002    p_balance_type_code          := l_balance_type_code;
16003    -- set the flag so later we will know whether the gain loss line needs to be created
16004    
16005    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
16006      p_actual_flag :='A';
16007    END IF;
16008 
16009    --
16010    -- bulk performance
16011    --
16012    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
16016    --
16013                                       p_header_num   => 0); -- 4262811
16014    --
16015    -- set accounting line options
16017    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
16018            p_natural_side_code          => 'C'
16019          , p_gain_or_loss_flag          => 'N'
16020          , p_gl_transfer_mode_code      => 'S'
16021          , p_acct_entry_type_code       => 'A'
16022          , p_switch_side_flag           => 'Y'
16023          , p_merge_duplicate_code       => 'A'
16024          );
16025    --
16026    l_acc_rev_natural_side_code := 'D';  -- 4262811
16027    -- 
16028    --
16029    -- set accounting line type info
16030    --
16031    xla_ae_lines_pkg.SetAcctLineType
16032       (p_component_type             => l_component_type
16033       ,p_event_type_code            => l_event_type_code
16034       ,p_line_definition_owner_code => l_line_definition_owner_code
16035       ,p_line_definition_code       => l_line_definition_code
16036       ,p_accounting_line_code       => l_component_code
16037       ,p_accounting_line_type_code  => l_component_type_code
16038       ,p_accounting_line_appl_id    => l_component_appl_id
16039       ,p_amb_context_code           => l_amb_context_code
16040       ,p_entity_code                => l_entity_code
16041       ,p_event_class_code           => l_event_class_code);
16042    --
16043    -- set accounting class
16044    --
16045    xla_ae_lines_pkg.SetAcctClass(
16046            p_accounting_class_code  => 'FREIGHT'
16047          , p_ae_header_id           => l_ae_header_id
16048          );
16049 
16050    --
16051    -- set rounding class
16052    --
16053    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
16054                       'RECEIVABLE';
16055 
16056    --
16057    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
16058    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
16059    --
16060    -- bulk performance
16061    --
16062    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
16063 
16064    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
16065       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
16066 
16067    -- 4955764
16068    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
16069       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
16070 
16071    -- 4458381 Public Sector Enh
16072    
16073    --
16074    -- set accounting attributes for the line type
16075    --
16076    l_entered_amt_idx := 3;
16077    l_accted_amt_idx  := 8;
16078    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
16079    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
16080    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
16081    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
16082    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
16083    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
16084    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
16085    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
16086    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
16087    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
16088    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
16089    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
16090    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
16091    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
16092    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
16093    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
16094    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
16095    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
16096    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
16097    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
16098    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
16099    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
16100    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
16101    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
16102    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
16103 
16104    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
16105    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
16106 
16107    ---------------------------------------------------------------------------------------------------------------
16108    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
16109    ---------------------------------------------------------------------------------------------------------------
16110    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
16111 
16112    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
16113    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
16114 
16115    IF xla_accounting_cache_pkg.GetValueChar
16116          (p_source_code         => 'LEDGER_CATEGORY_CODE'
16117          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
16118    AND l_bflow_method_code = 'PRIOR_ENTRY'
16122        )
16119 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
16120    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
16121          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
16123    THEN
16124          xla_ae_lines_pkg.BflowUpgEntry
16125            (p_business_method_code    => l_bflow_method_code
16126            ,p_business_class_code     => l_bflow_class_code
16127            ,p_balance_type            => l_balance_type_code);
16128    ELSE
16129       NULL;
16130 -- No business flow processing for business flow method of NONE.
16131    END IF;
16132 
16133    --
16134    -- call analytical criteria
16135    --
16136    
16137    --
16138    -- call description
16139    --
16140    -- No description or it is inherited.
16141    --
16142    -- call ADRs
16143    -- Bug 4922099
16144    --
16145    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
16146         (NVL(l_actual_upg_option, 'N') = 'O') OR
16147         (NVL(l_enc_upg_option, 'N') = 'O')
16148       )
16149    THEN
16150    NULL;
16151    --
16152    --
16153    
16154   l_ccid := AcctDerRule_32(
16155            p_application_id           => p_application_id
16156          , p_ae_header_id             => l_ae_header_id 
16157 , p_source_4 => p_source_4
16158          , x_transaction_coa_id       => l_adr_transaction_coa_id
16159          , x_accounting_coa_id        => l_adr_accounting_coa_id
16160          , x_value_type_code          => l_adr_value_type_code
16161          , p_side                     => 'NA'
16162    );
16163 
16164    xla_ae_lines_pkg.set_ccid(
16165     p_code_combination_id          => l_ccid
16166   , p_value_type_code              => l_adr_value_type_code
16167   , p_transaction_coa_id           => l_adr_transaction_coa_id
16168   , p_accounting_coa_id            => l_adr_accounting_coa_id
16169   , p_adr_code                     => 'TRX_DIST_CCID'
16170   , p_adr_type_code                => 'S'
16171   , p_component_type               => l_component_type
16172   , p_component_code               => l_component_code
16173   , p_component_type_code          => l_component_type_code
16174   , p_component_appl_id            => l_component_appl_id
16175   , p_amb_context_code             => l_amb_context_code
16176   , p_side                         => 'NA'
16177   );
16178 
16179 
16180    --
16181    --
16182    END IF;
16183    --
16184    -- Bug 4922099
16185    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
16186           (NVL(l_enc_upg_option, 'N') = 'O')
16187         ) AND
16188         (l_bflow_method_code = 'PRIOR_ENTRY')
16189       )
16190    THEN
16191       IF
16192       --
16193       1 = 2
16194       --
16195       THEN
16196       xla_accounting_err_pkg.build_message
16197                                     (p_appli_s_name            => 'XLA'
16198                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
16199                                     ,p_token_1                 => 'LINE_NUMBER'
16200                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
16201                                     ,p_token_2                 => 'LINE_TYPE_NAME'
16202                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
16203                                                                              l_component_type
16204                                                                             ,l_component_code
16205                                                                             ,l_component_type_code
16206                                                                             ,l_component_appl_id
16207                                                                             ,l_amb_context_code
16208                                                                             ,l_entity_code
16209                                                                             ,l_event_class_code
16210                                                                            )
16211                                     ,p_token_3                 => 'OWNER'
16212                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
16213                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
16214                                                                           ,p_lookup_code    => l_component_type_code
16215                                                                          )
16216                                     ,p_token_4                 => 'PRODUCT_NAME'
16217                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
16218                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
16219                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
16220                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
16221                                     ,p_ae_header_id            =>  NULL
16222                                        );
16223 
16224         IF (C_LEVEL_ERROR>= g_log_level) THEN
16225                  trace
16226                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
16227                       ,p_level    => C_LEVEL_ERROR
16228                       ,p_module   => l_log_module);
16229         END IF;
16230       END IF;
16231    END IF;
16232    --
16233    --
16237    -- Prior Entry.  Currently, the following code is always generated.
16234    ------------------------------------------------------------------------------------------------
16235    -- 4219869 Business Flow
16236    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
16238    ------------------------------------------------------------------------------------------------
16239    XLA_AE_LINES_PKG.ValidateCurrentLine;
16240 
16241    ------------------------------------------------------------------------------------
16242    -- 4219869 Business Flow
16243    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
16244    ------------------------------------------------------------------------------------
16245    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
16246 
16247    ----------------------------------------------------------------------------------
16248    -- 4219869 Business Flow
16249    -- Update journal entry status -- Need to generate this within IF <condition>
16250    ----------------------------------------------------------------------------------
16251    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
16252          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
16253          ,p_balance_type_code => l_balance_type_code
16254          );
16255 
16256    -------------------------------------------------------------------------------------------
16257    -- 4262811 - Generate the Accrual Reversal lines
16258    -------------------------------------------------------------------------------------------
16259    BEGIN
16260       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
16261                               (g_array_event(p_event_id).array_value_num('header_index'));
16262       IF l_acc_rev_flag IS NULL THEN
16263          l_acc_rev_flag := 'N';
16264       END IF;
16265    EXCEPTION
16266       WHEN OTHERS THEN
16267          l_acc_rev_flag := 'N';
16268    END;
16269    --
16270    IF (l_acc_rev_flag = 'Y') THEN
16271 
16272        -- 4645092  ------------------------------------------------------------------------------
16273        -- To allow MPA report to determine if it should generate report process
16274        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
16275        ------------------------------------------------------------------------------------------
16276 
16277        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
16278        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
16279    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
16280    -- call ADRs
16281    -- Bug 4922099
16282    --
16283    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
16284         (NVL(l_actual_upg_option, 'N') = 'O') OR
16285         (NVL(l_enc_upg_option, 'N') = 'O')
16286       )
16287    THEN
16288    NULL;
16289    --
16290    --
16291    
16292   l_ccid := AcctDerRule_32(
16293            p_application_id           => p_application_id
16294          , p_ae_header_id             => l_ae_header_id 
16295 , p_source_4 => p_source_4
16296          , x_transaction_coa_id       => l_adr_transaction_coa_id
16297          , x_accounting_coa_id        => l_adr_accounting_coa_id
16298          , x_value_type_code          => l_adr_value_type_code
16299          , p_side                     => 'NA'
16300    );
16301 
16302    xla_ae_lines_pkg.set_ccid(
16303     p_code_combination_id          => l_ccid
16304   , p_value_type_code              => l_adr_value_type_code
16305   , p_transaction_coa_id           => l_adr_transaction_coa_id
16306   , p_accounting_coa_id            => l_adr_accounting_coa_id
16307   , p_adr_code                     => 'TRX_DIST_CCID'
16308   , p_adr_type_code                => 'S'
16309   , p_component_type               => l_component_type
16310   , p_component_code               => l_component_code
16311   , p_component_type_code          => l_component_type_code
16312   , p_component_appl_id            => l_component_appl_id
16313   , p_amb_context_code             => l_amb_context_code
16314   , p_side                         => 'NA'
16315   );
16316 
16317 
16318    --
16319    --
16320    END IF;
16321 
16322        --
16323        -- Update the line information that should be overwritten
16324        --
16325        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
16326                                          p_header_num   => 1);
16327        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
16328 
16329        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
16330 
16331        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
16332           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
16333        END IF;
16334 
16335       --
16336       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
16337       --
16338       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
16339           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
16340       ELSE
16341           ---------------------------------------------------------------------------------------------------
16342           -- 4262811a Switch Sign
16343           ---------------------------------------------------------------------------------------------------
16347           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
16344           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
16345           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
16346                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
16348                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
16349           -- 5132302
16350           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
16351                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
16352 
16353       END IF;
16354 
16355       -- 4955764
16356       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
16357       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
16358 
16359 
16360       XLA_AE_LINES_PKG.ValidateCurrentLine;
16361       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
16362 
16363       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
16364                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
16365                ,p_balance_type_code => l_balance_type_code);
16366 
16367    END IF;
16368 
16369    -----------------------------------------------------------------------------------------
16370    -- 4262811 Multiperiod Accounting
16371    -----------------------------------------------------------------------------------------
16372      -- No MPA option is assigned.
16373 
16374 
16375 END IF;
16376 END IF;
16377 --
16378 
16379 --
16380 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16381    trace
16382       (p_msg      => 'END of AcctLineType_53'
16383       ,p_level    => C_LEVEL_PROCEDURE
16384       ,p_module   => l_log_module);
16385 END IF;
16386 --
16387 EXCEPTION
16388   WHEN xla_exceptions_pkg.application_exception THEN
16389       RAISE;
16390   WHEN OTHERS THEN
16391        xla_exceptions_pkg.raise_message
16392            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_53');
16393 END AcctLineType_53;
16394 --
16395 
16396 ---------------------------------------
16397 --
16398 -- PRIVATE FUNCTION
16399 --         AcctLineType_54
16400 --
16401 ---------------------------------------
16402 PROCEDURE AcctLineType_54 (
16403   p_application_id        IN NUMBER
16404  ,p_event_id              IN NUMBER
16405  ,p_calculate_acctd_flag  IN VARCHAR2
16406  ,p_calculate_g_l_flag    IN VARCHAR2
16407  ,p_actual_flag           IN OUT VARCHAR2
16408  ,p_balance_type_code     OUT VARCHAR2
16409  ,p_gain_or_loss_ref      OUT VARCHAR2
16410  
16411 --Transaction Distribution GL Account
16412  , p_source_4            IN NUMBER
16413 --Bill To Customer Account Identifier
16414  , p_source_30            IN NUMBER
16415 --Bill To Customer Site Use Identifier
16416  , p_source_31            IN NUMBER
16417 --SLA Party Type
16418  , p_source_32            IN VARCHAR2
16419 --Transaction Distribution Account Class
16420  , p_source_33            IN VARCHAR2
16421 --Transaction Distribution Identifier
16422  , p_source_34            IN NUMBER
16423 --Transaction Distribution Type
16424  , p_source_35            IN VARCHAR2
16425 --Transaction Distribution Entered Amount
16426  , p_source_36            IN NUMBER
16427 --Transaction Currency Code
16428  , p_source_37            IN VARCHAR2
16429 --Transaction Exchange Date
16430  , p_source_38            IN DATE
16431 --Transaction Exchange Rate
16432  , p_source_39            IN NUMBER
16433 --Transaction Exchange Rate Type
16434  , p_source_40            IN VARCHAR2
16435 --Transaction Accounting Amount
16436  , p_source_41            IN NUMBER
16437 --Transaction Tax Line Identifier
16438  , p_source_55            IN NUMBER
16439 )
16440 IS
16441 
16442 l_component_type              VARCHAR2(80);
16443 l_component_code              VARCHAR2(30);
16444 l_component_type_code         VARCHAR2(1);
16445 l_component_appl_id           INTEGER;
16446 l_amb_context_code            VARCHAR2(30);
16447 l_entity_code                 VARCHAR2(30);
16448 l_event_class_code            VARCHAR2(30);
16449 l_ae_header_id                NUMBER;
16450 l_event_type_code             VARCHAR2(30);
16451 l_line_definition_code        VARCHAR2(30);
16452 l_line_definition_owner_code  VARCHAR2(1);
16453 --
16454 -- adr variables
16455 l_segment                     VARCHAR2(30);
16456 l_ccid                        NUMBER;
16457 l_adr_transaction_coa_id      NUMBER;
16458 l_adr_accounting_coa_id       NUMBER;
16459 l_adr_flexfield_segment_code  VARCHAR2(30);
16460 l_adr_flex_value_set_id       NUMBER;
16461 l_adr_value_type_code         VARCHAR2(30);
16462 l_adr_value_combination_id    NUMBER;
16463 l_adr_value_segment_code      VARCHAR2(30);
16464 
16465 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
16466 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
16467 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
16468 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
16469 
16473 l_acc_rev_flag                VARCHAR2(1);
16470 -- 4262811 Variables ------------------------------------------------------------------------------------------
16471 l_entered_amt_idx             NUMBER;
16472 l_accted_amt_idx              NUMBER;
16474 l_accrual_line_num            NUMBER;
16475 l_tmp_amt                     NUMBER;
16476 l_acc_rev_natural_side_code   VARCHAR2(1);
16477 
16478 l_num_entries                 NUMBER;
16479 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
16480 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
16481 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
16482 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
16483 l_recog_line_1                NUMBER;
16484 l_recog_line_2                NUMBER;
16485 
16486 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
16487 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
16488 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
16489 
16490 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
16491 
16492 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
16493 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
16494 
16495 ---------------------------------------------------------------------------------------------------------------
16496 
16497 
16498 --
16499 -- bulk performance
16500 --
16501 l_balance_type_code           VARCHAR2(1);
16502 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
16503 l_log_module                  VARCHAR2(240);
16504 
16505 --
16506 -- Upgrade strategy
16507 --
16508 l_actual_upg_option           VARCHAR2(1);
16509 l_enc_upg_option           VARCHAR2(1);
16510 
16511 --
16512 BEGIN
16513 --
16514 IF g_log_enabled THEN
16515       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_54';
16516 END IF;
16517 --
16518 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16519 
16520       trace
16521          (p_msg      => 'BEGIN of AcctLineType_54'
16522          ,p_level    => C_LEVEL_PROCEDURE
16523          ,p_module   => l_log_module);
16524 
16525 END IF;
16526 --
16527 l_component_type             := 'AMB_JLT';
16528 l_component_code             := 'DM_REV';
16529 l_component_type_code        := 'S';
16530 l_component_appl_id          :=  222;
16531 l_amb_context_code           := 'DEFAULT';
16532 l_entity_code                := 'TRANSACTIONS';
16533 l_event_class_code           := 'DEBIT_MEMO';
16534 l_event_type_code            := 'DEBIT_MEMO_ALL';
16535 l_line_definition_owner_code := 'S';
16536 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
16537 --
16538 l_balance_type_code          := 'A';
16539 l_segment                     := NULL;
16540 l_ccid                        := NULL;
16541 l_adr_transaction_coa_id      := NULL;
16542 l_adr_accounting_coa_id       := NULL;
16543 l_adr_flexfield_segment_code  := NULL;
16544 l_adr_flex_value_set_id       := NULL;
16545 l_adr_value_type_code         := NULL;
16546 l_adr_value_combination_id    := NULL;
16547 l_adr_value_segment_code      := NULL;
16548 
16549 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
16550 l_bflow_class_code           := '';    -- 4219869 Business Flow
16551 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
16552 l_budgetary_control_flag     := 'N';
16553 
16554 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
16555 l_bflow_applied_to_amt       := NULL; -- 5132302
16556 l_entered_amt_idx            := NULL;          -- 4262811
16557 l_accted_amt_idx             := NULL;          -- 4262811
16558 l_acc_rev_flag               := NULL;          -- 4262811
16559 l_accrual_line_num           := NULL;          -- 4262811
16560 l_tmp_amt                    := NULL;          -- 4262811
16561 --
16562  
16563 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
16564     l_balance_type_code <> 'B' THEN
16565 IF NVL(p_source_33,'
16566 ') =  'REV'
16567  THEN 
16568 
16569    --
16570    XLA_AE_LINES_PKG.SetNewLine;
16571 
16572    p_balance_type_code          := l_balance_type_code;
16573    -- set the flag so later we will know whether the gain loss line needs to be created
16574    
16575    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
16576      p_actual_flag :='A';
16577    END IF;
16578 
16579    --
16580    -- bulk performance
16581    --
16582    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
16583                                       p_header_num   => 0); -- 4262811
16584    --
16585    -- set accounting line options
16586    --
16587    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
16588            p_natural_side_code          => 'C'
16589          , p_gain_or_loss_flag          => 'N'
16590          , p_gl_transfer_mode_code      => 'S'
16591          , p_acct_entry_type_code       => 'A'
16592          , p_switch_side_flag           => 'Y'
16593          , p_merge_duplicate_code       => 'A'
16594          );
16595    --
16596    l_acc_rev_natural_side_code := 'D';  -- 4262811
16597    -- 
16598    --
16599    -- set accounting line type info
16600    --
16604       ,p_line_definition_owner_code => l_line_definition_owner_code
16601    xla_ae_lines_pkg.SetAcctLineType
16602       (p_component_type             => l_component_type
16603       ,p_event_type_code            => l_event_type_code
16605       ,p_line_definition_code       => l_line_definition_code
16606       ,p_accounting_line_code       => l_component_code
16607       ,p_accounting_line_type_code  => l_component_type_code
16608       ,p_accounting_line_appl_id    => l_component_appl_id
16609       ,p_amb_context_code           => l_amb_context_code
16610       ,p_entity_code                => l_entity_code
16611       ,p_event_class_code           => l_event_class_code);
16612    --
16613    -- set accounting class
16614    --
16615    xla_ae_lines_pkg.SetAcctClass(
16616            p_accounting_class_code  => 'REVENUE'
16617          , p_ae_header_id           => l_ae_header_id
16618          );
16619 
16620    --
16621    -- set rounding class
16622    --
16623    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
16624                       'RECEIVABLE';
16625 
16626    --
16627    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
16628    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
16629    --
16630    -- bulk performance
16631    --
16632    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
16633 
16634    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
16635       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
16636 
16637    -- 4955764
16638    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
16639       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
16640 
16641    -- 4458381 Public Sector Enh
16642    
16643    --
16644    -- set accounting attributes for the line type
16645    --
16646    l_entered_amt_idx := 3;
16647    l_accted_amt_idx  := 8;
16648    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
16649    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
16650    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
16651    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
16652    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
16653    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
16654    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
16655    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
16656    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
16657    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
16658    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
16659    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
16660    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
16661    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
16662    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
16663    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
16664    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
16665    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
16666    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
16667    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
16668    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
16669    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
16670    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
16671    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
16672    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
16673 
16674    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
16675    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
16676 
16677    ---------------------------------------------------------------------------------------------------------------
16678    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
16679    ---------------------------------------------------------------------------------------------------------------
16680    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
16681 
16682    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
16683    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
16684 
16685    IF xla_accounting_cache_pkg.GetValueChar
16686          (p_source_code         => 'LEDGER_CATEGORY_CODE'
16687          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
16688    AND l_bflow_method_code = 'PRIOR_ENTRY'
16689 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
16690    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
16691          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
16692        )
16693    THEN
16694          xla_ae_lines_pkg.BflowUpgEntry
16695            (p_business_method_code    => l_bflow_method_code
16696            ,p_business_class_code     => l_bflow_class_code
16697            ,p_balance_type            => l_balance_type_code);
16698    ELSE
16699       NULL;
16700 -- No business flow processing for business flow method of NONE.
16701    END IF;
16702 
16703    --
16704    -- call analytical criteria
16705    --
16706    
16707    --
16711    --
16708    -- call description
16709    --
16710    -- No description or it is inherited.
16712    -- call ADRs
16713    -- Bug 4922099
16714    --
16715    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
16716         (NVL(l_actual_upg_option, 'N') = 'O') OR
16717         (NVL(l_enc_upg_option, 'N') = 'O')
16718       )
16719    THEN
16720    NULL;
16721    --
16722    --
16723    
16724   l_ccid := AcctDerRule_32(
16725            p_application_id           => p_application_id
16726          , p_ae_header_id             => l_ae_header_id 
16727 , p_source_4 => p_source_4
16728          , x_transaction_coa_id       => l_adr_transaction_coa_id
16729          , x_accounting_coa_id        => l_adr_accounting_coa_id
16730          , x_value_type_code          => l_adr_value_type_code
16731          , p_side                     => 'NA'
16732    );
16733 
16734    xla_ae_lines_pkg.set_ccid(
16735     p_code_combination_id          => l_ccid
16736   , p_value_type_code              => l_adr_value_type_code
16737   , p_transaction_coa_id           => l_adr_transaction_coa_id
16738   , p_accounting_coa_id            => l_adr_accounting_coa_id
16739   , p_adr_code                     => 'TRX_DIST_CCID'
16740   , p_adr_type_code                => 'S'
16741   , p_component_type               => l_component_type
16742   , p_component_code               => l_component_code
16743   , p_component_type_code          => l_component_type_code
16744   , p_component_appl_id            => l_component_appl_id
16745   , p_amb_context_code             => l_amb_context_code
16746   , p_side                         => 'NA'
16747   );
16748 
16749 
16750    --
16751    --
16752    END IF;
16753    --
16754    -- Bug 4922099
16755    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
16756           (NVL(l_enc_upg_option, 'N') = 'O')
16757         ) AND
16758         (l_bflow_method_code = 'PRIOR_ENTRY')
16759       )
16760    THEN
16761       IF
16762       --
16763       1 = 2
16764       --
16765       THEN
16766       xla_accounting_err_pkg.build_message
16767                                     (p_appli_s_name            => 'XLA'
16768                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
16769                                     ,p_token_1                 => 'LINE_NUMBER'
16770                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
16771                                     ,p_token_2                 => 'LINE_TYPE_NAME'
16772                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
16773                                                                              l_component_type
16774                                                                             ,l_component_code
16775                                                                             ,l_component_type_code
16776                                                                             ,l_component_appl_id
16777                                                                             ,l_amb_context_code
16778                                                                             ,l_entity_code
16779                                                                             ,l_event_class_code
16780                                                                            )
16781                                     ,p_token_3                 => 'OWNER'
16782                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
16783                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
16784                                                                           ,p_lookup_code    => l_component_type_code
16785                                                                          )
16786                                     ,p_token_4                 => 'PRODUCT_NAME'
16787                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
16788                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
16789                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
16790                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
16791                                     ,p_ae_header_id            =>  NULL
16792                                        );
16793 
16794         IF (C_LEVEL_ERROR>= g_log_level) THEN
16795                  trace
16796                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
16797                       ,p_level    => C_LEVEL_ERROR
16798                       ,p_module   => l_log_module);
16799         END IF;
16800       END IF;
16801    END IF;
16802    --
16803    --
16804    ------------------------------------------------------------------------------------------------
16805    -- 4219869 Business Flow
16806    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
16807    -- Prior Entry.  Currently, the following code is always generated.
16808    ------------------------------------------------------------------------------------------------
16809    XLA_AE_LINES_PKG.ValidateCurrentLine;
16810 
16811    ------------------------------------------------------------------------------------
16812    -- 4219869 Business Flow
16813    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
16817    ----------------------------------------------------------------------------------
16814    ------------------------------------------------------------------------------------
16815    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
16816 
16818    -- 4219869 Business Flow
16819    -- Update journal entry status -- Need to generate this within IF <condition>
16820    ----------------------------------------------------------------------------------
16821    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
16822          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
16823          ,p_balance_type_code => l_balance_type_code
16824          );
16825 
16826    -------------------------------------------------------------------------------------------
16827    -- 4262811 - Generate the Accrual Reversal lines
16828    -------------------------------------------------------------------------------------------
16829    BEGIN
16830       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
16831                               (g_array_event(p_event_id).array_value_num('header_index'));
16832       IF l_acc_rev_flag IS NULL THEN
16833          l_acc_rev_flag := 'N';
16834       END IF;
16835    EXCEPTION
16836       WHEN OTHERS THEN
16837          l_acc_rev_flag := 'N';
16838    END;
16839    --
16840    IF (l_acc_rev_flag = 'Y') THEN
16841 
16842        -- 4645092  ------------------------------------------------------------------------------
16843        -- To allow MPA report to determine if it should generate report process
16844        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
16845        ------------------------------------------------------------------------------------------
16846 
16847        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
16848        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
16849    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
16850    -- call ADRs
16851    -- Bug 4922099
16852    --
16853    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
16854         (NVL(l_actual_upg_option, 'N') = 'O') OR
16855         (NVL(l_enc_upg_option, 'N') = 'O')
16856       )
16857    THEN
16858    NULL;
16859    --
16860    --
16861    
16862   l_ccid := AcctDerRule_32(
16863            p_application_id           => p_application_id
16864          , p_ae_header_id             => l_ae_header_id 
16865 , p_source_4 => p_source_4
16866          , x_transaction_coa_id       => l_adr_transaction_coa_id
16867          , x_accounting_coa_id        => l_adr_accounting_coa_id
16868          , x_value_type_code          => l_adr_value_type_code
16869          , p_side                     => 'NA'
16870    );
16871 
16872    xla_ae_lines_pkg.set_ccid(
16873     p_code_combination_id          => l_ccid
16874   , p_value_type_code              => l_adr_value_type_code
16875   , p_transaction_coa_id           => l_adr_transaction_coa_id
16876   , p_accounting_coa_id            => l_adr_accounting_coa_id
16877   , p_adr_code                     => 'TRX_DIST_CCID'
16878   , p_adr_type_code                => 'S'
16879   , p_component_type               => l_component_type
16880   , p_component_code               => l_component_code
16881   , p_component_type_code          => l_component_type_code
16882   , p_component_appl_id            => l_component_appl_id
16883   , p_amb_context_code             => l_amb_context_code
16884   , p_side                         => 'NA'
16885   );
16886 
16887 
16888    --
16889    --
16890    END IF;
16891 
16892        --
16893        -- Update the line information that should be overwritten
16894        --
16895        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
16896                                          p_header_num   => 1);
16897        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
16898 
16899        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
16900 
16901        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
16902           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
16903        END IF;
16904 
16905       --
16906       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
16907       --
16908       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
16909           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
16910       ELSE
16911           ---------------------------------------------------------------------------------------------------
16912           -- 4262811a Switch Sign
16913           ---------------------------------------------------------------------------------------------------
16914           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
16915           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
16916                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
16917           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
16918                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
16919           -- 5132302
16920           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
16921                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
16925       -- 4955764
16922 
16923       END IF;
16924 
16926       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
16927       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
16928 
16929 
16930       XLA_AE_LINES_PKG.ValidateCurrentLine;
16931       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
16932 
16933       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
16934                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
16935                ,p_balance_type_code => l_balance_type_code);
16936 
16937    END IF;
16938 
16939    -----------------------------------------------------------------------------------------
16940    -- 4262811 Multiperiod Accounting
16941    -----------------------------------------------------------------------------------------
16942      -- No MPA option is assigned.
16943 
16944 
16945 END IF;
16946 END IF;
16947 --
16948 
16949 --
16950 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16951    trace
16952       (p_msg      => 'END of AcctLineType_54'
16953       ,p_level    => C_LEVEL_PROCEDURE
16954       ,p_module   => l_log_module);
16955 END IF;
16956 --
16957 EXCEPTION
16958   WHEN xla_exceptions_pkg.application_exception THEN
16959       RAISE;
16960   WHEN OTHERS THEN
16961        xla_exceptions_pkg.raise_message
16962            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_54');
16963 END AcctLineType_54;
16964 --
16965 
16966 ---------------------------------------
16967 --
16968 -- PRIVATE FUNCTION
16969 --         AcctLineType_55
16970 --
16971 ---------------------------------------
16972 PROCEDURE AcctLineType_55 (
16973   p_application_id        IN NUMBER
16974  ,p_event_id              IN NUMBER
16975  ,p_calculate_acctd_flag  IN VARCHAR2
16976  ,p_calculate_g_l_flag    IN VARCHAR2
16977  ,p_actual_flag           IN OUT VARCHAR2
16978  ,p_balance_type_code     OUT VARCHAR2
16979  ,p_gain_or_loss_ref      OUT VARCHAR2
16980  
16981 --Transaction Distribution GL Account
16982  , p_source_4            IN NUMBER
16983 --Bill To Customer Account Identifier
16984  , p_source_30            IN NUMBER
16985 --Bill To Customer Site Use Identifier
16986  , p_source_31            IN NUMBER
16987 --SLA Party Type
16988  , p_source_32            IN VARCHAR2
16989 --Transaction Distribution Account Class
16990  , p_source_33            IN VARCHAR2
16991 --Transaction Distribution Identifier
16992  , p_source_34            IN NUMBER
16993 --Transaction Distribution Type
16994  , p_source_35            IN VARCHAR2
16995 --Transaction Distribution Entered Amount
16996  , p_source_36            IN NUMBER
16997 --Transaction Currency Code
16998  , p_source_37            IN VARCHAR2
16999 --Transaction Exchange Date
17000  , p_source_38            IN DATE
17001 --Transaction Exchange Rate
17002  , p_source_39            IN NUMBER
17003 --Transaction Exchange Rate Type
17004  , p_source_40            IN VARCHAR2
17005 --Transaction Accounting Amount
17006  , p_source_41            IN NUMBER
17007 --Transaction Tax Line Identifier
17008  , p_source_55            IN NUMBER
17009 )
17010 IS
17011 
17012 l_component_type              VARCHAR2(80);
17013 l_component_code              VARCHAR2(30);
17014 l_component_type_code         VARCHAR2(1);
17015 l_component_appl_id           INTEGER;
17016 l_amb_context_code            VARCHAR2(30);
17017 l_entity_code                 VARCHAR2(30);
17018 l_event_class_code            VARCHAR2(30);
17019 l_ae_header_id                NUMBER;
17020 l_event_type_code             VARCHAR2(30);
17021 l_line_definition_code        VARCHAR2(30);
17022 l_line_definition_owner_code  VARCHAR2(1);
17023 --
17024 -- adr variables
17025 l_segment                     VARCHAR2(30);
17026 l_ccid                        NUMBER;
17027 l_adr_transaction_coa_id      NUMBER;
17028 l_adr_accounting_coa_id       NUMBER;
17029 l_adr_flexfield_segment_code  VARCHAR2(30);
17030 l_adr_flex_value_set_id       NUMBER;
17031 l_adr_value_type_code         VARCHAR2(30);
17032 l_adr_value_combination_id    NUMBER;
17033 l_adr_value_segment_code      VARCHAR2(30);
17034 
17035 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
17036 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
17037 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
17038 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
17039 
17040 -- 4262811 Variables ------------------------------------------------------------------------------------------
17041 l_entered_amt_idx             NUMBER;
17042 l_accted_amt_idx              NUMBER;
17043 l_acc_rev_flag                VARCHAR2(1);
17044 l_accrual_line_num            NUMBER;
17045 l_tmp_amt                     NUMBER;
17046 l_acc_rev_natural_side_code   VARCHAR2(1);
17047 
17048 l_num_entries                 NUMBER;
17049 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
17050 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
17051 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
17052 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
17056 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
17053 l_recog_line_1                NUMBER;
17054 l_recog_line_2                NUMBER;
17055 
17057 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
17058 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
17059 
17060 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
17061 
17062 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
17063 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
17064 
17065 ---------------------------------------------------------------------------------------------------------------
17066 
17067 
17068 --
17069 -- bulk performance
17070 --
17071 l_balance_type_code           VARCHAR2(1);
17072 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
17073 l_log_module                  VARCHAR2(240);
17074 
17075 --
17076 -- Upgrade strategy
17077 --
17078 l_actual_upg_option           VARCHAR2(1);
17079 l_enc_upg_option           VARCHAR2(1);
17080 
17081 --
17082 BEGIN
17083 --
17084 IF g_log_enabled THEN
17085       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_55';
17086 END IF;
17087 --
17088 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17089 
17090       trace
17091          (p_msg      => 'BEGIN of AcctLineType_55'
17092          ,p_level    => C_LEVEL_PROCEDURE
17093          ,p_module   => l_log_module);
17094 
17095 END IF;
17096 --
17097 l_component_type             := 'AMB_JLT';
17098 l_component_code             := 'DM_ROUND';
17099 l_component_type_code        := 'S';
17100 l_component_appl_id          :=  222;
17101 l_amb_context_code           := 'DEFAULT';
17102 l_entity_code                := 'TRANSACTIONS';
17103 l_event_class_code           := 'DEBIT_MEMO';
17104 l_event_type_code            := 'DEBIT_MEMO_ALL';
17105 l_line_definition_owner_code := 'S';
17106 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
17107 --
17108 l_balance_type_code          := 'A';
17109 l_segment                     := NULL;
17110 l_ccid                        := NULL;
17111 l_adr_transaction_coa_id      := NULL;
17112 l_adr_accounting_coa_id       := NULL;
17113 l_adr_flexfield_segment_code  := NULL;
17114 l_adr_flex_value_set_id       := NULL;
17115 l_adr_value_type_code         := NULL;
17116 l_adr_value_combination_id    := NULL;
17117 l_adr_value_segment_code      := NULL;
17118 
17119 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
17120 l_bflow_class_code           := '';    -- 4219869 Business Flow
17121 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
17122 l_budgetary_control_flag     := 'N';
17123 
17124 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
17125 l_bflow_applied_to_amt       := NULL; -- 5132302
17126 l_entered_amt_idx            := NULL;          -- 4262811
17127 l_accted_amt_idx             := NULL;          -- 4262811
17128 l_acc_rev_flag               := NULL;          -- 4262811
17129 l_accrual_line_num           := NULL;          -- 4262811
17130 l_tmp_amt                    := NULL;          -- 4262811
17131 --
17132  
17133 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
17134     l_balance_type_code <> 'B' THEN
17135 IF NVL(p_source_33,'
17136 ') =  'ROUND'
17137  THEN 
17138 
17139    --
17140    XLA_AE_LINES_PKG.SetNewLine;
17141 
17142    p_balance_type_code          := l_balance_type_code;
17143    -- set the flag so later we will know whether the gain loss line needs to be created
17144    
17145    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
17146      p_actual_flag :='A';
17147    END IF;
17148 
17149    --
17150    -- bulk performance
17151    --
17152    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
17153                                       p_header_num   => 0); -- 4262811
17154    --
17155    -- set accounting line options
17156    --
17157    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
17158            p_natural_side_code          => 'C'
17159          , p_gain_or_loss_flag          => 'N'
17160          , p_gl_transfer_mode_code      => 'S'
17161          , p_acct_entry_type_code       => 'A'
17162          , p_switch_side_flag           => 'Y'
17163          , p_merge_duplicate_code       => 'A'
17164          );
17165    --
17166    l_acc_rev_natural_side_code := 'D';  -- 4262811
17167    -- 
17168    --
17169    -- set accounting line type info
17170    --
17171    xla_ae_lines_pkg.SetAcctLineType
17172       (p_component_type             => l_component_type
17173       ,p_event_type_code            => l_event_type_code
17174       ,p_line_definition_owner_code => l_line_definition_owner_code
17175       ,p_line_definition_code       => l_line_definition_code
17176       ,p_accounting_line_code       => l_component_code
17177       ,p_accounting_line_type_code  => l_component_type_code
17178       ,p_accounting_line_appl_id    => l_component_appl_id
17179       ,p_amb_context_code           => l_amb_context_code
17180       ,p_entity_code                => l_entity_code
17181       ,p_event_class_code           => l_event_class_code);
17182    --
17183    -- set accounting class
17184    --
17188          );
17185    xla_ae_lines_pkg.SetAcctClass(
17186            p_accounting_class_code  => 'ROUNDING'
17187          , p_ae_header_id           => l_ae_header_id
17189 
17190    --
17191    -- set rounding class
17192    --
17193    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
17194                       'RECEIVABLE';
17195 
17196    --
17197    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
17198    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
17199    --
17200    -- bulk performance
17201    --
17202    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
17203 
17204    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
17205       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
17206 
17207    -- 4955764
17208    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
17209       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
17210 
17211    -- 4458381 Public Sector Enh
17212    
17213    --
17214    -- set accounting attributes for the line type
17215    --
17216    l_entered_amt_idx := 3;
17217    l_accted_amt_idx  := 8;
17218    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
17219    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
17220    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
17221    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
17222    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
17223    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
17224    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
17225    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
17226    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
17227    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
17228    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
17229    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
17230    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
17231    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
17232    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
17233    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
17234    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
17235    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
17236    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
17237    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
17238    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
17239    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
17240    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
17241    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
17242    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
17243 
17244    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
17245    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
17246 
17247    ---------------------------------------------------------------------------------------------------------------
17248    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
17249    ---------------------------------------------------------------------------------------------------------------
17250    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
17251 
17252    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
17253    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
17254 
17255    IF xla_accounting_cache_pkg.GetValueChar
17256          (p_source_code         => 'LEDGER_CATEGORY_CODE'
17257          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
17258    AND l_bflow_method_code = 'PRIOR_ENTRY'
17259 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
17260    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
17261          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
17262        )
17263    THEN
17264          xla_ae_lines_pkg.BflowUpgEntry
17265            (p_business_method_code    => l_bflow_method_code
17266            ,p_business_class_code     => l_bflow_class_code
17267            ,p_balance_type            => l_balance_type_code);
17268    ELSE
17269       NULL;
17270 -- No business flow processing for business flow method of NONE.
17271    END IF;
17272 
17273    --
17274    -- call analytical criteria
17275    --
17276    
17277    --
17278    -- call description
17279    --
17280    -- No description or it is inherited.
17281    --
17282    -- call ADRs
17283    -- Bug 4922099
17284    --
17285    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
17286         (NVL(l_actual_upg_option, 'N') = 'O') OR
17287         (NVL(l_enc_upg_option, 'N') = 'O')
17288       )
17289    THEN
17290    NULL;
17291    --
17292    --
17293    
17294   l_ccid := AcctDerRule_32(
17295            p_application_id           => p_application_id
17296          , p_ae_header_id             => l_ae_header_id 
17297 , p_source_4 => p_source_4
17298          , x_transaction_coa_id       => l_adr_transaction_coa_id
17302    );
17299          , x_accounting_coa_id        => l_adr_accounting_coa_id
17300          , x_value_type_code          => l_adr_value_type_code
17301          , p_side                     => 'NA'
17303 
17304    xla_ae_lines_pkg.set_ccid(
17305     p_code_combination_id          => l_ccid
17306   , p_value_type_code              => l_adr_value_type_code
17307   , p_transaction_coa_id           => l_adr_transaction_coa_id
17308   , p_accounting_coa_id            => l_adr_accounting_coa_id
17309   , p_adr_code                     => 'TRX_DIST_CCID'
17310   , p_adr_type_code                => 'S'
17311   , p_component_type               => l_component_type
17312   , p_component_code               => l_component_code
17313   , p_component_type_code          => l_component_type_code
17314   , p_component_appl_id            => l_component_appl_id
17315   , p_amb_context_code             => l_amb_context_code
17316   , p_side                         => 'NA'
17317   );
17318 
17319 
17320    --
17321    --
17322    END IF;
17323    --
17324    -- Bug 4922099
17325    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
17326           (NVL(l_enc_upg_option, 'N') = 'O')
17327         ) AND
17328         (l_bflow_method_code = 'PRIOR_ENTRY')
17329       )
17330    THEN
17331       IF
17332       --
17333       1 = 2
17334       --
17335       THEN
17336       xla_accounting_err_pkg.build_message
17337                                     (p_appli_s_name            => 'XLA'
17338                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
17339                                     ,p_token_1                 => 'LINE_NUMBER'
17340                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
17341                                     ,p_token_2                 => 'LINE_TYPE_NAME'
17342                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
17343                                                                              l_component_type
17344                                                                             ,l_component_code
17345                                                                             ,l_component_type_code
17346                                                                             ,l_component_appl_id
17347                                                                             ,l_amb_context_code
17348                                                                             ,l_entity_code
17349                                                                             ,l_event_class_code
17350                                                                            )
17351                                     ,p_token_3                 => 'OWNER'
17352                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
17353                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
17354                                                                           ,p_lookup_code    => l_component_type_code
17355                                                                          )
17356                                     ,p_token_4                 => 'PRODUCT_NAME'
17357                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
17358                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
17359                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
17360                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
17361                                     ,p_ae_header_id            =>  NULL
17362                                        );
17363 
17364         IF (C_LEVEL_ERROR>= g_log_level) THEN
17365                  trace
17366                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
17367                       ,p_level    => C_LEVEL_ERROR
17368                       ,p_module   => l_log_module);
17369         END IF;
17370       END IF;
17371    END IF;
17372    --
17373    --
17374    ------------------------------------------------------------------------------------------------
17375    -- 4219869 Business Flow
17376    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
17377    -- Prior Entry.  Currently, the following code is always generated.
17378    ------------------------------------------------------------------------------------------------
17379    XLA_AE_LINES_PKG.ValidateCurrentLine;
17380 
17381    ------------------------------------------------------------------------------------
17382    -- 4219869 Business Flow
17383    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
17384    ------------------------------------------------------------------------------------
17385    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
17386 
17387    ----------------------------------------------------------------------------------
17388    -- 4219869 Business Flow
17389    -- Update journal entry status -- Need to generate this within IF <condition>
17390    ----------------------------------------------------------------------------------
17391    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
17392          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
17393          ,p_balance_type_code => l_balance_type_code
17394          );
17395 
17399    BEGIN
17396    -------------------------------------------------------------------------------------------
17397    -- 4262811 - Generate the Accrual Reversal lines
17398    -------------------------------------------------------------------------------------------
17400       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
17401                               (g_array_event(p_event_id).array_value_num('header_index'));
17402       IF l_acc_rev_flag IS NULL THEN
17403          l_acc_rev_flag := 'N';
17404       END IF;
17405    EXCEPTION
17406       WHEN OTHERS THEN
17407          l_acc_rev_flag := 'N';
17408    END;
17409    --
17410    IF (l_acc_rev_flag = 'Y') THEN
17411 
17412        -- 4645092  ------------------------------------------------------------------------------
17413        -- To allow MPA report to determine if it should generate report process
17414        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
17415        ------------------------------------------------------------------------------------------
17416 
17417        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
17418        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
17419    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
17420    -- call ADRs
17421    -- Bug 4922099
17422    --
17423    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
17424         (NVL(l_actual_upg_option, 'N') = 'O') OR
17425         (NVL(l_enc_upg_option, 'N') = 'O')
17426       )
17427    THEN
17428    NULL;
17429    --
17430    --
17431    
17432   l_ccid := AcctDerRule_32(
17433            p_application_id           => p_application_id
17434          , p_ae_header_id             => l_ae_header_id 
17435 , p_source_4 => p_source_4
17436          , x_transaction_coa_id       => l_adr_transaction_coa_id
17437          , x_accounting_coa_id        => l_adr_accounting_coa_id
17438          , x_value_type_code          => l_adr_value_type_code
17439          , p_side                     => 'NA'
17440    );
17441 
17442    xla_ae_lines_pkg.set_ccid(
17443     p_code_combination_id          => l_ccid
17444   , p_value_type_code              => l_adr_value_type_code
17445   , p_transaction_coa_id           => l_adr_transaction_coa_id
17446   , p_accounting_coa_id            => l_adr_accounting_coa_id
17447   , p_adr_code                     => 'TRX_DIST_CCID'
17448   , p_adr_type_code                => 'S'
17449   , p_component_type               => l_component_type
17450   , p_component_code               => l_component_code
17451   , p_component_type_code          => l_component_type_code
17452   , p_component_appl_id            => l_component_appl_id
17453   , p_amb_context_code             => l_amb_context_code
17454   , p_side                         => 'NA'
17455   );
17456 
17457 
17458    --
17459    --
17460    END IF;
17461 
17462        --
17463        -- Update the line information that should be overwritten
17464        --
17465        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
17466                                          p_header_num   => 1);
17467        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
17468 
17469        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
17470 
17471        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
17472           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
17473        END IF;
17474 
17475       --
17476       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
17477       --
17478       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
17479           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
17480       ELSE
17481           ---------------------------------------------------------------------------------------------------
17482           -- 4262811a Switch Sign
17483           ---------------------------------------------------------------------------------------------------
17484           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
17485           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
17486                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
17487           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
17488                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
17489           -- 5132302
17490           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
17491                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
17492 
17493       END IF;
17494 
17495       -- 4955764
17496       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
17497       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
17498 
17499 
17500       XLA_AE_LINES_PKG.ValidateCurrentLine;
17501       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
17502 
17503       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
17504                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
17505                ,p_balance_type_code => l_balance_type_code);
17506 
17510    -- 4262811 Multiperiod Accounting
17507    END IF;
17508 
17509    -----------------------------------------------------------------------------------------
17511    -----------------------------------------------------------------------------------------
17512      -- No MPA option is assigned.
17513 
17514 
17515 END IF;
17516 END IF;
17517 --
17518 
17519 --
17520 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17521    trace
17522       (p_msg      => 'END of AcctLineType_55'
17523       ,p_level    => C_LEVEL_PROCEDURE
17524       ,p_module   => l_log_module);
17525 END IF;
17526 --
17527 EXCEPTION
17528   WHEN xla_exceptions_pkg.application_exception THEN
17529       RAISE;
17530   WHEN OTHERS THEN
17531        xla_exceptions_pkg.raise_message
17532            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_55');
17533 END AcctLineType_55;
17534 --
17535 
17536 ---------------------------------------
17537 --
17538 -- PRIVATE FUNCTION
17539 --         AcctLineType_56
17540 --
17541 ---------------------------------------
17542 PROCEDURE AcctLineType_56 (
17543   p_application_id        IN NUMBER
17544  ,p_event_id              IN NUMBER
17545  ,p_calculate_acctd_flag  IN VARCHAR2
17546  ,p_calculate_g_l_flag    IN VARCHAR2
17547  ,p_actual_flag           IN OUT VARCHAR2
17548  ,p_balance_type_code     OUT VARCHAR2
17549  ,p_gain_or_loss_ref      OUT VARCHAR2
17550  
17551 --Transaction Distribution GL Account
17552  , p_source_4            IN NUMBER
17553 --Bill To Customer Account Identifier
17554  , p_source_30            IN NUMBER
17555 --Bill To Customer Site Use Identifier
17556  , p_source_31            IN NUMBER
17557 --SLA Party Type
17558  , p_source_32            IN VARCHAR2
17559 --Transaction Distribution Account Class
17560  , p_source_33            IN VARCHAR2
17561 --Transaction Distribution Identifier
17562  , p_source_34            IN NUMBER
17563 --Transaction Distribution Type
17564  , p_source_35            IN VARCHAR2
17565 --Transaction Distribution Entered Amount
17566  , p_source_36            IN NUMBER
17567 --Transaction Currency Code
17568  , p_source_37            IN VARCHAR2
17569 --Transaction Exchange Date
17570  , p_source_38            IN DATE
17571 --Transaction Exchange Rate
17572  , p_source_39            IN NUMBER
17573 --Transaction Exchange Rate Type
17574  , p_source_40            IN VARCHAR2
17575 --Transaction Accounting Amount
17576  , p_source_41            IN NUMBER
17577 --Transaction Tax Line Identifier
17578  , p_source_55            IN NUMBER
17579 )
17580 IS
17581 
17582 l_component_type              VARCHAR2(80);
17583 l_component_code              VARCHAR2(30);
17584 l_component_type_code         VARCHAR2(1);
17585 l_component_appl_id           INTEGER;
17586 l_amb_context_code            VARCHAR2(30);
17587 l_entity_code                 VARCHAR2(30);
17588 l_event_class_code            VARCHAR2(30);
17589 l_ae_header_id                NUMBER;
17590 l_event_type_code             VARCHAR2(30);
17591 l_line_definition_code        VARCHAR2(30);
17592 l_line_definition_owner_code  VARCHAR2(1);
17593 --
17594 -- adr variables
17595 l_segment                     VARCHAR2(30);
17596 l_ccid                        NUMBER;
17597 l_adr_transaction_coa_id      NUMBER;
17598 l_adr_accounting_coa_id       NUMBER;
17599 l_adr_flexfield_segment_code  VARCHAR2(30);
17600 l_adr_flex_value_set_id       NUMBER;
17601 l_adr_value_type_code         VARCHAR2(30);
17602 l_adr_value_combination_id    NUMBER;
17603 l_adr_value_segment_code      VARCHAR2(30);
17604 
17605 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
17606 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
17607 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
17608 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
17609 
17610 -- 4262811 Variables ------------------------------------------------------------------------------------------
17611 l_entered_amt_idx             NUMBER;
17612 l_accted_amt_idx              NUMBER;
17613 l_acc_rev_flag                VARCHAR2(1);
17614 l_accrual_line_num            NUMBER;
17615 l_tmp_amt                     NUMBER;
17616 l_acc_rev_natural_side_code   VARCHAR2(1);
17617 
17618 l_num_entries                 NUMBER;
17619 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
17620 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
17621 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
17622 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
17623 l_recog_line_1                NUMBER;
17624 l_recog_line_2                NUMBER;
17625 
17626 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
17627 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
17628 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
17629 
17630 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
17631 
17632 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
17633 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
17634 
17635 ---------------------------------------------------------------------------------------------------------------
17639 -- bulk performance
17636 
17637 
17638 --
17640 --
17641 l_balance_type_code           VARCHAR2(1);
17642 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
17643 l_log_module                  VARCHAR2(240);
17644 
17645 --
17646 -- Upgrade strategy
17647 --
17648 l_actual_upg_option           VARCHAR2(1);
17649 l_enc_upg_option           VARCHAR2(1);
17650 
17651 --
17652 BEGIN
17653 --
17654 IF g_log_enabled THEN
17655       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_56';
17656 END IF;
17657 --
17658 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17659 
17660       trace
17661          (p_msg      => 'BEGIN of AcctLineType_56'
17662          ,p_level    => C_LEVEL_PROCEDURE
17663          ,p_module   => l_log_module);
17664 
17665 END IF;
17666 --
17667 l_component_type             := 'AMB_JLT';
17668 l_component_code             := 'DM_TAX';
17669 l_component_type_code        := 'S';
17670 l_component_appl_id          :=  222;
17671 l_amb_context_code           := 'DEFAULT';
17672 l_entity_code                := 'TRANSACTIONS';
17673 l_event_class_code           := 'DEBIT_MEMO';
17674 l_event_type_code            := 'DEBIT_MEMO_ALL';
17675 l_line_definition_owner_code := 'S';
17676 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
17677 --
17678 l_balance_type_code          := 'A';
17679 l_segment                     := NULL;
17680 l_ccid                        := NULL;
17681 l_adr_transaction_coa_id      := NULL;
17682 l_adr_accounting_coa_id       := NULL;
17683 l_adr_flexfield_segment_code  := NULL;
17684 l_adr_flex_value_set_id       := NULL;
17685 l_adr_value_type_code         := NULL;
17686 l_adr_value_combination_id    := NULL;
17687 l_adr_value_segment_code      := NULL;
17688 
17689 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
17690 l_bflow_class_code           := '';    -- 4219869 Business Flow
17691 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
17692 l_budgetary_control_flag     := 'N';
17693 
17694 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
17695 l_bflow_applied_to_amt       := NULL; -- 5132302
17696 l_entered_amt_idx            := NULL;          -- 4262811
17697 l_accted_amt_idx             := NULL;          -- 4262811
17698 l_acc_rev_flag               := NULL;          -- 4262811
17699 l_accrual_line_num           := NULL;          -- 4262811
17700 l_tmp_amt                    := NULL;          -- 4262811
17701 --
17702  
17703 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
17704     l_balance_type_code <> 'B' THEN
17705 IF NVL(p_source_33,'
17706 ') =  'TAX'
17707  THEN 
17708 
17709    --
17710    XLA_AE_LINES_PKG.SetNewLine;
17711 
17712    p_balance_type_code          := l_balance_type_code;
17713    -- set the flag so later we will know whether the gain loss line needs to be created
17714    
17715    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
17716      p_actual_flag :='A';
17717    END IF;
17718 
17719    --
17720    -- bulk performance
17721    --
17722    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
17723                                       p_header_num   => 0); -- 4262811
17724    --
17725    -- set accounting line options
17726    --
17727    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
17728            p_natural_side_code          => 'C'
17729          , p_gain_or_loss_flag          => 'N'
17730          , p_gl_transfer_mode_code      => 'S'
17731          , p_acct_entry_type_code       => 'A'
17732          , p_switch_side_flag           => 'Y'
17733          , p_merge_duplicate_code       => 'A'
17734          );
17735    --
17736    l_acc_rev_natural_side_code := 'D';  -- 4262811
17737    -- 
17738    --
17739    -- set accounting line type info
17740    --
17741    xla_ae_lines_pkg.SetAcctLineType
17742       (p_component_type             => l_component_type
17743       ,p_event_type_code            => l_event_type_code
17744       ,p_line_definition_owner_code => l_line_definition_owner_code
17745       ,p_line_definition_code       => l_line_definition_code
17746       ,p_accounting_line_code       => l_component_code
17747       ,p_accounting_line_type_code  => l_component_type_code
17748       ,p_accounting_line_appl_id    => l_component_appl_id
17749       ,p_amb_context_code           => l_amb_context_code
17750       ,p_entity_code                => l_entity_code
17751       ,p_event_class_code           => l_event_class_code);
17752    --
17753    -- set accounting class
17754    --
17755    xla_ae_lines_pkg.SetAcctClass(
17756            p_accounting_class_code  => 'TAX'
17757          , p_ae_header_id           => l_ae_header_id
17758          );
17759 
17760    --
17761    -- set rounding class
17762    --
17763    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
17764                       'RECEIVABLE';
17765 
17766    --
17767    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
17768    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
17769    --
17770    -- bulk performance
17771    --
17775       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
17772    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
17773 
17774    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
17776 
17777    -- 4955764
17778    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
17779       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
17780 
17781    -- 4458381 Public Sector Enh
17782    
17783    --
17784    -- set accounting attributes for the line type
17785    --
17786    l_entered_amt_idx := 3;
17787    l_accted_amt_idx  := 8;
17788    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
17789    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
17790    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
17791    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
17792    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
17793    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
17794    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
17795    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
17796    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
17797    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
17798    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
17799    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
17800    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
17801    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
17802    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
17803    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
17804    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
17805    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
17806    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
17807    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
17808    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
17809    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
17810    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
17811    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
17812    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
17813 
17814    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
17815    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
17816 
17817    ---------------------------------------------------------------------------------------------------------------
17818    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
17819    ---------------------------------------------------------------------------------------------------------------
17820    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
17821 
17822    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
17823    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
17824 
17825    IF xla_accounting_cache_pkg.GetValueChar
17826          (p_source_code         => 'LEDGER_CATEGORY_CODE'
17827          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
17828    AND l_bflow_method_code = 'PRIOR_ENTRY'
17829 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
17830    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
17831          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
17832        )
17833    THEN
17834          xla_ae_lines_pkg.BflowUpgEntry
17835            (p_business_method_code    => l_bflow_method_code
17836            ,p_business_class_code     => l_bflow_class_code
17837            ,p_balance_type            => l_balance_type_code);
17838    ELSE
17839       NULL;
17840 -- No business flow processing for business flow method of NONE.
17841    END IF;
17842 
17843    --
17844    -- call analytical criteria
17845    --
17846    
17847    --
17848    -- call description
17849    --
17850    -- No description or it is inherited.
17851    --
17852    -- call ADRs
17853    -- Bug 4922099
17854    --
17855    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
17856         (NVL(l_actual_upg_option, 'N') = 'O') OR
17857         (NVL(l_enc_upg_option, 'N') = 'O')
17858       )
17859    THEN
17860    NULL;
17861    --
17862    --
17863    
17864   l_ccid := AcctDerRule_32(
17865            p_application_id           => p_application_id
17866          , p_ae_header_id             => l_ae_header_id 
17867 , p_source_4 => p_source_4
17868          , x_transaction_coa_id       => l_adr_transaction_coa_id
17869          , x_accounting_coa_id        => l_adr_accounting_coa_id
17870          , x_value_type_code          => l_adr_value_type_code
17871          , p_side                     => 'NA'
17872    );
17873 
17874    xla_ae_lines_pkg.set_ccid(
17875     p_code_combination_id          => l_ccid
17876   , p_value_type_code              => l_adr_value_type_code
17877   , p_transaction_coa_id           => l_adr_transaction_coa_id
17878   , p_accounting_coa_id            => l_adr_accounting_coa_id
17879   , p_adr_code                     => 'TRX_DIST_CCID'
17880   , p_adr_type_code                => 'S'
17881   , p_component_type               => l_component_type
17882   , p_component_code               => l_component_code
17886   , p_side                         => 'NA'
17883   , p_component_type_code          => l_component_type_code
17884   , p_component_appl_id            => l_component_appl_id
17885   , p_amb_context_code             => l_amb_context_code
17887   );
17888 
17889 
17890    --
17891    --
17892    END IF;
17893    --
17894    -- Bug 4922099
17895    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
17896           (NVL(l_enc_upg_option, 'N') = 'O')
17897         ) AND
17898         (l_bflow_method_code = 'PRIOR_ENTRY')
17899       )
17900    THEN
17901       IF
17902       --
17903       1 = 2
17904       --
17905       THEN
17906       xla_accounting_err_pkg.build_message
17907                                     (p_appli_s_name            => 'XLA'
17908                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
17909                                     ,p_token_1                 => 'LINE_NUMBER'
17910                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
17911                                     ,p_token_2                 => 'LINE_TYPE_NAME'
17912                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
17913                                                                              l_component_type
17914                                                                             ,l_component_code
17915                                                                             ,l_component_type_code
17916                                                                             ,l_component_appl_id
17917                                                                             ,l_amb_context_code
17918                                                                             ,l_entity_code
17919                                                                             ,l_event_class_code
17920                                                                            )
17921                                     ,p_token_3                 => 'OWNER'
17922                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
17923                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
17924                                                                           ,p_lookup_code    => l_component_type_code
17925                                                                          )
17926                                     ,p_token_4                 => 'PRODUCT_NAME'
17927                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
17928                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
17929                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
17930                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
17931                                     ,p_ae_header_id            =>  NULL
17932                                        );
17933 
17934         IF (C_LEVEL_ERROR>= g_log_level) THEN
17935                  trace
17936                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
17937                       ,p_level    => C_LEVEL_ERROR
17938                       ,p_module   => l_log_module);
17939         END IF;
17940       END IF;
17941    END IF;
17942    --
17943    --
17944    ------------------------------------------------------------------------------------------------
17945    -- 4219869 Business Flow
17946    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
17947    -- Prior Entry.  Currently, the following code is always generated.
17948    ------------------------------------------------------------------------------------------------
17949    XLA_AE_LINES_PKG.ValidateCurrentLine;
17950 
17951    ------------------------------------------------------------------------------------
17952    -- 4219869 Business Flow
17953    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
17954    ------------------------------------------------------------------------------------
17955    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
17956 
17957    ----------------------------------------------------------------------------------
17958    -- 4219869 Business Flow
17959    -- Update journal entry status -- Need to generate this within IF <condition>
17960    ----------------------------------------------------------------------------------
17961    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
17962          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
17963          ,p_balance_type_code => l_balance_type_code
17964          );
17965 
17966    -------------------------------------------------------------------------------------------
17967    -- 4262811 - Generate the Accrual Reversal lines
17968    -------------------------------------------------------------------------------------------
17969    BEGIN
17970       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
17971                               (g_array_event(p_event_id).array_value_num('header_index'));
17972       IF l_acc_rev_flag IS NULL THEN
17973          l_acc_rev_flag := 'N';
17974       END IF;
17975    EXCEPTION
17976       WHEN OTHERS THEN
17977          l_acc_rev_flag := 'N';
17978    END;
17979    --
17980    IF (l_acc_rev_flag = 'Y') THEN
17981 
17985        ------------------------------------------------------------------------------------------
17982        -- 4645092  ------------------------------------------------------------------------------
17983        -- To allow MPA report to determine if it should generate report process
17984        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
17986 
17987        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
17988        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
17989    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
17990    -- call ADRs
17991    -- Bug 4922099
17992    --
17993    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
17994         (NVL(l_actual_upg_option, 'N') = 'O') OR
17995         (NVL(l_enc_upg_option, 'N') = 'O')
17996       )
17997    THEN
17998    NULL;
17999    --
18000    --
18001    
18002   l_ccid := AcctDerRule_32(
18003            p_application_id           => p_application_id
18004          , p_ae_header_id             => l_ae_header_id 
18005 , p_source_4 => p_source_4
18006          , x_transaction_coa_id       => l_adr_transaction_coa_id
18007          , x_accounting_coa_id        => l_adr_accounting_coa_id
18008          , x_value_type_code          => l_adr_value_type_code
18009          , p_side                     => 'NA'
18010    );
18011 
18012    xla_ae_lines_pkg.set_ccid(
18013     p_code_combination_id          => l_ccid
18014   , p_value_type_code              => l_adr_value_type_code
18015   , p_transaction_coa_id           => l_adr_transaction_coa_id
18016   , p_accounting_coa_id            => l_adr_accounting_coa_id
18017   , p_adr_code                     => 'TRX_DIST_CCID'
18018   , p_adr_type_code                => 'S'
18019   , p_component_type               => l_component_type
18020   , p_component_code               => l_component_code
18021   , p_component_type_code          => l_component_type_code
18022   , p_component_appl_id            => l_component_appl_id
18023   , p_amb_context_code             => l_amb_context_code
18024   , p_side                         => 'NA'
18025   );
18026 
18027 
18028    --
18029    --
18030    END IF;
18031 
18032        --
18033        -- Update the line information that should be overwritten
18034        --
18035        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
18036                                          p_header_num   => 1);
18037        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
18038 
18039        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
18040 
18041        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
18042           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
18043        END IF;
18044 
18045       --
18046       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
18047       --
18048       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
18049           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
18050       ELSE
18051           ---------------------------------------------------------------------------------------------------
18052           -- 4262811a Switch Sign
18053           ---------------------------------------------------------------------------------------------------
18054           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
18055           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
18056                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
18057           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
18058                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
18059           -- 5132302
18060           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
18061                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
18062 
18063       END IF;
18064 
18065       -- 4955764
18066       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
18067       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
18068 
18069 
18070       XLA_AE_LINES_PKG.ValidateCurrentLine;
18071       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
18072 
18073       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
18074                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
18075                ,p_balance_type_code => l_balance_type_code);
18076 
18077    END IF;
18078 
18079    -----------------------------------------------------------------------------------------
18080    -- 4262811 Multiperiod Accounting
18081    -----------------------------------------------------------------------------------------
18082      -- No MPA option is assigned.
18083 
18084 
18085 END IF;
18086 END IF;
18087 --
18088 
18089 --
18090 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18091    trace
18092       (p_msg      => 'END of AcctLineType_56'
18093       ,p_level    => C_LEVEL_PROCEDURE
18094       ,p_module   => l_log_module);
18095 END IF;
18096 --
18100   WHEN OTHERS THEN
18097 EXCEPTION
18098   WHEN xla_exceptions_pkg.application_exception THEN
18099       RAISE;
18101        xla_exceptions_pkg.raise_message
18102            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_56');
18103 END AcctLineType_56;
18104 --
18105 
18106 ---------------------------------------
18107 --
18108 -- PRIVATE FUNCTION
18109 --         AcctLineType_57
18110 --
18111 ---------------------------------------
18112 PROCEDURE AcctLineType_57 (
18113   p_application_id        IN NUMBER
18114  ,p_event_id              IN NUMBER
18115  ,p_calculate_acctd_flag  IN VARCHAR2
18116  ,p_calculate_g_l_flag    IN VARCHAR2
18117  ,p_actual_flag           IN OUT VARCHAR2
18118  ,p_balance_type_code     OUT VARCHAR2
18119  ,p_gain_or_loss_ref      OUT VARCHAR2
18120  
18121 --Transaction Distribution GL Account
18122  , p_source_4            IN NUMBER
18123 --Bill To Customer Account Identifier
18124  , p_source_30            IN NUMBER
18125 --Bill To Customer Site Use Identifier
18126  , p_source_31            IN NUMBER
18127 --SLA Party Type
18128  , p_source_32            IN VARCHAR2
18129 --Transaction Distribution Account Class
18130  , p_source_33            IN VARCHAR2
18131 --Transaction Distribution Identifier
18132  , p_source_34            IN NUMBER
18133 --Transaction Distribution Type
18134  , p_source_35            IN VARCHAR2
18135 --Transaction Distribution Entered Amount
18136  , p_source_36            IN NUMBER
18137 --Transaction Currency Code
18138  , p_source_37            IN VARCHAR2
18139 --Transaction Exchange Date
18140  , p_source_38            IN DATE
18141 --Transaction Exchange Rate
18142  , p_source_39            IN NUMBER
18143 --Transaction Exchange Rate Type
18144  , p_source_40            IN VARCHAR2
18145 --Transaction Accounting Amount
18146  , p_source_41            IN NUMBER
18147 --Transaction Tax Line Identifier
18148  , p_source_55            IN NUMBER
18149 )
18150 IS
18151 
18152 l_component_type              VARCHAR2(80);
18153 l_component_code              VARCHAR2(30);
18154 l_component_type_code         VARCHAR2(1);
18155 l_component_appl_id           INTEGER;
18156 l_amb_context_code            VARCHAR2(30);
18157 l_entity_code                 VARCHAR2(30);
18158 l_event_class_code            VARCHAR2(30);
18159 l_ae_header_id                NUMBER;
18160 l_event_type_code             VARCHAR2(30);
18161 l_line_definition_code        VARCHAR2(30);
18162 l_line_definition_owner_code  VARCHAR2(1);
18163 --
18164 -- adr variables
18165 l_segment                     VARCHAR2(30);
18166 l_ccid                        NUMBER;
18167 l_adr_transaction_coa_id      NUMBER;
18168 l_adr_accounting_coa_id       NUMBER;
18169 l_adr_flexfield_segment_code  VARCHAR2(30);
18170 l_adr_flex_value_set_id       NUMBER;
18171 l_adr_value_type_code         VARCHAR2(30);
18172 l_adr_value_combination_id    NUMBER;
18173 l_adr_value_segment_code      VARCHAR2(30);
18174 
18175 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
18176 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
18177 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
18178 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
18179 
18180 -- 4262811 Variables ------------------------------------------------------------------------------------------
18181 l_entered_amt_idx             NUMBER;
18182 l_accted_amt_idx              NUMBER;
18183 l_acc_rev_flag                VARCHAR2(1);
18184 l_accrual_line_num            NUMBER;
18185 l_tmp_amt                     NUMBER;
18186 l_acc_rev_natural_side_code   VARCHAR2(1);
18187 
18188 l_num_entries                 NUMBER;
18189 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
18190 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
18191 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
18192 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
18193 l_recog_line_1                NUMBER;
18194 l_recog_line_2                NUMBER;
18195 
18196 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
18197 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
18198 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
18199 
18200 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
18201 
18202 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
18203 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
18204 
18205 ---------------------------------------------------------------------------------------------------------------
18206 
18207 
18208 --
18209 -- bulk performance
18210 --
18211 l_balance_type_code           VARCHAR2(1);
18212 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
18213 l_log_module                  VARCHAR2(240);
18214 
18215 --
18216 -- Upgrade strategy
18217 --
18218 l_actual_upg_option           VARCHAR2(1);
18219 l_enc_upg_option           VARCHAR2(1);
18220 
18221 --
18222 BEGIN
18223 --
18224 IF g_log_enabled THEN
18225       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_57';
18226 END IF;
18227 --
18228 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18229 
18233          ,p_module   => l_log_module);
18230       trace
18231          (p_msg      => 'BEGIN of AcctLineType_57'
18232          ,p_level    => C_LEVEL_PROCEDURE
18234 
18235 END IF;
18236 --
18237 l_component_type             := 'AMB_JLT';
18238 l_component_code             := 'DM_UNBILL';
18239 l_component_type_code        := 'S';
18240 l_component_appl_id          :=  222;
18241 l_amb_context_code           := 'DEFAULT';
18242 l_entity_code                := 'TRANSACTIONS';
18243 l_event_class_code           := 'DEBIT_MEMO';
18244 l_event_type_code            := 'DEBIT_MEMO_ALL';
18245 l_line_definition_owner_code := 'S';
18246 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
18247 --
18248 l_balance_type_code          := 'A';
18249 l_segment                     := NULL;
18250 l_ccid                        := NULL;
18251 l_adr_transaction_coa_id      := NULL;
18252 l_adr_accounting_coa_id       := NULL;
18253 l_adr_flexfield_segment_code  := NULL;
18254 l_adr_flex_value_set_id       := NULL;
18255 l_adr_value_type_code         := NULL;
18256 l_adr_value_combination_id    := NULL;
18257 l_adr_value_segment_code      := NULL;
18258 
18259 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
18260 l_bflow_class_code           := '';    -- 4219869 Business Flow
18261 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
18262 l_budgetary_control_flag     := 'N';
18263 
18264 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
18265 l_bflow_applied_to_amt       := NULL; -- 5132302
18266 l_entered_amt_idx            := NULL;          -- 4262811
18267 l_accted_amt_idx             := NULL;          -- 4262811
18268 l_acc_rev_flag               := NULL;          -- 4262811
18269 l_accrual_line_num           := NULL;          -- 4262811
18270 l_tmp_amt                    := NULL;          -- 4262811
18271 --
18272  
18273 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
18274     l_balance_type_code <> 'B' THEN
18275 IF NVL(p_source_33,'
18276 ') =  'UNBILL'
18277  THEN 
18278 
18279    --
18280    XLA_AE_LINES_PKG.SetNewLine;
18281 
18282    p_balance_type_code          := l_balance_type_code;
18283    -- set the flag so later we will know whether the gain loss line needs to be created
18284    
18285    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
18286      p_actual_flag :='A';
18287    END IF;
18288 
18289    --
18290    -- bulk performance
18291    --
18292    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
18293                                       p_header_num   => 0); -- 4262811
18294    --
18295    -- set accounting line options
18296    --
18297    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
18298            p_natural_side_code          => 'D'
18299          , p_gain_or_loss_flag          => 'N'
18300          , p_gl_transfer_mode_code      => 'S'
18301          , p_acct_entry_type_code       => 'A'
18302          , p_switch_side_flag           => 'Y'
18303          , p_merge_duplicate_code       => 'A'
18304          );
18305    --
18306    l_acc_rev_natural_side_code := 'C';  -- 4262811
18307    -- 
18308    --
18309    -- set accounting line type info
18310    --
18311    xla_ae_lines_pkg.SetAcctLineType
18312       (p_component_type             => l_component_type
18313       ,p_event_type_code            => l_event_type_code
18314       ,p_line_definition_owner_code => l_line_definition_owner_code
18315       ,p_line_definition_code       => l_line_definition_code
18316       ,p_accounting_line_code       => l_component_code
18317       ,p_accounting_line_type_code  => l_component_type_code
18318       ,p_accounting_line_appl_id    => l_component_appl_id
18319       ,p_amb_context_code           => l_amb_context_code
18320       ,p_entity_code                => l_entity_code
18321       ,p_event_class_code           => l_event_class_code);
18322    --
18323    -- set accounting class
18324    --
18325    xla_ae_lines_pkg.SetAcctClass(
18326            p_accounting_class_code  => 'UNBILL'
18327          , p_ae_header_id           => l_ae_header_id
18328          );
18329 
18330    --
18331    -- set rounding class
18332    --
18333    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
18334                       'RECEIVABLE';
18335 
18336    --
18337    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
18338    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
18339    --
18340    -- bulk performance
18341    --
18342    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
18343 
18344    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
18345       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
18346 
18347    -- 4955764
18348    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
18349       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
18350 
18351    -- 4458381 Public Sector Enh
18352    
18353    --
18354    -- set accounting attributes for the line type
18355    --
18356    l_entered_amt_idx := 3;
18357    l_accted_amt_idx  := 8;
18358    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
18362    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
18359    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
18360    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
18361    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
18363    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
18364    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
18365    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
18366    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
18367    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
18368    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
18369    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
18370    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
18371    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
18372    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
18373    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
18374    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
18375    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
18376    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
18377    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
18378    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
18379    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
18380    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
18381    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
18382    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
18383 
18384    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
18385    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
18386 
18387    ---------------------------------------------------------------------------------------------------------------
18388    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
18389    ---------------------------------------------------------------------------------------------------------------
18390    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
18391 
18392    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
18393    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
18394 
18395    IF xla_accounting_cache_pkg.GetValueChar
18396          (p_source_code         => 'LEDGER_CATEGORY_CODE'
18397          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
18398    AND l_bflow_method_code = 'PRIOR_ENTRY'
18399 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
18400    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
18401          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
18402        )
18403    THEN
18404          xla_ae_lines_pkg.BflowUpgEntry
18405            (p_business_method_code    => l_bflow_method_code
18406            ,p_business_class_code     => l_bflow_class_code
18407            ,p_balance_type            => l_balance_type_code);
18408    ELSE
18409       NULL;
18410 -- No business flow processing for business flow method of NONE.
18411    END IF;
18412 
18413    --
18414    -- call analytical criteria
18415    --
18416    
18417    --
18418    -- call description
18419    --
18420    -- No description or it is inherited.
18421    --
18422    -- call ADRs
18423    -- Bug 4922099
18424    --
18425    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
18426         (NVL(l_actual_upg_option, 'N') = 'O') OR
18427         (NVL(l_enc_upg_option, 'N') = 'O')
18428       )
18429    THEN
18430    NULL;
18431    --
18432    --
18433    
18434   l_ccid := AcctDerRule_32(
18435            p_application_id           => p_application_id
18436          , p_ae_header_id             => l_ae_header_id 
18437 , p_source_4 => p_source_4
18438          , x_transaction_coa_id       => l_adr_transaction_coa_id
18439          , x_accounting_coa_id        => l_adr_accounting_coa_id
18440          , x_value_type_code          => l_adr_value_type_code
18441          , p_side                     => 'NA'
18442    );
18443 
18444    xla_ae_lines_pkg.set_ccid(
18445     p_code_combination_id          => l_ccid
18446   , p_value_type_code              => l_adr_value_type_code
18447   , p_transaction_coa_id           => l_adr_transaction_coa_id
18448   , p_accounting_coa_id            => l_adr_accounting_coa_id
18449   , p_adr_code                     => 'TRX_DIST_CCID'
18450   , p_adr_type_code                => 'S'
18451   , p_component_type               => l_component_type
18452   , p_component_code               => l_component_code
18453   , p_component_type_code          => l_component_type_code
18454   , p_component_appl_id            => l_component_appl_id
18455   , p_amb_context_code             => l_amb_context_code
18456   , p_side                         => 'NA'
18457   );
18458 
18459 
18460    --
18461    --
18462    END IF;
18463    --
18464    -- Bug 4922099
18465    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
18466           (NVL(l_enc_upg_option, 'N') = 'O')
18467         ) AND
18468         (l_bflow_method_code = 'PRIOR_ENTRY')
18469       )
18470    THEN
18471       IF
18472       --
18473       1 = 2
18474       --
18475       THEN
18476       xla_accounting_err_pkg.build_message
18477                                     (p_appli_s_name            => 'XLA'
18481                                     ,p_token_2                 => 'LINE_TYPE_NAME'
18478                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
18479                                     ,p_token_1                 => 'LINE_NUMBER'
18480                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
18482                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
18483                                                                              l_component_type
18484                                                                             ,l_component_code
18485                                                                             ,l_component_type_code
18486                                                                             ,l_component_appl_id
18487                                                                             ,l_amb_context_code
18488                                                                             ,l_entity_code
18489                                                                             ,l_event_class_code
18490                                                                            )
18491                                     ,p_token_3                 => 'OWNER'
18492                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
18493                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
18494                                                                           ,p_lookup_code    => l_component_type_code
18495                                                                          )
18496                                     ,p_token_4                 => 'PRODUCT_NAME'
18497                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
18498                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
18499                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
18500                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
18501                                     ,p_ae_header_id            =>  NULL
18502                                        );
18503 
18504         IF (C_LEVEL_ERROR>= g_log_level) THEN
18505                  trace
18506                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
18507                       ,p_level    => C_LEVEL_ERROR
18508                       ,p_module   => l_log_module);
18509         END IF;
18510       END IF;
18511    END IF;
18512    --
18513    --
18514    ------------------------------------------------------------------------------------------------
18515    -- 4219869 Business Flow
18516    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
18517    -- Prior Entry.  Currently, the following code is always generated.
18518    ------------------------------------------------------------------------------------------------
18519    XLA_AE_LINES_PKG.ValidateCurrentLine;
18520 
18521    ------------------------------------------------------------------------------------
18522    -- 4219869 Business Flow
18523    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
18524    ------------------------------------------------------------------------------------
18525    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
18526 
18527    ----------------------------------------------------------------------------------
18528    -- 4219869 Business Flow
18529    -- Update journal entry status -- Need to generate this within IF <condition>
18530    ----------------------------------------------------------------------------------
18531    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
18532          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
18533          ,p_balance_type_code => l_balance_type_code
18534          );
18535 
18536    -------------------------------------------------------------------------------------------
18537    -- 4262811 - Generate the Accrual Reversal lines
18538    -------------------------------------------------------------------------------------------
18539    BEGIN
18540       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
18541                               (g_array_event(p_event_id).array_value_num('header_index'));
18542       IF l_acc_rev_flag IS NULL THEN
18543          l_acc_rev_flag := 'N';
18544       END IF;
18545    EXCEPTION
18546       WHEN OTHERS THEN
18547          l_acc_rev_flag := 'N';
18548    END;
18549    --
18550    IF (l_acc_rev_flag = 'Y') THEN
18551 
18552        -- 4645092  ------------------------------------------------------------------------------
18553        -- To allow MPA report to determine if it should generate report process
18554        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
18555        ------------------------------------------------------------------------------------------
18556 
18557        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
18558        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
18559    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
18560    -- call ADRs
18561    -- Bug 4922099
18562    --
18563    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
18564         (NVL(l_actual_upg_option, 'N') = 'O') OR
18565         (NVL(l_enc_upg_option, 'N') = 'O')
18566       )
18567    THEN
18568    NULL;
18569    --
18570    --
18571    
18575 , p_source_4 => p_source_4
18572   l_ccid := AcctDerRule_32(
18573            p_application_id           => p_application_id
18574          , p_ae_header_id             => l_ae_header_id 
18576          , x_transaction_coa_id       => l_adr_transaction_coa_id
18577          , x_accounting_coa_id        => l_adr_accounting_coa_id
18578          , x_value_type_code          => l_adr_value_type_code
18579          , p_side                     => 'NA'
18580    );
18581 
18582    xla_ae_lines_pkg.set_ccid(
18583     p_code_combination_id          => l_ccid
18584   , p_value_type_code              => l_adr_value_type_code
18585   , p_transaction_coa_id           => l_adr_transaction_coa_id
18586   , p_accounting_coa_id            => l_adr_accounting_coa_id
18587   , p_adr_code                     => 'TRX_DIST_CCID'
18588   , p_adr_type_code                => 'S'
18589   , p_component_type               => l_component_type
18590   , p_component_code               => l_component_code
18591   , p_component_type_code          => l_component_type_code
18592   , p_component_appl_id            => l_component_appl_id
18593   , p_amb_context_code             => l_amb_context_code
18594   , p_side                         => 'NA'
18595   );
18596 
18597 
18598    --
18599    --
18600    END IF;
18601 
18602        --
18603        -- Update the line information that should be overwritten
18604        --
18605        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
18606                                          p_header_num   => 1);
18607        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
18608 
18609        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
18610 
18611        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
18612           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
18613        END IF;
18614 
18615       --
18616       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
18617       --
18618       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
18619           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
18620       ELSE
18621           ---------------------------------------------------------------------------------------------------
18622           -- 4262811a Switch Sign
18623           ---------------------------------------------------------------------------------------------------
18624           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
18625           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
18626                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
18627           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
18628                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
18629           -- 5132302
18630           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
18631                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
18632 
18633       END IF;
18634 
18635       -- 4955764
18636       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
18637       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
18638 
18639 
18640       XLA_AE_LINES_PKG.ValidateCurrentLine;
18641       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
18642 
18643       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
18644                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
18645                ,p_balance_type_code => l_balance_type_code);
18646 
18647    END IF;
18648 
18649    -----------------------------------------------------------------------------------------
18650    -- 4262811 Multiperiod Accounting
18651    -----------------------------------------------------------------------------------------
18652      -- No MPA option is assigned.
18653 
18654 
18655 END IF;
18656 END IF;
18657 --
18658 
18659 --
18660 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18661    trace
18662       (p_msg      => 'END of AcctLineType_57'
18663       ,p_level    => C_LEVEL_PROCEDURE
18664       ,p_module   => l_log_module);
18665 END IF;
18666 --
18667 EXCEPTION
18668   WHEN xla_exceptions_pkg.application_exception THEN
18669       RAISE;
18670   WHEN OTHERS THEN
18671        xla_exceptions_pkg.raise_message
18672            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_57');
18673 END AcctLineType_57;
18674 --
18675 
18676 ---------------------------------------
18677 --
18678 -- PRIVATE FUNCTION
18679 --         AcctLineType_58
18680 --
18681 ---------------------------------------
18682 PROCEDURE AcctLineType_58 (
18683   p_application_id        IN NUMBER
18684  ,p_event_id              IN NUMBER
18685  ,p_calculate_acctd_flag  IN VARCHAR2
18686  ,p_calculate_g_l_flag    IN VARCHAR2
18687  ,p_actual_flag           IN OUT VARCHAR2
18688  ,p_balance_type_code     OUT VARCHAR2
18689  ,p_gain_or_loss_ref      OUT VARCHAR2
18690  
18694  , p_source_30            IN NUMBER
18691 --Transaction Distribution GL Account
18692  , p_source_4            IN NUMBER
18693 --Bill To Customer Account Identifier
18695 --Bill To Customer Site Use Identifier
18696  , p_source_31            IN NUMBER
18697 --SLA Party Type
18698  , p_source_32            IN VARCHAR2
18699 --Transaction Distribution Account Class
18700  , p_source_33            IN VARCHAR2
18701 --Transaction Distribution Identifier
18702  , p_source_34            IN NUMBER
18703 --Transaction Distribution Type
18704  , p_source_35            IN VARCHAR2
18705 --Transaction Distribution Entered Amount
18706  , p_source_36            IN NUMBER
18707 --Transaction Currency Code
18708  , p_source_37            IN VARCHAR2
18709 --Transaction Exchange Date
18710  , p_source_38            IN DATE
18711 --Transaction Exchange Rate
18712  , p_source_39            IN NUMBER
18713 --Transaction Exchange Rate Type
18714  , p_source_40            IN VARCHAR2
18715 --Transaction Accounting Amount
18716  , p_source_41            IN NUMBER
18717 --Transaction Tax Line Identifier
18718  , p_source_55            IN NUMBER
18719 )
18720 IS
18721 
18722 l_component_type              VARCHAR2(80);
18723 l_component_code              VARCHAR2(30);
18724 l_component_type_code         VARCHAR2(1);
18725 l_component_appl_id           INTEGER;
18726 l_amb_context_code            VARCHAR2(30);
18727 l_entity_code                 VARCHAR2(30);
18728 l_event_class_code            VARCHAR2(30);
18729 l_ae_header_id                NUMBER;
18730 l_event_type_code             VARCHAR2(30);
18731 l_line_definition_code        VARCHAR2(30);
18732 l_line_definition_owner_code  VARCHAR2(1);
18733 --
18734 -- adr variables
18735 l_segment                     VARCHAR2(30);
18736 l_ccid                        NUMBER;
18737 l_adr_transaction_coa_id      NUMBER;
18738 l_adr_accounting_coa_id       NUMBER;
18739 l_adr_flexfield_segment_code  VARCHAR2(30);
18740 l_adr_flex_value_set_id       NUMBER;
18741 l_adr_value_type_code         VARCHAR2(30);
18742 l_adr_value_combination_id    NUMBER;
18743 l_adr_value_segment_code      VARCHAR2(30);
18744 
18745 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
18746 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
18747 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
18748 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
18749 
18750 -- 4262811 Variables ------------------------------------------------------------------------------------------
18751 l_entered_amt_idx             NUMBER;
18752 l_accted_amt_idx              NUMBER;
18753 l_acc_rev_flag                VARCHAR2(1);
18754 l_accrual_line_num            NUMBER;
18755 l_tmp_amt                     NUMBER;
18756 l_acc_rev_natural_side_code   VARCHAR2(1);
18757 
18758 l_num_entries                 NUMBER;
18759 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
18760 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
18761 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
18762 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
18763 l_recog_line_1                NUMBER;
18764 l_recog_line_2                NUMBER;
18765 
18766 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
18767 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
18768 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
18769 
18770 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
18771 
18772 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
18773 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
18774 
18775 ---------------------------------------------------------------------------------------------------------------
18776 
18777 
18778 --
18779 -- bulk performance
18780 --
18781 l_balance_type_code           VARCHAR2(1);
18782 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
18783 l_log_module                  VARCHAR2(240);
18784 
18785 --
18786 -- Upgrade strategy
18787 --
18788 l_actual_upg_option           VARCHAR2(1);
18789 l_enc_upg_option           VARCHAR2(1);
18790 
18791 --
18792 BEGIN
18793 --
18794 IF g_log_enabled THEN
18795       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_58';
18796 END IF;
18797 --
18798 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18799 
18800       trace
18801          (p_msg      => 'BEGIN of AcctLineType_58'
18802          ,p_level    => C_LEVEL_PROCEDURE
18803          ,p_module   => l_log_module);
18804 
18805 END IF;
18806 --
18807 l_component_type             := 'AMB_JLT';
18808 l_component_code             := 'DM_UNEARN';
18809 l_component_type_code        := 'S';
18810 l_component_appl_id          :=  222;
18811 l_amb_context_code           := 'DEFAULT';
18812 l_entity_code                := 'TRANSACTIONS';
18813 l_event_class_code           := 'DEBIT_MEMO';
18814 l_event_type_code            := 'DEBIT_MEMO_ALL';
18815 l_line_definition_owner_code := 'S';
18816 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
18817 --
18818 l_balance_type_code          := 'A';
18819 l_segment                     := NULL;
18823 l_adr_flexfield_segment_code  := NULL;
18820 l_ccid                        := NULL;
18821 l_adr_transaction_coa_id      := NULL;
18822 l_adr_accounting_coa_id       := NULL;
18824 l_adr_flex_value_set_id       := NULL;
18825 l_adr_value_type_code         := NULL;
18826 l_adr_value_combination_id    := NULL;
18827 l_adr_value_segment_code      := NULL;
18828 
18829 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
18830 l_bflow_class_code           := '';    -- 4219869 Business Flow
18831 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
18832 l_budgetary_control_flag     := 'N';
18833 
18834 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
18835 l_bflow_applied_to_amt       := NULL; -- 5132302
18836 l_entered_amt_idx            := NULL;          -- 4262811
18837 l_accted_amt_idx             := NULL;          -- 4262811
18838 l_acc_rev_flag               := NULL;          -- 4262811
18839 l_accrual_line_num           := NULL;          -- 4262811
18840 l_tmp_amt                    := NULL;          -- 4262811
18841 --
18842  
18843 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
18844     l_balance_type_code <> 'B' THEN
18845 IF NVL(p_source_33,'
18846 ') =  'UNEARN'
18847  THEN 
18848 
18849    --
18850    XLA_AE_LINES_PKG.SetNewLine;
18851 
18852    p_balance_type_code          := l_balance_type_code;
18853    -- set the flag so later we will know whether the gain loss line needs to be created
18854    
18855    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
18856      p_actual_flag :='A';
18857    END IF;
18858 
18859    --
18860    -- bulk performance
18861    --
18862    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
18863                                       p_header_num   => 0); -- 4262811
18864    --
18865    -- set accounting line options
18866    --
18867    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
18868            p_natural_side_code          => 'C'
18869          , p_gain_or_loss_flag          => 'N'
18870          , p_gl_transfer_mode_code      => 'S'
18871          , p_acct_entry_type_code       => 'A'
18872          , p_switch_side_flag           => 'Y'
18873          , p_merge_duplicate_code       => 'A'
18874          );
18875    --
18876    l_acc_rev_natural_side_code := 'D';  -- 4262811
18877    -- 
18878    --
18879    -- set accounting line type info
18880    --
18881    xla_ae_lines_pkg.SetAcctLineType
18882       (p_component_type             => l_component_type
18883       ,p_event_type_code            => l_event_type_code
18884       ,p_line_definition_owner_code => l_line_definition_owner_code
18885       ,p_line_definition_code       => l_line_definition_code
18886       ,p_accounting_line_code       => l_component_code
18887       ,p_accounting_line_type_code  => l_component_type_code
18888       ,p_accounting_line_appl_id    => l_component_appl_id
18889       ,p_amb_context_code           => l_amb_context_code
18890       ,p_entity_code                => l_entity_code
18891       ,p_event_class_code           => l_event_class_code);
18892    --
18893    -- set accounting class
18894    --
18895    xla_ae_lines_pkg.SetAcctClass(
18896            p_accounting_class_code  => 'UNEARNED_REVENUE'
18897          , p_ae_header_id           => l_ae_header_id
18898          );
18899 
18900    --
18901    -- set rounding class
18902    --
18903    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
18904                       'RECEIVABLE';
18905 
18906    --
18907    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
18908    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
18909    --
18910    -- bulk performance
18911    --
18912    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
18913 
18914    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
18915       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
18916 
18917    -- 4955764
18918    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
18919       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
18920 
18921    -- 4458381 Public Sector Enh
18922    
18923    --
18924    -- set accounting attributes for the line type
18925    --
18926    l_entered_amt_idx := 3;
18927    l_accted_amt_idx  := 8;
18928    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
18929    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
18930    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
18931    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
18932    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
18933    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
18934    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
18935    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
18936    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
18937    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
18938    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
18939    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
18940    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
18941    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
18945    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
18942    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
18943    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
18944    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
18946    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
18947    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
18948    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
18949    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
18950    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
18951    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
18952    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
18953 
18954    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
18955    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
18956 
18957    ---------------------------------------------------------------------------------------------------------------
18958    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
18959    ---------------------------------------------------------------------------------------------------------------
18960    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
18961 
18962    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
18963    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
18964 
18965    IF xla_accounting_cache_pkg.GetValueChar
18966          (p_source_code         => 'LEDGER_CATEGORY_CODE'
18967          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
18968    AND l_bflow_method_code = 'PRIOR_ENTRY'
18969 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
18970    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
18971          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
18972        )
18973    THEN
18974          xla_ae_lines_pkg.BflowUpgEntry
18975            (p_business_method_code    => l_bflow_method_code
18976            ,p_business_class_code     => l_bflow_class_code
18977            ,p_balance_type            => l_balance_type_code);
18978    ELSE
18979       NULL;
18980 -- No business flow processing for business flow method of NONE.
18981    END IF;
18982 
18983    --
18984    -- call analytical criteria
18985    --
18986    
18987    --
18988    -- call description
18989    --
18990    -- No description or it is inherited.
18991    --
18992    -- call ADRs
18993    -- Bug 4922099
18994    --
18995    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
18996         (NVL(l_actual_upg_option, 'N') = 'O') OR
18997         (NVL(l_enc_upg_option, 'N') = 'O')
18998       )
18999    THEN
19000    NULL;
19001    --
19002    --
19003    
19004   l_ccid := AcctDerRule_32(
19005            p_application_id           => p_application_id
19006          , p_ae_header_id             => l_ae_header_id 
19007 , p_source_4 => p_source_4
19008          , x_transaction_coa_id       => l_adr_transaction_coa_id
19009          , x_accounting_coa_id        => l_adr_accounting_coa_id
19010          , x_value_type_code          => l_adr_value_type_code
19011          , p_side                     => 'NA'
19012    );
19013 
19014    xla_ae_lines_pkg.set_ccid(
19015     p_code_combination_id          => l_ccid
19016   , p_value_type_code              => l_adr_value_type_code
19017   , p_transaction_coa_id           => l_adr_transaction_coa_id
19018   , p_accounting_coa_id            => l_adr_accounting_coa_id
19019   , p_adr_code                     => 'TRX_DIST_CCID'
19020   , p_adr_type_code                => 'S'
19021   , p_component_type               => l_component_type
19022   , p_component_code               => l_component_code
19023   , p_component_type_code          => l_component_type_code
19024   , p_component_appl_id            => l_component_appl_id
19025   , p_amb_context_code             => l_amb_context_code
19026   , p_side                         => 'NA'
19027   );
19028 
19029 
19030    --
19031    --
19032    END IF;
19033    --
19034    -- Bug 4922099
19035    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
19036           (NVL(l_enc_upg_option, 'N') = 'O')
19037         ) AND
19038         (l_bflow_method_code = 'PRIOR_ENTRY')
19039       )
19040    THEN
19041       IF
19042       --
19043       1 = 2
19044       --
19045       THEN
19046       xla_accounting_err_pkg.build_message
19047                                     (p_appli_s_name            => 'XLA'
19048                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
19049                                     ,p_token_1                 => 'LINE_NUMBER'
19050                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
19051                                     ,p_token_2                 => 'LINE_TYPE_NAME'
19052                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
19053                                                                              l_component_type
19054                                                                             ,l_component_code
19055                                                                             ,l_component_type_code
19056                                                                             ,l_component_appl_id
19060                                                                            )
19057                                                                             ,l_amb_context_code
19058                                                                             ,l_entity_code
19059                                                                             ,l_event_class_code
19061                                     ,p_token_3                 => 'OWNER'
19062                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
19063                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
19064                                                                           ,p_lookup_code    => l_component_type_code
19065                                                                          )
19066                                     ,p_token_4                 => 'PRODUCT_NAME'
19067                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
19068                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
19069                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
19070                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
19071                                     ,p_ae_header_id            =>  NULL
19072                                        );
19073 
19074         IF (C_LEVEL_ERROR>= g_log_level) THEN
19075                  trace
19076                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
19077                       ,p_level    => C_LEVEL_ERROR
19078                       ,p_module   => l_log_module);
19079         END IF;
19080       END IF;
19081    END IF;
19082    --
19083    --
19084    ------------------------------------------------------------------------------------------------
19085    -- 4219869 Business Flow
19086    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
19087    -- Prior Entry.  Currently, the following code is always generated.
19088    ------------------------------------------------------------------------------------------------
19089    XLA_AE_LINES_PKG.ValidateCurrentLine;
19090 
19091    ------------------------------------------------------------------------------------
19092    -- 4219869 Business Flow
19093    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
19094    ------------------------------------------------------------------------------------
19095    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
19096 
19097    ----------------------------------------------------------------------------------
19098    -- 4219869 Business Flow
19099    -- Update journal entry status -- Need to generate this within IF <condition>
19100    ----------------------------------------------------------------------------------
19101    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
19102          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
19103          ,p_balance_type_code => l_balance_type_code
19104          );
19105 
19106    -------------------------------------------------------------------------------------------
19107    -- 4262811 - Generate the Accrual Reversal lines
19108    -------------------------------------------------------------------------------------------
19109    BEGIN
19110       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
19111                               (g_array_event(p_event_id).array_value_num('header_index'));
19112       IF l_acc_rev_flag IS NULL THEN
19113          l_acc_rev_flag := 'N';
19114       END IF;
19115    EXCEPTION
19116       WHEN OTHERS THEN
19117          l_acc_rev_flag := 'N';
19118    END;
19119    --
19120    IF (l_acc_rev_flag = 'Y') THEN
19121 
19122        -- 4645092  ------------------------------------------------------------------------------
19123        -- To allow MPA report to determine if it should generate report process
19124        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
19125        ------------------------------------------------------------------------------------------
19126 
19127        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
19128        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
19129    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
19130    -- call ADRs
19131    -- Bug 4922099
19132    --
19133    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
19134         (NVL(l_actual_upg_option, 'N') = 'O') OR
19135         (NVL(l_enc_upg_option, 'N') = 'O')
19136       )
19137    THEN
19138    NULL;
19139    --
19140    --
19141    
19142   l_ccid := AcctDerRule_32(
19143            p_application_id           => p_application_id
19144          , p_ae_header_id             => l_ae_header_id 
19145 , p_source_4 => p_source_4
19146          , x_transaction_coa_id       => l_adr_transaction_coa_id
19147          , x_accounting_coa_id        => l_adr_accounting_coa_id
19148          , x_value_type_code          => l_adr_value_type_code
19149          , p_side                     => 'NA'
19150    );
19151 
19152    xla_ae_lines_pkg.set_ccid(
19153     p_code_combination_id          => l_ccid
19154   , p_value_type_code              => l_adr_value_type_code
19155   , p_transaction_coa_id           => l_adr_transaction_coa_id
19156   , p_accounting_coa_id            => l_adr_accounting_coa_id
19157   , p_adr_code                     => 'TRX_DIST_CCID'
19161   , p_component_type_code          => l_component_type_code
19158   , p_adr_type_code                => 'S'
19159   , p_component_type               => l_component_type
19160   , p_component_code               => l_component_code
19162   , p_component_appl_id            => l_component_appl_id
19163   , p_amb_context_code             => l_amb_context_code
19164   , p_side                         => 'NA'
19165   );
19166 
19167 
19168    --
19169    --
19170    END IF;
19171 
19172        --
19173        -- Update the line information that should be overwritten
19174        --
19175        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
19176                                          p_header_num   => 1);
19177        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
19178 
19179        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
19180 
19181        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
19182           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
19183        END IF;
19184 
19185       --
19186       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
19187       --
19188       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
19189           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
19190       ELSE
19191           ---------------------------------------------------------------------------------------------------
19192           -- 4262811a Switch Sign
19193           ---------------------------------------------------------------------------------------------------
19194           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
19195           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
19196                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19197           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
19198                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19199           -- 5132302
19200           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
19201                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19202 
19203       END IF;
19204 
19205       -- 4955764
19206       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
19207       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
19208 
19209 
19210       XLA_AE_LINES_PKG.ValidateCurrentLine;
19211       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
19212 
19213       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
19214                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
19215                ,p_balance_type_code => l_balance_type_code);
19216 
19217    END IF;
19218 
19219    -----------------------------------------------------------------------------------------
19220    -- 4262811 Multiperiod Accounting
19221    -----------------------------------------------------------------------------------------
19222      -- No MPA option is assigned.
19223 
19224 
19225 END IF;
19226 END IF;
19227 --
19228 
19229 --
19230 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19231    trace
19232       (p_msg      => 'END of AcctLineType_58'
19233       ,p_level    => C_LEVEL_PROCEDURE
19234       ,p_module   => l_log_module);
19235 END IF;
19236 --
19237 EXCEPTION
19238   WHEN xla_exceptions_pkg.application_exception THEN
19239       RAISE;
19240   WHEN OTHERS THEN
19241        xla_exceptions_pkg.raise_message
19242            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_58');
19243 END AcctLineType_58;
19244 --
19245 
19246 ---------------------------------------
19247 --
19248 -- PRIVATE FUNCTION
19249 --         AcctLineType_59
19250 --
19251 ---------------------------------------
19252 PROCEDURE AcctLineType_59 (
19253   p_application_id        IN NUMBER
19254  ,p_event_id              IN NUMBER
19255  ,p_calculate_acctd_flag  IN VARCHAR2
19256  ,p_calculate_g_l_flag    IN VARCHAR2
19257  ,p_actual_flag           IN OUT VARCHAR2
19258  ,p_balance_type_code     OUT VARCHAR2
19259  ,p_gain_or_loss_ref      OUT VARCHAR2
19260  
19261 --Transaction Distribution GL Account
19262  , p_source_4            IN NUMBER
19263 --Federal Fund Category
19264  , p_source_5            IN VARCHAR2
19265 --Bill To Customer Classification
19266  , p_source_6            IN VARCHAR2
19267 --Transaction Default Receivable Account
19268  , p_source_16            IN NUMBER
19269 --Bill To Customer Account Identifier
19270  , p_source_30            IN NUMBER
19271 --Bill To Customer Site Use Identifier
19272  , p_source_31            IN NUMBER
19273 --SLA Party Type
19274  , p_source_32            IN VARCHAR2
19275 --Transaction Distribution Account Class
19276  , p_source_33            IN VARCHAR2
19277 --Transaction Distribution Identifier
19278  , p_source_34            IN NUMBER
19279 --Transaction Distribution Type
19283 --Transaction Currency Code
19280  , p_source_35            IN VARCHAR2
19281 --Transaction Distribution Entered Amount
19282  , p_source_36            IN NUMBER
19284  , p_source_37            IN VARCHAR2
19285 --Transaction Exchange Date
19286  , p_source_38            IN DATE
19287 --Transaction Exchange Rate
19288  , p_source_39            IN NUMBER
19289 --Transaction Exchange Rate Type
19290  , p_source_40            IN VARCHAR2
19291 --Transaction Accounting Amount
19292  , p_source_41            IN NUMBER
19293 --Transaction Tax Line Identifier
19294  , p_source_55            IN NUMBER
19295 --Federal Account Valid Flag
19296  , p_source_56            IN VARCHAR2
19297 )
19298 IS
19299 
19300 l_component_type              VARCHAR2(80);
19301 l_component_code              VARCHAR2(30);
19302 l_component_type_code         VARCHAR2(1);
19303 l_component_appl_id           INTEGER;
19304 l_amb_context_code            VARCHAR2(30);
19305 l_entity_code                 VARCHAR2(30);
19306 l_event_class_code            VARCHAR2(30);
19307 l_ae_header_id                NUMBER;
19308 l_event_type_code             VARCHAR2(30);
19309 l_line_definition_code        VARCHAR2(30);
19310 l_line_definition_owner_code  VARCHAR2(1);
19311 --
19312 -- adr variables
19313 l_segment                     VARCHAR2(30);
19314 l_ccid                        NUMBER;
19315 l_adr_transaction_coa_id      NUMBER;
19316 l_adr_accounting_coa_id       NUMBER;
19317 l_adr_flexfield_segment_code  VARCHAR2(30);
19318 l_adr_flex_value_set_id       NUMBER;
19319 l_adr_value_type_code         VARCHAR2(30);
19320 l_adr_value_combination_id    NUMBER;
19321 l_adr_value_segment_code      VARCHAR2(30);
19322 
19323 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
19324 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
19325 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
19326 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
19327 
19328 -- 4262811 Variables ------------------------------------------------------------------------------------------
19329 l_entered_amt_idx             NUMBER;
19330 l_accted_amt_idx              NUMBER;
19331 l_acc_rev_flag                VARCHAR2(1);
19332 l_accrual_line_num            NUMBER;
19333 l_tmp_amt                     NUMBER;
19334 l_acc_rev_natural_side_code   VARCHAR2(1);
19335 
19336 l_num_entries                 NUMBER;
19337 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
19338 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
19339 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
19340 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
19341 l_recog_line_1                NUMBER;
19342 l_recog_line_2                NUMBER;
19343 
19344 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
19345 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
19346 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
19347 
19348 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
19349 
19350 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
19351 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
19352 
19353 ---------------------------------------------------------------------------------------------------------------
19354 
19355 
19356 --
19357 -- bulk performance
19358 --
19359 l_balance_type_code           VARCHAR2(1);
19360 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
19361 l_log_module                  VARCHAR2(240);
19362 
19363 --
19364 -- Upgrade strategy
19365 --
19366 l_actual_upg_option           VARCHAR2(1);
19367 l_enc_upg_option           VARCHAR2(1);
19368 
19369 --
19370 BEGIN
19371 --
19372 IF g_log_enabled THEN
19373       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_59';
19374 END IF;
19375 --
19376 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19377 
19378       trace
19379          (p_msg      => 'BEGIN of AcctLineType_59'
19380          ,p_level    => C_LEVEL_PROCEDURE
19381          ,p_module   => l_log_module);
19382 
19383 END IF;
19384 --
19385 l_component_type             := 'AMB_JLT';
19386 l_component_code             := 'FV_INV_REIM_ADV_CR';
19387 l_component_type_code        := 'S';
19388 l_component_appl_id          :=  222;
19389 l_amb_context_code           := 'DEFAULT';
19390 l_entity_code                := 'TRANSACTIONS';
19391 l_event_class_code           := 'INVOICE';
19392 l_event_type_code            := 'INVOICE_ALL';
19393 l_line_definition_owner_code := 'S';
19394 l_line_definition_code       := 'MFAR_FED_AR_ACCR_INV_BALANCING';
19395 --
19396 l_balance_type_code          := 'A';
19397 l_segment                     := NULL;
19398 l_ccid                        := NULL;
19399 l_adr_transaction_coa_id      := NULL;
19400 l_adr_accounting_coa_id       := NULL;
19401 l_adr_flexfield_segment_code  := NULL;
19402 l_adr_flex_value_set_id       := NULL;
19403 l_adr_value_type_code         := NULL;
19404 l_adr_value_combination_id    := NULL;
19405 l_adr_value_segment_code      := NULL;
19406 
19407 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
19411 
19408 l_bflow_class_code           := 'FV_INVOICE_REV_CR';    -- 4219869 Business Flow
19409 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
19410 l_budgetary_control_flag     := 'N';
19412 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
19413 l_bflow_applied_to_amt       := NULL; -- 5132302
19414 l_entered_amt_idx            := NULL;          -- 4262811
19415 l_accted_amt_idx             := NULL;          -- 4262811
19416 l_acc_rev_flag               := NULL;          -- 4262811
19417 l_accrual_line_num           := NULL;          -- 4262811
19418 l_tmp_amt                    := NULL;          -- 4262811
19419 --
19420  
19421 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
19422     l_balance_type_code <> 'B' THEN
19423 IF NVL(p_source_33,'
19424 ') =  'REV' AND 
19425 NVL(p_source_5,'
19426 ') =  'Reimbursable' AND 
19427 NVL(p_source_56,'
19428 ') =  'Y'
19429  THEN 
19430 
19431    --
19432    XLA_AE_LINES_PKG.SetNewLine;
19433 
19434    p_balance_type_code          := l_balance_type_code;
19435    -- set the flag so later we will know whether the gain loss line needs to be created
19436    
19437    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
19438      p_actual_flag :='A';
19439    END IF;
19440 
19441    --
19442    -- bulk performance
19443    --
19444    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
19445                                       p_header_num   => 0); -- 4262811
19446    --
19447    -- set accounting line options
19448    --
19449    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
19450            p_natural_side_code          => 'C'
19451          , p_gain_or_loss_flag          => 'N'
19452          , p_gl_transfer_mode_code      => 'S'
19453          , p_acct_entry_type_code       => 'A'
19454          , p_switch_side_flag           => 'Y'
19455          , p_merge_duplicate_code       => 'A'
19456          );
19457    --
19458    l_acc_rev_natural_side_code := 'D';  -- 4262811
19459    -- 
19460    --
19461    -- set accounting line type info
19462    --
19463    xla_ae_lines_pkg.SetAcctLineType
19464       (p_component_type             => l_component_type
19465       ,p_event_type_code            => l_event_type_code
19466       ,p_line_definition_owner_code => l_line_definition_owner_code
19467       ,p_line_definition_code       => l_line_definition_code
19468       ,p_accounting_line_code       => l_component_code
19469       ,p_accounting_line_type_code  => l_component_type_code
19470       ,p_accounting_line_appl_id    => l_component_appl_id
19471       ,p_amb_context_code           => l_amb_context_code
19472       ,p_entity_code                => l_entity_code
19473       ,p_event_class_code           => l_event_class_code);
19474    --
19475    -- set accounting class
19476    --
19477    xla_ae_lines_pkg.SetAcctClass(
19478            p_accounting_class_code  => 'FV_REC_CR'
19479          , p_ae_header_id           => l_ae_header_id
19480          );
19481 
19482    --
19483    -- set rounding class
19484    --
19485    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
19486                       'RECEIVABLE';
19487 
19488    --
19489    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
19490    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
19491    --
19492    -- bulk performance
19493    --
19494    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
19495 
19496    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
19497       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
19498 
19499    -- 4955764
19500    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
19501       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
19502 
19503    -- 4458381 Public Sector Enh
19504    
19505    --
19506    -- set accounting attributes for the line type
19507    --
19508    l_entered_amt_idx := 3;
19509    l_accted_amt_idx  := 8;
19510    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
19511    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
19512    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
19513    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
19514    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
19515    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
19516    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
19517    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
19518    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
19519    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
19520    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
19521    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
19522    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
19523    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
19524    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
19525    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
19526    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
19527    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
19528    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
19529    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
19533    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
19530    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
19531    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
19532    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
19534    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
19535 
19536    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
19537    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
19538 
19539    ---------------------------------------------------------------------------------------------------------------
19540    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
19541    ---------------------------------------------------------------------------------------------------------------
19542    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
19543 
19544    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
19545    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
19546 
19547    IF xla_accounting_cache_pkg.GetValueChar
19548          (p_source_code         => 'LEDGER_CATEGORY_CODE'
19549          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
19550    AND l_bflow_method_code = 'PRIOR_ENTRY'
19551 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
19552    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
19553          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
19554        )
19555    THEN
19556          xla_ae_lines_pkg.BflowUpgEntry
19557            (p_business_method_code    => l_bflow_method_code
19558            ,p_business_class_code     => l_bflow_class_code
19559            ,p_balance_type            => l_balance_type_code);
19560    ELSE
19561       NULL;
19562 -- No business flow processing for business flow method of NONE.
19563    END IF;
19564 
19565    --
19566    -- call analytical criteria
19567    --
19568    
19569    --
19570    -- call description
19571    --
19572    -- No description or it is inherited.
19573    --
19574    -- call ADRs
19575    -- Bug 4922099
19576    --
19577    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
19578         (NVL(l_actual_upg_option, 'N') = 'O') OR
19579         (NVL(l_enc_upg_option, 'N') = 'O')
19580       )
19581    THEN
19582    NULL;
19583    --
19584    --
19585    
19586   l_ccid := AcctDerRule_28(
19587            p_application_id           => p_application_id
19588          , p_ae_header_id             => l_ae_header_id 
19589 , p_source_16 => p_source_16
19590          , x_transaction_coa_id       => l_adr_transaction_coa_id
19591          , x_accounting_coa_id        => l_adr_accounting_coa_id
19592          , x_value_type_code          => l_adr_value_type_code
19593          , p_side                     => 'NA'
19594    );
19595 
19596    xla_ae_lines_pkg.set_ccid(
19597     p_code_combination_id          => l_ccid
19598   , p_value_type_code              => l_adr_value_type_code
19599   , p_transaction_coa_id           => l_adr_transaction_coa_id
19600   , p_accounting_coa_id            => l_adr_accounting_coa_id
19601   , p_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
19602   , p_adr_type_code                => 'S'
19603   , p_component_type               => l_component_type
19604   , p_component_code               => l_component_code
19605   , p_component_type_code          => l_component_type_code
19606   , p_component_appl_id            => l_component_appl_id
19607   , p_amb_context_code             => l_amb_context_code
19608   , p_side                         => 'NA'
19609   );
19610 
19611 
19612    l_segment := AcctDerRule_9(
19613            p_application_id           => p_application_id
19614          , p_ae_header_id             => l_ae_header_id 
19615 , p_source_5 => p_source_5
19616 , p_source_6 => p_source_6
19617          , x_transaction_coa_id       => l_adr_transaction_coa_id
19618          , x_accounting_coa_id        => l_adr_accounting_coa_id
19619          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
19620          , x_flex_value_set_id        => l_adr_flex_value_set_id
19621          , x_value_type_code          => l_adr_value_type_code
19622          , x_value_combination_id     => l_adr_value_combination_id
19623          , x_value_segment_code       => l_adr_value_segment_code
19624          , p_side                     => 'NA'
19625          , p_override_seg_flag        => 'Y'
19626    );
19627 
19628    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
19629 
19630       xla_ae_lines_pkg.set_segment(
19631           p_to_segment_code         => 'GL_ACCOUNT'
19632         , p_segment_value           => l_segment
19633         , p_from_segment_code       => l_adr_value_segment_code
19634         , p_from_combination_id     => l_adr_value_combination_id
19635         , p_value_type_code         => l_adr_value_type_code
19636         , p_transaction_coa_id      => l_adr_transaction_coa_id
19637         , p_accounting_coa_id       => l_adr_accounting_coa_id
19638         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
19639         , p_flex_value_set_id       => l_adr_flex_value_set_id
19640         , p_adr_code                => 'FV_AR_422X0X_INV_REIM_CR'
19641         , p_adr_type_code           => 'S'
19642         , p_component_type          => l_component_type
19646         , p_amb_context_code        => l_amb_context_code
19643         , p_component_code          => l_component_code
19644         , p_component_type_code     => l_component_type_code
19645         , p_component_appl_id       => l_component_appl_id
19647         , p_entity_code             => 'TRANSACTIONS'
19648         , p_event_class_code        => 'INVOICE'
19649         , p_side                    => 'NA'
19650         );
19651 
19652   END IF;
19653 
19654    l_segment := AcctDerRule_5(
19655            p_application_id           => p_application_id
19656          , p_ae_header_id             => l_ae_header_id 
19657 , p_source_4 => p_source_4
19658          , x_transaction_coa_id       => l_adr_transaction_coa_id
19659          , x_accounting_coa_id        => l_adr_accounting_coa_id
19660          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
19661          , x_flex_value_set_id        => l_adr_flex_value_set_id
19662          , x_value_type_code          => l_adr_value_type_code
19663          , x_value_combination_id     => l_adr_value_combination_id
19664          , x_value_segment_code       => l_adr_value_segment_code
19665          , p_side                     => 'NA'
19666          , p_override_seg_flag        => 'Y'
19667    );
19668 
19669    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
19670 
19671       xla_ae_lines_pkg.set_segment(
19672           p_to_segment_code         => 'GL_BALANCING'
19673         , p_segment_value           => l_segment
19674         , p_from_segment_code       => l_adr_value_segment_code
19675         , p_from_combination_id     => l_adr_value_combination_id
19676         , p_value_type_code         => l_adr_value_type_code
19677         , p_transaction_coa_id      => l_adr_transaction_coa_id
19678         , p_accounting_coa_id       => l_adr_accounting_coa_id
19679         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
19680         , p_flex_value_set_id       => l_adr_flex_value_set_id
19681         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
19682         , p_adr_type_code           => 'S'
19683         , p_component_type          => l_component_type
19684         , p_component_code          => l_component_code
19685         , p_component_type_code     => l_component_type_code
19686         , p_component_appl_id       => l_component_appl_id
19687         , p_amb_context_code        => l_amb_context_code
19688         , p_entity_code             => 'TRANSACTIONS'
19689         , p_event_class_code        => 'INVOICE'
19690         , p_side                    => 'NA'
19691         );
19692 
19693   END IF;
19694 
19695    --
19696    --
19697    END IF;
19698    --
19699    -- Bug 4922099
19700    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
19701           (NVL(l_enc_upg_option, 'N') = 'O')
19702         ) AND
19703         (l_bflow_method_code = 'PRIOR_ENTRY')
19704       )
19705    THEN
19706       IF
19707       --
19708       1 = 2
19709       --
19710       THEN
19711       xla_accounting_err_pkg.build_message
19712                                     (p_appli_s_name            => 'XLA'
19713                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
19714                                     ,p_token_1                 => 'LINE_NUMBER'
19715                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
19716                                     ,p_token_2                 => 'LINE_TYPE_NAME'
19717                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
19718                                                                              l_component_type
19719                                                                             ,l_component_code
19720                                                                             ,l_component_type_code
19721                                                                             ,l_component_appl_id
19722                                                                             ,l_amb_context_code
19723                                                                             ,l_entity_code
19724                                                                             ,l_event_class_code
19725                                                                            )
19726                                     ,p_token_3                 => 'OWNER'
19727                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
19728                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
19729                                                                           ,p_lookup_code    => l_component_type_code
19730                                                                          )
19731                                     ,p_token_4                 => 'PRODUCT_NAME'
19732                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
19733                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
19734                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
19735                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
19736                                     ,p_ae_header_id            =>  NULL
19737                                        );
19738 
19739         IF (C_LEVEL_ERROR>= g_log_level) THEN
19740                  trace
19744         END IF;
19741                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
19742                       ,p_level    => C_LEVEL_ERROR
19743                       ,p_module   => l_log_module);
19745       END IF;
19746    END IF;
19747    --
19748    --
19749    ------------------------------------------------------------------------------------------------
19750    -- 4219869 Business Flow
19751    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
19752    -- Prior Entry.  Currently, the following code is always generated.
19753    ------------------------------------------------------------------------------------------------
19754    XLA_AE_LINES_PKG.ValidateCurrentLine;
19755 
19756    ------------------------------------------------------------------------------------
19757    -- 4219869 Business Flow
19758    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
19759    ------------------------------------------------------------------------------------
19760    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
19761 
19762    ----------------------------------------------------------------------------------
19763    -- 4219869 Business Flow
19764    -- Update journal entry status -- Need to generate this within IF <condition>
19765    ----------------------------------------------------------------------------------
19766    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
19767          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
19768          ,p_balance_type_code => l_balance_type_code
19769          );
19770 
19771    -------------------------------------------------------------------------------------------
19772    -- 4262811 - Generate the Accrual Reversal lines
19773    -------------------------------------------------------------------------------------------
19774    BEGIN
19775       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
19776                               (g_array_event(p_event_id).array_value_num('header_index'));
19777       IF l_acc_rev_flag IS NULL THEN
19778          l_acc_rev_flag := 'N';
19779       END IF;
19780    EXCEPTION
19781       WHEN OTHERS THEN
19782          l_acc_rev_flag := 'N';
19783    END;
19784    --
19785    IF (l_acc_rev_flag = 'Y') THEN
19786 
19787        -- 4645092  ------------------------------------------------------------------------------
19788        -- To allow MPA report to determine if it should generate report process
19789        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
19790        ------------------------------------------------------------------------------------------
19791 
19792        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
19793        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
19794    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
19795    -- call ADRs
19796    -- Bug 4922099
19797    --
19798    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
19799         (NVL(l_actual_upg_option, 'N') = 'O') OR
19800         (NVL(l_enc_upg_option, 'N') = 'O')
19801       )
19802    THEN
19803    NULL;
19804    --
19805    --
19806    
19807   l_ccid := AcctDerRule_28(
19808            p_application_id           => p_application_id
19809          , p_ae_header_id             => l_ae_header_id 
19810 , p_source_16 => p_source_16
19811          , x_transaction_coa_id       => l_adr_transaction_coa_id
19812          , x_accounting_coa_id        => l_adr_accounting_coa_id
19813          , x_value_type_code          => l_adr_value_type_code
19814          , p_side                     => 'NA'
19815    );
19816 
19817    xla_ae_lines_pkg.set_ccid(
19818     p_code_combination_id          => l_ccid
19819   , p_value_type_code              => l_adr_value_type_code
19820   , p_transaction_coa_id           => l_adr_transaction_coa_id
19821   , p_accounting_coa_id            => l_adr_accounting_coa_id
19822   , p_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
19823   , p_adr_type_code                => 'S'
19824   , p_component_type               => l_component_type
19825   , p_component_code               => l_component_code
19826   , p_component_type_code          => l_component_type_code
19827   , p_component_appl_id            => l_component_appl_id
19828   , p_amb_context_code             => l_amb_context_code
19829   , p_side                         => 'NA'
19830   );
19831 
19832 
19833    l_segment := AcctDerRule_9(
19834            p_application_id           => p_application_id
19835          , p_ae_header_id             => l_ae_header_id 
19836 , p_source_5 => p_source_5
19837 , p_source_6 => p_source_6
19838          , x_transaction_coa_id       => l_adr_transaction_coa_id
19839          , x_accounting_coa_id        => l_adr_accounting_coa_id
19840          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
19841          , x_flex_value_set_id        => l_adr_flex_value_set_id
19842          , x_value_type_code          => l_adr_value_type_code
19843          , x_value_combination_id     => l_adr_value_combination_id
19844          , x_value_segment_code       => l_adr_value_segment_code
19845          , p_side                     => 'NA'
19846          , p_override_seg_flag        => 'Y'
19847    );
19848 
19849    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
19850 
19851       xla_ae_lines_pkg.set_segment(
19852           p_to_segment_code         => 'GL_ACCOUNT'
19856         , p_value_type_code         => l_adr_value_type_code
19853         , p_segment_value           => l_segment
19854         , p_from_segment_code       => l_adr_value_segment_code
19855         , p_from_combination_id     => l_adr_value_combination_id
19857         , p_transaction_coa_id      => l_adr_transaction_coa_id
19858         , p_accounting_coa_id       => l_adr_accounting_coa_id
19859         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
19860         , p_flex_value_set_id       => l_adr_flex_value_set_id
19861         , p_adr_code                => 'FV_AR_422X0X_INV_REIM_CR'
19862         , p_adr_type_code           => 'S'
19863         , p_component_type          => l_component_type
19864         , p_component_code          => l_component_code
19865         , p_component_type_code     => l_component_type_code
19866         , p_component_appl_id       => l_component_appl_id
19867         , p_amb_context_code        => l_amb_context_code
19868         , p_entity_code             => 'TRANSACTIONS'
19869         , p_event_class_code        => 'INVOICE'
19870         , p_side                    => 'NA'
19871         );
19872 
19873   END IF;
19874 
19875    l_segment := AcctDerRule_5(
19876            p_application_id           => p_application_id
19877          , p_ae_header_id             => l_ae_header_id 
19878 , p_source_4 => p_source_4
19879          , x_transaction_coa_id       => l_adr_transaction_coa_id
19880          , x_accounting_coa_id        => l_adr_accounting_coa_id
19881          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
19882          , x_flex_value_set_id        => l_adr_flex_value_set_id
19883          , x_value_type_code          => l_adr_value_type_code
19884          , x_value_combination_id     => l_adr_value_combination_id
19885          , x_value_segment_code       => l_adr_value_segment_code
19886          , p_side                     => 'NA'
19887          , p_override_seg_flag        => 'Y'
19888    );
19889 
19890    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
19891 
19892       xla_ae_lines_pkg.set_segment(
19893           p_to_segment_code         => 'GL_BALANCING'
19894         , p_segment_value           => l_segment
19895         , p_from_segment_code       => l_adr_value_segment_code
19896         , p_from_combination_id     => l_adr_value_combination_id
19897         , p_value_type_code         => l_adr_value_type_code
19898         , p_transaction_coa_id      => l_adr_transaction_coa_id
19899         , p_accounting_coa_id       => l_adr_accounting_coa_id
19900         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
19901         , p_flex_value_set_id       => l_adr_flex_value_set_id
19902         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
19903         , p_adr_type_code           => 'S'
19904         , p_component_type          => l_component_type
19905         , p_component_code          => l_component_code
19906         , p_component_type_code     => l_component_type_code
19907         , p_component_appl_id       => l_component_appl_id
19908         , p_amb_context_code        => l_amb_context_code
19909         , p_entity_code             => 'TRANSACTIONS'
19910         , p_event_class_code        => 'INVOICE'
19911         , p_side                    => 'NA'
19912         );
19913 
19914   END IF;
19915 
19916    --
19917    --
19918    END IF;
19919 
19920        --
19921        -- Update the line information that should be overwritten
19922        --
19923        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
19924                                          p_header_num   => 1);
19925        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
19926 
19927        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
19928 
19929        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
19930           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
19931        END IF;
19932 
19933       --
19934       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
19935       --
19936       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
19937           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
19938       ELSE
19939           ---------------------------------------------------------------------------------------------------
19940           -- 4262811a Switch Sign
19941           ---------------------------------------------------------------------------------------------------
19942           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
19943           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
19944                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19945           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
19946                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19947           -- 5132302
19948           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
19949                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19950 
19951       END IF;
19952 
19953       -- 4955764
19957 
19954       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
19955       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
19956 
19958       XLA_AE_LINES_PKG.ValidateCurrentLine;
19959       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
19960 
19961       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
19962                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
19963                ,p_balance_type_code => l_balance_type_code);
19964 
19965    END IF;
19966 
19967    -----------------------------------------------------------------------------------------
19968    -- 4262811 Multiperiod Accounting
19969    -----------------------------------------------------------------------------------------
19970      -- No MPA option is assigned.
19971 
19972 
19973 END IF;
19974 END IF;
19975 --
19976 
19977 --
19978 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19979    trace
19980       (p_msg      => 'END of AcctLineType_59'
19981       ,p_level    => C_LEVEL_PROCEDURE
19982       ,p_module   => l_log_module);
19983 END IF;
19984 --
19985 EXCEPTION
19986   WHEN xla_exceptions_pkg.application_exception THEN
19987       RAISE;
19988   WHEN OTHERS THEN
19989        xla_exceptions_pkg.raise_message
19990            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_59');
19991 END AcctLineType_59;
19992 --
19993 
19994 ---------------------------------------
19995 --
19996 -- PRIVATE FUNCTION
19997 --         AcctLineType_60
19998 --
19999 ---------------------------------------
20000 PROCEDURE AcctLineType_60 (
20001   p_application_id        IN NUMBER
20002  ,p_event_id              IN NUMBER
20003  ,p_calculate_acctd_flag  IN VARCHAR2
20004  ,p_calculate_g_l_flag    IN VARCHAR2
20005  ,p_actual_flag           IN OUT VARCHAR2
20006  ,p_balance_type_code     OUT VARCHAR2
20007  ,p_gain_or_loss_ref      OUT VARCHAR2
20008  
20009 --Transaction Distribution GL Account
20010  , p_source_4            IN NUMBER
20011 --Federal Fund Category
20012  , p_source_5            IN VARCHAR2
20013 --Bill To Customer Classification
20014  , p_source_6            IN VARCHAR2
20015 --Transaction Default Receivable Account
20016  , p_source_16            IN NUMBER
20017 --Bill To Customer Account Identifier
20018  , p_source_30            IN NUMBER
20019 --Bill To Customer Site Use Identifier
20020  , p_source_31            IN NUMBER
20021 --SLA Party Type
20022  , p_source_32            IN VARCHAR2
20023 --Transaction Distribution Account Class
20024  , p_source_33            IN VARCHAR2
20025 --Transaction Distribution Identifier
20026  , p_source_34            IN NUMBER
20027 --Transaction Distribution Type
20028  , p_source_35            IN VARCHAR2
20029 --Transaction Distribution Entered Amount
20030  , p_source_36            IN NUMBER
20031 --Transaction Currency Code
20032  , p_source_37            IN VARCHAR2
20033 --Transaction Exchange Date
20034  , p_source_38            IN DATE
20035 --Transaction Exchange Rate
20036  , p_source_39            IN NUMBER
20037 --Transaction Exchange Rate Type
20038  , p_source_40            IN VARCHAR2
20039 --Transaction Accounting Amount
20040  , p_source_41            IN NUMBER
20041 --Transaction Tax Line Identifier
20042  , p_source_55            IN NUMBER
20043 --Federal Account Valid Flag
20044  , p_source_56            IN VARCHAR2
20045 )
20046 IS
20047 
20048 l_component_type              VARCHAR2(80);
20049 l_component_code              VARCHAR2(30);
20050 l_component_type_code         VARCHAR2(1);
20051 l_component_appl_id           INTEGER;
20052 l_amb_context_code            VARCHAR2(30);
20053 l_entity_code                 VARCHAR2(30);
20054 l_event_class_code            VARCHAR2(30);
20055 l_ae_header_id                NUMBER;
20056 l_event_type_code             VARCHAR2(30);
20057 l_line_definition_code        VARCHAR2(30);
20058 l_line_definition_owner_code  VARCHAR2(1);
20059 --
20060 -- adr variables
20061 l_segment                     VARCHAR2(30);
20062 l_ccid                        NUMBER;
20063 l_adr_transaction_coa_id      NUMBER;
20064 l_adr_accounting_coa_id       NUMBER;
20065 l_adr_flexfield_segment_code  VARCHAR2(30);
20066 l_adr_flex_value_set_id       NUMBER;
20067 l_adr_value_type_code         VARCHAR2(30);
20068 l_adr_value_combination_id    NUMBER;
20069 l_adr_value_segment_code      VARCHAR2(30);
20070 
20071 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
20072 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
20073 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
20074 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
20075 
20076 -- 4262811 Variables ------------------------------------------------------------------------------------------
20077 l_entered_amt_idx             NUMBER;
20078 l_accted_amt_idx              NUMBER;
20079 l_acc_rev_flag                VARCHAR2(1);
20080 l_accrual_line_num            NUMBER;
20081 l_tmp_amt                     NUMBER;
20082 l_acc_rev_natural_side_code   VARCHAR2(1);
20083 
20084 l_num_entries                 NUMBER;
20085 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
20086 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
20087 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
20088 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
20092 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
20089 l_recog_line_1                NUMBER;
20090 l_recog_line_2                NUMBER;
20091 
20093 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
20094 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
20095 
20096 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
20097 
20098 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
20099 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
20100 
20101 ---------------------------------------------------------------------------------------------------------------
20102 
20103 
20104 --
20105 -- bulk performance
20106 --
20107 l_balance_type_code           VARCHAR2(1);
20108 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
20109 l_log_module                  VARCHAR2(240);
20110 
20111 --
20112 -- Upgrade strategy
20113 --
20114 l_actual_upg_option           VARCHAR2(1);
20115 l_enc_upg_option           VARCHAR2(1);
20116 
20117 --
20118 BEGIN
20119 --
20120 IF g_log_enabled THEN
20121       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_60';
20122 END IF;
20123 --
20124 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
20125 
20126       trace
20127          (p_msg      => 'BEGIN of AcctLineType_60'
20128          ,p_level    => C_LEVEL_PROCEDURE
20129          ,p_module   => l_log_module);
20130 
20131 END IF;
20132 --
20133 l_component_type             := 'AMB_JLT';
20134 l_component_code             := 'FV_INV_REIM_ADV_DR';
20135 l_component_type_code        := 'S';
20136 l_component_appl_id          :=  222;
20137 l_amb_context_code           := 'DEFAULT';
20138 l_entity_code                := 'TRANSACTIONS';
20139 l_event_class_code           := 'INVOICE';
20140 l_event_type_code            := 'INVOICE_ALL';
20141 l_line_definition_owner_code := 'S';
20142 l_line_definition_code       := 'MFAR_FED_AR_ACCR_INV_BALANCING';
20143 --
20144 l_balance_type_code          := 'A';
20145 l_segment                     := NULL;
20146 l_ccid                        := NULL;
20147 l_adr_transaction_coa_id      := NULL;
20148 l_adr_accounting_coa_id       := NULL;
20149 l_adr_flexfield_segment_code  := NULL;
20150 l_adr_flex_value_set_id       := NULL;
20151 l_adr_value_type_code         := NULL;
20152 l_adr_value_combination_id    := NULL;
20153 l_adr_value_segment_code      := NULL;
20154 
20155 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
20156 l_bflow_class_code           := 'FV_INVOICE_REC_DR';    -- 4219869 Business Flow
20157 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
20158 l_budgetary_control_flag     := 'N';
20159 
20160 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
20161 l_bflow_applied_to_amt       := NULL; -- 5132302
20162 l_entered_amt_idx            := NULL;          -- 4262811
20163 l_accted_amt_idx             := NULL;          -- 4262811
20164 l_acc_rev_flag               := NULL;          -- 4262811
20165 l_accrual_line_num           := NULL;          -- 4262811
20166 l_tmp_amt                    := NULL;          -- 4262811
20167 --
20168  
20169 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
20170     l_balance_type_code <> 'B' THEN
20171 IF NVL(p_source_33,'
20172 ') =  'REV' AND 
20173 NVL(p_source_5,'
20174 ') =  'Reimbursable' AND 
20175 NVL(p_source_56,'
20176 ') =  'Y'
20177  THEN 
20178 
20179    --
20180    XLA_AE_LINES_PKG.SetNewLine;
20181 
20182    p_balance_type_code          := l_balance_type_code;
20183    -- set the flag so later we will know whether the gain loss line needs to be created
20184    
20185    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
20186      p_actual_flag :='A';
20187    END IF;
20188 
20189    --
20190    -- bulk performance
20191    --
20192    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
20193                                       p_header_num   => 0); -- 4262811
20194    --
20195    -- set accounting line options
20196    --
20197    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
20198            p_natural_side_code          => 'D'
20199          , p_gain_or_loss_flag          => 'N'
20200          , p_gl_transfer_mode_code      => 'S'
20201          , p_acct_entry_type_code       => 'A'
20202          , p_switch_side_flag           => 'Y'
20203          , p_merge_duplicate_code       => 'A'
20204          );
20205    --
20206    l_acc_rev_natural_side_code := 'C';  -- 4262811
20207    -- 
20208    --
20209    -- set accounting line type info
20210    --
20211    xla_ae_lines_pkg.SetAcctLineType
20212       (p_component_type             => l_component_type
20213       ,p_event_type_code            => l_event_type_code
20214       ,p_line_definition_owner_code => l_line_definition_owner_code
20215       ,p_line_definition_code       => l_line_definition_code
20216       ,p_accounting_line_code       => l_component_code
20217       ,p_accounting_line_type_code  => l_component_type_code
20218       ,p_accounting_line_appl_id    => l_component_appl_id
20219       ,p_amb_context_code           => l_amb_context_code
20220       ,p_entity_code                => l_entity_code
20221       ,p_event_class_code           => l_event_class_code);
20222    --
20226            p_accounting_class_code  => 'FV_REC_DR'
20223    -- set accounting class
20224    --
20225    xla_ae_lines_pkg.SetAcctClass(
20227          , p_ae_header_id           => l_ae_header_id
20228          );
20229 
20230    --
20231    -- set rounding class
20232    --
20233    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
20234                       'RECEIVABLE';
20235 
20236    --
20237    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
20238    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
20239    --
20240    -- bulk performance
20241    --
20242    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
20243 
20244    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
20245       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
20246 
20247    -- 4955764
20248    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
20249       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
20250 
20251    -- 4458381 Public Sector Enh
20252    
20253    --
20254    -- set accounting attributes for the line type
20255    --
20256    l_entered_amt_idx := 3;
20257    l_accted_amt_idx  := 8;
20258    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
20259    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
20260    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
20261    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
20262    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
20263    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
20264    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
20265    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
20266    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
20267    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
20268    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
20269    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
20270    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
20271    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
20272    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
20273    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
20274    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
20275    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
20276    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
20277    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
20278    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
20279    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
20280    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
20281    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
20282    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
20283 
20284    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
20285    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
20286 
20287    ---------------------------------------------------------------------------------------------------------------
20288    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
20289    ---------------------------------------------------------------------------------------------------------------
20290    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
20291 
20292    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
20293    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
20294 
20295    IF xla_accounting_cache_pkg.GetValueChar
20296          (p_source_code         => 'LEDGER_CATEGORY_CODE'
20297          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
20298    AND l_bflow_method_code = 'PRIOR_ENTRY'
20299 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
20300    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
20301          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
20302        )
20303    THEN
20304          xla_ae_lines_pkg.BflowUpgEntry
20305            (p_business_method_code    => l_bflow_method_code
20306            ,p_business_class_code     => l_bflow_class_code
20307            ,p_balance_type            => l_balance_type_code);
20308    ELSE
20309       NULL;
20310 -- No business flow processing for business flow method of NONE.
20311    END IF;
20312 
20313    --
20314    -- call analytical criteria
20315    --
20316    
20317    --
20318    -- call description
20319    --
20320    -- No description or it is inherited.
20321    --
20322    -- call ADRs
20323    -- Bug 4922099
20324    --
20325    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
20326         (NVL(l_actual_upg_option, 'N') = 'O') OR
20327         (NVL(l_enc_upg_option, 'N') = 'O')
20328       )
20329    THEN
20330    NULL;
20331    --
20332    --
20333    
20334   l_ccid := AcctDerRule_28(
20335            p_application_id           => p_application_id
20336          , p_ae_header_id             => l_ae_header_id 
20340          , x_value_type_code          => l_adr_value_type_code
20337 , p_source_16 => p_source_16
20338          , x_transaction_coa_id       => l_adr_transaction_coa_id
20339          , x_accounting_coa_id        => l_adr_accounting_coa_id
20341          , p_side                     => 'NA'
20342    );
20343 
20344    xla_ae_lines_pkg.set_ccid(
20345     p_code_combination_id          => l_ccid
20346   , p_value_type_code              => l_adr_value_type_code
20347   , p_transaction_coa_id           => l_adr_transaction_coa_id
20348   , p_accounting_coa_id            => l_adr_accounting_coa_id
20349   , p_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
20350   , p_adr_type_code                => 'S'
20351   , p_component_type               => l_component_type
20352   , p_component_code               => l_component_code
20353   , p_component_type_code          => l_component_type_code
20354   , p_component_appl_id            => l_component_appl_id
20355   , p_amb_context_code             => l_amb_context_code
20356   , p_side                         => 'NA'
20357   );
20358 
20359 
20360    l_segment := AcctDerRule_13(
20361            p_application_id           => p_application_id
20362          , p_ae_header_id             => l_ae_header_id 
20363 , p_source_5 => p_source_5
20364 , p_source_6 => p_source_6
20365          , x_transaction_coa_id       => l_adr_transaction_coa_id
20366          , x_accounting_coa_id        => l_adr_accounting_coa_id
20367          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
20368          , x_flex_value_set_id        => l_adr_flex_value_set_id
20369          , x_value_type_code          => l_adr_value_type_code
20370          , x_value_combination_id     => l_adr_value_combination_id
20371          , x_value_segment_code       => l_adr_value_segment_code
20372          , p_side                     => 'NA'
20373          , p_override_seg_flag        => 'Y'
20374    );
20375 
20376    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
20377 
20378       xla_ae_lines_pkg.set_segment(
20379           p_to_segment_code         => 'GL_ACCOUNT'
20380         , p_segment_value           => l_segment
20381         , p_from_segment_code       => l_adr_value_segment_code
20382         , p_from_combination_id     => l_adr_value_combination_id
20383         , p_value_type_code         => l_adr_value_type_code
20384         , p_transaction_coa_id      => l_adr_transaction_coa_id
20385         , p_accounting_coa_id       => l_adr_accounting_coa_id
20386         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
20387         , p_flex_value_set_id       => l_adr_flex_value_set_id
20388         , p_adr_code                => 'FV_AR_425X0X_INV_REIM_DR'
20389         , p_adr_type_code           => 'S'
20390         , p_component_type          => l_component_type
20391         , p_component_code          => l_component_code
20392         , p_component_type_code     => l_component_type_code
20393         , p_component_appl_id       => l_component_appl_id
20394         , p_amb_context_code        => l_amb_context_code
20395         , p_entity_code             => 'TRANSACTIONS'
20396         , p_event_class_code        => 'INVOICE'
20397         , p_side                    => 'NA'
20398         );
20399 
20400   END IF;
20401 
20402    l_segment := AcctDerRule_5(
20403            p_application_id           => p_application_id
20404          , p_ae_header_id             => l_ae_header_id 
20405 , p_source_4 => p_source_4
20406          , x_transaction_coa_id       => l_adr_transaction_coa_id
20407          , x_accounting_coa_id        => l_adr_accounting_coa_id
20408          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
20409          , x_flex_value_set_id        => l_adr_flex_value_set_id
20410          , x_value_type_code          => l_adr_value_type_code
20411          , x_value_combination_id     => l_adr_value_combination_id
20412          , x_value_segment_code       => l_adr_value_segment_code
20413          , p_side                     => 'NA'
20414          , p_override_seg_flag        => 'Y'
20415    );
20416 
20417    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
20418 
20419       xla_ae_lines_pkg.set_segment(
20420           p_to_segment_code         => 'GL_BALANCING'
20421         , p_segment_value           => l_segment
20422         , p_from_segment_code       => l_adr_value_segment_code
20423         , p_from_combination_id     => l_adr_value_combination_id
20424         , p_value_type_code         => l_adr_value_type_code
20425         , p_transaction_coa_id      => l_adr_transaction_coa_id
20426         , p_accounting_coa_id       => l_adr_accounting_coa_id
20427         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
20428         , p_flex_value_set_id       => l_adr_flex_value_set_id
20429         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
20430         , p_adr_type_code           => 'S'
20431         , p_component_type          => l_component_type
20432         , p_component_code          => l_component_code
20433         , p_component_type_code     => l_component_type_code
20434         , p_component_appl_id       => l_component_appl_id
20435         , p_amb_context_code        => l_amb_context_code
20436         , p_entity_code             => 'TRANSACTIONS'
20437         , p_event_class_code        => 'INVOICE'
20438         , p_side                    => 'NA'
20439         );
20440 
20441   END IF;
20442 
20443    --
20444    --
20445    END IF;
20449           (NVL(l_enc_upg_option, 'N') = 'O')
20446    --
20447    -- Bug 4922099
20448    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
20450         ) AND
20451         (l_bflow_method_code = 'PRIOR_ENTRY')
20452       )
20453    THEN
20454       IF
20455       --
20456       1 = 2
20457       --
20458       THEN
20459       xla_accounting_err_pkg.build_message
20460                                     (p_appli_s_name            => 'XLA'
20461                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
20462                                     ,p_token_1                 => 'LINE_NUMBER'
20463                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
20464                                     ,p_token_2                 => 'LINE_TYPE_NAME'
20465                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
20466                                                                              l_component_type
20467                                                                             ,l_component_code
20468                                                                             ,l_component_type_code
20469                                                                             ,l_component_appl_id
20470                                                                             ,l_amb_context_code
20471                                                                             ,l_entity_code
20472                                                                             ,l_event_class_code
20473                                                                            )
20474                                     ,p_token_3                 => 'OWNER'
20475                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
20476                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
20477                                                                           ,p_lookup_code    => l_component_type_code
20478                                                                          )
20479                                     ,p_token_4                 => 'PRODUCT_NAME'
20480                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
20481                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
20482                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
20483                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
20484                                     ,p_ae_header_id            =>  NULL
20485                                        );
20486 
20487         IF (C_LEVEL_ERROR>= g_log_level) THEN
20488                  trace
20489                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
20490                       ,p_level    => C_LEVEL_ERROR
20491                       ,p_module   => l_log_module);
20492         END IF;
20493       END IF;
20494    END IF;
20495    --
20496    --
20497    ------------------------------------------------------------------------------------------------
20498    -- 4219869 Business Flow
20499    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
20500    -- Prior Entry.  Currently, the following code is always generated.
20501    ------------------------------------------------------------------------------------------------
20502    XLA_AE_LINES_PKG.ValidateCurrentLine;
20503 
20504    ------------------------------------------------------------------------------------
20505    -- 4219869 Business Flow
20506    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
20507    ------------------------------------------------------------------------------------
20508    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
20509 
20510    ----------------------------------------------------------------------------------
20511    -- 4219869 Business Flow
20512    -- Update journal entry status -- Need to generate this within IF <condition>
20513    ----------------------------------------------------------------------------------
20514    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
20515          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
20516          ,p_balance_type_code => l_balance_type_code
20517          );
20518 
20519    -------------------------------------------------------------------------------------------
20520    -- 4262811 - Generate the Accrual Reversal lines
20521    -------------------------------------------------------------------------------------------
20522    BEGIN
20523       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
20524                               (g_array_event(p_event_id).array_value_num('header_index'));
20525       IF l_acc_rev_flag IS NULL THEN
20526          l_acc_rev_flag := 'N';
20527       END IF;
20528    EXCEPTION
20529       WHEN OTHERS THEN
20530          l_acc_rev_flag := 'N';
20531    END;
20532    --
20533    IF (l_acc_rev_flag = 'Y') THEN
20534 
20535        -- 4645092  ------------------------------------------------------------------------------
20536        -- To allow MPA report to determine if it should generate report process
20537        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
20538        ------------------------------------------------------------------------------------------
20539 
20543    -- call ADRs
20540        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
20541        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
20542    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
20544    -- Bug 4922099
20545    --
20546    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
20547         (NVL(l_actual_upg_option, 'N') = 'O') OR
20548         (NVL(l_enc_upg_option, 'N') = 'O')
20549       )
20550    THEN
20551    NULL;
20552    --
20553    --
20554    
20555   l_ccid := AcctDerRule_28(
20556            p_application_id           => p_application_id
20557          , p_ae_header_id             => l_ae_header_id 
20558 , p_source_16 => p_source_16
20559          , x_transaction_coa_id       => l_adr_transaction_coa_id
20560          , x_accounting_coa_id        => l_adr_accounting_coa_id
20561          , x_value_type_code          => l_adr_value_type_code
20562          , p_side                     => 'NA'
20563    );
20564 
20565    xla_ae_lines_pkg.set_ccid(
20566     p_code_combination_id          => l_ccid
20567   , p_value_type_code              => l_adr_value_type_code
20568   , p_transaction_coa_id           => l_adr_transaction_coa_id
20569   , p_accounting_coa_id            => l_adr_accounting_coa_id
20570   , p_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
20571   , p_adr_type_code                => 'S'
20572   , p_component_type               => l_component_type
20573   , p_component_code               => l_component_code
20574   , p_component_type_code          => l_component_type_code
20575   , p_component_appl_id            => l_component_appl_id
20576   , p_amb_context_code             => l_amb_context_code
20577   , p_side                         => 'NA'
20578   );
20579 
20580 
20581    l_segment := AcctDerRule_13(
20582            p_application_id           => p_application_id
20583          , p_ae_header_id             => l_ae_header_id 
20584 , p_source_5 => p_source_5
20585 , p_source_6 => p_source_6
20586          , x_transaction_coa_id       => l_adr_transaction_coa_id
20587          , x_accounting_coa_id        => l_adr_accounting_coa_id
20588          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
20589          , x_flex_value_set_id        => l_adr_flex_value_set_id
20590          , x_value_type_code          => l_adr_value_type_code
20591          , x_value_combination_id     => l_adr_value_combination_id
20592          , x_value_segment_code       => l_adr_value_segment_code
20593          , p_side                     => 'NA'
20594          , p_override_seg_flag        => 'Y'
20595    );
20596 
20597    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
20598 
20599       xla_ae_lines_pkg.set_segment(
20600           p_to_segment_code         => 'GL_ACCOUNT'
20601         , p_segment_value           => l_segment
20602         , p_from_segment_code       => l_adr_value_segment_code
20603         , p_from_combination_id     => l_adr_value_combination_id
20604         , p_value_type_code         => l_adr_value_type_code
20605         , p_transaction_coa_id      => l_adr_transaction_coa_id
20606         , p_accounting_coa_id       => l_adr_accounting_coa_id
20607         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
20608         , p_flex_value_set_id       => l_adr_flex_value_set_id
20609         , p_adr_code                => 'FV_AR_425X0X_INV_REIM_DR'
20610         , p_adr_type_code           => 'S'
20611         , p_component_type          => l_component_type
20612         , p_component_code          => l_component_code
20613         , p_component_type_code     => l_component_type_code
20614         , p_component_appl_id       => l_component_appl_id
20615         , p_amb_context_code        => l_amb_context_code
20616         , p_entity_code             => 'TRANSACTIONS'
20617         , p_event_class_code        => 'INVOICE'
20618         , p_side                    => 'NA'
20619         );
20620 
20621   END IF;
20622 
20623    l_segment := AcctDerRule_5(
20624            p_application_id           => p_application_id
20625          , p_ae_header_id             => l_ae_header_id 
20626 , p_source_4 => p_source_4
20627          , x_transaction_coa_id       => l_adr_transaction_coa_id
20628          , x_accounting_coa_id        => l_adr_accounting_coa_id
20629          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
20630          , x_flex_value_set_id        => l_adr_flex_value_set_id
20631          , x_value_type_code          => l_adr_value_type_code
20632          , x_value_combination_id     => l_adr_value_combination_id
20633          , x_value_segment_code       => l_adr_value_segment_code
20634          , p_side                     => 'NA'
20635          , p_override_seg_flag        => 'Y'
20636    );
20637 
20638    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
20639 
20640       xla_ae_lines_pkg.set_segment(
20641           p_to_segment_code         => 'GL_BALANCING'
20642         , p_segment_value           => l_segment
20643         , p_from_segment_code       => l_adr_value_segment_code
20644         , p_from_combination_id     => l_adr_value_combination_id
20645         , p_value_type_code         => l_adr_value_type_code
20646         , p_transaction_coa_id      => l_adr_transaction_coa_id
20647         , p_accounting_coa_id       => l_adr_accounting_coa_id
20648         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
20649         , p_flex_value_set_id       => l_adr_flex_value_set_id
20650         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
20651         , p_adr_type_code           => 'S'
20655         , p_component_appl_id       => l_component_appl_id
20652         , p_component_type          => l_component_type
20653         , p_component_code          => l_component_code
20654         , p_component_type_code     => l_component_type_code
20656         , p_amb_context_code        => l_amb_context_code
20657         , p_entity_code             => 'TRANSACTIONS'
20658         , p_event_class_code        => 'INVOICE'
20659         , p_side                    => 'NA'
20660         );
20661 
20662   END IF;
20663 
20664    --
20665    --
20666    END IF;
20667 
20668        --
20669        -- Update the line information that should be overwritten
20670        --
20671        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
20672                                          p_header_num   => 1);
20673        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
20674 
20675        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
20676 
20677        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
20678           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
20679        END IF;
20680 
20681       --
20682       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
20683       --
20684       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
20685           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
20686       ELSE
20687           ---------------------------------------------------------------------------------------------------
20688           -- 4262811a Switch Sign
20689           ---------------------------------------------------------------------------------------------------
20690           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
20691           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
20692                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20693           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
20694                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20695           -- 5132302
20696           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
20697                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20698 
20699       END IF;
20700 
20701       -- 4955764
20702       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
20703       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
20704 
20705 
20706       XLA_AE_LINES_PKG.ValidateCurrentLine;
20707       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
20708 
20709       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
20710                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
20711                ,p_balance_type_code => l_balance_type_code);
20712 
20713    END IF;
20714 
20715    -----------------------------------------------------------------------------------------
20716    -- 4262811 Multiperiod Accounting
20717    -----------------------------------------------------------------------------------------
20718      -- No MPA option is assigned.
20719 
20720 
20721 END IF;
20722 END IF;
20723 --
20724 
20725 --
20726 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
20727    trace
20728       (p_msg      => 'END of AcctLineType_60'
20729       ,p_level    => C_LEVEL_PROCEDURE
20730       ,p_module   => l_log_module);
20731 END IF;
20732 --
20733 EXCEPTION
20734   WHEN xla_exceptions_pkg.application_exception THEN
20735       RAISE;
20736   WHEN OTHERS THEN
20737        xla_exceptions_pkg.raise_message
20738            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_60');
20739 END AcctLineType_60;
20740 --
20741 
20742 ---------------------------------------
20743 --
20744 -- PRIVATE FUNCTION
20745 --         AcctLineType_61
20746 --
20747 ---------------------------------------
20748 PROCEDURE AcctLineType_61 (
20749   p_application_id        IN NUMBER
20750  ,p_event_id              IN NUMBER
20751  ,p_calculate_acctd_flag  IN VARCHAR2
20752  ,p_calculate_g_l_flag    IN VARCHAR2
20753  ,p_actual_flag           IN OUT VARCHAR2
20754  ,p_balance_type_code     OUT VARCHAR2
20755  ,p_gain_or_loss_ref      OUT VARCHAR2
20756  
20757 --Distribution GL Account
20758  , p_source_3            IN NUMBER
20759 --Federal Fund Expired Status
20760  , p_source_8            IN VARCHAR2
20761 --Federal Prior Year Flag
20762  , p_source_9            IN VARCHAR2
20763 --Federal Fund Time Frame
20764  , p_source_10            IN VARCHAR2
20765 --Remittance Bank Account Cash Account
20766  , p_source_13            IN NUMBER
20767 --Distribution Source Type
20768  , p_source_20            IN VARCHAR2
20769 --Distribution Line Identifier
20770  , p_source_22            IN NUMBER
20771 --Distribution Type
20772  , p_source_23            IN VARCHAR2
20773 --Entered Amount
20774  , p_source_24            IN NUMBER
20775 --Currency Code
20776  , p_source_25            IN VARCHAR2
20777 --Exchange Rate
20781 --Applied To Document Accounting Amount
20778  , p_source_27            IN NUMBER
20779 --Exchange Rate Type
20780  , p_source_28            IN VARCHAR2
20782  , p_source_29            IN NUMBER
20783 --Federal Account Valid Flag
20784  , p_source_56            IN VARCHAR2
20785 --Applied To Document Exchange Date
20786  , p_source_57            IN DATE
20787 )
20788 IS
20789 
20790 l_component_type              VARCHAR2(80);
20791 l_component_code              VARCHAR2(30);
20792 l_component_type_code         VARCHAR2(1);
20793 l_component_appl_id           INTEGER;
20794 l_amb_context_code            VARCHAR2(30);
20795 l_entity_code                 VARCHAR2(30);
20796 l_event_class_code            VARCHAR2(30);
20797 l_ae_header_id                NUMBER;
20798 l_event_type_code             VARCHAR2(30);
20799 l_line_definition_code        VARCHAR2(30);
20800 l_line_definition_owner_code  VARCHAR2(1);
20801 --
20802 -- adr variables
20803 l_segment                     VARCHAR2(30);
20804 l_ccid                        NUMBER;
20805 l_adr_transaction_coa_id      NUMBER;
20806 l_adr_accounting_coa_id       NUMBER;
20807 l_adr_flexfield_segment_code  VARCHAR2(30);
20808 l_adr_flex_value_set_id       NUMBER;
20809 l_adr_value_type_code         VARCHAR2(30);
20810 l_adr_value_combination_id    NUMBER;
20811 l_adr_value_segment_code      VARCHAR2(30);
20812 
20813 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
20814 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
20815 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
20816 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
20817 
20818 -- 4262811 Variables ------------------------------------------------------------------------------------------
20819 l_entered_amt_idx             NUMBER;
20820 l_accted_amt_idx              NUMBER;
20821 l_acc_rev_flag                VARCHAR2(1);
20822 l_accrual_line_num            NUMBER;
20823 l_tmp_amt                     NUMBER;
20824 l_acc_rev_natural_side_code   VARCHAR2(1);
20825 
20826 l_num_entries                 NUMBER;
20827 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
20828 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
20829 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
20830 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
20831 l_recog_line_1                NUMBER;
20832 l_recog_line_2                NUMBER;
20833 
20834 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
20835 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
20836 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
20837 
20838 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
20839 
20840 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
20841 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
20842 
20843 ---------------------------------------------------------------------------------------------------------------
20844 
20845 
20846 --
20847 -- bulk performance
20848 --
20849 l_balance_type_code           VARCHAR2(1);
20850 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
20851 l_log_module                  VARCHAR2(240);
20852 
20853 --
20854 -- Upgrade strategy
20855 --
20856 l_actual_upg_option           VARCHAR2(1);
20857 l_enc_upg_option           VARCHAR2(1);
20858 
20859 --
20860 BEGIN
20861 --
20862 IF g_log_enabled THEN
20863       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_61';
20864 END IF;
20865 --
20866 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
20867 
20868       trace
20869          (p_msg      => 'BEGIN of AcctLineType_61'
20870          ,p_level    => C_LEVEL_PROCEDURE
20871          ,p_module   => l_log_module);
20872 
20873 END IF;
20874 --
20875 l_component_type             := 'AMB_JLT';
20876 l_component_code             := 'FV_MISC_RCT_REF_OEF_CR';
20877 l_component_type_code        := 'S';
20878 l_component_appl_id          :=  222;
20879 l_amb_context_code           := 'DEFAULT';
20880 l_entity_code                := 'RECEIPTS';
20881 l_event_class_code           := 'MISC_RECEIPT';
20882 l_event_type_code            := 'MISC_RECEIPT_ALL';
20883 l_line_definition_owner_code := 'S';
20884 l_line_definition_code       := 'MFAR_FED_AR_MISC_REC_BALANCING';
20885 --
20886 l_balance_type_code          := 'A';
20887 l_segment                     := NULL;
20888 l_ccid                        := NULL;
20889 l_adr_transaction_coa_id      := NULL;
20890 l_adr_accounting_coa_id       := NULL;
20891 l_adr_flexfield_segment_code  := NULL;
20892 l_adr_flex_value_set_id       := NULL;
20893 l_adr_value_type_code         := NULL;
20894 l_adr_value_combination_id    := NULL;
20895 l_adr_value_segment_code      := NULL;
20896 
20897 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
20898 l_bflow_class_code           := '';    -- 4219869 Business Flow
20899 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
20900 l_budgetary_control_flag     := 'N';
20901 
20902 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
20903 l_bflow_applied_to_amt       := NULL; -- 5132302
20904 l_entered_amt_idx            := NULL;          -- 4262811
20908 l_tmp_amt                    := NULL;          -- 4262811
20905 l_accted_amt_idx             := NULL;          -- 4262811
20906 l_acc_rev_flag               := NULL;          -- 4262811
20907 l_accrual_line_num           := NULL;          -- 4262811
20909 --
20910  
20911 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
20912     l_balance_type_code <> 'B' THEN
20913 IF NVL(p_source_20,'
20914 ') =  'MISCCASH' AND 
20915 NVL(p_source_8,'
20916 ') =  'Expired' AND 
20917 NVL(p_source_9,'
20918 ') =  'Y' AND 
20919 (NVL(p_source_10,'
20920 ') =  'SINGLE' OR 
20921 NVL(p_source_10,'
20922 ') =  'MULTIPLE' OR 
20923 NVL(p_source_10,'
20924 ') =  'NO_YEAR') AND 
20925 NVL(p_source_56,'
20926 ') =  'Y'
20927  THEN 
20928 
20929    --
20930    XLA_AE_LINES_PKG.SetNewLine;
20931 
20932    p_balance_type_code          := l_balance_type_code;
20933    -- set the flag so later we will know whether the gain loss line needs to be created
20934    
20935    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
20936      p_actual_flag :='A';
20937    END IF;
20938 
20939    --
20940    -- bulk performance
20941    --
20942    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
20943                                       p_header_num   => 0); -- 4262811
20944    --
20945    -- set accounting line options
20946    --
20947    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
20948            p_natural_side_code          => 'C'
20949          , p_gain_or_loss_flag          => 'N'
20950          , p_gl_transfer_mode_code      => 'S'
20951          , p_acct_entry_type_code       => 'A'
20952          , p_switch_side_flag           => 'Y'
20953          , p_merge_duplicate_code       => 'A'
20954          );
20955    --
20956    l_acc_rev_natural_side_code := 'D';  -- 4262811
20957    -- 
20958    --
20959    -- set accounting line type info
20960    --
20961    xla_ae_lines_pkg.SetAcctLineType
20962       (p_component_type             => l_component_type
20963       ,p_event_type_code            => l_event_type_code
20964       ,p_line_definition_owner_code => l_line_definition_owner_code
20965       ,p_line_definition_code       => l_line_definition_code
20966       ,p_accounting_line_code       => l_component_code
20967       ,p_accounting_line_type_code  => l_component_type_code
20968       ,p_accounting_line_appl_id    => l_component_appl_id
20969       ,p_amb_context_code           => l_amb_context_code
20970       ,p_entity_code                => l_entity_code
20971       ,p_event_class_code           => l_event_class_code);
20972    --
20973    -- set accounting class
20974    --
20975    xla_ae_lines_pkg.SetAcctClass(
20976            p_accounting_class_code  => 'FV_MISCCASH_CR'
20977          , p_ae_header_id           => l_ae_header_id
20978          );
20979 
20980    --
20981    -- set rounding class
20982    --
20983    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
20984                       'RECEIVABLE';
20985 
20986    --
20987    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
20988    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
20989    --
20990    -- bulk performance
20991    --
20992    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
20993 
20994    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
20995       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
20996 
20997    -- 4955764
20998    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
20999       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
21000 
21001    -- 4458381 Public Sector Enh
21002    
21003    --
21004    -- set accounting attributes for the line type
21005    --
21006    l_entered_amt_idx := 3;
21007    l_accted_amt_idx  := 8;
21008    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
21009    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
21010    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
21011    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
21012    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
21013    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
21014    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
21015    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
21016    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
21017    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
21018    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
21019    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
21020    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
21021    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
21022    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
21023    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
21024    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
21025 
21026    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
21027    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
21028 
21032    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
21029    ---------------------------------------------------------------------------------------------------------------
21030    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
21031    ---------------------------------------------------------------------------------------------------------------
21033 
21034    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
21035    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
21036 
21037    IF xla_accounting_cache_pkg.GetValueChar
21038          (p_source_code         => 'LEDGER_CATEGORY_CODE'
21039          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
21040    AND l_bflow_method_code = 'PRIOR_ENTRY'
21041 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
21042    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
21043          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
21044        )
21045    THEN
21046          xla_ae_lines_pkg.BflowUpgEntry
21047            (p_business_method_code    => l_bflow_method_code
21048            ,p_business_class_code     => l_bflow_class_code
21049            ,p_balance_type            => l_balance_type_code);
21050    ELSE
21051       NULL;
21052 -- No business flow processing for business flow method of NONE.
21053    END IF;
21054 
21055    --
21056    -- call analytical criteria
21057    --
21058    
21059    --
21060    -- call description
21061    --
21062    -- No description or it is inherited.
21063    --
21064    -- call ADRs
21065    -- Bug 4922099
21066    --
21067    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
21068         (NVL(l_actual_upg_option, 'N') = 'O') OR
21069         (NVL(l_enc_upg_option, 'N') = 'O')
21070       )
21071    THEN
21072    NULL;
21073    --
21074    --
21075    
21076   l_ccid := AcctDerRule_25(
21077            p_application_id           => p_application_id
21078          , p_ae_header_id             => l_ae_header_id 
21079 , p_source_13 => p_source_13
21080          , x_transaction_coa_id       => l_adr_transaction_coa_id
21081          , x_accounting_coa_id        => l_adr_accounting_coa_id
21082          , x_value_type_code          => l_adr_value_type_code
21083          , p_side                     => 'NA'
21084    );
21085 
21086    xla_ae_lines_pkg.set_ccid(
21087     p_code_combination_id          => l_ccid
21088   , p_value_type_code              => l_adr_value_type_code
21089   , p_transaction_coa_id           => l_adr_transaction_coa_id
21090   , p_accounting_coa_id            => l_adr_accounting_coa_id
21091   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
21092   , p_adr_type_code                => 'S'
21093   , p_component_type               => l_component_type
21094   , p_component_code               => l_component_code
21095   , p_component_type_code          => l_component_type_code
21096   , p_component_appl_id            => l_component_appl_id
21097   , p_amb_context_code             => l_amb_context_code
21098   , p_side                         => 'NA'
21099   );
21100 
21101 
21102    l_segment := AcctDerRule_16(
21103            p_application_id           => p_application_id
21104          , p_ae_header_id             => l_ae_header_id 
21105 , p_source_8 => p_source_8
21106 , p_source_9 => p_source_9
21107 , p_source_10 => p_source_10
21108          , x_transaction_coa_id       => l_adr_transaction_coa_id
21109          , x_accounting_coa_id        => l_adr_accounting_coa_id
21110          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
21111          , x_flex_value_set_id        => l_adr_flex_value_set_id
21112          , x_value_type_code          => l_adr_value_type_code
21113          , x_value_combination_id     => l_adr_value_combination_id
21114          , x_value_segment_code       => l_adr_value_segment_code
21115          , p_side                     => 'NA'
21116          , p_override_seg_flag        => 'Y'
21117    );
21118 
21119    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
21120 
21121       xla_ae_lines_pkg.set_segment(
21122           p_to_segment_code         => 'GL_ACCOUNT'
21123         , p_segment_value           => l_segment
21124         , p_from_segment_code       => l_adr_value_segment_code
21125         , p_from_combination_id     => l_adr_value_combination_id
21126         , p_value_type_code         => l_adr_value_type_code
21127         , p_transaction_coa_id      => l_adr_transaction_coa_id
21128         , p_accounting_coa_id       => l_adr_accounting_coa_id
21129         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
21130         , p_flex_value_set_id       => l_adr_flex_value_set_id
21131         , p_adr_code                => 'FV_AR_465002_MISC_RCT_CR'
21132         , p_adr_type_code           => 'S'
21133         , p_component_type          => l_component_type
21134         , p_component_code          => l_component_code
21135         , p_component_type_code     => l_component_type_code
21136         , p_component_appl_id       => l_component_appl_id
21137         , p_amb_context_code        => l_amb_context_code
21138         , p_entity_code             => 'RECEIPTS'
21139         , p_event_class_code        => 'MISC_RECEIPT'
21140         , p_side                    => 'NA'
21141         );
21142 
21143   END IF;
21144 
21148 , p_source_3 => p_source_3
21145    l_segment := AcctDerRule_4(
21146            p_application_id           => p_application_id
21147          , p_ae_header_id             => l_ae_header_id 
21149          , x_transaction_coa_id       => l_adr_transaction_coa_id
21150          , x_accounting_coa_id        => l_adr_accounting_coa_id
21151          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
21152          , x_flex_value_set_id        => l_adr_flex_value_set_id
21153          , x_value_type_code          => l_adr_value_type_code
21154          , x_value_combination_id     => l_adr_value_combination_id
21155          , x_value_segment_code       => l_adr_value_segment_code
21156          , p_side                     => 'NA'
21157          , p_override_seg_flag        => 'Y'
21158    );
21159 
21160    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
21161 
21162       xla_ae_lines_pkg.set_segment(
21163           p_to_segment_code         => 'GL_BALANCING'
21164         , p_segment_value           => l_segment
21165         , p_from_segment_code       => l_adr_value_segment_code
21166         , p_from_combination_id     => l_adr_value_combination_id
21167         , p_value_type_code         => l_adr_value_type_code
21168         , p_transaction_coa_id      => l_adr_transaction_coa_id
21169         , p_accounting_coa_id       => l_adr_accounting_coa_id
21170         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
21171         , p_flex_value_set_id       => l_adr_flex_value_set_id
21172         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
21173         , p_adr_type_code           => 'S'
21174         , p_component_type          => l_component_type
21175         , p_component_code          => l_component_code
21176         , p_component_type_code     => l_component_type_code
21177         , p_component_appl_id       => l_component_appl_id
21178         , p_amb_context_code        => l_amb_context_code
21179         , p_entity_code             => 'RECEIPTS'
21180         , p_event_class_code        => 'MISC_RECEIPT'
21181         , p_side                    => 'NA'
21182         );
21183 
21184   END IF;
21185 
21186    --
21187    --
21188    END IF;
21189    --
21190    -- Bug 4922099
21191    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
21192           (NVL(l_enc_upg_option, 'N') = 'O')
21193         ) AND
21194         (l_bflow_method_code = 'PRIOR_ENTRY')
21195       )
21196    THEN
21197       IF
21198       --
21199       1 = 2
21200       --
21201       THEN
21202       xla_accounting_err_pkg.build_message
21203                                     (p_appli_s_name            => 'XLA'
21204                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
21205                                     ,p_token_1                 => 'LINE_NUMBER'
21206                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
21207                                     ,p_token_2                 => 'LINE_TYPE_NAME'
21208                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
21209                                                                              l_component_type
21210                                                                             ,l_component_code
21211                                                                             ,l_component_type_code
21212                                                                             ,l_component_appl_id
21213                                                                             ,l_amb_context_code
21214                                                                             ,l_entity_code
21215                                                                             ,l_event_class_code
21216                                                                            )
21217                                     ,p_token_3                 => 'OWNER'
21218                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
21219                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
21220                                                                           ,p_lookup_code    => l_component_type_code
21221                                                                          )
21222                                     ,p_token_4                 => 'PRODUCT_NAME'
21223                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
21224                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
21225                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
21226                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
21227                                     ,p_ae_header_id            =>  NULL
21228                                        );
21229 
21230         IF (C_LEVEL_ERROR>= g_log_level) THEN
21231                  trace
21232                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
21233                       ,p_level    => C_LEVEL_ERROR
21234                       ,p_module   => l_log_module);
21235         END IF;
21236       END IF;
21237    END IF;
21238    --
21239    --
21240    ------------------------------------------------------------------------------------------------
21241    -- 4219869 Business Flow
21242    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
21246 
21243    -- Prior Entry.  Currently, the following code is always generated.
21244    ------------------------------------------------------------------------------------------------
21245    XLA_AE_LINES_PKG.ValidateCurrentLine;
21247    ------------------------------------------------------------------------------------
21248    -- 4219869 Business Flow
21249    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
21250    ------------------------------------------------------------------------------------
21251    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
21252 
21253    ----------------------------------------------------------------------------------
21254    -- 4219869 Business Flow
21255    -- Update journal entry status -- Need to generate this within IF <condition>
21256    ----------------------------------------------------------------------------------
21257    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
21258          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
21259          ,p_balance_type_code => l_balance_type_code
21260          );
21261 
21262    -------------------------------------------------------------------------------------------
21263    -- 4262811 - Generate the Accrual Reversal lines
21264    -------------------------------------------------------------------------------------------
21265    BEGIN
21266       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
21267                               (g_array_event(p_event_id).array_value_num('header_index'));
21268       IF l_acc_rev_flag IS NULL THEN
21269          l_acc_rev_flag := 'N';
21270       END IF;
21271    EXCEPTION
21272       WHEN OTHERS THEN
21273          l_acc_rev_flag := 'N';
21274    END;
21275    --
21276    IF (l_acc_rev_flag = 'Y') THEN
21277 
21278        -- 4645092  ------------------------------------------------------------------------------
21279        -- To allow MPA report to determine if it should generate report process
21280        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
21281        ------------------------------------------------------------------------------------------
21282 
21283        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
21284        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
21285    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
21286    -- call ADRs
21287    -- Bug 4922099
21288    --
21289    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
21290         (NVL(l_actual_upg_option, 'N') = 'O') OR
21291         (NVL(l_enc_upg_option, 'N') = 'O')
21292       )
21293    THEN
21294    NULL;
21295    --
21296    --
21297    
21298   l_ccid := AcctDerRule_25(
21299            p_application_id           => p_application_id
21300          , p_ae_header_id             => l_ae_header_id 
21301 , p_source_13 => p_source_13
21302          , x_transaction_coa_id       => l_adr_transaction_coa_id
21303          , x_accounting_coa_id        => l_adr_accounting_coa_id
21304          , x_value_type_code          => l_adr_value_type_code
21305          , p_side                     => 'NA'
21306    );
21307 
21308    xla_ae_lines_pkg.set_ccid(
21309     p_code_combination_id          => l_ccid
21310   , p_value_type_code              => l_adr_value_type_code
21311   , p_transaction_coa_id           => l_adr_transaction_coa_id
21312   , p_accounting_coa_id            => l_adr_accounting_coa_id
21313   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
21314   , p_adr_type_code                => 'S'
21315   , p_component_type               => l_component_type
21316   , p_component_code               => l_component_code
21317   , p_component_type_code          => l_component_type_code
21318   , p_component_appl_id            => l_component_appl_id
21319   , p_amb_context_code             => l_amb_context_code
21320   , p_side                         => 'NA'
21321   );
21322 
21323 
21324    l_segment := AcctDerRule_16(
21325            p_application_id           => p_application_id
21326          , p_ae_header_id             => l_ae_header_id 
21327 , p_source_8 => p_source_8
21328 , p_source_9 => p_source_9
21329 , p_source_10 => p_source_10
21330          , x_transaction_coa_id       => l_adr_transaction_coa_id
21331          , x_accounting_coa_id        => l_adr_accounting_coa_id
21332          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
21333          , x_flex_value_set_id        => l_adr_flex_value_set_id
21334          , x_value_type_code          => l_adr_value_type_code
21335          , x_value_combination_id     => l_adr_value_combination_id
21336          , x_value_segment_code       => l_adr_value_segment_code
21337          , p_side                     => 'NA'
21338          , p_override_seg_flag        => 'Y'
21339    );
21340 
21341    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
21342 
21343       xla_ae_lines_pkg.set_segment(
21344           p_to_segment_code         => 'GL_ACCOUNT'
21345         , p_segment_value           => l_segment
21346         , p_from_segment_code       => l_adr_value_segment_code
21347         , p_from_combination_id     => l_adr_value_combination_id
21348         , p_value_type_code         => l_adr_value_type_code
21349         , p_transaction_coa_id      => l_adr_transaction_coa_id
21350         , p_accounting_coa_id       => l_adr_accounting_coa_id
21351         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
21352         , p_flex_value_set_id       => l_adr_flex_value_set_id
21353         , p_adr_code                => 'FV_AR_465002_MISC_RCT_CR'
21357         , p_component_type_code     => l_component_type_code
21354         , p_adr_type_code           => 'S'
21355         , p_component_type          => l_component_type
21356         , p_component_code          => l_component_code
21358         , p_component_appl_id       => l_component_appl_id
21359         , p_amb_context_code        => l_amb_context_code
21360         , p_entity_code             => 'RECEIPTS'
21361         , p_event_class_code        => 'MISC_RECEIPT'
21362         , p_side                    => 'NA'
21363         );
21364 
21365   END IF;
21366 
21367    l_segment := AcctDerRule_4(
21368            p_application_id           => p_application_id
21369          , p_ae_header_id             => l_ae_header_id 
21370 , p_source_3 => p_source_3
21371          , x_transaction_coa_id       => l_adr_transaction_coa_id
21372          , x_accounting_coa_id        => l_adr_accounting_coa_id
21373          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
21374          , x_flex_value_set_id        => l_adr_flex_value_set_id
21375          , x_value_type_code          => l_adr_value_type_code
21376          , x_value_combination_id     => l_adr_value_combination_id
21377          , x_value_segment_code       => l_adr_value_segment_code
21378          , p_side                     => 'NA'
21379          , p_override_seg_flag        => 'Y'
21380    );
21381 
21382    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
21383 
21384       xla_ae_lines_pkg.set_segment(
21385           p_to_segment_code         => 'GL_BALANCING'
21386         , p_segment_value           => l_segment
21387         , p_from_segment_code       => l_adr_value_segment_code
21388         , p_from_combination_id     => l_adr_value_combination_id
21389         , p_value_type_code         => l_adr_value_type_code
21390         , p_transaction_coa_id      => l_adr_transaction_coa_id
21391         , p_accounting_coa_id       => l_adr_accounting_coa_id
21392         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
21393         , p_flex_value_set_id       => l_adr_flex_value_set_id
21394         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
21395         , p_adr_type_code           => 'S'
21396         , p_component_type          => l_component_type
21397         , p_component_code          => l_component_code
21398         , p_component_type_code     => l_component_type_code
21399         , p_component_appl_id       => l_component_appl_id
21400         , p_amb_context_code        => l_amb_context_code
21401         , p_entity_code             => 'RECEIPTS'
21402         , p_event_class_code        => 'MISC_RECEIPT'
21403         , p_side                    => 'NA'
21404         );
21405 
21406   END IF;
21407 
21408    --
21409    --
21410    END IF;
21411 
21412        --
21413        -- Update the line information that should be overwritten
21414        --
21415        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
21416                                          p_header_num   => 1);
21417        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
21418 
21419        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
21420 
21421        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
21422           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
21423        END IF;
21424 
21425       --
21426       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
21427       --
21428       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
21429           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
21430       ELSE
21431           ---------------------------------------------------------------------------------------------------
21432           -- 4262811a Switch Sign
21433           ---------------------------------------------------------------------------------------------------
21434           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
21435           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
21436                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
21437           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
21438                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
21439           -- 5132302
21440           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
21441                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
21442 
21443       END IF;
21444 
21445       -- 4955764
21446       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
21447       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
21448 
21449 
21450       XLA_AE_LINES_PKG.ValidateCurrentLine;
21451       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
21452 
21453       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
21454                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
21455                ,p_balance_type_code => l_balance_type_code);
21456 
21457    END IF;
21458 
21462      -- No MPA option is assigned.
21459    -----------------------------------------------------------------------------------------
21460    -- 4262811 Multiperiod Accounting
21461    -----------------------------------------------------------------------------------------
21463 
21464 
21465 END IF;
21466 END IF;
21467 --
21468 
21469 --
21470 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
21471    trace
21472       (p_msg      => 'END of AcctLineType_61'
21473       ,p_level    => C_LEVEL_PROCEDURE
21474       ,p_module   => l_log_module);
21475 END IF;
21476 --
21477 EXCEPTION
21478   WHEN xla_exceptions_pkg.application_exception THEN
21479       RAISE;
21480   WHEN OTHERS THEN
21481        xla_exceptions_pkg.raise_message
21482            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_61');
21483 END AcctLineType_61;
21484 --
21485 
21486 ---------------------------------------
21487 --
21488 -- PRIVATE FUNCTION
21489 --         AcctLineType_62
21490 --
21491 ---------------------------------------
21492 PROCEDURE AcctLineType_62 (
21493   p_application_id        IN NUMBER
21494  ,p_event_id              IN NUMBER
21495  ,p_calculate_acctd_flag  IN VARCHAR2
21496  ,p_calculate_g_l_flag    IN VARCHAR2
21497  ,p_actual_flag           IN OUT VARCHAR2
21498  ,p_balance_type_code     OUT VARCHAR2
21499  ,p_gain_or_loss_ref      OUT VARCHAR2
21500  
21501 --Distribution GL Account
21502  , p_source_3            IN NUMBER
21503 --Federal Fund Expired Status
21504  , p_source_8            IN VARCHAR2
21505 --Federal Prior Year Flag
21506  , p_source_9            IN VARCHAR2
21507 --Federal Fund Time Frame
21508  , p_source_10            IN VARCHAR2
21509 --Remittance Bank Account Cash Account
21510  , p_source_13            IN NUMBER
21511 --Distribution Source Type
21512  , p_source_20            IN VARCHAR2
21513 --Distribution Line Identifier
21514  , p_source_22            IN NUMBER
21515 --Distribution Type
21516  , p_source_23            IN VARCHAR2
21517 --Entered Amount
21518  , p_source_24            IN NUMBER
21519 --Currency Code
21520  , p_source_25            IN VARCHAR2
21521 --Exchange Rate
21522  , p_source_27            IN NUMBER
21523 --Exchange Rate Type
21524  , p_source_28            IN VARCHAR2
21525 --Applied To Document Accounting Amount
21526  , p_source_29            IN NUMBER
21527 --Federal Account Valid Flag
21528  , p_source_56            IN VARCHAR2
21529 --Applied To Document Exchange Date
21530  , p_source_57            IN DATE
21531 )
21532 IS
21533 
21534 l_component_type              VARCHAR2(80);
21535 l_component_code              VARCHAR2(30);
21536 l_component_type_code         VARCHAR2(1);
21537 l_component_appl_id           INTEGER;
21538 l_amb_context_code            VARCHAR2(30);
21539 l_entity_code                 VARCHAR2(30);
21540 l_event_class_code            VARCHAR2(30);
21541 l_ae_header_id                NUMBER;
21542 l_event_type_code             VARCHAR2(30);
21543 l_line_definition_code        VARCHAR2(30);
21544 l_line_definition_owner_code  VARCHAR2(1);
21545 --
21546 -- adr variables
21547 l_segment                     VARCHAR2(30);
21548 l_ccid                        NUMBER;
21549 l_adr_transaction_coa_id      NUMBER;
21550 l_adr_accounting_coa_id       NUMBER;
21551 l_adr_flexfield_segment_code  VARCHAR2(30);
21552 l_adr_flex_value_set_id       NUMBER;
21553 l_adr_value_type_code         VARCHAR2(30);
21554 l_adr_value_combination_id    NUMBER;
21555 l_adr_value_segment_code      VARCHAR2(30);
21556 
21557 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
21558 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
21559 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
21560 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
21561 
21562 -- 4262811 Variables ------------------------------------------------------------------------------------------
21563 l_entered_amt_idx             NUMBER;
21564 l_accted_amt_idx              NUMBER;
21565 l_acc_rev_flag                VARCHAR2(1);
21566 l_accrual_line_num            NUMBER;
21567 l_tmp_amt                     NUMBER;
21568 l_acc_rev_natural_side_code   VARCHAR2(1);
21569 
21570 l_num_entries                 NUMBER;
21571 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
21572 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
21573 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
21574 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
21575 l_recog_line_1                NUMBER;
21576 l_recog_line_2                NUMBER;
21577 
21578 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
21579 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
21580 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
21581 
21582 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
21583 
21584 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
21585 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
21586 
21587 ---------------------------------------------------------------------------------------------------------------
21588 
21589 
21590 --
21594 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
21591 -- bulk performance
21592 --
21593 l_balance_type_code           VARCHAR2(1);
21595 l_log_module                  VARCHAR2(240);
21596 
21597 --
21598 -- Upgrade strategy
21599 --
21600 l_actual_upg_option           VARCHAR2(1);
21601 l_enc_upg_option           VARCHAR2(1);
21602 
21603 --
21604 BEGIN
21605 --
21606 IF g_log_enabled THEN
21607       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_62';
21608 END IF;
21609 --
21610 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
21611 
21612       trace
21613          (p_msg      => 'BEGIN of AcctLineType_62'
21614          ,p_level    => C_LEVEL_PROCEDURE
21615          ,p_module   => l_log_module);
21616 
21617 END IF;
21618 --
21619 l_component_type             := 'AMB_JLT';
21620 l_component_code             := 'FV_MISC_RCT_REF_OEF_DR';
21621 l_component_type_code        := 'S';
21622 l_component_appl_id          :=  222;
21623 l_amb_context_code           := 'DEFAULT';
21624 l_entity_code                := 'RECEIPTS';
21625 l_event_class_code           := 'MISC_RECEIPT';
21626 l_event_type_code            := 'MISC_RECEIPT_ALL';
21627 l_line_definition_owner_code := 'S';
21628 l_line_definition_code       := 'MFAR_FED_AR_MISC_REC_BALANCING';
21629 --
21630 l_balance_type_code          := 'A';
21631 l_segment                     := NULL;
21632 l_ccid                        := NULL;
21633 l_adr_transaction_coa_id      := NULL;
21634 l_adr_accounting_coa_id       := NULL;
21635 l_adr_flexfield_segment_code  := NULL;
21636 l_adr_flex_value_set_id       := NULL;
21637 l_adr_value_type_code         := NULL;
21638 l_adr_value_combination_id    := NULL;
21639 l_adr_value_segment_code      := NULL;
21640 
21641 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
21642 l_bflow_class_code           := '';    -- 4219869 Business Flow
21643 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
21644 l_budgetary_control_flag     := 'N';
21645 
21646 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
21647 l_bflow_applied_to_amt       := NULL; -- 5132302
21648 l_entered_amt_idx            := NULL;          -- 4262811
21649 l_accted_amt_idx             := NULL;          -- 4262811
21650 l_acc_rev_flag               := NULL;          -- 4262811
21651 l_accrual_line_num           := NULL;          -- 4262811
21652 l_tmp_amt                    := NULL;          -- 4262811
21653 --
21654  
21655 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
21656     l_balance_type_code <> 'B' THEN
21657 IF NVL(p_source_20,'
21658 ') =  'MISCCASH' AND 
21659 NVL(p_source_8,'
21660 ') =  'Expired' AND 
21661 NVL(p_source_9,'
21662 ') =  'Y' AND 
21663 (NVL(p_source_10,'
21664 ') =  'SINGLE' OR 
21665 NVL(p_source_10,'
21666 ') =  'MULTIPLE' OR 
21667 NVL(p_source_10,'
21668 ') =  'NO_YEAR') AND 
21669 NVL(p_source_56,'
21670 ') =  'Y'
21671  THEN 
21672 
21673    --
21674    XLA_AE_LINES_PKG.SetNewLine;
21675 
21676    p_balance_type_code          := l_balance_type_code;
21677    -- set the flag so later we will know whether the gain loss line needs to be created
21678    
21679    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
21680      p_actual_flag :='A';
21681    END IF;
21682 
21683    --
21684    -- bulk performance
21685    --
21686    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
21687                                       p_header_num   => 0); -- 4262811
21688    --
21689    -- set accounting line options
21690    --
21691    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
21692            p_natural_side_code          => 'D'
21693          , p_gain_or_loss_flag          => 'N'
21694          , p_gl_transfer_mode_code      => 'S'
21695          , p_acct_entry_type_code       => 'A'
21696          , p_switch_side_flag           => 'Y'
21697          , p_merge_duplicate_code       => 'A'
21698          );
21699    --
21700    l_acc_rev_natural_side_code := 'C';  -- 4262811
21701    -- 
21702    --
21703    -- set accounting line type info
21704    --
21705    xla_ae_lines_pkg.SetAcctLineType
21706       (p_component_type             => l_component_type
21707       ,p_event_type_code            => l_event_type_code
21708       ,p_line_definition_owner_code => l_line_definition_owner_code
21709       ,p_line_definition_code       => l_line_definition_code
21710       ,p_accounting_line_code       => l_component_code
21711       ,p_accounting_line_type_code  => l_component_type_code
21712       ,p_accounting_line_appl_id    => l_component_appl_id
21713       ,p_amb_context_code           => l_amb_context_code
21714       ,p_entity_code                => l_entity_code
21715       ,p_event_class_code           => l_event_class_code);
21716    --
21717    -- set accounting class
21718    --
21719    xla_ae_lines_pkg.SetAcctClass(
21720            p_accounting_class_code  => 'FV_MISCCASH_DR'
21721          , p_ae_header_id           => l_ae_header_id
21722          );
21723 
21724    --
21725    -- set rounding class
21726    --
21727    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
21728                       'RECEIVABLE';
21729 
21730    --
21731    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
21735    --
21732    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
21733    --
21734    -- bulk performance
21736    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
21737 
21738    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
21739       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
21740 
21741    -- 4955764
21742    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
21743       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
21744 
21745    -- 4458381 Public Sector Enh
21746    
21747    --
21748    -- set accounting attributes for the line type
21749    --
21750    l_entered_amt_idx := 3;
21751    l_accted_amt_idx  := 8;
21752    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
21753    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
21754    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
21755    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
21756    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
21757    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
21758    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
21759    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
21760    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
21761    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
21762    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
21763    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
21764    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
21765    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
21766    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
21767    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
21768    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
21769 
21770    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
21771    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
21772 
21773    ---------------------------------------------------------------------------------------------------------------
21774    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
21775    ---------------------------------------------------------------------------------------------------------------
21776    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
21777 
21778    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
21779    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
21780 
21781    IF xla_accounting_cache_pkg.GetValueChar
21782          (p_source_code         => 'LEDGER_CATEGORY_CODE'
21783          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
21784    AND l_bflow_method_code = 'PRIOR_ENTRY'
21785 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
21786    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
21787          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
21788        )
21789    THEN
21790          xla_ae_lines_pkg.BflowUpgEntry
21791            (p_business_method_code    => l_bflow_method_code
21792            ,p_business_class_code     => l_bflow_class_code
21793            ,p_balance_type            => l_balance_type_code);
21794    ELSE
21795       NULL;
21796 -- No business flow processing for business flow method of NONE.
21797    END IF;
21798 
21799    --
21800    -- call analytical criteria
21801    --
21802    
21803    --
21804    -- call description
21805    --
21806    -- No description or it is inherited.
21807    --
21808    -- call ADRs
21809    -- Bug 4922099
21810    --
21811    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
21812         (NVL(l_actual_upg_option, 'N') = 'O') OR
21813         (NVL(l_enc_upg_option, 'N') = 'O')
21814       )
21815    THEN
21816    NULL;
21817    --
21818    --
21819    
21820   l_ccid := AcctDerRule_25(
21821            p_application_id           => p_application_id
21822          , p_ae_header_id             => l_ae_header_id 
21823 , p_source_13 => p_source_13
21824          , x_transaction_coa_id       => l_adr_transaction_coa_id
21825          , x_accounting_coa_id        => l_adr_accounting_coa_id
21826          , x_value_type_code          => l_adr_value_type_code
21827          , p_side                     => 'NA'
21828    );
21829 
21830    xla_ae_lines_pkg.set_ccid(
21831     p_code_combination_id          => l_ccid
21832   , p_value_type_code              => l_adr_value_type_code
21833   , p_transaction_coa_id           => l_adr_transaction_coa_id
21834   , p_accounting_coa_id            => l_adr_accounting_coa_id
21835   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
21836   , p_adr_type_code                => 'S'
21837   , p_component_type               => l_component_type
21838   , p_component_code               => l_component_code
21839   , p_component_type_code          => l_component_type_code
21840   , p_component_appl_id            => l_component_appl_id
21841   , p_amb_context_code             => l_amb_context_code
21842   , p_side                         => 'NA'
21843   );
21844 
21845 
21846    l_segment := AcctDerRule_21(
21850 , p_source_9 => p_source_9
21847            p_application_id           => p_application_id
21848          , p_ae_header_id             => l_ae_header_id 
21849 , p_source_8 => p_source_8
21851 , p_source_10 => p_source_10
21852          , x_transaction_coa_id       => l_adr_transaction_coa_id
21853          , x_accounting_coa_id        => l_adr_accounting_coa_id
21854          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
21855          , x_flex_value_set_id        => l_adr_flex_value_set_id
21856          , x_value_type_code          => l_adr_value_type_code
21857          , x_value_combination_id     => l_adr_value_combination_id
21858          , x_value_segment_code       => l_adr_value_segment_code
21859          , p_side                     => 'NA'
21860          , p_override_seg_flag        => 'Y'
21861    );
21862 
21863    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
21864 
21865       xla_ae_lines_pkg.set_segment(
21866           p_to_segment_code         => 'GL_ACCOUNT'
21867         , p_segment_value           => l_segment
21868         , p_from_segment_code       => l_adr_value_segment_code
21869         , p_from_combination_id     => l_adr_value_combination_id
21870         , p_value_type_code         => l_adr_value_type_code
21871         , p_transaction_coa_id      => l_adr_transaction_coa_id
21872         , p_accounting_coa_id       => l_adr_accounting_coa_id
21873         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
21874         , p_flex_value_set_id       => l_adr_flex_value_set_id
21875         , p_adr_code                => 'FV_AR_497201_MISC_RCT_DR'
21876         , p_adr_type_code           => 'S'
21877         , p_component_type          => l_component_type
21878         , p_component_code          => l_component_code
21879         , p_component_type_code     => l_component_type_code
21880         , p_component_appl_id       => l_component_appl_id
21881         , p_amb_context_code        => l_amb_context_code
21882         , p_entity_code             => 'RECEIPTS'
21883         , p_event_class_code        => 'MISC_RECEIPT'
21884         , p_side                    => 'NA'
21885         );
21886 
21887   END IF;
21888 
21889    l_segment := AcctDerRule_4(
21890            p_application_id           => p_application_id
21891          , p_ae_header_id             => l_ae_header_id 
21892 , p_source_3 => p_source_3
21893          , x_transaction_coa_id       => l_adr_transaction_coa_id
21894          , x_accounting_coa_id        => l_adr_accounting_coa_id
21895          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
21896          , x_flex_value_set_id        => l_adr_flex_value_set_id
21897          , x_value_type_code          => l_adr_value_type_code
21898          , x_value_combination_id     => l_adr_value_combination_id
21899          , x_value_segment_code       => l_adr_value_segment_code
21900          , p_side                     => 'NA'
21901          , p_override_seg_flag        => 'Y'
21902    );
21903 
21904    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
21905 
21906       xla_ae_lines_pkg.set_segment(
21907           p_to_segment_code         => 'GL_BALANCING'
21908         , p_segment_value           => l_segment
21909         , p_from_segment_code       => l_adr_value_segment_code
21910         , p_from_combination_id     => l_adr_value_combination_id
21911         , p_value_type_code         => l_adr_value_type_code
21912         , p_transaction_coa_id      => l_adr_transaction_coa_id
21913         , p_accounting_coa_id       => l_adr_accounting_coa_id
21914         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
21915         , p_flex_value_set_id       => l_adr_flex_value_set_id
21916         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
21917         , p_adr_type_code           => 'S'
21918         , p_component_type          => l_component_type
21919         , p_component_code          => l_component_code
21920         , p_component_type_code     => l_component_type_code
21921         , p_component_appl_id       => l_component_appl_id
21922         , p_amb_context_code        => l_amb_context_code
21923         , p_entity_code             => 'RECEIPTS'
21924         , p_event_class_code        => 'MISC_RECEIPT'
21925         , p_side                    => 'NA'
21926         );
21927 
21928   END IF;
21929 
21930    --
21931    --
21932    END IF;
21933    --
21934    -- Bug 4922099
21935    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
21936           (NVL(l_enc_upg_option, 'N') = 'O')
21937         ) AND
21938         (l_bflow_method_code = 'PRIOR_ENTRY')
21939       )
21940    THEN
21941       IF
21942       --
21943       1 = 2
21944       --
21945       THEN
21946       xla_accounting_err_pkg.build_message
21947                                     (p_appli_s_name            => 'XLA'
21948                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
21949                                     ,p_token_1                 => 'LINE_NUMBER'
21950                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
21951                                     ,p_token_2                 => 'LINE_TYPE_NAME'
21952                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
21953                                                                              l_component_type
21954                                                                             ,l_component_code
21958                                                                             ,l_entity_code
21955                                                                             ,l_component_type_code
21956                                                                             ,l_component_appl_id
21957                                                                             ,l_amb_context_code
21959                                                                             ,l_event_class_code
21960                                                                            )
21961                                     ,p_token_3                 => 'OWNER'
21962                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
21963                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
21964                                                                           ,p_lookup_code    => l_component_type_code
21965                                                                          )
21966                                     ,p_token_4                 => 'PRODUCT_NAME'
21967                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
21968                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
21969                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
21970                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
21971                                     ,p_ae_header_id            =>  NULL
21972                                        );
21973 
21974         IF (C_LEVEL_ERROR>= g_log_level) THEN
21975                  trace
21976                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
21977                       ,p_level    => C_LEVEL_ERROR
21978                       ,p_module   => l_log_module);
21979         END IF;
21980       END IF;
21981    END IF;
21982    --
21983    --
21984    ------------------------------------------------------------------------------------------------
21985    -- 4219869 Business Flow
21986    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
21987    -- Prior Entry.  Currently, the following code is always generated.
21988    ------------------------------------------------------------------------------------------------
21989    XLA_AE_LINES_PKG.ValidateCurrentLine;
21990 
21991    ------------------------------------------------------------------------------------
21992    -- 4219869 Business Flow
21993    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
21994    ------------------------------------------------------------------------------------
21995    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
21996 
21997    ----------------------------------------------------------------------------------
21998    -- 4219869 Business Flow
21999    -- Update journal entry status -- Need to generate this within IF <condition>
22000    ----------------------------------------------------------------------------------
22001    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
22002          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
22003          ,p_balance_type_code => l_balance_type_code
22004          );
22005 
22006    -------------------------------------------------------------------------------------------
22007    -- 4262811 - Generate the Accrual Reversal lines
22008    -------------------------------------------------------------------------------------------
22009    BEGIN
22010       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
22011                               (g_array_event(p_event_id).array_value_num('header_index'));
22012       IF l_acc_rev_flag IS NULL THEN
22013          l_acc_rev_flag := 'N';
22014       END IF;
22015    EXCEPTION
22016       WHEN OTHERS THEN
22017          l_acc_rev_flag := 'N';
22018    END;
22019    --
22020    IF (l_acc_rev_flag = 'Y') THEN
22021 
22022        -- 4645092  ------------------------------------------------------------------------------
22023        -- To allow MPA report to determine if it should generate report process
22024        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
22025        ------------------------------------------------------------------------------------------
22026 
22027        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
22028        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
22029    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
22030    -- call ADRs
22031    -- Bug 4922099
22032    --
22033    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
22034         (NVL(l_actual_upg_option, 'N') = 'O') OR
22035         (NVL(l_enc_upg_option, 'N') = 'O')
22036       )
22037    THEN
22038    NULL;
22039    --
22040    --
22041    
22042   l_ccid := AcctDerRule_25(
22043            p_application_id           => p_application_id
22044          , p_ae_header_id             => l_ae_header_id 
22045 , p_source_13 => p_source_13
22046          , x_transaction_coa_id       => l_adr_transaction_coa_id
22047          , x_accounting_coa_id        => l_adr_accounting_coa_id
22048          , x_value_type_code          => l_adr_value_type_code
22049          , p_side                     => 'NA'
22050    );
22051 
22052    xla_ae_lines_pkg.set_ccid(
22053     p_code_combination_id          => l_ccid
22057   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
22054   , p_value_type_code              => l_adr_value_type_code
22055   , p_transaction_coa_id           => l_adr_transaction_coa_id
22056   , p_accounting_coa_id            => l_adr_accounting_coa_id
22058   , p_adr_type_code                => 'S'
22059   , p_component_type               => l_component_type
22060   , p_component_code               => l_component_code
22061   , p_component_type_code          => l_component_type_code
22062   , p_component_appl_id            => l_component_appl_id
22063   , p_amb_context_code             => l_amb_context_code
22064   , p_side                         => 'NA'
22065   );
22066 
22067 
22068    l_segment := AcctDerRule_21(
22069            p_application_id           => p_application_id
22070          , p_ae_header_id             => l_ae_header_id 
22071 , p_source_8 => p_source_8
22072 , p_source_9 => p_source_9
22073 , p_source_10 => p_source_10
22074          , x_transaction_coa_id       => l_adr_transaction_coa_id
22075          , x_accounting_coa_id        => l_adr_accounting_coa_id
22076          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
22077          , x_flex_value_set_id        => l_adr_flex_value_set_id
22078          , x_value_type_code          => l_adr_value_type_code
22079          , x_value_combination_id     => l_adr_value_combination_id
22080          , x_value_segment_code       => l_adr_value_segment_code
22081          , p_side                     => 'NA'
22082          , p_override_seg_flag        => 'Y'
22083    );
22084 
22085    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
22086 
22087       xla_ae_lines_pkg.set_segment(
22088           p_to_segment_code         => 'GL_ACCOUNT'
22089         , p_segment_value           => l_segment
22090         , p_from_segment_code       => l_adr_value_segment_code
22091         , p_from_combination_id     => l_adr_value_combination_id
22092         , p_value_type_code         => l_adr_value_type_code
22093         , p_transaction_coa_id      => l_adr_transaction_coa_id
22094         , p_accounting_coa_id       => l_adr_accounting_coa_id
22095         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
22096         , p_flex_value_set_id       => l_adr_flex_value_set_id
22097         , p_adr_code                => 'FV_AR_497201_MISC_RCT_DR'
22098         , p_adr_type_code           => 'S'
22099         , p_component_type          => l_component_type
22100         , p_component_code          => l_component_code
22101         , p_component_type_code     => l_component_type_code
22102         , p_component_appl_id       => l_component_appl_id
22103         , p_amb_context_code        => l_amb_context_code
22104         , p_entity_code             => 'RECEIPTS'
22105         , p_event_class_code        => 'MISC_RECEIPT'
22106         , p_side                    => 'NA'
22107         );
22108 
22109   END IF;
22110 
22111    l_segment := AcctDerRule_4(
22112            p_application_id           => p_application_id
22113          , p_ae_header_id             => l_ae_header_id 
22114 , p_source_3 => p_source_3
22115          , x_transaction_coa_id       => l_adr_transaction_coa_id
22116          , x_accounting_coa_id        => l_adr_accounting_coa_id
22117          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
22118          , x_flex_value_set_id        => l_adr_flex_value_set_id
22119          , x_value_type_code          => l_adr_value_type_code
22120          , x_value_combination_id     => l_adr_value_combination_id
22121          , x_value_segment_code       => l_adr_value_segment_code
22122          , p_side                     => 'NA'
22123          , p_override_seg_flag        => 'Y'
22124    );
22125 
22126    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
22127 
22128       xla_ae_lines_pkg.set_segment(
22129           p_to_segment_code         => 'GL_BALANCING'
22130         , p_segment_value           => l_segment
22131         , p_from_segment_code       => l_adr_value_segment_code
22132         , p_from_combination_id     => l_adr_value_combination_id
22133         , p_value_type_code         => l_adr_value_type_code
22134         , p_transaction_coa_id      => l_adr_transaction_coa_id
22135         , p_accounting_coa_id       => l_adr_accounting_coa_id
22136         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
22137         , p_flex_value_set_id       => l_adr_flex_value_set_id
22138         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
22139         , p_adr_type_code           => 'S'
22140         , p_component_type          => l_component_type
22141         , p_component_code          => l_component_code
22142         , p_component_type_code     => l_component_type_code
22143         , p_component_appl_id       => l_component_appl_id
22144         , p_amb_context_code        => l_amb_context_code
22145         , p_entity_code             => 'RECEIPTS'
22146         , p_event_class_code        => 'MISC_RECEIPT'
22147         , p_side                    => 'NA'
22148         );
22149 
22150   END IF;
22151 
22152    --
22153    --
22154    END IF;
22155 
22156        --
22157        -- Update the line information that should be overwritten
22158        --
22159        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
22160                                          p_header_num   => 1);
22161        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
22162 
22166           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
22163        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
22164 
22165        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
22167        END IF;
22168 
22169       --
22170       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
22171       --
22172       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
22173           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
22174       ELSE
22175           ---------------------------------------------------------------------------------------------------
22176           -- 4262811a Switch Sign
22177           ---------------------------------------------------------------------------------------------------
22178           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
22179           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
22180                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
22181           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
22182                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
22183           -- 5132302
22184           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
22185                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
22186 
22187       END IF;
22188 
22189       -- 4955764
22190       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
22191       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
22192 
22193 
22194       XLA_AE_LINES_PKG.ValidateCurrentLine;
22195       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
22196 
22197       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
22198                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
22199                ,p_balance_type_code => l_balance_type_code);
22200 
22201    END IF;
22202 
22203    -----------------------------------------------------------------------------------------
22204    -- 4262811 Multiperiod Accounting
22205    -----------------------------------------------------------------------------------------
22206      -- No MPA option is assigned.
22207 
22208 
22209 END IF;
22210 END IF;
22211 --
22212 
22213 --
22214 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
22215    trace
22216       (p_msg      => 'END of AcctLineType_62'
22217       ,p_level    => C_LEVEL_PROCEDURE
22218       ,p_module   => l_log_module);
22219 END IF;
22220 --
22221 EXCEPTION
22222   WHEN xla_exceptions_pkg.application_exception THEN
22223       RAISE;
22224   WHEN OTHERS THEN
22225        xla_exceptions_pkg.raise_message
22226            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_62');
22227 END AcctLineType_62;
22228 --
22229 
22230 ---------------------------------------
22231 --
22232 -- PRIVATE FUNCTION
22233 --         AcctLineType_63
22234 --
22235 ---------------------------------------
22236 PROCEDURE AcctLineType_63 (
22237   p_application_id        IN NUMBER
22238  ,p_event_id              IN NUMBER
22239  ,p_calculate_acctd_flag  IN VARCHAR2
22240  ,p_calculate_g_l_flag    IN VARCHAR2
22241  ,p_actual_flag           IN OUT VARCHAR2
22242  ,p_balance_type_code     OUT VARCHAR2
22243  ,p_gain_or_loss_ref      OUT VARCHAR2
22244  
22245 --Distribution GL Account
22246  , p_source_3            IN NUMBER
22247 --Federal Fund Expired Status
22248  , p_source_8            IN VARCHAR2
22249 --Federal Prior Year Flag
22250  , p_source_9            IN VARCHAR2
22251 --Federal Fund Time Frame
22252  , p_source_10            IN VARCHAR2
22253 --Federal Apportionment Category
22254  , p_source_11            IN VARCHAR2
22255 --Remittance Bank Account Cash Account
22256  , p_source_13            IN NUMBER
22257 --Distribution Source Type
22258  , p_source_20            IN VARCHAR2
22259 --Distribution Line Identifier
22260  , p_source_22            IN NUMBER
22261 --Distribution Type
22262  , p_source_23            IN VARCHAR2
22263 --Entered Amount
22264  , p_source_24            IN NUMBER
22265 --Currency Code
22266  , p_source_25            IN VARCHAR2
22267 --Exchange Rate
22268  , p_source_27            IN NUMBER
22269 --Exchange Rate Type
22270  , p_source_28            IN VARCHAR2
22271 --Applied To Document Accounting Amount
22272  , p_source_29            IN NUMBER
22273 --Federal Account Valid Flag
22274  , p_source_56            IN VARCHAR2
22275 --Applied To Document Exchange Date
22276  , p_source_57            IN DATE
22277 )
22278 IS
22279 
22280 l_component_type              VARCHAR2(80);
22281 l_component_code              VARCHAR2(30);
22282 l_component_type_code         VARCHAR2(1);
22283 l_component_appl_id           INTEGER;
22284 l_amb_context_code            VARCHAR2(30);
22285 l_entity_code                 VARCHAR2(30);
22286 l_event_class_code            VARCHAR2(30);
22287 l_ae_header_id                NUMBER;
22288 l_event_type_code             VARCHAR2(30);
22289 l_line_definition_code        VARCHAR2(30);
22293 l_segment                     VARCHAR2(30);
22290 l_line_definition_owner_code  VARCHAR2(1);
22291 --
22292 -- adr variables
22294 l_ccid                        NUMBER;
22295 l_adr_transaction_coa_id      NUMBER;
22296 l_adr_accounting_coa_id       NUMBER;
22297 l_adr_flexfield_segment_code  VARCHAR2(30);
22298 l_adr_flex_value_set_id       NUMBER;
22299 l_adr_value_type_code         VARCHAR2(30);
22300 l_adr_value_combination_id    NUMBER;
22301 l_adr_value_segment_code      VARCHAR2(30);
22302 
22303 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
22304 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
22305 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
22306 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
22307 
22308 -- 4262811 Variables ------------------------------------------------------------------------------------------
22309 l_entered_amt_idx             NUMBER;
22310 l_accted_amt_idx              NUMBER;
22311 l_acc_rev_flag                VARCHAR2(1);
22312 l_accrual_line_num            NUMBER;
22313 l_tmp_amt                     NUMBER;
22314 l_acc_rev_natural_side_code   VARCHAR2(1);
22315 
22316 l_num_entries                 NUMBER;
22317 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
22318 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
22319 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
22320 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
22321 l_recog_line_1                NUMBER;
22322 l_recog_line_2                NUMBER;
22323 
22324 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
22325 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
22326 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
22327 
22328 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
22329 
22330 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
22331 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
22332 
22333 ---------------------------------------------------------------------------------------------------------------
22334 
22335 
22336 --
22337 -- bulk performance
22338 --
22339 l_balance_type_code           VARCHAR2(1);
22340 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
22341 l_log_module                  VARCHAR2(240);
22342 
22343 --
22344 -- Upgrade strategy
22345 --
22346 l_actual_upg_option           VARCHAR2(1);
22347 l_enc_upg_option           VARCHAR2(1);
22348 
22349 --
22350 BEGIN
22351 --
22352 IF g_log_enabled THEN
22353       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_63';
22354 END IF;
22355 --
22356 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
22357 
22358       trace
22359          (p_msg      => 'BEGIN of AcctLineType_63'
22360          ,p_level    => C_LEVEL_PROCEDURE
22361          ,p_module   => l_log_module);
22362 
22363 END IF;
22364 --
22365 l_component_type             := 'AMB_JLT';
22366 l_component_code             := 'FV_MISC_RCT_REF_OUFC_CR';
22367 l_component_type_code        := 'S';
22368 l_component_appl_id          :=  222;
22369 l_amb_context_code           := 'DEFAULT';
22370 l_entity_code                := 'RECEIPTS';
22371 l_event_class_code           := 'MISC_RECEIPT';
22372 l_event_type_code            := 'MISC_RECEIPT_ALL';
22373 l_line_definition_owner_code := 'S';
22374 l_line_definition_code       := 'MFAR_FED_AR_MISC_REC_BALANCING';
22375 --
22376 l_balance_type_code          := 'A';
22377 l_segment                     := NULL;
22378 l_ccid                        := NULL;
22379 l_adr_transaction_coa_id      := NULL;
22380 l_adr_accounting_coa_id       := NULL;
22381 l_adr_flexfield_segment_code  := NULL;
22382 l_adr_flex_value_set_id       := NULL;
22383 l_adr_value_type_code         := NULL;
22384 l_adr_value_combination_id    := NULL;
22385 l_adr_value_segment_code      := NULL;
22386 
22387 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
22388 l_bflow_class_code           := '';    -- 4219869 Business Flow
22389 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
22390 l_budgetary_control_flag     := 'N';
22391 
22392 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
22393 l_bflow_applied_to_amt       := NULL; -- 5132302
22394 l_entered_amt_idx            := NULL;          -- 4262811
22395 l_accted_amt_idx             := NULL;          -- 4262811
22396 l_acc_rev_flag               := NULL;          -- 4262811
22397 l_accrual_line_num           := NULL;          -- 4262811
22398 l_tmp_amt                    := NULL;          -- 4262811
22399 --
22400  
22401 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
22402     l_balance_type_code <> 'B' THEN
22403 IF NVL(p_source_20,'
22404 ') =  'MISCCASH' AND 
22405 NVL(p_source_8,'
22406 ') =  'Unexpired' AND 
22407 NVL(p_source_9,'
22408 ') =  'N' AND 
22409 (NVL(p_source_11,'
22410 ') =  'A' OR 
22411 NVL(p_source_11,'
22412 ') =  'B' OR 
22413 NVL(p_source_11,'
22414 ') =  'C') AND 
22415 (NVL(p_source_10,'
22416 ') =  'SINGLE' OR 
22417 NVL(p_source_10,'
22418 ') =  'MULTIPLE' OR 
22419 NVL(p_source_10,'
22420 ') =  'NO_YEAR') AND 
22421 NVL(p_source_56,'
22422 ') =  'Y'
22426    XLA_AE_LINES_PKG.SetNewLine;
22423  THEN 
22424 
22425    --
22427 
22428    p_balance_type_code          := l_balance_type_code;
22429    -- set the flag so later we will know whether the gain loss line needs to be created
22430    
22431    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
22432      p_actual_flag :='A';
22433    END IF;
22434 
22435    --
22436    -- bulk performance
22437    --
22438    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
22439                                       p_header_num   => 0); -- 4262811
22440    --
22441    -- set accounting line options
22442    --
22443    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
22444            p_natural_side_code          => 'C'
22445          , p_gain_or_loss_flag          => 'N'
22446          , p_gl_transfer_mode_code      => 'S'
22447          , p_acct_entry_type_code       => 'A'
22448          , p_switch_side_flag           => 'Y'
22449          , p_merge_duplicate_code       => 'A'
22450          );
22451    --
22452    l_acc_rev_natural_side_code := 'D';  -- 4262811
22453    -- 
22454    --
22455    -- set accounting line type info
22456    --
22457    xla_ae_lines_pkg.SetAcctLineType
22458       (p_component_type             => l_component_type
22459       ,p_event_type_code            => l_event_type_code
22460       ,p_line_definition_owner_code => l_line_definition_owner_code
22461       ,p_line_definition_code       => l_line_definition_code
22462       ,p_accounting_line_code       => l_component_code
22463       ,p_accounting_line_type_code  => l_component_type_code
22464       ,p_accounting_line_appl_id    => l_component_appl_id
22465       ,p_amb_context_code           => l_amb_context_code
22466       ,p_entity_code                => l_entity_code
22467       ,p_event_class_code           => l_event_class_code);
22468    --
22469    -- set accounting class
22470    --
22471    xla_ae_lines_pkg.SetAcctClass(
22472            p_accounting_class_code  => 'FV_MISCCASH_CR'
22473          , p_ae_header_id           => l_ae_header_id
22474          );
22475 
22476    --
22477    -- set rounding class
22478    --
22479    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
22480                       'RECEIVABLE';
22481 
22482    --
22483    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
22484    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
22485    --
22486    -- bulk performance
22487    --
22488    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
22489 
22490    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
22491       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
22492 
22493    -- 4955764
22494    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
22495       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
22496 
22497    -- 4458381 Public Sector Enh
22498    
22499    --
22500    -- set accounting attributes for the line type
22501    --
22502    l_entered_amt_idx := 3;
22503    l_accted_amt_idx  := 8;
22504    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
22505    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
22506    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
22507    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
22508    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
22509    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
22510    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
22511    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
22512    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
22513    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
22514    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
22515    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
22516    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
22517    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
22518    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
22519    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
22520    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
22521 
22522    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
22523    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
22524 
22525    ---------------------------------------------------------------------------------------------------------------
22526    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
22527    ---------------------------------------------------------------------------------------------------------------
22528    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
22529 
22530    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
22531    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
22532 
22533    IF xla_accounting_cache_pkg.GetValueChar
22534          (p_source_code         => 'LEDGER_CATEGORY_CODE'
22538    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
22535          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
22536    AND l_bflow_method_code = 'PRIOR_ENTRY'
22537 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
22539          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
22540        )
22541    THEN
22542          xla_ae_lines_pkg.BflowUpgEntry
22543            (p_business_method_code    => l_bflow_method_code
22544            ,p_business_class_code     => l_bflow_class_code
22545            ,p_balance_type            => l_balance_type_code);
22546    ELSE
22547       NULL;
22548 -- No business flow processing for business flow method of NONE.
22549    END IF;
22550 
22551    --
22552    -- call analytical criteria
22553    --
22554    
22555    --
22556    -- call description
22557    --
22558    -- No description or it is inherited.
22559    --
22560    -- call ADRs
22561    -- Bug 4922099
22562    --
22563    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
22564         (NVL(l_actual_upg_option, 'N') = 'O') OR
22565         (NVL(l_enc_upg_option, 'N') = 'O')
22566       )
22567    THEN
22568    NULL;
22569    --
22570    --
22571    
22572   l_ccid := AcctDerRule_25(
22573            p_application_id           => p_application_id
22574          , p_ae_header_id             => l_ae_header_id 
22575 , p_source_13 => p_source_13
22576          , x_transaction_coa_id       => l_adr_transaction_coa_id
22577          , x_accounting_coa_id        => l_adr_accounting_coa_id
22578          , x_value_type_code          => l_adr_value_type_code
22579          , p_side                     => 'NA'
22580    );
22581 
22582    xla_ae_lines_pkg.set_ccid(
22583     p_code_combination_id          => l_ccid
22584   , p_value_type_code              => l_adr_value_type_code
22585   , p_transaction_coa_id           => l_adr_transaction_coa_id
22586   , p_accounting_coa_id            => l_adr_accounting_coa_id
22587   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
22588   , p_adr_type_code                => 'S'
22589   , p_component_type               => l_component_type
22590   , p_component_code               => l_component_code
22591   , p_component_type_code          => l_component_type_code
22592   , p_component_appl_id            => l_component_appl_id
22593   , p_amb_context_code             => l_amb_context_code
22594   , p_side                         => 'NA'
22595   );
22596 
22597 
22598    l_segment := AcctDerRule_18(
22599            p_application_id           => p_application_id
22600          , p_ae_header_id             => l_ae_header_id 
22601 , p_source_8 => p_source_8
22602 , p_source_9 => p_source_9
22603 , p_source_10 => p_source_10
22604 , p_source_11 => p_source_11
22605          , x_transaction_coa_id       => l_adr_transaction_coa_id
22606          , x_accounting_coa_id        => l_adr_accounting_coa_id
22607          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
22608          , x_flex_value_set_id        => l_adr_flex_value_set_id
22609          , x_value_type_code          => l_adr_value_type_code
22610          , x_value_combination_id     => l_adr_value_combination_id
22611          , x_value_segment_code       => l_adr_value_segment_code
22612          , p_side                     => 'NA'
22613          , p_override_seg_flag        => 'Y'
22614    );
22615 
22616    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
22617 
22618       xla_ae_lines_pkg.set_segment(
22619           p_to_segment_code         => 'GL_ACCOUNT'
22620         , p_segment_value           => l_segment
22621         , p_from_segment_code       => l_adr_value_segment_code
22622         , p_from_combination_id     => l_adr_value_combination_id
22623         , p_value_type_code         => l_adr_value_type_code
22624         , p_transaction_coa_id      => l_adr_transaction_coa_id
22625         , p_accounting_coa_id       => l_adr_accounting_coa_id
22626         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
22627         , p_flex_value_set_id       => l_adr_flex_value_set_id
22628         , p_adr_code                => 'FV_AR_46X002_MISC_RCT_CR'
22629         , p_adr_type_code           => 'S'
22630         , p_component_type          => l_component_type
22631         , p_component_code          => l_component_code
22632         , p_component_type_code     => l_component_type_code
22633         , p_component_appl_id       => l_component_appl_id
22634         , p_amb_context_code        => l_amb_context_code
22635         , p_entity_code             => 'RECEIPTS'
22636         , p_event_class_code        => 'MISC_RECEIPT'
22637         , p_side                    => 'NA'
22638         );
22639 
22640   END IF;
22641 
22642    l_segment := AcctDerRule_4(
22643            p_application_id           => p_application_id
22644          , p_ae_header_id             => l_ae_header_id 
22645 , p_source_3 => p_source_3
22646          , x_transaction_coa_id       => l_adr_transaction_coa_id
22647          , x_accounting_coa_id        => l_adr_accounting_coa_id
22648          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
22649          , x_flex_value_set_id        => l_adr_flex_value_set_id
22650          , x_value_type_code          => l_adr_value_type_code
22651          , x_value_combination_id     => l_adr_value_combination_id
22655    );
22652          , x_value_segment_code       => l_adr_value_segment_code
22653          , p_side                     => 'NA'
22654          , p_override_seg_flag        => 'Y'
22656 
22657    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
22658 
22659       xla_ae_lines_pkg.set_segment(
22660           p_to_segment_code         => 'GL_BALANCING'
22661         , p_segment_value           => l_segment
22662         , p_from_segment_code       => l_adr_value_segment_code
22663         , p_from_combination_id     => l_adr_value_combination_id
22664         , p_value_type_code         => l_adr_value_type_code
22665         , p_transaction_coa_id      => l_adr_transaction_coa_id
22666         , p_accounting_coa_id       => l_adr_accounting_coa_id
22667         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
22668         , p_flex_value_set_id       => l_adr_flex_value_set_id
22669         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
22670         , p_adr_type_code           => 'S'
22671         , p_component_type          => l_component_type
22672         , p_component_code          => l_component_code
22673         , p_component_type_code     => l_component_type_code
22674         , p_component_appl_id       => l_component_appl_id
22675         , p_amb_context_code        => l_amb_context_code
22676         , p_entity_code             => 'RECEIPTS'
22677         , p_event_class_code        => 'MISC_RECEIPT'
22678         , p_side                    => 'NA'
22679         );
22680 
22681   END IF;
22682 
22683    --
22684    --
22685    END IF;
22686    --
22687    -- Bug 4922099
22688    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
22689           (NVL(l_enc_upg_option, 'N') = 'O')
22690         ) AND
22691         (l_bflow_method_code = 'PRIOR_ENTRY')
22692       )
22693    THEN
22694       IF
22695       --
22696       1 = 2
22697       --
22698       THEN
22699       xla_accounting_err_pkg.build_message
22700                                     (p_appli_s_name            => 'XLA'
22701                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
22702                                     ,p_token_1                 => 'LINE_NUMBER'
22703                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
22704                                     ,p_token_2                 => 'LINE_TYPE_NAME'
22705                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
22706                                                                              l_component_type
22707                                                                             ,l_component_code
22708                                                                             ,l_component_type_code
22709                                                                             ,l_component_appl_id
22710                                                                             ,l_amb_context_code
22711                                                                             ,l_entity_code
22712                                                                             ,l_event_class_code
22713                                                                            )
22714                                     ,p_token_3                 => 'OWNER'
22715                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
22716                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
22717                                                                           ,p_lookup_code    => l_component_type_code
22718                                                                          )
22719                                     ,p_token_4                 => 'PRODUCT_NAME'
22720                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
22721                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
22722                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
22723                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
22724                                     ,p_ae_header_id            =>  NULL
22725                                        );
22726 
22727         IF (C_LEVEL_ERROR>= g_log_level) THEN
22728                  trace
22729                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
22730                       ,p_level    => C_LEVEL_ERROR
22731                       ,p_module   => l_log_module);
22732         END IF;
22733       END IF;
22734    END IF;
22735    --
22736    --
22737    ------------------------------------------------------------------------------------------------
22738    -- 4219869 Business Flow
22739    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
22740    -- Prior Entry.  Currently, the following code is always generated.
22741    ------------------------------------------------------------------------------------------------
22742    XLA_AE_LINES_PKG.ValidateCurrentLine;
22743 
22744    ------------------------------------------------------------------------------------
22745    -- 4219869 Business Flow
22746    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
22747    ------------------------------------------------------------------------------------
22748    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
22749 
22753    ----------------------------------------------------------------------------------
22750    ----------------------------------------------------------------------------------
22751    -- 4219869 Business Flow
22752    -- Update journal entry status -- Need to generate this within IF <condition>
22754    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
22755          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
22756          ,p_balance_type_code => l_balance_type_code
22757          );
22758 
22759    -------------------------------------------------------------------------------------------
22760    -- 4262811 - Generate the Accrual Reversal lines
22761    -------------------------------------------------------------------------------------------
22762    BEGIN
22763       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
22764                               (g_array_event(p_event_id).array_value_num('header_index'));
22765       IF l_acc_rev_flag IS NULL THEN
22766          l_acc_rev_flag := 'N';
22767       END IF;
22768    EXCEPTION
22769       WHEN OTHERS THEN
22770          l_acc_rev_flag := 'N';
22771    END;
22772    --
22773    IF (l_acc_rev_flag = 'Y') THEN
22774 
22775        -- 4645092  ------------------------------------------------------------------------------
22776        -- To allow MPA report to determine if it should generate report process
22777        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
22778        ------------------------------------------------------------------------------------------
22779 
22780        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
22781        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
22782    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
22783    -- call ADRs
22784    -- Bug 4922099
22785    --
22786    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
22787         (NVL(l_actual_upg_option, 'N') = 'O') OR
22788         (NVL(l_enc_upg_option, 'N') = 'O')
22789       )
22790    THEN
22791    NULL;
22792    --
22793    --
22794    
22795   l_ccid := AcctDerRule_25(
22796            p_application_id           => p_application_id
22797          , p_ae_header_id             => l_ae_header_id 
22798 , p_source_13 => p_source_13
22799          , x_transaction_coa_id       => l_adr_transaction_coa_id
22800          , x_accounting_coa_id        => l_adr_accounting_coa_id
22801          , x_value_type_code          => l_adr_value_type_code
22802          , p_side                     => 'NA'
22803    );
22804 
22805    xla_ae_lines_pkg.set_ccid(
22806     p_code_combination_id          => l_ccid
22807   , p_value_type_code              => l_adr_value_type_code
22808   , p_transaction_coa_id           => l_adr_transaction_coa_id
22809   , p_accounting_coa_id            => l_adr_accounting_coa_id
22810   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
22811   , p_adr_type_code                => 'S'
22812   , p_component_type               => l_component_type
22813   , p_component_code               => l_component_code
22814   , p_component_type_code          => l_component_type_code
22815   , p_component_appl_id            => l_component_appl_id
22816   , p_amb_context_code             => l_amb_context_code
22817   , p_side                         => 'NA'
22818   );
22819 
22820 
22821    l_segment := AcctDerRule_18(
22822            p_application_id           => p_application_id
22823          , p_ae_header_id             => l_ae_header_id 
22824 , p_source_8 => p_source_8
22825 , p_source_9 => p_source_9
22826 , p_source_10 => p_source_10
22827 , p_source_11 => p_source_11
22828          , x_transaction_coa_id       => l_adr_transaction_coa_id
22829          , x_accounting_coa_id        => l_adr_accounting_coa_id
22830          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
22831          , x_flex_value_set_id        => l_adr_flex_value_set_id
22832          , x_value_type_code          => l_adr_value_type_code
22833          , x_value_combination_id     => l_adr_value_combination_id
22834          , x_value_segment_code       => l_adr_value_segment_code
22835          , p_side                     => 'NA'
22836          , p_override_seg_flag        => 'Y'
22837    );
22838 
22839    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
22840 
22841       xla_ae_lines_pkg.set_segment(
22842           p_to_segment_code         => 'GL_ACCOUNT'
22843         , p_segment_value           => l_segment
22844         , p_from_segment_code       => l_adr_value_segment_code
22845         , p_from_combination_id     => l_adr_value_combination_id
22846         , p_value_type_code         => l_adr_value_type_code
22847         , p_transaction_coa_id      => l_adr_transaction_coa_id
22848         , p_accounting_coa_id       => l_adr_accounting_coa_id
22849         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
22850         , p_flex_value_set_id       => l_adr_flex_value_set_id
22851         , p_adr_code                => 'FV_AR_46X002_MISC_RCT_CR'
22852         , p_adr_type_code           => 'S'
22853         , p_component_type          => l_component_type
22854         , p_component_code          => l_component_code
22855         , p_component_type_code     => l_component_type_code
22856         , p_component_appl_id       => l_component_appl_id
22857         , p_amb_context_code        => l_amb_context_code
22858         , p_entity_code             => 'RECEIPTS'
22859         , p_event_class_code        => 'MISC_RECEIPT'
22860         , p_side                    => 'NA'
22861         );
22862 
22866            p_application_id           => p_application_id
22863   END IF;
22864 
22865    l_segment := AcctDerRule_4(
22867          , p_ae_header_id             => l_ae_header_id 
22868 , p_source_3 => p_source_3
22869          , x_transaction_coa_id       => l_adr_transaction_coa_id
22870          , x_accounting_coa_id        => l_adr_accounting_coa_id
22871          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
22872          , x_flex_value_set_id        => l_adr_flex_value_set_id
22873          , x_value_type_code          => l_adr_value_type_code
22874          , x_value_combination_id     => l_adr_value_combination_id
22875          , x_value_segment_code       => l_adr_value_segment_code
22876          , p_side                     => 'NA'
22877          , p_override_seg_flag        => 'Y'
22878    );
22879 
22880    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
22881 
22882       xla_ae_lines_pkg.set_segment(
22883           p_to_segment_code         => 'GL_BALANCING'
22884         , p_segment_value           => l_segment
22885         , p_from_segment_code       => l_adr_value_segment_code
22886         , p_from_combination_id     => l_adr_value_combination_id
22887         , p_value_type_code         => l_adr_value_type_code
22888         , p_transaction_coa_id      => l_adr_transaction_coa_id
22889         , p_accounting_coa_id       => l_adr_accounting_coa_id
22890         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
22891         , p_flex_value_set_id       => l_adr_flex_value_set_id
22892         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
22893         , p_adr_type_code           => 'S'
22894         , p_component_type          => l_component_type
22895         , p_component_code          => l_component_code
22896         , p_component_type_code     => l_component_type_code
22897         , p_component_appl_id       => l_component_appl_id
22898         , p_amb_context_code        => l_amb_context_code
22899         , p_entity_code             => 'RECEIPTS'
22900         , p_event_class_code        => 'MISC_RECEIPT'
22901         , p_side                    => 'NA'
22902         );
22903 
22904   END IF;
22905 
22906    --
22907    --
22908    END IF;
22909 
22910        --
22911        -- Update the line information that should be overwritten
22912        --
22913        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
22914                                          p_header_num   => 1);
22915        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
22916 
22917        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
22918 
22919        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
22920           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
22921        END IF;
22922 
22923       --
22924       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
22925       --
22926       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
22927           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
22928       ELSE
22929           ---------------------------------------------------------------------------------------------------
22930           -- 4262811a Switch Sign
22931           ---------------------------------------------------------------------------------------------------
22932           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
22933           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
22934                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
22935           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
22936                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
22937           -- 5132302
22938           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
22939                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
22940 
22941       END IF;
22942 
22943       -- 4955764
22944       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
22945       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
22946 
22947 
22948       XLA_AE_LINES_PKG.ValidateCurrentLine;
22949       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
22950 
22951       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
22952                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
22953                ,p_balance_type_code => l_balance_type_code);
22954 
22955    END IF;
22956 
22957    -----------------------------------------------------------------------------------------
22958    -- 4262811 Multiperiod Accounting
22959    -----------------------------------------------------------------------------------------
22960      -- No MPA option is assigned.
22961 
22962 
22963 END IF;
22964 END IF;
22965 --
22966 
22967 --
22968 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
22969    trace
22970       (p_msg      => 'END of AcctLineType_63'
22971       ,p_level    => C_LEVEL_PROCEDURE
22972       ,p_module   => l_log_module);
22973 END IF;
22974 --
22978   WHEN OTHERS THEN
22975 EXCEPTION
22976   WHEN xla_exceptions_pkg.application_exception THEN
22977       RAISE;
22979        xla_exceptions_pkg.raise_message
22980            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_63');
22981 END AcctLineType_63;
22982 --
22983 
22984 ---------------------------------------
22985 --
22986 -- PRIVATE FUNCTION
22987 --         AcctLineType_64
22988 --
22989 ---------------------------------------
22990 PROCEDURE AcctLineType_64 (
22991   p_application_id        IN NUMBER
22992  ,p_event_id              IN NUMBER
22993  ,p_calculate_acctd_flag  IN VARCHAR2
22994  ,p_calculate_g_l_flag    IN VARCHAR2
22995  ,p_actual_flag           IN OUT VARCHAR2
22996  ,p_balance_type_code     OUT VARCHAR2
22997  ,p_gain_or_loss_ref      OUT VARCHAR2
22998  
22999 --Distribution GL Account
23000  , p_source_3            IN NUMBER
23001 --Federal Fund Expired Status
23002  , p_source_8            IN VARCHAR2
23003 --Federal Prior Year Flag
23004  , p_source_9            IN VARCHAR2
23005 --Federal Fund Time Frame
23006  , p_source_10            IN VARCHAR2
23007 --Federal Apportionment Category
23008  , p_source_11            IN VARCHAR2
23009 --Remittance Bank Account Cash Account
23010  , p_source_13            IN NUMBER
23011 --Distribution Source Type
23012  , p_source_20            IN VARCHAR2
23013 --Distribution Line Identifier
23014  , p_source_22            IN NUMBER
23015 --Distribution Type
23016  , p_source_23            IN VARCHAR2
23017 --Entered Amount
23018  , p_source_24            IN NUMBER
23019 --Currency Code
23020  , p_source_25            IN VARCHAR2
23021 --Exchange Rate
23022  , p_source_27            IN NUMBER
23023 --Exchange Rate Type
23024  , p_source_28            IN VARCHAR2
23025 --Applied To Document Accounting Amount
23026  , p_source_29            IN NUMBER
23027 --Federal Account Valid Flag
23028  , p_source_56            IN VARCHAR2
23029 --Applied To Document Exchange Date
23030  , p_source_57            IN DATE
23031 )
23032 IS
23033 
23034 l_component_type              VARCHAR2(80);
23035 l_component_code              VARCHAR2(30);
23036 l_component_type_code         VARCHAR2(1);
23037 l_component_appl_id           INTEGER;
23038 l_amb_context_code            VARCHAR2(30);
23039 l_entity_code                 VARCHAR2(30);
23040 l_event_class_code            VARCHAR2(30);
23041 l_ae_header_id                NUMBER;
23042 l_event_type_code             VARCHAR2(30);
23043 l_line_definition_code        VARCHAR2(30);
23044 l_line_definition_owner_code  VARCHAR2(1);
23045 --
23046 -- adr variables
23047 l_segment                     VARCHAR2(30);
23048 l_ccid                        NUMBER;
23049 l_adr_transaction_coa_id      NUMBER;
23050 l_adr_accounting_coa_id       NUMBER;
23051 l_adr_flexfield_segment_code  VARCHAR2(30);
23052 l_adr_flex_value_set_id       NUMBER;
23053 l_adr_value_type_code         VARCHAR2(30);
23054 l_adr_value_combination_id    NUMBER;
23055 l_adr_value_segment_code      VARCHAR2(30);
23056 
23057 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
23058 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
23059 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
23060 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
23061 
23062 -- 4262811 Variables ------------------------------------------------------------------------------------------
23063 l_entered_amt_idx             NUMBER;
23064 l_accted_amt_idx              NUMBER;
23065 l_acc_rev_flag                VARCHAR2(1);
23066 l_accrual_line_num            NUMBER;
23067 l_tmp_amt                     NUMBER;
23068 l_acc_rev_natural_side_code   VARCHAR2(1);
23069 
23070 l_num_entries                 NUMBER;
23071 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
23072 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
23073 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
23074 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
23075 l_recog_line_1                NUMBER;
23076 l_recog_line_2                NUMBER;
23077 
23078 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
23079 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
23080 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
23081 
23082 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
23083 
23084 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
23085 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
23086 
23087 ---------------------------------------------------------------------------------------------------------------
23088 
23089 
23090 --
23091 -- bulk performance
23092 --
23093 l_balance_type_code           VARCHAR2(1);
23094 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
23095 l_log_module                  VARCHAR2(240);
23096 
23097 --
23098 -- Upgrade strategy
23099 --
23100 l_actual_upg_option           VARCHAR2(1);
23101 l_enc_upg_option           VARCHAR2(1);
23102 
23103 --
23104 BEGIN
23105 --
23106 IF g_log_enabled THEN
23107       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_64';
23108 END IF;
23109 --
23113          (p_msg      => 'BEGIN of AcctLineType_64'
23110 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
23111 
23112       trace
23114          ,p_level    => C_LEVEL_PROCEDURE
23115          ,p_module   => l_log_module);
23116 
23117 END IF;
23118 --
23119 l_component_type             := 'AMB_JLT';
23120 l_component_code             := 'FV_MISC_RCT_REF_OUFC_DR';
23121 l_component_type_code        := 'S';
23122 l_component_appl_id          :=  222;
23123 l_amb_context_code           := 'DEFAULT';
23124 l_entity_code                := 'RECEIPTS';
23125 l_event_class_code           := 'MISC_RECEIPT';
23126 l_event_type_code            := 'MISC_RECEIPT_ALL';
23127 l_line_definition_owner_code := 'S';
23128 l_line_definition_code       := 'MFAR_FED_AR_MISC_REC_BALANCING';
23129 --
23130 l_balance_type_code          := 'A';
23131 l_segment                     := NULL;
23132 l_ccid                        := NULL;
23133 l_adr_transaction_coa_id      := NULL;
23134 l_adr_accounting_coa_id       := NULL;
23135 l_adr_flexfield_segment_code  := NULL;
23136 l_adr_flex_value_set_id       := NULL;
23137 l_adr_value_type_code         := NULL;
23138 l_adr_value_combination_id    := NULL;
23139 l_adr_value_segment_code      := NULL;
23140 
23141 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
23142 l_bflow_class_code           := '';    -- 4219869 Business Flow
23143 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
23144 l_budgetary_control_flag     := 'N';
23145 
23146 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
23147 l_bflow_applied_to_amt       := NULL; -- 5132302
23148 l_entered_amt_idx            := NULL;          -- 4262811
23149 l_accted_amt_idx             := NULL;          -- 4262811
23150 l_acc_rev_flag               := NULL;          -- 4262811
23151 l_accrual_line_num           := NULL;          -- 4262811
23152 l_tmp_amt                    := NULL;          -- 4262811
23153 --
23154  
23155 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
23156     l_balance_type_code <> 'B' THEN
23157 IF NVL(p_source_20,'
23158 ') =  'MISCCASH' AND 
23159 NVL(p_source_8,'
23160 ') =  'Unexpired' AND 
23161 NVL(p_source_9,'
23162 ') =  'N' AND 
23163 (NVL(p_source_11,'
23164 ') =  'A' OR 
23165 NVL(p_source_11,'
23166 ') =  'B' OR 
23167 NVL(p_source_11,'
23168 ') =  'C') AND 
23169 (NVL(p_source_10,'
23170 ') =  'SINGLE' OR 
23171 NVL(p_source_10,'
23172 ') =  'MULTIPLE' OR 
23173 NVL(p_source_10,'
23174 ') =  'NO_YEAR') AND 
23175 NVL(p_source_56,'
23176 ') =  'Y'
23177  THEN 
23178 
23179    --
23180    XLA_AE_LINES_PKG.SetNewLine;
23181 
23182    p_balance_type_code          := l_balance_type_code;
23183    -- set the flag so later we will know whether the gain loss line needs to be created
23184    
23185    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
23186      p_actual_flag :='A';
23187    END IF;
23188 
23189    --
23190    -- bulk performance
23191    --
23192    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
23193                                       p_header_num   => 0); -- 4262811
23194    --
23195    -- set accounting line options
23196    --
23197    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
23198            p_natural_side_code          => 'D'
23199          , p_gain_or_loss_flag          => 'N'
23200          , p_gl_transfer_mode_code      => 'S'
23201          , p_acct_entry_type_code       => 'A'
23202          , p_switch_side_flag           => 'Y'
23203          , p_merge_duplicate_code       => 'A'
23204          );
23205    --
23206    l_acc_rev_natural_side_code := 'C';  -- 4262811
23207    -- 
23208    --
23209    -- set accounting line type info
23210    --
23211    xla_ae_lines_pkg.SetAcctLineType
23212       (p_component_type             => l_component_type
23213       ,p_event_type_code            => l_event_type_code
23214       ,p_line_definition_owner_code => l_line_definition_owner_code
23215       ,p_line_definition_code       => l_line_definition_code
23216       ,p_accounting_line_code       => l_component_code
23217       ,p_accounting_line_type_code  => l_component_type_code
23218       ,p_accounting_line_appl_id    => l_component_appl_id
23219       ,p_amb_context_code           => l_amb_context_code
23220       ,p_entity_code                => l_entity_code
23221       ,p_event_class_code           => l_event_class_code);
23222    --
23223    -- set accounting class
23224    --
23225    xla_ae_lines_pkg.SetAcctClass(
23226            p_accounting_class_code  => 'FV_MISCCASH_DR'
23227          , p_ae_header_id           => l_ae_header_id
23228          );
23229 
23230    --
23231    -- set rounding class
23232    --
23233    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
23234                       'RECEIVABLE';
23235 
23236    --
23237    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
23238    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
23239    --
23240    -- bulk performance
23241    --
23242    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
23243 
23247    -- 4955764
23244    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
23245       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
23246 
23248    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
23249       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
23250 
23251    -- 4458381 Public Sector Enh
23252    
23253    --
23254    -- set accounting attributes for the line type
23255    --
23256    l_entered_amt_idx := 3;
23257    l_accted_amt_idx  := 8;
23258    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
23259    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
23260    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
23261    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
23262    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
23263    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
23264    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
23265    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
23266    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
23267    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
23268    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
23269    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
23270    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
23271    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
23272    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
23273    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
23274    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
23275 
23276    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
23277    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
23278 
23279    ---------------------------------------------------------------------------------------------------------------
23280    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
23281    ---------------------------------------------------------------------------------------------------------------
23282    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
23283 
23284    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
23285    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
23286 
23287    IF xla_accounting_cache_pkg.GetValueChar
23288          (p_source_code         => 'LEDGER_CATEGORY_CODE'
23289          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
23290    AND l_bflow_method_code = 'PRIOR_ENTRY'
23291 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
23292    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
23293          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
23294        )
23295    THEN
23296          xla_ae_lines_pkg.BflowUpgEntry
23297            (p_business_method_code    => l_bflow_method_code
23298            ,p_business_class_code     => l_bflow_class_code
23299            ,p_balance_type            => l_balance_type_code);
23300    ELSE
23301       NULL;
23302 -- No business flow processing for business flow method of NONE.
23303    END IF;
23304 
23305    --
23306    -- call analytical criteria
23307    --
23308    
23309    --
23310    -- call description
23311    --
23312    -- No description or it is inherited.
23313    --
23314    -- call ADRs
23315    -- Bug 4922099
23316    --
23317    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
23318         (NVL(l_actual_upg_option, 'N') = 'O') OR
23319         (NVL(l_enc_upg_option, 'N') = 'O')
23320       )
23321    THEN
23322    NULL;
23323    --
23324    --
23325    
23326   l_ccid := AcctDerRule_25(
23327            p_application_id           => p_application_id
23328          , p_ae_header_id             => l_ae_header_id 
23329 , p_source_13 => p_source_13
23330          , x_transaction_coa_id       => l_adr_transaction_coa_id
23331          , x_accounting_coa_id        => l_adr_accounting_coa_id
23332          , x_value_type_code          => l_adr_value_type_code
23333          , p_side                     => 'NA'
23334    );
23335 
23336    xla_ae_lines_pkg.set_ccid(
23337     p_code_combination_id          => l_ccid
23338   , p_value_type_code              => l_adr_value_type_code
23339   , p_transaction_coa_id           => l_adr_transaction_coa_id
23340   , p_accounting_coa_id            => l_adr_accounting_coa_id
23341   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
23342   , p_adr_type_code                => 'S'
23343   , p_component_type               => l_component_type
23344   , p_component_code               => l_component_code
23345   , p_component_type_code          => l_component_type_code
23346   , p_component_appl_id            => l_component_appl_id
23347   , p_amb_context_code             => l_amb_context_code
23348   , p_side                         => 'NA'
23349   );
23350 
23351 
23352    l_segment := AcctDerRule_20(
23353            p_application_id           => p_application_id
23354          , p_ae_header_id             => l_ae_header_id 
23355 , p_source_8 => p_source_8
23356 , p_source_9 => p_source_9
23357 , p_source_10 => p_source_10
23358 , p_source_11 => p_source_11
23362          , x_flex_value_set_id        => l_adr_flex_value_set_id
23359          , x_transaction_coa_id       => l_adr_transaction_coa_id
23360          , x_accounting_coa_id        => l_adr_accounting_coa_id
23361          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
23363          , x_value_type_code          => l_adr_value_type_code
23364          , x_value_combination_id     => l_adr_value_combination_id
23365          , x_value_segment_code       => l_adr_value_segment_code
23366          , p_side                     => 'NA'
23367          , p_override_seg_flag        => 'Y'
23368    );
23369 
23370    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
23371 
23372       xla_ae_lines_pkg.set_segment(
23373           p_to_segment_code         => 'GL_ACCOUNT'
23374         , p_segment_value           => l_segment
23375         , p_from_segment_code       => l_adr_value_segment_code
23376         , p_from_combination_id     => l_adr_value_combination_id
23377         , p_value_type_code         => l_adr_value_type_code
23378         , p_transaction_coa_id      => l_adr_transaction_coa_id
23379         , p_accounting_coa_id       => l_adr_accounting_coa_id
23380         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
23381         , p_flex_value_set_id       => l_adr_flex_value_set_id
23382         , p_adr_code                => 'FV_AR_490201_MISC_RCT_DR'
23383         , p_adr_type_code           => 'S'
23384         , p_component_type          => l_component_type
23385         , p_component_code          => l_component_code
23386         , p_component_type_code     => l_component_type_code
23387         , p_component_appl_id       => l_component_appl_id
23388         , p_amb_context_code        => l_amb_context_code
23389         , p_entity_code             => 'RECEIPTS'
23390         , p_event_class_code        => 'MISC_RECEIPT'
23391         , p_side                    => 'NA'
23392         );
23393 
23394   END IF;
23395 
23396    l_segment := AcctDerRule_4(
23397            p_application_id           => p_application_id
23398          , p_ae_header_id             => l_ae_header_id 
23399 , p_source_3 => p_source_3
23400          , x_transaction_coa_id       => l_adr_transaction_coa_id
23401          , x_accounting_coa_id        => l_adr_accounting_coa_id
23402          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
23403          , x_flex_value_set_id        => l_adr_flex_value_set_id
23404          , x_value_type_code          => l_adr_value_type_code
23405          , x_value_combination_id     => l_adr_value_combination_id
23406          , x_value_segment_code       => l_adr_value_segment_code
23407          , p_side                     => 'NA'
23408          , p_override_seg_flag        => 'Y'
23409    );
23410 
23411    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
23412 
23413       xla_ae_lines_pkg.set_segment(
23414           p_to_segment_code         => 'GL_BALANCING'
23415         , p_segment_value           => l_segment
23416         , p_from_segment_code       => l_adr_value_segment_code
23417         , p_from_combination_id     => l_adr_value_combination_id
23418         , p_value_type_code         => l_adr_value_type_code
23419         , p_transaction_coa_id      => l_adr_transaction_coa_id
23420         , p_accounting_coa_id       => l_adr_accounting_coa_id
23421         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
23422         , p_flex_value_set_id       => l_adr_flex_value_set_id
23423         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
23424         , p_adr_type_code           => 'S'
23425         , p_component_type          => l_component_type
23426         , p_component_code          => l_component_code
23427         , p_component_type_code     => l_component_type_code
23428         , p_component_appl_id       => l_component_appl_id
23429         , p_amb_context_code        => l_amb_context_code
23430         , p_entity_code             => 'RECEIPTS'
23431         , p_event_class_code        => 'MISC_RECEIPT'
23432         , p_side                    => 'NA'
23433         );
23434 
23435   END IF;
23436 
23437    --
23438    --
23439    END IF;
23440    --
23441    -- Bug 4922099
23442    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
23443           (NVL(l_enc_upg_option, 'N') = 'O')
23444         ) AND
23445         (l_bflow_method_code = 'PRIOR_ENTRY')
23446       )
23447    THEN
23448       IF
23449       --
23450       1 = 2
23451       --
23452       THEN
23453       xla_accounting_err_pkg.build_message
23454                                     (p_appli_s_name            => 'XLA'
23455                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
23456                                     ,p_token_1                 => 'LINE_NUMBER'
23457                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
23458                                     ,p_token_2                 => 'LINE_TYPE_NAME'
23459                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
23460                                                                              l_component_type
23461                                                                             ,l_component_code
23462                                                                             ,l_component_type_code
23463                                                                             ,l_component_appl_id
23464                                                                             ,l_amb_context_code
23468                                     ,p_token_3                 => 'OWNER'
23465                                                                             ,l_entity_code
23466                                                                             ,l_event_class_code
23467                                                                            )
23469                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
23470                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
23471                                                                           ,p_lookup_code    => l_component_type_code
23472                                                                          )
23473                                     ,p_token_4                 => 'PRODUCT_NAME'
23474                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
23475                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
23476                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
23477                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
23478                                     ,p_ae_header_id            =>  NULL
23479                                        );
23480 
23481         IF (C_LEVEL_ERROR>= g_log_level) THEN
23482                  trace
23483                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
23484                       ,p_level    => C_LEVEL_ERROR
23485                       ,p_module   => l_log_module);
23486         END IF;
23487       END IF;
23488    END IF;
23489    --
23490    --
23491    ------------------------------------------------------------------------------------------------
23492    -- 4219869 Business Flow
23493    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
23494    -- Prior Entry.  Currently, the following code is always generated.
23495    ------------------------------------------------------------------------------------------------
23496    XLA_AE_LINES_PKG.ValidateCurrentLine;
23497 
23498    ------------------------------------------------------------------------------------
23499    -- 4219869 Business Flow
23500    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
23501    ------------------------------------------------------------------------------------
23502    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
23503 
23504    ----------------------------------------------------------------------------------
23505    -- 4219869 Business Flow
23506    -- Update journal entry status -- Need to generate this within IF <condition>
23507    ----------------------------------------------------------------------------------
23508    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
23509          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
23510          ,p_balance_type_code => l_balance_type_code
23511          );
23512 
23513    -------------------------------------------------------------------------------------------
23514    -- 4262811 - Generate the Accrual Reversal lines
23515    -------------------------------------------------------------------------------------------
23516    BEGIN
23517       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
23518                               (g_array_event(p_event_id).array_value_num('header_index'));
23519       IF l_acc_rev_flag IS NULL THEN
23520          l_acc_rev_flag := 'N';
23521       END IF;
23522    EXCEPTION
23523       WHEN OTHERS THEN
23524          l_acc_rev_flag := 'N';
23525    END;
23526    --
23527    IF (l_acc_rev_flag = 'Y') THEN
23528 
23529        -- 4645092  ------------------------------------------------------------------------------
23530        -- To allow MPA report to determine if it should generate report process
23531        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
23532        ------------------------------------------------------------------------------------------
23533 
23534        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
23535        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
23536    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
23537    -- call ADRs
23538    -- Bug 4922099
23539    --
23540    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
23541         (NVL(l_actual_upg_option, 'N') = 'O') OR
23542         (NVL(l_enc_upg_option, 'N') = 'O')
23543       )
23544    THEN
23545    NULL;
23546    --
23547    --
23548    
23549   l_ccid := AcctDerRule_25(
23550            p_application_id           => p_application_id
23551          , p_ae_header_id             => l_ae_header_id 
23552 , p_source_13 => p_source_13
23553          , x_transaction_coa_id       => l_adr_transaction_coa_id
23554          , x_accounting_coa_id        => l_adr_accounting_coa_id
23555          , x_value_type_code          => l_adr_value_type_code
23556          , p_side                     => 'NA'
23557    );
23558 
23559    xla_ae_lines_pkg.set_ccid(
23560     p_code_combination_id          => l_ccid
23561   , p_value_type_code              => l_adr_value_type_code
23562   , p_transaction_coa_id           => l_adr_transaction_coa_id
23563   , p_accounting_coa_id            => l_adr_accounting_coa_id
23564   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
23565   , p_adr_type_code                => 'S'
23569   , p_component_appl_id            => l_component_appl_id
23566   , p_component_type               => l_component_type
23567   , p_component_code               => l_component_code
23568   , p_component_type_code          => l_component_type_code
23570   , p_amb_context_code             => l_amb_context_code
23571   , p_side                         => 'NA'
23572   );
23573 
23574 
23575    l_segment := AcctDerRule_20(
23576            p_application_id           => p_application_id
23577          , p_ae_header_id             => l_ae_header_id 
23578 , p_source_8 => p_source_8
23579 , p_source_9 => p_source_9
23580 , p_source_10 => p_source_10
23581 , p_source_11 => p_source_11
23582          , x_transaction_coa_id       => l_adr_transaction_coa_id
23583          , x_accounting_coa_id        => l_adr_accounting_coa_id
23584          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
23585          , x_flex_value_set_id        => l_adr_flex_value_set_id
23586          , x_value_type_code          => l_adr_value_type_code
23587          , x_value_combination_id     => l_adr_value_combination_id
23588          , x_value_segment_code       => l_adr_value_segment_code
23589          , p_side                     => 'NA'
23590          , p_override_seg_flag        => 'Y'
23591    );
23592 
23593    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
23594 
23595       xla_ae_lines_pkg.set_segment(
23596           p_to_segment_code         => 'GL_ACCOUNT'
23597         , p_segment_value           => l_segment
23598         , p_from_segment_code       => l_adr_value_segment_code
23599         , p_from_combination_id     => l_adr_value_combination_id
23600         , p_value_type_code         => l_adr_value_type_code
23601         , p_transaction_coa_id      => l_adr_transaction_coa_id
23602         , p_accounting_coa_id       => l_adr_accounting_coa_id
23603         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
23604         , p_flex_value_set_id       => l_adr_flex_value_set_id
23605         , p_adr_code                => 'FV_AR_490201_MISC_RCT_DR'
23606         , p_adr_type_code           => 'S'
23607         , p_component_type          => l_component_type
23608         , p_component_code          => l_component_code
23609         , p_component_type_code     => l_component_type_code
23610         , p_component_appl_id       => l_component_appl_id
23611         , p_amb_context_code        => l_amb_context_code
23612         , p_entity_code             => 'RECEIPTS'
23613         , p_event_class_code        => 'MISC_RECEIPT'
23614         , p_side                    => 'NA'
23615         );
23616 
23617   END IF;
23618 
23619    l_segment := AcctDerRule_4(
23620            p_application_id           => p_application_id
23621          , p_ae_header_id             => l_ae_header_id 
23622 , p_source_3 => p_source_3
23623          , x_transaction_coa_id       => l_adr_transaction_coa_id
23624          , x_accounting_coa_id        => l_adr_accounting_coa_id
23625          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
23626          , x_flex_value_set_id        => l_adr_flex_value_set_id
23627          , x_value_type_code          => l_adr_value_type_code
23628          , x_value_combination_id     => l_adr_value_combination_id
23629          , x_value_segment_code       => l_adr_value_segment_code
23630          , p_side                     => 'NA'
23631          , p_override_seg_flag        => 'Y'
23632    );
23633 
23634    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
23635 
23636       xla_ae_lines_pkg.set_segment(
23637           p_to_segment_code         => 'GL_BALANCING'
23638         , p_segment_value           => l_segment
23639         , p_from_segment_code       => l_adr_value_segment_code
23640         , p_from_combination_id     => l_adr_value_combination_id
23641         , p_value_type_code         => l_adr_value_type_code
23642         , p_transaction_coa_id      => l_adr_transaction_coa_id
23643         , p_accounting_coa_id       => l_adr_accounting_coa_id
23644         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
23645         , p_flex_value_set_id       => l_adr_flex_value_set_id
23646         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
23647         , p_adr_type_code           => 'S'
23648         , p_component_type          => l_component_type
23649         , p_component_code          => l_component_code
23650         , p_component_type_code     => l_component_type_code
23651         , p_component_appl_id       => l_component_appl_id
23652         , p_amb_context_code        => l_amb_context_code
23653         , p_entity_code             => 'RECEIPTS'
23654         , p_event_class_code        => 'MISC_RECEIPT'
23655         , p_side                    => 'NA'
23656         );
23657 
23658   END IF;
23659 
23660    --
23661    --
23662    END IF;
23663 
23664        --
23665        -- Update the line information that should be overwritten
23666        --
23667        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
23668                                          p_header_num   => 1);
23669        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
23670 
23671        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
23672 
23673        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
23677       --
23674           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
23675        END IF;
23676 
23678       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
23679       --
23680       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
23681           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
23682       ELSE
23683           ---------------------------------------------------------------------------------------------------
23684           -- 4262811a Switch Sign
23685           ---------------------------------------------------------------------------------------------------
23686           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
23687           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
23688                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
23689           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
23690                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
23691           -- 5132302
23692           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
23693                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
23694 
23695       END IF;
23696 
23697       -- 4955764
23698       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
23699       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
23700 
23701 
23702       XLA_AE_LINES_PKG.ValidateCurrentLine;
23703       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
23704 
23705       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
23706                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
23707                ,p_balance_type_code => l_balance_type_code);
23708 
23709    END IF;
23710 
23711    -----------------------------------------------------------------------------------------
23712    -- 4262811 Multiperiod Accounting
23713    -----------------------------------------------------------------------------------------
23714      -- No MPA option is assigned.
23715 
23716 
23717 END IF;
23718 END IF;
23719 --
23720 
23721 --
23722 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
23723    trace
23724       (p_msg      => 'END of AcctLineType_64'
23725       ,p_level    => C_LEVEL_PROCEDURE
23726       ,p_module   => l_log_module);
23727 END IF;
23728 --
23729 EXCEPTION
23730   WHEN xla_exceptions_pkg.application_exception THEN
23731       RAISE;
23732   WHEN OTHERS THEN
23733        xla_exceptions_pkg.raise_message
23734            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_64');
23735 END AcctLineType_64;
23736 --
23737 
23738 ---------------------------------------
23739 --
23740 -- PRIVATE FUNCTION
23741 --         AcctLineType_65
23742 --
23743 ---------------------------------------
23744 PROCEDURE AcctLineType_65 (
23745   p_application_id        IN NUMBER
23746  ,p_event_id              IN NUMBER
23747  ,p_calculate_acctd_flag  IN VARCHAR2
23748  ,p_calculate_g_l_flag    IN VARCHAR2
23749  ,p_actual_flag           IN OUT VARCHAR2
23750  ,p_balance_type_code     OUT VARCHAR2
23751  ,p_gain_or_loss_ref      OUT VARCHAR2
23752  
23753 --Distribution GL Account
23754  , p_source_3            IN NUMBER
23755 --Federal Fund Expired Status
23756  , p_source_8            IN VARCHAR2
23757 --Federal Prior Year Flag
23758  , p_source_9            IN VARCHAR2
23759 --Federal Fund Time Frame
23760  , p_source_10            IN VARCHAR2
23761 --Remittance Bank Account Cash Account
23762  , p_source_13            IN NUMBER
23763 --Distribution Source Type
23764  , p_source_20            IN VARCHAR2
23765 --Distribution Line Identifier
23766  , p_source_22            IN NUMBER
23767 --Distribution Type
23768  , p_source_23            IN VARCHAR2
23769 --Entered Amount
23770  , p_source_24            IN NUMBER
23771 --Currency Code
23772  , p_source_25            IN VARCHAR2
23773 --Exchange Rate
23774  , p_source_27            IN NUMBER
23775 --Exchange Rate Type
23776  , p_source_28            IN VARCHAR2
23777 --Applied To Document Accounting Amount
23778  , p_source_29            IN NUMBER
23779 --Federal Account Valid Flag
23780  , p_source_56            IN VARCHAR2
23781 --Applied To Document Exchange Date
23782  , p_source_57            IN DATE
23783 )
23784 IS
23785 
23786 l_component_type              VARCHAR2(80);
23787 l_component_code              VARCHAR2(30);
23788 l_component_type_code         VARCHAR2(1);
23789 l_component_appl_id           INTEGER;
23790 l_amb_context_code            VARCHAR2(30);
23791 l_entity_code                 VARCHAR2(30);
23792 l_event_class_code            VARCHAR2(30);
23793 l_ae_header_id                NUMBER;
23794 l_event_type_code             VARCHAR2(30);
23795 l_line_definition_code        VARCHAR2(30);
23796 l_line_definition_owner_code  VARCHAR2(1);
23797 --
23798 -- adr variables
23799 l_segment                     VARCHAR2(30);
23803 l_adr_flexfield_segment_code  VARCHAR2(30);
23800 l_ccid                        NUMBER;
23801 l_adr_transaction_coa_id      NUMBER;
23802 l_adr_accounting_coa_id       NUMBER;
23804 l_adr_flex_value_set_id       NUMBER;
23805 l_adr_value_type_code         VARCHAR2(30);
23806 l_adr_value_combination_id    NUMBER;
23807 l_adr_value_segment_code      VARCHAR2(30);
23808 
23809 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
23810 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
23811 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
23812 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
23813 
23814 -- 4262811 Variables ------------------------------------------------------------------------------------------
23815 l_entered_amt_idx             NUMBER;
23816 l_accted_amt_idx              NUMBER;
23817 l_acc_rev_flag                VARCHAR2(1);
23818 l_accrual_line_num            NUMBER;
23819 l_tmp_amt                     NUMBER;
23820 l_acc_rev_natural_side_code   VARCHAR2(1);
23821 
23822 l_num_entries                 NUMBER;
23823 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
23824 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
23825 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
23826 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
23827 l_recog_line_1                NUMBER;
23828 l_recog_line_2                NUMBER;
23829 
23830 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
23831 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
23832 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
23833 
23834 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
23835 
23836 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
23837 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
23838 
23839 ---------------------------------------------------------------------------------------------------------------
23840 
23841 
23842 --
23843 -- bulk performance
23844 --
23845 l_balance_type_code           VARCHAR2(1);
23846 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
23847 l_log_module                  VARCHAR2(240);
23848 
23849 --
23850 -- Upgrade strategy
23851 --
23852 l_actual_upg_option           VARCHAR2(1);
23853 l_enc_upg_option           VARCHAR2(1);
23854 
23855 --
23856 BEGIN
23857 --
23858 IF g_log_enabled THEN
23859       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_65';
23860 END IF;
23861 --
23862 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
23863 
23864       trace
23865          (p_msg      => 'BEGIN of AcctLineType_65'
23866          ,p_level    => C_LEVEL_PROCEDURE
23867          ,p_module   => l_log_module);
23868 
23869 END IF;
23870 --
23871 l_component_type             := 'AMB_JLT';
23872 l_component_code             := 'FV_MISC_RCT_REF_OUFP_CR';
23873 l_component_type_code        := 'S';
23874 l_component_appl_id          :=  222;
23875 l_amb_context_code           := 'DEFAULT';
23876 l_entity_code                := 'RECEIPTS';
23877 l_event_class_code           := 'MISC_RECEIPT';
23878 l_event_type_code            := 'MISC_RECEIPT_ALL';
23879 l_line_definition_owner_code := 'S';
23880 l_line_definition_code       := 'MFAR_FED_AR_MISC_REC_BALANCING';
23881 --
23882 l_balance_type_code          := 'A';
23883 l_segment                     := NULL;
23884 l_ccid                        := NULL;
23885 l_adr_transaction_coa_id      := NULL;
23886 l_adr_accounting_coa_id       := NULL;
23887 l_adr_flexfield_segment_code  := NULL;
23888 l_adr_flex_value_set_id       := NULL;
23889 l_adr_value_type_code         := NULL;
23890 l_adr_value_combination_id    := NULL;
23891 l_adr_value_segment_code      := NULL;
23892 
23893 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
23894 l_bflow_class_code           := '';    -- 4219869 Business Flow
23895 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
23896 l_budgetary_control_flag     := 'N';
23897 
23898 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
23899 l_bflow_applied_to_amt       := NULL; -- 5132302
23900 l_entered_amt_idx            := NULL;          -- 4262811
23901 l_accted_amt_idx             := NULL;          -- 4262811
23902 l_acc_rev_flag               := NULL;          -- 4262811
23903 l_accrual_line_num           := NULL;          -- 4262811
23904 l_tmp_amt                    := NULL;          -- 4262811
23905 --
23906  
23907 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
23908     l_balance_type_code <> 'B' THEN
23909 IF NVL(p_source_20,'
23910 ') =  'MISCCASH' AND 
23911 NVL(p_source_8,'
23912 ') =  'Unexpired' AND 
23913 NVL(p_source_9,'
23914 ') =  'Y' AND 
23915 (NVL(p_source_10,'
23916 ') =  'MULTIPLE' OR 
23917 NVL(p_source_10,'
23918 ') =  'NO_YEAR') AND 
23919 NVL(p_source_56,'
23920 ') =  'Y'
23921  THEN 
23922 
23923    --
23924    XLA_AE_LINES_PKG.SetNewLine;
23925 
23926    p_balance_type_code          := l_balance_type_code;
23927    -- set the flag so later we will know whether the gain loss line needs to be created
23928    
23929    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
23930      p_actual_flag :='A';
23931    END IF;
23932 
23933    --
23937                                       p_header_num   => 0); -- 4262811
23934    -- bulk performance
23935    --
23936    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
23938    --
23939    -- set accounting line options
23940    --
23941    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
23942            p_natural_side_code          => 'C'
23943          , p_gain_or_loss_flag          => 'N'
23944          , p_gl_transfer_mode_code      => 'S'
23945          , p_acct_entry_type_code       => 'A'
23946          , p_switch_side_flag           => 'Y'
23947          , p_merge_duplicate_code       => 'A'
23948          );
23949    --
23950    l_acc_rev_natural_side_code := 'D';  -- 4262811
23951    -- 
23952    --
23953    -- set accounting line type info
23954    --
23955    xla_ae_lines_pkg.SetAcctLineType
23956       (p_component_type             => l_component_type
23957       ,p_event_type_code            => l_event_type_code
23958       ,p_line_definition_owner_code => l_line_definition_owner_code
23959       ,p_line_definition_code       => l_line_definition_code
23960       ,p_accounting_line_code       => l_component_code
23961       ,p_accounting_line_type_code  => l_component_type_code
23962       ,p_accounting_line_appl_id    => l_component_appl_id
23963       ,p_amb_context_code           => l_amb_context_code
23964       ,p_entity_code                => l_entity_code
23965       ,p_event_class_code           => l_event_class_code);
23966    --
23967    -- set accounting class
23968    --
23969    xla_ae_lines_pkg.SetAcctClass(
23970            p_accounting_class_code  => 'FV_MISCCASH_CR'
23971          , p_ae_header_id           => l_ae_header_id
23972          );
23973 
23974    --
23975    -- set rounding class
23976    --
23977    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
23978                       'RECEIVABLE';
23979 
23980    --
23981    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
23982    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
23983    --
23984    -- bulk performance
23985    --
23986    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
23987 
23988    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
23989       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
23990 
23991    -- 4955764
23992    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
23993       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
23994 
23995    -- 4458381 Public Sector Enh
23996    
23997    --
23998    -- set accounting attributes for the line type
23999    --
24000    l_entered_amt_idx := 3;
24001    l_accted_amt_idx  := 8;
24002    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
24003    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
24004    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
24005    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
24006    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
24007    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
24008    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
24009    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
24010    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
24011    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
24012    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
24013    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
24014    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
24015    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
24016    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
24017    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
24018    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
24019 
24020    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
24021    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
24022 
24023    ---------------------------------------------------------------------------------------------------------------
24024    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
24025    ---------------------------------------------------------------------------------------------------------------
24026    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
24027 
24028    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
24029    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
24030 
24031    IF xla_accounting_cache_pkg.GetValueChar
24032          (p_source_code         => 'LEDGER_CATEGORY_CODE'
24033          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
24034    AND l_bflow_method_code = 'PRIOR_ENTRY'
24035 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
24036    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
24037          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
24038        )
24039    THEN
24040          xla_ae_lines_pkg.BflowUpgEntry
24041            (p_business_method_code    => l_bflow_method_code
24042            ,p_business_class_code     => l_bflow_class_code
24046 -- No business flow processing for business flow method of NONE.
24043            ,p_balance_type            => l_balance_type_code);
24044    ELSE
24045       NULL;
24047    END IF;
24048 
24049    --
24050    -- call analytical criteria
24051    --
24052    
24053    --
24054    -- call description
24055    --
24056    -- No description or it is inherited.
24057    --
24058    -- call ADRs
24059    -- Bug 4922099
24060    --
24061    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
24062         (NVL(l_actual_upg_option, 'N') = 'O') OR
24063         (NVL(l_enc_upg_option, 'N') = 'O')
24064       )
24065    THEN
24066    NULL;
24067    --
24068    --
24069    
24070   l_ccid := AcctDerRule_25(
24071            p_application_id           => p_application_id
24072          , p_ae_header_id             => l_ae_header_id 
24073 , p_source_13 => p_source_13
24074          , x_transaction_coa_id       => l_adr_transaction_coa_id
24075          , x_accounting_coa_id        => l_adr_accounting_coa_id
24076          , x_value_type_code          => l_adr_value_type_code
24077          , p_side                     => 'NA'
24078    );
24079 
24080    xla_ae_lines_pkg.set_ccid(
24081     p_code_combination_id          => l_ccid
24082   , p_value_type_code              => l_adr_value_type_code
24083   , p_transaction_coa_id           => l_adr_transaction_coa_id
24084   , p_accounting_coa_id            => l_adr_accounting_coa_id
24085   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
24086   , p_adr_type_code                => 'S'
24087   , p_component_type               => l_component_type
24088   , p_component_code               => l_component_code
24089   , p_component_type_code          => l_component_type_code
24090   , p_component_appl_id            => l_component_appl_id
24091   , p_amb_context_code             => l_amb_context_code
24092   , p_side                         => 'NA'
24093   );
24094 
24095 
24096    l_segment := AcctDerRule_14(
24097            p_application_id           => p_application_id
24098          , p_ae_header_id             => l_ae_header_id 
24099 , p_source_8 => p_source_8
24100 , p_source_9 => p_source_9
24101 , p_source_10 => p_source_10
24102          , x_transaction_coa_id       => l_adr_transaction_coa_id
24103          , x_accounting_coa_id        => l_adr_accounting_coa_id
24104          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
24105          , x_flex_value_set_id        => l_adr_flex_value_set_id
24106          , x_value_type_code          => l_adr_value_type_code
24107          , x_value_combination_id     => l_adr_value_combination_id
24108          , x_value_segment_code       => l_adr_value_segment_code
24109          , p_side                     => 'NA'
24110          , p_override_seg_flag        => 'Y'
24111    );
24112 
24113    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
24114 
24115       xla_ae_lines_pkg.set_segment(
24116           p_to_segment_code         => 'GL_ACCOUNT'
24117         , p_segment_value           => l_segment
24118         , p_from_segment_code       => l_adr_value_segment_code
24119         , p_from_combination_id     => l_adr_value_combination_id
24120         , p_value_type_code         => l_adr_value_type_code
24121         , p_transaction_coa_id      => l_adr_transaction_coa_id
24122         , p_accounting_coa_id       => l_adr_accounting_coa_id
24123         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
24124         , p_flex_value_set_id       => l_adr_flex_value_set_id
24125         , p_adr_code                => 'FV_AR_445001_MISC_RCT_CR'
24126         , p_adr_type_code           => 'S'
24127         , p_component_type          => l_component_type
24128         , p_component_code          => l_component_code
24129         , p_component_type_code     => l_component_type_code
24130         , p_component_appl_id       => l_component_appl_id
24131         , p_amb_context_code        => l_amb_context_code
24132         , p_entity_code             => 'RECEIPTS'
24133         , p_event_class_code        => 'MISC_RECEIPT'
24134         , p_side                    => 'NA'
24135         );
24136 
24137   END IF;
24138 
24139    l_segment := AcctDerRule_4(
24140            p_application_id           => p_application_id
24141          , p_ae_header_id             => l_ae_header_id 
24142 , p_source_3 => p_source_3
24143          , x_transaction_coa_id       => l_adr_transaction_coa_id
24144          , x_accounting_coa_id        => l_adr_accounting_coa_id
24145          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
24146          , x_flex_value_set_id        => l_adr_flex_value_set_id
24147          , x_value_type_code          => l_adr_value_type_code
24148          , x_value_combination_id     => l_adr_value_combination_id
24149          , x_value_segment_code       => l_adr_value_segment_code
24150          , p_side                     => 'NA'
24151          , p_override_seg_flag        => 'Y'
24152    );
24153 
24154    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
24155 
24156       xla_ae_lines_pkg.set_segment(
24157           p_to_segment_code         => 'GL_BALANCING'
24158         , p_segment_value           => l_segment
24159         , p_from_segment_code       => l_adr_value_segment_code
24160         , p_from_combination_id     => l_adr_value_combination_id
24161         , p_value_type_code         => l_adr_value_type_code
24162         , p_transaction_coa_id      => l_adr_transaction_coa_id
24163         , p_accounting_coa_id       => l_adr_accounting_coa_id
24167         , p_adr_type_code           => 'S'
24164         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
24165         , p_flex_value_set_id       => l_adr_flex_value_set_id
24166         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
24168         , p_component_type          => l_component_type
24169         , p_component_code          => l_component_code
24170         , p_component_type_code     => l_component_type_code
24171         , p_component_appl_id       => l_component_appl_id
24172         , p_amb_context_code        => l_amb_context_code
24173         , p_entity_code             => 'RECEIPTS'
24174         , p_event_class_code        => 'MISC_RECEIPT'
24175         , p_side                    => 'NA'
24176         );
24177 
24178   END IF;
24179 
24180    --
24181    --
24182    END IF;
24183    --
24184    -- Bug 4922099
24185    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
24186           (NVL(l_enc_upg_option, 'N') = 'O')
24187         ) AND
24188         (l_bflow_method_code = 'PRIOR_ENTRY')
24189       )
24190    THEN
24191       IF
24192       --
24193       1 = 2
24194       --
24195       THEN
24196       xla_accounting_err_pkg.build_message
24197                                     (p_appli_s_name            => 'XLA'
24198                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
24199                                     ,p_token_1                 => 'LINE_NUMBER'
24200                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
24201                                     ,p_token_2                 => 'LINE_TYPE_NAME'
24202                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
24203                                                                              l_component_type
24204                                                                             ,l_component_code
24205                                                                             ,l_component_type_code
24206                                                                             ,l_component_appl_id
24207                                                                             ,l_amb_context_code
24208                                                                             ,l_entity_code
24209                                                                             ,l_event_class_code
24210                                                                            )
24211                                     ,p_token_3                 => 'OWNER'
24212                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
24213                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
24214                                                                           ,p_lookup_code    => l_component_type_code
24215                                                                          )
24216                                     ,p_token_4                 => 'PRODUCT_NAME'
24217                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
24218                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
24219                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
24220                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
24221                                     ,p_ae_header_id            =>  NULL
24222                                        );
24223 
24224         IF (C_LEVEL_ERROR>= g_log_level) THEN
24225                  trace
24226                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
24227                       ,p_level    => C_LEVEL_ERROR
24228                       ,p_module   => l_log_module);
24229         END IF;
24230       END IF;
24231    END IF;
24232    --
24233    --
24234    ------------------------------------------------------------------------------------------------
24235    -- 4219869 Business Flow
24236    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
24237    -- Prior Entry.  Currently, the following code is always generated.
24238    ------------------------------------------------------------------------------------------------
24239    XLA_AE_LINES_PKG.ValidateCurrentLine;
24240 
24241    ------------------------------------------------------------------------------------
24242    -- 4219869 Business Flow
24243    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
24244    ------------------------------------------------------------------------------------
24245    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
24246 
24247    ----------------------------------------------------------------------------------
24248    -- 4219869 Business Flow
24249    -- Update journal entry status -- Need to generate this within IF <condition>
24250    ----------------------------------------------------------------------------------
24251    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
24252          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
24253          ,p_balance_type_code => l_balance_type_code
24254          );
24255 
24256    -------------------------------------------------------------------------------------------
24257    -- 4262811 - Generate the Accrual Reversal lines
24261                               (g_array_event(p_event_id).array_value_num('header_index'));
24258    -------------------------------------------------------------------------------------------
24259    BEGIN
24260       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
24262       IF l_acc_rev_flag IS NULL THEN
24263          l_acc_rev_flag := 'N';
24264       END IF;
24265    EXCEPTION
24266       WHEN OTHERS THEN
24267          l_acc_rev_flag := 'N';
24268    END;
24269    --
24270    IF (l_acc_rev_flag = 'Y') THEN
24271 
24272        -- 4645092  ------------------------------------------------------------------------------
24273        -- To allow MPA report to determine if it should generate report process
24274        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
24275        ------------------------------------------------------------------------------------------
24276 
24277        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
24278        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
24279    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
24280    -- call ADRs
24281    -- Bug 4922099
24282    --
24283    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
24284         (NVL(l_actual_upg_option, 'N') = 'O') OR
24285         (NVL(l_enc_upg_option, 'N') = 'O')
24286       )
24287    THEN
24288    NULL;
24289    --
24290    --
24291    
24292   l_ccid := AcctDerRule_25(
24293            p_application_id           => p_application_id
24294          , p_ae_header_id             => l_ae_header_id 
24295 , p_source_13 => p_source_13
24296          , x_transaction_coa_id       => l_adr_transaction_coa_id
24297          , x_accounting_coa_id        => l_adr_accounting_coa_id
24298          , x_value_type_code          => l_adr_value_type_code
24299          , p_side                     => 'NA'
24300    );
24301 
24302    xla_ae_lines_pkg.set_ccid(
24303     p_code_combination_id          => l_ccid
24304   , p_value_type_code              => l_adr_value_type_code
24305   , p_transaction_coa_id           => l_adr_transaction_coa_id
24306   , p_accounting_coa_id            => l_adr_accounting_coa_id
24307   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
24308   , p_adr_type_code                => 'S'
24309   , p_component_type               => l_component_type
24310   , p_component_code               => l_component_code
24311   , p_component_type_code          => l_component_type_code
24312   , p_component_appl_id            => l_component_appl_id
24313   , p_amb_context_code             => l_amb_context_code
24314   , p_side                         => 'NA'
24315   );
24316 
24317 
24318    l_segment := AcctDerRule_14(
24319            p_application_id           => p_application_id
24320          , p_ae_header_id             => l_ae_header_id 
24321 , p_source_8 => p_source_8
24322 , p_source_9 => p_source_9
24323 , p_source_10 => p_source_10
24324          , x_transaction_coa_id       => l_adr_transaction_coa_id
24325          , x_accounting_coa_id        => l_adr_accounting_coa_id
24326          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
24327          , x_flex_value_set_id        => l_adr_flex_value_set_id
24328          , x_value_type_code          => l_adr_value_type_code
24329          , x_value_combination_id     => l_adr_value_combination_id
24330          , x_value_segment_code       => l_adr_value_segment_code
24331          , p_side                     => 'NA'
24332          , p_override_seg_flag        => 'Y'
24333    );
24334 
24335    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
24336 
24337       xla_ae_lines_pkg.set_segment(
24338           p_to_segment_code         => 'GL_ACCOUNT'
24339         , p_segment_value           => l_segment
24340         , p_from_segment_code       => l_adr_value_segment_code
24341         , p_from_combination_id     => l_adr_value_combination_id
24342         , p_value_type_code         => l_adr_value_type_code
24343         , p_transaction_coa_id      => l_adr_transaction_coa_id
24344         , p_accounting_coa_id       => l_adr_accounting_coa_id
24345         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
24346         , p_flex_value_set_id       => l_adr_flex_value_set_id
24347         , p_adr_code                => 'FV_AR_445001_MISC_RCT_CR'
24348         , p_adr_type_code           => 'S'
24349         , p_component_type          => l_component_type
24350         , p_component_code          => l_component_code
24351         , p_component_type_code     => l_component_type_code
24352         , p_component_appl_id       => l_component_appl_id
24353         , p_amb_context_code        => l_amb_context_code
24354         , p_entity_code             => 'RECEIPTS'
24355         , p_event_class_code        => 'MISC_RECEIPT'
24356         , p_side                    => 'NA'
24357         );
24358 
24359   END IF;
24360 
24361    l_segment := AcctDerRule_4(
24362            p_application_id           => p_application_id
24363          , p_ae_header_id             => l_ae_header_id 
24364 , p_source_3 => p_source_3
24365          , x_transaction_coa_id       => l_adr_transaction_coa_id
24366          , x_accounting_coa_id        => l_adr_accounting_coa_id
24367          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
24368          , x_flex_value_set_id        => l_adr_flex_value_set_id
24369          , x_value_type_code          => l_adr_value_type_code
24373          , p_override_seg_flag        => 'Y'
24370          , x_value_combination_id     => l_adr_value_combination_id
24371          , x_value_segment_code       => l_adr_value_segment_code
24372          , p_side                     => 'NA'
24374    );
24375 
24376    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
24377 
24378       xla_ae_lines_pkg.set_segment(
24379           p_to_segment_code         => 'GL_BALANCING'
24380         , p_segment_value           => l_segment
24381         , p_from_segment_code       => l_adr_value_segment_code
24382         , p_from_combination_id     => l_adr_value_combination_id
24383         , p_value_type_code         => l_adr_value_type_code
24384         , p_transaction_coa_id      => l_adr_transaction_coa_id
24385         , p_accounting_coa_id       => l_adr_accounting_coa_id
24386         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
24387         , p_flex_value_set_id       => l_adr_flex_value_set_id
24388         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
24389         , p_adr_type_code           => 'S'
24390         , p_component_type          => l_component_type
24391         , p_component_code          => l_component_code
24392         , p_component_type_code     => l_component_type_code
24393         , p_component_appl_id       => l_component_appl_id
24394         , p_amb_context_code        => l_amb_context_code
24395         , p_entity_code             => 'RECEIPTS'
24396         , p_event_class_code        => 'MISC_RECEIPT'
24397         , p_side                    => 'NA'
24398         );
24399 
24400   END IF;
24401 
24402    --
24403    --
24404    END IF;
24405 
24406        --
24407        -- Update the line information that should be overwritten
24408        --
24409        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
24410                                          p_header_num   => 1);
24411        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
24412 
24413        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
24414 
24415        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
24416           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
24417        END IF;
24418 
24419       --
24420       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
24421       --
24422       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
24423           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
24424       ELSE
24425           ---------------------------------------------------------------------------------------------------
24426           -- 4262811a Switch Sign
24427           ---------------------------------------------------------------------------------------------------
24428           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
24429           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
24430                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
24431           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
24432                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
24433           -- 5132302
24434           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
24435                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
24436 
24437       END IF;
24438 
24439       -- 4955764
24440       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
24441       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
24442 
24443 
24444       XLA_AE_LINES_PKG.ValidateCurrentLine;
24445       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
24446 
24447       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
24448                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
24449                ,p_balance_type_code => l_balance_type_code);
24450 
24451    END IF;
24452 
24453    -----------------------------------------------------------------------------------------
24454    -- 4262811 Multiperiod Accounting
24455    -----------------------------------------------------------------------------------------
24456      -- No MPA option is assigned.
24457 
24458 
24459 END IF;
24460 END IF;
24461 --
24462 
24463 --
24464 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24465    trace
24466       (p_msg      => 'END of AcctLineType_65'
24467       ,p_level    => C_LEVEL_PROCEDURE
24468       ,p_module   => l_log_module);
24469 END IF;
24470 --
24471 EXCEPTION
24472   WHEN xla_exceptions_pkg.application_exception THEN
24473       RAISE;
24474   WHEN OTHERS THEN
24475        xla_exceptions_pkg.raise_message
24476            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_65');
24477 END AcctLineType_65;
24478 --
24479 
24480 ---------------------------------------
24481 --
24482 -- PRIVATE FUNCTION
24483 --         AcctLineType_66
24484 --
24485 ---------------------------------------
24486 PROCEDURE AcctLineType_66 (
24487   p_application_id        IN NUMBER
24488  ,p_event_id              IN NUMBER
24492  ,p_balance_type_code     OUT VARCHAR2
24489  ,p_calculate_acctd_flag  IN VARCHAR2
24490  ,p_calculate_g_l_flag    IN VARCHAR2
24491  ,p_actual_flag           IN OUT VARCHAR2
24493  ,p_gain_or_loss_ref      OUT VARCHAR2
24494  
24495 --Distribution GL Account
24496  , p_source_3            IN NUMBER
24497 --Federal Fund Expired Status
24498  , p_source_8            IN VARCHAR2
24499 --Federal Prior Year Flag
24500  , p_source_9            IN VARCHAR2
24501 --Federal Fund Time Frame
24502  , p_source_10            IN VARCHAR2
24503 --Remittance Bank Account Cash Account
24504  , p_source_13            IN NUMBER
24505 --Distribution Source Type
24506  , p_source_20            IN VARCHAR2
24507 --Distribution Line Identifier
24508  , p_source_22            IN NUMBER
24509 --Distribution Type
24510  , p_source_23            IN VARCHAR2
24511 --Entered Amount
24512  , p_source_24            IN NUMBER
24513 --Currency Code
24514  , p_source_25            IN VARCHAR2
24515 --Exchange Rate
24516  , p_source_27            IN NUMBER
24517 --Exchange Rate Type
24518  , p_source_28            IN VARCHAR2
24519 --Applied To Document Accounting Amount
24520  , p_source_29            IN NUMBER
24521 --Federal Account Valid Flag
24522  , p_source_56            IN VARCHAR2
24523 --Applied To Document Exchange Date
24524  , p_source_57            IN DATE
24525 )
24526 IS
24527 
24528 l_component_type              VARCHAR2(80);
24529 l_component_code              VARCHAR2(30);
24530 l_component_type_code         VARCHAR2(1);
24531 l_component_appl_id           INTEGER;
24532 l_amb_context_code            VARCHAR2(30);
24533 l_entity_code                 VARCHAR2(30);
24534 l_event_class_code            VARCHAR2(30);
24535 l_ae_header_id                NUMBER;
24536 l_event_type_code             VARCHAR2(30);
24537 l_line_definition_code        VARCHAR2(30);
24538 l_line_definition_owner_code  VARCHAR2(1);
24539 --
24540 -- adr variables
24541 l_segment                     VARCHAR2(30);
24542 l_ccid                        NUMBER;
24543 l_adr_transaction_coa_id      NUMBER;
24544 l_adr_accounting_coa_id       NUMBER;
24545 l_adr_flexfield_segment_code  VARCHAR2(30);
24546 l_adr_flex_value_set_id       NUMBER;
24547 l_adr_value_type_code         VARCHAR2(30);
24548 l_adr_value_combination_id    NUMBER;
24549 l_adr_value_segment_code      VARCHAR2(30);
24550 
24551 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
24552 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
24553 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
24554 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
24555 
24556 -- 4262811 Variables ------------------------------------------------------------------------------------------
24557 l_entered_amt_idx             NUMBER;
24558 l_accted_amt_idx              NUMBER;
24559 l_acc_rev_flag                VARCHAR2(1);
24560 l_accrual_line_num            NUMBER;
24561 l_tmp_amt                     NUMBER;
24562 l_acc_rev_natural_side_code   VARCHAR2(1);
24563 
24564 l_num_entries                 NUMBER;
24565 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
24566 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
24567 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
24568 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
24569 l_recog_line_1                NUMBER;
24570 l_recog_line_2                NUMBER;
24571 
24572 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
24573 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
24574 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
24575 
24576 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
24577 
24578 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
24579 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
24580 
24581 ---------------------------------------------------------------------------------------------------------------
24582 
24583 
24584 --
24585 -- bulk performance
24586 --
24587 l_balance_type_code           VARCHAR2(1);
24588 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
24589 l_log_module                  VARCHAR2(240);
24590 
24591 --
24592 -- Upgrade strategy
24593 --
24594 l_actual_upg_option           VARCHAR2(1);
24595 l_enc_upg_option           VARCHAR2(1);
24596 
24597 --
24598 BEGIN
24599 --
24600 IF g_log_enabled THEN
24601       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_66';
24602 END IF;
24603 --
24604 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24605 
24606       trace
24607          (p_msg      => 'BEGIN of AcctLineType_66'
24608          ,p_level    => C_LEVEL_PROCEDURE
24609          ,p_module   => l_log_module);
24610 
24611 END IF;
24612 --
24613 l_component_type             := 'AMB_JLT';
24614 l_component_code             := 'FV_MISC_RCT_REF_OUFP_DR';
24615 l_component_type_code        := 'S';
24616 l_component_appl_id          :=  222;
24617 l_amb_context_code           := 'DEFAULT';
24618 l_entity_code                := 'RECEIPTS';
24619 l_event_class_code           := 'MISC_RECEIPT';
24620 l_event_type_code            := 'MISC_RECEIPT_ALL';
24621 l_line_definition_owner_code := 'S';
24625 l_segment                     := NULL;
24622 l_line_definition_code       := 'MFAR_FED_AR_MISC_REC_BALANCING';
24623 --
24624 l_balance_type_code          := 'A';
24626 l_ccid                        := NULL;
24627 l_adr_transaction_coa_id      := NULL;
24628 l_adr_accounting_coa_id       := NULL;
24629 l_adr_flexfield_segment_code  := NULL;
24630 l_adr_flex_value_set_id       := NULL;
24631 l_adr_value_type_code         := NULL;
24632 l_adr_value_combination_id    := NULL;
24633 l_adr_value_segment_code      := NULL;
24634 
24635 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
24636 l_bflow_class_code           := '';    -- 4219869 Business Flow
24637 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
24638 l_budgetary_control_flag     := 'N';
24639 
24640 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
24641 l_bflow_applied_to_amt       := NULL; -- 5132302
24642 l_entered_amt_idx            := NULL;          -- 4262811
24643 l_accted_amt_idx             := NULL;          -- 4262811
24644 l_acc_rev_flag               := NULL;          -- 4262811
24645 l_accrual_line_num           := NULL;          -- 4262811
24646 l_tmp_amt                    := NULL;          -- 4262811
24647 --
24648  
24649 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
24650     l_balance_type_code <> 'B' THEN
24651 IF NVL(p_source_20,'
24652 ') =  'MISCCASH' AND 
24653 NVL(p_source_8,'
24654 ') =  'Unexpired' AND 
24655 NVL(p_source_9,'
24656 ') =  'Y' AND 
24657 (NVL(p_source_10,'
24658 ') =  'MULTIPLE' OR 
24659 NVL(p_source_10,'
24660 ') =  'NO_YEAR') AND 
24661 NVL(p_source_56,'
24662 ') =  'Y'
24663  THEN 
24664 
24665    --
24666    XLA_AE_LINES_PKG.SetNewLine;
24667 
24668    p_balance_type_code          := l_balance_type_code;
24669    -- set the flag so later we will know whether the gain loss line needs to be created
24670    
24671    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
24672      p_actual_flag :='A';
24673    END IF;
24674 
24675    --
24676    -- bulk performance
24677    --
24678    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
24679                                       p_header_num   => 0); -- 4262811
24680    --
24681    -- set accounting line options
24682    --
24683    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
24684            p_natural_side_code          => 'D'
24685          , p_gain_or_loss_flag          => 'N'
24686          , p_gl_transfer_mode_code      => 'S'
24687          , p_acct_entry_type_code       => 'A'
24688          , p_switch_side_flag           => 'Y'
24689          , p_merge_duplicate_code       => 'A'
24690          );
24691    --
24692    l_acc_rev_natural_side_code := 'C';  -- 4262811
24693    -- 
24694    --
24695    -- set accounting line type info
24696    --
24697    xla_ae_lines_pkg.SetAcctLineType
24698       (p_component_type             => l_component_type
24699       ,p_event_type_code            => l_event_type_code
24700       ,p_line_definition_owner_code => l_line_definition_owner_code
24701       ,p_line_definition_code       => l_line_definition_code
24702       ,p_accounting_line_code       => l_component_code
24703       ,p_accounting_line_type_code  => l_component_type_code
24704       ,p_accounting_line_appl_id    => l_component_appl_id
24705       ,p_amb_context_code           => l_amb_context_code
24706       ,p_entity_code                => l_entity_code
24707       ,p_event_class_code           => l_event_class_code);
24708    --
24709    -- set accounting class
24710    --
24711    xla_ae_lines_pkg.SetAcctClass(
24712            p_accounting_class_code  => 'FV_MISCCASH_DR'
24713          , p_ae_header_id           => l_ae_header_id
24714          );
24715 
24716    --
24717    -- set rounding class
24718    --
24719    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
24720                       'RECEIVABLE';
24721 
24722    --
24723    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
24724    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
24725    --
24726    -- bulk performance
24727    --
24728    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
24729 
24730    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
24731       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
24732 
24733    -- 4955764
24734    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
24735       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
24736 
24737    -- 4458381 Public Sector Enh
24738    
24739    --
24740    -- set accounting attributes for the line type
24741    --
24742    l_entered_amt_idx := 3;
24743    l_accted_amt_idx  := 8;
24744    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
24745    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
24746    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
24747    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
24748    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
24749    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
24753    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
24750    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
24751    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
24752    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
24754    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
24755    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
24756    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
24757    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
24758    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
24759    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
24760    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
24761 
24762    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
24763    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
24764 
24765    ---------------------------------------------------------------------------------------------------------------
24766    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
24767    ---------------------------------------------------------------------------------------------------------------
24768    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
24769 
24770    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
24771    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
24772 
24773    IF xla_accounting_cache_pkg.GetValueChar
24774          (p_source_code         => 'LEDGER_CATEGORY_CODE'
24775          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
24776    AND l_bflow_method_code = 'PRIOR_ENTRY'
24777 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
24778    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
24779          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
24780        )
24781    THEN
24782          xla_ae_lines_pkg.BflowUpgEntry
24783            (p_business_method_code    => l_bflow_method_code
24784            ,p_business_class_code     => l_bflow_class_code
24785            ,p_balance_type            => l_balance_type_code);
24786    ELSE
24787       NULL;
24788 -- No business flow processing for business flow method of NONE.
24789    END IF;
24790 
24791    --
24792    -- call analytical criteria
24793    --
24794    
24795    --
24796    -- call description
24797    --
24798    -- No description or it is inherited.
24799    --
24800    -- call ADRs
24801    -- Bug 4922099
24802    --
24803    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
24804         (NVL(l_actual_upg_option, 'N') = 'O') OR
24805         (NVL(l_enc_upg_option, 'N') = 'O')
24806       )
24807    THEN
24808    NULL;
24809    --
24810    --
24811    
24812   l_ccid := AcctDerRule_25(
24813            p_application_id           => p_application_id
24814          , p_ae_header_id             => l_ae_header_id 
24815 , p_source_13 => p_source_13
24816          , x_transaction_coa_id       => l_adr_transaction_coa_id
24817          , x_accounting_coa_id        => l_adr_accounting_coa_id
24818          , x_value_type_code          => l_adr_value_type_code
24819          , p_side                     => 'NA'
24820    );
24821 
24822    xla_ae_lines_pkg.set_ccid(
24823     p_code_combination_id          => l_ccid
24824   , p_value_type_code              => l_adr_value_type_code
24825   , p_transaction_coa_id           => l_adr_transaction_coa_id
24826   , p_accounting_coa_id            => l_adr_accounting_coa_id
24827   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
24828   , p_adr_type_code                => 'S'
24829   , p_component_type               => l_component_type
24830   , p_component_code               => l_component_code
24831   , p_component_type_code          => l_component_type_code
24832   , p_component_appl_id            => l_component_appl_id
24833   , p_amb_context_code             => l_amb_context_code
24834   , p_side                         => 'NA'
24835   );
24836 
24837 
24838    l_segment := AcctDerRule_21(
24839            p_application_id           => p_application_id
24840          , p_ae_header_id             => l_ae_header_id 
24841 , p_source_8 => p_source_8
24842 , p_source_9 => p_source_9
24843 , p_source_10 => p_source_10
24844          , x_transaction_coa_id       => l_adr_transaction_coa_id
24845          , x_accounting_coa_id        => l_adr_accounting_coa_id
24846          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
24847          , x_flex_value_set_id        => l_adr_flex_value_set_id
24848          , x_value_type_code          => l_adr_value_type_code
24849          , x_value_combination_id     => l_adr_value_combination_id
24850          , x_value_segment_code       => l_adr_value_segment_code
24851          , p_side                     => 'NA'
24852          , p_override_seg_flag        => 'Y'
24853    );
24854 
24855    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
24856 
24857       xla_ae_lines_pkg.set_segment(
24858           p_to_segment_code         => 'GL_ACCOUNT'
24859         , p_segment_value           => l_segment
24860         , p_from_segment_code       => l_adr_value_segment_code
24861         , p_from_combination_id     => l_adr_value_combination_id
24865         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
24862         , p_value_type_code         => l_adr_value_type_code
24863         , p_transaction_coa_id      => l_adr_transaction_coa_id
24864         , p_accounting_coa_id       => l_adr_accounting_coa_id
24866         , p_flex_value_set_id       => l_adr_flex_value_set_id
24867         , p_adr_code                => 'FV_AR_497201_MISC_RCT_DR'
24868         , p_adr_type_code           => 'S'
24869         , p_component_type          => l_component_type
24870         , p_component_code          => l_component_code
24871         , p_component_type_code     => l_component_type_code
24872         , p_component_appl_id       => l_component_appl_id
24873         , p_amb_context_code        => l_amb_context_code
24874         , p_entity_code             => 'RECEIPTS'
24875         , p_event_class_code        => 'MISC_RECEIPT'
24876         , p_side                    => 'NA'
24877         );
24878 
24879   END IF;
24880 
24881    l_segment := AcctDerRule_4(
24882            p_application_id           => p_application_id
24883          , p_ae_header_id             => l_ae_header_id 
24884 , p_source_3 => p_source_3
24885          , x_transaction_coa_id       => l_adr_transaction_coa_id
24886          , x_accounting_coa_id        => l_adr_accounting_coa_id
24887          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
24888          , x_flex_value_set_id        => l_adr_flex_value_set_id
24889          , x_value_type_code          => l_adr_value_type_code
24890          , x_value_combination_id     => l_adr_value_combination_id
24891          , x_value_segment_code       => l_adr_value_segment_code
24892          , p_side                     => 'NA'
24893          , p_override_seg_flag        => 'Y'
24894    );
24895 
24896    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
24897 
24898       xla_ae_lines_pkg.set_segment(
24899           p_to_segment_code         => 'GL_BALANCING'
24900         , p_segment_value           => l_segment
24901         , p_from_segment_code       => l_adr_value_segment_code
24902         , p_from_combination_id     => l_adr_value_combination_id
24903         , p_value_type_code         => l_adr_value_type_code
24904         , p_transaction_coa_id      => l_adr_transaction_coa_id
24905         , p_accounting_coa_id       => l_adr_accounting_coa_id
24906         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
24907         , p_flex_value_set_id       => l_adr_flex_value_set_id
24908         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
24909         , p_adr_type_code           => 'S'
24910         , p_component_type          => l_component_type
24911         , p_component_code          => l_component_code
24912         , p_component_type_code     => l_component_type_code
24913         , p_component_appl_id       => l_component_appl_id
24914         , p_amb_context_code        => l_amb_context_code
24915         , p_entity_code             => 'RECEIPTS'
24916         , p_event_class_code        => 'MISC_RECEIPT'
24917         , p_side                    => 'NA'
24918         );
24919 
24920   END IF;
24921 
24922    --
24923    --
24924    END IF;
24925    --
24926    -- Bug 4922099
24927    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
24928           (NVL(l_enc_upg_option, 'N') = 'O')
24929         ) AND
24930         (l_bflow_method_code = 'PRIOR_ENTRY')
24931       )
24932    THEN
24933       IF
24934       --
24935       1 = 2
24936       --
24937       THEN
24938       xla_accounting_err_pkg.build_message
24939                                     (p_appli_s_name            => 'XLA'
24940                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
24941                                     ,p_token_1                 => 'LINE_NUMBER'
24942                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
24943                                     ,p_token_2                 => 'LINE_TYPE_NAME'
24944                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
24945                                                                              l_component_type
24946                                                                             ,l_component_code
24947                                                                             ,l_component_type_code
24948                                                                             ,l_component_appl_id
24949                                                                             ,l_amb_context_code
24950                                                                             ,l_entity_code
24951                                                                             ,l_event_class_code
24952                                                                            )
24953                                     ,p_token_3                 => 'OWNER'
24954                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
24955                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
24956                                                                           ,p_lookup_code    => l_component_type_code
24957                                                                          )
24958                                     ,p_token_4                 => 'PRODUCT_NAME'
24959                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
24963                                     ,p_ae_header_id            =>  NULL
24960                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
24961                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
24962                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
24964                                        );
24965 
24966         IF (C_LEVEL_ERROR>= g_log_level) THEN
24967                  trace
24968                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
24969                       ,p_level    => C_LEVEL_ERROR
24970                       ,p_module   => l_log_module);
24971         END IF;
24972       END IF;
24973    END IF;
24974    --
24975    --
24976    ------------------------------------------------------------------------------------------------
24977    -- 4219869 Business Flow
24978    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
24979    -- Prior Entry.  Currently, the following code is always generated.
24980    ------------------------------------------------------------------------------------------------
24981    XLA_AE_LINES_PKG.ValidateCurrentLine;
24982 
24983    ------------------------------------------------------------------------------------
24984    -- 4219869 Business Flow
24985    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
24986    ------------------------------------------------------------------------------------
24987    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
24988 
24989    ----------------------------------------------------------------------------------
24990    -- 4219869 Business Flow
24991    -- Update journal entry status -- Need to generate this within IF <condition>
24992    ----------------------------------------------------------------------------------
24993    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
24994          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
24995          ,p_balance_type_code => l_balance_type_code
24996          );
24997 
24998    -------------------------------------------------------------------------------------------
24999    -- 4262811 - Generate the Accrual Reversal lines
25000    -------------------------------------------------------------------------------------------
25001    BEGIN
25002       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
25003                               (g_array_event(p_event_id).array_value_num('header_index'));
25004       IF l_acc_rev_flag IS NULL THEN
25005          l_acc_rev_flag := 'N';
25006       END IF;
25007    EXCEPTION
25008       WHEN OTHERS THEN
25009          l_acc_rev_flag := 'N';
25010    END;
25011    --
25012    IF (l_acc_rev_flag = 'Y') THEN
25013 
25014        -- 4645092  ------------------------------------------------------------------------------
25015        -- To allow MPA report to determine if it should generate report process
25016        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
25017        ------------------------------------------------------------------------------------------
25018 
25019        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
25020        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
25021    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
25022    -- call ADRs
25023    -- Bug 4922099
25024    --
25025    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
25026         (NVL(l_actual_upg_option, 'N') = 'O') OR
25027         (NVL(l_enc_upg_option, 'N') = 'O')
25028       )
25029    THEN
25030    NULL;
25031    --
25032    --
25033    
25034   l_ccid := AcctDerRule_25(
25035            p_application_id           => p_application_id
25036          , p_ae_header_id             => l_ae_header_id 
25037 , p_source_13 => p_source_13
25038          , x_transaction_coa_id       => l_adr_transaction_coa_id
25039          , x_accounting_coa_id        => l_adr_accounting_coa_id
25040          , x_value_type_code          => l_adr_value_type_code
25041          , p_side                     => 'NA'
25042    );
25043 
25044    xla_ae_lines_pkg.set_ccid(
25045     p_code_combination_id          => l_ccid
25046   , p_value_type_code              => l_adr_value_type_code
25047   , p_transaction_coa_id           => l_adr_transaction_coa_id
25048   , p_accounting_coa_id            => l_adr_accounting_coa_id
25049   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
25050   , p_adr_type_code                => 'S'
25051   , p_component_type               => l_component_type
25052   , p_component_code               => l_component_code
25053   , p_component_type_code          => l_component_type_code
25054   , p_component_appl_id            => l_component_appl_id
25055   , p_amb_context_code             => l_amb_context_code
25056   , p_side                         => 'NA'
25057   );
25058 
25059 
25060    l_segment := AcctDerRule_21(
25061            p_application_id           => p_application_id
25062          , p_ae_header_id             => l_ae_header_id 
25063 , p_source_8 => p_source_8
25064 , p_source_9 => p_source_9
25065 , p_source_10 => p_source_10
25066          , x_transaction_coa_id       => l_adr_transaction_coa_id
25067          , x_accounting_coa_id        => l_adr_accounting_coa_id
25068          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
25069          , x_flex_value_set_id        => l_adr_flex_value_set_id
25073          , p_side                     => 'NA'
25070          , x_value_type_code          => l_adr_value_type_code
25071          , x_value_combination_id     => l_adr_value_combination_id
25072          , x_value_segment_code       => l_adr_value_segment_code
25074          , p_override_seg_flag        => 'Y'
25075    );
25076 
25077    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
25078 
25079       xla_ae_lines_pkg.set_segment(
25080           p_to_segment_code         => 'GL_ACCOUNT'
25081         , p_segment_value           => l_segment
25082         , p_from_segment_code       => l_adr_value_segment_code
25083         , p_from_combination_id     => l_adr_value_combination_id
25084         , p_value_type_code         => l_adr_value_type_code
25085         , p_transaction_coa_id      => l_adr_transaction_coa_id
25086         , p_accounting_coa_id       => l_adr_accounting_coa_id
25087         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
25088         , p_flex_value_set_id       => l_adr_flex_value_set_id
25089         , p_adr_code                => 'FV_AR_497201_MISC_RCT_DR'
25090         , p_adr_type_code           => 'S'
25091         , p_component_type          => l_component_type
25092         , p_component_code          => l_component_code
25093         , p_component_type_code     => l_component_type_code
25094         , p_component_appl_id       => l_component_appl_id
25095         , p_amb_context_code        => l_amb_context_code
25096         , p_entity_code             => 'RECEIPTS'
25097         , p_event_class_code        => 'MISC_RECEIPT'
25098         , p_side                    => 'NA'
25099         );
25100 
25101   END IF;
25102 
25103    l_segment := AcctDerRule_4(
25104            p_application_id           => p_application_id
25105          , p_ae_header_id             => l_ae_header_id 
25106 , p_source_3 => p_source_3
25107          , x_transaction_coa_id       => l_adr_transaction_coa_id
25108          , x_accounting_coa_id        => l_adr_accounting_coa_id
25109          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
25110          , x_flex_value_set_id        => l_adr_flex_value_set_id
25111          , x_value_type_code          => l_adr_value_type_code
25112          , x_value_combination_id     => l_adr_value_combination_id
25113          , x_value_segment_code       => l_adr_value_segment_code
25114          , p_side                     => 'NA'
25115          , p_override_seg_flag        => 'Y'
25116    );
25117 
25118    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
25119 
25120       xla_ae_lines_pkg.set_segment(
25121           p_to_segment_code         => 'GL_BALANCING'
25122         , p_segment_value           => l_segment
25123         , p_from_segment_code       => l_adr_value_segment_code
25124         , p_from_combination_id     => l_adr_value_combination_id
25125         , p_value_type_code         => l_adr_value_type_code
25126         , p_transaction_coa_id      => l_adr_transaction_coa_id
25127         , p_accounting_coa_id       => l_adr_accounting_coa_id
25128         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
25129         , p_flex_value_set_id       => l_adr_flex_value_set_id
25130         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
25131         , p_adr_type_code           => 'S'
25132         , p_component_type          => l_component_type
25133         , p_component_code          => l_component_code
25134         , p_component_type_code     => l_component_type_code
25135         , p_component_appl_id       => l_component_appl_id
25136         , p_amb_context_code        => l_amb_context_code
25137         , p_entity_code             => 'RECEIPTS'
25138         , p_event_class_code        => 'MISC_RECEIPT'
25139         , p_side                    => 'NA'
25140         );
25141 
25142   END IF;
25143 
25144    --
25145    --
25146    END IF;
25147 
25148        --
25149        -- Update the line information that should be overwritten
25150        --
25151        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
25152                                          p_header_num   => 1);
25153        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
25154 
25155        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
25156 
25157        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
25158           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
25159        END IF;
25160 
25161       --
25162       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
25163       --
25164       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
25165           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
25166       ELSE
25167           ---------------------------------------------------------------------------------------------------
25168           -- 4262811a Switch Sign
25169           ---------------------------------------------------------------------------------------------------
25170           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
25171           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
25172                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
25173           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
25177                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
25174                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
25175           -- 5132302
25176           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
25178 
25179       END IF;
25180 
25181       -- 4955764
25182       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
25183       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
25184 
25185 
25186       XLA_AE_LINES_PKG.ValidateCurrentLine;
25187       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
25188 
25189       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
25190                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
25191                ,p_balance_type_code => l_balance_type_code);
25192 
25193    END IF;
25194 
25195    -----------------------------------------------------------------------------------------
25196    -- 4262811 Multiperiod Accounting
25197    -----------------------------------------------------------------------------------------
25198      -- No MPA option is assigned.
25199 
25200 
25201 END IF;
25202 END IF;
25203 --
25204 
25205 --
25206 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
25207    trace
25208       (p_msg      => 'END of AcctLineType_66'
25209       ,p_level    => C_LEVEL_PROCEDURE
25210       ,p_module   => l_log_module);
25211 END IF;
25212 --
25213 EXCEPTION
25214   WHEN xla_exceptions_pkg.application_exception THEN
25215       RAISE;
25216   WHEN OTHERS THEN
25217        xla_exceptions_pkg.raise_message
25218            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_66');
25219 END AcctLineType_66;
25220 --
25221 
25222 ---------------------------------------
25223 --
25224 -- PRIVATE FUNCTION
25225 --         AcctLineType_67
25226 --
25227 ---------------------------------------
25228 PROCEDURE AcctLineType_67 (
25229   p_application_id        IN NUMBER
25230  ,p_event_id              IN NUMBER
25231  ,p_calculate_acctd_flag  IN VARCHAR2
25232  ,p_calculate_g_l_flag    IN VARCHAR2
25233  ,p_actual_flag           IN OUT VARCHAR2
25234  ,p_balance_type_code     OUT VARCHAR2
25235  ,p_gain_or_loss_ref      OUT VARCHAR2
25236  
25237 --Distribution GL Account
25238  , p_source_3            IN NUMBER
25239 --Federal Fund Category
25240  , p_source_5            IN VARCHAR2
25241 --Remittance Bank Account Cash Account
25242  , p_source_13            IN NUMBER
25243 --Distribution Source Type
25244  , p_source_20            IN VARCHAR2
25245 --Distribution Line Identifier
25246  , p_source_22            IN NUMBER
25247 --Distribution Type
25248  , p_source_23            IN VARCHAR2
25249 --Entered Amount
25250  , p_source_24            IN NUMBER
25251 --Currency Code
25252  , p_source_25            IN VARCHAR2
25253 --Exchange Rate
25254  , p_source_27            IN NUMBER
25255 --Exchange Rate Type
25256  , p_source_28            IN VARCHAR2
25257 --Applied To Document Accounting Amount
25258  , p_source_29            IN NUMBER
25259 --Federal Account Valid Flag
25260  , p_source_56            IN VARCHAR2
25261 --Applied To Document Exchange Date
25262  , p_source_57            IN DATE
25263 )
25264 IS
25265 
25266 l_component_type              VARCHAR2(80);
25267 l_component_code              VARCHAR2(30);
25268 l_component_type_code         VARCHAR2(1);
25269 l_component_appl_id           INTEGER;
25270 l_amb_context_code            VARCHAR2(30);
25271 l_entity_code                 VARCHAR2(30);
25272 l_event_class_code            VARCHAR2(30);
25273 l_ae_header_id                NUMBER;
25274 l_event_type_code             VARCHAR2(30);
25275 l_line_definition_code        VARCHAR2(30);
25276 l_line_definition_owner_code  VARCHAR2(1);
25277 --
25278 -- adr variables
25279 l_segment                     VARCHAR2(30);
25280 l_ccid                        NUMBER;
25281 l_adr_transaction_coa_id      NUMBER;
25282 l_adr_accounting_coa_id       NUMBER;
25283 l_adr_flexfield_segment_code  VARCHAR2(30);
25284 l_adr_flex_value_set_id       NUMBER;
25285 l_adr_value_type_code         VARCHAR2(30);
25286 l_adr_value_combination_id    NUMBER;
25287 l_adr_value_segment_code      VARCHAR2(30);
25288 
25289 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
25290 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
25291 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
25292 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
25293 
25294 -- 4262811 Variables ------------------------------------------------------------------------------------------
25295 l_entered_amt_idx             NUMBER;
25296 l_accted_amt_idx              NUMBER;
25297 l_acc_rev_flag                VARCHAR2(1);
25298 l_accrual_line_num            NUMBER;
25299 l_tmp_amt                     NUMBER;
25300 l_acc_rev_natural_side_code   VARCHAR2(1);
25301 
25302 l_num_entries                 NUMBER;
25303 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
25304 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
25308 l_recog_line_2                NUMBER;
25305 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
25306 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
25307 l_recog_line_1                NUMBER;
25309 
25310 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
25311 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
25312 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
25313 
25314 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
25315 
25316 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
25317 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
25318 
25319 ---------------------------------------------------------------------------------------------------------------
25320 
25321 
25322 --
25323 -- bulk performance
25324 --
25325 l_balance_type_code           VARCHAR2(1);
25326 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
25327 l_log_module                  VARCHAR2(240);
25328 
25329 --
25330 -- Upgrade strategy
25331 --
25332 l_actual_upg_option           VARCHAR2(1);
25333 l_enc_upg_option           VARCHAR2(1);
25334 
25335 --
25336 BEGIN
25337 --
25338 IF g_log_enabled THEN
25339       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_67';
25340 END IF;
25341 --
25342 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
25343 
25344       trace
25345          (p_msg      => 'BEGIN of AcctLineType_67'
25346          ,p_level    => C_LEVEL_PROCEDURE
25347          ,p_module   => l_log_module);
25348 
25349 END IF;
25350 --
25351 l_component_type             := 'AMB_JLT';
25352 l_component_code             := 'FV_MISC_RCT_REIM_WO_ADV_CR';
25353 l_component_type_code        := 'S';
25354 l_component_appl_id          :=  222;
25355 l_amb_context_code           := 'DEFAULT';
25356 l_entity_code                := 'RECEIPTS';
25357 l_event_class_code           := 'MISC_RECEIPT';
25358 l_event_type_code            := 'MISC_RECEIPT_ALL';
25359 l_line_definition_owner_code := 'S';
25360 l_line_definition_code       := 'MFAR_FED_AR_MISC_REC_BALANCING';
25361 --
25362 l_balance_type_code          := 'A';
25363 l_segment                     := NULL;
25364 l_ccid                        := NULL;
25365 l_adr_transaction_coa_id      := NULL;
25366 l_adr_accounting_coa_id       := NULL;
25367 l_adr_flexfield_segment_code  := NULL;
25368 l_adr_flex_value_set_id       := NULL;
25369 l_adr_value_type_code         := NULL;
25370 l_adr_value_combination_id    := NULL;
25371 l_adr_value_segment_code      := NULL;
25372 
25373 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
25374 l_bflow_class_code           := '';    -- 4219869 Business Flow
25375 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
25376 l_budgetary_control_flag     := 'N';
25377 
25378 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
25379 l_bflow_applied_to_amt       := NULL; -- 5132302
25380 l_entered_amt_idx            := NULL;          -- 4262811
25381 l_accted_amt_idx             := NULL;          -- 4262811
25382 l_acc_rev_flag               := NULL;          -- 4262811
25383 l_accrual_line_num           := NULL;          -- 4262811
25384 l_tmp_amt                    := NULL;          -- 4262811
25385 --
25386  
25387 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
25388     l_balance_type_code <> 'B' THEN
25389 IF NVL(p_source_20,'
25390 ') =  'MISCCASH' AND 
25391 NVL(p_source_5,'
25392 ') =  'Reimbursable' AND 
25393 NVL(p_source_56,'
25394 ') =  'Y'
25395  THEN 
25396 
25397    --
25398    XLA_AE_LINES_PKG.SetNewLine;
25399 
25400    p_balance_type_code          := l_balance_type_code;
25401    -- set the flag so later we will know whether the gain loss line needs to be created
25402    
25403    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
25404      p_actual_flag :='A';
25405    END IF;
25406 
25407    --
25408    -- bulk performance
25409    --
25410    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
25411                                       p_header_num   => 0); -- 4262811
25412    --
25413    -- set accounting line options
25414    --
25415    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
25416            p_natural_side_code          => 'C'
25417          , p_gain_or_loss_flag          => 'N'
25418          , p_gl_transfer_mode_code      => 'S'
25419          , p_acct_entry_type_code       => 'A'
25420          , p_switch_side_flag           => 'Y'
25421          , p_merge_duplicate_code       => 'A'
25422          );
25423    --
25424    l_acc_rev_natural_side_code := 'D';  -- 4262811
25425    -- 
25426    --
25427    -- set accounting line type info
25428    --
25429    xla_ae_lines_pkg.SetAcctLineType
25430       (p_component_type             => l_component_type
25431       ,p_event_type_code            => l_event_type_code
25432       ,p_line_definition_owner_code => l_line_definition_owner_code
25433       ,p_line_definition_code       => l_line_definition_code
25434       ,p_accounting_line_code       => l_component_code
25435       ,p_accounting_line_type_code  => l_component_type_code
25439       ,p_event_class_code           => l_event_class_code);
25436       ,p_accounting_line_appl_id    => l_component_appl_id
25437       ,p_amb_context_code           => l_amb_context_code
25438       ,p_entity_code                => l_entity_code
25440    --
25441    -- set accounting class
25442    --
25443    xla_ae_lines_pkg.SetAcctClass(
25444            p_accounting_class_code  => 'FV_MISCCASH_CR'
25445          , p_ae_header_id           => l_ae_header_id
25446          );
25447 
25448    --
25449    -- set rounding class
25450    --
25451    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
25452                       'RECEIVABLE';
25453 
25454    --
25455    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
25456    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
25457    --
25458    -- bulk performance
25459    --
25460    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
25461 
25462    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
25463       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
25464 
25465    -- 4955764
25466    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
25467       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
25468 
25469    -- 4458381 Public Sector Enh
25470    
25471    --
25472    -- set accounting attributes for the line type
25473    --
25474    l_entered_amt_idx := 3;
25475    l_accted_amt_idx  := 8;
25476    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
25477    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
25478    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
25479    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
25480    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
25481    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
25482    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
25483    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
25484    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
25485    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
25486    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
25487    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
25488    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
25489    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
25490    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
25491    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
25492    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
25493 
25494    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
25495    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
25496 
25497    ---------------------------------------------------------------------------------------------------------------
25498    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
25499    ---------------------------------------------------------------------------------------------------------------
25500    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
25501 
25502    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
25503    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
25504 
25505    IF xla_accounting_cache_pkg.GetValueChar
25506          (p_source_code         => 'LEDGER_CATEGORY_CODE'
25507          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
25508    AND l_bflow_method_code = 'PRIOR_ENTRY'
25509 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
25510    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
25511          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
25512        )
25513    THEN
25514          xla_ae_lines_pkg.BflowUpgEntry
25515            (p_business_method_code    => l_bflow_method_code
25516            ,p_business_class_code     => l_bflow_class_code
25517            ,p_balance_type            => l_balance_type_code);
25518    ELSE
25519       NULL;
25520 -- No business flow processing for business flow method of NONE.
25521    END IF;
25522 
25523    --
25524    -- call analytical criteria
25525    --
25526    
25527    --
25528    -- call description
25529    --
25530    -- No description or it is inherited.
25531    --
25532    -- call ADRs
25533    -- Bug 4922099
25534    --
25535    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
25536         (NVL(l_actual_upg_option, 'N') = 'O') OR
25537         (NVL(l_enc_upg_option, 'N') = 'O')
25538       )
25539    THEN
25540    NULL;
25541    --
25542    --
25543    
25544   l_ccid := AcctDerRule_25(
25545            p_application_id           => p_application_id
25546          , p_ae_header_id             => l_ae_header_id 
25547 , p_source_13 => p_source_13
25548          , x_transaction_coa_id       => l_adr_transaction_coa_id
25549          , x_accounting_coa_id        => l_adr_accounting_coa_id
25550          , x_value_type_code          => l_adr_value_type_code
25551          , p_side                     => 'NA'
25552    );
25553 
25557   , p_transaction_coa_id           => l_adr_transaction_coa_id
25554    xla_ae_lines_pkg.set_ccid(
25555     p_code_combination_id          => l_ccid
25556   , p_value_type_code              => l_adr_value_type_code
25558   , p_accounting_coa_id            => l_adr_accounting_coa_id
25559   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
25560   , p_adr_type_code                => 'S'
25561   , p_component_type               => l_component_type
25562   , p_component_code               => l_component_code
25563   , p_component_type_code          => l_component_type_code
25564   , p_component_appl_id            => l_component_appl_id
25565   , p_amb_context_code             => l_amb_context_code
25566   , p_side                         => 'NA'
25567   );
25568 
25569 
25570    l_segment := AcctDerRule_8(
25571            p_application_id           => p_application_id
25572          , p_ae_header_id             => l_ae_header_id 
25573 , p_source_5 => p_source_5
25574          , x_transaction_coa_id       => l_adr_transaction_coa_id
25575          , x_accounting_coa_id        => l_adr_accounting_coa_id
25576          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
25577          , x_flex_value_set_id        => l_adr_flex_value_set_id
25578          , x_value_type_code          => l_adr_value_type_code
25579          , x_value_combination_id     => l_adr_value_combination_id
25580          , x_value_segment_code       => l_adr_value_segment_code
25581          , p_side                     => 'NA'
25582          , p_override_seg_flag        => 'Y'
25583    );
25584 
25585    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
25586 
25587       xla_ae_lines_pkg.set_segment(
25588           p_to_segment_code         => 'GL_ACCOUNT'
25589         , p_segment_value           => l_segment
25590         , p_from_segment_code       => l_adr_value_segment_code
25591         , p_from_combination_id     => l_adr_value_combination_id
25592         , p_value_type_code         => l_adr_value_type_code
25593         , p_transaction_coa_id      => l_adr_transaction_coa_id
25594         , p_accounting_coa_id       => l_adr_accounting_coa_id
25595         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
25596         , p_flex_value_set_id       => l_adr_flex_value_set_id
25597         , p_adr_code                => 'FV_AR_422101_MISC_RCT_CR'
25598         , p_adr_type_code           => 'S'
25599         , p_component_type          => l_component_type
25600         , p_component_code          => l_component_code
25601         , p_component_type_code     => l_component_type_code
25602         , p_component_appl_id       => l_component_appl_id
25603         , p_amb_context_code        => l_amb_context_code
25604         , p_entity_code             => 'RECEIPTS'
25605         , p_event_class_code        => 'MISC_RECEIPT'
25606         , p_side                    => 'NA'
25607         );
25608 
25609   END IF;
25610 
25611    l_segment := AcctDerRule_4(
25612            p_application_id           => p_application_id
25613          , p_ae_header_id             => l_ae_header_id 
25614 , p_source_3 => p_source_3
25615          , x_transaction_coa_id       => l_adr_transaction_coa_id
25616          , x_accounting_coa_id        => l_adr_accounting_coa_id
25617          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
25618          , x_flex_value_set_id        => l_adr_flex_value_set_id
25619          , x_value_type_code          => l_adr_value_type_code
25620          , x_value_combination_id     => l_adr_value_combination_id
25621          , x_value_segment_code       => l_adr_value_segment_code
25622          , p_side                     => 'NA'
25623          , p_override_seg_flag        => 'Y'
25624    );
25625 
25626    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
25627 
25628       xla_ae_lines_pkg.set_segment(
25629           p_to_segment_code         => 'GL_BALANCING'
25630         , p_segment_value           => l_segment
25631         , p_from_segment_code       => l_adr_value_segment_code
25632         , p_from_combination_id     => l_adr_value_combination_id
25633         , p_value_type_code         => l_adr_value_type_code
25634         , p_transaction_coa_id      => l_adr_transaction_coa_id
25635         , p_accounting_coa_id       => l_adr_accounting_coa_id
25636         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
25637         , p_flex_value_set_id       => l_adr_flex_value_set_id
25638         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
25639         , p_adr_type_code           => 'S'
25640         , p_component_type          => l_component_type
25641         , p_component_code          => l_component_code
25642         , p_component_type_code     => l_component_type_code
25643         , p_component_appl_id       => l_component_appl_id
25644         , p_amb_context_code        => l_amb_context_code
25645         , p_entity_code             => 'RECEIPTS'
25646         , p_event_class_code        => 'MISC_RECEIPT'
25647         , p_side                    => 'NA'
25648         );
25649 
25650   END IF;
25651 
25652    --
25653    --
25654    END IF;
25655    --
25656    -- Bug 4922099
25657    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
25658           (NVL(l_enc_upg_option, 'N') = 'O')
25659         ) AND
25660         (l_bflow_method_code = 'PRIOR_ENTRY')
25661       )
25662    THEN
25663       IF
25664       --
25665       1 = 2
25666       --
25667       THEN
25668       xla_accounting_err_pkg.build_message
25672                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
25669                                     (p_appli_s_name            => 'XLA'
25670                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
25671                                     ,p_token_1                 => 'LINE_NUMBER'
25673                                     ,p_token_2                 => 'LINE_TYPE_NAME'
25674                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
25675                                                                              l_component_type
25676                                                                             ,l_component_code
25677                                                                             ,l_component_type_code
25678                                                                             ,l_component_appl_id
25679                                                                             ,l_amb_context_code
25680                                                                             ,l_entity_code
25681                                                                             ,l_event_class_code
25682                                                                            )
25683                                     ,p_token_3                 => 'OWNER'
25684                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
25685                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
25686                                                                           ,p_lookup_code    => l_component_type_code
25687                                                                          )
25688                                     ,p_token_4                 => 'PRODUCT_NAME'
25689                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
25690                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
25691                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
25692                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
25693                                     ,p_ae_header_id            =>  NULL
25694                                        );
25695 
25696         IF (C_LEVEL_ERROR>= g_log_level) THEN
25697                  trace
25698                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
25699                       ,p_level    => C_LEVEL_ERROR
25700                       ,p_module   => l_log_module);
25701         END IF;
25702       END IF;
25703    END IF;
25704    --
25705    --
25706    ------------------------------------------------------------------------------------------------
25707    -- 4219869 Business Flow
25708    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
25709    -- Prior Entry.  Currently, the following code is always generated.
25710    ------------------------------------------------------------------------------------------------
25711    XLA_AE_LINES_PKG.ValidateCurrentLine;
25712 
25713    ------------------------------------------------------------------------------------
25714    -- 4219869 Business Flow
25715    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
25716    ------------------------------------------------------------------------------------
25717    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
25718 
25719    ----------------------------------------------------------------------------------
25720    -- 4219869 Business Flow
25721    -- Update journal entry status -- Need to generate this within IF <condition>
25722    ----------------------------------------------------------------------------------
25723    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
25724          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
25725          ,p_balance_type_code => l_balance_type_code
25726          );
25727 
25728    -------------------------------------------------------------------------------------------
25729    -- 4262811 - Generate the Accrual Reversal lines
25730    -------------------------------------------------------------------------------------------
25731    BEGIN
25732       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
25733                               (g_array_event(p_event_id).array_value_num('header_index'));
25734       IF l_acc_rev_flag IS NULL THEN
25735          l_acc_rev_flag := 'N';
25736       END IF;
25737    EXCEPTION
25738       WHEN OTHERS THEN
25739          l_acc_rev_flag := 'N';
25740    END;
25741    --
25742    IF (l_acc_rev_flag = 'Y') THEN
25743 
25744        -- 4645092  ------------------------------------------------------------------------------
25745        -- To allow MPA report to determine if it should generate report process
25746        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
25747        ------------------------------------------------------------------------------------------
25748 
25749        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
25750        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
25751    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
25752    -- call ADRs
25753    -- Bug 4922099
25754    --
25755    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
25756         (NVL(l_actual_upg_option, 'N') = 'O') OR
25757         (NVL(l_enc_upg_option, 'N') = 'O')
25758       )
25759    THEN
25760    NULL;
25764   l_ccid := AcctDerRule_25(
25761    --
25762    --
25763    
25765            p_application_id           => p_application_id
25766          , p_ae_header_id             => l_ae_header_id 
25767 , p_source_13 => p_source_13
25768          , x_transaction_coa_id       => l_adr_transaction_coa_id
25769          , x_accounting_coa_id        => l_adr_accounting_coa_id
25770          , x_value_type_code          => l_adr_value_type_code
25771          , p_side                     => 'NA'
25772    );
25773 
25774    xla_ae_lines_pkg.set_ccid(
25775     p_code_combination_id          => l_ccid
25776   , p_value_type_code              => l_adr_value_type_code
25777   , p_transaction_coa_id           => l_adr_transaction_coa_id
25778   , p_accounting_coa_id            => l_adr_accounting_coa_id
25779   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
25780   , p_adr_type_code                => 'S'
25781   , p_component_type               => l_component_type
25782   , p_component_code               => l_component_code
25783   , p_component_type_code          => l_component_type_code
25784   , p_component_appl_id            => l_component_appl_id
25785   , p_amb_context_code             => l_amb_context_code
25786   , p_side                         => 'NA'
25787   );
25788 
25789 
25790    l_segment := AcctDerRule_8(
25791            p_application_id           => p_application_id
25792          , p_ae_header_id             => l_ae_header_id 
25793 , p_source_5 => p_source_5
25794          , x_transaction_coa_id       => l_adr_transaction_coa_id
25795          , x_accounting_coa_id        => l_adr_accounting_coa_id
25796          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
25797          , x_flex_value_set_id        => l_adr_flex_value_set_id
25798          , x_value_type_code          => l_adr_value_type_code
25799          , x_value_combination_id     => l_adr_value_combination_id
25800          , x_value_segment_code       => l_adr_value_segment_code
25801          , p_side                     => 'NA'
25802          , p_override_seg_flag        => 'Y'
25803    );
25804 
25805    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
25806 
25807       xla_ae_lines_pkg.set_segment(
25808           p_to_segment_code         => 'GL_ACCOUNT'
25809         , p_segment_value           => l_segment
25810         , p_from_segment_code       => l_adr_value_segment_code
25811         , p_from_combination_id     => l_adr_value_combination_id
25812         , p_value_type_code         => l_adr_value_type_code
25813         , p_transaction_coa_id      => l_adr_transaction_coa_id
25814         , p_accounting_coa_id       => l_adr_accounting_coa_id
25815         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
25816         , p_flex_value_set_id       => l_adr_flex_value_set_id
25817         , p_adr_code                => 'FV_AR_422101_MISC_RCT_CR'
25818         , p_adr_type_code           => 'S'
25819         , p_component_type          => l_component_type
25820         , p_component_code          => l_component_code
25821         , p_component_type_code     => l_component_type_code
25822         , p_component_appl_id       => l_component_appl_id
25823         , p_amb_context_code        => l_amb_context_code
25824         , p_entity_code             => 'RECEIPTS'
25825         , p_event_class_code        => 'MISC_RECEIPT'
25826         , p_side                    => 'NA'
25827         );
25828 
25829   END IF;
25830 
25831    l_segment := AcctDerRule_4(
25832            p_application_id           => p_application_id
25833          , p_ae_header_id             => l_ae_header_id 
25834 , p_source_3 => p_source_3
25835          , x_transaction_coa_id       => l_adr_transaction_coa_id
25836          , x_accounting_coa_id        => l_adr_accounting_coa_id
25837          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
25838          , x_flex_value_set_id        => l_adr_flex_value_set_id
25839          , x_value_type_code          => l_adr_value_type_code
25840          , x_value_combination_id     => l_adr_value_combination_id
25841          , x_value_segment_code       => l_adr_value_segment_code
25842          , p_side                     => 'NA'
25843          , p_override_seg_flag        => 'Y'
25844    );
25845 
25846    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
25847 
25848       xla_ae_lines_pkg.set_segment(
25849           p_to_segment_code         => 'GL_BALANCING'
25850         , p_segment_value           => l_segment
25851         , p_from_segment_code       => l_adr_value_segment_code
25852         , p_from_combination_id     => l_adr_value_combination_id
25853         , p_value_type_code         => l_adr_value_type_code
25854         , p_transaction_coa_id      => l_adr_transaction_coa_id
25855         , p_accounting_coa_id       => l_adr_accounting_coa_id
25856         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
25857         , p_flex_value_set_id       => l_adr_flex_value_set_id
25858         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
25859         , p_adr_type_code           => 'S'
25860         , p_component_type          => l_component_type
25861         , p_component_code          => l_component_code
25862         , p_component_type_code     => l_component_type_code
25863         , p_component_appl_id       => l_component_appl_id
25864         , p_amb_context_code        => l_amb_context_code
25865         , p_entity_code             => 'RECEIPTS'
25866         , p_event_class_code        => 'MISC_RECEIPT'
25870   END IF;
25867         , p_side                    => 'NA'
25868         );
25869 
25871 
25872    --
25873    --
25874    END IF;
25875 
25876        --
25877        -- Update the line information that should be overwritten
25878        --
25879        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
25880                                          p_header_num   => 1);
25881        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
25882 
25883        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
25884 
25885        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
25886           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
25887        END IF;
25888 
25889       --
25890       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
25891       --
25892       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
25893           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
25894       ELSE
25895           ---------------------------------------------------------------------------------------------------
25896           -- 4262811a Switch Sign
25897           ---------------------------------------------------------------------------------------------------
25898           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
25899           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
25900                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
25901           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
25902                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
25903           -- 5132302
25904           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
25905                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
25906 
25907       END IF;
25908 
25909       -- 4955764
25910       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
25911       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
25912 
25913 
25914       XLA_AE_LINES_PKG.ValidateCurrentLine;
25915       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
25916 
25917       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
25918                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
25919                ,p_balance_type_code => l_balance_type_code);
25920 
25921    END IF;
25922 
25923    -----------------------------------------------------------------------------------------
25924    -- 4262811 Multiperiod Accounting
25925    -----------------------------------------------------------------------------------------
25926      -- No MPA option is assigned.
25927 
25928 
25929 END IF;
25930 END IF;
25931 --
25932 
25933 --
25934 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
25935    trace
25936       (p_msg      => 'END of AcctLineType_67'
25937       ,p_level    => C_LEVEL_PROCEDURE
25938       ,p_module   => l_log_module);
25939 END IF;
25940 --
25941 EXCEPTION
25942   WHEN xla_exceptions_pkg.application_exception THEN
25943       RAISE;
25944   WHEN OTHERS THEN
25945        xla_exceptions_pkg.raise_message
25946            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_67');
25947 END AcctLineType_67;
25948 --
25949 
25950 ---------------------------------------
25951 --
25952 -- PRIVATE FUNCTION
25953 --         AcctLineType_68
25954 --
25955 ---------------------------------------
25956 PROCEDURE AcctLineType_68 (
25957   p_application_id        IN NUMBER
25958  ,p_event_id              IN NUMBER
25959  ,p_calculate_acctd_flag  IN VARCHAR2
25960  ,p_calculate_g_l_flag    IN VARCHAR2
25961  ,p_actual_flag           IN OUT VARCHAR2
25962  ,p_balance_type_code     OUT VARCHAR2
25963  ,p_gain_or_loss_ref      OUT VARCHAR2
25964  
25965 --Distribution GL Account
25966  , p_source_3            IN NUMBER
25967 --Federal Fund Category
25968  , p_source_5            IN VARCHAR2
25969 --Remittance Bank Account Cash Account
25970  , p_source_13            IN NUMBER
25971 --Distribution Source Type
25972  , p_source_20            IN VARCHAR2
25973 --Distribution Line Identifier
25974  , p_source_22            IN NUMBER
25975 --Distribution Type
25976  , p_source_23            IN VARCHAR2
25977 --Entered Amount
25978  , p_source_24            IN NUMBER
25979 --Currency Code
25980  , p_source_25            IN VARCHAR2
25981 --Exchange Rate
25982  , p_source_27            IN NUMBER
25983 --Exchange Rate Type
25984  , p_source_28            IN VARCHAR2
25985 --Applied To Document Accounting Amount
25986  , p_source_29            IN NUMBER
25987 --Federal Account Valid Flag
25988  , p_source_56            IN VARCHAR2
25989 --Applied To Document Exchange Date
25990  , p_source_57            IN DATE
25991 )
25992 IS
25993 
25994 l_component_type              VARCHAR2(80);
25995 l_component_code              VARCHAR2(30);
25999 l_entity_code                 VARCHAR2(30);
25996 l_component_type_code         VARCHAR2(1);
25997 l_component_appl_id           INTEGER;
25998 l_amb_context_code            VARCHAR2(30);
26000 l_event_class_code            VARCHAR2(30);
26001 l_ae_header_id                NUMBER;
26002 l_event_type_code             VARCHAR2(30);
26003 l_line_definition_code        VARCHAR2(30);
26004 l_line_definition_owner_code  VARCHAR2(1);
26005 --
26006 -- adr variables
26007 l_segment                     VARCHAR2(30);
26008 l_ccid                        NUMBER;
26009 l_adr_transaction_coa_id      NUMBER;
26010 l_adr_accounting_coa_id       NUMBER;
26011 l_adr_flexfield_segment_code  VARCHAR2(30);
26012 l_adr_flex_value_set_id       NUMBER;
26013 l_adr_value_type_code         VARCHAR2(30);
26014 l_adr_value_combination_id    NUMBER;
26015 l_adr_value_segment_code      VARCHAR2(30);
26016 
26017 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
26018 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
26019 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
26020 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
26021 
26022 -- 4262811 Variables ------------------------------------------------------------------------------------------
26023 l_entered_amt_idx             NUMBER;
26024 l_accted_amt_idx              NUMBER;
26025 l_acc_rev_flag                VARCHAR2(1);
26026 l_accrual_line_num            NUMBER;
26027 l_tmp_amt                     NUMBER;
26028 l_acc_rev_natural_side_code   VARCHAR2(1);
26029 
26030 l_num_entries                 NUMBER;
26031 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
26032 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
26033 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
26034 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
26035 l_recog_line_1                NUMBER;
26036 l_recog_line_2                NUMBER;
26037 
26038 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
26039 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
26040 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
26041 
26042 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
26043 
26044 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
26045 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
26046 
26047 ---------------------------------------------------------------------------------------------------------------
26048 
26049 
26050 --
26051 -- bulk performance
26052 --
26053 l_balance_type_code           VARCHAR2(1);
26054 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
26055 l_log_module                  VARCHAR2(240);
26056 
26057 --
26058 -- Upgrade strategy
26059 --
26060 l_actual_upg_option           VARCHAR2(1);
26061 l_enc_upg_option           VARCHAR2(1);
26062 
26063 --
26064 BEGIN
26065 --
26066 IF g_log_enabled THEN
26067       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_68';
26068 END IF;
26069 --
26070 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
26071 
26072       trace
26073          (p_msg      => 'BEGIN of AcctLineType_68'
26074          ,p_level    => C_LEVEL_PROCEDURE
26075          ,p_module   => l_log_module);
26076 
26077 END IF;
26078 --
26079 l_component_type             := 'AMB_JLT';
26080 l_component_code             := 'FV_MISC_RCT_REIM_WO_ADV_DR';
26081 l_component_type_code        := 'S';
26082 l_component_appl_id          :=  222;
26083 l_amb_context_code           := 'DEFAULT';
26084 l_entity_code                := 'RECEIPTS';
26085 l_event_class_code           := 'MISC_RECEIPT';
26086 l_event_type_code            := 'MISC_RECEIPT_ALL';
26087 l_line_definition_owner_code := 'S';
26088 l_line_definition_code       := 'MFAR_FED_AR_MISC_REC_BALANCING';
26089 --
26090 l_balance_type_code          := 'A';
26091 l_segment                     := NULL;
26092 l_ccid                        := NULL;
26093 l_adr_transaction_coa_id      := NULL;
26094 l_adr_accounting_coa_id       := NULL;
26095 l_adr_flexfield_segment_code  := NULL;
26096 l_adr_flex_value_set_id       := NULL;
26097 l_adr_value_type_code         := NULL;
26098 l_adr_value_combination_id    := NULL;
26099 l_adr_value_segment_code      := NULL;
26100 
26101 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
26102 l_bflow_class_code           := '';    -- 4219869 Business Flow
26103 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
26104 l_budgetary_control_flag     := 'N';
26105 
26106 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
26107 l_bflow_applied_to_amt       := NULL; -- 5132302
26108 l_entered_amt_idx            := NULL;          -- 4262811
26109 l_accted_amt_idx             := NULL;          -- 4262811
26110 l_acc_rev_flag               := NULL;          -- 4262811
26111 l_accrual_line_num           := NULL;          -- 4262811
26112 l_tmp_amt                    := NULL;          -- 4262811
26113 --
26114  
26115 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
26116     l_balance_type_code <> 'B' THEN
26117 IF NVL(p_source_20,'
26118 ') =  'MISCCASH' AND 
26119 NVL(p_source_5,'
26120 ') =  'Reimbursable' AND 
26121 NVL(p_source_56,'
26122 ') =  'Y'
26123  THEN 
26124 
26125    --
26129    -- set the flag so later we will know whether the gain loss line needs to be created
26126    XLA_AE_LINES_PKG.SetNewLine;
26127 
26128    p_balance_type_code          := l_balance_type_code;
26130    
26131    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
26132      p_actual_flag :='A';
26133    END IF;
26134 
26135    --
26136    -- bulk performance
26137    --
26138    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
26139                                       p_header_num   => 0); -- 4262811
26140    --
26141    -- set accounting line options
26142    --
26143    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
26144            p_natural_side_code          => 'D'
26145          , p_gain_or_loss_flag          => 'N'
26146          , p_gl_transfer_mode_code      => 'S'
26147          , p_acct_entry_type_code       => 'A'
26148          , p_switch_side_flag           => 'Y'
26149          , p_merge_duplicate_code       => 'A'
26150          );
26151    --
26152    l_acc_rev_natural_side_code := 'C';  -- 4262811
26153    -- 
26154    --
26155    -- set accounting line type info
26156    --
26157    xla_ae_lines_pkg.SetAcctLineType
26158       (p_component_type             => l_component_type
26159       ,p_event_type_code            => l_event_type_code
26160       ,p_line_definition_owner_code => l_line_definition_owner_code
26161       ,p_line_definition_code       => l_line_definition_code
26162       ,p_accounting_line_code       => l_component_code
26163       ,p_accounting_line_type_code  => l_component_type_code
26164       ,p_accounting_line_appl_id    => l_component_appl_id
26165       ,p_amb_context_code           => l_amb_context_code
26166       ,p_entity_code                => l_entity_code
26167       ,p_event_class_code           => l_event_class_code);
26168    --
26169    -- set accounting class
26170    --
26171    xla_ae_lines_pkg.SetAcctClass(
26172            p_accounting_class_code  => 'FV_MISCCASH_DR'
26173          , p_ae_header_id           => l_ae_header_id
26174          );
26175 
26176    --
26177    -- set rounding class
26178    --
26179    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
26180                       'RECEIVABLE';
26181 
26182    --
26183    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
26184    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
26185    --
26186    -- bulk performance
26187    --
26188    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
26189 
26190    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
26191       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
26192 
26193    -- 4955764
26194    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
26195       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
26196 
26197    -- 4458381 Public Sector Enh
26198    
26199    --
26200    -- set accounting attributes for the line type
26201    --
26202    l_entered_amt_idx := 3;
26203    l_accted_amt_idx  := 8;
26204    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
26205    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
26206    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
26207    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
26208    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
26209    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
26210    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
26211    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
26212    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
26213    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
26214    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
26215    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
26216    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
26217    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
26218    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
26219    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
26220    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
26221 
26222    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
26223    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
26224 
26225    ---------------------------------------------------------------------------------------------------------------
26226    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
26227    ---------------------------------------------------------------------------------------------------------------
26228    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
26229 
26230    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
26231    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
26232 
26233    IF xla_accounting_cache_pkg.GetValueChar
26234          (p_source_code         => 'LEDGER_CATEGORY_CODE'
26235          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
26239          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
26236    AND l_bflow_method_code = 'PRIOR_ENTRY'
26237 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
26238    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
26240        )
26241    THEN
26242          xla_ae_lines_pkg.BflowUpgEntry
26243            (p_business_method_code    => l_bflow_method_code
26244            ,p_business_class_code     => l_bflow_class_code
26245            ,p_balance_type            => l_balance_type_code);
26246    ELSE
26247       NULL;
26248 -- No business flow processing for business flow method of NONE.
26249    END IF;
26250 
26251    --
26252    -- call analytical criteria
26253    --
26254    
26255    --
26256    -- call description
26257    --
26258    -- No description or it is inherited.
26259    --
26260    -- call ADRs
26261    -- Bug 4922099
26262    --
26263    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
26264         (NVL(l_actual_upg_option, 'N') = 'O') OR
26265         (NVL(l_enc_upg_option, 'N') = 'O')
26266       )
26267    THEN
26268    NULL;
26269    --
26270    --
26271    
26272   l_ccid := AcctDerRule_25(
26273            p_application_id           => p_application_id
26274          , p_ae_header_id             => l_ae_header_id 
26275 , p_source_13 => p_source_13
26276          , x_transaction_coa_id       => l_adr_transaction_coa_id
26277          , x_accounting_coa_id        => l_adr_accounting_coa_id
26278          , x_value_type_code          => l_adr_value_type_code
26279          , p_side                     => 'NA'
26280    );
26281 
26282    xla_ae_lines_pkg.set_ccid(
26283     p_code_combination_id          => l_ccid
26284   , p_value_type_code              => l_adr_value_type_code
26285   , p_transaction_coa_id           => l_adr_transaction_coa_id
26286   , p_accounting_coa_id            => l_adr_accounting_coa_id
26287   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
26288   , p_adr_type_code                => 'S'
26289   , p_component_type               => l_component_type
26290   , p_component_code               => l_component_code
26291   , p_component_type_code          => l_component_type_code
26292   , p_component_appl_id            => l_component_appl_id
26293   , p_amb_context_code             => l_amb_context_code
26294   , p_side                         => 'NA'
26295   );
26296 
26297 
26298    l_segment := AcctDerRule_11(
26299            p_application_id           => p_application_id
26300          , p_ae_header_id             => l_ae_header_id 
26301 , p_source_5 => p_source_5
26302          , x_transaction_coa_id       => l_adr_transaction_coa_id
26303          , x_accounting_coa_id        => l_adr_accounting_coa_id
26304          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
26305          , x_flex_value_set_id        => l_adr_flex_value_set_id
26306          , x_value_type_code          => l_adr_value_type_code
26307          , x_value_combination_id     => l_adr_value_combination_id
26308          , x_value_segment_code       => l_adr_value_segment_code
26309          , p_side                     => 'NA'
26310          , p_override_seg_flag        => 'Y'
26311    );
26312 
26313    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
26314 
26315       xla_ae_lines_pkg.set_segment(
26316           p_to_segment_code         => 'GL_ACCOUNT'
26317         , p_segment_value           => l_segment
26318         , p_from_segment_code       => l_adr_value_segment_code
26319         , p_from_combination_id     => l_adr_value_combination_id
26320         , p_value_type_code         => l_adr_value_type_code
26321         , p_transaction_coa_id      => l_adr_transaction_coa_id
26322         , p_accounting_coa_id       => l_adr_accounting_coa_id
26323         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
26324         , p_flex_value_set_id       => l_adr_flex_value_set_id
26325         , p_adr_code                => 'FV_AR_425201_MISC_RCT_DR'
26326         , p_adr_type_code           => 'S'
26327         , p_component_type          => l_component_type
26328         , p_component_code          => l_component_code
26329         , p_component_type_code     => l_component_type_code
26330         , p_component_appl_id       => l_component_appl_id
26331         , p_amb_context_code        => l_amb_context_code
26332         , p_entity_code             => 'RECEIPTS'
26333         , p_event_class_code        => 'MISC_RECEIPT'
26334         , p_side                    => 'NA'
26335         );
26336 
26337   END IF;
26338 
26339    l_segment := AcctDerRule_4(
26340            p_application_id           => p_application_id
26341          , p_ae_header_id             => l_ae_header_id 
26342 , p_source_3 => p_source_3
26343          , x_transaction_coa_id       => l_adr_transaction_coa_id
26344          , x_accounting_coa_id        => l_adr_accounting_coa_id
26345          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
26346          , x_flex_value_set_id        => l_adr_flex_value_set_id
26347          , x_value_type_code          => l_adr_value_type_code
26348          , x_value_combination_id     => l_adr_value_combination_id
26349          , x_value_segment_code       => l_adr_value_segment_code
26350          , p_side                     => 'NA'
26351          , p_override_seg_flag        => 'Y'
26352    );
26353 
26354    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
26355 
26356       xla_ae_lines_pkg.set_segment(
26360         , p_from_combination_id     => l_adr_value_combination_id
26357           p_to_segment_code         => 'GL_BALANCING'
26358         , p_segment_value           => l_segment
26359         , p_from_segment_code       => l_adr_value_segment_code
26361         , p_value_type_code         => l_adr_value_type_code
26362         , p_transaction_coa_id      => l_adr_transaction_coa_id
26363         , p_accounting_coa_id       => l_adr_accounting_coa_id
26364         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
26365         , p_flex_value_set_id       => l_adr_flex_value_set_id
26366         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
26367         , p_adr_type_code           => 'S'
26368         , p_component_type          => l_component_type
26369         , p_component_code          => l_component_code
26370         , p_component_type_code     => l_component_type_code
26371         , p_component_appl_id       => l_component_appl_id
26372         , p_amb_context_code        => l_amb_context_code
26373         , p_entity_code             => 'RECEIPTS'
26374         , p_event_class_code        => 'MISC_RECEIPT'
26375         , p_side                    => 'NA'
26376         );
26377 
26378   END IF;
26379 
26380    --
26381    --
26382    END IF;
26383    --
26384    -- Bug 4922099
26385    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
26386           (NVL(l_enc_upg_option, 'N') = 'O')
26387         ) AND
26388         (l_bflow_method_code = 'PRIOR_ENTRY')
26389       )
26390    THEN
26391       IF
26392       --
26393       1 = 2
26394       --
26395       THEN
26396       xla_accounting_err_pkg.build_message
26397                                     (p_appli_s_name            => 'XLA'
26398                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
26399                                     ,p_token_1                 => 'LINE_NUMBER'
26400                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
26401                                     ,p_token_2                 => 'LINE_TYPE_NAME'
26402                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
26403                                                                              l_component_type
26404                                                                             ,l_component_code
26405                                                                             ,l_component_type_code
26406                                                                             ,l_component_appl_id
26407                                                                             ,l_amb_context_code
26408                                                                             ,l_entity_code
26409                                                                             ,l_event_class_code
26410                                                                            )
26411                                     ,p_token_3                 => 'OWNER'
26412                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
26413                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
26414                                                                           ,p_lookup_code    => l_component_type_code
26415                                                                          )
26416                                     ,p_token_4                 => 'PRODUCT_NAME'
26417                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
26418                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
26419                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
26420                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
26421                                     ,p_ae_header_id            =>  NULL
26422                                        );
26423 
26424         IF (C_LEVEL_ERROR>= g_log_level) THEN
26425                  trace
26426                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
26427                       ,p_level    => C_LEVEL_ERROR
26428                       ,p_module   => l_log_module);
26429         END IF;
26430       END IF;
26431    END IF;
26432    --
26433    --
26434    ------------------------------------------------------------------------------------------------
26435    -- 4219869 Business Flow
26436    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
26437    -- Prior Entry.  Currently, the following code is always generated.
26438    ------------------------------------------------------------------------------------------------
26439    XLA_AE_LINES_PKG.ValidateCurrentLine;
26440 
26441    ------------------------------------------------------------------------------------
26442    -- 4219869 Business Flow
26443    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
26444    ------------------------------------------------------------------------------------
26445    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
26446 
26447    ----------------------------------------------------------------------------------
26448    -- 4219869 Business Flow
26449    -- Update journal entry status -- Need to generate this within IF <condition>
26453          ,p_balance_type_code => l_balance_type_code
26450    ----------------------------------------------------------------------------------
26451    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
26452          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
26454          );
26455 
26456    -------------------------------------------------------------------------------------------
26457    -- 4262811 - Generate the Accrual Reversal lines
26458    -------------------------------------------------------------------------------------------
26459    BEGIN
26460       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
26461                               (g_array_event(p_event_id).array_value_num('header_index'));
26462       IF l_acc_rev_flag IS NULL THEN
26463          l_acc_rev_flag := 'N';
26464       END IF;
26465    EXCEPTION
26466       WHEN OTHERS THEN
26467          l_acc_rev_flag := 'N';
26468    END;
26469    --
26470    IF (l_acc_rev_flag = 'Y') THEN
26471 
26472        -- 4645092  ------------------------------------------------------------------------------
26473        -- To allow MPA report to determine if it should generate report process
26474        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
26475        ------------------------------------------------------------------------------------------
26476 
26477        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
26478        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
26479    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
26480    -- call ADRs
26481    -- Bug 4922099
26482    --
26483    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
26484         (NVL(l_actual_upg_option, 'N') = 'O') OR
26485         (NVL(l_enc_upg_option, 'N') = 'O')
26486       )
26487    THEN
26488    NULL;
26489    --
26490    --
26491    
26492   l_ccid := AcctDerRule_25(
26493            p_application_id           => p_application_id
26494          , p_ae_header_id             => l_ae_header_id 
26495 , p_source_13 => p_source_13
26496          , x_transaction_coa_id       => l_adr_transaction_coa_id
26497          , x_accounting_coa_id        => l_adr_accounting_coa_id
26498          , x_value_type_code          => l_adr_value_type_code
26499          , p_side                     => 'NA'
26500    );
26501 
26502    xla_ae_lines_pkg.set_ccid(
26503     p_code_combination_id          => l_ccid
26504   , p_value_type_code              => l_adr_value_type_code
26505   , p_transaction_coa_id           => l_adr_transaction_coa_id
26506   , p_accounting_coa_id            => l_adr_accounting_coa_id
26507   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
26508   , p_adr_type_code                => 'S'
26509   , p_component_type               => l_component_type
26510   , p_component_code               => l_component_code
26511   , p_component_type_code          => l_component_type_code
26512   , p_component_appl_id            => l_component_appl_id
26513   , p_amb_context_code             => l_amb_context_code
26514   , p_side                         => 'NA'
26515   );
26516 
26517 
26518    l_segment := AcctDerRule_11(
26519            p_application_id           => p_application_id
26520          , p_ae_header_id             => l_ae_header_id 
26521 , p_source_5 => p_source_5
26522          , x_transaction_coa_id       => l_adr_transaction_coa_id
26523          , x_accounting_coa_id        => l_adr_accounting_coa_id
26524          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
26525          , x_flex_value_set_id        => l_adr_flex_value_set_id
26526          , x_value_type_code          => l_adr_value_type_code
26527          , x_value_combination_id     => l_adr_value_combination_id
26528          , x_value_segment_code       => l_adr_value_segment_code
26529          , p_side                     => 'NA'
26530          , p_override_seg_flag        => 'Y'
26531    );
26532 
26533    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
26534 
26535       xla_ae_lines_pkg.set_segment(
26536           p_to_segment_code         => 'GL_ACCOUNT'
26537         , p_segment_value           => l_segment
26538         , p_from_segment_code       => l_adr_value_segment_code
26539         , p_from_combination_id     => l_adr_value_combination_id
26540         , p_value_type_code         => l_adr_value_type_code
26541         , p_transaction_coa_id      => l_adr_transaction_coa_id
26542         , p_accounting_coa_id       => l_adr_accounting_coa_id
26543         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
26544         , p_flex_value_set_id       => l_adr_flex_value_set_id
26545         , p_adr_code                => 'FV_AR_425201_MISC_RCT_DR'
26546         , p_adr_type_code           => 'S'
26547         , p_component_type          => l_component_type
26548         , p_component_code          => l_component_code
26549         , p_component_type_code     => l_component_type_code
26550         , p_component_appl_id       => l_component_appl_id
26551         , p_amb_context_code        => l_amb_context_code
26552         , p_entity_code             => 'RECEIPTS'
26553         , p_event_class_code        => 'MISC_RECEIPT'
26554         , p_side                    => 'NA'
26555         );
26556 
26557   END IF;
26558 
26559    l_segment := AcctDerRule_4(
26560            p_application_id           => p_application_id
26561          , p_ae_header_id             => l_ae_header_id 
26562 , p_source_3 => p_source_3
26566          , x_flex_value_set_id        => l_adr_flex_value_set_id
26563          , x_transaction_coa_id       => l_adr_transaction_coa_id
26564          , x_accounting_coa_id        => l_adr_accounting_coa_id
26565          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
26567          , x_value_type_code          => l_adr_value_type_code
26568          , x_value_combination_id     => l_adr_value_combination_id
26569          , x_value_segment_code       => l_adr_value_segment_code
26570          , p_side                     => 'NA'
26571          , p_override_seg_flag        => 'Y'
26572    );
26573 
26574    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
26575 
26576       xla_ae_lines_pkg.set_segment(
26577           p_to_segment_code         => 'GL_BALANCING'
26578         , p_segment_value           => l_segment
26579         , p_from_segment_code       => l_adr_value_segment_code
26580         , p_from_combination_id     => l_adr_value_combination_id
26581         , p_value_type_code         => l_adr_value_type_code
26582         , p_transaction_coa_id      => l_adr_transaction_coa_id
26583         , p_accounting_coa_id       => l_adr_accounting_coa_id
26584         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
26585         , p_flex_value_set_id       => l_adr_flex_value_set_id
26586         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
26587         , p_adr_type_code           => 'S'
26588         , p_component_type          => l_component_type
26589         , p_component_code          => l_component_code
26590         , p_component_type_code     => l_component_type_code
26591         , p_component_appl_id       => l_component_appl_id
26592         , p_amb_context_code        => l_amb_context_code
26593         , p_entity_code             => 'RECEIPTS'
26594         , p_event_class_code        => 'MISC_RECEIPT'
26595         , p_side                    => 'NA'
26596         );
26597 
26598   END IF;
26599 
26600    --
26601    --
26602    END IF;
26603 
26604        --
26605        -- Update the line information that should be overwritten
26606        --
26607        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
26608                                          p_header_num   => 1);
26609        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
26610 
26611        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
26612 
26613        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
26614           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
26615        END IF;
26616 
26617       --
26618       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
26619       --
26620       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
26621           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
26622       ELSE
26623           ---------------------------------------------------------------------------------------------------
26624           -- 4262811a Switch Sign
26625           ---------------------------------------------------------------------------------------------------
26626           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
26627           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
26628                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
26629           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
26630                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
26631           -- 5132302
26632           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
26633                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
26634 
26635       END IF;
26636 
26637       -- 4955764
26638       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
26639       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
26640 
26641 
26642       XLA_AE_LINES_PKG.ValidateCurrentLine;
26643       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
26644 
26645       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
26646                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
26647                ,p_balance_type_code => l_balance_type_code);
26648 
26649    END IF;
26650 
26651    -----------------------------------------------------------------------------------------
26652    -- 4262811 Multiperiod Accounting
26653    -----------------------------------------------------------------------------------------
26654      -- No MPA option is assigned.
26655 
26656 
26657 END IF;
26658 END IF;
26659 --
26660 
26661 --
26662 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
26663    trace
26664       (p_msg      => 'END of AcctLineType_68'
26665       ,p_level    => C_LEVEL_PROCEDURE
26666       ,p_module   => l_log_module);
26667 END IF;
26668 --
26669 EXCEPTION
26670   WHEN xla_exceptions_pkg.application_exception THEN
26671       RAISE;
26672   WHEN OTHERS THEN
26673        xla_exceptions_pkg.raise_message
26674            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_68');
26675 END AcctLineType_68;
26679 --
26676 --
26677 
26678 ---------------------------------------
26680 -- PRIVATE FUNCTION
26681 --         AcctLineType_69
26682 --
26683 ---------------------------------------
26684 PROCEDURE AcctLineType_69 (
26685   p_application_id        IN NUMBER
26686  ,p_event_id              IN NUMBER
26687  ,p_calculate_acctd_flag  IN VARCHAR2
26688  ,p_calculate_g_l_flag    IN VARCHAR2
26689  ,p_actual_flag           IN OUT VARCHAR2
26690  ,p_balance_type_code     OUT VARCHAR2
26691  ,p_gain_or_loss_ref      OUT VARCHAR2
26692  
26693 --Distribution GL Account
26694  , p_source_3            IN NUMBER
26695 --Transaction Distribution GL Account
26696  , p_source_4            IN NUMBER
26697 --Federal Account Rule
26698  , p_source_7            IN VARCHAR2
26699 --Federal Fund Expired Status
26700  , p_source_8            IN VARCHAR2
26701 --Federal Prior Year Flag
26702  , p_source_9            IN VARCHAR2
26703 --Federal Fund Time Frame
26704  , p_source_10            IN VARCHAR2
26705 --Distribution Source Type
26706  , p_source_20            IN VARCHAR2
26707 --Distribution Line Identifier
26708  , p_source_22            IN NUMBER
26709 --Distribution Type
26710  , p_source_23            IN VARCHAR2
26711 --Entered Amount
26712  , p_source_24            IN NUMBER
26713 --Exchange Rate Type
26714  , p_source_28            IN VARCHAR2
26715 --Applied To Document Accounting Amount
26716  , p_source_29            IN NUMBER
26717 --Transaction Distribution Account Class
26718  , p_source_33            IN VARCHAR2
26719 --Transaction Distribution Identifier
26720  , p_source_34            IN NUMBER
26721 --Transaction Distribution Type
26722  , p_source_35            IN VARCHAR2
26723 --Federal Account Valid Flag
26724  , p_source_56            IN VARCHAR2
26725 --Applied To Document Exchange Date
26726  , p_source_57            IN DATE
26727 --Receipt Applied To Application Identifier
26728  , p_source_58            IN NUMBER
26729 --Transaction Entity Code
26730  , p_source_59            IN VARCHAR2
26731 --Transaction Identifier
26732  , p_source_60            IN NUMBER
26733 --Applying Document Currency Code
26734  , p_source_61            IN VARCHAR2
26735 --Applied To Document Exchange Rate
26736  , p_source_62            IN NUMBER
26737 --Distribution Party Identifier
26738  , p_source_63            IN NUMBER
26739 --Distribution Party Site Id
26740  , p_source_64            IN NUMBER
26741 --Distribution Party Type
26742  , p_source_65            IN VARCHAR2
26743 )
26744 IS
26745 
26746 l_component_type              VARCHAR2(80);
26747 l_component_code              VARCHAR2(30);
26748 l_component_type_code         VARCHAR2(1);
26749 l_component_appl_id           INTEGER;
26750 l_amb_context_code            VARCHAR2(30);
26751 l_entity_code                 VARCHAR2(30);
26752 l_event_class_code            VARCHAR2(30);
26753 l_ae_header_id                NUMBER;
26754 l_event_type_code             VARCHAR2(30);
26755 l_line_definition_code        VARCHAR2(30);
26756 l_line_definition_owner_code  VARCHAR2(1);
26757 --
26758 -- adr variables
26759 l_segment                     VARCHAR2(30);
26760 l_ccid                        NUMBER;
26761 l_adr_transaction_coa_id      NUMBER;
26762 l_adr_accounting_coa_id       NUMBER;
26763 l_adr_flexfield_segment_code  VARCHAR2(30);
26764 l_adr_flex_value_set_id       NUMBER;
26765 l_adr_value_type_code         VARCHAR2(30);
26766 l_adr_value_combination_id    NUMBER;
26767 l_adr_value_segment_code      VARCHAR2(30);
26768 
26769 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
26770 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
26771 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
26772 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
26773 
26774 -- 4262811 Variables ------------------------------------------------------------------------------------------
26775 l_entered_amt_idx             NUMBER;
26776 l_accted_amt_idx              NUMBER;
26777 l_acc_rev_flag                VARCHAR2(1);
26778 l_accrual_line_num            NUMBER;
26779 l_tmp_amt                     NUMBER;
26780 l_acc_rev_natural_side_code   VARCHAR2(1);
26781 
26782 l_num_entries                 NUMBER;
26783 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
26784 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
26785 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
26786 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
26787 l_recog_line_1                NUMBER;
26788 l_recog_line_2                NUMBER;
26789 
26790 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
26791 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
26792 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
26793 
26794 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
26795 
26796 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
26797 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
26798 
26799 ---------------------------------------------------------------------------------------------------------------
26800 
26801 
26802 --
26803 -- bulk performance
26804 --
26805 l_balance_type_code           VARCHAR2(1);
26809 --
26806 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
26807 l_log_module                  VARCHAR2(240);
26808 
26810 -- Upgrade strategy
26811 --
26812 l_actual_upg_option           VARCHAR2(1);
26813 l_enc_upg_option           VARCHAR2(1);
26814 
26815 --
26816 BEGIN
26817 --
26818 IF g_log_enabled THEN
26819       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_69';
26820 END IF;
26821 --
26822 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
26823 
26824       trace
26825          (p_msg      => 'BEGIN of AcctLineType_69'
26826          ,p_level    => C_LEVEL_PROCEDURE
26827          ,p_module   => l_log_module);
26828 
26829 END IF;
26830 --
26831 l_component_type             := 'AMB_JLT';
26832 l_component_code             := 'FV_RCT_REF_OAP_EF_CR';
26833 l_component_type_code        := 'S';
26834 l_component_appl_id          :=  222;
26835 l_amb_context_code           := 'DEFAULT';
26836 l_entity_code                := 'RECEIPTS';
26837 l_event_class_code           := 'RECEIPT';
26838 l_event_type_code            := 'RECEIPT_ALL';
26839 l_line_definition_owner_code := 'S';
26840 l_line_definition_code       := 'MFAR_FED_AR_RCT_BALANCING';
26841 --
26842 l_balance_type_code          := 'A';
26843 l_segment                     := NULL;
26844 l_ccid                        := NULL;
26845 l_adr_transaction_coa_id      := NULL;
26846 l_adr_accounting_coa_id       := NULL;
26847 l_adr_flexfield_segment_code  := NULL;
26848 l_adr_flex_value_set_id       := NULL;
26849 l_adr_value_type_code         := NULL;
26850 l_adr_value_combination_id    := NULL;
26851 l_adr_value_segment_code      := NULL;
26852 
26853 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
26854 l_bflow_class_code           := '';    -- 4219869 Business Flow
26855 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
26856 l_budgetary_control_flag     := 'N';
26857 
26858 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
26859 l_bflow_applied_to_amt       := NULL; -- 5132302
26860 l_entered_amt_idx            := NULL;          -- 4262811
26861 l_accted_amt_idx             := NULL;          -- 4262811
26862 l_acc_rev_flag               := NULL;          -- 4262811
26863 l_accrual_line_num           := NULL;          -- 4262811
26864 l_tmp_amt                    := NULL;          -- 4262811
26865 --
26866  
26867 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
26868     l_balance_type_code <> 'B' THEN
26869 IF NVL(p_source_20,'
26870 ') =  'REC' AND 
26871 NVL(p_source_33,'
26872 ') =  'REV' AND 
26873 NVL(p_source_8,'
26874 ') =  'Expired' AND 
26875 NVL(p_source_9,'
26876 ') =  'Y' AND 
26877 (NVL(p_source_10,'
26878 ') =  'SINGLE' OR 
26879 NVL(p_source_10,'
26880 ') =  'MULTIPLE' OR 
26881 NVL(p_source_10,'
26882 ') =  'NO_YEAR') AND 
26883 (NVL(p_source_7,'
26884 ') =  'Overpayment Refund' OR 
26885 NVL(p_source_7,'
26886 ') =  'Advance Refund') AND 
26887 NVL(p_source_56,'
26888 ') =  'Y'
26889  THEN 
26890 
26891    --
26892    XLA_AE_LINES_PKG.SetNewLine;
26893 
26894    p_balance_type_code          := l_balance_type_code;
26895    -- set the flag so later we will know whether the gain loss line needs to be created
26896    
26897    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
26898      p_actual_flag :='A';
26899    END IF;
26900 
26901    --
26902    -- bulk performance
26903    --
26904    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
26905                                       p_header_num   => 0); -- 4262811
26906    --
26907    -- set accounting line options
26908    --
26909    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
26910            p_natural_side_code          => 'C'
26911          , p_gain_or_loss_flag          => 'N'
26912          , p_gl_transfer_mode_code      => 'S'
26913          , p_acct_entry_type_code       => 'A'
26914          , p_switch_side_flag           => 'Y'
26915          , p_merge_duplicate_code       => 'A'
26916          );
26917    --
26918    l_acc_rev_natural_side_code := 'D';  -- 4262811
26919    -- 
26920    --
26921    -- set accounting line type info
26922    --
26923    xla_ae_lines_pkg.SetAcctLineType
26924       (p_component_type             => l_component_type
26925       ,p_event_type_code            => l_event_type_code
26926       ,p_line_definition_owner_code => l_line_definition_owner_code
26927       ,p_line_definition_code       => l_line_definition_code
26928       ,p_accounting_line_code       => l_component_code
26929       ,p_accounting_line_type_code  => l_component_type_code
26930       ,p_accounting_line_appl_id    => l_component_appl_id
26931       ,p_amb_context_code           => l_amb_context_code
26932       ,p_entity_code                => l_entity_code
26933       ,p_event_class_code           => l_event_class_code);
26934    --
26935    -- set accounting class
26936    --
26937    xla_ae_lines_pkg.SetAcctClass(
26938            p_accounting_class_code  => 'FV_CASH_CR'
26939          , p_ae_header_id           => l_ae_header_id
26940          );
26941 
26942    --
26943    -- set rounding class
26944    --
26945    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
26946                       'RECEIVABLE';
26950    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
26947 
26948    --
26949    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
26951    --
26952    -- bulk performance
26953    --
26954    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
26955 
26956    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
26957       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
26958 
26959    -- 4955764
26960    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
26961       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
26962 
26963    -- 4458381 Public Sector Enh
26964    
26965    --
26966    -- set accounting attributes for the line type
26967    --
26968    l_entered_amt_idx := 8;
26969    l_accted_amt_idx  := 13;
26970    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
26971    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
26972    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
26973    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
26974    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
26975    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
26976    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
26977    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
26978    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
26979    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
26980    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
26981    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
26982    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
26983    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
26984    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
26985    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
26986    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
26987    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
26988    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
26989    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
26990    l_rec_acct_attrs.array_date_value(10)  := p_source_57;
26991    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
26992    l_rec_acct_attrs.array_num_value(11)  := p_source_62;
26993    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
26994    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
26995    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
26996    l_rec_acct_attrs.array_num_value(13)  := p_source_29;
26997    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
26998    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
26999    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
27000    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
27001    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
27002    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
27003 
27004    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
27005    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
27006 
27007    ---------------------------------------------------------------------------------------------------------------
27008    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
27009    ---------------------------------------------------------------------------------------------------------------
27010    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
27011 
27012    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
27013    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
27014 
27015    IF xla_accounting_cache_pkg.GetValueChar
27016          (p_source_code         => 'LEDGER_CATEGORY_CODE'
27017          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
27018    AND l_bflow_method_code = 'PRIOR_ENTRY'
27019 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
27020    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
27021          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
27022        )
27023    THEN
27024          xla_ae_lines_pkg.BflowUpgEntry
27025            (p_business_method_code    => l_bflow_method_code
27026            ,p_business_class_code     => l_bflow_class_code
27027            ,p_balance_type            => l_balance_type_code);
27028    ELSE
27029       NULL;
27030 -- No business flow processing for business flow method of NONE.
27031    END IF;
27032 
27033    --
27034    -- call analytical criteria
27035    --
27036    
27037    --
27038    -- call description
27039    --
27040    -- No description or it is inherited.
27041    --
27042    -- call ADRs
27043    -- Bug 4922099
27044    --
27045    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
27046         (NVL(l_actual_upg_option, 'N') = 'O') OR
27047         (NVL(l_enc_upg_option, 'N') = 'O')
27048       )
27049    THEN
27050    NULL;
27051    --
27052    --
27053    
27057 , p_source_3 => p_source_3
27054   l_ccid := AcctDerRule_7(
27055            p_application_id           => p_application_id
27056          , p_ae_header_id             => l_ae_header_id 
27058          , x_transaction_coa_id       => l_adr_transaction_coa_id
27059          , x_accounting_coa_id        => l_adr_accounting_coa_id
27060          , x_value_type_code          => l_adr_value_type_code
27061          , p_side                     => 'NA'
27062    );
27063 
27064    xla_ae_lines_pkg.set_ccid(
27065     p_code_combination_id          => l_ccid
27066   , p_value_type_code              => l_adr_value_type_code
27067   , p_transaction_coa_id           => l_adr_transaction_coa_id
27068   , p_accounting_coa_id            => l_adr_accounting_coa_id
27069   , p_adr_code                     => 'DIST_CCID'
27070   , p_adr_type_code                => 'S'
27071   , p_component_type               => l_component_type
27072   , p_component_code               => l_component_code
27073   , p_component_type_code          => l_component_type_code
27074   , p_component_appl_id            => l_component_appl_id
27075   , p_amb_context_code             => l_amb_context_code
27076   , p_side                         => 'NA'
27077   );
27078 
27079 
27080    l_segment := AcctDerRule_17(
27081            p_application_id           => p_application_id
27082          , p_ae_header_id             => l_ae_header_id 
27083 , p_source_8 => p_source_8
27084 , p_source_9 => p_source_9
27085 , p_source_10 => p_source_10
27086          , x_transaction_coa_id       => l_adr_transaction_coa_id
27087          , x_accounting_coa_id        => l_adr_accounting_coa_id
27088          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
27089          , x_flex_value_set_id        => l_adr_flex_value_set_id
27090          , x_value_type_code          => l_adr_value_type_code
27091          , x_value_combination_id     => l_adr_value_combination_id
27092          , x_value_segment_code       => l_adr_value_segment_code
27093          , p_side                     => 'NA'
27094          , p_override_seg_flag        => 'Y'
27095    );
27096 
27097    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
27098 
27099       xla_ae_lines_pkg.set_segment(
27100           p_to_segment_code         => 'GL_ACCOUNT'
27101         , p_segment_value           => l_segment
27102         , p_from_segment_code       => l_adr_value_segment_code
27103         , p_from_combination_id     => l_adr_value_combination_id
27104         , p_value_type_code         => l_adr_value_type_code
27105         , p_transaction_coa_id      => l_adr_transaction_coa_id
27106         , p_accounting_coa_id       => l_adr_accounting_coa_id
27107         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
27108         , p_flex_value_set_id       => l_adr_flex_value_set_id
27109         , p_adr_code                => 'FV_AR_465002_RCT_CR'
27110         , p_adr_type_code           => 'S'
27111         , p_component_type          => l_component_type
27112         , p_component_code          => l_component_code
27113         , p_component_type_code     => l_component_type_code
27114         , p_component_appl_id       => l_component_appl_id
27115         , p_amb_context_code        => l_amb_context_code
27116         , p_entity_code             => 'RECEIPTS'
27117         , p_event_class_code        => 'RECEIPT'
27118         , p_side                    => 'NA'
27119         );
27120 
27121   END IF;
27122 
27123    l_segment := AcctDerRule_5(
27124            p_application_id           => p_application_id
27125          , p_ae_header_id             => l_ae_header_id 
27126 , p_source_4 => p_source_4
27127          , x_transaction_coa_id       => l_adr_transaction_coa_id
27128          , x_accounting_coa_id        => l_adr_accounting_coa_id
27129          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
27130          , x_flex_value_set_id        => l_adr_flex_value_set_id
27131          , x_value_type_code          => l_adr_value_type_code
27132          , x_value_combination_id     => l_adr_value_combination_id
27133          , x_value_segment_code       => l_adr_value_segment_code
27134          , p_side                     => 'NA'
27135          , p_override_seg_flag        => 'Y'
27136    );
27137 
27138    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
27139 
27140       xla_ae_lines_pkg.set_segment(
27141           p_to_segment_code         => 'GL_BALANCING'
27142         , p_segment_value           => l_segment
27143         , p_from_segment_code       => l_adr_value_segment_code
27144         , p_from_combination_id     => l_adr_value_combination_id
27145         , p_value_type_code         => l_adr_value_type_code
27146         , p_transaction_coa_id      => l_adr_transaction_coa_id
27147         , p_accounting_coa_id       => l_adr_accounting_coa_id
27148         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
27149         , p_flex_value_set_id       => l_adr_flex_value_set_id
27150         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
27151         , p_adr_type_code           => 'S'
27152         , p_component_type          => l_component_type
27153         , p_component_code          => l_component_code
27154         , p_component_type_code     => l_component_type_code
27155         , p_component_appl_id       => l_component_appl_id
27156         , p_amb_context_code        => l_amb_context_code
27157         , p_entity_code             => 'RECEIPTS'
27158         , p_event_class_code        => 'RECEIPT'
27159         , p_side                    => 'NA'
27160         );
27161 
27162   END IF;
27163 
27164    --
27168    -- Bug 4922099
27165    --
27166    END IF;
27167    --
27169    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
27170           (NVL(l_enc_upg_option, 'N') = 'O')
27171         ) AND
27172         (l_bflow_method_code = 'PRIOR_ENTRY')
27173       )
27174    THEN
27175       IF
27176       --
27177       1 = 2
27178       --
27179       THEN
27180       xla_accounting_err_pkg.build_message
27181                                     (p_appli_s_name            => 'XLA'
27182                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
27183                                     ,p_token_1                 => 'LINE_NUMBER'
27184                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
27185                                     ,p_token_2                 => 'LINE_TYPE_NAME'
27186                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
27187                                                                              l_component_type
27188                                                                             ,l_component_code
27189                                                                             ,l_component_type_code
27190                                                                             ,l_component_appl_id
27191                                                                             ,l_amb_context_code
27192                                                                             ,l_entity_code
27193                                                                             ,l_event_class_code
27194                                                                            )
27195                                     ,p_token_3                 => 'OWNER'
27196                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
27197                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
27198                                                                           ,p_lookup_code    => l_component_type_code
27199                                                                          )
27200                                     ,p_token_4                 => 'PRODUCT_NAME'
27201                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
27202                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
27203                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
27204                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
27205                                     ,p_ae_header_id            =>  NULL
27206                                        );
27207 
27208         IF (C_LEVEL_ERROR>= g_log_level) THEN
27209                  trace
27210                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
27211                       ,p_level    => C_LEVEL_ERROR
27212                       ,p_module   => l_log_module);
27213         END IF;
27214       END IF;
27215    END IF;
27216    --
27217    --
27218    ------------------------------------------------------------------------------------------------
27219    -- 4219869 Business Flow
27220    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
27221    -- Prior Entry.  Currently, the following code is always generated.
27222    ------------------------------------------------------------------------------------------------
27223    XLA_AE_LINES_PKG.ValidateCurrentLine;
27224 
27225    ------------------------------------------------------------------------------------
27226    -- 4219869 Business Flow
27227    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
27228    ------------------------------------------------------------------------------------
27229    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
27230 
27231    ----------------------------------------------------------------------------------
27232    -- 4219869 Business Flow
27233    -- Update journal entry status -- Need to generate this within IF <condition>
27234    ----------------------------------------------------------------------------------
27235    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
27236          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
27237          ,p_balance_type_code => l_balance_type_code
27238          );
27239 
27240    -------------------------------------------------------------------------------------------
27241    -- 4262811 - Generate the Accrual Reversal lines
27242    -------------------------------------------------------------------------------------------
27243    BEGIN
27244       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
27245                               (g_array_event(p_event_id).array_value_num('header_index'));
27246       IF l_acc_rev_flag IS NULL THEN
27247          l_acc_rev_flag := 'N';
27248       END IF;
27249    EXCEPTION
27250       WHEN OTHERS THEN
27251          l_acc_rev_flag := 'N';
27252    END;
27253    --
27254    IF (l_acc_rev_flag = 'Y') THEN
27255 
27256        -- 4645092  ------------------------------------------------------------------------------
27257        -- To allow MPA report to determine if it should generate report process
27258        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
27259        ------------------------------------------------------------------------------------------
27260 
27264    -- call ADRs
27261        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
27262        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
27263    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
27265    -- Bug 4922099
27266    --
27267    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
27268         (NVL(l_actual_upg_option, 'N') = 'O') OR
27269         (NVL(l_enc_upg_option, 'N') = 'O')
27270       )
27271    THEN
27272    NULL;
27273    --
27274    --
27275    
27276   l_ccid := AcctDerRule_7(
27277            p_application_id           => p_application_id
27278          , p_ae_header_id             => l_ae_header_id 
27279 , p_source_3 => p_source_3
27280          , x_transaction_coa_id       => l_adr_transaction_coa_id
27281          , x_accounting_coa_id        => l_adr_accounting_coa_id
27282          , x_value_type_code          => l_adr_value_type_code
27283          , p_side                     => 'NA'
27284    );
27285 
27286    xla_ae_lines_pkg.set_ccid(
27287     p_code_combination_id          => l_ccid
27288   , p_value_type_code              => l_adr_value_type_code
27289   , p_transaction_coa_id           => l_adr_transaction_coa_id
27290   , p_accounting_coa_id            => l_adr_accounting_coa_id
27291   , p_adr_code                     => 'DIST_CCID'
27292   , p_adr_type_code                => 'S'
27293   , p_component_type               => l_component_type
27294   , p_component_code               => l_component_code
27295   , p_component_type_code          => l_component_type_code
27296   , p_component_appl_id            => l_component_appl_id
27297   , p_amb_context_code             => l_amb_context_code
27298   , p_side                         => 'NA'
27299   );
27300 
27301 
27302    l_segment := AcctDerRule_17(
27303            p_application_id           => p_application_id
27304          , p_ae_header_id             => l_ae_header_id 
27305 , p_source_8 => p_source_8
27306 , p_source_9 => p_source_9
27307 , p_source_10 => p_source_10
27308          , x_transaction_coa_id       => l_adr_transaction_coa_id
27309          , x_accounting_coa_id        => l_adr_accounting_coa_id
27310          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
27311          , x_flex_value_set_id        => l_adr_flex_value_set_id
27312          , x_value_type_code          => l_adr_value_type_code
27313          , x_value_combination_id     => l_adr_value_combination_id
27314          , x_value_segment_code       => l_adr_value_segment_code
27315          , p_side                     => 'NA'
27316          , p_override_seg_flag        => 'Y'
27317    );
27318 
27319    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
27320 
27321       xla_ae_lines_pkg.set_segment(
27322           p_to_segment_code         => 'GL_ACCOUNT'
27323         , p_segment_value           => l_segment
27324         , p_from_segment_code       => l_adr_value_segment_code
27325         , p_from_combination_id     => l_adr_value_combination_id
27326         , p_value_type_code         => l_adr_value_type_code
27327         , p_transaction_coa_id      => l_adr_transaction_coa_id
27328         , p_accounting_coa_id       => l_adr_accounting_coa_id
27329         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
27330         , p_flex_value_set_id       => l_adr_flex_value_set_id
27331         , p_adr_code                => 'FV_AR_465002_RCT_CR'
27332         , p_adr_type_code           => 'S'
27333         , p_component_type          => l_component_type
27334         , p_component_code          => l_component_code
27335         , p_component_type_code     => l_component_type_code
27336         , p_component_appl_id       => l_component_appl_id
27337         , p_amb_context_code        => l_amb_context_code
27338         , p_entity_code             => 'RECEIPTS'
27339         , p_event_class_code        => 'RECEIPT'
27340         , p_side                    => 'NA'
27341         );
27342 
27343   END IF;
27344 
27345    l_segment := AcctDerRule_5(
27346            p_application_id           => p_application_id
27347          , p_ae_header_id             => l_ae_header_id 
27348 , p_source_4 => p_source_4
27349          , x_transaction_coa_id       => l_adr_transaction_coa_id
27350          , x_accounting_coa_id        => l_adr_accounting_coa_id
27351          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
27352          , x_flex_value_set_id        => l_adr_flex_value_set_id
27353          , x_value_type_code          => l_adr_value_type_code
27354          , x_value_combination_id     => l_adr_value_combination_id
27355          , x_value_segment_code       => l_adr_value_segment_code
27356          , p_side                     => 'NA'
27357          , p_override_seg_flag        => 'Y'
27358    );
27359 
27360    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
27361 
27362       xla_ae_lines_pkg.set_segment(
27363           p_to_segment_code         => 'GL_BALANCING'
27364         , p_segment_value           => l_segment
27365         , p_from_segment_code       => l_adr_value_segment_code
27366         , p_from_combination_id     => l_adr_value_combination_id
27367         , p_value_type_code         => l_adr_value_type_code
27368         , p_transaction_coa_id      => l_adr_transaction_coa_id
27369         , p_accounting_coa_id       => l_adr_accounting_coa_id
27370         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
27371         , p_flex_value_set_id       => l_adr_flex_value_set_id
27372         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
27376         , p_component_type_code     => l_component_type_code
27373         , p_adr_type_code           => 'S'
27374         , p_component_type          => l_component_type
27375         , p_component_code          => l_component_code
27377         , p_component_appl_id       => l_component_appl_id
27378         , p_amb_context_code        => l_amb_context_code
27379         , p_entity_code             => 'RECEIPTS'
27380         , p_event_class_code        => 'RECEIPT'
27381         , p_side                    => 'NA'
27382         );
27383 
27384   END IF;
27385 
27386    --
27387    --
27388    END IF;
27389 
27390        --
27391        -- Update the line information that should be overwritten
27392        --
27393        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
27394                                          p_header_num   => 1);
27395        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
27396 
27397        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
27398 
27399        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
27400           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
27401        END IF;
27402 
27403       --
27404       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
27405       --
27406       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
27407           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
27408       ELSE
27409           ---------------------------------------------------------------------------------------------------
27410           -- 4262811a Switch Sign
27411           ---------------------------------------------------------------------------------------------------
27412           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
27413           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
27414                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
27415           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
27416                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
27417           -- 5132302
27418           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
27419                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
27420 
27421       END IF;
27422 
27423       -- 4955764
27424       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
27425       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
27426 
27427 
27428       XLA_AE_LINES_PKG.ValidateCurrentLine;
27429       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
27430 
27431       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
27432                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
27433                ,p_balance_type_code => l_balance_type_code);
27434 
27435    END IF;
27436 
27437    -----------------------------------------------------------------------------------------
27438    -- 4262811 Multiperiod Accounting
27439    -----------------------------------------------------------------------------------------
27440      -- No MPA option is assigned.
27441 
27442 
27443 END IF;
27444 END IF;
27445 --
27446 
27447 --
27448 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
27449    trace
27450       (p_msg      => 'END of AcctLineType_69'
27451       ,p_level    => C_LEVEL_PROCEDURE
27452       ,p_module   => l_log_module);
27453 END IF;
27454 --
27455 EXCEPTION
27456   WHEN xla_exceptions_pkg.application_exception THEN
27457       RAISE;
27458   WHEN OTHERS THEN
27459        xla_exceptions_pkg.raise_message
27460            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_69');
27461 END AcctLineType_69;
27462 --
27463 
27464 ---------------------------------------
27465 --
27466 -- PRIVATE FUNCTION
27467 --         AcctLineType_70
27468 --
27469 ---------------------------------------
27470 PROCEDURE AcctLineType_70 (
27471   p_application_id        IN NUMBER
27472  ,p_event_id              IN NUMBER
27473  ,p_calculate_acctd_flag  IN VARCHAR2
27474  ,p_calculate_g_l_flag    IN VARCHAR2
27475  ,p_actual_flag           IN OUT VARCHAR2
27476  ,p_balance_type_code     OUT VARCHAR2
27477  ,p_gain_or_loss_ref      OUT VARCHAR2
27478  
27479 --Distribution GL Account
27480  , p_source_3            IN NUMBER
27481 --Transaction Distribution GL Account
27482  , p_source_4            IN NUMBER
27483 --Federal Account Rule
27484  , p_source_7            IN VARCHAR2
27485 --Federal Fund Expired Status
27486  , p_source_8            IN VARCHAR2
27487 --Federal Prior Year Flag
27488  , p_source_9            IN VARCHAR2
27489 --Federal Fund Time Frame
27490  , p_source_10            IN VARCHAR2
27491 --Distribution Source Type
27492  , p_source_20            IN VARCHAR2
27493 --Distribution Line Identifier
27494  , p_source_22            IN NUMBER
27495 --Distribution Type
27496  , p_source_23            IN VARCHAR2
27500  , p_source_28            IN VARCHAR2
27497 --Entered Amount
27498  , p_source_24            IN NUMBER
27499 --Exchange Rate Type
27501 --Applied To Document Accounting Amount
27502  , p_source_29            IN NUMBER
27503 --Transaction Distribution Account Class
27504  , p_source_33            IN VARCHAR2
27505 --Transaction Distribution Identifier
27506  , p_source_34            IN NUMBER
27507 --Transaction Distribution Type
27508  , p_source_35            IN VARCHAR2
27509 --Federal Account Valid Flag
27510  , p_source_56            IN VARCHAR2
27511 --Applied To Document Exchange Date
27512  , p_source_57            IN DATE
27513 --Receipt Applied To Application Identifier
27514  , p_source_58            IN NUMBER
27515 --Transaction Entity Code
27516  , p_source_59            IN VARCHAR2
27517 --Transaction Identifier
27518  , p_source_60            IN NUMBER
27519 --Applying Document Currency Code
27520  , p_source_61            IN VARCHAR2
27521 --Applied To Document Exchange Rate
27522  , p_source_62            IN NUMBER
27523 --Distribution Party Identifier
27524  , p_source_63            IN NUMBER
27525 --Distribution Party Site Id
27526  , p_source_64            IN NUMBER
27527 --Distribution Party Type
27528  , p_source_65            IN VARCHAR2
27529 )
27530 IS
27531 
27532 l_component_type              VARCHAR2(80);
27533 l_component_code              VARCHAR2(30);
27534 l_component_type_code         VARCHAR2(1);
27535 l_component_appl_id           INTEGER;
27536 l_amb_context_code            VARCHAR2(30);
27537 l_entity_code                 VARCHAR2(30);
27538 l_event_class_code            VARCHAR2(30);
27539 l_ae_header_id                NUMBER;
27540 l_event_type_code             VARCHAR2(30);
27541 l_line_definition_code        VARCHAR2(30);
27542 l_line_definition_owner_code  VARCHAR2(1);
27543 --
27544 -- adr variables
27545 l_segment                     VARCHAR2(30);
27546 l_ccid                        NUMBER;
27547 l_adr_transaction_coa_id      NUMBER;
27548 l_adr_accounting_coa_id       NUMBER;
27549 l_adr_flexfield_segment_code  VARCHAR2(30);
27550 l_adr_flex_value_set_id       NUMBER;
27551 l_adr_value_type_code         VARCHAR2(30);
27552 l_adr_value_combination_id    NUMBER;
27553 l_adr_value_segment_code      VARCHAR2(30);
27554 
27555 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
27556 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
27557 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
27558 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
27559 
27560 -- 4262811 Variables ------------------------------------------------------------------------------------------
27561 l_entered_amt_idx             NUMBER;
27562 l_accted_amt_idx              NUMBER;
27563 l_acc_rev_flag                VARCHAR2(1);
27564 l_accrual_line_num            NUMBER;
27565 l_tmp_amt                     NUMBER;
27566 l_acc_rev_natural_side_code   VARCHAR2(1);
27567 
27568 l_num_entries                 NUMBER;
27569 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
27570 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
27571 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
27572 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
27573 l_recog_line_1                NUMBER;
27574 l_recog_line_2                NUMBER;
27575 
27576 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
27577 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
27578 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
27579 
27580 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
27581 
27582 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
27583 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
27584 
27585 ---------------------------------------------------------------------------------------------------------------
27586 
27587 
27588 --
27589 -- bulk performance
27590 --
27591 l_balance_type_code           VARCHAR2(1);
27592 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
27593 l_log_module                  VARCHAR2(240);
27594 
27595 --
27596 -- Upgrade strategy
27597 --
27598 l_actual_upg_option           VARCHAR2(1);
27599 l_enc_upg_option           VARCHAR2(1);
27600 
27601 --
27602 BEGIN
27603 --
27604 IF g_log_enabled THEN
27605       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_70';
27606 END IF;
27607 --
27608 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
27609 
27610       trace
27611          (p_msg      => 'BEGIN of AcctLineType_70'
27612          ,p_level    => C_LEVEL_PROCEDURE
27613          ,p_module   => l_log_module);
27614 
27615 END IF;
27616 --
27617 l_component_type             := 'AMB_JLT';
27618 l_component_code             := 'FV_RCT_REF_OAP_EF_DR';
27619 l_component_type_code        := 'S';
27620 l_component_appl_id          :=  222;
27621 l_amb_context_code           := 'DEFAULT';
27622 l_entity_code                := 'RECEIPTS';
27623 l_event_class_code           := 'RECEIPT';
27624 l_event_type_code            := 'RECEIPT_ALL';
27625 l_line_definition_owner_code := 'S';
27626 l_line_definition_code       := 'MFAR_FED_AR_RCT_BALANCING';
27630 l_ccid                        := NULL;
27627 --
27628 l_balance_type_code          := 'A';
27629 l_segment                     := NULL;
27631 l_adr_transaction_coa_id      := NULL;
27632 l_adr_accounting_coa_id       := NULL;
27633 l_adr_flexfield_segment_code  := NULL;
27634 l_adr_flex_value_set_id       := NULL;
27635 l_adr_value_type_code         := NULL;
27636 l_adr_value_combination_id    := NULL;
27637 l_adr_value_segment_code      := NULL;
27638 
27639 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
27640 l_bflow_class_code           := '';    -- 4219869 Business Flow
27641 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
27642 l_budgetary_control_flag     := 'N';
27643 
27644 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
27645 l_bflow_applied_to_amt       := NULL; -- 5132302
27646 l_entered_amt_idx            := NULL;          -- 4262811
27647 l_accted_amt_idx             := NULL;          -- 4262811
27648 l_acc_rev_flag               := NULL;          -- 4262811
27649 l_accrual_line_num           := NULL;          -- 4262811
27650 l_tmp_amt                    := NULL;          -- 4262811
27651 --
27652  
27653 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
27654     l_balance_type_code <> 'B' THEN
27655 IF NVL(p_source_20,'
27656 ') =  'REC' AND 
27657 NVL(p_source_33,'
27658 ') =  'REV' AND 
27659 NVL(p_source_8,'
27660 ') =  'Expired' AND 
27661 NVL(p_source_9,'
27662 ') =  'Y' AND 
27663 (NVL(p_source_10,'
27664 ') =  'SINGLE' OR 
27665 NVL(p_source_10,'
27666 ') =  'MULTIPLE' OR 
27667 NVL(p_source_10,'
27668 ') =  'NO_YEAR') AND 
27669 (NVL(p_source_7,'
27670 ') =  'Overpayment Refund' OR 
27671 NVL(p_source_7,'
27672 ') =  'Advance Refund') AND 
27673 NVL(p_source_56,'
27674 ') =  'Y'
27675  THEN 
27676 
27677    --
27678    XLA_AE_LINES_PKG.SetNewLine;
27679 
27680    p_balance_type_code          := l_balance_type_code;
27681    -- set the flag so later we will know whether the gain loss line needs to be created
27682    
27683    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
27684      p_actual_flag :='A';
27685    END IF;
27686 
27687    --
27688    -- bulk performance
27689    --
27690    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
27691                                       p_header_num   => 0); -- 4262811
27692    --
27693    -- set accounting line options
27694    --
27695    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
27696            p_natural_side_code          => 'D'
27697          , p_gain_or_loss_flag          => 'N'
27698          , p_gl_transfer_mode_code      => 'S'
27699          , p_acct_entry_type_code       => 'A'
27700          , p_switch_side_flag           => 'Y'
27701          , p_merge_duplicate_code       => 'A'
27702          );
27703    --
27704    l_acc_rev_natural_side_code := 'C';  -- 4262811
27705    -- 
27706    --
27707    -- set accounting line type info
27708    --
27709    xla_ae_lines_pkg.SetAcctLineType
27710       (p_component_type             => l_component_type
27711       ,p_event_type_code            => l_event_type_code
27712       ,p_line_definition_owner_code => l_line_definition_owner_code
27713       ,p_line_definition_code       => l_line_definition_code
27714       ,p_accounting_line_code       => l_component_code
27715       ,p_accounting_line_type_code  => l_component_type_code
27716       ,p_accounting_line_appl_id    => l_component_appl_id
27717       ,p_amb_context_code           => l_amb_context_code
27718       ,p_entity_code                => l_entity_code
27719       ,p_event_class_code           => l_event_class_code);
27720    --
27721    -- set accounting class
27722    --
27723    xla_ae_lines_pkg.SetAcctClass(
27724            p_accounting_class_code  => 'FV_CASH_DR'
27725          , p_ae_header_id           => l_ae_header_id
27726          );
27727 
27728    --
27729    -- set rounding class
27730    --
27731    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
27732                       'RECEIVABLE';
27733 
27734    --
27735    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
27736    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
27737    --
27738    -- bulk performance
27739    --
27740    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
27741 
27742    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
27743       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
27744 
27745    -- 4955764
27746    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
27747       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
27748 
27749    -- 4458381 Public Sector Enh
27750    
27751    --
27752    -- set accounting attributes for the line type
27753    --
27754    l_entered_amt_idx := 8;
27755    l_accted_amt_idx  := 13;
27756    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
27757    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
27758    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
27759    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
27763    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
27760    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
27761    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
27762    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
27764    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
27765    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
27766    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
27767    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
27768    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
27769    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
27770    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
27771    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
27772    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
27773    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
27774    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
27775    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
27776    l_rec_acct_attrs.array_date_value(10)  := p_source_57;
27777    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
27778    l_rec_acct_attrs.array_num_value(11)  := p_source_62;
27779    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
27780    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
27781    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
27782    l_rec_acct_attrs.array_num_value(13)  := p_source_29;
27783    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
27784    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
27785    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
27786    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
27787    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
27788    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
27789 
27790    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
27791    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
27792 
27793    ---------------------------------------------------------------------------------------------------------------
27794    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
27795    ---------------------------------------------------------------------------------------------------------------
27796    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
27797 
27798    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
27799    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
27800 
27801    IF xla_accounting_cache_pkg.GetValueChar
27802          (p_source_code         => 'LEDGER_CATEGORY_CODE'
27803          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
27804    AND l_bflow_method_code = 'PRIOR_ENTRY'
27805 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
27806    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
27807          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
27808        )
27809    THEN
27810          xla_ae_lines_pkg.BflowUpgEntry
27811            (p_business_method_code    => l_bflow_method_code
27812            ,p_business_class_code     => l_bflow_class_code
27813            ,p_balance_type            => l_balance_type_code);
27814    ELSE
27815       NULL;
27816 -- No business flow processing for business flow method of NONE.
27817    END IF;
27818 
27819    --
27820    -- call analytical criteria
27821    --
27822    
27823    --
27824    -- call description
27825    --
27826    -- No description or it is inherited.
27827    --
27828    -- call ADRs
27829    -- Bug 4922099
27830    --
27831    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
27832         (NVL(l_actual_upg_option, 'N') = 'O') OR
27833         (NVL(l_enc_upg_option, 'N') = 'O')
27834       )
27835    THEN
27836    NULL;
27837    --
27838    --
27839    
27840   l_ccid := AcctDerRule_7(
27841            p_application_id           => p_application_id
27842          , p_ae_header_id             => l_ae_header_id 
27843 , p_source_3 => p_source_3
27844          , x_transaction_coa_id       => l_adr_transaction_coa_id
27845          , x_accounting_coa_id        => l_adr_accounting_coa_id
27846          , x_value_type_code          => l_adr_value_type_code
27847          , p_side                     => 'NA'
27848    );
27849 
27850    xla_ae_lines_pkg.set_ccid(
27851     p_code_combination_id          => l_ccid
27852   , p_value_type_code              => l_adr_value_type_code
27853   , p_transaction_coa_id           => l_adr_transaction_coa_id
27854   , p_accounting_coa_id            => l_adr_accounting_coa_id
27855   , p_adr_code                     => 'DIST_CCID'
27856   , p_adr_type_code                => 'S'
27857   , p_component_type               => l_component_type
27858   , p_component_code               => l_component_code
27859   , p_component_type_code          => l_component_type_code
27860   , p_component_appl_id            => l_component_appl_id
27861   , p_amb_context_code             => l_amb_context_code
27862   , p_side                         => 'NA'
27863   );
27864 
27865 
27866    l_segment := AcctDerRule_23(
27867            p_application_id           => p_application_id
27868          , p_ae_header_id             => l_ae_header_id 
27869 , p_source_7 => p_source_7
27873          , x_transaction_coa_id       => l_adr_transaction_coa_id
27870 , p_source_8 => p_source_8
27871 , p_source_9 => p_source_9
27872 , p_source_10 => p_source_10
27874          , x_accounting_coa_id        => l_adr_accounting_coa_id
27875          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
27876          , x_flex_value_set_id        => l_adr_flex_value_set_id
27877          , x_value_type_code          => l_adr_value_type_code
27878          , x_value_combination_id     => l_adr_value_combination_id
27879          , x_value_segment_code       => l_adr_value_segment_code
27880          , p_side                     => 'NA'
27881          , p_override_seg_flag        => 'Y'
27882    );
27883 
27884    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
27885 
27886       xla_ae_lines_pkg.set_segment(
27887           p_to_segment_code         => 'GL_ACCOUNT'
27888         , p_segment_value           => l_segment
27889         , p_from_segment_code       => l_adr_value_segment_code
27890         , p_from_combination_id     => l_adr_value_combination_id
27891         , p_value_type_code         => l_adr_value_type_code
27892         , p_transaction_coa_id      => l_adr_transaction_coa_id
27893         , p_accounting_coa_id       => l_adr_accounting_coa_id
27894         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
27895         , p_flex_value_set_id       => l_adr_flex_value_set_id
27896         , p_adr_code                => 'FV_AR_4X7201_RCT_DR'
27897         , p_adr_type_code           => 'S'
27898         , p_component_type          => l_component_type
27899         , p_component_code          => l_component_code
27900         , p_component_type_code     => l_component_type_code
27901         , p_component_appl_id       => l_component_appl_id
27902         , p_amb_context_code        => l_amb_context_code
27903         , p_entity_code             => 'RECEIPTS'
27904         , p_event_class_code        => 'RECEIPT'
27905         , p_side                    => 'NA'
27906         );
27907 
27908   END IF;
27909 
27910    l_segment := AcctDerRule_5(
27911            p_application_id           => p_application_id
27912          , p_ae_header_id             => l_ae_header_id 
27913 , p_source_4 => p_source_4
27914          , x_transaction_coa_id       => l_adr_transaction_coa_id
27915          , x_accounting_coa_id        => l_adr_accounting_coa_id
27916          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
27917          , x_flex_value_set_id        => l_adr_flex_value_set_id
27918          , x_value_type_code          => l_adr_value_type_code
27919          , x_value_combination_id     => l_adr_value_combination_id
27920          , x_value_segment_code       => l_adr_value_segment_code
27921          , p_side                     => 'NA'
27922          , p_override_seg_flag        => 'Y'
27923    );
27924 
27925    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
27926 
27927       xla_ae_lines_pkg.set_segment(
27928           p_to_segment_code         => 'GL_BALANCING'
27929         , p_segment_value           => l_segment
27930         , p_from_segment_code       => l_adr_value_segment_code
27931         , p_from_combination_id     => l_adr_value_combination_id
27932         , p_value_type_code         => l_adr_value_type_code
27933         , p_transaction_coa_id      => l_adr_transaction_coa_id
27934         , p_accounting_coa_id       => l_adr_accounting_coa_id
27935         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
27936         , p_flex_value_set_id       => l_adr_flex_value_set_id
27937         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
27938         , p_adr_type_code           => 'S'
27939         , p_component_type          => l_component_type
27940         , p_component_code          => l_component_code
27941         , p_component_type_code     => l_component_type_code
27942         , p_component_appl_id       => l_component_appl_id
27943         , p_amb_context_code        => l_amb_context_code
27944         , p_entity_code             => 'RECEIPTS'
27945         , p_event_class_code        => 'RECEIPT'
27946         , p_side                    => 'NA'
27947         );
27948 
27949   END IF;
27950 
27951    --
27952    --
27953    END IF;
27954    --
27955    -- Bug 4922099
27956    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
27957           (NVL(l_enc_upg_option, 'N') = 'O')
27958         ) AND
27959         (l_bflow_method_code = 'PRIOR_ENTRY')
27960       )
27961    THEN
27962       IF
27963       --
27964       1 = 2
27965       --
27966       THEN
27967       xla_accounting_err_pkg.build_message
27968                                     (p_appli_s_name            => 'XLA'
27969                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
27970                                     ,p_token_1                 => 'LINE_NUMBER'
27971                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
27972                                     ,p_token_2                 => 'LINE_TYPE_NAME'
27973                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
27974                                                                              l_component_type
27975                                                                             ,l_component_code
27976                                                                             ,l_component_type_code
27977                                                                             ,l_component_appl_id
27981                                                                            )
27978                                                                             ,l_amb_context_code
27979                                                                             ,l_entity_code
27980                                                                             ,l_event_class_code
27982                                     ,p_token_3                 => 'OWNER'
27983                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
27984                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
27985                                                                           ,p_lookup_code    => l_component_type_code
27986                                                                          )
27987                                     ,p_token_4                 => 'PRODUCT_NAME'
27988                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
27989                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
27990                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
27991                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
27992                                     ,p_ae_header_id            =>  NULL
27993                                        );
27994 
27995         IF (C_LEVEL_ERROR>= g_log_level) THEN
27996                  trace
27997                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
27998                       ,p_level    => C_LEVEL_ERROR
27999                       ,p_module   => l_log_module);
28000         END IF;
28001       END IF;
28002    END IF;
28003    --
28004    --
28005    ------------------------------------------------------------------------------------------------
28006    -- 4219869 Business Flow
28007    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
28008    -- Prior Entry.  Currently, the following code is always generated.
28009    ------------------------------------------------------------------------------------------------
28010    XLA_AE_LINES_PKG.ValidateCurrentLine;
28011 
28012    ------------------------------------------------------------------------------------
28013    -- 4219869 Business Flow
28014    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
28015    ------------------------------------------------------------------------------------
28016    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
28017 
28018    ----------------------------------------------------------------------------------
28019    -- 4219869 Business Flow
28020    -- Update journal entry status -- Need to generate this within IF <condition>
28021    ----------------------------------------------------------------------------------
28022    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
28023          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
28024          ,p_balance_type_code => l_balance_type_code
28025          );
28026 
28027    -------------------------------------------------------------------------------------------
28028    -- 4262811 - Generate the Accrual Reversal lines
28029    -------------------------------------------------------------------------------------------
28030    BEGIN
28031       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
28032                               (g_array_event(p_event_id).array_value_num('header_index'));
28033       IF l_acc_rev_flag IS NULL THEN
28034          l_acc_rev_flag := 'N';
28035       END IF;
28036    EXCEPTION
28037       WHEN OTHERS THEN
28038          l_acc_rev_flag := 'N';
28039    END;
28040    --
28041    IF (l_acc_rev_flag = 'Y') THEN
28042 
28043        -- 4645092  ------------------------------------------------------------------------------
28044        -- To allow MPA report to determine if it should generate report process
28045        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
28046        ------------------------------------------------------------------------------------------
28047 
28048        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
28049        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
28050    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
28051    -- call ADRs
28052    -- Bug 4922099
28053    --
28054    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
28055         (NVL(l_actual_upg_option, 'N') = 'O') OR
28056         (NVL(l_enc_upg_option, 'N') = 'O')
28057       )
28058    THEN
28059    NULL;
28060    --
28061    --
28062    
28063   l_ccid := AcctDerRule_7(
28064            p_application_id           => p_application_id
28065          , p_ae_header_id             => l_ae_header_id 
28066 , p_source_3 => p_source_3
28067          , x_transaction_coa_id       => l_adr_transaction_coa_id
28068          , x_accounting_coa_id        => l_adr_accounting_coa_id
28069          , x_value_type_code          => l_adr_value_type_code
28070          , p_side                     => 'NA'
28071    );
28072 
28073    xla_ae_lines_pkg.set_ccid(
28074     p_code_combination_id          => l_ccid
28075   , p_value_type_code              => l_adr_value_type_code
28076   , p_transaction_coa_id           => l_adr_transaction_coa_id
28080   , p_component_type               => l_component_type
28077   , p_accounting_coa_id            => l_adr_accounting_coa_id
28078   , p_adr_code                     => 'DIST_CCID'
28079   , p_adr_type_code                => 'S'
28081   , p_component_code               => l_component_code
28082   , p_component_type_code          => l_component_type_code
28083   , p_component_appl_id            => l_component_appl_id
28084   , p_amb_context_code             => l_amb_context_code
28085   , p_side                         => 'NA'
28086   );
28087 
28088 
28089    l_segment := AcctDerRule_23(
28090            p_application_id           => p_application_id
28091          , p_ae_header_id             => l_ae_header_id 
28092 , p_source_7 => p_source_7
28093 , p_source_8 => p_source_8
28094 , p_source_9 => p_source_9
28095 , p_source_10 => p_source_10
28096          , x_transaction_coa_id       => l_adr_transaction_coa_id
28097          , x_accounting_coa_id        => l_adr_accounting_coa_id
28098          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
28099          , x_flex_value_set_id        => l_adr_flex_value_set_id
28100          , x_value_type_code          => l_adr_value_type_code
28101          , x_value_combination_id     => l_adr_value_combination_id
28102          , x_value_segment_code       => l_adr_value_segment_code
28103          , p_side                     => 'NA'
28104          , p_override_seg_flag        => 'Y'
28105    );
28106 
28107    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
28108 
28109       xla_ae_lines_pkg.set_segment(
28110           p_to_segment_code         => 'GL_ACCOUNT'
28111         , p_segment_value           => l_segment
28112         , p_from_segment_code       => l_adr_value_segment_code
28113         , p_from_combination_id     => l_adr_value_combination_id
28114         , p_value_type_code         => l_adr_value_type_code
28115         , p_transaction_coa_id      => l_adr_transaction_coa_id
28116         , p_accounting_coa_id       => l_adr_accounting_coa_id
28117         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
28118         , p_flex_value_set_id       => l_adr_flex_value_set_id
28119         , p_adr_code                => 'FV_AR_4X7201_RCT_DR'
28120         , p_adr_type_code           => 'S'
28121         , p_component_type          => l_component_type
28122         , p_component_code          => l_component_code
28123         , p_component_type_code     => l_component_type_code
28124         , p_component_appl_id       => l_component_appl_id
28125         , p_amb_context_code        => l_amb_context_code
28126         , p_entity_code             => 'RECEIPTS'
28127         , p_event_class_code        => 'RECEIPT'
28128         , p_side                    => 'NA'
28129         );
28130 
28131   END IF;
28132 
28133    l_segment := AcctDerRule_5(
28134            p_application_id           => p_application_id
28135          , p_ae_header_id             => l_ae_header_id 
28136 , p_source_4 => p_source_4
28137          , x_transaction_coa_id       => l_adr_transaction_coa_id
28138          , x_accounting_coa_id        => l_adr_accounting_coa_id
28139          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
28140          , x_flex_value_set_id        => l_adr_flex_value_set_id
28141          , x_value_type_code          => l_adr_value_type_code
28142          , x_value_combination_id     => l_adr_value_combination_id
28143          , x_value_segment_code       => l_adr_value_segment_code
28144          , p_side                     => 'NA'
28145          , p_override_seg_flag        => 'Y'
28146    );
28147 
28148    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
28149 
28150       xla_ae_lines_pkg.set_segment(
28151           p_to_segment_code         => 'GL_BALANCING'
28152         , p_segment_value           => l_segment
28153         , p_from_segment_code       => l_adr_value_segment_code
28154         , p_from_combination_id     => l_adr_value_combination_id
28155         , p_value_type_code         => l_adr_value_type_code
28156         , p_transaction_coa_id      => l_adr_transaction_coa_id
28157         , p_accounting_coa_id       => l_adr_accounting_coa_id
28158         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
28159         , p_flex_value_set_id       => l_adr_flex_value_set_id
28160         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
28161         , p_adr_type_code           => 'S'
28162         , p_component_type          => l_component_type
28163         , p_component_code          => l_component_code
28164         , p_component_type_code     => l_component_type_code
28165         , p_component_appl_id       => l_component_appl_id
28166         , p_amb_context_code        => l_amb_context_code
28167         , p_entity_code             => 'RECEIPTS'
28168         , p_event_class_code        => 'RECEIPT'
28169         , p_side                    => 'NA'
28170         );
28171 
28172   END IF;
28173 
28174    --
28175    --
28176    END IF;
28177 
28178        --
28179        -- Update the line information that should be overwritten
28180        --
28181        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
28182                                          p_header_num   => 1);
28183        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
28184 
28185        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
28186 
28190 
28187        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
28188           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
28189        END IF;
28191       --
28192       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
28193       --
28194       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
28195           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
28196       ELSE
28197           ---------------------------------------------------------------------------------------------------
28198           -- 4262811a Switch Sign
28199           ---------------------------------------------------------------------------------------------------
28200           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
28201           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
28202                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
28203           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
28204                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
28205           -- 5132302
28206           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
28207                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
28208 
28209       END IF;
28210 
28211       -- 4955764
28212       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
28213       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
28214 
28215 
28216       XLA_AE_LINES_PKG.ValidateCurrentLine;
28217       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
28218 
28219       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
28220                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
28221                ,p_balance_type_code => l_balance_type_code);
28222 
28223    END IF;
28224 
28225    -----------------------------------------------------------------------------------------
28226    -- 4262811 Multiperiod Accounting
28227    -----------------------------------------------------------------------------------------
28228      -- No MPA option is assigned.
28229 
28230 
28231 END IF;
28232 END IF;
28233 --
28234 
28235 --
28236 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
28237    trace
28238       (p_msg      => 'END of AcctLineType_70'
28239       ,p_level    => C_LEVEL_PROCEDURE
28240       ,p_module   => l_log_module);
28241 END IF;
28242 --
28243 EXCEPTION
28244   WHEN xla_exceptions_pkg.application_exception THEN
28245       RAISE;
28246   WHEN OTHERS THEN
28247        xla_exceptions_pkg.raise_message
28248            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_70');
28249 END AcctLineType_70;
28250 --
28251 
28252 ---------------------------------------
28253 --
28254 -- PRIVATE FUNCTION
28255 --         AcctLineType_71
28256 --
28257 ---------------------------------------
28258 PROCEDURE AcctLineType_71 (
28259   p_application_id        IN NUMBER
28260  ,p_event_id              IN NUMBER
28261  ,p_calculate_acctd_flag  IN VARCHAR2
28262  ,p_calculate_g_l_flag    IN VARCHAR2
28263  ,p_actual_flag           IN OUT VARCHAR2
28264  ,p_balance_type_code     OUT VARCHAR2
28265  ,p_gain_or_loss_ref      OUT VARCHAR2
28266  
28267 --Distribution GL Account
28268  , p_source_3            IN NUMBER
28269 --Transaction Distribution GL Account
28270  , p_source_4            IN NUMBER
28271 --Federal Account Rule
28272  , p_source_7            IN VARCHAR2
28273 --Federal Fund Expired Status
28274  , p_source_8            IN VARCHAR2
28275 --Federal Prior Year Flag
28276  , p_source_9            IN VARCHAR2
28277 --Federal Fund Time Frame
28278  , p_source_10            IN VARCHAR2
28279 --Federal Apportionment Category
28280  , p_source_11            IN VARCHAR2
28281 --Distribution Source Type
28282  , p_source_20            IN VARCHAR2
28283 --Distribution Line Identifier
28284  , p_source_22            IN NUMBER
28285 --Distribution Type
28286  , p_source_23            IN VARCHAR2
28287 --Entered Amount
28288  , p_source_24            IN NUMBER
28289 --Exchange Rate Type
28290  , p_source_28            IN VARCHAR2
28291 --Applied To Document Accounting Amount
28292  , p_source_29            IN NUMBER
28293 --Transaction Distribution Account Class
28294  , p_source_33            IN VARCHAR2
28295 --Transaction Distribution Identifier
28296  , p_source_34            IN NUMBER
28297 --Transaction Distribution Type
28298  , p_source_35            IN VARCHAR2
28299 --Federal Account Valid Flag
28300  , p_source_56            IN VARCHAR2
28301 --Applied To Document Exchange Date
28302  , p_source_57            IN DATE
28303 --Receipt Applied To Application Identifier
28304  , p_source_58            IN NUMBER
28305 --Transaction Entity Code
28306  , p_source_59            IN VARCHAR2
28307 --Transaction Identifier
28308  , p_source_60            IN NUMBER
28309 --Applying Document Currency Code
28310  , p_source_61            IN VARCHAR2
28311 --Applied To Document Exchange Rate
28312  , p_source_62            IN NUMBER
28313 --Distribution Party Identifier
28317 --Distribution Party Type
28314  , p_source_63            IN NUMBER
28315 --Distribution Party Site Id
28316  , p_source_64            IN NUMBER
28318  , p_source_65            IN VARCHAR2
28319 )
28320 IS
28321 
28322 l_component_type              VARCHAR2(80);
28323 l_component_code              VARCHAR2(30);
28324 l_component_type_code         VARCHAR2(1);
28325 l_component_appl_id           INTEGER;
28326 l_amb_context_code            VARCHAR2(30);
28327 l_entity_code                 VARCHAR2(30);
28328 l_event_class_code            VARCHAR2(30);
28329 l_ae_header_id                NUMBER;
28330 l_event_type_code             VARCHAR2(30);
28331 l_line_definition_code        VARCHAR2(30);
28332 l_line_definition_owner_code  VARCHAR2(1);
28333 --
28334 -- adr variables
28335 l_segment                     VARCHAR2(30);
28336 l_ccid                        NUMBER;
28337 l_adr_transaction_coa_id      NUMBER;
28338 l_adr_accounting_coa_id       NUMBER;
28339 l_adr_flexfield_segment_code  VARCHAR2(30);
28340 l_adr_flex_value_set_id       NUMBER;
28341 l_adr_value_type_code         VARCHAR2(30);
28342 l_adr_value_combination_id    NUMBER;
28343 l_adr_value_segment_code      VARCHAR2(30);
28344 
28345 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
28346 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
28347 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
28348 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
28349 
28350 -- 4262811 Variables ------------------------------------------------------------------------------------------
28351 l_entered_amt_idx             NUMBER;
28352 l_accted_amt_idx              NUMBER;
28353 l_acc_rev_flag                VARCHAR2(1);
28354 l_accrual_line_num            NUMBER;
28355 l_tmp_amt                     NUMBER;
28356 l_acc_rev_natural_side_code   VARCHAR2(1);
28357 
28358 l_num_entries                 NUMBER;
28359 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
28360 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
28361 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
28362 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
28363 l_recog_line_1                NUMBER;
28364 l_recog_line_2                NUMBER;
28365 
28366 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
28367 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
28368 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
28369 
28370 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
28371 
28372 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
28373 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
28374 
28375 ---------------------------------------------------------------------------------------------------------------
28376 
28377 
28378 --
28379 -- bulk performance
28380 --
28381 l_balance_type_code           VARCHAR2(1);
28382 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
28383 l_log_module                  VARCHAR2(240);
28384 
28385 --
28386 -- Upgrade strategy
28387 --
28388 l_actual_upg_option           VARCHAR2(1);
28389 l_enc_upg_option           VARCHAR2(1);
28390 
28391 --
28392 BEGIN
28393 --
28394 IF g_log_enabled THEN
28395       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_71';
28396 END IF;
28397 --
28398 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
28399 
28400       trace
28401          (p_msg      => 'BEGIN of AcctLineType_71'
28402          ,p_level    => C_LEVEL_PROCEDURE
28403          ,p_module   => l_log_module);
28404 
28405 END IF;
28406 --
28407 l_component_type             := 'AMB_JLT';
28408 l_component_code             := 'FV_RCT_REF_OAP_UFC_CR';
28409 l_component_type_code        := 'S';
28410 l_component_appl_id          :=  222;
28411 l_amb_context_code           := 'DEFAULT';
28412 l_entity_code                := 'RECEIPTS';
28413 l_event_class_code           := 'RECEIPT';
28414 l_event_type_code            := 'RECEIPT_ALL';
28415 l_line_definition_owner_code := 'S';
28416 l_line_definition_code       := 'MFAR_FED_AR_RCT_BALANCING';
28417 --
28418 l_balance_type_code          := 'A';
28419 l_segment                     := NULL;
28420 l_ccid                        := NULL;
28421 l_adr_transaction_coa_id      := NULL;
28422 l_adr_accounting_coa_id       := NULL;
28423 l_adr_flexfield_segment_code  := NULL;
28424 l_adr_flex_value_set_id       := NULL;
28425 l_adr_value_type_code         := NULL;
28426 l_adr_value_combination_id    := NULL;
28427 l_adr_value_segment_code      := NULL;
28428 
28429 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
28430 l_bflow_class_code           := '';    -- 4219869 Business Flow
28431 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
28432 l_budgetary_control_flag     := 'N';
28433 
28434 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
28435 l_bflow_applied_to_amt       := NULL; -- 5132302
28436 l_entered_amt_idx            := NULL;          -- 4262811
28437 l_accted_amt_idx             := NULL;          -- 4262811
28438 l_acc_rev_flag               := NULL;          -- 4262811
28439 l_accrual_line_num           := NULL;          -- 4262811
28443 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
28440 l_tmp_amt                    := NULL;          -- 4262811
28441 --
28442  
28444     l_balance_type_code <> 'B' THEN
28445 IF NVL(p_source_20,'
28446 ') =  'REC' AND 
28447 NVL(p_source_33,'
28448 ') =  'REV' AND 
28449 NVL(p_source_8,'
28450 ') =  'Unexpired' AND 
28451 NVL(p_source_9,'
28452 ') =  'N' AND 
28453 (NVL(p_source_11,'
28454 ') =  'A' OR 
28455 NVL(p_source_11,'
28456 ') =  'B' OR 
28457 NVL(p_source_11,'
28458 ') =  'C') AND 
28459 (NVL(p_source_10,'
28460 ') =  'SINGLE' OR 
28461 NVL(p_source_10,'
28462 ') =  'MUTIPLE' OR 
28463 NVL(p_source_10,'
28464 ') =  'NO_YEAR') AND 
28465 (NVL(p_source_7,'
28466 ') =  'Overpayment Refund' OR 
28467 NVL(p_source_7,'
28468 ') =  'Advance Refund') AND 
28469 NVL(p_source_56,'
28470 ') =  'Y'
28471  THEN 
28472 
28473    --
28474    XLA_AE_LINES_PKG.SetNewLine;
28475 
28476    p_balance_type_code          := l_balance_type_code;
28477    -- set the flag so later we will know whether the gain loss line needs to be created
28478    
28479    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
28480      p_actual_flag :='A';
28481    END IF;
28482 
28483    --
28484    -- bulk performance
28485    --
28486    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
28487                                       p_header_num   => 0); -- 4262811
28488    --
28489    -- set accounting line options
28490    --
28491    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
28492            p_natural_side_code          => 'C'
28493          , p_gain_or_loss_flag          => 'N'
28494          , p_gl_transfer_mode_code      => 'S'
28495          , p_acct_entry_type_code       => 'A'
28496          , p_switch_side_flag           => 'Y'
28497          , p_merge_duplicate_code       => 'A'
28498          );
28499    --
28500    l_acc_rev_natural_side_code := 'D';  -- 4262811
28501    -- 
28502    --
28503    -- set accounting line type info
28504    --
28505    xla_ae_lines_pkg.SetAcctLineType
28506       (p_component_type             => l_component_type
28507       ,p_event_type_code            => l_event_type_code
28508       ,p_line_definition_owner_code => l_line_definition_owner_code
28509       ,p_line_definition_code       => l_line_definition_code
28510       ,p_accounting_line_code       => l_component_code
28511       ,p_accounting_line_type_code  => l_component_type_code
28512       ,p_accounting_line_appl_id    => l_component_appl_id
28513       ,p_amb_context_code           => l_amb_context_code
28514       ,p_entity_code                => l_entity_code
28515       ,p_event_class_code           => l_event_class_code);
28516    --
28517    -- set accounting class
28518    --
28519    xla_ae_lines_pkg.SetAcctClass(
28520            p_accounting_class_code  => 'FV_CASH_CR'
28521          , p_ae_header_id           => l_ae_header_id
28522          );
28523 
28524    --
28525    -- set rounding class
28526    --
28527    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
28528                       'RECEIVABLE';
28529 
28530    --
28531    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
28532    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
28533    --
28534    -- bulk performance
28535    --
28536    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
28537 
28538    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
28539       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
28540 
28541    -- 4955764
28542    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
28543       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
28544 
28545    -- 4458381 Public Sector Enh
28546    
28547    --
28548    -- set accounting attributes for the line type
28549    --
28550    l_entered_amt_idx := 8;
28551    l_accted_amt_idx  := 13;
28552    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
28553    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
28554    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
28555    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
28556    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
28557    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
28558    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
28559    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
28560    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
28561    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
28562    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
28563    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
28564    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
28565    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
28566    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
28567    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
28568    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
28569    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
28573    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
28570    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
28571    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
28572    l_rec_acct_attrs.array_date_value(10)  := p_source_57;
28574    l_rec_acct_attrs.array_num_value(11)  := p_source_62;
28575    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
28576    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
28577    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
28578    l_rec_acct_attrs.array_num_value(13)  := p_source_29;
28579    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
28580    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
28581    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
28582    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
28583    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
28584    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
28585 
28586    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
28587    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
28588 
28589    ---------------------------------------------------------------------------------------------------------------
28590    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
28591    ---------------------------------------------------------------------------------------------------------------
28592    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
28593 
28594    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
28595    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
28596 
28597    IF xla_accounting_cache_pkg.GetValueChar
28598          (p_source_code         => 'LEDGER_CATEGORY_CODE'
28599          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
28600    AND l_bflow_method_code = 'PRIOR_ENTRY'
28601 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
28602    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
28603          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
28604        )
28605    THEN
28606          xla_ae_lines_pkg.BflowUpgEntry
28607            (p_business_method_code    => l_bflow_method_code
28608            ,p_business_class_code     => l_bflow_class_code
28609            ,p_balance_type            => l_balance_type_code);
28610    ELSE
28611       NULL;
28612 -- No business flow processing for business flow method of NONE.
28613    END IF;
28614 
28615    --
28616    -- call analytical criteria
28617    --
28618    
28619    --
28620    -- call description
28621    --
28622    -- No description or it is inherited.
28623    --
28624    -- call ADRs
28625    -- Bug 4922099
28626    --
28627    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
28628         (NVL(l_actual_upg_option, 'N') = 'O') OR
28629         (NVL(l_enc_upg_option, 'N') = 'O')
28630       )
28631    THEN
28632    NULL;
28633    --
28634    --
28635    
28636   l_ccid := AcctDerRule_7(
28637            p_application_id           => p_application_id
28638          , p_ae_header_id             => l_ae_header_id 
28639 , p_source_3 => p_source_3
28640          , x_transaction_coa_id       => l_adr_transaction_coa_id
28641          , x_accounting_coa_id        => l_adr_accounting_coa_id
28642          , x_value_type_code          => l_adr_value_type_code
28643          , p_side                     => 'NA'
28644    );
28645 
28646    xla_ae_lines_pkg.set_ccid(
28647     p_code_combination_id          => l_ccid
28648   , p_value_type_code              => l_adr_value_type_code
28649   , p_transaction_coa_id           => l_adr_transaction_coa_id
28650   , p_accounting_coa_id            => l_adr_accounting_coa_id
28651   , p_adr_code                     => 'DIST_CCID'
28652   , p_adr_type_code                => 'S'
28653   , p_component_type               => l_component_type
28654   , p_component_code               => l_component_code
28655   , p_component_type_code          => l_component_type_code
28656   , p_component_appl_id            => l_component_appl_id
28657   , p_amb_context_code             => l_amb_context_code
28658   , p_side                         => 'NA'
28659   );
28660 
28661 
28662    l_segment := AcctDerRule_19(
28663            p_application_id           => p_application_id
28664          , p_ae_header_id             => l_ae_header_id 
28665 , p_source_8 => p_source_8
28666 , p_source_9 => p_source_9
28667 , p_source_10 => p_source_10
28668 , p_source_11 => p_source_11
28669          , x_transaction_coa_id       => l_adr_transaction_coa_id
28670          , x_accounting_coa_id        => l_adr_accounting_coa_id
28671          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
28672          , x_flex_value_set_id        => l_adr_flex_value_set_id
28673          , x_value_type_code          => l_adr_value_type_code
28674          , x_value_combination_id     => l_adr_value_combination_id
28675          , x_value_segment_code       => l_adr_value_segment_code
28676          , p_side                     => 'NA'
28677          , p_override_seg_flag        => 'Y'
28678    );
28679 
28680    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
28681 
28682       xla_ae_lines_pkg.set_segment(
28686         , p_from_combination_id     => l_adr_value_combination_id
28683           p_to_segment_code         => 'GL_ACCOUNT'
28684         , p_segment_value           => l_segment
28685         , p_from_segment_code       => l_adr_value_segment_code
28687         , p_value_type_code         => l_adr_value_type_code
28688         , p_transaction_coa_id      => l_adr_transaction_coa_id
28689         , p_accounting_coa_id       => l_adr_accounting_coa_id
28690         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
28691         , p_flex_value_set_id       => l_adr_flex_value_set_id
28692         , p_adr_code                => 'FV_AR_46X002_RCT_CR'
28693         , p_adr_type_code           => 'S'
28694         , p_component_type          => l_component_type
28695         , p_component_code          => l_component_code
28696         , p_component_type_code     => l_component_type_code
28697         , p_component_appl_id       => l_component_appl_id
28698         , p_amb_context_code        => l_amb_context_code
28699         , p_entity_code             => 'RECEIPTS'
28700         , p_event_class_code        => 'RECEIPT'
28701         , p_side                    => 'NA'
28702         );
28703 
28704   END IF;
28705 
28706    l_segment := AcctDerRule_5(
28707            p_application_id           => p_application_id
28708          , p_ae_header_id             => l_ae_header_id 
28709 , p_source_4 => p_source_4
28710          , x_transaction_coa_id       => l_adr_transaction_coa_id
28711          , x_accounting_coa_id        => l_adr_accounting_coa_id
28712          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
28713          , x_flex_value_set_id        => l_adr_flex_value_set_id
28714          , x_value_type_code          => l_adr_value_type_code
28715          , x_value_combination_id     => l_adr_value_combination_id
28716          , x_value_segment_code       => l_adr_value_segment_code
28717          , p_side                     => 'NA'
28718          , p_override_seg_flag        => 'Y'
28719    );
28720 
28721    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
28722 
28723       xla_ae_lines_pkg.set_segment(
28724           p_to_segment_code         => 'GL_BALANCING'
28725         , p_segment_value           => l_segment
28726         , p_from_segment_code       => l_adr_value_segment_code
28727         , p_from_combination_id     => l_adr_value_combination_id
28728         , p_value_type_code         => l_adr_value_type_code
28729         , p_transaction_coa_id      => l_adr_transaction_coa_id
28730         , p_accounting_coa_id       => l_adr_accounting_coa_id
28731         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
28732         , p_flex_value_set_id       => l_adr_flex_value_set_id
28733         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
28734         , p_adr_type_code           => 'S'
28735         , p_component_type          => l_component_type
28736         , p_component_code          => l_component_code
28737         , p_component_type_code     => l_component_type_code
28738         , p_component_appl_id       => l_component_appl_id
28739         , p_amb_context_code        => l_amb_context_code
28740         , p_entity_code             => 'RECEIPTS'
28741         , p_event_class_code        => 'RECEIPT'
28742         , p_side                    => 'NA'
28743         );
28744 
28745   END IF;
28746 
28747    --
28748    --
28749    END IF;
28750    --
28751    -- Bug 4922099
28752    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
28753           (NVL(l_enc_upg_option, 'N') = 'O')
28754         ) AND
28755         (l_bflow_method_code = 'PRIOR_ENTRY')
28756       )
28757    THEN
28758       IF
28759       --
28760       1 = 2
28761       --
28762       THEN
28763       xla_accounting_err_pkg.build_message
28764                                     (p_appli_s_name            => 'XLA'
28765                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
28766                                     ,p_token_1                 => 'LINE_NUMBER'
28767                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
28768                                     ,p_token_2                 => 'LINE_TYPE_NAME'
28769                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
28770                                                                              l_component_type
28771                                                                             ,l_component_code
28772                                                                             ,l_component_type_code
28773                                                                             ,l_component_appl_id
28774                                                                             ,l_amb_context_code
28775                                                                             ,l_entity_code
28776                                                                             ,l_event_class_code
28777                                                                            )
28778                                     ,p_token_3                 => 'OWNER'
28779                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
28780                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
28781                                                                           ,p_lookup_code    => l_component_type_code
28785                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
28782                                                                          )
28783                                     ,p_token_4                 => 'PRODUCT_NAME'
28784                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
28786                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
28787                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
28788                                     ,p_ae_header_id            =>  NULL
28789                                        );
28790 
28791         IF (C_LEVEL_ERROR>= g_log_level) THEN
28792                  trace
28793                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
28794                       ,p_level    => C_LEVEL_ERROR
28795                       ,p_module   => l_log_module);
28796         END IF;
28797       END IF;
28798    END IF;
28799    --
28800    --
28801    ------------------------------------------------------------------------------------------------
28802    -- 4219869 Business Flow
28803    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
28804    -- Prior Entry.  Currently, the following code is always generated.
28805    ------------------------------------------------------------------------------------------------
28806    XLA_AE_LINES_PKG.ValidateCurrentLine;
28807 
28808    ------------------------------------------------------------------------------------
28809    -- 4219869 Business Flow
28810    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
28811    ------------------------------------------------------------------------------------
28812    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
28813 
28814    ----------------------------------------------------------------------------------
28815    -- 4219869 Business Flow
28816    -- Update journal entry status -- Need to generate this within IF <condition>
28817    ----------------------------------------------------------------------------------
28818    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
28819          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
28820          ,p_balance_type_code => l_balance_type_code
28821          );
28822 
28823    -------------------------------------------------------------------------------------------
28824    -- 4262811 - Generate the Accrual Reversal lines
28825    -------------------------------------------------------------------------------------------
28826    BEGIN
28827       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
28828                               (g_array_event(p_event_id).array_value_num('header_index'));
28829       IF l_acc_rev_flag IS NULL THEN
28830          l_acc_rev_flag := 'N';
28831       END IF;
28832    EXCEPTION
28833       WHEN OTHERS THEN
28834          l_acc_rev_flag := 'N';
28835    END;
28836    --
28837    IF (l_acc_rev_flag = 'Y') THEN
28838 
28839        -- 4645092  ------------------------------------------------------------------------------
28840        -- To allow MPA report to determine if it should generate report process
28841        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
28842        ------------------------------------------------------------------------------------------
28843 
28844        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
28845        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
28846    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
28847    -- call ADRs
28848    -- Bug 4922099
28849    --
28850    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
28851         (NVL(l_actual_upg_option, 'N') = 'O') OR
28852         (NVL(l_enc_upg_option, 'N') = 'O')
28853       )
28854    THEN
28855    NULL;
28856    --
28857    --
28858    
28859   l_ccid := AcctDerRule_7(
28860            p_application_id           => p_application_id
28861          , p_ae_header_id             => l_ae_header_id 
28862 , p_source_3 => p_source_3
28863          , x_transaction_coa_id       => l_adr_transaction_coa_id
28864          , x_accounting_coa_id        => l_adr_accounting_coa_id
28865          , x_value_type_code          => l_adr_value_type_code
28866          , p_side                     => 'NA'
28867    );
28868 
28869    xla_ae_lines_pkg.set_ccid(
28870     p_code_combination_id          => l_ccid
28871   , p_value_type_code              => l_adr_value_type_code
28872   , p_transaction_coa_id           => l_adr_transaction_coa_id
28873   , p_accounting_coa_id            => l_adr_accounting_coa_id
28874   , p_adr_code                     => 'DIST_CCID'
28875   , p_adr_type_code                => 'S'
28876   , p_component_type               => l_component_type
28877   , p_component_code               => l_component_code
28878   , p_component_type_code          => l_component_type_code
28879   , p_component_appl_id            => l_component_appl_id
28880   , p_amb_context_code             => l_amb_context_code
28881   , p_side                         => 'NA'
28882   );
28883 
28884 
28885    l_segment := AcctDerRule_19(
28886            p_application_id           => p_application_id
28887          , p_ae_header_id             => l_ae_header_id 
28888 , p_source_8 => p_source_8
28889 , p_source_9 => p_source_9
28890 , p_source_10 => p_source_10
28891 , p_source_11 => p_source_11
28895          , x_flex_value_set_id        => l_adr_flex_value_set_id
28892          , x_transaction_coa_id       => l_adr_transaction_coa_id
28893          , x_accounting_coa_id        => l_adr_accounting_coa_id
28894          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
28896          , x_value_type_code          => l_adr_value_type_code
28897          , x_value_combination_id     => l_adr_value_combination_id
28898          , x_value_segment_code       => l_adr_value_segment_code
28899          , p_side                     => 'NA'
28900          , p_override_seg_flag        => 'Y'
28901    );
28902 
28903    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
28904 
28905       xla_ae_lines_pkg.set_segment(
28906           p_to_segment_code         => 'GL_ACCOUNT'
28907         , p_segment_value           => l_segment
28908         , p_from_segment_code       => l_adr_value_segment_code
28909         , p_from_combination_id     => l_adr_value_combination_id
28910         , p_value_type_code         => l_adr_value_type_code
28911         , p_transaction_coa_id      => l_adr_transaction_coa_id
28912         , p_accounting_coa_id       => l_adr_accounting_coa_id
28913         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
28914         , p_flex_value_set_id       => l_adr_flex_value_set_id
28915         , p_adr_code                => 'FV_AR_46X002_RCT_CR'
28916         , p_adr_type_code           => 'S'
28917         , p_component_type          => l_component_type
28918         , p_component_code          => l_component_code
28919         , p_component_type_code     => l_component_type_code
28920         , p_component_appl_id       => l_component_appl_id
28921         , p_amb_context_code        => l_amb_context_code
28922         , p_entity_code             => 'RECEIPTS'
28923         , p_event_class_code        => 'RECEIPT'
28924         , p_side                    => 'NA'
28925         );
28926 
28927   END IF;
28928 
28929    l_segment := AcctDerRule_5(
28930            p_application_id           => p_application_id
28931          , p_ae_header_id             => l_ae_header_id 
28932 , p_source_4 => p_source_4
28933          , x_transaction_coa_id       => l_adr_transaction_coa_id
28934          , x_accounting_coa_id        => l_adr_accounting_coa_id
28935          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
28936          , x_flex_value_set_id        => l_adr_flex_value_set_id
28937          , x_value_type_code          => l_adr_value_type_code
28938          , x_value_combination_id     => l_adr_value_combination_id
28939          , x_value_segment_code       => l_adr_value_segment_code
28940          , p_side                     => 'NA'
28941          , p_override_seg_flag        => 'Y'
28942    );
28943 
28944    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
28945 
28946       xla_ae_lines_pkg.set_segment(
28947           p_to_segment_code         => 'GL_BALANCING'
28948         , p_segment_value           => l_segment
28949         , p_from_segment_code       => l_adr_value_segment_code
28950         , p_from_combination_id     => l_adr_value_combination_id
28951         , p_value_type_code         => l_adr_value_type_code
28952         , p_transaction_coa_id      => l_adr_transaction_coa_id
28953         , p_accounting_coa_id       => l_adr_accounting_coa_id
28954         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
28955         , p_flex_value_set_id       => l_adr_flex_value_set_id
28956         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
28957         , p_adr_type_code           => 'S'
28958         , p_component_type          => l_component_type
28959         , p_component_code          => l_component_code
28960         , p_component_type_code     => l_component_type_code
28961         , p_component_appl_id       => l_component_appl_id
28962         , p_amb_context_code        => l_amb_context_code
28963         , p_entity_code             => 'RECEIPTS'
28964         , p_event_class_code        => 'RECEIPT'
28965         , p_side                    => 'NA'
28966         );
28967 
28968   END IF;
28969 
28970    --
28971    --
28972    END IF;
28973 
28974        --
28975        -- Update the line information that should be overwritten
28976        --
28977        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
28978                                          p_header_num   => 1);
28979        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
28980 
28981        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
28982 
28983        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
28984           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
28985        END IF;
28986 
28987       --
28988       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
28989       --
28990       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
28991           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
28992       ELSE
28993           ---------------------------------------------------------------------------------------------------
28994           -- 4262811a Switch Sign
28995           ---------------------------------------------------------------------------------------------------
28996           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
29000                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
28997           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
28998                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
28999           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
29001           -- 5132302
29002           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
29003                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
29004 
29005       END IF;
29006 
29007       -- 4955764
29008       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
29009       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
29010 
29011 
29012       XLA_AE_LINES_PKG.ValidateCurrentLine;
29013       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
29014 
29015       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
29016                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
29017                ,p_balance_type_code => l_balance_type_code);
29018 
29019    END IF;
29020 
29021    -----------------------------------------------------------------------------------------
29022    -- 4262811 Multiperiod Accounting
29023    -----------------------------------------------------------------------------------------
29024      -- No MPA option is assigned.
29025 
29026 
29027 END IF;
29028 END IF;
29029 --
29030 
29031 --
29032 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
29033    trace
29034       (p_msg      => 'END of AcctLineType_71'
29035       ,p_level    => C_LEVEL_PROCEDURE
29036       ,p_module   => l_log_module);
29037 END IF;
29038 --
29039 EXCEPTION
29040   WHEN xla_exceptions_pkg.application_exception THEN
29041       RAISE;
29042   WHEN OTHERS THEN
29043        xla_exceptions_pkg.raise_message
29044            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_71');
29045 END AcctLineType_71;
29046 --
29047 
29048 ---------------------------------------
29049 --
29050 -- PRIVATE FUNCTION
29051 --         AcctLineType_72
29052 --
29053 ---------------------------------------
29054 PROCEDURE AcctLineType_72 (
29055   p_application_id        IN NUMBER
29056  ,p_event_id              IN NUMBER
29057  ,p_calculate_acctd_flag  IN VARCHAR2
29058  ,p_calculate_g_l_flag    IN VARCHAR2
29059  ,p_actual_flag           IN OUT VARCHAR2
29060  ,p_balance_type_code     OUT VARCHAR2
29061  ,p_gain_or_loss_ref      OUT VARCHAR2
29062  
29063 --Distribution GL Account
29064  , p_source_3            IN NUMBER
29065 --Transaction Distribution GL Account
29066  , p_source_4            IN NUMBER
29067 --Federal Account Rule
29068  , p_source_7            IN VARCHAR2
29069 --Federal Fund Expired Status
29070  , p_source_8            IN VARCHAR2
29071 --Federal Prior Year Flag
29072  , p_source_9            IN VARCHAR2
29073 --Federal Fund Time Frame
29074  , p_source_10            IN VARCHAR2
29075 --Federal Apportionment Category
29076  , p_source_11            IN VARCHAR2
29077 --Distribution Source Type
29078  , p_source_20            IN VARCHAR2
29079 --Distribution Line Identifier
29080  , p_source_22            IN NUMBER
29081 --Distribution Type
29082  , p_source_23            IN VARCHAR2
29083 --Entered Amount
29084  , p_source_24            IN NUMBER
29085 --Exchange Rate Type
29086  , p_source_28            IN VARCHAR2
29087 --Applied To Document Accounting Amount
29088  , p_source_29            IN NUMBER
29089 --Transaction Distribution Account Class
29090  , p_source_33            IN VARCHAR2
29091 --Transaction Distribution Identifier
29092  , p_source_34            IN NUMBER
29093 --Transaction Distribution Type
29094  , p_source_35            IN VARCHAR2
29095 --Federal Account Valid Flag
29096  , p_source_56            IN VARCHAR2
29097 --Applied To Document Exchange Date
29098  , p_source_57            IN DATE
29099 --Receipt Applied To Application Identifier
29100  , p_source_58            IN NUMBER
29101 --Transaction Entity Code
29102  , p_source_59            IN VARCHAR2
29103 --Transaction Identifier
29104  , p_source_60            IN NUMBER
29105 --Applying Document Currency Code
29106  , p_source_61            IN VARCHAR2
29107 --Applied To Document Exchange Rate
29108  , p_source_62            IN NUMBER
29109 --Distribution Party Identifier
29110  , p_source_63            IN NUMBER
29111 --Distribution Party Site Id
29112  , p_source_64            IN NUMBER
29113 --Distribution Party Type
29114  , p_source_65            IN VARCHAR2
29115 )
29116 IS
29117 
29118 l_component_type              VARCHAR2(80);
29119 l_component_code              VARCHAR2(30);
29120 l_component_type_code         VARCHAR2(1);
29121 l_component_appl_id           INTEGER;
29122 l_amb_context_code            VARCHAR2(30);
29123 l_entity_code                 VARCHAR2(30);
29124 l_event_class_code            VARCHAR2(30);
29125 l_ae_header_id                NUMBER;
29126 l_event_type_code             VARCHAR2(30);
29127 l_line_definition_code        VARCHAR2(30);
29128 l_line_definition_owner_code  VARCHAR2(1);
29129 --
29130 -- adr variables
29131 l_segment                     VARCHAR2(30);
29132 l_ccid                        NUMBER;
29136 l_adr_flex_value_set_id       NUMBER;
29133 l_adr_transaction_coa_id      NUMBER;
29134 l_adr_accounting_coa_id       NUMBER;
29135 l_adr_flexfield_segment_code  VARCHAR2(30);
29137 l_adr_value_type_code         VARCHAR2(30);
29138 l_adr_value_combination_id    NUMBER;
29139 l_adr_value_segment_code      VARCHAR2(30);
29140 
29141 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
29142 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
29143 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
29144 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
29145 
29146 -- 4262811 Variables ------------------------------------------------------------------------------------------
29147 l_entered_amt_idx             NUMBER;
29148 l_accted_amt_idx              NUMBER;
29149 l_acc_rev_flag                VARCHAR2(1);
29150 l_accrual_line_num            NUMBER;
29151 l_tmp_amt                     NUMBER;
29152 l_acc_rev_natural_side_code   VARCHAR2(1);
29153 
29154 l_num_entries                 NUMBER;
29155 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
29156 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
29157 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
29158 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
29159 l_recog_line_1                NUMBER;
29160 l_recog_line_2                NUMBER;
29161 
29162 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
29163 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
29164 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
29165 
29166 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
29167 
29168 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
29169 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
29170 
29171 ---------------------------------------------------------------------------------------------------------------
29172 
29173 
29174 --
29175 -- bulk performance
29176 --
29177 l_balance_type_code           VARCHAR2(1);
29178 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
29179 l_log_module                  VARCHAR2(240);
29180 
29181 --
29182 -- Upgrade strategy
29183 --
29184 l_actual_upg_option           VARCHAR2(1);
29185 l_enc_upg_option           VARCHAR2(1);
29186 
29187 --
29188 BEGIN
29189 --
29190 IF g_log_enabled THEN
29191       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_72';
29192 END IF;
29193 --
29194 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
29195 
29196       trace
29197          (p_msg      => 'BEGIN of AcctLineType_72'
29198          ,p_level    => C_LEVEL_PROCEDURE
29199          ,p_module   => l_log_module);
29200 
29201 END IF;
29202 --
29203 l_component_type             := 'AMB_JLT';
29204 l_component_code             := 'FV_RCT_REF_OAP_UFC_DR';
29205 l_component_type_code        := 'S';
29206 l_component_appl_id          :=  222;
29207 l_amb_context_code           := 'DEFAULT';
29208 l_entity_code                := 'RECEIPTS';
29209 l_event_class_code           := 'RECEIPT';
29210 l_event_type_code            := 'RECEIPT_ALL';
29211 l_line_definition_owner_code := 'S';
29212 l_line_definition_code       := 'MFAR_FED_AR_RCT_BALANCING';
29213 --
29214 l_balance_type_code          := 'A';
29215 l_segment                     := NULL;
29216 l_ccid                        := NULL;
29217 l_adr_transaction_coa_id      := NULL;
29218 l_adr_accounting_coa_id       := NULL;
29219 l_adr_flexfield_segment_code  := NULL;
29220 l_adr_flex_value_set_id       := NULL;
29221 l_adr_value_type_code         := NULL;
29222 l_adr_value_combination_id    := NULL;
29223 l_adr_value_segment_code      := NULL;
29224 
29225 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
29226 l_bflow_class_code           := '';    -- 4219869 Business Flow
29227 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
29228 l_budgetary_control_flag     := 'N';
29229 
29230 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
29231 l_bflow_applied_to_amt       := NULL; -- 5132302
29232 l_entered_amt_idx            := NULL;          -- 4262811
29233 l_accted_amt_idx             := NULL;          -- 4262811
29234 l_acc_rev_flag               := NULL;          -- 4262811
29235 l_accrual_line_num           := NULL;          -- 4262811
29236 l_tmp_amt                    := NULL;          -- 4262811
29237 --
29238  
29239 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
29240     l_balance_type_code <> 'B' THEN
29241 IF NVL(p_source_20,'
29242 ') =  'REC' AND 
29243 NVL(p_source_33,'
29244 ') =  'REV' AND 
29245 NVL(p_source_8,'
29246 ') =  'Unexpired' AND 
29247 NVL(p_source_9,'
29248 ') =  'N' AND 
29249 (NVL(p_source_11,'
29250 ') =  'A' OR 
29251 NVL(p_source_11,'
29252 ') =  'B' OR 
29253 NVL(p_source_11,'
29254 ') =  'C') AND 
29255 (NVL(p_source_10,'
29256 ') =  'SINGLE' OR 
29257 NVL(p_source_10,'
29258 ') =  'MUTIPLE' OR 
29259 NVL(p_source_10,'
29260 ') =  'NO_YEAR') AND 
29261 (NVL(p_source_7,'
29262 ') =  'Overpayment Refund' OR 
29263 NVL(p_source_7,'
29264 ') =  'Advance Refund') AND 
29268 
29265 NVL(p_source_56,'
29266 ') =  'Y'
29267  THEN 
29269    --
29270    XLA_AE_LINES_PKG.SetNewLine;
29271 
29272    p_balance_type_code          := l_balance_type_code;
29273    -- set the flag so later we will know whether the gain loss line needs to be created
29274    
29275    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
29276      p_actual_flag :='A';
29277    END IF;
29278 
29279    --
29280    -- bulk performance
29281    --
29282    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
29283                                       p_header_num   => 0); -- 4262811
29284    --
29285    -- set accounting line options
29286    --
29287    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
29288            p_natural_side_code          => 'D'
29289          , p_gain_or_loss_flag          => 'N'
29290          , p_gl_transfer_mode_code      => 'S'
29291          , p_acct_entry_type_code       => 'A'
29292          , p_switch_side_flag           => 'Y'
29293          , p_merge_duplicate_code       => 'A'
29294          );
29295    --
29296    l_acc_rev_natural_side_code := 'C';  -- 4262811
29297    -- 
29298    --
29299    -- set accounting line type info
29300    --
29301    xla_ae_lines_pkg.SetAcctLineType
29302       (p_component_type             => l_component_type
29303       ,p_event_type_code            => l_event_type_code
29304       ,p_line_definition_owner_code => l_line_definition_owner_code
29305       ,p_line_definition_code       => l_line_definition_code
29306       ,p_accounting_line_code       => l_component_code
29307       ,p_accounting_line_type_code  => l_component_type_code
29308       ,p_accounting_line_appl_id    => l_component_appl_id
29309       ,p_amb_context_code           => l_amb_context_code
29310       ,p_entity_code                => l_entity_code
29311       ,p_event_class_code           => l_event_class_code);
29312    --
29313    -- set accounting class
29314    --
29315    xla_ae_lines_pkg.SetAcctClass(
29316            p_accounting_class_code  => 'FV_CASH_DR'
29317          , p_ae_header_id           => l_ae_header_id
29318          );
29319 
29320    --
29321    -- set rounding class
29322    --
29323    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
29324                       'RECEIVABLE';
29325 
29326    --
29327    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
29328    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
29329    --
29330    -- bulk performance
29331    --
29332    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
29333 
29334    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
29335       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
29336 
29337    -- 4955764
29338    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
29339       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
29340 
29341    -- 4458381 Public Sector Enh
29342    
29343    --
29344    -- set accounting attributes for the line type
29345    --
29346    l_entered_amt_idx := 8;
29347    l_accted_amt_idx  := 13;
29348    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
29349    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
29350    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
29351    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
29352    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
29353    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
29354    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
29355    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
29356    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
29357    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
29358    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
29359    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
29360    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
29361    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
29362    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
29363    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
29364    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
29365    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
29366    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
29367    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
29368    l_rec_acct_attrs.array_date_value(10)  := p_source_57;
29369    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
29370    l_rec_acct_attrs.array_num_value(11)  := p_source_62;
29371    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
29372    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
29373    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
29374    l_rec_acct_attrs.array_num_value(13)  := p_source_29;
29375    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
29376    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
29377    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
29378    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
29382    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
29379    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
29380    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
29381 
29383    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
29384 
29385    ---------------------------------------------------------------------------------------------------------------
29386    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
29387    ---------------------------------------------------------------------------------------------------------------
29388    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
29389 
29390    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
29391    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
29392 
29393    IF xla_accounting_cache_pkg.GetValueChar
29394          (p_source_code         => 'LEDGER_CATEGORY_CODE'
29395          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
29396    AND l_bflow_method_code = 'PRIOR_ENTRY'
29397 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
29398    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
29399          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
29400        )
29401    THEN
29402          xla_ae_lines_pkg.BflowUpgEntry
29403            (p_business_method_code    => l_bflow_method_code
29404            ,p_business_class_code     => l_bflow_class_code
29405            ,p_balance_type            => l_balance_type_code);
29406    ELSE
29407       NULL;
29408 -- No business flow processing for business flow method of NONE.
29409    END IF;
29410 
29411    --
29412    -- call analytical criteria
29413    --
29414    
29415    --
29416    -- call description
29417    --
29418    -- No description or it is inherited.
29419    --
29420    -- call ADRs
29421    -- Bug 4922099
29422    --
29423    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
29424         (NVL(l_actual_upg_option, 'N') = 'O') OR
29425         (NVL(l_enc_upg_option, 'N') = 'O')
29426       )
29427    THEN
29428    NULL;
29429    --
29430    --
29431    
29432   l_ccid := AcctDerRule_7(
29433            p_application_id           => p_application_id
29434          , p_ae_header_id             => l_ae_header_id 
29435 , p_source_3 => p_source_3
29436          , x_transaction_coa_id       => l_adr_transaction_coa_id
29437          , x_accounting_coa_id        => l_adr_accounting_coa_id
29438          , x_value_type_code          => l_adr_value_type_code
29439          , p_side                     => 'NA'
29440    );
29441 
29442    xla_ae_lines_pkg.set_ccid(
29443     p_code_combination_id          => l_ccid
29444   , p_value_type_code              => l_adr_value_type_code
29445   , p_transaction_coa_id           => l_adr_transaction_coa_id
29446   , p_accounting_coa_id            => l_adr_accounting_coa_id
29447   , p_adr_code                     => 'DIST_CCID'
29448   , p_adr_type_code                => 'S'
29449   , p_component_type               => l_component_type
29450   , p_component_code               => l_component_code
29451   , p_component_type_code          => l_component_type_code
29452   , p_component_appl_id            => l_component_appl_id
29453   , p_amb_context_code             => l_amb_context_code
29454   , p_side                         => 'NA'
29455   );
29456 
29457 
29458    l_segment := AcctDerRule_22(
29459            p_application_id           => p_application_id
29460          , p_ae_header_id             => l_ae_header_id 
29461 , p_source_7 => p_source_7
29462 , p_source_8 => p_source_8
29463 , p_source_9 => p_source_9
29464 , p_source_10 => p_source_10
29465 , p_source_11 => p_source_11
29466          , x_transaction_coa_id       => l_adr_transaction_coa_id
29467          , x_accounting_coa_id        => l_adr_accounting_coa_id
29468          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
29469          , x_flex_value_set_id        => l_adr_flex_value_set_id
29470          , x_value_type_code          => l_adr_value_type_code
29471          , x_value_combination_id     => l_adr_value_combination_id
29472          , x_value_segment_code       => l_adr_value_segment_code
29473          , p_side                     => 'NA'
29474          , p_override_seg_flag        => 'Y'
29475    );
29476 
29477    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
29478 
29479       xla_ae_lines_pkg.set_segment(
29480           p_to_segment_code         => 'GL_ACCOUNT'
29481         , p_segment_value           => l_segment
29482         , p_from_segment_code       => l_adr_value_segment_code
29483         , p_from_combination_id     => l_adr_value_combination_id
29484         , p_value_type_code         => l_adr_value_type_code
29485         , p_transaction_coa_id      => l_adr_transaction_coa_id
29486         , p_accounting_coa_id       => l_adr_accounting_coa_id
29487         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
29488         , p_flex_value_set_id       => l_adr_flex_value_set_id
29489         , p_adr_code                => 'FV_AR_4X0201_RCT_DR'
29490         , p_adr_type_code           => 'S'
29491         , p_component_type          => l_component_type
29492         , p_component_code          => l_component_code
29493         , p_component_type_code     => l_component_type_code
29494         , p_component_appl_id       => l_component_appl_id
29498         , p_side                    => 'NA'
29495         , p_amb_context_code        => l_amb_context_code
29496         , p_entity_code             => 'RECEIPTS'
29497         , p_event_class_code        => 'RECEIPT'
29499         );
29500 
29501   END IF;
29502 
29503    l_segment := AcctDerRule_5(
29504            p_application_id           => p_application_id
29505          , p_ae_header_id             => l_ae_header_id 
29506 , p_source_4 => p_source_4
29507          , x_transaction_coa_id       => l_adr_transaction_coa_id
29508          , x_accounting_coa_id        => l_adr_accounting_coa_id
29509          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
29510          , x_flex_value_set_id        => l_adr_flex_value_set_id
29511          , x_value_type_code          => l_adr_value_type_code
29512          , x_value_combination_id     => l_adr_value_combination_id
29513          , x_value_segment_code       => l_adr_value_segment_code
29514          , p_side                     => 'NA'
29515          , p_override_seg_flag        => 'Y'
29516    );
29517 
29518    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
29519 
29520       xla_ae_lines_pkg.set_segment(
29521           p_to_segment_code         => 'GL_BALANCING'
29522         , p_segment_value           => l_segment
29523         , p_from_segment_code       => l_adr_value_segment_code
29524         , p_from_combination_id     => l_adr_value_combination_id
29525         , p_value_type_code         => l_adr_value_type_code
29526         , p_transaction_coa_id      => l_adr_transaction_coa_id
29527         , p_accounting_coa_id       => l_adr_accounting_coa_id
29528         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
29529         , p_flex_value_set_id       => l_adr_flex_value_set_id
29530         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
29531         , p_adr_type_code           => 'S'
29532         , p_component_type          => l_component_type
29533         , p_component_code          => l_component_code
29534         , p_component_type_code     => l_component_type_code
29535         , p_component_appl_id       => l_component_appl_id
29536         , p_amb_context_code        => l_amb_context_code
29537         , p_entity_code             => 'RECEIPTS'
29538         , p_event_class_code        => 'RECEIPT'
29539         , p_side                    => 'NA'
29540         );
29541 
29542   END IF;
29543 
29544    --
29545    --
29546    END IF;
29547    --
29548    -- Bug 4922099
29549    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
29550           (NVL(l_enc_upg_option, 'N') = 'O')
29551         ) AND
29552         (l_bflow_method_code = 'PRIOR_ENTRY')
29553       )
29554    THEN
29555       IF
29556       --
29557       1 = 2
29558       --
29559       THEN
29560       xla_accounting_err_pkg.build_message
29561                                     (p_appli_s_name            => 'XLA'
29562                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
29563                                     ,p_token_1                 => 'LINE_NUMBER'
29564                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
29565                                     ,p_token_2                 => 'LINE_TYPE_NAME'
29566                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
29567                                                                              l_component_type
29568                                                                             ,l_component_code
29569                                                                             ,l_component_type_code
29570                                                                             ,l_component_appl_id
29571                                                                             ,l_amb_context_code
29572                                                                             ,l_entity_code
29573                                                                             ,l_event_class_code
29574                                                                            )
29575                                     ,p_token_3                 => 'OWNER'
29576                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
29577                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
29578                                                                           ,p_lookup_code    => l_component_type_code
29579                                                                          )
29580                                     ,p_token_4                 => 'PRODUCT_NAME'
29581                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
29582                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
29583                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
29584                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
29585                                     ,p_ae_header_id            =>  NULL
29586                                        );
29587 
29588         IF (C_LEVEL_ERROR>= g_log_level) THEN
29589                  trace
29590                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
29591                       ,p_level    => C_LEVEL_ERROR
29592                       ,p_module   => l_log_module);
29593         END IF;
29594       END IF;
29595    END IF;
29596    --
29597    --
29601    -- Prior Entry.  Currently, the following code is always generated.
29598    ------------------------------------------------------------------------------------------------
29599    -- 4219869 Business Flow
29600    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
29602    ------------------------------------------------------------------------------------------------
29603    XLA_AE_LINES_PKG.ValidateCurrentLine;
29604 
29605    ------------------------------------------------------------------------------------
29606    -- 4219869 Business Flow
29607    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
29608    ------------------------------------------------------------------------------------
29609    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
29610 
29611    ----------------------------------------------------------------------------------
29612    -- 4219869 Business Flow
29613    -- Update journal entry status -- Need to generate this within IF <condition>
29614    ----------------------------------------------------------------------------------
29615    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
29616          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
29617          ,p_balance_type_code => l_balance_type_code
29618          );
29619 
29620    -------------------------------------------------------------------------------------------
29621    -- 4262811 - Generate the Accrual Reversal lines
29622    -------------------------------------------------------------------------------------------
29623    BEGIN
29624       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
29625                               (g_array_event(p_event_id).array_value_num('header_index'));
29626       IF l_acc_rev_flag IS NULL THEN
29627          l_acc_rev_flag := 'N';
29628       END IF;
29629    EXCEPTION
29630       WHEN OTHERS THEN
29631          l_acc_rev_flag := 'N';
29632    END;
29633    --
29634    IF (l_acc_rev_flag = 'Y') THEN
29635 
29636        -- 4645092  ------------------------------------------------------------------------------
29637        -- To allow MPA report to determine if it should generate report process
29638        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
29639        ------------------------------------------------------------------------------------------
29640 
29641        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
29642        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
29643    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
29644    -- call ADRs
29645    -- Bug 4922099
29646    --
29647    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
29648         (NVL(l_actual_upg_option, 'N') = 'O') OR
29649         (NVL(l_enc_upg_option, 'N') = 'O')
29650       )
29651    THEN
29652    NULL;
29653    --
29654    --
29655    
29656   l_ccid := AcctDerRule_7(
29657            p_application_id           => p_application_id
29658          , p_ae_header_id             => l_ae_header_id 
29659 , p_source_3 => p_source_3
29660          , x_transaction_coa_id       => l_adr_transaction_coa_id
29661          , x_accounting_coa_id        => l_adr_accounting_coa_id
29662          , x_value_type_code          => l_adr_value_type_code
29663          , p_side                     => 'NA'
29664    );
29665 
29666    xla_ae_lines_pkg.set_ccid(
29667     p_code_combination_id          => l_ccid
29668   , p_value_type_code              => l_adr_value_type_code
29669   , p_transaction_coa_id           => l_adr_transaction_coa_id
29670   , p_accounting_coa_id            => l_adr_accounting_coa_id
29671   , p_adr_code                     => 'DIST_CCID'
29672   , p_adr_type_code                => 'S'
29673   , p_component_type               => l_component_type
29674   , p_component_code               => l_component_code
29675   , p_component_type_code          => l_component_type_code
29676   , p_component_appl_id            => l_component_appl_id
29677   , p_amb_context_code             => l_amb_context_code
29678   , p_side                         => 'NA'
29679   );
29680 
29681 
29682    l_segment := AcctDerRule_22(
29683            p_application_id           => p_application_id
29684          , p_ae_header_id             => l_ae_header_id 
29685 , p_source_7 => p_source_7
29686 , p_source_8 => p_source_8
29687 , p_source_9 => p_source_9
29688 , p_source_10 => p_source_10
29689 , p_source_11 => p_source_11
29690          , x_transaction_coa_id       => l_adr_transaction_coa_id
29691          , x_accounting_coa_id        => l_adr_accounting_coa_id
29692          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
29693          , x_flex_value_set_id        => l_adr_flex_value_set_id
29694          , x_value_type_code          => l_adr_value_type_code
29695          , x_value_combination_id     => l_adr_value_combination_id
29696          , x_value_segment_code       => l_adr_value_segment_code
29697          , p_side                     => 'NA'
29698          , p_override_seg_flag        => 'Y'
29699    );
29700 
29701    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
29702 
29703       xla_ae_lines_pkg.set_segment(
29704           p_to_segment_code         => 'GL_ACCOUNT'
29705         , p_segment_value           => l_segment
29706         , p_from_segment_code       => l_adr_value_segment_code
29707         , p_from_combination_id     => l_adr_value_combination_id
29708         , p_value_type_code         => l_adr_value_type_code
29712         , p_flex_value_set_id       => l_adr_flex_value_set_id
29709         , p_transaction_coa_id      => l_adr_transaction_coa_id
29710         , p_accounting_coa_id       => l_adr_accounting_coa_id
29711         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
29713         , p_adr_code                => 'FV_AR_4X0201_RCT_DR'
29714         , p_adr_type_code           => 'S'
29715         , p_component_type          => l_component_type
29716         , p_component_code          => l_component_code
29717         , p_component_type_code     => l_component_type_code
29718         , p_component_appl_id       => l_component_appl_id
29719         , p_amb_context_code        => l_amb_context_code
29720         , p_entity_code             => 'RECEIPTS'
29721         , p_event_class_code        => 'RECEIPT'
29722         , p_side                    => 'NA'
29723         );
29724 
29725   END IF;
29726 
29727    l_segment := AcctDerRule_5(
29728            p_application_id           => p_application_id
29729          , p_ae_header_id             => l_ae_header_id 
29730 , p_source_4 => p_source_4
29731          , x_transaction_coa_id       => l_adr_transaction_coa_id
29732          , x_accounting_coa_id        => l_adr_accounting_coa_id
29733          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
29734          , x_flex_value_set_id        => l_adr_flex_value_set_id
29735          , x_value_type_code          => l_adr_value_type_code
29736          , x_value_combination_id     => l_adr_value_combination_id
29737          , x_value_segment_code       => l_adr_value_segment_code
29738          , p_side                     => 'NA'
29739          , p_override_seg_flag        => 'Y'
29740    );
29741 
29742    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
29743 
29744       xla_ae_lines_pkg.set_segment(
29745           p_to_segment_code         => 'GL_BALANCING'
29746         , p_segment_value           => l_segment
29747         , p_from_segment_code       => l_adr_value_segment_code
29748         , p_from_combination_id     => l_adr_value_combination_id
29749         , p_value_type_code         => l_adr_value_type_code
29750         , p_transaction_coa_id      => l_adr_transaction_coa_id
29751         , p_accounting_coa_id       => l_adr_accounting_coa_id
29752         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
29753         , p_flex_value_set_id       => l_adr_flex_value_set_id
29754         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
29755         , p_adr_type_code           => 'S'
29756         , p_component_type          => l_component_type
29757         , p_component_code          => l_component_code
29758         , p_component_type_code     => l_component_type_code
29759         , p_component_appl_id       => l_component_appl_id
29760         , p_amb_context_code        => l_amb_context_code
29761         , p_entity_code             => 'RECEIPTS'
29762         , p_event_class_code        => 'RECEIPT'
29763         , p_side                    => 'NA'
29764         );
29765 
29766   END IF;
29767 
29768    --
29769    --
29770    END IF;
29771 
29772        --
29773        -- Update the line information that should be overwritten
29774        --
29775        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
29776                                          p_header_num   => 1);
29777        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
29778 
29779        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
29780 
29781        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
29782           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
29783        END IF;
29784 
29785       --
29786       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
29787       --
29788       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
29789           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
29790       ELSE
29791           ---------------------------------------------------------------------------------------------------
29792           -- 4262811a Switch Sign
29793           ---------------------------------------------------------------------------------------------------
29794           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
29795           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
29796                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
29797           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
29798                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
29799           -- 5132302
29800           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
29801                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
29802 
29803       END IF;
29804 
29805       -- 4955764
29806       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
29807       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
29808 
29809 
29810       XLA_AE_LINES_PKG.ValidateCurrentLine;
29814                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
29811       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
29812 
29813       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
29815                ,p_balance_type_code => l_balance_type_code);
29816 
29817    END IF;
29818 
29819    -----------------------------------------------------------------------------------------
29820    -- 4262811 Multiperiod Accounting
29821    -----------------------------------------------------------------------------------------
29822      -- No MPA option is assigned.
29823 
29824 
29825 END IF;
29826 END IF;
29827 --
29828 
29829 --
29830 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
29831    trace
29832       (p_msg      => 'END of AcctLineType_72'
29833       ,p_level    => C_LEVEL_PROCEDURE
29834       ,p_module   => l_log_module);
29835 END IF;
29836 --
29837 EXCEPTION
29838   WHEN xla_exceptions_pkg.application_exception THEN
29839       RAISE;
29840   WHEN OTHERS THEN
29841        xla_exceptions_pkg.raise_message
29842            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_72');
29843 END AcctLineType_72;
29844 --
29845 
29846 ---------------------------------------
29847 --
29848 -- PRIVATE FUNCTION
29849 --         AcctLineType_73
29850 --
29851 ---------------------------------------
29852 PROCEDURE AcctLineType_73 (
29853   p_application_id        IN NUMBER
29854  ,p_event_id              IN NUMBER
29855  ,p_calculate_acctd_flag  IN VARCHAR2
29856  ,p_calculate_g_l_flag    IN VARCHAR2
29857  ,p_actual_flag           IN OUT VARCHAR2
29858  ,p_balance_type_code     OUT VARCHAR2
29859  ,p_gain_or_loss_ref      OUT VARCHAR2
29860  
29861 --Distribution GL Account
29862  , p_source_3            IN NUMBER
29863 --Transaction Distribution GL Account
29864  , p_source_4            IN NUMBER
29865 --Federal Account Rule
29866  , p_source_7            IN VARCHAR2
29867 --Federal Fund Expired Status
29868  , p_source_8            IN VARCHAR2
29869 --Federal Prior Year Flag
29870  , p_source_9            IN VARCHAR2
29871 --Federal Fund Time Frame
29872  , p_source_10            IN VARCHAR2
29873 --Distribution Source Type
29874  , p_source_20            IN VARCHAR2
29875 --Distribution Line Identifier
29876  , p_source_22            IN NUMBER
29877 --Distribution Type
29878  , p_source_23            IN VARCHAR2
29879 --Entered Amount
29880  , p_source_24            IN NUMBER
29881 --Exchange Rate Type
29882  , p_source_28            IN VARCHAR2
29883 --Applied To Document Accounting Amount
29884  , p_source_29            IN NUMBER
29885 --Transaction Distribution Account Class
29886  , p_source_33            IN VARCHAR2
29887 --Transaction Distribution Identifier
29888  , p_source_34            IN NUMBER
29889 --Transaction Distribution Type
29890  , p_source_35            IN VARCHAR2
29891 --Federal Account Valid Flag
29892  , p_source_56            IN VARCHAR2
29893 --Applied To Document Exchange Date
29894  , p_source_57            IN DATE
29895 --Receipt Applied To Application Identifier
29896  , p_source_58            IN NUMBER
29897 --Transaction Entity Code
29898  , p_source_59            IN VARCHAR2
29899 --Transaction Identifier
29900  , p_source_60            IN NUMBER
29901 --Applying Document Currency Code
29902  , p_source_61            IN VARCHAR2
29903 --Applied To Document Exchange Rate
29904  , p_source_62            IN NUMBER
29905 --Distribution Party Identifier
29906  , p_source_63            IN NUMBER
29907 --Distribution Party Site Id
29908  , p_source_64            IN NUMBER
29909 --Distribution Party Type
29910  , p_source_65            IN VARCHAR2
29911 )
29912 IS
29913 
29914 l_component_type              VARCHAR2(80);
29915 l_component_code              VARCHAR2(30);
29916 l_component_type_code         VARCHAR2(1);
29917 l_component_appl_id           INTEGER;
29918 l_amb_context_code            VARCHAR2(30);
29919 l_entity_code                 VARCHAR2(30);
29920 l_event_class_code            VARCHAR2(30);
29921 l_ae_header_id                NUMBER;
29922 l_event_type_code             VARCHAR2(30);
29923 l_line_definition_code        VARCHAR2(30);
29924 l_line_definition_owner_code  VARCHAR2(1);
29925 --
29926 -- adr variables
29927 l_segment                     VARCHAR2(30);
29928 l_ccid                        NUMBER;
29929 l_adr_transaction_coa_id      NUMBER;
29930 l_adr_accounting_coa_id       NUMBER;
29931 l_adr_flexfield_segment_code  VARCHAR2(30);
29932 l_adr_flex_value_set_id       NUMBER;
29933 l_adr_value_type_code         VARCHAR2(30);
29934 l_adr_value_combination_id    NUMBER;
29935 l_adr_value_segment_code      VARCHAR2(30);
29936 
29937 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
29938 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
29939 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
29940 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
29941 
29942 -- 4262811 Variables ------------------------------------------------------------------------------------------
29943 l_entered_amt_idx             NUMBER;
29944 l_accted_amt_idx              NUMBER;
29945 l_acc_rev_flag                VARCHAR2(1);
29946 l_accrual_line_num            NUMBER;
29950 l_num_entries                 NUMBER;
29947 l_tmp_amt                     NUMBER;
29948 l_acc_rev_natural_side_code   VARCHAR2(1);
29949 
29951 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
29952 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
29953 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
29954 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
29955 l_recog_line_1                NUMBER;
29956 l_recog_line_2                NUMBER;
29957 
29958 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
29959 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
29960 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
29961 
29962 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
29963 
29964 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
29965 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
29966 
29967 ---------------------------------------------------------------------------------------------------------------
29968 
29969 
29970 --
29971 -- bulk performance
29972 --
29973 l_balance_type_code           VARCHAR2(1);
29974 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
29975 l_log_module                  VARCHAR2(240);
29976 
29977 --
29978 -- Upgrade strategy
29979 --
29980 l_actual_upg_option           VARCHAR2(1);
29981 l_enc_upg_option           VARCHAR2(1);
29982 
29983 --
29984 BEGIN
29985 --
29986 IF g_log_enabled THEN
29987       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_73';
29988 END IF;
29989 --
29990 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
29991 
29992       trace
29993          (p_msg      => 'BEGIN of AcctLineType_73'
29994          ,p_level    => C_LEVEL_PROCEDURE
29995          ,p_module   => l_log_module);
29996 
29997 END IF;
29998 --
29999 l_component_type             := 'AMB_JLT';
30000 l_component_code             := 'FV_RCT_REF_OAP_UFP_CR';
30001 l_component_type_code        := 'S';
30002 l_component_appl_id          :=  222;
30003 l_amb_context_code           := 'DEFAULT';
30004 l_entity_code                := 'RECEIPTS';
30005 l_event_class_code           := 'RECEIPT';
30006 l_event_type_code            := 'RECEIPT_ALL';
30007 l_line_definition_owner_code := 'S';
30008 l_line_definition_code       := 'MFAR_FED_AR_RCT_BALANCING';
30009 --
30010 l_balance_type_code          := 'A';
30011 l_segment                     := NULL;
30012 l_ccid                        := NULL;
30013 l_adr_transaction_coa_id      := NULL;
30014 l_adr_accounting_coa_id       := NULL;
30015 l_adr_flexfield_segment_code  := NULL;
30016 l_adr_flex_value_set_id       := NULL;
30017 l_adr_value_type_code         := NULL;
30018 l_adr_value_combination_id    := NULL;
30019 l_adr_value_segment_code      := NULL;
30020 
30021 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
30022 l_bflow_class_code           := '';    -- 4219869 Business Flow
30023 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
30024 l_budgetary_control_flag     := 'N';
30025 
30026 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
30027 l_bflow_applied_to_amt       := NULL; -- 5132302
30028 l_entered_amt_idx            := NULL;          -- 4262811
30029 l_accted_amt_idx             := NULL;          -- 4262811
30030 l_acc_rev_flag               := NULL;          -- 4262811
30031 l_accrual_line_num           := NULL;          -- 4262811
30032 l_tmp_amt                    := NULL;          -- 4262811
30033 --
30034  
30035 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
30036     l_balance_type_code <> 'B' THEN
30037 IF NVL(p_source_20,'
30038 ') =  'REC' AND 
30039 NVL(p_source_33,'
30040 ') =  'REV' AND 
30041 NVL(p_source_8,'
30042 ') =  'Unexpired' AND 
30043 NVL(p_source_9,'
30044 ') =  'Y' AND 
30045 (NVL(p_source_10,'
30046 ') =  'MUTIPLE' OR 
30047 NVL(p_source_10,'
30048 ') =  'NO_YEAR') AND 
30049 (NVL(p_source_7,'
30050 ') =  'Overpayment Refund' OR 
30051 NVL(p_source_7,'
30052 ') =  'Advance Refund') AND 
30053 NVL(p_source_56,'
30054 ') =  'Y'
30055  THEN 
30056 
30057    --
30058    XLA_AE_LINES_PKG.SetNewLine;
30059 
30060    p_balance_type_code          := l_balance_type_code;
30061    -- set the flag so later we will know whether the gain loss line needs to be created
30062    
30063    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
30064      p_actual_flag :='A';
30065    END IF;
30066 
30067    --
30068    -- bulk performance
30069    --
30070    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
30071                                       p_header_num   => 0); -- 4262811
30072    --
30073    -- set accounting line options
30074    --
30075    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
30076            p_natural_side_code          => 'C'
30077          , p_gain_or_loss_flag          => 'N'
30078          , p_gl_transfer_mode_code      => 'S'
30079          , p_acct_entry_type_code       => 'A'
30080          , p_switch_side_flag           => 'Y'
30081          , p_merge_duplicate_code       => 'A'
30082          );
30083    --
30084    l_acc_rev_natural_side_code := 'D';  -- 4262811
30085    -- 
30086    --
30090       (p_component_type             => l_component_type
30087    -- set accounting line type info
30088    --
30089    xla_ae_lines_pkg.SetAcctLineType
30091       ,p_event_type_code            => l_event_type_code
30092       ,p_line_definition_owner_code => l_line_definition_owner_code
30093       ,p_line_definition_code       => l_line_definition_code
30094       ,p_accounting_line_code       => l_component_code
30095       ,p_accounting_line_type_code  => l_component_type_code
30096       ,p_accounting_line_appl_id    => l_component_appl_id
30097       ,p_amb_context_code           => l_amb_context_code
30098       ,p_entity_code                => l_entity_code
30099       ,p_event_class_code           => l_event_class_code);
30100    --
30101    -- set accounting class
30102    --
30103    xla_ae_lines_pkg.SetAcctClass(
30104            p_accounting_class_code  => 'FV_CASH_CR'
30105          , p_ae_header_id           => l_ae_header_id
30106          );
30107 
30108    --
30109    -- set rounding class
30110    --
30111    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
30112                       'RECEIVABLE';
30113 
30114    --
30115    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
30116    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
30117    --
30118    -- bulk performance
30119    --
30120    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
30121 
30122    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
30123       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
30124 
30125    -- 4955764
30126    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
30127       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
30128 
30129    -- 4458381 Public Sector Enh
30130    
30131    --
30132    -- set accounting attributes for the line type
30133    --
30134    l_entered_amt_idx := 8;
30135    l_accted_amt_idx  := 13;
30136    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
30137    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
30138    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
30139    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
30140    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
30141    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
30142    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
30143    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
30144    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
30145    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
30146    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
30147    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
30148    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
30149    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
30150    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
30151    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
30152    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
30153    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
30154    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
30155    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
30156    l_rec_acct_attrs.array_date_value(10)  := p_source_57;
30157    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
30158    l_rec_acct_attrs.array_num_value(11)  := p_source_62;
30159    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
30160    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
30161    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
30162    l_rec_acct_attrs.array_num_value(13)  := p_source_29;
30163    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
30164    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
30165    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
30166    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
30167    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
30168    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
30169 
30170    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
30171    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
30172 
30173    ---------------------------------------------------------------------------------------------------------------
30174    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
30175    ---------------------------------------------------------------------------------------------------------------
30176    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
30177 
30178    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
30179    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
30180 
30181    IF xla_accounting_cache_pkg.GetValueChar
30182          (p_source_code         => 'LEDGER_CATEGORY_CODE'
30183          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
30184    AND l_bflow_method_code = 'PRIOR_ENTRY'
30185 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
30189    THEN
30186    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
30187          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
30188        )
30190          xla_ae_lines_pkg.BflowUpgEntry
30191            (p_business_method_code    => l_bflow_method_code
30192            ,p_business_class_code     => l_bflow_class_code
30193            ,p_balance_type            => l_balance_type_code);
30194    ELSE
30195       NULL;
30196 -- No business flow processing for business flow method of NONE.
30197    END IF;
30198 
30199    --
30200    -- call analytical criteria
30201    --
30202    
30203    --
30204    -- call description
30205    --
30206    -- No description or it is inherited.
30207    --
30208    -- call ADRs
30209    -- Bug 4922099
30210    --
30211    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
30212         (NVL(l_actual_upg_option, 'N') = 'O') OR
30213         (NVL(l_enc_upg_option, 'N') = 'O')
30214       )
30215    THEN
30216    NULL;
30217    --
30218    --
30219    
30220   l_ccid := AcctDerRule_7(
30221            p_application_id           => p_application_id
30222          , p_ae_header_id             => l_ae_header_id 
30223 , p_source_3 => p_source_3
30224          , x_transaction_coa_id       => l_adr_transaction_coa_id
30225          , x_accounting_coa_id        => l_adr_accounting_coa_id
30226          , x_value_type_code          => l_adr_value_type_code
30227          , p_side                     => 'NA'
30228    );
30229 
30230    xla_ae_lines_pkg.set_ccid(
30231     p_code_combination_id          => l_ccid
30232   , p_value_type_code              => l_adr_value_type_code
30233   , p_transaction_coa_id           => l_adr_transaction_coa_id
30234   , p_accounting_coa_id            => l_adr_accounting_coa_id
30235   , p_adr_code                     => 'DIST_CCID'
30236   , p_adr_type_code                => 'S'
30237   , p_component_type               => l_component_type
30238   , p_component_code               => l_component_code
30239   , p_component_type_code          => l_component_type_code
30240   , p_component_appl_id            => l_component_appl_id
30241   , p_amb_context_code             => l_amb_context_code
30242   , p_side                         => 'NA'
30243   );
30244 
30245 
30246    l_segment := AcctDerRule_15(
30247            p_application_id           => p_application_id
30248          , p_ae_header_id             => l_ae_header_id 
30249 , p_source_8 => p_source_8
30250 , p_source_9 => p_source_9
30251 , p_source_10 => p_source_10
30252          , x_transaction_coa_id       => l_adr_transaction_coa_id
30253          , x_accounting_coa_id        => l_adr_accounting_coa_id
30254          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
30255          , x_flex_value_set_id        => l_adr_flex_value_set_id
30256          , x_value_type_code          => l_adr_value_type_code
30257          , x_value_combination_id     => l_adr_value_combination_id
30258          , x_value_segment_code       => l_adr_value_segment_code
30259          , p_side                     => 'NA'
30260          , p_override_seg_flag        => 'Y'
30261    );
30262 
30263    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
30264 
30265       xla_ae_lines_pkg.set_segment(
30266           p_to_segment_code         => 'GL_ACCOUNT'
30267         , p_segment_value           => l_segment
30268         , p_from_segment_code       => l_adr_value_segment_code
30269         , p_from_combination_id     => l_adr_value_combination_id
30270         , p_value_type_code         => l_adr_value_type_code
30271         , p_transaction_coa_id      => l_adr_transaction_coa_id
30272         , p_accounting_coa_id       => l_adr_accounting_coa_id
30273         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
30274         , p_flex_value_set_id       => l_adr_flex_value_set_id
30275         , p_adr_code                => 'FV_AR_445001_RCT_CR'
30276         , p_adr_type_code           => 'S'
30277         , p_component_type          => l_component_type
30278         , p_component_code          => l_component_code
30279         , p_component_type_code     => l_component_type_code
30280         , p_component_appl_id       => l_component_appl_id
30281         , p_amb_context_code        => l_amb_context_code
30282         , p_entity_code             => 'RECEIPTS'
30283         , p_event_class_code        => 'RECEIPT'
30284         , p_side                    => 'NA'
30285         );
30286 
30287   END IF;
30288 
30289    l_segment := AcctDerRule_5(
30290            p_application_id           => p_application_id
30291          , p_ae_header_id             => l_ae_header_id 
30292 , p_source_4 => p_source_4
30293          , x_transaction_coa_id       => l_adr_transaction_coa_id
30294          , x_accounting_coa_id        => l_adr_accounting_coa_id
30295          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
30296          , x_flex_value_set_id        => l_adr_flex_value_set_id
30297          , x_value_type_code          => l_adr_value_type_code
30298          , x_value_combination_id     => l_adr_value_combination_id
30299          , x_value_segment_code       => l_adr_value_segment_code
30300          , p_side                     => 'NA'
30301          , p_override_seg_flag        => 'Y'
30302    );
30303 
30304    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
30305 
30306       xla_ae_lines_pkg.set_segment(
30307           p_to_segment_code         => 'GL_BALANCING'
30308         , p_segment_value           => l_segment
30312         , p_transaction_coa_id      => l_adr_transaction_coa_id
30309         , p_from_segment_code       => l_adr_value_segment_code
30310         , p_from_combination_id     => l_adr_value_combination_id
30311         , p_value_type_code         => l_adr_value_type_code
30313         , p_accounting_coa_id       => l_adr_accounting_coa_id
30314         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
30315         , p_flex_value_set_id       => l_adr_flex_value_set_id
30316         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
30317         , p_adr_type_code           => 'S'
30318         , p_component_type          => l_component_type
30319         , p_component_code          => l_component_code
30320         , p_component_type_code     => l_component_type_code
30321         , p_component_appl_id       => l_component_appl_id
30322         , p_amb_context_code        => l_amb_context_code
30323         , p_entity_code             => 'RECEIPTS'
30324         , p_event_class_code        => 'RECEIPT'
30325         , p_side                    => 'NA'
30326         );
30327 
30328   END IF;
30329 
30330    --
30331    --
30332    END IF;
30333    --
30334    -- Bug 4922099
30335    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
30336           (NVL(l_enc_upg_option, 'N') = 'O')
30337         ) AND
30338         (l_bflow_method_code = 'PRIOR_ENTRY')
30339       )
30340    THEN
30341       IF
30342       --
30343       1 = 2
30344       --
30345       THEN
30346       xla_accounting_err_pkg.build_message
30347                                     (p_appli_s_name            => 'XLA'
30348                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
30349                                     ,p_token_1                 => 'LINE_NUMBER'
30350                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
30351                                     ,p_token_2                 => 'LINE_TYPE_NAME'
30352                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
30353                                                                              l_component_type
30354                                                                             ,l_component_code
30355                                                                             ,l_component_type_code
30356                                                                             ,l_component_appl_id
30357                                                                             ,l_amb_context_code
30358                                                                             ,l_entity_code
30359                                                                             ,l_event_class_code
30360                                                                            )
30361                                     ,p_token_3                 => 'OWNER'
30362                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
30363                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
30364                                                                           ,p_lookup_code    => l_component_type_code
30365                                                                          )
30366                                     ,p_token_4                 => 'PRODUCT_NAME'
30367                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
30368                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
30369                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
30370                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
30371                                     ,p_ae_header_id            =>  NULL
30372                                        );
30373 
30374         IF (C_LEVEL_ERROR>= g_log_level) THEN
30375                  trace
30376                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
30377                       ,p_level    => C_LEVEL_ERROR
30378                       ,p_module   => l_log_module);
30379         END IF;
30380       END IF;
30381    END IF;
30382    --
30383    --
30384    ------------------------------------------------------------------------------------------------
30385    -- 4219869 Business Flow
30386    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
30387    -- Prior Entry.  Currently, the following code is always generated.
30388    ------------------------------------------------------------------------------------------------
30389    XLA_AE_LINES_PKG.ValidateCurrentLine;
30390 
30391    ------------------------------------------------------------------------------------
30392    -- 4219869 Business Flow
30393    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
30394    ------------------------------------------------------------------------------------
30395    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
30396 
30397    ----------------------------------------------------------------------------------
30398    -- 4219869 Business Flow
30399    -- Update journal entry status -- Need to generate this within IF <condition>
30400    ----------------------------------------------------------------------------------
30401    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
30405 
30402          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
30403          ,p_balance_type_code => l_balance_type_code
30404          );
30406    -------------------------------------------------------------------------------------------
30407    -- 4262811 - Generate the Accrual Reversal lines
30408    -------------------------------------------------------------------------------------------
30409    BEGIN
30410       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
30411                               (g_array_event(p_event_id).array_value_num('header_index'));
30412       IF l_acc_rev_flag IS NULL THEN
30413          l_acc_rev_flag := 'N';
30414       END IF;
30415    EXCEPTION
30416       WHEN OTHERS THEN
30417          l_acc_rev_flag := 'N';
30418    END;
30419    --
30420    IF (l_acc_rev_flag = 'Y') THEN
30421 
30422        -- 4645092  ------------------------------------------------------------------------------
30423        -- To allow MPA report to determine if it should generate report process
30424        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
30425        ------------------------------------------------------------------------------------------
30426 
30427        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
30428        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
30429    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
30430    -- call ADRs
30431    -- Bug 4922099
30432    --
30433    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
30434         (NVL(l_actual_upg_option, 'N') = 'O') OR
30435         (NVL(l_enc_upg_option, 'N') = 'O')
30436       )
30437    THEN
30438    NULL;
30439    --
30440    --
30441    
30442   l_ccid := AcctDerRule_7(
30443            p_application_id           => p_application_id
30444          , p_ae_header_id             => l_ae_header_id 
30445 , p_source_3 => p_source_3
30446          , x_transaction_coa_id       => l_adr_transaction_coa_id
30447          , x_accounting_coa_id        => l_adr_accounting_coa_id
30448          , x_value_type_code          => l_adr_value_type_code
30449          , p_side                     => 'NA'
30450    );
30451 
30452    xla_ae_lines_pkg.set_ccid(
30453     p_code_combination_id          => l_ccid
30454   , p_value_type_code              => l_adr_value_type_code
30455   , p_transaction_coa_id           => l_adr_transaction_coa_id
30456   , p_accounting_coa_id            => l_adr_accounting_coa_id
30457   , p_adr_code                     => 'DIST_CCID'
30458   , p_adr_type_code                => 'S'
30459   , p_component_type               => l_component_type
30460   , p_component_code               => l_component_code
30461   , p_component_type_code          => l_component_type_code
30462   , p_component_appl_id            => l_component_appl_id
30463   , p_amb_context_code             => l_amb_context_code
30464   , p_side                         => 'NA'
30465   );
30466 
30467 
30468    l_segment := AcctDerRule_15(
30469            p_application_id           => p_application_id
30470          , p_ae_header_id             => l_ae_header_id 
30471 , p_source_8 => p_source_8
30472 , p_source_9 => p_source_9
30473 , p_source_10 => p_source_10
30474          , x_transaction_coa_id       => l_adr_transaction_coa_id
30475          , x_accounting_coa_id        => l_adr_accounting_coa_id
30476          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
30477          , x_flex_value_set_id        => l_adr_flex_value_set_id
30478          , x_value_type_code          => l_adr_value_type_code
30479          , x_value_combination_id     => l_adr_value_combination_id
30480          , x_value_segment_code       => l_adr_value_segment_code
30481          , p_side                     => 'NA'
30482          , p_override_seg_flag        => 'Y'
30483    );
30484 
30485    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
30486 
30487       xla_ae_lines_pkg.set_segment(
30488           p_to_segment_code         => 'GL_ACCOUNT'
30489         , p_segment_value           => l_segment
30490         , p_from_segment_code       => l_adr_value_segment_code
30491         , p_from_combination_id     => l_adr_value_combination_id
30492         , p_value_type_code         => l_adr_value_type_code
30493         , p_transaction_coa_id      => l_adr_transaction_coa_id
30494         , p_accounting_coa_id       => l_adr_accounting_coa_id
30495         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
30496         , p_flex_value_set_id       => l_adr_flex_value_set_id
30497         , p_adr_code                => 'FV_AR_445001_RCT_CR'
30498         , p_adr_type_code           => 'S'
30499         , p_component_type          => l_component_type
30500         , p_component_code          => l_component_code
30501         , p_component_type_code     => l_component_type_code
30502         , p_component_appl_id       => l_component_appl_id
30503         , p_amb_context_code        => l_amb_context_code
30504         , p_entity_code             => 'RECEIPTS'
30505         , p_event_class_code        => 'RECEIPT'
30506         , p_side                    => 'NA'
30507         );
30508 
30509   END IF;
30510 
30511    l_segment := AcctDerRule_5(
30512            p_application_id           => p_application_id
30513          , p_ae_header_id             => l_ae_header_id 
30514 , p_source_4 => p_source_4
30515          , x_transaction_coa_id       => l_adr_transaction_coa_id
30519          , x_value_type_code          => l_adr_value_type_code
30516          , x_accounting_coa_id        => l_adr_accounting_coa_id
30517          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
30518          , x_flex_value_set_id        => l_adr_flex_value_set_id
30520          , x_value_combination_id     => l_adr_value_combination_id
30521          , x_value_segment_code       => l_adr_value_segment_code
30522          , p_side                     => 'NA'
30523          , p_override_seg_flag        => 'Y'
30524    );
30525 
30526    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
30527 
30528       xla_ae_lines_pkg.set_segment(
30529           p_to_segment_code         => 'GL_BALANCING'
30530         , p_segment_value           => l_segment
30531         , p_from_segment_code       => l_adr_value_segment_code
30532         , p_from_combination_id     => l_adr_value_combination_id
30533         , p_value_type_code         => l_adr_value_type_code
30534         , p_transaction_coa_id      => l_adr_transaction_coa_id
30535         , p_accounting_coa_id       => l_adr_accounting_coa_id
30536         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
30537         , p_flex_value_set_id       => l_adr_flex_value_set_id
30538         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
30539         , p_adr_type_code           => 'S'
30540         , p_component_type          => l_component_type
30541         , p_component_code          => l_component_code
30542         , p_component_type_code     => l_component_type_code
30543         , p_component_appl_id       => l_component_appl_id
30544         , p_amb_context_code        => l_amb_context_code
30545         , p_entity_code             => 'RECEIPTS'
30546         , p_event_class_code        => 'RECEIPT'
30547         , p_side                    => 'NA'
30548         );
30549 
30550   END IF;
30551 
30552    --
30553    --
30554    END IF;
30555 
30556        --
30557        -- Update the line information that should be overwritten
30558        --
30559        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
30560                                          p_header_num   => 1);
30561        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
30562 
30563        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
30564 
30565        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
30566           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
30567        END IF;
30568 
30569       --
30570       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
30571       --
30572       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
30573           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
30574       ELSE
30575           ---------------------------------------------------------------------------------------------------
30576           -- 4262811a Switch Sign
30577           ---------------------------------------------------------------------------------------------------
30578           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
30579           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
30580                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
30581           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
30582                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
30583           -- 5132302
30584           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
30585                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
30586 
30587       END IF;
30588 
30589       -- 4955764
30590       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
30591       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
30592 
30593 
30594       XLA_AE_LINES_PKG.ValidateCurrentLine;
30595       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
30596 
30597       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
30598                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
30599                ,p_balance_type_code => l_balance_type_code);
30600 
30601    END IF;
30602 
30603    -----------------------------------------------------------------------------------------
30604    -- 4262811 Multiperiod Accounting
30605    -----------------------------------------------------------------------------------------
30606      -- No MPA option is assigned.
30607 
30608 
30609 END IF;
30610 END IF;
30611 --
30612 
30613 --
30614 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
30615    trace
30616       (p_msg      => 'END of AcctLineType_73'
30617       ,p_level    => C_LEVEL_PROCEDURE
30618       ,p_module   => l_log_module);
30619 END IF;
30620 --
30621 EXCEPTION
30622   WHEN xla_exceptions_pkg.application_exception THEN
30623       RAISE;
30624   WHEN OTHERS THEN
30625        xla_exceptions_pkg.raise_message
30626            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_73');
30627 END AcctLineType_73;
30628 --
30629 
30630 ---------------------------------------
30634 --
30631 --
30632 -- PRIVATE FUNCTION
30633 --         AcctLineType_74
30635 ---------------------------------------
30636 PROCEDURE AcctLineType_74 (
30637   p_application_id        IN NUMBER
30638  ,p_event_id              IN NUMBER
30639  ,p_calculate_acctd_flag  IN VARCHAR2
30640  ,p_calculate_g_l_flag    IN VARCHAR2
30641  ,p_actual_flag           IN OUT VARCHAR2
30642  ,p_balance_type_code     OUT VARCHAR2
30643  ,p_gain_or_loss_ref      OUT VARCHAR2
30644  
30645 --Distribution GL Account
30646  , p_source_3            IN NUMBER
30647 --Transaction Distribution GL Account
30648  , p_source_4            IN NUMBER
30649 --Federal Account Rule
30650  , p_source_7            IN VARCHAR2
30651 --Federal Fund Expired Status
30652  , p_source_8            IN VARCHAR2
30653 --Federal Prior Year Flag
30654  , p_source_9            IN VARCHAR2
30655 --Federal Fund Time Frame
30656  , p_source_10            IN VARCHAR2
30657 --Distribution Source Type
30658  , p_source_20            IN VARCHAR2
30659 --Distribution Line Identifier
30660  , p_source_22            IN NUMBER
30661 --Distribution Type
30662  , p_source_23            IN VARCHAR2
30663 --Entered Amount
30664  , p_source_24            IN NUMBER
30665 --Exchange Rate Type
30666  , p_source_28            IN VARCHAR2
30667 --Applied To Document Accounting Amount
30668  , p_source_29            IN NUMBER
30669 --Transaction Distribution Account Class
30670  , p_source_33            IN VARCHAR2
30671 --Transaction Distribution Identifier
30672  , p_source_34            IN NUMBER
30673 --Transaction Distribution Type
30674  , p_source_35            IN VARCHAR2
30675 --Federal Account Valid Flag
30676  , p_source_56            IN VARCHAR2
30677 --Applied To Document Exchange Date
30678  , p_source_57            IN DATE
30679 --Receipt Applied To Application Identifier
30680  , p_source_58            IN NUMBER
30681 --Transaction Entity Code
30682  , p_source_59            IN VARCHAR2
30683 --Transaction Identifier
30684  , p_source_60            IN NUMBER
30685 --Applying Document Currency Code
30686  , p_source_61            IN VARCHAR2
30687 --Applied To Document Exchange Rate
30688  , p_source_62            IN NUMBER
30689 --Distribution Party Identifier
30690  , p_source_63            IN NUMBER
30691 --Distribution Party Site Id
30692  , p_source_64            IN NUMBER
30693 --Distribution Party Type
30694  , p_source_65            IN VARCHAR2
30695 )
30696 IS
30697 
30698 l_component_type              VARCHAR2(80);
30699 l_component_code              VARCHAR2(30);
30700 l_component_type_code         VARCHAR2(1);
30701 l_component_appl_id           INTEGER;
30702 l_amb_context_code            VARCHAR2(30);
30703 l_entity_code                 VARCHAR2(30);
30704 l_event_class_code            VARCHAR2(30);
30705 l_ae_header_id                NUMBER;
30706 l_event_type_code             VARCHAR2(30);
30707 l_line_definition_code        VARCHAR2(30);
30708 l_line_definition_owner_code  VARCHAR2(1);
30709 --
30710 -- adr variables
30711 l_segment                     VARCHAR2(30);
30712 l_ccid                        NUMBER;
30713 l_adr_transaction_coa_id      NUMBER;
30714 l_adr_accounting_coa_id       NUMBER;
30715 l_adr_flexfield_segment_code  VARCHAR2(30);
30716 l_adr_flex_value_set_id       NUMBER;
30717 l_adr_value_type_code         VARCHAR2(30);
30718 l_adr_value_combination_id    NUMBER;
30719 l_adr_value_segment_code      VARCHAR2(30);
30720 
30721 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
30722 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
30723 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
30724 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
30725 
30726 -- 4262811 Variables ------------------------------------------------------------------------------------------
30727 l_entered_amt_idx             NUMBER;
30728 l_accted_amt_idx              NUMBER;
30729 l_acc_rev_flag                VARCHAR2(1);
30730 l_accrual_line_num            NUMBER;
30731 l_tmp_amt                     NUMBER;
30732 l_acc_rev_natural_side_code   VARCHAR2(1);
30733 
30734 l_num_entries                 NUMBER;
30735 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
30736 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
30737 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
30738 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
30739 l_recog_line_1                NUMBER;
30740 l_recog_line_2                NUMBER;
30741 
30742 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
30743 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
30744 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
30745 
30746 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
30747 
30748 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
30749 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
30750 
30751 ---------------------------------------------------------------------------------------------------------------
30752 
30753 
30754 --
30755 -- bulk performance
30756 --
30757 l_balance_type_code           VARCHAR2(1);
30758 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
30759 l_log_module                  VARCHAR2(240);
30760 
30764 l_actual_upg_option           VARCHAR2(1);
30761 --
30762 -- Upgrade strategy
30763 --
30765 l_enc_upg_option           VARCHAR2(1);
30766 
30767 --
30768 BEGIN
30769 --
30770 IF g_log_enabled THEN
30771       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_74';
30772 END IF;
30773 --
30774 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
30775 
30776       trace
30777          (p_msg      => 'BEGIN of AcctLineType_74'
30778          ,p_level    => C_LEVEL_PROCEDURE
30779          ,p_module   => l_log_module);
30780 
30781 END IF;
30782 --
30783 l_component_type             := 'AMB_JLT';
30784 l_component_code             := 'FV_RCT_REF_OAP_UFP_DR';
30785 l_component_type_code        := 'S';
30786 l_component_appl_id          :=  222;
30787 l_amb_context_code           := 'DEFAULT';
30788 l_entity_code                := 'RECEIPTS';
30789 l_event_class_code           := 'RECEIPT';
30790 l_event_type_code            := 'RECEIPT_ALL';
30791 l_line_definition_owner_code := 'S';
30792 l_line_definition_code       := 'MFAR_FED_AR_RCT_BALANCING';
30793 --
30794 l_balance_type_code          := 'A';
30795 l_segment                     := NULL;
30796 l_ccid                        := NULL;
30797 l_adr_transaction_coa_id      := NULL;
30798 l_adr_accounting_coa_id       := NULL;
30799 l_adr_flexfield_segment_code  := NULL;
30800 l_adr_flex_value_set_id       := NULL;
30801 l_adr_value_type_code         := NULL;
30802 l_adr_value_combination_id    := NULL;
30803 l_adr_value_segment_code      := NULL;
30804 
30805 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
30806 l_bflow_class_code           := '';    -- 4219869 Business Flow
30807 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
30808 l_budgetary_control_flag     := 'N';
30809 
30810 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
30811 l_bflow_applied_to_amt       := NULL; -- 5132302
30812 l_entered_amt_idx            := NULL;          -- 4262811
30813 l_accted_amt_idx             := NULL;          -- 4262811
30814 l_acc_rev_flag               := NULL;          -- 4262811
30815 l_accrual_line_num           := NULL;          -- 4262811
30816 l_tmp_amt                    := NULL;          -- 4262811
30817 --
30818  
30819 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
30820     l_balance_type_code <> 'B' THEN
30821 IF NVL(p_source_20,'
30822 ') =  'REC' AND 
30823 NVL(p_source_33,'
30824 ') =  'REV' AND 
30825 NVL(p_source_8,'
30826 ') =  'Unexpired' AND 
30827 NVL(p_source_9,'
30828 ') =  'Y' AND 
30829 (NVL(p_source_10,'
30830 ') =  'MUTIPLE' OR 
30831 NVL(p_source_10,'
30832 ') =  'NO_YEAR') AND 
30833 (NVL(p_source_7,'
30834 ') =  'Overpayment Refund' OR 
30835 NVL(p_source_7,'
30836 ') =  'Advance Refund') AND 
30837 NVL(p_source_56,'
30838 ') =  'Y'
30839  THEN 
30840 
30841    --
30842    XLA_AE_LINES_PKG.SetNewLine;
30843 
30844    p_balance_type_code          := l_balance_type_code;
30845    -- set the flag so later we will know whether the gain loss line needs to be created
30846    
30847    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
30848      p_actual_flag :='A';
30849    END IF;
30850 
30851    --
30852    -- bulk performance
30853    --
30854    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
30855                                       p_header_num   => 0); -- 4262811
30856    --
30857    -- set accounting line options
30858    --
30859    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
30860            p_natural_side_code          => 'D'
30861          , p_gain_or_loss_flag          => 'N'
30862          , p_gl_transfer_mode_code      => 'S'
30863          , p_acct_entry_type_code       => 'A'
30864          , p_switch_side_flag           => 'Y'
30865          , p_merge_duplicate_code       => 'A'
30866          );
30867    --
30868    l_acc_rev_natural_side_code := 'C';  -- 4262811
30869    -- 
30870    --
30871    -- set accounting line type info
30872    --
30873    xla_ae_lines_pkg.SetAcctLineType
30874       (p_component_type             => l_component_type
30875       ,p_event_type_code            => l_event_type_code
30876       ,p_line_definition_owner_code => l_line_definition_owner_code
30877       ,p_line_definition_code       => l_line_definition_code
30878       ,p_accounting_line_code       => l_component_code
30879       ,p_accounting_line_type_code  => l_component_type_code
30880       ,p_accounting_line_appl_id    => l_component_appl_id
30881       ,p_amb_context_code           => l_amb_context_code
30882       ,p_entity_code                => l_entity_code
30883       ,p_event_class_code           => l_event_class_code);
30884    --
30885    -- set accounting class
30886    --
30887    xla_ae_lines_pkg.SetAcctClass(
30888            p_accounting_class_code  => 'FV_CASH_DR'
30889          , p_ae_header_id           => l_ae_header_id
30890          );
30891 
30892    --
30893    -- set rounding class
30894    --
30895    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
30896                       'RECEIVABLE';
30897 
30898    --
30899    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
30903    --
30900    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
30901    --
30902    -- bulk performance
30904    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
30905 
30906    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
30907       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
30908 
30909    -- 4955764
30910    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
30911       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
30912 
30913    -- 4458381 Public Sector Enh
30914    
30915    --
30916    -- set accounting attributes for the line type
30917    --
30918    l_entered_amt_idx := 8;
30919    l_accted_amt_idx  := 13;
30920    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
30921    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
30922    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
30923    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
30924    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
30925    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
30926    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
30927    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
30928    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
30929    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
30930    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
30931    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
30932    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
30933    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
30934    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
30935    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
30936    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
30937    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
30938    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
30939    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
30940    l_rec_acct_attrs.array_date_value(10)  := p_source_57;
30941    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
30942    l_rec_acct_attrs.array_num_value(11)  := p_source_62;
30943    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
30944    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
30945    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
30946    l_rec_acct_attrs.array_num_value(13)  := p_source_29;
30947    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
30948    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
30949    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
30950    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
30951    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
30952    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
30953 
30954    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
30955    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
30956 
30957    ---------------------------------------------------------------------------------------------------------------
30958    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
30959    ---------------------------------------------------------------------------------------------------------------
30960    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
30961 
30962    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
30963    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
30964 
30965    IF xla_accounting_cache_pkg.GetValueChar
30966          (p_source_code         => 'LEDGER_CATEGORY_CODE'
30967          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
30968    AND l_bflow_method_code = 'PRIOR_ENTRY'
30969 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
30970    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
30971          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
30972        )
30973    THEN
30974          xla_ae_lines_pkg.BflowUpgEntry
30975            (p_business_method_code    => l_bflow_method_code
30976            ,p_business_class_code     => l_bflow_class_code
30977            ,p_balance_type            => l_balance_type_code);
30978    ELSE
30979       NULL;
30980 -- No business flow processing for business flow method of NONE.
30981    END IF;
30982 
30983    --
30984    -- call analytical criteria
30985    --
30986    
30987    --
30988    -- call description
30989    --
30990    -- No description or it is inherited.
30991    --
30992    -- call ADRs
30993    -- Bug 4922099
30994    --
30995    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
30996         (NVL(l_actual_upg_option, 'N') = 'O') OR
30997         (NVL(l_enc_upg_option, 'N') = 'O')
30998       )
30999    THEN
31000    NULL;
31001    --
31002    --
31003    
31004   l_ccid := AcctDerRule_7(
31005            p_application_id           => p_application_id
31006          , p_ae_header_id             => l_ae_header_id 
31010          , x_value_type_code          => l_adr_value_type_code
31007 , p_source_3 => p_source_3
31008          , x_transaction_coa_id       => l_adr_transaction_coa_id
31009          , x_accounting_coa_id        => l_adr_accounting_coa_id
31011          , p_side                     => 'NA'
31012    );
31013 
31014    xla_ae_lines_pkg.set_ccid(
31015     p_code_combination_id          => l_ccid
31016   , p_value_type_code              => l_adr_value_type_code
31017   , p_transaction_coa_id           => l_adr_transaction_coa_id
31018   , p_accounting_coa_id            => l_adr_accounting_coa_id
31019   , p_adr_code                     => 'DIST_CCID'
31020   , p_adr_type_code                => 'S'
31021   , p_component_type               => l_component_type
31022   , p_component_code               => l_component_code
31023   , p_component_type_code          => l_component_type_code
31024   , p_component_appl_id            => l_component_appl_id
31025   , p_amb_context_code             => l_amb_context_code
31026   , p_side                         => 'NA'
31027   );
31028 
31029 
31030    l_segment := AcctDerRule_23(
31031            p_application_id           => p_application_id
31032          , p_ae_header_id             => l_ae_header_id 
31033 , p_source_7 => p_source_7
31034 , p_source_8 => p_source_8
31035 , p_source_9 => p_source_9
31036 , p_source_10 => p_source_10
31037          , x_transaction_coa_id       => l_adr_transaction_coa_id
31038          , x_accounting_coa_id        => l_adr_accounting_coa_id
31039          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
31040          , x_flex_value_set_id        => l_adr_flex_value_set_id
31041          , x_value_type_code          => l_adr_value_type_code
31042          , x_value_combination_id     => l_adr_value_combination_id
31043          , x_value_segment_code       => l_adr_value_segment_code
31044          , p_side                     => 'NA'
31045          , p_override_seg_flag        => 'Y'
31046    );
31047 
31048    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
31049 
31050       xla_ae_lines_pkg.set_segment(
31051           p_to_segment_code         => 'GL_ACCOUNT'
31052         , p_segment_value           => l_segment
31053         , p_from_segment_code       => l_adr_value_segment_code
31054         , p_from_combination_id     => l_adr_value_combination_id
31055         , p_value_type_code         => l_adr_value_type_code
31056         , p_transaction_coa_id      => l_adr_transaction_coa_id
31057         , p_accounting_coa_id       => l_adr_accounting_coa_id
31058         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
31059         , p_flex_value_set_id       => l_adr_flex_value_set_id
31060         , p_adr_code                => 'FV_AR_4X7201_RCT_DR'
31061         , p_adr_type_code           => 'S'
31062         , p_component_type          => l_component_type
31063         , p_component_code          => l_component_code
31064         , p_component_type_code     => l_component_type_code
31065         , p_component_appl_id       => l_component_appl_id
31066         , p_amb_context_code        => l_amb_context_code
31067         , p_entity_code             => 'RECEIPTS'
31068         , p_event_class_code        => 'RECEIPT'
31069         , p_side                    => 'NA'
31070         );
31071 
31072   END IF;
31073 
31074    l_segment := AcctDerRule_5(
31075            p_application_id           => p_application_id
31076          , p_ae_header_id             => l_ae_header_id 
31077 , p_source_4 => p_source_4
31078          , x_transaction_coa_id       => l_adr_transaction_coa_id
31079          , x_accounting_coa_id        => l_adr_accounting_coa_id
31080          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
31081          , x_flex_value_set_id        => l_adr_flex_value_set_id
31082          , x_value_type_code          => l_adr_value_type_code
31083          , x_value_combination_id     => l_adr_value_combination_id
31084          , x_value_segment_code       => l_adr_value_segment_code
31085          , p_side                     => 'NA'
31086          , p_override_seg_flag        => 'Y'
31087    );
31088 
31089    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
31090 
31091       xla_ae_lines_pkg.set_segment(
31092           p_to_segment_code         => 'GL_BALANCING'
31093         , p_segment_value           => l_segment
31094         , p_from_segment_code       => l_adr_value_segment_code
31095         , p_from_combination_id     => l_adr_value_combination_id
31096         , p_value_type_code         => l_adr_value_type_code
31097         , p_transaction_coa_id      => l_adr_transaction_coa_id
31098         , p_accounting_coa_id       => l_adr_accounting_coa_id
31099         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
31100         , p_flex_value_set_id       => l_adr_flex_value_set_id
31101         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
31102         , p_adr_type_code           => 'S'
31103         , p_component_type          => l_component_type
31104         , p_component_code          => l_component_code
31105         , p_component_type_code     => l_component_type_code
31106         , p_component_appl_id       => l_component_appl_id
31107         , p_amb_context_code        => l_amb_context_code
31108         , p_entity_code             => 'RECEIPTS'
31109         , p_event_class_code        => 'RECEIPT'
31110         , p_side                    => 'NA'
31111         );
31112 
31113   END IF;
31114 
31115    --
31116    --
31117    END IF;
31118    --
31122         ) AND
31119    -- Bug 4922099
31120    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
31121           (NVL(l_enc_upg_option, 'N') = 'O')
31123         (l_bflow_method_code = 'PRIOR_ENTRY')
31124       )
31125    THEN
31126       IF
31127       --
31128       1 = 2
31129       --
31130       THEN
31131       xla_accounting_err_pkg.build_message
31132                                     (p_appli_s_name            => 'XLA'
31133                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
31134                                     ,p_token_1                 => 'LINE_NUMBER'
31135                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
31136                                     ,p_token_2                 => 'LINE_TYPE_NAME'
31137                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
31138                                                                              l_component_type
31139                                                                             ,l_component_code
31140                                                                             ,l_component_type_code
31141                                                                             ,l_component_appl_id
31142                                                                             ,l_amb_context_code
31143                                                                             ,l_entity_code
31144                                                                             ,l_event_class_code
31145                                                                            )
31146                                     ,p_token_3                 => 'OWNER'
31147                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
31148                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
31149                                                                           ,p_lookup_code    => l_component_type_code
31150                                                                          )
31151                                     ,p_token_4                 => 'PRODUCT_NAME'
31152                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
31153                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
31154                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
31155                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
31156                                     ,p_ae_header_id            =>  NULL
31157                                        );
31158 
31159         IF (C_LEVEL_ERROR>= g_log_level) THEN
31160                  trace
31161                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
31162                       ,p_level    => C_LEVEL_ERROR
31163                       ,p_module   => l_log_module);
31164         END IF;
31165       END IF;
31166    END IF;
31167    --
31168    --
31169    ------------------------------------------------------------------------------------------------
31170    -- 4219869 Business Flow
31171    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
31172    -- Prior Entry.  Currently, the following code is always generated.
31173    ------------------------------------------------------------------------------------------------
31174    XLA_AE_LINES_PKG.ValidateCurrentLine;
31175 
31176    ------------------------------------------------------------------------------------
31177    -- 4219869 Business Flow
31178    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
31179    ------------------------------------------------------------------------------------
31180    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
31181 
31182    ----------------------------------------------------------------------------------
31183    -- 4219869 Business Flow
31184    -- Update journal entry status -- Need to generate this within IF <condition>
31185    ----------------------------------------------------------------------------------
31186    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
31187          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
31188          ,p_balance_type_code => l_balance_type_code
31189          );
31190 
31191    -------------------------------------------------------------------------------------------
31192    -- 4262811 - Generate the Accrual Reversal lines
31193    -------------------------------------------------------------------------------------------
31194    BEGIN
31195       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
31196                               (g_array_event(p_event_id).array_value_num('header_index'));
31197       IF l_acc_rev_flag IS NULL THEN
31198          l_acc_rev_flag := 'N';
31199       END IF;
31200    EXCEPTION
31201       WHEN OTHERS THEN
31202          l_acc_rev_flag := 'N';
31203    END;
31204    --
31205    IF (l_acc_rev_flag = 'Y') THEN
31206 
31207        -- 4645092  ------------------------------------------------------------------------------
31208        -- To allow MPA report to determine if it should generate report process
31209        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
31210        ------------------------------------------------------------------------------------------
31211 
31212        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
31216    -- Bug 4922099
31213        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
31214    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
31215    -- call ADRs
31217    --
31218    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
31219         (NVL(l_actual_upg_option, 'N') = 'O') OR
31220         (NVL(l_enc_upg_option, 'N') = 'O')
31221       )
31222    THEN
31223    NULL;
31224    --
31225    --
31226    
31227   l_ccid := AcctDerRule_7(
31228            p_application_id           => p_application_id
31229          , p_ae_header_id             => l_ae_header_id 
31230 , p_source_3 => p_source_3
31231          , x_transaction_coa_id       => l_adr_transaction_coa_id
31232          , x_accounting_coa_id        => l_adr_accounting_coa_id
31233          , x_value_type_code          => l_adr_value_type_code
31234          , p_side                     => 'NA'
31235    );
31236 
31237    xla_ae_lines_pkg.set_ccid(
31238     p_code_combination_id          => l_ccid
31239   , p_value_type_code              => l_adr_value_type_code
31240   , p_transaction_coa_id           => l_adr_transaction_coa_id
31241   , p_accounting_coa_id            => l_adr_accounting_coa_id
31242   , p_adr_code                     => 'DIST_CCID'
31243   , p_adr_type_code                => 'S'
31244   , p_component_type               => l_component_type
31245   , p_component_code               => l_component_code
31246   , p_component_type_code          => l_component_type_code
31247   , p_component_appl_id            => l_component_appl_id
31248   , p_amb_context_code             => l_amb_context_code
31249   , p_side                         => 'NA'
31250   );
31251 
31252 
31253    l_segment := AcctDerRule_23(
31254            p_application_id           => p_application_id
31255          , p_ae_header_id             => l_ae_header_id 
31256 , p_source_7 => p_source_7
31257 , p_source_8 => p_source_8
31258 , p_source_9 => p_source_9
31259 , p_source_10 => p_source_10
31260          , x_transaction_coa_id       => l_adr_transaction_coa_id
31261          , x_accounting_coa_id        => l_adr_accounting_coa_id
31262          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
31263          , x_flex_value_set_id        => l_adr_flex_value_set_id
31264          , x_value_type_code          => l_adr_value_type_code
31265          , x_value_combination_id     => l_adr_value_combination_id
31266          , x_value_segment_code       => l_adr_value_segment_code
31267          , p_side                     => 'NA'
31268          , p_override_seg_flag        => 'Y'
31269    );
31270 
31271    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
31272 
31273       xla_ae_lines_pkg.set_segment(
31274           p_to_segment_code         => 'GL_ACCOUNT'
31275         , p_segment_value           => l_segment
31276         , p_from_segment_code       => l_adr_value_segment_code
31277         , p_from_combination_id     => l_adr_value_combination_id
31278         , p_value_type_code         => l_adr_value_type_code
31279         , p_transaction_coa_id      => l_adr_transaction_coa_id
31280         , p_accounting_coa_id       => l_adr_accounting_coa_id
31281         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
31282         , p_flex_value_set_id       => l_adr_flex_value_set_id
31283         , p_adr_code                => 'FV_AR_4X7201_RCT_DR'
31284         , p_adr_type_code           => 'S'
31285         , p_component_type          => l_component_type
31286         , p_component_code          => l_component_code
31287         , p_component_type_code     => l_component_type_code
31288         , p_component_appl_id       => l_component_appl_id
31289         , p_amb_context_code        => l_amb_context_code
31290         , p_entity_code             => 'RECEIPTS'
31291         , p_event_class_code        => 'RECEIPT'
31292         , p_side                    => 'NA'
31293         );
31294 
31295   END IF;
31296 
31297    l_segment := AcctDerRule_5(
31298            p_application_id           => p_application_id
31299          , p_ae_header_id             => l_ae_header_id 
31300 , p_source_4 => p_source_4
31301          , x_transaction_coa_id       => l_adr_transaction_coa_id
31302          , x_accounting_coa_id        => l_adr_accounting_coa_id
31303          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
31304          , x_flex_value_set_id        => l_adr_flex_value_set_id
31305          , x_value_type_code          => l_adr_value_type_code
31306          , x_value_combination_id     => l_adr_value_combination_id
31307          , x_value_segment_code       => l_adr_value_segment_code
31308          , p_side                     => 'NA'
31309          , p_override_seg_flag        => 'Y'
31310    );
31311 
31312    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
31313 
31314       xla_ae_lines_pkg.set_segment(
31315           p_to_segment_code         => 'GL_BALANCING'
31316         , p_segment_value           => l_segment
31317         , p_from_segment_code       => l_adr_value_segment_code
31318         , p_from_combination_id     => l_adr_value_combination_id
31319         , p_value_type_code         => l_adr_value_type_code
31320         , p_transaction_coa_id      => l_adr_transaction_coa_id
31321         , p_accounting_coa_id       => l_adr_accounting_coa_id
31322         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
31323         , p_flex_value_set_id       => l_adr_flex_value_set_id
31324         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
31328         , p_component_type_code     => l_component_type_code
31325         , p_adr_type_code           => 'S'
31326         , p_component_type          => l_component_type
31327         , p_component_code          => l_component_code
31329         , p_component_appl_id       => l_component_appl_id
31330         , p_amb_context_code        => l_amb_context_code
31331         , p_entity_code             => 'RECEIPTS'
31332         , p_event_class_code        => 'RECEIPT'
31333         , p_side                    => 'NA'
31334         );
31335 
31336   END IF;
31337 
31338    --
31339    --
31340    END IF;
31341 
31342        --
31343        -- Update the line information that should be overwritten
31344        --
31345        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
31346                                          p_header_num   => 1);
31347        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
31348 
31349        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
31350 
31351        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
31352           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
31353        END IF;
31354 
31355       --
31356       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
31357       --
31358       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
31359           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
31360       ELSE
31361           ---------------------------------------------------------------------------------------------------
31362           -- 4262811a Switch Sign
31363           ---------------------------------------------------------------------------------------------------
31364           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
31365           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
31366                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
31367           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
31368                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
31369           -- 5132302
31370           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
31371                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
31372 
31373       END IF;
31374 
31375       -- 4955764
31376       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
31377       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
31378 
31379 
31380       XLA_AE_LINES_PKG.ValidateCurrentLine;
31381       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
31382 
31383       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
31384                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
31385                ,p_balance_type_code => l_balance_type_code);
31386 
31387    END IF;
31388 
31389    -----------------------------------------------------------------------------------------
31390    -- 4262811 Multiperiod Accounting
31391    -----------------------------------------------------------------------------------------
31392      -- No MPA option is assigned.
31393 
31394 
31395 END IF;
31396 END IF;
31397 --
31398 
31399 --
31400 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
31401    trace
31402       (p_msg      => 'END of AcctLineType_74'
31403       ,p_level    => C_LEVEL_PROCEDURE
31404       ,p_module   => l_log_module);
31405 END IF;
31406 --
31407 EXCEPTION
31408   WHEN xla_exceptions_pkg.application_exception THEN
31409       RAISE;
31410   WHEN OTHERS THEN
31411        xla_exceptions_pkg.raise_message
31412            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_74');
31413 END AcctLineType_74;
31414 --
31415 
31416 ---------------------------------------
31417 --
31418 -- PRIVATE FUNCTION
31419 --         AcctLineType_75
31420 --
31421 ---------------------------------------
31422 PROCEDURE AcctLineType_75 (
31423   p_application_id        IN NUMBER
31424  ,p_event_id              IN NUMBER
31425  ,p_calculate_acctd_flag  IN VARCHAR2
31426  ,p_calculate_g_l_flag    IN VARCHAR2
31427  ,p_actual_flag           IN OUT VARCHAR2
31428  ,p_balance_type_code     OUT VARCHAR2
31429  ,p_gain_or_loss_ref      OUT VARCHAR2
31430  
31431 --Distribution GL Account
31432  , p_source_3            IN NUMBER
31433 --Transaction Distribution GL Account
31434  , p_source_4            IN NUMBER
31435 --Bill To Customer Classification
31436  , p_source_6            IN VARCHAR2
31437 --Federal Account Rule
31438  , p_source_7            IN VARCHAR2
31439 --Distribution Source Type
31440  , p_source_20            IN VARCHAR2
31441 --Distribution Line Identifier
31442  , p_source_22            IN NUMBER
31443 --Distribution Type
31444  , p_source_23            IN VARCHAR2
31445 --Entered Amount
31446  , p_source_24            IN NUMBER
31447 --Exchange Date
31451 --Exchange Rate Type
31448  , p_source_26            IN DATE
31449 --Exchange Rate
31450  , p_source_27            IN NUMBER
31452  , p_source_28            IN VARCHAR2
31453 --Applied To Document Accounting Amount
31454  , p_source_29            IN NUMBER
31455 --Transaction Distribution Account Class
31456  , p_source_33            IN VARCHAR2
31457 --Transaction Distribution Identifier
31458  , p_source_34            IN NUMBER
31459 --Transaction Distribution Type
31460  , p_source_35            IN VARCHAR2
31461 --Federal Account Valid Flag
31462  , p_source_56            IN VARCHAR2
31463 --Receipt Applied To Application Identifier
31464  , p_source_58            IN NUMBER
31465 --Transaction Entity Code
31466  , p_source_59            IN VARCHAR2
31467 --Transaction Identifier
31468  , p_source_60            IN NUMBER
31469 --Applying Document Currency Code
31470  , p_source_61            IN VARCHAR2
31471 --Distribution Party Identifier
31472  , p_source_63            IN NUMBER
31473 --Distribution Party Site Id
31474  , p_source_64            IN NUMBER
31475 --Distribution Party Type
31476  , p_source_65            IN VARCHAR2
31477 )
31478 IS
31479 
31480 l_component_type              VARCHAR2(80);
31481 l_component_code              VARCHAR2(30);
31482 l_component_type_code         VARCHAR2(1);
31483 l_component_appl_id           INTEGER;
31484 l_amb_context_code            VARCHAR2(30);
31485 l_entity_code                 VARCHAR2(30);
31486 l_event_class_code            VARCHAR2(30);
31487 l_ae_header_id                NUMBER;
31488 l_event_type_code             VARCHAR2(30);
31489 l_line_definition_code        VARCHAR2(30);
31490 l_line_definition_owner_code  VARCHAR2(1);
31491 --
31492 -- adr variables
31493 l_segment                     VARCHAR2(30);
31494 l_ccid                        NUMBER;
31495 l_adr_transaction_coa_id      NUMBER;
31496 l_adr_accounting_coa_id       NUMBER;
31497 l_adr_flexfield_segment_code  VARCHAR2(30);
31498 l_adr_flex_value_set_id       NUMBER;
31499 l_adr_value_type_code         VARCHAR2(30);
31500 l_adr_value_combination_id    NUMBER;
31501 l_adr_value_segment_code      VARCHAR2(30);
31502 
31503 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
31504 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
31505 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
31506 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
31507 
31508 -- 4262811 Variables ------------------------------------------------------------------------------------------
31509 l_entered_amt_idx             NUMBER;
31510 l_accted_amt_idx              NUMBER;
31511 l_acc_rev_flag                VARCHAR2(1);
31512 l_accrual_line_num            NUMBER;
31513 l_tmp_amt                     NUMBER;
31514 l_acc_rev_natural_side_code   VARCHAR2(1);
31515 
31516 l_num_entries                 NUMBER;
31517 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
31518 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
31519 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
31520 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
31521 l_recog_line_1                NUMBER;
31522 l_recog_line_2                NUMBER;
31523 
31524 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
31525 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
31526 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
31527 
31528 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
31529 
31530 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
31531 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
31532 
31533 ---------------------------------------------------------------------------------------------------------------
31534 
31535 
31536 --
31537 -- bulk performance
31538 --
31539 l_balance_type_code           VARCHAR2(1);
31540 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
31541 l_log_module                  VARCHAR2(240);
31542 
31543 --
31544 -- Upgrade strategy
31545 --
31546 l_actual_upg_option           VARCHAR2(1);
31547 l_enc_upg_option           VARCHAR2(1);
31548 
31549 --
31550 BEGIN
31551 --
31552 IF g_log_enabled THEN
31553       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_75';
31554 END IF;
31555 --
31556 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
31557 
31558       trace
31559          (p_msg      => 'BEGIN of AcctLineType_75'
31560          ,p_level    => C_LEVEL_PROCEDURE
31561          ,p_module   => l_log_module);
31562 
31563 END IF;
31564 --
31565 l_component_type             := 'AMB_JLT';
31566 l_component_code             := 'FV_RCT_REIM_WO_ADV_CR';
31567 l_component_type_code        := 'S';
31568 l_component_appl_id          :=  222;
31569 l_amb_context_code           := 'DEFAULT';
31570 l_entity_code                := 'RECEIPTS';
31571 l_event_class_code           := 'RECEIPT';
31572 l_event_type_code            := 'RECEIPT_ALL';
31573 l_line_definition_owner_code := 'S';
31574 l_line_definition_code       := 'MFAR_FED_AR_RCT_BALANCING';
31575 --
31576 l_balance_type_code          := 'A';
31577 l_segment                     := NULL;
31578 l_ccid                        := NULL;
31582 l_adr_flex_value_set_id       := NULL;
31579 l_adr_transaction_coa_id      := NULL;
31580 l_adr_accounting_coa_id       := NULL;
31581 l_adr_flexfield_segment_code  := NULL;
31583 l_adr_value_type_code         := NULL;
31584 l_adr_value_combination_id    := NULL;
31585 l_adr_value_segment_code      := NULL;
31586 
31587 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
31588 l_bflow_class_code           := '';    -- 4219869 Business Flow
31589 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
31590 l_budgetary_control_flag     := 'N';
31591 
31592 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
31593 l_bflow_applied_to_amt       := NULL; -- 5132302
31594 l_entered_amt_idx            := NULL;          -- 4262811
31595 l_accted_amt_idx             := NULL;          -- 4262811
31596 l_acc_rev_flag               := NULL;          -- 4262811
31597 l_accrual_line_num           := NULL;          -- 4262811
31598 l_tmp_amt                    := NULL;          -- 4262811
31599 --
31600  
31601 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
31602     l_balance_type_code <> 'B' THEN
31603 IF NVL(p_source_20,'
31604 ') =  'REC' AND 
31605 NVL(p_source_33,'
31606 ') =  'REV' AND 
31607 NVL(p_source_6,'
31608 ') =  'FEDERAL' AND 
31609 NVL(p_source_7,'
31610 ') =  'Order No Advance' AND 
31611 NVL(p_source_56,'
31612 ') =  'Y'
31613  THEN 
31614 
31615    --
31616    XLA_AE_LINES_PKG.SetNewLine;
31617 
31618    p_balance_type_code          := l_balance_type_code;
31619    -- set the flag so later we will know whether the gain loss line needs to be created
31620    
31621    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
31622      p_actual_flag :='A';
31623    END IF;
31624 
31625    --
31626    -- bulk performance
31627    --
31628    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
31629                                       p_header_num   => 0); -- 4262811
31630    --
31631    -- set accounting line options
31632    --
31633    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
31634            p_natural_side_code          => 'C'
31635          , p_gain_or_loss_flag          => 'N'
31636          , p_gl_transfer_mode_code      => 'S'
31637          , p_acct_entry_type_code       => 'A'
31638          , p_switch_side_flag           => 'Y'
31639          , p_merge_duplicate_code       => 'A'
31640          );
31641    --
31642    l_acc_rev_natural_side_code := 'D';  -- 4262811
31643    -- 
31644    --
31645    -- set accounting line type info
31646    --
31647    xla_ae_lines_pkg.SetAcctLineType
31648       (p_component_type             => l_component_type
31649       ,p_event_type_code            => l_event_type_code
31650       ,p_line_definition_owner_code => l_line_definition_owner_code
31651       ,p_line_definition_code       => l_line_definition_code
31652       ,p_accounting_line_code       => l_component_code
31653       ,p_accounting_line_type_code  => l_component_type_code
31654       ,p_accounting_line_appl_id    => l_component_appl_id
31655       ,p_amb_context_code           => l_amb_context_code
31656       ,p_entity_code                => l_entity_code
31657       ,p_event_class_code           => l_event_class_code);
31658    --
31659    -- set accounting class
31660    --
31661    xla_ae_lines_pkg.SetAcctClass(
31662            p_accounting_class_code  => 'FV_CASH_CR'
31663          , p_ae_header_id           => l_ae_header_id
31664          );
31665 
31666    --
31667    -- set rounding class
31668    --
31669    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
31670                       'RECEIVABLE';
31671 
31672    --
31673    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
31674    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
31675    --
31676    -- bulk performance
31677    --
31678    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
31679 
31680    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
31681       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
31682 
31683    -- 4955764
31684    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
31685       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
31686 
31687    -- 4458381 Public Sector Enh
31688    
31689    --
31690    -- set accounting attributes for the line type
31691    --
31692    l_entered_amt_idx := 8;
31693    l_accted_amt_idx  := 13;
31694    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
31695    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
31696    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
31697    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
31698    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
31699    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
31700    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
31701    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
31702    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
31703    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
31704    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
31708    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
31705    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
31706    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
31707    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
31709    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
31710    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
31711    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
31712    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
31713    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
31714    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
31715    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
31716    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
31717    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
31718    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
31719    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
31720    l_rec_acct_attrs.array_num_value(13)  := p_source_29;
31721    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
31722    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
31723    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
31724    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
31725    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
31726    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
31727 
31728    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
31729    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
31730 
31731    ---------------------------------------------------------------------------------------------------------------
31732    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
31733    ---------------------------------------------------------------------------------------------------------------
31734    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
31735 
31736    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
31737    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
31738 
31739    IF xla_accounting_cache_pkg.GetValueChar
31740          (p_source_code         => 'LEDGER_CATEGORY_CODE'
31741          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
31742    AND l_bflow_method_code = 'PRIOR_ENTRY'
31743 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
31744    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
31745          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
31746        )
31747    THEN
31748          xla_ae_lines_pkg.BflowUpgEntry
31749            (p_business_method_code    => l_bflow_method_code
31750            ,p_business_class_code     => l_bflow_class_code
31751            ,p_balance_type            => l_balance_type_code);
31752    ELSE
31753       NULL;
31754 -- No business flow processing for business flow method of NONE.
31755    END IF;
31756 
31757    --
31758    -- call analytical criteria
31759    --
31760    
31761    --
31762    -- call description
31763    --
31764    -- No description or it is inherited.
31765    --
31766    -- call ADRs
31767    -- Bug 4922099
31768    --
31769    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
31770         (NVL(l_actual_upg_option, 'N') = 'O') OR
31771         (NVL(l_enc_upg_option, 'N') = 'O')
31772       )
31773    THEN
31774    NULL;
31775    --
31776    --
31777    
31778   l_ccid := AcctDerRule_7(
31779            p_application_id           => p_application_id
31780          , p_ae_header_id             => l_ae_header_id 
31781 , p_source_3 => p_source_3
31782          , x_transaction_coa_id       => l_adr_transaction_coa_id
31783          , x_accounting_coa_id        => l_adr_accounting_coa_id
31784          , x_value_type_code          => l_adr_value_type_code
31785          , p_side                     => 'NA'
31786    );
31787 
31788    xla_ae_lines_pkg.set_ccid(
31789     p_code_combination_id          => l_ccid
31790   , p_value_type_code              => l_adr_value_type_code
31791   , p_transaction_coa_id           => l_adr_transaction_coa_id
31792   , p_accounting_coa_id            => l_adr_accounting_coa_id
31793   , p_adr_code                     => 'DIST_CCID'
31794   , p_adr_type_code                => 'S'
31795   , p_component_type               => l_component_type
31796   , p_component_code               => l_component_code
31797   , p_component_type_code          => l_component_type_code
31798   , p_component_appl_id            => l_component_appl_id
31799   , p_amb_context_code             => l_amb_context_code
31800   , p_side                         => 'NA'
31801   );
31802 
31803 
31804    l_segment := AcctDerRule_10(
31805            p_application_id           => p_application_id
31806          , p_ae_header_id             => l_ae_header_id 
31807 , p_source_7 => p_source_7
31808          , x_transaction_coa_id       => l_adr_transaction_coa_id
31809          , x_accounting_coa_id        => l_adr_accounting_coa_id
31810          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
31811          , x_flex_value_set_id        => l_adr_flex_value_set_id
31812          , x_value_type_code          => l_adr_value_type_code
31816          , p_override_seg_flag        => 'Y'
31813          , x_value_combination_id     => l_adr_value_combination_id
31814          , x_value_segment_code       => l_adr_value_segment_code
31815          , p_side                     => 'NA'
31817    );
31818 
31819    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
31820 
31821       xla_ae_lines_pkg.set_segment(
31822           p_to_segment_code         => 'GL_ACCOUNT'
31823         , p_segment_value           => l_segment
31824         , p_from_segment_code       => l_adr_value_segment_code
31825         , p_from_combination_id     => l_adr_value_combination_id
31826         , p_value_type_code         => l_adr_value_type_code
31827         , p_transaction_coa_id      => l_adr_transaction_coa_id
31828         , p_accounting_coa_id       => l_adr_accounting_coa_id
31829         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
31830         , p_flex_value_set_id       => l_adr_flex_value_set_id
31831         , p_adr_code                => 'FV_AR_425101_RCT_CR'
31832         , p_adr_type_code           => 'S'
31833         , p_component_type          => l_component_type
31834         , p_component_code          => l_component_code
31835         , p_component_type_code     => l_component_type_code
31836         , p_component_appl_id       => l_component_appl_id
31837         , p_amb_context_code        => l_amb_context_code
31838         , p_entity_code             => 'RECEIPTS'
31839         , p_event_class_code        => 'RECEIPT'
31840         , p_side                    => 'NA'
31841         );
31842 
31843   END IF;
31844 
31845    l_segment := AcctDerRule_5(
31846            p_application_id           => p_application_id
31847          , p_ae_header_id             => l_ae_header_id 
31848 , p_source_4 => p_source_4
31849          , x_transaction_coa_id       => l_adr_transaction_coa_id
31850          , x_accounting_coa_id        => l_adr_accounting_coa_id
31851          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
31852          , x_flex_value_set_id        => l_adr_flex_value_set_id
31853          , x_value_type_code          => l_adr_value_type_code
31854          , x_value_combination_id     => l_adr_value_combination_id
31855          , x_value_segment_code       => l_adr_value_segment_code
31856          , p_side                     => 'NA'
31857          , p_override_seg_flag        => 'Y'
31858    );
31859 
31860    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
31861 
31862       xla_ae_lines_pkg.set_segment(
31863           p_to_segment_code         => 'GL_BALANCING'
31864         , p_segment_value           => l_segment
31865         , p_from_segment_code       => l_adr_value_segment_code
31866         , p_from_combination_id     => l_adr_value_combination_id
31867         , p_value_type_code         => l_adr_value_type_code
31868         , p_transaction_coa_id      => l_adr_transaction_coa_id
31869         , p_accounting_coa_id       => l_adr_accounting_coa_id
31870         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
31871         , p_flex_value_set_id       => l_adr_flex_value_set_id
31872         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
31873         , p_adr_type_code           => 'S'
31874         , p_component_type          => l_component_type
31875         , p_component_code          => l_component_code
31876         , p_component_type_code     => l_component_type_code
31877         , p_component_appl_id       => l_component_appl_id
31878         , p_amb_context_code        => l_amb_context_code
31879         , p_entity_code             => 'RECEIPTS'
31880         , p_event_class_code        => 'RECEIPT'
31881         , p_side                    => 'NA'
31882         );
31883 
31884   END IF;
31885 
31886    --
31887    --
31888    END IF;
31889    --
31890    -- Bug 4922099
31891    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
31892           (NVL(l_enc_upg_option, 'N') = 'O')
31893         ) AND
31894         (l_bflow_method_code = 'PRIOR_ENTRY')
31895       )
31896    THEN
31897       IF
31898       --
31899       1 = 2
31900       --
31901       THEN
31902       xla_accounting_err_pkg.build_message
31903                                     (p_appli_s_name            => 'XLA'
31904                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
31905                                     ,p_token_1                 => 'LINE_NUMBER'
31906                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
31907                                     ,p_token_2                 => 'LINE_TYPE_NAME'
31908                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
31909                                                                              l_component_type
31910                                                                             ,l_component_code
31911                                                                             ,l_component_type_code
31912                                                                             ,l_component_appl_id
31913                                                                             ,l_amb_context_code
31914                                                                             ,l_entity_code
31915                                                                             ,l_event_class_code
31916                                                                            )
31920                                                                           ,p_lookup_code    => l_component_type_code
31917                                     ,p_token_3                 => 'OWNER'
31918                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
31919                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
31921                                                                          )
31922                                     ,p_token_4                 => 'PRODUCT_NAME'
31923                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
31924                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
31925                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
31926                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
31927                                     ,p_ae_header_id            =>  NULL
31928                                        );
31929 
31930         IF (C_LEVEL_ERROR>= g_log_level) THEN
31931                  trace
31932                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
31933                       ,p_level    => C_LEVEL_ERROR
31934                       ,p_module   => l_log_module);
31935         END IF;
31936       END IF;
31937    END IF;
31938    --
31939    --
31940    ------------------------------------------------------------------------------------------------
31941    -- 4219869 Business Flow
31942    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
31943    -- Prior Entry.  Currently, the following code is always generated.
31944    ------------------------------------------------------------------------------------------------
31945    XLA_AE_LINES_PKG.ValidateCurrentLine;
31946 
31947    ------------------------------------------------------------------------------------
31948    -- 4219869 Business Flow
31949    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
31950    ------------------------------------------------------------------------------------
31951    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
31952 
31953    ----------------------------------------------------------------------------------
31954    -- 4219869 Business Flow
31955    -- Update journal entry status -- Need to generate this within IF <condition>
31956    ----------------------------------------------------------------------------------
31957    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
31958          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
31959          ,p_balance_type_code => l_balance_type_code
31960          );
31961 
31962    -------------------------------------------------------------------------------------------
31963    -- 4262811 - Generate the Accrual Reversal lines
31964    -------------------------------------------------------------------------------------------
31965    BEGIN
31966       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
31967                               (g_array_event(p_event_id).array_value_num('header_index'));
31968       IF l_acc_rev_flag IS NULL THEN
31969          l_acc_rev_flag := 'N';
31970       END IF;
31971    EXCEPTION
31972       WHEN OTHERS THEN
31973          l_acc_rev_flag := 'N';
31974    END;
31975    --
31976    IF (l_acc_rev_flag = 'Y') THEN
31977 
31978        -- 4645092  ------------------------------------------------------------------------------
31979        -- To allow MPA report to determine if it should generate report process
31980        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
31981        ------------------------------------------------------------------------------------------
31982 
31983        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
31984        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
31985    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
31986    -- call ADRs
31987    -- Bug 4922099
31988    --
31989    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
31990         (NVL(l_actual_upg_option, 'N') = 'O') OR
31991         (NVL(l_enc_upg_option, 'N') = 'O')
31992       )
31993    THEN
31994    NULL;
31995    --
31996    --
31997    
31998   l_ccid := AcctDerRule_7(
31999            p_application_id           => p_application_id
32000          , p_ae_header_id             => l_ae_header_id 
32001 , p_source_3 => p_source_3
32002          , x_transaction_coa_id       => l_adr_transaction_coa_id
32003          , x_accounting_coa_id        => l_adr_accounting_coa_id
32004          , x_value_type_code          => l_adr_value_type_code
32005          , p_side                     => 'NA'
32006    );
32007 
32008    xla_ae_lines_pkg.set_ccid(
32009     p_code_combination_id          => l_ccid
32010   , p_value_type_code              => l_adr_value_type_code
32011   , p_transaction_coa_id           => l_adr_transaction_coa_id
32012   , p_accounting_coa_id            => l_adr_accounting_coa_id
32013   , p_adr_code                     => 'DIST_CCID'
32014   , p_adr_type_code                => 'S'
32015   , p_component_type               => l_component_type
32016   , p_component_code               => l_component_code
32017   , p_component_type_code          => l_component_type_code
32021   );
32018   , p_component_appl_id            => l_component_appl_id
32019   , p_amb_context_code             => l_amb_context_code
32020   , p_side                         => 'NA'
32022 
32023 
32024    l_segment := AcctDerRule_10(
32025            p_application_id           => p_application_id
32026          , p_ae_header_id             => l_ae_header_id 
32027 , p_source_7 => p_source_7
32028          , x_transaction_coa_id       => l_adr_transaction_coa_id
32029          , x_accounting_coa_id        => l_adr_accounting_coa_id
32030          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
32031          , x_flex_value_set_id        => l_adr_flex_value_set_id
32032          , x_value_type_code          => l_adr_value_type_code
32033          , x_value_combination_id     => l_adr_value_combination_id
32034          , x_value_segment_code       => l_adr_value_segment_code
32035          , p_side                     => 'NA'
32036          , p_override_seg_flag        => 'Y'
32037    );
32038 
32039    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
32040 
32041       xla_ae_lines_pkg.set_segment(
32042           p_to_segment_code         => 'GL_ACCOUNT'
32043         , p_segment_value           => l_segment
32044         , p_from_segment_code       => l_adr_value_segment_code
32045         , p_from_combination_id     => l_adr_value_combination_id
32046         , p_value_type_code         => l_adr_value_type_code
32047         , p_transaction_coa_id      => l_adr_transaction_coa_id
32048         , p_accounting_coa_id       => l_adr_accounting_coa_id
32049         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
32050         , p_flex_value_set_id       => l_adr_flex_value_set_id
32051         , p_adr_code                => 'FV_AR_425101_RCT_CR'
32052         , p_adr_type_code           => 'S'
32053         , p_component_type          => l_component_type
32054         , p_component_code          => l_component_code
32055         , p_component_type_code     => l_component_type_code
32056         , p_component_appl_id       => l_component_appl_id
32057         , p_amb_context_code        => l_amb_context_code
32058         , p_entity_code             => 'RECEIPTS'
32059         , p_event_class_code        => 'RECEIPT'
32060         , p_side                    => 'NA'
32061         );
32062 
32063   END IF;
32064 
32065    l_segment := AcctDerRule_5(
32066            p_application_id           => p_application_id
32067          , p_ae_header_id             => l_ae_header_id 
32068 , p_source_4 => p_source_4
32069          , x_transaction_coa_id       => l_adr_transaction_coa_id
32070          , x_accounting_coa_id        => l_adr_accounting_coa_id
32071          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
32072          , x_flex_value_set_id        => l_adr_flex_value_set_id
32073          , x_value_type_code          => l_adr_value_type_code
32074          , x_value_combination_id     => l_adr_value_combination_id
32075          , x_value_segment_code       => l_adr_value_segment_code
32076          , p_side                     => 'NA'
32077          , p_override_seg_flag        => 'Y'
32078    );
32079 
32080    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
32081 
32082       xla_ae_lines_pkg.set_segment(
32083           p_to_segment_code         => 'GL_BALANCING'
32084         , p_segment_value           => l_segment
32085         , p_from_segment_code       => l_adr_value_segment_code
32086         , p_from_combination_id     => l_adr_value_combination_id
32087         , p_value_type_code         => l_adr_value_type_code
32088         , p_transaction_coa_id      => l_adr_transaction_coa_id
32089         , p_accounting_coa_id       => l_adr_accounting_coa_id
32090         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
32091         , p_flex_value_set_id       => l_adr_flex_value_set_id
32092         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
32093         , p_adr_type_code           => 'S'
32094         , p_component_type          => l_component_type
32095         , p_component_code          => l_component_code
32096         , p_component_type_code     => l_component_type_code
32097         , p_component_appl_id       => l_component_appl_id
32098         , p_amb_context_code        => l_amb_context_code
32099         , p_entity_code             => 'RECEIPTS'
32100         , p_event_class_code        => 'RECEIPT'
32101         , p_side                    => 'NA'
32102         );
32103 
32104   END IF;
32105 
32106    --
32107    --
32108    END IF;
32109 
32110        --
32111        -- Update the line information that should be overwritten
32112        --
32113        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
32114                                          p_header_num   => 1);
32115        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
32116 
32117        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
32118 
32119        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
32120           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
32121        END IF;
32122 
32123       --
32124       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
32125       --
32126       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
32127           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
32128       ELSE
32132           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
32129           ---------------------------------------------------------------------------------------------------
32130           -- 4262811a Switch Sign
32131           ---------------------------------------------------------------------------------------------------
32133           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
32134                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
32135           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
32136                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
32137           -- 5132302
32138           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
32139                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
32140 
32141       END IF;
32142 
32143       -- 4955764
32144       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
32145       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
32146 
32147 
32148       XLA_AE_LINES_PKG.ValidateCurrentLine;
32149       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
32150 
32151       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
32152                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
32153                ,p_balance_type_code => l_balance_type_code);
32154 
32155    END IF;
32156 
32157    -----------------------------------------------------------------------------------------
32158    -- 4262811 Multiperiod Accounting
32159    -----------------------------------------------------------------------------------------
32160      -- No MPA option is assigned.
32161 
32162 
32163 END IF;
32164 END IF;
32165 --
32166 
32167 --
32168 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
32169    trace
32170       (p_msg      => 'END of AcctLineType_75'
32171       ,p_level    => C_LEVEL_PROCEDURE
32172       ,p_module   => l_log_module);
32173 END IF;
32174 --
32175 EXCEPTION
32176   WHEN xla_exceptions_pkg.application_exception THEN
32177       RAISE;
32178   WHEN OTHERS THEN
32179        xla_exceptions_pkg.raise_message
32180            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_75');
32181 END AcctLineType_75;
32182 --
32183 
32184 ---------------------------------------
32185 --
32186 -- PRIVATE FUNCTION
32187 --         AcctLineType_76
32188 --
32189 ---------------------------------------
32190 PROCEDURE AcctLineType_76 (
32191   p_application_id        IN NUMBER
32192  ,p_event_id              IN NUMBER
32193  ,p_calculate_acctd_flag  IN VARCHAR2
32194  ,p_calculate_g_l_flag    IN VARCHAR2
32195  ,p_actual_flag           IN OUT VARCHAR2
32196  ,p_balance_type_code     OUT VARCHAR2
32197  ,p_gain_or_loss_ref      OUT VARCHAR2
32198  
32199 --Distribution GL Account
32200  , p_source_3            IN NUMBER
32201 --Transaction Distribution GL Account
32202  , p_source_4            IN NUMBER
32203 --Bill To Customer Classification
32204  , p_source_6            IN VARCHAR2
32205 --Federal Account Rule
32206  , p_source_7            IN VARCHAR2
32207 --Distribution Source Type
32208  , p_source_20            IN VARCHAR2
32209 --Distribution Line Identifier
32210  , p_source_22            IN NUMBER
32211 --Distribution Type
32212  , p_source_23            IN VARCHAR2
32213 --Entered Amount
32214  , p_source_24            IN NUMBER
32215 --Exchange Rate Type
32216  , p_source_28            IN VARCHAR2
32217 --Applied To Document Accounting Amount
32218  , p_source_29            IN NUMBER
32219 --Transaction Distribution Account Class
32220  , p_source_33            IN VARCHAR2
32221 --Transaction Distribution Identifier
32222  , p_source_34            IN NUMBER
32223 --Transaction Distribution Type
32224  , p_source_35            IN VARCHAR2
32225 --Federal Account Valid Flag
32226  , p_source_56            IN VARCHAR2
32227 --Applied To Document Exchange Date
32228  , p_source_57            IN DATE
32229 --Receipt Applied To Application Identifier
32230  , p_source_58            IN NUMBER
32231 --Transaction Entity Code
32232  , p_source_59            IN VARCHAR2
32233 --Transaction Identifier
32234  , p_source_60            IN NUMBER
32235 --Applying Document Currency Code
32236  , p_source_61            IN VARCHAR2
32237 --Applied To Document Exchange Rate
32238  , p_source_62            IN NUMBER
32239 --Distribution Party Identifier
32240  , p_source_63            IN NUMBER
32241 --Distribution Party Site Id
32242  , p_source_64            IN NUMBER
32243 --Distribution Party Type
32244  , p_source_65            IN VARCHAR2
32245 )
32246 IS
32247 
32248 l_component_type              VARCHAR2(80);
32249 l_component_code              VARCHAR2(30);
32250 l_component_type_code         VARCHAR2(1);
32251 l_component_appl_id           INTEGER;
32252 l_amb_context_code            VARCHAR2(30);
32253 l_entity_code                 VARCHAR2(30);
32254 l_event_class_code            VARCHAR2(30);
32255 l_ae_header_id                NUMBER;
32256 l_event_type_code             VARCHAR2(30);
32257 l_line_definition_code        VARCHAR2(30);
32258 l_line_definition_owner_code  VARCHAR2(1);
32259 --
32263 l_adr_transaction_coa_id      NUMBER;
32260 -- adr variables
32261 l_segment                     VARCHAR2(30);
32262 l_ccid                        NUMBER;
32264 l_adr_accounting_coa_id       NUMBER;
32265 l_adr_flexfield_segment_code  VARCHAR2(30);
32266 l_adr_flex_value_set_id       NUMBER;
32267 l_adr_value_type_code         VARCHAR2(30);
32268 l_adr_value_combination_id    NUMBER;
32269 l_adr_value_segment_code      VARCHAR2(30);
32270 
32271 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
32272 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
32273 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
32274 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
32275 
32276 -- 4262811 Variables ------------------------------------------------------------------------------------------
32277 l_entered_amt_idx             NUMBER;
32278 l_accted_amt_idx              NUMBER;
32279 l_acc_rev_flag                VARCHAR2(1);
32280 l_accrual_line_num            NUMBER;
32281 l_tmp_amt                     NUMBER;
32282 l_acc_rev_natural_side_code   VARCHAR2(1);
32283 
32284 l_num_entries                 NUMBER;
32285 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
32286 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
32287 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
32288 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
32289 l_recog_line_1                NUMBER;
32290 l_recog_line_2                NUMBER;
32291 
32292 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
32293 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
32294 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
32295 
32296 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
32297 
32298 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
32299 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
32300 
32301 ---------------------------------------------------------------------------------------------------------------
32302 
32303 
32304 --
32305 -- bulk performance
32306 --
32307 l_balance_type_code           VARCHAR2(1);
32308 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
32309 l_log_module                  VARCHAR2(240);
32310 
32311 --
32312 -- Upgrade strategy
32313 --
32314 l_actual_upg_option           VARCHAR2(1);
32315 l_enc_upg_option           VARCHAR2(1);
32316 
32317 --
32318 BEGIN
32319 --
32320 IF g_log_enabled THEN
32321       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_76';
32322 END IF;
32323 --
32324 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
32325 
32326       trace
32327          (p_msg      => 'BEGIN of AcctLineType_76'
32328          ,p_level    => C_LEVEL_PROCEDURE
32329          ,p_module   => l_log_module);
32330 
32331 END IF;
32332 --
32333 l_component_type             := 'AMB_JLT';
32334 l_component_code             := 'FV_RCT_REIM_WO_ADV_DR';
32335 l_component_type_code        := 'S';
32336 l_component_appl_id          :=  222;
32337 l_amb_context_code           := 'DEFAULT';
32338 l_entity_code                := 'RECEIPTS';
32339 l_event_class_code           := 'RECEIPT';
32340 l_event_type_code            := 'RECEIPT_ALL';
32341 l_line_definition_owner_code := 'S';
32342 l_line_definition_code       := 'MFAR_FED_AR_RCT_BALANCING';
32343 --
32344 l_balance_type_code          := 'A';
32345 l_segment                     := NULL;
32346 l_ccid                        := NULL;
32347 l_adr_transaction_coa_id      := NULL;
32348 l_adr_accounting_coa_id       := NULL;
32349 l_adr_flexfield_segment_code  := NULL;
32350 l_adr_flex_value_set_id       := NULL;
32351 l_adr_value_type_code         := NULL;
32352 l_adr_value_combination_id    := NULL;
32353 l_adr_value_segment_code      := NULL;
32354 
32355 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
32356 l_bflow_class_code           := '';    -- 4219869 Business Flow
32357 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
32358 l_budgetary_control_flag     := 'N';
32359 
32360 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
32361 l_bflow_applied_to_amt       := NULL; -- 5132302
32362 l_entered_amt_idx            := NULL;          -- 4262811
32363 l_accted_amt_idx             := NULL;          -- 4262811
32364 l_acc_rev_flag               := NULL;          -- 4262811
32365 l_accrual_line_num           := NULL;          -- 4262811
32366 l_tmp_amt                    := NULL;          -- 4262811
32367 --
32368  
32369 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
32370     l_balance_type_code <> 'B' THEN
32371 IF NVL(p_source_20,'
32372 ') =  'REC' AND 
32373 NVL(p_source_33,'
32374 ') =  'REV' AND 
32375 NVL(p_source_6,'
32376 ') =  'FEDERAL' AND 
32377 NVL(p_source_7,'
32378 ') =  'Order No Advance' AND 
32379 NVL(p_source_56,'
32380 ') =  'Y'
32381  THEN 
32382 
32383    --
32384    XLA_AE_LINES_PKG.SetNewLine;
32385 
32386    p_balance_type_code          := l_balance_type_code;
32387    -- set the flag so later we will know whether the gain loss line needs to be created
32388    
32389    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
32390      p_actual_flag :='A';
32394    -- bulk performance
32391    END IF;
32392 
32393    --
32395    --
32396    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
32397                                       p_header_num   => 0); -- 4262811
32398    --
32399    -- set accounting line options
32400    --
32401    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
32402            p_natural_side_code          => 'D'
32403          , p_gain_or_loss_flag          => 'N'
32404          , p_gl_transfer_mode_code      => 'S'
32405          , p_acct_entry_type_code       => 'A'
32406          , p_switch_side_flag           => 'Y'
32407          , p_merge_duplicate_code       => 'A'
32408          );
32409    --
32410    l_acc_rev_natural_side_code := 'C';  -- 4262811
32411    -- 
32412    --
32413    -- set accounting line type info
32414    --
32415    xla_ae_lines_pkg.SetAcctLineType
32416       (p_component_type             => l_component_type
32417       ,p_event_type_code            => l_event_type_code
32418       ,p_line_definition_owner_code => l_line_definition_owner_code
32419       ,p_line_definition_code       => l_line_definition_code
32420       ,p_accounting_line_code       => l_component_code
32421       ,p_accounting_line_type_code  => l_component_type_code
32422       ,p_accounting_line_appl_id    => l_component_appl_id
32423       ,p_amb_context_code           => l_amb_context_code
32424       ,p_entity_code                => l_entity_code
32425       ,p_event_class_code           => l_event_class_code);
32426    --
32427    -- set accounting class
32428    --
32429    xla_ae_lines_pkg.SetAcctClass(
32430            p_accounting_class_code  => 'FV_CASH_DR'
32431          , p_ae_header_id           => l_ae_header_id
32432          );
32433 
32434    --
32435    -- set rounding class
32436    --
32437    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
32438                       'RECEIVABLE';
32439 
32440    --
32441    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
32442    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
32443    --
32444    -- bulk performance
32445    --
32446    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
32447 
32448    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
32449       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
32450 
32451    -- 4955764
32452    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
32453       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
32454 
32455    -- 4458381 Public Sector Enh
32456    
32457    --
32458    -- set accounting attributes for the line type
32459    --
32460    l_entered_amt_idx := 8;
32461    l_accted_amt_idx  := 13;
32462    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
32463    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
32464    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
32465    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
32466    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
32467    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
32468    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
32469    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
32470    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
32471    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
32472    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
32473    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
32474    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
32475    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
32476    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
32477    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
32478    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
32479    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
32480    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
32481    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
32482    l_rec_acct_attrs.array_date_value(10)  := p_source_57;
32483    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
32484    l_rec_acct_attrs.array_num_value(11)  := p_source_62;
32485    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
32486    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
32487    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
32488    l_rec_acct_attrs.array_num_value(13)  := p_source_29;
32489    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
32490    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
32491    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
32492    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
32493    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
32494    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
32495 
32496    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
32497    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
32498 
32499    ---------------------------------------------------------------------------------------------------------------
32503 
32500    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
32501    ---------------------------------------------------------------------------------------------------------------
32502    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
32504    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
32505    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
32506 
32507    IF xla_accounting_cache_pkg.GetValueChar
32508          (p_source_code         => 'LEDGER_CATEGORY_CODE'
32509          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
32510    AND l_bflow_method_code = 'PRIOR_ENTRY'
32511 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
32512    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
32513          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
32514        )
32515    THEN
32516          xla_ae_lines_pkg.BflowUpgEntry
32517            (p_business_method_code    => l_bflow_method_code
32518            ,p_business_class_code     => l_bflow_class_code
32519            ,p_balance_type            => l_balance_type_code);
32520    ELSE
32521       NULL;
32522 -- No business flow processing for business flow method of NONE.
32523    END IF;
32524 
32525    --
32526    -- call analytical criteria
32527    --
32528    
32529    --
32530    -- call description
32531    --
32532    -- No description or it is inherited.
32533    --
32534    -- call ADRs
32535    -- Bug 4922099
32536    --
32537    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
32538         (NVL(l_actual_upg_option, 'N') = 'O') OR
32539         (NVL(l_enc_upg_option, 'N') = 'O')
32540       )
32541    THEN
32542    NULL;
32543    --
32544    --
32545    
32546   l_ccid := AcctDerRule_7(
32547            p_application_id           => p_application_id
32548          , p_ae_header_id             => l_ae_header_id 
32549 , p_source_3 => p_source_3
32550          , x_transaction_coa_id       => l_adr_transaction_coa_id
32551          , x_accounting_coa_id        => l_adr_accounting_coa_id
32552          , x_value_type_code          => l_adr_value_type_code
32553          , p_side                     => 'NA'
32554    );
32555 
32556    xla_ae_lines_pkg.set_ccid(
32557     p_code_combination_id          => l_ccid
32558   , p_value_type_code              => l_adr_value_type_code
32559   , p_transaction_coa_id           => l_adr_transaction_coa_id
32560   , p_accounting_coa_id            => l_adr_accounting_coa_id
32561   , p_adr_code                     => 'DIST_CCID'
32562   , p_adr_type_code                => 'S'
32563   , p_component_type               => l_component_type
32564   , p_component_code               => l_component_code
32565   , p_component_type_code          => l_component_type_code
32566   , p_component_appl_id            => l_component_appl_id
32567   , p_amb_context_code             => l_amb_context_code
32568   , p_side                         => 'NA'
32569   );
32570 
32571 
32572    l_segment := AcctDerRule_12(
32573            p_application_id           => p_application_id
32574          , p_ae_header_id             => l_ae_header_id 
32575 , p_source_7 => p_source_7
32576          , x_transaction_coa_id       => l_adr_transaction_coa_id
32577          , x_accounting_coa_id        => l_adr_accounting_coa_id
32578          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
32579          , x_flex_value_set_id        => l_adr_flex_value_set_id
32580          , x_value_type_code          => l_adr_value_type_code
32581          , x_value_combination_id     => l_adr_value_combination_id
32582          , x_value_segment_code       => l_adr_value_segment_code
32583          , p_side                     => 'NA'
32584          , p_override_seg_flag        => 'Y'
32585    );
32586 
32587    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
32588 
32589       xla_ae_lines_pkg.set_segment(
32590           p_to_segment_code         => 'GL_ACCOUNT'
32591         , p_segment_value           => l_segment
32592         , p_from_segment_code       => l_adr_value_segment_code
32593         , p_from_combination_id     => l_adr_value_combination_id
32594         , p_value_type_code         => l_adr_value_type_code
32595         , p_transaction_coa_id      => l_adr_transaction_coa_id
32596         , p_accounting_coa_id       => l_adr_accounting_coa_id
32597         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
32598         , p_flex_value_set_id       => l_adr_flex_value_set_id
32599         , p_adr_code                => 'FV_AR_425201_RCT_DR'
32600         , p_adr_type_code           => 'S'
32601         , p_component_type          => l_component_type
32602         , p_component_code          => l_component_code
32603         , p_component_type_code     => l_component_type_code
32604         , p_component_appl_id       => l_component_appl_id
32605         , p_amb_context_code        => l_amb_context_code
32606         , p_entity_code             => 'RECEIPTS'
32607         , p_event_class_code        => 'RECEIPT'
32608         , p_side                    => 'NA'
32609         );
32610 
32611   END IF;
32612 
32613    l_segment := AcctDerRule_5(
32614            p_application_id           => p_application_id
32615          , p_ae_header_id             => l_ae_header_id 
32619          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
32616 , p_source_4 => p_source_4
32617          , x_transaction_coa_id       => l_adr_transaction_coa_id
32618          , x_accounting_coa_id        => l_adr_accounting_coa_id
32620          , x_flex_value_set_id        => l_adr_flex_value_set_id
32621          , x_value_type_code          => l_adr_value_type_code
32622          , x_value_combination_id     => l_adr_value_combination_id
32623          , x_value_segment_code       => l_adr_value_segment_code
32624          , p_side                     => 'NA'
32625          , p_override_seg_flag        => 'Y'
32626    );
32627 
32628    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
32629 
32630       xla_ae_lines_pkg.set_segment(
32631           p_to_segment_code         => 'GL_BALANCING'
32632         , p_segment_value           => l_segment
32633         , p_from_segment_code       => l_adr_value_segment_code
32634         , p_from_combination_id     => l_adr_value_combination_id
32635         , p_value_type_code         => l_adr_value_type_code
32636         , p_transaction_coa_id      => l_adr_transaction_coa_id
32637         , p_accounting_coa_id       => l_adr_accounting_coa_id
32638         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
32639         , p_flex_value_set_id       => l_adr_flex_value_set_id
32640         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
32641         , p_adr_type_code           => 'S'
32642         , p_component_type          => l_component_type
32643         , p_component_code          => l_component_code
32644         , p_component_type_code     => l_component_type_code
32645         , p_component_appl_id       => l_component_appl_id
32646         , p_amb_context_code        => l_amb_context_code
32647         , p_entity_code             => 'RECEIPTS'
32648         , p_event_class_code        => 'RECEIPT'
32649         , p_side                    => 'NA'
32650         );
32651 
32652   END IF;
32653 
32654    --
32655    --
32656    END IF;
32657    --
32658    -- Bug 4922099
32659    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
32660           (NVL(l_enc_upg_option, 'N') = 'O')
32661         ) AND
32662         (l_bflow_method_code = 'PRIOR_ENTRY')
32663       )
32664    THEN
32665       IF
32666       --
32667       1 = 2
32668       --
32669       THEN
32670       xla_accounting_err_pkg.build_message
32671                                     (p_appli_s_name            => 'XLA'
32672                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
32673                                     ,p_token_1                 => 'LINE_NUMBER'
32674                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
32675                                     ,p_token_2                 => 'LINE_TYPE_NAME'
32676                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
32677                                                                              l_component_type
32678                                                                             ,l_component_code
32679                                                                             ,l_component_type_code
32680                                                                             ,l_component_appl_id
32681                                                                             ,l_amb_context_code
32682                                                                             ,l_entity_code
32683                                                                             ,l_event_class_code
32684                                                                            )
32685                                     ,p_token_3                 => 'OWNER'
32686                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
32687                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
32688                                                                           ,p_lookup_code    => l_component_type_code
32689                                                                          )
32690                                     ,p_token_4                 => 'PRODUCT_NAME'
32691                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
32692                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
32693                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
32694                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
32695                                     ,p_ae_header_id            =>  NULL
32696                                        );
32697 
32698         IF (C_LEVEL_ERROR>= g_log_level) THEN
32699                  trace
32700                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
32701                       ,p_level    => C_LEVEL_ERROR
32702                       ,p_module   => l_log_module);
32703         END IF;
32704       END IF;
32705    END IF;
32706    --
32707    --
32708    ------------------------------------------------------------------------------------------------
32709    -- 4219869 Business Flow
32710    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
32711    -- Prior Entry.  Currently, the following code is always generated.
32712    ------------------------------------------------------------------------------------------------
32713    XLA_AE_LINES_PKG.ValidateCurrentLine;
32717    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
32714 
32715    ------------------------------------------------------------------------------------
32716    -- 4219869 Business Flow
32718    ------------------------------------------------------------------------------------
32719    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
32720 
32721    ----------------------------------------------------------------------------------
32722    -- 4219869 Business Flow
32723    -- Update journal entry status -- Need to generate this within IF <condition>
32724    ----------------------------------------------------------------------------------
32725    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
32726          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
32727          ,p_balance_type_code => l_balance_type_code
32728          );
32729 
32730    -------------------------------------------------------------------------------------------
32731    -- 4262811 - Generate the Accrual Reversal lines
32732    -------------------------------------------------------------------------------------------
32733    BEGIN
32734       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
32735                               (g_array_event(p_event_id).array_value_num('header_index'));
32736       IF l_acc_rev_flag IS NULL THEN
32737          l_acc_rev_flag := 'N';
32738       END IF;
32739    EXCEPTION
32740       WHEN OTHERS THEN
32741          l_acc_rev_flag := 'N';
32742    END;
32743    --
32744    IF (l_acc_rev_flag = 'Y') THEN
32745 
32746        -- 4645092  ------------------------------------------------------------------------------
32747        -- To allow MPA report to determine if it should generate report process
32748        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
32749        ------------------------------------------------------------------------------------------
32750 
32751        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
32752        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
32753    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
32754    -- call ADRs
32755    -- Bug 4922099
32756    --
32757    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
32758         (NVL(l_actual_upg_option, 'N') = 'O') OR
32759         (NVL(l_enc_upg_option, 'N') = 'O')
32760       )
32761    THEN
32762    NULL;
32763    --
32764    --
32765    
32766   l_ccid := AcctDerRule_7(
32767            p_application_id           => p_application_id
32768          , p_ae_header_id             => l_ae_header_id 
32769 , p_source_3 => p_source_3
32770          , x_transaction_coa_id       => l_adr_transaction_coa_id
32771          , x_accounting_coa_id        => l_adr_accounting_coa_id
32772          , x_value_type_code          => l_adr_value_type_code
32773          , p_side                     => 'NA'
32774    );
32775 
32776    xla_ae_lines_pkg.set_ccid(
32777     p_code_combination_id          => l_ccid
32778   , p_value_type_code              => l_adr_value_type_code
32779   , p_transaction_coa_id           => l_adr_transaction_coa_id
32780   , p_accounting_coa_id            => l_adr_accounting_coa_id
32781   , p_adr_code                     => 'DIST_CCID'
32782   , p_adr_type_code                => 'S'
32783   , p_component_type               => l_component_type
32784   , p_component_code               => l_component_code
32785   , p_component_type_code          => l_component_type_code
32786   , p_component_appl_id            => l_component_appl_id
32787   , p_amb_context_code             => l_amb_context_code
32788   , p_side                         => 'NA'
32789   );
32790 
32791 
32792    l_segment := AcctDerRule_12(
32793            p_application_id           => p_application_id
32794          , p_ae_header_id             => l_ae_header_id 
32795 , p_source_7 => p_source_7
32796          , x_transaction_coa_id       => l_adr_transaction_coa_id
32797          , x_accounting_coa_id        => l_adr_accounting_coa_id
32798          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
32799          , x_flex_value_set_id        => l_adr_flex_value_set_id
32800          , x_value_type_code          => l_adr_value_type_code
32801          , x_value_combination_id     => l_adr_value_combination_id
32802          , x_value_segment_code       => l_adr_value_segment_code
32803          , p_side                     => 'NA'
32804          , p_override_seg_flag        => 'Y'
32805    );
32806 
32807    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
32808 
32809       xla_ae_lines_pkg.set_segment(
32810           p_to_segment_code         => 'GL_ACCOUNT'
32811         , p_segment_value           => l_segment
32812         , p_from_segment_code       => l_adr_value_segment_code
32813         , p_from_combination_id     => l_adr_value_combination_id
32814         , p_value_type_code         => l_adr_value_type_code
32815         , p_transaction_coa_id      => l_adr_transaction_coa_id
32816         , p_accounting_coa_id       => l_adr_accounting_coa_id
32817         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
32818         , p_flex_value_set_id       => l_adr_flex_value_set_id
32819         , p_adr_code                => 'FV_AR_425201_RCT_DR'
32820         , p_adr_type_code           => 'S'
32821         , p_component_type          => l_component_type
32822         , p_component_code          => l_component_code
32823         , p_component_type_code     => l_component_type_code
32827         , p_event_class_code        => 'RECEIPT'
32824         , p_component_appl_id       => l_component_appl_id
32825         , p_amb_context_code        => l_amb_context_code
32826         , p_entity_code             => 'RECEIPTS'
32828         , p_side                    => 'NA'
32829         );
32830 
32831   END IF;
32832 
32833    l_segment := AcctDerRule_5(
32834            p_application_id           => p_application_id
32835          , p_ae_header_id             => l_ae_header_id 
32836 , p_source_4 => p_source_4
32837          , x_transaction_coa_id       => l_adr_transaction_coa_id
32838          , x_accounting_coa_id        => l_adr_accounting_coa_id
32839          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
32840          , x_flex_value_set_id        => l_adr_flex_value_set_id
32841          , x_value_type_code          => l_adr_value_type_code
32842          , x_value_combination_id     => l_adr_value_combination_id
32843          , x_value_segment_code       => l_adr_value_segment_code
32844          , p_side                     => 'NA'
32845          , p_override_seg_flag        => 'Y'
32846    );
32847 
32848    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
32849 
32850       xla_ae_lines_pkg.set_segment(
32851           p_to_segment_code         => 'GL_BALANCING'
32852         , p_segment_value           => l_segment
32853         , p_from_segment_code       => l_adr_value_segment_code
32854         , p_from_combination_id     => l_adr_value_combination_id
32855         , p_value_type_code         => l_adr_value_type_code
32856         , p_transaction_coa_id      => l_adr_transaction_coa_id
32857         , p_accounting_coa_id       => l_adr_accounting_coa_id
32858         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
32859         , p_flex_value_set_id       => l_adr_flex_value_set_id
32860         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
32861         , p_adr_type_code           => 'S'
32862         , p_component_type          => l_component_type
32863         , p_component_code          => l_component_code
32864         , p_component_type_code     => l_component_type_code
32865         , p_component_appl_id       => l_component_appl_id
32866         , p_amb_context_code        => l_amb_context_code
32867         , p_entity_code             => 'RECEIPTS'
32868         , p_event_class_code        => 'RECEIPT'
32869         , p_side                    => 'NA'
32870         );
32871 
32872   END IF;
32873 
32874    --
32875    --
32876    END IF;
32877 
32878        --
32879        -- Update the line information that should be overwritten
32880        --
32881        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
32882                                          p_header_num   => 1);
32883        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
32884 
32885        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
32886 
32887        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
32888           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
32889        END IF;
32890 
32891       --
32892       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
32893       --
32894       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
32895           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
32896       ELSE
32897           ---------------------------------------------------------------------------------------------------
32898           -- 4262811a Switch Sign
32899           ---------------------------------------------------------------------------------------------------
32900           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
32901           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
32902                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
32903           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
32904                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
32905           -- 5132302
32906           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
32907                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
32908 
32909       END IF;
32910 
32911       -- 4955764
32912       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
32913       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
32914 
32915 
32916       XLA_AE_LINES_PKG.ValidateCurrentLine;
32917       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
32918 
32919       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
32920                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
32921                ,p_balance_type_code => l_balance_type_code);
32922 
32923    END IF;
32924 
32925    -----------------------------------------------------------------------------------------
32926    -- 4262811 Multiperiod Accounting
32927    -----------------------------------------------------------------------------------------
32931 END IF;
32928      -- No MPA option is assigned.
32929 
32930 
32932 END IF;
32933 --
32934 
32935 --
32936 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
32937    trace
32938       (p_msg      => 'END of AcctLineType_76'
32939       ,p_level    => C_LEVEL_PROCEDURE
32940       ,p_module   => l_log_module);
32941 END IF;
32942 --
32943 EXCEPTION
32944   WHEN xla_exceptions_pkg.application_exception THEN
32945       RAISE;
32946   WHEN OTHERS THEN
32947        xla_exceptions_pkg.raise_message
32948            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_76');
32949 END AcctLineType_76;
32950 --
32951 
32952 ---------------------------------------
32953 --
32954 -- PRIVATE FUNCTION
32955 --         AcctLineType_77
32956 --
32957 ---------------------------------------
32958 PROCEDURE AcctLineType_77 (
32959   p_application_id        IN NUMBER
32960  ,p_event_id              IN NUMBER
32961  ,p_calculate_acctd_flag  IN VARCHAR2
32962  ,p_calculate_g_l_flag    IN VARCHAR2
32963  ,p_actual_flag           IN OUT VARCHAR2
32964  ,p_balance_type_code     OUT VARCHAR2
32965  ,p_gain_or_loss_ref      OUT VARCHAR2
32966  
32967 --Transaction Distribution GL Account
32968  , p_source_4            IN NUMBER
32969 --Bill To Customer Account Identifier
32970  , p_source_30            IN NUMBER
32971 --Bill To Customer Site Use Identifier
32972  , p_source_31            IN NUMBER
32973 --SLA Party Type
32974  , p_source_32            IN VARCHAR2
32975 --Transaction Distribution Account Class
32976  , p_source_33            IN VARCHAR2
32977 --Transaction Distribution Identifier
32978  , p_source_34            IN NUMBER
32979 --Transaction Distribution Type
32980  , p_source_35            IN VARCHAR2
32981 --Transaction Distribution Entered Amount
32982  , p_source_36            IN NUMBER
32983 --Transaction Currency Code
32984  , p_source_37            IN VARCHAR2
32985 --Transaction Exchange Date
32986  , p_source_38            IN DATE
32987 --Transaction Exchange Rate
32988  , p_source_39            IN NUMBER
32989 --Transaction Exchange Rate Type
32990  , p_source_40            IN VARCHAR2
32991 --Transaction Accounting Amount
32992  , p_source_41            IN NUMBER
32993 )
32994 IS
32995 
32996 l_component_type              VARCHAR2(80);
32997 l_component_code              VARCHAR2(30);
32998 l_component_type_code         VARCHAR2(1);
32999 l_component_appl_id           INTEGER;
33000 l_amb_context_code            VARCHAR2(30);
33001 l_entity_code                 VARCHAR2(30);
33002 l_event_class_code            VARCHAR2(30);
33003 l_ae_header_id                NUMBER;
33004 l_event_type_code             VARCHAR2(30);
33005 l_line_definition_code        VARCHAR2(30);
33006 l_line_definition_owner_code  VARCHAR2(1);
33007 --
33008 -- adr variables
33009 l_segment                     VARCHAR2(30);
33010 l_ccid                        NUMBER;
33011 l_adr_transaction_coa_id      NUMBER;
33012 l_adr_accounting_coa_id       NUMBER;
33013 l_adr_flexfield_segment_code  VARCHAR2(30);
33014 l_adr_flex_value_set_id       NUMBER;
33015 l_adr_value_type_code         VARCHAR2(30);
33016 l_adr_value_combination_id    NUMBER;
33017 l_adr_value_segment_code      VARCHAR2(30);
33018 
33019 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
33020 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
33021 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
33022 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
33023 
33024 -- 4262811 Variables ------------------------------------------------------------------------------------------
33025 l_entered_amt_idx             NUMBER;
33026 l_accted_amt_idx              NUMBER;
33027 l_acc_rev_flag                VARCHAR2(1);
33028 l_accrual_line_num            NUMBER;
33029 l_tmp_amt                     NUMBER;
33030 l_acc_rev_natural_side_code   VARCHAR2(1);
33031 
33032 l_num_entries                 NUMBER;
33033 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
33034 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
33035 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
33036 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
33037 l_recog_line_1                NUMBER;
33038 l_recog_line_2                NUMBER;
33039 
33040 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
33041 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
33042 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
33043 
33044 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
33045 
33046 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
33047 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
33048 
33049 ---------------------------------------------------------------------------------------------------------------
33050 
33051 
33052 --
33053 -- bulk performance
33054 --
33055 l_balance_type_code           VARCHAR2(1);
33056 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
33057 l_log_module                  VARCHAR2(240);
33058 
33059 --
33060 -- Upgrade strategy
33061 --
33062 l_actual_upg_option           VARCHAR2(1);
33066 BEGIN
33063 l_enc_upg_option           VARCHAR2(1);
33064 
33065 --
33067 --
33068 IF g_log_enabled THEN
33069       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_77';
33070 END IF;
33071 --
33072 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
33073 
33074       trace
33075          (p_msg      => 'BEGIN of AcctLineType_77'
33076          ,p_level    => C_LEVEL_PROCEDURE
33077          ,p_module   => l_log_module);
33078 
33079 END IF;
33080 --
33081 l_component_type             := 'AMB_JLT';
33082 l_component_code             := 'GUAR_DEFAULT_REC';
33083 l_component_type_code        := 'S';
33084 l_component_appl_id          :=  222;
33085 l_amb_context_code           := 'DEFAULT';
33086 l_entity_code                := 'TRANSACTIONS';
33087 l_event_class_code           := 'GUARANTEE';
33088 l_event_type_code            := 'GUARANTEE_ALL';
33089 l_line_definition_owner_code := 'S';
33090 l_line_definition_code       := 'AR_GUAR_DEFAULT_ACCRUAL';
33091 --
33092 l_balance_type_code          := 'A';
33093 l_segment                     := NULL;
33094 l_ccid                        := NULL;
33095 l_adr_transaction_coa_id      := NULL;
33096 l_adr_accounting_coa_id       := NULL;
33097 l_adr_flexfield_segment_code  := NULL;
33098 l_adr_flex_value_set_id       := NULL;
33099 l_adr_value_type_code         := NULL;
33100 l_adr_value_combination_id    := NULL;
33101 l_adr_value_segment_code      := NULL;
33102 
33103 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
33104 l_bflow_class_code           := '';    -- 4219869 Business Flow
33105 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
33106 l_budgetary_control_flag     := 'N';
33107 
33108 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
33109 l_bflow_applied_to_amt       := NULL; -- 5132302
33110 l_entered_amt_idx            := NULL;          -- 4262811
33111 l_accted_amt_idx             := NULL;          -- 4262811
33112 l_acc_rev_flag               := NULL;          -- 4262811
33113 l_accrual_line_num           := NULL;          -- 4262811
33114 l_tmp_amt                    := NULL;          -- 4262811
33115 --
33116  
33117 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
33118     l_balance_type_code <> 'B' THEN
33119 IF NVL(p_source_33,'
33120 ') =  'REC'
33121  THEN 
33122 
33123    --
33124    XLA_AE_LINES_PKG.SetNewLine;
33125 
33126    p_balance_type_code          := l_balance_type_code;
33127    -- set the flag so later we will know whether the gain loss line needs to be created
33128    
33129    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
33130      p_actual_flag :='A';
33131    END IF;
33132 
33133    --
33134    -- bulk performance
33135    --
33136    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
33137                                       p_header_num   => 0); -- 4262811
33138    --
33139    -- set accounting line options
33140    --
33141    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
33142            p_natural_side_code          => 'D'
33143          , p_gain_or_loss_flag          => 'N'
33144          , p_gl_transfer_mode_code      => 'S'
33145          , p_acct_entry_type_code       => 'A'
33146          , p_switch_side_flag           => 'Y'
33147          , p_merge_duplicate_code       => 'A'
33148          );
33149    --
33150    l_acc_rev_natural_side_code := 'C';  -- 4262811
33151    -- 
33152    --
33153    -- set accounting line type info
33154    --
33155    xla_ae_lines_pkg.SetAcctLineType
33156       (p_component_type             => l_component_type
33157       ,p_event_type_code            => l_event_type_code
33158       ,p_line_definition_owner_code => l_line_definition_owner_code
33159       ,p_line_definition_code       => l_line_definition_code
33160       ,p_accounting_line_code       => l_component_code
33161       ,p_accounting_line_type_code  => l_component_type_code
33162       ,p_accounting_line_appl_id    => l_component_appl_id
33163       ,p_amb_context_code           => l_amb_context_code
33164       ,p_entity_code                => l_entity_code
33165       ,p_event_class_code           => l_event_class_code);
33166    --
33167    -- set accounting class
33168    --
33169    xla_ae_lines_pkg.SetAcctClass(
33170            p_accounting_class_code  => 'RECEIVABLE'
33171          , p_ae_header_id           => l_ae_header_id
33172          );
33173 
33174    --
33175    -- set rounding class
33176    --
33177    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
33178                       'RECEIVABLE';
33179 
33180    --
33181    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
33182    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
33183    --
33184    -- bulk performance
33185    --
33186    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
33187 
33188    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
33189       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
33190 
33191    -- 4955764
33192    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
33193       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
33194 
33195    -- 4458381 Public Sector Enh
33196    
33197    --
33201    l_accted_amt_idx  := 8;
33198    -- set accounting attributes for the line type
33199    --
33200    l_entered_amt_idx := 3;
33202    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
33203    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
33204    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
33205    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
33206    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
33207    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
33208    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
33209    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
33210    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
33211    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
33212    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
33213    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
33214    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
33215    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
33216    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
33217    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
33218    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
33219    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
33220    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
33221    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
33222    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
33223    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
33224    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
33225 
33226    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
33227    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
33228 
33229    ---------------------------------------------------------------------------------------------------------------
33230    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
33231    ---------------------------------------------------------------------------------------------------------------
33232    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
33233 
33234    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
33235    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
33236 
33237    IF xla_accounting_cache_pkg.GetValueChar
33238          (p_source_code         => 'LEDGER_CATEGORY_CODE'
33239          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
33240    AND l_bflow_method_code = 'PRIOR_ENTRY'
33241 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
33242    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
33243          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
33244        )
33245    THEN
33246          xla_ae_lines_pkg.BflowUpgEntry
33247            (p_business_method_code    => l_bflow_method_code
33248            ,p_business_class_code     => l_bflow_class_code
33249            ,p_balance_type            => l_balance_type_code);
33250    ELSE
33251       NULL;
33252 -- No business flow processing for business flow method of NONE.
33253    END IF;
33254 
33255    --
33256    -- call analytical criteria
33257    --
33258    
33259    --
33260    -- call description
33261    --
33262    -- No description or it is inherited.
33263    --
33264    -- call ADRs
33265    -- Bug 4922099
33266    --
33267    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
33268         (NVL(l_actual_upg_option, 'N') = 'O') OR
33269         (NVL(l_enc_upg_option, 'N') = 'O')
33270       )
33271    THEN
33272    NULL;
33273    --
33274    --
33275    
33276   l_ccid := AcctDerRule_32(
33277            p_application_id           => p_application_id
33278          , p_ae_header_id             => l_ae_header_id 
33279 , p_source_4 => p_source_4
33280          , x_transaction_coa_id       => l_adr_transaction_coa_id
33281          , x_accounting_coa_id        => l_adr_accounting_coa_id
33282          , x_value_type_code          => l_adr_value_type_code
33283          , p_side                     => 'NA'
33284    );
33285 
33286    xla_ae_lines_pkg.set_ccid(
33287     p_code_combination_id          => l_ccid
33288   , p_value_type_code              => l_adr_value_type_code
33289   , p_transaction_coa_id           => l_adr_transaction_coa_id
33290   , p_accounting_coa_id            => l_adr_accounting_coa_id
33291   , p_adr_code                     => 'TRX_DIST_CCID'
33292   , p_adr_type_code                => 'S'
33293   , p_component_type               => l_component_type
33294   , p_component_code               => l_component_code
33295   , p_component_type_code          => l_component_type_code
33296   , p_component_appl_id            => l_component_appl_id
33297   , p_amb_context_code             => l_amb_context_code
33298   , p_side                         => 'NA'
33299   );
33300 
33301 
33302    --
33303    --
33304    END IF;
33305    --
33306    -- Bug 4922099
33307    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
33308           (NVL(l_enc_upg_option, 'N') = 'O')
33309         ) AND
33310         (l_bflow_method_code = 'PRIOR_ENTRY')
33311       )
33312    THEN
33313       IF
33314       --
33315       1 = 2
33316       --
33317       THEN
33321                                     ,p_token_1                 => 'LINE_NUMBER'
33318       xla_accounting_err_pkg.build_message
33319                                     (p_appli_s_name            => 'XLA'
33320                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
33322                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
33323                                     ,p_token_2                 => 'LINE_TYPE_NAME'
33324                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
33325                                                                              l_component_type
33326                                                                             ,l_component_code
33327                                                                             ,l_component_type_code
33328                                                                             ,l_component_appl_id
33329                                                                             ,l_amb_context_code
33330                                                                             ,l_entity_code
33331                                                                             ,l_event_class_code
33332                                                                            )
33333                                     ,p_token_3                 => 'OWNER'
33334                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
33335                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
33336                                                                           ,p_lookup_code    => l_component_type_code
33337                                                                          )
33338                                     ,p_token_4                 => 'PRODUCT_NAME'
33339                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
33340                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
33341                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
33342                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
33343                                     ,p_ae_header_id            =>  NULL
33344                                        );
33345 
33346         IF (C_LEVEL_ERROR>= g_log_level) THEN
33347                  trace
33348                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
33349                       ,p_level    => C_LEVEL_ERROR
33350                       ,p_module   => l_log_module);
33351         END IF;
33352       END IF;
33353    END IF;
33354    --
33355    --
33356    ------------------------------------------------------------------------------------------------
33357    -- 4219869 Business Flow
33358    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
33359    -- Prior Entry.  Currently, the following code is always generated.
33360    ------------------------------------------------------------------------------------------------
33361    XLA_AE_LINES_PKG.ValidateCurrentLine;
33362 
33363    ------------------------------------------------------------------------------------
33364    -- 4219869 Business Flow
33365    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
33366    ------------------------------------------------------------------------------------
33367    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
33368 
33369    ----------------------------------------------------------------------------------
33370    -- 4219869 Business Flow
33371    -- Update journal entry status -- Need to generate this within IF <condition>
33372    ----------------------------------------------------------------------------------
33373    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
33374          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
33375          ,p_balance_type_code => l_balance_type_code
33376          );
33377 
33378    -------------------------------------------------------------------------------------------
33379    -- 4262811 - Generate the Accrual Reversal lines
33380    -------------------------------------------------------------------------------------------
33381    BEGIN
33382       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
33383                               (g_array_event(p_event_id).array_value_num('header_index'));
33384       IF l_acc_rev_flag IS NULL THEN
33385          l_acc_rev_flag := 'N';
33386       END IF;
33387    EXCEPTION
33388       WHEN OTHERS THEN
33389          l_acc_rev_flag := 'N';
33390    END;
33391    --
33392    IF (l_acc_rev_flag = 'Y') THEN
33393 
33394        -- 4645092  ------------------------------------------------------------------------------
33395        -- To allow MPA report to determine if it should generate report process
33396        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
33397        ------------------------------------------------------------------------------------------
33398 
33399        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
33400        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
33401    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
33402    -- call ADRs
33403    -- Bug 4922099
33404    --
33408       )
33405    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
33406         (NVL(l_actual_upg_option, 'N') = 'O') OR
33407         (NVL(l_enc_upg_option, 'N') = 'O')
33409    THEN
33410    NULL;
33411    --
33412    --
33413    
33414   l_ccid := AcctDerRule_32(
33415            p_application_id           => p_application_id
33416          , p_ae_header_id             => l_ae_header_id 
33417 , p_source_4 => p_source_4
33418          , x_transaction_coa_id       => l_adr_transaction_coa_id
33419          , x_accounting_coa_id        => l_adr_accounting_coa_id
33420          , x_value_type_code          => l_adr_value_type_code
33421          , p_side                     => 'NA'
33422    );
33423 
33424    xla_ae_lines_pkg.set_ccid(
33425     p_code_combination_id          => l_ccid
33426   , p_value_type_code              => l_adr_value_type_code
33427   , p_transaction_coa_id           => l_adr_transaction_coa_id
33428   , p_accounting_coa_id            => l_adr_accounting_coa_id
33429   , p_adr_code                     => 'TRX_DIST_CCID'
33430   , p_adr_type_code                => 'S'
33431   , p_component_type               => l_component_type
33432   , p_component_code               => l_component_code
33433   , p_component_type_code          => l_component_type_code
33434   , p_component_appl_id            => l_component_appl_id
33435   , p_amb_context_code             => l_amb_context_code
33436   , p_side                         => 'NA'
33437   );
33438 
33439 
33440    --
33441    --
33442    END IF;
33443 
33444        --
33445        -- Update the line information that should be overwritten
33446        --
33447        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
33448                                          p_header_num   => 1);
33449        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
33450 
33451        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
33452 
33453        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
33454           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
33455        END IF;
33456 
33457       --
33458       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
33459       --
33460       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
33461           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
33462       ELSE
33463           ---------------------------------------------------------------------------------------------------
33464           -- 4262811a Switch Sign
33465           ---------------------------------------------------------------------------------------------------
33466           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
33467           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
33468                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
33469           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
33470                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
33471           -- 5132302
33472           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
33473                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
33474 
33475       END IF;
33476 
33477       -- 4955764
33478       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
33479       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
33480 
33481 
33482       XLA_AE_LINES_PKG.ValidateCurrentLine;
33483       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
33484 
33485       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
33486                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
33487                ,p_balance_type_code => l_balance_type_code);
33488 
33489    END IF;
33490 
33491    -----------------------------------------------------------------------------------------
33492    -- 4262811 Multiperiod Accounting
33493    -----------------------------------------------------------------------------------------
33494      -- No MPA option is assigned.
33495 
33496 
33497 END IF;
33498 END IF;
33499 --
33500 
33501 --
33502 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
33503    trace
33504       (p_msg      => 'END of AcctLineType_77'
33505       ,p_level    => C_LEVEL_PROCEDURE
33506       ,p_module   => l_log_module);
33507 END IF;
33508 --
33509 EXCEPTION
33510   WHEN xla_exceptions_pkg.application_exception THEN
33511       RAISE;
33512   WHEN OTHERS THEN
33513        xla_exceptions_pkg.raise_message
33514            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_77');
33515 END AcctLineType_77;
33516 --
33517 
33518 ---------------------------------------
33519 --
33520 -- PRIVATE FUNCTION
33521 --         AcctLineType_78
33522 --
33523 ---------------------------------------
33524 PROCEDURE AcctLineType_78 (
33525   p_application_id        IN NUMBER
33529  ,p_actual_flag           IN OUT VARCHAR2
33526  ,p_event_id              IN NUMBER
33527  ,p_calculate_acctd_flag  IN VARCHAR2
33528  ,p_calculate_g_l_flag    IN VARCHAR2
33530  ,p_balance_type_code     OUT VARCHAR2
33531  ,p_gain_or_loss_ref      OUT VARCHAR2
33532  
33533 --Transaction Distribution GL Account
33534  , p_source_4            IN NUMBER
33535 --Bill To Customer Account Identifier
33536  , p_source_30            IN NUMBER
33537 --Bill To Customer Site Use Identifier
33538  , p_source_31            IN NUMBER
33539 --SLA Party Type
33540  , p_source_32            IN VARCHAR2
33541 --Transaction Distribution Account Class
33542  , p_source_33            IN VARCHAR2
33543 --Transaction Distribution Identifier
33544  , p_source_34            IN NUMBER
33545 --Transaction Distribution Type
33546  , p_source_35            IN VARCHAR2
33547 --Transaction Distribution Entered Amount
33548  , p_source_36            IN NUMBER
33549 --Transaction Currency Code
33550  , p_source_37            IN VARCHAR2
33551 --Transaction Exchange Date
33552  , p_source_38            IN DATE
33553 --Transaction Exchange Rate
33554  , p_source_39            IN NUMBER
33555 --Transaction Exchange Rate Type
33556  , p_source_40            IN VARCHAR2
33557 --Transaction Accounting Amount
33558  , p_source_41            IN NUMBER
33559 )
33560 IS
33561 
33562 l_component_type              VARCHAR2(80);
33563 l_component_code              VARCHAR2(30);
33564 l_component_type_code         VARCHAR2(1);
33565 l_component_appl_id           INTEGER;
33566 l_amb_context_code            VARCHAR2(30);
33567 l_entity_code                 VARCHAR2(30);
33568 l_event_class_code            VARCHAR2(30);
33569 l_ae_header_id                NUMBER;
33570 l_event_type_code             VARCHAR2(30);
33571 l_line_definition_code        VARCHAR2(30);
33572 l_line_definition_owner_code  VARCHAR2(1);
33573 --
33574 -- adr variables
33575 l_segment                     VARCHAR2(30);
33576 l_ccid                        NUMBER;
33577 l_adr_transaction_coa_id      NUMBER;
33578 l_adr_accounting_coa_id       NUMBER;
33579 l_adr_flexfield_segment_code  VARCHAR2(30);
33580 l_adr_flex_value_set_id       NUMBER;
33581 l_adr_value_type_code         VARCHAR2(30);
33582 l_adr_value_combination_id    NUMBER;
33583 l_adr_value_segment_code      VARCHAR2(30);
33584 
33585 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
33586 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
33587 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
33588 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
33589 
33590 -- 4262811 Variables ------------------------------------------------------------------------------------------
33591 l_entered_amt_idx             NUMBER;
33592 l_accted_amt_idx              NUMBER;
33593 l_acc_rev_flag                VARCHAR2(1);
33594 l_accrual_line_num            NUMBER;
33595 l_tmp_amt                     NUMBER;
33596 l_acc_rev_natural_side_code   VARCHAR2(1);
33597 
33598 l_num_entries                 NUMBER;
33599 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
33600 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
33601 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
33602 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
33603 l_recog_line_1                NUMBER;
33604 l_recog_line_2                NUMBER;
33605 
33606 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
33607 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
33608 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
33609 
33610 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
33611 
33612 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
33613 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
33614 
33615 ---------------------------------------------------------------------------------------------------------------
33616 
33617 
33618 --
33619 -- bulk performance
33620 --
33621 l_balance_type_code           VARCHAR2(1);
33622 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
33623 l_log_module                  VARCHAR2(240);
33624 
33625 --
33626 -- Upgrade strategy
33627 --
33628 l_actual_upg_option           VARCHAR2(1);
33629 l_enc_upg_option           VARCHAR2(1);
33630 
33631 --
33632 BEGIN
33633 --
33634 IF g_log_enabled THEN
33635       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_78';
33636 END IF;
33637 --
33638 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
33639 
33640       trace
33641          (p_msg      => 'BEGIN of AcctLineType_78'
33642          ,p_level    => C_LEVEL_PROCEDURE
33643          ,p_module   => l_log_module);
33644 
33645 END IF;
33646 --
33647 l_component_type             := 'AMB_JLT';
33648 l_component_code             := 'GUAR_REV';
33649 l_component_type_code        := 'S';
33650 l_component_appl_id          :=  222;
33651 l_amb_context_code           := 'DEFAULT';
33652 l_entity_code                := 'TRANSACTIONS';
33653 l_event_class_code           := 'GUARANTEE';
33654 l_event_type_code            := 'GUARANTEE_ALL';
33655 l_line_definition_owner_code := 'S';
33656 l_line_definition_code       := 'AR_GUAR_DEFAULT_ACCRUAL';
33657 --
33658 l_balance_type_code          := 'A';
33662 l_adr_accounting_coa_id       := NULL;
33659 l_segment                     := NULL;
33660 l_ccid                        := NULL;
33661 l_adr_transaction_coa_id      := NULL;
33663 l_adr_flexfield_segment_code  := NULL;
33664 l_adr_flex_value_set_id       := NULL;
33665 l_adr_value_type_code         := NULL;
33666 l_adr_value_combination_id    := NULL;
33667 l_adr_value_segment_code      := NULL;
33668 
33669 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
33670 l_bflow_class_code           := '';    -- 4219869 Business Flow
33671 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
33672 l_budgetary_control_flag     := 'N';
33673 
33674 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
33675 l_bflow_applied_to_amt       := NULL; -- 5132302
33676 l_entered_amt_idx            := NULL;          -- 4262811
33677 l_accted_amt_idx             := NULL;          -- 4262811
33678 l_acc_rev_flag               := NULL;          -- 4262811
33679 l_accrual_line_num           := NULL;          -- 4262811
33680 l_tmp_amt                    := NULL;          -- 4262811
33681 --
33682  
33683 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
33684     l_balance_type_code <> 'B' THEN
33685 IF NVL(p_source_33,'
33686 ') =  'REV'
33687  THEN 
33688 
33689    --
33690    XLA_AE_LINES_PKG.SetNewLine;
33691 
33692    p_balance_type_code          := l_balance_type_code;
33693    -- set the flag so later we will know whether the gain loss line needs to be created
33694    
33695    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
33696      p_actual_flag :='A';
33697    END IF;
33698 
33699    --
33700    -- bulk performance
33701    --
33702    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
33703                                       p_header_num   => 0); -- 4262811
33704    --
33705    -- set accounting line options
33706    --
33707    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
33708            p_natural_side_code          => 'C'
33709          , p_gain_or_loss_flag          => 'N'
33710          , p_gl_transfer_mode_code      => 'S'
33711          , p_acct_entry_type_code       => 'A'
33712          , p_switch_side_flag           => 'Y'
33713          , p_merge_duplicate_code       => 'A'
33714          );
33715    --
33716    l_acc_rev_natural_side_code := 'D';  -- 4262811
33717    -- 
33718    --
33719    -- set accounting line type info
33720    --
33721    xla_ae_lines_pkg.SetAcctLineType
33722       (p_component_type             => l_component_type
33723       ,p_event_type_code            => l_event_type_code
33724       ,p_line_definition_owner_code => l_line_definition_owner_code
33725       ,p_line_definition_code       => l_line_definition_code
33726       ,p_accounting_line_code       => l_component_code
33727       ,p_accounting_line_type_code  => l_component_type_code
33728       ,p_accounting_line_appl_id    => l_component_appl_id
33729       ,p_amb_context_code           => l_amb_context_code
33730       ,p_entity_code                => l_entity_code
33731       ,p_event_class_code           => l_event_class_code);
33732    --
33733    -- set accounting class
33734    --
33735    xla_ae_lines_pkg.SetAcctClass(
33736            p_accounting_class_code  => 'REVENUE'
33737          , p_ae_header_id           => l_ae_header_id
33738          );
33739 
33740    --
33741    -- set rounding class
33742    --
33743    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
33744                       'RECEIVABLE';
33745 
33746    --
33747    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
33748    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
33749    --
33750    -- bulk performance
33751    --
33752    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
33753 
33754    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
33755       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
33756 
33757    -- 4955764
33758    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
33759       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
33760 
33761    -- 4458381 Public Sector Enh
33762    
33763    --
33764    -- set accounting attributes for the line type
33765    --
33766    l_entered_amt_idx := 3;
33767    l_accted_amt_idx  := 8;
33768    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
33769    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
33770    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
33771    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
33772    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
33773    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
33774    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
33775    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
33776    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
33777    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
33778    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
33779    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
33780    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
33784    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
33781    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
33782    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
33783    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
33785    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
33786    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
33787    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
33788    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
33789    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
33790    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
33791 
33792    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
33793    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
33794 
33795    ---------------------------------------------------------------------------------------------------------------
33796    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
33797    ---------------------------------------------------------------------------------------------------------------
33798    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
33799 
33800    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
33801    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
33802 
33803    IF xla_accounting_cache_pkg.GetValueChar
33804          (p_source_code         => 'LEDGER_CATEGORY_CODE'
33805          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
33806    AND l_bflow_method_code = 'PRIOR_ENTRY'
33807 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
33808    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
33809          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
33810        )
33811    THEN
33812          xla_ae_lines_pkg.BflowUpgEntry
33813            (p_business_method_code    => l_bflow_method_code
33814            ,p_business_class_code     => l_bflow_class_code
33815            ,p_balance_type            => l_balance_type_code);
33816    ELSE
33817       NULL;
33818 -- No business flow processing for business flow method of NONE.
33819    END IF;
33820 
33821    --
33822    -- call analytical criteria
33823    --
33824    
33825    --
33826    -- call description
33827    --
33828    -- No description or it is inherited.
33829    --
33830    -- call ADRs
33831    -- Bug 4922099
33832    --
33833    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
33834         (NVL(l_actual_upg_option, 'N') = 'O') OR
33835         (NVL(l_enc_upg_option, 'N') = 'O')
33836       )
33837    THEN
33838    NULL;
33839    --
33840    --
33841    
33842   l_ccid := AcctDerRule_32(
33843            p_application_id           => p_application_id
33844          , p_ae_header_id             => l_ae_header_id 
33845 , p_source_4 => p_source_4
33846          , x_transaction_coa_id       => l_adr_transaction_coa_id
33847          , x_accounting_coa_id        => l_adr_accounting_coa_id
33848          , x_value_type_code          => l_adr_value_type_code
33849          , p_side                     => 'NA'
33850    );
33851 
33852    xla_ae_lines_pkg.set_ccid(
33853     p_code_combination_id          => l_ccid
33854   , p_value_type_code              => l_adr_value_type_code
33855   , p_transaction_coa_id           => l_adr_transaction_coa_id
33856   , p_accounting_coa_id            => l_adr_accounting_coa_id
33857   , p_adr_code                     => 'TRX_DIST_CCID'
33858   , p_adr_type_code                => 'S'
33859   , p_component_type               => l_component_type
33860   , p_component_code               => l_component_code
33861   , p_component_type_code          => l_component_type_code
33862   , p_component_appl_id            => l_component_appl_id
33863   , p_amb_context_code             => l_amb_context_code
33864   , p_side                         => 'NA'
33865   );
33866 
33867 
33868    --
33869    --
33870    END IF;
33871    --
33872    -- Bug 4922099
33873    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
33874           (NVL(l_enc_upg_option, 'N') = 'O')
33875         ) AND
33876         (l_bflow_method_code = 'PRIOR_ENTRY')
33877       )
33878    THEN
33879       IF
33880       --
33881       1 = 2
33882       --
33883       THEN
33884       xla_accounting_err_pkg.build_message
33885                                     (p_appli_s_name            => 'XLA'
33886                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
33887                                     ,p_token_1                 => 'LINE_NUMBER'
33888                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
33889                                     ,p_token_2                 => 'LINE_TYPE_NAME'
33890                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
33891                                                                              l_component_type
33892                                                                             ,l_component_code
33893                                                                             ,l_component_type_code
33894                                                                             ,l_component_appl_id
33895                                                                             ,l_amb_context_code
33899                                     ,p_token_3                 => 'OWNER'
33896                                                                             ,l_entity_code
33897                                                                             ,l_event_class_code
33898                                                                            )
33900                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
33901                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
33902                                                                           ,p_lookup_code    => l_component_type_code
33903                                                                          )
33904                                     ,p_token_4                 => 'PRODUCT_NAME'
33905                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
33906                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
33907                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
33908                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
33909                                     ,p_ae_header_id            =>  NULL
33910                                        );
33911 
33912         IF (C_LEVEL_ERROR>= g_log_level) THEN
33913                  trace
33914                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
33915                       ,p_level    => C_LEVEL_ERROR
33916                       ,p_module   => l_log_module);
33917         END IF;
33918       END IF;
33919    END IF;
33920    --
33921    --
33922    ------------------------------------------------------------------------------------------------
33923    -- 4219869 Business Flow
33924    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
33925    -- Prior Entry.  Currently, the following code is always generated.
33926    ------------------------------------------------------------------------------------------------
33927    XLA_AE_LINES_PKG.ValidateCurrentLine;
33928 
33929    ------------------------------------------------------------------------------------
33930    -- 4219869 Business Flow
33931    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
33932    ------------------------------------------------------------------------------------
33933    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
33934 
33935    ----------------------------------------------------------------------------------
33936    -- 4219869 Business Flow
33937    -- Update journal entry status -- Need to generate this within IF <condition>
33938    ----------------------------------------------------------------------------------
33939    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
33940          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
33941          ,p_balance_type_code => l_balance_type_code
33942          );
33943 
33944    -------------------------------------------------------------------------------------------
33945    -- 4262811 - Generate the Accrual Reversal lines
33946    -------------------------------------------------------------------------------------------
33947    BEGIN
33948       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
33949                               (g_array_event(p_event_id).array_value_num('header_index'));
33950       IF l_acc_rev_flag IS NULL THEN
33951          l_acc_rev_flag := 'N';
33952       END IF;
33953    EXCEPTION
33954       WHEN OTHERS THEN
33955          l_acc_rev_flag := 'N';
33956    END;
33957    --
33958    IF (l_acc_rev_flag = 'Y') THEN
33959 
33960        -- 4645092  ------------------------------------------------------------------------------
33961        -- To allow MPA report to determine if it should generate report process
33962        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
33963        ------------------------------------------------------------------------------------------
33964 
33965        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
33966        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
33967    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
33968    -- call ADRs
33969    -- Bug 4922099
33970    --
33971    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
33972         (NVL(l_actual_upg_option, 'N') = 'O') OR
33973         (NVL(l_enc_upg_option, 'N') = 'O')
33974       )
33975    THEN
33976    NULL;
33977    --
33978    --
33979    
33980   l_ccid := AcctDerRule_32(
33981            p_application_id           => p_application_id
33982          , p_ae_header_id             => l_ae_header_id 
33983 , p_source_4 => p_source_4
33984          , x_transaction_coa_id       => l_adr_transaction_coa_id
33985          , x_accounting_coa_id        => l_adr_accounting_coa_id
33986          , x_value_type_code          => l_adr_value_type_code
33987          , p_side                     => 'NA'
33988    );
33989 
33990    xla_ae_lines_pkg.set_ccid(
33991     p_code_combination_id          => l_ccid
33992   , p_value_type_code              => l_adr_value_type_code
33993   , p_transaction_coa_id           => l_adr_transaction_coa_id
33994   , p_accounting_coa_id            => l_adr_accounting_coa_id
33995   , p_adr_code                     => 'TRX_DIST_CCID'
33999   , p_component_type_code          => l_component_type_code
33996   , p_adr_type_code                => 'S'
33997   , p_component_type               => l_component_type
33998   , p_component_code               => l_component_code
34000   , p_component_appl_id            => l_component_appl_id
34001   , p_amb_context_code             => l_amb_context_code
34002   , p_side                         => 'NA'
34003   );
34004 
34005 
34006    --
34007    --
34008    END IF;
34009 
34010        --
34011        -- Update the line information that should be overwritten
34012        --
34013        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
34014                                          p_header_num   => 1);
34015        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
34016 
34017        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
34018 
34019        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
34020           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
34021        END IF;
34022 
34023       --
34024       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
34025       --
34026       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
34027           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
34028       ELSE
34029           ---------------------------------------------------------------------------------------------------
34030           -- 4262811a Switch Sign
34031           ---------------------------------------------------------------------------------------------------
34032           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
34033           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
34034                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
34035           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
34036                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
34037           -- 5132302
34038           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
34039                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
34040 
34041       END IF;
34042 
34043       -- 4955764
34044       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
34045       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
34046 
34047 
34048       XLA_AE_LINES_PKG.ValidateCurrentLine;
34049       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
34050 
34051       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
34052                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
34053                ,p_balance_type_code => l_balance_type_code);
34054 
34055    END IF;
34056 
34057    -----------------------------------------------------------------------------------------
34058    -- 4262811 Multiperiod Accounting
34059    -----------------------------------------------------------------------------------------
34060      -- No MPA option is assigned.
34061 
34062 
34063 END IF;
34064 END IF;
34065 --
34066 
34067 --
34068 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
34069    trace
34070       (p_msg      => 'END of AcctLineType_78'
34071       ,p_level    => C_LEVEL_PROCEDURE
34072       ,p_module   => l_log_module);
34073 END IF;
34074 --
34075 EXCEPTION
34076   WHEN xla_exceptions_pkg.application_exception THEN
34077       RAISE;
34078   WHEN OTHERS THEN
34079        xla_exceptions_pkg.raise_message
34080            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_78');
34081 END AcctLineType_78;
34082 --
34083 
34084 ---------------------------------------
34085 --
34086 -- PRIVATE FUNCTION
34087 --         AcctLineType_79
34088 --
34089 ---------------------------------------
34090 PROCEDURE AcctLineType_79 (
34091   p_application_id        IN NUMBER
34092  ,p_event_id              IN NUMBER
34093  ,p_calculate_acctd_flag  IN VARCHAR2
34094  ,p_calculate_g_l_flag    IN VARCHAR2
34095  ,p_actual_flag           IN OUT VARCHAR2
34096  ,p_balance_type_code     OUT VARCHAR2
34097  ,p_gain_or_loss_ref      OUT VARCHAR2
34098  
34099 --Transaction Distribution GL Account
34100  , p_source_4            IN NUMBER
34101 --Bill To Customer Account Identifier
34102  , p_source_30            IN NUMBER
34103 --Bill To Customer Site Use Identifier
34104  , p_source_31            IN NUMBER
34105 --SLA Party Type
34106  , p_source_32            IN VARCHAR2
34107 --Transaction Distribution Account Class
34108  , p_source_33            IN VARCHAR2
34109 --Transaction Distribution Identifier
34110  , p_source_34            IN NUMBER
34111 --Transaction Distribution Type
34112  , p_source_35            IN VARCHAR2
34113 --Transaction Distribution Entered Amount
34114  , p_source_36            IN NUMBER
34115 --Transaction Currency Code
34116  , p_source_37            IN VARCHAR2
34117 --Transaction Exchange Date
34121 --Transaction Exchange Rate Type
34118  , p_source_38            IN DATE
34119 --Transaction Exchange Rate
34120  , p_source_39            IN NUMBER
34122  , p_source_40            IN VARCHAR2
34123 --Transaction Accounting Amount
34124  , p_source_41            IN NUMBER
34125 --Transaction Tax Line Identifier
34126  , p_source_55            IN NUMBER
34127 )
34128 IS
34129 
34130 l_component_type              VARCHAR2(80);
34131 l_component_code              VARCHAR2(30);
34132 l_component_type_code         VARCHAR2(1);
34133 l_component_appl_id           INTEGER;
34134 l_amb_context_code            VARCHAR2(30);
34135 l_entity_code                 VARCHAR2(30);
34136 l_event_class_code            VARCHAR2(30);
34137 l_ae_header_id                NUMBER;
34138 l_event_type_code             VARCHAR2(30);
34139 l_line_definition_code        VARCHAR2(30);
34140 l_line_definition_owner_code  VARCHAR2(1);
34141 --
34142 -- adr variables
34143 l_segment                     VARCHAR2(30);
34144 l_ccid                        NUMBER;
34145 l_adr_transaction_coa_id      NUMBER;
34146 l_adr_accounting_coa_id       NUMBER;
34147 l_adr_flexfield_segment_code  VARCHAR2(30);
34148 l_adr_flex_value_set_id       NUMBER;
34149 l_adr_value_type_code         VARCHAR2(30);
34150 l_adr_value_combination_id    NUMBER;
34151 l_adr_value_segment_code      VARCHAR2(30);
34152 
34153 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
34154 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
34155 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
34156 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
34157 
34158 -- 4262811 Variables ------------------------------------------------------------------------------------------
34159 l_entered_amt_idx             NUMBER;
34160 l_accted_amt_idx              NUMBER;
34161 l_acc_rev_flag                VARCHAR2(1);
34162 l_accrual_line_num            NUMBER;
34163 l_tmp_amt                     NUMBER;
34164 l_acc_rev_natural_side_code   VARCHAR2(1);
34165 
34166 l_num_entries                 NUMBER;
34167 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
34168 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
34169 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
34170 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
34171 l_recog_line_1                NUMBER;
34172 l_recog_line_2                NUMBER;
34173 
34174 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
34175 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
34176 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
34177 
34178 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
34179 
34180 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
34181 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
34182 
34183 ---------------------------------------------------------------------------------------------------------------
34184 
34185 
34186 --
34187 -- bulk performance
34188 --
34189 l_balance_type_code           VARCHAR2(1);
34190 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
34191 l_log_module                  VARCHAR2(240);
34192 
34193 --
34194 -- Upgrade strategy
34195 --
34196 l_actual_upg_option           VARCHAR2(1);
34197 l_enc_upg_option           VARCHAR2(1);
34198 
34199 --
34200 BEGIN
34201 --
34202 IF g_log_enabled THEN
34203       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_79';
34204 END IF;
34205 --
34206 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
34207 
34208       trace
34209          (p_msg      => 'BEGIN of AcctLineType_79'
34210          ,p_level    => C_LEVEL_PROCEDURE
34211          ,p_module   => l_log_module);
34212 
34213 END IF;
34214 --
34215 l_component_type             := 'AMB_JLT';
34216 l_component_code             := 'INV_CHARGES';
34217 l_component_type_code        := 'S';
34218 l_component_appl_id          :=  222;
34219 l_amb_context_code           := 'DEFAULT';
34220 l_entity_code                := 'TRANSACTIONS';
34221 l_event_class_code           := 'INVOICE';
34222 l_event_type_code            := 'INVOICE_ALL';
34223 l_line_definition_owner_code := 'S';
34224 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
34225 --
34226 l_balance_type_code          := 'A';
34227 l_segment                     := NULL;
34228 l_ccid                        := NULL;
34229 l_adr_transaction_coa_id      := NULL;
34230 l_adr_accounting_coa_id       := NULL;
34231 l_adr_flexfield_segment_code  := NULL;
34232 l_adr_flex_value_set_id       := NULL;
34233 l_adr_value_type_code         := NULL;
34234 l_adr_value_combination_id    := NULL;
34235 l_adr_value_segment_code      := NULL;
34236 
34237 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
34238 l_bflow_class_code           := '';    -- 4219869 Business Flow
34239 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
34240 l_budgetary_control_flag     := 'N';
34241 
34242 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
34243 l_bflow_applied_to_amt       := NULL; -- 5132302
34244 l_entered_amt_idx            := NULL;          -- 4262811
34245 l_accted_amt_idx             := NULL;          -- 4262811
34246 l_acc_rev_flag               := NULL;          -- 4262811
34247 l_accrual_line_num           := NULL;          -- 4262811
34251 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
34248 l_tmp_amt                    := NULL;          -- 4262811
34249 --
34250  
34252     l_balance_type_code <> 'B' THEN
34253 IF NVL(p_source_33,'
34254 ') =  'CHARGES'
34255  THEN 
34256 
34257    --
34258    XLA_AE_LINES_PKG.SetNewLine;
34259 
34260    p_balance_type_code          := l_balance_type_code;
34261    -- set the flag so later we will know whether the gain loss line needs to be created
34262    
34263    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
34264      p_actual_flag :='A';
34265    END IF;
34266 
34267    --
34268    -- bulk performance
34269    --
34270    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
34271                                       p_header_num   => 0); -- 4262811
34272    --
34273    -- set accounting line options
34274    --
34275    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
34276            p_natural_side_code          => 'C'
34277          , p_gain_or_loss_flag          => 'N'
34278          , p_gl_transfer_mode_code      => 'S'
34279          , p_acct_entry_type_code       => 'A'
34280          , p_switch_side_flag           => 'Y'
34281          , p_merge_duplicate_code       => 'A'
34282          );
34283    --
34284    l_acc_rev_natural_side_code := 'D';  -- 4262811
34285    -- 
34286    --
34287    -- set accounting line type info
34288    --
34289    xla_ae_lines_pkg.SetAcctLineType
34290       (p_component_type             => l_component_type
34291       ,p_event_type_code            => l_event_type_code
34292       ,p_line_definition_owner_code => l_line_definition_owner_code
34293       ,p_line_definition_code       => l_line_definition_code
34294       ,p_accounting_line_code       => l_component_code
34295       ,p_accounting_line_type_code  => l_component_type_code
34296       ,p_accounting_line_appl_id    => l_component_appl_id
34297       ,p_amb_context_code           => l_amb_context_code
34298       ,p_entity_code                => l_entity_code
34299       ,p_event_class_code           => l_event_class_code);
34300    --
34301    -- set accounting class
34302    --
34303    xla_ae_lines_pkg.SetAcctClass(
34304            p_accounting_class_code  => 'CHARGES'
34305          , p_ae_header_id           => l_ae_header_id
34306          );
34307 
34308    --
34309    -- set rounding class
34310    --
34311    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
34312                       'RECEIVABLE';
34313 
34314    --
34315    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
34316    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
34317    --
34318    -- bulk performance
34319    --
34320    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
34321 
34322    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
34323       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
34324 
34325    -- 4955764
34326    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
34327       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
34328 
34329    -- 4458381 Public Sector Enh
34330    
34331    --
34332    -- set accounting attributes for the line type
34333    --
34334    l_entered_amt_idx := 3;
34335    l_accted_amt_idx  := 8;
34336    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
34337    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
34338    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
34339    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
34340    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
34341    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
34342    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
34343    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
34344    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
34345    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
34346    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
34347    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
34348    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
34349    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
34350    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
34351    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
34352    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
34353    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
34354    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
34355    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
34356    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
34357    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
34358    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
34359    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
34360    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
34361 
34362    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
34363    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
34364 
34365    ---------------------------------------------------------------------------------------------------------------
34369 
34366    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
34367    ---------------------------------------------------------------------------------------------------------------
34368    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
34370    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
34371    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
34372 
34373    IF xla_accounting_cache_pkg.GetValueChar
34374          (p_source_code         => 'LEDGER_CATEGORY_CODE'
34375          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
34376    AND l_bflow_method_code = 'PRIOR_ENTRY'
34377 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
34378    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
34379          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
34380        )
34381    THEN
34382          xla_ae_lines_pkg.BflowUpgEntry
34383            (p_business_method_code    => l_bflow_method_code
34384            ,p_business_class_code     => l_bflow_class_code
34385            ,p_balance_type            => l_balance_type_code);
34386    ELSE
34387       NULL;
34388 -- No business flow processing for business flow method of NONE.
34389    END IF;
34390 
34391    --
34392    -- call analytical criteria
34393    --
34394    
34395    --
34396    -- call description
34397    --
34398    -- No description or it is inherited.
34399    --
34400    -- call ADRs
34401    -- Bug 4922099
34402    --
34403    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
34404         (NVL(l_actual_upg_option, 'N') = 'O') OR
34405         (NVL(l_enc_upg_option, 'N') = 'O')
34406       )
34407    THEN
34408    NULL;
34409    --
34410    --
34411    
34412   l_ccid := AcctDerRule_32(
34413            p_application_id           => p_application_id
34414          , p_ae_header_id             => l_ae_header_id 
34415 , p_source_4 => p_source_4
34416          , x_transaction_coa_id       => l_adr_transaction_coa_id
34417          , x_accounting_coa_id        => l_adr_accounting_coa_id
34418          , x_value_type_code          => l_adr_value_type_code
34419          , p_side                     => 'NA'
34420    );
34421 
34422    xla_ae_lines_pkg.set_ccid(
34423     p_code_combination_id          => l_ccid
34424   , p_value_type_code              => l_adr_value_type_code
34425   , p_transaction_coa_id           => l_adr_transaction_coa_id
34426   , p_accounting_coa_id            => l_adr_accounting_coa_id
34427   , p_adr_code                     => 'TRX_DIST_CCID'
34428   , p_adr_type_code                => 'S'
34429   , p_component_type               => l_component_type
34430   , p_component_code               => l_component_code
34431   , p_component_type_code          => l_component_type_code
34432   , p_component_appl_id            => l_component_appl_id
34433   , p_amb_context_code             => l_amb_context_code
34434   , p_side                         => 'NA'
34435   );
34436 
34437 
34438    --
34439    --
34440    END IF;
34441    --
34442    -- Bug 4922099
34443    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
34444           (NVL(l_enc_upg_option, 'N') = 'O')
34445         ) AND
34446         (l_bflow_method_code = 'PRIOR_ENTRY')
34447       )
34448    THEN
34449       IF
34450       --
34451       1 = 2
34452       --
34453       THEN
34454       xla_accounting_err_pkg.build_message
34455                                     (p_appli_s_name            => 'XLA'
34456                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
34457                                     ,p_token_1                 => 'LINE_NUMBER'
34458                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
34459                                     ,p_token_2                 => 'LINE_TYPE_NAME'
34460                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
34461                                                                              l_component_type
34462                                                                             ,l_component_code
34463                                                                             ,l_component_type_code
34464                                                                             ,l_component_appl_id
34465                                                                             ,l_amb_context_code
34466                                                                             ,l_entity_code
34467                                                                             ,l_event_class_code
34468                                                                            )
34469                                     ,p_token_3                 => 'OWNER'
34470                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
34471                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
34472                                                                           ,p_lookup_code    => l_component_type_code
34473                                                                          )
34474                                     ,p_token_4                 => 'PRODUCT_NAME'
34478                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
34475                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
34476                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
34477                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
34479                                     ,p_ae_header_id            =>  NULL
34480                                        );
34481 
34482         IF (C_LEVEL_ERROR>= g_log_level) THEN
34483                  trace
34484                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
34485                       ,p_level    => C_LEVEL_ERROR
34486                       ,p_module   => l_log_module);
34487         END IF;
34488       END IF;
34489    END IF;
34490    --
34491    --
34492    ------------------------------------------------------------------------------------------------
34493    -- 4219869 Business Flow
34494    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
34495    -- Prior Entry.  Currently, the following code is always generated.
34496    ------------------------------------------------------------------------------------------------
34497    XLA_AE_LINES_PKG.ValidateCurrentLine;
34498 
34499    ------------------------------------------------------------------------------------
34500    -- 4219869 Business Flow
34501    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
34502    ------------------------------------------------------------------------------------
34503    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
34504 
34505    ----------------------------------------------------------------------------------
34506    -- 4219869 Business Flow
34507    -- Update journal entry status -- Need to generate this within IF <condition>
34508    ----------------------------------------------------------------------------------
34509    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
34510          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
34511          ,p_balance_type_code => l_balance_type_code
34512          );
34513 
34514    -------------------------------------------------------------------------------------------
34515    -- 4262811 - Generate the Accrual Reversal lines
34516    -------------------------------------------------------------------------------------------
34517    BEGIN
34518       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
34519                               (g_array_event(p_event_id).array_value_num('header_index'));
34520       IF l_acc_rev_flag IS NULL THEN
34521          l_acc_rev_flag := 'N';
34522       END IF;
34523    EXCEPTION
34524       WHEN OTHERS THEN
34525          l_acc_rev_flag := 'N';
34526    END;
34527    --
34528    IF (l_acc_rev_flag = 'Y') THEN
34529 
34530        -- 4645092  ------------------------------------------------------------------------------
34531        -- To allow MPA report to determine if it should generate report process
34532        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
34533        ------------------------------------------------------------------------------------------
34534 
34535        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
34536        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
34537    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
34538    -- call ADRs
34539    -- Bug 4922099
34540    --
34541    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
34542         (NVL(l_actual_upg_option, 'N') = 'O') OR
34543         (NVL(l_enc_upg_option, 'N') = 'O')
34544       )
34545    THEN
34546    NULL;
34547    --
34548    --
34549    
34550   l_ccid := AcctDerRule_32(
34551            p_application_id           => p_application_id
34552          , p_ae_header_id             => l_ae_header_id 
34553 , p_source_4 => p_source_4
34554          , x_transaction_coa_id       => l_adr_transaction_coa_id
34555          , x_accounting_coa_id        => l_adr_accounting_coa_id
34556          , x_value_type_code          => l_adr_value_type_code
34557          , p_side                     => 'NA'
34558    );
34559 
34560    xla_ae_lines_pkg.set_ccid(
34561     p_code_combination_id          => l_ccid
34562   , p_value_type_code              => l_adr_value_type_code
34563   , p_transaction_coa_id           => l_adr_transaction_coa_id
34564   , p_accounting_coa_id            => l_adr_accounting_coa_id
34565   , p_adr_code                     => 'TRX_DIST_CCID'
34566   , p_adr_type_code                => 'S'
34567   , p_component_type               => l_component_type
34568   , p_component_code               => l_component_code
34569   , p_component_type_code          => l_component_type_code
34570   , p_component_appl_id            => l_component_appl_id
34571   , p_amb_context_code             => l_amb_context_code
34572   , p_side                         => 'NA'
34573   );
34574 
34575 
34576    --
34577    --
34578    END IF;
34579 
34580        --
34581        -- Update the line information that should be overwritten
34582        --
34583        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
34584                                          p_header_num   => 1);
34588 
34585        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
34586 
34587        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
34589        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
34590           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
34591        END IF;
34592 
34593       --
34594       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
34595       --
34596       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
34597           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
34598       ELSE
34599           ---------------------------------------------------------------------------------------------------
34600           -- 4262811a Switch Sign
34601           ---------------------------------------------------------------------------------------------------
34602           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
34603           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
34604                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
34605           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
34606                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
34607           -- 5132302
34608           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
34609                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
34610 
34611       END IF;
34612 
34613       -- 4955764
34614       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
34615       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
34616 
34617 
34618       XLA_AE_LINES_PKG.ValidateCurrentLine;
34619       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
34620 
34621       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
34622                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
34623                ,p_balance_type_code => l_balance_type_code);
34624 
34625    END IF;
34626 
34627    -----------------------------------------------------------------------------------------
34628    -- 4262811 Multiperiod Accounting
34629    -----------------------------------------------------------------------------------------
34630      -- No MPA option is assigned.
34631 
34632 
34633 END IF;
34634 END IF;
34635 --
34636 
34637 --
34638 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
34639    trace
34640       (p_msg      => 'END of AcctLineType_79'
34641       ,p_level    => C_LEVEL_PROCEDURE
34642       ,p_module   => l_log_module);
34643 END IF;
34644 --
34645 EXCEPTION
34646   WHEN xla_exceptions_pkg.application_exception THEN
34647       RAISE;
34648   WHEN OTHERS THEN
34649        xla_exceptions_pkg.raise_message
34650            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_79');
34651 END AcctLineType_79;
34652 --
34653 
34654 ---------------------------------------
34655 --
34656 -- PRIVATE FUNCTION
34657 --         AcctLineType_80
34658 --
34659 ---------------------------------------
34660 PROCEDURE AcctLineType_80 (
34661   p_application_id        IN NUMBER
34662  ,p_event_id              IN NUMBER
34663  ,p_calculate_acctd_flag  IN VARCHAR2
34664  ,p_calculate_g_l_flag    IN VARCHAR2
34665  ,p_actual_flag           IN OUT VARCHAR2
34666  ,p_balance_type_code     OUT VARCHAR2
34667  ,p_gain_or_loss_ref      OUT VARCHAR2
34668  
34669 --Transaction Distribution GL Account
34670  , p_source_4            IN NUMBER
34671 --Bill To Customer Account Identifier
34672  , p_source_30            IN NUMBER
34673 --Bill To Customer Site Use Identifier
34674  , p_source_31            IN NUMBER
34675 --SLA Party Type
34676  , p_source_32            IN VARCHAR2
34677 --Transaction Distribution Account Class
34678  , p_source_33            IN VARCHAR2
34679 --Transaction Distribution Identifier
34680  , p_source_34            IN NUMBER
34681 --Transaction Distribution Type
34682  , p_source_35            IN VARCHAR2
34683 --Transaction Distribution Entered Amount
34684  , p_source_36            IN NUMBER
34685 --Transaction Currency Code
34686  , p_source_37            IN VARCHAR2
34687 --Transaction Exchange Date
34688  , p_source_38            IN DATE
34689 --Transaction Exchange Rate
34690  , p_source_39            IN NUMBER
34691 --Transaction Exchange Rate Type
34692  , p_source_40            IN VARCHAR2
34693 --Transaction Accounting Amount
34694  , p_source_41            IN NUMBER
34695 --Transaction Tax Line Identifier
34696  , p_source_55            IN NUMBER
34697 )
34698 IS
34699 
34700 l_component_type              VARCHAR2(80);
34701 l_component_code              VARCHAR2(30);
34702 l_component_type_code         VARCHAR2(1);
34703 l_component_appl_id           INTEGER;
34704 l_amb_context_code            VARCHAR2(30);
34705 l_entity_code                 VARCHAR2(30);
34706 l_event_class_code            VARCHAR2(30);
34707 l_ae_header_id                NUMBER;
34708 l_event_type_code             VARCHAR2(30);
34712 -- adr variables
34709 l_line_definition_code        VARCHAR2(30);
34710 l_line_definition_owner_code  VARCHAR2(1);
34711 --
34713 l_segment                     VARCHAR2(30);
34714 l_ccid                        NUMBER;
34715 l_adr_transaction_coa_id      NUMBER;
34716 l_adr_accounting_coa_id       NUMBER;
34717 l_adr_flexfield_segment_code  VARCHAR2(30);
34718 l_adr_flex_value_set_id       NUMBER;
34719 l_adr_value_type_code         VARCHAR2(30);
34720 l_adr_value_combination_id    NUMBER;
34721 l_adr_value_segment_code      VARCHAR2(30);
34722 
34723 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
34724 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
34725 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
34726 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
34727 
34728 -- 4262811 Variables ------------------------------------------------------------------------------------------
34729 l_entered_amt_idx             NUMBER;
34730 l_accted_amt_idx              NUMBER;
34731 l_acc_rev_flag                VARCHAR2(1);
34732 l_accrual_line_num            NUMBER;
34733 l_tmp_amt                     NUMBER;
34734 l_acc_rev_natural_side_code   VARCHAR2(1);
34735 
34736 l_num_entries                 NUMBER;
34737 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
34738 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
34739 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
34740 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
34741 l_recog_line_1                NUMBER;
34742 l_recog_line_2                NUMBER;
34743 
34744 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
34745 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
34746 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
34747 
34748 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
34749 
34750 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
34751 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
34752 
34753 ---------------------------------------------------------------------------------------------------------------
34754 
34755 
34756 --
34757 -- bulk performance
34758 --
34759 l_balance_type_code           VARCHAR2(1);
34760 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
34761 l_log_module                  VARCHAR2(240);
34762 
34763 --
34764 -- Upgrade strategy
34765 --
34766 l_actual_upg_option           VARCHAR2(1);
34767 l_enc_upg_option           VARCHAR2(1);
34768 
34769 --
34770 BEGIN
34771 --
34772 IF g_log_enabled THEN
34773       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_80';
34774 END IF;
34775 --
34776 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
34777 
34778       trace
34779          (p_msg      => 'BEGIN of AcctLineType_80'
34780          ,p_level    => C_LEVEL_PROCEDURE
34781          ,p_module   => l_log_module);
34782 
34783 END IF;
34784 --
34785 l_component_type             := 'AMB_JLT';
34786 l_component_code             := 'INV_FREIGHT';
34787 l_component_type_code        := 'S';
34788 l_component_appl_id          :=  222;
34789 l_amb_context_code           := 'DEFAULT';
34790 l_entity_code                := 'TRANSACTIONS';
34791 l_event_class_code           := 'INVOICE';
34792 l_event_type_code            := 'INVOICE_ALL';
34793 l_line_definition_owner_code := 'S';
34794 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
34795 --
34796 l_balance_type_code          := 'A';
34797 l_segment                     := NULL;
34798 l_ccid                        := NULL;
34799 l_adr_transaction_coa_id      := NULL;
34800 l_adr_accounting_coa_id       := NULL;
34801 l_adr_flexfield_segment_code  := NULL;
34802 l_adr_flex_value_set_id       := NULL;
34803 l_adr_value_type_code         := NULL;
34804 l_adr_value_combination_id    := NULL;
34805 l_adr_value_segment_code      := NULL;
34806 
34807 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
34808 l_bflow_class_code           := 'FREIGHT';    -- 4219869 Business Flow
34809 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
34810 l_budgetary_control_flag     := 'N';
34811 
34812 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
34813 l_bflow_applied_to_amt       := NULL; -- 5132302
34814 l_entered_amt_idx            := NULL;          -- 4262811
34815 l_accted_amt_idx             := NULL;          -- 4262811
34816 l_acc_rev_flag               := NULL;          -- 4262811
34817 l_accrual_line_num           := NULL;          -- 4262811
34818 l_tmp_amt                    := NULL;          -- 4262811
34819 --
34820  
34821 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
34822     l_balance_type_code <> 'B' THEN
34823 IF NVL(p_source_33,'
34824 ') =  'FREIGHT'
34825  THEN 
34826 
34827    --
34828    XLA_AE_LINES_PKG.SetNewLine;
34829 
34830    p_balance_type_code          := l_balance_type_code;
34831    -- set the flag so later we will know whether the gain loss line needs to be created
34832    
34833    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
34834      p_actual_flag :='A';
34835    END IF;
34836 
34837    --
34838    -- bulk performance
34839    --
34843    -- set accounting line options
34840    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
34841                                       p_header_num   => 0); -- 4262811
34842    --
34844    --
34845    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
34846            p_natural_side_code          => 'C'
34847          , p_gain_or_loss_flag          => 'N'
34848          , p_gl_transfer_mode_code      => 'S'
34849          , p_acct_entry_type_code       => 'A'
34850          , p_switch_side_flag           => 'Y'
34851          , p_merge_duplicate_code       => 'A'
34852          );
34853    --
34854    l_acc_rev_natural_side_code := 'D';  -- 4262811
34855    -- 
34856    --
34857    -- set accounting line type info
34858    --
34859    xla_ae_lines_pkg.SetAcctLineType
34860       (p_component_type             => l_component_type
34861       ,p_event_type_code            => l_event_type_code
34862       ,p_line_definition_owner_code => l_line_definition_owner_code
34863       ,p_line_definition_code       => l_line_definition_code
34864       ,p_accounting_line_code       => l_component_code
34865       ,p_accounting_line_type_code  => l_component_type_code
34866       ,p_accounting_line_appl_id    => l_component_appl_id
34867       ,p_amb_context_code           => l_amb_context_code
34868       ,p_entity_code                => l_entity_code
34869       ,p_event_class_code           => l_event_class_code);
34870    --
34871    -- set accounting class
34872    --
34873    xla_ae_lines_pkg.SetAcctClass(
34874            p_accounting_class_code  => 'FREIGHT'
34875          , p_ae_header_id           => l_ae_header_id
34876          );
34877 
34878    --
34879    -- set rounding class
34880    --
34881    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
34882                       'RECEIVABLE';
34883 
34884    --
34885    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
34886    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
34887    --
34888    -- bulk performance
34889    --
34890    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
34891 
34892    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
34893       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
34894 
34895    -- 4955764
34896    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
34897       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
34898 
34899    -- 4458381 Public Sector Enh
34900    
34901    --
34902    -- set accounting attributes for the line type
34903    --
34904    l_entered_amt_idx := 3;
34905    l_accted_amt_idx  := 8;
34906    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
34907    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
34908    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
34909    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
34910    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
34911    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
34912    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
34913    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
34914    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
34915    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
34916    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
34917    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
34918    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
34919    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
34920    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
34921    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
34922    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
34923    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
34924    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
34925    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
34926    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
34927    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
34928    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
34929    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
34930    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
34931 
34932    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
34933    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
34934 
34935    ---------------------------------------------------------------------------------------------------------------
34936    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
34937    ---------------------------------------------------------------------------------------------------------------
34938    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
34939 
34940    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
34941    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
34942 
34943    IF xla_accounting_cache_pkg.GetValueChar
34944          (p_source_code         => 'LEDGER_CATEGORY_CODE'
34945          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
34949          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
34946    AND l_bflow_method_code = 'PRIOR_ENTRY'
34947 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
34948    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
34950        )
34951    THEN
34952          xla_ae_lines_pkg.BflowUpgEntry
34953            (p_business_method_code    => l_bflow_method_code
34954            ,p_business_class_code     => l_bflow_class_code
34955            ,p_balance_type            => l_balance_type_code);
34956    ELSE
34957       NULL;
34958 -- No business flow processing for business flow method of NONE.
34959    END IF;
34960 
34961    --
34962    -- call analytical criteria
34963    --
34964    
34965    --
34966    -- call description
34967    --
34968    -- No description or it is inherited.
34969    --
34970    -- call ADRs
34971    -- Bug 4922099
34972    --
34973    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
34974         (NVL(l_actual_upg_option, 'N') = 'O') OR
34975         (NVL(l_enc_upg_option, 'N') = 'O')
34976       )
34977    THEN
34978    NULL;
34979    --
34980    --
34981    
34982   l_ccid := AcctDerRule_32(
34983            p_application_id           => p_application_id
34984          , p_ae_header_id             => l_ae_header_id 
34985 , p_source_4 => p_source_4
34986          , x_transaction_coa_id       => l_adr_transaction_coa_id
34987          , x_accounting_coa_id        => l_adr_accounting_coa_id
34988          , x_value_type_code          => l_adr_value_type_code
34989          , p_side                     => 'NA'
34990    );
34991 
34992    xla_ae_lines_pkg.set_ccid(
34993     p_code_combination_id          => l_ccid
34994   , p_value_type_code              => l_adr_value_type_code
34995   , p_transaction_coa_id           => l_adr_transaction_coa_id
34996   , p_accounting_coa_id            => l_adr_accounting_coa_id
34997   , p_adr_code                     => 'TRX_DIST_CCID'
34998   , p_adr_type_code                => 'S'
34999   , p_component_type               => l_component_type
35000   , p_component_code               => l_component_code
35001   , p_component_type_code          => l_component_type_code
35002   , p_component_appl_id            => l_component_appl_id
35003   , p_amb_context_code             => l_amb_context_code
35004   , p_side                         => 'NA'
35005   );
35006 
35007 
35008    --
35009    --
35010    END IF;
35011    --
35012    -- Bug 4922099
35013    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
35014           (NVL(l_enc_upg_option, 'N') = 'O')
35015         ) AND
35016         (l_bflow_method_code = 'PRIOR_ENTRY')
35017       )
35018    THEN
35019       IF
35020       --
35021       1 = 2
35022       --
35023       THEN
35024       xla_accounting_err_pkg.build_message
35025                                     (p_appli_s_name            => 'XLA'
35026                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
35027                                     ,p_token_1                 => 'LINE_NUMBER'
35028                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
35029                                     ,p_token_2                 => 'LINE_TYPE_NAME'
35030                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
35031                                                                              l_component_type
35032                                                                             ,l_component_code
35033                                                                             ,l_component_type_code
35034                                                                             ,l_component_appl_id
35035                                                                             ,l_amb_context_code
35036                                                                             ,l_entity_code
35037                                                                             ,l_event_class_code
35038                                                                            )
35039                                     ,p_token_3                 => 'OWNER'
35040                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
35041                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
35042                                                                           ,p_lookup_code    => l_component_type_code
35043                                                                          )
35044                                     ,p_token_4                 => 'PRODUCT_NAME'
35045                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
35046                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
35047                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
35048                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
35049                                     ,p_ae_header_id            =>  NULL
35050                                        );
35051 
35052         IF (C_LEVEL_ERROR>= g_log_level) THEN
35053                  trace
35054                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
35058       END IF;
35055                       ,p_level    => C_LEVEL_ERROR
35056                       ,p_module   => l_log_module);
35057         END IF;
35059    END IF;
35060    --
35061    --
35062    ------------------------------------------------------------------------------------------------
35063    -- 4219869 Business Flow
35064    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
35065    -- Prior Entry.  Currently, the following code is always generated.
35066    ------------------------------------------------------------------------------------------------
35067    XLA_AE_LINES_PKG.ValidateCurrentLine;
35068 
35069    ------------------------------------------------------------------------------------
35070    -- 4219869 Business Flow
35071    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
35072    ------------------------------------------------------------------------------------
35073    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
35074 
35075    ----------------------------------------------------------------------------------
35076    -- 4219869 Business Flow
35077    -- Update journal entry status -- Need to generate this within IF <condition>
35078    ----------------------------------------------------------------------------------
35079    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
35080          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
35081          ,p_balance_type_code => l_balance_type_code
35082          );
35083 
35084    -------------------------------------------------------------------------------------------
35085    -- 4262811 - Generate the Accrual Reversal lines
35086    -------------------------------------------------------------------------------------------
35087    BEGIN
35088       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
35089                               (g_array_event(p_event_id).array_value_num('header_index'));
35090       IF l_acc_rev_flag IS NULL THEN
35091          l_acc_rev_flag := 'N';
35092       END IF;
35093    EXCEPTION
35094       WHEN OTHERS THEN
35095          l_acc_rev_flag := 'N';
35096    END;
35097    --
35098    IF (l_acc_rev_flag = 'Y') THEN
35099 
35100        -- 4645092  ------------------------------------------------------------------------------
35101        -- To allow MPA report to determine if it should generate report process
35102        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
35103        ------------------------------------------------------------------------------------------
35104 
35105        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
35106        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
35107    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
35108    -- call ADRs
35109    -- Bug 4922099
35110    --
35111    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
35112         (NVL(l_actual_upg_option, 'N') = 'O') OR
35113         (NVL(l_enc_upg_option, 'N') = 'O')
35114       )
35115    THEN
35116    NULL;
35117    --
35118    --
35119    
35120   l_ccid := AcctDerRule_32(
35121            p_application_id           => p_application_id
35122          , p_ae_header_id             => l_ae_header_id 
35123 , p_source_4 => p_source_4
35124          , x_transaction_coa_id       => l_adr_transaction_coa_id
35125          , x_accounting_coa_id        => l_adr_accounting_coa_id
35126          , x_value_type_code          => l_adr_value_type_code
35127          , p_side                     => 'NA'
35128    );
35129 
35130    xla_ae_lines_pkg.set_ccid(
35131     p_code_combination_id          => l_ccid
35132   , p_value_type_code              => l_adr_value_type_code
35133   , p_transaction_coa_id           => l_adr_transaction_coa_id
35134   , p_accounting_coa_id            => l_adr_accounting_coa_id
35135   , p_adr_code                     => 'TRX_DIST_CCID'
35136   , p_adr_type_code                => 'S'
35137   , p_component_type               => l_component_type
35138   , p_component_code               => l_component_code
35139   , p_component_type_code          => l_component_type_code
35140   , p_component_appl_id            => l_component_appl_id
35141   , p_amb_context_code             => l_amb_context_code
35142   , p_side                         => 'NA'
35143   );
35144 
35145 
35146    --
35147    --
35148    END IF;
35149 
35150        --
35151        -- Update the line information that should be overwritten
35152        --
35153        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
35154                                          p_header_num   => 1);
35155        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
35156 
35157        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
35158 
35159        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
35160           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
35161        END IF;
35162 
35163       --
35164       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
35165       --
35166       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
35170           -- 4262811a Switch Sign
35167           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
35168       ELSE
35169           ---------------------------------------------------------------------------------------------------
35171           ---------------------------------------------------------------------------------------------------
35172           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
35173           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
35174                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
35175           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
35176                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
35177           -- 5132302
35178           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
35179                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
35180 
35181       END IF;
35182 
35183       -- 4955764
35184       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
35185       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
35186 
35187 
35188       XLA_AE_LINES_PKG.ValidateCurrentLine;
35189       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
35190 
35191       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
35192                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
35193                ,p_balance_type_code => l_balance_type_code);
35194 
35195    END IF;
35196 
35197    -----------------------------------------------------------------------------------------
35198    -- 4262811 Multiperiod Accounting
35199    -----------------------------------------------------------------------------------------
35200      -- No MPA option is assigned.
35201 
35202 
35203 END IF;
35204 END IF;
35205 --
35206 
35207 --
35208 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
35209    trace
35210       (p_msg      => 'END of AcctLineType_80'
35211       ,p_level    => C_LEVEL_PROCEDURE
35212       ,p_module   => l_log_module);
35213 END IF;
35214 --
35215 EXCEPTION
35216   WHEN xla_exceptions_pkg.application_exception THEN
35217       RAISE;
35218   WHEN OTHERS THEN
35219        xla_exceptions_pkg.raise_message
35220            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_80');
35221 END AcctLineType_80;
35222 --
35223 
35224 ---------------------------------------
35225 --
35226 -- PRIVATE FUNCTION
35227 --         AcctLineType_81
35228 --
35229 ---------------------------------------
35230 PROCEDURE AcctLineType_81 (
35231   p_application_id        IN NUMBER
35232  ,p_event_id              IN NUMBER
35233  ,p_calculate_acctd_flag  IN VARCHAR2
35234  ,p_calculate_g_l_flag    IN VARCHAR2
35235  ,p_actual_flag           IN OUT VARCHAR2
35236  ,p_balance_type_code     OUT VARCHAR2
35237  ,p_gain_or_loss_ref      OUT VARCHAR2
35238  
35239 --Transaction Distribution GL Account
35240  , p_source_4            IN NUMBER
35241 --Bill To Customer Account Identifier
35242  , p_source_30            IN NUMBER
35243 --Bill To Customer Site Use Identifier
35244  , p_source_31            IN NUMBER
35245 --SLA Party Type
35246  , p_source_32            IN VARCHAR2
35247 --Transaction Distribution Account Class
35248  , p_source_33            IN VARCHAR2
35249 --Transaction Distribution Identifier
35250  , p_source_34            IN NUMBER
35251 --Transaction Distribution Type
35252  , p_source_35            IN VARCHAR2
35253 --Transaction Distribution Entered Amount
35254  , p_source_36            IN NUMBER
35255 --Transaction Currency Code
35256  , p_source_37            IN VARCHAR2
35257 --Transaction Exchange Date
35258  , p_source_38            IN DATE
35259 --Transaction Exchange Rate
35260  , p_source_39            IN NUMBER
35261 --Transaction Exchange Rate Type
35262  , p_source_40            IN VARCHAR2
35263 --Transaction Accounting Amount
35264  , p_source_41            IN NUMBER
35265 --Transaction Tax Line Identifier
35266  , p_source_55            IN NUMBER
35267 --Rounding Correction Flag
35268  , p_source_66            IN VARCHAR2
35269 )
35270 IS
35271 
35272 l_component_type              VARCHAR2(80);
35273 l_component_code              VARCHAR2(30);
35274 l_component_type_code         VARCHAR2(1);
35275 l_component_appl_id           INTEGER;
35276 l_amb_context_code            VARCHAR2(30);
35277 l_entity_code                 VARCHAR2(30);
35278 l_event_class_code            VARCHAR2(30);
35279 l_ae_header_id                NUMBER;
35280 l_event_type_code             VARCHAR2(30);
35281 l_line_definition_code        VARCHAR2(30);
35282 l_line_definition_owner_code  VARCHAR2(1);
35283 --
35284 -- adr variables
35285 l_segment                     VARCHAR2(30);
35286 l_ccid                        NUMBER;
35287 l_adr_transaction_coa_id      NUMBER;
35288 l_adr_accounting_coa_id       NUMBER;
35289 l_adr_flexfield_segment_code  VARCHAR2(30);
35290 l_adr_flex_value_set_id       NUMBER;
35291 l_adr_value_type_code         VARCHAR2(30);
35292 l_adr_value_combination_id    NUMBER;
35293 l_adr_value_segment_code      VARCHAR2(30);
35294 
35298 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
35295 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
35296 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
35297 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
35299 
35300 -- 4262811 Variables ------------------------------------------------------------------------------------------
35301 l_entered_amt_idx             NUMBER;
35302 l_accted_amt_idx              NUMBER;
35303 l_acc_rev_flag                VARCHAR2(1);
35304 l_accrual_line_num            NUMBER;
35305 l_tmp_amt                     NUMBER;
35306 l_acc_rev_natural_side_code   VARCHAR2(1);
35307 
35308 l_num_entries                 NUMBER;
35309 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
35310 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
35311 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
35312 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
35313 l_recog_line_1                NUMBER;
35314 l_recog_line_2                NUMBER;
35315 
35316 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
35317 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
35318 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
35319 
35320 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
35321 
35322 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
35323 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
35324 
35325 ---------------------------------------------------------------------------------------------------------------
35326 
35327 
35328 --
35329 -- bulk performance
35330 --
35331 l_balance_type_code           VARCHAR2(1);
35332 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
35333 l_log_module                  VARCHAR2(240);
35334 
35335 --
35336 -- Upgrade strategy
35337 --
35338 l_actual_upg_option           VARCHAR2(1);
35339 l_enc_upg_option           VARCHAR2(1);
35340 
35341 --
35342 BEGIN
35343 --
35344 IF g_log_enabled THEN
35345       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_81';
35346 END IF;
35347 --
35348 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
35349 
35350       trace
35351          (p_msg      => 'BEGIN of AcctLineType_81'
35352          ,p_level    => C_LEVEL_PROCEDURE
35353          ,p_module   => l_log_module);
35354 
35355 END IF;
35356 --
35357 l_component_type             := 'AMB_JLT';
35358 l_component_code             := 'INV_REV';
35359 l_component_type_code        := 'S';
35360 l_component_appl_id          :=  222;
35361 l_amb_context_code           := 'DEFAULT';
35362 l_entity_code                := 'TRANSACTIONS';
35363 l_event_class_code           := 'INVOICE';
35364 l_event_type_code            := 'INVOICE_ALL';
35365 l_line_definition_owner_code := 'S';
35366 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
35367 --
35368 l_balance_type_code          := 'A';
35369 l_segment                     := NULL;
35370 l_ccid                        := NULL;
35371 l_adr_transaction_coa_id      := NULL;
35372 l_adr_accounting_coa_id       := NULL;
35373 l_adr_flexfield_segment_code  := NULL;
35374 l_adr_flex_value_set_id       := NULL;
35375 l_adr_value_type_code         := NULL;
35376 l_adr_value_combination_id    := NULL;
35377 l_adr_value_segment_code      := NULL;
35378 
35379 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
35380 l_bflow_class_code           := 'REVENUE';    -- 4219869 Business Flow
35381 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
35382 l_budgetary_control_flag     := 'N';
35383 
35384 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
35385 l_bflow_applied_to_amt       := NULL; -- 5132302
35386 l_entered_amt_idx            := NULL;          -- 4262811
35387 l_accted_amt_idx             := NULL;          -- 4262811
35388 l_acc_rev_flag               := NULL;          -- 4262811
35389 l_accrual_line_num           := NULL;          -- 4262811
35390 l_tmp_amt                    := NULL;          -- 4262811
35391 --
35392  
35393 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
35394     l_balance_type_code <> 'B' THEN
35395 IF NVL(p_source_33,'
35396 ') =  'REV' AND 
35397 p_source_66 IS NULL 
35398  THEN 
35399 
35400    --
35401    XLA_AE_LINES_PKG.SetNewLine;
35402 
35403    p_balance_type_code          := l_balance_type_code;
35404    -- set the flag so later we will know whether the gain loss line needs to be created
35405    
35406    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
35407      p_actual_flag :='A';
35408    END IF;
35409 
35410    --
35411    -- bulk performance
35412    --
35413    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
35414                                       p_header_num   => 0); -- 4262811
35415    --
35416    -- set accounting line options
35417    --
35418    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
35419            p_natural_side_code          => 'C'
35420          , p_gain_or_loss_flag          => 'N'
35421          , p_gl_transfer_mode_code      => 'S'
35422          , p_acct_entry_type_code       => 'A'
35423          , p_switch_side_flag           => 'Y'
35427    l_acc_rev_natural_side_code := 'D';  -- 4262811
35424          , p_merge_duplicate_code       => 'A'
35425          );
35426    --
35428    -- 
35429    --
35430    -- set accounting line type info
35431    --
35432    xla_ae_lines_pkg.SetAcctLineType
35433       (p_component_type             => l_component_type
35434       ,p_event_type_code            => l_event_type_code
35435       ,p_line_definition_owner_code => l_line_definition_owner_code
35436       ,p_line_definition_code       => l_line_definition_code
35437       ,p_accounting_line_code       => l_component_code
35438       ,p_accounting_line_type_code  => l_component_type_code
35439       ,p_accounting_line_appl_id    => l_component_appl_id
35440       ,p_amb_context_code           => l_amb_context_code
35441       ,p_entity_code                => l_entity_code
35442       ,p_event_class_code           => l_event_class_code);
35443    --
35444    -- set accounting class
35445    --
35446    xla_ae_lines_pkg.SetAcctClass(
35447            p_accounting_class_code  => 'REVENUE'
35448          , p_ae_header_id           => l_ae_header_id
35449          );
35450 
35451    --
35452    -- set rounding class
35453    --
35454    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
35455                       'RECEIVABLE';
35456 
35457    --
35458    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
35459    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
35460    --
35461    -- bulk performance
35462    --
35463    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
35464 
35465    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
35466       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
35467 
35468    -- 4955764
35469    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
35470       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
35471 
35472    -- 4458381 Public Sector Enh
35473    
35474    --
35475    -- set accounting attributes for the line type
35476    --
35477    l_entered_amt_idx := 3;
35478    l_accted_amt_idx  := 8;
35479    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
35480    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
35481    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
35482    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
35483    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
35484    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
35485    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
35486    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
35487    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
35488    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
35489    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
35490    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
35491    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
35492    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
35493    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
35494    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
35495    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
35496    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
35497    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
35498    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
35499    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
35500    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
35501    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
35502    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
35503    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
35504 
35505    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
35506    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
35507 
35508    ---------------------------------------------------------------------------------------------------------------
35509    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
35510    ---------------------------------------------------------------------------------------------------------------
35511    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
35512 
35513    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
35514    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
35515 
35516    IF xla_accounting_cache_pkg.GetValueChar
35517          (p_source_code         => 'LEDGER_CATEGORY_CODE'
35518          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
35519    AND l_bflow_method_code = 'PRIOR_ENTRY'
35520 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
35521    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
35522          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
35523        )
35524    THEN
35525          xla_ae_lines_pkg.BflowUpgEntry
35526            (p_business_method_code    => l_bflow_method_code
35527            ,p_business_class_code     => l_bflow_class_code
35528            ,p_balance_type            => l_balance_type_code);
35529    ELSE
35533 
35530       NULL;
35531 -- No business flow processing for business flow method of NONE.
35532    END IF;
35534    --
35535    -- call analytical criteria
35536    --
35537    
35538    --
35539    -- call description
35540    --
35541    -- No description or it is inherited.
35542    --
35543    -- call ADRs
35544    -- Bug 4922099
35545    --
35546    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
35547         (NVL(l_actual_upg_option, 'N') = 'O') OR
35548         (NVL(l_enc_upg_option, 'N') = 'O')
35549       )
35550    THEN
35551    NULL;
35552    --
35553    --
35554    
35555   l_ccid := AcctDerRule_32(
35556            p_application_id           => p_application_id
35557          , p_ae_header_id             => l_ae_header_id 
35558 , p_source_4 => p_source_4
35559          , x_transaction_coa_id       => l_adr_transaction_coa_id
35560          , x_accounting_coa_id        => l_adr_accounting_coa_id
35561          , x_value_type_code          => l_adr_value_type_code
35562          , p_side                     => 'NA'
35563    );
35564 
35565    xla_ae_lines_pkg.set_ccid(
35566     p_code_combination_id          => l_ccid
35567   , p_value_type_code              => l_adr_value_type_code
35568   , p_transaction_coa_id           => l_adr_transaction_coa_id
35569   , p_accounting_coa_id            => l_adr_accounting_coa_id
35570   , p_adr_code                     => 'TRX_DIST_CCID'
35571   , p_adr_type_code                => 'S'
35572   , p_component_type               => l_component_type
35573   , p_component_code               => l_component_code
35574   , p_component_type_code          => l_component_type_code
35575   , p_component_appl_id            => l_component_appl_id
35576   , p_amb_context_code             => l_amb_context_code
35577   , p_side                         => 'NA'
35578   );
35579 
35580 
35581    --
35582    --
35583    END IF;
35584    --
35585    -- Bug 4922099
35586    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
35587           (NVL(l_enc_upg_option, 'N') = 'O')
35588         ) AND
35589         (l_bflow_method_code = 'PRIOR_ENTRY')
35590       )
35591    THEN
35592       IF
35593       --
35594       1 = 2
35595       --
35596       THEN
35597       xla_accounting_err_pkg.build_message
35598                                     (p_appli_s_name            => 'XLA'
35599                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
35600                                     ,p_token_1                 => 'LINE_NUMBER'
35601                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
35602                                     ,p_token_2                 => 'LINE_TYPE_NAME'
35603                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
35604                                                                              l_component_type
35605                                                                             ,l_component_code
35606                                                                             ,l_component_type_code
35607                                                                             ,l_component_appl_id
35608                                                                             ,l_amb_context_code
35609                                                                             ,l_entity_code
35610                                                                             ,l_event_class_code
35611                                                                            )
35612                                     ,p_token_3                 => 'OWNER'
35613                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
35614                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
35615                                                                           ,p_lookup_code    => l_component_type_code
35616                                                                          )
35617                                     ,p_token_4                 => 'PRODUCT_NAME'
35618                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
35619                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
35620                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
35621                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
35622                                     ,p_ae_header_id            =>  NULL
35623                                        );
35624 
35625         IF (C_LEVEL_ERROR>= g_log_level) THEN
35626                  trace
35627                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
35628                       ,p_level    => C_LEVEL_ERROR
35629                       ,p_module   => l_log_module);
35630         END IF;
35631       END IF;
35632    END IF;
35633    --
35634    --
35635    ------------------------------------------------------------------------------------------------
35636    -- 4219869 Business Flow
35637    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
35638    -- Prior Entry.  Currently, the following code is always generated.
35642    ------------------------------------------------------------------------------------
35639    ------------------------------------------------------------------------------------------------
35640    XLA_AE_LINES_PKG.ValidateCurrentLine;
35641 
35643    -- 4219869 Business Flow
35644    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
35645    ------------------------------------------------------------------------------------
35646    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
35647 
35648    ----------------------------------------------------------------------------------
35649    -- 4219869 Business Flow
35650    -- Update journal entry status -- Need to generate this within IF <condition>
35651    ----------------------------------------------------------------------------------
35652    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
35653          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
35654          ,p_balance_type_code => l_balance_type_code
35655          );
35656 
35657    -------------------------------------------------------------------------------------------
35658    -- 4262811 - Generate the Accrual Reversal lines
35659    -------------------------------------------------------------------------------------------
35660    BEGIN
35661       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
35662                               (g_array_event(p_event_id).array_value_num('header_index'));
35663       IF l_acc_rev_flag IS NULL THEN
35664          l_acc_rev_flag := 'N';
35665       END IF;
35666    EXCEPTION
35667       WHEN OTHERS THEN
35668          l_acc_rev_flag := 'N';
35669    END;
35670    --
35671    IF (l_acc_rev_flag = 'Y') THEN
35672 
35673        -- 4645092  ------------------------------------------------------------------------------
35674        -- To allow MPA report to determine if it should generate report process
35675        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
35676        ------------------------------------------------------------------------------------------
35677 
35678        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
35679        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
35680    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
35681    -- call ADRs
35682    -- Bug 4922099
35683    --
35684    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
35685         (NVL(l_actual_upg_option, 'N') = 'O') OR
35686         (NVL(l_enc_upg_option, 'N') = 'O')
35687       )
35688    THEN
35689    NULL;
35690    --
35691    --
35692    
35693   l_ccid := AcctDerRule_32(
35694            p_application_id           => p_application_id
35695          , p_ae_header_id             => l_ae_header_id 
35696 , p_source_4 => p_source_4
35697          , x_transaction_coa_id       => l_adr_transaction_coa_id
35698          , x_accounting_coa_id        => l_adr_accounting_coa_id
35699          , x_value_type_code          => l_adr_value_type_code
35700          , p_side                     => 'NA'
35701    );
35702 
35703    xla_ae_lines_pkg.set_ccid(
35704     p_code_combination_id          => l_ccid
35705   , p_value_type_code              => l_adr_value_type_code
35706   , p_transaction_coa_id           => l_adr_transaction_coa_id
35707   , p_accounting_coa_id            => l_adr_accounting_coa_id
35708   , p_adr_code                     => 'TRX_DIST_CCID'
35709   , p_adr_type_code                => 'S'
35710   , p_component_type               => l_component_type
35711   , p_component_code               => l_component_code
35712   , p_component_type_code          => l_component_type_code
35713   , p_component_appl_id            => l_component_appl_id
35714   , p_amb_context_code             => l_amb_context_code
35715   , p_side                         => 'NA'
35716   );
35717 
35718 
35719    --
35720    --
35721    END IF;
35722 
35723        --
35724        -- Update the line information that should be overwritten
35725        --
35726        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
35727                                          p_header_num   => 1);
35728        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
35729 
35730        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
35731 
35732        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
35733           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
35734        END IF;
35735 
35736       --
35737       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
35738       --
35739       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
35740           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
35741       ELSE
35742           ---------------------------------------------------------------------------------------------------
35743           -- 4262811a Switch Sign
35744           ---------------------------------------------------------------------------------------------------
35745           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
35746           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
35750           -- 5132302
35747                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
35748           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
35749                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
35751           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
35752                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
35753 
35754       END IF;
35755 
35756       -- 4955764
35757       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
35758       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
35759 
35760 
35761       XLA_AE_LINES_PKG.ValidateCurrentLine;
35762       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
35763 
35764       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
35765                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
35766                ,p_balance_type_code => l_balance_type_code);
35767 
35768    END IF;
35769 
35770    -----------------------------------------------------------------------------------------
35771    -- 4262811 Multiperiod Accounting
35772    -----------------------------------------------------------------------------------------
35773      -- No MPA option is assigned.
35774 
35775 
35776 END IF;
35777 END IF;
35778 --
35779 
35780 --
35781 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
35782    trace
35783       (p_msg      => 'END of AcctLineType_81'
35784       ,p_level    => C_LEVEL_PROCEDURE
35785       ,p_module   => l_log_module);
35786 END IF;
35787 --
35788 EXCEPTION
35789   WHEN xla_exceptions_pkg.application_exception THEN
35790       RAISE;
35791   WHEN OTHERS THEN
35792        xla_exceptions_pkg.raise_message
35793            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_81');
35794 END AcctLineType_81;
35795 --
35796 
35797 ---------------------------------------
35798 --
35799 -- PRIVATE FUNCTION
35800 --         AcctLineType_82
35801 --
35802 ---------------------------------------
35803 PROCEDURE AcctLineType_82 (
35804   p_application_id        IN NUMBER
35805  ,p_event_id              IN NUMBER
35806  ,p_calculate_acctd_flag  IN VARCHAR2
35807  ,p_calculate_g_l_flag    IN VARCHAR2
35808  ,p_actual_flag           IN OUT VARCHAR2
35809  ,p_balance_type_code     OUT VARCHAR2
35810  ,p_gain_or_loss_ref      OUT VARCHAR2
35811  
35812 --Transaction Distribution GL Account
35813  , p_source_4            IN NUMBER
35814 --Bill To Customer Account Identifier
35815  , p_source_30            IN NUMBER
35816 --Bill To Customer Site Use Identifier
35817  , p_source_31            IN NUMBER
35818 --SLA Party Type
35819  , p_source_32            IN VARCHAR2
35820 --Transaction Distribution Account Class
35821  , p_source_33            IN VARCHAR2
35822 --Transaction Distribution Identifier
35823  , p_source_34            IN NUMBER
35824 --Transaction Distribution Type
35825  , p_source_35            IN VARCHAR2
35826 --Transaction Distribution Entered Amount
35827  , p_source_36            IN NUMBER
35828 --Transaction Currency Code
35829  , p_source_37            IN VARCHAR2
35830 --Transaction Exchange Date
35831  , p_source_38            IN DATE
35832 --Transaction Exchange Rate
35833  , p_source_39            IN NUMBER
35834 --Transaction Exchange Rate Type
35835  , p_source_40            IN VARCHAR2
35836 --Transaction Accounting Amount
35837  , p_source_41            IN NUMBER
35838 --Transaction Tax Line Identifier
35839  , p_source_55            IN NUMBER
35840 )
35841 IS
35842 
35843 l_component_type              VARCHAR2(80);
35844 l_component_code              VARCHAR2(30);
35845 l_component_type_code         VARCHAR2(1);
35846 l_component_appl_id           INTEGER;
35847 l_amb_context_code            VARCHAR2(30);
35848 l_entity_code                 VARCHAR2(30);
35849 l_event_class_code            VARCHAR2(30);
35850 l_ae_header_id                NUMBER;
35851 l_event_type_code             VARCHAR2(30);
35852 l_line_definition_code        VARCHAR2(30);
35853 l_line_definition_owner_code  VARCHAR2(1);
35854 --
35855 -- adr variables
35856 l_segment                     VARCHAR2(30);
35857 l_ccid                        NUMBER;
35858 l_adr_transaction_coa_id      NUMBER;
35859 l_adr_accounting_coa_id       NUMBER;
35860 l_adr_flexfield_segment_code  VARCHAR2(30);
35861 l_adr_flex_value_set_id       NUMBER;
35862 l_adr_value_type_code         VARCHAR2(30);
35863 l_adr_value_combination_id    NUMBER;
35864 l_adr_value_segment_code      VARCHAR2(30);
35865 
35866 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
35867 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
35868 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
35869 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
35870 
35871 -- 4262811 Variables ------------------------------------------------------------------------------------------
35872 l_entered_amt_idx             NUMBER;
35873 l_accted_amt_idx              NUMBER;
35874 l_acc_rev_flag                VARCHAR2(1);
35875 l_accrual_line_num            NUMBER;
35876 l_tmp_amt                     NUMBER;
35877 l_acc_rev_natural_side_code   VARCHAR2(1);
35878 
35879 l_num_entries                 NUMBER;
35883 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
35880 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
35881 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
35882 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
35884 l_recog_line_1                NUMBER;
35885 l_recog_line_2                NUMBER;
35886 
35887 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
35888 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
35889 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
35890 
35891 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
35892 
35893 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
35894 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
35895 
35896 ---------------------------------------------------------------------------------------------------------------
35897 
35898 
35899 --
35900 -- bulk performance
35901 --
35902 l_balance_type_code           VARCHAR2(1);
35903 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
35904 l_log_module                  VARCHAR2(240);
35905 
35906 --
35907 -- Upgrade strategy
35908 --
35909 l_actual_upg_option           VARCHAR2(1);
35910 l_enc_upg_option           VARCHAR2(1);
35911 
35912 --
35913 BEGIN
35914 --
35915 IF g_log_enabled THEN
35916       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_82';
35917 END IF;
35918 --
35919 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
35920 
35921       trace
35922          (p_msg      => 'BEGIN of AcctLineType_82'
35923          ,p_level    => C_LEVEL_PROCEDURE
35924          ,p_module   => l_log_module);
35925 
35926 END IF;
35927 --
35928 l_component_type             := 'AMB_JLT';
35929 l_component_code             := 'INV_ROUND';
35930 l_component_type_code        := 'S';
35931 l_component_appl_id          :=  222;
35932 l_amb_context_code           := 'DEFAULT';
35933 l_entity_code                := 'TRANSACTIONS';
35934 l_event_class_code           := 'INVOICE';
35935 l_event_type_code            := 'INVOICE_ALL';
35936 l_line_definition_owner_code := 'S';
35937 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
35938 --
35939 l_balance_type_code          := 'A';
35940 l_segment                     := NULL;
35941 l_ccid                        := NULL;
35942 l_adr_transaction_coa_id      := NULL;
35943 l_adr_accounting_coa_id       := NULL;
35944 l_adr_flexfield_segment_code  := NULL;
35945 l_adr_flex_value_set_id       := NULL;
35946 l_adr_value_type_code         := NULL;
35947 l_adr_value_combination_id    := NULL;
35948 l_adr_value_segment_code      := NULL;
35949 
35950 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
35951 l_bflow_class_code           := '';    -- 4219869 Business Flow
35952 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
35953 l_budgetary_control_flag     := 'N';
35954 
35955 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
35956 l_bflow_applied_to_amt       := NULL; -- 5132302
35957 l_entered_amt_idx            := NULL;          -- 4262811
35958 l_accted_amt_idx             := NULL;          -- 4262811
35959 l_acc_rev_flag               := NULL;          -- 4262811
35960 l_accrual_line_num           := NULL;          -- 4262811
35961 l_tmp_amt                    := NULL;          -- 4262811
35962 --
35963  
35964 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
35965     l_balance_type_code <> 'B' THEN
35966 IF NVL(p_source_33,'
35967 ') =  'ROUND'
35968  THEN 
35969 
35970    --
35971    XLA_AE_LINES_PKG.SetNewLine;
35972 
35973    p_balance_type_code          := l_balance_type_code;
35974    -- set the flag so later we will know whether the gain loss line needs to be created
35975    
35976    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
35977      p_actual_flag :='A';
35978    END IF;
35979 
35980    --
35981    -- bulk performance
35982    --
35983    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
35984                                       p_header_num   => 0); -- 4262811
35985    --
35986    -- set accounting line options
35987    --
35988    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
35989            p_natural_side_code          => 'C'
35990          , p_gain_or_loss_flag          => 'N'
35991          , p_gl_transfer_mode_code      => 'S'
35992          , p_acct_entry_type_code       => 'A'
35993          , p_switch_side_flag           => 'Y'
35994          , p_merge_duplicate_code       => 'A'
35995          );
35996    --
35997    l_acc_rev_natural_side_code := 'D';  -- 4262811
35998    -- 
35999    --
36000    -- set accounting line type info
36001    --
36002    xla_ae_lines_pkg.SetAcctLineType
36003       (p_component_type             => l_component_type
36004       ,p_event_type_code            => l_event_type_code
36005       ,p_line_definition_owner_code => l_line_definition_owner_code
36006       ,p_line_definition_code       => l_line_definition_code
36007       ,p_accounting_line_code       => l_component_code
36008       ,p_accounting_line_type_code  => l_component_type_code
36009       ,p_accounting_line_appl_id    => l_component_appl_id
36013    --
36010       ,p_amb_context_code           => l_amb_context_code
36011       ,p_entity_code                => l_entity_code
36012       ,p_event_class_code           => l_event_class_code);
36014    -- set accounting class
36015    --
36016    xla_ae_lines_pkg.SetAcctClass(
36017            p_accounting_class_code  => 'ROUNDING'
36018          , p_ae_header_id           => l_ae_header_id
36019          );
36020 
36021    --
36022    -- set rounding class
36023    --
36024    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
36025                       'RECEIVABLE';
36026 
36027    --
36028    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
36029    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
36030    --
36031    -- bulk performance
36032    --
36033    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
36034 
36035    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
36036       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
36037 
36038    -- 4955764
36039    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
36040       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
36041 
36042    -- 4458381 Public Sector Enh
36043    
36044    --
36045    -- set accounting attributes for the line type
36046    --
36047    l_entered_amt_idx := 3;
36048    l_accted_amt_idx  := 8;
36049    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
36050    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
36051    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
36052    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
36053    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
36054    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
36055    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
36056    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
36057    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
36058    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
36059    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
36060    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
36061    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
36062    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
36063    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
36064    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
36065    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
36066    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
36067    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
36068    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
36069    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
36070    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
36071    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
36072    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
36073    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
36074 
36075    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
36076    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
36077 
36078    ---------------------------------------------------------------------------------------------------------------
36079    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
36080    ---------------------------------------------------------------------------------------------------------------
36081    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
36082 
36083    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
36084    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
36085 
36086    IF xla_accounting_cache_pkg.GetValueChar
36087          (p_source_code         => 'LEDGER_CATEGORY_CODE'
36088          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
36089    AND l_bflow_method_code = 'PRIOR_ENTRY'
36090 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
36091    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
36092          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
36093        )
36094    THEN
36095          xla_ae_lines_pkg.BflowUpgEntry
36096            (p_business_method_code    => l_bflow_method_code
36097            ,p_business_class_code     => l_bflow_class_code
36098            ,p_balance_type            => l_balance_type_code);
36099    ELSE
36100       NULL;
36101 -- No business flow processing for business flow method of NONE.
36102    END IF;
36103 
36104    --
36105    -- call analytical criteria
36106    --
36107    
36108    --
36109    -- call description
36110    --
36111    -- No description or it is inherited.
36112    --
36113    -- call ADRs
36114    -- Bug 4922099
36115    --
36116    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
36117         (NVL(l_actual_upg_option, 'N') = 'O') OR
36118         (NVL(l_enc_upg_option, 'N') = 'O')
36119       )
36120    THEN
36121    NULL;
36122    --
36126            p_application_id           => p_application_id
36123    --
36124    
36125   l_ccid := AcctDerRule_32(
36127          , p_ae_header_id             => l_ae_header_id 
36128 , p_source_4 => p_source_4
36129          , x_transaction_coa_id       => l_adr_transaction_coa_id
36130          , x_accounting_coa_id        => l_adr_accounting_coa_id
36131          , x_value_type_code          => l_adr_value_type_code
36132          , p_side                     => 'NA'
36133    );
36134 
36135    xla_ae_lines_pkg.set_ccid(
36136     p_code_combination_id          => l_ccid
36137   , p_value_type_code              => l_adr_value_type_code
36138   , p_transaction_coa_id           => l_adr_transaction_coa_id
36139   , p_accounting_coa_id            => l_adr_accounting_coa_id
36140   , p_adr_code                     => 'TRX_DIST_CCID'
36141   , p_adr_type_code                => 'S'
36142   , p_component_type               => l_component_type
36143   , p_component_code               => l_component_code
36144   , p_component_type_code          => l_component_type_code
36145   , p_component_appl_id            => l_component_appl_id
36146   , p_amb_context_code             => l_amb_context_code
36147   , p_side                         => 'NA'
36148   );
36149 
36150 
36151    --
36152    --
36153    END IF;
36154    --
36155    -- Bug 4922099
36156    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
36157           (NVL(l_enc_upg_option, 'N') = 'O')
36158         ) AND
36159         (l_bflow_method_code = 'PRIOR_ENTRY')
36160       )
36161    THEN
36162       IF
36163       --
36164       1 = 2
36165       --
36166       THEN
36167       xla_accounting_err_pkg.build_message
36168                                     (p_appli_s_name            => 'XLA'
36169                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
36170                                     ,p_token_1                 => 'LINE_NUMBER'
36171                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
36172                                     ,p_token_2                 => 'LINE_TYPE_NAME'
36173                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
36174                                                                              l_component_type
36175                                                                             ,l_component_code
36176                                                                             ,l_component_type_code
36177                                                                             ,l_component_appl_id
36178                                                                             ,l_amb_context_code
36179                                                                             ,l_entity_code
36180                                                                             ,l_event_class_code
36181                                                                            )
36182                                     ,p_token_3                 => 'OWNER'
36183                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
36184                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
36185                                                                           ,p_lookup_code    => l_component_type_code
36186                                                                          )
36187                                     ,p_token_4                 => 'PRODUCT_NAME'
36188                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
36189                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
36190                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
36191                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
36192                                     ,p_ae_header_id            =>  NULL
36193                                        );
36194 
36195         IF (C_LEVEL_ERROR>= g_log_level) THEN
36196                  trace
36197                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
36198                       ,p_level    => C_LEVEL_ERROR
36199                       ,p_module   => l_log_module);
36200         END IF;
36201       END IF;
36202    END IF;
36203    --
36204    --
36205    ------------------------------------------------------------------------------------------------
36206    -- 4219869 Business Flow
36207    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
36208    -- Prior Entry.  Currently, the following code is always generated.
36209    ------------------------------------------------------------------------------------------------
36210    XLA_AE_LINES_PKG.ValidateCurrentLine;
36211 
36212    ------------------------------------------------------------------------------------
36213    -- 4219869 Business Flow
36214    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
36215    ------------------------------------------------------------------------------------
36216    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
36217 
36218    ----------------------------------------------------------------------------------
36219    -- 4219869 Business Flow
36220    -- Update journal entry status -- Need to generate this within IF <condition>
36224          ,p_balance_type_code => l_balance_type_code
36221    ----------------------------------------------------------------------------------
36222    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
36223          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
36225          );
36226 
36227    -------------------------------------------------------------------------------------------
36228    -- 4262811 - Generate the Accrual Reversal lines
36229    -------------------------------------------------------------------------------------------
36230    BEGIN
36231       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
36232                               (g_array_event(p_event_id).array_value_num('header_index'));
36233       IF l_acc_rev_flag IS NULL THEN
36234          l_acc_rev_flag := 'N';
36235       END IF;
36236    EXCEPTION
36237       WHEN OTHERS THEN
36238          l_acc_rev_flag := 'N';
36239    END;
36240    --
36241    IF (l_acc_rev_flag = 'Y') THEN
36242 
36243        -- 4645092  ------------------------------------------------------------------------------
36244        -- To allow MPA report to determine if it should generate report process
36245        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
36246        ------------------------------------------------------------------------------------------
36247 
36248        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
36249        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
36250    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
36251    -- call ADRs
36252    -- Bug 4922099
36253    --
36254    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
36255         (NVL(l_actual_upg_option, 'N') = 'O') OR
36256         (NVL(l_enc_upg_option, 'N') = 'O')
36257       )
36258    THEN
36259    NULL;
36260    --
36261    --
36262    
36263   l_ccid := AcctDerRule_32(
36264            p_application_id           => p_application_id
36265          , p_ae_header_id             => l_ae_header_id 
36266 , p_source_4 => p_source_4
36267          , x_transaction_coa_id       => l_adr_transaction_coa_id
36268          , x_accounting_coa_id        => l_adr_accounting_coa_id
36269          , x_value_type_code          => l_adr_value_type_code
36270          , p_side                     => 'NA'
36271    );
36272 
36273    xla_ae_lines_pkg.set_ccid(
36274     p_code_combination_id          => l_ccid
36275   , p_value_type_code              => l_adr_value_type_code
36276   , p_transaction_coa_id           => l_adr_transaction_coa_id
36277   , p_accounting_coa_id            => l_adr_accounting_coa_id
36278   , p_adr_code                     => 'TRX_DIST_CCID'
36279   , p_adr_type_code                => 'S'
36280   , p_component_type               => l_component_type
36281   , p_component_code               => l_component_code
36282   , p_component_type_code          => l_component_type_code
36283   , p_component_appl_id            => l_component_appl_id
36284   , p_amb_context_code             => l_amb_context_code
36285   , p_side                         => 'NA'
36286   );
36287 
36288 
36289    --
36290    --
36291    END IF;
36292 
36293        --
36294        -- Update the line information that should be overwritten
36295        --
36296        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
36297                                          p_header_num   => 1);
36298        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
36299 
36300        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
36301 
36302        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
36303           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
36304        END IF;
36305 
36306       --
36307       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
36308       --
36309       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
36310           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
36311       ELSE
36312           ---------------------------------------------------------------------------------------------------
36313           -- 4262811a Switch Sign
36314           ---------------------------------------------------------------------------------------------------
36315           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
36316           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
36317                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
36318           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
36319                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
36320           -- 5132302
36321           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
36322                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
36323 
36324       END IF;
36325 
36326       -- 4955764
36327       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
36331       XLA_AE_LINES_PKG.ValidateCurrentLine;
36328       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
36329 
36330 
36332       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
36333 
36334       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
36335                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
36336                ,p_balance_type_code => l_balance_type_code);
36337 
36338    END IF;
36339 
36340    -----------------------------------------------------------------------------------------
36341    -- 4262811 Multiperiod Accounting
36342    -----------------------------------------------------------------------------------------
36343      -- No MPA option is assigned.
36344 
36345 
36346 END IF;
36347 END IF;
36348 --
36349 
36350 --
36351 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
36352    trace
36353       (p_msg      => 'END of AcctLineType_82'
36354       ,p_level    => C_LEVEL_PROCEDURE
36355       ,p_module   => l_log_module);
36356 END IF;
36357 --
36358 EXCEPTION
36359   WHEN xla_exceptions_pkg.application_exception THEN
36360       RAISE;
36361   WHEN OTHERS THEN
36362        xla_exceptions_pkg.raise_message
36363            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_82');
36364 END AcctLineType_82;
36365 --
36366 
36367 ---------------------------------------
36368 --
36369 -- PRIVATE FUNCTION
36370 --         AcctLineType_83
36371 --
36372 ---------------------------------------
36373 PROCEDURE AcctLineType_83 (
36374   p_application_id        IN NUMBER
36375  ,p_event_id              IN NUMBER
36376  ,p_calculate_acctd_flag  IN VARCHAR2
36377  ,p_calculate_g_l_flag    IN VARCHAR2
36378  ,p_actual_flag           IN OUT VARCHAR2
36379  ,p_balance_type_code     OUT VARCHAR2
36380  ,p_gain_or_loss_ref      OUT VARCHAR2
36381  
36382 --Transaction Distribution GL Account
36383  , p_source_4            IN NUMBER
36384 --Bill To Customer Account Identifier
36385  , p_source_30            IN NUMBER
36386 --Bill To Customer Site Use Identifier
36387  , p_source_31            IN NUMBER
36388 --SLA Party Type
36389  , p_source_32            IN VARCHAR2
36390 --Transaction Distribution Account Class
36391  , p_source_33            IN VARCHAR2
36392 --Transaction Distribution Identifier
36393  , p_source_34            IN NUMBER
36394 --Transaction Distribution Type
36395  , p_source_35            IN VARCHAR2
36396 --Transaction Distribution Entered Amount
36397  , p_source_36            IN NUMBER
36398 --Transaction Currency Code
36399  , p_source_37            IN VARCHAR2
36400 --Transaction Exchange Date
36401  , p_source_38            IN DATE
36402 --Transaction Exchange Rate
36403  , p_source_39            IN NUMBER
36404 --Transaction Exchange Rate Type
36405  , p_source_40            IN VARCHAR2
36406 --Transaction Accounting Amount
36407  , p_source_41            IN NUMBER
36408 --Transaction Tax Line Identifier
36409  , p_source_55            IN NUMBER
36410 )
36411 IS
36412 
36413 l_component_type              VARCHAR2(80);
36414 l_component_code              VARCHAR2(30);
36415 l_component_type_code         VARCHAR2(1);
36416 l_component_appl_id           INTEGER;
36417 l_amb_context_code            VARCHAR2(30);
36418 l_entity_code                 VARCHAR2(30);
36419 l_event_class_code            VARCHAR2(30);
36420 l_ae_header_id                NUMBER;
36421 l_event_type_code             VARCHAR2(30);
36422 l_line_definition_code        VARCHAR2(30);
36423 l_line_definition_owner_code  VARCHAR2(1);
36424 --
36425 -- adr variables
36426 l_segment                     VARCHAR2(30);
36427 l_ccid                        NUMBER;
36428 l_adr_transaction_coa_id      NUMBER;
36429 l_adr_accounting_coa_id       NUMBER;
36430 l_adr_flexfield_segment_code  VARCHAR2(30);
36431 l_adr_flex_value_set_id       NUMBER;
36432 l_adr_value_type_code         VARCHAR2(30);
36433 l_adr_value_combination_id    NUMBER;
36434 l_adr_value_segment_code      VARCHAR2(30);
36435 
36436 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
36437 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
36438 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
36439 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
36440 
36441 -- 4262811 Variables ------------------------------------------------------------------------------------------
36442 l_entered_amt_idx             NUMBER;
36443 l_accted_amt_idx              NUMBER;
36444 l_acc_rev_flag                VARCHAR2(1);
36445 l_accrual_line_num            NUMBER;
36446 l_tmp_amt                     NUMBER;
36447 l_acc_rev_natural_side_code   VARCHAR2(1);
36448 
36449 l_num_entries                 NUMBER;
36450 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
36451 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
36452 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
36453 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
36454 l_recog_line_1                NUMBER;
36455 l_recog_line_2                NUMBER;
36456 
36457 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
36458 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
36459 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
36460 
36464 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
36461 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
36462 
36463 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
36465 
36466 ---------------------------------------------------------------------------------------------------------------
36467 
36468 
36469 --
36470 -- bulk performance
36471 --
36472 l_balance_type_code           VARCHAR2(1);
36473 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
36474 l_log_module                  VARCHAR2(240);
36475 
36476 --
36477 -- Upgrade strategy
36478 --
36479 l_actual_upg_option           VARCHAR2(1);
36480 l_enc_upg_option           VARCHAR2(1);
36481 
36482 --
36483 BEGIN
36484 --
36485 IF g_log_enabled THEN
36486       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_83';
36487 END IF;
36488 --
36489 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
36490 
36491       trace
36492          (p_msg      => 'BEGIN of AcctLineType_83'
36493          ,p_level    => C_LEVEL_PROCEDURE
36494          ,p_module   => l_log_module);
36495 
36496 END IF;
36497 --
36498 l_component_type             := 'AMB_JLT';
36499 l_component_code             := 'INV_TAX';
36500 l_component_type_code        := 'S';
36501 l_component_appl_id          :=  222;
36502 l_amb_context_code           := 'DEFAULT';
36503 l_entity_code                := 'TRANSACTIONS';
36504 l_event_class_code           := 'INVOICE';
36505 l_event_type_code            := 'INVOICE_ALL';
36506 l_line_definition_owner_code := 'S';
36507 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
36508 --
36509 l_balance_type_code          := 'A';
36510 l_segment                     := NULL;
36511 l_ccid                        := NULL;
36512 l_adr_transaction_coa_id      := NULL;
36513 l_adr_accounting_coa_id       := NULL;
36514 l_adr_flexfield_segment_code  := NULL;
36515 l_adr_flex_value_set_id       := NULL;
36516 l_adr_value_type_code         := NULL;
36517 l_adr_value_combination_id    := NULL;
36518 l_adr_value_segment_code      := NULL;
36519 
36520 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
36521 l_bflow_class_code           := 'TAX';    -- 4219869 Business Flow
36522 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
36523 l_budgetary_control_flag     := 'N';
36524 
36525 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
36526 l_bflow_applied_to_amt       := NULL; -- 5132302
36527 l_entered_amt_idx            := NULL;          -- 4262811
36528 l_accted_amt_idx             := NULL;          -- 4262811
36529 l_acc_rev_flag               := NULL;          -- 4262811
36530 l_accrual_line_num           := NULL;          -- 4262811
36531 l_tmp_amt                    := NULL;          -- 4262811
36532 --
36533  
36534 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
36535     l_balance_type_code <> 'B' THEN
36536 IF NVL(p_source_33,'
36537 ') =  'TAX'
36538  THEN 
36539 
36540    --
36541    XLA_AE_LINES_PKG.SetNewLine;
36542 
36543    p_balance_type_code          := l_balance_type_code;
36544    -- set the flag so later we will know whether the gain loss line needs to be created
36545    
36546    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
36547      p_actual_flag :='A';
36548    END IF;
36549 
36550    --
36551    -- bulk performance
36552    --
36553    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
36554                                       p_header_num   => 0); -- 4262811
36555    --
36556    -- set accounting line options
36557    --
36558    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
36559            p_natural_side_code          => 'C'
36560          , p_gain_or_loss_flag          => 'N'
36561          , p_gl_transfer_mode_code      => 'S'
36562          , p_acct_entry_type_code       => 'A'
36563          , p_switch_side_flag           => 'Y'
36564          , p_merge_duplicate_code       => 'A'
36565          );
36566    --
36567    l_acc_rev_natural_side_code := 'D';  -- 4262811
36568    -- 
36569    --
36570    -- set accounting line type info
36571    --
36572    xla_ae_lines_pkg.SetAcctLineType
36573       (p_component_type             => l_component_type
36574       ,p_event_type_code            => l_event_type_code
36575       ,p_line_definition_owner_code => l_line_definition_owner_code
36576       ,p_line_definition_code       => l_line_definition_code
36577       ,p_accounting_line_code       => l_component_code
36578       ,p_accounting_line_type_code  => l_component_type_code
36579       ,p_accounting_line_appl_id    => l_component_appl_id
36580       ,p_amb_context_code           => l_amb_context_code
36581       ,p_entity_code                => l_entity_code
36582       ,p_event_class_code           => l_event_class_code);
36583    --
36584    -- set accounting class
36585    --
36586    xla_ae_lines_pkg.SetAcctClass(
36587            p_accounting_class_code  => 'TAX'
36588          , p_ae_header_id           => l_ae_header_id
36589          );
36590 
36591    --
36592    -- set rounding class
36593    --
36594    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
36595                       'RECEIVABLE';
36596 
36597    --
36601    -- bulk performance
36598    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
36599    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
36600    --
36602    --
36603    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
36604 
36605    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
36606       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
36607 
36608    -- 4955764
36609    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
36610       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
36611 
36612    -- 4458381 Public Sector Enh
36613    
36614    --
36615    -- set accounting attributes for the line type
36616    --
36617    l_entered_amt_idx := 3;
36618    l_accted_amt_idx  := 8;
36619    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
36620    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
36621    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
36622    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
36623    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
36624    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
36625    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
36626    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
36627    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
36628    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
36629    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
36630    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
36631    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
36632    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
36633    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
36634    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
36635    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
36636    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
36637    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
36638    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
36639    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
36640    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
36641    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
36642    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
36643    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
36644 
36645    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
36646    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
36647 
36648    ---------------------------------------------------------------------------------------------------------------
36649    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
36650    ---------------------------------------------------------------------------------------------------------------
36651    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
36652 
36653    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
36654    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
36655 
36656    IF xla_accounting_cache_pkg.GetValueChar
36657          (p_source_code         => 'LEDGER_CATEGORY_CODE'
36658          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
36659    AND l_bflow_method_code = 'PRIOR_ENTRY'
36660 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
36661    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
36662          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
36663        )
36664    THEN
36665          xla_ae_lines_pkg.BflowUpgEntry
36666            (p_business_method_code    => l_bflow_method_code
36667            ,p_business_class_code     => l_bflow_class_code
36668            ,p_balance_type            => l_balance_type_code);
36669    ELSE
36670       NULL;
36671 -- No business flow processing for business flow method of NONE.
36672    END IF;
36673 
36674    --
36675    -- call analytical criteria
36676    --
36677    
36678    --
36679    -- call description
36680    --
36681    -- No description or it is inherited.
36682    --
36683    -- call ADRs
36684    -- Bug 4922099
36685    --
36686    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
36687         (NVL(l_actual_upg_option, 'N') = 'O') OR
36688         (NVL(l_enc_upg_option, 'N') = 'O')
36689       )
36690    THEN
36691    NULL;
36692    --
36693    --
36694    
36695   l_ccid := AcctDerRule_32(
36696            p_application_id           => p_application_id
36697          , p_ae_header_id             => l_ae_header_id 
36698 , p_source_4 => p_source_4
36699          , x_transaction_coa_id       => l_adr_transaction_coa_id
36700          , x_accounting_coa_id        => l_adr_accounting_coa_id
36701          , x_value_type_code          => l_adr_value_type_code
36702          , p_side                     => 'NA'
36703    );
36704 
36705    xla_ae_lines_pkg.set_ccid(
36706     p_code_combination_id          => l_ccid
36707   , p_value_type_code              => l_adr_value_type_code
36708   , p_transaction_coa_id           => l_adr_transaction_coa_id
36712   , p_component_type               => l_component_type
36709   , p_accounting_coa_id            => l_adr_accounting_coa_id
36710   , p_adr_code                     => 'TRX_DIST_CCID'
36711   , p_adr_type_code                => 'S'
36713   , p_component_code               => l_component_code
36714   , p_component_type_code          => l_component_type_code
36715   , p_component_appl_id            => l_component_appl_id
36716   , p_amb_context_code             => l_amb_context_code
36717   , p_side                         => 'NA'
36718   );
36719 
36720 
36721    --
36722    --
36723    END IF;
36724    --
36725    -- Bug 4922099
36726    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
36727           (NVL(l_enc_upg_option, 'N') = 'O')
36728         ) AND
36729         (l_bflow_method_code = 'PRIOR_ENTRY')
36730       )
36731    THEN
36732       IF
36733       --
36734       1 = 2
36735       --
36736       THEN
36737       xla_accounting_err_pkg.build_message
36738                                     (p_appli_s_name            => 'XLA'
36739                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
36740                                     ,p_token_1                 => 'LINE_NUMBER'
36741                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
36742                                     ,p_token_2                 => 'LINE_TYPE_NAME'
36743                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
36744                                                                              l_component_type
36745                                                                             ,l_component_code
36746                                                                             ,l_component_type_code
36747                                                                             ,l_component_appl_id
36748                                                                             ,l_amb_context_code
36749                                                                             ,l_entity_code
36750                                                                             ,l_event_class_code
36751                                                                            )
36752                                     ,p_token_3                 => 'OWNER'
36753                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
36754                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
36755                                                                           ,p_lookup_code    => l_component_type_code
36756                                                                          )
36757                                     ,p_token_4                 => 'PRODUCT_NAME'
36758                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
36759                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
36760                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
36761                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
36762                                     ,p_ae_header_id            =>  NULL
36763                                        );
36764 
36765         IF (C_LEVEL_ERROR>= g_log_level) THEN
36766                  trace
36767                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
36768                       ,p_level    => C_LEVEL_ERROR
36769                       ,p_module   => l_log_module);
36770         END IF;
36771       END IF;
36772    END IF;
36773    --
36774    --
36775    ------------------------------------------------------------------------------------------------
36776    -- 4219869 Business Flow
36777    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
36778    -- Prior Entry.  Currently, the following code is always generated.
36779    ------------------------------------------------------------------------------------------------
36780    XLA_AE_LINES_PKG.ValidateCurrentLine;
36781 
36782    ------------------------------------------------------------------------------------
36783    -- 4219869 Business Flow
36784    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
36785    ------------------------------------------------------------------------------------
36786    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
36787 
36788    ----------------------------------------------------------------------------------
36789    -- 4219869 Business Flow
36790    -- Update journal entry status -- Need to generate this within IF <condition>
36791    ----------------------------------------------------------------------------------
36792    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
36793          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
36794          ,p_balance_type_code => l_balance_type_code
36795          );
36796 
36797    -------------------------------------------------------------------------------------------
36798    -- 4262811 - Generate the Accrual Reversal lines
36799    -------------------------------------------------------------------------------------------
36800    BEGIN
36801       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
36805       END IF;
36802                               (g_array_event(p_event_id).array_value_num('header_index'));
36803       IF l_acc_rev_flag IS NULL THEN
36804          l_acc_rev_flag := 'N';
36806    EXCEPTION
36807       WHEN OTHERS THEN
36808          l_acc_rev_flag := 'N';
36809    END;
36810    --
36811    IF (l_acc_rev_flag = 'Y') THEN
36812 
36813        -- 4645092  ------------------------------------------------------------------------------
36814        -- To allow MPA report to determine if it should generate report process
36815        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
36816        ------------------------------------------------------------------------------------------
36817 
36818        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
36819        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
36820    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
36821    -- call ADRs
36822    -- Bug 4922099
36823    --
36824    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
36825         (NVL(l_actual_upg_option, 'N') = 'O') OR
36826         (NVL(l_enc_upg_option, 'N') = 'O')
36827       )
36828    THEN
36829    NULL;
36830    --
36831    --
36832    
36833   l_ccid := AcctDerRule_32(
36834            p_application_id           => p_application_id
36835          , p_ae_header_id             => l_ae_header_id 
36836 , p_source_4 => p_source_4
36837          , x_transaction_coa_id       => l_adr_transaction_coa_id
36838          , x_accounting_coa_id        => l_adr_accounting_coa_id
36839          , x_value_type_code          => l_adr_value_type_code
36840          , p_side                     => 'NA'
36841    );
36842 
36843    xla_ae_lines_pkg.set_ccid(
36844     p_code_combination_id          => l_ccid
36845   , p_value_type_code              => l_adr_value_type_code
36846   , p_transaction_coa_id           => l_adr_transaction_coa_id
36847   , p_accounting_coa_id            => l_adr_accounting_coa_id
36848   , p_adr_code                     => 'TRX_DIST_CCID'
36849   , p_adr_type_code                => 'S'
36850   , p_component_type               => l_component_type
36851   , p_component_code               => l_component_code
36852   , p_component_type_code          => l_component_type_code
36853   , p_component_appl_id            => l_component_appl_id
36854   , p_amb_context_code             => l_amb_context_code
36855   , p_side                         => 'NA'
36856   );
36857 
36858 
36859    --
36860    --
36861    END IF;
36862 
36863        --
36864        -- Update the line information that should be overwritten
36865        --
36866        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
36867                                          p_header_num   => 1);
36868        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
36869 
36870        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
36871 
36872        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
36873           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
36874        END IF;
36875 
36876       --
36877       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
36878       --
36879       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
36880           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
36881       ELSE
36882           ---------------------------------------------------------------------------------------------------
36883           -- 4262811a Switch Sign
36884           ---------------------------------------------------------------------------------------------------
36885           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
36886           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
36887                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
36888           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
36889                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
36890           -- 5132302
36891           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
36892                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
36893 
36894       END IF;
36895 
36896       -- 4955764
36897       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
36898       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
36899 
36900 
36901       XLA_AE_LINES_PKG.ValidateCurrentLine;
36902       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
36903 
36904       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
36905                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
36906                ,p_balance_type_code => l_balance_type_code);
36907 
36908    END IF;
36909 
36910    -----------------------------------------------------------------------------------------
36911    -- 4262811 Multiperiod Accounting
36915 
36912    -----------------------------------------------------------------------------------------
36913      -- No MPA option is assigned.
36914 
36916 END IF;
36917 END IF;
36918 --
36919 
36920 --
36921 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
36922    trace
36923       (p_msg      => 'END of AcctLineType_83'
36924       ,p_level    => C_LEVEL_PROCEDURE
36925       ,p_module   => l_log_module);
36926 END IF;
36927 --
36928 EXCEPTION
36929   WHEN xla_exceptions_pkg.application_exception THEN
36930       RAISE;
36931   WHEN OTHERS THEN
36932        xla_exceptions_pkg.raise_message
36933            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_83');
36934 END AcctLineType_83;
36935 --
36936 
36937 ---------------------------------------
36938 --
36939 -- PRIVATE FUNCTION
36940 --         AcctLineType_84
36941 --
36942 ---------------------------------------
36943 PROCEDURE AcctLineType_84 (
36944   p_application_id        IN NUMBER
36945  ,p_event_id              IN NUMBER
36946  ,p_calculate_acctd_flag  IN VARCHAR2
36947  ,p_calculate_g_l_flag    IN VARCHAR2
36948  ,p_actual_flag           IN OUT VARCHAR2
36949  ,p_balance_type_code     OUT VARCHAR2
36950  ,p_gain_or_loss_ref      OUT VARCHAR2
36951  
36952 --Transaction Distribution GL Account
36953  , p_source_4            IN NUMBER
36954 --Bill To Customer Account Identifier
36955  , p_source_30            IN NUMBER
36956 --Bill To Customer Site Use Identifier
36957  , p_source_31            IN NUMBER
36958 --SLA Party Type
36959  , p_source_32            IN VARCHAR2
36960 --Transaction Distribution Account Class
36961  , p_source_33            IN VARCHAR2
36962 --Transaction Distribution Identifier
36963  , p_source_34            IN NUMBER
36964 --Transaction Distribution Type
36965  , p_source_35            IN VARCHAR2
36966 --Transaction Distribution Entered Amount
36967  , p_source_36            IN NUMBER
36968 --Transaction Currency Code
36969  , p_source_37            IN VARCHAR2
36970 --Transaction Exchange Date
36971  , p_source_38            IN DATE
36972 --Transaction Exchange Rate
36973  , p_source_39            IN NUMBER
36974 --Transaction Exchange Rate Type
36975  , p_source_40            IN VARCHAR2
36976 --Transaction Accounting Amount
36977  , p_source_41            IN NUMBER
36978 --Transaction Tax Line Identifier
36979  , p_source_55            IN NUMBER
36980 --Rounding Correction Flag
36981  , p_source_66            IN VARCHAR2
36982 )
36983 IS
36984 
36985 l_component_type              VARCHAR2(80);
36986 l_component_code              VARCHAR2(30);
36987 l_component_type_code         VARCHAR2(1);
36988 l_component_appl_id           INTEGER;
36989 l_amb_context_code            VARCHAR2(30);
36990 l_entity_code                 VARCHAR2(30);
36991 l_event_class_code            VARCHAR2(30);
36992 l_ae_header_id                NUMBER;
36993 l_event_type_code             VARCHAR2(30);
36994 l_line_definition_code        VARCHAR2(30);
36995 l_line_definition_owner_code  VARCHAR2(1);
36996 --
36997 -- adr variables
36998 l_segment                     VARCHAR2(30);
36999 l_ccid                        NUMBER;
37000 l_adr_transaction_coa_id      NUMBER;
37001 l_adr_accounting_coa_id       NUMBER;
37002 l_adr_flexfield_segment_code  VARCHAR2(30);
37003 l_adr_flex_value_set_id       NUMBER;
37004 l_adr_value_type_code         VARCHAR2(30);
37005 l_adr_value_combination_id    NUMBER;
37006 l_adr_value_segment_code      VARCHAR2(30);
37007 
37008 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
37009 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
37010 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
37011 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
37012 
37013 -- 4262811 Variables ------------------------------------------------------------------------------------------
37014 l_entered_amt_idx             NUMBER;
37015 l_accted_amt_idx              NUMBER;
37016 l_acc_rev_flag                VARCHAR2(1);
37017 l_accrual_line_num            NUMBER;
37018 l_tmp_amt                     NUMBER;
37019 l_acc_rev_natural_side_code   VARCHAR2(1);
37020 
37021 l_num_entries                 NUMBER;
37022 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
37023 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
37024 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
37025 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
37026 l_recog_line_1                NUMBER;
37027 l_recog_line_2                NUMBER;
37028 
37029 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
37030 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
37031 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
37032 
37033 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
37034 
37035 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
37036 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
37037 
37038 ---------------------------------------------------------------------------------------------------------------
37039 
37040 
37041 --
37042 -- bulk performance
37043 --
37044 l_balance_type_code           VARCHAR2(1);
37045 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
37046 l_log_module                  VARCHAR2(240);
37050 --
37047 
37048 --
37049 -- Upgrade strategy
37051 l_actual_upg_option           VARCHAR2(1);
37052 l_enc_upg_option           VARCHAR2(1);
37053 
37054 --
37055 BEGIN
37056 --
37057 IF g_log_enabled THEN
37058       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_84';
37059 END IF;
37060 --
37061 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
37062 
37063       trace
37064          (p_msg      => 'BEGIN of AcctLineType_84'
37065          ,p_level    => C_LEVEL_PROCEDURE
37066          ,p_module   => l_log_module);
37067 
37068 END IF;
37069 --
37070 l_component_type             := 'AMB_JLT';
37071 l_component_code             := 'INV_UNBILL';
37072 l_component_type_code        := 'S';
37073 l_component_appl_id          :=  222;
37074 l_amb_context_code           := 'DEFAULT';
37075 l_entity_code                := 'TRANSACTIONS';
37076 l_event_class_code           := 'INVOICE';
37077 l_event_type_code            := 'INVOICE_ALL';
37078 l_line_definition_owner_code := 'S';
37079 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
37080 --
37081 l_balance_type_code          := 'A';
37082 l_segment                     := NULL;
37083 l_ccid                        := NULL;
37084 l_adr_transaction_coa_id      := NULL;
37085 l_adr_accounting_coa_id       := NULL;
37086 l_adr_flexfield_segment_code  := NULL;
37087 l_adr_flex_value_set_id       := NULL;
37088 l_adr_value_type_code         := NULL;
37089 l_adr_value_combination_id    := NULL;
37090 l_adr_value_segment_code      := NULL;
37091 
37092 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
37093 l_bflow_class_code           := '';    -- 4219869 Business Flow
37094 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
37095 l_budgetary_control_flag     := 'N';
37096 
37097 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
37098 l_bflow_applied_to_amt       := NULL; -- 5132302
37099 l_entered_amt_idx            := NULL;          -- 4262811
37100 l_accted_amt_idx             := NULL;          -- 4262811
37101 l_acc_rev_flag               := NULL;          -- 4262811
37102 l_accrual_line_num           := NULL;          -- 4262811
37103 l_tmp_amt                    := NULL;          -- 4262811
37104 --
37105  
37106 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
37107     l_balance_type_code <> 'B' THEN
37108 IF NVL(p_source_33,'
37109 ') =  'UNBILL' AND 
37110 p_source_66 IS NULL 
37111  THEN 
37112 
37113    --
37114    XLA_AE_LINES_PKG.SetNewLine;
37115 
37116    p_balance_type_code          := l_balance_type_code;
37117    -- set the flag so later we will know whether the gain loss line needs to be created
37118    
37119    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
37120      p_actual_flag :='A';
37121    END IF;
37122 
37123    --
37124    -- bulk performance
37125    --
37126    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
37127                                       p_header_num   => 0); -- 4262811
37128    --
37129    -- set accounting line options
37130    --
37131    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
37132            p_natural_side_code          => 'C'
37133          , p_gain_or_loss_flag          => 'N'
37134          , p_gl_transfer_mode_code      => 'S'
37135          , p_acct_entry_type_code       => 'A'
37136          , p_switch_side_flag           => 'Y'
37137          , p_merge_duplicate_code       => 'A'
37138          );
37139    --
37140    l_acc_rev_natural_side_code := 'D';  -- 4262811
37141    -- 
37142    --
37143    -- set accounting line type info
37144    --
37145    xla_ae_lines_pkg.SetAcctLineType
37146       (p_component_type             => l_component_type
37147       ,p_event_type_code            => l_event_type_code
37148       ,p_line_definition_owner_code => l_line_definition_owner_code
37149       ,p_line_definition_code       => l_line_definition_code
37150       ,p_accounting_line_code       => l_component_code
37151       ,p_accounting_line_type_code  => l_component_type_code
37152       ,p_accounting_line_appl_id    => l_component_appl_id
37153       ,p_amb_context_code           => l_amb_context_code
37154       ,p_entity_code                => l_entity_code
37155       ,p_event_class_code           => l_event_class_code);
37156    --
37157    -- set accounting class
37158    --
37159    xla_ae_lines_pkg.SetAcctClass(
37160            p_accounting_class_code  => 'UNBILL'
37161          , p_ae_header_id           => l_ae_header_id
37162          );
37163 
37164    --
37165    -- set rounding class
37166    --
37167    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
37168                       'UNBILL';
37169 
37170    --
37171    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
37172    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
37173    --
37174    -- bulk performance
37175    --
37176    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
37177 
37178    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
37179       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
37180 
37184 
37181    -- 4955764
37182    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
37183       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
37185    -- 4458381 Public Sector Enh
37186    
37187    --
37188    -- set accounting attributes for the line type
37189    --
37190    l_entered_amt_idx := 3;
37191    l_accted_amt_idx  := 8;
37192    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
37193    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
37194    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
37195    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
37196    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
37197    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
37198    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
37199    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
37200    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
37201    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
37202    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
37203    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
37204    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
37205    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
37206    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
37207    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
37208    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
37209    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
37210    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
37211    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
37212    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
37213    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
37214    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
37215    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
37216    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
37217 
37218    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
37219    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
37220 
37221    ---------------------------------------------------------------------------------------------------------------
37222    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
37223    ---------------------------------------------------------------------------------------------------------------
37224    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
37225 
37226    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
37227    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
37228 
37229    IF xla_accounting_cache_pkg.GetValueChar
37230          (p_source_code         => 'LEDGER_CATEGORY_CODE'
37231          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
37232    AND l_bflow_method_code = 'PRIOR_ENTRY'
37233 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
37234    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
37235          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
37236        )
37237    THEN
37238          xla_ae_lines_pkg.BflowUpgEntry
37239            (p_business_method_code    => l_bflow_method_code
37240            ,p_business_class_code     => l_bflow_class_code
37241            ,p_balance_type            => l_balance_type_code);
37242    ELSE
37243       NULL;
37244 -- No business flow processing for business flow method of NONE.
37245    END IF;
37246 
37247    --
37248    -- call analytical criteria
37249    --
37250    
37251    --
37252    -- call description
37253    --
37254    -- No description or it is inherited.
37255    --
37256    -- call ADRs
37257    -- Bug 4922099
37258    --
37259    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
37260         (NVL(l_actual_upg_option, 'N') = 'O') OR
37261         (NVL(l_enc_upg_option, 'N') = 'O')
37262       )
37263    THEN
37264    NULL;
37265    --
37266    --
37267    
37268   l_ccid := AcctDerRule_32(
37269            p_application_id           => p_application_id
37270          , p_ae_header_id             => l_ae_header_id 
37271 , p_source_4 => p_source_4
37272          , x_transaction_coa_id       => l_adr_transaction_coa_id
37273          , x_accounting_coa_id        => l_adr_accounting_coa_id
37274          , x_value_type_code          => l_adr_value_type_code
37275          , p_side                     => 'NA'
37276    );
37277 
37278    xla_ae_lines_pkg.set_ccid(
37279     p_code_combination_id          => l_ccid
37280   , p_value_type_code              => l_adr_value_type_code
37281   , p_transaction_coa_id           => l_adr_transaction_coa_id
37282   , p_accounting_coa_id            => l_adr_accounting_coa_id
37283   , p_adr_code                     => 'TRX_DIST_CCID'
37284   , p_adr_type_code                => 'S'
37285   , p_component_type               => l_component_type
37286   , p_component_code               => l_component_code
37287   , p_component_type_code          => l_component_type_code
37288   , p_component_appl_id            => l_component_appl_id
37289   , p_amb_context_code             => l_amb_context_code
37290   , p_side                         => 'NA'
37291   );
37292 
37296    END IF;
37293 
37294    --
37295    --
37297    --
37298    -- Bug 4922099
37299    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
37300           (NVL(l_enc_upg_option, 'N') = 'O')
37301         ) AND
37302         (l_bflow_method_code = 'PRIOR_ENTRY')
37303       )
37304    THEN
37305       IF
37306       --
37307       1 = 2
37308       --
37309       THEN
37310       xla_accounting_err_pkg.build_message
37311                                     (p_appli_s_name            => 'XLA'
37312                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
37313                                     ,p_token_1                 => 'LINE_NUMBER'
37314                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
37315                                     ,p_token_2                 => 'LINE_TYPE_NAME'
37316                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
37317                                                                              l_component_type
37318                                                                             ,l_component_code
37319                                                                             ,l_component_type_code
37320                                                                             ,l_component_appl_id
37321                                                                             ,l_amb_context_code
37322                                                                             ,l_entity_code
37323                                                                             ,l_event_class_code
37324                                                                            )
37325                                     ,p_token_3                 => 'OWNER'
37326                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
37327                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
37328                                                                           ,p_lookup_code    => l_component_type_code
37329                                                                          )
37330                                     ,p_token_4                 => 'PRODUCT_NAME'
37331                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
37332                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
37333                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
37334                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
37335                                     ,p_ae_header_id            =>  NULL
37336                                        );
37337 
37338         IF (C_LEVEL_ERROR>= g_log_level) THEN
37339                  trace
37340                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
37341                       ,p_level    => C_LEVEL_ERROR
37342                       ,p_module   => l_log_module);
37343         END IF;
37344       END IF;
37345    END IF;
37346    --
37347    --
37348    ------------------------------------------------------------------------------------------------
37349    -- 4219869 Business Flow
37350    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
37351    -- Prior Entry.  Currently, the following code is always generated.
37352    ------------------------------------------------------------------------------------------------
37353    XLA_AE_LINES_PKG.ValidateCurrentLine;
37354 
37355    ------------------------------------------------------------------------------------
37356    -- 4219869 Business Flow
37357    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
37358    ------------------------------------------------------------------------------------
37359    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
37360 
37361    ----------------------------------------------------------------------------------
37362    -- 4219869 Business Flow
37363    -- Update journal entry status -- Need to generate this within IF <condition>
37364    ----------------------------------------------------------------------------------
37365    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
37366          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
37367          ,p_balance_type_code => l_balance_type_code
37368          );
37369 
37370    -------------------------------------------------------------------------------------------
37371    -- 4262811 - Generate the Accrual Reversal lines
37372    -------------------------------------------------------------------------------------------
37373    BEGIN
37374       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
37375                               (g_array_event(p_event_id).array_value_num('header_index'));
37376       IF l_acc_rev_flag IS NULL THEN
37377          l_acc_rev_flag := 'N';
37378       END IF;
37379    EXCEPTION
37380       WHEN OTHERS THEN
37381          l_acc_rev_flag := 'N';
37382    END;
37383    --
37384    IF (l_acc_rev_flag = 'Y') THEN
37385 
37386        -- 4645092  ------------------------------------------------------------------------------
37387        -- To allow MPA report to determine if it should generate report process
37388        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
37392        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
37389        ------------------------------------------------------------------------------------------
37390 
37391        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
37393    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
37394    -- call ADRs
37395    -- Bug 4922099
37396    --
37397    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
37398         (NVL(l_actual_upg_option, 'N') = 'O') OR
37399         (NVL(l_enc_upg_option, 'N') = 'O')
37400       )
37401    THEN
37402    NULL;
37403    --
37404    --
37405    
37406   l_ccid := AcctDerRule_32(
37407            p_application_id           => p_application_id
37408          , p_ae_header_id             => l_ae_header_id 
37409 , p_source_4 => p_source_4
37410          , x_transaction_coa_id       => l_adr_transaction_coa_id
37411          , x_accounting_coa_id        => l_adr_accounting_coa_id
37412          , x_value_type_code          => l_adr_value_type_code
37413          , p_side                     => 'NA'
37414    );
37415 
37416    xla_ae_lines_pkg.set_ccid(
37417     p_code_combination_id          => l_ccid
37418   , p_value_type_code              => l_adr_value_type_code
37419   , p_transaction_coa_id           => l_adr_transaction_coa_id
37420   , p_accounting_coa_id            => l_adr_accounting_coa_id
37421   , p_adr_code                     => 'TRX_DIST_CCID'
37422   , p_adr_type_code                => 'S'
37423   , p_component_type               => l_component_type
37424   , p_component_code               => l_component_code
37425   , p_component_type_code          => l_component_type_code
37426   , p_component_appl_id            => l_component_appl_id
37427   , p_amb_context_code             => l_amb_context_code
37428   , p_side                         => 'NA'
37429   );
37430 
37431 
37432    --
37433    --
37434    END IF;
37435 
37436        --
37437        -- Update the line information that should be overwritten
37438        --
37439        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
37440                                          p_header_num   => 1);
37441        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
37442 
37443        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
37444 
37445        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
37446           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
37447        END IF;
37448 
37449       --
37450       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
37451       --
37452       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
37453           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
37454       ELSE
37455           ---------------------------------------------------------------------------------------------------
37456           -- 4262811a Switch Sign
37457           ---------------------------------------------------------------------------------------------------
37458           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
37459           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
37460                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
37461           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
37462                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
37463           -- 5132302
37464           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
37465                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
37466 
37467       END IF;
37468 
37469       -- 4955764
37470       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
37471       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
37472 
37473 
37474       XLA_AE_LINES_PKG.ValidateCurrentLine;
37475       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
37476 
37477       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
37478                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
37479                ,p_balance_type_code => l_balance_type_code);
37480 
37481    END IF;
37482 
37483    -----------------------------------------------------------------------------------------
37484    -- 4262811 Multiperiod Accounting
37485    -----------------------------------------------------------------------------------------
37486      -- No MPA option is assigned.
37487 
37488 
37489 END IF;
37490 END IF;
37491 --
37492 
37493 --
37494 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
37495    trace
37496       (p_msg      => 'END of AcctLineType_84'
37497       ,p_level    => C_LEVEL_PROCEDURE
37498       ,p_module   => l_log_module);
37499 END IF;
37500 --
37501 EXCEPTION
37502   WHEN xla_exceptions_pkg.application_exception THEN
37503       RAISE;
37504   WHEN OTHERS THEN
37505        xla_exceptions_pkg.raise_message
37509 
37506            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_84');
37507 END AcctLineType_84;
37508 --
37510 ---------------------------------------
37511 --
37512 -- PRIVATE FUNCTION
37513 --         AcctLineType_85
37514 --
37515 ---------------------------------------
37516 PROCEDURE AcctLineType_85 (
37517   p_application_id        IN NUMBER
37518  ,p_event_id              IN NUMBER
37519  ,p_calculate_acctd_flag  IN VARCHAR2
37520  ,p_calculate_g_l_flag    IN VARCHAR2
37521  ,p_actual_flag           IN OUT VARCHAR2
37522  ,p_balance_type_code     OUT VARCHAR2
37523  ,p_gain_or_loss_ref      OUT VARCHAR2
37524  
37525 --Transaction Distribution GL Account
37526  , p_source_4            IN NUMBER
37527 --Bill To Customer Account Identifier
37528  , p_source_30            IN NUMBER
37529 --Bill To Customer Site Use Identifier
37530  , p_source_31            IN NUMBER
37531 --SLA Party Type
37532  , p_source_32            IN VARCHAR2
37533 --Transaction Distribution Account Class
37534  , p_source_33            IN VARCHAR2
37535 --Transaction Distribution Identifier
37536  , p_source_34            IN NUMBER
37537 --Transaction Distribution Type
37538  , p_source_35            IN VARCHAR2
37539 --Transaction Distribution Entered Amount
37540  , p_source_36            IN NUMBER
37541 --Transaction Currency Code
37542  , p_source_37            IN VARCHAR2
37543 --Transaction Exchange Date
37544  , p_source_38            IN DATE
37545 --Transaction Exchange Rate
37546  , p_source_39            IN NUMBER
37547 --Transaction Exchange Rate Type
37548  , p_source_40            IN VARCHAR2
37549 --Transaction Accounting Amount
37550  , p_source_41            IN NUMBER
37551 --Transaction Tax Line Identifier
37552  , p_source_55            IN NUMBER
37553 --Rounding Correction Flag
37554  , p_source_66            IN VARCHAR2
37555 )
37556 IS
37557 
37558 l_component_type              VARCHAR2(80);
37559 l_component_code              VARCHAR2(30);
37560 l_component_type_code         VARCHAR2(1);
37561 l_component_appl_id           INTEGER;
37562 l_amb_context_code            VARCHAR2(30);
37563 l_entity_code                 VARCHAR2(30);
37564 l_event_class_code            VARCHAR2(30);
37565 l_ae_header_id                NUMBER;
37566 l_event_type_code             VARCHAR2(30);
37567 l_line_definition_code        VARCHAR2(30);
37568 l_line_definition_owner_code  VARCHAR2(1);
37569 --
37570 -- adr variables
37571 l_segment                     VARCHAR2(30);
37572 l_ccid                        NUMBER;
37573 l_adr_transaction_coa_id      NUMBER;
37574 l_adr_accounting_coa_id       NUMBER;
37575 l_adr_flexfield_segment_code  VARCHAR2(30);
37576 l_adr_flex_value_set_id       NUMBER;
37577 l_adr_value_type_code         VARCHAR2(30);
37578 l_adr_value_combination_id    NUMBER;
37579 l_adr_value_segment_code      VARCHAR2(30);
37580 
37581 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
37582 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
37583 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
37584 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
37585 
37586 -- 4262811 Variables ------------------------------------------------------------------------------------------
37587 l_entered_amt_idx             NUMBER;
37588 l_accted_amt_idx              NUMBER;
37589 l_acc_rev_flag                VARCHAR2(1);
37590 l_accrual_line_num            NUMBER;
37591 l_tmp_amt                     NUMBER;
37592 l_acc_rev_natural_side_code   VARCHAR2(1);
37593 
37594 l_num_entries                 NUMBER;
37595 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
37596 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
37597 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
37598 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
37599 l_recog_line_1                NUMBER;
37600 l_recog_line_2                NUMBER;
37601 
37602 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
37603 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
37604 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
37605 
37606 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
37607 
37608 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
37609 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
37610 
37611 ---------------------------------------------------------------------------------------------------------------
37612 
37613 
37614 --
37615 -- bulk performance
37616 --
37617 l_balance_type_code           VARCHAR2(1);
37618 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
37619 l_log_module                  VARCHAR2(240);
37620 
37621 --
37622 -- Upgrade strategy
37623 --
37624 l_actual_upg_option           VARCHAR2(1);
37625 l_enc_upg_option           VARCHAR2(1);
37626 
37627 --
37628 BEGIN
37629 --
37630 IF g_log_enabled THEN
37631       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_85';
37632 END IF;
37633 --
37634 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
37635 
37636       trace
37637          (p_msg      => 'BEGIN of AcctLineType_85'
37638          ,p_level    => C_LEVEL_PROCEDURE
37639          ,p_module   => l_log_module);
37640 
37641 END IF;
37645 l_component_type_code        := 'S';
37642 --
37643 l_component_type             := 'AMB_JLT';
37644 l_component_code             := 'INV_UNEARN';
37646 l_component_appl_id          :=  222;
37647 l_amb_context_code           := 'DEFAULT';
37648 l_entity_code                := 'TRANSACTIONS';
37649 l_event_class_code           := 'INVOICE';
37650 l_event_type_code            := 'INVOICE_ALL';
37651 l_line_definition_owner_code := 'S';
37652 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
37653 --
37654 l_balance_type_code          := 'A';
37655 l_segment                     := NULL;
37656 l_ccid                        := NULL;
37657 l_adr_transaction_coa_id      := NULL;
37658 l_adr_accounting_coa_id       := NULL;
37659 l_adr_flexfield_segment_code  := NULL;
37660 l_adr_flex_value_set_id       := NULL;
37661 l_adr_value_type_code         := NULL;
37662 l_adr_value_combination_id    := NULL;
37663 l_adr_value_segment_code      := NULL;
37664 
37665 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
37666 l_bflow_class_code           := '';    -- 4219869 Business Flow
37667 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
37668 l_budgetary_control_flag     := 'N';
37669 
37670 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
37671 l_bflow_applied_to_amt       := NULL; -- 5132302
37672 l_entered_amt_idx            := NULL;          -- 4262811
37673 l_accted_amt_idx             := NULL;          -- 4262811
37674 l_acc_rev_flag               := NULL;          -- 4262811
37675 l_accrual_line_num           := NULL;          -- 4262811
37676 l_tmp_amt                    := NULL;          -- 4262811
37677 --
37678  
37679 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
37680     l_balance_type_code <> 'B' THEN
37681 IF NVL(p_source_33,'
37682 ') =  'UNEARN' AND 
37683 p_source_66 IS NULL 
37684  THEN 
37685 
37686    --
37687    XLA_AE_LINES_PKG.SetNewLine;
37688 
37689    p_balance_type_code          := l_balance_type_code;
37690    -- set the flag so later we will know whether the gain loss line needs to be created
37691    
37692    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
37693      p_actual_flag :='A';
37694    END IF;
37695 
37696    --
37697    -- bulk performance
37698    --
37699    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
37700                                       p_header_num   => 0); -- 4262811
37701    --
37702    -- set accounting line options
37703    --
37704    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
37705            p_natural_side_code          => 'C'
37706          , p_gain_or_loss_flag          => 'N'
37707          , p_gl_transfer_mode_code      => 'S'
37708          , p_acct_entry_type_code       => 'A'
37709          , p_switch_side_flag           => 'Y'
37710          , p_merge_duplicate_code       => 'A'
37711          );
37712    --
37713    l_acc_rev_natural_side_code := 'D';  -- 4262811
37714    -- 
37715    --
37716    -- set accounting line type info
37717    --
37718    xla_ae_lines_pkg.SetAcctLineType
37719       (p_component_type             => l_component_type
37720       ,p_event_type_code            => l_event_type_code
37721       ,p_line_definition_owner_code => l_line_definition_owner_code
37722       ,p_line_definition_code       => l_line_definition_code
37723       ,p_accounting_line_code       => l_component_code
37724       ,p_accounting_line_type_code  => l_component_type_code
37725       ,p_accounting_line_appl_id    => l_component_appl_id
37726       ,p_amb_context_code           => l_amb_context_code
37727       ,p_entity_code                => l_entity_code
37728       ,p_event_class_code           => l_event_class_code);
37729    --
37730    -- set accounting class
37731    --
37732    xla_ae_lines_pkg.SetAcctClass(
37733            p_accounting_class_code  => 'UNEARNED_REVENUE'
37734          , p_ae_header_id           => l_ae_header_id
37735          );
37736 
37737    --
37738    -- set rounding class
37739    --
37740    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
37741                       'RECEIVABLE';
37742 
37743    --
37744    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
37745    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
37746    --
37747    -- bulk performance
37748    --
37749    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
37750 
37751    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
37752       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
37753 
37754    -- 4955764
37755    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
37756       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
37757 
37758    -- 4458381 Public Sector Enh
37759    
37760    --
37761    -- set accounting attributes for the line type
37762    --
37763    l_entered_amt_idx := 3;
37764    l_accted_amt_idx  := 8;
37765    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
37766    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
37767    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
37771    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
37768    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
37769    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
37770    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
37772    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
37773    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
37774    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
37775    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
37776    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
37777    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
37778    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
37779    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
37780    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
37781    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
37782    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
37783    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
37784    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
37785    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
37786    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
37787    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
37788    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
37789    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
37790 
37791    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
37792    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
37793 
37794    ---------------------------------------------------------------------------------------------------------------
37795    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
37796    ---------------------------------------------------------------------------------------------------------------
37797    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
37798 
37799    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
37800    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
37801 
37802    IF xla_accounting_cache_pkg.GetValueChar
37803          (p_source_code         => 'LEDGER_CATEGORY_CODE'
37804          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
37805    AND l_bflow_method_code = 'PRIOR_ENTRY'
37806 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
37807    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
37808          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
37809        )
37810    THEN
37811          xla_ae_lines_pkg.BflowUpgEntry
37812            (p_business_method_code    => l_bflow_method_code
37813            ,p_business_class_code     => l_bflow_class_code
37814            ,p_balance_type            => l_balance_type_code);
37815    ELSE
37816       NULL;
37817 -- No business flow processing for business flow method of NONE.
37818    END IF;
37819 
37820    --
37821    -- call analytical criteria
37822    --
37823    
37824    --
37825    -- call description
37826    --
37827    -- No description or it is inherited.
37828    --
37829    -- call ADRs
37830    -- Bug 4922099
37831    --
37832    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
37833         (NVL(l_actual_upg_option, 'N') = 'O') OR
37834         (NVL(l_enc_upg_option, 'N') = 'O')
37835       )
37836    THEN
37837    NULL;
37838    --
37839    --
37840    
37841   l_ccid := AcctDerRule_32(
37842            p_application_id           => p_application_id
37843          , p_ae_header_id             => l_ae_header_id 
37844 , p_source_4 => p_source_4
37845          , x_transaction_coa_id       => l_adr_transaction_coa_id
37846          , x_accounting_coa_id        => l_adr_accounting_coa_id
37847          , x_value_type_code          => l_adr_value_type_code
37848          , p_side                     => 'NA'
37849    );
37850 
37851    xla_ae_lines_pkg.set_ccid(
37852     p_code_combination_id          => l_ccid
37853   , p_value_type_code              => l_adr_value_type_code
37854   , p_transaction_coa_id           => l_adr_transaction_coa_id
37855   , p_accounting_coa_id            => l_adr_accounting_coa_id
37856   , p_adr_code                     => 'TRX_DIST_CCID'
37857   , p_adr_type_code                => 'S'
37858   , p_component_type               => l_component_type
37859   , p_component_code               => l_component_code
37860   , p_component_type_code          => l_component_type_code
37861   , p_component_appl_id            => l_component_appl_id
37862   , p_amb_context_code             => l_amb_context_code
37863   , p_side                         => 'NA'
37864   );
37865 
37866 
37867    --
37868    --
37869    END IF;
37870    --
37871    -- Bug 4922099
37872    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
37873           (NVL(l_enc_upg_option, 'N') = 'O')
37874         ) AND
37875         (l_bflow_method_code = 'PRIOR_ENTRY')
37876       )
37877    THEN
37878       IF
37879       --
37880       1 = 2
37881       --
37882       THEN
37883       xla_accounting_err_pkg.build_message
37884                                     (p_appli_s_name            => 'XLA'
37888                                     ,p_token_2                 => 'LINE_TYPE_NAME'
37885                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
37886                                     ,p_token_1                 => 'LINE_NUMBER'
37887                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
37889                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
37890                                                                              l_component_type
37891                                                                             ,l_component_code
37892                                                                             ,l_component_type_code
37893                                                                             ,l_component_appl_id
37894                                                                             ,l_amb_context_code
37895                                                                             ,l_entity_code
37896                                                                             ,l_event_class_code
37897                                                                            )
37898                                     ,p_token_3                 => 'OWNER'
37899                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
37900                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
37901                                                                           ,p_lookup_code    => l_component_type_code
37902                                                                          )
37903                                     ,p_token_4                 => 'PRODUCT_NAME'
37904                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
37905                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
37906                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
37907                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
37908                                     ,p_ae_header_id            =>  NULL
37909                                        );
37910 
37911         IF (C_LEVEL_ERROR>= g_log_level) THEN
37912                  trace
37913                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
37914                       ,p_level    => C_LEVEL_ERROR
37915                       ,p_module   => l_log_module);
37916         END IF;
37917       END IF;
37918    END IF;
37919    --
37920    --
37921    ------------------------------------------------------------------------------------------------
37922    -- 4219869 Business Flow
37923    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
37924    -- Prior Entry.  Currently, the following code is always generated.
37925    ------------------------------------------------------------------------------------------------
37926    XLA_AE_LINES_PKG.ValidateCurrentLine;
37927 
37928    ------------------------------------------------------------------------------------
37929    -- 4219869 Business Flow
37930    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
37931    ------------------------------------------------------------------------------------
37932    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
37933 
37934    ----------------------------------------------------------------------------------
37935    -- 4219869 Business Flow
37936    -- Update journal entry status -- Need to generate this within IF <condition>
37937    ----------------------------------------------------------------------------------
37938    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
37939          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
37940          ,p_balance_type_code => l_balance_type_code
37941          );
37942 
37943    -------------------------------------------------------------------------------------------
37944    -- 4262811 - Generate the Accrual Reversal lines
37945    -------------------------------------------------------------------------------------------
37946    BEGIN
37947       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
37948                               (g_array_event(p_event_id).array_value_num('header_index'));
37949       IF l_acc_rev_flag IS NULL THEN
37950          l_acc_rev_flag := 'N';
37951       END IF;
37952    EXCEPTION
37953       WHEN OTHERS THEN
37954          l_acc_rev_flag := 'N';
37955    END;
37956    --
37957    IF (l_acc_rev_flag = 'Y') THEN
37958 
37959        -- 4645092  ------------------------------------------------------------------------------
37960        -- To allow MPA report to determine if it should generate report process
37961        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
37962        ------------------------------------------------------------------------------------------
37963 
37964        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
37965        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
37966    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
37967    -- call ADRs
37968    -- Bug 4922099
37969    --
37970    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
37971         (NVL(l_actual_upg_option, 'N') = 'O') OR
37975    NULL;
37972         (NVL(l_enc_upg_option, 'N') = 'O')
37973       )
37974    THEN
37976    --
37977    --
37978    
37979   l_ccid := AcctDerRule_32(
37980            p_application_id           => p_application_id
37981          , p_ae_header_id             => l_ae_header_id 
37982 , p_source_4 => p_source_4
37983          , x_transaction_coa_id       => l_adr_transaction_coa_id
37984          , x_accounting_coa_id        => l_adr_accounting_coa_id
37985          , x_value_type_code          => l_adr_value_type_code
37986          , p_side                     => 'NA'
37987    );
37988 
37989    xla_ae_lines_pkg.set_ccid(
37990     p_code_combination_id          => l_ccid
37991   , p_value_type_code              => l_adr_value_type_code
37992   , p_transaction_coa_id           => l_adr_transaction_coa_id
37993   , p_accounting_coa_id            => l_adr_accounting_coa_id
37994   , p_adr_code                     => 'TRX_DIST_CCID'
37995   , p_adr_type_code                => 'S'
37996   , p_component_type               => l_component_type
37997   , p_component_code               => l_component_code
37998   , p_component_type_code          => l_component_type_code
37999   , p_component_appl_id            => l_component_appl_id
38000   , p_amb_context_code             => l_amb_context_code
38001   , p_side                         => 'NA'
38002   );
38003 
38004 
38005    --
38006    --
38007    END IF;
38008 
38009        --
38010        -- Update the line information that should be overwritten
38011        --
38012        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
38013                                          p_header_num   => 1);
38014        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
38015 
38016        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
38017 
38018        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
38019           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
38020        END IF;
38021 
38022       --
38023       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
38024       --
38025       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
38026           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
38027       ELSE
38028           ---------------------------------------------------------------------------------------------------
38029           -- 4262811a Switch Sign
38030           ---------------------------------------------------------------------------------------------------
38031           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
38032           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
38033                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
38034           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
38035                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
38036           -- 5132302
38037           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
38038                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
38039 
38040       END IF;
38041 
38042       -- 4955764
38043       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
38044       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
38045 
38046 
38047       XLA_AE_LINES_PKG.ValidateCurrentLine;
38048       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
38049 
38050       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
38051                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
38052                ,p_balance_type_code => l_balance_type_code);
38053 
38054    END IF;
38055 
38056    -----------------------------------------------------------------------------------------
38057    -- 4262811 Multiperiod Accounting
38058    -----------------------------------------------------------------------------------------
38059      -- No MPA option is assigned.
38060 
38061 
38062 END IF;
38063 END IF;
38064 --
38065 
38066 --
38067 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
38068    trace
38069       (p_msg      => 'END of AcctLineType_85'
38070       ,p_level    => C_LEVEL_PROCEDURE
38071       ,p_module   => l_log_module);
38072 END IF;
38073 --
38074 EXCEPTION
38075   WHEN xla_exceptions_pkg.application_exception THEN
38076       RAISE;
38077   WHEN OTHERS THEN
38078        xla_exceptions_pkg.raise_message
38079            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_85');
38080 END AcctLineType_85;
38081 --
38082 
38083 ---------------------------------------
38084 --
38085 -- PRIVATE FUNCTION
38086 --         AcctLineType_86
38087 --
38088 ---------------------------------------
38089 PROCEDURE AcctLineType_86 (
38090   p_application_id        IN NUMBER
38091  ,p_event_id              IN NUMBER
38092  ,p_calculate_acctd_flag  IN VARCHAR2
38093  ,p_calculate_g_l_flag    IN VARCHAR2
38094  ,p_actual_flag           IN OUT VARCHAR2
38098 --Distribution GL Account
38095  ,p_balance_type_code     OUT VARCHAR2
38096  ,p_gain_or_loss_ref      OUT VARCHAR2
38097  
38099  , p_source_3            IN NUMBER
38100 --Transaction Default Receivable Account
38101  , p_source_16            IN NUMBER
38102 --Distribution Source Type
38103  , p_source_20            IN VARCHAR2
38104 --Receivable Activity Type
38105  , p_source_21            IN VARCHAR2
38106 --Distribution Line Identifier
38107  , p_source_22            IN NUMBER
38108 --Distribution Type
38109  , p_source_23            IN VARCHAR2
38110 --Entered Amount
38111  , p_source_24            IN NUMBER
38112 --Currency Code
38113  , p_source_25            IN VARCHAR2
38114 --Exchange Date
38115  , p_source_26            IN DATE
38116 --Exchange Rate
38117  , p_source_27            IN NUMBER
38118 --Exchange Rate Type
38119  , p_source_28            IN VARCHAR2
38120 --Applied To Document Accounting Amount
38121  , p_source_29            IN NUMBER
38122 --Bill To Customer Account Identifier
38123  , p_source_30            IN NUMBER
38124 --Bill To Customer Site Use Identifier
38125  , p_source_31            IN NUMBER
38126 --SLA Party Type
38127  , p_source_32            IN VARCHAR2
38128 )
38129 IS
38130 
38131 l_component_type              VARCHAR2(80);
38132 l_component_code              VARCHAR2(30);
38133 l_component_type_code         VARCHAR2(1);
38134 l_component_appl_id           INTEGER;
38135 l_amb_context_code            VARCHAR2(30);
38136 l_entity_code                 VARCHAR2(30);
38137 l_event_class_code            VARCHAR2(30);
38138 l_ae_header_id                NUMBER;
38139 l_event_type_code             VARCHAR2(30);
38140 l_line_definition_code        VARCHAR2(30);
38141 l_line_definition_owner_code  VARCHAR2(1);
38142 --
38143 -- adr variables
38144 l_segment                     VARCHAR2(30);
38145 l_ccid                        NUMBER;
38146 l_adr_transaction_coa_id      NUMBER;
38147 l_adr_accounting_coa_id       NUMBER;
38148 l_adr_flexfield_segment_code  VARCHAR2(30);
38149 l_adr_flex_value_set_id       NUMBER;
38150 l_adr_value_type_code         VARCHAR2(30);
38151 l_adr_value_combination_id    NUMBER;
38152 l_adr_value_segment_code      VARCHAR2(30);
38153 
38154 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
38155 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
38156 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
38157 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
38158 
38159 -- 4262811 Variables ------------------------------------------------------------------------------------------
38160 l_entered_amt_idx             NUMBER;
38161 l_accted_amt_idx              NUMBER;
38162 l_acc_rev_flag                VARCHAR2(1);
38163 l_accrual_line_num            NUMBER;
38164 l_tmp_amt                     NUMBER;
38165 l_acc_rev_natural_side_code   VARCHAR2(1);
38166 
38167 l_num_entries                 NUMBER;
38168 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
38169 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
38170 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
38171 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
38172 l_recog_line_1                NUMBER;
38173 l_recog_line_2                NUMBER;
38174 
38175 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
38176 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
38177 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
38178 
38179 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
38180 
38181 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
38182 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
38183 
38184 ---------------------------------------------------------------------------------------------------------------
38185 
38186 
38187 --
38188 -- bulk performance
38189 --
38190 l_balance_type_code           VARCHAR2(1);
38191 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
38192 l_log_module                  VARCHAR2(240);
38193 
38194 --
38195 -- Upgrade strategy
38196 --
38197 l_actual_upg_option           VARCHAR2(1);
38198 l_enc_upg_option           VARCHAR2(1);
38199 
38200 --
38201 BEGIN
38202 --
38203 IF g_log_enabled THEN
38204       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_86';
38205 END IF;
38206 --
38207 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
38208 
38209       trace
38210          (p_msg      => 'BEGIN of AcctLineType_86'
38211          ,p_level    => C_LEVEL_PROCEDURE
38212          ,p_module   => l_log_module);
38213 
38214 END IF;
38215 --
38216 l_component_type             := 'AMB_JLT';
38217 l_component_code             := 'MFAR_ADJ_REC';
38218 l_component_type_code        := 'S';
38219 l_component_appl_id          :=  222;
38220 l_amb_context_code           := 'DEFAULT';
38221 l_entity_code                := 'ADJUSTMENTS';
38222 l_event_class_code           := 'ADJUSTMENT';
38223 l_event_type_code            := 'ADJUSTMENT_ALL';
38224 l_line_definition_owner_code := 'S';
38225 l_line_definition_code       := 'MFAR_ADJ_ACCRUAL_BALANCING';
38226 --
38227 l_balance_type_code          := 'A';
38228 l_segment                     := NULL;
38229 l_ccid                        := NULL;
38233 l_adr_flex_value_set_id       := NULL;
38230 l_adr_transaction_coa_id      := NULL;
38231 l_adr_accounting_coa_id       := NULL;
38232 l_adr_flexfield_segment_code  := NULL;
38234 l_adr_value_type_code         := NULL;
38235 l_adr_value_combination_id    := NULL;
38236 l_adr_value_segment_code      := NULL;
38237 
38238 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
38239 l_bflow_class_code           := 'RECEIVABLE';    -- 4219869 Business Flow
38240 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
38241 l_budgetary_control_flag     := 'N';
38242 
38243 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
38244 l_bflow_applied_to_amt       := NULL; -- 5132302
38245 l_entered_amt_idx            := NULL;          -- 4262811
38246 l_accted_amt_idx             := NULL;          -- 4262811
38247 l_acc_rev_flag               := NULL;          -- 4262811
38248 l_accrual_line_num           := NULL;          -- 4262811
38249 l_tmp_amt                    := NULL;          -- 4262811
38250 --
38251  
38252 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
38253     l_balance_type_code <> 'B' THEN
38254 IF NVL(p_source_20,'
38255 ') =  'TAX' OR 
38256 NVL(p_source_20,'
38257 ') =  'DEFERRED_TAX' OR 
38258 NVL(p_source_20,'
38259 ') =  'FINCHRG' OR 
38260 (NVL(p_source_20,'
38261 ') =  'ADJ' AND 
38262 NVL(p_source_21,'
38263 ') =  'ENDORSEMENT') OR 
38264 (NVL(p_source_20,'
38265 ') =  'ADJ' AND 
38266 NVL(p_source_21,'
38267 ') <>  'ENDORSEMENT')
38268  THEN 
38269 
38270    --
38271    XLA_AE_LINES_PKG.SetNewLine;
38272 
38273    p_balance_type_code          := l_balance_type_code;
38274    -- set the flag so later we will know whether the gain loss line needs to be created
38275    
38276    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
38277      p_actual_flag :='A';
38278    END IF;
38279 
38280    --
38281    -- bulk performance
38282    --
38283    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
38284                                       p_header_num   => 0); -- 4262811
38285    --
38286    -- set accounting line options
38287    --
38288    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
38289            p_natural_side_code          => 'D'
38290          , p_gain_or_loss_flag          => 'N'
38291          , p_gl_transfer_mode_code      => 'S'
38292          , p_acct_entry_type_code       => 'A'
38293          , p_switch_side_flag           => 'Y'
38294          , p_merge_duplicate_code       => 'A'
38295          );
38296    --
38297    l_acc_rev_natural_side_code := 'C';  -- 4262811
38298    -- 
38299    --
38300    -- set accounting line type info
38301    --
38302    xla_ae_lines_pkg.SetAcctLineType
38303       (p_component_type             => l_component_type
38304       ,p_event_type_code            => l_event_type_code
38305       ,p_line_definition_owner_code => l_line_definition_owner_code
38306       ,p_line_definition_code       => l_line_definition_code
38307       ,p_accounting_line_code       => l_component_code
38308       ,p_accounting_line_type_code  => l_component_type_code
38309       ,p_accounting_line_appl_id    => l_component_appl_id
38310       ,p_amb_context_code           => l_amb_context_code
38311       ,p_entity_code                => l_entity_code
38312       ,p_event_class_code           => l_event_class_code);
38313    --
38314    -- set accounting class
38315    --
38316    xla_ae_lines_pkg.SetAcctClass(
38317            p_accounting_class_code  => 'RECEIVABLE'
38318          , p_ae_header_id           => l_ae_header_id
38319          );
38320 
38321    --
38322    -- set rounding class
38323    --
38324    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
38325                       'RECEIVABLE';
38326 
38327    --
38328    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
38329    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
38330    --
38331    -- bulk performance
38332    --
38333    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
38334 
38335    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
38336       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
38337 
38338    -- 4955764
38339    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
38340       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
38341 
38342    -- 4458381 Public Sector Enh
38343    
38344    --
38345    -- set accounting attributes for the line type
38346    --
38347    l_entered_amt_idx := 3;
38348    l_accted_amt_idx  := 8;
38349    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
38350    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
38351    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
38352    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
38353    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
38354    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
38355    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
38356    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
38360    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
38357    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
38358    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
38359    l_rec_acct_attrs.array_date_value(5)  := p_source_26;
38361    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
38362    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
38363    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
38364    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
38365    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
38366    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
38367    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
38368    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
38369    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
38370    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
38371    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
38372 
38373    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
38374    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
38375 
38376    ---------------------------------------------------------------------------------------------------------------
38377    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
38378    ---------------------------------------------------------------------------------------------------------------
38379    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
38380 
38381    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
38382    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
38383 
38384    IF xla_accounting_cache_pkg.GetValueChar
38385          (p_source_code         => 'LEDGER_CATEGORY_CODE'
38386          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
38387    AND l_bflow_method_code = 'PRIOR_ENTRY'
38388 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
38389    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
38390          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
38391        )
38392    THEN
38393          xla_ae_lines_pkg.BflowUpgEntry
38394            (p_business_method_code    => l_bflow_method_code
38395            ,p_business_class_code     => l_bflow_class_code
38396            ,p_balance_type            => l_balance_type_code);
38397    ELSE
38398       NULL;
38399 -- No business flow processing for business flow method of NONE.
38400    END IF;
38401 
38402    --
38403    -- call analytical criteria
38404    --
38405    
38406    --
38407    -- call description
38408    --
38409    
38410 xla_ae_lines_pkg.SetLineDescription(
38411    p_ae_header_id => l_ae_header_id
38412   ,p_description  => Description_1 (
38413      p_application_id         => p_application_id
38414    , p_ae_header_id           => l_ae_header_id 
38415    )
38416 );
38417 
38418 
38419    --
38420    -- call ADRs
38421    -- Bug 4922099
38422    --
38423    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
38424         (NVL(l_actual_upg_option, 'N') = 'O') OR
38425         (NVL(l_enc_upg_option, 'N') = 'O')
38426       )
38427    THEN
38428    NULL;
38429    --
38430    --
38431    
38432   l_ccid := AcctDerRule_28(
38433            p_application_id           => p_application_id
38434          , p_ae_header_id             => l_ae_header_id 
38435 , p_source_16 => p_source_16
38436          , x_transaction_coa_id       => l_adr_transaction_coa_id
38437          , x_accounting_coa_id        => l_adr_accounting_coa_id
38438          , x_value_type_code          => l_adr_value_type_code
38439          , p_side                     => 'NA'
38440    );
38441 
38442    xla_ae_lines_pkg.set_ccid(
38443     p_code_combination_id          => l_ccid
38444   , p_value_type_code              => l_adr_value_type_code
38445   , p_transaction_coa_id           => l_adr_transaction_coa_id
38446   , p_accounting_coa_id            => l_adr_accounting_coa_id
38447   , p_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
38448   , p_adr_type_code                => 'S'
38449   , p_component_type               => l_component_type
38450   , p_component_code               => l_component_code
38451   , p_component_type_code          => l_component_type_code
38452   , p_component_appl_id            => l_component_appl_id
38453   , p_amb_context_code             => l_amb_context_code
38454   , p_side                         => 'NA'
38455   );
38456 
38457 
38458    l_segment := AcctDerRule_4(
38459            p_application_id           => p_application_id
38460          , p_ae_header_id             => l_ae_header_id 
38461 , p_source_3 => p_source_3
38462          , x_transaction_coa_id       => l_adr_transaction_coa_id
38463          , x_accounting_coa_id        => l_adr_accounting_coa_id
38464          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
38465          , x_flex_value_set_id        => l_adr_flex_value_set_id
38466          , x_value_type_code          => l_adr_value_type_code
38467          , x_value_combination_id     => l_adr_value_combination_id
38468          , x_value_segment_code       => l_adr_value_segment_code
38469          , p_side                     => 'NA'
38470          , p_override_seg_flag        => 'Y'
38471    );
38475       xla_ae_lines_pkg.set_segment(
38472 
38473    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
38474 
38476           p_to_segment_code         => 'GL_BALANCING'
38477         , p_segment_value           => l_segment
38478         , p_from_segment_code       => l_adr_value_segment_code
38479         , p_from_combination_id     => l_adr_value_combination_id
38480         , p_value_type_code         => l_adr_value_type_code
38481         , p_transaction_coa_id      => l_adr_transaction_coa_id
38482         , p_accounting_coa_id       => l_adr_accounting_coa_id
38483         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
38484         , p_flex_value_set_id       => l_adr_flex_value_set_id
38485         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
38486         , p_adr_type_code           => 'S'
38487         , p_component_type          => l_component_type
38488         , p_component_code          => l_component_code
38489         , p_component_type_code     => l_component_type_code
38490         , p_component_appl_id       => l_component_appl_id
38491         , p_amb_context_code        => l_amb_context_code
38492         , p_entity_code             => 'ADJUSTMENTS'
38493         , p_event_class_code        => 'ADJUSTMENT'
38494         , p_side                    => 'NA'
38495         );
38496 
38497   END IF;
38498 
38499    --
38500    --
38501    END IF;
38502    --
38503    -- Bug 4922099
38504    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
38505           (NVL(l_enc_upg_option, 'N') = 'O')
38506         ) AND
38507         (l_bflow_method_code = 'PRIOR_ENTRY')
38508       )
38509    THEN
38510       IF
38511       --
38512       1 = 2
38513       --
38514       THEN
38515       xla_accounting_err_pkg.build_message
38516                                     (p_appli_s_name            => 'XLA'
38517                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
38518                                     ,p_token_1                 => 'LINE_NUMBER'
38519                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
38520                                     ,p_token_2                 => 'LINE_TYPE_NAME'
38521                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
38522                                                                              l_component_type
38523                                                                             ,l_component_code
38524                                                                             ,l_component_type_code
38525                                                                             ,l_component_appl_id
38526                                                                             ,l_amb_context_code
38527                                                                             ,l_entity_code
38528                                                                             ,l_event_class_code
38529                                                                            )
38530                                     ,p_token_3                 => 'OWNER'
38531                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
38532                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
38533                                                                           ,p_lookup_code    => l_component_type_code
38534                                                                          )
38535                                     ,p_token_4                 => 'PRODUCT_NAME'
38536                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
38537                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
38538                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
38539                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
38540                                     ,p_ae_header_id            =>  NULL
38541                                        );
38542 
38543         IF (C_LEVEL_ERROR>= g_log_level) THEN
38544                  trace
38545                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
38546                       ,p_level    => C_LEVEL_ERROR
38547                       ,p_module   => l_log_module);
38548         END IF;
38549       END IF;
38550    END IF;
38551    --
38552    --
38553    ------------------------------------------------------------------------------------------------
38554    -- 4219869 Business Flow
38555    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
38556    -- Prior Entry.  Currently, the following code is always generated.
38557    ------------------------------------------------------------------------------------------------
38558    XLA_AE_LINES_PKG.ValidateCurrentLine;
38559 
38560    ------------------------------------------------------------------------------------
38561    -- 4219869 Business Flow
38562    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
38563    ------------------------------------------------------------------------------------
38564    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
38565 
38566    ----------------------------------------------------------------------------------
38570    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
38567    -- 4219869 Business Flow
38568    -- Update journal entry status -- Need to generate this within IF <condition>
38569    ----------------------------------------------------------------------------------
38571          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
38572          ,p_balance_type_code => l_balance_type_code
38573          );
38574 
38575    -------------------------------------------------------------------------------------------
38576    -- 4262811 - Generate the Accrual Reversal lines
38577    -------------------------------------------------------------------------------------------
38578    BEGIN
38579       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
38580                               (g_array_event(p_event_id).array_value_num('header_index'));
38581       IF l_acc_rev_flag IS NULL THEN
38582          l_acc_rev_flag := 'N';
38583       END IF;
38584    EXCEPTION
38585       WHEN OTHERS THEN
38586          l_acc_rev_flag := 'N';
38587    END;
38588    --
38589    IF (l_acc_rev_flag = 'Y') THEN
38590 
38591        -- 4645092  ------------------------------------------------------------------------------
38592        -- To allow MPA report to determine if it should generate report process
38593        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
38594        ------------------------------------------------------------------------------------------
38595 
38596        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
38597        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
38598    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
38599    -- call ADRs
38600    -- Bug 4922099
38601    --
38602    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
38603         (NVL(l_actual_upg_option, 'N') = 'O') OR
38604         (NVL(l_enc_upg_option, 'N') = 'O')
38605       )
38606    THEN
38607    NULL;
38608    --
38609    --
38610    
38611   l_ccid := AcctDerRule_28(
38612            p_application_id           => p_application_id
38613          , p_ae_header_id             => l_ae_header_id 
38614 , p_source_16 => p_source_16
38615          , x_transaction_coa_id       => l_adr_transaction_coa_id
38616          , x_accounting_coa_id        => l_adr_accounting_coa_id
38617          , x_value_type_code          => l_adr_value_type_code
38618          , p_side                     => 'NA'
38619    );
38620 
38621    xla_ae_lines_pkg.set_ccid(
38622     p_code_combination_id          => l_ccid
38623   , p_value_type_code              => l_adr_value_type_code
38624   , p_transaction_coa_id           => l_adr_transaction_coa_id
38625   , p_accounting_coa_id            => l_adr_accounting_coa_id
38626   , p_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
38627   , p_adr_type_code                => 'S'
38628   , p_component_type               => l_component_type
38629   , p_component_code               => l_component_code
38630   , p_component_type_code          => l_component_type_code
38631   , p_component_appl_id            => l_component_appl_id
38632   , p_amb_context_code             => l_amb_context_code
38633   , p_side                         => 'NA'
38634   );
38635 
38636 
38637    l_segment := AcctDerRule_4(
38638            p_application_id           => p_application_id
38639          , p_ae_header_id             => l_ae_header_id 
38640 , p_source_3 => p_source_3
38641          , x_transaction_coa_id       => l_adr_transaction_coa_id
38642          , x_accounting_coa_id        => l_adr_accounting_coa_id
38643          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
38644          , x_flex_value_set_id        => l_adr_flex_value_set_id
38645          , x_value_type_code          => l_adr_value_type_code
38646          , x_value_combination_id     => l_adr_value_combination_id
38647          , x_value_segment_code       => l_adr_value_segment_code
38648          , p_side                     => 'NA'
38649          , p_override_seg_flag        => 'Y'
38650    );
38651 
38652    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
38653 
38654       xla_ae_lines_pkg.set_segment(
38655           p_to_segment_code         => 'GL_BALANCING'
38656         , p_segment_value           => l_segment
38657         , p_from_segment_code       => l_adr_value_segment_code
38658         , p_from_combination_id     => l_adr_value_combination_id
38659         , p_value_type_code         => l_adr_value_type_code
38660         , p_transaction_coa_id      => l_adr_transaction_coa_id
38661         , p_accounting_coa_id       => l_adr_accounting_coa_id
38662         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
38663         , p_flex_value_set_id       => l_adr_flex_value_set_id
38664         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
38665         , p_adr_type_code           => 'S'
38666         , p_component_type          => l_component_type
38667         , p_component_code          => l_component_code
38668         , p_component_type_code     => l_component_type_code
38669         , p_component_appl_id       => l_component_appl_id
38670         , p_amb_context_code        => l_amb_context_code
38671         , p_entity_code             => 'ADJUSTMENTS'
38672         , p_event_class_code        => 'ADJUSTMENT'
38673         , p_side                    => 'NA'
38674         );
38675 
38676   END IF;
38677 
38678    --
38679    --
38680    END IF;
38681 
38682        --
38683        -- Update the line information that should be overwritten
38687        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
38684        --
38685        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
38686                                          p_header_num   => 1);
38688 
38689        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
38690 
38691        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
38692           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
38693        END IF;
38694 
38695       --
38696       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
38697       --
38698       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
38699           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
38700       ELSE
38701           ---------------------------------------------------------------------------------------------------
38702           -- 4262811a Switch Sign
38703           ---------------------------------------------------------------------------------------------------
38704           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
38705           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
38706                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
38707           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
38708                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
38709           -- 5132302
38710           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
38711                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
38712 
38713       END IF;
38714 
38715       -- 4955764
38716       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
38717       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
38718 
38719 
38720       XLA_AE_LINES_PKG.ValidateCurrentLine;
38721       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
38722 
38723       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
38724                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
38725                ,p_balance_type_code => l_balance_type_code);
38726 
38727    END IF;
38728 
38729    -----------------------------------------------------------------------------------------
38730    -- 4262811 Multiperiod Accounting
38731    -----------------------------------------------------------------------------------------
38732      -- No MPA option is assigned.
38733 
38734 
38735 END IF;
38736 END IF;
38737 --
38738 
38739 --
38740 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
38741    trace
38742       (p_msg      => 'END of AcctLineType_86'
38743       ,p_level    => C_LEVEL_PROCEDURE
38744       ,p_module   => l_log_module);
38745 END IF;
38746 --
38747 EXCEPTION
38748   WHEN xla_exceptions_pkg.application_exception THEN
38749       RAISE;
38750   WHEN OTHERS THEN
38751        xla_exceptions_pkg.raise_message
38752            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_86');
38753 END AcctLineType_86;
38754 --
38755 
38756 ---------------------------------------
38757 --
38758 -- PRIVATE FUNCTION
38759 --         AcctLineType_87
38760 --
38761 ---------------------------------------
38762 PROCEDURE AcctLineType_87 (
38763   p_application_id        IN NUMBER
38764  ,p_event_id              IN NUMBER
38765  ,p_calculate_acctd_flag  IN VARCHAR2
38766  ,p_calculate_g_l_flag    IN VARCHAR2
38767  ,p_actual_flag           IN OUT VARCHAR2
38768  ,p_balance_type_code     OUT VARCHAR2
38769  ,p_gain_or_loss_ref      OUT VARCHAR2
38770  
38771 --Credit Memo Distribution GL Account
38772  , p_source_2            IN NUMBER
38773 --Credit Memo Default Receivable Account
38774  , p_source_12            IN NUMBER
38775 --SLA Party Type
38776  , p_source_32            IN VARCHAR2
38777 --Credit Memo Distribution Identifier
38778  , p_source_42            IN NUMBER
38779 --Credit memo distributions type
38780  , p_source_43            IN VARCHAR2
38781 --Credit Memo Currency Code
38782  , p_source_44            IN VARCHAR2
38783 --Credit Memo Exchange Date
38784  , p_source_45            IN DATE
38785 --Credit Memo Exchange Rate
38786  , p_source_46            IN NUMBER
38787 --Credit Memo Exchange Rate Type
38788  , p_source_47            IN VARCHAR2
38789 --Gain Loss Reference
38790  , p_source_48            IN VARCHAR2
38791 --Credit Memo Accounting Amount
38792  , p_source_49            IN NUMBER
38793 --Credit Memo Bill To Customer Account Identifier
38794  , p_source_50            IN NUMBER
38795 --Credit Memo Bill To Customer Site Use Identifier
38796  , p_source_51            IN NUMBER
38797 --Credit Memo Tax Line Identifier
38798  , p_source_52            IN NUMBER
38799 --Credit Memo Distribution Account Class
38800  , p_source_53            IN VARCHAR2
38801 --Credit Memo Distribution Entered Amount
38802  , p_source_54            IN NUMBER
38803 --Credit Memo Invoicing Rule
38804  , p_source_67            IN NUMBER
38805 )
38806 IS
38807 
38808 l_component_type              VARCHAR2(80);
38812 l_amb_context_code            VARCHAR2(30);
38809 l_component_code              VARCHAR2(30);
38810 l_component_type_code         VARCHAR2(1);
38811 l_component_appl_id           INTEGER;
38813 l_entity_code                 VARCHAR2(30);
38814 l_event_class_code            VARCHAR2(30);
38815 l_ae_header_id                NUMBER;
38816 l_event_type_code             VARCHAR2(30);
38817 l_line_definition_code        VARCHAR2(30);
38818 l_line_definition_owner_code  VARCHAR2(1);
38819 --
38820 -- adr variables
38821 l_segment                     VARCHAR2(30);
38822 l_ccid                        NUMBER;
38823 l_adr_transaction_coa_id      NUMBER;
38824 l_adr_accounting_coa_id       NUMBER;
38825 l_adr_flexfield_segment_code  VARCHAR2(30);
38826 l_adr_flex_value_set_id       NUMBER;
38827 l_adr_value_type_code         VARCHAR2(30);
38828 l_adr_value_combination_id    NUMBER;
38829 l_adr_value_segment_code      VARCHAR2(30);
38830 
38831 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
38832 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
38833 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
38834 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
38835 
38836 -- 4262811 Variables ------------------------------------------------------------------------------------------
38837 l_entered_amt_idx             NUMBER;
38838 l_accted_amt_idx              NUMBER;
38839 l_acc_rev_flag                VARCHAR2(1);
38840 l_accrual_line_num            NUMBER;
38841 l_tmp_amt                     NUMBER;
38842 l_acc_rev_natural_side_code   VARCHAR2(1);
38843 
38844 l_num_entries                 NUMBER;
38845 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
38846 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
38847 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
38848 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
38849 l_recog_line_1                NUMBER;
38850 l_recog_line_2                NUMBER;
38851 
38852 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
38853 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
38854 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
38855 
38856 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
38857 
38858 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
38859 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
38860 
38861 ---------------------------------------------------------------------------------------------------------------
38862 
38863 
38864 --
38865 -- bulk performance
38866 --
38867 l_balance_type_code           VARCHAR2(1);
38868 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
38869 l_log_module                  VARCHAR2(240);
38870 
38871 --
38872 -- Upgrade strategy
38873 --
38874 l_actual_upg_option           VARCHAR2(1);
38875 l_enc_upg_option           VARCHAR2(1);
38876 
38877 --
38878 BEGIN
38879 --
38880 IF g_log_enabled THEN
38881       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_87';
38882 END IF;
38883 --
38884 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
38885 
38886       trace
38887          (p_msg      => 'BEGIN of AcctLineType_87'
38888          ,p_level    => C_LEVEL_PROCEDURE
38889          ,p_module   => l_log_module);
38890 
38891 END IF;
38892 --
38893 l_component_type             := 'AMB_JLT';
38894 l_component_code             := 'MFAR_CM_REC';
38895 l_component_type_code        := 'S';
38896 l_component_appl_id          :=  222;
38897 l_amb_context_code           := 'DEFAULT';
38898 l_entity_code                := 'TRANSACTIONS';
38899 l_event_class_code           := 'CREDIT_MEMO';
38900 l_event_type_code            := 'CREDIT_MEMO_ALL';
38901 l_line_definition_owner_code := 'S';
38902 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
38903 --
38904 l_balance_type_code          := 'A';
38905 l_segment                     := NULL;
38906 l_ccid                        := NULL;
38907 l_adr_transaction_coa_id      := NULL;
38908 l_adr_accounting_coa_id       := NULL;
38909 l_adr_flexfield_segment_code  := NULL;
38910 l_adr_flex_value_set_id       := NULL;
38911 l_adr_value_type_code         := NULL;
38912 l_adr_value_combination_id    := NULL;
38913 l_adr_value_segment_code      := NULL;
38914 
38915 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
38916 l_bflow_class_code           := 'RECEIVABLE';    -- 4219869 Business Flow
38917 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
38918 l_budgetary_control_flag     := 'N';
38919 
38920 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
38921 l_bflow_applied_to_amt       := NULL; -- 5132302
38922 l_entered_amt_idx            := NULL;          -- 4262811
38923 l_accted_amt_idx             := NULL;          -- 4262811
38924 l_acc_rev_flag               := NULL;          -- 4262811
38925 l_accrual_line_num           := NULL;          -- 4262811
38926 l_tmp_amt                    := NULL;          -- 4262811
38927 --
38928  
38929 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
38930     l_balance_type_code <> 'B' THEN
38931 IF (p_source_67 IS NULL ) AND 
38932 (NVL(p_source_53,'
38933 ') =  'REV' OR 
38934 NVL(p_source_53,'
38938 NVL(p_source_53,'
38935 ') =  'TAX' OR 
38936 NVL(p_source_53,'
38937 ') =  'FREIGHT' OR 
38939 ') =  'ROUND' OR 
38940 NVL(p_source_53,'
38941 ') =  'CHARGES')
38942  THEN 
38943 
38944    --
38945    XLA_AE_LINES_PKG.SetNewLine;
38946 
38947    p_balance_type_code          := l_balance_type_code;
38948    -- set the flag so later we will know whether the gain loss line needs to be created
38949    
38950    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
38951      p_actual_flag :='A';
38952    END IF;
38953 
38954    --
38955    -- bulk performance
38956    --
38957    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
38958                                       p_header_num   => 0); -- 4262811
38959    --
38960    -- set accounting line options
38961    --
38962    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
38963            p_natural_side_code          => 'D'
38964          , p_gain_or_loss_flag          => 'N'
38965          , p_gl_transfer_mode_code      => 'S'
38966          , p_acct_entry_type_code       => 'A'
38967          , p_switch_side_flag           => 'Y'
38968          , p_merge_duplicate_code       => 'A'
38969          );
38970    --
38971    l_acc_rev_natural_side_code := 'C';  -- 4262811
38972    -- 
38973    --
38974    -- set accounting line type info
38975    --
38976    xla_ae_lines_pkg.SetAcctLineType
38977       (p_component_type             => l_component_type
38978       ,p_event_type_code            => l_event_type_code
38979       ,p_line_definition_owner_code => l_line_definition_owner_code
38980       ,p_line_definition_code       => l_line_definition_code
38981       ,p_accounting_line_code       => l_component_code
38982       ,p_accounting_line_type_code  => l_component_type_code
38983       ,p_accounting_line_appl_id    => l_component_appl_id
38984       ,p_amb_context_code           => l_amb_context_code
38985       ,p_entity_code                => l_entity_code
38986       ,p_event_class_code           => l_event_class_code);
38987    --
38988    -- set accounting class
38989    --
38990    xla_ae_lines_pkg.SetAcctClass(
38991            p_accounting_class_code  => 'RECEIVABLE'
38992          , p_ae_header_id           => l_ae_header_id
38993          );
38994 
38995    --
38996    -- set rounding class
38997    --
38998    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
38999                       'RECEIVABLE';
39000 
39001    --
39002    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
39003    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
39004    --
39005    -- bulk performance
39006    --
39007    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
39008 
39009    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
39010       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
39011 
39012    -- 4955764
39013    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
39014       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
39015 
39016    -- 4458381 Public Sector Enh
39017    
39018    --
39019    -- set accounting attributes for the line type
39020    --
39021    l_entered_amt_idx := 3;
39022    l_accted_amt_idx  := 9;
39023    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
39024    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
39025    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_42);
39026    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
39027    l_rec_acct_attrs.array_char_value(2)  := p_source_43;
39028    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
39029    l_rec_acct_attrs.array_num_value(3)  := p_source_54;
39030    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
39031    l_rec_acct_attrs.array_char_value(4)  := p_source_44;
39032    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
39033    l_rec_acct_attrs.array_date_value(5)  := p_source_45;
39034    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
39035    l_rec_acct_attrs.array_num_value(6)  := p_source_46;
39036    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
39037    l_rec_acct_attrs.array_char_value(7)  := p_source_47;
39038    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
39039    l_rec_acct_attrs.array_char_value(8)  := p_source_48;
39040    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
39041    l_rec_acct_attrs.array_num_value(9)  := p_source_49;
39042    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
39043    l_rec_acct_attrs.array_num_value(10)  := p_source_50;
39044    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
39045    l_rec_acct_attrs.array_num_value(11)  := p_source_51;
39046    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
39047    l_rec_acct_attrs.array_char_value(12)  := p_source_32;
39048    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
39049    l_rec_acct_attrs.array_num_value(13)  := p_source_52;
39050 
39051    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
39052    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
39056    ---------------------------------------------------------------------------------------------------------------
39053 
39054    ---------------------------------------------------------------------------------------------------------------
39055    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
39057    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
39058 
39059    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
39060    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
39061 
39062    IF xla_accounting_cache_pkg.GetValueChar
39063          (p_source_code         => 'LEDGER_CATEGORY_CODE'
39064          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
39065    AND l_bflow_method_code = 'PRIOR_ENTRY'
39066 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
39067    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
39068          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
39069        )
39070    THEN
39071          xla_ae_lines_pkg.BflowUpgEntry
39072            (p_business_method_code    => l_bflow_method_code
39073            ,p_business_class_code     => l_bflow_class_code
39074            ,p_balance_type            => l_balance_type_code);
39075    ELSE
39076       NULL;
39077 -- No business flow processing for business flow method of NONE.
39078    END IF;
39079 
39080    --
39081    -- call analytical criteria
39082    --
39083    
39084    --
39085    -- call description
39086    --
39087    
39088 xla_ae_lines_pkg.SetLineDescription(
39089    p_ae_header_id => l_ae_header_id
39090   ,p_description  => Description_1 (
39091      p_application_id         => p_application_id
39092    , p_ae_header_id           => l_ae_header_id 
39093    )
39094 );
39095 
39096 
39097    --
39098    -- call ADRs
39099    -- Bug 4922099
39100    --
39101    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
39102         (NVL(l_actual_upg_option, 'N') = 'O') OR
39103         (NVL(l_enc_upg_option, 'N') = 'O')
39104       )
39105    THEN
39106    NULL;
39107    --
39108    --
39109    
39110   l_ccid := AcctDerRule_24(
39111            p_application_id           => p_application_id
39112          , p_ae_header_id             => l_ae_header_id 
39113 , p_source_12 => p_source_12
39114          , x_transaction_coa_id       => l_adr_transaction_coa_id
39115          , x_accounting_coa_id        => l_adr_accounting_coa_id
39116          , x_value_type_code          => l_adr_value_type_code
39117          , p_side                     => 'NA'
39118    );
39119 
39120    xla_ae_lines_pkg.set_ccid(
39121     p_code_combination_id          => l_ccid
39122   , p_value_type_code              => l_adr_value_type_code
39123   , p_transaction_coa_id           => l_adr_transaction_coa_id
39124   , p_accounting_coa_id            => l_adr_accounting_coa_id
39125   , p_adr_code                     => 'MFAR_CM_DEF_REC_CCID'
39126   , p_adr_type_code                => 'S'
39127   , p_component_type               => l_component_type
39128   , p_component_code               => l_component_code
39129   , p_component_type_code          => l_component_type_code
39130   , p_component_appl_id            => l_component_appl_id
39131   , p_amb_context_code             => l_amb_context_code
39132   , p_side                         => 'NA'
39133   );
39134 
39135 
39136    l_segment := AcctDerRule_3(
39137            p_application_id           => p_application_id
39138          , p_ae_header_id             => l_ae_header_id 
39139 , p_source_2 => p_source_2
39140          , x_transaction_coa_id       => l_adr_transaction_coa_id
39141          , x_accounting_coa_id        => l_adr_accounting_coa_id
39142          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
39143          , x_flex_value_set_id        => l_adr_flex_value_set_id
39144          , x_value_type_code          => l_adr_value_type_code
39145          , x_value_combination_id     => l_adr_value_combination_id
39146          , x_value_segment_code       => l_adr_value_segment_code
39147          , p_side                     => 'NA'
39148          , p_override_seg_flag        => 'Y'
39149    );
39150 
39151    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
39152 
39153       xla_ae_lines_pkg.set_segment(
39154           p_to_segment_code         => 'GL_BALANCING'
39155         , p_segment_value           => l_segment
39156         , p_from_segment_code       => l_adr_value_segment_code
39157         , p_from_combination_id     => l_adr_value_combination_id
39158         , p_value_type_code         => l_adr_value_type_code
39159         , p_transaction_coa_id      => l_adr_transaction_coa_id
39160         , p_accounting_coa_id       => l_adr_accounting_coa_id
39161         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
39162         , p_flex_value_set_id       => l_adr_flex_value_set_id
39163         , p_adr_code                => 'MFAR_CM_BALANCING_SEGMENT'
39164         , p_adr_type_code           => 'S'
39165         , p_component_type          => l_component_type
39166         , p_component_code          => l_component_code
39167         , p_component_type_code     => l_component_type_code
39168         , p_component_appl_id       => l_component_appl_id
39172         , p_side                    => 'NA'
39169         , p_amb_context_code        => l_amb_context_code
39170         , p_entity_code             => 'TRANSACTIONS'
39171         , p_event_class_code        => 'CREDIT_MEMO'
39173         );
39174 
39175   END IF;
39176 
39177    --
39178    --
39179    END IF;
39180    --
39181    -- Bug 4922099
39182    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
39183           (NVL(l_enc_upg_option, 'N') = 'O')
39184         ) AND
39185         (l_bflow_method_code = 'PRIOR_ENTRY')
39186       )
39187    THEN
39188       IF
39189       --
39190       1 = 2
39191       --
39192       THEN
39193       xla_accounting_err_pkg.build_message
39194                                     (p_appli_s_name            => 'XLA'
39195                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
39196                                     ,p_token_1                 => 'LINE_NUMBER'
39197                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
39198                                     ,p_token_2                 => 'LINE_TYPE_NAME'
39199                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
39200                                                                              l_component_type
39201                                                                             ,l_component_code
39202                                                                             ,l_component_type_code
39203                                                                             ,l_component_appl_id
39204                                                                             ,l_amb_context_code
39205                                                                             ,l_entity_code
39206                                                                             ,l_event_class_code
39207                                                                            )
39208                                     ,p_token_3                 => 'OWNER'
39209                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
39210                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
39211                                                                           ,p_lookup_code    => l_component_type_code
39212                                                                          )
39213                                     ,p_token_4                 => 'PRODUCT_NAME'
39214                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
39215                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
39216                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
39217                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
39218                                     ,p_ae_header_id            =>  NULL
39219                                        );
39220 
39221         IF (C_LEVEL_ERROR>= g_log_level) THEN
39222                  trace
39223                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
39224                       ,p_level    => C_LEVEL_ERROR
39225                       ,p_module   => l_log_module);
39226         END IF;
39227       END IF;
39228    END IF;
39229    --
39230    --
39231    ------------------------------------------------------------------------------------------------
39232    -- 4219869 Business Flow
39233    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
39234    -- Prior Entry.  Currently, the following code is always generated.
39235    ------------------------------------------------------------------------------------------------
39236    XLA_AE_LINES_PKG.ValidateCurrentLine;
39237 
39238    ------------------------------------------------------------------------------------
39239    -- 4219869 Business Flow
39240    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
39241    ------------------------------------------------------------------------------------
39242    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
39243 
39244    ----------------------------------------------------------------------------------
39245    -- 4219869 Business Flow
39246    -- Update journal entry status -- Need to generate this within IF <condition>
39247    ----------------------------------------------------------------------------------
39248    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
39249          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
39250          ,p_balance_type_code => l_balance_type_code
39251          );
39252 
39253    -------------------------------------------------------------------------------------------
39254    -- 4262811 - Generate the Accrual Reversal lines
39255    -------------------------------------------------------------------------------------------
39256    BEGIN
39257       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
39258                               (g_array_event(p_event_id).array_value_num('header_index'));
39259       IF l_acc_rev_flag IS NULL THEN
39260          l_acc_rev_flag := 'N';
39261       END IF;
39262    EXCEPTION
39263       WHEN OTHERS THEN
39264          l_acc_rev_flag := 'N';
39265    END;
39266    --
39267    IF (l_acc_rev_flag = 'Y') THEN
39268 
39272        ------------------------------------------------------------------------------------------
39269        -- 4645092  ------------------------------------------------------------------------------
39270        -- To allow MPA report to determine if it should generate report process
39271        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
39273 
39274        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
39275        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
39276    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
39277    -- call ADRs
39278    -- Bug 4922099
39279    --
39280    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
39281         (NVL(l_actual_upg_option, 'N') = 'O') OR
39282         (NVL(l_enc_upg_option, 'N') = 'O')
39283       )
39284    THEN
39285    NULL;
39286    --
39287    --
39288    
39289   l_ccid := AcctDerRule_24(
39290            p_application_id           => p_application_id
39291          , p_ae_header_id             => l_ae_header_id 
39292 , p_source_12 => p_source_12
39293          , x_transaction_coa_id       => l_adr_transaction_coa_id
39294          , x_accounting_coa_id        => l_adr_accounting_coa_id
39295          , x_value_type_code          => l_adr_value_type_code
39296          , p_side                     => 'NA'
39297    );
39298 
39299    xla_ae_lines_pkg.set_ccid(
39300     p_code_combination_id          => l_ccid
39301   , p_value_type_code              => l_adr_value_type_code
39302   , p_transaction_coa_id           => l_adr_transaction_coa_id
39303   , p_accounting_coa_id            => l_adr_accounting_coa_id
39304   , p_adr_code                     => 'MFAR_CM_DEF_REC_CCID'
39305   , p_adr_type_code                => 'S'
39306   , p_component_type               => l_component_type
39307   , p_component_code               => l_component_code
39308   , p_component_type_code          => l_component_type_code
39309   , p_component_appl_id            => l_component_appl_id
39310   , p_amb_context_code             => l_amb_context_code
39311   , p_side                         => 'NA'
39312   );
39313 
39314 
39315    l_segment := AcctDerRule_3(
39316            p_application_id           => p_application_id
39317          , p_ae_header_id             => l_ae_header_id 
39318 , p_source_2 => p_source_2
39319          , x_transaction_coa_id       => l_adr_transaction_coa_id
39320          , x_accounting_coa_id        => l_adr_accounting_coa_id
39321          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
39322          , x_flex_value_set_id        => l_adr_flex_value_set_id
39323          , x_value_type_code          => l_adr_value_type_code
39324          , x_value_combination_id     => l_adr_value_combination_id
39325          , x_value_segment_code       => l_adr_value_segment_code
39326          , p_side                     => 'NA'
39327          , p_override_seg_flag        => 'Y'
39328    );
39329 
39330    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
39331 
39332       xla_ae_lines_pkg.set_segment(
39333           p_to_segment_code         => 'GL_BALANCING'
39334         , p_segment_value           => l_segment
39335         , p_from_segment_code       => l_adr_value_segment_code
39336         , p_from_combination_id     => l_adr_value_combination_id
39337         , p_value_type_code         => l_adr_value_type_code
39338         , p_transaction_coa_id      => l_adr_transaction_coa_id
39339         , p_accounting_coa_id       => l_adr_accounting_coa_id
39340         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
39341         , p_flex_value_set_id       => l_adr_flex_value_set_id
39342         , p_adr_code                => 'MFAR_CM_BALANCING_SEGMENT'
39343         , p_adr_type_code           => 'S'
39344         , p_component_type          => l_component_type
39345         , p_component_code          => l_component_code
39346         , p_component_type_code     => l_component_type_code
39347         , p_component_appl_id       => l_component_appl_id
39348         , p_amb_context_code        => l_amb_context_code
39349         , p_entity_code             => 'TRANSACTIONS'
39350         , p_event_class_code        => 'CREDIT_MEMO'
39351         , p_side                    => 'NA'
39352         );
39353 
39354   END IF;
39355 
39356    --
39357    --
39358    END IF;
39359 
39360        --
39361        -- Update the line information that should be overwritten
39362        --
39363        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
39364                                          p_header_num   => 1);
39365        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
39366 
39367        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
39368 
39369        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
39370           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
39371        END IF;
39372 
39373       --
39374       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
39375       --
39376       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
39377           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
39378       ELSE
39379           ---------------------------------------------------------------------------------------------------
39380           -- 4262811a Switch Sign
39384                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
39381           ---------------------------------------------------------------------------------------------------
39382           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
39383           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
39385           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
39386                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
39387           -- 5132302
39388           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
39389                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
39390 
39391       END IF;
39392 
39393       -- 4955764
39394       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
39395       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
39396 
39397 
39398       XLA_AE_LINES_PKG.ValidateCurrentLine;
39399       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
39400 
39401       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
39402                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
39403                ,p_balance_type_code => l_balance_type_code);
39404 
39405    END IF;
39406 
39407    -----------------------------------------------------------------------------------------
39408    -- 4262811 Multiperiod Accounting
39409    -----------------------------------------------------------------------------------------
39410      -- No MPA option is assigned.
39411 
39412 
39413 END IF;
39414 END IF;
39415 --
39416 
39417 --
39418 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
39419    trace
39420       (p_msg      => 'END of AcctLineType_87'
39421       ,p_level    => C_LEVEL_PROCEDURE
39422       ,p_module   => l_log_module);
39423 END IF;
39424 --
39425 EXCEPTION
39426   WHEN xla_exceptions_pkg.application_exception THEN
39427       RAISE;
39428   WHEN OTHERS THEN
39429        xla_exceptions_pkg.raise_message
39430            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_87');
39431 END AcctLineType_87;
39432 --
39433 
39434 ---------------------------------------
39435 --
39436 -- PRIVATE FUNCTION
39437 --         AcctLineType_88
39438 --
39439 ---------------------------------------
39440 PROCEDURE AcctLineType_88 (
39441   p_application_id        IN NUMBER
39442  ,p_event_id              IN NUMBER
39443  ,p_calculate_acctd_flag  IN VARCHAR2
39444  ,p_calculate_g_l_flag    IN VARCHAR2
39445  ,p_actual_flag           IN OUT VARCHAR2
39446  ,p_balance_type_code     OUT VARCHAR2
39447  ,p_gain_or_loss_ref      OUT VARCHAR2
39448  
39449 --Transaction Distribution GL Account
39450  , p_source_4            IN NUMBER
39451 --Transaction Default Receivable Account
39452  , p_source_16            IN NUMBER
39453 --Bill To Customer Account Identifier
39454  , p_source_30            IN NUMBER
39455 --Bill To Customer Site Use Identifier
39456  , p_source_31            IN NUMBER
39457 --SLA Party Type
39458  , p_source_32            IN VARCHAR2
39459 --Transaction Distribution Account Class
39460  , p_source_33            IN VARCHAR2
39461 --Transaction Distribution Identifier
39462  , p_source_34            IN NUMBER
39463 --Transaction Distribution Type
39464  , p_source_35            IN VARCHAR2
39465 --Transaction Distribution Entered Amount
39466  , p_source_36            IN NUMBER
39467 --Transaction Currency Code
39468  , p_source_37            IN VARCHAR2
39469 --Transaction Exchange Date
39470  , p_source_38            IN DATE
39471 --Transaction Exchange Rate
39472  , p_source_39            IN NUMBER
39473 --Transaction Exchange Rate Type
39474  , p_source_40            IN VARCHAR2
39475 --Transaction Accounting Amount
39476  , p_source_41            IN NUMBER
39477 --Transaction Tax Line Identifier
39478  , p_source_55            IN NUMBER
39479 --Transaction Invoicing Rule
39480  , p_source_68            IN NUMBER
39481 )
39482 IS
39483 
39484 l_component_type              VARCHAR2(80);
39485 l_component_code              VARCHAR2(30);
39486 l_component_type_code         VARCHAR2(1);
39487 l_component_appl_id           INTEGER;
39488 l_amb_context_code            VARCHAR2(30);
39489 l_entity_code                 VARCHAR2(30);
39490 l_event_class_code            VARCHAR2(30);
39491 l_ae_header_id                NUMBER;
39492 l_event_type_code             VARCHAR2(30);
39493 l_line_definition_code        VARCHAR2(30);
39494 l_line_definition_owner_code  VARCHAR2(1);
39495 --
39496 -- adr variables
39497 l_segment                     VARCHAR2(30);
39498 l_ccid                        NUMBER;
39499 l_adr_transaction_coa_id      NUMBER;
39500 l_adr_accounting_coa_id       NUMBER;
39501 l_adr_flexfield_segment_code  VARCHAR2(30);
39502 l_adr_flex_value_set_id       NUMBER;
39503 l_adr_value_type_code         VARCHAR2(30);
39504 l_adr_value_combination_id    NUMBER;
39505 l_adr_value_segment_code      VARCHAR2(30);
39506 
39507 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
39508 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
39512 -- 4262811 Variables ------------------------------------------------------------------------------------------
39509 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
39510 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
39511 
39513 l_entered_amt_idx             NUMBER;
39514 l_accted_amt_idx              NUMBER;
39515 l_acc_rev_flag                VARCHAR2(1);
39516 l_accrual_line_num            NUMBER;
39517 l_tmp_amt                     NUMBER;
39518 l_acc_rev_natural_side_code   VARCHAR2(1);
39519 
39520 l_num_entries                 NUMBER;
39521 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
39522 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
39523 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
39524 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
39525 l_recog_line_1                NUMBER;
39526 l_recog_line_2                NUMBER;
39527 
39528 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
39529 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
39530 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
39531 
39532 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
39533 
39534 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
39535 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
39536 
39537 ---------------------------------------------------------------------------------------------------------------
39538 
39539 
39540 --
39541 -- bulk performance
39542 --
39543 l_balance_type_code           VARCHAR2(1);
39544 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
39545 l_log_module                  VARCHAR2(240);
39546 
39547 --
39548 -- Upgrade strategy
39549 --
39550 l_actual_upg_option           VARCHAR2(1);
39551 l_enc_upg_option           VARCHAR2(1);
39552 
39553 --
39554 BEGIN
39555 --
39556 IF g_log_enabled THEN
39557       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_88';
39558 END IF;
39559 --
39560 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
39561 
39562       trace
39563          (p_msg      => 'BEGIN of AcctLineType_88'
39564          ,p_level    => C_LEVEL_PROCEDURE
39565          ,p_module   => l_log_module);
39566 
39567 END IF;
39568 --
39569 l_component_type             := 'AMB_JLT';
39570 l_component_code             := 'MFAR_DM_REC';
39571 l_component_type_code        := 'S';
39572 l_component_appl_id          :=  222;
39573 l_amb_context_code           := 'DEFAULT';
39574 l_entity_code                := 'TRANSACTIONS';
39575 l_event_class_code           := 'DEBIT_MEMO';
39576 l_event_type_code            := 'DEBIT_MEMO_ALL';
39577 l_line_definition_owner_code := 'S';
39578 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
39579 --
39580 l_balance_type_code          := 'A';
39581 l_segment                     := NULL;
39582 l_ccid                        := NULL;
39583 l_adr_transaction_coa_id      := NULL;
39584 l_adr_accounting_coa_id       := NULL;
39585 l_adr_flexfield_segment_code  := NULL;
39586 l_adr_flex_value_set_id       := NULL;
39587 l_adr_value_type_code         := NULL;
39588 l_adr_value_combination_id    := NULL;
39589 l_adr_value_segment_code      := NULL;
39590 
39591 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
39592 l_bflow_class_code           := 'RECEIVABLE';    -- 4219869 Business Flow
39593 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
39594 l_budgetary_control_flag     := 'N';
39595 
39596 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
39597 l_bflow_applied_to_amt       := NULL; -- 5132302
39598 l_entered_amt_idx            := NULL;          -- 4262811
39599 l_accted_amt_idx             := NULL;          -- 4262811
39600 l_acc_rev_flag               := NULL;          -- 4262811
39601 l_accrual_line_num           := NULL;          -- 4262811
39602 l_tmp_amt                    := NULL;          -- 4262811
39603 --
39604  
39605 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
39606     l_balance_type_code <> 'B' THEN
39607 IF (p_source_68 IS NULL ) AND 
39608 (NVL(p_source_33,'
39609 ') =  'REV' OR 
39610 NVL(p_source_33,'
39611 ') =  'TAX' OR 
39612 NVL(p_source_33,'
39613 ') =  'FREIGHT' OR 
39614 NVL(p_source_33,'
39615 ') =  'ROUND' OR 
39616 NVL(p_source_33,'
39617 ') =  'CHARGES')
39618  THEN 
39619 
39620    --
39621    XLA_AE_LINES_PKG.SetNewLine;
39622 
39623    p_balance_type_code          := l_balance_type_code;
39624    -- set the flag so later we will know whether the gain loss line needs to be created
39625    
39626    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
39627      p_actual_flag :='A';
39628    END IF;
39629 
39630    --
39631    -- bulk performance
39632    --
39633    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
39634                                       p_header_num   => 0); -- 4262811
39635    --
39636    -- set accounting line options
39637    --
39638    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
39639            p_natural_side_code          => 'D'
39643          , p_switch_side_flag           => 'Y'
39640          , p_gain_or_loss_flag          => 'N'
39641          , p_gl_transfer_mode_code      => 'S'
39642          , p_acct_entry_type_code       => 'A'
39644          , p_merge_duplicate_code       => 'A'
39645          );
39646    --
39647    l_acc_rev_natural_side_code := 'C';  -- 4262811
39648    -- 
39649    --
39650    -- set accounting line type info
39651    --
39652    xla_ae_lines_pkg.SetAcctLineType
39653       (p_component_type             => l_component_type
39654       ,p_event_type_code            => l_event_type_code
39655       ,p_line_definition_owner_code => l_line_definition_owner_code
39656       ,p_line_definition_code       => l_line_definition_code
39657       ,p_accounting_line_code       => l_component_code
39658       ,p_accounting_line_type_code  => l_component_type_code
39659       ,p_accounting_line_appl_id    => l_component_appl_id
39660       ,p_amb_context_code           => l_amb_context_code
39661       ,p_entity_code                => l_entity_code
39662       ,p_event_class_code           => l_event_class_code);
39663    --
39664    -- set accounting class
39665    --
39666    xla_ae_lines_pkg.SetAcctClass(
39667            p_accounting_class_code  => 'RECEIVABLE'
39668          , p_ae_header_id           => l_ae_header_id
39669          );
39670 
39671    --
39672    -- set rounding class
39673    --
39674    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
39675                       'RECEIVABLE';
39676 
39677    --
39678    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
39679    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
39680    --
39681    -- bulk performance
39682    --
39683    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
39684 
39685    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
39686       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
39687 
39688    -- 4955764
39689    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
39690       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
39691 
39692    -- 4458381 Public Sector Enh
39693    
39694    --
39695    -- set accounting attributes for the line type
39696    --
39697    l_entered_amt_idx := 3;
39698    l_accted_amt_idx  := 8;
39699    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
39700    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
39701    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
39702    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
39703    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
39704    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
39705    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
39706    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
39707    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
39708    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
39709    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
39710    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
39711    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
39712    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
39713    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
39714    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
39715    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
39716    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
39717    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
39718    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
39719    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
39720    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
39721    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
39722    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
39723    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
39724 
39725    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
39726    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
39727 
39728    ---------------------------------------------------------------------------------------------------------------
39729    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
39730    ---------------------------------------------------------------------------------------------------------------
39731    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
39732 
39733    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
39734    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
39735 
39736    IF xla_accounting_cache_pkg.GetValueChar
39737          (p_source_code         => 'LEDGER_CATEGORY_CODE'
39738          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
39739    AND l_bflow_method_code = 'PRIOR_ENTRY'
39740 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
39741    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
39742          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
39743        )
39747            ,p_business_class_code     => l_bflow_class_code
39744    THEN
39745          xla_ae_lines_pkg.BflowUpgEntry
39746            (p_business_method_code    => l_bflow_method_code
39748            ,p_balance_type            => l_balance_type_code);
39749    ELSE
39750       NULL;
39751 -- No business flow processing for business flow method of NONE.
39752    END IF;
39753 
39754    --
39755    -- call analytical criteria
39756    --
39757    
39758    --
39759    -- call description
39760    --
39761    
39762 xla_ae_lines_pkg.SetLineDescription(
39763    p_ae_header_id => l_ae_header_id
39764   ,p_description  => Description_1 (
39765      p_application_id         => p_application_id
39766    , p_ae_header_id           => l_ae_header_id 
39767    )
39768 );
39769 
39770 
39771    --
39772    -- call ADRs
39773    -- Bug 4922099
39774    --
39775    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
39776         (NVL(l_actual_upg_option, 'N') = 'O') OR
39777         (NVL(l_enc_upg_option, 'N') = 'O')
39778       )
39779    THEN
39780    NULL;
39781    --
39782    --
39783    
39784   l_ccid := AcctDerRule_28(
39785            p_application_id           => p_application_id
39786          , p_ae_header_id             => l_ae_header_id 
39787 , p_source_16 => p_source_16
39788          , x_transaction_coa_id       => l_adr_transaction_coa_id
39789          , x_accounting_coa_id        => l_adr_accounting_coa_id
39790          , x_value_type_code          => l_adr_value_type_code
39791          , p_side                     => 'NA'
39792    );
39793 
39794    xla_ae_lines_pkg.set_ccid(
39795     p_code_combination_id          => l_ccid
39796   , p_value_type_code              => l_adr_value_type_code
39797   , p_transaction_coa_id           => l_adr_transaction_coa_id
39798   , p_accounting_coa_id            => l_adr_accounting_coa_id
39799   , p_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
39800   , p_adr_type_code                => 'S'
39801   , p_component_type               => l_component_type
39802   , p_component_code               => l_component_code
39803   , p_component_type_code          => l_component_type_code
39804   , p_component_appl_id            => l_component_appl_id
39805   , p_amb_context_code             => l_amb_context_code
39806   , p_side                         => 'NA'
39807   );
39808 
39809 
39810    l_segment := AcctDerRule_5(
39811            p_application_id           => p_application_id
39812          , p_ae_header_id             => l_ae_header_id 
39813 , p_source_4 => p_source_4
39814          , x_transaction_coa_id       => l_adr_transaction_coa_id
39815          , x_accounting_coa_id        => l_adr_accounting_coa_id
39816          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
39817          , x_flex_value_set_id        => l_adr_flex_value_set_id
39818          , x_value_type_code          => l_adr_value_type_code
39819          , x_value_combination_id     => l_adr_value_combination_id
39820          , x_value_segment_code       => l_adr_value_segment_code
39821          , p_side                     => 'NA'
39822          , p_override_seg_flag        => 'Y'
39823    );
39824 
39825    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
39826 
39827       xla_ae_lines_pkg.set_segment(
39828           p_to_segment_code         => 'GL_BALANCING'
39829         , p_segment_value           => l_segment
39830         , p_from_segment_code       => l_adr_value_segment_code
39831         , p_from_combination_id     => l_adr_value_combination_id
39832         , p_value_type_code         => l_adr_value_type_code
39833         , p_transaction_coa_id      => l_adr_transaction_coa_id
39834         , p_accounting_coa_id       => l_adr_accounting_coa_id
39835         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
39836         , p_flex_value_set_id       => l_adr_flex_value_set_id
39837         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
39838         , p_adr_type_code           => 'S'
39839         , p_component_type          => l_component_type
39840         , p_component_code          => l_component_code
39841         , p_component_type_code     => l_component_type_code
39842         , p_component_appl_id       => l_component_appl_id
39843         , p_amb_context_code        => l_amb_context_code
39844         , p_entity_code             => 'TRANSACTIONS'
39845         , p_event_class_code        => 'DEBIT_MEMO'
39846         , p_side                    => 'NA'
39847         );
39848 
39849   END IF;
39850 
39851    --
39852    --
39853    END IF;
39854    --
39855    -- Bug 4922099
39856    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
39857           (NVL(l_enc_upg_option, 'N') = 'O')
39858         ) AND
39859         (l_bflow_method_code = 'PRIOR_ENTRY')
39860       )
39861    THEN
39862       IF
39863       --
39864       1 = 2
39865       --
39866       THEN
39867       xla_accounting_err_pkg.build_message
39868                                     (p_appli_s_name            => 'XLA'
39869                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
39870                                     ,p_token_1                 => 'LINE_NUMBER'
39871                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
39872                                     ,p_token_2                 => 'LINE_TYPE_NAME'
39873                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
39877                                                                             ,l_component_appl_id
39874                                                                              l_component_type
39875                                                                             ,l_component_code
39876                                                                             ,l_component_type_code
39878                                                                             ,l_amb_context_code
39879                                                                             ,l_entity_code
39880                                                                             ,l_event_class_code
39881                                                                            )
39882                                     ,p_token_3                 => 'OWNER'
39883                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
39884                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
39885                                                                           ,p_lookup_code    => l_component_type_code
39886                                                                          )
39887                                     ,p_token_4                 => 'PRODUCT_NAME'
39888                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
39889                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
39890                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
39891                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
39892                                     ,p_ae_header_id            =>  NULL
39893                                        );
39894 
39895         IF (C_LEVEL_ERROR>= g_log_level) THEN
39896                  trace
39897                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
39898                       ,p_level    => C_LEVEL_ERROR
39899                       ,p_module   => l_log_module);
39900         END IF;
39901       END IF;
39902    END IF;
39903    --
39904    --
39905    ------------------------------------------------------------------------------------------------
39906    -- 4219869 Business Flow
39907    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
39908    -- Prior Entry.  Currently, the following code is always generated.
39909    ------------------------------------------------------------------------------------------------
39910    XLA_AE_LINES_PKG.ValidateCurrentLine;
39911 
39912    ------------------------------------------------------------------------------------
39913    -- 4219869 Business Flow
39914    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
39915    ------------------------------------------------------------------------------------
39916    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
39917 
39918    ----------------------------------------------------------------------------------
39919    -- 4219869 Business Flow
39920    -- Update journal entry status -- Need to generate this within IF <condition>
39921    ----------------------------------------------------------------------------------
39922    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
39923          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
39924          ,p_balance_type_code => l_balance_type_code
39925          );
39926 
39927    -------------------------------------------------------------------------------------------
39928    -- 4262811 - Generate the Accrual Reversal lines
39929    -------------------------------------------------------------------------------------------
39930    BEGIN
39931       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
39932                               (g_array_event(p_event_id).array_value_num('header_index'));
39933       IF l_acc_rev_flag IS NULL THEN
39934          l_acc_rev_flag := 'N';
39935       END IF;
39936    EXCEPTION
39937       WHEN OTHERS THEN
39938          l_acc_rev_flag := 'N';
39939    END;
39940    --
39941    IF (l_acc_rev_flag = 'Y') THEN
39942 
39943        -- 4645092  ------------------------------------------------------------------------------
39944        -- To allow MPA report to determine if it should generate report process
39945        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
39946        ------------------------------------------------------------------------------------------
39947 
39948        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
39949        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
39950    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
39951    -- call ADRs
39952    -- Bug 4922099
39953    --
39954    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
39955         (NVL(l_actual_upg_option, 'N') = 'O') OR
39956         (NVL(l_enc_upg_option, 'N') = 'O')
39957       )
39958    THEN
39959    NULL;
39960    --
39961    --
39962    
39963   l_ccid := AcctDerRule_28(
39964            p_application_id           => p_application_id
39965          , p_ae_header_id             => l_ae_header_id 
39966 , p_source_16 => p_source_16
39967          , x_transaction_coa_id       => l_adr_transaction_coa_id
39968          , x_accounting_coa_id        => l_adr_accounting_coa_id
39969          , x_value_type_code          => l_adr_value_type_code
39970          , p_side                     => 'NA'
39974     p_code_combination_id          => l_ccid
39971    );
39972 
39973    xla_ae_lines_pkg.set_ccid(
39975   , p_value_type_code              => l_adr_value_type_code
39976   , p_transaction_coa_id           => l_adr_transaction_coa_id
39977   , p_accounting_coa_id            => l_adr_accounting_coa_id
39978   , p_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
39979   , p_adr_type_code                => 'S'
39980   , p_component_type               => l_component_type
39981   , p_component_code               => l_component_code
39982   , p_component_type_code          => l_component_type_code
39983   , p_component_appl_id            => l_component_appl_id
39984   , p_amb_context_code             => l_amb_context_code
39985   , p_side                         => 'NA'
39986   );
39987 
39988 
39989    l_segment := AcctDerRule_5(
39990            p_application_id           => p_application_id
39991          , p_ae_header_id             => l_ae_header_id 
39992 , p_source_4 => p_source_4
39993          , x_transaction_coa_id       => l_adr_transaction_coa_id
39994          , x_accounting_coa_id        => l_adr_accounting_coa_id
39995          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
39996          , x_flex_value_set_id        => l_adr_flex_value_set_id
39997          , x_value_type_code          => l_adr_value_type_code
39998          , x_value_combination_id     => l_adr_value_combination_id
39999          , x_value_segment_code       => l_adr_value_segment_code
40000          , p_side                     => 'NA'
40001          , p_override_seg_flag        => 'Y'
40002    );
40003 
40004    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
40005 
40006       xla_ae_lines_pkg.set_segment(
40007           p_to_segment_code         => 'GL_BALANCING'
40008         , p_segment_value           => l_segment
40009         , p_from_segment_code       => l_adr_value_segment_code
40010         , p_from_combination_id     => l_adr_value_combination_id
40011         , p_value_type_code         => l_adr_value_type_code
40012         , p_transaction_coa_id      => l_adr_transaction_coa_id
40013         , p_accounting_coa_id       => l_adr_accounting_coa_id
40014         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
40015         , p_flex_value_set_id       => l_adr_flex_value_set_id
40016         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
40017         , p_adr_type_code           => 'S'
40018         , p_component_type          => l_component_type
40019         , p_component_code          => l_component_code
40020         , p_component_type_code     => l_component_type_code
40021         , p_component_appl_id       => l_component_appl_id
40022         , p_amb_context_code        => l_amb_context_code
40023         , p_entity_code             => 'TRANSACTIONS'
40024         , p_event_class_code        => 'DEBIT_MEMO'
40025         , p_side                    => 'NA'
40026         );
40027 
40028   END IF;
40029 
40030    --
40031    --
40032    END IF;
40033 
40034        --
40035        -- Update the line information that should be overwritten
40036        --
40037        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
40038                                          p_header_num   => 1);
40039        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
40040 
40041        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
40042 
40043        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
40044           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
40045        END IF;
40046 
40047       --
40048       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
40049       --
40050       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
40051           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
40052       ELSE
40053           ---------------------------------------------------------------------------------------------------
40054           -- 4262811a Switch Sign
40055           ---------------------------------------------------------------------------------------------------
40056           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
40057           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
40058                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
40059           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
40060                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
40061           -- 5132302
40062           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
40063                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
40064 
40065       END IF;
40066 
40067       -- 4955764
40068       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
40069       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
40070 
40071 
40072       XLA_AE_LINES_PKG.ValidateCurrentLine;
40073       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
40074 
40075       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
40079    END IF;
40076                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
40077                ,p_balance_type_code => l_balance_type_code);
40078 
40080 
40081    -----------------------------------------------------------------------------------------
40082    -- 4262811 Multiperiod Accounting
40083    -----------------------------------------------------------------------------------------
40084      -- No MPA option is assigned.
40085 
40086 
40087 END IF;
40088 END IF;
40089 --
40090 
40091 --
40092 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
40093    trace
40094       (p_msg      => 'END of AcctLineType_88'
40095       ,p_level    => C_LEVEL_PROCEDURE
40096       ,p_module   => l_log_module);
40097 END IF;
40098 --
40099 EXCEPTION
40100   WHEN xla_exceptions_pkg.application_exception THEN
40101       RAISE;
40102   WHEN OTHERS THEN
40103        xla_exceptions_pkg.raise_message
40104            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_88');
40105 END AcctLineType_88;
40106 --
40107 
40108 ---------------------------------------
40109 --
40110 -- PRIVATE FUNCTION
40111 --         AcctLineType_89
40112 --
40113 ---------------------------------------
40114 PROCEDURE AcctLineType_89 (
40115   p_application_id        IN NUMBER
40116  ,p_event_id              IN NUMBER
40117  ,p_calculate_acctd_flag  IN VARCHAR2
40118  ,p_calculate_g_l_flag    IN VARCHAR2
40119  ,p_actual_flag           IN OUT VARCHAR2
40120  ,p_balance_type_code     OUT VARCHAR2
40121  ,p_gain_or_loss_ref      OUT VARCHAR2
40122  
40123 --Transaction Distribution GL Account
40124  , p_source_4            IN NUMBER
40125 --Transaction Default Receivable Account
40126  , p_source_16            IN NUMBER
40127 --Bill To Customer Account Identifier
40128  , p_source_30            IN NUMBER
40129 --Bill To Customer Site Use Identifier
40130  , p_source_31            IN NUMBER
40131 --SLA Party Type
40132  , p_source_32            IN VARCHAR2
40133 --Transaction Distribution Account Class
40134  , p_source_33            IN VARCHAR2
40135 --Transaction Distribution Identifier
40136  , p_source_34            IN NUMBER
40137 --Transaction Distribution Type
40138  , p_source_35            IN VARCHAR2
40139 --Transaction Distribution Entered Amount
40140  , p_source_36            IN NUMBER
40141 --Transaction Currency Code
40142  , p_source_37            IN VARCHAR2
40143 --Transaction Exchange Date
40144  , p_source_38            IN DATE
40145 --Transaction Exchange Rate
40146  , p_source_39            IN NUMBER
40147 --Transaction Exchange Rate Type
40148  , p_source_40            IN VARCHAR2
40149 --Transaction Accounting Amount
40150  , p_source_41            IN NUMBER
40151 --Transaction Tax Line Identifier
40152  , p_source_55            IN NUMBER
40153 --Transaction Invoicing Rule
40154  , p_source_68            IN NUMBER
40155 )
40156 IS
40157 
40158 l_component_type              VARCHAR2(80);
40159 l_component_code              VARCHAR2(30);
40160 l_component_type_code         VARCHAR2(1);
40161 l_component_appl_id           INTEGER;
40162 l_amb_context_code            VARCHAR2(30);
40163 l_entity_code                 VARCHAR2(30);
40164 l_event_class_code            VARCHAR2(30);
40165 l_ae_header_id                NUMBER;
40166 l_event_type_code             VARCHAR2(30);
40167 l_line_definition_code        VARCHAR2(30);
40168 l_line_definition_owner_code  VARCHAR2(1);
40169 --
40170 -- adr variables
40171 l_segment                     VARCHAR2(30);
40172 l_ccid                        NUMBER;
40173 l_adr_transaction_coa_id      NUMBER;
40174 l_adr_accounting_coa_id       NUMBER;
40175 l_adr_flexfield_segment_code  VARCHAR2(30);
40176 l_adr_flex_value_set_id       NUMBER;
40177 l_adr_value_type_code         VARCHAR2(30);
40178 l_adr_value_combination_id    NUMBER;
40179 l_adr_value_segment_code      VARCHAR2(30);
40180 
40181 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
40182 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
40183 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
40184 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
40185 
40186 -- 4262811 Variables ------------------------------------------------------------------------------------------
40187 l_entered_amt_idx             NUMBER;
40188 l_accted_amt_idx              NUMBER;
40189 l_acc_rev_flag                VARCHAR2(1);
40190 l_accrual_line_num            NUMBER;
40191 l_tmp_amt                     NUMBER;
40192 l_acc_rev_natural_side_code   VARCHAR2(1);
40193 
40194 l_num_entries                 NUMBER;
40195 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
40196 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
40197 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
40198 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
40199 l_recog_line_1                NUMBER;
40200 l_recog_line_2                NUMBER;
40201 
40202 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
40203 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
40204 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
40205 
40209 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
40206 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
40207 
40208 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
40210 
40211 ---------------------------------------------------------------------------------------------------------------
40212 
40213 
40214 --
40215 -- bulk performance
40216 --
40217 l_balance_type_code           VARCHAR2(1);
40218 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
40219 l_log_module                  VARCHAR2(240);
40220 
40221 --
40222 -- Upgrade strategy
40223 --
40224 l_actual_upg_option           VARCHAR2(1);
40225 l_enc_upg_option           VARCHAR2(1);
40226 
40227 --
40228 BEGIN
40229 --
40230 IF g_log_enabled THEN
40231       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_89';
40232 END IF;
40233 --
40234 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
40235 
40236       trace
40237          (p_msg      => 'BEGIN of AcctLineType_89'
40238          ,p_level    => C_LEVEL_PROCEDURE
40239          ,p_module   => l_log_module);
40240 
40241 END IF;
40242 --
40243 l_component_type             := 'AMB_JLT';
40244 l_component_code             := 'MFAR_INV_REC';
40245 l_component_type_code        := 'S';
40246 l_component_appl_id          :=  222;
40247 l_amb_context_code           := 'DEFAULT';
40248 l_entity_code                := 'TRANSACTIONS';
40249 l_event_class_code           := 'INVOICE';
40250 l_event_type_code            := 'INVOICE_ALL';
40251 l_line_definition_owner_code := 'S';
40252 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
40253 --
40254 l_balance_type_code          := 'A';
40255 l_segment                     := NULL;
40256 l_ccid                        := NULL;
40257 l_adr_transaction_coa_id      := NULL;
40258 l_adr_accounting_coa_id       := NULL;
40259 l_adr_flexfield_segment_code  := NULL;
40260 l_adr_flex_value_set_id       := NULL;
40261 l_adr_value_type_code         := NULL;
40262 l_adr_value_combination_id    := NULL;
40263 l_adr_value_segment_code      := NULL;
40264 
40265 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
40266 l_bflow_class_code           := 'RECEIVABLE';    -- 4219869 Business Flow
40267 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
40268 l_budgetary_control_flag     := 'N';
40269 
40270 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
40271 l_bflow_applied_to_amt       := NULL; -- 5132302
40272 l_entered_amt_idx            := NULL;          -- 4262811
40273 l_accted_amt_idx             := NULL;          -- 4262811
40274 l_acc_rev_flag               := NULL;          -- 4262811
40275 l_accrual_line_num           := NULL;          -- 4262811
40276 l_tmp_amt                    := NULL;          -- 4262811
40277 --
40278  
40279 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
40280     l_balance_type_code <> 'B' THEN
40281 IF (p_source_68 IS NULL ) AND 
40282 (NVL(p_source_33,'
40283 ') =  'REV' OR 
40284 NVL(p_source_33,'
40285 ') =  'TAX' OR 
40286 NVL(p_source_33,'
40287 ') =  'FREIGHT' OR 
40288 NVL(p_source_33,'
40289 ') =  'ROUND' OR 
40290 NVL(p_source_33,'
40291 ') =  'CHARGES')
40292  THEN 
40293 
40294    --
40295    XLA_AE_LINES_PKG.SetNewLine;
40296 
40297    p_balance_type_code          := l_balance_type_code;
40298    -- set the flag so later we will know whether the gain loss line needs to be created
40299    
40300    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
40301      p_actual_flag :='A';
40302    END IF;
40303 
40304    --
40305    -- bulk performance
40306    --
40307    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
40308                                       p_header_num   => 0); -- 4262811
40309    --
40310    -- set accounting line options
40311    --
40312    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
40313            p_natural_side_code          => 'D'
40314          , p_gain_or_loss_flag          => 'N'
40315          , p_gl_transfer_mode_code      => 'S'
40316          , p_acct_entry_type_code       => 'A'
40317          , p_switch_side_flag           => 'Y'
40318          , p_merge_duplicate_code       => 'A'
40319          );
40320    --
40321    l_acc_rev_natural_side_code := 'C';  -- 4262811
40322    -- 
40323    --
40324    -- set accounting line type info
40325    --
40326    xla_ae_lines_pkg.SetAcctLineType
40327       (p_component_type             => l_component_type
40328       ,p_event_type_code            => l_event_type_code
40329       ,p_line_definition_owner_code => l_line_definition_owner_code
40330       ,p_line_definition_code       => l_line_definition_code
40331       ,p_accounting_line_code       => l_component_code
40332       ,p_accounting_line_type_code  => l_component_type_code
40333       ,p_accounting_line_appl_id    => l_component_appl_id
40334       ,p_amb_context_code           => l_amb_context_code
40335       ,p_entity_code                => l_entity_code
40336       ,p_event_class_code           => l_event_class_code);
40337    --
40338    -- set accounting class
40339    --
40340    xla_ae_lines_pkg.SetAcctClass(
40341            p_accounting_class_code  => 'RECEIVABLE'
40345    --
40342          , p_ae_header_id           => l_ae_header_id
40343          );
40344 
40346    -- set rounding class
40347    --
40348    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
40349                       'RECEIVABLE';
40350 
40351    --
40352    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
40353    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
40354    --
40355    -- bulk performance
40356    --
40357    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
40358 
40359    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
40360       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
40361 
40362    -- 4955764
40363    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
40364       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
40365 
40366    -- 4458381 Public Sector Enh
40367    
40368    --
40369    -- set accounting attributes for the line type
40370    --
40371    l_entered_amt_idx := 3;
40372    l_accted_amt_idx  := 8;
40373    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
40374    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
40375    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_34);
40376    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
40377    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
40378    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
40379    l_rec_acct_attrs.array_num_value(3)  := p_source_36;
40380    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
40381    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
40382    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
40383    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
40384    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
40385    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
40386    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
40387    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
40388    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
40389    l_rec_acct_attrs.array_num_value(8)  := p_source_41;
40390    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
40391    l_rec_acct_attrs.array_num_value(9)  := p_source_30;
40392    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
40393    l_rec_acct_attrs.array_num_value(10)  := p_source_31;
40394    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
40395    l_rec_acct_attrs.array_char_value(11)  := p_source_32;
40396    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
40397    l_rec_acct_attrs.array_num_value(12)  := p_source_55;
40398 
40399    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
40400    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
40401 
40402    ---------------------------------------------------------------------------------------------------------------
40403    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
40404    ---------------------------------------------------------------------------------------------------------------
40405    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
40406 
40407    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
40408    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
40409 
40410    IF xla_accounting_cache_pkg.GetValueChar
40411          (p_source_code         => 'LEDGER_CATEGORY_CODE'
40412          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
40413    AND l_bflow_method_code = 'PRIOR_ENTRY'
40414 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
40415    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
40416          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
40417        )
40418    THEN
40419          xla_ae_lines_pkg.BflowUpgEntry
40420            (p_business_method_code    => l_bflow_method_code
40421            ,p_business_class_code     => l_bflow_class_code
40422            ,p_balance_type            => l_balance_type_code);
40423    ELSE
40424       NULL;
40425 -- No business flow processing for business flow method of NONE.
40426    END IF;
40427 
40428    --
40429    -- call analytical criteria
40430    --
40431    
40432    --
40433    -- call description
40434    --
40435    
40436 xla_ae_lines_pkg.SetLineDescription(
40437    p_ae_header_id => l_ae_header_id
40438   ,p_description  => Description_1 (
40439      p_application_id         => p_application_id
40440    , p_ae_header_id           => l_ae_header_id 
40441    )
40442 );
40443 
40444 
40445    --
40446    -- call ADRs
40447    -- Bug 4922099
40448    --
40449    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
40450         (NVL(l_actual_upg_option, 'N') = 'O') OR
40451         (NVL(l_enc_upg_option, 'N') = 'O')
40452       )
40453    THEN
40454    NULL;
40455    --
40456    --
40457    
40458   l_ccid := AcctDerRule_28(
40459            p_application_id           => p_application_id
40460          , p_ae_header_id             => l_ae_header_id 
40464          , x_value_type_code          => l_adr_value_type_code
40461 , p_source_16 => p_source_16
40462          , x_transaction_coa_id       => l_adr_transaction_coa_id
40463          , x_accounting_coa_id        => l_adr_accounting_coa_id
40465          , p_side                     => 'NA'
40466    );
40467 
40468    xla_ae_lines_pkg.set_ccid(
40469     p_code_combination_id          => l_ccid
40470   , p_value_type_code              => l_adr_value_type_code
40471   , p_transaction_coa_id           => l_adr_transaction_coa_id
40472   , p_accounting_coa_id            => l_adr_accounting_coa_id
40473   , p_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
40474   , p_adr_type_code                => 'S'
40475   , p_component_type               => l_component_type
40476   , p_component_code               => l_component_code
40477   , p_component_type_code          => l_component_type_code
40478   , p_component_appl_id            => l_component_appl_id
40479   , p_amb_context_code             => l_amb_context_code
40480   , p_side                         => 'NA'
40481   );
40482 
40483 
40484    l_segment := AcctDerRule_5(
40485            p_application_id           => p_application_id
40486          , p_ae_header_id             => l_ae_header_id 
40487 , p_source_4 => p_source_4
40488          , x_transaction_coa_id       => l_adr_transaction_coa_id
40489          , x_accounting_coa_id        => l_adr_accounting_coa_id
40490          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
40491          , x_flex_value_set_id        => l_adr_flex_value_set_id
40492          , x_value_type_code          => l_adr_value_type_code
40493          , x_value_combination_id     => l_adr_value_combination_id
40494          , x_value_segment_code       => l_adr_value_segment_code
40495          , p_side                     => 'NA'
40496          , p_override_seg_flag        => 'Y'
40497    );
40498 
40499    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
40500 
40501       xla_ae_lines_pkg.set_segment(
40502           p_to_segment_code         => 'GL_BALANCING'
40503         , p_segment_value           => l_segment
40504         , p_from_segment_code       => l_adr_value_segment_code
40505         , p_from_combination_id     => l_adr_value_combination_id
40506         , p_value_type_code         => l_adr_value_type_code
40507         , p_transaction_coa_id      => l_adr_transaction_coa_id
40508         , p_accounting_coa_id       => l_adr_accounting_coa_id
40509         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
40510         , p_flex_value_set_id       => l_adr_flex_value_set_id
40511         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
40512         , p_adr_type_code           => 'S'
40513         , p_component_type          => l_component_type
40514         , p_component_code          => l_component_code
40515         , p_component_type_code     => l_component_type_code
40516         , p_component_appl_id       => l_component_appl_id
40517         , p_amb_context_code        => l_amb_context_code
40518         , p_entity_code             => 'TRANSACTIONS'
40519         , p_event_class_code        => 'INVOICE'
40520         , p_side                    => 'NA'
40521         );
40522 
40523   END IF;
40524 
40525    --
40526    --
40527    END IF;
40528    --
40529    -- Bug 4922099
40530    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
40531           (NVL(l_enc_upg_option, 'N') = 'O')
40532         ) AND
40533         (l_bflow_method_code = 'PRIOR_ENTRY')
40534       )
40535    THEN
40536       IF
40537       --
40538       1 = 2
40539       --
40540       THEN
40541       xla_accounting_err_pkg.build_message
40542                                     (p_appli_s_name            => 'XLA'
40543                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
40544                                     ,p_token_1                 => 'LINE_NUMBER'
40545                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
40546                                     ,p_token_2                 => 'LINE_TYPE_NAME'
40547                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
40548                                                                              l_component_type
40549                                                                             ,l_component_code
40550                                                                             ,l_component_type_code
40551                                                                             ,l_component_appl_id
40552                                                                             ,l_amb_context_code
40553                                                                             ,l_entity_code
40554                                                                             ,l_event_class_code
40555                                                                            )
40556                                     ,p_token_3                 => 'OWNER'
40557                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
40558                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
40559                                                                           ,p_lookup_code    => l_component_type_code
40560                                                                          )
40561                                     ,p_token_4                 => 'PRODUCT_NAME'
40565                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
40562                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
40563                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
40564                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
40566                                     ,p_ae_header_id            =>  NULL
40567                                        );
40568 
40569         IF (C_LEVEL_ERROR>= g_log_level) THEN
40570                  trace
40571                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
40572                       ,p_level    => C_LEVEL_ERROR
40573                       ,p_module   => l_log_module);
40574         END IF;
40575       END IF;
40576    END IF;
40577    --
40578    --
40579    ------------------------------------------------------------------------------------------------
40580    -- 4219869 Business Flow
40581    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
40582    -- Prior Entry.  Currently, the following code is always generated.
40583    ------------------------------------------------------------------------------------------------
40584    XLA_AE_LINES_PKG.ValidateCurrentLine;
40585 
40586    ------------------------------------------------------------------------------------
40587    -- 4219869 Business Flow
40588    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
40589    ------------------------------------------------------------------------------------
40590    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
40591 
40592    ----------------------------------------------------------------------------------
40593    -- 4219869 Business Flow
40594    -- Update journal entry status -- Need to generate this within IF <condition>
40595    ----------------------------------------------------------------------------------
40596    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
40597          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
40598          ,p_balance_type_code => l_balance_type_code
40599          );
40600 
40601    -------------------------------------------------------------------------------------------
40602    -- 4262811 - Generate the Accrual Reversal lines
40603    -------------------------------------------------------------------------------------------
40604    BEGIN
40605       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
40606                               (g_array_event(p_event_id).array_value_num('header_index'));
40607       IF l_acc_rev_flag IS NULL THEN
40608          l_acc_rev_flag := 'N';
40609       END IF;
40610    EXCEPTION
40611       WHEN OTHERS THEN
40612          l_acc_rev_flag := 'N';
40613    END;
40614    --
40615    IF (l_acc_rev_flag = 'Y') THEN
40616 
40617        -- 4645092  ------------------------------------------------------------------------------
40618        -- To allow MPA report to determine if it should generate report process
40619        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
40620        ------------------------------------------------------------------------------------------
40621 
40622        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
40623        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
40624    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
40625    -- call ADRs
40626    -- Bug 4922099
40627    --
40628    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
40629         (NVL(l_actual_upg_option, 'N') = 'O') OR
40630         (NVL(l_enc_upg_option, 'N') = 'O')
40631       )
40632    THEN
40633    NULL;
40634    --
40635    --
40636    
40637   l_ccid := AcctDerRule_28(
40638            p_application_id           => p_application_id
40639          , p_ae_header_id             => l_ae_header_id 
40640 , p_source_16 => p_source_16
40641          , x_transaction_coa_id       => l_adr_transaction_coa_id
40642          , x_accounting_coa_id        => l_adr_accounting_coa_id
40643          , x_value_type_code          => l_adr_value_type_code
40644          , p_side                     => 'NA'
40645    );
40646 
40647    xla_ae_lines_pkg.set_ccid(
40648     p_code_combination_id          => l_ccid
40649   , p_value_type_code              => l_adr_value_type_code
40650   , p_transaction_coa_id           => l_adr_transaction_coa_id
40651   , p_accounting_coa_id            => l_adr_accounting_coa_id
40652   , p_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
40653   , p_adr_type_code                => 'S'
40654   , p_component_type               => l_component_type
40655   , p_component_code               => l_component_code
40656   , p_component_type_code          => l_component_type_code
40657   , p_component_appl_id            => l_component_appl_id
40658   , p_amb_context_code             => l_amb_context_code
40659   , p_side                         => 'NA'
40660   );
40661 
40662 
40663    l_segment := AcctDerRule_5(
40664            p_application_id           => p_application_id
40665          , p_ae_header_id             => l_ae_header_id 
40666 , p_source_4 => p_source_4
40667          , x_transaction_coa_id       => l_adr_transaction_coa_id
40668          , x_accounting_coa_id        => l_adr_accounting_coa_id
40669          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
40673          , x_value_segment_code       => l_adr_value_segment_code
40670          , x_flex_value_set_id        => l_adr_flex_value_set_id
40671          , x_value_type_code          => l_adr_value_type_code
40672          , x_value_combination_id     => l_adr_value_combination_id
40674          , p_side                     => 'NA'
40675          , p_override_seg_flag        => 'Y'
40676    );
40677 
40678    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
40679 
40680       xla_ae_lines_pkg.set_segment(
40681           p_to_segment_code         => 'GL_BALANCING'
40682         , p_segment_value           => l_segment
40683         , p_from_segment_code       => l_adr_value_segment_code
40684         , p_from_combination_id     => l_adr_value_combination_id
40685         , p_value_type_code         => l_adr_value_type_code
40686         , p_transaction_coa_id      => l_adr_transaction_coa_id
40687         , p_accounting_coa_id       => l_adr_accounting_coa_id
40688         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
40689         , p_flex_value_set_id       => l_adr_flex_value_set_id
40690         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
40691         , p_adr_type_code           => 'S'
40692         , p_component_type          => l_component_type
40693         , p_component_code          => l_component_code
40694         , p_component_type_code     => l_component_type_code
40695         , p_component_appl_id       => l_component_appl_id
40696         , p_amb_context_code        => l_amb_context_code
40697         , p_entity_code             => 'TRANSACTIONS'
40698         , p_event_class_code        => 'INVOICE'
40699         , p_side                    => 'NA'
40700         );
40701 
40702   END IF;
40703 
40704    --
40705    --
40706    END IF;
40707 
40708        --
40709        -- Update the line information that should be overwritten
40710        --
40711        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
40712                                          p_header_num   => 1);
40713        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
40714 
40715        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
40716 
40717        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
40718           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
40719        END IF;
40720 
40721       --
40722       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
40723       --
40724       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
40725           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
40726       ELSE
40727           ---------------------------------------------------------------------------------------------------
40728           -- 4262811a Switch Sign
40729           ---------------------------------------------------------------------------------------------------
40730           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
40731           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
40732                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
40733           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
40734                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
40735           -- 5132302
40736           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
40737                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
40738 
40739       END IF;
40740 
40741       -- 4955764
40742       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
40743       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
40744 
40745 
40746       XLA_AE_LINES_PKG.ValidateCurrentLine;
40747       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
40748 
40749       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
40750                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
40751                ,p_balance_type_code => l_balance_type_code);
40752 
40753    END IF;
40754 
40755    -----------------------------------------------------------------------------------------
40756    -- 4262811 Multiperiod Accounting
40757    -----------------------------------------------------------------------------------------
40758      -- No MPA option is assigned.
40759 
40760 
40761 END IF;
40762 END IF;
40763 --
40764 
40765 --
40766 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
40767    trace
40768       (p_msg      => 'END of AcctLineType_89'
40769       ,p_level    => C_LEVEL_PROCEDURE
40770       ,p_module   => l_log_module);
40771 END IF;
40772 --
40773 EXCEPTION
40774   WHEN xla_exceptions_pkg.application_exception THEN
40775       RAISE;
40776   WHEN OTHERS THEN
40777        xla_exceptions_pkg.raise_message
40778            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_89');
40779 END AcctLineType_89;
40780 --
40781 
40782 ---------------------------------------
40786 --
40783 --
40784 -- PRIVATE FUNCTION
40785 --         AcctLineType_90
40787 ---------------------------------------
40788 PROCEDURE AcctLineType_90 (
40789   p_application_id        IN NUMBER
40790  ,p_event_id              IN NUMBER
40791  ,p_calculate_acctd_flag  IN VARCHAR2
40792  ,p_calculate_g_l_flag    IN VARCHAR2
40793  ,p_actual_flag           IN OUT VARCHAR2
40794  ,p_balance_type_code     OUT VARCHAR2
40795  ,p_gain_or_loss_ref      OUT VARCHAR2
40796  
40797 --Remittance Bank Account Bank Charges Acount
40798  , p_source_1            IN NUMBER
40799 --Remittance Bank Account Cash Account
40800  , p_source_13            IN NUMBER
40801 --Distribution Source Type
40802  , p_source_20            IN VARCHAR2
40803 --Distribution Line Identifier
40804  , p_source_22            IN NUMBER
40805 --Distribution Type
40806  , p_source_23            IN VARCHAR2
40807 --Entered Amount
40808  , p_source_24            IN NUMBER
40809 --Currency Code
40810  , p_source_25            IN VARCHAR2
40811 --Exchange Rate
40812  , p_source_27            IN NUMBER
40813 --Exchange Rate Type
40814  , p_source_28            IN VARCHAR2
40815 --Applied To Document Accounting Amount
40816  , p_source_29            IN NUMBER
40817 --Applied To Document Exchange Date
40818  , p_source_57            IN DATE
40819 --Distribution Multi Fund Additional Entry
40820  , p_source_69            IN VARCHAR2
40821 )
40822 IS
40823 
40824 l_component_type              VARCHAR2(80);
40825 l_component_code              VARCHAR2(30);
40826 l_component_type_code         VARCHAR2(1);
40827 l_component_appl_id           INTEGER;
40828 l_amb_context_code            VARCHAR2(30);
40829 l_entity_code                 VARCHAR2(30);
40830 l_event_class_code            VARCHAR2(30);
40831 l_ae_header_id                NUMBER;
40832 l_event_type_code             VARCHAR2(30);
40833 l_line_definition_code        VARCHAR2(30);
40834 l_line_definition_owner_code  VARCHAR2(1);
40835 --
40836 -- adr variables
40837 l_segment                     VARCHAR2(30);
40838 l_ccid                        NUMBER;
40839 l_adr_transaction_coa_id      NUMBER;
40840 l_adr_accounting_coa_id       NUMBER;
40841 l_adr_flexfield_segment_code  VARCHAR2(30);
40842 l_adr_flex_value_set_id       NUMBER;
40843 l_adr_value_type_code         VARCHAR2(30);
40844 l_adr_value_combination_id    NUMBER;
40845 l_adr_value_segment_code      VARCHAR2(30);
40846 
40847 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
40848 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
40849 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
40850 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
40851 
40852 -- 4262811 Variables ------------------------------------------------------------------------------------------
40853 l_entered_amt_idx             NUMBER;
40854 l_accted_amt_idx              NUMBER;
40855 l_acc_rev_flag                VARCHAR2(1);
40856 l_accrual_line_num            NUMBER;
40857 l_tmp_amt                     NUMBER;
40858 l_acc_rev_natural_side_code   VARCHAR2(1);
40859 
40860 l_num_entries                 NUMBER;
40861 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
40862 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
40863 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
40864 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
40865 l_recog_line_1                NUMBER;
40866 l_recog_line_2                NUMBER;
40867 
40868 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
40869 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
40870 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
40871 
40872 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
40873 
40874 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
40875 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
40876 
40877 ---------------------------------------------------------------------------------------------------------------
40878 
40879 
40880 --
40881 -- bulk performance
40882 --
40883 l_balance_type_code           VARCHAR2(1);
40884 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
40885 l_log_module                  VARCHAR2(240);
40886 
40887 --
40888 -- Upgrade strategy
40889 --
40890 l_actual_upg_option           VARCHAR2(1);
40891 l_enc_upg_option           VARCHAR2(1);
40892 
40893 --
40894 BEGIN
40895 --
40896 IF g_log_enabled THEN
40897       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_90';
40898 END IF;
40899 --
40900 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
40901 
40902       trace
40903          (p_msg      => 'BEGIN of AcctLineType_90'
40904          ,p_level    => C_LEVEL_PROCEDURE
40905          ,p_module   => l_log_module);
40906 
40907 END IF;
40908 --
40909 l_component_type             := 'AMB_JLT';
40910 l_component_code             := 'MFAR_MISC_RCT_BNK_CHG_CASH';
40911 l_component_type_code        := 'S';
40912 l_component_appl_id          :=  222;
40913 l_amb_context_code           := 'DEFAULT';
40914 l_entity_code                := 'RECEIPTS';
40915 l_event_class_code           := 'MISC_RECEIPT';
40919 --
40916 l_event_type_code            := 'MISC_RECEIPT_ALL';
40917 l_line_definition_owner_code := 'S';
40918 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
40920 l_balance_type_code          := 'A';
40921 l_segment                     := NULL;
40922 l_ccid                        := NULL;
40923 l_adr_transaction_coa_id      := NULL;
40924 l_adr_accounting_coa_id       := NULL;
40925 l_adr_flexfield_segment_code  := NULL;
40926 l_adr_flex_value_set_id       := NULL;
40927 l_adr_value_type_code         := NULL;
40928 l_adr_value_combination_id    := NULL;
40929 l_adr_value_segment_code      := NULL;
40930 
40931 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
40932 l_bflow_class_code           := '';    -- 4219869 Business Flow
40933 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
40934 l_budgetary_control_flag     := 'N';
40935 
40936 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
40937 l_bflow_applied_to_amt       := NULL; -- 5132302
40938 l_entered_amt_idx            := NULL;          -- 4262811
40939 l_accted_amt_idx             := NULL;          -- 4262811
40940 l_acc_rev_flag               := NULL;          -- 4262811
40941 l_accrual_line_num           := NULL;          -- 4262811
40942 l_tmp_amt                    := NULL;          -- 4262811
40943 --
40944  
40945 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
40946     l_balance_type_code <> 'B' THEN
40947 IF NVL(p_source_20,'
40948 ') =  'BANK_CHARGES' AND 
40949 NVL(p_source_69,'
40950 ') =  'N'
40951  THEN 
40952 
40953    --
40954    XLA_AE_LINES_PKG.SetNewLine;
40955 
40956    p_balance_type_code          := l_balance_type_code;
40957    -- set the flag so later we will know whether the gain loss line needs to be created
40958    
40959    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
40960      p_actual_flag :='A';
40961    END IF;
40962 
40963    --
40964    -- bulk performance
40965    --
40966    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
40967                                       p_header_num   => 0); -- 4262811
40968    --
40969    -- set accounting line options
40970    --
40971    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
40972            p_natural_side_code          => 'D'
40973          , p_gain_or_loss_flag          => 'N'
40974          , p_gl_transfer_mode_code      => 'S'
40975          , p_acct_entry_type_code       => 'A'
40976          , p_switch_side_flag           => 'Y'
40977          , p_merge_duplicate_code       => 'A'
40978          );
40979    --
40980    l_acc_rev_natural_side_code := 'C';  -- 4262811
40981    -- 
40982    --
40983    -- set accounting line type info
40984    --
40985    xla_ae_lines_pkg.SetAcctLineType
40986       (p_component_type             => l_component_type
40987       ,p_event_type_code            => l_event_type_code
40988       ,p_line_definition_owner_code => l_line_definition_owner_code
40989       ,p_line_definition_code       => l_line_definition_code
40990       ,p_accounting_line_code       => l_component_code
40991       ,p_accounting_line_type_code  => l_component_type_code
40992       ,p_accounting_line_appl_id    => l_component_appl_id
40993       ,p_amb_context_code           => l_amb_context_code
40994       ,p_entity_code                => l_entity_code
40995       ,p_event_class_code           => l_event_class_code);
40996    --
40997    -- set accounting class
40998    --
40999    xla_ae_lines_pkg.SetAcctClass(
41000            p_accounting_class_code  => 'BANK_CHG'
41001          , p_ae_header_id           => l_ae_header_id
41002          );
41003 
41004    --
41005    -- set rounding class
41006    --
41007    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
41008                       'RECEIVABLE';
41009 
41010    --
41011    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
41012    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
41013    --
41014    -- bulk performance
41015    --
41016    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
41017 
41018    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
41019       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
41020 
41021    -- 4955764
41022    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
41023       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
41024 
41025    -- 4458381 Public Sector Enh
41026    
41027    --
41028    -- set accounting attributes for the line type
41029    --
41030    l_entered_amt_idx := 3;
41031    l_accted_amt_idx  := 8;
41032    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
41033    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
41034    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
41035    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
41036    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
41037    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
41038    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
41039    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
41040    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
41044    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
41041    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
41042    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
41043    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
41045    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
41046    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
41047    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
41048    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
41049 
41050    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
41051    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
41052 
41053    ---------------------------------------------------------------------------------------------------------------
41054    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
41055    ---------------------------------------------------------------------------------------------------------------
41056    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
41057 
41058    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
41059    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
41060 
41061    IF xla_accounting_cache_pkg.GetValueChar
41062          (p_source_code         => 'LEDGER_CATEGORY_CODE'
41063          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
41064    AND l_bflow_method_code = 'PRIOR_ENTRY'
41065 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
41066    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
41067          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
41068        )
41069    THEN
41070          xla_ae_lines_pkg.BflowUpgEntry
41071            (p_business_method_code    => l_bflow_method_code
41072            ,p_business_class_code     => l_bflow_class_code
41073            ,p_balance_type            => l_balance_type_code);
41074    ELSE
41075       NULL;
41076 -- No business flow processing for business flow method of NONE.
41077    END IF;
41078 
41079    --
41080    -- call analytical criteria
41081    --
41082    
41083    --
41084    -- call description
41085    --
41086    
41087 xla_ae_lines_pkg.SetLineDescription(
41088    p_ae_header_id => l_ae_header_id
41089   ,p_description  => Description_1 (
41090      p_application_id         => p_application_id
41091    , p_ae_header_id           => l_ae_header_id 
41092    )
41093 );
41094 
41095 
41096    --
41097    -- call ADRs
41098    -- Bug 4922099
41099    --
41100    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
41101         (NVL(l_actual_upg_option, 'N') = 'O') OR
41102         (NVL(l_enc_upg_option, 'N') = 'O')
41103       )
41104    THEN
41105    NULL;
41106    --
41107    --
41108    
41109   l_ccid := AcctDerRule_25(
41110            p_application_id           => p_application_id
41111          , p_ae_header_id             => l_ae_header_id 
41112 , p_source_13 => p_source_13
41113          , x_transaction_coa_id       => l_adr_transaction_coa_id
41114          , x_accounting_coa_id        => l_adr_accounting_coa_id
41115          , x_value_type_code          => l_adr_value_type_code
41116          , p_side                     => 'NA'
41117    );
41118 
41119    xla_ae_lines_pkg.set_ccid(
41120     p_code_combination_id          => l_ccid
41121   , p_value_type_code              => l_adr_value_type_code
41122   , p_transaction_coa_id           => l_adr_transaction_coa_id
41123   , p_accounting_coa_id            => l_adr_accounting_coa_id
41124   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
41125   , p_adr_type_code                => 'S'
41126   , p_component_type               => l_component_type
41127   , p_component_code               => l_component_code
41128   , p_component_type_code          => l_component_type_code
41129   , p_component_appl_id            => l_component_appl_id
41130   , p_amb_context_code             => l_amb_context_code
41131   , p_side                         => 'NA'
41132   );
41133 
41134 
41135    l_segment := AcctDerRule_2(
41136            p_application_id           => p_application_id
41137          , p_ae_header_id             => l_ae_header_id 
41138 , p_source_1 => p_source_1
41139          , x_transaction_coa_id       => l_adr_transaction_coa_id
41140          , x_accounting_coa_id        => l_adr_accounting_coa_id
41141          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
41142          , x_flex_value_set_id        => l_adr_flex_value_set_id
41143          , x_value_type_code          => l_adr_value_type_code
41144          , x_value_combination_id     => l_adr_value_combination_id
41145          , x_value_segment_code       => l_adr_value_segment_code
41146          , p_side                     => 'NA'
41147          , p_override_seg_flag        => 'Y'
41148    );
41149 
41150    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
41151 
41152       xla_ae_lines_pkg.set_segment(
41153           p_to_segment_code         => 'GL_BALANCING'
41154         , p_segment_value           => l_segment
41155         , p_from_segment_code       => l_adr_value_segment_code
41156         , p_from_combination_id     => l_adr_value_combination_id
41157         , p_value_type_code         => l_adr_value_type_code
41158         , p_transaction_coa_id      => l_adr_transaction_coa_id
41162         , p_adr_code                => 'MFAR_BNK_CHARGES_BALANCING_SEG'
41159         , p_accounting_coa_id       => l_adr_accounting_coa_id
41160         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
41161         , p_flex_value_set_id       => l_adr_flex_value_set_id
41163         , p_adr_type_code           => 'S'
41164         , p_component_type          => l_component_type
41165         , p_component_code          => l_component_code
41166         , p_component_type_code     => l_component_type_code
41167         , p_component_appl_id       => l_component_appl_id
41168         , p_amb_context_code        => l_amb_context_code
41169         , p_entity_code             => 'RECEIPTS'
41170         , p_event_class_code        => 'MISC_RECEIPT'
41171         , p_side                    => 'NA'
41172         );
41173 
41174   END IF;
41175 
41176    --
41177    --
41178    END IF;
41179    --
41180    -- Bug 4922099
41181    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
41182           (NVL(l_enc_upg_option, 'N') = 'O')
41183         ) AND
41184         (l_bflow_method_code = 'PRIOR_ENTRY')
41185       )
41186    THEN
41187       IF
41188       --
41189       1 = 2
41190       --
41191       THEN
41192       xla_accounting_err_pkg.build_message
41193                                     (p_appli_s_name            => 'XLA'
41194                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
41195                                     ,p_token_1                 => 'LINE_NUMBER'
41196                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
41197                                     ,p_token_2                 => 'LINE_TYPE_NAME'
41198                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
41199                                                                              l_component_type
41200                                                                             ,l_component_code
41201                                                                             ,l_component_type_code
41202                                                                             ,l_component_appl_id
41203                                                                             ,l_amb_context_code
41204                                                                             ,l_entity_code
41205                                                                             ,l_event_class_code
41206                                                                            )
41207                                     ,p_token_3                 => 'OWNER'
41208                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
41209                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
41210                                                                           ,p_lookup_code    => l_component_type_code
41211                                                                          )
41212                                     ,p_token_4                 => 'PRODUCT_NAME'
41213                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
41214                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
41215                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
41216                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
41217                                     ,p_ae_header_id            =>  NULL
41218                                        );
41219 
41220         IF (C_LEVEL_ERROR>= g_log_level) THEN
41221                  trace
41222                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
41223                       ,p_level    => C_LEVEL_ERROR
41224                       ,p_module   => l_log_module);
41225         END IF;
41226       END IF;
41227    END IF;
41228    --
41229    --
41230    ------------------------------------------------------------------------------------------------
41231    -- 4219869 Business Flow
41232    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
41233    -- Prior Entry.  Currently, the following code is always generated.
41234    ------------------------------------------------------------------------------------------------
41235    XLA_AE_LINES_PKG.ValidateCurrentLine;
41236 
41237    ------------------------------------------------------------------------------------
41238    -- 4219869 Business Flow
41239    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
41240    ------------------------------------------------------------------------------------
41241    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
41242 
41243    ----------------------------------------------------------------------------------
41244    -- 4219869 Business Flow
41245    -- Update journal entry status -- Need to generate this within IF <condition>
41246    ----------------------------------------------------------------------------------
41247    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
41248          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
41249          ,p_balance_type_code => l_balance_type_code
41250          );
41251 
41252    -------------------------------------------------------------------------------------------
41253    -- 4262811 - Generate the Accrual Reversal lines
41257                               (g_array_event(p_event_id).array_value_num('header_index'));
41254    -------------------------------------------------------------------------------------------
41255    BEGIN
41256       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
41258       IF l_acc_rev_flag IS NULL THEN
41259          l_acc_rev_flag := 'N';
41260       END IF;
41261    EXCEPTION
41262       WHEN OTHERS THEN
41263          l_acc_rev_flag := 'N';
41264    END;
41265    --
41266    IF (l_acc_rev_flag = 'Y') THEN
41267 
41268        -- 4645092  ------------------------------------------------------------------------------
41269        -- To allow MPA report to determine if it should generate report process
41270        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
41271        ------------------------------------------------------------------------------------------
41272 
41273        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
41274        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
41275    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
41276    -- call ADRs
41277    -- Bug 4922099
41278    --
41279    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
41280         (NVL(l_actual_upg_option, 'N') = 'O') OR
41281         (NVL(l_enc_upg_option, 'N') = 'O')
41282       )
41283    THEN
41284    NULL;
41285    --
41286    --
41287    
41288   l_ccid := AcctDerRule_25(
41289            p_application_id           => p_application_id
41290          , p_ae_header_id             => l_ae_header_id 
41291 , p_source_13 => p_source_13
41292          , x_transaction_coa_id       => l_adr_transaction_coa_id
41293          , x_accounting_coa_id        => l_adr_accounting_coa_id
41294          , x_value_type_code          => l_adr_value_type_code
41295          , p_side                     => 'NA'
41296    );
41297 
41298    xla_ae_lines_pkg.set_ccid(
41299     p_code_combination_id          => l_ccid
41300   , p_value_type_code              => l_adr_value_type_code
41301   , p_transaction_coa_id           => l_adr_transaction_coa_id
41302   , p_accounting_coa_id            => l_adr_accounting_coa_id
41303   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
41304   , p_adr_type_code                => 'S'
41305   , p_component_type               => l_component_type
41306   , p_component_code               => l_component_code
41307   , p_component_type_code          => l_component_type_code
41308   , p_component_appl_id            => l_component_appl_id
41309   , p_amb_context_code             => l_amb_context_code
41310   , p_side                         => 'NA'
41311   );
41312 
41313 
41314    l_segment := AcctDerRule_2(
41315            p_application_id           => p_application_id
41316          , p_ae_header_id             => l_ae_header_id 
41317 , p_source_1 => p_source_1
41318          , x_transaction_coa_id       => l_adr_transaction_coa_id
41319          , x_accounting_coa_id        => l_adr_accounting_coa_id
41320          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
41321          , x_flex_value_set_id        => l_adr_flex_value_set_id
41322          , x_value_type_code          => l_adr_value_type_code
41323          , x_value_combination_id     => l_adr_value_combination_id
41324          , x_value_segment_code       => l_adr_value_segment_code
41325          , p_side                     => 'NA'
41326          , p_override_seg_flag        => 'Y'
41327    );
41328 
41329    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
41330 
41331       xla_ae_lines_pkg.set_segment(
41332           p_to_segment_code         => 'GL_BALANCING'
41333         , p_segment_value           => l_segment
41334         , p_from_segment_code       => l_adr_value_segment_code
41335         , p_from_combination_id     => l_adr_value_combination_id
41336         , p_value_type_code         => l_adr_value_type_code
41337         , p_transaction_coa_id      => l_adr_transaction_coa_id
41338         , p_accounting_coa_id       => l_adr_accounting_coa_id
41339         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
41340         , p_flex_value_set_id       => l_adr_flex_value_set_id
41341         , p_adr_code                => 'MFAR_BNK_CHARGES_BALANCING_SEG'
41342         , p_adr_type_code           => 'S'
41343         , p_component_type          => l_component_type
41344         , p_component_code          => l_component_code
41345         , p_component_type_code     => l_component_type_code
41346         , p_component_appl_id       => l_component_appl_id
41347         , p_amb_context_code        => l_amb_context_code
41348         , p_entity_code             => 'RECEIPTS'
41349         , p_event_class_code        => 'MISC_RECEIPT'
41350         , p_side                    => 'NA'
41351         );
41352 
41353   END IF;
41354 
41355    --
41356    --
41357    END IF;
41358 
41359        --
41360        -- Update the line information that should be overwritten
41361        --
41362        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
41363                                          p_header_num   => 1);
41364        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
41365 
41366        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
41367 
41368        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
41372       --
41369           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
41370        END IF;
41371 
41373       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
41374       --
41375       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
41376           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
41377       ELSE
41378           ---------------------------------------------------------------------------------------------------
41379           -- 4262811a Switch Sign
41380           ---------------------------------------------------------------------------------------------------
41381           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
41382           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
41383                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
41384           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
41385                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
41386           -- 5132302
41387           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
41388                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
41389 
41390       END IF;
41391 
41392       -- 4955764
41393       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
41394       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
41395 
41396 
41397       XLA_AE_LINES_PKG.ValidateCurrentLine;
41398       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
41399 
41400       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
41401                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
41402                ,p_balance_type_code => l_balance_type_code);
41403 
41404    END IF;
41405 
41406    -----------------------------------------------------------------------------------------
41407    -- 4262811 Multiperiod Accounting
41408    -----------------------------------------------------------------------------------------
41409      -- No MPA option is assigned.
41410 
41411 
41412 END IF;
41413 END IF;
41414 --
41415 
41416 --
41417 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
41418    trace
41419       (p_msg      => 'END of AcctLineType_90'
41420       ,p_level    => C_LEVEL_PROCEDURE
41421       ,p_module   => l_log_module);
41422 END IF;
41423 --
41424 EXCEPTION
41425   WHEN xla_exceptions_pkg.application_exception THEN
41426       RAISE;
41427   WHEN OTHERS THEN
41428        xla_exceptions_pkg.raise_message
41429            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_90');
41430 END AcctLineType_90;
41431 --
41432 
41433 ---------------------------------------
41434 --
41435 -- PRIVATE FUNCTION
41436 --         AcctLineType_91
41437 --
41438 ---------------------------------------
41439 PROCEDURE AcctLineType_91 (
41440   p_application_id        IN NUMBER
41441  ,p_event_id              IN NUMBER
41442  ,p_calculate_acctd_flag  IN VARCHAR2
41443  ,p_calculate_g_l_flag    IN VARCHAR2
41444  ,p_actual_flag           IN OUT VARCHAR2
41445  ,p_balance_type_code     OUT VARCHAR2
41446  ,p_gain_or_loss_ref      OUT VARCHAR2
41447  
41448 --Distribution GL Account
41449  , p_source_3            IN NUMBER
41450 --Remittance Bank Account Cash Account
41451  , p_source_13            IN NUMBER
41452 --Distribution Source Type
41453  , p_source_20            IN VARCHAR2
41454 --Distribution Line Identifier
41455  , p_source_22            IN NUMBER
41456 --Distribution Type
41457  , p_source_23            IN VARCHAR2
41458 --Entered Amount
41459  , p_source_24            IN NUMBER
41460 --Currency Code
41461  , p_source_25            IN VARCHAR2
41462 --Exchange Rate
41463  , p_source_27            IN NUMBER
41464 --Exchange Rate Type
41465  , p_source_28            IN VARCHAR2
41466 --Applied To Document Accounting Amount
41467  , p_source_29            IN NUMBER
41468 --Applied To Document Exchange Date
41469  , p_source_57            IN DATE
41470 --Distribution Multi Fund Additional Entry
41471  , p_source_69            IN VARCHAR2
41472 --Receipt Class Require Remittance Flag
41473  , p_source_70            IN VARCHAR2
41474 --Receipt Class Confirm Flag
41475  , p_source_71            IN VARCHAR2
41476 )
41477 IS
41478 
41479 l_component_type              VARCHAR2(80);
41480 l_component_code              VARCHAR2(30);
41481 l_component_type_code         VARCHAR2(1);
41482 l_component_appl_id           INTEGER;
41483 l_amb_context_code            VARCHAR2(30);
41484 l_entity_code                 VARCHAR2(30);
41485 l_event_class_code            VARCHAR2(30);
41486 l_ae_header_id                NUMBER;
41487 l_event_type_code             VARCHAR2(30);
41488 l_line_definition_code        VARCHAR2(30);
41489 l_line_definition_owner_code  VARCHAR2(1);
41490 --
41491 -- adr variables
41492 l_segment                     VARCHAR2(30);
41493 l_ccid                        NUMBER;
41497 l_adr_flex_value_set_id       NUMBER;
41494 l_adr_transaction_coa_id      NUMBER;
41495 l_adr_accounting_coa_id       NUMBER;
41496 l_adr_flexfield_segment_code  VARCHAR2(30);
41498 l_adr_value_type_code         VARCHAR2(30);
41499 l_adr_value_combination_id    NUMBER;
41500 l_adr_value_segment_code      VARCHAR2(30);
41501 
41502 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
41503 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
41504 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
41505 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
41506 
41507 -- 4262811 Variables ------------------------------------------------------------------------------------------
41508 l_entered_amt_idx             NUMBER;
41509 l_accted_amt_idx              NUMBER;
41510 l_acc_rev_flag                VARCHAR2(1);
41511 l_accrual_line_num            NUMBER;
41512 l_tmp_amt                     NUMBER;
41513 l_acc_rev_natural_side_code   VARCHAR2(1);
41514 
41515 l_num_entries                 NUMBER;
41516 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
41517 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
41518 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
41519 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
41520 l_recog_line_1                NUMBER;
41521 l_recog_line_2                NUMBER;
41522 
41523 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
41524 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
41525 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
41526 
41527 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
41528 
41529 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
41530 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
41531 
41532 ---------------------------------------------------------------------------------------------------------------
41533 
41534 
41535 --
41536 -- bulk performance
41537 --
41538 l_balance_type_code           VARCHAR2(1);
41539 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
41540 l_log_module                  VARCHAR2(240);
41541 
41542 --
41543 -- Upgrade strategy
41544 --
41545 l_actual_upg_option           VARCHAR2(1);
41546 l_enc_upg_option           VARCHAR2(1);
41547 
41548 --
41549 BEGIN
41550 --
41551 IF g_log_enabled THEN
41552       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_91';
41553 END IF;
41554 --
41555 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
41556 
41557       trace
41558          (p_msg      => 'BEGIN of AcctLineType_91'
41559          ,p_level    => C_LEVEL_PROCEDURE
41560          ,p_module   => l_log_module);
41561 
41562 END IF;
41563 --
41564 l_component_type             := 'AMB_JLT';
41565 l_component_code             := 'MFAR_MISC_RCT_CASH';
41566 l_component_type_code        := 'S';
41567 l_component_appl_id          :=  222;
41568 l_amb_context_code           := 'DEFAULT';
41569 l_entity_code                := 'RECEIPTS';
41570 l_event_class_code           := 'MISC_RECEIPT';
41571 l_event_type_code            := 'MISC_RECEIPT_ALL';
41572 l_line_definition_owner_code := 'S';
41573 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
41574 --
41575 l_balance_type_code          := 'A';
41576 l_segment                     := NULL;
41577 l_ccid                        := NULL;
41578 l_adr_transaction_coa_id      := NULL;
41579 l_adr_accounting_coa_id       := NULL;
41580 l_adr_flexfield_segment_code  := NULL;
41581 l_adr_flex_value_set_id       := NULL;
41582 l_adr_value_type_code         := NULL;
41583 l_adr_value_combination_id    := NULL;
41584 l_adr_value_segment_code      := NULL;
41585 
41586 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
41587 l_bflow_class_code           := '';    -- 4219869 Business Flow
41588 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
41589 l_budgetary_control_flag     := 'N';
41590 
41591 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
41592 l_bflow_applied_to_amt       := NULL; -- 5132302
41593 l_entered_amt_idx            := NULL;          -- 4262811
41594 l_accted_amt_idx             := NULL;          -- 4262811
41595 l_acc_rev_flag               := NULL;          -- 4262811
41596 l_accrual_line_num           := NULL;          -- 4262811
41597 l_tmp_amt                    := NULL;          -- 4262811
41598 --
41599  
41600 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
41601     l_balance_type_code <> 'B' THEN
41602 IF (NVL(p_source_20,'
41603 ') =  'CASH' OR 
41604 NVL(p_source_20,'
41605 ') =  'TAX') AND 
41606 NVL(p_source_69,'
41607 ') =  'N' AND 
41608 NVL(p_source_70,'
41609 ') =  'N' AND 
41610 NVL(p_source_71,'
41611 ') =  'N'
41612  THEN 
41613 
41614    --
41615    XLA_AE_LINES_PKG.SetNewLine;
41616 
41617    p_balance_type_code          := l_balance_type_code;
41618    -- set the flag so later we will know whether the gain loss line needs to be created
41619    
41620    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
41621      p_actual_flag :='A';
41622    END IF;
41623 
41624    --
41625    -- bulk performance
41626    --
41627    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
41631    --
41628                                       p_header_num   => 0); -- 4262811
41629    --
41630    -- set accounting line options
41632    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
41633            p_natural_side_code          => 'C'
41634          , p_gain_or_loss_flag          => 'N'
41635          , p_gl_transfer_mode_code      => 'S'
41636          , p_acct_entry_type_code       => 'A'
41637          , p_switch_side_flag           => 'Y'
41638          , p_merge_duplicate_code       => 'A'
41639          );
41640    --
41641    l_acc_rev_natural_side_code := 'D';  -- 4262811
41642    -- 
41643    --
41644    -- set accounting line type info
41645    --
41646    xla_ae_lines_pkg.SetAcctLineType
41647       (p_component_type             => l_component_type
41648       ,p_event_type_code            => l_event_type_code
41649       ,p_line_definition_owner_code => l_line_definition_owner_code
41650       ,p_line_definition_code       => l_line_definition_code
41651       ,p_accounting_line_code       => l_component_code
41652       ,p_accounting_line_type_code  => l_component_type_code
41653       ,p_accounting_line_appl_id    => l_component_appl_id
41654       ,p_amb_context_code           => l_amb_context_code
41655       ,p_entity_code                => l_entity_code
41656       ,p_event_class_code           => l_event_class_code);
41657    --
41658    -- set accounting class
41659    --
41660    xla_ae_lines_pkg.SetAcctClass(
41661            p_accounting_class_code  => 'CASH'
41662          , p_ae_header_id           => l_ae_header_id
41663          );
41664 
41665    --
41666    -- set rounding class
41667    --
41668    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
41669                       'RECEIVABLE';
41670 
41671    --
41672    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
41673    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
41674    --
41675    -- bulk performance
41676    --
41677    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
41678 
41679    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
41680       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
41681 
41682    -- 4955764
41683    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
41684       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
41685 
41686    -- 4458381 Public Sector Enh
41687    
41688    --
41689    -- set accounting attributes for the line type
41690    --
41691    l_entered_amt_idx := 3;
41692    l_accted_amt_idx  := 8;
41693    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
41694    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
41695    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
41696    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
41697    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
41698    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
41699    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
41700    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
41701    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
41702    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
41703    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
41704    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
41705    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
41706    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
41707    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
41708    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
41709    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
41710 
41711    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
41712    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
41713 
41714    ---------------------------------------------------------------------------------------------------------------
41715    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
41716    ---------------------------------------------------------------------------------------------------------------
41717    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
41718 
41719    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
41720    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
41721 
41722    IF xla_accounting_cache_pkg.GetValueChar
41723          (p_source_code         => 'LEDGER_CATEGORY_CODE'
41724          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
41725    AND l_bflow_method_code = 'PRIOR_ENTRY'
41726 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
41727    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
41728          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
41729        )
41730    THEN
41731          xla_ae_lines_pkg.BflowUpgEntry
41732            (p_business_method_code    => l_bflow_method_code
41733            ,p_business_class_code     => l_bflow_class_code
41734            ,p_balance_type            => l_balance_type_code);
41735    ELSE
41736       NULL;
41740    --
41737 -- No business flow processing for business flow method of NONE.
41738    END IF;
41739 
41741    -- call analytical criteria
41742    --
41743    
41744    --
41745    -- call description
41746    --
41747    
41748 xla_ae_lines_pkg.SetLineDescription(
41749    p_ae_header_id => l_ae_header_id
41750   ,p_description  => Description_1 (
41751      p_application_id         => p_application_id
41752    , p_ae_header_id           => l_ae_header_id 
41753    )
41754 );
41755 
41756 
41757    --
41758    -- call ADRs
41759    -- Bug 4922099
41760    --
41761    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
41762         (NVL(l_actual_upg_option, 'N') = 'O') OR
41763         (NVL(l_enc_upg_option, 'N') = 'O')
41764       )
41765    THEN
41766    NULL;
41767    --
41768    --
41769    
41770   l_ccid := AcctDerRule_25(
41771            p_application_id           => p_application_id
41772          , p_ae_header_id             => l_ae_header_id 
41773 , p_source_13 => p_source_13
41774          , x_transaction_coa_id       => l_adr_transaction_coa_id
41775          , x_accounting_coa_id        => l_adr_accounting_coa_id
41776          , x_value_type_code          => l_adr_value_type_code
41777          , p_side                     => 'NA'
41778    );
41779 
41780    xla_ae_lines_pkg.set_ccid(
41781     p_code_combination_id          => l_ccid
41782   , p_value_type_code              => l_adr_value_type_code
41783   , p_transaction_coa_id           => l_adr_transaction_coa_id
41784   , p_accounting_coa_id            => l_adr_accounting_coa_id
41785   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
41786   , p_adr_type_code                => 'S'
41787   , p_component_type               => l_component_type
41788   , p_component_code               => l_component_code
41789   , p_component_type_code          => l_component_type_code
41790   , p_component_appl_id            => l_component_appl_id
41791   , p_amb_context_code             => l_amb_context_code
41792   , p_side                         => 'NA'
41793   );
41794 
41795 
41796    l_segment := AcctDerRule_4(
41797            p_application_id           => p_application_id
41798          , p_ae_header_id             => l_ae_header_id 
41799 , p_source_3 => p_source_3
41800          , x_transaction_coa_id       => l_adr_transaction_coa_id
41801          , x_accounting_coa_id        => l_adr_accounting_coa_id
41802          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
41803          , x_flex_value_set_id        => l_adr_flex_value_set_id
41804          , x_value_type_code          => l_adr_value_type_code
41805          , x_value_combination_id     => l_adr_value_combination_id
41806          , x_value_segment_code       => l_adr_value_segment_code
41807          , p_side                     => 'NA'
41808          , p_override_seg_flag        => 'Y'
41809    );
41810 
41811    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
41812 
41813       xla_ae_lines_pkg.set_segment(
41814           p_to_segment_code         => 'GL_BALANCING'
41815         , p_segment_value           => l_segment
41816         , p_from_segment_code       => l_adr_value_segment_code
41817         , p_from_combination_id     => l_adr_value_combination_id
41818         , p_value_type_code         => l_adr_value_type_code
41819         , p_transaction_coa_id      => l_adr_transaction_coa_id
41820         , p_accounting_coa_id       => l_adr_accounting_coa_id
41821         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
41822         , p_flex_value_set_id       => l_adr_flex_value_set_id
41823         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
41824         , p_adr_type_code           => 'S'
41825         , p_component_type          => l_component_type
41826         , p_component_code          => l_component_code
41827         , p_component_type_code     => l_component_type_code
41828         , p_component_appl_id       => l_component_appl_id
41829         , p_amb_context_code        => l_amb_context_code
41830         , p_entity_code             => 'RECEIPTS'
41831         , p_event_class_code        => 'MISC_RECEIPT'
41832         , p_side                    => 'NA'
41833         );
41834 
41835   END IF;
41836 
41837    --
41838    --
41839    END IF;
41840    --
41841    -- Bug 4922099
41842    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
41843           (NVL(l_enc_upg_option, 'N') = 'O')
41844         ) AND
41845         (l_bflow_method_code = 'PRIOR_ENTRY')
41846       )
41847    THEN
41848       IF
41849       --
41850       1 = 2
41851       --
41852       THEN
41853       xla_accounting_err_pkg.build_message
41854                                     (p_appli_s_name            => 'XLA'
41855                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
41856                                     ,p_token_1                 => 'LINE_NUMBER'
41857                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
41858                                     ,p_token_2                 => 'LINE_TYPE_NAME'
41859                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
41860                                                                              l_component_type
41861                                                                             ,l_component_code
41865                                                                             ,l_entity_code
41862                                                                             ,l_component_type_code
41863                                                                             ,l_component_appl_id
41864                                                                             ,l_amb_context_code
41866                                                                             ,l_event_class_code
41867                                                                            )
41868                                     ,p_token_3                 => 'OWNER'
41869                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
41870                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
41871                                                                           ,p_lookup_code    => l_component_type_code
41872                                                                          )
41873                                     ,p_token_4                 => 'PRODUCT_NAME'
41874                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
41875                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
41876                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
41877                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
41878                                     ,p_ae_header_id            =>  NULL
41879                                        );
41880 
41881         IF (C_LEVEL_ERROR>= g_log_level) THEN
41882                  trace
41883                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
41884                       ,p_level    => C_LEVEL_ERROR
41885                       ,p_module   => l_log_module);
41886         END IF;
41887       END IF;
41888    END IF;
41889    --
41890    --
41891    ------------------------------------------------------------------------------------------------
41892    -- 4219869 Business Flow
41893    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
41894    -- Prior Entry.  Currently, the following code is always generated.
41895    ------------------------------------------------------------------------------------------------
41896    XLA_AE_LINES_PKG.ValidateCurrentLine;
41897 
41898    ------------------------------------------------------------------------------------
41899    -- 4219869 Business Flow
41900    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
41901    ------------------------------------------------------------------------------------
41902    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
41903 
41904    ----------------------------------------------------------------------------------
41905    -- 4219869 Business Flow
41906    -- Update journal entry status -- Need to generate this within IF <condition>
41907    ----------------------------------------------------------------------------------
41908    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
41909          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
41910          ,p_balance_type_code => l_balance_type_code
41911          );
41912 
41913    -------------------------------------------------------------------------------------------
41914    -- 4262811 - Generate the Accrual Reversal lines
41915    -------------------------------------------------------------------------------------------
41916    BEGIN
41917       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
41918                               (g_array_event(p_event_id).array_value_num('header_index'));
41919       IF l_acc_rev_flag IS NULL THEN
41920          l_acc_rev_flag := 'N';
41921       END IF;
41922    EXCEPTION
41923       WHEN OTHERS THEN
41924          l_acc_rev_flag := 'N';
41925    END;
41926    --
41927    IF (l_acc_rev_flag = 'Y') THEN
41928 
41929        -- 4645092  ------------------------------------------------------------------------------
41930        -- To allow MPA report to determine if it should generate report process
41931        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
41932        ------------------------------------------------------------------------------------------
41933 
41934        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
41935        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
41936    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
41937    -- call ADRs
41938    -- Bug 4922099
41939    --
41940    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
41941         (NVL(l_actual_upg_option, 'N') = 'O') OR
41942         (NVL(l_enc_upg_option, 'N') = 'O')
41943       )
41944    THEN
41945    NULL;
41946    --
41947    --
41948    
41949   l_ccid := AcctDerRule_25(
41950            p_application_id           => p_application_id
41951          , p_ae_header_id             => l_ae_header_id 
41952 , p_source_13 => p_source_13
41953          , x_transaction_coa_id       => l_adr_transaction_coa_id
41954          , x_accounting_coa_id        => l_adr_accounting_coa_id
41955          , x_value_type_code          => l_adr_value_type_code
41956          , p_side                     => 'NA'
41957    );
41958 
41959    xla_ae_lines_pkg.set_ccid(
41963   , p_accounting_coa_id            => l_adr_accounting_coa_id
41960     p_code_combination_id          => l_ccid
41961   , p_value_type_code              => l_adr_value_type_code
41962   , p_transaction_coa_id           => l_adr_transaction_coa_id
41964   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
41965   , p_adr_type_code                => 'S'
41966   , p_component_type               => l_component_type
41967   , p_component_code               => l_component_code
41968   , p_component_type_code          => l_component_type_code
41969   , p_component_appl_id            => l_component_appl_id
41970   , p_amb_context_code             => l_amb_context_code
41971   , p_side                         => 'NA'
41972   );
41973 
41974 
41975    l_segment := AcctDerRule_4(
41976            p_application_id           => p_application_id
41977          , p_ae_header_id             => l_ae_header_id 
41978 , p_source_3 => p_source_3
41979          , x_transaction_coa_id       => l_adr_transaction_coa_id
41980          , x_accounting_coa_id        => l_adr_accounting_coa_id
41981          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
41982          , x_flex_value_set_id        => l_adr_flex_value_set_id
41983          , x_value_type_code          => l_adr_value_type_code
41984          , x_value_combination_id     => l_adr_value_combination_id
41985          , x_value_segment_code       => l_adr_value_segment_code
41986          , p_side                     => 'NA'
41987          , p_override_seg_flag        => 'Y'
41988    );
41989 
41990    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
41991 
41992       xla_ae_lines_pkg.set_segment(
41993           p_to_segment_code         => 'GL_BALANCING'
41994         , p_segment_value           => l_segment
41995         , p_from_segment_code       => l_adr_value_segment_code
41996         , p_from_combination_id     => l_adr_value_combination_id
41997         , p_value_type_code         => l_adr_value_type_code
41998         , p_transaction_coa_id      => l_adr_transaction_coa_id
41999         , p_accounting_coa_id       => l_adr_accounting_coa_id
42000         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
42001         , p_flex_value_set_id       => l_adr_flex_value_set_id
42002         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
42003         , p_adr_type_code           => 'S'
42004         , p_component_type          => l_component_type
42005         , p_component_code          => l_component_code
42006         , p_component_type_code     => l_component_type_code
42007         , p_component_appl_id       => l_component_appl_id
42008         , p_amb_context_code        => l_amb_context_code
42009         , p_entity_code             => 'RECEIPTS'
42010         , p_event_class_code        => 'MISC_RECEIPT'
42011         , p_side                    => 'NA'
42012         );
42013 
42014   END IF;
42015 
42016    --
42017    --
42018    END IF;
42019 
42020        --
42021        -- Update the line information that should be overwritten
42022        --
42023        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
42024                                          p_header_num   => 1);
42025        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
42026 
42027        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
42028 
42029        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
42030           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
42031        END IF;
42032 
42033       --
42034       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
42035       --
42036       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
42037           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
42038       ELSE
42039           ---------------------------------------------------------------------------------------------------
42040           -- 4262811a Switch Sign
42041           ---------------------------------------------------------------------------------------------------
42042           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
42043           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
42044                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
42045           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
42046                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
42047           -- 5132302
42048           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
42049                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
42050 
42051       END IF;
42052 
42053       -- 4955764
42054       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
42055       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
42056 
42057 
42058       XLA_AE_LINES_PKG.ValidateCurrentLine;
42059       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
42060 
42061       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
42065    END IF;
42062                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
42063                ,p_balance_type_code => l_balance_type_code);
42064 
42066 
42067    -----------------------------------------------------------------------------------------
42068    -- 4262811 Multiperiod Accounting
42069    -----------------------------------------------------------------------------------------
42070      -- No MPA option is assigned.
42071 
42072 
42073 END IF;
42074 END IF;
42075 --
42076 
42077 --
42078 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
42079    trace
42080       (p_msg      => 'END of AcctLineType_91'
42081       ,p_level    => C_LEVEL_PROCEDURE
42082       ,p_module   => l_log_module);
42083 END IF;
42084 --
42085 EXCEPTION
42086   WHEN xla_exceptions_pkg.application_exception THEN
42087       RAISE;
42088   WHEN OTHERS THEN
42089        xla_exceptions_pkg.raise_message
42090            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_91');
42091 END AcctLineType_91;
42092 --
42093 
42094 ---------------------------------------
42095 --
42096 -- PRIVATE FUNCTION
42097 --         AcctLineType_92
42098 --
42099 ---------------------------------------
42100 PROCEDURE AcctLineType_92 (
42101   p_application_id        IN NUMBER
42102  ,p_event_id              IN NUMBER
42103  ,p_calculate_acctd_flag  IN VARCHAR2
42104  ,p_calculate_g_l_flag    IN VARCHAR2
42105  ,p_actual_flag           IN OUT VARCHAR2
42106  ,p_balance_type_code     OUT VARCHAR2
42107  ,p_gain_or_loss_ref      OUT VARCHAR2
42108  
42109 --Distribution GL Account
42110  , p_source_3            IN NUMBER
42111 --Remittance Bank Account Cash Account
42112  , p_source_13            IN NUMBER
42113 --Distribution Source Type
42114  , p_source_20            IN VARCHAR2
42115 --Distribution Line Identifier
42116  , p_source_22            IN NUMBER
42117 --Distribution Type
42118  , p_source_23            IN VARCHAR2
42119 --Entered Amount
42120  , p_source_24            IN NUMBER
42121 --Currency Code
42122  , p_source_25            IN VARCHAR2
42123 --Exchange Rate
42124  , p_source_27            IN NUMBER
42125 --Exchange Rate Type
42126  , p_source_28            IN VARCHAR2
42127 --Applied To Document Accounting Amount
42128  , p_source_29            IN NUMBER
42129 --Applied To Document Exchange Date
42130  , p_source_57            IN DATE
42131 --Distribution Multi Fund Additional Entry
42132  , p_source_69            IN VARCHAR2
42133 --Receipt Class Require Remittance Flag
42134  , p_source_70            IN VARCHAR2
42135 )
42136 IS
42137 
42138 l_component_type              VARCHAR2(80);
42139 l_component_code              VARCHAR2(30);
42140 l_component_type_code         VARCHAR2(1);
42141 l_component_appl_id           INTEGER;
42142 l_amb_context_code            VARCHAR2(30);
42143 l_entity_code                 VARCHAR2(30);
42144 l_event_class_code            VARCHAR2(30);
42145 l_ae_header_id                NUMBER;
42146 l_event_type_code             VARCHAR2(30);
42147 l_line_definition_code        VARCHAR2(30);
42148 l_line_definition_owner_code  VARCHAR2(1);
42149 --
42150 -- adr variables
42151 l_segment                     VARCHAR2(30);
42152 l_ccid                        NUMBER;
42153 l_adr_transaction_coa_id      NUMBER;
42154 l_adr_accounting_coa_id       NUMBER;
42155 l_adr_flexfield_segment_code  VARCHAR2(30);
42156 l_adr_flex_value_set_id       NUMBER;
42157 l_adr_value_type_code         VARCHAR2(30);
42158 l_adr_value_combination_id    NUMBER;
42159 l_adr_value_segment_code      VARCHAR2(30);
42160 
42161 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
42162 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
42163 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
42164 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
42165 
42166 -- 4262811 Variables ------------------------------------------------------------------------------------------
42167 l_entered_amt_idx             NUMBER;
42168 l_accted_amt_idx              NUMBER;
42169 l_acc_rev_flag                VARCHAR2(1);
42170 l_accrual_line_num            NUMBER;
42171 l_tmp_amt                     NUMBER;
42172 l_acc_rev_natural_side_code   VARCHAR2(1);
42173 
42174 l_num_entries                 NUMBER;
42175 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
42176 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
42177 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
42178 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
42179 l_recog_line_1                NUMBER;
42180 l_recog_line_2                NUMBER;
42181 
42182 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
42183 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
42184 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
42185 
42186 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
42187 
42188 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
42189 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
42190 
42191 ---------------------------------------------------------------------------------------------------------------
42192 
42193 
42194 --
42195 -- bulk performance
42196 --
42200 
42197 l_balance_type_code           VARCHAR2(1);
42198 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
42199 l_log_module                  VARCHAR2(240);
42201 --
42202 -- Upgrade strategy
42203 --
42204 l_actual_upg_option           VARCHAR2(1);
42205 l_enc_upg_option           VARCHAR2(1);
42206 
42207 --
42208 BEGIN
42209 --
42210 IF g_log_enabled THEN
42211       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_92';
42212 END IF;
42213 --
42214 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
42215 
42216       trace
42217          (p_msg      => 'BEGIN of AcctLineType_92'
42218          ,p_level    => C_LEVEL_PROCEDURE
42219          ,p_module   => l_log_module);
42220 
42221 END IF;
42222 --
42223 l_component_type             := 'AMB_JLT';
42224 l_component_code             := 'MFAR_MISC_RCT_CM_CASH';
42225 l_component_type_code        := 'S';
42226 l_component_appl_id          :=  222;
42227 l_amb_context_code           := 'DEFAULT';
42228 l_entity_code                := 'RECEIPTS';
42229 l_event_class_code           := 'MISC_RECEIPT';
42230 l_event_type_code            := 'MISC_RECEIPT_ALL';
42231 l_line_definition_owner_code := 'S';
42232 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
42233 --
42234 l_balance_type_code          := 'A';
42235 l_segment                     := NULL;
42236 l_ccid                        := NULL;
42237 l_adr_transaction_coa_id      := NULL;
42238 l_adr_accounting_coa_id       := NULL;
42239 l_adr_flexfield_segment_code  := NULL;
42240 l_adr_flex_value_set_id       := NULL;
42241 l_adr_value_type_code         := NULL;
42242 l_adr_value_combination_id    := NULL;
42243 l_adr_value_segment_code      := NULL;
42244 
42245 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
42246 l_bflow_class_code           := '';    -- 4219869 Business Flow
42247 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
42248 l_budgetary_control_flag     := 'N';
42249 
42250 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
42251 l_bflow_applied_to_amt       := NULL; -- 5132302
42252 l_entered_amt_idx            := NULL;          -- 4262811
42253 l_accted_amt_idx             := NULL;          -- 4262811
42254 l_acc_rev_flag               := NULL;          -- 4262811
42255 l_accrual_line_num           := NULL;          -- 4262811
42256 l_tmp_amt                    := NULL;          -- 4262811
42257 --
42258  
42259 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
42260     l_balance_type_code <> 'B' THEN
42261 IF NVL(p_source_20,'
42262 ') =  'MISCCASH' AND 
42263 NVL(p_source_69,'
42264 ') =  'Y' AND 
42265 NVL(p_source_70,'
42266 ') =  'Y'
42267  THEN 
42268 
42269    --
42270    XLA_AE_LINES_PKG.SetNewLine;
42271 
42272    p_balance_type_code          := l_balance_type_code;
42273    -- set the flag so later we will know whether the gain loss line needs to be created
42274    
42275    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
42276      p_actual_flag :='A';
42277    END IF;
42278 
42279    --
42280    -- bulk performance
42281    --
42282    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
42283                                       p_header_num   => 0); -- 4262811
42284    --
42285    -- set accounting line options
42286    --
42287    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
42288            p_natural_side_code          => 'C'
42289          , p_gain_or_loss_flag          => 'N'
42290          , p_gl_transfer_mode_code      => 'S'
42291          , p_acct_entry_type_code       => 'A'
42292          , p_switch_side_flag           => 'Y'
42293          , p_merge_duplicate_code       => 'A'
42294          );
42295    --
42296    l_acc_rev_natural_side_code := 'D';  -- 4262811
42297    -- 
42298    --
42299    -- set accounting line type info
42300    --
42301    xla_ae_lines_pkg.SetAcctLineType
42302       (p_component_type             => l_component_type
42303       ,p_event_type_code            => l_event_type_code
42304       ,p_line_definition_owner_code => l_line_definition_owner_code
42305       ,p_line_definition_code       => l_line_definition_code
42306       ,p_accounting_line_code       => l_component_code
42307       ,p_accounting_line_type_code  => l_component_type_code
42308       ,p_accounting_line_appl_id    => l_component_appl_id
42309       ,p_amb_context_code           => l_amb_context_code
42310       ,p_entity_code                => l_entity_code
42311       ,p_event_class_code           => l_event_class_code);
42312    --
42313    -- set accounting class
42314    --
42315    xla_ae_lines_pkg.SetAcctClass(
42316            p_accounting_class_code  => 'CASH'
42317          , p_ae_header_id           => l_ae_header_id
42318          );
42319 
42320    --
42321    -- set rounding class
42322    --
42323    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
42324                       'RECEIVABLE';
42325 
42326    --
42327    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
42328    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
42329    --
42330    -- bulk performance
42331    --
42332    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
42336 
42333 
42334    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
42335       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
42337    -- 4955764
42338    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
42339       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
42340 
42341    -- 4458381 Public Sector Enh
42342    
42343    --
42344    -- set accounting attributes for the line type
42345    --
42346    l_entered_amt_idx := 3;
42347    l_accted_amt_idx  := 8;
42348    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
42349    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
42350    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
42351    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
42352    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
42353    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
42354    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
42355    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
42356    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
42357    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
42358    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
42359    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
42360    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
42361    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
42362    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
42363    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
42364    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
42365 
42366    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
42367    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
42368 
42369    ---------------------------------------------------------------------------------------------------------------
42370    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
42371    ---------------------------------------------------------------------------------------------------------------
42372    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
42373 
42374    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
42375    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
42376 
42377    IF xla_accounting_cache_pkg.GetValueChar
42378          (p_source_code         => 'LEDGER_CATEGORY_CODE'
42379          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
42380    AND l_bflow_method_code = 'PRIOR_ENTRY'
42381 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
42382    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
42383          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
42384        )
42385    THEN
42386          xla_ae_lines_pkg.BflowUpgEntry
42387            (p_business_method_code    => l_bflow_method_code
42388            ,p_business_class_code     => l_bflow_class_code
42389            ,p_balance_type            => l_balance_type_code);
42390    ELSE
42391       NULL;
42392 -- No business flow processing for business flow method of NONE.
42393    END IF;
42394 
42395    --
42396    -- call analytical criteria
42397    --
42398    
42399    --
42400    -- call description
42401    --
42402    
42403 xla_ae_lines_pkg.SetLineDescription(
42404    p_ae_header_id => l_ae_header_id
42405   ,p_description  => Description_1 (
42406      p_application_id         => p_application_id
42407    , p_ae_header_id           => l_ae_header_id 
42408    )
42409 );
42410 
42411 
42412    --
42413    -- call ADRs
42414    -- Bug 4922099
42415    --
42416    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
42417         (NVL(l_actual_upg_option, 'N') = 'O') OR
42418         (NVL(l_enc_upg_option, 'N') = 'O')
42419       )
42420    THEN
42421    NULL;
42422    --
42423    --
42424    
42425   l_ccid := AcctDerRule_25(
42426            p_application_id           => p_application_id
42427          , p_ae_header_id             => l_ae_header_id 
42428 , p_source_13 => p_source_13
42429          , x_transaction_coa_id       => l_adr_transaction_coa_id
42430          , x_accounting_coa_id        => l_adr_accounting_coa_id
42431          , x_value_type_code          => l_adr_value_type_code
42432          , p_side                     => 'NA'
42433    );
42434 
42435    xla_ae_lines_pkg.set_ccid(
42436     p_code_combination_id          => l_ccid
42437   , p_value_type_code              => l_adr_value_type_code
42438   , p_transaction_coa_id           => l_adr_transaction_coa_id
42439   , p_accounting_coa_id            => l_adr_accounting_coa_id
42440   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
42441   , p_adr_type_code                => 'S'
42442   , p_component_type               => l_component_type
42443   , p_component_code               => l_component_code
42444   , p_component_type_code          => l_component_type_code
42445   , p_component_appl_id            => l_component_appl_id
42446   , p_amb_context_code             => l_amb_context_code
42447   , p_side                         => 'NA'
42448   );
42449 
42450 
42451    l_segment := AcctDerRule_4(
42455          , x_transaction_coa_id       => l_adr_transaction_coa_id
42452            p_application_id           => p_application_id
42453          , p_ae_header_id             => l_ae_header_id 
42454 , p_source_3 => p_source_3
42456          , x_accounting_coa_id        => l_adr_accounting_coa_id
42457          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
42458          , x_flex_value_set_id        => l_adr_flex_value_set_id
42459          , x_value_type_code          => l_adr_value_type_code
42460          , x_value_combination_id     => l_adr_value_combination_id
42461          , x_value_segment_code       => l_adr_value_segment_code
42462          , p_side                     => 'NA'
42463          , p_override_seg_flag        => 'Y'
42464    );
42465 
42466    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
42467 
42468       xla_ae_lines_pkg.set_segment(
42469           p_to_segment_code         => 'GL_BALANCING'
42470         , p_segment_value           => l_segment
42471         , p_from_segment_code       => l_adr_value_segment_code
42472         , p_from_combination_id     => l_adr_value_combination_id
42473         , p_value_type_code         => l_adr_value_type_code
42474         , p_transaction_coa_id      => l_adr_transaction_coa_id
42475         , p_accounting_coa_id       => l_adr_accounting_coa_id
42476         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
42477         , p_flex_value_set_id       => l_adr_flex_value_set_id
42478         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
42479         , p_adr_type_code           => 'S'
42480         , p_component_type          => l_component_type
42481         , p_component_code          => l_component_code
42482         , p_component_type_code     => l_component_type_code
42483         , p_component_appl_id       => l_component_appl_id
42484         , p_amb_context_code        => l_amb_context_code
42485         , p_entity_code             => 'RECEIPTS'
42486         , p_event_class_code        => 'MISC_RECEIPT'
42487         , p_side                    => 'NA'
42488         );
42489 
42490   END IF;
42491 
42492    --
42493    --
42494    END IF;
42495    --
42496    -- Bug 4922099
42497    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
42498           (NVL(l_enc_upg_option, 'N') = 'O')
42499         ) AND
42500         (l_bflow_method_code = 'PRIOR_ENTRY')
42501       )
42502    THEN
42503       IF
42504       --
42505       1 = 2
42506       --
42507       THEN
42508       xla_accounting_err_pkg.build_message
42509                                     (p_appli_s_name            => 'XLA'
42510                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
42511                                     ,p_token_1                 => 'LINE_NUMBER'
42512                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
42513                                     ,p_token_2                 => 'LINE_TYPE_NAME'
42514                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
42515                                                                              l_component_type
42516                                                                             ,l_component_code
42517                                                                             ,l_component_type_code
42518                                                                             ,l_component_appl_id
42519                                                                             ,l_amb_context_code
42520                                                                             ,l_entity_code
42521                                                                             ,l_event_class_code
42522                                                                            )
42523                                     ,p_token_3                 => 'OWNER'
42524                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
42525                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
42526                                                                           ,p_lookup_code    => l_component_type_code
42527                                                                          )
42528                                     ,p_token_4                 => 'PRODUCT_NAME'
42529                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
42530                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
42531                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
42532                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
42533                                     ,p_ae_header_id            =>  NULL
42534                                        );
42535 
42536         IF (C_LEVEL_ERROR>= g_log_level) THEN
42537                  trace
42538                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
42539                       ,p_level    => C_LEVEL_ERROR
42540                       ,p_module   => l_log_module);
42541         END IF;
42542       END IF;
42543    END IF;
42544    --
42545    --
42546    ------------------------------------------------------------------------------------------------
42547    -- 4219869 Business Flow
42551    XLA_AE_LINES_PKG.ValidateCurrentLine;
42548    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
42549    -- Prior Entry.  Currently, the following code is always generated.
42550    ------------------------------------------------------------------------------------------------
42552 
42553    ------------------------------------------------------------------------------------
42554    -- 4219869 Business Flow
42555    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
42556    ------------------------------------------------------------------------------------
42557    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
42558 
42559    ----------------------------------------------------------------------------------
42560    -- 4219869 Business Flow
42561    -- Update journal entry status -- Need to generate this within IF <condition>
42562    ----------------------------------------------------------------------------------
42563    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
42564          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
42565          ,p_balance_type_code => l_balance_type_code
42566          );
42567 
42568    -------------------------------------------------------------------------------------------
42569    -- 4262811 - Generate the Accrual Reversal lines
42570    -------------------------------------------------------------------------------------------
42571    BEGIN
42572       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
42573                               (g_array_event(p_event_id).array_value_num('header_index'));
42574       IF l_acc_rev_flag IS NULL THEN
42575          l_acc_rev_flag := 'N';
42576       END IF;
42577    EXCEPTION
42578       WHEN OTHERS THEN
42579          l_acc_rev_flag := 'N';
42580    END;
42581    --
42582    IF (l_acc_rev_flag = 'Y') THEN
42583 
42584        -- 4645092  ------------------------------------------------------------------------------
42585        -- To allow MPA report to determine if it should generate report process
42586        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
42587        ------------------------------------------------------------------------------------------
42588 
42589        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
42590        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
42591    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
42592    -- call ADRs
42593    -- Bug 4922099
42594    --
42595    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
42596         (NVL(l_actual_upg_option, 'N') = 'O') OR
42597         (NVL(l_enc_upg_option, 'N') = 'O')
42598       )
42599    THEN
42600    NULL;
42601    --
42602    --
42603    
42604   l_ccid := AcctDerRule_25(
42605            p_application_id           => p_application_id
42606          , p_ae_header_id             => l_ae_header_id 
42607 , p_source_13 => p_source_13
42608          , x_transaction_coa_id       => l_adr_transaction_coa_id
42609          , x_accounting_coa_id        => l_adr_accounting_coa_id
42610          , x_value_type_code          => l_adr_value_type_code
42611          , p_side                     => 'NA'
42612    );
42613 
42614    xla_ae_lines_pkg.set_ccid(
42615     p_code_combination_id          => l_ccid
42616   , p_value_type_code              => l_adr_value_type_code
42617   , p_transaction_coa_id           => l_adr_transaction_coa_id
42618   , p_accounting_coa_id            => l_adr_accounting_coa_id
42619   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
42620   , p_adr_type_code                => 'S'
42621   , p_component_type               => l_component_type
42622   , p_component_code               => l_component_code
42623   , p_component_type_code          => l_component_type_code
42624   , p_component_appl_id            => l_component_appl_id
42625   , p_amb_context_code             => l_amb_context_code
42626   , p_side                         => 'NA'
42627   );
42628 
42629 
42630    l_segment := AcctDerRule_4(
42631            p_application_id           => p_application_id
42632          , p_ae_header_id             => l_ae_header_id 
42633 , p_source_3 => p_source_3
42634          , x_transaction_coa_id       => l_adr_transaction_coa_id
42635          , x_accounting_coa_id        => l_adr_accounting_coa_id
42636          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
42637          , x_flex_value_set_id        => l_adr_flex_value_set_id
42638          , x_value_type_code          => l_adr_value_type_code
42639          , x_value_combination_id     => l_adr_value_combination_id
42640          , x_value_segment_code       => l_adr_value_segment_code
42641          , p_side                     => 'NA'
42642          , p_override_seg_flag        => 'Y'
42643    );
42644 
42645    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
42646 
42647       xla_ae_lines_pkg.set_segment(
42648           p_to_segment_code         => 'GL_BALANCING'
42649         , p_segment_value           => l_segment
42650         , p_from_segment_code       => l_adr_value_segment_code
42651         , p_from_combination_id     => l_adr_value_combination_id
42652         , p_value_type_code         => l_adr_value_type_code
42653         , p_transaction_coa_id      => l_adr_transaction_coa_id
42654         , p_accounting_coa_id       => l_adr_accounting_coa_id
42655         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
42659         , p_component_type          => l_component_type
42656         , p_flex_value_set_id       => l_adr_flex_value_set_id
42657         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
42658         , p_adr_type_code           => 'S'
42660         , p_component_code          => l_component_code
42661         , p_component_type_code     => l_component_type_code
42662         , p_component_appl_id       => l_component_appl_id
42663         , p_amb_context_code        => l_amb_context_code
42664         , p_entity_code             => 'RECEIPTS'
42665         , p_event_class_code        => 'MISC_RECEIPT'
42666         , p_side                    => 'NA'
42667         );
42668 
42669   END IF;
42670 
42671    --
42672    --
42673    END IF;
42674 
42675        --
42676        -- Update the line information that should be overwritten
42677        --
42678        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
42679                                          p_header_num   => 1);
42680        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
42681 
42682        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
42683 
42684        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
42685           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
42686        END IF;
42687 
42688       --
42689       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
42690       --
42691       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
42692           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
42693       ELSE
42694           ---------------------------------------------------------------------------------------------------
42695           -- 4262811a Switch Sign
42696           ---------------------------------------------------------------------------------------------------
42697           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
42698           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
42699                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
42700           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
42701                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
42702           -- 5132302
42703           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
42704                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
42705 
42706       END IF;
42707 
42708       -- 4955764
42709       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
42710       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
42711 
42712 
42713       XLA_AE_LINES_PKG.ValidateCurrentLine;
42714       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
42715 
42716       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
42717                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
42718                ,p_balance_type_code => l_balance_type_code);
42719 
42720    END IF;
42721 
42722    -----------------------------------------------------------------------------------------
42723    -- 4262811 Multiperiod Accounting
42724    -----------------------------------------------------------------------------------------
42725      -- No MPA option is assigned.
42726 
42727 
42728 END IF;
42729 END IF;
42730 --
42731 
42732 --
42733 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
42734    trace
42735       (p_msg      => 'END of AcctLineType_92'
42736       ,p_level    => C_LEVEL_PROCEDURE
42737       ,p_module   => l_log_module);
42738 END IF;
42739 --
42740 EXCEPTION
42741   WHEN xla_exceptions_pkg.application_exception THEN
42742       RAISE;
42743   WHEN OTHERS THEN
42744        xla_exceptions_pkg.raise_message
42745            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_92');
42746 END AcctLineType_92;
42747 --
42748 
42749 ---------------------------------------
42750 --
42751 -- PRIVATE FUNCTION
42752 --         AcctLineType_93
42753 --
42754 ---------------------------------------
42755 PROCEDURE AcctLineType_93 (
42756   p_application_id        IN NUMBER
42757  ,p_event_id              IN NUMBER
42758  ,p_calculate_acctd_flag  IN VARCHAR2
42759  ,p_calculate_g_l_flag    IN VARCHAR2
42760  ,p_actual_flag           IN OUT VARCHAR2
42761  ,p_balance_type_code     OUT VARCHAR2
42762  ,p_gain_or_loss_ref      OUT VARCHAR2
42763  
42764 --Distribution GL Account
42765  , p_source_3            IN NUMBER
42766 --Remittance Bank Account Confirmation Account
42767  , p_source_14            IN NUMBER
42768 --Distribution Source Type
42769  , p_source_20            IN VARCHAR2
42770 --Distribution Line Identifier
42771  , p_source_22            IN NUMBER
42772 --Distribution Type
42773  , p_source_23            IN VARCHAR2
42774 --Entered Amount
42775  , p_source_24            IN NUMBER
42776 --Currency Code
42777  , p_source_25            IN VARCHAR2
42778 --Exchange Rate
42779  , p_source_27            IN NUMBER
42780 --Exchange Rate Type
42781  , p_source_28            IN VARCHAR2
42785  , p_source_57            IN DATE
42782 --Applied To Document Accounting Amount
42783  , p_source_29            IN NUMBER
42784 --Applied To Document Exchange Date
42786 --Distribution Multi Fund Additional Entry
42787  , p_source_69            IN VARCHAR2
42788 )
42789 IS
42790 
42791 l_component_type              VARCHAR2(80);
42792 l_component_code              VARCHAR2(30);
42793 l_component_type_code         VARCHAR2(1);
42794 l_component_appl_id           INTEGER;
42795 l_amb_context_code            VARCHAR2(30);
42796 l_entity_code                 VARCHAR2(30);
42797 l_event_class_code            VARCHAR2(30);
42798 l_ae_header_id                NUMBER;
42799 l_event_type_code             VARCHAR2(30);
42800 l_line_definition_code        VARCHAR2(30);
42801 l_line_definition_owner_code  VARCHAR2(1);
42802 --
42803 -- adr variables
42804 l_segment                     VARCHAR2(30);
42805 l_ccid                        NUMBER;
42806 l_adr_transaction_coa_id      NUMBER;
42807 l_adr_accounting_coa_id       NUMBER;
42808 l_adr_flexfield_segment_code  VARCHAR2(30);
42809 l_adr_flex_value_set_id       NUMBER;
42810 l_adr_value_type_code         VARCHAR2(30);
42811 l_adr_value_combination_id    NUMBER;
42812 l_adr_value_segment_code      VARCHAR2(30);
42813 
42814 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
42815 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
42816 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
42817 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
42818 
42819 -- 4262811 Variables ------------------------------------------------------------------------------------------
42820 l_entered_amt_idx             NUMBER;
42821 l_accted_amt_idx              NUMBER;
42822 l_acc_rev_flag                VARCHAR2(1);
42823 l_accrual_line_num            NUMBER;
42824 l_tmp_amt                     NUMBER;
42825 l_acc_rev_natural_side_code   VARCHAR2(1);
42826 
42827 l_num_entries                 NUMBER;
42828 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
42829 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
42830 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
42831 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
42832 l_recog_line_1                NUMBER;
42833 l_recog_line_2                NUMBER;
42834 
42835 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
42836 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
42837 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
42838 
42839 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
42840 
42841 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
42842 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
42843 
42844 ---------------------------------------------------------------------------------------------------------------
42845 
42846 
42847 --
42848 -- bulk performance
42849 --
42850 l_balance_type_code           VARCHAR2(1);
42851 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
42852 l_log_module                  VARCHAR2(240);
42853 
42854 --
42855 -- Upgrade strategy
42856 --
42857 l_actual_upg_option           VARCHAR2(1);
42858 l_enc_upg_option           VARCHAR2(1);
42859 
42860 --
42861 BEGIN
42862 --
42863 IF g_log_enabled THEN
42864       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_93';
42865 END IF;
42866 --
42867 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
42868 
42869       trace
42870          (p_msg      => 'BEGIN of AcctLineType_93'
42871          ,p_level    => C_LEVEL_PROCEDURE
42872          ,p_module   => l_log_module);
42873 
42874 END IF;
42875 --
42876 l_component_type             := 'AMB_JLT';
42877 l_component_code             := 'MFAR_MISC_RCT_CONFIRMATION';
42878 l_component_type_code        := 'S';
42879 l_component_appl_id          :=  222;
42880 l_amb_context_code           := 'DEFAULT';
42881 l_entity_code                := 'RECEIPTS';
42882 l_event_class_code           := 'MISC_RECEIPT';
42883 l_event_type_code            := 'MISC_RECEIPT_ALL';
42884 l_line_definition_owner_code := 'S';
42885 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
42886 --
42887 l_balance_type_code          := 'A';
42888 l_segment                     := NULL;
42889 l_ccid                        := NULL;
42890 l_adr_transaction_coa_id      := NULL;
42891 l_adr_accounting_coa_id       := NULL;
42892 l_adr_flexfield_segment_code  := NULL;
42893 l_adr_flex_value_set_id       := NULL;
42894 l_adr_value_type_code         := NULL;
42895 l_adr_value_combination_id    := NULL;
42896 l_adr_value_segment_code      := NULL;
42897 
42898 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
42899 l_bflow_class_code           := '';    -- 4219869 Business Flow
42900 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
42901 l_budgetary_control_flag     := 'N';
42902 
42903 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
42904 l_bflow_applied_to_amt       := NULL; -- 5132302
42905 l_entered_amt_idx            := NULL;          -- 4262811
42906 l_accted_amt_idx             := NULL;          -- 4262811
42907 l_acc_rev_flag               := NULL;          -- 4262811
42911  
42908 l_accrual_line_num           := NULL;          -- 4262811
42909 l_tmp_amt                    := NULL;          -- 4262811
42910 --
42912 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
42913     l_balance_type_code <> 'B' THEN
42914 IF NVL(p_source_20,'
42915 ') =  'CONFIRMATION' AND 
42916 NVL(p_source_69,'
42917 ') =  'Y'
42918  THEN 
42919 
42920    --
42921    XLA_AE_LINES_PKG.SetNewLine;
42922 
42923    p_balance_type_code          := l_balance_type_code;
42924    -- set the flag so later we will know whether the gain loss line needs to be created
42925    
42926    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
42927      p_actual_flag :='A';
42928    END IF;
42929 
42930    --
42931    -- bulk performance
42932    --
42933    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
42934                                       p_header_num   => 0); -- 4262811
42935    --
42936    -- set accounting line options
42937    --
42938    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
42939            p_natural_side_code          => 'C'
42940          , p_gain_or_loss_flag          => 'N'
42941          , p_gl_transfer_mode_code      => 'S'
42942          , p_acct_entry_type_code       => 'A'
42943          , p_switch_side_flag           => 'Y'
42944          , p_merge_duplicate_code       => 'A'
42945          );
42946    --
42947    l_acc_rev_natural_side_code := 'D';  -- 4262811
42948    -- 
42949    --
42950    -- set accounting line type info
42951    --
42952    xla_ae_lines_pkg.SetAcctLineType
42953       (p_component_type             => l_component_type
42954       ,p_event_type_code            => l_event_type_code
42955       ,p_line_definition_owner_code => l_line_definition_owner_code
42956       ,p_line_definition_code       => l_line_definition_code
42957       ,p_accounting_line_code       => l_component_code
42958       ,p_accounting_line_type_code  => l_component_type_code
42959       ,p_accounting_line_appl_id    => l_component_appl_id
42960       ,p_amb_context_code           => l_amb_context_code
42961       ,p_entity_code                => l_entity_code
42962       ,p_event_class_code           => l_event_class_code);
42963    --
42964    -- set accounting class
42965    --
42966    xla_ae_lines_pkg.SetAcctClass(
42967            p_accounting_class_code  => 'CONFIRMATION'
42968          , p_ae_header_id           => l_ae_header_id
42969          );
42970 
42971    --
42972    -- set rounding class
42973    --
42974    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
42975                       'RECEIVABLE';
42976 
42977    --
42978    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
42979    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
42980    --
42981    -- bulk performance
42982    --
42983    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
42984 
42985    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
42986       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
42987 
42988    -- 4955764
42989    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
42990       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
42991 
42992    -- 4458381 Public Sector Enh
42993    
42994    --
42995    -- set accounting attributes for the line type
42996    --
42997    l_entered_amt_idx := 3;
42998    l_accted_amt_idx  := 8;
42999    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
43000    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
43001    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
43002    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
43003    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
43004    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
43005    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
43006    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
43007    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
43008    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
43009    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
43010    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
43011    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
43012    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
43013    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
43014    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
43015    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
43016 
43017    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
43018    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
43019 
43020    ---------------------------------------------------------------------------------------------------------------
43021    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
43022    ---------------------------------------------------------------------------------------------------------------
43026    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
43023    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
43024 
43025    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
43027 
43028    IF xla_accounting_cache_pkg.GetValueChar
43029          (p_source_code         => 'LEDGER_CATEGORY_CODE'
43030          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
43031    AND l_bflow_method_code = 'PRIOR_ENTRY'
43032 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
43033    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
43034          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
43035        )
43036    THEN
43037          xla_ae_lines_pkg.BflowUpgEntry
43038            (p_business_method_code    => l_bflow_method_code
43039            ,p_business_class_code     => l_bflow_class_code
43040            ,p_balance_type            => l_balance_type_code);
43041    ELSE
43042       NULL;
43043 -- No business flow processing for business flow method of NONE.
43044    END IF;
43045 
43046    --
43047    -- call analytical criteria
43048    --
43049    
43050    --
43051    -- call description
43052    --
43053    
43054 xla_ae_lines_pkg.SetLineDescription(
43055    p_ae_header_id => l_ae_header_id
43056   ,p_description  => Description_1 (
43057      p_application_id         => p_application_id
43058    , p_ae_header_id           => l_ae_header_id 
43059    )
43060 );
43061 
43062 
43063    --
43064    -- call ADRs
43065    -- Bug 4922099
43066    --
43067    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
43068         (NVL(l_actual_upg_option, 'N') = 'O') OR
43069         (NVL(l_enc_upg_option, 'N') = 'O')
43070       )
43071    THEN
43072    NULL;
43073    --
43074    --
43075    
43076   l_ccid := AcctDerRule_26(
43077            p_application_id           => p_application_id
43078          , p_ae_header_id             => l_ae_header_id 
43079 , p_source_14 => p_source_14
43080          , x_transaction_coa_id       => l_adr_transaction_coa_id
43081          , x_accounting_coa_id        => l_adr_accounting_coa_id
43082          , x_value_type_code          => l_adr_value_type_code
43083          , p_side                     => 'NA'
43084    );
43085 
43086    xla_ae_lines_pkg.set_ccid(
43087     p_code_combination_id          => l_ccid
43088   , p_value_type_code              => l_adr_value_type_code
43089   , p_transaction_coa_id           => l_adr_transaction_coa_id
43090   , p_accounting_coa_id            => l_adr_accounting_coa_id
43091   , p_adr_code                     => 'MFAR_RCT_DEF_CONFIRMATION_CCID'
43092   , p_adr_type_code                => 'S'
43093   , p_component_type               => l_component_type
43094   , p_component_code               => l_component_code
43095   , p_component_type_code          => l_component_type_code
43096   , p_component_appl_id            => l_component_appl_id
43097   , p_amb_context_code             => l_amb_context_code
43098   , p_side                         => 'NA'
43099   );
43100 
43101 
43102    l_segment := AcctDerRule_4(
43103            p_application_id           => p_application_id
43104          , p_ae_header_id             => l_ae_header_id 
43105 , p_source_3 => p_source_3
43106          , x_transaction_coa_id       => l_adr_transaction_coa_id
43107          , x_accounting_coa_id        => l_adr_accounting_coa_id
43108          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
43109          , x_flex_value_set_id        => l_adr_flex_value_set_id
43110          , x_value_type_code          => l_adr_value_type_code
43111          , x_value_combination_id     => l_adr_value_combination_id
43112          , x_value_segment_code       => l_adr_value_segment_code
43113          , p_side                     => 'NA'
43114          , p_override_seg_flag        => 'Y'
43115    );
43116 
43117    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
43118 
43119       xla_ae_lines_pkg.set_segment(
43120           p_to_segment_code         => 'GL_BALANCING'
43121         , p_segment_value           => l_segment
43122         , p_from_segment_code       => l_adr_value_segment_code
43123         , p_from_combination_id     => l_adr_value_combination_id
43124         , p_value_type_code         => l_adr_value_type_code
43125         , p_transaction_coa_id      => l_adr_transaction_coa_id
43126         , p_accounting_coa_id       => l_adr_accounting_coa_id
43127         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
43128         , p_flex_value_set_id       => l_adr_flex_value_set_id
43129         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
43130         , p_adr_type_code           => 'S'
43131         , p_component_type          => l_component_type
43132         , p_component_code          => l_component_code
43133         , p_component_type_code     => l_component_type_code
43134         , p_component_appl_id       => l_component_appl_id
43135         , p_amb_context_code        => l_amb_context_code
43136         , p_entity_code             => 'RECEIPTS'
43137         , p_event_class_code        => 'MISC_RECEIPT'
43138         , p_side                    => 'NA'
43139         );
43140 
43141   END IF;
43142 
43143    --
43144    --
43145    END IF;
43149           (NVL(l_enc_upg_option, 'N') = 'O')
43146    --
43147    -- Bug 4922099
43148    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
43150         ) AND
43151         (l_bflow_method_code = 'PRIOR_ENTRY')
43152       )
43153    THEN
43154       IF
43155       --
43156       1 = 2
43157       --
43158       THEN
43159       xla_accounting_err_pkg.build_message
43160                                     (p_appli_s_name            => 'XLA'
43161                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
43162                                     ,p_token_1                 => 'LINE_NUMBER'
43163                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
43164                                     ,p_token_2                 => 'LINE_TYPE_NAME'
43165                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
43166                                                                              l_component_type
43167                                                                             ,l_component_code
43168                                                                             ,l_component_type_code
43169                                                                             ,l_component_appl_id
43170                                                                             ,l_amb_context_code
43171                                                                             ,l_entity_code
43172                                                                             ,l_event_class_code
43173                                                                            )
43174                                     ,p_token_3                 => 'OWNER'
43175                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
43176                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
43177                                                                           ,p_lookup_code    => l_component_type_code
43178                                                                          )
43179                                     ,p_token_4                 => 'PRODUCT_NAME'
43180                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
43181                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
43182                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
43183                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
43184                                     ,p_ae_header_id            =>  NULL
43185                                        );
43186 
43187         IF (C_LEVEL_ERROR>= g_log_level) THEN
43188                  trace
43189                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
43190                       ,p_level    => C_LEVEL_ERROR
43191                       ,p_module   => l_log_module);
43192         END IF;
43193       END IF;
43194    END IF;
43195    --
43196    --
43197    ------------------------------------------------------------------------------------------------
43198    -- 4219869 Business Flow
43199    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
43200    -- Prior Entry.  Currently, the following code is always generated.
43201    ------------------------------------------------------------------------------------------------
43202    XLA_AE_LINES_PKG.ValidateCurrentLine;
43203 
43204    ------------------------------------------------------------------------------------
43205    -- 4219869 Business Flow
43206    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
43207    ------------------------------------------------------------------------------------
43208    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
43209 
43210    ----------------------------------------------------------------------------------
43211    -- 4219869 Business Flow
43212    -- Update journal entry status -- Need to generate this within IF <condition>
43213    ----------------------------------------------------------------------------------
43214    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
43215          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
43216          ,p_balance_type_code => l_balance_type_code
43217          );
43218 
43219    -------------------------------------------------------------------------------------------
43220    -- 4262811 - Generate the Accrual Reversal lines
43221    -------------------------------------------------------------------------------------------
43222    BEGIN
43223       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
43224                               (g_array_event(p_event_id).array_value_num('header_index'));
43225       IF l_acc_rev_flag IS NULL THEN
43226          l_acc_rev_flag := 'N';
43227       END IF;
43228    EXCEPTION
43229       WHEN OTHERS THEN
43230          l_acc_rev_flag := 'N';
43231    END;
43232    --
43233    IF (l_acc_rev_flag = 'Y') THEN
43234 
43235        -- 4645092  ------------------------------------------------------------------------------
43236        -- To allow MPA report to determine if it should generate report process
43237        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
43238        ------------------------------------------------------------------------------------------
43239 
43240        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
43244    -- Bug 4922099
43241        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
43242    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
43243    -- call ADRs
43245    --
43246    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
43247         (NVL(l_actual_upg_option, 'N') = 'O') OR
43248         (NVL(l_enc_upg_option, 'N') = 'O')
43249       )
43250    THEN
43251    NULL;
43252    --
43253    --
43254    
43255   l_ccid := AcctDerRule_26(
43256            p_application_id           => p_application_id
43257          , p_ae_header_id             => l_ae_header_id 
43258 , p_source_14 => p_source_14
43259          , x_transaction_coa_id       => l_adr_transaction_coa_id
43260          , x_accounting_coa_id        => l_adr_accounting_coa_id
43261          , x_value_type_code          => l_adr_value_type_code
43262          , p_side                     => 'NA'
43263    );
43264 
43265    xla_ae_lines_pkg.set_ccid(
43266     p_code_combination_id          => l_ccid
43267   , p_value_type_code              => l_adr_value_type_code
43268   , p_transaction_coa_id           => l_adr_transaction_coa_id
43269   , p_accounting_coa_id            => l_adr_accounting_coa_id
43270   , p_adr_code                     => 'MFAR_RCT_DEF_CONFIRMATION_CCID'
43271   , p_adr_type_code                => 'S'
43272   , p_component_type               => l_component_type
43273   , p_component_code               => l_component_code
43274   , p_component_type_code          => l_component_type_code
43275   , p_component_appl_id            => l_component_appl_id
43276   , p_amb_context_code             => l_amb_context_code
43277   , p_side                         => 'NA'
43278   );
43279 
43280 
43281    l_segment := AcctDerRule_4(
43282            p_application_id           => p_application_id
43283          , p_ae_header_id             => l_ae_header_id 
43284 , p_source_3 => p_source_3
43285          , x_transaction_coa_id       => l_adr_transaction_coa_id
43286          , x_accounting_coa_id        => l_adr_accounting_coa_id
43287          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
43288          , x_flex_value_set_id        => l_adr_flex_value_set_id
43289          , x_value_type_code          => l_adr_value_type_code
43290          , x_value_combination_id     => l_adr_value_combination_id
43291          , x_value_segment_code       => l_adr_value_segment_code
43292          , p_side                     => 'NA'
43293          , p_override_seg_flag        => 'Y'
43294    );
43295 
43296    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
43297 
43298       xla_ae_lines_pkg.set_segment(
43299           p_to_segment_code         => 'GL_BALANCING'
43300         , p_segment_value           => l_segment
43301         , p_from_segment_code       => l_adr_value_segment_code
43302         , p_from_combination_id     => l_adr_value_combination_id
43303         , p_value_type_code         => l_adr_value_type_code
43304         , p_transaction_coa_id      => l_adr_transaction_coa_id
43305         , p_accounting_coa_id       => l_adr_accounting_coa_id
43306         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
43307         , p_flex_value_set_id       => l_adr_flex_value_set_id
43308         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
43309         , p_adr_type_code           => 'S'
43310         , p_component_type          => l_component_type
43311         , p_component_code          => l_component_code
43312         , p_component_type_code     => l_component_type_code
43313         , p_component_appl_id       => l_component_appl_id
43314         , p_amb_context_code        => l_amb_context_code
43315         , p_entity_code             => 'RECEIPTS'
43316         , p_event_class_code        => 'MISC_RECEIPT'
43317         , p_side                    => 'NA'
43318         );
43319 
43320   END IF;
43321 
43322    --
43323    --
43324    END IF;
43325 
43326        --
43327        -- Update the line information that should be overwritten
43328        --
43329        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
43330                                          p_header_num   => 1);
43331        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
43332 
43333        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
43334 
43335        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
43336           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
43337        END IF;
43338 
43339       --
43340       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
43341       --
43342       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
43343           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
43344       ELSE
43345           ---------------------------------------------------------------------------------------------------
43346           -- 4262811a Switch Sign
43347           ---------------------------------------------------------------------------------------------------
43348           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
43349           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
43350                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
43354           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
43351           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
43352                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
43353           -- 5132302
43355                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
43356 
43357       END IF;
43358 
43359       -- 4955764
43360       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
43361       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
43362 
43363 
43364       XLA_AE_LINES_PKG.ValidateCurrentLine;
43365       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
43366 
43367       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
43368                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
43369                ,p_balance_type_code => l_balance_type_code);
43370 
43371    END IF;
43372 
43373    -----------------------------------------------------------------------------------------
43374    -- 4262811 Multiperiod Accounting
43375    -----------------------------------------------------------------------------------------
43376      -- No MPA option is assigned.
43377 
43378 
43379 END IF;
43380 END IF;
43381 --
43382 
43383 --
43384 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
43385    trace
43386       (p_msg      => 'END of AcctLineType_93'
43387       ,p_level    => C_LEVEL_PROCEDURE
43388       ,p_module   => l_log_module);
43389 END IF;
43390 --
43391 EXCEPTION
43392   WHEN xla_exceptions_pkg.application_exception THEN
43393       RAISE;
43394   WHEN OTHERS THEN
43395        xla_exceptions_pkg.raise_message
43396            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_93');
43397 END AcctLineType_93;
43398 --
43399 
43400 ---------------------------------------
43401 --
43402 -- PRIVATE FUNCTION
43403 --         AcctLineType_94
43404 --
43405 ---------------------------------------
43406 PROCEDURE AcctLineType_94 (
43407   p_application_id        IN NUMBER
43408  ,p_event_id              IN NUMBER
43409  ,p_calculate_acctd_flag  IN VARCHAR2
43410  ,p_calculate_g_l_flag    IN VARCHAR2
43411  ,p_actual_flag           IN OUT VARCHAR2
43412  ,p_balance_type_code     OUT VARCHAR2
43413  ,p_gain_or_loss_ref      OUT VARCHAR2
43414  
43415 --Distribution GL Account
43416  , p_source_3            IN NUMBER
43417 --Remittance Bank Account Remittance Account
43418  , p_source_15            IN NUMBER
43419 --Distribution Source Type
43420  , p_source_20            IN VARCHAR2
43421 --Distribution Line Identifier
43422  , p_source_22            IN NUMBER
43423 --Distribution Type
43424  , p_source_23            IN VARCHAR2
43425 --Entered Amount
43426  , p_source_24            IN NUMBER
43427 --Currency Code
43428  , p_source_25            IN VARCHAR2
43429 --Exchange Rate
43430  , p_source_27            IN NUMBER
43431 --Exchange Rate Type
43432  , p_source_28            IN VARCHAR2
43433 --Applied To Document Accounting Amount
43434  , p_source_29            IN NUMBER
43435 --Applied To Document Exchange Date
43436  , p_source_57            IN DATE
43437 --Distribution Multi Fund Additional Entry
43438  , p_source_69            IN VARCHAR2
43439 )
43440 IS
43441 
43442 l_component_type              VARCHAR2(80);
43443 l_component_code              VARCHAR2(30);
43444 l_component_type_code         VARCHAR2(1);
43445 l_component_appl_id           INTEGER;
43446 l_amb_context_code            VARCHAR2(30);
43447 l_entity_code                 VARCHAR2(30);
43448 l_event_class_code            VARCHAR2(30);
43449 l_ae_header_id                NUMBER;
43450 l_event_type_code             VARCHAR2(30);
43451 l_line_definition_code        VARCHAR2(30);
43452 l_line_definition_owner_code  VARCHAR2(1);
43453 --
43454 -- adr variables
43455 l_segment                     VARCHAR2(30);
43456 l_ccid                        NUMBER;
43457 l_adr_transaction_coa_id      NUMBER;
43458 l_adr_accounting_coa_id       NUMBER;
43459 l_adr_flexfield_segment_code  VARCHAR2(30);
43460 l_adr_flex_value_set_id       NUMBER;
43461 l_adr_value_type_code         VARCHAR2(30);
43462 l_adr_value_combination_id    NUMBER;
43463 l_adr_value_segment_code      VARCHAR2(30);
43464 
43465 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
43466 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
43467 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
43468 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
43469 
43470 -- 4262811 Variables ------------------------------------------------------------------------------------------
43471 l_entered_amt_idx             NUMBER;
43472 l_accted_amt_idx              NUMBER;
43473 l_acc_rev_flag                VARCHAR2(1);
43474 l_accrual_line_num            NUMBER;
43475 l_tmp_amt                     NUMBER;
43476 l_acc_rev_natural_side_code   VARCHAR2(1);
43477 
43478 l_num_entries                 NUMBER;
43479 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
43480 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
43481 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
43485 
43482 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
43483 l_recog_line_1                NUMBER;
43484 l_recog_line_2                NUMBER;
43486 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
43487 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
43488 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
43489 
43490 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
43491 
43492 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
43493 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
43494 
43495 ---------------------------------------------------------------------------------------------------------------
43496 
43497 
43498 --
43499 -- bulk performance
43500 --
43501 l_balance_type_code           VARCHAR2(1);
43502 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
43503 l_log_module                  VARCHAR2(240);
43504 
43505 --
43506 -- Upgrade strategy
43507 --
43508 l_actual_upg_option           VARCHAR2(1);
43509 l_enc_upg_option           VARCHAR2(1);
43510 
43511 --
43512 BEGIN
43513 --
43514 IF g_log_enabled THEN
43515       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_94';
43516 END IF;
43517 --
43518 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
43519 
43520       trace
43521          (p_msg      => 'BEGIN of AcctLineType_94'
43522          ,p_level    => C_LEVEL_PROCEDURE
43523          ,p_module   => l_log_module);
43524 
43525 END IF;
43526 --
43527 l_component_type             := 'AMB_JLT';
43528 l_component_code             := 'MFAR_MISC_RCT_REMITTANCE';
43529 l_component_type_code        := 'S';
43530 l_component_appl_id          :=  222;
43531 l_amb_context_code           := 'DEFAULT';
43532 l_entity_code                := 'RECEIPTS';
43533 l_event_class_code           := 'MISC_RECEIPT';
43534 l_event_type_code            := 'MISC_RECEIPT_ALL';
43535 l_line_definition_owner_code := 'S';
43536 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
43537 --
43538 l_balance_type_code          := 'A';
43539 l_segment                     := NULL;
43540 l_ccid                        := NULL;
43541 l_adr_transaction_coa_id      := NULL;
43542 l_adr_accounting_coa_id       := NULL;
43543 l_adr_flexfield_segment_code  := NULL;
43544 l_adr_flex_value_set_id       := NULL;
43545 l_adr_value_type_code         := NULL;
43546 l_adr_value_combination_id    := NULL;
43547 l_adr_value_segment_code      := NULL;
43548 
43549 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
43550 l_bflow_class_code           := '';    -- 4219869 Business Flow
43551 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
43552 l_budgetary_control_flag     := 'N';
43553 
43554 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
43555 l_bflow_applied_to_amt       := NULL; -- 5132302
43556 l_entered_amt_idx            := NULL;          -- 4262811
43557 l_accted_amt_idx             := NULL;          -- 4262811
43558 l_acc_rev_flag               := NULL;          -- 4262811
43559 l_accrual_line_num           := NULL;          -- 4262811
43560 l_tmp_amt                    := NULL;          -- 4262811
43561 --
43562  
43563 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
43564     l_balance_type_code <> 'B' THEN
43565 IF NVL(p_source_20,'
43566 ') =  'REMITTANCE' AND 
43567 NVL(p_source_69,'
43568 ') =  'Y'
43569  THEN 
43570 
43571    --
43572    XLA_AE_LINES_PKG.SetNewLine;
43573 
43574    p_balance_type_code          := l_balance_type_code;
43575    -- set the flag so later we will know whether the gain loss line needs to be created
43576    
43577    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
43578      p_actual_flag :='A';
43579    END IF;
43580 
43581    --
43582    -- bulk performance
43583    --
43584    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
43585                                       p_header_num   => 0); -- 4262811
43586    --
43587    -- set accounting line options
43588    --
43589    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
43590            p_natural_side_code          => 'C'
43591          , p_gain_or_loss_flag          => 'N'
43592          , p_gl_transfer_mode_code      => 'S'
43593          , p_acct_entry_type_code       => 'A'
43594          , p_switch_side_flag           => 'Y'
43595          , p_merge_duplicate_code       => 'A'
43596          );
43597    --
43598    l_acc_rev_natural_side_code := 'D';  -- 4262811
43599    -- 
43600    --
43601    -- set accounting line type info
43602    --
43603    xla_ae_lines_pkg.SetAcctLineType
43604       (p_component_type             => l_component_type
43605       ,p_event_type_code            => l_event_type_code
43606       ,p_line_definition_owner_code => l_line_definition_owner_code
43607       ,p_line_definition_code       => l_line_definition_code
43608       ,p_accounting_line_code       => l_component_code
43609       ,p_accounting_line_type_code  => l_component_type_code
43610       ,p_accounting_line_appl_id    => l_component_appl_id
43611       ,p_amb_context_code           => l_amb_context_code
43612       ,p_entity_code                => l_entity_code
43616    --
43613       ,p_event_class_code           => l_event_class_code);
43614    --
43615    -- set accounting class
43617    xla_ae_lines_pkg.SetAcctClass(
43618            p_accounting_class_code  => 'REMITTANCE'
43619          , p_ae_header_id           => l_ae_header_id
43620          );
43621 
43622    --
43623    -- set rounding class
43624    --
43625    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
43626                       'RECEIVABLE';
43627 
43628    --
43629    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
43630    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
43631    --
43632    -- bulk performance
43633    --
43634    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
43635 
43636    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
43637       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
43638 
43639    -- 4955764
43640    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
43641       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
43642 
43643    -- 4458381 Public Sector Enh
43644    
43645    --
43646    -- set accounting attributes for the line type
43647    --
43648    l_entered_amt_idx := 3;
43649    l_accted_amt_idx  := 8;
43650    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
43651    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
43652    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
43653    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
43654    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
43655    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
43656    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
43657    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
43658    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
43659    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
43660    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
43661    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
43662    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
43663    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
43664    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
43665    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
43666    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
43667 
43668    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
43669    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
43670 
43671    ---------------------------------------------------------------------------------------------------------------
43672    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
43673    ---------------------------------------------------------------------------------------------------------------
43674    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
43675 
43676    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
43677    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
43678 
43679    IF xla_accounting_cache_pkg.GetValueChar
43680          (p_source_code         => 'LEDGER_CATEGORY_CODE'
43681          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
43682    AND l_bflow_method_code = 'PRIOR_ENTRY'
43683 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
43684    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
43685          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
43686        )
43687    THEN
43688          xla_ae_lines_pkg.BflowUpgEntry
43689            (p_business_method_code    => l_bflow_method_code
43690            ,p_business_class_code     => l_bflow_class_code
43691            ,p_balance_type            => l_balance_type_code);
43692    ELSE
43693       NULL;
43694 -- No business flow processing for business flow method of NONE.
43695    END IF;
43696 
43697    --
43698    -- call analytical criteria
43699    --
43700    
43701    --
43702    -- call description
43703    --
43704    
43705 xla_ae_lines_pkg.SetLineDescription(
43706    p_ae_header_id => l_ae_header_id
43707   ,p_description  => Description_1 (
43708      p_application_id         => p_application_id
43709    , p_ae_header_id           => l_ae_header_id 
43710    )
43711 );
43712 
43713 
43714    --
43715    -- call ADRs
43716    -- Bug 4922099
43717    --
43718    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
43719         (NVL(l_actual_upg_option, 'N') = 'O') OR
43720         (NVL(l_enc_upg_option, 'N') = 'O')
43721       )
43722    THEN
43723    NULL;
43724    --
43725    --
43726    
43727   l_ccid := AcctDerRule_27(
43728            p_application_id           => p_application_id
43729          , p_ae_header_id             => l_ae_header_id 
43730 , p_source_15 => p_source_15
43731          , x_transaction_coa_id       => l_adr_transaction_coa_id
43732          , x_accounting_coa_id        => l_adr_accounting_coa_id
43736 
43733          , x_value_type_code          => l_adr_value_type_code
43734          , p_side                     => 'NA'
43735    );
43737    xla_ae_lines_pkg.set_ccid(
43738     p_code_combination_id          => l_ccid
43739   , p_value_type_code              => l_adr_value_type_code
43740   , p_transaction_coa_id           => l_adr_transaction_coa_id
43741   , p_accounting_coa_id            => l_adr_accounting_coa_id
43742   , p_adr_code                     => 'MFAR_RCT_DEF_REMITTANCE_CCID'
43743   , p_adr_type_code                => 'S'
43744   , p_component_type               => l_component_type
43745   , p_component_code               => l_component_code
43746   , p_component_type_code          => l_component_type_code
43747   , p_component_appl_id            => l_component_appl_id
43748   , p_amb_context_code             => l_amb_context_code
43749   , p_side                         => 'NA'
43750   );
43751 
43752 
43753    l_segment := AcctDerRule_4(
43754            p_application_id           => p_application_id
43755          , p_ae_header_id             => l_ae_header_id 
43756 , p_source_3 => p_source_3
43757          , x_transaction_coa_id       => l_adr_transaction_coa_id
43758          , x_accounting_coa_id        => l_adr_accounting_coa_id
43759          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
43760          , x_flex_value_set_id        => l_adr_flex_value_set_id
43761          , x_value_type_code          => l_adr_value_type_code
43762          , x_value_combination_id     => l_adr_value_combination_id
43763          , x_value_segment_code       => l_adr_value_segment_code
43764          , p_side                     => 'NA'
43765          , p_override_seg_flag        => 'Y'
43766    );
43767 
43768    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
43769 
43770       xla_ae_lines_pkg.set_segment(
43771           p_to_segment_code         => 'GL_BALANCING'
43772         , p_segment_value           => l_segment
43773         , p_from_segment_code       => l_adr_value_segment_code
43774         , p_from_combination_id     => l_adr_value_combination_id
43775         , p_value_type_code         => l_adr_value_type_code
43776         , p_transaction_coa_id      => l_adr_transaction_coa_id
43777         , p_accounting_coa_id       => l_adr_accounting_coa_id
43778         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
43779         , p_flex_value_set_id       => l_adr_flex_value_set_id
43780         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
43781         , p_adr_type_code           => 'S'
43782         , p_component_type          => l_component_type
43783         , p_component_code          => l_component_code
43784         , p_component_type_code     => l_component_type_code
43785         , p_component_appl_id       => l_component_appl_id
43786         , p_amb_context_code        => l_amb_context_code
43787         , p_entity_code             => 'RECEIPTS'
43788         , p_event_class_code        => 'MISC_RECEIPT'
43789         , p_side                    => 'NA'
43790         );
43791 
43792   END IF;
43793 
43794    --
43795    --
43796    END IF;
43797    --
43798    -- Bug 4922099
43799    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
43800           (NVL(l_enc_upg_option, 'N') = 'O')
43801         ) AND
43802         (l_bflow_method_code = 'PRIOR_ENTRY')
43803       )
43804    THEN
43805       IF
43806       --
43807       1 = 2
43808       --
43809       THEN
43810       xla_accounting_err_pkg.build_message
43811                                     (p_appli_s_name            => 'XLA'
43812                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
43813                                     ,p_token_1                 => 'LINE_NUMBER'
43814                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
43815                                     ,p_token_2                 => 'LINE_TYPE_NAME'
43816                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
43817                                                                              l_component_type
43818                                                                             ,l_component_code
43819                                                                             ,l_component_type_code
43820                                                                             ,l_component_appl_id
43821                                                                             ,l_amb_context_code
43822                                                                             ,l_entity_code
43823                                                                             ,l_event_class_code
43824                                                                            )
43825                                     ,p_token_3                 => 'OWNER'
43826                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
43827                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
43828                                                                           ,p_lookup_code    => l_component_type_code
43829                                                                          )
43830                                     ,p_token_4                 => 'PRODUCT_NAME'
43831                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
43832                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
43836                                        );
43833                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
43834                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
43835                                     ,p_ae_header_id            =>  NULL
43837 
43838         IF (C_LEVEL_ERROR>= g_log_level) THEN
43839                  trace
43840                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
43841                       ,p_level    => C_LEVEL_ERROR
43842                       ,p_module   => l_log_module);
43843         END IF;
43844       END IF;
43845    END IF;
43846    --
43847    --
43848    ------------------------------------------------------------------------------------------------
43849    -- 4219869 Business Flow
43850    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
43851    -- Prior Entry.  Currently, the following code is always generated.
43852    ------------------------------------------------------------------------------------------------
43853    XLA_AE_LINES_PKG.ValidateCurrentLine;
43854 
43855    ------------------------------------------------------------------------------------
43856    -- 4219869 Business Flow
43857    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
43858    ------------------------------------------------------------------------------------
43859    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
43860 
43861    ----------------------------------------------------------------------------------
43862    -- 4219869 Business Flow
43863    -- Update journal entry status -- Need to generate this within IF <condition>
43864    ----------------------------------------------------------------------------------
43865    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
43866          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
43867          ,p_balance_type_code => l_balance_type_code
43868          );
43869 
43870    -------------------------------------------------------------------------------------------
43871    -- 4262811 - Generate the Accrual Reversal lines
43872    -------------------------------------------------------------------------------------------
43873    BEGIN
43874       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
43875                               (g_array_event(p_event_id).array_value_num('header_index'));
43876       IF l_acc_rev_flag IS NULL THEN
43877          l_acc_rev_flag := 'N';
43878       END IF;
43879    EXCEPTION
43880       WHEN OTHERS THEN
43881          l_acc_rev_flag := 'N';
43882    END;
43883    --
43884    IF (l_acc_rev_flag = 'Y') THEN
43885 
43886        -- 4645092  ------------------------------------------------------------------------------
43887        -- To allow MPA report to determine if it should generate report process
43888        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
43889        ------------------------------------------------------------------------------------------
43890 
43891        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
43892        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
43893    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
43894    -- call ADRs
43895    -- Bug 4922099
43896    --
43897    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
43898         (NVL(l_actual_upg_option, 'N') = 'O') OR
43899         (NVL(l_enc_upg_option, 'N') = 'O')
43900       )
43901    THEN
43902    NULL;
43903    --
43904    --
43905    
43906   l_ccid := AcctDerRule_27(
43907            p_application_id           => p_application_id
43908          , p_ae_header_id             => l_ae_header_id 
43909 , p_source_15 => p_source_15
43910          , x_transaction_coa_id       => l_adr_transaction_coa_id
43911          , x_accounting_coa_id        => l_adr_accounting_coa_id
43912          , x_value_type_code          => l_adr_value_type_code
43913          , p_side                     => 'NA'
43914    );
43915 
43916    xla_ae_lines_pkg.set_ccid(
43917     p_code_combination_id          => l_ccid
43918   , p_value_type_code              => l_adr_value_type_code
43919   , p_transaction_coa_id           => l_adr_transaction_coa_id
43920   , p_accounting_coa_id            => l_adr_accounting_coa_id
43921   , p_adr_code                     => 'MFAR_RCT_DEF_REMITTANCE_CCID'
43922   , p_adr_type_code                => 'S'
43923   , p_component_type               => l_component_type
43924   , p_component_code               => l_component_code
43925   , p_component_type_code          => l_component_type_code
43926   , p_component_appl_id            => l_component_appl_id
43927   , p_amb_context_code             => l_amb_context_code
43928   , p_side                         => 'NA'
43929   );
43930 
43931 
43932    l_segment := AcctDerRule_4(
43933            p_application_id           => p_application_id
43934          , p_ae_header_id             => l_ae_header_id 
43935 , p_source_3 => p_source_3
43936          , x_transaction_coa_id       => l_adr_transaction_coa_id
43937          , x_accounting_coa_id        => l_adr_accounting_coa_id
43938          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
43939          , x_flex_value_set_id        => l_adr_flex_value_set_id
43940          , x_value_type_code          => l_adr_value_type_code
43941          , x_value_combination_id     => l_adr_value_combination_id
43945    );
43942          , x_value_segment_code       => l_adr_value_segment_code
43943          , p_side                     => 'NA'
43944          , p_override_seg_flag        => 'Y'
43946 
43947    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
43948 
43949       xla_ae_lines_pkg.set_segment(
43950           p_to_segment_code         => 'GL_BALANCING'
43951         , p_segment_value           => l_segment
43952         , p_from_segment_code       => l_adr_value_segment_code
43953         , p_from_combination_id     => l_adr_value_combination_id
43954         , p_value_type_code         => l_adr_value_type_code
43955         , p_transaction_coa_id      => l_adr_transaction_coa_id
43956         , p_accounting_coa_id       => l_adr_accounting_coa_id
43957         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
43958         , p_flex_value_set_id       => l_adr_flex_value_set_id
43959         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
43960         , p_adr_type_code           => 'S'
43961         , p_component_type          => l_component_type
43962         , p_component_code          => l_component_code
43963         , p_component_type_code     => l_component_type_code
43964         , p_component_appl_id       => l_component_appl_id
43965         , p_amb_context_code        => l_amb_context_code
43966         , p_entity_code             => 'RECEIPTS'
43967         , p_event_class_code        => 'MISC_RECEIPT'
43968         , p_side                    => 'NA'
43969         );
43970 
43971   END IF;
43972 
43973    --
43974    --
43975    END IF;
43976 
43977        --
43978        -- Update the line information that should be overwritten
43979        --
43980        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
43981                                          p_header_num   => 1);
43982        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
43983 
43984        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
43985 
43986        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
43987           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
43988        END IF;
43989 
43990       --
43991       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
43992       --
43993       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
43994           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
43995       ELSE
43996           ---------------------------------------------------------------------------------------------------
43997           -- 4262811a Switch Sign
43998           ---------------------------------------------------------------------------------------------------
43999           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
44000           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
44001                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
44002           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
44003                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
44004           -- 5132302
44005           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
44006                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
44007 
44008       END IF;
44009 
44010       -- 4955764
44011       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
44012       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
44013 
44014 
44015       XLA_AE_LINES_PKG.ValidateCurrentLine;
44016       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
44017 
44018       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
44019                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
44020                ,p_balance_type_code => l_balance_type_code);
44021 
44022    END IF;
44023 
44024    -----------------------------------------------------------------------------------------
44025    -- 4262811 Multiperiod Accounting
44026    -----------------------------------------------------------------------------------------
44027      -- No MPA option is assigned.
44028 
44029 
44030 END IF;
44031 END IF;
44032 --
44033 
44034 --
44035 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
44036    trace
44037       (p_msg      => 'END of AcctLineType_94'
44038       ,p_level    => C_LEVEL_PROCEDURE
44039       ,p_module   => l_log_module);
44040 END IF;
44041 --
44042 EXCEPTION
44043   WHEN xla_exceptions_pkg.application_exception THEN
44044       RAISE;
44045   WHEN OTHERS THEN
44046        xla_exceptions_pkg.raise_message
44047            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_94');
44048 END AcctLineType_94;
44049 --
44050 
44051 ---------------------------------------
44052 --
44053 -- PRIVATE FUNCTION
44054 --         AcctLineType_95
44055 --
44056 ---------------------------------------
44057 PROCEDURE AcctLineType_95 (
44061  ,p_calculate_g_l_flag    IN VARCHAR2
44058   p_application_id        IN NUMBER
44059  ,p_event_id              IN NUMBER
44060  ,p_calculate_acctd_flag  IN VARCHAR2
44062  ,p_actual_flag           IN OUT VARCHAR2
44063  ,p_balance_type_code     OUT VARCHAR2
44064  ,p_gain_or_loss_ref      OUT VARCHAR2
44065  
44066 --Remittance Bank Account Bank Charges Acount
44067  , p_source_1            IN NUMBER
44068 --Remittance Bank Account Cash Account
44069  , p_source_13            IN NUMBER
44070 --Distribution Source Type
44071  , p_source_20            IN VARCHAR2
44072 --Distribution Line Identifier
44073  , p_source_22            IN NUMBER
44074 --Distribution Type
44075  , p_source_23            IN VARCHAR2
44076 --Exchange Date
44077  , p_source_26            IN DATE
44078 --Exchange Rate
44079  , p_source_27            IN NUMBER
44080 --Exchange Rate Type
44081  , p_source_28            IN VARCHAR2
44082 --Transaction Distribution Identifier
44083  , p_source_34            IN NUMBER
44084 --Transaction Distribution Type
44085  , p_source_35            IN VARCHAR2
44086 --Receipt Applied To Application Identifier
44087  , p_source_58            IN NUMBER
44088 --Transaction Entity Code
44089  , p_source_59            IN VARCHAR2
44090 --Transaction Identifier
44091  , p_source_60            IN NUMBER
44092 --Applying Document Currency Code
44093  , p_source_61            IN VARCHAR2
44094 --Distribution Party Identifier
44095  , p_source_63            IN NUMBER
44096 --Distribution Party Site Id
44097  , p_source_64            IN NUMBER
44098 --Distribution Party Type
44099  , p_source_65            IN VARCHAR2
44100 --Distribution Multi Fund Additional Entry
44101  , p_source_69            IN VARCHAR2
44102 --DIST_ENT_AMT_FROM
44103  , p_source_72            IN NUMBER
44104 --Accounting Amount
44105  , p_source_73            IN NUMBER
44106 )
44107 IS
44108 
44109 l_component_type              VARCHAR2(80);
44110 l_component_code              VARCHAR2(30);
44111 l_component_type_code         VARCHAR2(1);
44112 l_component_appl_id           INTEGER;
44113 l_amb_context_code            VARCHAR2(30);
44114 l_entity_code                 VARCHAR2(30);
44115 l_event_class_code            VARCHAR2(30);
44116 l_ae_header_id                NUMBER;
44117 l_event_type_code             VARCHAR2(30);
44118 l_line_definition_code        VARCHAR2(30);
44119 l_line_definition_owner_code  VARCHAR2(1);
44120 --
44121 -- adr variables
44122 l_segment                     VARCHAR2(30);
44123 l_ccid                        NUMBER;
44124 l_adr_transaction_coa_id      NUMBER;
44125 l_adr_accounting_coa_id       NUMBER;
44126 l_adr_flexfield_segment_code  VARCHAR2(30);
44127 l_adr_flex_value_set_id       NUMBER;
44128 l_adr_value_type_code         VARCHAR2(30);
44129 l_adr_value_combination_id    NUMBER;
44130 l_adr_value_segment_code      VARCHAR2(30);
44131 
44132 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
44133 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
44134 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
44135 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
44136 
44137 -- 4262811 Variables ------------------------------------------------------------------------------------------
44138 l_entered_amt_idx             NUMBER;
44139 l_accted_amt_idx              NUMBER;
44140 l_acc_rev_flag                VARCHAR2(1);
44141 l_accrual_line_num            NUMBER;
44142 l_tmp_amt                     NUMBER;
44143 l_acc_rev_natural_side_code   VARCHAR2(1);
44144 
44145 l_num_entries                 NUMBER;
44146 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
44147 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
44148 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
44149 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
44150 l_recog_line_1                NUMBER;
44151 l_recog_line_2                NUMBER;
44152 
44153 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
44154 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
44155 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
44156 
44157 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
44158 
44159 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
44160 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
44161 
44162 ---------------------------------------------------------------------------------------------------------------
44163 
44164 
44165 --
44166 -- bulk performance
44167 --
44168 l_balance_type_code           VARCHAR2(1);
44169 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
44170 l_log_module                  VARCHAR2(240);
44171 
44172 --
44173 -- Upgrade strategy
44174 --
44175 l_actual_upg_option           VARCHAR2(1);
44176 l_enc_upg_option           VARCHAR2(1);
44177 
44178 --
44179 BEGIN
44180 --
44181 IF g_log_enabled THEN
44182       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_95';
44183 END IF;
44184 --
44185 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
44186 
44187       trace
44188          (p_msg      => 'BEGIN of AcctLineType_95'
44192 END IF;
44189          ,p_level    => C_LEVEL_PROCEDURE
44190          ,p_module   => l_log_module);
44191 
44193 --
44194 l_component_type             := 'AMB_JLT';
44195 l_component_code             := 'MFAR_RCT_BNK_CHG_CASH';
44196 l_component_type_code        := 'S';
44197 l_component_appl_id          :=  222;
44198 l_amb_context_code           := 'DEFAULT';
44199 l_entity_code                := 'RECEIPTS';
44200 l_event_class_code           := 'RECEIPT';
44201 l_event_type_code            := 'RECEIPT_ALL';
44202 l_line_definition_owner_code := 'S';
44203 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
44204 --
44205 l_balance_type_code          := 'A';
44206 l_segment                     := NULL;
44207 l_ccid                        := NULL;
44208 l_adr_transaction_coa_id      := NULL;
44209 l_adr_accounting_coa_id       := NULL;
44210 l_adr_flexfield_segment_code  := NULL;
44211 l_adr_flex_value_set_id       := NULL;
44212 l_adr_value_type_code         := NULL;
44213 l_adr_value_combination_id    := NULL;
44214 l_adr_value_segment_code      := NULL;
44215 
44216 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
44217 l_bflow_class_code           := '';    -- 4219869 Business Flow
44218 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
44219 l_budgetary_control_flag     := 'N';
44220 
44221 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
44222 l_bflow_applied_to_amt       := NULL; -- 5132302
44223 l_entered_amt_idx            := NULL;          -- 4262811
44224 l_accted_amt_idx             := NULL;          -- 4262811
44225 l_acc_rev_flag               := NULL;          -- 4262811
44226 l_accrual_line_num           := NULL;          -- 4262811
44227 l_tmp_amt                    := NULL;          -- 4262811
44228 --
44229  
44230 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
44231     l_balance_type_code <> 'B' THEN
44232 IF NVL(p_source_20,'
44233 ') =  'BANK_CHARGES' AND 
44234 NVL(p_source_69,'
44235 ') =  'N'
44236  THEN 
44237 
44238    --
44239    XLA_AE_LINES_PKG.SetNewLine;
44240 
44241    p_balance_type_code          := l_balance_type_code;
44242    -- set the flag so later we will know whether the gain loss line needs to be created
44243    
44244    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
44245      p_actual_flag :='A';
44246    END IF;
44247 
44248    --
44249    -- bulk performance
44250    --
44251    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
44252                                       p_header_num   => 0); -- 4262811
44253    --
44254    -- set accounting line options
44255    --
44256    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
44257            p_natural_side_code          => 'D'
44258          , p_gain_or_loss_flag          => 'N'
44259          , p_gl_transfer_mode_code      => 'S'
44260          , p_acct_entry_type_code       => 'A'
44261          , p_switch_side_flag           => 'Y'
44262          , p_merge_duplicate_code       => 'A'
44263          );
44264    --
44265    l_acc_rev_natural_side_code := 'C';  -- 4262811
44266    -- 
44267    --
44268    -- set accounting line type info
44269    --
44270    xla_ae_lines_pkg.SetAcctLineType
44271       (p_component_type             => l_component_type
44272       ,p_event_type_code            => l_event_type_code
44273       ,p_line_definition_owner_code => l_line_definition_owner_code
44274       ,p_line_definition_code       => l_line_definition_code
44275       ,p_accounting_line_code       => l_component_code
44276       ,p_accounting_line_type_code  => l_component_type_code
44277       ,p_accounting_line_appl_id    => l_component_appl_id
44278       ,p_amb_context_code           => l_amb_context_code
44279       ,p_entity_code                => l_entity_code
44280       ,p_event_class_code           => l_event_class_code);
44281    --
44282    -- set accounting class
44283    --
44284    xla_ae_lines_pkg.SetAcctClass(
44285            p_accounting_class_code  => 'CASH'
44286          , p_ae_header_id           => l_ae_header_id
44287          );
44288 
44289    --
44290    -- set rounding class
44291    --
44292    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
44293                       'RECEIVABLE';
44294 
44295    --
44296    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
44297    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
44298    --
44299    -- bulk performance
44300    --
44301    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
44302 
44303    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
44304       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
44305 
44306    -- 4955764
44307    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
44308       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
44309 
44310    -- 4458381 Public Sector Enh
44311    
44312    --
44313    -- set accounting attributes for the line type
44314    --
44315    l_entered_amt_idx := 8;
44316    l_accted_amt_idx  := 13;
44317    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
44318    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
44322    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
44319    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
44320    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
44321    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
44323    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
44324    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
44325    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
44326    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
44327    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
44328    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
44329    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
44330    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
44331    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
44332    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
44333    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
44334    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
44335    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
44336    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
44337    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
44338    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
44339    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
44340    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
44341    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
44342    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
44343    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
44344    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
44345    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
44346    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
44347    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
44348    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
44349    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
44350 
44351    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
44352    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
44353 
44354    ---------------------------------------------------------------------------------------------------------------
44355    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
44356    ---------------------------------------------------------------------------------------------------------------
44357    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
44358 
44359    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
44360    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
44361 
44362    IF xla_accounting_cache_pkg.GetValueChar
44363          (p_source_code         => 'LEDGER_CATEGORY_CODE'
44364          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
44365    AND l_bflow_method_code = 'PRIOR_ENTRY'
44366 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
44367    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
44368          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
44369        )
44370    THEN
44371          xla_ae_lines_pkg.BflowUpgEntry
44372            (p_business_method_code    => l_bflow_method_code
44373            ,p_business_class_code     => l_bflow_class_code
44374            ,p_balance_type            => l_balance_type_code);
44375    ELSE
44376       NULL;
44377 -- No business flow processing for business flow method of NONE.
44378    END IF;
44379 
44380    --
44381    -- call analytical criteria
44382    --
44383    
44384    --
44385    -- call description
44386    --
44387    
44388 xla_ae_lines_pkg.SetLineDescription(
44389    p_ae_header_id => l_ae_header_id
44390   ,p_description  => Description_1 (
44391      p_application_id         => p_application_id
44392    , p_ae_header_id           => l_ae_header_id 
44393    )
44394 );
44395 
44396 
44397    --
44398    -- call ADRs
44399    -- Bug 4922099
44400    --
44401    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
44402         (NVL(l_actual_upg_option, 'N') = 'O') OR
44403         (NVL(l_enc_upg_option, 'N') = 'O')
44404       )
44405    THEN
44406    NULL;
44407    --
44408    --
44409    
44410   l_ccid := AcctDerRule_25(
44411            p_application_id           => p_application_id
44412          , p_ae_header_id             => l_ae_header_id 
44413 , p_source_13 => p_source_13
44414          , x_transaction_coa_id       => l_adr_transaction_coa_id
44415          , x_accounting_coa_id        => l_adr_accounting_coa_id
44416          , x_value_type_code          => l_adr_value_type_code
44417          , p_side                     => 'NA'
44418    );
44419 
44420    xla_ae_lines_pkg.set_ccid(
44421     p_code_combination_id          => l_ccid
44422   , p_value_type_code              => l_adr_value_type_code
44423   , p_transaction_coa_id           => l_adr_transaction_coa_id
44424   , p_accounting_coa_id            => l_adr_accounting_coa_id
44425   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
44426   , p_adr_type_code                => 'S'
44427   , p_component_type               => l_component_type
44428   , p_component_code               => l_component_code
44432   , p_side                         => 'NA'
44429   , p_component_type_code          => l_component_type_code
44430   , p_component_appl_id            => l_component_appl_id
44431   , p_amb_context_code             => l_amb_context_code
44433   );
44434 
44435 
44436    l_segment := AcctDerRule_2(
44437            p_application_id           => p_application_id
44438          , p_ae_header_id             => l_ae_header_id 
44439 , p_source_1 => p_source_1
44440          , x_transaction_coa_id       => l_adr_transaction_coa_id
44441          , x_accounting_coa_id        => l_adr_accounting_coa_id
44442          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
44443          , x_flex_value_set_id        => l_adr_flex_value_set_id
44444          , x_value_type_code          => l_adr_value_type_code
44445          , x_value_combination_id     => l_adr_value_combination_id
44446          , x_value_segment_code       => l_adr_value_segment_code
44447          , p_side                     => 'NA'
44448          , p_override_seg_flag        => 'Y'
44449    );
44450 
44451    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
44452 
44453       xla_ae_lines_pkg.set_segment(
44454           p_to_segment_code         => 'GL_BALANCING'
44455         , p_segment_value           => l_segment
44456         , p_from_segment_code       => l_adr_value_segment_code
44457         , p_from_combination_id     => l_adr_value_combination_id
44458         , p_value_type_code         => l_adr_value_type_code
44459         , p_transaction_coa_id      => l_adr_transaction_coa_id
44460         , p_accounting_coa_id       => l_adr_accounting_coa_id
44461         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
44462         , p_flex_value_set_id       => l_adr_flex_value_set_id
44463         , p_adr_code                => 'MFAR_BNK_CHARGES_BALANCING_SEG'
44464         , p_adr_type_code           => 'S'
44465         , p_component_type          => l_component_type
44466         , p_component_code          => l_component_code
44467         , p_component_type_code     => l_component_type_code
44468         , p_component_appl_id       => l_component_appl_id
44469         , p_amb_context_code        => l_amb_context_code
44470         , p_entity_code             => 'RECEIPTS'
44471         , p_event_class_code        => 'RECEIPT'
44472         , p_side                    => 'NA'
44473         );
44474 
44475   END IF;
44476 
44477    --
44478    --
44479    END IF;
44480    --
44481    -- Bug 4922099
44482    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
44483           (NVL(l_enc_upg_option, 'N') = 'O')
44484         ) AND
44485         (l_bflow_method_code = 'PRIOR_ENTRY')
44486       )
44487    THEN
44488       IF
44489       --
44490       1 = 2
44491       --
44492       THEN
44493       xla_accounting_err_pkg.build_message
44494                                     (p_appli_s_name            => 'XLA'
44495                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
44496                                     ,p_token_1                 => 'LINE_NUMBER'
44497                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
44498                                     ,p_token_2                 => 'LINE_TYPE_NAME'
44499                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
44500                                                                              l_component_type
44501                                                                             ,l_component_code
44502                                                                             ,l_component_type_code
44503                                                                             ,l_component_appl_id
44504                                                                             ,l_amb_context_code
44505                                                                             ,l_entity_code
44506                                                                             ,l_event_class_code
44507                                                                            )
44508                                     ,p_token_3                 => 'OWNER'
44509                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
44510                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
44511                                                                           ,p_lookup_code    => l_component_type_code
44512                                                                          )
44513                                     ,p_token_4                 => 'PRODUCT_NAME'
44514                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
44515                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
44516                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
44517                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
44518                                     ,p_ae_header_id            =>  NULL
44519                                        );
44520 
44521         IF (C_LEVEL_ERROR>= g_log_level) THEN
44522                  trace
44523                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
44524                       ,p_level    => C_LEVEL_ERROR
44525                       ,p_module   => l_log_module);
44526         END IF;
44527       END IF;
44528    END IF;
44532    -- 4219869 Business Flow
44529    --
44530    --
44531    ------------------------------------------------------------------------------------------------
44533    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
44534    -- Prior Entry.  Currently, the following code is always generated.
44535    ------------------------------------------------------------------------------------------------
44536    XLA_AE_LINES_PKG.ValidateCurrentLine;
44537 
44538    ------------------------------------------------------------------------------------
44539    -- 4219869 Business Flow
44540    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
44541    ------------------------------------------------------------------------------------
44542    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
44543 
44544    ----------------------------------------------------------------------------------
44545    -- 4219869 Business Flow
44546    -- Update journal entry status -- Need to generate this within IF <condition>
44547    ----------------------------------------------------------------------------------
44548    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
44549          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
44550          ,p_balance_type_code => l_balance_type_code
44551          );
44552 
44553    -------------------------------------------------------------------------------------------
44554    -- 4262811 - Generate the Accrual Reversal lines
44555    -------------------------------------------------------------------------------------------
44556    BEGIN
44557       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
44558                               (g_array_event(p_event_id).array_value_num('header_index'));
44559       IF l_acc_rev_flag IS NULL THEN
44560          l_acc_rev_flag := 'N';
44561       END IF;
44562    EXCEPTION
44563       WHEN OTHERS THEN
44564          l_acc_rev_flag := 'N';
44565    END;
44566    --
44567    IF (l_acc_rev_flag = 'Y') THEN
44568 
44569        -- 4645092  ------------------------------------------------------------------------------
44570        -- To allow MPA report to determine if it should generate report process
44571        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
44572        ------------------------------------------------------------------------------------------
44573 
44574        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
44575        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
44576    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
44577    -- call ADRs
44578    -- Bug 4922099
44579    --
44580    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
44581         (NVL(l_actual_upg_option, 'N') = 'O') OR
44582         (NVL(l_enc_upg_option, 'N') = 'O')
44583       )
44584    THEN
44585    NULL;
44586    --
44587    --
44588    
44589   l_ccid := AcctDerRule_25(
44590            p_application_id           => p_application_id
44591          , p_ae_header_id             => l_ae_header_id 
44592 , p_source_13 => p_source_13
44593          , x_transaction_coa_id       => l_adr_transaction_coa_id
44594          , x_accounting_coa_id        => l_adr_accounting_coa_id
44595          , x_value_type_code          => l_adr_value_type_code
44596          , p_side                     => 'NA'
44597    );
44598 
44599    xla_ae_lines_pkg.set_ccid(
44600     p_code_combination_id          => l_ccid
44601   , p_value_type_code              => l_adr_value_type_code
44602   , p_transaction_coa_id           => l_adr_transaction_coa_id
44603   , p_accounting_coa_id            => l_adr_accounting_coa_id
44604   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
44605   , p_adr_type_code                => 'S'
44606   , p_component_type               => l_component_type
44607   , p_component_code               => l_component_code
44608   , p_component_type_code          => l_component_type_code
44609   , p_component_appl_id            => l_component_appl_id
44610   , p_amb_context_code             => l_amb_context_code
44611   , p_side                         => 'NA'
44612   );
44613 
44614 
44615    l_segment := AcctDerRule_2(
44616            p_application_id           => p_application_id
44617          , p_ae_header_id             => l_ae_header_id 
44618 , p_source_1 => p_source_1
44619          , x_transaction_coa_id       => l_adr_transaction_coa_id
44620          , x_accounting_coa_id        => l_adr_accounting_coa_id
44621          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
44622          , x_flex_value_set_id        => l_adr_flex_value_set_id
44623          , x_value_type_code          => l_adr_value_type_code
44624          , x_value_combination_id     => l_adr_value_combination_id
44625          , x_value_segment_code       => l_adr_value_segment_code
44626          , p_side                     => 'NA'
44627          , p_override_seg_flag        => 'Y'
44628    );
44629 
44630    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
44631 
44632       xla_ae_lines_pkg.set_segment(
44633           p_to_segment_code         => 'GL_BALANCING'
44634         , p_segment_value           => l_segment
44635         , p_from_segment_code       => l_adr_value_segment_code
44636         , p_from_combination_id     => l_adr_value_combination_id
44637         , p_value_type_code         => l_adr_value_type_code
44638         , p_transaction_coa_id      => l_adr_transaction_coa_id
44642         , p_adr_code                => 'MFAR_BNK_CHARGES_BALANCING_SEG'
44639         , p_accounting_coa_id       => l_adr_accounting_coa_id
44640         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
44641         , p_flex_value_set_id       => l_adr_flex_value_set_id
44643         , p_adr_type_code           => 'S'
44644         , p_component_type          => l_component_type
44645         , p_component_code          => l_component_code
44646         , p_component_type_code     => l_component_type_code
44647         , p_component_appl_id       => l_component_appl_id
44648         , p_amb_context_code        => l_amb_context_code
44649         , p_entity_code             => 'RECEIPTS'
44650         , p_event_class_code        => 'RECEIPT'
44651         , p_side                    => 'NA'
44652         );
44653 
44654   END IF;
44655 
44656    --
44657    --
44658    END IF;
44659 
44660        --
44661        -- Update the line information that should be overwritten
44662        --
44663        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
44664                                          p_header_num   => 1);
44665        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
44666 
44667        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
44668 
44669        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
44670           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
44671        END IF;
44672 
44673       --
44674       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
44675       --
44676       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
44677           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
44678       ELSE
44679           ---------------------------------------------------------------------------------------------------
44680           -- 4262811a Switch Sign
44681           ---------------------------------------------------------------------------------------------------
44682           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
44683           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
44684                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
44685           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
44686                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
44687           -- 5132302
44688           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
44689                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
44690 
44691       END IF;
44692 
44693       -- 4955764
44694       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
44695       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
44696 
44697 
44698       XLA_AE_LINES_PKG.ValidateCurrentLine;
44699       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
44700 
44701       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
44702                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
44703                ,p_balance_type_code => l_balance_type_code);
44704 
44705    END IF;
44706 
44707    -----------------------------------------------------------------------------------------
44708    -- 4262811 Multiperiod Accounting
44709    -----------------------------------------------------------------------------------------
44710      -- No MPA option is assigned.
44711 
44712 
44713 END IF;
44714 END IF;
44715 --
44716 
44717 --
44718 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
44719    trace
44720       (p_msg      => 'END of AcctLineType_95'
44721       ,p_level    => C_LEVEL_PROCEDURE
44722       ,p_module   => l_log_module);
44723 END IF;
44724 --
44725 EXCEPTION
44726   WHEN xla_exceptions_pkg.application_exception THEN
44727       RAISE;
44728   WHEN OTHERS THEN
44729        xla_exceptions_pkg.raise_message
44730            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_95');
44731 END AcctLineType_95;
44732 --
44733 
44734 ---------------------------------------
44735 --
44736 -- PRIVATE FUNCTION
44737 --         AcctLineType_96
44738 --
44739 ---------------------------------------
44740 PROCEDURE AcctLineType_96 (
44741   p_application_id        IN NUMBER
44742  ,p_event_id              IN NUMBER
44743  ,p_calculate_acctd_flag  IN VARCHAR2
44744  ,p_calculate_g_l_flag    IN VARCHAR2
44745  ,p_actual_flag           IN OUT VARCHAR2
44746  ,p_balance_type_code     OUT VARCHAR2
44747  ,p_gain_or_loss_ref      OUT VARCHAR2
44748  
44749 --Remittance Bank Account Cash Account
44750  , p_source_13            IN NUMBER
44751 --Distribution Source Type
44752  , p_source_20            IN VARCHAR2
44753 --Distribution Line Identifier
44754  , p_source_22            IN NUMBER
44755 --Distribution Type
44756  , p_source_23            IN VARCHAR2
44757 --Exchange Date
44758  , p_source_26            IN DATE
44759 --Exchange Rate
44763 --Transaction Distribution Account Class
44760  , p_source_27            IN NUMBER
44761 --Exchange Rate Type
44762  , p_source_28            IN VARCHAR2
44764  , p_source_33            IN VARCHAR2
44765 --Transaction Distribution Identifier
44766  , p_source_34            IN NUMBER
44767 --Transaction Distribution Type
44768  , p_source_35            IN VARCHAR2
44769 --Receipt Applied To Application Identifier
44770  , p_source_58            IN NUMBER
44771 --Transaction Entity Code
44772  , p_source_59            IN VARCHAR2
44773 --Transaction Identifier
44774  , p_source_60            IN NUMBER
44775 --Applying Document Currency Code
44776  , p_source_61            IN VARCHAR2
44777 --Distribution Party Identifier
44778  , p_source_63            IN NUMBER
44779 --Distribution Party Site Id
44780  , p_source_64            IN NUMBER
44781 --Distribution Party Type
44782  , p_source_65            IN VARCHAR2
44783 --Distribution Multi Fund Additional Entry
44784  , p_source_69            IN VARCHAR2
44785 --Receipt Class Require Remittance Flag
44786  , p_source_70            IN VARCHAR2
44787 --Receipt Class Confirm Flag
44788  , p_source_71            IN VARCHAR2
44789 --DIST_ENT_AMT_FROM
44790  , p_source_72            IN NUMBER
44791 --Accounting Amount
44792  , p_source_73            IN NUMBER
44793 )
44794 IS
44795 
44796 l_component_type              VARCHAR2(80);
44797 l_component_code              VARCHAR2(30);
44798 l_component_type_code         VARCHAR2(1);
44799 l_component_appl_id           INTEGER;
44800 l_amb_context_code            VARCHAR2(30);
44801 l_entity_code                 VARCHAR2(30);
44802 l_event_class_code            VARCHAR2(30);
44803 l_ae_header_id                NUMBER;
44804 l_event_type_code             VARCHAR2(30);
44805 l_line_definition_code        VARCHAR2(30);
44806 l_line_definition_owner_code  VARCHAR2(1);
44807 --
44808 -- adr variables
44809 l_segment                     VARCHAR2(30);
44810 l_ccid                        NUMBER;
44811 l_adr_transaction_coa_id      NUMBER;
44812 l_adr_accounting_coa_id       NUMBER;
44813 l_adr_flexfield_segment_code  VARCHAR2(30);
44814 l_adr_flex_value_set_id       NUMBER;
44815 l_adr_value_type_code         VARCHAR2(30);
44816 l_adr_value_combination_id    NUMBER;
44817 l_adr_value_segment_code      VARCHAR2(30);
44818 
44819 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
44820 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
44821 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
44822 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
44823 
44824 -- 4262811 Variables ------------------------------------------------------------------------------------------
44825 l_entered_amt_idx             NUMBER;
44826 l_accted_amt_idx              NUMBER;
44827 l_acc_rev_flag                VARCHAR2(1);
44828 l_accrual_line_num            NUMBER;
44829 l_tmp_amt                     NUMBER;
44830 l_acc_rev_natural_side_code   VARCHAR2(1);
44831 
44832 l_num_entries                 NUMBER;
44833 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
44834 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
44835 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
44836 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
44837 l_recog_line_1                NUMBER;
44838 l_recog_line_2                NUMBER;
44839 
44840 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
44841 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
44842 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
44843 
44844 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
44845 
44846 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
44847 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
44848 
44849 ---------------------------------------------------------------------------------------------------------------
44850 
44851 
44852 --
44853 -- bulk performance
44854 --
44855 l_balance_type_code           VARCHAR2(1);
44856 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
44857 l_log_module                  VARCHAR2(240);
44858 
44859 --
44860 -- Upgrade strategy
44861 --
44862 l_actual_upg_option           VARCHAR2(1);
44863 l_enc_upg_option           VARCHAR2(1);
44864 
44865 --
44866 BEGIN
44867 --
44868 IF g_log_enabled THEN
44869       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_96';
44870 END IF;
44871 --
44872 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
44873 
44874       trace
44875          (p_msg      => 'BEGIN of AcctLineType_96'
44876          ,p_level    => C_LEVEL_PROCEDURE
44877          ,p_module   => l_log_module);
44878 
44879 END IF;
44880 --
44881 l_component_type             := 'AMB_JLT';
44882 l_component_code             := 'MFAR_RCT_CASH_REVERSE';
44883 l_component_type_code        := 'S';
44884 l_component_appl_id          :=  222;
44885 l_amb_context_code           := 'DEFAULT';
44886 l_entity_code                := 'RECEIPTS';
44887 l_event_class_code           := 'RECEIPT';
44888 l_event_type_code            := 'RECEIPT_ALL';
44889 l_line_definition_owner_code := 'S';
44890 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
44891 --
44892 l_balance_type_code          := 'A';
44896 l_adr_accounting_coa_id       := NULL;
44893 l_segment                     := NULL;
44894 l_ccid                        := NULL;
44895 l_adr_transaction_coa_id      := NULL;
44897 l_adr_flexfield_segment_code  := NULL;
44898 l_adr_flex_value_set_id       := NULL;
44899 l_adr_value_type_code         := NULL;
44900 l_adr_value_combination_id    := NULL;
44901 l_adr_value_segment_code      := NULL;
44902 
44903 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
44904 l_bflow_class_code           := '';    -- 4219869 Business Flow
44905 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
44906 l_budgetary_control_flag     := 'N';
44907 
44908 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
44909 l_bflow_applied_to_amt       := NULL; -- 5132302
44910 l_entered_amt_idx            := NULL;          -- 4262811
44911 l_accted_amt_idx             := NULL;          -- 4262811
44912 l_acc_rev_flag               := NULL;          -- 4262811
44913 l_accrual_line_num           := NULL;          -- 4262811
44914 l_tmp_amt                    := NULL;          -- 4262811
44915 --
44916  
44917 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
44918     l_balance_type_code <> 'B' THEN
44919 IF (NVL(p_source_33,'
44920 ') =  'REV' OR 
44921 NVL(p_source_33,'
44922 ') =  'TAX' OR 
44923 NVL(p_source_33,'
44924 ') =  'FREIGHT' OR 
44925 NVL(p_source_33,'
44926 ') =  'CHARGES' OR 
44927 NVL(p_source_33,'
44928 ') =  'ROUND') AND 
44929 NVL(p_source_20,'
44930 ') =  'REC' AND 
44931 NVL(p_source_69,'
44932 ') =  'N' AND 
44933 NVL(p_source_70,'
44934 ') =  'N' AND 
44935 NVL(p_source_71,'
44936 ') =  'N'
44937  THEN 
44938 
44939    --
44940    XLA_AE_LINES_PKG.SetNewLine;
44941 
44942    p_balance_type_code          := l_balance_type_code;
44943    -- set the flag so later we will know whether the gain loss line needs to be created
44944    
44945    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
44946      p_actual_flag :='A';
44947    END IF;
44948 
44949    --
44950    -- bulk performance
44951    --
44952    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
44953                                       p_header_num   => 0); -- 4262811
44954    --
44955    -- set accounting line options
44956    --
44957    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
44958            p_natural_side_code          => 'C'
44959          , p_gain_or_loss_flag          => 'N'
44960          , p_gl_transfer_mode_code      => 'S'
44961          , p_acct_entry_type_code       => 'A'
44962          , p_switch_side_flag           => 'Y'
44963          , p_merge_duplicate_code       => 'A'
44964          );
44965    --
44966    l_acc_rev_natural_side_code := 'D';  -- 4262811
44967    -- 
44968    --
44969    -- set accounting line type info
44970    --
44971    xla_ae_lines_pkg.SetAcctLineType
44972       (p_component_type             => l_component_type
44973       ,p_event_type_code            => l_event_type_code
44974       ,p_line_definition_owner_code => l_line_definition_owner_code
44975       ,p_line_definition_code       => l_line_definition_code
44976       ,p_accounting_line_code       => l_component_code
44977       ,p_accounting_line_type_code  => l_component_type_code
44978       ,p_accounting_line_appl_id    => l_component_appl_id
44979       ,p_amb_context_code           => l_amb_context_code
44980       ,p_entity_code                => l_entity_code
44981       ,p_event_class_code           => l_event_class_code);
44982    --
44983    -- set accounting class
44984    --
44985    xla_ae_lines_pkg.SetAcctClass(
44986            p_accounting_class_code  => 'CASH'
44987          , p_ae_header_id           => l_ae_header_id
44988          );
44989 
44990    --
44991    -- set rounding class
44992    --
44993    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
44994                       'RECEIVABLE';
44995 
44996    --
44997    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
44998    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
44999    --
45000    -- bulk performance
45001    --
45002    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
45003 
45004    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
45005       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
45006 
45007    -- 4955764
45008    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
45009       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
45010 
45011    -- 4458381 Public Sector Enh
45012    
45013    --
45014    -- set accounting attributes for the line type
45015    --
45016    l_entered_amt_idx := 8;
45017    l_accted_amt_idx  := 13;
45018    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
45019    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
45020    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
45021    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
45022    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
45023    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
45027    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
45024    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
45025    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
45026    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
45028    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
45029    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
45030    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
45031    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
45032    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
45033    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
45034    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
45035    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
45036    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
45037    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
45038    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
45039    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
45040    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
45041    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
45042    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
45043    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
45044    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
45045    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
45046    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
45047    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
45048    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
45049    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
45050    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
45051 
45052    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
45053    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
45054 
45055    ---------------------------------------------------------------------------------------------------------------
45056    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
45057    ---------------------------------------------------------------------------------------------------------------
45058    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
45059 
45060    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
45061    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
45062 
45063    IF xla_accounting_cache_pkg.GetValueChar
45064          (p_source_code         => 'LEDGER_CATEGORY_CODE'
45065          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
45066    AND l_bflow_method_code = 'PRIOR_ENTRY'
45067 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
45068    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
45069          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
45070        )
45071    THEN
45072          xla_ae_lines_pkg.BflowUpgEntry
45073            (p_business_method_code    => l_bflow_method_code
45074            ,p_business_class_code     => l_bflow_class_code
45075            ,p_balance_type            => l_balance_type_code);
45076    ELSE
45077       NULL;
45078 -- No business flow processing for business flow method of NONE.
45079    END IF;
45080 
45081    --
45082    -- call analytical criteria
45083    --
45084    
45085    --
45086    -- call description
45087    --
45088    
45089 xla_ae_lines_pkg.SetLineDescription(
45090    p_ae_header_id => l_ae_header_id
45091   ,p_description  => Description_1 (
45092      p_application_id         => p_application_id
45093    , p_ae_header_id           => l_ae_header_id 
45094    )
45095 );
45096 
45097 
45098    --
45099    -- call ADRs
45100    -- Bug 4922099
45101    --
45102    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
45103         (NVL(l_actual_upg_option, 'N') = 'O') OR
45104         (NVL(l_enc_upg_option, 'N') = 'O')
45105       )
45106    THEN
45107    NULL;
45108    --
45109    --
45110    
45111   l_ccid := AcctDerRule_25(
45112            p_application_id           => p_application_id
45113          , p_ae_header_id             => l_ae_header_id 
45114 , p_source_13 => p_source_13
45115          , x_transaction_coa_id       => l_adr_transaction_coa_id
45116          , x_accounting_coa_id        => l_adr_accounting_coa_id
45117          , x_value_type_code          => l_adr_value_type_code
45118          , p_side                     => 'NA'
45119    );
45120 
45121    xla_ae_lines_pkg.set_ccid(
45122     p_code_combination_id          => l_ccid
45123   , p_value_type_code              => l_adr_value_type_code
45124   , p_transaction_coa_id           => l_adr_transaction_coa_id
45125   , p_accounting_coa_id            => l_adr_accounting_coa_id
45126   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
45127   , p_adr_type_code                => 'S'
45128   , p_component_type               => l_component_type
45129   , p_component_code               => l_component_code
45130   , p_component_type_code          => l_component_type_code
45131   , p_component_appl_id            => l_component_appl_id
45132   , p_amb_context_code             => l_amb_context_code
45136 
45133   , p_side                         => 'NA'
45134   );
45135 
45137    --
45138    --
45139    END IF;
45140    --
45141    -- Bug 4922099
45142    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
45143           (NVL(l_enc_upg_option, 'N') = 'O')
45144         ) AND
45145         (l_bflow_method_code = 'PRIOR_ENTRY')
45146       )
45147    THEN
45148       IF
45149       --
45150       1 = 2
45151       --
45152       THEN
45153       xla_accounting_err_pkg.build_message
45154                                     (p_appli_s_name            => 'XLA'
45155                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
45156                                     ,p_token_1                 => 'LINE_NUMBER'
45157                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
45158                                     ,p_token_2                 => 'LINE_TYPE_NAME'
45159                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
45160                                                                              l_component_type
45161                                                                             ,l_component_code
45162                                                                             ,l_component_type_code
45163                                                                             ,l_component_appl_id
45164                                                                             ,l_amb_context_code
45165                                                                             ,l_entity_code
45166                                                                             ,l_event_class_code
45167                                                                            )
45168                                     ,p_token_3                 => 'OWNER'
45169                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
45170                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
45171                                                                           ,p_lookup_code    => l_component_type_code
45172                                                                          )
45173                                     ,p_token_4                 => 'PRODUCT_NAME'
45174                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
45175                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
45176                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
45177                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
45178                                     ,p_ae_header_id            =>  NULL
45179                                        );
45180 
45181         IF (C_LEVEL_ERROR>= g_log_level) THEN
45182                  trace
45183                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
45184                       ,p_level    => C_LEVEL_ERROR
45185                       ,p_module   => l_log_module);
45186         END IF;
45187       END IF;
45188    END IF;
45189    --
45190    --
45191    ------------------------------------------------------------------------------------------------
45192    -- 4219869 Business Flow
45193    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
45194    -- Prior Entry.  Currently, the following code is always generated.
45195    ------------------------------------------------------------------------------------------------
45196    XLA_AE_LINES_PKG.ValidateCurrentLine;
45197 
45198    ------------------------------------------------------------------------------------
45199    -- 4219869 Business Flow
45200    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
45201    ------------------------------------------------------------------------------------
45202    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
45203 
45204    ----------------------------------------------------------------------------------
45205    -- 4219869 Business Flow
45206    -- Update journal entry status -- Need to generate this within IF <condition>
45207    ----------------------------------------------------------------------------------
45208    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
45209          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
45210          ,p_balance_type_code => l_balance_type_code
45211          );
45212 
45213    -------------------------------------------------------------------------------------------
45214    -- 4262811 - Generate the Accrual Reversal lines
45215    -------------------------------------------------------------------------------------------
45216    BEGIN
45217       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
45218                               (g_array_event(p_event_id).array_value_num('header_index'));
45219       IF l_acc_rev_flag IS NULL THEN
45220          l_acc_rev_flag := 'N';
45221       END IF;
45222    EXCEPTION
45223       WHEN OTHERS THEN
45224          l_acc_rev_flag := 'N';
45225    END;
45226    --
45227    IF (l_acc_rev_flag = 'Y') THEN
45228 
45229        -- 4645092  ------------------------------------------------------------------------------
45230        -- To allow MPA report to determine if it should generate report process
45234        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
45231        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
45232        ------------------------------------------------------------------------------------------
45233 
45235        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
45236    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
45237    -- call ADRs
45238    -- Bug 4922099
45239    --
45240    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
45241         (NVL(l_actual_upg_option, 'N') = 'O') OR
45242         (NVL(l_enc_upg_option, 'N') = 'O')
45243       )
45244    THEN
45245    NULL;
45246    --
45247    --
45248    
45249   l_ccid := AcctDerRule_25(
45250            p_application_id           => p_application_id
45251          , p_ae_header_id             => l_ae_header_id 
45252 , p_source_13 => p_source_13
45253          , x_transaction_coa_id       => l_adr_transaction_coa_id
45254          , x_accounting_coa_id        => l_adr_accounting_coa_id
45255          , x_value_type_code          => l_adr_value_type_code
45256          , p_side                     => 'NA'
45257    );
45258 
45259    xla_ae_lines_pkg.set_ccid(
45260     p_code_combination_id          => l_ccid
45261   , p_value_type_code              => l_adr_value_type_code
45262   , p_transaction_coa_id           => l_adr_transaction_coa_id
45263   , p_accounting_coa_id            => l_adr_accounting_coa_id
45264   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
45265   , p_adr_type_code                => 'S'
45266   , p_component_type               => l_component_type
45267   , p_component_code               => l_component_code
45268   , p_component_type_code          => l_component_type_code
45269   , p_component_appl_id            => l_component_appl_id
45270   , p_amb_context_code             => l_amb_context_code
45271   , p_side                         => 'NA'
45272   );
45273 
45274 
45275    --
45276    --
45277    END IF;
45278 
45279        --
45280        -- Update the line information that should be overwritten
45281        --
45282        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
45283                                          p_header_num   => 1);
45284        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
45285 
45286        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
45287 
45288        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
45289           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
45290        END IF;
45291 
45292       --
45293       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
45294       --
45295       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
45296           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
45297       ELSE
45298           ---------------------------------------------------------------------------------------------------
45299           -- 4262811a Switch Sign
45300           ---------------------------------------------------------------------------------------------------
45301           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
45302           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
45303                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45304           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
45305                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45306           -- 5132302
45307           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
45308                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45309 
45310       END IF;
45311 
45312       -- 4955764
45313       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
45314       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
45315 
45316 
45317       XLA_AE_LINES_PKG.ValidateCurrentLine;
45318       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
45319 
45320       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
45321                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
45322                ,p_balance_type_code => l_balance_type_code);
45323 
45324    END IF;
45325 
45326    -----------------------------------------------------------------------------------------
45327    -- 4262811 Multiperiod Accounting
45328    -----------------------------------------------------------------------------------------
45329      -- No MPA option is assigned.
45330 
45331 
45332 END IF;
45333 END IF;
45334 --
45335 
45336 --
45337 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
45338    trace
45339       (p_msg      => 'END of AcctLineType_96'
45340       ,p_level    => C_LEVEL_PROCEDURE
45341       ,p_module   => l_log_module);
45342 END IF;
45343 --
45344 EXCEPTION
45345   WHEN xla_exceptions_pkg.application_exception THEN
45346       RAISE;
45347   WHEN OTHERS THEN
45348        xla_exceptions_pkg.raise_message
45352 
45349            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_96');
45350 END AcctLineType_96;
45351 --
45353 ---------------------------------------
45354 --
45355 -- PRIVATE FUNCTION
45356 --         AcctLineType_97
45357 --
45358 ---------------------------------------
45359 PROCEDURE AcctLineType_97 (
45360   p_application_id        IN NUMBER
45361  ,p_event_id              IN NUMBER
45362  ,p_calculate_acctd_flag  IN VARCHAR2
45363  ,p_calculate_g_l_flag    IN VARCHAR2
45364  ,p_actual_flag           IN OUT VARCHAR2
45365  ,p_balance_type_code     OUT VARCHAR2
45366  ,p_gain_or_loss_ref      OUT VARCHAR2
45367  
45368 --Remittance Bank Account Cash Account
45369  , p_source_13            IN NUMBER
45370 --Distribution Source Type
45371  , p_source_20            IN VARCHAR2
45372 --Distribution Line Identifier
45373  , p_source_22            IN NUMBER
45374 --Distribution Type
45375  , p_source_23            IN VARCHAR2
45376 --Exchange Date
45377  , p_source_26            IN DATE
45378 --Exchange Rate
45379  , p_source_27            IN NUMBER
45380 --Exchange Rate Type
45381  , p_source_28            IN VARCHAR2
45382 --Transaction Distribution Identifier
45383  , p_source_34            IN NUMBER
45384 --Transaction Distribution Type
45385  , p_source_35            IN VARCHAR2
45386 --Receipt Applied To Application Identifier
45387  , p_source_58            IN NUMBER
45388 --Transaction Entity Code
45389  , p_source_59            IN VARCHAR2
45390 --Transaction Identifier
45391  , p_source_60            IN NUMBER
45392 --Applying Document Currency Code
45393  , p_source_61            IN VARCHAR2
45394 --Distribution Party Identifier
45395  , p_source_63            IN NUMBER
45396 --Distribution Party Site Id
45397  , p_source_64            IN NUMBER
45398 --Distribution Party Type
45399  , p_source_65            IN VARCHAR2
45400 --Distribution Multi Fund Additional Entry
45401  , p_source_69            IN VARCHAR2
45402 --Receipt Class Require Remittance Flag
45403  , p_source_70            IN VARCHAR2
45404 --DIST_ENT_AMT_FROM
45405  , p_source_72            IN NUMBER
45406 --Accounting Amount
45407  , p_source_73            IN NUMBER
45408 )
45409 IS
45410 
45411 l_component_type              VARCHAR2(80);
45412 l_component_code              VARCHAR2(30);
45413 l_component_type_code         VARCHAR2(1);
45414 l_component_appl_id           INTEGER;
45415 l_amb_context_code            VARCHAR2(30);
45416 l_entity_code                 VARCHAR2(30);
45417 l_event_class_code            VARCHAR2(30);
45418 l_ae_header_id                NUMBER;
45419 l_event_type_code             VARCHAR2(30);
45420 l_line_definition_code        VARCHAR2(30);
45421 l_line_definition_owner_code  VARCHAR2(1);
45422 --
45423 -- adr variables
45424 l_segment                     VARCHAR2(30);
45425 l_ccid                        NUMBER;
45426 l_adr_transaction_coa_id      NUMBER;
45427 l_adr_accounting_coa_id       NUMBER;
45428 l_adr_flexfield_segment_code  VARCHAR2(30);
45429 l_adr_flex_value_set_id       NUMBER;
45430 l_adr_value_type_code         VARCHAR2(30);
45431 l_adr_value_combination_id    NUMBER;
45432 l_adr_value_segment_code      VARCHAR2(30);
45433 
45434 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
45435 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
45436 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
45437 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
45438 
45439 -- 4262811 Variables ------------------------------------------------------------------------------------------
45440 l_entered_amt_idx             NUMBER;
45441 l_accted_amt_idx              NUMBER;
45442 l_acc_rev_flag                VARCHAR2(1);
45443 l_accrual_line_num            NUMBER;
45444 l_tmp_amt                     NUMBER;
45445 l_acc_rev_natural_side_code   VARCHAR2(1);
45446 
45447 l_num_entries                 NUMBER;
45448 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
45449 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
45450 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
45451 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
45452 l_recog_line_1                NUMBER;
45453 l_recog_line_2                NUMBER;
45454 
45455 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
45456 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
45457 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
45458 
45459 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
45460 
45461 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
45462 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
45463 
45464 ---------------------------------------------------------------------------------------------------------------
45465 
45466 
45467 --
45468 -- bulk performance
45469 --
45470 l_balance_type_code           VARCHAR2(1);
45471 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
45472 l_log_module                  VARCHAR2(240);
45473 
45474 --
45475 -- Upgrade strategy
45476 --
45477 l_actual_upg_option           VARCHAR2(1);
45478 l_enc_upg_option           VARCHAR2(1);
45479 
45480 --
45481 BEGIN
45482 --
45486 --
45483 IF g_log_enabled THEN
45484       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_97';
45485 END IF;
45487 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
45488 
45489       trace
45490          (p_msg      => 'BEGIN of AcctLineType_97'
45491          ,p_level    => C_LEVEL_PROCEDURE
45492          ,p_module   => l_log_module);
45493 
45494 END IF;
45495 --
45496 l_component_type             := 'AMB_JLT';
45497 l_component_code             := 'MFAR_RCT_CM_CASH_REVERSAL';
45498 l_component_type_code        := 'S';
45499 l_component_appl_id          :=  222;
45500 l_amb_context_code           := 'DEFAULT';
45501 l_entity_code                := 'RECEIPTS';
45502 l_event_class_code           := 'RECEIPT';
45503 l_event_type_code            := 'RECEIPT_ALL';
45504 l_line_definition_owner_code := 'S';
45505 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
45506 --
45507 l_balance_type_code          := 'A';
45508 l_segment                     := NULL;
45509 l_ccid                        := NULL;
45510 l_adr_transaction_coa_id      := NULL;
45511 l_adr_accounting_coa_id       := NULL;
45512 l_adr_flexfield_segment_code  := NULL;
45513 l_adr_flex_value_set_id       := NULL;
45514 l_adr_value_type_code         := NULL;
45515 l_adr_value_combination_id    := NULL;
45516 l_adr_value_segment_code      := NULL;
45517 
45518 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
45519 l_bflow_class_code           := '';    -- 4219869 Business Flow
45520 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
45521 l_budgetary_control_flag     := 'N';
45522 
45523 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
45524 l_bflow_applied_to_amt       := NULL; -- 5132302
45525 l_entered_amt_idx            := NULL;          -- 4262811
45526 l_accted_amt_idx             := NULL;          -- 4262811
45527 l_acc_rev_flag               := NULL;          -- 4262811
45528 l_accrual_line_num           := NULL;          -- 4262811
45529 l_tmp_amt                    := NULL;          -- 4262811
45530 --
45531  
45532 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
45533     l_balance_type_code <> 'B' THEN
45534 IF NVL(p_source_20,'
45535 ') =  'CASH' AND 
45536 NVL(p_source_69,'
45537 ') =  'Y' AND 
45538 NVL(p_source_70,'
45539 ') =  'Y'
45540  THEN 
45541 
45542    --
45543    XLA_AE_LINES_PKG.SetNewLine;
45544 
45545    p_balance_type_code          := l_balance_type_code;
45546    -- set the flag so later we will know whether the gain loss line needs to be created
45547    
45548    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
45549      p_actual_flag :='A';
45550    END IF;
45551 
45552    --
45553    -- bulk performance
45554    --
45555    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
45556                                       p_header_num   => 0); -- 4262811
45557    --
45558    -- set accounting line options
45559    --
45560    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
45561            p_natural_side_code          => 'D'
45562          , p_gain_or_loss_flag          => 'N'
45563          , p_gl_transfer_mode_code      => 'S'
45564          , p_acct_entry_type_code       => 'A'
45565          , p_switch_side_flag           => 'Y'
45566          , p_merge_duplicate_code       => 'A'
45567          );
45568    --
45569    l_acc_rev_natural_side_code := 'C';  -- 4262811
45570    -- 
45571    --
45572    -- set accounting line type info
45573    --
45574    xla_ae_lines_pkg.SetAcctLineType
45575       (p_component_type             => l_component_type
45576       ,p_event_type_code            => l_event_type_code
45577       ,p_line_definition_owner_code => l_line_definition_owner_code
45578       ,p_line_definition_code       => l_line_definition_code
45579       ,p_accounting_line_code       => l_component_code
45580       ,p_accounting_line_type_code  => l_component_type_code
45581       ,p_accounting_line_appl_id    => l_component_appl_id
45582       ,p_amb_context_code           => l_amb_context_code
45583       ,p_entity_code                => l_entity_code
45584       ,p_event_class_code           => l_event_class_code);
45585    --
45586    -- set accounting class
45587    --
45588    xla_ae_lines_pkg.SetAcctClass(
45589            p_accounting_class_code  => 'CASH'
45590          , p_ae_header_id           => l_ae_header_id
45591          );
45592 
45593    --
45594    -- set rounding class
45595    --
45596    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
45597                       'RECEIVABLE';
45598 
45599    --
45600    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
45601    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
45602    --
45603    -- bulk performance
45604    --
45605    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
45606 
45607    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
45608       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
45609 
45610    -- 4955764
45611    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
45612       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
45613 
45617    -- set accounting attributes for the line type
45614    -- 4458381 Public Sector Enh
45615    
45616    --
45618    --
45619    l_entered_amt_idx := 8;
45620    l_accted_amt_idx  := 13;
45621    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
45622    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
45623    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
45624    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
45625    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
45626    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
45627    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
45628    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
45629    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
45630    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
45631    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
45632    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
45633    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
45634    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
45635    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
45636    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
45637    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
45638    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
45639    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
45640    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
45641    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
45642    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
45643    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
45644    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
45645    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
45646    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
45647    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
45648    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
45649    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
45650    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
45651    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
45652    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
45653    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
45654 
45655    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
45656    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
45657 
45658    ---------------------------------------------------------------------------------------------------------------
45659    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
45660    ---------------------------------------------------------------------------------------------------------------
45661    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
45662 
45663    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
45664    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
45665 
45666    IF xla_accounting_cache_pkg.GetValueChar
45667          (p_source_code         => 'LEDGER_CATEGORY_CODE'
45668          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
45669    AND l_bflow_method_code = 'PRIOR_ENTRY'
45670 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
45671    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
45672          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
45673        )
45674    THEN
45675          xla_ae_lines_pkg.BflowUpgEntry
45676            (p_business_method_code    => l_bflow_method_code
45677            ,p_business_class_code     => l_bflow_class_code
45678            ,p_balance_type            => l_balance_type_code);
45679    ELSE
45680       NULL;
45681 -- No business flow processing for business flow method of NONE.
45682    END IF;
45683 
45684    --
45685    -- call analytical criteria
45686    --
45687    
45688    --
45689    -- call description
45690    --
45691    
45692 xla_ae_lines_pkg.SetLineDescription(
45693    p_ae_header_id => l_ae_header_id
45694   ,p_description  => Description_1 (
45695      p_application_id         => p_application_id
45696    , p_ae_header_id           => l_ae_header_id 
45697    )
45698 );
45699 
45700 
45701    --
45702    -- call ADRs
45703    -- Bug 4922099
45704    --
45705    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
45706         (NVL(l_actual_upg_option, 'N') = 'O') OR
45707         (NVL(l_enc_upg_option, 'N') = 'O')
45708       )
45709    THEN
45710    NULL;
45711    --
45712    --
45713    
45714   l_ccid := AcctDerRule_25(
45715            p_application_id           => p_application_id
45716          , p_ae_header_id             => l_ae_header_id 
45717 , p_source_13 => p_source_13
45718          , x_transaction_coa_id       => l_adr_transaction_coa_id
45719          , x_accounting_coa_id        => l_adr_accounting_coa_id
45720          , x_value_type_code          => l_adr_value_type_code
45721          , p_side                     => 'NA'
45722    );
45723 
45724    xla_ae_lines_pkg.set_ccid(
45725     p_code_combination_id          => l_ccid
45729   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
45726   , p_value_type_code              => l_adr_value_type_code
45727   , p_transaction_coa_id           => l_adr_transaction_coa_id
45728   , p_accounting_coa_id            => l_adr_accounting_coa_id
45730   , p_adr_type_code                => 'S'
45731   , p_component_type               => l_component_type
45732   , p_component_code               => l_component_code
45733   , p_component_type_code          => l_component_type_code
45734   , p_component_appl_id            => l_component_appl_id
45735   , p_amb_context_code             => l_amb_context_code
45736   , p_side                         => 'NA'
45737   );
45738 
45739 
45740    --
45741    --
45742    END IF;
45743    --
45744    -- Bug 4922099
45745    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
45746           (NVL(l_enc_upg_option, 'N') = 'O')
45747         ) AND
45748         (l_bflow_method_code = 'PRIOR_ENTRY')
45749       )
45750    THEN
45751       IF
45752       --
45753       1 = 2
45754       --
45755       THEN
45756       xla_accounting_err_pkg.build_message
45757                                     (p_appli_s_name            => 'XLA'
45758                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
45759                                     ,p_token_1                 => 'LINE_NUMBER'
45760                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
45761                                     ,p_token_2                 => 'LINE_TYPE_NAME'
45762                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
45763                                                                              l_component_type
45764                                                                             ,l_component_code
45765                                                                             ,l_component_type_code
45766                                                                             ,l_component_appl_id
45767                                                                             ,l_amb_context_code
45768                                                                             ,l_entity_code
45769                                                                             ,l_event_class_code
45770                                                                            )
45771                                     ,p_token_3                 => 'OWNER'
45772                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
45773                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
45774                                                                           ,p_lookup_code    => l_component_type_code
45775                                                                          )
45776                                     ,p_token_4                 => 'PRODUCT_NAME'
45777                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
45778                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
45779                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
45780                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
45781                                     ,p_ae_header_id            =>  NULL
45782                                        );
45783 
45784         IF (C_LEVEL_ERROR>= g_log_level) THEN
45785                  trace
45786                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
45787                       ,p_level    => C_LEVEL_ERROR
45788                       ,p_module   => l_log_module);
45789         END IF;
45790       END IF;
45791    END IF;
45792    --
45793    --
45794    ------------------------------------------------------------------------------------------------
45795    -- 4219869 Business Flow
45796    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
45797    -- Prior Entry.  Currently, the following code is always generated.
45798    ------------------------------------------------------------------------------------------------
45799    XLA_AE_LINES_PKG.ValidateCurrentLine;
45800 
45801    ------------------------------------------------------------------------------------
45802    -- 4219869 Business Flow
45803    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
45804    ------------------------------------------------------------------------------------
45805    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
45806 
45807    ----------------------------------------------------------------------------------
45808    -- 4219869 Business Flow
45809    -- Update journal entry status -- Need to generate this within IF <condition>
45810    ----------------------------------------------------------------------------------
45811    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
45812          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
45813          ,p_balance_type_code => l_balance_type_code
45814          );
45815 
45816    -------------------------------------------------------------------------------------------
45817    -- 4262811 - Generate the Accrual Reversal lines
45818    -------------------------------------------------------------------------------------------
45819    BEGIN
45823          l_acc_rev_flag := 'N';
45820       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
45821                               (g_array_event(p_event_id).array_value_num('header_index'));
45822       IF l_acc_rev_flag IS NULL THEN
45824       END IF;
45825    EXCEPTION
45826       WHEN OTHERS THEN
45827          l_acc_rev_flag := 'N';
45828    END;
45829    --
45830    IF (l_acc_rev_flag = 'Y') THEN
45831 
45832        -- 4645092  ------------------------------------------------------------------------------
45833        -- To allow MPA report to determine if it should generate report process
45834        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
45835        ------------------------------------------------------------------------------------------
45836 
45837        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
45838        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
45839    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
45840    -- call ADRs
45841    -- Bug 4922099
45842    --
45843    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
45844         (NVL(l_actual_upg_option, 'N') = 'O') OR
45845         (NVL(l_enc_upg_option, 'N') = 'O')
45846       )
45847    THEN
45848    NULL;
45849    --
45850    --
45851    
45852   l_ccid := AcctDerRule_25(
45853            p_application_id           => p_application_id
45854          , p_ae_header_id             => l_ae_header_id 
45855 , p_source_13 => p_source_13
45856          , x_transaction_coa_id       => l_adr_transaction_coa_id
45857          , x_accounting_coa_id        => l_adr_accounting_coa_id
45858          , x_value_type_code          => l_adr_value_type_code
45859          , p_side                     => 'NA'
45860    );
45861 
45862    xla_ae_lines_pkg.set_ccid(
45863     p_code_combination_id          => l_ccid
45864   , p_value_type_code              => l_adr_value_type_code
45865   , p_transaction_coa_id           => l_adr_transaction_coa_id
45866   , p_accounting_coa_id            => l_adr_accounting_coa_id
45867   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
45868   , p_adr_type_code                => 'S'
45869   , p_component_type               => l_component_type
45870   , p_component_code               => l_component_code
45871   , p_component_type_code          => l_component_type_code
45872   , p_component_appl_id            => l_component_appl_id
45873   , p_amb_context_code             => l_amb_context_code
45874   , p_side                         => 'NA'
45875   );
45876 
45877 
45878    --
45879    --
45880    END IF;
45881 
45882        --
45883        -- Update the line information that should be overwritten
45884        --
45885        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
45886                                          p_header_num   => 1);
45887        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
45888 
45889        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
45890 
45891        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
45892           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
45893        END IF;
45894 
45895       --
45896       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
45897       --
45898       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
45899           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
45900       ELSE
45901           ---------------------------------------------------------------------------------------------------
45902           -- 4262811a Switch Sign
45903           ---------------------------------------------------------------------------------------------------
45904           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
45905           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
45906                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45907           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
45908                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45909           -- 5132302
45910           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
45911                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45912 
45913       END IF;
45914 
45915       -- 4955764
45916       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
45917       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
45918 
45919 
45920       XLA_AE_LINES_PKG.ValidateCurrentLine;
45921       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
45922 
45923       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
45924                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
45925                ,p_balance_type_code => l_balance_type_code);
45926 
45927    END IF;
45928 
45929    -----------------------------------------------------------------------------------------
45930    -- 4262811 Multiperiod Accounting
45931    -----------------------------------------------------------------------------------------
45935 END IF;
45932      -- No MPA option is assigned.
45933 
45934 
45936 END IF;
45937 --
45938 
45939 --
45940 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
45941    trace
45942       (p_msg      => 'END of AcctLineType_97'
45943       ,p_level    => C_LEVEL_PROCEDURE
45944       ,p_module   => l_log_module);
45945 END IF;
45946 --
45947 EXCEPTION
45948   WHEN xla_exceptions_pkg.application_exception THEN
45949       RAISE;
45950   WHEN OTHERS THEN
45951        xla_exceptions_pkg.raise_message
45952            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_97');
45953 END AcctLineType_97;
45954 --
45955 
45956 ---------------------------------------
45957 --
45958 -- PRIVATE FUNCTION
45959 --         AcctLineType_98
45960 --
45961 ---------------------------------------
45962 PROCEDURE AcctLineType_98 (
45963   p_application_id        IN NUMBER
45964  ,p_event_id              IN NUMBER
45965  ,p_calculate_acctd_flag  IN VARCHAR2
45966  ,p_calculate_g_l_flag    IN VARCHAR2
45967  ,p_actual_flag           IN OUT VARCHAR2
45968  ,p_balance_type_code     OUT VARCHAR2
45969  ,p_gain_or_loss_ref      OUT VARCHAR2
45970  
45971 --Remittance Bank Account Confirmation Account
45972  , p_source_14            IN NUMBER
45973 --Distribution Source Type
45974  , p_source_20            IN VARCHAR2
45975 --Distribution Line Identifier
45976  , p_source_22            IN NUMBER
45977 --Distribution Type
45978  , p_source_23            IN VARCHAR2
45979 --Exchange Date
45980  , p_source_26            IN DATE
45981 --Exchange Rate
45982  , p_source_27            IN NUMBER
45983 --Exchange Rate Type
45984  , p_source_28            IN VARCHAR2
45985 --Transaction Distribution Identifier
45986  , p_source_34            IN NUMBER
45987 --Transaction Distribution Type
45988  , p_source_35            IN VARCHAR2
45989 --Receipt Applied To Application Identifier
45990  , p_source_58            IN NUMBER
45991 --Transaction Entity Code
45992  , p_source_59            IN VARCHAR2
45993 --Transaction Identifier
45994  , p_source_60            IN NUMBER
45995 --Applying Document Currency Code
45996  , p_source_61            IN VARCHAR2
45997 --Distribution Party Identifier
45998  , p_source_63            IN NUMBER
45999 --Distribution Party Site Id
46000  , p_source_64            IN NUMBER
46001 --Distribution Party Type
46002  , p_source_65            IN VARCHAR2
46003 --Distribution Multi Fund Additional Entry
46004  , p_source_69            IN VARCHAR2
46005 --DIST_ENT_AMT_FROM
46006  , p_source_72            IN NUMBER
46007 --Accounting Amount
46008  , p_source_73            IN NUMBER
46009 )
46010 IS
46011 
46012 l_component_type              VARCHAR2(80);
46013 l_component_code              VARCHAR2(30);
46014 l_component_type_code         VARCHAR2(1);
46015 l_component_appl_id           INTEGER;
46016 l_amb_context_code            VARCHAR2(30);
46017 l_entity_code                 VARCHAR2(30);
46018 l_event_class_code            VARCHAR2(30);
46019 l_ae_header_id                NUMBER;
46020 l_event_type_code             VARCHAR2(30);
46021 l_line_definition_code        VARCHAR2(30);
46022 l_line_definition_owner_code  VARCHAR2(1);
46023 --
46024 -- adr variables
46025 l_segment                     VARCHAR2(30);
46026 l_ccid                        NUMBER;
46027 l_adr_transaction_coa_id      NUMBER;
46028 l_adr_accounting_coa_id       NUMBER;
46029 l_adr_flexfield_segment_code  VARCHAR2(30);
46030 l_adr_flex_value_set_id       NUMBER;
46031 l_adr_value_type_code         VARCHAR2(30);
46032 l_adr_value_combination_id    NUMBER;
46033 l_adr_value_segment_code      VARCHAR2(30);
46034 
46035 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
46036 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
46037 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
46038 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
46039 
46040 -- 4262811 Variables ------------------------------------------------------------------------------------------
46041 l_entered_amt_idx             NUMBER;
46042 l_accted_amt_idx              NUMBER;
46043 l_acc_rev_flag                VARCHAR2(1);
46044 l_accrual_line_num            NUMBER;
46045 l_tmp_amt                     NUMBER;
46046 l_acc_rev_natural_side_code   VARCHAR2(1);
46047 
46048 l_num_entries                 NUMBER;
46049 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
46050 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
46051 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
46052 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
46053 l_recog_line_1                NUMBER;
46054 l_recog_line_2                NUMBER;
46055 
46056 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
46057 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
46058 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
46059 
46060 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
46061 
46062 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
46063 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
46064 
46068 --
46065 ---------------------------------------------------------------------------------------------------------------
46066 
46067 
46069 -- bulk performance
46070 --
46071 l_balance_type_code           VARCHAR2(1);
46072 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
46073 l_log_module                  VARCHAR2(240);
46074 
46075 --
46076 -- Upgrade strategy
46077 --
46078 l_actual_upg_option           VARCHAR2(1);
46079 l_enc_upg_option           VARCHAR2(1);
46080 
46081 --
46082 BEGIN
46083 --
46084 IF g_log_enabled THEN
46085       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_98';
46086 END IF;
46087 --
46088 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
46089 
46090       trace
46091          (p_msg      => 'BEGIN of AcctLineType_98'
46092          ,p_level    => C_LEVEL_PROCEDURE
46093          ,p_module   => l_log_module);
46094 
46095 END IF;
46096 --
46097 l_component_type             := 'AMB_JLT';
46098 l_component_code             := 'MFAR_RCT_CONFIRM_REVERSAL';
46099 l_component_type_code        := 'S';
46100 l_component_appl_id          :=  222;
46101 l_amb_context_code           := 'DEFAULT';
46102 l_entity_code                := 'RECEIPTS';
46103 l_event_class_code           := 'RECEIPT';
46104 l_event_type_code            := 'RECEIPT_ALL';
46105 l_line_definition_owner_code := 'S';
46106 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
46107 --
46108 l_balance_type_code          := 'A';
46109 l_segment                     := NULL;
46110 l_ccid                        := NULL;
46111 l_adr_transaction_coa_id      := NULL;
46112 l_adr_accounting_coa_id       := NULL;
46113 l_adr_flexfield_segment_code  := NULL;
46114 l_adr_flex_value_set_id       := NULL;
46115 l_adr_value_type_code         := NULL;
46116 l_adr_value_combination_id    := NULL;
46117 l_adr_value_segment_code      := NULL;
46118 
46119 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
46120 l_bflow_class_code           := '';    -- 4219869 Business Flow
46121 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
46122 l_budgetary_control_flag     := 'N';
46123 
46124 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
46125 l_bflow_applied_to_amt       := NULL; -- 5132302
46126 l_entered_amt_idx            := NULL;          -- 4262811
46127 l_accted_amt_idx             := NULL;          -- 4262811
46128 l_acc_rev_flag               := NULL;          -- 4262811
46129 l_accrual_line_num           := NULL;          -- 4262811
46130 l_tmp_amt                    := NULL;          -- 4262811
46131 --
46132  
46133 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
46134     l_balance_type_code <> 'B' THEN
46135 IF NVL(p_source_20,'
46136 ') =  'CONFIRMATION' AND 
46137 NVL(p_source_69,'
46138 ') =  'Y'
46139  THEN 
46140 
46141    --
46142    XLA_AE_LINES_PKG.SetNewLine;
46143 
46144    p_balance_type_code          := l_balance_type_code;
46145    -- set the flag so later we will know whether the gain loss line needs to be created
46146    
46147    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
46148      p_actual_flag :='A';
46149    END IF;
46150 
46151    --
46152    -- bulk performance
46153    --
46154    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
46155                                       p_header_num   => 0); -- 4262811
46156    --
46157    -- set accounting line options
46158    --
46159    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
46160            p_natural_side_code          => 'D'
46161          , p_gain_or_loss_flag          => 'N'
46162          , p_gl_transfer_mode_code      => 'S'
46163          , p_acct_entry_type_code       => 'A'
46164          , p_switch_side_flag           => 'Y'
46165          , p_merge_duplicate_code       => 'A'
46166          );
46167    --
46168    l_acc_rev_natural_side_code := 'C';  -- 4262811
46169    -- 
46170    --
46171    -- set accounting line type info
46172    --
46173    xla_ae_lines_pkg.SetAcctLineType
46174       (p_component_type             => l_component_type
46175       ,p_event_type_code            => l_event_type_code
46176       ,p_line_definition_owner_code => l_line_definition_owner_code
46177       ,p_line_definition_code       => l_line_definition_code
46178       ,p_accounting_line_code       => l_component_code
46179       ,p_accounting_line_type_code  => l_component_type_code
46180       ,p_accounting_line_appl_id    => l_component_appl_id
46181       ,p_amb_context_code           => l_amb_context_code
46182       ,p_entity_code                => l_entity_code
46183       ,p_event_class_code           => l_event_class_code);
46184    --
46185    -- set accounting class
46186    --
46187    xla_ae_lines_pkg.SetAcctClass(
46188            p_accounting_class_code  => 'CONFIRMATION'
46189          , p_ae_header_id           => l_ae_header_id
46190          );
46191 
46192    --
46193    -- set rounding class
46194    --
46195    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
46196                       'RECEIVABLE';
46197 
46198    --
46199    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
46203    --
46200    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
46201    --
46202    -- bulk performance
46204    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
46205 
46206    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
46207       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
46208 
46209    -- 4955764
46210    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
46211       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
46212 
46213    -- 4458381 Public Sector Enh
46214    
46215    --
46216    -- set accounting attributes for the line type
46217    --
46218    l_entered_amt_idx := 8;
46219    l_accted_amt_idx  := 13;
46220    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
46221    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
46222    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
46223    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
46224    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
46225    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
46226    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
46227    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
46228    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
46229    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
46230    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
46231    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
46232    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
46233    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
46234    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
46235    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
46236    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
46237    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
46238    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
46239    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
46240    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
46241    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
46242    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
46243    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
46244    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
46245    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
46246    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
46247    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
46248    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
46249    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
46250    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
46251    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
46252    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
46253 
46254    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
46255    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
46256 
46257    ---------------------------------------------------------------------------------------------------------------
46258    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
46259    ---------------------------------------------------------------------------------------------------------------
46260    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
46261 
46262    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
46263    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
46264 
46265    IF xla_accounting_cache_pkg.GetValueChar
46266          (p_source_code         => 'LEDGER_CATEGORY_CODE'
46267          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
46268    AND l_bflow_method_code = 'PRIOR_ENTRY'
46269 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
46270    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
46271          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
46272        )
46273    THEN
46274          xla_ae_lines_pkg.BflowUpgEntry
46275            (p_business_method_code    => l_bflow_method_code
46276            ,p_business_class_code     => l_bflow_class_code
46277            ,p_balance_type            => l_balance_type_code);
46278    ELSE
46279       NULL;
46280 -- No business flow processing for business flow method of NONE.
46281    END IF;
46282 
46283    --
46284    -- call analytical criteria
46285    --
46286    
46287    --
46288    -- call description
46289    --
46290    
46291 xla_ae_lines_pkg.SetLineDescription(
46292    p_ae_header_id => l_ae_header_id
46293   ,p_description  => Description_1 (
46294      p_application_id         => p_application_id
46295    , p_ae_header_id           => l_ae_header_id 
46296    )
46297 );
46298 
46299 
46300    --
46301    -- call ADRs
46302    -- Bug 4922099
46303    --
46304    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
46305         (NVL(l_actual_upg_option, 'N') = 'O') OR
46306         (NVL(l_enc_upg_option, 'N') = 'O')
46307       )
46308    THEN
46312    
46309    NULL;
46310    --
46311    --
46313   l_ccid := AcctDerRule_26(
46314            p_application_id           => p_application_id
46315          , p_ae_header_id             => l_ae_header_id 
46316 , p_source_14 => p_source_14
46317          , x_transaction_coa_id       => l_adr_transaction_coa_id
46318          , x_accounting_coa_id        => l_adr_accounting_coa_id
46319          , x_value_type_code          => l_adr_value_type_code
46320          , p_side                     => 'NA'
46321    );
46322 
46323    xla_ae_lines_pkg.set_ccid(
46324     p_code_combination_id          => l_ccid
46325   , p_value_type_code              => l_adr_value_type_code
46326   , p_transaction_coa_id           => l_adr_transaction_coa_id
46327   , p_accounting_coa_id            => l_adr_accounting_coa_id
46328   , p_adr_code                     => 'MFAR_RCT_DEF_CONFIRMATION_CCID'
46329   , p_adr_type_code                => 'S'
46330   , p_component_type               => l_component_type
46331   , p_component_code               => l_component_code
46332   , p_component_type_code          => l_component_type_code
46333   , p_component_appl_id            => l_component_appl_id
46334   , p_amb_context_code             => l_amb_context_code
46335   , p_side                         => 'NA'
46336   );
46337 
46338 
46339    --
46340    --
46341    END IF;
46342    --
46343    -- Bug 4922099
46344    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
46345           (NVL(l_enc_upg_option, 'N') = 'O')
46346         ) AND
46347         (l_bflow_method_code = 'PRIOR_ENTRY')
46348       )
46349    THEN
46350       IF
46351       --
46352       1 = 2
46353       --
46354       THEN
46355       xla_accounting_err_pkg.build_message
46356                                     (p_appli_s_name            => 'XLA'
46357                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
46358                                     ,p_token_1                 => 'LINE_NUMBER'
46359                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
46360                                     ,p_token_2                 => 'LINE_TYPE_NAME'
46361                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
46362                                                                              l_component_type
46363                                                                             ,l_component_code
46364                                                                             ,l_component_type_code
46365                                                                             ,l_component_appl_id
46366                                                                             ,l_amb_context_code
46367                                                                             ,l_entity_code
46368                                                                             ,l_event_class_code
46369                                                                            )
46370                                     ,p_token_3                 => 'OWNER'
46371                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
46372                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
46373                                                                           ,p_lookup_code    => l_component_type_code
46374                                                                          )
46375                                     ,p_token_4                 => 'PRODUCT_NAME'
46376                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
46377                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
46378                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
46379                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
46380                                     ,p_ae_header_id            =>  NULL
46381                                        );
46382 
46383         IF (C_LEVEL_ERROR>= g_log_level) THEN
46384                  trace
46385                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
46386                       ,p_level    => C_LEVEL_ERROR
46387                       ,p_module   => l_log_module);
46388         END IF;
46389       END IF;
46390    END IF;
46391    --
46392    --
46393    ------------------------------------------------------------------------------------------------
46394    -- 4219869 Business Flow
46395    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
46396    -- Prior Entry.  Currently, the following code is always generated.
46397    ------------------------------------------------------------------------------------------------
46398    XLA_AE_LINES_PKG.ValidateCurrentLine;
46399 
46400    ------------------------------------------------------------------------------------
46401    -- 4219869 Business Flow
46402    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
46403    ------------------------------------------------------------------------------------
46404    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
46405 
46406    ----------------------------------------------------------------------------------
46407    -- 4219869 Business Flow
46408    -- Update journal entry status -- Need to generate this within IF <condition>
46412          ,p_balance_type_code => l_balance_type_code
46409    ----------------------------------------------------------------------------------
46410    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
46411          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
46413          );
46414 
46415    -------------------------------------------------------------------------------------------
46416    -- 4262811 - Generate the Accrual Reversal lines
46417    -------------------------------------------------------------------------------------------
46418    BEGIN
46419       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
46420                               (g_array_event(p_event_id).array_value_num('header_index'));
46421       IF l_acc_rev_flag IS NULL THEN
46422          l_acc_rev_flag := 'N';
46423       END IF;
46424    EXCEPTION
46425       WHEN OTHERS THEN
46426          l_acc_rev_flag := 'N';
46427    END;
46428    --
46429    IF (l_acc_rev_flag = 'Y') THEN
46430 
46431        -- 4645092  ------------------------------------------------------------------------------
46432        -- To allow MPA report to determine if it should generate report process
46433        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
46434        ------------------------------------------------------------------------------------------
46435 
46436        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
46437        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
46438    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
46439    -- call ADRs
46440    -- Bug 4922099
46441    --
46442    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
46443         (NVL(l_actual_upg_option, 'N') = 'O') OR
46444         (NVL(l_enc_upg_option, 'N') = 'O')
46445       )
46446    THEN
46447    NULL;
46448    --
46449    --
46450    
46451   l_ccid := AcctDerRule_26(
46452            p_application_id           => p_application_id
46453          , p_ae_header_id             => l_ae_header_id 
46454 , p_source_14 => p_source_14
46455          , x_transaction_coa_id       => l_adr_transaction_coa_id
46456          , x_accounting_coa_id        => l_adr_accounting_coa_id
46457          , x_value_type_code          => l_adr_value_type_code
46458          , p_side                     => 'NA'
46459    );
46460 
46461    xla_ae_lines_pkg.set_ccid(
46462     p_code_combination_id          => l_ccid
46463   , p_value_type_code              => l_adr_value_type_code
46464   , p_transaction_coa_id           => l_adr_transaction_coa_id
46465   , p_accounting_coa_id            => l_adr_accounting_coa_id
46466   , p_adr_code                     => 'MFAR_RCT_DEF_CONFIRMATION_CCID'
46467   , p_adr_type_code                => 'S'
46468   , p_component_type               => l_component_type
46469   , p_component_code               => l_component_code
46470   , p_component_type_code          => l_component_type_code
46471   , p_component_appl_id            => l_component_appl_id
46472   , p_amb_context_code             => l_amb_context_code
46473   , p_side                         => 'NA'
46474   );
46475 
46476 
46477    --
46478    --
46479    END IF;
46480 
46481        --
46482        -- Update the line information that should be overwritten
46483        --
46484        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
46485                                          p_header_num   => 1);
46486        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
46487 
46488        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
46489 
46490        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
46491           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
46492        END IF;
46493 
46494       --
46495       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
46496       --
46497       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
46498           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
46499       ELSE
46500           ---------------------------------------------------------------------------------------------------
46501           -- 4262811a Switch Sign
46502           ---------------------------------------------------------------------------------------------------
46503           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
46504           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
46505                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
46506           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
46507                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
46508           -- 5132302
46509           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
46510                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
46511 
46512       END IF;
46513 
46514       -- 4955764
46515       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
46519       XLA_AE_LINES_PKG.ValidateCurrentLine;
46516       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
46517 
46518 
46520       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
46521 
46522       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
46523                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
46524                ,p_balance_type_code => l_balance_type_code);
46525 
46526    END IF;
46527 
46528    -----------------------------------------------------------------------------------------
46529    -- 4262811 Multiperiod Accounting
46530    -----------------------------------------------------------------------------------------
46531      -- No MPA option is assigned.
46532 
46533 
46534 END IF;
46535 END IF;
46536 --
46537 
46538 --
46539 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
46540    trace
46541       (p_msg      => 'END of AcctLineType_98'
46542       ,p_level    => C_LEVEL_PROCEDURE
46543       ,p_module   => l_log_module);
46544 END IF;
46545 --
46546 EXCEPTION
46547   WHEN xla_exceptions_pkg.application_exception THEN
46548       RAISE;
46549   WHEN OTHERS THEN
46550        xla_exceptions_pkg.raise_message
46551            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_98');
46552 END AcctLineType_98;
46553 --
46554 
46555 ---------------------------------------
46556 --
46557 -- PRIVATE FUNCTION
46558 --         AcctLineType_99
46559 --
46560 ---------------------------------------
46561 PROCEDURE AcctLineType_99 (
46562   p_application_id        IN NUMBER
46563  ,p_event_id              IN NUMBER
46564  ,p_calculate_acctd_flag  IN VARCHAR2
46565  ,p_calculate_g_l_flag    IN VARCHAR2
46566  ,p_actual_flag           IN OUT VARCHAR2
46567  ,p_balance_type_code     OUT VARCHAR2
46568  ,p_gain_or_loss_ref      OUT VARCHAR2
46569  
46570 --Distribution Source Type
46571  , p_source_20            IN VARCHAR2
46572 --Distribution Line Identifier
46573  , p_source_22            IN NUMBER
46574 --Distribution Type
46575  , p_source_23            IN VARCHAR2
46576 --Entered Amount
46577  , p_source_24            IN NUMBER
46578 --Currency Code
46579  , p_source_25            IN VARCHAR2
46580 --Applied To Document Accounting Amount
46581  , p_source_29            IN NUMBER
46582 --Transaction Distribution Identifier
46583  , p_source_34            IN NUMBER
46584 --Transaction Distribution Type
46585  , p_source_35            IN VARCHAR2
46586 --Receipt Applied To Application Identifier
46587  , p_source_58            IN NUMBER
46588 --Transaction Entity Code
46589  , p_source_59            IN VARCHAR2
46590 --Transaction Identifier
46591  , p_source_60            IN NUMBER
46592 --Distribution Party Type
46593  , p_source_65            IN VARCHAR2
46594 --Distribution Multi Fund Additional Entry
46595  , p_source_69            IN VARCHAR2
46596 )
46597 IS
46598 
46599 l_component_type              VARCHAR2(80);
46600 l_component_code              VARCHAR2(30);
46601 l_component_type_code         VARCHAR2(1);
46602 l_component_appl_id           INTEGER;
46603 l_amb_context_code            VARCHAR2(30);
46604 l_entity_code                 VARCHAR2(30);
46605 l_event_class_code            VARCHAR2(30);
46606 l_ae_header_id                NUMBER;
46607 l_event_type_code             VARCHAR2(30);
46608 l_line_definition_code        VARCHAR2(30);
46609 l_line_definition_owner_code  VARCHAR2(1);
46610 --
46611 -- adr variables
46612 l_segment                     VARCHAR2(30);
46613 l_ccid                        NUMBER;
46614 l_adr_transaction_coa_id      NUMBER;
46615 l_adr_accounting_coa_id       NUMBER;
46616 l_adr_flexfield_segment_code  VARCHAR2(30);
46617 l_adr_flex_value_set_id       NUMBER;
46618 l_adr_value_type_code         VARCHAR2(30);
46619 l_adr_value_combination_id    NUMBER;
46620 l_adr_value_segment_code      VARCHAR2(30);
46621 
46622 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
46623 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
46624 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
46625 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
46626 
46627 -- 4262811 Variables ------------------------------------------------------------------------------------------
46628 l_entered_amt_idx             NUMBER;
46629 l_accted_amt_idx              NUMBER;
46630 l_acc_rev_flag                VARCHAR2(1);
46631 l_accrual_line_num            NUMBER;
46632 l_tmp_amt                     NUMBER;
46633 l_acc_rev_natural_side_code   VARCHAR2(1);
46634 
46635 l_num_entries                 NUMBER;
46636 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
46637 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
46638 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
46639 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
46640 l_recog_line_1                NUMBER;
46641 l_recog_line_2                NUMBER;
46642 
46643 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
46644 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
46645 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
46646 
46647 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
46648 
46652 ---------------------------------------------------------------------------------------------------------------
46649 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
46650 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
46651 
46653 
46654 
46655 --
46656 -- bulk performance
46657 --
46658 l_balance_type_code           VARCHAR2(1);
46659 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
46660 l_log_module                  VARCHAR2(240);
46661 
46662 --
46663 -- Upgrade strategy
46664 --
46665 l_actual_upg_option           VARCHAR2(1);
46666 l_enc_upg_option           VARCHAR2(1);
46667 
46668 --
46669 BEGIN
46670 --
46671 IF g_log_enabled THEN
46672       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_99';
46673 END IF;
46674 --
46675 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
46676 
46677       trace
46678          (p_msg      => 'BEGIN of AcctLineType_99'
46679          ,p_level    => C_LEVEL_PROCEDURE
46680          ,p_module   => l_log_module);
46681 
46682 END IF;
46683 --
46684 l_component_type             := 'AMB_JLT';
46685 l_component_code             := 'MFAR_RCT_EDISC_REC';
46686 l_component_type_code        := 'S';
46687 l_component_appl_id          :=  222;
46688 l_amb_context_code           := 'DEFAULT';
46689 l_entity_code                := 'RECEIPTS';
46690 l_event_class_code           := 'RECEIPT';
46691 l_event_type_code            := 'RECEIPT_ALL';
46692 l_line_definition_owner_code := 'S';
46693 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
46694 --
46695 l_balance_type_code          := 'A';
46696 l_segment                     := NULL;
46697 l_ccid                        := NULL;
46698 l_adr_transaction_coa_id      := NULL;
46699 l_adr_accounting_coa_id       := NULL;
46700 l_adr_flexfield_segment_code  := NULL;
46701 l_adr_flex_value_set_id       := NULL;
46702 l_adr_value_type_code         := NULL;
46703 l_adr_value_combination_id    := NULL;
46704 l_adr_value_segment_code      := NULL;
46705 
46706 l_bflow_method_code          := 'PRIOR_ENTRY';   -- 4219869 Business Flow
46707 l_bflow_class_code           := 'RECEIVABLE';    -- 4219869 Business Flow
46708 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
46709 l_budgetary_control_flag     := 'N';
46710 
46711 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
46712 l_bflow_applied_to_amt       := NULL; -- 5132302
46713 l_entered_amt_idx            := NULL;          -- 4262811
46714 l_accted_amt_idx             := NULL;          -- 4262811
46715 l_acc_rev_flag               := NULL;          -- 4262811
46716 l_accrual_line_num           := NULL;          -- 4262811
46717 l_tmp_amt                    := NULL;          -- 4262811
46718 --
46719  
46720 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
46721     l_balance_type_code <> 'B' THEN
46722 IF NVL(p_source_20,'
46723 ') =  'EDISC' AND 
46724 NVL(p_source_69,'
46725 ') =  'N'
46726  THEN 
46727 
46728    --
46729    XLA_AE_LINES_PKG.SetNewLine;
46730 
46731    p_balance_type_code          := l_balance_type_code;
46732    -- set the flag so later we will know whether the gain loss line needs to be created
46733    
46734    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
46735      p_actual_flag :='A';
46736    END IF;
46737 
46738    --
46739    -- bulk performance
46740    --
46741    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
46742                                       p_header_num   => 0); -- 4262811
46743    --
46744    -- set accounting line options
46745    --
46746    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
46747            p_natural_side_code          => 'D'
46748          , p_gain_or_loss_flag          => 'N'
46749          , p_gl_transfer_mode_code      => 'S'
46750          , p_acct_entry_type_code       => 'A'
46751          , p_switch_side_flag           => 'Y'
46752          , p_merge_duplicate_code       => 'A'
46753          );
46754    --
46755    l_acc_rev_natural_side_code := 'C';  -- 4262811
46756    -- 
46757    --
46758    -- set accounting line type info
46759    --
46760    xla_ae_lines_pkg.SetAcctLineType
46761       (p_component_type             => l_component_type
46762       ,p_event_type_code            => l_event_type_code
46763       ,p_line_definition_owner_code => l_line_definition_owner_code
46764       ,p_line_definition_code       => l_line_definition_code
46765       ,p_accounting_line_code       => l_component_code
46766       ,p_accounting_line_type_code  => l_component_type_code
46767       ,p_accounting_line_appl_id    => l_component_appl_id
46768       ,p_amb_context_code           => l_amb_context_code
46769       ,p_entity_code                => l_entity_code
46770       ,p_event_class_code           => l_event_class_code);
46771    --
46772    -- set accounting class
46773    --
46774    xla_ae_lines_pkg.SetAcctClass(
46775            p_accounting_class_code  => 'RECEIVABLE'
46776          , p_ae_header_id           => l_ae_header_id
46777          );
46778 
46779    --
46780    -- set rounding class
46781    --
46782    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
46783                       'RECEIVABLE';
46784 
46785    --
46789    -- bulk performance
46786    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
46787    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
46788    --
46790    --
46791    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
46792 
46793    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
46794       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
46795 
46796    -- 4955764
46797    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
46798       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
46799 
46800    -- 4458381 Public Sector Enh
46801    
46802    --
46803    -- set accounting attributes for the line type
46804    --
46805    l_entered_amt_idx := 8;
46806    l_accted_amt_idx  := 10;
46807    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
46808    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
46809    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
46810    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
46811    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
46812    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
46813    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
46814    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
46815    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
46816    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
46817    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
46818    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
46819    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
46820    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
46821    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
46822    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
46823    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
46824    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
46825    l_rec_acct_attrs.array_char_value(9)  := p_source_25;
46826    l_rec_acct_attrs.array_acct_attr_code(10) := 'LEDGER_AMOUNT';
46827    l_rec_acct_attrs.array_num_value(10)  := p_source_29;
46828    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
46829    l_rec_acct_attrs.array_char_value(11)  := p_source_65;
46830 
46831    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
46832    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
46833 
46834    ---------------------------------------------------------------------------------------------------------------
46835    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
46836    ---------------------------------------------------------------------------------------------------------------
46837    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
46838 
46839    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
46840    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
46841 
46842    IF xla_accounting_cache_pkg.GetValueChar
46843          (p_source_code         => 'LEDGER_CATEGORY_CODE'
46844          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
46845    AND l_bflow_method_code = 'PRIOR_ENTRY'
46846 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
46847    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
46848          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
46849        )
46850    THEN
46851          xla_ae_lines_pkg.BflowUpgEntry
46852            (p_business_method_code    => l_bflow_method_code
46853            ,p_business_class_code     => l_bflow_class_code
46854            ,p_balance_type            => l_balance_type_code);
46855    ELSE
46856       NULL;
46857 XLA_AE_LINES_PKG.business_flow_validation(
46858                                 p_business_method_code     => l_bflow_method_code
46859                                ,p_business_class_code      => l_bflow_class_code
46860                                ,p_inherit_description_flag => l_inherit_desc_flag);
46861    END IF;
46862 
46863    --
46864    -- call analytical criteria
46865    --
46866    -- Inherited Analytical Criteria for business flow method of Prior Entry.
46867    --
46868    -- call description
46869    --
46870    
46871 xla_ae_lines_pkg.SetLineDescription(
46872    p_ae_header_id => l_ae_header_id
46873   ,p_description  => Description_1 (
46874      p_application_id         => p_application_id
46875    , p_ae_header_id           => l_ae_header_id 
46876    )
46877 );
46878 
46879 
46880    --
46881    -- call ADRs
46882    -- Bug 4922099
46883    --
46884    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
46885         (NVL(l_actual_upg_option, 'N') = 'O') OR
46886         (NVL(l_enc_upg_option, 'N') = 'O')
46887       )
46888    THEN
46889    NULL;
46890    --
46891    --
46892    
46893    --
46894    --
46895    END IF;
46896    --
46897    -- Bug 4922099
46898    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
46902       )
46899           (NVL(l_enc_upg_option, 'N') = 'O')
46900         ) AND
46901         (l_bflow_method_code = 'PRIOR_ENTRY')
46903    THEN
46904       IF
46905       --
46906       1 = 1
46907       --
46908       THEN
46909       xla_accounting_err_pkg.build_message
46910                                     (p_appli_s_name            => 'XLA'
46911                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
46912                                     ,p_token_1                 => 'LINE_NUMBER'
46913                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
46914                                     ,p_token_2                 => 'LINE_TYPE_NAME'
46915                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
46916                                                                              l_component_type
46917                                                                             ,l_component_code
46918                                                                             ,l_component_type_code
46919                                                                             ,l_component_appl_id
46920                                                                             ,l_amb_context_code
46921                                                                             ,l_entity_code
46922                                                                             ,l_event_class_code
46923                                                                            )
46924                                     ,p_token_3                 => 'OWNER'
46925                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
46926                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
46927                                                                           ,p_lookup_code    => l_component_type_code
46928                                                                          )
46929                                     ,p_token_4                 => 'PRODUCT_NAME'
46930                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
46931                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
46932                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
46933                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
46934                                     ,p_ae_header_id            =>  NULL
46935                                        );
46936 
46937         IF (C_LEVEL_ERROR>= g_log_level) THEN
46938                  trace
46939                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
46940                       ,p_level    => C_LEVEL_ERROR
46941                       ,p_module   => l_log_module);
46942         END IF;
46943       END IF;
46944    END IF;
46945    --
46946    --
46947    ------------------------------------------------------------------------------------------------
46948    -- 4219869 Business Flow
46949    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
46950    -- Prior Entry.  Currently, the following code is always generated.
46951    ------------------------------------------------------------------------------------------------
46952    -- No ValidateCurrentLine for business flow method of Prior Entry
46953 
46954    ------------------------------------------------------------------------------------
46955    -- 4219869 Business Flow
46956    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
46957    ------------------------------------------------------------------------------------
46958    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
46959 
46960    ----------------------------------------------------------------------------------
46961    -- 4219869 Business Flow
46962    -- Update journal entry status -- Need to generate this within IF <condition>
46963    ----------------------------------------------------------------------------------
46964    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
46965          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
46966          ,p_balance_type_code => l_balance_type_code
46967          );
46968 
46969    -------------------------------------------------------------------------------------------
46970    -- 4262811 - Generate the Accrual Reversal lines
46971    -------------------------------------------------------------------------------------------
46972    BEGIN
46973       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
46974                               (g_array_event(p_event_id).array_value_num('header_index'));
46975       IF l_acc_rev_flag IS NULL THEN
46976          l_acc_rev_flag := 'N';
46977       END IF;
46978    EXCEPTION
46979       WHEN OTHERS THEN
46980          l_acc_rev_flag := 'N';
46981    END;
46982    --
46983    IF (l_acc_rev_flag = 'Y') THEN
46984 
46985        -- 4645092  ------------------------------------------------------------------------------
46986        -- To allow MPA report to determine if it should generate report process
46987        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
46988        ------------------------------------------------------------------------------------------
46989 
46990        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
46991        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
46995    --
46992    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
46993    -- call ADRs
46994    -- Bug 4922099
46996    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
46997         (NVL(l_actual_upg_option, 'N') = 'O') OR
46998         (NVL(l_enc_upg_option, 'N') = 'O')
46999       )
47000    THEN
47001    NULL;
47002    --
47003    --
47004    
47005    --
47006    --
47007    END IF;
47008 
47009        --
47010        -- Update the line information that should be overwritten
47011        --
47012        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
47013                                          p_header_num   => 1);
47014        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
47015 
47016        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
47017 
47018        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
47019           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
47020        END IF;
47021 
47022       --
47023       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
47024       --
47025       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
47026           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
47027       ELSE
47028           ---------------------------------------------------------------------------------------------------
47029           -- 4262811a Switch Sign
47030           ---------------------------------------------------------------------------------------------------
47031           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
47032           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
47033                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
47034           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
47035                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
47036           -- 5132302
47037           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
47038                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
47039 
47040       END IF;
47041 
47042       -- 4955764
47043       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
47044       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
47045 
47046 
47047       XLA_AE_LINES_PKG.ValidateCurrentLine;
47048       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
47049 
47050       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
47051                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
47052                ,p_balance_type_code => l_balance_type_code);
47053 
47054    END IF;
47055 
47056    -----------------------------------------------------------------------------------------
47057    -- 4262811 Multiperiod Accounting
47058    -----------------------------------------------------------------------------------------
47059      -- No MPA option is assigned.
47060 
47061 
47062 END IF;
47063 END IF;
47064 --
47065 
47066 --
47067 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
47068    trace
47069       (p_msg      => 'END of AcctLineType_99'
47070       ,p_level    => C_LEVEL_PROCEDURE
47071       ,p_module   => l_log_module);
47072 END IF;
47073 --
47074 EXCEPTION
47075   WHEN xla_exceptions_pkg.application_exception THEN
47076       RAISE;
47077   WHEN OTHERS THEN
47078        xla_exceptions_pkg.raise_message
47079            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_99');
47080 END AcctLineType_99;
47081 --
47082 
47083 ---------------------------------------
47084 --
47085 -- PRIVATE FUNCTION
47086 --         AcctLineType_100
47087 --
47088 ---------------------------------------
47089 PROCEDURE AcctLineType_100 (
47090   p_application_id        IN NUMBER
47091  ,p_event_id              IN NUMBER
47092  ,p_calculate_acctd_flag  IN VARCHAR2
47093  ,p_calculate_g_l_flag    IN VARCHAR2
47094  ,p_actual_flag           IN OUT VARCHAR2
47095  ,p_balance_type_code     OUT VARCHAR2
47096  ,p_gain_or_loss_ref      OUT VARCHAR2
47097  
47098 --Remittance Bank Account Remittance Account
47099  , p_source_15            IN NUMBER
47100 --Distribution Source Type
47101  , p_source_20            IN VARCHAR2
47102 --Distribution Line Identifier
47103  , p_source_22            IN NUMBER
47104 --Distribution Type
47105  , p_source_23            IN VARCHAR2
47106 --Exchange Date
47107  , p_source_26            IN DATE
47108 --Exchange Rate
47109  , p_source_27            IN NUMBER
47110 --Exchange Rate Type
47111  , p_source_28            IN VARCHAR2
47112 --Transaction Distribution Identifier
47113  , p_source_34            IN NUMBER
47114 --Transaction Distribution Type
47115  , p_source_35            IN VARCHAR2
47116 --Receipt Applied To Application Identifier
47117  , p_source_58            IN NUMBER
47118 --Transaction Entity Code
47119  , p_source_59            IN VARCHAR2
47123  , p_source_61            IN VARCHAR2
47120 --Transaction Identifier
47121  , p_source_60            IN NUMBER
47122 --Applying Document Currency Code
47124 --Distribution Party Identifier
47125  , p_source_63            IN NUMBER
47126 --Distribution Party Site Id
47127  , p_source_64            IN NUMBER
47128 --Distribution Party Type
47129  , p_source_65            IN VARCHAR2
47130 --Distribution Multi Fund Additional Entry
47131  , p_source_69            IN VARCHAR2
47132 --DIST_ENT_AMT_FROM
47133  , p_source_72            IN NUMBER
47134 --Accounting Amount
47135  , p_source_73            IN NUMBER
47136 )
47137 IS
47138 
47139 l_component_type              VARCHAR2(80);
47140 l_component_code              VARCHAR2(30);
47141 l_component_type_code         VARCHAR2(1);
47142 l_component_appl_id           INTEGER;
47143 l_amb_context_code            VARCHAR2(30);
47144 l_entity_code                 VARCHAR2(30);
47145 l_event_class_code            VARCHAR2(30);
47146 l_ae_header_id                NUMBER;
47147 l_event_type_code             VARCHAR2(30);
47148 l_line_definition_code        VARCHAR2(30);
47149 l_line_definition_owner_code  VARCHAR2(1);
47150 --
47151 -- adr variables
47152 l_segment                     VARCHAR2(30);
47153 l_ccid                        NUMBER;
47154 l_adr_transaction_coa_id      NUMBER;
47155 l_adr_accounting_coa_id       NUMBER;
47156 l_adr_flexfield_segment_code  VARCHAR2(30);
47157 l_adr_flex_value_set_id       NUMBER;
47158 l_adr_value_type_code         VARCHAR2(30);
47159 l_adr_value_combination_id    NUMBER;
47160 l_adr_value_segment_code      VARCHAR2(30);
47161 
47162 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
47163 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
47164 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
47165 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
47166 
47167 -- 4262811 Variables ------------------------------------------------------------------------------------------
47168 l_entered_amt_idx             NUMBER;
47169 l_accted_amt_idx              NUMBER;
47170 l_acc_rev_flag                VARCHAR2(1);
47171 l_accrual_line_num            NUMBER;
47172 l_tmp_amt                     NUMBER;
47173 l_acc_rev_natural_side_code   VARCHAR2(1);
47174 
47175 l_num_entries                 NUMBER;
47176 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
47177 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
47178 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
47179 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
47180 l_recog_line_1                NUMBER;
47181 l_recog_line_2                NUMBER;
47182 
47183 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
47184 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
47185 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
47186 
47187 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
47188 
47189 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
47190 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
47191 
47192 ---------------------------------------------------------------------------------------------------------------
47193 
47194 
47195 --
47196 -- bulk performance
47197 --
47198 l_balance_type_code           VARCHAR2(1);
47199 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
47200 l_log_module                  VARCHAR2(240);
47201 
47202 --
47203 -- Upgrade strategy
47204 --
47205 l_actual_upg_option           VARCHAR2(1);
47206 l_enc_upg_option           VARCHAR2(1);
47207 
47208 --
47209 BEGIN
47210 --
47211 IF g_log_enabled THEN
47212       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_100';
47213 END IF;
47214 --
47215 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
47216 
47217       trace
47218          (p_msg      => 'BEGIN of AcctLineType_100'
47219          ,p_level    => C_LEVEL_PROCEDURE
47220          ,p_module   => l_log_module);
47221 
47222 END IF;
47223 --
47224 l_component_type             := 'AMB_JLT';
47225 l_component_code             := 'MFAR_RCT_REMIT_REVERSAL';
47226 l_component_type_code        := 'S';
47227 l_component_appl_id          :=  222;
47228 l_amb_context_code           := 'DEFAULT';
47229 l_entity_code                := 'RECEIPTS';
47230 l_event_class_code           := 'RECEIPT';
47231 l_event_type_code            := 'RECEIPT_ALL';
47232 l_line_definition_owner_code := 'S';
47233 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
47234 --
47235 l_balance_type_code          := 'A';
47236 l_segment                     := NULL;
47237 l_ccid                        := NULL;
47238 l_adr_transaction_coa_id      := NULL;
47239 l_adr_accounting_coa_id       := NULL;
47240 l_adr_flexfield_segment_code  := NULL;
47241 l_adr_flex_value_set_id       := NULL;
47242 l_adr_value_type_code         := NULL;
47243 l_adr_value_combination_id    := NULL;
47244 l_adr_value_segment_code      := NULL;
47245 
47246 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
47247 l_bflow_class_code           := '';    -- 4219869 Business Flow
47248 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
47249 l_budgetary_control_flag     := 'N';
47250 
47254 l_accted_amt_idx             := NULL;          -- 4262811
47251 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
47252 l_bflow_applied_to_amt       := NULL; -- 5132302
47253 l_entered_amt_idx            := NULL;          -- 4262811
47255 l_acc_rev_flag               := NULL;          -- 4262811
47256 l_accrual_line_num           := NULL;          -- 4262811
47257 l_tmp_amt                    := NULL;          -- 4262811
47258 --
47259  
47260 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
47261     l_balance_type_code <> 'B' THEN
47262 IF NVL(p_source_20,'
47263 ') =  'REMITTANCE' AND 
47264 NVL(p_source_69,'
47265 ') =  'Y'
47266  THEN 
47267 
47268    --
47269    XLA_AE_LINES_PKG.SetNewLine;
47270 
47271    p_balance_type_code          := l_balance_type_code;
47272    -- set the flag so later we will know whether the gain loss line needs to be created
47273    
47274    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
47275      p_actual_flag :='A';
47276    END IF;
47277 
47278    --
47279    -- bulk performance
47280    --
47281    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
47282                                       p_header_num   => 0); -- 4262811
47283    --
47284    -- set accounting line options
47285    --
47286    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
47287            p_natural_side_code          => 'D'
47288          , p_gain_or_loss_flag          => 'N'
47289          , p_gl_transfer_mode_code      => 'S'
47290          , p_acct_entry_type_code       => 'A'
47291          , p_switch_side_flag           => 'Y'
47292          , p_merge_duplicate_code       => 'A'
47293          );
47294    --
47295    l_acc_rev_natural_side_code := 'C';  -- 4262811
47296    -- 
47297    --
47298    -- set accounting line type info
47299    --
47300    xla_ae_lines_pkg.SetAcctLineType
47301       (p_component_type             => l_component_type
47302       ,p_event_type_code            => l_event_type_code
47303       ,p_line_definition_owner_code => l_line_definition_owner_code
47304       ,p_line_definition_code       => l_line_definition_code
47305       ,p_accounting_line_code       => l_component_code
47306       ,p_accounting_line_type_code  => l_component_type_code
47307       ,p_accounting_line_appl_id    => l_component_appl_id
47308       ,p_amb_context_code           => l_amb_context_code
47309       ,p_entity_code                => l_entity_code
47310       ,p_event_class_code           => l_event_class_code);
47311    --
47312    -- set accounting class
47313    --
47314    xla_ae_lines_pkg.SetAcctClass(
47315            p_accounting_class_code  => 'REMITTANCE'
47316          , p_ae_header_id           => l_ae_header_id
47317          );
47318 
47319    --
47320    -- set rounding class
47321    --
47322    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
47323                       'RECEIVABLE';
47324 
47325    --
47326    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
47327    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
47328    --
47329    -- bulk performance
47330    --
47331    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
47332 
47333    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
47334       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
47335 
47336    -- 4955764
47337    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
47338       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
47339 
47340    -- 4458381 Public Sector Enh
47341    
47342    --
47343    -- set accounting attributes for the line type
47344    --
47345    l_entered_amt_idx := 8;
47346    l_accted_amt_idx  := 13;
47347    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
47348    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
47349    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
47350    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
47351    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
47352    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
47353    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
47354    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
47355    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
47356    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
47357    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
47358    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
47359    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
47360    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
47361    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
47362    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
47363    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
47364    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
47365    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
47366    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
47370    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
47367    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
47368    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
47369    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
47371    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
47372    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
47373    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
47374    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
47375    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
47376    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
47377    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
47378    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
47379    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
47380 
47381    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
47382    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
47383 
47384    ---------------------------------------------------------------------------------------------------------------
47385    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
47386    ---------------------------------------------------------------------------------------------------------------
47387    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
47388 
47389    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
47390    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
47391 
47392    IF xla_accounting_cache_pkg.GetValueChar
47393          (p_source_code         => 'LEDGER_CATEGORY_CODE'
47394          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
47395    AND l_bflow_method_code = 'PRIOR_ENTRY'
47396 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
47397    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
47398          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
47399        )
47400    THEN
47401          xla_ae_lines_pkg.BflowUpgEntry
47402            (p_business_method_code    => l_bflow_method_code
47403            ,p_business_class_code     => l_bflow_class_code
47404            ,p_balance_type            => l_balance_type_code);
47405    ELSE
47406       NULL;
47407 -- No business flow processing for business flow method of NONE.
47408    END IF;
47409 
47410    --
47411    -- call analytical criteria
47412    --
47413    
47414    --
47415    -- call description
47416    --
47417    
47418 xla_ae_lines_pkg.SetLineDescription(
47419    p_ae_header_id => l_ae_header_id
47420   ,p_description  => Description_1 (
47421      p_application_id         => p_application_id
47422    , p_ae_header_id           => l_ae_header_id 
47423    )
47424 );
47425 
47426 
47427    --
47428    -- call ADRs
47429    -- Bug 4922099
47430    --
47431    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
47432         (NVL(l_actual_upg_option, 'N') = 'O') OR
47433         (NVL(l_enc_upg_option, 'N') = 'O')
47434       )
47435    THEN
47436    NULL;
47437    --
47438    --
47439    
47440   l_ccid := AcctDerRule_27(
47441            p_application_id           => p_application_id
47442          , p_ae_header_id             => l_ae_header_id 
47443 , p_source_15 => p_source_15
47444          , x_transaction_coa_id       => l_adr_transaction_coa_id
47445          , x_accounting_coa_id        => l_adr_accounting_coa_id
47446          , x_value_type_code          => l_adr_value_type_code
47447          , p_side                     => 'NA'
47448    );
47449 
47450    xla_ae_lines_pkg.set_ccid(
47451     p_code_combination_id          => l_ccid
47452   , p_value_type_code              => l_adr_value_type_code
47453   , p_transaction_coa_id           => l_adr_transaction_coa_id
47454   , p_accounting_coa_id            => l_adr_accounting_coa_id
47455   , p_adr_code                     => 'MFAR_RCT_DEF_REMITTANCE_CCID'
47456   , p_adr_type_code                => 'S'
47457   , p_component_type               => l_component_type
47458   , p_component_code               => l_component_code
47459   , p_component_type_code          => l_component_type_code
47460   , p_component_appl_id            => l_component_appl_id
47461   , p_amb_context_code             => l_amb_context_code
47462   , p_side                         => 'NA'
47463   );
47464 
47465 
47466    --
47467    --
47468    END IF;
47469    --
47470    -- Bug 4922099
47471    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
47472           (NVL(l_enc_upg_option, 'N') = 'O')
47473         ) AND
47474         (l_bflow_method_code = 'PRIOR_ENTRY')
47475       )
47476    THEN
47477       IF
47478       --
47479       1 = 2
47480       --
47481       THEN
47482       xla_accounting_err_pkg.build_message
47483                                     (p_appli_s_name            => 'XLA'
47484                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
47485                                     ,p_token_1                 => 'LINE_NUMBER'
47486                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
47490                                                                             ,l_component_code
47487                                     ,p_token_2                 => 'LINE_TYPE_NAME'
47488                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
47489                                                                              l_component_type
47491                                                                             ,l_component_type_code
47492                                                                             ,l_component_appl_id
47493                                                                             ,l_amb_context_code
47494                                                                             ,l_entity_code
47495                                                                             ,l_event_class_code
47496                                                                            )
47497                                     ,p_token_3                 => 'OWNER'
47498                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
47499                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
47500                                                                           ,p_lookup_code    => l_component_type_code
47501                                                                          )
47502                                     ,p_token_4                 => 'PRODUCT_NAME'
47503                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
47504                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
47505                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
47506                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
47507                                     ,p_ae_header_id            =>  NULL
47508                                        );
47509 
47510         IF (C_LEVEL_ERROR>= g_log_level) THEN
47511                  trace
47512                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
47513                       ,p_level    => C_LEVEL_ERROR
47514                       ,p_module   => l_log_module);
47515         END IF;
47516       END IF;
47517    END IF;
47518    --
47519    --
47520    ------------------------------------------------------------------------------------------------
47521    -- 4219869 Business Flow
47522    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
47523    -- Prior Entry.  Currently, the following code is always generated.
47524    ------------------------------------------------------------------------------------------------
47525    XLA_AE_LINES_PKG.ValidateCurrentLine;
47526 
47527    ------------------------------------------------------------------------------------
47528    -- 4219869 Business Flow
47529    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
47530    ------------------------------------------------------------------------------------
47531    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
47532 
47533    ----------------------------------------------------------------------------------
47534    -- 4219869 Business Flow
47535    -- Update journal entry status -- Need to generate this within IF <condition>
47536    ----------------------------------------------------------------------------------
47537    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
47538          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
47539          ,p_balance_type_code => l_balance_type_code
47540          );
47541 
47542    -------------------------------------------------------------------------------------------
47543    -- 4262811 - Generate the Accrual Reversal lines
47544    -------------------------------------------------------------------------------------------
47545    BEGIN
47546       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
47547                               (g_array_event(p_event_id).array_value_num('header_index'));
47548       IF l_acc_rev_flag IS NULL THEN
47549          l_acc_rev_flag := 'N';
47550       END IF;
47551    EXCEPTION
47552       WHEN OTHERS THEN
47553          l_acc_rev_flag := 'N';
47554    END;
47555    --
47556    IF (l_acc_rev_flag = 'Y') THEN
47557 
47558        -- 4645092  ------------------------------------------------------------------------------
47559        -- To allow MPA report to determine if it should generate report process
47560        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
47561        ------------------------------------------------------------------------------------------
47562 
47563        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
47564        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
47565    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
47566    -- call ADRs
47567    -- Bug 4922099
47568    --
47569    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
47570         (NVL(l_actual_upg_option, 'N') = 'O') OR
47571         (NVL(l_enc_upg_option, 'N') = 'O')
47572       )
47573    THEN
47574    NULL;
47575    --
47576    --
47577    
47578   l_ccid := AcctDerRule_27(
47579            p_application_id           => p_application_id
47580          , p_ae_header_id             => l_ae_header_id 
47581 , p_source_15 => p_source_15
47582          , x_transaction_coa_id       => l_adr_transaction_coa_id
47586    );
47583          , x_accounting_coa_id        => l_adr_accounting_coa_id
47584          , x_value_type_code          => l_adr_value_type_code
47585          , p_side                     => 'NA'
47587 
47588    xla_ae_lines_pkg.set_ccid(
47589     p_code_combination_id          => l_ccid
47590   , p_value_type_code              => l_adr_value_type_code
47591   , p_transaction_coa_id           => l_adr_transaction_coa_id
47592   , p_accounting_coa_id            => l_adr_accounting_coa_id
47593   , p_adr_code                     => 'MFAR_RCT_DEF_REMITTANCE_CCID'
47594   , p_adr_type_code                => 'S'
47595   , p_component_type               => l_component_type
47596   , p_component_code               => l_component_code
47597   , p_component_type_code          => l_component_type_code
47598   , p_component_appl_id            => l_component_appl_id
47599   , p_amb_context_code             => l_amb_context_code
47600   , p_side                         => 'NA'
47601   );
47602 
47603 
47604    --
47605    --
47606    END IF;
47607 
47608        --
47609        -- Update the line information that should be overwritten
47610        --
47611        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
47612                                          p_header_num   => 1);
47613        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
47614 
47615        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
47616 
47617        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
47618           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
47619        END IF;
47620 
47621       --
47622       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
47623       --
47624       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
47625           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
47626       ELSE
47627           ---------------------------------------------------------------------------------------------------
47628           -- 4262811a Switch Sign
47629           ---------------------------------------------------------------------------------------------------
47630           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
47631           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
47632                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
47633           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
47634                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
47635           -- 5132302
47636           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
47637                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
47638 
47639       END IF;
47640 
47641       -- 4955764
47642       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
47643       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
47644 
47645 
47646       XLA_AE_LINES_PKG.ValidateCurrentLine;
47647       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
47648 
47649       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
47650                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
47651                ,p_balance_type_code => l_balance_type_code);
47652 
47653    END IF;
47654 
47655    -----------------------------------------------------------------------------------------
47656    -- 4262811 Multiperiod Accounting
47657    -----------------------------------------------------------------------------------------
47658      -- No MPA option is assigned.
47659 
47660 
47661 END IF;
47662 END IF;
47663 --
47664 
47665 --
47666 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
47667    trace
47668       (p_msg      => 'END of AcctLineType_100'
47669       ,p_level    => C_LEVEL_PROCEDURE
47670       ,p_module   => l_log_module);
47671 END IF;
47672 --
47673 EXCEPTION
47674   WHEN xla_exceptions_pkg.application_exception THEN
47675       RAISE;
47676   WHEN OTHERS THEN
47677        xla_exceptions_pkg.raise_message
47678            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_100');
47679 END AcctLineType_100;
47680 --
47681 
47682 ---------------------------------------
47683 --
47684 -- PRIVATE FUNCTION
47685 --         AcctLineType_101
47686 --
47687 ---------------------------------------
47688 PROCEDURE AcctLineType_101 (
47689   p_application_id        IN NUMBER
47690  ,p_event_id              IN NUMBER
47691  ,p_calculate_acctd_flag  IN VARCHAR2
47692  ,p_calculate_g_l_flag    IN VARCHAR2
47693  ,p_actual_flag           IN OUT VARCHAR2
47694  ,p_balance_type_code     OUT VARCHAR2
47695  ,p_gain_or_loss_ref      OUT VARCHAR2
47696  
47697 --Distribution Source Type
47698  , p_source_20            IN VARCHAR2
47699 --Distribution Line Identifier
47700  , p_source_22            IN NUMBER
47701 --Distribution Type
47702  , p_source_23            IN VARCHAR2
47703 --Entered Amount
47704  , p_source_24            IN NUMBER
47705 --Currency Code
47709 --Transaction Distribution Identifier
47706  , p_source_25            IN VARCHAR2
47707 --Applied To Document Accounting Amount
47708  , p_source_29            IN NUMBER
47710  , p_source_34            IN NUMBER
47711 --Transaction Distribution Type
47712  , p_source_35            IN VARCHAR2
47713 --Receipt Applied To Application Identifier
47714  , p_source_58            IN NUMBER
47715 --Transaction Entity Code
47716  , p_source_59            IN VARCHAR2
47717 --Transaction Identifier
47718  , p_source_60            IN NUMBER
47719 --Distribution Party Type
47720  , p_source_65            IN VARCHAR2
47721 --Distribution Multi Fund Additional Entry
47722  , p_source_69            IN VARCHAR2
47723 )
47724 IS
47725 
47726 l_component_type              VARCHAR2(80);
47727 l_component_code              VARCHAR2(30);
47728 l_component_type_code         VARCHAR2(1);
47729 l_component_appl_id           INTEGER;
47730 l_amb_context_code            VARCHAR2(30);
47731 l_entity_code                 VARCHAR2(30);
47732 l_event_class_code            VARCHAR2(30);
47733 l_ae_header_id                NUMBER;
47734 l_event_type_code             VARCHAR2(30);
47735 l_line_definition_code        VARCHAR2(30);
47736 l_line_definition_owner_code  VARCHAR2(1);
47737 --
47738 -- adr variables
47739 l_segment                     VARCHAR2(30);
47740 l_ccid                        NUMBER;
47741 l_adr_transaction_coa_id      NUMBER;
47742 l_adr_accounting_coa_id       NUMBER;
47743 l_adr_flexfield_segment_code  VARCHAR2(30);
47744 l_adr_flex_value_set_id       NUMBER;
47745 l_adr_value_type_code         VARCHAR2(30);
47746 l_adr_value_combination_id    NUMBER;
47747 l_adr_value_segment_code      VARCHAR2(30);
47748 
47749 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
47750 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
47751 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
47752 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
47753 
47754 -- 4262811 Variables ------------------------------------------------------------------------------------------
47755 l_entered_amt_idx             NUMBER;
47756 l_accted_amt_idx              NUMBER;
47757 l_acc_rev_flag                VARCHAR2(1);
47758 l_accrual_line_num            NUMBER;
47759 l_tmp_amt                     NUMBER;
47760 l_acc_rev_natural_side_code   VARCHAR2(1);
47761 
47762 l_num_entries                 NUMBER;
47763 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
47764 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
47765 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
47766 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
47767 l_recog_line_1                NUMBER;
47768 l_recog_line_2                NUMBER;
47769 
47770 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
47771 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
47772 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
47773 
47774 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
47775 
47776 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
47777 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
47778 
47779 ---------------------------------------------------------------------------------------------------------------
47780 
47781 
47782 --
47783 -- bulk performance
47784 --
47785 l_balance_type_code           VARCHAR2(1);
47786 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
47787 l_log_module                  VARCHAR2(240);
47788 
47789 --
47790 -- Upgrade strategy
47791 --
47792 l_actual_upg_option           VARCHAR2(1);
47793 l_enc_upg_option           VARCHAR2(1);
47794 
47795 --
47796 BEGIN
47797 --
47798 IF g_log_enabled THEN
47799       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_101';
47800 END IF;
47801 --
47802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
47803 
47804       trace
47805          (p_msg      => 'BEGIN of AcctLineType_101'
47806          ,p_level    => C_LEVEL_PROCEDURE
47807          ,p_module   => l_log_module);
47808 
47809 END IF;
47810 --
47811 l_component_type             := 'AMB_JLT';
47812 l_component_code             := 'MFAR_RCT_UNDISC_REC';
47813 l_component_type_code        := 'S';
47814 l_component_appl_id          :=  222;
47815 l_amb_context_code           := 'DEFAULT';
47816 l_entity_code                := 'RECEIPTS';
47817 l_event_class_code           := 'RECEIPT';
47818 l_event_type_code            := 'RECEIPT_ALL';
47819 l_line_definition_owner_code := 'S';
47820 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
47821 --
47822 l_balance_type_code          := 'A';
47823 l_segment                     := NULL;
47824 l_ccid                        := NULL;
47825 l_adr_transaction_coa_id      := NULL;
47826 l_adr_accounting_coa_id       := NULL;
47827 l_adr_flexfield_segment_code  := NULL;
47828 l_adr_flex_value_set_id       := NULL;
47829 l_adr_value_type_code         := NULL;
47830 l_adr_value_combination_id    := NULL;
47831 l_adr_value_segment_code      := NULL;
47832 
47833 l_bflow_method_code          := 'PRIOR_ENTRY';   -- 4219869 Business Flow
47834 l_bflow_class_code           := 'RECEIVABLE';    -- 4219869 Business Flow
47838 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
47835 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
47836 l_budgetary_control_flag     := 'N';
47837 
47839 l_bflow_applied_to_amt       := NULL; -- 5132302
47840 l_entered_amt_idx            := NULL;          -- 4262811
47841 l_accted_amt_idx             := NULL;          -- 4262811
47842 l_acc_rev_flag               := NULL;          -- 4262811
47843 l_accrual_line_num           := NULL;          -- 4262811
47844 l_tmp_amt                    := NULL;          -- 4262811
47845 --
47846  
47847 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
47848     l_balance_type_code <> 'B' THEN
47849 IF NVL(p_source_20,'
47850 ') =  'UNEDISC' AND 
47851 NVL(p_source_69,'
47852 ') =  'N'
47853  THEN 
47854 
47855    --
47856    XLA_AE_LINES_PKG.SetNewLine;
47857 
47858    p_balance_type_code          := l_balance_type_code;
47859    -- set the flag so later we will know whether the gain loss line needs to be created
47860    
47861    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
47862      p_actual_flag :='A';
47863    END IF;
47864 
47865    --
47866    -- bulk performance
47867    --
47868    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
47869                                       p_header_num   => 0); -- 4262811
47870    --
47871    -- set accounting line options
47872    --
47873    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
47874            p_natural_side_code          => 'D'
47875          , p_gain_or_loss_flag          => 'N'
47876          , p_gl_transfer_mode_code      => 'S'
47877          , p_acct_entry_type_code       => 'A'
47878          , p_switch_side_flag           => 'Y'
47879          , p_merge_duplicate_code       => 'A'
47880          );
47881    --
47882    l_acc_rev_natural_side_code := 'C';  -- 4262811
47883    -- 
47884    --
47885    -- set accounting line type info
47886    --
47887    xla_ae_lines_pkg.SetAcctLineType
47888       (p_component_type             => l_component_type
47889       ,p_event_type_code            => l_event_type_code
47890       ,p_line_definition_owner_code => l_line_definition_owner_code
47891       ,p_line_definition_code       => l_line_definition_code
47892       ,p_accounting_line_code       => l_component_code
47893       ,p_accounting_line_type_code  => l_component_type_code
47894       ,p_accounting_line_appl_id    => l_component_appl_id
47895       ,p_amb_context_code           => l_amb_context_code
47896       ,p_entity_code                => l_entity_code
47897       ,p_event_class_code           => l_event_class_code);
47898    --
47899    -- set accounting class
47900    --
47901    xla_ae_lines_pkg.SetAcctClass(
47902            p_accounting_class_code  => 'RECEIVABLE'
47903          , p_ae_header_id           => l_ae_header_id
47904          );
47905 
47906    --
47907    -- set rounding class
47908    --
47909    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
47910                       'RECEIVABLE';
47911 
47912    --
47913    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
47914    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
47915    --
47916    -- bulk performance
47917    --
47918    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
47919 
47920    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
47921       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
47922 
47923    -- 4955764
47924    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
47925       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
47926 
47927    -- 4458381 Public Sector Enh
47928    
47929    --
47930    -- set accounting attributes for the line type
47931    --
47932    l_entered_amt_idx := 8;
47933    l_accted_amt_idx  := 10;
47934    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
47935    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
47936    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
47937    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
47938    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
47939    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
47940    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
47941    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
47942    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
47943    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
47944    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
47945    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
47946    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
47947    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
47948    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
47949    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
47950    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
47951    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
47952    l_rec_acct_attrs.array_char_value(9)  := p_source_25;
47956    l_rec_acct_attrs.array_char_value(11)  := p_source_65;
47953    l_rec_acct_attrs.array_acct_attr_code(10) := 'LEDGER_AMOUNT';
47954    l_rec_acct_attrs.array_num_value(10)  := p_source_29;
47955    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
47957 
47958    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
47959    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
47960 
47961    ---------------------------------------------------------------------------------------------------------------
47962    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
47963    ---------------------------------------------------------------------------------------------------------------
47964    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
47965 
47966    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
47967    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
47968 
47969    IF xla_accounting_cache_pkg.GetValueChar
47970          (p_source_code         => 'LEDGER_CATEGORY_CODE'
47971          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
47972    AND l_bflow_method_code = 'PRIOR_ENTRY'
47973 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
47974    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
47975          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
47976        )
47977    THEN
47978          xla_ae_lines_pkg.BflowUpgEntry
47979            (p_business_method_code    => l_bflow_method_code
47980            ,p_business_class_code     => l_bflow_class_code
47981            ,p_balance_type            => l_balance_type_code);
47982    ELSE
47983       NULL;
47984 XLA_AE_LINES_PKG.business_flow_validation(
47985                                 p_business_method_code     => l_bflow_method_code
47986                                ,p_business_class_code      => l_bflow_class_code
47987                                ,p_inherit_description_flag => l_inherit_desc_flag);
47988    END IF;
47989 
47990    --
47991    -- call analytical criteria
47992    --
47993    -- Inherited Analytical Criteria for business flow method of Prior Entry.
47994    --
47995    -- call description
47996    --
47997    
47998 xla_ae_lines_pkg.SetLineDescription(
47999    p_ae_header_id => l_ae_header_id
48000   ,p_description  => Description_1 (
48001      p_application_id         => p_application_id
48002    , p_ae_header_id           => l_ae_header_id 
48003    )
48004 );
48005 
48006 
48007    --
48008    -- call ADRs
48009    -- Bug 4922099
48010    --
48011    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
48012         (NVL(l_actual_upg_option, 'N') = 'O') OR
48013         (NVL(l_enc_upg_option, 'N') = 'O')
48014       )
48015    THEN
48016    NULL;
48017    --
48018    --
48019    
48020    --
48021    --
48022    END IF;
48023    --
48024    -- Bug 4922099
48025    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
48026           (NVL(l_enc_upg_option, 'N') = 'O')
48027         ) AND
48028         (l_bflow_method_code = 'PRIOR_ENTRY')
48029       )
48030    THEN
48031       IF
48032       --
48033       1 = 1
48034       --
48035       THEN
48036       xla_accounting_err_pkg.build_message
48037                                     (p_appli_s_name            => 'XLA'
48038                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
48039                                     ,p_token_1                 => 'LINE_NUMBER'
48040                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
48041                                     ,p_token_2                 => 'LINE_TYPE_NAME'
48042                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
48043                                                                              l_component_type
48044                                                                             ,l_component_code
48045                                                                             ,l_component_type_code
48046                                                                             ,l_component_appl_id
48047                                                                             ,l_amb_context_code
48048                                                                             ,l_entity_code
48049                                                                             ,l_event_class_code
48050                                                                            )
48051                                     ,p_token_3                 => 'OWNER'
48052                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
48053                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
48054                                                                           ,p_lookup_code    => l_component_type_code
48055                                                                          )
48056                                     ,p_token_4                 => 'PRODUCT_NAME'
48057                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
48058                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
48062                                        );
48059                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
48060                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
48061                                     ,p_ae_header_id            =>  NULL
48063 
48064         IF (C_LEVEL_ERROR>= g_log_level) THEN
48065                  trace
48066                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
48067                       ,p_level    => C_LEVEL_ERROR
48068                       ,p_module   => l_log_module);
48069         END IF;
48070       END IF;
48071    END IF;
48072    --
48073    --
48074    ------------------------------------------------------------------------------------------------
48075    -- 4219869 Business Flow
48076    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
48077    -- Prior Entry.  Currently, the following code is always generated.
48078    ------------------------------------------------------------------------------------------------
48079    -- No ValidateCurrentLine for business flow method of Prior Entry
48080 
48081    ------------------------------------------------------------------------------------
48082    -- 4219869 Business Flow
48083    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
48084    ------------------------------------------------------------------------------------
48085    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
48086 
48087    ----------------------------------------------------------------------------------
48088    -- 4219869 Business Flow
48089    -- Update journal entry status -- Need to generate this within IF <condition>
48090    ----------------------------------------------------------------------------------
48091    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
48092          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
48093          ,p_balance_type_code => l_balance_type_code
48094          );
48095 
48096    -------------------------------------------------------------------------------------------
48097    -- 4262811 - Generate the Accrual Reversal lines
48098    -------------------------------------------------------------------------------------------
48099    BEGIN
48100       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
48101                               (g_array_event(p_event_id).array_value_num('header_index'));
48102       IF l_acc_rev_flag IS NULL THEN
48103          l_acc_rev_flag := 'N';
48104       END IF;
48105    EXCEPTION
48106       WHEN OTHERS THEN
48107          l_acc_rev_flag := 'N';
48108    END;
48109    --
48110    IF (l_acc_rev_flag = 'Y') THEN
48111 
48112        -- 4645092  ------------------------------------------------------------------------------
48113        -- To allow MPA report to determine if it should generate report process
48114        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
48115        ------------------------------------------------------------------------------------------
48116 
48117        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
48118        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
48119    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
48120    -- call ADRs
48121    -- Bug 4922099
48122    --
48123    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
48124         (NVL(l_actual_upg_option, 'N') = 'O') OR
48125         (NVL(l_enc_upg_option, 'N') = 'O')
48126       )
48127    THEN
48128    NULL;
48129    --
48130    --
48131    
48132    --
48133    --
48134    END IF;
48135 
48136        --
48137        -- Update the line information that should be overwritten
48138        --
48139        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
48140                                          p_header_num   => 1);
48141        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
48142 
48143        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
48144 
48145        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
48146           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
48147        END IF;
48148 
48149       --
48150       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
48151       --
48152       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
48153           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
48154       ELSE
48155           ---------------------------------------------------------------------------------------------------
48156           -- 4262811a Switch Sign
48157           ---------------------------------------------------------------------------------------------------
48158           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
48159           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
48160                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48161           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
48165                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48162                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48163           -- 5132302
48164           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
48166 
48167       END IF;
48168 
48169       -- 4955764
48170       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
48171       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
48172 
48173 
48174       XLA_AE_LINES_PKG.ValidateCurrentLine;
48175       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
48176 
48177       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
48178                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
48179                ,p_balance_type_code => l_balance_type_code);
48180 
48181    END IF;
48182 
48183    -----------------------------------------------------------------------------------------
48184    -- 4262811 Multiperiod Accounting
48185    -----------------------------------------------------------------------------------------
48186      -- No MPA option is assigned.
48187 
48188 
48189 END IF;
48190 END IF;
48191 --
48192 
48193 --
48194 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
48195    trace
48196       (p_msg      => 'END of AcctLineType_101'
48197       ,p_level    => C_LEVEL_PROCEDURE
48198       ,p_module   => l_log_module);
48199 END IF;
48200 --
48201 EXCEPTION
48202   WHEN xla_exceptions_pkg.application_exception THEN
48203       RAISE;
48204   WHEN OTHERS THEN
48205        xla_exceptions_pkg.raise_message
48206            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_101');
48207 END AcctLineType_101;
48208 --
48209 
48210 ---------------------------------------
48211 --
48212 -- PRIVATE FUNCTION
48213 --         AcctLineType_102
48214 --
48215 ---------------------------------------
48216 PROCEDURE AcctLineType_102 (
48217   p_application_id        IN NUMBER
48218  ,p_event_id              IN NUMBER
48219  ,p_calculate_acctd_flag  IN VARCHAR2
48220  ,p_calculate_g_l_flag    IN VARCHAR2
48221  ,p_actual_flag           IN OUT VARCHAR2
48222  ,p_balance_type_code     OUT VARCHAR2
48223  ,p_gain_or_loss_ref      OUT VARCHAR2
48224  
48225 --Distribution GL Account
48226  , p_source_3            IN NUMBER
48227 --Distribution Source Type
48228  , p_source_20            IN VARCHAR2
48229 --Distribution Line Identifier
48230  , p_source_22            IN NUMBER
48231 --Distribution Type
48232  , p_source_23            IN VARCHAR2
48233 --Entered Amount
48234  , p_source_24            IN NUMBER
48235 --Currency Code
48236  , p_source_25            IN VARCHAR2
48237 --Exchange Rate
48238  , p_source_27            IN NUMBER
48239 --Exchange Rate Type
48240  , p_source_28            IN VARCHAR2
48241 --Applied To Document Accounting Amount
48242  , p_source_29            IN NUMBER
48243 --Applied To Document Exchange Date
48244  , p_source_57            IN DATE
48245 --Distribution Multi Fund Additional Entry
48246  , p_source_69            IN VARCHAR2
48247 )
48248 IS
48249 
48250 l_component_type              VARCHAR2(80);
48251 l_component_code              VARCHAR2(30);
48252 l_component_type_code         VARCHAR2(1);
48253 l_component_appl_id           INTEGER;
48254 l_amb_context_code            VARCHAR2(30);
48255 l_entity_code                 VARCHAR2(30);
48256 l_event_class_code            VARCHAR2(30);
48257 l_ae_header_id                NUMBER;
48258 l_event_type_code             VARCHAR2(30);
48259 l_line_definition_code        VARCHAR2(30);
48260 l_line_definition_owner_code  VARCHAR2(1);
48261 --
48262 -- adr variables
48263 l_segment                     VARCHAR2(30);
48264 l_ccid                        NUMBER;
48265 l_adr_transaction_coa_id      NUMBER;
48266 l_adr_accounting_coa_id       NUMBER;
48267 l_adr_flexfield_segment_code  VARCHAR2(30);
48268 l_adr_flex_value_set_id       NUMBER;
48269 l_adr_value_type_code         VARCHAR2(30);
48270 l_adr_value_combination_id    NUMBER;
48271 l_adr_value_segment_code      VARCHAR2(30);
48272 
48273 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
48274 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
48275 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
48276 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
48277 
48278 -- 4262811 Variables ------------------------------------------------------------------------------------------
48279 l_entered_amt_idx             NUMBER;
48280 l_accted_amt_idx              NUMBER;
48281 l_acc_rev_flag                VARCHAR2(1);
48282 l_accrual_line_num            NUMBER;
48283 l_tmp_amt                     NUMBER;
48284 l_acc_rev_natural_side_code   VARCHAR2(1);
48285 
48286 l_num_entries                 NUMBER;
48287 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
48288 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
48289 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
48290 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
48291 l_recog_line_1                NUMBER;
48292 l_recog_line_2                NUMBER;
48293 
48294 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
48298 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
48295 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
48296 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
48297 
48299 
48300 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
48301 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
48302 
48303 ---------------------------------------------------------------------------------------------------------------
48304 
48305 
48306 --
48307 -- bulk performance
48308 --
48309 l_balance_type_code           VARCHAR2(1);
48310 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
48311 l_log_module                  VARCHAR2(240);
48312 
48313 --
48314 -- Upgrade strategy
48315 --
48316 l_actual_upg_option           VARCHAR2(1);
48317 l_enc_upg_option           VARCHAR2(1);
48318 
48319 --
48320 BEGIN
48321 --
48322 IF g_log_enabled THEN
48323       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_102';
48324 END IF;
48325 --
48326 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
48327 
48328       trace
48329          (p_msg      => 'BEGIN of AcctLineType_102'
48330          ,p_level    => C_LEVEL_PROCEDURE
48331          ,p_module   => l_log_module);
48332 
48333 END IF;
48334 --
48335 l_component_type             := 'AMB_JLT';
48336 l_component_code             := 'MISC_RCT_BNK_CHG';
48337 l_component_type_code        := 'S';
48338 l_component_appl_id          :=  222;
48339 l_amb_context_code           := 'DEFAULT';
48340 l_entity_code                := 'RECEIPTS';
48341 l_event_class_code           := 'MISC_RECEIPT';
48342 l_event_type_code            := 'MISC_RECEIPT_ALL';
48343 l_line_definition_owner_code := 'S';
48344 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
48345 --
48346 l_balance_type_code          := 'A';
48347 l_segment                     := NULL;
48348 l_ccid                        := NULL;
48349 l_adr_transaction_coa_id      := NULL;
48350 l_adr_accounting_coa_id       := NULL;
48351 l_adr_flexfield_segment_code  := NULL;
48352 l_adr_flex_value_set_id       := NULL;
48353 l_adr_value_type_code         := NULL;
48354 l_adr_value_combination_id    := NULL;
48355 l_adr_value_segment_code      := NULL;
48356 
48357 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
48358 l_bflow_class_code           := '';    -- 4219869 Business Flow
48359 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
48360 l_budgetary_control_flag     := 'N';
48361 
48362 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
48363 l_bflow_applied_to_amt       := NULL; -- 5132302
48364 l_entered_amt_idx            := NULL;          -- 4262811
48365 l_accted_amt_idx             := NULL;          -- 4262811
48366 l_acc_rev_flag               := NULL;          -- 4262811
48367 l_accrual_line_num           := NULL;          -- 4262811
48368 l_tmp_amt                    := NULL;          -- 4262811
48369 --
48370  
48371 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
48372     l_balance_type_code <> 'B' THEN
48373 IF NVL(p_source_20,'
48374 ') =  'BANK_CHARGES' AND 
48375 NVL(p_source_69,'
48376 ') =  'N'
48377  THEN 
48378 
48379    --
48380    XLA_AE_LINES_PKG.SetNewLine;
48381 
48382    p_balance_type_code          := l_balance_type_code;
48383    -- set the flag so later we will know whether the gain loss line needs to be created
48384    
48385    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
48386      p_actual_flag :='A';
48387    END IF;
48388 
48389    --
48390    -- bulk performance
48391    --
48392    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
48393                                       p_header_num   => 0); -- 4262811
48394    --
48395    -- set accounting line options
48396    --
48397    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
48398            p_natural_side_code          => 'C'
48399          , p_gain_or_loss_flag          => 'N'
48400          , p_gl_transfer_mode_code      => 'S'
48401          , p_acct_entry_type_code       => 'A'
48402          , p_switch_side_flag           => 'Y'
48403          , p_merge_duplicate_code       => 'A'
48404          );
48405    --
48406    l_acc_rev_natural_side_code := 'D';  -- 4262811
48407    -- 
48408    --
48409    -- set accounting line type info
48410    --
48411    xla_ae_lines_pkg.SetAcctLineType
48412       (p_component_type             => l_component_type
48413       ,p_event_type_code            => l_event_type_code
48414       ,p_line_definition_owner_code => l_line_definition_owner_code
48415       ,p_line_definition_code       => l_line_definition_code
48416       ,p_accounting_line_code       => l_component_code
48417       ,p_accounting_line_type_code  => l_component_type_code
48418       ,p_accounting_line_appl_id    => l_component_appl_id
48419       ,p_amb_context_code           => l_amb_context_code
48420       ,p_entity_code                => l_entity_code
48421       ,p_event_class_code           => l_event_class_code);
48422    --
48423    -- set accounting class
48424    --
48425    xla_ae_lines_pkg.SetAcctClass(
48426            p_accounting_class_code  => 'BANK_CHG'
48427          , p_ae_header_id           => l_ae_header_id
48428          );
48429 
48433    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
48430    --
48431    -- set rounding class
48432    --
48434                       'RECEIVABLE';
48435 
48436    --
48437    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
48438    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
48439    --
48440    -- bulk performance
48441    --
48442    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
48443 
48444    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
48445       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
48446 
48447    -- 4955764
48448    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
48449       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
48450 
48451    -- 4458381 Public Sector Enh
48452    
48453    --
48454    -- set accounting attributes for the line type
48455    --
48456    l_entered_amt_idx := 3;
48457    l_accted_amt_idx  := 8;
48458    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
48459    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
48460    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
48461    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
48462    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
48463    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
48464    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
48465    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
48466    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
48467    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
48468    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
48469    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
48470    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
48471    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
48472    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
48473    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
48474    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
48475 
48476    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
48477    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
48478 
48479    ---------------------------------------------------------------------------------------------------------------
48480    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
48481    ---------------------------------------------------------------------------------------------------------------
48482    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
48483 
48484    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
48485    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
48486 
48487    IF xla_accounting_cache_pkg.GetValueChar
48488          (p_source_code         => 'LEDGER_CATEGORY_CODE'
48489          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
48490    AND l_bflow_method_code = 'PRIOR_ENTRY'
48491 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
48492    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
48493          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
48494        )
48495    THEN
48496          xla_ae_lines_pkg.BflowUpgEntry
48497            (p_business_method_code    => l_bflow_method_code
48498            ,p_business_class_code     => l_bflow_class_code
48499            ,p_balance_type            => l_balance_type_code);
48500    ELSE
48501       NULL;
48502 -- No business flow processing for business flow method of NONE.
48503    END IF;
48504 
48505    --
48506    -- call analytical criteria
48507    --
48508    
48509    --
48510    -- call description
48511    --
48512    -- No description or it is inherited.
48513    --
48514    -- call ADRs
48515    -- Bug 4922099
48516    --
48517    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
48518         (NVL(l_actual_upg_option, 'N') = 'O') OR
48519         (NVL(l_enc_upg_option, 'N') = 'O')
48520       )
48521    THEN
48522    NULL;
48523    --
48524    --
48525    
48526   l_ccid := AcctDerRule_7(
48527            p_application_id           => p_application_id
48528          , p_ae_header_id             => l_ae_header_id 
48529 , p_source_3 => p_source_3
48530          , x_transaction_coa_id       => l_adr_transaction_coa_id
48531          , x_accounting_coa_id        => l_adr_accounting_coa_id
48532          , x_value_type_code          => l_adr_value_type_code
48533          , p_side                     => 'NA'
48534    );
48535 
48536    xla_ae_lines_pkg.set_ccid(
48537     p_code_combination_id          => l_ccid
48538   , p_value_type_code              => l_adr_value_type_code
48539   , p_transaction_coa_id           => l_adr_transaction_coa_id
48540   , p_accounting_coa_id            => l_adr_accounting_coa_id
48541   , p_adr_code                     => 'DIST_CCID'
48542   , p_adr_type_code                => 'S'
48543   , p_component_type               => l_component_type
48544   , p_component_code               => l_component_code
48548   , p_side                         => 'NA'
48545   , p_component_type_code          => l_component_type_code
48546   , p_component_appl_id            => l_component_appl_id
48547   , p_amb_context_code             => l_amb_context_code
48549   );
48550 
48551 
48552    --
48553    --
48554    END IF;
48555    --
48556    -- Bug 4922099
48557    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
48558           (NVL(l_enc_upg_option, 'N') = 'O')
48559         ) AND
48560         (l_bflow_method_code = 'PRIOR_ENTRY')
48561       )
48562    THEN
48563       IF
48564       --
48565       1 = 2
48566       --
48567       THEN
48568       xla_accounting_err_pkg.build_message
48569                                     (p_appli_s_name            => 'XLA'
48570                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
48571                                     ,p_token_1                 => 'LINE_NUMBER'
48572                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
48573                                     ,p_token_2                 => 'LINE_TYPE_NAME'
48574                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
48575                                                                              l_component_type
48576                                                                             ,l_component_code
48577                                                                             ,l_component_type_code
48578                                                                             ,l_component_appl_id
48579                                                                             ,l_amb_context_code
48580                                                                             ,l_entity_code
48581                                                                             ,l_event_class_code
48582                                                                            )
48583                                     ,p_token_3                 => 'OWNER'
48584                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
48585                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
48586                                                                           ,p_lookup_code    => l_component_type_code
48587                                                                          )
48588                                     ,p_token_4                 => 'PRODUCT_NAME'
48589                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
48590                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
48591                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
48592                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
48593                                     ,p_ae_header_id            =>  NULL
48594                                        );
48595 
48596         IF (C_LEVEL_ERROR>= g_log_level) THEN
48597                  trace
48598                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
48599                       ,p_level    => C_LEVEL_ERROR
48600                       ,p_module   => l_log_module);
48601         END IF;
48602       END IF;
48603    END IF;
48604    --
48605    --
48606    ------------------------------------------------------------------------------------------------
48607    -- 4219869 Business Flow
48608    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
48609    -- Prior Entry.  Currently, the following code is always generated.
48610    ------------------------------------------------------------------------------------------------
48611    XLA_AE_LINES_PKG.ValidateCurrentLine;
48612 
48613    ------------------------------------------------------------------------------------
48614    -- 4219869 Business Flow
48615    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
48616    ------------------------------------------------------------------------------------
48617    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
48618 
48619    ----------------------------------------------------------------------------------
48620    -- 4219869 Business Flow
48621    -- Update journal entry status -- Need to generate this within IF <condition>
48622    ----------------------------------------------------------------------------------
48623    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
48624          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
48625          ,p_balance_type_code => l_balance_type_code
48626          );
48627 
48628    -------------------------------------------------------------------------------------------
48629    -- 4262811 - Generate the Accrual Reversal lines
48630    -------------------------------------------------------------------------------------------
48631    BEGIN
48632       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
48633                               (g_array_event(p_event_id).array_value_num('header_index'));
48634       IF l_acc_rev_flag IS NULL THEN
48635          l_acc_rev_flag := 'N';
48636       END IF;
48637    EXCEPTION
48638       WHEN OTHERS THEN
48639          l_acc_rev_flag := 'N';
48640    END;
48641    --
48645        -- To allow MPA report to determine if it should generate report process
48642    IF (l_acc_rev_flag = 'Y') THEN
48643 
48644        -- 4645092  ------------------------------------------------------------------------------
48646        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
48647        ------------------------------------------------------------------------------------------
48648 
48649        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
48650        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
48651    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
48652    -- call ADRs
48653    -- Bug 4922099
48654    --
48655    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
48656         (NVL(l_actual_upg_option, 'N') = 'O') OR
48657         (NVL(l_enc_upg_option, 'N') = 'O')
48658       )
48659    THEN
48660    NULL;
48661    --
48662    --
48663    
48664   l_ccid := AcctDerRule_7(
48665            p_application_id           => p_application_id
48666          , p_ae_header_id             => l_ae_header_id 
48667 , p_source_3 => p_source_3
48668          , x_transaction_coa_id       => l_adr_transaction_coa_id
48669          , x_accounting_coa_id        => l_adr_accounting_coa_id
48670          , x_value_type_code          => l_adr_value_type_code
48671          , p_side                     => 'NA'
48672    );
48673 
48674    xla_ae_lines_pkg.set_ccid(
48675     p_code_combination_id          => l_ccid
48676   , p_value_type_code              => l_adr_value_type_code
48677   , p_transaction_coa_id           => l_adr_transaction_coa_id
48678   , p_accounting_coa_id            => l_adr_accounting_coa_id
48679   , p_adr_code                     => 'DIST_CCID'
48680   , p_adr_type_code                => 'S'
48681   , p_component_type               => l_component_type
48682   , p_component_code               => l_component_code
48683   , p_component_type_code          => l_component_type_code
48684   , p_component_appl_id            => l_component_appl_id
48685   , p_amb_context_code             => l_amb_context_code
48686   , p_side                         => 'NA'
48687   );
48688 
48689 
48690    --
48691    --
48692    END IF;
48693 
48694        --
48695        -- Update the line information that should be overwritten
48696        --
48697        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
48698                                          p_header_num   => 1);
48699        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
48700 
48701        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
48702 
48703        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
48704           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
48705        END IF;
48706 
48707       --
48708       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
48709       --
48710       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
48711           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
48712       ELSE
48713           ---------------------------------------------------------------------------------------------------
48714           -- 4262811a Switch Sign
48715           ---------------------------------------------------------------------------------------------------
48716           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
48717           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
48718                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48719           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
48720                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48721           -- 5132302
48722           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
48723                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48724 
48725       END IF;
48726 
48727       -- 4955764
48728       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
48729       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
48730 
48731 
48732       XLA_AE_LINES_PKG.ValidateCurrentLine;
48733       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
48734 
48735       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
48736                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
48737                ,p_balance_type_code => l_balance_type_code);
48738 
48739    END IF;
48740 
48741    -----------------------------------------------------------------------------------------
48742    -- 4262811 Multiperiod Accounting
48743    -----------------------------------------------------------------------------------------
48744      -- No MPA option is assigned.
48745 
48746 
48747 END IF;
48748 END IF;
48749 --
48750 
48751 --
48752 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
48753    trace
48754       (p_msg      => 'END of AcctLineType_102'
48755       ,p_level    => C_LEVEL_PROCEDURE
48759 EXCEPTION
48756       ,p_module   => l_log_module);
48757 END IF;
48758 --
48760   WHEN xla_exceptions_pkg.application_exception THEN
48761       RAISE;
48762   WHEN OTHERS THEN
48763        xla_exceptions_pkg.raise_message
48764            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_102');
48765 END AcctLineType_102;
48766 --
48767 
48768 ---------------------------------------
48769 --
48770 -- PRIVATE FUNCTION
48771 --         AcctLineType_103
48772 --
48773 ---------------------------------------
48774 PROCEDURE AcctLineType_103 (
48775   p_application_id        IN NUMBER
48776  ,p_event_id              IN NUMBER
48777  ,p_calculate_acctd_flag  IN VARCHAR2
48778  ,p_calculate_g_l_flag    IN VARCHAR2
48779  ,p_actual_flag           IN OUT VARCHAR2
48780  ,p_balance_type_code     OUT VARCHAR2
48781  ,p_gain_or_loss_ref      OUT VARCHAR2
48782  
48783 --Distribution GL Account
48784  , p_source_3            IN NUMBER
48785 --Distribution Source Type
48786  , p_source_20            IN VARCHAR2
48787 --Distribution Line Identifier
48788  , p_source_22            IN NUMBER
48789 --Distribution Type
48790  , p_source_23            IN VARCHAR2
48791 --Entered Amount
48792  , p_source_24            IN NUMBER
48793 --Currency Code
48794  , p_source_25            IN VARCHAR2
48795 --Exchange Rate
48796  , p_source_27            IN NUMBER
48797 --Exchange Rate Type
48798  , p_source_28            IN VARCHAR2
48799 --Applied To Document Accounting Amount
48800  , p_source_29            IN NUMBER
48801 --Applied To Document Exchange Date
48802  , p_source_57            IN DATE
48803 --Distribution Multi Fund Additional Entry
48804  , p_source_69            IN VARCHAR2
48805 )
48806 IS
48807 
48808 l_component_type              VARCHAR2(80);
48809 l_component_code              VARCHAR2(30);
48810 l_component_type_code         VARCHAR2(1);
48811 l_component_appl_id           INTEGER;
48812 l_amb_context_code            VARCHAR2(30);
48813 l_entity_code                 VARCHAR2(30);
48814 l_event_class_code            VARCHAR2(30);
48815 l_ae_header_id                NUMBER;
48816 l_event_type_code             VARCHAR2(30);
48817 l_line_definition_code        VARCHAR2(30);
48818 l_line_definition_owner_code  VARCHAR2(1);
48819 --
48820 -- adr variables
48821 l_segment                     VARCHAR2(30);
48822 l_ccid                        NUMBER;
48823 l_adr_transaction_coa_id      NUMBER;
48824 l_adr_accounting_coa_id       NUMBER;
48825 l_adr_flexfield_segment_code  VARCHAR2(30);
48826 l_adr_flex_value_set_id       NUMBER;
48827 l_adr_value_type_code         VARCHAR2(30);
48828 l_adr_value_combination_id    NUMBER;
48829 l_adr_value_segment_code      VARCHAR2(30);
48830 
48831 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
48832 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
48833 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
48834 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
48835 
48836 -- 4262811 Variables ------------------------------------------------------------------------------------------
48837 l_entered_amt_idx             NUMBER;
48838 l_accted_amt_idx              NUMBER;
48839 l_acc_rev_flag                VARCHAR2(1);
48840 l_accrual_line_num            NUMBER;
48841 l_tmp_amt                     NUMBER;
48842 l_acc_rev_natural_side_code   VARCHAR2(1);
48843 
48844 l_num_entries                 NUMBER;
48845 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
48846 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
48847 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
48848 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
48849 l_recog_line_1                NUMBER;
48850 l_recog_line_2                NUMBER;
48851 
48852 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
48853 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
48854 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
48855 
48856 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
48857 
48858 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
48859 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
48860 
48861 ---------------------------------------------------------------------------------------------------------------
48862 
48863 
48864 --
48865 -- bulk performance
48866 --
48867 l_balance_type_code           VARCHAR2(1);
48868 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
48869 l_log_module                  VARCHAR2(240);
48870 
48871 --
48872 -- Upgrade strategy
48873 --
48874 l_actual_upg_option           VARCHAR2(1);
48875 l_enc_upg_option           VARCHAR2(1);
48876 
48877 --
48878 BEGIN
48879 --
48880 IF g_log_enabled THEN
48881       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_103';
48882 END IF;
48883 --
48884 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
48885 
48886       trace
48887          (p_msg      => 'BEGIN of AcctLineType_103'
48888          ,p_level    => C_LEVEL_PROCEDURE
48889          ,p_module   => l_log_module);
48890 
48891 END IF;
48892 --
48893 l_component_type             := 'AMB_JLT';
48894 l_component_code             := 'MISC_RCT_DEBT';
48898 l_entity_code                := 'RECEIPTS';
48895 l_component_type_code        := 'S';
48896 l_component_appl_id          :=  222;
48897 l_amb_context_code           := 'DEFAULT';
48899 l_event_class_code           := 'MISC_RECEIPT';
48900 l_event_type_code            := 'MISC_RECEIPT_ALL';
48901 l_line_definition_owner_code := 'S';
48902 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
48903 --
48904 l_balance_type_code          := 'A';
48905 l_segment                     := NULL;
48906 l_ccid                        := NULL;
48907 l_adr_transaction_coa_id      := NULL;
48908 l_adr_accounting_coa_id       := NULL;
48909 l_adr_flexfield_segment_code  := NULL;
48910 l_adr_flex_value_set_id       := NULL;
48911 l_adr_value_type_code         := NULL;
48912 l_adr_value_combination_id    := NULL;
48913 l_adr_value_segment_code      := NULL;
48914 
48915 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
48916 l_bflow_class_code           := '';    -- 4219869 Business Flow
48917 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
48918 l_budgetary_control_flag     := 'N';
48919 
48920 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
48921 l_bflow_applied_to_amt       := NULL; -- 5132302
48922 l_entered_amt_idx            := NULL;          -- 4262811
48923 l_accted_amt_idx             := NULL;          -- 4262811
48924 l_acc_rev_flag               := NULL;          -- 4262811
48925 l_accrual_line_num           := NULL;          -- 4262811
48926 l_tmp_amt                    := NULL;          -- 4262811
48927 --
48928  
48929 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
48930     l_balance_type_code <> 'B' THEN
48931 IF NVL(p_source_20,'
48932 ') =  'SHORT_TERM_DEBT' AND 
48933 NVL(p_source_69,'
48934 ') =  'N'
48935  THEN 
48936 
48937    --
48938    XLA_AE_LINES_PKG.SetNewLine;
48939 
48940    p_balance_type_code          := l_balance_type_code;
48941    -- set the flag so later we will know whether the gain loss line needs to be created
48942    
48943    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
48944      p_actual_flag :='A';
48945    END IF;
48946 
48947    --
48948    -- bulk performance
48949    --
48950    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
48951                                       p_header_num   => 0); -- 4262811
48952    --
48953    -- set accounting line options
48954    --
48955    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
48956            p_natural_side_code          => 'C'
48957          , p_gain_or_loss_flag          => 'N'
48958          , p_gl_transfer_mode_code      => 'S'
48959          , p_acct_entry_type_code       => 'A'
48960          , p_switch_side_flag           => 'Y'
48961          , p_merge_duplicate_code       => 'A'
48962          );
48963    --
48964    l_acc_rev_natural_side_code := 'D';  -- 4262811
48965    -- 
48966    --
48967    -- set accounting line type info
48968    --
48969    xla_ae_lines_pkg.SetAcctLineType
48970       (p_component_type             => l_component_type
48971       ,p_event_type_code            => l_event_type_code
48972       ,p_line_definition_owner_code => l_line_definition_owner_code
48973       ,p_line_definition_code       => l_line_definition_code
48974       ,p_accounting_line_code       => l_component_code
48975       ,p_accounting_line_type_code  => l_component_type_code
48976       ,p_accounting_line_appl_id    => l_component_appl_id
48977       ,p_amb_context_code           => l_amb_context_code
48978       ,p_entity_code                => l_entity_code
48979       ,p_event_class_code           => l_event_class_code);
48980    --
48981    -- set accounting class
48982    --
48983    xla_ae_lines_pkg.SetAcctClass(
48984            p_accounting_class_code  => 'SHORT_TERM_DEBT'
48985          , p_ae_header_id           => l_ae_header_id
48986          );
48987 
48988    --
48989    -- set rounding class
48990    --
48991    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
48992                       'RECEIVABLE';
48993 
48994    --
48995    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
48996    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
48997    --
48998    -- bulk performance
48999    --
49000    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
49001 
49002    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
49003       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
49004 
49005    -- 4955764
49006    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
49007       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
49008 
49009    -- 4458381 Public Sector Enh
49010    
49011    --
49012    -- set accounting attributes for the line type
49013    --
49014    l_entered_amt_idx := 3;
49015    l_accted_amt_idx  := 8;
49016    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
49017    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
49018    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
49019    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
49020    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
49024    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
49021    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
49022    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
49023    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
49025    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
49026    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
49027    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
49028    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
49029    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
49030    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
49031    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
49032    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
49033 
49034    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
49035    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
49036 
49037    ---------------------------------------------------------------------------------------------------------------
49038    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
49039    ---------------------------------------------------------------------------------------------------------------
49040    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
49041 
49042    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
49043    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
49044 
49045    IF xla_accounting_cache_pkg.GetValueChar
49046          (p_source_code         => 'LEDGER_CATEGORY_CODE'
49047          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
49048    AND l_bflow_method_code = 'PRIOR_ENTRY'
49049 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
49050    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
49051          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
49052        )
49053    THEN
49054          xla_ae_lines_pkg.BflowUpgEntry
49055            (p_business_method_code    => l_bflow_method_code
49056            ,p_business_class_code     => l_bflow_class_code
49057            ,p_balance_type            => l_balance_type_code);
49058    ELSE
49059       NULL;
49060 -- No business flow processing for business flow method of NONE.
49061    END IF;
49062 
49063    --
49064    -- call analytical criteria
49065    --
49066    
49067    --
49068    -- call description
49069    --
49070    -- No description or it is inherited.
49071    --
49072    -- call ADRs
49073    -- Bug 4922099
49074    --
49075    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
49076         (NVL(l_actual_upg_option, 'N') = 'O') OR
49077         (NVL(l_enc_upg_option, 'N') = 'O')
49078       )
49079    THEN
49080    NULL;
49081    --
49082    --
49083    
49084   l_ccid := AcctDerRule_7(
49085            p_application_id           => p_application_id
49086          , p_ae_header_id             => l_ae_header_id 
49087 , p_source_3 => p_source_3
49088          , x_transaction_coa_id       => l_adr_transaction_coa_id
49089          , x_accounting_coa_id        => l_adr_accounting_coa_id
49090          , x_value_type_code          => l_adr_value_type_code
49091          , p_side                     => 'NA'
49092    );
49093 
49094    xla_ae_lines_pkg.set_ccid(
49095     p_code_combination_id          => l_ccid
49096   , p_value_type_code              => l_adr_value_type_code
49097   , p_transaction_coa_id           => l_adr_transaction_coa_id
49098   , p_accounting_coa_id            => l_adr_accounting_coa_id
49099   , p_adr_code                     => 'DIST_CCID'
49100   , p_adr_type_code                => 'S'
49101   , p_component_type               => l_component_type
49102   , p_component_code               => l_component_code
49103   , p_component_type_code          => l_component_type_code
49104   , p_component_appl_id            => l_component_appl_id
49105   , p_amb_context_code             => l_amb_context_code
49106   , p_side                         => 'NA'
49107   );
49108 
49109 
49110    --
49111    --
49112    END IF;
49113    --
49114    -- Bug 4922099
49115    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
49116           (NVL(l_enc_upg_option, 'N') = 'O')
49117         ) AND
49118         (l_bflow_method_code = 'PRIOR_ENTRY')
49119       )
49120    THEN
49121       IF
49122       --
49123       1 = 2
49124       --
49125       THEN
49126       xla_accounting_err_pkg.build_message
49127                                     (p_appli_s_name            => 'XLA'
49128                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
49129                                     ,p_token_1                 => 'LINE_NUMBER'
49130                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
49131                                     ,p_token_2                 => 'LINE_TYPE_NAME'
49132                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
49133                                                                              l_component_type
49134                                                                             ,l_component_code
49135                                                                             ,l_component_type_code
49139                                                                             ,l_event_class_code
49136                                                                             ,l_component_appl_id
49137                                                                             ,l_amb_context_code
49138                                                                             ,l_entity_code
49140                                                                            )
49141                                     ,p_token_3                 => 'OWNER'
49142                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
49143                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
49144                                                                           ,p_lookup_code    => l_component_type_code
49145                                                                          )
49146                                     ,p_token_4                 => 'PRODUCT_NAME'
49147                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
49148                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
49149                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
49150                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
49151                                     ,p_ae_header_id            =>  NULL
49152                                        );
49153 
49154         IF (C_LEVEL_ERROR>= g_log_level) THEN
49155                  trace
49156                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
49157                       ,p_level    => C_LEVEL_ERROR
49158                       ,p_module   => l_log_module);
49159         END IF;
49160       END IF;
49161    END IF;
49162    --
49163    --
49164    ------------------------------------------------------------------------------------------------
49165    -- 4219869 Business Flow
49166    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
49167    -- Prior Entry.  Currently, the following code is always generated.
49168    ------------------------------------------------------------------------------------------------
49169    XLA_AE_LINES_PKG.ValidateCurrentLine;
49170 
49171    ------------------------------------------------------------------------------------
49172    -- 4219869 Business Flow
49173    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
49174    ------------------------------------------------------------------------------------
49175    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
49176 
49177    ----------------------------------------------------------------------------------
49178    -- 4219869 Business Flow
49179    -- Update journal entry status -- Need to generate this within IF <condition>
49180    ----------------------------------------------------------------------------------
49181    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
49182          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
49183          ,p_balance_type_code => l_balance_type_code
49184          );
49185 
49186    -------------------------------------------------------------------------------------------
49187    -- 4262811 - Generate the Accrual Reversal lines
49188    -------------------------------------------------------------------------------------------
49189    BEGIN
49190       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
49191                               (g_array_event(p_event_id).array_value_num('header_index'));
49192       IF l_acc_rev_flag IS NULL THEN
49193          l_acc_rev_flag := 'N';
49194       END IF;
49195    EXCEPTION
49196       WHEN OTHERS THEN
49197          l_acc_rev_flag := 'N';
49198    END;
49199    --
49200    IF (l_acc_rev_flag = 'Y') THEN
49201 
49202        -- 4645092  ------------------------------------------------------------------------------
49203        -- To allow MPA report to determine if it should generate report process
49204        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
49205        ------------------------------------------------------------------------------------------
49206 
49207        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
49208        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
49209    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
49210    -- call ADRs
49211    -- Bug 4922099
49212    --
49213    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
49214         (NVL(l_actual_upg_option, 'N') = 'O') OR
49215         (NVL(l_enc_upg_option, 'N') = 'O')
49216       )
49217    THEN
49218    NULL;
49219    --
49220    --
49221    
49222   l_ccid := AcctDerRule_7(
49223            p_application_id           => p_application_id
49224          , p_ae_header_id             => l_ae_header_id 
49225 , p_source_3 => p_source_3
49226          , x_transaction_coa_id       => l_adr_transaction_coa_id
49227          , x_accounting_coa_id        => l_adr_accounting_coa_id
49228          , x_value_type_code          => l_adr_value_type_code
49229          , p_side                     => 'NA'
49230    );
49231 
49232    xla_ae_lines_pkg.set_ccid(
49233     p_code_combination_id          => l_ccid
49234   , p_value_type_code              => l_adr_value_type_code
49235   , p_transaction_coa_id           => l_adr_transaction_coa_id
49239   , p_component_type               => l_component_type
49236   , p_accounting_coa_id            => l_adr_accounting_coa_id
49237   , p_adr_code                     => 'DIST_CCID'
49238   , p_adr_type_code                => 'S'
49240   , p_component_code               => l_component_code
49241   , p_component_type_code          => l_component_type_code
49242   , p_component_appl_id            => l_component_appl_id
49243   , p_amb_context_code             => l_amb_context_code
49244   , p_side                         => 'NA'
49245   );
49246 
49247 
49248    --
49249    --
49250    END IF;
49251 
49252        --
49253        -- Update the line information that should be overwritten
49254        --
49255        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
49256                                          p_header_num   => 1);
49257        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
49258 
49259        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
49260 
49261        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
49262           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
49263        END IF;
49264 
49265       --
49266       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
49267       --
49268       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
49269           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
49270       ELSE
49271           ---------------------------------------------------------------------------------------------------
49272           -- 4262811a Switch Sign
49273           ---------------------------------------------------------------------------------------------------
49274           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
49275           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
49276                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
49277           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
49278                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
49279           -- 5132302
49280           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
49281                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
49282 
49283       END IF;
49284 
49285       -- 4955764
49286       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
49287       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
49288 
49289 
49290       XLA_AE_LINES_PKG.ValidateCurrentLine;
49291       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
49292 
49293       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
49294                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
49295                ,p_balance_type_code => l_balance_type_code);
49296 
49297    END IF;
49298 
49299    -----------------------------------------------------------------------------------------
49300    -- 4262811 Multiperiod Accounting
49301    -----------------------------------------------------------------------------------------
49302      -- No MPA option is assigned.
49303 
49304 
49305 END IF;
49306 END IF;
49307 --
49308 
49309 --
49310 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
49311    trace
49312       (p_msg      => 'END of AcctLineType_103'
49313       ,p_level    => C_LEVEL_PROCEDURE
49314       ,p_module   => l_log_module);
49315 END IF;
49316 --
49317 EXCEPTION
49318   WHEN xla_exceptions_pkg.application_exception THEN
49319       RAISE;
49320   WHEN OTHERS THEN
49321        xla_exceptions_pkg.raise_message
49322            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_103');
49323 END AcctLineType_103;
49324 --
49325 
49326 ---------------------------------------
49327 --
49328 -- PRIVATE FUNCTION
49329 --         AcctLineType_104
49330 --
49331 ---------------------------------------
49332 PROCEDURE AcctLineType_104 (
49333   p_application_id        IN NUMBER
49334  ,p_event_id              IN NUMBER
49335  ,p_calculate_acctd_flag  IN VARCHAR2
49336  ,p_calculate_g_l_flag    IN VARCHAR2
49337  ,p_actual_flag           IN OUT VARCHAR2
49338  ,p_balance_type_code     OUT VARCHAR2
49339  ,p_gain_or_loss_ref      OUT VARCHAR2
49340  
49341 --Distribution GL Account
49342  , p_source_3            IN NUMBER
49343 --Distribution Source Type
49344  , p_source_20            IN VARCHAR2
49345 --Distribution Line Identifier
49346  , p_source_22            IN NUMBER
49347 --Distribution Type
49348  , p_source_23            IN VARCHAR2
49349 --Entered Amount
49350  , p_source_24            IN NUMBER
49351 --Currency Code
49352  , p_source_25            IN VARCHAR2
49353 --Exchange Rate
49354  , p_source_27            IN NUMBER
49355 --Exchange Rate Type
49356  , p_source_28            IN VARCHAR2
49357 --Applied To Document Accounting Amount
49358  , p_source_29            IN NUMBER
49362  , p_source_69            IN VARCHAR2
49359 --Applied To Document Exchange Date
49360  , p_source_57            IN DATE
49361 --Distribution Multi Fund Additional Entry
49363 )
49364 IS
49365 
49366 l_component_type              VARCHAR2(80);
49367 l_component_code              VARCHAR2(30);
49368 l_component_type_code         VARCHAR2(1);
49369 l_component_appl_id           INTEGER;
49370 l_amb_context_code            VARCHAR2(30);
49371 l_entity_code                 VARCHAR2(30);
49372 l_event_class_code            VARCHAR2(30);
49373 l_ae_header_id                NUMBER;
49374 l_event_type_code             VARCHAR2(30);
49375 l_line_definition_code        VARCHAR2(30);
49376 l_line_definition_owner_code  VARCHAR2(1);
49377 --
49378 -- adr variables
49379 l_segment                     VARCHAR2(30);
49380 l_ccid                        NUMBER;
49381 l_adr_transaction_coa_id      NUMBER;
49382 l_adr_accounting_coa_id       NUMBER;
49383 l_adr_flexfield_segment_code  VARCHAR2(30);
49384 l_adr_flex_value_set_id       NUMBER;
49385 l_adr_value_type_code         VARCHAR2(30);
49386 l_adr_value_combination_id    NUMBER;
49387 l_adr_value_segment_code      VARCHAR2(30);
49388 
49389 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
49390 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
49391 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
49392 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
49393 
49394 -- 4262811 Variables ------------------------------------------------------------------------------------------
49395 l_entered_amt_idx             NUMBER;
49396 l_accted_amt_idx              NUMBER;
49397 l_acc_rev_flag                VARCHAR2(1);
49398 l_accrual_line_num            NUMBER;
49399 l_tmp_amt                     NUMBER;
49400 l_acc_rev_natural_side_code   VARCHAR2(1);
49401 
49402 l_num_entries                 NUMBER;
49403 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
49404 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
49405 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
49406 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
49407 l_recog_line_1                NUMBER;
49408 l_recog_line_2                NUMBER;
49409 
49410 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
49411 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
49412 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
49413 
49414 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
49415 
49416 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
49417 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
49418 
49419 ---------------------------------------------------------------------------------------------------------------
49420 
49421 
49422 --
49423 -- bulk performance
49424 --
49425 l_balance_type_code           VARCHAR2(1);
49426 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
49427 l_log_module                  VARCHAR2(240);
49428 
49429 --
49430 -- Upgrade strategy
49431 --
49432 l_actual_upg_option           VARCHAR2(1);
49433 l_enc_upg_option           VARCHAR2(1);
49434 
49435 --
49436 BEGIN
49437 --
49438 IF g_log_enabled THEN
49439       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_104';
49440 END IF;
49441 --
49442 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
49443 
49444       trace
49445          (p_msg      => 'BEGIN of AcctLineType_104'
49446          ,p_level    => C_LEVEL_PROCEDURE
49447          ,p_module   => l_log_module);
49448 
49449 END IF;
49450 --
49451 l_component_type             := 'AMB_JLT';
49452 l_component_code             := 'MISC_RCT_FACTOR';
49453 l_component_type_code        := 'S';
49454 l_component_appl_id          :=  222;
49455 l_amb_context_code           := 'DEFAULT';
49456 l_entity_code                := 'RECEIPTS';
49457 l_event_class_code           := 'MISC_RECEIPT';
49458 l_event_type_code            := 'MISC_RECEIPT_ALL';
49459 l_line_definition_owner_code := 'S';
49460 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
49461 --
49462 l_balance_type_code          := 'A';
49463 l_segment                     := NULL;
49464 l_ccid                        := NULL;
49465 l_adr_transaction_coa_id      := NULL;
49466 l_adr_accounting_coa_id       := NULL;
49467 l_adr_flexfield_segment_code  := NULL;
49468 l_adr_flex_value_set_id       := NULL;
49469 l_adr_value_type_code         := NULL;
49470 l_adr_value_combination_id    := NULL;
49471 l_adr_value_segment_code      := NULL;
49472 
49473 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
49474 l_bflow_class_code           := '';    -- 4219869 Business Flow
49475 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
49476 l_budgetary_control_flag     := 'N';
49477 
49478 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
49479 l_bflow_applied_to_amt       := NULL; -- 5132302
49480 l_entered_amt_idx            := NULL;          -- 4262811
49481 l_accted_amt_idx             := NULL;          -- 4262811
49482 l_acc_rev_flag               := NULL;          -- 4262811
49483 l_accrual_line_num           := NULL;          -- 4262811
49487 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
49484 l_tmp_amt                    := NULL;          -- 4262811
49485 --
49486  
49488     l_balance_type_code <> 'B' THEN
49489 IF NVL(p_source_20,'
49490 ') =  'FACTOR' AND 
49491 NVL(p_source_69,'
49492 ') =  'N'
49493  THEN 
49494 
49495    --
49496    XLA_AE_LINES_PKG.SetNewLine;
49497 
49498    p_balance_type_code          := l_balance_type_code;
49499    -- set the flag so later we will know whether the gain loss line needs to be created
49500    
49501    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
49502      p_actual_flag :='A';
49503    END IF;
49504 
49505    --
49506    -- bulk performance
49507    --
49508    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
49509                                       p_header_num   => 0); -- 4262811
49510    --
49511    -- set accounting line options
49512    --
49513    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
49514            p_natural_side_code          => 'C'
49515          , p_gain_or_loss_flag          => 'N'
49516          , p_gl_transfer_mode_code      => 'S'
49517          , p_acct_entry_type_code       => 'A'
49518          , p_switch_side_flag           => 'Y'
49519          , p_merge_duplicate_code       => 'A'
49520          );
49521    --
49522    l_acc_rev_natural_side_code := 'D';  -- 4262811
49523    -- 
49524    --
49525    -- set accounting line type info
49526    --
49527    xla_ae_lines_pkg.SetAcctLineType
49528       (p_component_type             => l_component_type
49529       ,p_event_type_code            => l_event_type_code
49530       ,p_line_definition_owner_code => l_line_definition_owner_code
49531       ,p_line_definition_code       => l_line_definition_code
49532       ,p_accounting_line_code       => l_component_code
49533       ,p_accounting_line_type_code  => l_component_type_code
49534       ,p_accounting_line_appl_id    => l_component_appl_id
49535       ,p_amb_context_code           => l_amb_context_code
49536       ,p_entity_code                => l_entity_code
49537       ,p_event_class_code           => l_event_class_code);
49538    --
49539    -- set accounting class
49540    --
49541    xla_ae_lines_pkg.SetAcctClass(
49542            p_accounting_class_code  => 'FACTOR'
49543          , p_ae_header_id           => l_ae_header_id
49544          );
49545 
49546    --
49547    -- set rounding class
49548    --
49549    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
49550                       'RECEIVABLE';
49551 
49552    --
49553    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
49554    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
49555    --
49556    -- bulk performance
49557    --
49558    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
49559 
49560    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
49561       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
49562 
49563    -- 4955764
49564    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
49565       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
49566 
49567    -- 4458381 Public Sector Enh
49568    
49569    --
49570    -- set accounting attributes for the line type
49571    --
49572    l_entered_amt_idx := 3;
49573    l_accted_amt_idx  := 8;
49574    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
49575    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
49576    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
49577    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
49578    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
49579    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
49580    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
49581    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
49582    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
49583    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
49584    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
49585    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
49586    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
49587    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
49588    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
49589    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
49590    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
49591 
49592    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
49593    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
49594 
49595    ---------------------------------------------------------------------------------------------------------------
49596    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
49597    ---------------------------------------------------------------------------------------------------------------
49598    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
49599 
49600    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
49601    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
49605          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
49602 
49603    IF xla_accounting_cache_pkg.GetValueChar
49604          (p_source_code         => 'LEDGER_CATEGORY_CODE'
49606    AND l_bflow_method_code = 'PRIOR_ENTRY'
49607 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
49608    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
49609          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
49610        )
49611    THEN
49612          xla_ae_lines_pkg.BflowUpgEntry
49613            (p_business_method_code    => l_bflow_method_code
49614            ,p_business_class_code     => l_bflow_class_code
49615            ,p_balance_type            => l_balance_type_code);
49616    ELSE
49617       NULL;
49618 -- No business flow processing for business flow method of NONE.
49619    END IF;
49620 
49621    --
49622    -- call analytical criteria
49623    --
49624    
49625    --
49626    -- call description
49627    --
49628    -- No description or it is inherited.
49629    --
49630    -- call ADRs
49631    -- Bug 4922099
49632    --
49633    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
49634         (NVL(l_actual_upg_option, 'N') = 'O') OR
49635         (NVL(l_enc_upg_option, 'N') = 'O')
49636       )
49637    THEN
49638    NULL;
49639    --
49640    --
49641    
49642   l_ccid := AcctDerRule_7(
49643            p_application_id           => p_application_id
49644          , p_ae_header_id             => l_ae_header_id 
49645 , p_source_3 => p_source_3
49646          , x_transaction_coa_id       => l_adr_transaction_coa_id
49647          , x_accounting_coa_id        => l_adr_accounting_coa_id
49648          , x_value_type_code          => l_adr_value_type_code
49649          , p_side                     => 'NA'
49650    );
49651 
49652    xla_ae_lines_pkg.set_ccid(
49653     p_code_combination_id          => l_ccid
49654   , p_value_type_code              => l_adr_value_type_code
49655   , p_transaction_coa_id           => l_adr_transaction_coa_id
49656   , p_accounting_coa_id            => l_adr_accounting_coa_id
49657   , p_adr_code                     => 'DIST_CCID'
49658   , p_adr_type_code                => 'S'
49659   , p_component_type               => l_component_type
49660   , p_component_code               => l_component_code
49661   , p_component_type_code          => l_component_type_code
49662   , p_component_appl_id            => l_component_appl_id
49663   , p_amb_context_code             => l_amb_context_code
49664   , p_side                         => 'NA'
49665   );
49666 
49667 
49668    --
49669    --
49670    END IF;
49671    --
49672    -- Bug 4922099
49673    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
49674           (NVL(l_enc_upg_option, 'N') = 'O')
49675         ) AND
49676         (l_bflow_method_code = 'PRIOR_ENTRY')
49677       )
49678    THEN
49679       IF
49680       --
49681       1 = 2
49682       --
49683       THEN
49684       xla_accounting_err_pkg.build_message
49685                                     (p_appli_s_name            => 'XLA'
49686                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
49687                                     ,p_token_1                 => 'LINE_NUMBER'
49688                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
49689                                     ,p_token_2                 => 'LINE_TYPE_NAME'
49690                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
49691                                                                              l_component_type
49692                                                                             ,l_component_code
49693                                                                             ,l_component_type_code
49694                                                                             ,l_component_appl_id
49695                                                                             ,l_amb_context_code
49696                                                                             ,l_entity_code
49697                                                                             ,l_event_class_code
49698                                                                            )
49699                                     ,p_token_3                 => 'OWNER'
49700                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
49701                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
49702                                                                           ,p_lookup_code    => l_component_type_code
49703                                                                          )
49704                                     ,p_token_4                 => 'PRODUCT_NAME'
49705                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
49706                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
49707                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
49708                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
49709                                     ,p_ae_header_id            =>  NULL
49710                                        );
49711 
49712         IF (C_LEVEL_ERROR>= g_log_level) THEN
49716                       ,p_module   => l_log_module);
49713                  trace
49714                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
49715                       ,p_level    => C_LEVEL_ERROR
49717         END IF;
49718       END IF;
49719    END IF;
49720    --
49721    --
49722    ------------------------------------------------------------------------------------------------
49723    -- 4219869 Business Flow
49724    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
49725    -- Prior Entry.  Currently, the following code is always generated.
49726    ------------------------------------------------------------------------------------------------
49727    XLA_AE_LINES_PKG.ValidateCurrentLine;
49728 
49729    ------------------------------------------------------------------------------------
49730    -- 4219869 Business Flow
49731    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
49732    ------------------------------------------------------------------------------------
49733    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
49734 
49735    ----------------------------------------------------------------------------------
49736    -- 4219869 Business Flow
49737    -- Update journal entry status -- Need to generate this within IF <condition>
49738    ----------------------------------------------------------------------------------
49739    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
49740          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
49741          ,p_balance_type_code => l_balance_type_code
49742          );
49743 
49744    -------------------------------------------------------------------------------------------
49745    -- 4262811 - Generate the Accrual Reversal lines
49746    -------------------------------------------------------------------------------------------
49747    BEGIN
49748       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
49749                               (g_array_event(p_event_id).array_value_num('header_index'));
49750       IF l_acc_rev_flag IS NULL THEN
49751          l_acc_rev_flag := 'N';
49752       END IF;
49753    EXCEPTION
49754       WHEN OTHERS THEN
49755          l_acc_rev_flag := 'N';
49756    END;
49757    --
49758    IF (l_acc_rev_flag = 'Y') THEN
49759 
49760        -- 4645092  ------------------------------------------------------------------------------
49761        -- To allow MPA report to determine if it should generate report process
49762        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
49763        ------------------------------------------------------------------------------------------
49764 
49765        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
49766        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
49767    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
49768    -- call ADRs
49769    -- Bug 4922099
49770    --
49771    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
49772         (NVL(l_actual_upg_option, 'N') = 'O') OR
49773         (NVL(l_enc_upg_option, 'N') = 'O')
49774       )
49775    THEN
49776    NULL;
49777    --
49778    --
49779    
49780   l_ccid := AcctDerRule_7(
49781            p_application_id           => p_application_id
49782          , p_ae_header_id             => l_ae_header_id 
49783 , p_source_3 => p_source_3
49784          , x_transaction_coa_id       => l_adr_transaction_coa_id
49785          , x_accounting_coa_id        => l_adr_accounting_coa_id
49786          , x_value_type_code          => l_adr_value_type_code
49787          , p_side                     => 'NA'
49788    );
49789 
49790    xla_ae_lines_pkg.set_ccid(
49791     p_code_combination_id          => l_ccid
49792   , p_value_type_code              => l_adr_value_type_code
49793   , p_transaction_coa_id           => l_adr_transaction_coa_id
49794   , p_accounting_coa_id            => l_adr_accounting_coa_id
49795   , p_adr_code                     => 'DIST_CCID'
49796   , p_adr_type_code                => 'S'
49797   , p_component_type               => l_component_type
49798   , p_component_code               => l_component_code
49799   , p_component_type_code          => l_component_type_code
49800   , p_component_appl_id            => l_component_appl_id
49801   , p_amb_context_code             => l_amb_context_code
49802   , p_side                         => 'NA'
49803   );
49804 
49805 
49806    --
49807    --
49808    END IF;
49809 
49810        --
49811        -- Update the line information that should be overwritten
49812        --
49813        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
49814                                          p_header_num   => 1);
49815        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
49816 
49817        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
49818 
49819        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
49820           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
49821        END IF;
49822 
49823       --
49824       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
49825       --
49826       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
49830           -- 4262811a Switch Sign
49827           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
49828       ELSE
49829           ---------------------------------------------------------------------------------------------------
49831           ---------------------------------------------------------------------------------------------------
49832           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
49833           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
49834                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
49835           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
49836                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
49837           -- 5132302
49838           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
49839                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
49840 
49841       END IF;
49842 
49843       -- 4955764
49844       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
49845       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
49846 
49847 
49848       XLA_AE_LINES_PKG.ValidateCurrentLine;
49849       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
49850 
49851       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
49852                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
49853                ,p_balance_type_code => l_balance_type_code);
49854 
49855    END IF;
49856 
49857    -----------------------------------------------------------------------------------------
49858    -- 4262811 Multiperiod Accounting
49859    -----------------------------------------------------------------------------------------
49860      -- No MPA option is assigned.
49861 
49862 
49863 END IF;
49864 END IF;
49865 --
49866 
49867 --
49868 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
49869    trace
49870       (p_msg      => 'END of AcctLineType_104'
49871       ,p_level    => C_LEVEL_PROCEDURE
49872       ,p_module   => l_log_module);
49873 END IF;
49874 --
49875 EXCEPTION
49876   WHEN xla_exceptions_pkg.application_exception THEN
49877       RAISE;
49878   WHEN OTHERS THEN
49879        xla_exceptions_pkg.raise_message
49880            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_104');
49881 END AcctLineType_104;
49882 --
49883 
49884 ---------------------------------------
49885 --
49886 -- PRIVATE FUNCTION
49887 --         AcctLineType_105
49888 --
49889 ---------------------------------------
49890 PROCEDURE AcctLineType_105 (
49891   p_application_id        IN NUMBER
49892  ,p_event_id              IN NUMBER
49893  ,p_calculate_acctd_flag  IN VARCHAR2
49894  ,p_calculate_g_l_flag    IN VARCHAR2
49895  ,p_actual_flag           IN OUT VARCHAR2
49896  ,p_balance_type_code     OUT VARCHAR2
49897  ,p_gain_or_loss_ref      OUT VARCHAR2
49898  
49899 --Distribution GL Account
49900  , p_source_3            IN NUMBER
49901 --Distribution Source Type
49902  , p_source_20            IN VARCHAR2
49903 --Distribution Line Identifier
49904  , p_source_22            IN NUMBER
49905 --Distribution Type
49906  , p_source_23            IN VARCHAR2
49907 --Entered Amount
49908  , p_source_24            IN NUMBER
49909 --Currency Code
49910  , p_source_25            IN VARCHAR2
49911 --Exchange Rate
49912  , p_source_27            IN NUMBER
49913 --Exchange Rate Type
49914  , p_source_28            IN VARCHAR2
49915 --Applied To Document Accounting Amount
49916  , p_source_29            IN NUMBER
49917 --Applied To Document Exchange Date
49918  , p_source_57            IN DATE
49919 --Distribution Multi Fund Additional Entry
49920  , p_source_69            IN VARCHAR2
49921 )
49922 IS
49923 
49924 l_component_type              VARCHAR2(80);
49925 l_component_code              VARCHAR2(30);
49926 l_component_type_code         VARCHAR2(1);
49927 l_component_appl_id           INTEGER;
49928 l_amb_context_code            VARCHAR2(30);
49929 l_entity_code                 VARCHAR2(30);
49930 l_event_class_code            VARCHAR2(30);
49931 l_ae_header_id                NUMBER;
49932 l_event_type_code             VARCHAR2(30);
49933 l_line_definition_code        VARCHAR2(30);
49934 l_line_definition_owner_code  VARCHAR2(1);
49935 --
49936 -- adr variables
49937 l_segment                     VARCHAR2(30);
49938 l_ccid                        NUMBER;
49939 l_adr_transaction_coa_id      NUMBER;
49940 l_adr_accounting_coa_id       NUMBER;
49941 l_adr_flexfield_segment_code  VARCHAR2(30);
49942 l_adr_flex_value_set_id       NUMBER;
49943 l_adr_value_type_code         VARCHAR2(30);
49944 l_adr_value_combination_id    NUMBER;
49945 l_adr_value_segment_code      VARCHAR2(30);
49946 
49947 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
49948 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
49949 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
49950 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
49951 
49955 l_acc_rev_flag                VARCHAR2(1);
49952 -- 4262811 Variables ------------------------------------------------------------------------------------------
49953 l_entered_amt_idx             NUMBER;
49954 l_accted_amt_idx              NUMBER;
49956 l_accrual_line_num            NUMBER;
49957 l_tmp_amt                     NUMBER;
49958 l_acc_rev_natural_side_code   VARCHAR2(1);
49959 
49960 l_num_entries                 NUMBER;
49961 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
49962 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
49963 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
49964 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
49965 l_recog_line_1                NUMBER;
49966 l_recog_line_2                NUMBER;
49967 
49968 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
49969 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
49970 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
49971 
49972 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
49973 
49974 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
49975 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
49976 
49977 ---------------------------------------------------------------------------------------------------------------
49978 
49979 
49980 --
49981 -- bulk performance
49982 --
49983 l_balance_type_code           VARCHAR2(1);
49984 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
49985 l_log_module                  VARCHAR2(240);
49986 
49987 --
49988 -- Upgrade strategy
49989 --
49990 l_actual_upg_option           VARCHAR2(1);
49991 l_enc_upg_option           VARCHAR2(1);
49992 
49993 --
49994 BEGIN
49995 --
49996 IF g_log_enabled THEN
49997       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_105';
49998 END IF;
49999 --
50000 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
50001 
50002       trace
50003          (p_msg      => 'BEGIN of AcctLineType_105'
50004          ,p_level    => C_LEVEL_PROCEDURE
50005          ,p_module   => l_log_module);
50006 
50007 END IF;
50008 --
50009 l_component_type             := 'AMB_JLT';
50010 l_component_code             := 'MISC_RCT_MISCCASH';
50011 l_component_type_code        := 'S';
50012 l_component_appl_id          :=  222;
50013 l_amb_context_code           := 'DEFAULT';
50014 l_entity_code                := 'RECEIPTS';
50015 l_event_class_code           := 'MISC_RECEIPT';
50016 l_event_type_code            := 'MISC_RECEIPT_ALL';
50017 l_line_definition_owner_code := 'S';
50018 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
50019 --
50020 l_balance_type_code          := 'A';
50021 l_segment                     := NULL;
50022 l_ccid                        := NULL;
50023 l_adr_transaction_coa_id      := NULL;
50024 l_adr_accounting_coa_id       := NULL;
50025 l_adr_flexfield_segment_code  := NULL;
50026 l_adr_flex_value_set_id       := NULL;
50027 l_adr_value_type_code         := NULL;
50028 l_adr_value_combination_id    := NULL;
50029 l_adr_value_segment_code      := NULL;
50030 
50031 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
50032 l_bflow_class_code           := '';    -- 4219869 Business Flow
50033 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
50034 l_budgetary_control_flag     := 'N';
50035 
50036 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
50037 l_bflow_applied_to_amt       := NULL; -- 5132302
50038 l_entered_amt_idx            := NULL;          -- 4262811
50039 l_accted_amt_idx             := NULL;          -- 4262811
50040 l_acc_rev_flag               := NULL;          -- 4262811
50041 l_accrual_line_num           := NULL;          -- 4262811
50042 l_tmp_amt                    := NULL;          -- 4262811
50043 --
50044  
50045 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
50046     l_balance_type_code <> 'B' THEN
50047 IF NVL(p_source_20,'
50048 ') =  'MISCCASH' AND 
50049 NVL(p_source_69,'
50050 ') =  'N'
50051  THEN 
50052 
50053    --
50054    XLA_AE_LINES_PKG.SetNewLine;
50055 
50056    p_balance_type_code          := l_balance_type_code;
50057    -- set the flag so later we will know whether the gain loss line needs to be created
50058    
50059    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
50060      p_actual_flag :='A';
50061    END IF;
50062 
50063    --
50064    -- bulk performance
50065    --
50066    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
50067                                       p_header_num   => 0); -- 4262811
50068    --
50069    -- set accounting line options
50070    --
50071    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
50072            p_natural_side_code          => 'C'
50073          , p_gain_or_loss_flag          => 'N'
50074          , p_gl_transfer_mode_code      => 'S'
50075          , p_acct_entry_type_code       => 'A'
50076          , p_switch_side_flag           => 'Y'
50077          , p_merge_duplicate_code       => 'A'
50078          );
50079    --
50080    l_acc_rev_natural_side_code := 'D';  -- 4262811
50081    -- 
50082    --
50086       (p_component_type             => l_component_type
50083    -- set accounting line type info
50084    --
50085    xla_ae_lines_pkg.SetAcctLineType
50087       ,p_event_type_code            => l_event_type_code
50088       ,p_line_definition_owner_code => l_line_definition_owner_code
50089       ,p_line_definition_code       => l_line_definition_code
50090       ,p_accounting_line_code       => l_component_code
50091       ,p_accounting_line_type_code  => l_component_type_code
50092       ,p_accounting_line_appl_id    => l_component_appl_id
50093       ,p_amb_context_code           => l_amb_context_code
50094       ,p_entity_code                => l_entity_code
50095       ,p_event_class_code           => l_event_class_code);
50096    --
50097    -- set accounting class
50098    --
50099    xla_ae_lines_pkg.SetAcctClass(
50100            p_accounting_class_code  => 'MISC_CASH'
50101          , p_ae_header_id           => l_ae_header_id
50102          );
50103 
50104    --
50105    -- set rounding class
50106    --
50107    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
50108                       'RECEIVABLE';
50109 
50110    --
50111    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
50112    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
50113    --
50114    -- bulk performance
50115    --
50116    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
50117 
50118    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
50119       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
50120 
50121    -- 4955764
50122    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
50123       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
50124 
50125    -- 4458381 Public Sector Enh
50126    
50127    --
50128    -- set accounting attributes for the line type
50129    --
50130    l_entered_amt_idx := 3;
50131    l_accted_amt_idx  := 8;
50132    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
50133    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
50134    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
50135    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
50136    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
50137    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
50138    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
50139    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
50140    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
50141    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
50142    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
50143    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
50144    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
50145    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
50146    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
50147    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
50148    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
50149 
50150    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
50151    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
50152 
50153    ---------------------------------------------------------------------------------------------------------------
50154    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
50155    ---------------------------------------------------------------------------------------------------------------
50156    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
50157 
50158    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
50159    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
50160 
50161    IF xla_accounting_cache_pkg.GetValueChar
50162          (p_source_code         => 'LEDGER_CATEGORY_CODE'
50163          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
50164    AND l_bflow_method_code = 'PRIOR_ENTRY'
50165 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
50166    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
50167          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
50168        )
50169    THEN
50170          xla_ae_lines_pkg.BflowUpgEntry
50171            (p_business_method_code    => l_bflow_method_code
50172            ,p_business_class_code     => l_bflow_class_code
50173            ,p_balance_type            => l_balance_type_code);
50174    ELSE
50175       NULL;
50176 -- No business flow processing for business flow method of NONE.
50177    END IF;
50178 
50179    --
50180    -- call analytical criteria
50181    --
50182    
50183    --
50184    -- call description
50185    --
50186    -- No description or it is inherited.
50187    --
50188    -- call ADRs
50189    -- Bug 4922099
50190    --
50191    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
50192         (NVL(l_actual_upg_option, 'N') = 'O') OR
50193         (NVL(l_enc_upg_option, 'N') = 'O')
50194       )
50198    --
50195    THEN
50196    NULL;
50197    --
50199    
50200   l_ccid := AcctDerRule_7(
50201            p_application_id           => p_application_id
50202          , p_ae_header_id             => l_ae_header_id 
50203 , p_source_3 => p_source_3
50204          , x_transaction_coa_id       => l_adr_transaction_coa_id
50205          , x_accounting_coa_id        => l_adr_accounting_coa_id
50206          , x_value_type_code          => l_adr_value_type_code
50207          , p_side                     => 'NA'
50208    );
50209 
50210    xla_ae_lines_pkg.set_ccid(
50211     p_code_combination_id          => l_ccid
50212   , p_value_type_code              => l_adr_value_type_code
50213   , p_transaction_coa_id           => l_adr_transaction_coa_id
50214   , p_accounting_coa_id            => l_adr_accounting_coa_id
50215   , p_adr_code                     => 'DIST_CCID'
50216   , p_adr_type_code                => 'S'
50217   , p_component_type               => l_component_type
50218   , p_component_code               => l_component_code
50219   , p_component_type_code          => l_component_type_code
50220   , p_component_appl_id            => l_component_appl_id
50221   , p_amb_context_code             => l_amb_context_code
50222   , p_side                         => 'NA'
50223   );
50224 
50225 
50226    --
50227    --
50228    END IF;
50229    --
50230    -- Bug 4922099
50231    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
50232           (NVL(l_enc_upg_option, 'N') = 'O')
50233         ) AND
50234         (l_bflow_method_code = 'PRIOR_ENTRY')
50235       )
50236    THEN
50237       IF
50238       --
50239       1 = 2
50240       --
50241       THEN
50242       xla_accounting_err_pkg.build_message
50243                                     (p_appli_s_name            => 'XLA'
50244                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
50245                                     ,p_token_1                 => 'LINE_NUMBER'
50246                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
50247                                     ,p_token_2                 => 'LINE_TYPE_NAME'
50248                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
50249                                                                              l_component_type
50250                                                                             ,l_component_code
50251                                                                             ,l_component_type_code
50252                                                                             ,l_component_appl_id
50253                                                                             ,l_amb_context_code
50254                                                                             ,l_entity_code
50255                                                                             ,l_event_class_code
50256                                                                            )
50257                                     ,p_token_3                 => 'OWNER'
50258                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
50259                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
50260                                                                           ,p_lookup_code    => l_component_type_code
50261                                                                          )
50262                                     ,p_token_4                 => 'PRODUCT_NAME'
50263                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
50264                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
50265                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
50266                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
50267                                     ,p_ae_header_id            =>  NULL
50268                                        );
50269 
50270         IF (C_LEVEL_ERROR>= g_log_level) THEN
50271                  trace
50272                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
50273                       ,p_level    => C_LEVEL_ERROR
50274                       ,p_module   => l_log_module);
50275         END IF;
50276       END IF;
50277    END IF;
50278    --
50279    --
50280    ------------------------------------------------------------------------------------------------
50281    -- 4219869 Business Flow
50282    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
50283    -- Prior Entry.  Currently, the following code is always generated.
50284    ------------------------------------------------------------------------------------------------
50285    XLA_AE_LINES_PKG.ValidateCurrentLine;
50286 
50287    ------------------------------------------------------------------------------------
50288    -- 4219869 Business Flow
50289    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
50290    ------------------------------------------------------------------------------------
50291    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
50292 
50293    ----------------------------------------------------------------------------------
50294    -- 4219869 Business Flow
50295    -- Update journal entry status -- Need to generate this within IF <condition>
50296    ----------------------------------------------------------------------------------
50300          );
50297    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
50298          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
50299          ,p_balance_type_code => l_balance_type_code
50301 
50302    -------------------------------------------------------------------------------------------
50303    -- 4262811 - Generate the Accrual Reversal lines
50304    -------------------------------------------------------------------------------------------
50305    BEGIN
50306       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
50307                               (g_array_event(p_event_id).array_value_num('header_index'));
50308       IF l_acc_rev_flag IS NULL THEN
50309          l_acc_rev_flag := 'N';
50310       END IF;
50311    EXCEPTION
50312       WHEN OTHERS THEN
50313          l_acc_rev_flag := 'N';
50314    END;
50315    --
50316    IF (l_acc_rev_flag = 'Y') THEN
50317 
50318        -- 4645092  ------------------------------------------------------------------------------
50319        -- To allow MPA report to determine if it should generate report process
50320        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
50321        ------------------------------------------------------------------------------------------
50322 
50323        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
50324        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
50325    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
50326    -- call ADRs
50327    -- Bug 4922099
50328    --
50329    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
50330         (NVL(l_actual_upg_option, 'N') = 'O') OR
50331         (NVL(l_enc_upg_option, 'N') = 'O')
50332       )
50333    THEN
50334    NULL;
50335    --
50336    --
50337    
50338   l_ccid := AcctDerRule_7(
50339            p_application_id           => p_application_id
50340          , p_ae_header_id             => l_ae_header_id 
50341 , p_source_3 => p_source_3
50342          , x_transaction_coa_id       => l_adr_transaction_coa_id
50343          , x_accounting_coa_id        => l_adr_accounting_coa_id
50344          , x_value_type_code          => l_adr_value_type_code
50345          , p_side                     => 'NA'
50346    );
50347 
50348    xla_ae_lines_pkg.set_ccid(
50349     p_code_combination_id          => l_ccid
50350   , p_value_type_code              => l_adr_value_type_code
50351   , p_transaction_coa_id           => l_adr_transaction_coa_id
50352   , p_accounting_coa_id            => l_adr_accounting_coa_id
50353   , p_adr_code                     => 'DIST_CCID'
50354   , p_adr_type_code                => 'S'
50355   , p_component_type               => l_component_type
50356   , p_component_code               => l_component_code
50357   , p_component_type_code          => l_component_type_code
50358   , p_component_appl_id            => l_component_appl_id
50359   , p_amb_context_code             => l_amb_context_code
50360   , p_side                         => 'NA'
50361   );
50362 
50363 
50364    --
50365    --
50366    END IF;
50367 
50368        --
50369        -- Update the line information that should be overwritten
50370        --
50371        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
50372                                          p_header_num   => 1);
50373        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
50374 
50375        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
50376 
50377        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
50378           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
50379        END IF;
50380 
50381       --
50382       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
50383       --
50384       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
50385           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
50386       ELSE
50387           ---------------------------------------------------------------------------------------------------
50388           -- 4262811a Switch Sign
50389           ---------------------------------------------------------------------------------------------------
50390           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
50391           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
50392                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
50393           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
50394                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
50395           -- 5132302
50396           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
50397                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
50398 
50399       END IF;
50400 
50401       -- 4955764
50402       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
50403       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
50404 
50405 
50406       XLA_AE_LINES_PKG.ValidateCurrentLine;
50410                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
50407       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
50408 
50409       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
50411                ,p_balance_type_code => l_balance_type_code);
50412 
50413    END IF;
50414 
50415    -----------------------------------------------------------------------------------------
50416    -- 4262811 Multiperiod Accounting
50417    -----------------------------------------------------------------------------------------
50418      -- No MPA option is assigned.
50419 
50420 
50421 END IF;
50422 END IF;
50423 --
50424 
50425 --
50426 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
50427    trace
50428       (p_msg      => 'END of AcctLineType_105'
50429       ,p_level    => C_LEVEL_PROCEDURE
50430       ,p_module   => l_log_module);
50431 END IF;
50432 --
50433 EXCEPTION
50434   WHEN xla_exceptions_pkg.application_exception THEN
50435       RAISE;
50436   WHEN OTHERS THEN
50437        xla_exceptions_pkg.raise_message
50438            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_105');
50439 END AcctLineType_105;
50440 --
50441 
50442 ---------------------------------------
50443 --
50444 -- PRIVATE FUNCTION
50445 --         AcctLineType_106
50446 --
50447 ---------------------------------------
50448 PROCEDURE AcctLineType_106 (
50449   p_application_id        IN NUMBER
50450  ,p_event_id              IN NUMBER
50451  ,p_calculate_acctd_flag  IN VARCHAR2
50452  ,p_calculate_g_l_flag    IN VARCHAR2
50453  ,p_actual_flag           IN OUT VARCHAR2
50454  ,p_balance_type_code     OUT VARCHAR2
50455  ,p_gain_or_loss_ref      OUT VARCHAR2
50456  
50457 --Distribution GL Account
50458  , p_source_3            IN NUMBER
50459 --Distribution Source Type
50460  , p_source_20            IN VARCHAR2
50461 --Distribution Line Identifier
50462  , p_source_22            IN NUMBER
50463 --Distribution Type
50464  , p_source_23            IN VARCHAR2
50465 --Entered Amount
50466  , p_source_24            IN NUMBER
50467 --Currency Code
50468  , p_source_25            IN VARCHAR2
50469 --Exchange Rate
50470  , p_source_27            IN NUMBER
50471 --Exchange Rate Type
50472  , p_source_28            IN VARCHAR2
50473 --Applied To Document Accounting Amount
50474  , p_source_29            IN NUMBER
50475 --Applied To Document Exchange Date
50476  , p_source_57            IN DATE
50477 --Distribution Multi Fund Additional Entry
50478  , p_source_69            IN VARCHAR2
50479 )
50480 IS
50481 
50482 l_component_type              VARCHAR2(80);
50483 l_component_code              VARCHAR2(30);
50484 l_component_type_code         VARCHAR2(1);
50485 l_component_appl_id           INTEGER;
50486 l_amb_context_code            VARCHAR2(30);
50487 l_entity_code                 VARCHAR2(30);
50488 l_event_class_code            VARCHAR2(30);
50489 l_ae_header_id                NUMBER;
50490 l_event_type_code             VARCHAR2(30);
50491 l_line_definition_code        VARCHAR2(30);
50492 l_line_definition_owner_code  VARCHAR2(1);
50493 --
50494 -- adr variables
50495 l_segment                     VARCHAR2(30);
50496 l_ccid                        NUMBER;
50497 l_adr_transaction_coa_id      NUMBER;
50498 l_adr_accounting_coa_id       NUMBER;
50499 l_adr_flexfield_segment_code  VARCHAR2(30);
50500 l_adr_flex_value_set_id       NUMBER;
50501 l_adr_value_type_code         VARCHAR2(30);
50502 l_adr_value_combination_id    NUMBER;
50503 l_adr_value_segment_code      VARCHAR2(30);
50504 
50505 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
50506 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
50507 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
50508 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
50509 
50510 -- 4262811 Variables ------------------------------------------------------------------------------------------
50511 l_entered_amt_idx             NUMBER;
50512 l_accted_amt_idx              NUMBER;
50513 l_acc_rev_flag                VARCHAR2(1);
50514 l_accrual_line_num            NUMBER;
50515 l_tmp_amt                     NUMBER;
50516 l_acc_rev_natural_side_code   VARCHAR2(1);
50517 
50518 l_num_entries                 NUMBER;
50519 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
50520 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
50521 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
50522 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
50523 l_recog_line_1                NUMBER;
50524 l_recog_line_2                NUMBER;
50525 
50526 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
50527 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
50528 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
50529 
50530 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
50531 
50532 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
50533 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
50534 
50535 ---------------------------------------------------------------------------------------------------------------
50536 
50537 
50538 --
50539 -- bulk performance
50540 --
50544 
50541 l_balance_type_code           VARCHAR2(1);
50542 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
50543 l_log_module                  VARCHAR2(240);
50545 --
50546 -- Upgrade strategy
50547 --
50548 l_actual_upg_option           VARCHAR2(1);
50549 l_enc_upg_option           VARCHAR2(1);
50550 
50551 --
50552 BEGIN
50553 --
50554 IF g_log_enabled THEN
50555       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_106';
50556 END IF;
50557 --
50558 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
50559 
50560       trace
50561          (p_msg      => 'BEGIN of AcctLineType_106'
50562          ,p_level    => C_LEVEL_PROCEDURE
50563          ,p_module   => l_log_module);
50564 
50565 END IF;
50566 --
50567 l_component_type             := 'AMB_JLT';
50568 l_component_code             := 'MISC_RCT_TAX';
50569 l_component_type_code        := 'S';
50570 l_component_appl_id          :=  222;
50571 l_amb_context_code           := 'DEFAULT';
50572 l_entity_code                := 'RECEIPTS';
50573 l_event_class_code           := 'MISC_RECEIPT';
50574 l_event_type_code            := 'MISC_RECEIPT_ALL';
50575 l_line_definition_owner_code := 'S';
50576 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
50577 --
50578 l_balance_type_code          := 'A';
50579 l_segment                     := NULL;
50580 l_ccid                        := NULL;
50581 l_adr_transaction_coa_id      := NULL;
50582 l_adr_accounting_coa_id       := NULL;
50583 l_adr_flexfield_segment_code  := NULL;
50584 l_adr_flex_value_set_id       := NULL;
50585 l_adr_value_type_code         := NULL;
50586 l_adr_value_combination_id    := NULL;
50587 l_adr_value_segment_code      := NULL;
50588 
50589 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
50590 l_bflow_class_code           := '';    -- 4219869 Business Flow
50591 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
50592 l_budgetary_control_flag     := 'N';
50593 
50594 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
50595 l_bflow_applied_to_amt       := NULL; -- 5132302
50596 l_entered_amt_idx            := NULL;          -- 4262811
50597 l_accted_amt_idx             := NULL;          -- 4262811
50598 l_acc_rev_flag               := NULL;          -- 4262811
50599 l_accrual_line_num           := NULL;          -- 4262811
50600 l_tmp_amt                    := NULL;          -- 4262811
50601 --
50602  
50603 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
50604     l_balance_type_code <> 'B' THEN
50605 IF NVL(p_source_20,'
50606 ') =  'TAX' AND 
50607 NVL(p_source_69,'
50608 ') =  'N'
50609  THEN 
50610 
50611    --
50612    XLA_AE_LINES_PKG.SetNewLine;
50613 
50614    p_balance_type_code          := l_balance_type_code;
50615    -- set the flag so later we will know whether the gain loss line needs to be created
50616    
50617    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
50618      p_actual_flag :='A';
50619    END IF;
50620 
50621    --
50622    -- bulk performance
50623    --
50624    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
50625                                       p_header_num   => 0); -- 4262811
50626    --
50627    -- set accounting line options
50628    --
50629    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
50630            p_natural_side_code          => 'C'
50631          , p_gain_or_loss_flag          => 'N'
50632          , p_gl_transfer_mode_code      => 'S'
50633          , p_acct_entry_type_code       => 'A'
50634          , p_switch_side_flag           => 'Y'
50635          , p_merge_duplicate_code       => 'A'
50636          );
50637    --
50638    l_acc_rev_natural_side_code := 'D';  -- 4262811
50639    -- 
50640    --
50641    -- set accounting line type info
50642    --
50643    xla_ae_lines_pkg.SetAcctLineType
50644       (p_component_type             => l_component_type
50645       ,p_event_type_code            => l_event_type_code
50646       ,p_line_definition_owner_code => l_line_definition_owner_code
50647       ,p_line_definition_code       => l_line_definition_code
50648       ,p_accounting_line_code       => l_component_code
50649       ,p_accounting_line_type_code  => l_component_type_code
50650       ,p_accounting_line_appl_id    => l_component_appl_id
50651       ,p_amb_context_code           => l_amb_context_code
50652       ,p_entity_code                => l_entity_code
50653       ,p_event_class_code           => l_event_class_code);
50654    --
50655    -- set accounting class
50656    --
50657    xla_ae_lines_pkg.SetAcctClass(
50658            p_accounting_class_code  => 'TAX'
50659          , p_ae_header_id           => l_ae_header_id
50660          );
50661 
50662    --
50663    -- set rounding class
50664    --
50665    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
50666                       'RECEIVABLE';
50667 
50668    --
50669    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
50670    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
50671    --
50672    -- bulk performance
50673    --
50677       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
50674    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
50675 
50676    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
50678 
50679    -- 4955764
50680    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
50681       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
50682 
50683    -- 4458381 Public Sector Enh
50684    
50685    --
50686    -- set accounting attributes for the line type
50687    --
50688    l_entered_amt_idx := 3;
50689    l_accted_amt_idx  := 8;
50690    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
50691    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
50692    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_22);
50693    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
50694    l_rec_acct_attrs.array_char_value(2)  := p_source_23;
50695    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
50696    l_rec_acct_attrs.array_num_value(3)  := p_source_24;
50697    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
50698    l_rec_acct_attrs.array_char_value(4)  := p_source_25;
50699    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
50700    l_rec_acct_attrs.array_date_value(5)  := p_source_57;
50701    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
50702    l_rec_acct_attrs.array_num_value(6)  := p_source_27;
50703    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
50704    l_rec_acct_attrs.array_char_value(7)  := p_source_28;
50705    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
50706    l_rec_acct_attrs.array_num_value(8)  := p_source_29;
50707 
50708    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
50709    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
50710 
50711    ---------------------------------------------------------------------------------------------------------------
50712    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
50713    ---------------------------------------------------------------------------------------------------------------
50714    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
50715 
50716    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
50717    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
50718 
50719    IF xla_accounting_cache_pkg.GetValueChar
50720          (p_source_code         => 'LEDGER_CATEGORY_CODE'
50721          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
50722    AND l_bflow_method_code = 'PRIOR_ENTRY'
50723 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
50724    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
50725          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
50726        )
50727    THEN
50728          xla_ae_lines_pkg.BflowUpgEntry
50729            (p_business_method_code    => l_bflow_method_code
50730            ,p_business_class_code     => l_bflow_class_code
50731            ,p_balance_type            => l_balance_type_code);
50732    ELSE
50733       NULL;
50734 -- No business flow processing for business flow method of NONE.
50735    END IF;
50736 
50737    --
50738    -- call analytical criteria
50739    --
50740    
50741    --
50742    -- call description
50743    --
50744    -- No description or it is inherited.
50745    --
50746    -- call ADRs
50747    -- Bug 4922099
50748    --
50749    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
50750         (NVL(l_actual_upg_option, 'N') = 'O') OR
50751         (NVL(l_enc_upg_option, 'N') = 'O')
50752       )
50753    THEN
50754    NULL;
50755    --
50756    --
50757    
50758   l_ccid := AcctDerRule_7(
50759            p_application_id           => p_application_id
50760          , p_ae_header_id             => l_ae_header_id 
50761 , p_source_3 => p_source_3
50762          , x_transaction_coa_id       => l_adr_transaction_coa_id
50763          , x_accounting_coa_id        => l_adr_accounting_coa_id
50764          , x_value_type_code          => l_adr_value_type_code
50765          , p_side                     => 'NA'
50766    );
50767 
50768    xla_ae_lines_pkg.set_ccid(
50769     p_code_combination_id          => l_ccid
50770   , p_value_type_code              => l_adr_value_type_code
50771   , p_transaction_coa_id           => l_adr_transaction_coa_id
50772   , p_accounting_coa_id            => l_adr_accounting_coa_id
50773   , p_adr_code                     => 'DIST_CCID'
50774   , p_adr_type_code                => 'S'
50775   , p_component_type               => l_component_type
50776   , p_component_code               => l_component_code
50777   , p_component_type_code          => l_component_type_code
50778   , p_component_appl_id            => l_component_appl_id
50779   , p_amb_context_code             => l_amb_context_code
50780   , p_side                         => 'NA'
50781   );
50782 
50783 
50784    --
50785    --
50786    END IF;
50787    --
50788    -- Bug 4922099
50789    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
50793       )
50790           (NVL(l_enc_upg_option, 'N') = 'O')
50791         ) AND
50792         (l_bflow_method_code = 'PRIOR_ENTRY')
50794    THEN
50795       IF
50796       --
50797       1 = 2
50798       --
50799       THEN
50800       xla_accounting_err_pkg.build_message
50801                                     (p_appli_s_name            => 'XLA'
50802                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
50803                                     ,p_token_1                 => 'LINE_NUMBER'
50804                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
50805                                     ,p_token_2                 => 'LINE_TYPE_NAME'
50806                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
50807                                                                              l_component_type
50808                                                                             ,l_component_code
50809                                                                             ,l_component_type_code
50810                                                                             ,l_component_appl_id
50811                                                                             ,l_amb_context_code
50812                                                                             ,l_entity_code
50813                                                                             ,l_event_class_code
50814                                                                            )
50815                                     ,p_token_3                 => 'OWNER'
50816                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
50817                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
50818                                                                           ,p_lookup_code    => l_component_type_code
50819                                                                          )
50820                                     ,p_token_4                 => 'PRODUCT_NAME'
50821                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
50822                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
50823                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
50824                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
50825                                     ,p_ae_header_id            =>  NULL
50826                                        );
50827 
50828         IF (C_LEVEL_ERROR>= g_log_level) THEN
50829                  trace
50830                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
50831                       ,p_level    => C_LEVEL_ERROR
50832                       ,p_module   => l_log_module);
50833         END IF;
50834       END IF;
50835    END IF;
50836    --
50837    --
50838    ------------------------------------------------------------------------------------------------
50839    -- 4219869 Business Flow
50840    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
50841    -- Prior Entry.  Currently, the following code is always generated.
50842    ------------------------------------------------------------------------------------------------
50843    XLA_AE_LINES_PKG.ValidateCurrentLine;
50844 
50845    ------------------------------------------------------------------------------------
50846    -- 4219869 Business Flow
50847    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
50848    ------------------------------------------------------------------------------------
50849    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
50850 
50851    ----------------------------------------------------------------------------------
50852    -- 4219869 Business Flow
50853    -- Update journal entry status -- Need to generate this within IF <condition>
50854    ----------------------------------------------------------------------------------
50855    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
50856          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
50857          ,p_balance_type_code => l_balance_type_code
50858          );
50859 
50860    -------------------------------------------------------------------------------------------
50861    -- 4262811 - Generate the Accrual Reversal lines
50862    -------------------------------------------------------------------------------------------
50863    BEGIN
50864       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
50865                               (g_array_event(p_event_id).array_value_num('header_index'));
50866       IF l_acc_rev_flag IS NULL THEN
50867          l_acc_rev_flag := 'N';
50868       END IF;
50869    EXCEPTION
50870       WHEN OTHERS THEN
50871          l_acc_rev_flag := 'N';
50872    END;
50873    --
50874    IF (l_acc_rev_flag = 'Y') THEN
50875 
50876        -- 4645092  ------------------------------------------------------------------------------
50877        -- To allow MPA report to determine if it should generate report process
50878        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
50879        ------------------------------------------------------------------------------------------
50880 
50881        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
50882        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
50886    --
50883    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
50884    -- call ADRs
50885    -- Bug 4922099
50887    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
50888         (NVL(l_actual_upg_option, 'N') = 'O') OR
50889         (NVL(l_enc_upg_option, 'N') = 'O')
50890       )
50891    THEN
50892    NULL;
50893    --
50894    --
50895    
50896   l_ccid := AcctDerRule_7(
50897            p_application_id           => p_application_id
50898          , p_ae_header_id             => l_ae_header_id 
50899 , p_source_3 => p_source_3
50900          , x_transaction_coa_id       => l_adr_transaction_coa_id
50901          , x_accounting_coa_id        => l_adr_accounting_coa_id
50902          , x_value_type_code          => l_adr_value_type_code
50903          , p_side                     => 'NA'
50904    );
50905 
50906    xla_ae_lines_pkg.set_ccid(
50907     p_code_combination_id          => l_ccid
50908   , p_value_type_code              => l_adr_value_type_code
50909   , p_transaction_coa_id           => l_adr_transaction_coa_id
50910   , p_accounting_coa_id            => l_adr_accounting_coa_id
50911   , p_adr_code                     => 'DIST_CCID'
50912   , p_adr_type_code                => 'S'
50913   , p_component_type               => l_component_type
50914   , p_component_code               => l_component_code
50915   , p_component_type_code          => l_component_type_code
50916   , p_component_appl_id            => l_component_appl_id
50917   , p_amb_context_code             => l_amb_context_code
50918   , p_side                         => 'NA'
50919   );
50920 
50921 
50922    --
50923    --
50924    END IF;
50925 
50926        --
50927        -- Update the line information that should be overwritten
50928        --
50929        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
50930                                          p_header_num   => 1);
50931        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
50932 
50933        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
50934 
50935        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
50936           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
50937        END IF;
50938 
50939       --
50940       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
50941       --
50942       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
50943           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
50944       ELSE
50945           ---------------------------------------------------------------------------------------------------
50946           -- 4262811a Switch Sign
50947           ---------------------------------------------------------------------------------------------------
50948           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
50949           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
50950                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
50951           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
50952                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
50953           -- 5132302
50954           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
50955                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
50956 
50957       END IF;
50958 
50959       -- 4955764
50960       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
50961       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
50962 
50963 
50964       XLA_AE_LINES_PKG.ValidateCurrentLine;
50965       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
50966 
50967       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
50968                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
50969                ,p_balance_type_code => l_balance_type_code);
50970 
50971    END IF;
50972 
50973    -----------------------------------------------------------------------------------------
50974    -- 4262811 Multiperiod Accounting
50975    -----------------------------------------------------------------------------------------
50976      -- No MPA option is assigned.
50977 
50978 
50979 END IF;
50980 END IF;
50981 --
50982 
50983 --
50984 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
50985    trace
50986       (p_msg      => 'END of AcctLineType_106'
50987       ,p_level    => C_LEVEL_PROCEDURE
50988       ,p_module   => l_log_module);
50989 END IF;
50990 --
50991 EXCEPTION
50992   WHEN xla_exceptions_pkg.application_exception THEN
50993       RAISE;
50994   WHEN OTHERS THEN
50995        xla_exceptions_pkg.raise_message
50996            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_106');
50997 END AcctLineType_106;
50998 --
50999 
51000 ---------------------------------------
51001 --
51002 -- PRIVATE FUNCTION
51003 --         AcctLineType_107
51004 --
51005 ---------------------------------------
51006 PROCEDURE AcctLineType_107 (
51007   p_application_id        IN NUMBER
51011  ,p_actual_flag           IN OUT VARCHAR2
51008  ,p_event_id              IN NUMBER
51009  ,p_calculate_acctd_flag  IN VARCHAR2
51010  ,p_calculate_g_l_flag    IN VARCHAR2
51012  ,p_balance_type_code     OUT VARCHAR2
51013  ,p_gain_or_loss_ref      OUT VARCHAR2
51014  
51015 --Distribution GL Account
51016  , p_source_3            IN NUMBER
51017 --Distribution Source Type
51018  , p_source_20            IN VARCHAR2
51019 --Distribution Line Identifier
51020  , p_source_22            IN NUMBER
51021 --Distribution Type
51022  , p_source_23            IN VARCHAR2
51023 --Exchange Date
51024  , p_source_26            IN DATE
51025 --Exchange Rate
51026  , p_source_27            IN NUMBER
51027 --Exchange Rate Type
51028  , p_source_28            IN VARCHAR2
51029 --Transaction Distribution Identifier
51030  , p_source_34            IN NUMBER
51031 --Transaction Distribution Type
51032  , p_source_35            IN VARCHAR2
51033 --Receipt Applied To Application Identifier
51034  , p_source_58            IN NUMBER
51035 --Transaction Entity Code
51036  , p_source_59            IN VARCHAR2
51037 --Transaction Identifier
51038  , p_source_60            IN NUMBER
51039 --Applying Document Currency Code
51040  , p_source_61            IN VARCHAR2
51041 --Distribution Party Identifier
51042  , p_source_63            IN NUMBER
51043 --Distribution Party Site Id
51044  , p_source_64            IN NUMBER
51045 --Distribution Party Type
51046  , p_source_65            IN VARCHAR2
51047 --Distribution Multi Fund Additional Entry
51048  , p_source_69            IN VARCHAR2
51049 --DIST_ENT_AMT_FROM
51050  , p_source_72            IN NUMBER
51051 --Accounting Amount
51052  , p_source_73            IN NUMBER
51053 )
51054 IS
51055 
51056 l_component_type              VARCHAR2(80);
51057 l_component_code              VARCHAR2(30);
51058 l_component_type_code         VARCHAR2(1);
51059 l_component_appl_id           INTEGER;
51060 l_amb_context_code            VARCHAR2(30);
51061 l_entity_code                 VARCHAR2(30);
51062 l_event_class_code            VARCHAR2(30);
51063 l_ae_header_id                NUMBER;
51064 l_event_type_code             VARCHAR2(30);
51065 l_line_definition_code        VARCHAR2(30);
51066 l_line_definition_owner_code  VARCHAR2(1);
51067 --
51068 -- adr variables
51069 l_segment                     VARCHAR2(30);
51070 l_ccid                        NUMBER;
51071 l_adr_transaction_coa_id      NUMBER;
51072 l_adr_accounting_coa_id       NUMBER;
51073 l_adr_flexfield_segment_code  VARCHAR2(30);
51074 l_adr_flex_value_set_id       NUMBER;
51075 l_adr_value_type_code         VARCHAR2(30);
51076 l_adr_value_combination_id    NUMBER;
51077 l_adr_value_segment_code      VARCHAR2(30);
51078 
51079 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
51080 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
51081 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
51082 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
51083 
51084 -- 4262811 Variables ------------------------------------------------------------------------------------------
51085 l_entered_amt_idx             NUMBER;
51086 l_accted_amt_idx              NUMBER;
51087 l_acc_rev_flag                VARCHAR2(1);
51088 l_accrual_line_num            NUMBER;
51089 l_tmp_amt                     NUMBER;
51090 l_acc_rev_natural_side_code   VARCHAR2(1);
51091 
51092 l_num_entries                 NUMBER;
51093 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
51094 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
51095 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
51096 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
51097 l_recog_line_1                NUMBER;
51098 l_recog_line_2                NUMBER;
51099 
51100 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
51101 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
51102 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
51103 
51104 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
51105 
51106 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
51107 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
51108 
51109 ---------------------------------------------------------------------------------------------------------------
51110 
51111 
51112 --
51113 -- bulk performance
51114 --
51115 l_balance_type_code           VARCHAR2(1);
51116 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
51117 l_log_module                  VARCHAR2(240);
51118 
51119 --
51120 -- Upgrade strategy
51121 --
51122 l_actual_upg_option           VARCHAR2(1);
51123 l_enc_upg_option           VARCHAR2(1);
51124 
51125 --
51126 BEGIN
51127 --
51128 IF g_log_enabled THEN
51129       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_107';
51130 END IF;
51131 --
51132 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
51133 
51134       trace
51135          (p_msg      => 'BEGIN of AcctLineType_107'
51136          ,p_level    => C_LEVEL_PROCEDURE
51137          ,p_module   => l_log_module);
51138 
51139 END IF;
51140 --
51141 l_component_type             := 'AMB_JLT';
51145 l_amb_context_code           := 'DEFAULT';
51142 l_component_code             := 'RCT_ACC';
51143 l_component_type_code        := 'S';
51144 l_component_appl_id          :=  222;
51146 l_entity_code                := 'RECEIPTS';
51147 l_event_class_code           := 'RECEIPT';
51148 l_event_type_code            := 'RECEIPT_ALL';
51149 l_line_definition_owner_code := 'S';
51150 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
51151 --
51152 l_balance_type_code          := 'A';
51153 l_segment                     := NULL;
51154 l_ccid                        := NULL;
51155 l_adr_transaction_coa_id      := NULL;
51156 l_adr_accounting_coa_id       := NULL;
51157 l_adr_flexfield_segment_code  := NULL;
51158 l_adr_flex_value_set_id       := NULL;
51159 l_adr_value_type_code         := NULL;
51160 l_adr_value_combination_id    := NULL;
51161 l_adr_value_segment_code      := NULL;
51162 
51163 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
51164 l_bflow_class_code           := '';    -- 4219869 Business Flow
51165 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
51166 l_budgetary_control_flag     := 'N';
51167 
51168 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
51169 l_bflow_applied_to_amt       := NULL; -- 5132302
51170 l_entered_amt_idx            := NULL;          -- 4262811
51171 l_accted_amt_idx             := NULL;          -- 4262811
51172 l_acc_rev_flag               := NULL;          -- 4262811
51173 l_accrual_line_num           := NULL;          -- 4262811
51174 l_tmp_amt                    := NULL;          -- 4262811
51175 --
51176  
51177 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
51178     l_balance_type_code <> 'B' THEN
51179 IF NVL(p_source_20,'
51180 ') =  'ACC' AND 
51181 NVL(p_source_69,'
51182 ') =  'N'
51183  THEN 
51184 
51185    --
51186    XLA_AE_LINES_PKG.SetNewLine;
51187 
51188    p_balance_type_code          := l_balance_type_code;
51189    -- set the flag so later we will know whether the gain loss line needs to be created
51190    
51191    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
51192      p_actual_flag :='A';
51193    END IF;
51194 
51195    --
51196    -- bulk performance
51197    --
51198    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
51199                                       p_header_num   => 0); -- 4262811
51200    --
51201    -- set accounting line options
51202    --
51203    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
51204            p_natural_side_code          => 'C'
51205          , p_gain_or_loss_flag          => 'N'
51206          , p_gl_transfer_mode_code      => 'S'
51207          , p_acct_entry_type_code       => 'A'
51208          , p_switch_side_flag           => 'Y'
51209          , p_merge_duplicate_code       => 'A'
51210          );
51211    --
51212    l_acc_rev_natural_side_code := 'D';  -- 4262811
51213    -- 
51214    --
51215    -- set accounting line type info
51216    --
51217    xla_ae_lines_pkg.SetAcctLineType
51218       (p_component_type             => l_component_type
51219       ,p_event_type_code            => l_event_type_code
51220       ,p_line_definition_owner_code => l_line_definition_owner_code
51221       ,p_line_definition_code       => l_line_definition_code
51222       ,p_accounting_line_code       => l_component_code
51223       ,p_accounting_line_type_code  => l_component_type_code
51224       ,p_accounting_line_appl_id    => l_component_appl_id
51225       ,p_amb_context_code           => l_amb_context_code
51226       ,p_entity_code                => l_entity_code
51227       ,p_event_class_code           => l_event_class_code);
51228    --
51229    -- set accounting class
51230    --
51231    xla_ae_lines_pkg.SetAcctClass(
51232            p_accounting_class_code  => 'ACC'
51233          , p_ae_header_id           => l_ae_header_id
51234          );
51235 
51236    --
51237    -- set rounding class
51238    --
51239    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
51240                       'RECEIVABLE';
51241 
51242    --
51243    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
51244    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
51245    --
51246    -- bulk performance
51247    --
51248    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
51249 
51250    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
51251       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
51252 
51253    -- 4955764
51254    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
51255       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
51256 
51257    -- 4458381 Public Sector Enh
51258    
51259    --
51260    -- set accounting attributes for the line type
51261    --
51262    l_entered_amt_idx := 8;
51263    l_accted_amt_idx  := 13;
51264    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
51265    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
51266    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
51267    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
51268    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
51272    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
51269    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
51270    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
51271    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
51273    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
51274    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
51275    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
51276    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
51277    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
51278    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
51279    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
51280    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
51281    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
51282    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
51283    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
51284    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
51285    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
51286    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
51287    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
51288    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
51289    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
51290    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
51291    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
51292    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
51293    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
51294    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
51295    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
51296    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
51297 
51298    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
51299    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
51300 
51301    ---------------------------------------------------------------------------------------------------------------
51302    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
51303    ---------------------------------------------------------------------------------------------------------------
51304    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
51305 
51306    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
51307    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
51308 
51309    IF xla_accounting_cache_pkg.GetValueChar
51310          (p_source_code         => 'LEDGER_CATEGORY_CODE'
51311          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
51312    AND l_bflow_method_code = 'PRIOR_ENTRY'
51313 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
51314    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
51315          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
51316        )
51317    THEN
51318          xla_ae_lines_pkg.BflowUpgEntry
51319            (p_business_method_code    => l_bflow_method_code
51320            ,p_business_class_code     => l_bflow_class_code
51321            ,p_balance_type            => l_balance_type_code);
51322    ELSE
51323       NULL;
51324 -- No business flow processing for business flow method of NONE.
51325    END IF;
51326 
51327    --
51328    -- call analytical criteria
51329    --
51330    
51331    --
51332    -- call description
51333    --
51334    -- No description or it is inherited.
51335    --
51336    -- call ADRs
51337    -- Bug 4922099
51338    --
51339    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
51340         (NVL(l_actual_upg_option, 'N') = 'O') OR
51341         (NVL(l_enc_upg_option, 'N') = 'O')
51342       )
51343    THEN
51344    NULL;
51345    --
51346    --
51347    
51348   l_ccid := AcctDerRule_7(
51349            p_application_id           => p_application_id
51350          , p_ae_header_id             => l_ae_header_id 
51351 , p_source_3 => p_source_3
51352          , x_transaction_coa_id       => l_adr_transaction_coa_id
51353          , x_accounting_coa_id        => l_adr_accounting_coa_id
51354          , x_value_type_code          => l_adr_value_type_code
51355          , p_side                     => 'NA'
51356    );
51357 
51358    xla_ae_lines_pkg.set_ccid(
51359     p_code_combination_id          => l_ccid
51360   , p_value_type_code              => l_adr_value_type_code
51361   , p_transaction_coa_id           => l_adr_transaction_coa_id
51362   , p_accounting_coa_id            => l_adr_accounting_coa_id
51363   , p_adr_code                     => 'DIST_CCID'
51364   , p_adr_type_code                => 'S'
51365   , p_component_type               => l_component_type
51366   , p_component_code               => l_component_code
51367   , p_component_type_code          => l_component_type_code
51368   , p_component_appl_id            => l_component_appl_id
51369   , p_amb_context_code             => l_amb_context_code
51370   , p_side                         => 'NA'
51371   );
51372 
51373 
51374    --
51375    --
51376    END IF;
51377    --
51378    -- Bug 4922099
51382         (l_bflow_method_code = 'PRIOR_ENTRY')
51379    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
51380           (NVL(l_enc_upg_option, 'N') = 'O')
51381         ) AND
51383       )
51384    THEN
51385       IF
51386       --
51387       1 = 2
51388       --
51389       THEN
51390       xla_accounting_err_pkg.build_message
51391                                     (p_appli_s_name            => 'XLA'
51392                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
51393                                     ,p_token_1                 => 'LINE_NUMBER'
51394                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
51395                                     ,p_token_2                 => 'LINE_TYPE_NAME'
51396                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
51397                                                                              l_component_type
51398                                                                             ,l_component_code
51399                                                                             ,l_component_type_code
51400                                                                             ,l_component_appl_id
51401                                                                             ,l_amb_context_code
51402                                                                             ,l_entity_code
51403                                                                             ,l_event_class_code
51404                                                                            )
51405                                     ,p_token_3                 => 'OWNER'
51406                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
51407                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
51408                                                                           ,p_lookup_code    => l_component_type_code
51409                                                                          )
51410                                     ,p_token_4                 => 'PRODUCT_NAME'
51411                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
51412                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
51413                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
51414                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
51415                                     ,p_ae_header_id            =>  NULL
51416                                        );
51417 
51418         IF (C_LEVEL_ERROR>= g_log_level) THEN
51419                  trace
51420                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
51421                       ,p_level    => C_LEVEL_ERROR
51422                       ,p_module   => l_log_module);
51423         END IF;
51424       END IF;
51425    END IF;
51426    --
51427    --
51428    ------------------------------------------------------------------------------------------------
51429    -- 4219869 Business Flow
51430    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
51431    -- Prior Entry.  Currently, the following code is always generated.
51432    ------------------------------------------------------------------------------------------------
51433    XLA_AE_LINES_PKG.ValidateCurrentLine;
51434 
51435    ------------------------------------------------------------------------------------
51436    -- 4219869 Business Flow
51437    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
51438    ------------------------------------------------------------------------------------
51439    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
51440 
51441    ----------------------------------------------------------------------------------
51442    -- 4219869 Business Flow
51443    -- Update journal entry status -- Need to generate this within IF <condition>
51444    ----------------------------------------------------------------------------------
51445    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
51446          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
51447          ,p_balance_type_code => l_balance_type_code
51448          );
51449 
51450    -------------------------------------------------------------------------------------------
51451    -- 4262811 - Generate the Accrual Reversal lines
51452    -------------------------------------------------------------------------------------------
51453    BEGIN
51454       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
51455                               (g_array_event(p_event_id).array_value_num('header_index'));
51456       IF l_acc_rev_flag IS NULL THEN
51457          l_acc_rev_flag := 'N';
51458       END IF;
51459    EXCEPTION
51460       WHEN OTHERS THEN
51461          l_acc_rev_flag := 'N';
51462    END;
51463    --
51464    IF (l_acc_rev_flag = 'Y') THEN
51465 
51466        -- 4645092  ------------------------------------------------------------------------------
51467        -- To allow MPA report to determine if it should generate report process
51468        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
51469        ------------------------------------------------------------------------------------------
51470 
51474    -- call ADRs
51471        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
51472        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
51473    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
51475    -- Bug 4922099
51476    --
51477    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
51478         (NVL(l_actual_upg_option, 'N') = 'O') OR
51479         (NVL(l_enc_upg_option, 'N') = 'O')
51480       )
51481    THEN
51482    NULL;
51483    --
51484    --
51485    
51486   l_ccid := AcctDerRule_7(
51487            p_application_id           => p_application_id
51488          , p_ae_header_id             => l_ae_header_id 
51489 , p_source_3 => p_source_3
51490          , x_transaction_coa_id       => l_adr_transaction_coa_id
51491          , x_accounting_coa_id        => l_adr_accounting_coa_id
51492          , x_value_type_code          => l_adr_value_type_code
51493          , p_side                     => 'NA'
51494    );
51495 
51496    xla_ae_lines_pkg.set_ccid(
51497     p_code_combination_id          => l_ccid
51498   , p_value_type_code              => l_adr_value_type_code
51499   , p_transaction_coa_id           => l_adr_transaction_coa_id
51500   , p_accounting_coa_id            => l_adr_accounting_coa_id
51501   , p_adr_code                     => 'DIST_CCID'
51502   , p_adr_type_code                => 'S'
51503   , p_component_type               => l_component_type
51504   , p_component_code               => l_component_code
51505   , p_component_type_code          => l_component_type_code
51506   , p_component_appl_id            => l_component_appl_id
51507   , p_amb_context_code             => l_amb_context_code
51508   , p_side                         => 'NA'
51509   );
51510 
51511 
51512    --
51513    --
51514    END IF;
51515 
51516        --
51517        -- Update the line information that should be overwritten
51518        --
51519        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
51520                                          p_header_num   => 1);
51521        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
51522 
51523        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
51524 
51525        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
51526           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
51527        END IF;
51528 
51529       --
51530       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
51531       --
51532       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
51533           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
51534       ELSE
51535           ---------------------------------------------------------------------------------------------------
51536           -- 4262811a Switch Sign
51537           ---------------------------------------------------------------------------------------------------
51538           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
51539           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
51540                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
51541           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
51542                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
51543           -- 5132302
51544           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
51545                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
51546 
51547       END IF;
51548 
51549       -- 4955764
51550       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
51551       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
51552 
51553 
51554       XLA_AE_LINES_PKG.ValidateCurrentLine;
51555       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
51556 
51557       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
51558                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
51559                ,p_balance_type_code => l_balance_type_code);
51560 
51561    END IF;
51562 
51563    -----------------------------------------------------------------------------------------
51564    -- 4262811 Multiperiod Accounting
51565    -----------------------------------------------------------------------------------------
51566      -- No MPA option is assigned.
51567 
51568 
51569 END IF;
51570 END IF;
51571 --
51572 
51573 --
51574 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
51575    trace
51576       (p_msg      => 'END of AcctLineType_107'
51577       ,p_level    => C_LEVEL_PROCEDURE
51578       ,p_module   => l_log_module);
51579 END IF;
51580 --
51581 EXCEPTION
51582   WHEN xla_exceptions_pkg.application_exception THEN
51583       RAISE;
51584   WHEN OTHERS THEN
51585        xla_exceptions_pkg.raise_message
51586            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_107');
51587 END AcctLineType_107;
51588 --
51589 
51590 ---------------------------------------
51591 --
51592 -- PRIVATE FUNCTION
51593 --         AcctLineType_108
51594 --
51598  ,p_event_id              IN NUMBER
51595 ---------------------------------------
51596 PROCEDURE AcctLineType_108 (
51597   p_application_id        IN NUMBER
51599  ,p_calculate_acctd_flag  IN VARCHAR2
51600  ,p_calculate_g_l_flag    IN VARCHAR2
51601  ,p_actual_flag           IN OUT VARCHAR2
51602  ,p_balance_type_code     OUT VARCHAR2
51603  ,p_gain_or_loss_ref      OUT VARCHAR2
51604  
51605 --Transaction Distribution GL Account
51606  , p_source_4            IN NUMBER
51607 --Remittance Bank Account Cash Account
51608  , p_source_13            IN NUMBER
51609 --Distribution Source Type
51610  , p_source_20            IN VARCHAR2
51611 --Distribution Line Identifier
51612  , p_source_22            IN NUMBER
51613 --Distribution Type
51614  , p_source_23            IN VARCHAR2
51615 --Exchange Date
51616  , p_source_26            IN DATE
51617 --Exchange Rate
51618  , p_source_27            IN NUMBER
51619 --Exchange Rate Type
51620  , p_source_28            IN VARCHAR2
51621 --Transaction Distribution Account Class
51622  , p_source_33            IN VARCHAR2
51623 --Transaction Distribution Identifier
51624  , p_source_34            IN NUMBER
51625 --Transaction Distribution Type
51626  , p_source_35            IN VARCHAR2
51627 --Receipt Applied To Application Identifier
51628  , p_source_58            IN NUMBER
51629 --Transaction Entity Code
51630  , p_source_59            IN VARCHAR2
51631 --Transaction Identifier
51632  , p_source_60            IN NUMBER
51633 --Applying Document Currency Code
51634  , p_source_61            IN VARCHAR2
51635 --Distribution Party Identifier
51636  , p_source_63            IN NUMBER
51637 --Distribution Party Site Id
51638  , p_source_64            IN NUMBER
51639 --Distribution Party Type
51640  , p_source_65            IN VARCHAR2
51641 --Distribution Multi Fund Additional Entry
51642  , p_source_69            IN VARCHAR2
51643 --Receipt Class Require Remittance Flag
51644  , p_source_70            IN VARCHAR2
51645 --Receipt Class Confirm Flag
51646  , p_source_71            IN VARCHAR2
51647 --DIST_ENT_AMT_FROM
51648  , p_source_72            IN NUMBER
51649 --Accounting Amount
51650  , p_source_73            IN NUMBER
51651 )
51652 IS
51653 
51654 l_component_type              VARCHAR2(80);
51655 l_component_code              VARCHAR2(30);
51656 l_component_type_code         VARCHAR2(1);
51657 l_component_appl_id           INTEGER;
51658 l_amb_context_code            VARCHAR2(30);
51659 l_entity_code                 VARCHAR2(30);
51660 l_event_class_code            VARCHAR2(30);
51661 l_ae_header_id                NUMBER;
51662 l_event_type_code             VARCHAR2(30);
51663 l_line_definition_code        VARCHAR2(30);
51664 l_line_definition_owner_code  VARCHAR2(1);
51665 --
51666 -- adr variables
51667 l_segment                     VARCHAR2(30);
51668 l_ccid                        NUMBER;
51669 l_adr_transaction_coa_id      NUMBER;
51670 l_adr_accounting_coa_id       NUMBER;
51671 l_adr_flexfield_segment_code  VARCHAR2(30);
51672 l_adr_flex_value_set_id       NUMBER;
51673 l_adr_value_type_code         VARCHAR2(30);
51674 l_adr_value_combination_id    NUMBER;
51675 l_adr_value_segment_code      VARCHAR2(30);
51676 
51677 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
51678 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
51679 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
51680 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
51681 
51682 -- 4262811 Variables ------------------------------------------------------------------------------------------
51683 l_entered_amt_idx             NUMBER;
51684 l_accted_amt_idx              NUMBER;
51685 l_acc_rev_flag                VARCHAR2(1);
51686 l_accrual_line_num            NUMBER;
51687 l_tmp_amt                     NUMBER;
51688 l_acc_rev_natural_side_code   VARCHAR2(1);
51689 
51690 l_num_entries                 NUMBER;
51691 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
51692 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
51693 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
51694 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
51695 l_recog_line_1                NUMBER;
51696 l_recog_line_2                NUMBER;
51697 
51698 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
51699 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
51700 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
51701 
51702 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
51703 
51704 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
51705 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
51706 
51707 ---------------------------------------------------------------------------------------------------------------
51708 
51709 
51710 --
51711 -- bulk performance
51712 --
51713 l_balance_type_code           VARCHAR2(1);
51714 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
51715 l_log_module                  VARCHAR2(240);
51716 
51717 --
51718 -- Upgrade strategy
51719 --
51720 l_actual_upg_option           VARCHAR2(1);
51721 l_enc_upg_option           VARCHAR2(1);
51722 
51723 --
51724 BEGIN
51725 --
51726 IF g_log_enabled THEN
51730 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
51727       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_108';
51728 END IF;
51729 --
51731 
51732       trace
51733          (p_msg      => 'BEGIN of AcctLineType_108'
51734          ,p_level    => C_LEVEL_PROCEDURE
51735          ,p_module   => l_log_module);
51736 
51737 END IF;
51738 --
51739 l_component_type             := 'AMB_JLT';
51740 l_component_code             := 'RCT_APP_MFAR_TRX_CASH';
51741 l_component_type_code        := 'S';
51742 l_component_appl_id          :=  222;
51743 l_amb_context_code           := 'DEFAULT';
51744 l_entity_code                := 'RECEIPTS';
51745 l_event_class_code           := 'RECEIPT';
51746 l_event_type_code            := 'RECEIPT_ALL';
51747 l_line_definition_owner_code := 'S';
51748 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
51749 --
51750 l_balance_type_code          := 'A';
51751 l_segment                     := NULL;
51752 l_ccid                        := NULL;
51753 l_adr_transaction_coa_id      := NULL;
51754 l_adr_accounting_coa_id       := NULL;
51755 l_adr_flexfield_segment_code  := NULL;
51756 l_adr_flex_value_set_id       := NULL;
51757 l_adr_value_type_code         := NULL;
51758 l_adr_value_combination_id    := NULL;
51759 l_adr_value_segment_code      := NULL;
51760 
51761 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
51762 l_bflow_class_code           := '';    -- 4219869 Business Flow
51763 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
51764 l_budgetary_control_flag     := 'N';
51765 
51766 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
51767 l_bflow_applied_to_amt       := NULL; -- 5132302
51768 l_entered_amt_idx            := NULL;          -- 4262811
51769 l_accted_amt_idx             := NULL;          -- 4262811
51770 l_acc_rev_flag               := NULL;          -- 4262811
51771 l_accrual_line_num           := NULL;          -- 4262811
51772 l_tmp_amt                    := NULL;          -- 4262811
51773 --
51774  
51775 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
51776     l_balance_type_code <> 'B' THEN
51777 IF (NVL(p_source_33,'
51778 ') =  'REV' OR 
51779 NVL(p_source_33,'
51780 ') =  'TAX' OR 
51781 NVL(p_source_33,'
51782 ') =  'FREIGHT' OR 
51783 NVL(p_source_33,'
51784 ') =  'CHARGES' OR 
51785 NVL(p_source_33,'
51786 ') =  'ROUND') AND 
51787 NVL(p_source_20,'
51788 ') =  'REC' AND 
51789 NVL(p_source_69,'
51790 ') =  'N' AND 
51791 NVL(p_source_70,'
51792 ') =  'N' AND 
51793 NVL(p_source_71,'
51794 ') =  'N'
51795  THEN 
51796 
51797    --
51798    XLA_AE_LINES_PKG.SetNewLine;
51799 
51800    p_balance_type_code          := l_balance_type_code;
51801    -- set the flag so later we will know whether the gain loss line needs to be created
51802    
51803    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
51804      p_actual_flag :='A';
51805    END IF;
51806 
51807    --
51808    -- bulk performance
51809    --
51810    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
51811                                       p_header_num   => 0); -- 4262811
51812    --
51813    -- set accounting line options
51814    --
51815    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
51816            p_natural_side_code          => 'D'
51817          , p_gain_or_loss_flag          => 'N'
51818          , p_gl_transfer_mode_code      => 'S'
51819          , p_acct_entry_type_code       => 'A'
51820          , p_switch_side_flag           => 'Y'
51821          , p_merge_duplicate_code       => 'A'
51822          );
51823    --
51824    l_acc_rev_natural_side_code := 'C';  -- 4262811
51825    -- 
51826    --
51827    -- set accounting line type info
51828    --
51829    xla_ae_lines_pkg.SetAcctLineType
51830       (p_component_type             => l_component_type
51831       ,p_event_type_code            => l_event_type_code
51832       ,p_line_definition_owner_code => l_line_definition_owner_code
51833       ,p_line_definition_code       => l_line_definition_code
51834       ,p_accounting_line_code       => l_component_code
51835       ,p_accounting_line_type_code  => l_component_type_code
51836       ,p_accounting_line_appl_id    => l_component_appl_id
51837       ,p_amb_context_code           => l_amb_context_code
51838       ,p_entity_code                => l_entity_code
51839       ,p_event_class_code           => l_event_class_code);
51840    --
51841    -- set accounting class
51842    --
51843    xla_ae_lines_pkg.SetAcctClass(
51844            p_accounting_class_code  => 'CASH'
51845          , p_ae_header_id           => l_ae_header_id
51846          );
51847 
51848    --
51849    -- set rounding class
51850    --
51851    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
51852                       'RECEIVABLE';
51853 
51854    --
51855    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
51856    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
51857    --
51858    -- bulk performance
51859    --
51860    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
51861 
51862    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
51866    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
51863       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
51864 
51865    -- 4955764
51867       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
51868 
51869    -- 4458381 Public Sector Enh
51870    
51871    --
51872    -- set accounting attributes for the line type
51873    --
51874    l_entered_amt_idx := 8;
51875    l_accted_amt_idx  := 13;
51876    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
51877    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
51878    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
51879    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
51880    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
51881    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
51882    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
51883    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
51884    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
51885    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
51886    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
51887    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
51888    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
51889    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
51890    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
51891    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
51892    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
51893    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
51894    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
51895    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
51896    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
51897    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
51898    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
51899    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
51900    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
51901    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
51902    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
51903    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
51904    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
51905    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
51906    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
51907    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
51908    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
51909 
51910    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
51911    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
51912 
51913    ---------------------------------------------------------------------------------------------------------------
51914    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
51915    ---------------------------------------------------------------------------------------------------------------
51916    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
51917 
51918    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
51919    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
51920 
51921    IF xla_accounting_cache_pkg.GetValueChar
51922          (p_source_code         => 'LEDGER_CATEGORY_CODE'
51923          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
51924    AND l_bflow_method_code = 'PRIOR_ENTRY'
51925 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
51926    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
51927          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
51928        )
51929    THEN
51930          xla_ae_lines_pkg.BflowUpgEntry
51931            (p_business_method_code    => l_bflow_method_code
51932            ,p_business_class_code     => l_bflow_class_code
51933            ,p_balance_type            => l_balance_type_code);
51934    ELSE
51935       NULL;
51936 -- No business flow processing for business flow method of NONE.
51937    END IF;
51938 
51939    --
51940    -- call analytical criteria
51941    --
51942    
51943    --
51944    -- call description
51945    --
51946    
51947 xla_ae_lines_pkg.SetLineDescription(
51948    p_ae_header_id => l_ae_header_id
51949   ,p_description  => Description_1 (
51950      p_application_id         => p_application_id
51951    , p_ae_header_id           => l_ae_header_id 
51952    )
51953 );
51954 
51955 
51956    --
51957    -- call ADRs
51958    -- Bug 4922099
51959    --
51960    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
51961         (NVL(l_actual_upg_option, 'N') = 'O') OR
51962         (NVL(l_enc_upg_option, 'N') = 'O')
51963       )
51964    THEN
51965    NULL;
51966    --
51967    --
51968    
51969   l_ccid := AcctDerRule_25(
51970            p_application_id           => p_application_id
51971          , p_ae_header_id             => l_ae_header_id 
51972 , p_source_13 => p_source_13
51973          , x_transaction_coa_id       => l_adr_transaction_coa_id
51977    );
51974          , x_accounting_coa_id        => l_adr_accounting_coa_id
51975          , x_value_type_code          => l_adr_value_type_code
51976          , p_side                     => 'NA'
51978 
51979    xla_ae_lines_pkg.set_ccid(
51980     p_code_combination_id          => l_ccid
51981   , p_value_type_code              => l_adr_value_type_code
51982   , p_transaction_coa_id           => l_adr_transaction_coa_id
51983   , p_accounting_coa_id            => l_adr_accounting_coa_id
51984   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
51985   , p_adr_type_code                => 'S'
51986   , p_component_type               => l_component_type
51987   , p_component_code               => l_component_code
51988   , p_component_type_code          => l_component_type_code
51989   , p_component_appl_id            => l_component_appl_id
51990   , p_amb_context_code             => l_amb_context_code
51991   , p_side                         => 'NA'
51992   );
51993 
51994 
51995    l_segment := AcctDerRule_5(
51996            p_application_id           => p_application_id
51997          , p_ae_header_id             => l_ae_header_id 
51998 , p_source_4 => p_source_4
51999          , x_transaction_coa_id       => l_adr_transaction_coa_id
52000          , x_accounting_coa_id        => l_adr_accounting_coa_id
52001          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
52002          , x_flex_value_set_id        => l_adr_flex_value_set_id
52003          , x_value_type_code          => l_adr_value_type_code
52004          , x_value_combination_id     => l_adr_value_combination_id
52005          , x_value_segment_code       => l_adr_value_segment_code
52006          , p_side                     => 'NA'
52007          , p_override_seg_flag        => 'Y'
52008    );
52009 
52010    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
52011 
52012       xla_ae_lines_pkg.set_segment(
52013           p_to_segment_code         => 'GL_BALANCING'
52014         , p_segment_value           => l_segment
52015         , p_from_segment_code       => l_adr_value_segment_code
52016         , p_from_combination_id     => l_adr_value_combination_id
52017         , p_value_type_code         => l_adr_value_type_code
52018         , p_transaction_coa_id      => l_adr_transaction_coa_id
52019         , p_accounting_coa_id       => l_adr_accounting_coa_id
52020         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
52021         , p_flex_value_set_id       => l_adr_flex_value_set_id
52022         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
52023         , p_adr_type_code           => 'S'
52024         , p_component_type          => l_component_type
52025         , p_component_code          => l_component_code
52026         , p_component_type_code     => l_component_type_code
52027         , p_component_appl_id       => l_component_appl_id
52028         , p_amb_context_code        => l_amb_context_code
52029         , p_entity_code             => 'RECEIPTS'
52030         , p_event_class_code        => 'RECEIPT'
52031         , p_side                    => 'NA'
52032         );
52033 
52034   END IF;
52035 
52036    --
52037    --
52038    END IF;
52039    --
52040    -- Bug 4922099
52041    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
52042           (NVL(l_enc_upg_option, 'N') = 'O')
52043         ) AND
52044         (l_bflow_method_code = 'PRIOR_ENTRY')
52045       )
52046    THEN
52047       IF
52048       --
52049       1 = 2
52050       --
52051       THEN
52052       xla_accounting_err_pkg.build_message
52053                                     (p_appli_s_name            => 'XLA'
52054                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
52055                                     ,p_token_1                 => 'LINE_NUMBER'
52056                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
52057                                     ,p_token_2                 => 'LINE_TYPE_NAME'
52058                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
52059                                                                              l_component_type
52060                                                                             ,l_component_code
52061                                                                             ,l_component_type_code
52062                                                                             ,l_component_appl_id
52063                                                                             ,l_amb_context_code
52064                                                                             ,l_entity_code
52065                                                                             ,l_event_class_code
52066                                                                            )
52067                                     ,p_token_3                 => 'OWNER'
52068                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
52069                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
52070                                                                           ,p_lookup_code    => l_component_type_code
52071                                                                          )
52072                                     ,p_token_4                 => 'PRODUCT_NAME'
52073                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
52077                                     ,p_ae_header_id            =>  NULL
52074                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
52075                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
52076                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
52078                                        );
52079 
52080         IF (C_LEVEL_ERROR>= g_log_level) THEN
52081                  trace
52082                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
52083                       ,p_level    => C_LEVEL_ERROR
52084                       ,p_module   => l_log_module);
52085         END IF;
52086       END IF;
52087    END IF;
52088    --
52089    --
52090    ------------------------------------------------------------------------------------------------
52091    -- 4219869 Business Flow
52092    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
52093    -- Prior Entry.  Currently, the following code is always generated.
52094    ------------------------------------------------------------------------------------------------
52095    XLA_AE_LINES_PKG.ValidateCurrentLine;
52096 
52097    ------------------------------------------------------------------------------------
52098    -- 4219869 Business Flow
52099    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
52100    ------------------------------------------------------------------------------------
52101    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
52102 
52103    ----------------------------------------------------------------------------------
52104    -- 4219869 Business Flow
52105    -- Update journal entry status -- Need to generate this within IF <condition>
52106    ----------------------------------------------------------------------------------
52107    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
52108          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
52109          ,p_balance_type_code => l_balance_type_code
52110          );
52111 
52112    -------------------------------------------------------------------------------------------
52113    -- 4262811 - Generate the Accrual Reversal lines
52114    -------------------------------------------------------------------------------------------
52115    BEGIN
52116       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
52117                               (g_array_event(p_event_id).array_value_num('header_index'));
52118       IF l_acc_rev_flag IS NULL THEN
52119          l_acc_rev_flag := 'N';
52120       END IF;
52121    EXCEPTION
52122       WHEN OTHERS THEN
52123          l_acc_rev_flag := 'N';
52124    END;
52125    --
52126    IF (l_acc_rev_flag = 'Y') THEN
52127 
52128        -- 4645092  ------------------------------------------------------------------------------
52129        -- To allow MPA report to determine if it should generate report process
52130        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
52131        ------------------------------------------------------------------------------------------
52132 
52133        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
52134        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
52135    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
52136    -- call ADRs
52137    -- Bug 4922099
52138    --
52139    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
52140         (NVL(l_actual_upg_option, 'N') = 'O') OR
52141         (NVL(l_enc_upg_option, 'N') = 'O')
52142       )
52143    THEN
52144    NULL;
52145    --
52146    --
52147    
52148   l_ccid := AcctDerRule_25(
52149            p_application_id           => p_application_id
52150          , p_ae_header_id             => l_ae_header_id 
52151 , p_source_13 => p_source_13
52152          , x_transaction_coa_id       => l_adr_transaction_coa_id
52153          , x_accounting_coa_id        => l_adr_accounting_coa_id
52154          , x_value_type_code          => l_adr_value_type_code
52155          , p_side                     => 'NA'
52156    );
52157 
52158    xla_ae_lines_pkg.set_ccid(
52159     p_code_combination_id          => l_ccid
52160   , p_value_type_code              => l_adr_value_type_code
52161   , p_transaction_coa_id           => l_adr_transaction_coa_id
52162   , p_accounting_coa_id            => l_adr_accounting_coa_id
52163   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
52164   , p_adr_type_code                => 'S'
52165   , p_component_type               => l_component_type
52166   , p_component_code               => l_component_code
52167   , p_component_type_code          => l_component_type_code
52168   , p_component_appl_id            => l_component_appl_id
52169   , p_amb_context_code             => l_amb_context_code
52170   , p_side                         => 'NA'
52171   );
52172 
52173 
52174    l_segment := AcctDerRule_5(
52175            p_application_id           => p_application_id
52176          , p_ae_header_id             => l_ae_header_id 
52177 , p_source_4 => p_source_4
52178          , x_transaction_coa_id       => l_adr_transaction_coa_id
52179          , x_accounting_coa_id        => l_adr_accounting_coa_id
52180          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
52181          , x_flex_value_set_id        => l_adr_flex_value_set_id
52185          , p_side                     => 'NA'
52182          , x_value_type_code          => l_adr_value_type_code
52183          , x_value_combination_id     => l_adr_value_combination_id
52184          , x_value_segment_code       => l_adr_value_segment_code
52186          , p_override_seg_flag        => 'Y'
52187    );
52188 
52189    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
52190 
52191       xla_ae_lines_pkg.set_segment(
52192           p_to_segment_code         => 'GL_BALANCING'
52193         , p_segment_value           => l_segment
52194         , p_from_segment_code       => l_adr_value_segment_code
52195         , p_from_combination_id     => l_adr_value_combination_id
52196         , p_value_type_code         => l_adr_value_type_code
52197         , p_transaction_coa_id      => l_adr_transaction_coa_id
52198         , p_accounting_coa_id       => l_adr_accounting_coa_id
52199         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
52200         , p_flex_value_set_id       => l_adr_flex_value_set_id
52201         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
52202         , p_adr_type_code           => 'S'
52203         , p_component_type          => l_component_type
52204         , p_component_code          => l_component_code
52205         , p_component_type_code     => l_component_type_code
52206         , p_component_appl_id       => l_component_appl_id
52207         , p_amb_context_code        => l_amb_context_code
52208         , p_entity_code             => 'RECEIPTS'
52209         , p_event_class_code        => 'RECEIPT'
52210         , p_side                    => 'NA'
52211         );
52212 
52213   END IF;
52214 
52215    --
52216    --
52217    END IF;
52218 
52219        --
52220        -- Update the line information that should be overwritten
52221        --
52222        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
52223                                          p_header_num   => 1);
52224        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
52225 
52226        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
52227 
52228        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
52229           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
52230        END IF;
52231 
52232       --
52233       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
52234       --
52235       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
52236           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
52237       ELSE
52238           ---------------------------------------------------------------------------------------------------
52239           -- 4262811a Switch Sign
52240           ---------------------------------------------------------------------------------------------------
52241           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
52242           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
52243                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
52244           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
52245                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
52246           -- 5132302
52247           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
52248                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
52249 
52250       END IF;
52251 
52252       -- 4955764
52253       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
52254       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
52255 
52256 
52257       XLA_AE_LINES_PKG.ValidateCurrentLine;
52258       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
52259 
52260       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
52261                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
52262                ,p_balance_type_code => l_balance_type_code);
52263 
52264    END IF;
52265 
52266    -----------------------------------------------------------------------------------------
52267    -- 4262811 Multiperiod Accounting
52268    -----------------------------------------------------------------------------------------
52269      -- No MPA option is assigned.
52270 
52271 
52272 END IF;
52273 END IF;
52274 --
52275 
52276 --
52277 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
52278    trace
52279       (p_msg      => 'END of AcctLineType_108'
52280       ,p_level    => C_LEVEL_PROCEDURE
52281       ,p_module   => l_log_module);
52282 END IF;
52283 --
52284 EXCEPTION
52285   WHEN xla_exceptions_pkg.application_exception THEN
52286       RAISE;
52287   WHEN OTHERS THEN
52288        xla_exceptions_pkg.raise_message
52289            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_108');
52290 END AcctLineType_108;
52291 --
52292 
52293 ---------------------------------------
52294 --
52295 -- PRIVATE FUNCTION
52296 --         AcctLineType_109
52297 --
52298 ---------------------------------------
52302  ,p_calculate_acctd_flag  IN VARCHAR2
52299 PROCEDURE AcctLineType_109 (
52300   p_application_id        IN NUMBER
52301  ,p_event_id              IN NUMBER
52303  ,p_calculate_g_l_flag    IN VARCHAR2
52304  ,p_actual_flag           IN OUT VARCHAR2
52305  ,p_balance_type_code     OUT VARCHAR2
52306  ,p_gain_or_loss_ref      OUT VARCHAR2
52307  
52308 --Transaction Distribution GL Account
52309  , p_source_4            IN NUMBER
52310 --Remittance Bank Account Cash Account
52311  , p_source_13            IN NUMBER
52312 --Distribution Source Type
52313  , p_source_20            IN VARCHAR2
52314 --Distribution Line Identifier
52315  , p_source_22            IN NUMBER
52316 --Distribution Type
52317  , p_source_23            IN VARCHAR2
52318 --Exchange Date
52319  , p_source_26            IN DATE
52320 --Exchange Rate
52321  , p_source_27            IN NUMBER
52322 --Exchange Rate Type
52323  , p_source_28            IN VARCHAR2
52324 --Transaction Distribution Identifier
52325  , p_source_34            IN NUMBER
52326 --Transaction Distribution Type
52327  , p_source_35            IN VARCHAR2
52328 --Receipt Applied To Application Identifier
52329  , p_source_58            IN NUMBER
52330 --Transaction Entity Code
52331  , p_source_59            IN VARCHAR2
52332 --Transaction Identifier
52333  , p_source_60            IN NUMBER
52334 --Applying Document Currency Code
52335  , p_source_61            IN VARCHAR2
52336 --Distribution Party Identifier
52337  , p_source_63            IN NUMBER
52338 --Distribution Party Site Id
52339  , p_source_64            IN NUMBER
52340 --Distribution Party Type
52341  , p_source_65            IN VARCHAR2
52342 --Distribution Multi Fund Additional Entry
52343  , p_source_69            IN VARCHAR2
52344 --Receipt Class Require Remittance Flag
52345  , p_source_70            IN VARCHAR2
52346 --DIST_ENT_AMT_FROM
52347  , p_source_72            IN NUMBER
52348 --Accounting Amount
52349  , p_source_73            IN NUMBER
52350 )
52351 IS
52352 
52353 l_component_type              VARCHAR2(80);
52354 l_component_code              VARCHAR2(30);
52355 l_component_type_code         VARCHAR2(1);
52356 l_component_appl_id           INTEGER;
52357 l_amb_context_code            VARCHAR2(30);
52358 l_entity_code                 VARCHAR2(30);
52359 l_event_class_code            VARCHAR2(30);
52360 l_ae_header_id                NUMBER;
52361 l_event_type_code             VARCHAR2(30);
52362 l_line_definition_code        VARCHAR2(30);
52363 l_line_definition_owner_code  VARCHAR2(1);
52364 --
52365 -- adr variables
52366 l_segment                     VARCHAR2(30);
52367 l_ccid                        NUMBER;
52368 l_adr_transaction_coa_id      NUMBER;
52369 l_adr_accounting_coa_id       NUMBER;
52370 l_adr_flexfield_segment_code  VARCHAR2(30);
52371 l_adr_flex_value_set_id       NUMBER;
52372 l_adr_value_type_code         VARCHAR2(30);
52373 l_adr_value_combination_id    NUMBER;
52374 l_adr_value_segment_code      VARCHAR2(30);
52375 
52376 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
52377 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
52378 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
52379 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
52380 
52381 -- 4262811 Variables ------------------------------------------------------------------------------------------
52382 l_entered_amt_idx             NUMBER;
52383 l_accted_amt_idx              NUMBER;
52384 l_acc_rev_flag                VARCHAR2(1);
52385 l_accrual_line_num            NUMBER;
52386 l_tmp_amt                     NUMBER;
52387 l_acc_rev_natural_side_code   VARCHAR2(1);
52388 
52389 l_num_entries                 NUMBER;
52390 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
52391 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
52392 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
52393 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
52394 l_recog_line_1                NUMBER;
52395 l_recog_line_2                NUMBER;
52396 
52397 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
52398 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
52399 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
52400 
52401 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
52402 
52403 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
52404 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
52405 
52406 ---------------------------------------------------------------------------------------------------------------
52407 
52408 
52409 --
52410 -- bulk performance
52411 --
52412 l_balance_type_code           VARCHAR2(1);
52413 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
52414 l_log_module                  VARCHAR2(240);
52415 
52416 --
52417 -- Upgrade strategy
52418 --
52419 l_actual_upg_option           VARCHAR2(1);
52420 l_enc_upg_option           VARCHAR2(1);
52421 
52422 --
52423 BEGIN
52424 --
52425 IF g_log_enabled THEN
52426       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_109';
52427 END IF;
52428 --
52429 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
52430 
52431       trace
52435 
52432          (p_msg      => 'BEGIN of AcctLineType_109'
52433          ,p_level    => C_LEVEL_PROCEDURE
52434          ,p_module   => l_log_module);
52436 END IF;
52437 --
52438 l_component_type             := 'AMB_JLT';
52439 l_component_code             := 'RCT_APP_MFAR_TRX_CM_CASH';
52440 l_component_type_code        := 'S';
52441 l_component_appl_id          :=  222;
52442 l_amb_context_code           := 'DEFAULT';
52443 l_entity_code                := 'RECEIPTS';
52444 l_event_class_code           := 'RECEIPT';
52445 l_event_type_code            := 'RECEIPT_ALL';
52446 l_line_definition_owner_code := 'S';
52447 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
52448 --
52449 l_balance_type_code          := 'A';
52450 l_segment                     := NULL;
52451 l_ccid                        := NULL;
52452 l_adr_transaction_coa_id      := NULL;
52453 l_adr_accounting_coa_id       := NULL;
52454 l_adr_flexfield_segment_code  := NULL;
52455 l_adr_flex_value_set_id       := NULL;
52456 l_adr_value_type_code         := NULL;
52457 l_adr_value_combination_id    := NULL;
52458 l_adr_value_segment_code      := NULL;
52459 
52460 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
52461 l_bflow_class_code           := '';    -- 4219869 Business Flow
52462 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
52463 l_budgetary_control_flag     := 'N';
52464 
52465 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
52466 l_bflow_applied_to_amt       := NULL; -- 5132302
52467 l_entered_amt_idx            := NULL;          -- 4262811
52468 l_accted_amt_idx             := NULL;          -- 4262811
52469 l_acc_rev_flag               := NULL;          -- 4262811
52470 l_accrual_line_num           := NULL;          -- 4262811
52471 l_tmp_amt                    := NULL;          -- 4262811
52472 --
52473  
52474 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
52475     l_balance_type_code <> 'B' THEN
52476 IF NVL(p_source_20,'
52477 ') =  'CASH' AND 
52478 NVL(p_source_69,'
52479 ') =  'Y' AND 
52480 NVL(p_source_70,'
52481 ') =  'Y'
52482  THEN 
52483 
52484    --
52485    XLA_AE_LINES_PKG.SetNewLine;
52486 
52487    p_balance_type_code          := l_balance_type_code;
52488    -- set the flag so later we will know whether the gain loss line needs to be created
52489    
52490    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
52491      p_actual_flag :='A';
52492    END IF;
52493 
52494    --
52495    -- bulk performance
52496    --
52497    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
52498                                       p_header_num   => 0); -- 4262811
52499    --
52500    -- set accounting line options
52501    --
52502    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
52503            p_natural_side_code          => 'C'
52504          , p_gain_or_loss_flag          => 'N'
52505          , p_gl_transfer_mode_code      => 'S'
52506          , p_acct_entry_type_code       => 'A'
52507          , p_switch_side_flag           => 'Y'
52508          , p_merge_duplicate_code       => 'A'
52509          );
52510    --
52511    l_acc_rev_natural_side_code := 'D';  -- 4262811
52512    -- 
52513    --
52514    -- set accounting line type info
52515    --
52516    xla_ae_lines_pkg.SetAcctLineType
52517       (p_component_type             => l_component_type
52518       ,p_event_type_code            => l_event_type_code
52519       ,p_line_definition_owner_code => l_line_definition_owner_code
52520       ,p_line_definition_code       => l_line_definition_code
52521       ,p_accounting_line_code       => l_component_code
52522       ,p_accounting_line_type_code  => l_component_type_code
52523       ,p_accounting_line_appl_id    => l_component_appl_id
52524       ,p_amb_context_code           => l_amb_context_code
52525       ,p_entity_code                => l_entity_code
52526       ,p_event_class_code           => l_event_class_code);
52527    --
52528    -- set accounting class
52529    --
52530    xla_ae_lines_pkg.SetAcctClass(
52531            p_accounting_class_code  => 'CASH'
52532          , p_ae_header_id           => l_ae_header_id
52533          );
52534 
52535    --
52536    -- set rounding class
52537    --
52538    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
52539                       'RECEIVABLE';
52540 
52541    --
52542    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
52543    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
52544    --
52545    -- bulk performance
52546    --
52547    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
52548 
52549    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
52550       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
52551 
52552    -- 4955764
52553    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
52554       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
52555 
52556    -- 4458381 Public Sector Enh
52557    
52558    --
52559    -- set accounting attributes for the line type
52560    --
52561    l_entered_amt_idx := 8;
52562    l_accted_amt_idx  := 13;
52566    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
52563    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
52564    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
52565    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
52567    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
52568    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
52569    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
52570    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
52571    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
52572    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
52573    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
52574    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
52575    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
52576    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
52577    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
52578    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
52579    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
52580    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
52581    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
52582    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
52583    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
52584    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
52585    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
52586    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
52587    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
52588    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
52589    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
52590    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
52591    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
52592    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
52593    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
52594    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
52595    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
52596 
52597    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
52598    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
52599 
52600    ---------------------------------------------------------------------------------------------------------------
52601    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
52602    ---------------------------------------------------------------------------------------------------------------
52603    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
52604 
52605    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
52606    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
52607 
52608    IF xla_accounting_cache_pkg.GetValueChar
52609          (p_source_code         => 'LEDGER_CATEGORY_CODE'
52610          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
52611    AND l_bflow_method_code = 'PRIOR_ENTRY'
52612 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
52613    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
52614          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
52615        )
52616    THEN
52617          xla_ae_lines_pkg.BflowUpgEntry
52618            (p_business_method_code    => l_bflow_method_code
52619            ,p_business_class_code     => l_bflow_class_code
52620            ,p_balance_type            => l_balance_type_code);
52621    ELSE
52622       NULL;
52623 -- No business flow processing for business flow method of NONE.
52624    END IF;
52625 
52626    --
52627    -- call analytical criteria
52628    --
52629    
52630    --
52631    -- call description
52632    --
52633    
52634 xla_ae_lines_pkg.SetLineDescription(
52635    p_ae_header_id => l_ae_header_id
52636   ,p_description  => Description_1 (
52637      p_application_id         => p_application_id
52638    , p_ae_header_id           => l_ae_header_id 
52639    )
52640 );
52641 
52642 
52643    --
52644    -- call ADRs
52645    -- Bug 4922099
52646    --
52647    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
52648         (NVL(l_actual_upg_option, 'N') = 'O') OR
52649         (NVL(l_enc_upg_option, 'N') = 'O')
52650       )
52651    THEN
52652    NULL;
52653    --
52654    --
52655    
52656   l_ccid := AcctDerRule_25(
52657            p_application_id           => p_application_id
52658          , p_ae_header_id             => l_ae_header_id 
52659 , p_source_13 => p_source_13
52660          , x_transaction_coa_id       => l_adr_transaction_coa_id
52661          , x_accounting_coa_id        => l_adr_accounting_coa_id
52662          , x_value_type_code          => l_adr_value_type_code
52663          , p_side                     => 'NA'
52664    );
52665 
52666    xla_ae_lines_pkg.set_ccid(
52667     p_code_combination_id          => l_ccid
52668   , p_value_type_code              => l_adr_value_type_code
52669   , p_transaction_coa_id           => l_adr_transaction_coa_id
52670   , p_accounting_coa_id            => l_adr_accounting_coa_id
52674   , p_component_code               => l_component_code
52671   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
52672   , p_adr_type_code                => 'S'
52673   , p_component_type               => l_component_type
52675   , p_component_type_code          => l_component_type_code
52676   , p_component_appl_id            => l_component_appl_id
52677   , p_amb_context_code             => l_amb_context_code
52678   , p_side                         => 'NA'
52679   );
52680 
52681 
52682    l_segment := AcctDerRule_5(
52683            p_application_id           => p_application_id
52684          , p_ae_header_id             => l_ae_header_id 
52685 , p_source_4 => p_source_4
52686          , x_transaction_coa_id       => l_adr_transaction_coa_id
52687          , x_accounting_coa_id        => l_adr_accounting_coa_id
52688          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
52689          , x_flex_value_set_id        => l_adr_flex_value_set_id
52690          , x_value_type_code          => l_adr_value_type_code
52691          , x_value_combination_id     => l_adr_value_combination_id
52692          , x_value_segment_code       => l_adr_value_segment_code
52693          , p_side                     => 'NA'
52694          , p_override_seg_flag        => 'Y'
52695    );
52696 
52697    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
52698 
52699       xla_ae_lines_pkg.set_segment(
52700           p_to_segment_code         => 'GL_BALANCING'
52701         , p_segment_value           => l_segment
52702         , p_from_segment_code       => l_adr_value_segment_code
52703         , p_from_combination_id     => l_adr_value_combination_id
52704         , p_value_type_code         => l_adr_value_type_code
52705         , p_transaction_coa_id      => l_adr_transaction_coa_id
52706         , p_accounting_coa_id       => l_adr_accounting_coa_id
52707         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
52708         , p_flex_value_set_id       => l_adr_flex_value_set_id
52709         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
52710         , p_adr_type_code           => 'S'
52711         , p_component_type          => l_component_type
52712         , p_component_code          => l_component_code
52713         , p_component_type_code     => l_component_type_code
52714         , p_component_appl_id       => l_component_appl_id
52715         , p_amb_context_code        => l_amb_context_code
52716         , p_entity_code             => 'RECEIPTS'
52717         , p_event_class_code        => 'RECEIPT'
52718         , p_side                    => 'NA'
52719         );
52720 
52721   END IF;
52722 
52723    --
52724    --
52725    END IF;
52726    --
52727    -- Bug 4922099
52728    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
52729           (NVL(l_enc_upg_option, 'N') = 'O')
52730         ) AND
52731         (l_bflow_method_code = 'PRIOR_ENTRY')
52732       )
52733    THEN
52734       IF
52735       --
52736       1 = 2
52737       --
52738       THEN
52739       xla_accounting_err_pkg.build_message
52740                                     (p_appli_s_name            => 'XLA'
52741                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
52742                                     ,p_token_1                 => 'LINE_NUMBER'
52743                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
52744                                     ,p_token_2                 => 'LINE_TYPE_NAME'
52745                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
52746                                                                              l_component_type
52747                                                                             ,l_component_code
52748                                                                             ,l_component_type_code
52749                                                                             ,l_component_appl_id
52750                                                                             ,l_amb_context_code
52751                                                                             ,l_entity_code
52752                                                                             ,l_event_class_code
52753                                                                            )
52754                                     ,p_token_3                 => 'OWNER'
52755                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
52756                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
52757                                                                           ,p_lookup_code    => l_component_type_code
52758                                                                          )
52759                                     ,p_token_4                 => 'PRODUCT_NAME'
52760                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
52761                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
52762                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
52763                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
52764                                     ,p_ae_header_id            =>  NULL
52765                                        );
52766 
52770                       ,p_level    => C_LEVEL_ERROR
52767         IF (C_LEVEL_ERROR>= g_log_level) THEN
52768                  trace
52769                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
52771                       ,p_module   => l_log_module);
52772         END IF;
52773       END IF;
52774    END IF;
52775    --
52776    --
52777    ------------------------------------------------------------------------------------------------
52778    -- 4219869 Business Flow
52779    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
52780    -- Prior Entry.  Currently, the following code is always generated.
52781    ------------------------------------------------------------------------------------------------
52782    XLA_AE_LINES_PKG.ValidateCurrentLine;
52783 
52784    ------------------------------------------------------------------------------------
52785    -- 4219869 Business Flow
52786    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
52787    ------------------------------------------------------------------------------------
52788    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
52789 
52790    ----------------------------------------------------------------------------------
52791    -- 4219869 Business Flow
52792    -- Update journal entry status -- Need to generate this within IF <condition>
52793    ----------------------------------------------------------------------------------
52794    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
52795          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
52796          ,p_balance_type_code => l_balance_type_code
52797          );
52798 
52799    -------------------------------------------------------------------------------------------
52800    -- 4262811 - Generate the Accrual Reversal lines
52801    -------------------------------------------------------------------------------------------
52802    BEGIN
52803       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
52804                               (g_array_event(p_event_id).array_value_num('header_index'));
52805       IF l_acc_rev_flag IS NULL THEN
52806          l_acc_rev_flag := 'N';
52807       END IF;
52808    EXCEPTION
52809       WHEN OTHERS THEN
52810          l_acc_rev_flag := 'N';
52811    END;
52812    --
52813    IF (l_acc_rev_flag = 'Y') THEN
52814 
52815        -- 4645092  ------------------------------------------------------------------------------
52816        -- To allow MPA report to determine if it should generate report process
52817        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
52818        ------------------------------------------------------------------------------------------
52819 
52820        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
52821        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
52822    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
52823    -- call ADRs
52824    -- Bug 4922099
52825    --
52826    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
52827         (NVL(l_actual_upg_option, 'N') = 'O') OR
52828         (NVL(l_enc_upg_option, 'N') = 'O')
52829       )
52830    THEN
52831    NULL;
52832    --
52833    --
52834    
52835   l_ccid := AcctDerRule_25(
52836            p_application_id           => p_application_id
52837          , p_ae_header_id             => l_ae_header_id 
52838 , p_source_13 => p_source_13
52839          , x_transaction_coa_id       => l_adr_transaction_coa_id
52840          , x_accounting_coa_id        => l_adr_accounting_coa_id
52841          , x_value_type_code          => l_adr_value_type_code
52842          , p_side                     => 'NA'
52843    );
52844 
52845    xla_ae_lines_pkg.set_ccid(
52846     p_code_combination_id          => l_ccid
52847   , p_value_type_code              => l_adr_value_type_code
52848   , p_transaction_coa_id           => l_adr_transaction_coa_id
52849   , p_accounting_coa_id            => l_adr_accounting_coa_id
52850   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
52851   , p_adr_type_code                => 'S'
52852   , p_component_type               => l_component_type
52853   , p_component_code               => l_component_code
52854   , p_component_type_code          => l_component_type_code
52855   , p_component_appl_id            => l_component_appl_id
52856   , p_amb_context_code             => l_amb_context_code
52857   , p_side                         => 'NA'
52858   );
52859 
52860 
52861    l_segment := AcctDerRule_5(
52862            p_application_id           => p_application_id
52863          , p_ae_header_id             => l_ae_header_id 
52864 , p_source_4 => p_source_4
52865          , x_transaction_coa_id       => l_adr_transaction_coa_id
52866          , x_accounting_coa_id        => l_adr_accounting_coa_id
52867          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
52868          , x_flex_value_set_id        => l_adr_flex_value_set_id
52869          , x_value_type_code          => l_adr_value_type_code
52870          , x_value_combination_id     => l_adr_value_combination_id
52871          , x_value_segment_code       => l_adr_value_segment_code
52872          , p_side                     => 'NA'
52873          , p_override_seg_flag        => 'Y'
52874    );
52875 
52876    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
52877 
52878       xla_ae_lines_pkg.set_segment(
52879           p_to_segment_code         => 'GL_BALANCING'
52880         , p_segment_value           => l_segment
52884         , p_transaction_coa_id      => l_adr_transaction_coa_id
52881         , p_from_segment_code       => l_adr_value_segment_code
52882         , p_from_combination_id     => l_adr_value_combination_id
52883         , p_value_type_code         => l_adr_value_type_code
52885         , p_accounting_coa_id       => l_adr_accounting_coa_id
52886         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
52887         , p_flex_value_set_id       => l_adr_flex_value_set_id
52888         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
52889         , p_adr_type_code           => 'S'
52890         , p_component_type          => l_component_type
52891         , p_component_code          => l_component_code
52892         , p_component_type_code     => l_component_type_code
52893         , p_component_appl_id       => l_component_appl_id
52894         , p_amb_context_code        => l_amb_context_code
52895         , p_entity_code             => 'RECEIPTS'
52896         , p_event_class_code        => 'RECEIPT'
52897         , p_side                    => 'NA'
52898         );
52899 
52900   END IF;
52901 
52902    --
52903    --
52904    END IF;
52905 
52906        --
52907        -- Update the line information that should be overwritten
52908        --
52909        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
52910                                          p_header_num   => 1);
52911        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
52912 
52913        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
52914 
52915        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
52916           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
52917        END IF;
52918 
52919       --
52920       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
52921       --
52922       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
52923           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
52924       ELSE
52925           ---------------------------------------------------------------------------------------------------
52926           -- 4262811a Switch Sign
52927           ---------------------------------------------------------------------------------------------------
52928           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
52929           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
52930                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
52931           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
52932                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
52933           -- 5132302
52934           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
52935                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
52936 
52937       END IF;
52938 
52939       -- 4955764
52940       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
52941       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
52942 
52943 
52944       XLA_AE_LINES_PKG.ValidateCurrentLine;
52945       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
52946 
52947       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
52948                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
52949                ,p_balance_type_code => l_balance_type_code);
52950 
52951    END IF;
52952 
52953    -----------------------------------------------------------------------------------------
52954    -- 4262811 Multiperiod Accounting
52955    -----------------------------------------------------------------------------------------
52956      -- No MPA option is assigned.
52957 
52958 
52959 END IF;
52960 END IF;
52961 --
52962 
52963 --
52964 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
52965    trace
52966       (p_msg      => 'END of AcctLineType_109'
52967       ,p_level    => C_LEVEL_PROCEDURE
52968       ,p_module   => l_log_module);
52969 END IF;
52970 --
52971 EXCEPTION
52972   WHEN xla_exceptions_pkg.application_exception THEN
52973       RAISE;
52974   WHEN OTHERS THEN
52975        xla_exceptions_pkg.raise_message
52976            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_109');
52977 END AcctLineType_109;
52978 --
52979 
52980 ---------------------------------------
52981 --
52982 -- PRIVATE FUNCTION
52983 --         AcctLineType_110
52984 --
52985 ---------------------------------------
52986 PROCEDURE AcctLineType_110 (
52987   p_application_id        IN NUMBER
52988  ,p_event_id              IN NUMBER
52989  ,p_calculate_acctd_flag  IN VARCHAR2
52990  ,p_calculate_g_l_flag    IN VARCHAR2
52991  ,p_actual_flag           IN OUT VARCHAR2
52992  ,p_balance_type_code     OUT VARCHAR2
52993  ,p_gain_or_loss_ref      OUT VARCHAR2
52994  
52995 --Transaction Distribution GL Account
52996  , p_source_4            IN NUMBER
52997 --Remittance Bank Account Confirmation Account
52998  , p_source_14            IN NUMBER
53002  , p_source_22            IN NUMBER
52999 --Distribution Source Type
53000  , p_source_20            IN VARCHAR2
53001 --Distribution Line Identifier
53003 --Distribution Type
53004  , p_source_23            IN VARCHAR2
53005 --Exchange Date
53006  , p_source_26            IN DATE
53007 --Exchange Rate
53008  , p_source_27            IN NUMBER
53009 --Exchange Rate Type
53010  , p_source_28            IN VARCHAR2
53011 --Transaction Distribution Identifier
53012  , p_source_34            IN NUMBER
53013 --Transaction Distribution Type
53014  , p_source_35            IN VARCHAR2
53015 --Receipt Applied To Application Identifier
53016  , p_source_58            IN NUMBER
53017 --Transaction Entity Code
53018  , p_source_59            IN VARCHAR2
53019 --Transaction Identifier
53020  , p_source_60            IN NUMBER
53021 --Applying Document Currency Code
53022  , p_source_61            IN VARCHAR2
53023 --Distribution Party Identifier
53024  , p_source_63            IN NUMBER
53025 --Distribution Party Site Id
53026  , p_source_64            IN NUMBER
53027 --Distribution Party Type
53028  , p_source_65            IN VARCHAR2
53029 --Distribution Multi Fund Additional Entry
53030  , p_source_69            IN VARCHAR2
53031 --DIST_ENT_AMT_FROM
53032  , p_source_72            IN NUMBER
53033 --Accounting Amount
53034  , p_source_73            IN NUMBER
53035 )
53036 IS
53037 
53038 l_component_type              VARCHAR2(80);
53039 l_component_code              VARCHAR2(30);
53040 l_component_type_code         VARCHAR2(1);
53041 l_component_appl_id           INTEGER;
53042 l_amb_context_code            VARCHAR2(30);
53043 l_entity_code                 VARCHAR2(30);
53044 l_event_class_code            VARCHAR2(30);
53045 l_ae_header_id                NUMBER;
53046 l_event_type_code             VARCHAR2(30);
53047 l_line_definition_code        VARCHAR2(30);
53048 l_line_definition_owner_code  VARCHAR2(1);
53049 --
53050 -- adr variables
53051 l_segment                     VARCHAR2(30);
53052 l_ccid                        NUMBER;
53053 l_adr_transaction_coa_id      NUMBER;
53054 l_adr_accounting_coa_id       NUMBER;
53055 l_adr_flexfield_segment_code  VARCHAR2(30);
53056 l_adr_flex_value_set_id       NUMBER;
53057 l_adr_value_type_code         VARCHAR2(30);
53058 l_adr_value_combination_id    NUMBER;
53059 l_adr_value_segment_code      VARCHAR2(30);
53060 
53061 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
53062 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
53063 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
53064 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
53065 
53066 -- 4262811 Variables ------------------------------------------------------------------------------------------
53067 l_entered_amt_idx             NUMBER;
53068 l_accted_amt_idx              NUMBER;
53069 l_acc_rev_flag                VARCHAR2(1);
53070 l_accrual_line_num            NUMBER;
53071 l_tmp_amt                     NUMBER;
53072 l_acc_rev_natural_side_code   VARCHAR2(1);
53073 
53074 l_num_entries                 NUMBER;
53075 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
53076 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
53077 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
53078 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
53079 l_recog_line_1                NUMBER;
53080 l_recog_line_2                NUMBER;
53081 
53082 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
53083 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
53084 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
53085 
53086 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
53087 
53088 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
53089 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
53090 
53091 ---------------------------------------------------------------------------------------------------------------
53092 
53093 
53094 --
53095 -- bulk performance
53096 --
53097 l_balance_type_code           VARCHAR2(1);
53098 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
53099 l_log_module                  VARCHAR2(240);
53100 
53101 --
53102 -- Upgrade strategy
53103 --
53104 l_actual_upg_option           VARCHAR2(1);
53105 l_enc_upg_option           VARCHAR2(1);
53106 
53107 --
53108 BEGIN
53109 --
53110 IF g_log_enabled THEN
53111       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_110';
53112 END IF;
53113 --
53114 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
53115 
53116       trace
53117          (p_msg      => 'BEGIN of AcctLineType_110'
53118          ,p_level    => C_LEVEL_PROCEDURE
53119          ,p_module   => l_log_module);
53120 
53121 END IF;
53122 --
53123 l_component_type             := 'AMB_JLT';
53124 l_component_code             := 'RCT_APP_MFAR_TRX_CONFIRMATION';
53125 l_component_type_code        := 'S';
53126 l_component_appl_id          :=  222;
53127 l_amb_context_code           := 'DEFAULT';
53128 l_entity_code                := 'RECEIPTS';
53129 l_event_class_code           := 'RECEIPT';
53130 l_event_type_code            := 'RECEIPT_ALL';
53131 l_line_definition_owner_code := 'S';
53135 l_segment                     := NULL;
53132 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
53133 --
53134 l_balance_type_code          := 'A';
53136 l_ccid                        := NULL;
53137 l_adr_transaction_coa_id      := NULL;
53138 l_adr_accounting_coa_id       := NULL;
53139 l_adr_flexfield_segment_code  := NULL;
53140 l_adr_flex_value_set_id       := NULL;
53141 l_adr_value_type_code         := NULL;
53142 l_adr_value_combination_id    := NULL;
53143 l_adr_value_segment_code      := NULL;
53144 
53145 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
53146 l_bflow_class_code           := '';    -- 4219869 Business Flow
53147 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
53148 l_budgetary_control_flag     := 'N';
53149 
53150 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
53151 l_bflow_applied_to_amt       := NULL; -- 5132302
53152 l_entered_amt_idx            := NULL;          -- 4262811
53153 l_accted_amt_idx             := NULL;          -- 4262811
53154 l_acc_rev_flag               := NULL;          -- 4262811
53155 l_accrual_line_num           := NULL;          -- 4262811
53156 l_tmp_amt                    := NULL;          -- 4262811
53157 --
53158  
53159 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
53160     l_balance_type_code <> 'B' THEN
53161 IF NVL(p_source_20,'
53162 ') =  'CONFIRMATION' AND 
53163 NVL(p_source_69,'
53164 ') =  'Y'
53165  THEN 
53166 
53167    --
53168    XLA_AE_LINES_PKG.SetNewLine;
53169 
53170    p_balance_type_code          := l_balance_type_code;
53171    -- set the flag so later we will know whether the gain loss line needs to be created
53172    
53173    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
53174      p_actual_flag :='A';
53175    END IF;
53176 
53177    --
53178    -- bulk performance
53179    --
53180    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
53181                                       p_header_num   => 0); -- 4262811
53182    --
53183    -- set accounting line options
53184    --
53185    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
53186            p_natural_side_code          => 'C'
53187          , p_gain_or_loss_flag          => 'N'
53188          , p_gl_transfer_mode_code      => 'S'
53189          , p_acct_entry_type_code       => 'A'
53190          , p_switch_side_flag           => 'Y'
53191          , p_merge_duplicate_code       => 'A'
53192          );
53193    --
53194    l_acc_rev_natural_side_code := 'D';  -- 4262811
53195    -- 
53196    --
53197    -- set accounting line type info
53198    --
53199    xla_ae_lines_pkg.SetAcctLineType
53200       (p_component_type             => l_component_type
53201       ,p_event_type_code            => l_event_type_code
53202       ,p_line_definition_owner_code => l_line_definition_owner_code
53203       ,p_line_definition_code       => l_line_definition_code
53204       ,p_accounting_line_code       => l_component_code
53205       ,p_accounting_line_type_code  => l_component_type_code
53206       ,p_accounting_line_appl_id    => l_component_appl_id
53207       ,p_amb_context_code           => l_amb_context_code
53208       ,p_entity_code                => l_entity_code
53209       ,p_event_class_code           => l_event_class_code);
53210    --
53211    -- set accounting class
53212    --
53213    xla_ae_lines_pkg.SetAcctClass(
53214            p_accounting_class_code  => 'CONFIRMATION'
53215          , p_ae_header_id           => l_ae_header_id
53216          );
53217 
53218    --
53219    -- set rounding class
53220    --
53221    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
53222                       'RECEIVABLE';
53223 
53224    --
53225    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
53226    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
53227    --
53228    -- bulk performance
53229    --
53230    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
53231 
53232    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
53233       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
53234 
53235    -- 4955764
53236    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
53237       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
53238 
53239    -- 4458381 Public Sector Enh
53240    
53241    --
53242    -- set accounting attributes for the line type
53243    --
53244    l_entered_amt_idx := 8;
53245    l_accted_amt_idx  := 13;
53246    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
53247    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
53248    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
53249    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
53250    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
53251    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
53252    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
53253    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
53254    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
53258    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
53255    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
53256    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
53257    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
53259    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
53260    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
53261    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
53262    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
53263    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
53264    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
53265    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
53266    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
53267    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
53268    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
53269    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
53270    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
53271    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
53272    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
53273    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
53274    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
53275    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
53276    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
53277    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
53278    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
53279 
53280    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
53281    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
53282 
53283    ---------------------------------------------------------------------------------------------------------------
53284    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
53285    ---------------------------------------------------------------------------------------------------------------
53286    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
53287 
53288    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
53289    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
53290 
53291    IF xla_accounting_cache_pkg.GetValueChar
53292          (p_source_code         => 'LEDGER_CATEGORY_CODE'
53293          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
53294    AND l_bflow_method_code = 'PRIOR_ENTRY'
53295 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
53296    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
53297          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
53298        )
53299    THEN
53300          xla_ae_lines_pkg.BflowUpgEntry
53301            (p_business_method_code    => l_bflow_method_code
53302            ,p_business_class_code     => l_bflow_class_code
53303            ,p_balance_type            => l_balance_type_code);
53304    ELSE
53305       NULL;
53306 -- No business flow processing for business flow method of NONE.
53307    END IF;
53308 
53309    --
53310    -- call analytical criteria
53311    --
53312    
53313    --
53314    -- call description
53315    --
53316    
53317 xla_ae_lines_pkg.SetLineDescription(
53318    p_ae_header_id => l_ae_header_id
53319   ,p_description  => Description_1 (
53320      p_application_id         => p_application_id
53321    , p_ae_header_id           => l_ae_header_id 
53322    )
53323 );
53324 
53325 
53326    --
53327    -- call ADRs
53328    -- Bug 4922099
53329    --
53330    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
53331         (NVL(l_actual_upg_option, 'N') = 'O') OR
53332         (NVL(l_enc_upg_option, 'N') = 'O')
53333       )
53334    THEN
53335    NULL;
53336    --
53337    --
53338    
53339   l_ccid := AcctDerRule_26(
53340            p_application_id           => p_application_id
53341          , p_ae_header_id             => l_ae_header_id 
53342 , p_source_14 => p_source_14
53343          , x_transaction_coa_id       => l_adr_transaction_coa_id
53344          , x_accounting_coa_id        => l_adr_accounting_coa_id
53345          , x_value_type_code          => l_adr_value_type_code
53346          , p_side                     => 'NA'
53347    );
53348 
53349    xla_ae_lines_pkg.set_ccid(
53350     p_code_combination_id          => l_ccid
53351   , p_value_type_code              => l_adr_value_type_code
53352   , p_transaction_coa_id           => l_adr_transaction_coa_id
53353   , p_accounting_coa_id            => l_adr_accounting_coa_id
53354   , p_adr_code                     => 'MFAR_RCT_DEF_CONFIRMATION_CCID'
53355   , p_adr_type_code                => 'S'
53356   , p_component_type               => l_component_type
53357   , p_component_code               => l_component_code
53358   , p_component_type_code          => l_component_type_code
53359   , p_component_appl_id            => l_component_appl_id
53360   , p_amb_context_code             => l_amb_context_code
53361   , p_side                         => 'NA'
53362   );
53363 
53364 
53365    l_segment := AcctDerRule_5(
53366            p_application_id           => p_application_id
53370          , x_accounting_coa_id        => l_adr_accounting_coa_id
53367          , p_ae_header_id             => l_ae_header_id 
53368 , p_source_4 => p_source_4
53369          , x_transaction_coa_id       => l_adr_transaction_coa_id
53371          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
53372          , x_flex_value_set_id        => l_adr_flex_value_set_id
53373          , x_value_type_code          => l_adr_value_type_code
53374          , x_value_combination_id     => l_adr_value_combination_id
53375          , x_value_segment_code       => l_adr_value_segment_code
53376          , p_side                     => 'NA'
53377          , p_override_seg_flag        => 'Y'
53378    );
53379 
53380    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
53381 
53382       xla_ae_lines_pkg.set_segment(
53383           p_to_segment_code         => 'GL_BALANCING'
53384         , p_segment_value           => l_segment
53385         , p_from_segment_code       => l_adr_value_segment_code
53386         , p_from_combination_id     => l_adr_value_combination_id
53387         , p_value_type_code         => l_adr_value_type_code
53388         , p_transaction_coa_id      => l_adr_transaction_coa_id
53389         , p_accounting_coa_id       => l_adr_accounting_coa_id
53390         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
53391         , p_flex_value_set_id       => l_adr_flex_value_set_id
53392         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
53393         , p_adr_type_code           => 'S'
53394         , p_component_type          => l_component_type
53395         , p_component_code          => l_component_code
53396         , p_component_type_code     => l_component_type_code
53397         , p_component_appl_id       => l_component_appl_id
53398         , p_amb_context_code        => l_amb_context_code
53399         , p_entity_code             => 'RECEIPTS'
53400         , p_event_class_code        => 'RECEIPT'
53401         , p_side                    => 'NA'
53402         );
53403 
53404   END IF;
53405 
53406    --
53407    --
53408    END IF;
53409    --
53410    -- Bug 4922099
53411    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
53412           (NVL(l_enc_upg_option, 'N') = 'O')
53413         ) AND
53414         (l_bflow_method_code = 'PRIOR_ENTRY')
53415       )
53416    THEN
53417       IF
53418       --
53419       1 = 2
53420       --
53421       THEN
53422       xla_accounting_err_pkg.build_message
53423                                     (p_appli_s_name            => 'XLA'
53424                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
53425                                     ,p_token_1                 => 'LINE_NUMBER'
53426                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
53427                                     ,p_token_2                 => 'LINE_TYPE_NAME'
53428                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
53429                                                                              l_component_type
53430                                                                             ,l_component_code
53431                                                                             ,l_component_type_code
53432                                                                             ,l_component_appl_id
53433                                                                             ,l_amb_context_code
53434                                                                             ,l_entity_code
53435                                                                             ,l_event_class_code
53436                                                                            )
53437                                     ,p_token_3                 => 'OWNER'
53438                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
53439                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
53440                                                                           ,p_lookup_code    => l_component_type_code
53441                                                                          )
53442                                     ,p_token_4                 => 'PRODUCT_NAME'
53443                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
53444                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
53445                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
53446                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
53447                                     ,p_ae_header_id            =>  NULL
53448                                        );
53449 
53450         IF (C_LEVEL_ERROR>= g_log_level) THEN
53451                  trace
53452                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
53453                       ,p_level    => C_LEVEL_ERROR
53454                       ,p_module   => l_log_module);
53455         END IF;
53456       END IF;
53457    END IF;
53458    --
53459    --
53460    ------------------------------------------------------------------------------------------------
53461    -- 4219869 Business Flow
53462    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
53463    -- Prior Entry.  Currently, the following code is always generated.
53467    ------------------------------------------------------------------------------------
53464    ------------------------------------------------------------------------------------------------
53465    XLA_AE_LINES_PKG.ValidateCurrentLine;
53466 
53468    -- 4219869 Business Flow
53469    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
53470    ------------------------------------------------------------------------------------
53471    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
53472 
53473    ----------------------------------------------------------------------------------
53474    -- 4219869 Business Flow
53475    -- Update journal entry status -- Need to generate this within IF <condition>
53476    ----------------------------------------------------------------------------------
53477    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
53478          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
53479          ,p_balance_type_code => l_balance_type_code
53480          );
53481 
53482    -------------------------------------------------------------------------------------------
53483    -- 4262811 - Generate the Accrual Reversal lines
53484    -------------------------------------------------------------------------------------------
53485    BEGIN
53486       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
53487                               (g_array_event(p_event_id).array_value_num('header_index'));
53488       IF l_acc_rev_flag IS NULL THEN
53489          l_acc_rev_flag := 'N';
53490       END IF;
53491    EXCEPTION
53492       WHEN OTHERS THEN
53493          l_acc_rev_flag := 'N';
53494    END;
53495    --
53496    IF (l_acc_rev_flag = 'Y') THEN
53497 
53498        -- 4645092  ------------------------------------------------------------------------------
53499        -- To allow MPA report to determine if it should generate report process
53500        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
53501        ------------------------------------------------------------------------------------------
53502 
53503        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
53504        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
53505    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
53506    -- call ADRs
53507    -- Bug 4922099
53508    --
53509    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
53510         (NVL(l_actual_upg_option, 'N') = 'O') OR
53511         (NVL(l_enc_upg_option, 'N') = 'O')
53512       )
53513    THEN
53514    NULL;
53515    --
53516    --
53517    
53518   l_ccid := AcctDerRule_26(
53519            p_application_id           => p_application_id
53520          , p_ae_header_id             => l_ae_header_id 
53521 , p_source_14 => p_source_14
53522          , x_transaction_coa_id       => l_adr_transaction_coa_id
53523          , x_accounting_coa_id        => l_adr_accounting_coa_id
53524          , x_value_type_code          => l_adr_value_type_code
53525          , p_side                     => 'NA'
53526    );
53527 
53528    xla_ae_lines_pkg.set_ccid(
53529     p_code_combination_id          => l_ccid
53530   , p_value_type_code              => l_adr_value_type_code
53531   , p_transaction_coa_id           => l_adr_transaction_coa_id
53532   , p_accounting_coa_id            => l_adr_accounting_coa_id
53533   , p_adr_code                     => 'MFAR_RCT_DEF_CONFIRMATION_CCID'
53534   , p_adr_type_code                => 'S'
53535   , p_component_type               => l_component_type
53536   , p_component_code               => l_component_code
53537   , p_component_type_code          => l_component_type_code
53538   , p_component_appl_id            => l_component_appl_id
53539   , p_amb_context_code             => l_amb_context_code
53540   , p_side                         => 'NA'
53541   );
53542 
53543 
53544    l_segment := AcctDerRule_5(
53545            p_application_id           => p_application_id
53546          , p_ae_header_id             => l_ae_header_id 
53547 , p_source_4 => p_source_4
53548          , x_transaction_coa_id       => l_adr_transaction_coa_id
53549          , x_accounting_coa_id        => l_adr_accounting_coa_id
53550          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
53551          , x_flex_value_set_id        => l_adr_flex_value_set_id
53552          , x_value_type_code          => l_adr_value_type_code
53553          , x_value_combination_id     => l_adr_value_combination_id
53554          , x_value_segment_code       => l_adr_value_segment_code
53555          , p_side                     => 'NA'
53556          , p_override_seg_flag        => 'Y'
53557    );
53558 
53559    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
53560 
53561       xla_ae_lines_pkg.set_segment(
53562           p_to_segment_code         => 'GL_BALANCING'
53563         , p_segment_value           => l_segment
53564         , p_from_segment_code       => l_adr_value_segment_code
53565         , p_from_combination_id     => l_adr_value_combination_id
53566         , p_value_type_code         => l_adr_value_type_code
53567         , p_transaction_coa_id      => l_adr_transaction_coa_id
53568         , p_accounting_coa_id       => l_adr_accounting_coa_id
53569         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
53570         , p_flex_value_set_id       => l_adr_flex_value_set_id
53571         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
53572         , p_adr_type_code           => 'S'
53573         , p_component_type          => l_component_type
53577         , p_amb_context_code        => l_amb_context_code
53574         , p_component_code          => l_component_code
53575         , p_component_type_code     => l_component_type_code
53576         , p_component_appl_id       => l_component_appl_id
53578         , p_entity_code             => 'RECEIPTS'
53579         , p_event_class_code        => 'RECEIPT'
53580         , p_side                    => 'NA'
53581         );
53582 
53583   END IF;
53584 
53585    --
53586    --
53587    END IF;
53588 
53589        --
53590        -- Update the line information that should be overwritten
53591        --
53592        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
53593                                          p_header_num   => 1);
53594        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
53595 
53596        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
53597 
53598        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
53599           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
53600        END IF;
53601 
53602       --
53603       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
53604       --
53605       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
53606           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
53607       ELSE
53608           ---------------------------------------------------------------------------------------------------
53609           -- 4262811a Switch Sign
53610           ---------------------------------------------------------------------------------------------------
53611           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
53612           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
53613                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
53614           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
53615                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
53616           -- 5132302
53617           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
53618                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
53619 
53620       END IF;
53621 
53622       -- 4955764
53623       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
53624       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
53625 
53626 
53627       XLA_AE_LINES_PKG.ValidateCurrentLine;
53628       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
53629 
53630       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
53631                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
53632                ,p_balance_type_code => l_balance_type_code);
53633 
53634    END IF;
53635 
53636    -----------------------------------------------------------------------------------------
53637    -- 4262811 Multiperiod Accounting
53638    -----------------------------------------------------------------------------------------
53639      -- No MPA option is assigned.
53640 
53641 
53642 END IF;
53643 END IF;
53644 --
53645 
53646 --
53647 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
53648    trace
53649       (p_msg      => 'END of AcctLineType_110'
53650       ,p_level    => C_LEVEL_PROCEDURE
53651       ,p_module   => l_log_module);
53652 END IF;
53653 --
53654 EXCEPTION
53655   WHEN xla_exceptions_pkg.application_exception THEN
53656       RAISE;
53657   WHEN OTHERS THEN
53658        xla_exceptions_pkg.raise_message
53659            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_110');
53660 END AcctLineType_110;
53661 --
53662 
53663 ---------------------------------------
53664 --
53665 -- PRIVATE FUNCTION
53666 --         AcctLineType_111
53667 --
53668 ---------------------------------------
53669 PROCEDURE AcctLineType_111 (
53670   p_application_id        IN NUMBER
53671  ,p_event_id              IN NUMBER
53672  ,p_calculate_acctd_flag  IN VARCHAR2
53673  ,p_calculate_g_l_flag    IN VARCHAR2
53674  ,p_actual_flag           IN OUT VARCHAR2
53675  ,p_balance_type_code     OUT VARCHAR2
53676  ,p_gain_or_loss_ref      OUT VARCHAR2
53677  
53678 --Distribution Source Type
53679  , p_source_20            IN VARCHAR2
53680 --Distribution Line Identifier
53681  , p_source_22            IN NUMBER
53682 --Distribution Type
53683  , p_source_23            IN VARCHAR2
53684 --Entered Amount
53685  , p_source_24            IN NUMBER
53686 --Currency Code
53687  , p_source_25            IN VARCHAR2
53688 --Applied To Document Accounting Amount
53689  , p_source_29            IN NUMBER
53690 --Transaction Distribution Account Class
53691  , p_source_33            IN VARCHAR2
53692 --Transaction Distribution Identifier
53693  , p_source_34            IN NUMBER
53694 --Transaction Distribution Type
53695  , p_source_35            IN VARCHAR2
53696 --Receipt Applied To Application Identifier
53697  , p_source_58            IN NUMBER
53698 --Transaction Entity Code
53702 --Distribution Party Type
53699  , p_source_59            IN VARCHAR2
53700 --Transaction Identifier
53701  , p_source_60            IN NUMBER
53703  , p_source_65            IN VARCHAR2
53704 --Distribution Multi Fund Additional Entry
53705  , p_source_69            IN VARCHAR2
53706 )
53707 IS
53708 
53709 l_component_type              VARCHAR2(80);
53710 l_component_code              VARCHAR2(30);
53711 l_component_type_code         VARCHAR2(1);
53712 l_component_appl_id           INTEGER;
53713 l_amb_context_code            VARCHAR2(30);
53714 l_entity_code                 VARCHAR2(30);
53715 l_event_class_code            VARCHAR2(30);
53716 l_ae_header_id                NUMBER;
53717 l_event_type_code             VARCHAR2(30);
53718 l_line_definition_code        VARCHAR2(30);
53719 l_line_definition_owner_code  VARCHAR2(1);
53720 --
53721 -- adr variables
53722 l_segment                     VARCHAR2(30);
53723 l_ccid                        NUMBER;
53724 l_adr_transaction_coa_id      NUMBER;
53725 l_adr_accounting_coa_id       NUMBER;
53726 l_adr_flexfield_segment_code  VARCHAR2(30);
53727 l_adr_flex_value_set_id       NUMBER;
53728 l_adr_value_type_code         VARCHAR2(30);
53729 l_adr_value_combination_id    NUMBER;
53730 l_adr_value_segment_code      VARCHAR2(30);
53731 
53732 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
53733 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
53734 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
53735 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
53736 
53737 -- 4262811 Variables ------------------------------------------------------------------------------------------
53738 l_entered_amt_idx             NUMBER;
53739 l_accted_amt_idx              NUMBER;
53740 l_acc_rev_flag                VARCHAR2(1);
53741 l_accrual_line_num            NUMBER;
53742 l_tmp_amt                     NUMBER;
53743 l_acc_rev_natural_side_code   VARCHAR2(1);
53744 
53745 l_num_entries                 NUMBER;
53746 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
53747 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
53748 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
53749 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
53750 l_recog_line_1                NUMBER;
53751 l_recog_line_2                NUMBER;
53752 
53753 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
53754 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
53755 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
53756 
53757 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
53758 
53759 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
53760 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
53761 
53762 ---------------------------------------------------------------------------------------------------------------
53763 
53764 
53765 --
53766 -- bulk performance
53767 --
53768 l_balance_type_code           VARCHAR2(1);
53769 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
53770 l_log_module                  VARCHAR2(240);
53771 
53772 --
53773 -- Upgrade strategy
53774 --
53775 l_actual_upg_option           VARCHAR2(1);
53776 l_enc_upg_option           VARCHAR2(1);
53777 
53778 --
53779 BEGIN
53780 --
53781 IF g_log_enabled THEN
53782       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_111';
53783 END IF;
53784 --
53785 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
53786 
53787       trace
53788          (p_msg      => 'BEGIN of AcctLineType_111'
53789          ,p_level    => C_LEVEL_PROCEDURE
53790          ,p_module   => l_log_module);
53791 
53792 END IF;
53793 --
53794 l_component_type             := 'AMB_JLT';
53795 l_component_code             := 'RCT_APP_MFAR_TRX_REC';
53796 l_component_type_code        := 'S';
53797 l_component_appl_id          :=  222;
53798 l_amb_context_code           := 'DEFAULT';
53799 l_entity_code                := 'RECEIPTS';
53800 l_event_class_code           := 'RECEIPT';
53801 l_event_type_code            := 'RECEIPT_ALL';
53802 l_line_definition_owner_code := 'S';
53803 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
53804 --
53805 l_balance_type_code          := 'A';
53806 l_segment                     := NULL;
53807 l_ccid                        := NULL;
53808 l_adr_transaction_coa_id      := NULL;
53809 l_adr_accounting_coa_id       := NULL;
53810 l_adr_flexfield_segment_code  := NULL;
53811 l_adr_flex_value_set_id       := NULL;
53812 l_adr_value_type_code         := NULL;
53813 l_adr_value_combination_id    := NULL;
53814 l_adr_value_segment_code      := NULL;
53815 
53816 l_bflow_method_code          := 'PRIOR_ENTRY';   -- 4219869 Business Flow
53817 l_bflow_class_code           := 'RECEIVABLE';    -- 4219869 Business Flow
53818 l_inherit_desc_flag          := 'Y';   -- 4219869 Business Flow
53819 l_budgetary_control_flag     := 'N';
53820 
53821 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
53822 l_bflow_applied_to_amt       := NULL; -- 5132302
53823 l_entered_amt_idx            := NULL;          -- 4262811
53824 l_accted_amt_idx             := NULL;          -- 4262811
53828 --
53825 l_acc_rev_flag               := NULL;          -- 4262811
53826 l_accrual_line_num           := NULL;          -- 4262811
53827 l_tmp_amt                    := NULL;          -- 4262811
53829  
53830 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
53831     l_balance_type_code <> 'B' THEN
53832 IF (NVL(p_source_33,'
53833 ') =  'REV' OR 
53834 NVL(p_source_33,'
53835 ') =  'TAX' OR 
53836 NVL(p_source_33,'
53837 ') =  'FREIGHT' OR 
53838 NVL(p_source_33,'
53839 ') =  'ROUND' OR 
53840 NVL(p_source_33,'
53841 ') =  'CHARGES') AND 
53842 NVL(p_source_20,'
53843 ') =  'REC' AND 
53844 NVL(p_source_69,'
53845 ') =  'N'
53846  THEN 
53847 
53848    --
53849    XLA_AE_LINES_PKG.SetNewLine;
53850 
53851    p_balance_type_code          := l_balance_type_code;
53852    -- set the flag so later we will know whether the gain loss line needs to be created
53853    
53854    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
53855      p_actual_flag :='A';
53856    END IF;
53857 
53858    --
53859    -- bulk performance
53860    --
53861    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
53862                                       p_header_num   => 0); -- 4262811
53863    --
53864    -- set accounting line options
53865    --
53866    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
53867            p_natural_side_code          => 'C'
53868          , p_gain_or_loss_flag          => 'N'
53869          , p_gl_transfer_mode_code      => 'S'
53870          , p_acct_entry_type_code       => 'A'
53871          , p_switch_side_flag           => 'Y'
53872          , p_merge_duplicate_code       => 'A'
53873          );
53874    --
53875    l_acc_rev_natural_side_code := 'D';  -- 4262811
53876    -- 
53877    --
53878    -- set accounting line type info
53879    --
53880    xla_ae_lines_pkg.SetAcctLineType
53881       (p_component_type             => l_component_type
53882       ,p_event_type_code            => l_event_type_code
53883       ,p_line_definition_owner_code => l_line_definition_owner_code
53884       ,p_line_definition_code       => l_line_definition_code
53885       ,p_accounting_line_code       => l_component_code
53886       ,p_accounting_line_type_code  => l_component_type_code
53887       ,p_accounting_line_appl_id    => l_component_appl_id
53888       ,p_amb_context_code           => l_amb_context_code
53889       ,p_entity_code                => l_entity_code
53890       ,p_event_class_code           => l_event_class_code);
53891    --
53892    -- set accounting class
53893    --
53894    xla_ae_lines_pkg.SetAcctClass(
53895            p_accounting_class_code  => 'RECEIVABLE'
53896          , p_ae_header_id           => l_ae_header_id
53897          );
53898 
53899    --
53900    -- set rounding class
53901    --
53902    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
53903                       'RECEIVABLE';
53904 
53905    --
53906    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
53907    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
53908    --
53909    -- bulk performance
53910    --
53911    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
53912 
53913    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
53914       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
53915 
53916    -- 4955764
53917    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
53918       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
53919 
53920    -- 4458381 Public Sector Enh
53921    
53922    --
53923    -- set accounting attributes for the line type
53924    --
53925    l_entered_amt_idx := 8;
53926    l_accted_amt_idx  := 10;
53927    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
53928    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
53929    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
53930    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
53931    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
53932    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
53933    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
53934    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
53935    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
53936    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
53937    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
53938    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
53939    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
53940    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
53941    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
53942    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
53943    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
53944    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
53945    l_rec_acct_attrs.array_char_value(9)  := p_source_25;
53946    l_rec_acct_attrs.array_acct_attr_code(10) := 'LEDGER_AMOUNT';
53950 
53947    l_rec_acct_attrs.array_num_value(10)  := p_source_29;
53948    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
53949    l_rec_acct_attrs.array_char_value(11)  := p_source_65;
53951    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
53952    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
53953 
53954    ---------------------------------------------------------------------------------------------------------------
53955    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
53956    ---------------------------------------------------------------------------------------------------------------
53957    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
53958 
53959    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
53960    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
53961 
53962    IF xla_accounting_cache_pkg.GetValueChar
53963          (p_source_code         => 'LEDGER_CATEGORY_CODE'
53964          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
53965    AND l_bflow_method_code = 'PRIOR_ENTRY'
53966 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
53967    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
53968          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
53969        )
53970    THEN
53971          xla_ae_lines_pkg.BflowUpgEntry
53972            (p_business_method_code    => l_bflow_method_code
53973            ,p_business_class_code     => l_bflow_class_code
53974            ,p_balance_type            => l_balance_type_code);
53975    ELSE
53976       NULL;
53977 XLA_AE_LINES_PKG.business_flow_validation(
53978                                 p_business_method_code     => l_bflow_method_code
53979                                ,p_business_class_code      => l_bflow_class_code
53980                                ,p_inherit_description_flag => l_inherit_desc_flag);
53981    END IF;
53982 
53983    --
53984    -- call analytical criteria
53985    --
53986    -- Inherited Analytical Criteria for business flow method of Prior Entry.
53987    --
53988    -- call description
53989    --
53990    -- No description or it is inherited.
53991    --
53992    -- call ADRs
53993    -- Bug 4922099
53994    --
53995    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
53996         (NVL(l_actual_upg_option, 'N') = 'O') OR
53997         (NVL(l_enc_upg_option, 'N') = 'O')
53998       )
53999    THEN
54000    NULL;
54001    --
54002    --
54003    
54004    --
54005    --
54006    END IF;
54007    --
54008    -- Bug 4922099
54009    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
54010           (NVL(l_enc_upg_option, 'N') = 'O')
54011         ) AND
54012         (l_bflow_method_code = 'PRIOR_ENTRY')
54013       )
54014    THEN
54015       IF
54016       --
54017       1 = 1
54018       --
54019       THEN
54020       xla_accounting_err_pkg.build_message
54021                                     (p_appli_s_name            => 'XLA'
54022                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
54023                                     ,p_token_1                 => 'LINE_NUMBER'
54024                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
54025                                     ,p_token_2                 => 'LINE_TYPE_NAME'
54026                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
54027                                                                              l_component_type
54028                                                                             ,l_component_code
54029                                                                             ,l_component_type_code
54030                                                                             ,l_component_appl_id
54031                                                                             ,l_amb_context_code
54032                                                                             ,l_entity_code
54033                                                                             ,l_event_class_code
54034                                                                            )
54035                                     ,p_token_3                 => 'OWNER'
54036                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
54037                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
54038                                                                           ,p_lookup_code    => l_component_type_code
54039                                                                          )
54040                                     ,p_token_4                 => 'PRODUCT_NAME'
54041                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
54042                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
54043                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
54044                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
54045                                     ,p_ae_header_id            =>  NULL
54046                                        );
54047 
54051                       ,p_level    => C_LEVEL_ERROR
54048         IF (C_LEVEL_ERROR>= g_log_level) THEN
54049                  trace
54050                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
54052                       ,p_module   => l_log_module);
54053         END IF;
54054       END IF;
54055    END IF;
54056    --
54057    --
54058    ------------------------------------------------------------------------------------------------
54059    -- 4219869 Business Flow
54060    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
54061    -- Prior Entry.  Currently, the following code is always generated.
54062    ------------------------------------------------------------------------------------------------
54063    -- No ValidateCurrentLine for business flow method of Prior Entry
54064 
54065    ------------------------------------------------------------------------------------
54066    -- 4219869 Business Flow
54067    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
54068    ------------------------------------------------------------------------------------
54069    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
54070 
54071    ----------------------------------------------------------------------------------
54072    -- 4219869 Business Flow
54073    -- Update journal entry status -- Need to generate this within IF <condition>
54074    ----------------------------------------------------------------------------------
54075    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
54076          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
54077          ,p_balance_type_code => l_balance_type_code
54078          );
54079 
54080    -------------------------------------------------------------------------------------------
54081    -- 4262811 - Generate the Accrual Reversal lines
54082    -------------------------------------------------------------------------------------------
54083    BEGIN
54084       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
54085                               (g_array_event(p_event_id).array_value_num('header_index'));
54086       IF l_acc_rev_flag IS NULL THEN
54087          l_acc_rev_flag := 'N';
54088       END IF;
54089    EXCEPTION
54090       WHEN OTHERS THEN
54091          l_acc_rev_flag := 'N';
54092    END;
54093    --
54094    IF (l_acc_rev_flag = 'Y') THEN
54095 
54096        -- 4645092  ------------------------------------------------------------------------------
54097        -- To allow MPA report to determine if it should generate report process
54098        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
54099        ------------------------------------------------------------------------------------------
54100 
54101        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
54102        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
54103    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
54104    -- call ADRs
54105    -- Bug 4922099
54106    --
54107    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
54108         (NVL(l_actual_upg_option, 'N') = 'O') OR
54109         (NVL(l_enc_upg_option, 'N') = 'O')
54110       )
54111    THEN
54112    NULL;
54113    --
54114    --
54115    
54116    --
54117    --
54118    END IF;
54119 
54120        --
54121        -- Update the line information that should be overwritten
54122        --
54123        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
54124                                          p_header_num   => 1);
54125        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
54126 
54127        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
54128 
54129        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
54130           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
54131        END IF;
54132 
54133       --
54134       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
54135       --
54136       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
54137           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
54138       ELSE
54139           ---------------------------------------------------------------------------------------------------
54140           -- 4262811a Switch Sign
54141           ---------------------------------------------------------------------------------------------------
54142           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
54143           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
54144                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
54145           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
54146                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
54147           -- 5132302
54148           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
54149                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
54150 
54151       END IF;
54152 
54153       -- 4955764
54154       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
54158       XLA_AE_LINES_PKG.ValidateCurrentLine;
54155       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
54156 
54157 
54159       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
54160 
54161       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
54162                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
54163                ,p_balance_type_code => l_balance_type_code);
54164 
54165    END IF;
54166 
54167    -----------------------------------------------------------------------------------------
54168    -- 4262811 Multiperiod Accounting
54169    -----------------------------------------------------------------------------------------
54170      -- No MPA option is assigned.
54171 
54172 
54173 END IF;
54174 END IF;
54175 --
54176 
54177 --
54178 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
54179    trace
54180       (p_msg      => 'END of AcctLineType_111'
54181       ,p_level    => C_LEVEL_PROCEDURE
54182       ,p_module   => l_log_module);
54183 END IF;
54184 --
54185 EXCEPTION
54186   WHEN xla_exceptions_pkg.application_exception THEN
54187       RAISE;
54188   WHEN OTHERS THEN
54189        xla_exceptions_pkg.raise_message
54190            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_111');
54191 END AcctLineType_111;
54192 --
54193 
54194 ---------------------------------------
54195 --
54196 -- PRIVATE FUNCTION
54197 --         AcctLineType_112
54198 --
54199 ---------------------------------------
54200 PROCEDURE AcctLineType_112 (
54201   p_application_id        IN NUMBER
54202  ,p_event_id              IN NUMBER
54203  ,p_calculate_acctd_flag  IN VARCHAR2
54204  ,p_calculate_g_l_flag    IN VARCHAR2
54205  ,p_actual_flag           IN OUT VARCHAR2
54206  ,p_balance_type_code     OUT VARCHAR2
54207  ,p_gain_or_loss_ref      OUT VARCHAR2
54208  
54209 --Transaction Distribution GL Account
54210  , p_source_4            IN NUMBER
54211 --Remittance Bank Account Remittance Account
54212  , p_source_15            IN NUMBER
54213 --Distribution Source Type
54214  , p_source_20            IN VARCHAR2
54215 --Distribution Line Identifier
54216  , p_source_22            IN NUMBER
54217 --Distribution Type
54218  , p_source_23            IN VARCHAR2
54219 --Exchange Date
54220  , p_source_26            IN DATE
54221 --Exchange Rate
54222  , p_source_27            IN NUMBER
54223 --Exchange Rate Type
54224  , p_source_28            IN VARCHAR2
54225 --Transaction Distribution Identifier
54226  , p_source_34            IN NUMBER
54227 --Transaction Distribution Type
54228  , p_source_35            IN VARCHAR2
54229 --Receipt Applied To Application Identifier
54230  , p_source_58            IN NUMBER
54231 --Transaction Entity Code
54232  , p_source_59            IN VARCHAR2
54233 --Transaction Identifier
54234  , p_source_60            IN NUMBER
54235 --Applying Document Currency Code
54236  , p_source_61            IN VARCHAR2
54237 --Distribution Party Identifier
54238  , p_source_63            IN NUMBER
54239 --Distribution Party Site Id
54240  , p_source_64            IN NUMBER
54241 --Distribution Party Type
54242  , p_source_65            IN VARCHAR2
54243 --Distribution Multi Fund Additional Entry
54244  , p_source_69            IN VARCHAR2
54245 --DIST_ENT_AMT_FROM
54246  , p_source_72            IN NUMBER
54247 --Accounting Amount
54248  , p_source_73            IN NUMBER
54249 )
54250 IS
54251 
54252 l_component_type              VARCHAR2(80);
54253 l_component_code              VARCHAR2(30);
54254 l_component_type_code         VARCHAR2(1);
54255 l_component_appl_id           INTEGER;
54256 l_amb_context_code            VARCHAR2(30);
54257 l_entity_code                 VARCHAR2(30);
54258 l_event_class_code            VARCHAR2(30);
54259 l_ae_header_id                NUMBER;
54260 l_event_type_code             VARCHAR2(30);
54261 l_line_definition_code        VARCHAR2(30);
54262 l_line_definition_owner_code  VARCHAR2(1);
54263 --
54264 -- adr variables
54265 l_segment                     VARCHAR2(30);
54266 l_ccid                        NUMBER;
54267 l_adr_transaction_coa_id      NUMBER;
54268 l_adr_accounting_coa_id       NUMBER;
54269 l_adr_flexfield_segment_code  VARCHAR2(30);
54270 l_adr_flex_value_set_id       NUMBER;
54271 l_adr_value_type_code         VARCHAR2(30);
54272 l_adr_value_combination_id    NUMBER;
54273 l_adr_value_segment_code      VARCHAR2(30);
54274 
54275 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
54276 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
54277 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
54278 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
54279 
54280 -- 4262811 Variables ------------------------------------------------------------------------------------------
54281 l_entered_amt_idx             NUMBER;
54282 l_accted_amt_idx              NUMBER;
54283 l_acc_rev_flag                VARCHAR2(1);
54284 l_accrual_line_num            NUMBER;
54285 l_tmp_amt                     NUMBER;
54286 l_acc_rev_natural_side_code   VARCHAR2(1);
54287 
54288 l_num_entries                 NUMBER;
54289 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
54290 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
54291 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
54295 
54292 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
54293 l_recog_line_1                NUMBER;
54294 l_recog_line_2                NUMBER;
54296 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
54297 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
54298 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
54299 
54300 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
54301 
54302 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
54303 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
54304 
54305 ---------------------------------------------------------------------------------------------------------------
54306 
54307 
54308 --
54309 -- bulk performance
54310 --
54311 l_balance_type_code           VARCHAR2(1);
54312 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
54313 l_log_module                  VARCHAR2(240);
54314 
54315 --
54316 -- Upgrade strategy
54317 --
54318 l_actual_upg_option           VARCHAR2(1);
54319 l_enc_upg_option           VARCHAR2(1);
54320 
54321 --
54322 BEGIN
54323 --
54324 IF g_log_enabled THEN
54325       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_112';
54326 END IF;
54327 --
54328 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
54329 
54330       trace
54331          (p_msg      => 'BEGIN of AcctLineType_112'
54332          ,p_level    => C_LEVEL_PROCEDURE
54333          ,p_module   => l_log_module);
54334 
54335 END IF;
54336 --
54337 l_component_type             := 'AMB_JLT';
54338 l_component_code             := 'RCT_APP_MFAR_TRX_REMITTANCE';
54339 l_component_type_code        := 'S';
54340 l_component_appl_id          :=  222;
54341 l_amb_context_code           := 'DEFAULT';
54342 l_entity_code                := 'RECEIPTS';
54343 l_event_class_code           := 'RECEIPT';
54344 l_event_type_code            := 'RECEIPT_ALL';
54345 l_line_definition_owner_code := 'S';
54346 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
54347 --
54348 l_balance_type_code          := 'A';
54349 l_segment                     := NULL;
54350 l_ccid                        := NULL;
54351 l_adr_transaction_coa_id      := NULL;
54352 l_adr_accounting_coa_id       := NULL;
54353 l_adr_flexfield_segment_code  := NULL;
54354 l_adr_flex_value_set_id       := NULL;
54355 l_adr_value_type_code         := NULL;
54356 l_adr_value_combination_id    := NULL;
54357 l_adr_value_segment_code      := NULL;
54358 
54359 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
54360 l_bflow_class_code           := '';    -- 4219869 Business Flow
54361 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
54362 l_budgetary_control_flag     := 'N';
54363 
54364 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
54365 l_bflow_applied_to_amt       := NULL; -- 5132302
54366 l_entered_amt_idx            := NULL;          -- 4262811
54367 l_accted_amt_idx             := NULL;          -- 4262811
54368 l_acc_rev_flag               := NULL;          -- 4262811
54369 l_accrual_line_num           := NULL;          -- 4262811
54370 l_tmp_amt                    := NULL;          -- 4262811
54371 --
54372  
54373 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
54374     l_balance_type_code <> 'B' THEN
54375 IF NVL(p_source_20,'
54376 ') =  'REMITTANCE' AND 
54377 NVL(p_source_69,'
54378 ') =  'Y'
54379  THEN 
54380 
54381    --
54382    XLA_AE_LINES_PKG.SetNewLine;
54383 
54384    p_balance_type_code          := l_balance_type_code;
54385    -- set the flag so later we will know whether the gain loss line needs to be created
54386    
54387    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
54388      p_actual_flag :='A';
54389    END IF;
54390 
54391    --
54392    -- bulk performance
54393    --
54394    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
54395                                       p_header_num   => 0); -- 4262811
54396    --
54397    -- set accounting line options
54398    --
54399    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
54400            p_natural_side_code          => 'C'
54401          , p_gain_or_loss_flag          => 'N'
54402          , p_gl_transfer_mode_code      => 'S'
54403          , p_acct_entry_type_code       => 'A'
54404          , p_switch_side_flag           => 'Y'
54405          , p_merge_duplicate_code       => 'A'
54406          );
54407    --
54408    l_acc_rev_natural_side_code := 'D';  -- 4262811
54409    -- 
54410    --
54411    -- set accounting line type info
54412    --
54413    xla_ae_lines_pkg.SetAcctLineType
54414       (p_component_type             => l_component_type
54415       ,p_event_type_code            => l_event_type_code
54416       ,p_line_definition_owner_code => l_line_definition_owner_code
54417       ,p_line_definition_code       => l_line_definition_code
54418       ,p_accounting_line_code       => l_component_code
54419       ,p_accounting_line_type_code  => l_component_type_code
54420       ,p_accounting_line_appl_id    => l_component_appl_id
54421       ,p_amb_context_code           => l_amb_context_code
54422       ,p_entity_code                => l_entity_code
54426    --
54423       ,p_event_class_code           => l_event_class_code);
54424    --
54425    -- set accounting class
54427    xla_ae_lines_pkg.SetAcctClass(
54428            p_accounting_class_code  => 'REMITTANCE'
54429          , p_ae_header_id           => l_ae_header_id
54430          );
54431 
54432    --
54433    -- set rounding class
54434    --
54435    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
54436                       'RECEIVABLE';
54437 
54438    --
54439    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
54440    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
54441    --
54442    -- bulk performance
54443    --
54444    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
54445 
54446    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
54447       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
54448 
54449    -- 4955764
54450    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
54451       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
54452 
54453    -- 4458381 Public Sector Enh
54454    
54455    --
54456    -- set accounting attributes for the line type
54457    --
54458    l_entered_amt_idx := 8;
54459    l_accted_amt_idx  := 13;
54460    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
54461    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
54462    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
54463    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
54464    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
54465    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
54466    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
54467    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
54468    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
54469    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
54470    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
54471    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
54472    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
54473    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
54474    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
54475    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
54476    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
54477    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
54478    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
54479    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
54480    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
54481    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
54482    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
54483    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
54484    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
54485    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
54486    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
54487    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
54488    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
54489    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
54490    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
54491    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
54492    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
54493 
54494    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
54495    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
54496 
54497    ---------------------------------------------------------------------------------------------------------------
54498    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
54499    ---------------------------------------------------------------------------------------------------------------
54500    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
54501 
54502    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
54503    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
54504 
54505    IF xla_accounting_cache_pkg.GetValueChar
54506          (p_source_code         => 'LEDGER_CATEGORY_CODE'
54507          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
54508    AND l_bflow_method_code = 'PRIOR_ENTRY'
54509 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
54510    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
54511          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
54512        )
54513    THEN
54514          xla_ae_lines_pkg.BflowUpgEntry
54515            (p_business_method_code    => l_bflow_method_code
54516            ,p_business_class_code     => l_bflow_class_code
54517            ,p_balance_type            => l_balance_type_code);
54518    ELSE
54519       NULL;
54520 -- No business flow processing for business flow method of NONE.
54521    END IF;
54522 
54523    --
54524    -- call analytical criteria
54525    --
54529    --
54526    
54527    --
54528    -- call description
54530    
54531 xla_ae_lines_pkg.SetLineDescription(
54532    p_ae_header_id => l_ae_header_id
54533   ,p_description  => Description_1 (
54534      p_application_id         => p_application_id
54535    , p_ae_header_id           => l_ae_header_id 
54536    )
54537 );
54538 
54539 
54540    --
54541    -- call ADRs
54542    -- Bug 4922099
54543    --
54544    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
54545         (NVL(l_actual_upg_option, 'N') = 'O') OR
54546         (NVL(l_enc_upg_option, 'N') = 'O')
54547       )
54548    THEN
54549    NULL;
54550    --
54551    --
54552    
54553   l_ccid := AcctDerRule_27(
54554            p_application_id           => p_application_id
54555          , p_ae_header_id             => l_ae_header_id 
54556 , p_source_15 => p_source_15
54557          , x_transaction_coa_id       => l_adr_transaction_coa_id
54558          , x_accounting_coa_id        => l_adr_accounting_coa_id
54559          , x_value_type_code          => l_adr_value_type_code
54560          , p_side                     => 'NA'
54561    );
54562 
54563    xla_ae_lines_pkg.set_ccid(
54564     p_code_combination_id          => l_ccid
54565   , p_value_type_code              => l_adr_value_type_code
54566   , p_transaction_coa_id           => l_adr_transaction_coa_id
54567   , p_accounting_coa_id            => l_adr_accounting_coa_id
54568   , p_adr_code                     => 'MFAR_RCT_DEF_REMITTANCE_CCID'
54569   , p_adr_type_code                => 'S'
54570   , p_component_type               => l_component_type
54571   , p_component_code               => l_component_code
54572   , p_component_type_code          => l_component_type_code
54573   , p_component_appl_id            => l_component_appl_id
54574   , p_amb_context_code             => l_amb_context_code
54575   , p_side                         => 'NA'
54576   );
54577 
54578 
54579    l_segment := AcctDerRule_5(
54580            p_application_id           => p_application_id
54581          , p_ae_header_id             => l_ae_header_id 
54582 , p_source_4 => p_source_4
54583          , x_transaction_coa_id       => l_adr_transaction_coa_id
54584          , x_accounting_coa_id        => l_adr_accounting_coa_id
54585          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
54586          , x_flex_value_set_id        => l_adr_flex_value_set_id
54587          , x_value_type_code          => l_adr_value_type_code
54588          , x_value_combination_id     => l_adr_value_combination_id
54589          , x_value_segment_code       => l_adr_value_segment_code
54590          , p_side                     => 'NA'
54591          , p_override_seg_flag        => 'Y'
54592    );
54593 
54594    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
54595 
54596       xla_ae_lines_pkg.set_segment(
54597           p_to_segment_code         => 'GL_BALANCING'
54598         , p_segment_value           => l_segment
54599         , p_from_segment_code       => l_adr_value_segment_code
54600         , p_from_combination_id     => l_adr_value_combination_id
54601         , p_value_type_code         => l_adr_value_type_code
54602         , p_transaction_coa_id      => l_adr_transaction_coa_id
54603         , p_accounting_coa_id       => l_adr_accounting_coa_id
54604         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
54605         , p_flex_value_set_id       => l_adr_flex_value_set_id
54606         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
54607         , p_adr_type_code           => 'S'
54608         , p_component_type          => l_component_type
54609         , p_component_code          => l_component_code
54610         , p_component_type_code     => l_component_type_code
54611         , p_component_appl_id       => l_component_appl_id
54612         , p_amb_context_code        => l_amb_context_code
54613         , p_entity_code             => 'RECEIPTS'
54614         , p_event_class_code        => 'RECEIPT'
54615         , p_side                    => 'NA'
54616         );
54617 
54618   END IF;
54619 
54620    --
54621    --
54622    END IF;
54623    --
54624    -- Bug 4922099
54625    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
54626           (NVL(l_enc_upg_option, 'N') = 'O')
54627         ) AND
54628         (l_bflow_method_code = 'PRIOR_ENTRY')
54629       )
54630    THEN
54631       IF
54632       --
54633       1 = 2
54634       --
54635       THEN
54636       xla_accounting_err_pkg.build_message
54637                                     (p_appli_s_name            => 'XLA'
54638                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
54639                                     ,p_token_1                 => 'LINE_NUMBER'
54640                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
54641                                     ,p_token_2                 => 'LINE_TYPE_NAME'
54642                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
54643                                                                              l_component_type
54644                                                                             ,l_component_code
54645                                                                             ,l_component_type_code
54646                                                                             ,l_component_appl_id
54650                                                                            )
54647                                                                             ,l_amb_context_code
54648                                                                             ,l_entity_code
54649                                                                             ,l_event_class_code
54651                                     ,p_token_3                 => 'OWNER'
54652                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
54653                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
54654                                                                           ,p_lookup_code    => l_component_type_code
54655                                                                          )
54656                                     ,p_token_4                 => 'PRODUCT_NAME'
54657                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
54658                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
54659                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
54660                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
54661                                     ,p_ae_header_id            =>  NULL
54662                                        );
54663 
54664         IF (C_LEVEL_ERROR>= g_log_level) THEN
54665                  trace
54666                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
54667                       ,p_level    => C_LEVEL_ERROR
54668                       ,p_module   => l_log_module);
54669         END IF;
54670       END IF;
54671    END IF;
54672    --
54673    --
54674    ------------------------------------------------------------------------------------------------
54675    -- 4219869 Business Flow
54676    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
54677    -- Prior Entry.  Currently, the following code is always generated.
54678    ------------------------------------------------------------------------------------------------
54679    XLA_AE_LINES_PKG.ValidateCurrentLine;
54680 
54681    ------------------------------------------------------------------------------------
54682    -- 4219869 Business Flow
54683    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
54684    ------------------------------------------------------------------------------------
54685    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
54686 
54687    ----------------------------------------------------------------------------------
54688    -- 4219869 Business Flow
54689    -- Update journal entry status -- Need to generate this within IF <condition>
54690    ----------------------------------------------------------------------------------
54691    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
54692          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
54693          ,p_balance_type_code => l_balance_type_code
54694          );
54695 
54696    -------------------------------------------------------------------------------------------
54697    -- 4262811 - Generate the Accrual Reversal lines
54698    -------------------------------------------------------------------------------------------
54699    BEGIN
54700       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
54701                               (g_array_event(p_event_id).array_value_num('header_index'));
54702       IF l_acc_rev_flag IS NULL THEN
54703          l_acc_rev_flag := 'N';
54704       END IF;
54705    EXCEPTION
54706       WHEN OTHERS THEN
54707          l_acc_rev_flag := 'N';
54708    END;
54709    --
54710    IF (l_acc_rev_flag = 'Y') THEN
54711 
54712        -- 4645092  ------------------------------------------------------------------------------
54713        -- To allow MPA report to determine if it should generate report process
54714        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
54715        ------------------------------------------------------------------------------------------
54716 
54717        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
54718        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
54719    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
54720    -- call ADRs
54721    -- Bug 4922099
54722    --
54723    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
54724         (NVL(l_actual_upg_option, 'N') = 'O') OR
54725         (NVL(l_enc_upg_option, 'N') = 'O')
54726       )
54727    THEN
54728    NULL;
54729    --
54730    --
54731    
54732   l_ccid := AcctDerRule_27(
54733            p_application_id           => p_application_id
54734          , p_ae_header_id             => l_ae_header_id 
54735 , p_source_15 => p_source_15
54736          , x_transaction_coa_id       => l_adr_transaction_coa_id
54737          , x_accounting_coa_id        => l_adr_accounting_coa_id
54738          , x_value_type_code          => l_adr_value_type_code
54739          , p_side                     => 'NA'
54740    );
54741 
54742    xla_ae_lines_pkg.set_ccid(
54743     p_code_combination_id          => l_ccid
54744   , p_value_type_code              => l_adr_value_type_code
54745   , p_transaction_coa_id           => l_adr_transaction_coa_id
54746   , p_accounting_coa_id            => l_adr_accounting_coa_id
54747   , p_adr_code                     => 'MFAR_RCT_DEF_REMITTANCE_CCID'
54751   , p_component_type_code          => l_component_type_code
54748   , p_adr_type_code                => 'S'
54749   , p_component_type               => l_component_type
54750   , p_component_code               => l_component_code
54752   , p_component_appl_id            => l_component_appl_id
54753   , p_amb_context_code             => l_amb_context_code
54754   , p_side                         => 'NA'
54755   );
54756 
54757 
54758    l_segment := AcctDerRule_5(
54759            p_application_id           => p_application_id
54760          , p_ae_header_id             => l_ae_header_id 
54761 , p_source_4 => p_source_4
54762          , x_transaction_coa_id       => l_adr_transaction_coa_id
54763          , x_accounting_coa_id        => l_adr_accounting_coa_id
54764          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
54765          , x_flex_value_set_id        => l_adr_flex_value_set_id
54766          , x_value_type_code          => l_adr_value_type_code
54767          , x_value_combination_id     => l_adr_value_combination_id
54768          , x_value_segment_code       => l_adr_value_segment_code
54769          , p_side                     => 'NA'
54770          , p_override_seg_flag        => 'Y'
54771    );
54772 
54773    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
54774 
54775       xla_ae_lines_pkg.set_segment(
54776           p_to_segment_code         => 'GL_BALANCING'
54777         , p_segment_value           => l_segment
54778         , p_from_segment_code       => l_adr_value_segment_code
54779         , p_from_combination_id     => l_adr_value_combination_id
54780         , p_value_type_code         => l_adr_value_type_code
54781         , p_transaction_coa_id      => l_adr_transaction_coa_id
54782         , p_accounting_coa_id       => l_adr_accounting_coa_id
54783         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
54784         , p_flex_value_set_id       => l_adr_flex_value_set_id
54785         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
54786         , p_adr_type_code           => 'S'
54787         , p_component_type          => l_component_type
54788         , p_component_code          => l_component_code
54789         , p_component_type_code     => l_component_type_code
54790         , p_component_appl_id       => l_component_appl_id
54791         , p_amb_context_code        => l_amb_context_code
54792         , p_entity_code             => 'RECEIPTS'
54793         , p_event_class_code        => 'RECEIPT'
54794         , p_side                    => 'NA'
54795         );
54796 
54797   END IF;
54798 
54799    --
54800    --
54801    END IF;
54802 
54803        --
54804        -- Update the line information that should be overwritten
54805        --
54806        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
54807                                          p_header_num   => 1);
54808        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
54809 
54810        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
54811 
54812        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
54813           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
54814        END IF;
54815 
54816       --
54817       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
54818       --
54819       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
54820           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
54821       ELSE
54822           ---------------------------------------------------------------------------------------------------
54823           -- 4262811a Switch Sign
54824           ---------------------------------------------------------------------------------------------------
54825           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
54826           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
54827                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
54828           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
54829                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
54830           -- 5132302
54831           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
54832                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
54833 
54834       END IF;
54835 
54836       -- 4955764
54837       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
54838       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
54839 
54840 
54841       XLA_AE_LINES_PKG.ValidateCurrentLine;
54842       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
54843 
54844       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
54845                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
54846                ,p_balance_type_code => l_balance_type_code);
54847 
54848    END IF;
54849 
54850    -----------------------------------------------------------------------------------------
54851    -- 4262811 Multiperiod Accounting
54855 
54852    -----------------------------------------------------------------------------------------
54853      -- No MPA option is assigned.
54854 
54856 END IF;
54857 END IF;
54858 --
54859 
54860 --
54861 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
54862    trace
54863       (p_msg      => 'END of AcctLineType_112'
54864       ,p_level    => C_LEVEL_PROCEDURE
54865       ,p_module   => l_log_module);
54866 END IF;
54867 --
54868 EXCEPTION
54869   WHEN xla_exceptions_pkg.application_exception THEN
54870       RAISE;
54871   WHEN OTHERS THEN
54872        xla_exceptions_pkg.raise_message
54873            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_112');
54874 END AcctLineType_112;
54875 --
54876 
54877 ---------------------------------------
54878 --
54879 -- PRIVATE FUNCTION
54880 --         AcctLineType_113
54881 --
54882 ---------------------------------------
54883 PROCEDURE AcctLineType_113 (
54884   p_application_id        IN NUMBER
54885  ,p_event_id              IN NUMBER
54886  ,p_calculate_acctd_flag  IN VARCHAR2
54887  ,p_calculate_g_l_flag    IN VARCHAR2
54888  ,p_actual_flag           IN OUT VARCHAR2
54889  ,p_balance_type_code     OUT VARCHAR2
54890  ,p_gain_or_loss_ref      OUT VARCHAR2
54891  
54892 --Distribution GL Account
54893  , p_source_3            IN NUMBER
54894 --Distribution Source Type
54895  , p_source_20            IN VARCHAR2
54896 --Distribution Line Identifier
54897  , p_source_22            IN NUMBER
54898 --Distribution Type
54899  , p_source_23            IN VARCHAR2
54900 --Exchange Date
54901  , p_source_26            IN DATE
54902 --Exchange Rate
54903  , p_source_27            IN NUMBER
54904 --Exchange Rate Type
54905  , p_source_28            IN VARCHAR2
54906 --Transaction Distribution Identifier
54907  , p_source_34            IN NUMBER
54908 --Transaction Distribution Type
54909  , p_source_35            IN VARCHAR2
54910 --Receipt Applied To Application Identifier
54911  , p_source_58            IN NUMBER
54912 --Transaction Entity Code
54913  , p_source_59            IN VARCHAR2
54914 --Transaction Identifier
54915  , p_source_60            IN NUMBER
54916 --Applying Document Currency Code
54917  , p_source_61            IN VARCHAR2
54918 --Distribution Party Identifier
54919  , p_source_63            IN NUMBER
54920 --Distribution Party Site Id
54921  , p_source_64            IN NUMBER
54922 --Distribution Party Type
54923  , p_source_65            IN VARCHAR2
54924 --Distribution Multi Fund Additional Entry
54925  , p_source_69            IN VARCHAR2
54926 --DIST_ENT_AMT_FROM
54927  , p_source_72            IN NUMBER
54928 --Accounting Amount
54929  , p_source_73            IN NUMBER
54930 )
54931 IS
54932 
54933 l_component_type              VARCHAR2(80);
54934 l_component_code              VARCHAR2(30);
54935 l_component_type_code         VARCHAR2(1);
54936 l_component_appl_id           INTEGER;
54937 l_amb_context_code            VARCHAR2(30);
54938 l_entity_code                 VARCHAR2(30);
54939 l_event_class_code            VARCHAR2(30);
54940 l_ae_header_id                NUMBER;
54941 l_event_type_code             VARCHAR2(30);
54942 l_line_definition_code        VARCHAR2(30);
54943 l_line_definition_owner_code  VARCHAR2(1);
54944 --
54945 -- adr variables
54946 l_segment                     VARCHAR2(30);
54947 l_ccid                        NUMBER;
54948 l_adr_transaction_coa_id      NUMBER;
54949 l_adr_accounting_coa_id       NUMBER;
54950 l_adr_flexfield_segment_code  VARCHAR2(30);
54951 l_adr_flex_value_set_id       NUMBER;
54952 l_adr_value_type_code         VARCHAR2(30);
54953 l_adr_value_combination_id    NUMBER;
54954 l_adr_value_segment_code      VARCHAR2(30);
54955 
54956 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
54957 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
54958 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
54959 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
54960 
54961 -- 4262811 Variables ------------------------------------------------------------------------------------------
54962 l_entered_amt_idx             NUMBER;
54963 l_accted_amt_idx              NUMBER;
54964 l_acc_rev_flag                VARCHAR2(1);
54965 l_accrual_line_num            NUMBER;
54966 l_tmp_amt                     NUMBER;
54967 l_acc_rev_natural_side_code   VARCHAR2(1);
54968 
54969 l_num_entries                 NUMBER;
54970 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
54971 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
54972 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
54973 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
54974 l_recog_line_1                NUMBER;
54975 l_recog_line_2                NUMBER;
54976 
54977 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
54978 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
54979 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
54980 
54981 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
54982 
54983 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
54984 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
54985 
54989 --
54986 ---------------------------------------------------------------------------------------------------------------
54987 
54988 
54990 -- bulk performance
54991 --
54992 l_balance_type_code           VARCHAR2(1);
54993 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
54994 l_log_module                  VARCHAR2(240);
54995 
54996 --
54997 -- Upgrade strategy
54998 --
54999 l_actual_upg_option           VARCHAR2(1);
55000 l_enc_upg_option           VARCHAR2(1);
55001 
55002 --
55003 BEGIN
55004 --
55005 IF g_log_enabled THEN
55006       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_113';
55007 END IF;
55008 --
55009 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
55010 
55011       trace
55012          (p_msg      => 'BEGIN of AcctLineType_113'
55013          ,p_level    => C_LEVEL_PROCEDURE
55014          ,p_module   => l_log_module);
55015 
55016 END IF;
55017 --
55018 l_component_type             := 'AMB_JLT';
55019 l_component_code             := 'RCT_BNK_CHG';
55020 l_component_type_code        := 'S';
55021 l_component_appl_id          :=  222;
55022 l_amb_context_code           := 'DEFAULT';
55023 l_entity_code                := 'RECEIPTS';
55024 l_event_class_code           := 'RECEIPT';
55025 l_event_type_code            := 'RECEIPT_ALL';
55026 l_line_definition_owner_code := 'S';
55027 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
55028 --
55029 l_balance_type_code          := 'A';
55030 l_segment                     := NULL;
55031 l_ccid                        := NULL;
55032 l_adr_transaction_coa_id      := NULL;
55033 l_adr_accounting_coa_id       := NULL;
55034 l_adr_flexfield_segment_code  := NULL;
55035 l_adr_flex_value_set_id       := NULL;
55036 l_adr_value_type_code         := NULL;
55037 l_adr_value_combination_id    := NULL;
55038 l_adr_value_segment_code      := NULL;
55039 
55040 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
55041 l_bflow_class_code           := '';    -- 4219869 Business Flow
55042 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
55043 l_budgetary_control_flag     := 'N';
55044 
55045 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
55046 l_bflow_applied_to_amt       := NULL; -- 5132302
55047 l_entered_amt_idx            := NULL;          -- 4262811
55048 l_accted_amt_idx             := NULL;          -- 4262811
55049 l_acc_rev_flag               := NULL;          -- 4262811
55050 l_accrual_line_num           := NULL;          -- 4262811
55051 l_tmp_amt                    := NULL;          -- 4262811
55052 --
55053  
55054 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
55055     l_balance_type_code <> 'B' THEN
55056 IF NVL(p_source_20,'
55057 ') =  'BANK_CHARGES' AND 
55058 NVL(p_source_69,'
55059 ') =  'N'
55060  THEN 
55061 
55062    --
55063    XLA_AE_LINES_PKG.SetNewLine;
55064 
55065    p_balance_type_code          := l_balance_type_code;
55066    -- set the flag so later we will know whether the gain loss line needs to be created
55067    
55068    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
55069      p_actual_flag :='A';
55070    END IF;
55071 
55072    --
55073    -- bulk performance
55074    --
55075    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
55076                                       p_header_num   => 0); -- 4262811
55077    --
55078    -- set accounting line options
55079    --
55080    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
55081            p_natural_side_code          => 'C'
55082          , p_gain_or_loss_flag          => 'N'
55083          , p_gl_transfer_mode_code      => 'S'
55084          , p_acct_entry_type_code       => 'A'
55085          , p_switch_side_flag           => 'Y'
55086          , p_merge_duplicate_code       => 'A'
55087          );
55088    --
55089    l_acc_rev_natural_side_code := 'D';  -- 4262811
55090    -- 
55091    --
55092    -- set accounting line type info
55093    --
55094    xla_ae_lines_pkg.SetAcctLineType
55095       (p_component_type             => l_component_type
55096       ,p_event_type_code            => l_event_type_code
55097       ,p_line_definition_owner_code => l_line_definition_owner_code
55098       ,p_line_definition_code       => l_line_definition_code
55099       ,p_accounting_line_code       => l_component_code
55100       ,p_accounting_line_type_code  => l_component_type_code
55101       ,p_accounting_line_appl_id    => l_component_appl_id
55102       ,p_amb_context_code           => l_amb_context_code
55103       ,p_entity_code                => l_entity_code
55104       ,p_event_class_code           => l_event_class_code);
55105    --
55106    -- set accounting class
55107    --
55108    xla_ae_lines_pkg.SetAcctClass(
55109            p_accounting_class_code  => 'BANK_CHG'
55110          , p_ae_header_id           => l_ae_header_id
55111          );
55112 
55113    --
55114    -- set rounding class
55115    --
55116    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
55117                       'RECEIVABLE';
55118 
55119    --
55120    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
55124    --
55121    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
55122    --
55123    -- bulk performance
55125    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
55126 
55127    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
55128       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
55129 
55130    -- 4955764
55131    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
55132       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
55133 
55134    -- 4458381 Public Sector Enh
55135    
55136    --
55137    -- set accounting attributes for the line type
55138    --
55139    l_entered_amt_idx := 8;
55140    l_accted_amt_idx  := 13;
55141    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
55142    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
55143    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
55144    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
55145    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
55146    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
55147    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
55148    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
55149    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
55150    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
55151    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
55152    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
55153    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
55154    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
55155    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
55156    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
55157    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
55158    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
55159    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
55160    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
55161    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
55162    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
55163    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
55164    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
55165    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
55166    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
55167    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
55168    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
55169    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
55170    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
55171    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
55172    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
55173    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
55174 
55175    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
55176    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
55177 
55178    ---------------------------------------------------------------------------------------------------------------
55179    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
55180    ---------------------------------------------------------------------------------------------------------------
55181    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
55182 
55183    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
55184    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
55185 
55186    IF xla_accounting_cache_pkg.GetValueChar
55187          (p_source_code         => 'LEDGER_CATEGORY_CODE'
55188          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
55189    AND l_bflow_method_code = 'PRIOR_ENTRY'
55190 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
55191    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
55192          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
55193        )
55194    THEN
55195          xla_ae_lines_pkg.BflowUpgEntry
55196            (p_business_method_code    => l_bflow_method_code
55197            ,p_business_class_code     => l_bflow_class_code
55198            ,p_balance_type            => l_balance_type_code);
55199    ELSE
55200       NULL;
55201 -- No business flow processing for business flow method of NONE.
55202    END IF;
55203 
55204    --
55205    -- call analytical criteria
55206    --
55207    
55208    --
55209    -- call description
55210    --
55211    -- No description or it is inherited.
55212    --
55213    -- call ADRs
55214    -- Bug 4922099
55215    --
55216    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
55217         (NVL(l_actual_upg_option, 'N') = 'O') OR
55218         (NVL(l_enc_upg_option, 'N') = 'O')
55219       )
55220    THEN
55221    NULL;
55222    --
55223    --
55224    
55225   l_ccid := AcctDerRule_7(
55226            p_application_id           => p_application_id
55227          , p_ae_header_id             => l_ae_header_id 
55231          , x_value_type_code          => l_adr_value_type_code
55228 , p_source_3 => p_source_3
55229          , x_transaction_coa_id       => l_adr_transaction_coa_id
55230          , x_accounting_coa_id        => l_adr_accounting_coa_id
55232          , p_side                     => 'NA'
55233    );
55234 
55235    xla_ae_lines_pkg.set_ccid(
55236     p_code_combination_id          => l_ccid
55237   , p_value_type_code              => l_adr_value_type_code
55238   , p_transaction_coa_id           => l_adr_transaction_coa_id
55239   , p_accounting_coa_id            => l_adr_accounting_coa_id
55240   , p_adr_code                     => 'DIST_CCID'
55241   , p_adr_type_code                => 'S'
55242   , p_component_type               => l_component_type
55243   , p_component_code               => l_component_code
55244   , p_component_type_code          => l_component_type_code
55245   , p_component_appl_id            => l_component_appl_id
55246   , p_amb_context_code             => l_amb_context_code
55247   , p_side                         => 'NA'
55248   );
55249 
55250 
55251    --
55252    --
55253    END IF;
55254    --
55255    -- Bug 4922099
55256    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
55257           (NVL(l_enc_upg_option, 'N') = 'O')
55258         ) AND
55259         (l_bflow_method_code = 'PRIOR_ENTRY')
55260       )
55261    THEN
55262       IF
55263       --
55264       1 = 2
55265       --
55266       THEN
55267       xla_accounting_err_pkg.build_message
55268                                     (p_appli_s_name            => 'XLA'
55269                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
55270                                     ,p_token_1                 => 'LINE_NUMBER'
55271                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
55272                                     ,p_token_2                 => 'LINE_TYPE_NAME'
55273                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
55274                                                                              l_component_type
55275                                                                             ,l_component_code
55276                                                                             ,l_component_type_code
55277                                                                             ,l_component_appl_id
55278                                                                             ,l_amb_context_code
55279                                                                             ,l_entity_code
55280                                                                             ,l_event_class_code
55281                                                                            )
55282                                     ,p_token_3                 => 'OWNER'
55283                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
55284                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
55285                                                                           ,p_lookup_code    => l_component_type_code
55286                                                                          )
55287                                     ,p_token_4                 => 'PRODUCT_NAME'
55288                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
55289                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
55290                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
55291                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
55292                                     ,p_ae_header_id            =>  NULL
55293                                        );
55294 
55295         IF (C_LEVEL_ERROR>= g_log_level) THEN
55296                  trace
55297                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
55298                       ,p_level    => C_LEVEL_ERROR
55299                       ,p_module   => l_log_module);
55300         END IF;
55301       END IF;
55302    END IF;
55303    --
55304    --
55305    ------------------------------------------------------------------------------------------------
55306    -- 4219869 Business Flow
55307    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
55308    -- Prior Entry.  Currently, the following code is always generated.
55309    ------------------------------------------------------------------------------------------------
55310    XLA_AE_LINES_PKG.ValidateCurrentLine;
55311 
55312    ------------------------------------------------------------------------------------
55313    -- 4219869 Business Flow
55314    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
55315    ------------------------------------------------------------------------------------
55316    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
55317 
55318    ----------------------------------------------------------------------------------
55319    -- 4219869 Business Flow
55320    -- Update journal entry status -- Need to generate this within IF <condition>
55321    ----------------------------------------------------------------------------------
55322    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
55323          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
55324          ,p_balance_type_code => l_balance_type_code
55325          );
55326 
55330    BEGIN
55327    -------------------------------------------------------------------------------------------
55328    -- 4262811 - Generate the Accrual Reversal lines
55329    -------------------------------------------------------------------------------------------
55331       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
55332                               (g_array_event(p_event_id).array_value_num('header_index'));
55333       IF l_acc_rev_flag IS NULL THEN
55334          l_acc_rev_flag := 'N';
55335       END IF;
55336    EXCEPTION
55337       WHEN OTHERS THEN
55338          l_acc_rev_flag := 'N';
55339    END;
55340    --
55341    IF (l_acc_rev_flag = 'Y') THEN
55342 
55343        -- 4645092  ------------------------------------------------------------------------------
55344        -- To allow MPA report to determine if it should generate report process
55345        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
55346        ------------------------------------------------------------------------------------------
55347 
55348        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
55349        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
55350    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
55351    -- call ADRs
55352    -- Bug 4922099
55353    --
55354    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
55355         (NVL(l_actual_upg_option, 'N') = 'O') OR
55356         (NVL(l_enc_upg_option, 'N') = 'O')
55357       )
55358    THEN
55359    NULL;
55360    --
55361    --
55362    
55363   l_ccid := AcctDerRule_7(
55364            p_application_id           => p_application_id
55365          , p_ae_header_id             => l_ae_header_id 
55366 , p_source_3 => p_source_3
55367          , x_transaction_coa_id       => l_adr_transaction_coa_id
55368          , x_accounting_coa_id        => l_adr_accounting_coa_id
55369          , x_value_type_code          => l_adr_value_type_code
55370          , p_side                     => 'NA'
55371    );
55372 
55373    xla_ae_lines_pkg.set_ccid(
55374     p_code_combination_id          => l_ccid
55375   , p_value_type_code              => l_adr_value_type_code
55376   , p_transaction_coa_id           => l_adr_transaction_coa_id
55377   , p_accounting_coa_id            => l_adr_accounting_coa_id
55378   , p_adr_code                     => 'DIST_CCID'
55379   , p_adr_type_code                => 'S'
55380   , p_component_type               => l_component_type
55381   , p_component_code               => l_component_code
55382   , p_component_type_code          => l_component_type_code
55383   , p_component_appl_id            => l_component_appl_id
55384   , p_amb_context_code             => l_amb_context_code
55385   , p_side                         => 'NA'
55386   );
55387 
55388 
55389    --
55390    --
55391    END IF;
55392 
55393        --
55394        -- Update the line information that should be overwritten
55395        --
55396        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
55397                                          p_header_num   => 1);
55398        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
55399 
55400        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
55401 
55402        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
55403           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
55404        END IF;
55405 
55406       --
55407       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
55408       --
55409       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
55410           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
55411       ELSE
55412           ---------------------------------------------------------------------------------------------------
55413           -- 4262811a Switch Sign
55414           ---------------------------------------------------------------------------------------------------
55415           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
55416           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
55417                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
55418           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
55419                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
55420           -- 5132302
55421           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
55422                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
55423 
55424       END IF;
55425 
55426       -- 4955764
55427       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
55428       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
55429 
55430 
55431       XLA_AE_LINES_PKG.ValidateCurrentLine;
55432       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
55433 
55434       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
55435                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
55439 
55436                ,p_balance_type_code => l_balance_type_code);
55437 
55438    END IF;
55440    -----------------------------------------------------------------------------------------
55441    -- 4262811 Multiperiod Accounting
55442    -----------------------------------------------------------------------------------------
55443      -- No MPA option is assigned.
55444 
55445 
55446 END IF;
55447 END IF;
55448 --
55449 
55450 --
55451 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
55452    trace
55453       (p_msg      => 'END of AcctLineType_113'
55454       ,p_level    => C_LEVEL_PROCEDURE
55455       ,p_module   => l_log_module);
55456 END IF;
55457 --
55458 EXCEPTION
55459   WHEN xla_exceptions_pkg.application_exception THEN
55460       RAISE;
55461   WHEN OTHERS THEN
55462        xla_exceptions_pkg.raise_message
55463            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_113');
55464 END AcctLineType_113;
55465 --
55466 
55467 ---------------------------------------
55468 --
55469 -- PRIVATE FUNCTION
55470 --         AcctLineType_114
55471 --
55472 ---------------------------------------
55473 PROCEDURE AcctLineType_114 (
55474   p_application_id        IN NUMBER
55475  ,p_event_id              IN NUMBER
55476  ,p_calculate_acctd_flag  IN VARCHAR2
55477  ,p_calculate_g_l_flag    IN VARCHAR2
55478  ,p_actual_flag           IN OUT VARCHAR2
55479  ,p_balance_type_code     OUT VARCHAR2
55480  ,p_gain_or_loss_ref      OUT VARCHAR2
55481  
55482 --Distribution GL Account
55483  , p_source_3            IN NUMBER
55484 --Distribution Source Type
55485  , p_source_20            IN VARCHAR2
55486 --Distribution Line Identifier
55487  , p_source_22            IN NUMBER
55488 --Distribution Type
55489  , p_source_23            IN VARCHAR2
55490 --Exchange Date
55491  , p_source_26            IN DATE
55492 --Exchange Rate
55493  , p_source_27            IN NUMBER
55494 --Exchange Rate Type
55495  , p_source_28            IN VARCHAR2
55496 --Transaction Distribution Identifier
55497  , p_source_34            IN NUMBER
55498 --Transaction Distribution Type
55499  , p_source_35            IN VARCHAR2
55500 --Receipt Applied To Application Identifier
55501  , p_source_58            IN NUMBER
55502 --Transaction Entity Code
55503  , p_source_59            IN VARCHAR2
55504 --Transaction Identifier
55505  , p_source_60            IN NUMBER
55506 --Applying Document Currency Code
55507  , p_source_61            IN VARCHAR2
55508 --Distribution Party Identifier
55509  , p_source_63            IN NUMBER
55510 --Distribution Party Site Id
55511  , p_source_64            IN NUMBER
55512 --Distribution Party Type
55513  , p_source_65            IN VARCHAR2
55514 --Distribution Multi Fund Additional Entry
55515  , p_source_69            IN VARCHAR2
55516 --DIST_ENT_AMT_FROM
55517  , p_source_72            IN NUMBER
55518 --Accounting Amount
55519  , p_source_73            IN NUMBER
55520 )
55521 IS
55522 
55523 l_component_type              VARCHAR2(80);
55524 l_component_code              VARCHAR2(30);
55525 l_component_type_code         VARCHAR2(1);
55526 l_component_appl_id           INTEGER;
55527 l_amb_context_code            VARCHAR2(30);
55528 l_entity_code                 VARCHAR2(30);
55529 l_event_class_code            VARCHAR2(30);
55530 l_ae_header_id                NUMBER;
55531 l_event_type_code             VARCHAR2(30);
55532 l_line_definition_code        VARCHAR2(30);
55533 l_line_definition_owner_code  VARCHAR2(1);
55534 --
55535 -- adr variables
55536 l_segment                     VARCHAR2(30);
55537 l_ccid                        NUMBER;
55538 l_adr_transaction_coa_id      NUMBER;
55539 l_adr_accounting_coa_id       NUMBER;
55540 l_adr_flexfield_segment_code  VARCHAR2(30);
55541 l_adr_flex_value_set_id       NUMBER;
55542 l_adr_value_type_code         VARCHAR2(30);
55543 l_adr_value_combination_id    NUMBER;
55544 l_adr_value_segment_code      VARCHAR2(30);
55545 
55546 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
55547 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
55548 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
55549 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
55550 
55551 -- 4262811 Variables ------------------------------------------------------------------------------------------
55552 l_entered_amt_idx             NUMBER;
55553 l_accted_amt_idx              NUMBER;
55554 l_acc_rev_flag                VARCHAR2(1);
55555 l_accrual_line_num            NUMBER;
55556 l_tmp_amt                     NUMBER;
55557 l_acc_rev_natural_side_code   VARCHAR2(1);
55558 
55559 l_num_entries                 NUMBER;
55560 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
55561 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
55562 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
55563 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
55564 l_recog_line_1                NUMBER;
55565 l_recog_line_2                NUMBER;
55566 
55567 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
55568 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
55569 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
55570 
55574 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
55571 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
55572 
55573 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
55575 
55576 ---------------------------------------------------------------------------------------------------------------
55577 
55578 
55579 --
55580 -- bulk performance
55581 --
55582 l_balance_type_code           VARCHAR2(1);
55583 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
55584 l_log_module                  VARCHAR2(240);
55585 
55586 --
55587 -- Upgrade strategy
55588 --
55589 l_actual_upg_option           VARCHAR2(1);
55590 l_enc_upg_option           VARCHAR2(1);
55591 
55592 --
55593 BEGIN
55594 --
55595 IF g_log_enabled THEN
55596       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_114';
55597 END IF;
55598 --
55599 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
55600 
55601       trace
55602          (p_msg      => 'BEGIN of AcctLineType_114'
55603          ,p_level    => C_LEVEL_PROCEDURE
55604          ,p_module   => l_log_module);
55605 
55606 END IF;
55607 --
55608 l_component_type             := 'AMB_JLT';
55609 l_component_code             := 'RCT_CASH';
55610 l_component_type_code        := 'S';
55611 l_component_appl_id          :=  222;
55612 l_amb_context_code           := 'DEFAULT';
55613 l_entity_code                := 'RECEIPTS';
55614 l_event_class_code           := 'RECEIPT';
55615 l_event_type_code            := 'RECEIPT_ALL';
55616 l_line_definition_owner_code := 'S';
55617 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
55618 --
55619 l_balance_type_code          := 'A';
55620 l_segment                     := NULL;
55621 l_ccid                        := NULL;
55622 l_adr_transaction_coa_id      := NULL;
55623 l_adr_accounting_coa_id       := NULL;
55624 l_adr_flexfield_segment_code  := NULL;
55625 l_adr_flex_value_set_id       := NULL;
55626 l_adr_value_type_code         := NULL;
55627 l_adr_value_combination_id    := NULL;
55628 l_adr_value_segment_code      := NULL;
55629 
55630 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
55631 l_bflow_class_code           := '';    -- 4219869 Business Flow
55632 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
55633 l_budgetary_control_flag     := 'N';
55634 
55635 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
55636 l_bflow_applied_to_amt       := NULL; -- 5132302
55637 l_entered_amt_idx            := NULL;          -- 4262811
55638 l_accted_amt_idx             := NULL;          -- 4262811
55639 l_acc_rev_flag               := NULL;          -- 4262811
55640 l_accrual_line_num           := NULL;          -- 4262811
55641 l_tmp_amt                    := NULL;          -- 4262811
55642 --
55643  
55644 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
55645     l_balance_type_code <> 'B' THEN
55646 IF NVL(p_source_20,'
55647 ') =  'CASH' AND 
55648 NVL(p_source_69,'
55649 ') =  'N'
55650  THEN 
55651 
55652    --
55653    XLA_AE_LINES_PKG.SetNewLine;
55654 
55655    p_balance_type_code          := l_balance_type_code;
55656    -- set the flag so later we will know whether the gain loss line needs to be created
55657    
55658    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
55659      p_actual_flag :='A';
55660    END IF;
55661 
55662    --
55663    -- bulk performance
55664    --
55665    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
55666                                       p_header_num   => 0); -- 4262811
55667    --
55668    -- set accounting line options
55669    --
55670    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
55671            p_natural_side_code          => 'C'
55672          , p_gain_or_loss_flag          => 'N'
55673          , p_gl_transfer_mode_code      => 'S'
55674          , p_acct_entry_type_code       => 'A'
55675          , p_switch_side_flag           => 'Y'
55676          , p_merge_duplicate_code       => 'A'
55677          );
55678    --
55679    l_acc_rev_natural_side_code := 'D';  -- 4262811
55680    -- 
55681    --
55682    -- set accounting line type info
55683    --
55684    xla_ae_lines_pkg.SetAcctLineType
55685       (p_component_type             => l_component_type
55686       ,p_event_type_code            => l_event_type_code
55687       ,p_line_definition_owner_code => l_line_definition_owner_code
55688       ,p_line_definition_code       => l_line_definition_code
55689       ,p_accounting_line_code       => l_component_code
55690       ,p_accounting_line_type_code  => l_component_type_code
55691       ,p_accounting_line_appl_id    => l_component_appl_id
55692       ,p_amb_context_code           => l_amb_context_code
55693       ,p_entity_code                => l_entity_code
55694       ,p_event_class_code           => l_event_class_code);
55695    --
55696    -- set accounting class
55697    --
55698    xla_ae_lines_pkg.SetAcctClass(
55699            p_accounting_class_code  => 'CASH'
55700          , p_ae_header_id           => l_ae_header_id
55701          );
55702 
55703    --
55704    -- set rounding class
55705    --
55709    --
55706    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
55707                       'RECEIVABLE';
55708 
55710    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
55711    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
55712    --
55713    -- bulk performance
55714    --
55715    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
55716 
55717    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
55718       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
55719 
55720    -- 4955764
55721    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
55722       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
55723 
55724    -- 4458381 Public Sector Enh
55725    
55726    --
55727    -- set accounting attributes for the line type
55728    --
55729    l_entered_amt_idx := 8;
55730    l_accted_amt_idx  := 13;
55731    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
55732    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
55733    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
55734    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
55735    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
55736    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
55737    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
55738    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
55739    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
55740    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
55741    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
55742    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
55743    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
55744    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
55745    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
55746    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
55747    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
55748    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
55749    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
55750    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
55751    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
55752    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
55753    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
55754    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
55755    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
55756    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
55757    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
55758    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
55759    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
55760    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
55761    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
55762    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
55763    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
55764 
55765    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
55766    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
55767 
55768    ---------------------------------------------------------------------------------------------------------------
55769    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
55770    ---------------------------------------------------------------------------------------------------------------
55771    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
55772 
55773    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
55774    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
55775 
55776    IF xla_accounting_cache_pkg.GetValueChar
55777          (p_source_code         => 'LEDGER_CATEGORY_CODE'
55778          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
55779    AND l_bflow_method_code = 'PRIOR_ENTRY'
55780 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
55781    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
55782          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
55783        )
55784    THEN
55785          xla_ae_lines_pkg.BflowUpgEntry
55786            (p_business_method_code    => l_bflow_method_code
55787            ,p_business_class_code     => l_bflow_class_code
55788            ,p_balance_type            => l_balance_type_code);
55789    ELSE
55790       NULL;
55791 -- No business flow processing for business flow method of NONE.
55792    END IF;
55793 
55794    --
55795    -- call analytical criteria
55796    --
55797    
55798    --
55799    -- call description
55800    --
55801    -- No description or it is inherited.
55802    --
55803    -- call ADRs
55804    -- Bug 4922099
55805    --
55806    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
55807         (NVL(l_actual_upg_option, 'N') = 'O') OR
55808         (NVL(l_enc_upg_option, 'N') = 'O')
55812    --
55809       )
55810    THEN
55811    NULL;
55813    --
55814    
55815   l_ccid := AcctDerRule_7(
55816            p_application_id           => p_application_id
55817          , p_ae_header_id             => l_ae_header_id 
55818 , p_source_3 => p_source_3
55819          , x_transaction_coa_id       => l_adr_transaction_coa_id
55820          , x_accounting_coa_id        => l_adr_accounting_coa_id
55821          , x_value_type_code          => l_adr_value_type_code
55822          , p_side                     => 'NA'
55823    );
55824 
55825    xla_ae_lines_pkg.set_ccid(
55826     p_code_combination_id          => l_ccid
55827   , p_value_type_code              => l_adr_value_type_code
55828   , p_transaction_coa_id           => l_adr_transaction_coa_id
55829   , p_accounting_coa_id            => l_adr_accounting_coa_id
55830   , p_adr_code                     => 'DIST_CCID'
55831   , p_adr_type_code                => 'S'
55832   , p_component_type               => l_component_type
55833   , p_component_code               => l_component_code
55834   , p_component_type_code          => l_component_type_code
55835   , p_component_appl_id            => l_component_appl_id
55836   , p_amb_context_code             => l_amb_context_code
55837   , p_side                         => 'NA'
55838   );
55839 
55840 
55841    --
55842    --
55843    END IF;
55844    --
55845    -- Bug 4922099
55846    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
55847           (NVL(l_enc_upg_option, 'N') = 'O')
55848         ) AND
55849         (l_bflow_method_code = 'PRIOR_ENTRY')
55850       )
55851    THEN
55852       IF
55853       --
55854       1 = 2
55855       --
55856       THEN
55857       xla_accounting_err_pkg.build_message
55858                                     (p_appli_s_name            => 'XLA'
55859                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
55860                                     ,p_token_1                 => 'LINE_NUMBER'
55861                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
55862                                     ,p_token_2                 => 'LINE_TYPE_NAME'
55863                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
55864                                                                              l_component_type
55865                                                                             ,l_component_code
55866                                                                             ,l_component_type_code
55867                                                                             ,l_component_appl_id
55868                                                                             ,l_amb_context_code
55869                                                                             ,l_entity_code
55870                                                                             ,l_event_class_code
55871                                                                            )
55872                                     ,p_token_3                 => 'OWNER'
55873                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
55874                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
55875                                                                           ,p_lookup_code    => l_component_type_code
55876                                                                          )
55877                                     ,p_token_4                 => 'PRODUCT_NAME'
55878                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
55879                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
55880                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
55881                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
55882                                     ,p_ae_header_id            =>  NULL
55883                                        );
55884 
55885         IF (C_LEVEL_ERROR>= g_log_level) THEN
55886                  trace
55887                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
55888                       ,p_level    => C_LEVEL_ERROR
55889                       ,p_module   => l_log_module);
55890         END IF;
55891       END IF;
55892    END IF;
55893    --
55894    --
55895    ------------------------------------------------------------------------------------------------
55896    -- 4219869 Business Flow
55897    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
55898    -- Prior Entry.  Currently, the following code is always generated.
55899    ------------------------------------------------------------------------------------------------
55900    XLA_AE_LINES_PKG.ValidateCurrentLine;
55901 
55902    ------------------------------------------------------------------------------------
55903    -- 4219869 Business Flow
55904    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
55905    ------------------------------------------------------------------------------------
55906    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
55907 
55908    ----------------------------------------------------------------------------------
55909    -- 4219869 Business Flow
55910    -- Update journal entry status -- Need to generate this within IF <condition>
55914          ,p_balance_type_code => l_balance_type_code
55911    ----------------------------------------------------------------------------------
55912    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
55913          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
55915          );
55916 
55917    -------------------------------------------------------------------------------------------
55918    -- 4262811 - Generate the Accrual Reversal lines
55919    -------------------------------------------------------------------------------------------
55920    BEGIN
55921       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
55922                               (g_array_event(p_event_id).array_value_num('header_index'));
55923       IF l_acc_rev_flag IS NULL THEN
55924          l_acc_rev_flag := 'N';
55925       END IF;
55926    EXCEPTION
55927       WHEN OTHERS THEN
55928          l_acc_rev_flag := 'N';
55929    END;
55930    --
55931    IF (l_acc_rev_flag = 'Y') THEN
55932 
55933        -- 4645092  ------------------------------------------------------------------------------
55934        -- To allow MPA report to determine if it should generate report process
55935        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
55936        ------------------------------------------------------------------------------------------
55937 
55938        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
55939        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
55940    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
55941    -- call ADRs
55942    -- Bug 4922099
55943    --
55944    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
55945         (NVL(l_actual_upg_option, 'N') = 'O') OR
55946         (NVL(l_enc_upg_option, 'N') = 'O')
55947       )
55948    THEN
55949    NULL;
55950    --
55951    --
55952    
55953   l_ccid := AcctDerRule_7(
55954            p_application_id           => p_application_id
55955          , p_ae_header_id             => l_ae_header_id 
55956 , p_source_3 => p_source_3
55957          , x_transaction_coa_id       => l_adr_transaction_coa_id
55958          , x_accounting_coa_id        => l_adr_accounting_coa_id
55959          , x_value_type_code          => l_adr_value_type_code
55960          , p_side                     => 'NA'
55961    );
55962 
55963    xla_ae_lines_pkg.set_ccid(
55964     p_code_combination_id          => l_ccid
55965   , p_value_type_code              => l_adr_value_type_code
55966   , p_transaction_coa_id           => l_adr_transaction_coa_id
55967   , p_accounting_coa_id            => l_adr_accounting_coa_id
55968   , p_adr_code                     => 'DIST_CCID'
55969   , p_adr_type_code                => 'S'
55970   , p_component_type               => l_component_type
55971   , p_component_code               => l_component_code
55972   , p_component_type_code          => l_component_type_code
55973   , p_component_appl_id            => l_component_appl_id
55974   , p_amb_context_code             => l_amb_context_code
55975   , p_side                         => 'NA'
55976   );
55977 
55978 
55979    --
55980    --
55981    END IF;
55982 
55983        --
55984        -- Update the line information that should be overwritten
55985        --
55986        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
55987                                          p_header_num   => 1);
55988        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
55989 
55990        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
55991 
55992        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
55993           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
55994        END IF;
55995 
55996       --
55997       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
55998       --
55999       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
56000           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
56001       ELSE
56002           ---------------------------------------------------------------------------------------------------
56003           -- 4262811a Switch Sign
56004           ---------------------------------------------------------------------------------------------------
56005           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
56006           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
56007                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
56008           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
56009                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
56010           -- 5132302
56011           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
56012                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
56013 
56014       END IF;
56015 
56016       -- 4955764
56017       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
56018       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
56019 
56020 
56024       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
56021       XLA_AE_LINES_PKG.ValidateCurrentLine;
56022       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
56023 
56025                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
56026                ,p_balance_type_code => l_balance_type_code);
56027 
56028    END IF;
56029 
56030    -----------------------------------------------------------------------------------------
56031    -- 4262811 Multiperiod Accounting
56032    -----------------------------------------------------------------------------------------
56033      -- No MPA option is assigned.
56034 
56035 
56036 END IF;
56037 END IF;
56038 --
56039 
56040 --
56041 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
56042    trace
56043       (p_msg      => 'END of AcctLineType_114'
56044       ,p_level    => C_LEVEL_PROCEDURE
56045       ,p_module   => l_log_module);
56046 END IF;
56047 --
56048 EXCEPTION
56049   WHEN xla_exceptions_pkg.application_exception THEN
56050       RAISE;
56051   WHEN OTHERS THEN
56052        xla_exceptions_pkg.raise_message
56053            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_114');
56054 END AcctLineType_114;
56055 --
56056 
56057 ---------------------------------------
56058 --
56059 -- PRIVATE FUNCTION
56060 --         AcctLineType_115
56061 --
56062 ---------------------------------------
56063 PROCEDURE AcctLineType_115 (
56064   p_application_id        IN NUMBER
56065  ,p_event_id              IN NUMBER
56066  ,p_calculate_acctd_flag  IN VARCHAR2
56067  ,p_calculate_g_l_flag    IN VARCHAR2
56068  ,p_actual_flag           IN OUT VARCHAR2
56069  ,p_balance_type_code     OUT VARCHAR2
56070  ,p_gain_or_loss_ref      OUT VARCHAR2
56071  
56072 --Distribution GL Account
56073  , p_source_3            IN NUMBER
56074 --Distribution Source Type
56075  , p_source_20            IN VARCHAR2
56076 --Receivable Activity Type
56077  , p_source_21            IN VARCHAR2
56078 --Distribution Line Identifier
56079  , p_source_22            IN NUMBER
56080 --Distribution Type
56081  , p_source_23            IN VARCHAR2
56082 --Exchange Date
56083  , p_source_26            IN DATE
56084 --Exchange Rate
56085  , p_source_27            IN NUMBER
56086 --Transaction Distribution Identifier
56087  , p_source_34            IN NUMBER
56088 --Transaction Distribution Type
56089  , p_source_35            IN VARCHAR2
56090 --Receipt Applied To Application Identifier
56091  , p_source_58            IN NUMBER
56092 --Transaction Entity Code
56093  , p_source_59            IN VARCHAR2
56094 --Transaction Identifier
56095  , p_source_60            IN NUMBER
56096 --Applying Document Currency Code
56097  , p_source_61            IN VARCHAR2
56098 --Distribution Party Identifier
56099  , p_source_63            IN NUMBER
56100 --Distribution Party Site Id
56101  , p_source_64            IN NUMBER
56102 --Distribution Party Type
56103  , p_source_65            IN VARCHAR2
56104 --Distribution Multi Fund Additional Entry
56105  , p_source_69            IN VARCHAR2
56106 --DIST_ENT_AMT_FROM
56107  , p_source_72            IN NUMBER
56108 --Accounting Amount
56109  , p_source_73            IN NUMBER
56110 --Applied To Document Exchange Rate Type
56111  , p_source_74            IN VARCHAR2
56112 )
56113 IS
56114 
56115 l_component_type              VARCHAR2(80);
56116 l_component_code              VARCHAR2(30);
56117 l_component_type_code         VARCHAR2(1);
56118 l_component_appl_id           INTEGER;
56119 l_amb_context_code            VARCHAR2(30);
56120 l_entity_code                 VARCHAR2(30);
56121 l_event_class_code            VARCHAR2(30);
56122 l_ae_header_id                NUMBER;
56123 l_event_type_code             VARCHAR2(30);
56124 l_line_definition_code        VARCHAR2(30);
56125 l_line_definition_owner_code  VARCHAR2(1);
56126 --
56127 -- adr variables
56128 l_segment                     VARCHAR2(30);
56129 l_ccid                        NUMBER;
56130 l_adr_transaction_coa_id      NUMBER;
56131 l_adr_accounting_coa_id       NUMBER;
56132 l_adr_flexfield_segment_code  VARCHAR2(30);
56133 l_adr_flex_value_set_id       NUMBER;
56134 l_adr_value_type_code         VARCHAR2(30);
56135 l_adr_value_combination_id    NUMBER;
56136 l_adr_value_segment_code      VARCHAR2(30);
56137 
56138 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
56139 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
56140 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
56141 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
56142 
56143 -- 4262811 Variables ------------------------------------------------------------------------------------------
56144 l_entered_amt_idx             NUMBER;
56145 l_accted_amt_idx              NUMBER;
56146 l_acc_rev_flag                VARCHAR2(1);
56147 l_accrual_line_num            NUMBER;
56148 l_tmp_amt                     NUMBER;
56149 l_acc_rev_natural_side_code   VARCHAR2(1);
56150 
56151 l_num_entries                 NUMBER;
56152 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
56153 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
56154 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
56155 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
56156 l_recog_line_1                NUMBER;
56160 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
56157 l_recog_line_2                NUMBER;
56158 
56159 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
56161 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
56162 
56163 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
56164 
56165 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
56166 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
56167 
56168 ---------------------------------------------------------------------------------------------------------------
56169 
56170 
56171 --
56172 -- bulk performance
56173 --
56174 l_balance_type_code           VARCHAR2(1);
56175 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
56176 l_log_module                  VARCHAR2(240);
56177 
56178 --
56179 -- Upgrade strategy
56180 --
56181 l_actual_upg_option           VARCHAR2(1);
56182 l_enc_upg_option           VARCHAR2(1);
56183 
56184 --
56185 BEGIN
56186 --
56187 IF g_log_enabled THEN
56188       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_115';
56189 END IF;
56190 --
56191 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
56192 
56193       trace
56194          (p_msg      => 'BEGIN of AcctLineType_115'
56195          ,p_level    => C_LEVEL_PROCEDURE
56196          ,p_module   => l_log_module);
56197 
56198 END IF;
56199 --
56200 l_component_type             := 'AMB_JLT';
56201 l_component_code             := 'RCT_CLAIM';
56202 l_component_type_code        := 'S';
56203 l_component_appl_id          :=  222;
56204 l_amb_context_code           := 'DEFAULT';
56205 l_entity_code                := 'RECEIPTS';
56206 l_event_class_code           := 'RECEIPT';
56207 l_event_type_code            := 'RECEIPT_ALL';
56208 l_line_definition_owner_code := 'S';
56209 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
56210 --
56211 l_balance_type_code          := 'A';
56212 l_segment                     := NULL;
56213 l_ccid                        := NULL;
56214 l_adr_transaction_coa_id      := NULL;
56215 l_adr_accounting_coa_id       := NULL;
56216 l_adr_flexfield_segment_code  := NULL;
56217 l_adr_flex_value_set_id       := NULL;
56218 l_adr_value_type_code         := NULL;
56219 l_adr_value_combination_id    := NULL;
56220 l_adr_value_segment_code      := NULL;
56221 
56222 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
56223 l_bflow_class_code           := '';    -- 4219869 Business Flow
56224 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
56225 l_budgetary_control_flag     := 'N';
56226 
56227 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
56228 l_bflow_applied_to_amt       := NULL; -- 5132302
56229 l_entered_amt_idx            := NULL;          -- 4262811
56230 l_accted_amt_idx             := NULL;          -- 4262811
56231 l_acc_rev_flag               := NULL;          -- 4262811
56232 l_accrual_line_num           := NULL;          -- 4262811
56233 l_tmp_amt                    := NULL;          -- 4262811
56234 --
56235  
56236 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
56237     l_balance_type_code <> 'B' THEN
56238 IF NVL(p_source_20,'
56239 ') =  'OTHER ACC' AND 
56240 NVL(p_source_21,'
56241 ') =  'CLAIM_INVESTIGATION' AND 
56242 NVL(p_source_69,'
56243 ') =  'N'
56244  THEN 
56245 
56246    --
56247    XLA_AE_LINES_PKG.SetNewLine;
56248 
56249    p_balance_type_code          := l_balance_type_code;
56250    -- set the flag so later we will know whether the gain loss line needs to be created
56251    
56252    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
56253      p_actual_flag :='A';
56254    END IF;
56255 
56256    --
56257    -- bulk performance
56258    --
56259    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
56260                                       p_header_num   => 0); -- 4262811
56261    --
56262    -- set accounting line options
56263    --
56264    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
56265            p_natural_side_code          => 'C'
56266          , p_gain_or_loss_flag          => 'N'
56267          , p_gl_transfer_mode_code      => 'S'
56268          , p_acct_entry_type_code       => 'A'
56269          , p_switch_side_flag           => 'Y'
56270          , p_merge_duplicate_code       => 'A'
56271          );
56272    --
56273    l_acc_rev_natural_side_code := 'D';  -- 4262811
56274    -- 
56275    --
56276    -- set accounting line type info
56277    --
56278    xla_ae_lines_pkg.SetAcctLineType
56279       (p_component_type             => l_component_type
56280       ,p_event_type_code            => l_event_type_code
56281       ,p_line_definition_owner_code => l_line_definition_owner_code
56282       ,p_line_definition_code       => l_line_definition_code
56283       ,p_accounting_line_code       => l_component_code
56284       ,p_accounting_line_type_code  => l_component_type_code
56285       ,p_accounting_line_appl_id    => l_component_appl_id
56286       ,p_amb_context_code           => l_amb_context_code
56287       ,p_entity_code                => l_entity_code
56288       ,p_event_class_code           => l_event_class_code);
56289    --
56290    -- set accounting class
56294          , p_ae_header_id           => l_ae_header_id
56291    --
56292    xla_ae_lines_pkg.SetAcctClass(
56293            p_accounting_class_code  => 'CLAIM'
56295          );
56296 
56297    --
56298    -- set rounding class
56299    --
56300    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
56301                       'RECEIVABLE';
56302 
56303    --
56304    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
56305    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
56306    --
56307    -- bulk performance
56308    --
56309    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
56310 
56311    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
56312       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
56313 
56314    -- 4955764
56315    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
56316       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
56317 
56318    -- 4458381 Public Sector Enh
56319    
56320    --
56321    -- set accounting attributes for the line type
56322    --
56323    l_entered_amt_idx := 8;
56324    l_accted_amt_idx  := 13;
56325    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
56326    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
56327    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
56328    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
56329    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
56330    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
56331    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
56332    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
56333    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
56334    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
56335    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
56336    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
56337    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
56338    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
56339    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
56340    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
56341    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
56342    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
56343    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
56344    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
56345    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
56346    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
56347    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
56348    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
56349    l_rec_acct_attrs.array_char_value(12)  := p_source_74;
56350    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
56351    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
56352    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
56353    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
56354    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
56355    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
56356    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
56357    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
56358 
56359    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
56360    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
56361 
56362    ---------------------------------------------------------------------------------------------------------------
56363    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
56364    ---------------------------------------------------------------------------------------------------------------
56365    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
56366 
56367    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
56368    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
56369 
56370    IF xla_accounting_cache_pkg.GetValueChar
56371          (p_source_code         => 'LEDGER_CATEGORY_CODE'
56372          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
56373    AND l_bflow_method_code = 'PRIOR_ENTRY'
56374 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
56375    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
56376          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
56377        )
56378    THEN
56379          xla_ae_lines_pkg.BflowUpgEntry
56380            (p_business_method_code    => l_bflow_method_code
56381            ,p_business_class_code     => l_bflow_class_code
56382            ,p_balance_type            => l_balance_type_code);
56383    ELSE
56384       NULL;
56385 -- No business flow processing for business flow method of NONE.
56386    END IF;
56387 
56388    --
56389    -- call analytical criteria
56390    --
56391    
56392    --
56393    -- call description
56394    --
56398    -- Bug 4922099
56395    -- No description or it is inherited.
56396    --
56397    -- call ADRs
56399    --
56400    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
56401         (NVL(l_actual_upg_option, 'N') = 'O') OR
56402         (NVL(l_enc_upg_option, 'N') = 'O')
56403       )
56404    THEN
56405    NULL;
56406    --
56407    --
56408    
56409   l_ccid := AcctDerRule_7(
56410            p_application_id           => p_application_id
56411          , p_ae_header_id             => l_ae_header_id 
56412 , p_source_3 => p_source_3
56413          , x_transaction_coa_id       => l_adr_transaction_coa_id
56414          , x_accounting_coa_id        => l_adr_accounting_coa_id
56415          , x_value_type_code          => l_adr_value_type_code
56416          , p_side                     => 'NA'
56417    );
56418 
56419    xla_ae_lines_pkg.set_ccid(
56420     p_code_combination_id          => l_ccid
56421   , p_value_type_code              => l_adr_value_type_code
56422   , p_transaction_coa_id           => l_adr_transaction_coa_id
56423   , p_accounting_coa_id            => l_adr_accounting_coa_id
56424   , p_adr_code                     => 'DIST_CCID'
56425   , p_adr_type_code                => 'S'
56426   , p_component_type               => l_component_type
56427   , p_component_code               => l_component_code
56428   , p_component_type_code          => l_component_type_code
56429   , p_component_appl_id            => l_component_appl_id
56430   , p_amb_context_code             => l_amb_context_code
56431   , p_side                         => 'NA'
56432   );
56433 
56434 
56435    --
56436    --
56437    END IF;
56438    --
56439    -- Bug 4922099
56440    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
56441           (NVL(l_enc_upg_option, 'N') = 'O')
56442         ) AND
56443         (l_bflow_method_code = 'PRIOR_ENTRY')
56444       )
56445    THEN
56446       IF
56447       --
56448       1 = 2
56449       --
56450       THEN
56451       xla_accounting_err_pkg.build_message
56452                                     (p_appli_s_name            => 'XLA'
56453                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
56454                                     ,p_token_1                 => 'LINE_NUMBER'
56455                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
56456                                     ,p_token_2                 => 'LINE_TYPE_NAME'
56457                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
56458                                                                              l_component_type
56459                                                                             ,l_component_code
56460                                                                             ,l_component_type_code
56461                                                                             ,l_component_appl_id
56462                                                                             ,l_amb_context_code
56463                                                                             ,l_entity_code
56464                                                                             ,l_event_class_code
56465                                                                            )
56466                                     ,p_token_3                 => 'OWNER'
56467                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
56468                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
56469                                                                           ,p_lookup_code    => l_component_type_code
56470                                                                          )
56471                                     ,p_token_4                 => 'PRODUCT_NAME'
56472                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
56473                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
56474                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
56475                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
56476                                     ,p_ae_header_id            =>  NULL
56477                                        );
56478 
56479         IF (C_LEVEL_ERROR>= g_log_level) THEN
56480                  trace
56481                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
56482                       ,p_level    => C_LEVEL_ERROR
56483                       ,p_module   => l_log_module);
56484         END IF;
56485       END IF;
56486    END IF;
56487    --
56488    --
56489    ------------------------------------------------------------------------------------------------
56490    -- 4219869 Business Flow
56491    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
56492    -- Prior Entry.  Currently, the following code is always generated.
56493    ------------------------------------------------------------------------------------------------
56494    XLA_AE_LINES_PKG.ValidateCurrentLine;
56495 
56496    ------------------------------------------------------------------------------------
56497    -- 4219869 Business Flow
56498    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
56502    ----------------------------------------------------------------------------------
56499    ------------------------------------------------------------------------------------
56500    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
56501 
56503    -- 4219869 Business Flow
56504    -- Update journal entry status -- Need to generate this within IF <condition>
56505    ----------------------------------------------------------------------------------
56506    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
56507          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
56508          ,p_balance_type_code => l_balance_type_code
56509          );
56510 
56511    -------------------------------------------------------------------------------------------
56512    -- 4262811 - Generate the Accrual Reversal lines
56513    -------------------------------------------------------------------------------------------
56514    BEGIN
56515       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
56516                               (g_array_event(p_event_id).array_value_num('header_index'));
56517       IF l_acc_rev_flag IS NULL THEN
56518          l_acc_rev_flag := 'N';
56519       END IF;
56520    EXCEPTION
56521       WHEN OTHERS THEN
56522          l_acc_rev_flag := 'N';
56523    END;
56524    --
56525    IF (l_acc_rev_flag = 'Y') THEN
56526 
56527        -- 4645092  ------------------------------------------------------------------------------
56528        -- To allow MPA report to determine if it should generate report process
56529        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
56530        ------------------------------------------------------------------------------------------
56531 
56532        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
56533        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
56534    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
56535    -- call ADRs
56536    -- Bug 4922099
56537    --
56538    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
56539         (NVL(l_actual_upg_option, 'N') = 'O') OR
56540         (NVL(l_enc_upg_option, 'N') = 'O')
56541       )
56542    THEN
56543    NULL;
56544    --
56545    --
56546    
56547   l_ccid := AcctDerRule_7(
56548            p_application_id           => p_application_id
56549          , p_ae_header_id             => l_ae_header_id 
56550 , p_source_3 => p_source_3
56551          , x_transaction_coa_id       => l_adr_transaction_coa_id
56552          , x_accounting_coa_id        => l_adr_accounting_coa_id
56553          , x_value_type_code          => l_adr_value_type_code
56554          , p_side                     => 'NA'
56555    );
56556 
56557    xla_ae_lines_pkg.set_ccid(
56558     p_code_combination_id          => l_ccid
56559   , p_value_type_code              => l_adr_value_type_code
56560   , p_transaction_coa_id           => l_adr_transaction_coa_id
56561   , p_accounting_coa_id            => l_adr_accounting_coa_id
56562   , p_adr_code                     => 'DIST_CCID'
56563   , p_adr_type_code                => 'S'
56564   , p_component_type               => l_component_type
56565   , p_component_code               => l_component_code
56566   , p_component_type_code          => l_component_type_code
56567   , p_component_appl_id            => l_component_appl_id
56568   , p_amb_context_code             => l_amb_context_code
56569   , p_side                         => 'NA'
56570   );
56571 
56572 
56573    --
56574    --
56575    END IF;
56576 
56577        --
56578        -- Update the line information that should be overwritten
56579        --
56580        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
56581                                          p_header_num   => 1);
56582        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
56583 
56584        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
56585 
56586        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
56587           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
56588        END IF;
56589 
56590       --
56591       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
56592       --
56593       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
56594           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
56595       ELSE
56596           ---------------------------------------------------------------------------------------------------
56597           -- 4262811a Switch Sign
56598           ---------------------------------------------------------------------------------------------------
56599           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
56600           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
56601                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
56602           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
56603                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
56604           -- 5132302
56605           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
56606                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
56607 
56608       END IF;
56612       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
56609 
56610       -- 4955764
56611       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
56613 
56614 
56615       XLA_AE_LINES_PKG.ValidateCurrentLine;
56616       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
56617 
56618       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
56619                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
56620                ,p_balance_type_code => l_balance_type_code);
56621 
56622    END IF;
56623 
56624    -----------------------------------------------------------------------------------------
56625    -- 4262811 Multiperiod Accounting
56626    -----------------------------------------------------------------------------------------
56627      -- No MPA option is assigned.
56628 
56629 
56630 END IF;
56631 END IF;
56632 --
56633 
56634 --
56635 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
56636    trace
56637       (p_msg      => 'END of AcctLineType_115'
56638       ,p_level    => C_LEVEL_PROCEDURE
56639       ,p_module   => l_log_module);
56640 END IF;
56641 --
56642 EXCEPTION
56643   WHEN xla_exceptions_pkg.application_exception THEN
56644       RAISE;
56645   WHEN OTHERS THEN
56646        xla_exceptions_pkg.raise_message
56647            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_115');
56648 END AcctLineType_115;
56649 --
56650 
56651 ---------------------------------------
56652 --
56653 -- PRIVATE FUNCTION
56654 --         AcctLineType_116
56655 --
56656 ---------------------------------------
56657 PROCEDURE AcctLineType_116 (
56658   p_application_id        IN NUMBER
56659  ,p_event_id              IN NUMBER
56660  ,p_calculate_acctd_flag  IN VARCHAR2
56661  ,p_calculate_g_l_flag    IN VARCHAR2
56662  ,p_actual_flag           IN OUT VARCHAR2
56663  ,p_balance_type_code     OUT VARCHAR2
56664  ,p_gain_or_loss_ref      OUT VARCHAR2
56665  
56666 --Distribution GL Account
56667  , p_source_3            IN NUMBER
56668 --Distribution Source Type
56669  , p_source_20            IN VARCHAR2
56670 --Distribution Line Identifier
56671  , p_source_22            IN NUMBER
56672 --Distribution Type
56673  , p_source_23            IN VARCHAR2
56674 --Exchange Date
56675  , p_source_26            IN DATE
56676 --Exchange Rate
56677  , p_source_27            IN NUMBER
56678 --Exchange Rate Type
56679  , p_source_28            IN VARCHAR2
56680 --Transaction Distribution Identifier
56681  , p_source_34            IN NUMBER
56682 --Transaction Distribution Type
56683  , p_source_35            IN VARCHAR2
56684 --Receipt Applied To Application Identifier
56685  , p_source_58            IN NUMBER
56686 --Transaction Entity Code
56687  , p_source_59            IN VARCHAR2
56688 --Transaction Identifier
56689  , p_source_60            IN NUMBER
56690 --Applying Document Currency Code
56691  , p_source_61            IN VARCHAR2
56692 --Distribution Party Identifier
56693  , p_source_63            IN NUMBER
56694 --Distribution Party Site Id
56695  , p_source_64            IN NUMBER
56696 --Distribution Party Type
56697  , p_source_65            IN VARCHAR2
56698 --Distribution Multi Fund Additional Entry
56699  , p_source_69            IN VARCHAR2
56700 --DIST_ENT_AMT_FROM
56701  , p_source_72            IN NUMBER
56702 --Accounting Amount
56703  , p_source_73            IN NUMBER
56704 )
56705 IS
56706 
56707 l_component_type              VARCHAR2(80);
56708 l_component_code              VARCHAR2(30);
56709 l_component_type_code         VARCHAR2(1);
56710 l_component_appl_id           INTEGER;
56711 l_amb_context_code            VARCHAR2(30);
56712 l_entity_code                 VARCHAR2(30);
56713 l_event_class_code            VARCHAR2(30);
56714 l_ae_header_id                NUMBER;
56715 l_event_type_code             VARCHAR2(30);
56716 l_line_definition_code        VARCHAR2(30);
56717 l_line_definition_owner_code  VARCHAR2(1);
56718 --
56719 -- adr variables
56720 l_segment                     VARCHAR2(30);
56721 l_ccid                        NUMBER;
56722 l_adr_transaction_coa_id      NUMBER;
56723 l_adr_accounting_coa_id       NUMBER;
56724 l_adr_flexfield_segment_code  VARCHAR2(30);
56725 l_adr_flex_value_set_id       NUMBER;
56726 l_adr_value_type_code         VARCHAR2(30);
56727 l_adr_value_combination_id    NUMBER;
56728 l_adr_value_segment_code      VARCHAR2(30);
56729 
56730 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
56731 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
56732 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
56733 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
56734 
56735 -- 4262811 Variables ------------------------------------------------------------------------------------------
56736 l_entered_amt_idx             NUMBER;
56737 l_accted_amt_idx              NUMBER;
56738 l_acc_rev_flag                VARCHAR2(1);
56739 l_accrual_line_num            NUMBER;
56740 l_tmp_amt                     NUMBER;
56741 l_acc_rev_natural_side_code   VARCHAR2(1);
56742 
56743 l_num_entries                 NUMBER;
56744 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
56745 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
56749 l_recog_line_2                NUMBER;
56746 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
56747 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
56748 l_recog_line_1                NUMBER;
56750 
56751 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
56752 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
56753 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
56754 
56755 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
56756 
56757 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
56758 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
56759 
56760 ---------------------------------------------------------------------------------------------------------------
56761 
56762 
56763 --
56764 -- bulk performance
56765 --
56766 l_balance_type_code           VARCHAR2(1);
56767 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
56768 l_log_module                  VARCHAR2(240);
56769 
56770 --
56771 -- Upgrade strategy
56772 --
56773 l_actual_upg_option           VARCHAR2(1);
56774 l_enc_upg_option           VARCHAR2(1);
56775 
56776 --
56777 BEGIN
56778 --
56779 IF g_log_enabled THEN
56780       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_116';
56781 END IF;
56782 --
56783 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
56784 
56785       trace
56786          (p_msg      => 'BEGIN of AcctLineType_116'
56787          ,p_level    => C_LEVEL_PROCEDURE
56788          ,p_module   => l_log_module);
56789 
56790 END IF;
56791 --
56792 l_component_type             := 'AMB_JLT';
56793 l_component_code             := 'RCT_CONFIRM';
56794 l_component_type_code        := 'S';
56795 l_component_appl_id          :=  222;
56796 l_amb_context_code           := 'DEFAULT';
56797 l_entity_code                := 'RECEIPTS';
56798 l_event_class_code           := 'RECEIPT';
56799 l_event_type_code            := 'RECEIPT_ALL';
56800 l_line_definition_owner_code := 'S';
56801 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
56802 --
56803 l_balance_type_code          := 'A';
56804 l_segment                     := NULL;
56805 l_ccid                        := NULL;
56806 l_adr_transaction_coa_id      := NULL;
56807 l_adr_accounting_coa_id       := NULL;
56808 l_adr_flexfield_segment_code  := NULL;
56809 l_adr_flex_value_set_id       := NULL;
56810 l_adr_value_type_code         := NULL;
56811 l_adr_value_combination_id    := NULL;
56812 l_adr_value_segment_code      := NULL;
56813 
56814 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
56815 l_bflow_class_code           := '';    -- 4219869 Business Flow
56816 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
56817 l_budgetary_control_flag     := 'N';
56818 
56819 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
56820 l_bflow_applied_to_amt       := NULL; -- 5132302
56821 l_entered_amt_idx            := NULL;          -- 4262811
56822 l_accted_amt_idx             := NULL;          -- 4262811
56823 l_acc_rev_flag               := NULL;          -- 4262811
56824 l_accrual_line_num           := NULL;          -- 4262811
56825 l_tmp_amt                    := NULL;          -- 4262811
56826 --
56827  
56828 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
56829     l_balance_type_code <> 'B' THEN
56830 IF NVL(p_source_20,'
56831 ') =  'CONFIRMATION' AND 
56832 NVL(p_source_69,'
56833 ') =  'N'
56834  THEN 
56835 
56836    --
56837    XLA_AE_LINES_PKG.SetNewLine;
56838 
56839    p_balance_type_code          := l_balance_type_code;
56840    -- set the flag so later we will know whether the gain loss line needs to be created
56841    
56842    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
56843      p_actual_flag :='A';
56844    END IF;
56845 
56846    --
56847    -- bulk performance
56848    --
56849    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
56850                                       p_header_num   => 0); -- 4262811
56851    --
56852    -- set accounting line options
56853    --
56854    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
56855            p_natural_side_code          => 'C'
56856          , p_gain_or_loss_flag          => 'N'
56857          , p_gl_transfer_mode_code      => 'S'
56858          , p_acct_entry_type_code       => 'A'
56859          , p_switch_side_flag           => 'Y'
56860          , p_merge_duplicate_code       => 'A'
56861          );
56862    --
56863    l_acc_rev_natural_side_code := 'D';  -- 4262811
56864    -- 
56865    --
56866    -- set accounting line type info
56867    --
56868    xla_ae_lines_pkg.SetAcctLineType
56869       (p_component_type             => l_component_type
56870       ,p_event_type_code            => l_event_type_code
56871       ,p_line_definition_owner_code => l_line_definition_owner_code
56872       ,p_line_definition_code       => l_line_definition_code
56873       ,p_accounting_line_code       => l_component_code
56874       ,p_accounting_line_type_code  => l_component_type_code
56875       ,p_accounting_line_appl_id    => l_component_appl_id
56876       ,p_amb_context_code           => l_amb_context_code
56877       ,p_entity_code                => l_entity_code
56881    --
56878       ,p_event_class_code           => l_event_class_code);
56879    --
56880    -- set accounting class
56882    xla_ae_lines_pkg.SetAcctClass(
56883            p_accounting_class_code  => 'CONFIRMATION'
56884          , p_ae_header_id           => l_ae_header_id
56885          );
56886 
56887    --
56888    -- set rounding class
56889    --
56890    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
56891                       'RECEIVABLE';
56892 
56893    --
56894    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
56895    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
56896    --
56897    -- bulk performance
56898    --
56899    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
56900 
56901    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
56902       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
56903 
56904    -- 4955764
56905    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
56906       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
56907 
56908    -- 4458381 Public Sector Enh
56909    
56910    --
56911    -- set accounting attributes for the line type
56912    --
56913    l_entered_amt_idx := 8;
56914    l_accted_amt_idx  := 13;
56915    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
56916    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
56917    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
56918    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
56919    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
56920    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
56921    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
56922    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
56923    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
56924    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
56925    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
56926    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
56927    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
56928    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
56929    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
56930    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
56931    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
56932    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
56933    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
56934    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
56935    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
56936    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
56937    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
56938    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
56939    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
56940    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
56941    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
56942    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
56943    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
56944    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
56945    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
56946    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
56947    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
56948 
56949    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
56950    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
56951 
56952    ---------------------------------------------------------------------------------------------------------------
56953    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
56954    ---------------------------------------------------------------------------------------------------------------
56955    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
56956 
56957    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
56958    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
56959 
56960    IF xla_accounting_cache_pkg.GetValueChar
56961          (p_source_code         => 'LEDGER_CATEGORY_CODE'
56962          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
56963    AND l_bflow_method_code = 'PRIOR_ENTRY'
56964 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
56965    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
56966          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
56967        )
56968    THEN
56969          xla_ae_lines_pkg.BflowUpgEntry
56970            (p_business_method_code    => l_bflow_method_code
56971            ,p_business_class_code     => l_bflow_class_code
56972            ,p_balance_type            => l_balance_type_code);
56973    ELSE
56974       NULL;
56975 -- No business flow processing for business flow method of NONE.
56976    END IF;
56977 
56978    --
56979    -- call analytical criteria
56983    -- call description
56980    --
56981    
56982    --
56984    --
56985    -- No description or it is inherited.
56986    --
56987    -- call ADRs
56988    -- Bug 4922099
56989    --
56990    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
56991         (NVL(l_actual_upg_option, 'N') = 'O') OR
56992         (NVL(l_enc_upg_option, 'N') = 'O')
56993       )
56994    THEN
56995    NULL;
56996    --
56997    --
56998    
56999   l_ccid := AcctDerRule_7(
57000            p_application_id           => p_application_id
57001          , p_ae_header_id             => l_ae_header_id 
57002 , p_source_3 => p_source_3
57003          , x_transaction_coa_id       => l_adr_transaction_coa_id
57004          , x_accounting_coa_id        => l_adr_accounting_coa_id
57005          , x_value_type_code          => l_adr_value_type_code
57006          , p_side                     => 'NA'
57007    );
57008 
57009    xla_ae_lines_pkg.set_ccid(
57010     p_code_combination_id          => l_ccid
57011   , p_value_type_code              => l_adr_value_type_code
57012   , p_transaction_coa_id           => l_adr_transaction_coa_id
57013   , p_accounting_coa_id            => l_adr_accounting_coa_id
57014   , p_adr_code                     => 'DIST_CCID'
57015   , p_adr_type_code                => 'S'
57016   , p_component_type               => l_component_type
57017   , p_component_code               => l_component_code
57018   , p_component_type_code          => l_component_type_code
57019   , p_component_appl_id            => l_component_appl_id
57020   , p_amb_context_code             => l_amb_context_code
57021   , p_side                         => 'NA'
57022   );
57023 
57024 
57025    --
57026    --
57027    END IF;
57028    --
57029    -- Bug 4922099
57030    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
57031           (NVL(l_enc_upg_option, 'N') = 'O')
57032         ) AND
57033         (l_bflow_method_code = 'PRIOR_ENTRY')
57034       )
57035    THEN
57036       IF
57037       --
57038       1 = 2
57039       --
57040       THEN
57041       xla_accounting_err_pkg.build_message
57042                                     (p_appli_s_name            => 'XLA'
57043                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
57044                                     ,p_token_1                 => 'LINE_NUMBER'
57045                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
57046                                     ,p_token_2                 => 'LINE_TYPE_NAME'
57047                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
57048                                                                              l_component_type
57049                                                                             ,l_component_code
57050                                                                             ,l_component_type_code
57051                                                                             ,l_component_appl_id
57052                                                                             ,l_amb_context_code
57053                                                                             ,l_entity_code
57054                                                                             ,l_event_class_code
57055                                                                            )
57056                                     ,p_token_3                 => 'OWNER'
57057                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
57058                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
57059                                                                           ,p_lookup_code    => l_component_type_code
57060                                                                          )
57061                                     ,p_token_4                 => 'PRODUCT_NAME'
57062                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
57063                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
57064                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
57065                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
57066                                     ,p_ae_header_id            =>  NULL
57067                                        );
57068 
57069         IF (C_LEVEL_ERROR>= g_log_level) THEN
57070                  trace
57071                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
57072                       ,p_level    => C_LEVEL_ERROR
57073                       ,p_module   => l_log_module);
57074         END IF;
57075       END IF;
57076    END IF;
57077    --
57078    --
57079    ------------------------------------------------------------------------------------------------
57080    -- 4219869 Business Flow
57081    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
57082    -- Prior Entry.  Currently, the following code is always generated.
57083    ------------------------------------------------------------------------------------------------
57084    XLA_AE_LINES_PKG.ValidateCurrentLine;
57085 
57086    ------------------------------------------------------------------------------------
57087    -- 4219869 Business Flow
57091 
57088    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
57089    ------------------------------------------------------------------------------------
57090    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
57092    ----------------------------------------------------------------------------------
57093    -- 4219869 Business Flow
57094    -- Update journal entry status -- Need to generate this within IF <condition>
57095    ----------------------------------------------------------------------------------
57096    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
57097          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
57098          ,p_balance_type_code => l_balance_type_code
57099          );
57100 
57101    -------------------------------------------------------------------------------------------
57102    -- 4262811 - Generate the Accrual Reversal lines
57103    -------------------------------------------------------------------------------------------
57104    BEGIN
57105       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
57106                               (g_array_event(p_event_id).array_value_num('header_index'));
57107       IF l_acc_rev_flag IS NULL THEN
57108          l_acc_rev_flag := 'N';
57109       END IF;
57110    EXCEPTION
57111       WHEN OTHERS THEN
57112          l_acc_rev_flag := 'N';
57113    END;
57114    --
57115    IF (l_acc_rev_flag = 'Y') THEN
57116 
57117        -- 4645092  ------------------------------------------------------------------------------
57118        -- To allow MPA report to determine if it should generate report process
57119        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
57120        ------------------------------------------------------------------------------------------
57121 
57122        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
57123        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
57124    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
57125    -- call ADRs
57126    -- Bug 4922099
57127    --
57128    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
57129         (NVL(l_actual_upg_option, 'N') = 'O') OR
57130         (NVL(l_enc_upg_option, 'N') = 'O')
57131       )
57132    THEN
57133    NULL;
57134    --
57135    --
57136    
57137   l_ccid := AcctDerRule_7(
57138            p_application_id           => p_application_id
57139          , p_ae_header_id             => l_ae_header_id 
57140 , p_source_3 => p_source_3
57141          , x_transaction_coa_id       => l_adr_transaction_coa_id
57142          , x_accounting_coa_id        => l_adr_accounting_coa_id
57143          , x_value_type_code          => l_adr_value_type_code
57144          , p_side                     => 'NA'
57145    );
57146 
57147    xla_ae_lines_pkg.set_ccid(
57148     p_code_combination_id          => l_ccid
57149   , p_value_type_code              => l_adr_value_type_code
57150   , p_transaction_coa_id           => l_adr_transaction_coa_id
57151   , p_accounting_coa_id            => l_adr_accounting_coa_id
57152   , p_adr_code                     => 'DIST_CCID'
57153   , p_adr_type_code                => 'S'
57154   , p_component_type               => l_component_type
57155   , p_component_code               => l_component_code
57156   , p_component_type_code          => l_component_type_code
57157   , p_component_appl_id            => l_component_appl_id
57158   , p_amb_context_code             => l_amb_context_code
57159   , p_side                         => 'NA'
57160   );
57161 
57162 
57163    --
57164    --
57165    END IF;
57166 
57167        --
57168        -- Update the line information that should be overwritten
57169        --
57170        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
57171                                          p_header_num   => 1);
57172        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
57173 
57174        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
57175 
57176        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
57177           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
57178        END IF;
57179 
57180       --
57181       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
57182       --
57183       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
57184           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
57185       ELSE
57186           ---------------------------------------------------------------------------------------------------
57187           -- 4262811a Switch Sign
57188           ---------------------------------------------------------------------------------------------------
57189           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
57190           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
57191                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
57192           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
57193                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
57194           -- 5132302
57195           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
57199 
57196                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
57197 
57198       END IF;
57200       -- 4955764
57201       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
57202       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
57203 
57204 
57205       XLA_AE_LINES_PKG.ValidateCurrentLine;
57206       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
57207 
57208       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
57209                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
57210                ,p_balance_type_code => l_balance_type_code);
57211 
57212    END IF;
57213 
57214    -----------------------------------------------------------------------------------------
57215    -- 4262811 Multiperiod Accounting
57216    -----------------------------------------------------------------------------------------
57217      -- No MPA option is assigned.
57218 
57219 
57220 END IF;
57221 END IF;
57222 --
57223 
57224 --
57225 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
57226    trace
57227       (p_msg      => 'END of AcctLineType_116'
57228       ,p_level    => C_LEVEL_PROCEDURE
57229       ,p_module   => l_log_module);
57230 END IF;
57231 --
57232 EXCEPTION
57233   WHEN xla_exceptions_pkg.application_exception THEN
57234       RAISE;
57235   WHEN OTHERS THEN
57236        xla_exceptions_pkg.raise_message
57237            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_116');
57238 END AcctLineType_116;
57239 --
57240 
57241 ---------------------------------------
57242 --
57243 -- PRIVATE FUNCTION
57244 --         AcctLineType_117
57245 --
57246 ---------------------------------------
57247 PROCEDURE AcctLineType_117 (
57248   p_application_id        IN NUMBER
57249  ,p_event_id              IN NUMBER
57250  ,p_calculate_acctd_flag  IN VARCHAR2
57251  ,p_calculate_g_l_flag    IN VARCHAR2
57252  ,p_actual_flag           IN OUT VARCHAR2
57253  ,p_balance_type_code     OUT VARCHAR2
57254  ,p_gain_or_loss_ref      OUT VARCHAR2
57255  
57256 --Distribution GL Account
57257  , p_source_3            IN NUMBER
57258 --Distribution Source Type
57259  , p_source_20            IN VARCHAR2
57260 --Distribution Line Identifier
57261  , p_source_22            IN NUMBER
57262 --Distribution Type
57263  , p_source_23            IN VARCHAR2
57264 --Exchange Date
57265  , p_source_26            IN DATE
57266 --Exchange Rate
57267  , p_source_27            IN NUMBER
57268 --Exchange Rate Type
57269  , p_source_28            IN VARCHAR2
57270 --Transaction Distribution Identifier
57271  , p_source_34            IN NUMBER
57272 --Transaction Distribution Type
57273  , p_source_35            IN VARCHAR2
57274 --Receipt Applied To Application Identifier
57275  , p_source_58            IN NUMBER
57276 --Transaction Entity Code
57277  , p_source_59            IN VARCHAR2
57278 --Transaction Identifier
57279  , p_source_60            IN NUMBER
57280 --Applying Document Currency Code
57281  , p_source_61            IN VARCHAR2
57282 --Distribution Party Identifier
57283  , p_source_63            IN NUMBER
57284 --Distribution Party Site Id
57285  , p_source_64            IN NUMBER
57286 --Distribution Party Type
57287  , p_source_65            IN VARCHAR2
57288 --Distribution Multi Fund Additional Entry
57289  , p_source_69            IN VARCHAR2
57290 --DIST_ENT_AMT_FROM
57291  , p_source_72            IN NUMBER
57292 --Accounting Amount
57293  , p_source_73            IN NUMBER
57294 )
57295 IS
57296 
57297 l_component_type              VARCHAR2(80);
57298 l_component_code              VARCHAR2(30);
57299 l_component_type_code         VARCHAR2(1);
57300 l_component_appl_id           INTEGER;
57301 l_amb_context_code            VARCHAR2(30);
57302 l_entity_code                 VARCHAR2(30);
57303 l_event_class_code            VARCHAR2(30);
57304 l_ae_header_id                NUMBER;
57305 l_event_type_code             VARCHAR2(30);
57306 l_line_definition_code        VARCHAR2(30);
57307 l_line_definition_owner_code  VARCHAR2(1);
57308 --
57309 -- adr variables
57310 l_segment                     VARCHAR2(30);
57311 l_ccid                        NUMBER;
57312 l_adr_transaction_coa_id      NUMBER;
57313 l_adr_accounting_coa_id       NUMBER;
57314 l_adr_flexfield_segment_code  VARCHAR2(30);
57315 l_adr_flex_value_set_id       NUMBER;
57316 l_adr_value_type_code         VARCHAR2(30);
57317 l_adr_value_combination_id    NUMBER;
57318 l_adr_value_segment_code      VARCHAR2(30);
57319 
57320 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
57321 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
57322 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
57323 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
57324 
57325 -- 4262811 Variables ------------------------------------------------------------------------------------------
57326 l_entered_amt_idx             NUMBER;
57327 l_accted_amt_idx              NUMBER;
57328 l_acc_rev_flag                VARCHAR2(1);
57329 l_accrual_line_num            NUMBER;
57330 l_tmp_amt                     NUMBER;
57331 l_acc_rev_natural_side_code   VARCHAR2(1);
57332 
57333 l_num_entries                 NUMBER;
57337 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
57334 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
57335 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
57336 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
57338 l_recog_line_1                NUMBER;
57339 l_recog_line_2                NUMBER;
57340 
57341 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
57342 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
57343 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
57344 
57345 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
57346 
57347 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
57348 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
57349 
57350 ---------------------------------------------------------------------------------------------------------------
57351 
57352 
57353 --
57354 -- bulk performance
57355 --
57356 l_balance_type_code           VARCHAR2(1);
57357 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
57358 l_log_module                  VARCHAR2(240);
57359 
57360 --
57361 -- Upgrade strategy
57362 --
57363 l_actual_upg_option           VARCHAR2(1);
57364 l_enc_upg_option           VARCHAR2(1);
57365 
57366 --
57367 BEGIN
57368 --
57369 IF g_log_enabled THEN
57370       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_117';
57371 END IF;
57372 --
57373 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
57374 
57375       trace
57376          (p_msg      => 'BEGIN of AcctLineType_117'
57377          ,p_level    => C_LEVEL_PROCEDURE
57378          ,p_module   => l_log_module);
57379 
57380 END IF;
57381 --
57382 l_component_type             := 'AMB_JLT';
57383 l_component_code             := 'RCT_CURR_ROUND';
57384 l_component_type_code        := 'S';
57385 l_component_appl_id          :=  222;
57386 l_amb_context_code           := 'DEFAULT';
57387 l_entity_code                := 'RECEIPTS';
57388 l_event_class_code           := 'RECEIPT';
57389 l_event_type_code            := 'RECEIPT_ALL';
57390 l_line_definition_owner_code := 'S';
57391 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
57392 --
57393 l_balance_type_code          := 'A';
57394 l_segment                     := NULL;
57395 l_ccid                        := NULL;
57396 l_adr_transaction_coa_id      := NULL;
57397 l_adr_accounting_coa_id       := NULL;
57398 l_adr_flexfield_segment_code  := NULL;
57399 l_adr_flex_value_set_id       := NULL;
57400 l_adr_value_type_code         := NULL;
57401 l_adr_value_combination_id    := NULL;
57402 l_adr_value_segment_code      := NULL;
57403 
57404 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
57405 l_bflow_class_code           := '';    -- 4219869 Business Flow
57406 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
57407 l_budgetary_control_flag     := 'N';
57408 
57409 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
57410 l_bflow_applied_to_amt       := NULL; -- 5132302
57411 l_entered_amt_idx            := NULL;          -- 4262811
57412 l_accted_amt_idx             := NULL;          -- 4262811
57413 l_acc_rev_flag               := NULL;          -- 4262811
57414 l_accrual_line_num           := NULL;          -- 4262811
57415 l_tmp_amt                    := NULL;          -- 4262811
57416 --
57417  
57418 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
57419     l_balance_type_code <> 'B' THEN
57420 IF NVL(p_source_20,'
57421 ') =  'CURR_ROUND' AND 
57422 NVL(p_source_69,'
57423 ') =  'N'
57424  THEN 
57425 
57426    --
57427    XLA_AE_LINES_PKG.SetNewLine;
57428 
57429    p_balance_type_code          := l_balance_type_code;
57430    -- set the flag so later we will know whether the gain loss line needs to be created
57431    
57432    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
57433      p_actual_flag :='A';
57434    END IF;
57435 
57436    --
57437    -- bulk performance
57438    --
57439    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
57440                                       p_header_num   => 0); -- 4262811
57441    --
57442    -- set accounting line options
57443    --
57444    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
57445            p_natural_side_code          => 'C'
57446          , p_gain_or_loss_flag          => 'N'
57447          , p_gl_transfer_mode_code      => 'S'
57448          , p_acct_entry_type_code       => 'A'
57449          , p_switch_side_flag           => 'Y'
57450          , p_merge_duplicate_code       => 'A'
57451          );
57452    --
57453    l_acc_rev_natural_side_code := 'D';  -- 4262811
57454    -- 
57455    --
57456    -- set accounting line type info
57457    --
57458    xla_ae_lines_pkg.SetAcctLineType
57459       (p_component_type             => l_component_type
57460       ,p_event_type_code            => l_event_type_code
57461       ,p_line_definition_owner_code => l_line_definition_owner_code
57462       ,p_line_definition_code       => l_line_definition_code
57463       ,p_accounting_line_code       => l_component_code
57464       ,p_accounting_line_type_code  => l_component_type_code
57465       ,p_accounting_line_appl_id    => l_component_appl_id
57469    --
57466       ,p_amb_context_code           => l_amb_context_code
57467       ,p_entity_code                => l_entity_code
57468       ,p_event_class_code           => l_event_class_code);
57470    -- set accounting class
57471    --
57472    xla_ae_lines_pkg.SetAcctClass(
57473            p_accounting_class_code  => 'ROUNDING'
57474          , p_ae_header_id           => l_ae_header_id
57475          );
57476 
57477    --
57478    -- set rounding class
57479    --
57480    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
57481                       'RECEIVABLE';
57482 
57483    --
57484    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
57485    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
57486    --
57487    -- bulk performance
57488    --
57489    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
57490 
57491    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
57492       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
57493 
57494    -- 4955764
57495    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
57496       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
57497 
57498    -- 4458381 Public Sector Enh
57499    
57500    --
57501    -- set accounting attributes for the line type
57502    --
57503    l_entered_amt_idx := 8;
57504    l_accted_amt_idx  := 13;
57505    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
57506    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
57507    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
57508    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
57509    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
57510    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
57511    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
57512    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
57513    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
57514    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
57515    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
57516    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
57517    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
57518    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
57519    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
57520    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
57521    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
57522    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
57523    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
57524    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
57525    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
57526    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
57527    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
57528    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
57529    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
57530    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
57531    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
57532    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
57533    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
57534    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
57535    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
57536    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
57537    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
57538 
57539    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
57540    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
57541 
57542    ---------------------------------------------------------------------------------------------------------------
57543    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
57544    ---------------------------------------------------------------------------------------------------------------
57545    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
57546 
57547    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
57548    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
57549 
57550    IF xla_accounting_cache_pkg.GetValueChar
57551          (p_source_code         => 'LEDGER_CATEGORY_CODE'
57552          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
57553    AND l_bflow_method_code = 'PRIOR_ENTRY'
57554 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
57555    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
57556          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
57557        )
57558    THEN
57559          xla_ae_lines_pkg.BflowUpgEntry
57560            (p_business_method_code    => l_bflow_method_code
57561            ,p_business_class_code     => l_bflow_class_code
57562            ,p_balance_type            => l_balance_type_code);
57563    ELSE
57564       NULL;
57568    --
57565 -- No business flow processing for business flow method of NONE.
57566    END IF;
57567 
57569    -- call analytical criteria
57570    --
57571    
57572    --
57573    -- call description
57574    --
57575    -- No description or it is inherited.
57576    --
57577    -- call ADRs
57578    -- Bug 4922099
57579    --
57580    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
57581         (NVL(l_actual_upg_option, 'N') = 'O') OR
57582         (NVL(l_enc_upg_option, 'N') = 'O')
57583       )
57584    THEN
57585    NULL;
57586    --
57587    --
57588    
57589   l_ccid := AcctDerRule_7(
57590            p_application_id           => p_application_id
57591          , p_ae_header_id             => l_ae_header_id 
57592 , p_source_3 => p_source_3
57593          , x_transaction_coa_id       => l_adr_transaction_coa_id
57594          , x_accounting_coa_id        => l_adr_accounting_coa_id
57595          , x_value_type_code          => l_adr_value_type_code
57596          , p_side                     => 'NA'
57597    );
57598 
57599    xla_ae_lines_pkg.set_ccid(
57600     p_code_combination_id          => l_ccid
57601   , p_value_type_code              => l_adr_value_type_code
57602   , p_transaction_coa_id           => l_adr_transaction_coa_id
57603   , p_accounting_coa_id            => l_adr_accounting_coa_id
57604   , p_adr_code                     => 'DIST_CCID'
57605   , p_adr_type_code                => 'S'
57606   , p_component_type               => l_component_type
57607   , p_component_code               => l_component_code
57608   , p_component_type_code          => l_component_type_code
57609   , p_component_appl_id            => l_component_appl_id
57610   , p_amb_context_code             => l_amb_context_code
57611   , p_side                         => 'NA'
57612   );
57613 
57614 
57615    --
57616    --
57617    END IF;
57618    --
57619    -- Bug 4922099
57620    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
57621           (NVL(l_enc_upg_option, 'N') = 'O')
57622         ) AND
57623         (l_bflow_method_code = 'PRIOR_ENTRY')
57624       )
57625    THEN
57626       IF
57627       --
57628       1 = 2
57629       --
57630       THEN
57631       xla_accounting_err_pkg.build_message
57632                                     (p_appli_s_name            => 'XLA'
57633                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
57634                                     ,p_token_1                 => 'LINE_NUMBER'
57635                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
57636                                     ,p_token_2                 => 'LINE_TYPE_NAME'
57637                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
57638                                                                              l_component_type
57639                                                                             ,l_component_code
57640                                                                             ,l_component_type_code
57641                                                                             ,l_component_appl_id
57642                                                                             ,l_amb_context_code
57643                                                                             ,l_entity_code
57644                                                                             ,l_event_class_code
57645                                                                            )
57646                                     ,p_token_3                 => 'OWNER'
57647                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
57648                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
57649                                                                           ,p_lookup_code    => l_component_type_code
57650                                                                          )
57651                                     ,p_token_4                 => 'PRODUCT_NAME'
57652                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
57653                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
57654                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
57655                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
57656                                     ,p_ae_header_id            =>  NULL
57657                                        );
57658 
57659         IF (C_LEVEL_ERROR>= g_log_level) THEN
57660                  trace
57661                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
57662                       ,p_level    => C_LEVEL_ERROR
57663                       ,p_module   => l_log_module);
57664         END IF;
57665       END IF;
57666    END IF;
57667    --
57668    --
57669    ------------------------------------------------------------------------------------------------
57670    -- 4219869 Business Flow
57671    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
57672    -- Prior Entry.  Currently, the following code is always generated.
57673    ------------------------------------------------------------------------------------------------
57677    -- 4219869 Business Flow
57674    XLA_AE_LINES_PKG.ValidateCurrentLine;
57675 
57676    ------------------------------------------------------------------------------------
57678    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
57679    ------------------------------------------------------------------------------------
57680    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
57681 
57682    ----------------------------------------------------------------------------------
57683    -- 4219869 Business Flow
57684    -- Update journal entry status -- Need to generate this within IF <condition>
57685    ----------------------------------------------------------------------------------
57686    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
57687          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
57688          ,p_balance_type_code => l_balance_type_code
57689          );
57690 
57691    -------------------------------------------------------------------------------------------
57692    -- 4262811 - Generate the Accrual Reversal lines
57693    -------------------------------------------------------------------------------------------
57694    BEGIN
57695       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
57696                               (g_array_event(p_event_id).array_value_num('header_index'));
57697       IF l_acc_rev_flag IS NULL THEN
57698          l_acc_rev_flag := 'N';
57699       END IF;
57700    EXCEPTION
57701       WHEN OTHERS THEN
57702          l_acc_rev_flag := 'N';
57703    END;
57704    --
57705    IF (l_acc_rev_flag = 'Y') THEN
57706 
57707        -- 4645092  ------------------------------------------------------------------------------
57708        -- To allow MPA report to determine if it should generate report process
57709        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
57710        ------------------------------------------------------------------------------------------
57711 
57712        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
57713        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
57714    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
57715    -- call ADRs
57716    -- Bug 4922099
57717    --
57718    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
57719         (NVL(l_actual_upg_option, 'N') = 'O') OR
57720         (NVL(l_enc_upg_option, 'N') = 'O')
57721       )
57722    THEN
57723    NULL;
57724    --
57725    --
57726    
57727   l_ccid := AcctDerRule_7(
57728            p_application_id           => p_application_id
57729          , p_ae_header_id             => l_ae_header_id 
57730 , p_source_3 => p_source_3
57731          , x_transaction_coa_id       => l_adr_transaction_coa_id
57732          , x_accounting_coa_id        => l_adr_accounting_coa_id
57733          , x_value_type_code          => l_adr_value_type_code
57734          , p_side                     => 'NA'
57735    );
57736 
57737    xla_ae_lines_pkg.set_ccid(
57738     p_code_combination_id          => l_ccid
57739   , p_value_type_code              => l_adr_value_type_code
57740   , p_transaction_coa_id           => l_adr_transaction_coa_id
57741   , p_accounting_coa_id            => l_adr_accounting_coa_id
57742   , p_adr_code                     => 'DIST_CCID'
57743   , p_adr_type_code                => 'S'
57744   , p_component_type               => l_component_type
57745   , p_component_code               => l_component_code
57746   , p_component_type_code          => l_component_type_code
57747   , p_component_appl_id            => l_component_appl_id
57748   , p_amb_context_code             => l_amb_context_code
57749   , p_side                         => 'NA'
57750   );
57751 
57752 
57753    --
57754    --
57755    END IF;
57756 
57757        --
57758        -- Update the line information that should be overwritten
57759        --
57760        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
57761                                          p_header_num   => 1);
57762        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
57763 
57764        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
57765 
57766        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
57767           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
57768        END IF;
57769 
57770       --
57771       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
57772       --
57773       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
57774           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
57775       ELSE
57776           ---------------------------------------------------------------------------------------------------
57777           -- 4262811a Switch Sign
57778           ---------------------------------------------------------------------------------------------------
57779           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
57780           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
57781                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
57782           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
57783                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
57787 
57784           -- 5132302
57785           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
57786                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
57788       END IF;
57789 
57790       -- 4955764
57791       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
57792       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
57793 
57794 
57795       XLA_AE_LINES_PKG.ValidateCurrentLine;
57796       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
57797 
57798       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
57799                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
57800                ,p_balance_type_code => l_balance_type_code);
57801 
57802    END IF;
57803 
57804    -----------------------------------------------------------------------------------------
57805    -- 4262811 Multiperiod Accounting
57806    -----------------------------------------------------------------------------------------
57807      -- No MPA option is assigned.
57808 
57809 
57810 END IF;
57811 END IF;
57812 --
57813 
57814 --
57815 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
57816    trace
57817       (p_msg      => 'END of AcctLineType_117'
57818       ,p_level    => C_LEVEL_PROCEDURE
57819       ,p_module   => l_log_module);
57820 END IF;
57821 --
57822 EXCEPTION
57823   WHEN xla_exceptions_pkg.application_exception THEN
57824       RAISE;
57825   WHEN OTHERS THEN
57826        xla_exceptions_pkg.raise_message
57827            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_117');
57828 END AcctLineType_117;
57829 --
57830 
57831 ---------------------------------------
57832 --
57833 -- PRIVATE FUNCTION
57834 --         AcctLineType_118
57835 --
57836 ---------------------------------------
57837 PROCEDURE AcctLineType_118 (
57838   p_application_id        IN NUMBER
57839  ,p_event_id              IN NUMBER
57840  ,p_calculate_acctd_flag  IN VARCHAR2
57841  ,p_calculate_g_l_flag    IN VARCHAR2
57842  ,p_actual_flag           IN OUT VARCHAR2
57843  ,p_balance_type_code     OUT VARCHAR2
57844  ,p_gain_or_loss_ref      OUT VARCHAR2
57845  
57846 --Distribution GL Account
57847  , p_source_3            IN NUMBER
57848 --Distribution Source Type
57849  , p_source_20            IN VARCHAR2
57850 --Distribution Line Identifier
57851  , p_source_22            IN NUMBER
57852 --Distribution Type
57853  , p_source_23            IN VARCHAR2
57854 --Exchange Date
57855  , p_source_26            IN DATE
57856 --Exchange Rate
57857  , p_source_27            IN NUMBER
57858 --Exchange Rate Type
57859  , p_source_28            IN VARCHAR2
57860 --Transaction Distribution Identifier
57861  , p_source_34            IN NUMBER
57862 --Transaction Distribution Type
57863  , p_source_35            IN VARCHAR2
57864 --Receipt Applied To Application Identifier
57865  , p_source_58            IN NUMBER
57866 --Transaction Entity Code
57867  , p_source_59            IN VARCHAR2
57868 --Transaction Identifier
57869  , p_source_60            IN NUMBER
57870 --Applying Document Currency Code
57871  , p_source_61            IN VARCHAR2
57872 --Distribution Party Identifier
57873  , p_source_63            IN NUMBER
57874 --Distribution Party Site Id
57875  , p_source_64            IN NUMBER
57876 --Distribution Party Type
57877  , p_source_65            IN VARCHAR2
57878 --Distribution Multi Fund Additional Entry
57879  , p_source_69            IN VARCHAR2
57880 --DIST_ENT_AMT_FROM
57881  , p_source_72            IN NUMBER
57882 --Accounting Amount
57883  , p_source_73            IN NUMBER
57884 )
57885 IS
57886 
57887 l_component_type              VARCHAR2(80);
57888 l_component_code              VARCHAR2(30);
57889 l_component_type_code         VARCHAR2(1);
57890 l_component_appl_id           INTEGER;
57891 l_amb_context_code            VARCHAR2(30);
57892 l_entity_code                 VARCHAR2(30);
57893 l_event_class_code            VARCHAR2(30);
57894 l_ae_header_id                NUMBER;
57895 l_event_type_code             VARCHAR2(30);
57896 l_line_definition_code        VARCHAR2(30);
57897 l_line_definition_owner_code  VARCHAR2(1);
57898 --
57899 -- adr variables
57900 l_segment                     VARCHAR2(30);
57901 l_ccid                        NUMBER;
57902 l_adr_transaction_coa_id      NUMBER;
57903 l_adr_accounting_coa_id       NUMBER;
57904 l_adr_flexfield_segment_code  VARCHAR2(30);
57905 l_adr_flex_value_set_id       NUMBER;
57906 l_adr_value_type_code         VARCHAR2(30);
57907 l_adr_value_combination_id    NUMBER;
57908 l_adr_value_segment_code      VARCHAR2(30);
57909 
57910 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
57911 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
57912 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
57913 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
57914 
57915 -- 4262811 Variables ------------------------------------------------------------------------------------------
57916 l_entered_amt_idx             NUMBER;
57917 l_accted_amt_idx              NUMBER;
57918 l_acc_rev_flag                VARCHAR2(1);
57919 l_accrual_line_num            NUMBER;
57920 l_tmp_amt                     NUMBER;
57921 l_acc_rev_natural_side_code   VARCHAR2(1);
57922 
57926 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
57923 l_num_entries                 NUMBER;
57924 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
57925 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
57927 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
57928 l_recog_line_1                NUMBER;
57929 l_recog_line_2                NUMBER;
57930 
57931 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
57932 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
57933 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
57934 
57935 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
57936 
57937 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
57938 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
57939 
57940 ---------------------------------------------------------------------------------------------------------------
57941 
57942 
57943 --
57944 -- bulk performance
57945 --
57946 l_balance_type_code           VARCHAR2(1);
57947 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
57948 l_log_module                  VARCHAR2(240);
57949 
57950 --
57951 -- Upgrade strategy
57952 --
57953 l_actual_upg_option           VARCHAR2(1);
57954 l_enc_upg_option           VARCHAR2(1);
57955 
57956 --
57957 BEGIN
57958 --
57959 IF g_log_enabled THEN
57960       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_118';
57961 END IF;
57962 --
57963 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
57964 
57965       trace
57966          (p_msg      => 'BEGIN of AcctLineType_118'
57967          ,p_level    => C_LEVEL_PROCEDURE
57968          ,p_module   => l_log_module);
57969 
57970 END IF;
57971 --
57972 l_component_type             := 'AMB_JLT';
57973 l_component_code             := 'RCT_DEBT';
57974 l_component_type_code        := 'S';
57975 l_component_appl_id          :=  222;
57976 l_amb_context_code           := 'DEFAULT';
57977 l_entity_code                := 'RECEIPTS';
57978 l_event_class_code           := 'RECEIPT';
57979 l_event_type_code            := 'RECEIPT_ALL';
57980 l_line_definition_owner_code := 'S';
57981 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
57982 --
57983 l_balance_type_code          := 'A';
57984 l_segment                     := NULL;
57985 l_ccid                        := NULL;
57986 l_adr_transaction_coa_id      := NULL;
57987 l_adr_accounting_coa_id       := NULL;
57988 l_adr_flexfield_segment_code  := NULL;
57989 l_adr_flex_value_set_id       := NULL;
57990 l_adr_value_type_code         := NULL;
57991 l_adr_value_combination_id    := NULL;
57992 l_adr_value_segment_code      := NULL;
57993 
57994 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
57995 l_bflow_class_code           := '';    -- 4219869 Business Flow
57996 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
57997 l_budgetary_control_flag     := 'N';
57998 
57999 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
58000 l_bflow_applied_to_amt       := NULL; -- 5132302
58001 l_entered_amt_idx            := NULL;          -- 4262811
58002 l_accted_amt_idx             := NULL;          -- 4262811
58003 l_acc_rev_flag               := NULL;          -- 4262811
58004 l_accrual_line_num           := NULL;          -- 4262811
58005 l_tmp_amt                    := NULL;          -- 4262811
58006 --
58007  
58008 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
58009     l_balance_type_code <> 'B' THEN
58010 IF NVL(p_source_20,'
58011 ') =  'SHORT_TERM_DEBT' AND 
58012 NVL(p_source_69,'
58013 ') =  'N'
58014  THEN 
58015 
58016    --
58017    XLA_AE_LINES_PKG.SetNewLine;
58018 
58019    p_balance_type_code          := l_balance_type_code;
58020    -- set the flag so later we will know whether the gain loss line needs to be created
58021    
58022    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
58023      p_actual_flag :='A';
58024    END IF;
58025 
58026    --
58027    -- bulk performance
58028    --
58029    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
58030                                       p_header_num   => 0); -- 4262811
58031    --
58032    -- set accounting line options
58033    --
58034    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
58035            p_natural_side_code          => 'C'
58036          , p_gain_or_loss_flag          => 'N'
58037          , p_gl_transfer_mode_code      => 'S'
58038          , p_acct_entry_type_code       => 'A'
58039          , p_switch_side_flag           => 'Y'
58040          , p_merge_duplicate_code       => 'A'
58041          );
58042    --
58043    l_acc_rev_natural_side_code := 'D';  -- 4262811
58044    -- 
58045    --
58046    -- set accounting line type info
58047    --
58048    xla_ae_lines_pkg.SetAcctLineType
58049       (p_component_type             => l_component_type
58050       ,p_event_type_code            => l_event_type_code
58051       ,p_line_definition_owner_code => l_line_definition_owner_code
58052       ,p_line_definition_code       => l_line_definition_code
58053       ,p_accounting_line_code       => l_component_code
58054       ,p_accounting_line_type_code  => l_component_type_code
58058       ,p_event_class_code           => l_event_class_code);
58055       ,p_accounting_line_appl_id    => l_component_appl_id
58056       ,p_amb_context_code           => l_amb_context_code
58057       ,p_entity_code                => l_entity_code
58059    --
58060    -- set accounting class
58061    --
58062    xla_ae_lines_pkg.SetAcctClass(
58063            p_accounting_class_code  => 'SHORT_TERM_DEBT'
58064          , p_ae_header_id           => l_ae_header_id
58065          );
58066 
58067    --
58068    -- set rounding class
58069    --
58070    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
58071                       'RECEIVABLE';
58072 
58073    --
58074    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
58075    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
58076    --
58077    -- bulk performance
58078    --
58079    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
58080 
58081    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
58082       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
58083 
58084    -- 4955764
58085    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
58086       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
58087 
58088    -- 4458381 Public Sector Enh
58089    
58090    --
58091    -- set accounting attributes for the line type
58092    --
58093    l_entered_amt_idx := 8;
58094    l_accted_amt_idx  := 13;
58095    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
58096    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
58097    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
58098    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
58099    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
58100    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
58101    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
58102    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
58103    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
58104    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
58105    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
58106    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
58107    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
58108    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
58109    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
58110    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
58111    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
58112    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
58113    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
58114    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
58115    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
58116    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
58117    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
58118    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
58119    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
58120    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
58121    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
58122    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
58123    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
58124    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
58125    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
58126    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
58127    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
58128 
58129    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
58130    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
58131 
58132    ---------------------------------------------------------------------------------------------------------------
58133    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
58134    ---------------------------------------------------------------------------------------------------------------
58135    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
58136 
58137    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
58138    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
58139 
58140    IF xla_accounting_cache_pkg.GetValueChar
58141          (p_source_code         => 'LEDGER_CATEGORY_CODE'
58142          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
58143    AND l_bflow_method_code = 'PRIOR_ENTRY'
58144 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
58145    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
58146          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
58147        )
58148    THEN
58149          xla_ae_lines_pkg.BflowUpgEntry
58150            (p_business_method_code    => l_bflow_method_code
58151            ,p_business_class_code     => l_bflow_class_code
58152            ,p_balance_type            => l_balance_type_code);
58156    END IF;
58153    ELSE
58154       NULL;
58155 -- No business flow processing for business flow method of NONE.
58157 
58158    --
58159    -- call analytical criteria
58160    --
58161    
58162    --
58163    -- call description
58164    --
58165    -- No description or it is inherited.
58166    --
58167    -- call ADRs
58168    -- Bug 4922099
58169    --
58170    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
58171         (NVL(l_actual_upg_option, 'N') = 'O') OR
58172         (NVL(l_enc_upg_option, 'N') = 'O')
58173       )
58174    THEN
58175    NULL;
58176    --
58177    --
58178    
58179   l_ccid := AcctDerRule_7(
58180            p_application_id           => p_application_id
58181          , p_ae_header_id             => l_ae_header_id 
58182 , p_source_3 => p_source_3
58183          , x_transaction_coa_id       => l_adr_transaction_coa_id
58184          , x_accounting_coa_id        => l_adr_accounting_coa_id
58185          , x_value_type_code          => l_adr_value_type_code
58186          , p_side                     => 'NA'
58187    );
58188 
58189    xla_ae_lines_pkg.set_ccid(
58190     p_code_combination_id          => l_ccid
58191   , p_value_type_code              => l_adr_value_type_code
58192   , p_transaction_coa_id           => l_adr_transaction_coa_id
58193   , p_accounting_coa_id            => l_adr_accounting_coa_id
58194   , p_adr_code                     => 'DIST_CCID'
58195   , p_adr_type_code                => 'S'
58196   , p_component_type               => l_component_type
58197   , p_component_code               => l_component_code
58198   , p_component_type_code          => l_component_type_code
58199   , p_component_appl_id            => l_component_appl_id
58200   , p_amb_context_code             => l_amb_context_code
58201   , p_side                         => 'NA'
58202   );
58203 
58204 
58205    --
58206    --
58207    END IF;
58208    --
58209    -- Bug 4922099
58210    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
58211           (NVL(l_enc_upg_option, 'N') = 'O')
58212         ) AND
58213         (l_bflow_method_code = 'PRIOR_ENTRY')
58214       )
58215    THEN
58216       IF
58217       --
58218       1 = 2
58219       --
58220       THEN
58221       xla_accounting_err_pkg.build_message
58222                                     (p_appli_s_name            => 'XLA'
58223                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
58224                                     ,p_token_1                 => 'LINE_NUMBER'
58225                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
58226                                     ,p_token_2                 => 'LINE_TYPE_NAME'
58227                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
58228                                                                              l_component_type
58229                                                                             ,l_component_code
58230                                                                             ,l_component_type_code
58231                                                                             ,l_component_appl_id
58232                                                                             ,l_amb_context_code
58233                                                                             ,l_entity_code
58234                                                                             ,l_event_class_code
58235                                                                            )
58236                                     ,p_token_3                 => 'OWNER'
58237                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
58238                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
58239                                                                           ,p_lookup_code    => l_component_type_code
58240                                                                          )
58241                                     ,p_token_4                 => 'PRODUCT_NAME'
58242                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
58243                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
58244                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
58245                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
58246                                     ,p_ae_header_id            =>  NULL
58247                                        );
58248 
58249         IF (C_LEVEL_ERROR>= g_log_level) THEN
58250                  trace
58251                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
58252                       ,p_level    => C_LEVEL_ERROR
58253                       ,p_module   => l_log_module);
58254         END IF;
58255       END IF;
58256    END IF;
58257    --
58258    --
58259    ------------------------------------------------------------------------------------------------
58260    -- 4219869 Business Flow
58261    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
58262    -- Prior Entry.  Currently, the following code is always generated.
58266    ------------------------------------------------------------------------------------
58263    ------------------------------------------------------------------------------------------------
58264    XLA_AE_LINES_PKG.ValidateCurrentLine;
58265 
58267    -- 4219869 Business Flow
58268    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
58269    ------------------------------------------------------------------------------------
58270    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
58271 
58272    ----------------------------------------------------------------------------------
58273    -- 4219869 Business Flow
58274    -- Update journal entry status -- Need to generate this within IF <condition>
58275    ----------------------------------------------------------------------------------
58276    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
58277          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
58278          ,p_balance_type_code => l_balance_type_code
58279          );
58280 
58281    -------------------------------------------------------------------------------------------
58282    -- 4262811 - Generate the Accrual Reversal lines
58283    -------------------------------------------------------------------------------------------
58284    BEGIN
58285       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
58286                               (g_array_event(p_event_id).array_value_num('header_index'));
58287       IF l_acc_rev_flag IS NULL THEN
58288          l_acc_rev_flag := 'N';
58289       END IF;
58290    EXCEPTION
58291       WHEN OTHERS THEN
58292          l_acc_rev_flag := 'N';
58293    END;
58294    --
58295    IF (l_acc_rev_flag = 'Y') THEN
58296 
58297        -- 4645092  ------------------------------------------------------------------------------
58298        -- To allow MPA report to determine if it should generate report process
58299        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
58300        ------------------------------------------------------------------------------------------
58301 
58302        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
58303        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
58304    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
58305    -- call ADRs
58306    -- Bug 4922099
58307    --
58308    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
58309         (NVL(l_actual_upg_option, 'N') = 'O') OR
58310         (NVL(l_enc_upg_option, 'N') = 'O')
58311       )
58312    THEN
58313    NULL;
58314    --
58315    --
58316    
58317   l_ccid := AcctDerRule_7(
58318            p_application_id           => p_application_id
58319          , p_ae_header_id             => l_ae_header_id 
58320 , p_source_3 => p_source_3
58321          , x_transaction_coa_id       => l_adr_transaction_coa_id
58322          , x_accounting_coa_id        => l_adr_accounting_coa_id
58323          , x_value_type_code          => l_adr_value_type_code
58324          , p_side                     => 'NA'
58325    );
58326 
58327    xla_ae_lines_pkg.set_ccid(
58328     p_code_combination_id          => l_ccid
58329   , p_value_type_code              => l_adr_value_type_code
58330   , p_transaction_coa_id           => l_adr_transaction_coa_id
58331   , p_accounting_coa_id            => l_adr_accounting_coa_id
58332   , p_adr_code                     => 'DIST_CCID'
58333   , p_adr_type_code                => 'S'
58334   , p_component_type               => l_component_type
58335   , p_component_code               => l_component_code
58336   , p_component_type_code          => l_component_type_code
58337   , p_component_appl_id            => l_component_appl_id
58338   , p_amb_context_code             => l_amb_context_code
58339   , p_side                         => 'NA'
58340   );
58341 
58342 
58343    --
58344    --
58345    END IF;
58346 
58347        --
58348        -- Update the line information that should be overwritten
58349        --
58350        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
58351                                          p_header_num   => 1);
58352        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
58353 
58354        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
58355 
58356        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
58357           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
58358        END IF;
58359 
58360       --
58361       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
58362       --
58363       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
58364           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
58365       ELSE
58366           ---------------------------------------------------------------------------------------------------
58367           -- 4262811a Switch Sign
58368           ---------------------------------------------------------------------------------------------------
58369           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
58370           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
58371                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
58375           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
58372           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
58373                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
58374           -- 5132302
58376                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
58377 
58378       END IF;
58379 
58380       -- 4955764
58381       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
58382       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
58383 
58384 
58385       XLA_AE_LINES_PKG.ValidateCurrentLine;
58386       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
58387 
58388       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
58389                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
58390                ,p_balance_type_code => l_balance_type_code);
58391 
58392    END IF;
58393 
58394    -----------------------------------------------------------------------------------------
58395    -- 4262811 Multiperiod Accounting
58396    -----------------------------------------------------------------------------------------
58397      -- No MPA option is assigned.
58398 
58399 
58400 END IF;
58401 END IF;
58402 --
58403 
58404 --
58405 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
58406    trace
58407       (p_msg      => 'END of AcctLineType_118'
58408       ,p_level    => C_LEVEL_PROCEDURE
58409       ,p_module   => l_log_module);
58410 END IF;
58411 --
58412 EXCEPTION
58413   WHEN xla_exceptions_pkg.application_exception THEN
58414       RAISE;
58415   WHEN OTHERS THEN
58416        xla_exceptions_pkg.raise_message
58417            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_118');
58418 END AcctLineType_118;
58419 --
58420 
58421 ---------------------------------------
58422 --
58423 -- PRIVATE FUNCTION
58424 --         AcctLineType_119
58425 --
58426 ---------------------------------------
58427 PROCEDURE AcctLineType_119 (
58428   p_application_id        IN NUMBER
58429  ,p_event_id              IN NUMBER
58430  ,p_calculate_acctd_flag  IN VARCHAR2
58431  ,p_calculate_g_l_flag    IN VARCHAR2
58432  ,p_actual_flag           IN OUT VARCHAR2
58433  ,p_balance_type_code     OUT VARCHAR2
58434  ,p_gain_or_loss_ref      OUT VARCHAR2
58435  
58436 --Distribution GL Account
58437  , p_source_3            IN NUMBER
58438 --Distribution Source Type
58439  , p_source_20            IN VARCHAR2
58440 --Distribution Line Identifier
58441  , p_source_22            IN NUMBER
58442 --Distribution Type
58443  , p_source_23            IN VARCHAR2
58444 --Entered Amount
58445  , p_source_24            IN NUMBER
58446 --Currency Code
58447  , p_source_25            IN VARCHAR2
58448 --Applied To Document Accounting Amount
58449  , p_source_29            IN NUMBER
58450 --Transaction Distribution Identifier
58451  , p_source_34            IN NUMBER
58452 --Transaction Distribution Type
58453  , p_source_35            IN VARCHAR2
58454 --Applied To Document Exchange Date
58455  , p_source_57            IN DATE
58456 --Receipt Applied To Application Identifier
58457  , p_source_58            IN NUMBER
58458 --Transaction Entity Code
58459  , p_source_59            IN VARCHAR2
58460 --Transaction Identifier
58461  , p_source_60            IN NUMBER
58462 --Applied To Document Exchange Rate
58463  , p_source_62            IN NUMBER
58464 --Distribution Party Identifier
58465  , p_source_63            IN NUMBER
58466 --Distribution Party Site Id
58467  , p_source_64            IN NUMBER
58468 --Distribution Party Type
58469  , p_source_65            IN VARCHAR2
58470 --Distribution Multi Fund Additional Entry
58471  , p_source_69            IN VARCHAR2
58472 --Applied To Document Exchange Rate Type
58473  , p_source_74            IN VARCHAR2
58474 )
58475 IS
58476 
58477 l_component_type              VARCHAR2(80);
58478 l_component_code              VARCHAR2(30);
58479 l_component_type_code         VARCHAR2(1);
58480 l_component_appl_id           INTEGER;
58481 l_amb_context_code            VARCHAR2(30);
58482 l_entity_code                 VARCHAR2(30);
58483 l_event_class_code            VARCHAR2(30);
58484 l_ae_header_id                NUMBER;
58485 l_event_type_code             VARCHAR2(30);
58486 l_line_definition_code        VARCHAR2(30);
58487 l_line_definition_owner_code  VARCHAR2(1);
58488 --
58489 -- adr variables
58490 l_segment                     VARCHAR2(30);
58491 l_ccid                        NUMBER;
58492 l_adr_transaction_coa_id      NUMBER;
58493 l_adr_accounting_coa_id       NUMBER;
58494 l_adr_flexfield_segment_code  VARCHAR2(30);
58495 l_adr_flex_value_set_id       NUMBER;
58496 l_adr_value_type_code         VARCHAR2(30);
58497 l_adr_value_combination_id    NUMBER;
58498 l_adr_value_segment_code      VARCHAR2(30);
58499 
58500 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
58501 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
58502 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
58503 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
58504 
58505 -- 4262811 Variables ------------------------------------------------------------------------------------------
58506 l_entered_amt_idx             NUMBER;
58510 l_tmp_amt                     NUMBER;
58507 l_accted_amt_idx              NUMBER;
58508 l_acc_rev_flag                VARCHAR2(1);
58509 l_accrual_line_num            NUMBER;
58511 l_acc_rev_natural_side_code   VARCHAR2(1);
58512 
58513 l_num_entries                 NUMBER;
58514 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
58515 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
58516 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
58517 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
58518 l_recog_line_1                NUMBER;
58519 l_recog_line_2                NUMBER;
58520 
58521 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
58522 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
58523 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
58524 
58525 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
58526 
58527 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
58528 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
58529 
58530 ---------------------------------------------------------------------------------------------------------------
58531 
58532 
58533 --
58534 -- bulk performance
58535 --
58536 l_balance_type_code           VARCHAR2(1);
58537 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
58538 l_log_module                  VARCHAR2(240);
58539 
58540 --
58541 -- Upgrade strategy
58542 --
58543 l_actual_upg_option           VARCHAR2(1);
58544 l_enc_upg_option           VARCHAR2(1);
58545 
58546 --
58547 BEGIN
58548 --
58549 IF g_log_enabled THEN
58550       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_119';
58551 END IF;
58552 --
58553 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
58554 
58555       trace
58556          (p_msg      => 'BEGIN of AcctLineType_119'
58557          ,p_level    => C_LEVEL_PROCEDURE
58558          ,p_module   => l_log_module);
58559 
58560 END IF;
58561 --
58562 l_component_type             := 'AMB_JLT';
58563 l_component_code             := 'RCT_DEFERRED_TAX';
58564 l_component_type_code        := 'S';
58565 l_component_appl_id          :=  222;
58566 l_amb_context_code           := 'DEFAULT';
58567 l_entity_code                := 'RECEIPTS';
58568 l_event_class_code           := 'RECEIPT';
58569 l_event_type_code            := 'RECEIPT_ALL';
58570 l_line_definition_owner_code := 'S';
58571 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
58572 --
58573 l_balance_type_code          := 'A';
58574 l_segment                     := NULL;
58575 l_ccid                        := NULL;
58576 l_adr_transaction_coa_id      := NULL;
58577 l_adr_accounting_coa_id       := NULL;
58578 l_adr_flexfield_segment_code  := NULL;
58579 l_adr_flex_value_set_id       := NULL;
58580 l_adr_value_type_code         := NULL;
58581 l_adr_value_combination_id    := NULL;
58582 l_adr_value_segment_code      := NULL;
58583 
58584 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
58585 l_bflow_class_code           := '';    -- 4219869 Business Flow
58586 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
58587 l_budgetary_control_flag     := 'N';
58588 
58589 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
58590 l_bflow_applied_to_amt       := NULL; -- 5132302
58591 l_entered_amt_idx            := NULL;          -- 4262811
58592 l_accted_amt_idx             := NULL;          -- 4262811
58593 l_acc_rev_flag               := NULL;          -- 4262811
58594 l_accrual_line_num           := NULL;          -- 4262811
58595 l_tmp_amt                    := NULL;          -- 4262811
58596 --
58597  
58598 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
58599     l_balance_type_code <> 'B' THEN
58600 IF NVL(p_source_20,'
58601 ') =  'DEFERRED_TAX' AND 
58602 NVL(p_source_69,'
58603 ') =  'N'
58604  THEN 
58605 
58606    --
58607    XLA_AE_LINES_PKG.SetNewLine;
58608 
58609    p_balance_type_code          := l_balance_type_code;
58610    -- set the flag so later we will know whether the gain loss line needs to be created
58611    
58612    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
58613      p_actual_flag :='A';
58614    END IF;
58615 
58616    --
58617    -- bulk performance
58618    --
58619    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
58620                                       p_header_num   => 0); -- 4262811
58621    --
58622    -- set accounting line options
58623    --
58624    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
58625            p_natural_side_code          => 'C'
58626          , p_gain_or_loss_flag          => 'N'
58627          , p_gl_transfer_mode_code      => 'S'
58628          , p_acct_entry_type_code       => 'A'
58629          , p_switch_side_flag           => 'Y'
58630          , p_merge_duplicate_code       => 'A'
58631          );
58632    --
58633    l_acc_rev_natural_side_code := 'D';  -- 4262811
58634    -- 
58635    --
58636    -- set accounting line type info
58637    --
58638    xla_ae_lines_pkg.SetAcctLineType
58639       (p_component_type             => l_component_type
58640       ,p_event_type_code            => l_event_type_code
58644       ,p_accounting_line_type_code  => l_component_type_code
58641       ,p_line_definition_owner_code => l_line_definition_owner_code
58642       ,p_line_definition_code       => l_line_definition_code
58643       ,p_accounting_line_code       => l_component_code
58645       ,p_accounting_line_appl_id    => l_component_appl_id
58646       ,p_amb_context_code           => l_amb_context_code
58647       ,p_entity_code                => l_entity_code
58648       ,p_event_class_code           => l_event_class_code);
58649    --
58650    -- set accounting class
58651    --
58652    xla_ae_lines_pkg.SetAcctClass(
58653            p_accounting_class_code  => 'DEFERRED_TAX'
58654          , p_ae_header_id           => l_ae_header_id
58655          );
58656 
58657    --
58658    -- set rounding class
58659    --
58660    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
58661                       'RECEIVABLE';
58662 
58663    --
58664    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
58665    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
58666    --
58667    -- bulk performance
58668    --
58669    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
58670 
58671    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
58672       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
58673 
58674    -- 4955764
58675    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
58676       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
58677 
58678    -- 4458381 Public Sector Enh
58679    
58680    --
58681    -- set accounting attributes for the line type
58682    --
58683    l_entered_amt_idx := 8;
58684    l_accted_amt_idx  := 13;
58685    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
58686    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
58687    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
58688    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
58689    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
58690    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
58691    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
58692    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
58693    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
58694    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
58695    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
58696    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
58697    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
58698    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
58699    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
58700    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
58701    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
58702    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
58703    l_rec_acct_attrs.array_char_value(9)  := p_source_25;
58704    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
58705    l_rec_acct_attrs.array_date_value(10)  := p_source_57;
58706    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
58707    l_rec_acct_attrs.array_num_value(11)  := p_source_62;
58708    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
58709    l_rec_acct_attrs.array_char_value(12)  := p_source_74;
58710    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
58711    l_rec_acct_attrs.array_num_value(13)  := p_source_29;
58712    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
58713    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
58714    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
58715    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
58716    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
58717    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
58718 
58719    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
58720    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
58721 
58722    ---------------------------------------------------------------------------------------------------------------
58723    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
58724    ---------------------------------------------------------------------------------------------------------------
58725    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
58726 
58727    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
58728    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
58729 
58730    IF xla_accounting_cache_pkg.GetValueChar
58731          (p_source_code         => 'LEDGER_CATEGORY_CODE'
58732          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
58733    AND l_bflow_method_code = 'PRIOR_ENTRY'
58734 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
58735    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
58736          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
58737        )
58738    THEN
58742            ,p_balance_type            => l_balance_type_code);
58739          xla_ae_lines_pkg.BflowUpgEntry
58740            (p_business_method_code    => l_bflow_method_code
58741            ,p_business_class_code     => l_bflow_class_code
58743    ELSE
58744       NULL;
58745 -- No business flow processing for business flow method of NONE.
58746    END IF;
58747 
58748    --
58749    -- call analytical criteria
58750    --
58751    
58752    --
58753    -- call description
58754    --
58755    -- No description or it is inherited.
58756    --
58757    -- call ADRs
58758    -- Bug 4922099
58759    --
58760    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
58761         (NVL(l_actual_upg_option, 'N') = 'O') OR
58762         (NVL(l_enc_upg_option, 'N') = 'O')
58763       )
58764    THEN
58765    NULL;
58766    --
58767    --
58768    
58769   l_ccid := AcctDerRule_7(
58770            p_application_id           => p_application_id
58771          , p_ae_header_id             => l_ae_header_id 
58772 , p_source_3 => p_source_3
58773          , x_transaction_coa_id       => l_adr_transaction_coa_id
58774          , x_accounting_coa_id        => l_adr_accounting_coa_id
58775          , x_value_type_code          => l_adr_value_type_code
58776          , p_side                     => 'NA'
58777    );
58778 
58779    xla_ae_lines_pkg.set_ccid(
58780     p_code_combination_id          => l_ccid
58781   , p_value_type_code              => l_adr_value_type_code
58782   , p_transaction_coa_id           => l_adr_transaction_coa_id
58783   , p_accounting_coa_id            => l_adr_accounting_coa_id
58784   , p_adr_code                     => 'DIST_CCID'
58785   , p_adr_type_code                => 'S'
58786   , p_component_type               => l_component_type
58787   , p_component_code               => l_component_code
58788   , p_component_type_code          => l_component_type_code
58789   , p_component_appl_id            => l_component_appl_id
58790   , p_amb_context_code             => l_amb_context_code
58791   , p_side                         => 'NA'
58792   );
58793 
58794 
58795    --
58796    --
58797    END IF;
58798    --
58799    -- Bug 4922099
58800    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
58801           (NVL(l_enc_upg_option, 'N') = 'O')
58802         ) AND
58803         (l_bflow_method_code = 'PRIOR_ENTRY')
58804       )
58805    THEN
58806       IF
58807       --
58808       1 = 2
58809       --
58810       THEN
58811       xla_accounting_err_pkg.build_message
58812                                     (p_appli_s_name            => 'XLA'
58813                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
58814                                     ,p_token_1                 => 'LINE_NUMBER'
58815                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
58816                                     ,p_token_2                 => 'LINE_TYPE_NAME'
58817                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
58818                                                                              l_component_type
58819                                                                             ,l_component_code
58820                                                                             ,l_component_type_code
58821                                                                             ,l_component_appl_id
58822                                                                             ,l_amb_context_code
58823                                                                             ,l_entity_code
58824                                                                             ,l_event_class_code
58825                                                                            )
58826                                     ,p_token_3                 => 'OWNER'
58827                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
58828                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
58829                                                                           ,p_lookup_code    => l_component_type_code
58830                                                                          )
58831                                     ,p_token_4                 => 'PRODUCT_NAME'
58832                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
58833                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
58834                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
58835                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
58836                                     ,p_ae_header_id            =>  NULL
58837                                        );
58838 
58839         IF (C_LEVEL_ERROR>= g_log_level) THEN
58840                  trace
58841                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
58842                       ,p_level    => C_LEVEL_ERROR
58843                       ,p_module   => l_log_module);
58844         END IF;
58845       END IF;
58846    END IF;
58847    --
58848    --
58849    ------------------------------------------------------------------------------------------------
58853    ------------------------------------------------------------------------------------------------
58850    -- 4219869 Business Flow
58851    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
58852    -- Prior Entry.  Currently, the following code is always generated.
58854    XLA_AE_LINES_PKG.ValidateCurrentLine;
58855 
58856    ------------------------------------------------------------------------------------
58857    -- 4219869 Business Flow
58858    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
58859    ------------------------------------------------------------------------------------
58860    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
58861 
58862    ----------------------------------------------------------------------------------
58863    -- 4219869 Business Flow
58864    -- Update journal entry status -- Need to generate this within IF <condition>
58865    ----------------------------------------------------------------------------------
58866    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
58867          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
58868          ,p_balance_type_code => l_balance_type_code
58869          );
58870 
58871    -------------------------------------------------------------------------------------------
58872    -- 4262811 - Generate the Accrual Reversal lines
58873    -------------------------------------------------------------------------------------------
58874    BEGIN
58875       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
58876                               (g_array_event(p_event_id).array_value_num('header_index'));
58877       IF l_acc_rev_flag IS NULL THEN
58878          l_acc_rev_flag := 'N';
58879       END IF;
58880    EXCEPTION
58881       WHEN OTHERS THEN
58882          l_acc_rev_flag := 'N';
58883    END;
58884    --
58885    IF (l_acc_rev_flag = 'Y') THEN
58886 
58887        -- 4645092  ------------------------------------------------------------------------------
58888        -- To allow MPA report to determine if it should generate report process
58889        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
58890        ------------------------------------------------------------------------------------------
58891 
58892        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
58893        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
58894    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
58895    -- call ADRs
58896    -- Bug 4922099
58897    --
58898    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
58899         (NVL(l_actual_upg_option, 'N') = 'O') OR
58900         (NVL(l_enc_upg_option, 'N') = 'O')
58901       )
58902    THEN
58903    NULL;
58904    --
58905    --
58906    
58907   l_ccid := AcctDerRule_7(
58908            p_application_id           => p_application_id
58909          , p_ae_header_id             => l_ae_header_id 
58910 , p_source_3 => p_source_3
58911          , x_transaction_coa_id       => l_adr_transaction_coa_id
58912          , x_accounting_coa_id        => l_adr_accounting_coa_id
58913          , x_value_type_code          => l_adr_value_type_code
58914          , p_side                     => 'NA'
58915    );
58916 
58917    xla_ae_lines_pkg.set_ccid(
58918     p_code_combination_id          => l_ccid
58919   , p_value_type_code              => l_adr_value_type_code
58920   , p_transaction_coa_id           => l_adr_transaction_coa_id
58921   , p_accounting_coa_id            => l_adr_accounting_coa_id
58922   , p_adr_code                     => 'DIST_CCID'
58923   , p_adr_type_code                => 'S'
58924   , p_component_type               => l_component_type
58925   , p_component_code               => l_component_code
58926   , p_component_type_code          => l_component_type_code
58927   , p_component_appl_id            => l_component_appl_id
58928   , p_amb_context_code             => l_amb_context_code
58929   , p_side                         => 'NA'
58930   );
58931 
58932 
58933    --
58934    --
58935    END IF;
58936 
58937        --
58938        -- Update the line information that should be overwritten
58939        --
58940        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
58941                                          p_header_num   => 1);
58942        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
58943 
58944        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
58945 
58946        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
58947           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
58948        END IF;
58949 
58950       --
58951       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
58952       --
58953       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
58954           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
58955       ELSE
58956           ---------------------------------------------------------------------------------------------------
58957           -- 4262811a Switch Sign
58958           ---------------------------------------------------------------------------------------------------
58959           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
58960           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
58964           -- 5132302
58961                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
58962           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
58963                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
58965           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
58966                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
58967 
58968       END IF;
58969 
58970       -- 4955764
58971       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
58972       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
58973 
58974 
58975       XLA_AE_LINES_PKG.ValidateCurrentLine;
58976       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
58977 
58978       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
58979                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
58980                ,p_balance_type_code => l_balance_type_code);
58981 
58982    END IF;
58983 
58984    -----------------------------------------------------------------------------------------
58985    -- 4262811 Multiperiod Accounting
58986    -----------------------------------------------------------------------------------------
58987      -- No MPA option is assigned.
58988 
58989 
58990 END IF;
58991 END IF;
58992 --
58993 
58994 --
58995 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
58996    trace
58997       (p_msg      => 'END of AcctLineType_119'
58998       ,p_level    => C_LEVEL_PROCEDURE
58999       ,p_module   => l_log_module);
59000 END IF;
59001 --
59002 EXCEPTION
59003   WHEN xla_exceptions_pkg.application_exception THEN
59004       RAISE;
59005   WHEN OTHERS THEN
59006        xla_exceptions_pkg.raise_message
59007            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_119');
59008 END AcctLineType_119;
59009 --
59010 
59011 ---------------------------------------
59012 --
59013 -- PRIVATE FUNCTION
59014 --         AcctLineType_120
59015 --
59016 ---------------------------------------
59017 PROCEDURE AcctLineType_120 (
59018   p_application_id        IN NUMBER
59019  ,p_event_id              IN NUMBER
59020  ,p_calculate_acctd_flag  IN VARCHAR2
59021  ,p_calculate_g_l_flag    IN VARCHAR2
59022  ,p_actual_flag           IN OUT VARCHAR2
59023  ,p_balance_type_code     OUT VARCHAR2
59024  ,p_gain_or_loss_ref      OUT VARCHAR2
59025  
59026 --Distribution GL Account
59027  , p_source_3            IN NUMBER
59028 --Transaction Distribution GL Account
59029  , p_source_4            IN NUMBER
59030 --Distribution Source Type
59031  , p_source_20            IN VARCHAR2
59032 --Distribution Line Identifier
59033  , p_source_22            IN NUMBER
59034 --Distribution Type
59035  , p_source_23            IN VARCHAR2
59036 --Entered Amount
59037  , p_source_24            IN NUMBER
59038 --Currency Code
59039  , p_source_25            IN VARCHAR2
59040 --Applied To Document Accounting Amount
59041  , p_source_29            IN NUMBER
59042 --Transaction Distribution Identifier
59043  , p_source_34            IN NUMBER
59044 --Transaction Distribution Type
59045  , p_source_35            IN VARCHAR2
59046 --Applied To Document Exchange Date
59047  , p_source_57            IN DATE
59048 --Receipt Applied To Application Identifier
59049  , p_source_58            IN NUMBER
59050 --Transaction Entity Code
59051  , p_source_59            IN VARCHAR2
59052 --Transaction Identifier
59053  , p_source_60            IN NUMBER
59054 --Applied To Document Exchange Rate
59055  , p_source_62            IN NUMBER
59056 --Distribution Party Identifier
59057  , p_source_63            IN NUMBER
59058 --Distribution Party Site Id
59059  , p_source_64            IN NUMBER
59060 --Distribution Party Type
59061  , p_source_65            IN VARCHAR2
59062 --Distribution Multi Fund Additional Entry
59063  , p_source_69            IN VARCHAR2
59064 --Applied To Document Exchange Rate Type
59065  , p_source_74            IN VARCHAR2
59066 )
59067 IS
59068 
59069 l_component_type              VARCHAR2(80);
59070 l_component_code              VARCHAR2(30);
59071 l_component_type_code         VARCHAR2(1);
59072 l_component_appl_id           INTEGER;
59073 l_amb_context_code            VARCHAR2(30);
59074 l_entity_code                 VARCHAR2(30);
59075 l_event_class_code            VARCHAR2(30);
59076 l_ae_header_id                NUMBER;
59077 l_event_type_code             VARCHAR2(30);
59078 l_line_definition_code        VARCHAR2(30);
59079 l_line_definition_owner_code  VARCHAR2(1);
59080 --
59081 -- adr variables
59082 l_segment                     VARCHAR2(30);
59083 l_ccid                        NUMBER;
59084 l_adr_transaction_coa_id      NUMBER;
59085 l_adr_accounting_coa_id       NUMBER;
59086 l_adr_flexfield_segment_code  VARCHAR2(30);
59087 l_adr_flex_value_set_id       NUMBER;
59088 l_adr_value_type_code         VARCHAR2(30);
59089 l_adr_value_combination_id    NUMBER;
59090 l_adr_value_segment_code      VARCHAR2(30);
59091 
59092 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
59093 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
59097 -- 4262811 Variables ------------------------------------------------------------------------------------------
59094 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
59095 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
59096 
59098 l_entered_amt_idx             NUMBER;
59099 l_accted_amt_idx              NUMBER;
59100 l_acc_rev_flag                VARCHAR2(1);
59101 l_accrual_line_num            NUMBER;
59102 l_tmp_amt                     NUMBER;
59103 l_acc_rev_natural_side_code   VARCHAR2(1);
59104 
59105 l_num_entries                 NUMBER;
59106 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
59107 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
59108 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
59109 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
59110 l_recog_line_1                NUMBER;
59111 l_recog_line_2                NUMBER;
59112 
59113 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
59114 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
59115 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
59116 
59117 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
59118 
59119 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
59120 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
59121 
59122 ---------------------------------------------------------------------------------------------------------------
59123 
59124 
59125 --
59126 -- bulk performance
59127 --
59128 l_balance_type_code           VARCHAR2(1);
59129 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
59130 l_log_module                  VARCHAR2(240);
59131 
59132 --
59133 -- Upgrade strategy
59134 --
59135 l_actual_upg_option           VARCHAR2(1);
59136 l_enc_upg_option           VARCHAR2(1);
59137 
59138 --
59139 BEGIN
59140 --
59141 IF g_log_enabled THEN
59142       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_120';
59143 END IF;
59144 --
59145 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
59146 
59147       trace
59148          (p_msg      => 'BEGIN of AcctLineType_120'
59149          ,p_level    => C_LEVEL_PROCEDURE
59150          ,p_module   => l_log_module);
59151 
59152 END IF;
59153 --
59154 l_component_type             := 'AMB_JLT';
59155 l_component_code             := 'RCT_EDISC';
59156 l_component_type_code        := 'S';
59157 l_component_appl_id          :=  222;
59158 l_amb_context_code           := 'DEFAULT';
59159 l_entity_code                := 'RECEIPTS';
59160 l_event_class_code           := 'RECEIPT';
59161 l_event_type_code            := 'RECEIPT_ALL';
59162 l_line_definition_owner_code := 'S';
59163 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
59164 --
59165 l_balance_type_code          := 'A';
59166 l_segment                     := NULL;
59167 l_ccid                        := NULL;
59168 l_adr_transaction_coa_id      := NULL;
59169 l_adr_accounting_coa_id       := NULL;
59170 l_adr_flexfield_segment_code  := NULL;
59171 l_adr_flex_value_set_id       := NULL;
59172 l_adr_value_type_code         := NULL;
59173 l_adr_value_combination_id    := NULL;
59174 l_adr_value_segment_code      := NULL;
59175 
59176 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
59177 l_bflow_class_code           := '';    -- 4219869 Business Flow
59178 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
59179 l_budgetary_control_flag     := 'N';
59180 
59181 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
59182 l_bflow_applied_to_amt       := NULL; -- 5132302
59183 l_entered_amt_idx            := NULL;          -- 4262811
59184 l_accted_amt_idx             := NULL;          -- 4262811
59185 l_acc_rev_flag               := NULL;          -- 4262811
59186 l_accrual_line_num           := NULL;          -- 4262811
59187 l_tmp_amt                    := NULL;          -- 4262811
59188 --
59189  
59190 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
59191     l_balance_type_code <> 'B' THEN
59192 IF NVL(p_source_20,'
59193 ') =  'EDISC' AND 
59194 NVL(p_source_69,'
59195 ') =  'N'
59196  THEN 
59197 
59198    --
59199    XLA_AE_LINES_PKG.SetNewLine;
59200 
59201    p_balance_type_code          := l_balance_type_code;
59202    -- set the flag so later we will know whether the gain loss line needs to be created
59203    
59204    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
59205      p_actual_flag :='A';
59206    END IF;
59207 
59208    --
59209    -- bulk performance
59210    --
59211    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
59212                                       p_header_num   => 0); -- 4262811
59213    --
59214    -- set accounting line options
59215    --
59216    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
59217            p_natural_side_code          => 'C'
59218          , p_gain_or_loss_flag          => 'N'
59219          , p_gl_transfer_mode_code      => 'S'
59220          , p_acct_entry_type_code       => 'A'
59221          , p_switch_side_flag           => 'Y'
59222          , p_merge_duplicate_code       => 'A'
59223          );
59224    --
59228    -- set accounting line type info
59225    l_acc_rev_natural_side_code := 'D';  -- 4262811
59226    -- 
59227    --
59229    --
59230    xla_ae_lines_pkg.SetAcctLineType
59231       (p_component_type             => l_component_type
59232       ,p_event_type_code            => l_event_type_code
59233       ,p_line_definition_owner_code => l_line_definition_owner_code
59234       ,p_line_definition_code       => l_line_definition_code
59235       ,p_accounting_line_code       => l_component_code
59236       ,p_accounting_line_type_code  => l_component_type_code
59237       ,p_accounting_line_appl_id    => l_component_appl_id
59238       ,p_amb_context_code           => l_amb_context_code
59239       ,p_entity_code                => l_entity_code
59240       ,p_event_class_code           => l_event_class_code);
59241    --
59242    -- set accounting class
59243    --
59244    xla_ae_lines_pkg.SetAcctClass(
59245            p_accounting_class_code  => 'EDISC'
59246          , p_ae_header_id           => l_ae_header_id
59247          );
59248 
59249    --
59250    -- set rounding class
59251    --
59252    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
59253                       'RECEIVABLE';
59254 
59255    --
59256    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
59257    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
59258    --
59259    -- bulk performance
59260    --
59261    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
59262 
59263    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
59264       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
59265 
59266    -- 4955764
59267    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
59268       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
59269 
59270    -- 4458381 Public Sector Enh
59271    
59272    --
59273    -- set accounting attributes for the line type
59274    --
59275    l_entered_amt_idx := 8;
59276    l_accted_amt_idx  := 13;
59277    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
59278    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
59279    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
59280    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
59281    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
59282    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
59283    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
59284    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
59285    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
59286    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
59287    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
59288    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
59289    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
59290    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
59291    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
59292    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
59293    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
59294    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
59295    l_rec_acct_attrs.array_char_value(9)  := p_source_25;
59296    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
59297    l_rec_acct_attrs.array_date_value(10)  := p_source_57;
59298    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
59299    l_rec_acct_attrs.array_num_value(11)  := p_source_62;
59300    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
59301    l_rec_acct_attrs.array_char_value(12)  := p_source_74;
59302    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
59303    l_rec_acct_attrs.array_num_value(13)  := p_source_29;
59304    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
59305    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
59306    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
59307    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
59308    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
59309    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
59310 
59311    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
59312    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
59313 
59314    ---------------------------------------------------------------------------------------------------------------
59315    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
59316    ---------------------------------------------------------------------------------------------------------------
59317    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
59318 
59319    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
59320    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
59321 
59322    IF xla_accounting_cache_pkg.GetValueChar
59323          (p_source_code         => 'LEDGER_CATEGORY_CODE'
59324          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
59328          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
59325    AND l_bflow_method_code = 'PRIOR_ENTRY'
59326 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
59327    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
59329        )
59330    THEN
59331          xla_ae_lines_pkg.BflowUpgEntry
59332            (p_business_method_code    => l_bflow_method_code
59333            ,p_business_class_code     => l_bflow_class_code
59334            ,p_balance_type            => l_balance_type_code);
59335    ELSE
59336       NULL;
59337 -- No business flow processing for business flow method of NONE.
59338    END IF;
59339 
59340    --
59341    -- call analytical criteria
59342    --
59343    
59344    --
59345    -- call description
59346    --
59347    
59348 xla_ae_lines_pkg.SetLineDescription(
59349    p_ae_header_id => l_ae_header_id
59350   ,p_description  => Description_1 (
59351      p_application_id         => p_application_id
59352    , p_ae_header_id           => l_ae_header_id 
59353    )
59354 );
59355 
59356 
59357    --
59358    -- call ADRs
59359    -- Bug 4922099
59360    --
59361    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
59362         (NVL(l_actual_upg_option, 'N') = 'O') OR
59363         (NVL(l_enc_upg_option, 'N') = 'O')
59364       )
59365    THEN
59366    NULL;
59367    --
59368    --
59369    
59370   l_ccid := AcctDerRule_7(
59371            p_application_id           => p_application_id
59372          , p_ae_header_id             => l_ae_header_id 
59373 , p_source_3 => p_source_3
59374          , x_transaction_coa_id       => l_adr_transaction_coa_id
59375          , x_accounting_coa_id        => l_adr_accounting_coa_id
59376          , x_value_type_code          => l_adr_value_type_code
59377          , p_side                     => 'NA'
59378    );
59379 
59380    xla_ae_lines_pkg.set_ccid(
59381     p_code_combination_id          => l_ccid
59382   , p_value_type_code              => l_adr_value_type_code
59383   , p_transaction_coa_id           => l_adr_transaction_coa_id
59384   , p_accounting_coa_id            => l_adr_accounting_coa_id
59385   , p_adr_code                     => 'DIST_CCID'
59386   , p_adr_type_code                => 'S'
59387   , p_component_type               => l_component_type
59388   , p_component_code               => l_component_code
59389   , p_component_type_code          => l_component_type_code
59390   , p_component_appl_id            => l_component_appl_id
59391   , p_amb_context_code             => l_amb_context_code
59392   , p_side                         => 'NA'
59393   );
59394 
59395 
59396    l_segment := AcctDerRule_5(
59397            p_application_id           => p_application_id
59398          , p_ae_header_id             => l_ae_header_id 
59399 , p_source_4 => p_source_4
59400          , x_transaction_coa_id       => l_adr_transaction_coa_id
59401          , x_accounting_coa_id        => l_adr_accounting_coa_id
59402          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
59403          , x_flex_value_set_id        => l_adr_flex_value_set_id
59404          , x_value_type_code          => l_adr_value_type_code
59405          , x_value_combination_id     => l_adr_value_combination_id
59406          , x_value_segment_code       => l_adr_value_segment_code
59407          , p_side                     => 'NA'
59408          , p_override_seg_flag        => 'Y'
59409    );
59410 
59411    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
59412 
59413       xla_ae_lines_pkg.set_segment(
59414           p_to_segment_code         => 'GL_BALANCING'
59415         , p_segment_value           => l_segment
59416         , p_from_segment_code       => l_adr_value_segment_code
59417         , p_from_combination_id     => l_adr_value_combination_id
59418         , p_value_type_code         => l_adr_value_type_code
59419         , p_transaction_coa_id      => l_adr_transaction_coa_id
59420         , p_accounting_coa_id       => l_adr_accounting_coa_id
59421         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
59422         , p_flex_value_set_id       => l_adr_flex_value_set_id
59423         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
59424         , p_adr_type_code           => 'S'
59425         , p_component_type          => l_component_type
59426         , p_component_code          => l_component_code
59427         , p_component_type_code     => l_component_type_code
59428         , p_component_appl_id       => l_component_appl_id
59429         , p_amb_context_code        => l_amb_context_code
59430         , p_entity_code             => 'RECEIPTS'
59431         , p_event_class_code        => 'RECEIPT'
59432         , p_side                    => 'NA'
59433         );
59434 
59435   END IF;
59436 
59437    --
59438    --
59439    END IF;
59440    --
59441    -- Bug 4922099
59442    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
59443           (NVL(l_enc_upg_option, 'N') = 'O')
59444         ) AND
59445         (l_bflow_method_code = 'PRIOR_ENTRY')
59446       )
59447    THEN
59448       IF
59449       --
59450       1 = 2
59451       --
59452       THEN
59453       xla_accounting_err_pkg.build_message
59454                                     (p_appli_s_name            => 'XLA'
59455                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
59459                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
59456                                     ,p_token_1                 => 'LINE_NUMBER'
59457                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
59458                                     ,p_token_2                 => 'LINE_TYPE_NAME'
59460                                                                              l_component_type
59461                                                                             ,l_component_code
59462                                                                             ,l_component_type_code
59463                                                                             ,l_component_appl_id
59464                                                                             ,l_amb_context_code
59465                                                                             ,l_entity_code
59466                                                                             ,l_event_class_code
59467                                                                            )
59468                                     ,p_token_3                 => 'OWNER'
59469                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
59470                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
59471                                                                           ,p_lookup_code    => l_component_type_code
59472                                                                          )
59473                                     ,p_token_4                 => 'PRODUCT_NAME'
59474                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
59475                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
59476                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
59477                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
59478                                     ,p_ae_header_id            =>  NULL
59479                                        );
59480 
59481         IF (C_LEVEL_ERROR>= g_log_level) THEN
59482                  trace
59483                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
59484                       ,p_level    => C_LEVEL_ERROR
59485                       ,p_module   => l_log_module);
59486         END IF;
59487       END IF;
59488    END IF;
59489    --
59490    --
59491    ------------------------------------------------------------------------------------------------
59492    -- 4219869 Business Flow
59493    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
59494    -- Prior Entry.  Currently, the following code is always generated.
59495    ------------------------------------------------------------------------------------------------
59496    XLA_AE_LINES_PKG.ValidateCurrentLine;
59497 
59498    ------------------------------------------------------------------------------------
59499    -- 4219869 Business Flow
59500    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
59501    ------------------------------------------------------------------------------------
59502    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
59503 
59504    ----------------------------------------------------------------------------------
59505    -- 4219869 Business Flow
59506    -- Update journal entry status -- Need to generate this within IF <condition>
59507    ----------------------------------------------------------------------------------
59508    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
59509          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
59510          ,p_balance_type_code => l_balance_type_code
59511          );
59512 
59513    -------------------------------------------------------------------------------------------
59514    -- 4262811 - Generate the Accrual Reversal lines
59515    -------------------------------------------------------------------------------------------
59516    BEGIN
59517       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
59518                               (g_array_event(p_event_id).array_value_num('header_index'));
59519       IF l_acc_rev_flag IS NULL THEN
59520          l_acc_rev_flag := 'N';
59521       END IF;
59522    EXCEPTION
59523       WHEN OTHERS THEN
59524          l_acc_rev_flag := 'N';
59525    END;
59526    --
59527    IF (l_acc_rev_flag = 'Y') THEN
59528 
59529        -- 4645092  ------------------------------------------------------------------------------
59530        -- To allow MPA report to determine if it should generate report process
59531        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
59532        ------------------------------------------------------------------------------------------
59533 
59534        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
59535        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
59536    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
59537    -- call ADRs
59538    -- Bug 4922099
59539    --
59540    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
59541         (NVL(l_actual_upg_option, 'N') = 'O') OR
59542         (NVL(l_enc_upg_option, 'N') = 'O')
59543       )
59544    THEN
59545    NULL;
59546    --
59547    --
59548    
59549   l_ccid := AcctDerRule_7(
59550            p_application_id           => p_application_id
59554          , x_accounting_coa_id        => l_adr_accounting_coa_id
59551          , p_ae_header_id             => l_ae_header_id 
59552 , p_source_3 => p_source_3
59553          , x_transaction_coa_id       => l_adr_transaction_coa_id
59555          , x_value_type_code          => l_adr_value_type_code
59556          , p_side                     => 'NA'
59557    );
59558 
59559    xla_ae_lines_pkg.set_ccid(
59560     p_code_combination_id          => l_ccid
59561   , p_value_type_code              => l_adr_value_type_code
59562   , p_transaction_coa_id           => l_adr_transaction_coa_id
59563   , p_accounting_coa_id            => l_adr_accounting_coa_id
59564   , p_adr_code                     => 'DIST_CCID'
59565   , p_adr_type_code                => 'S'
59566   , p_component_type               => l_component_type
59567   , p_component_code               => l_component_code
59568   , p_component_type_code          => l_component_type_code
59569   , p_component_appl_id            => l_component_appl_id
59570   , p_amb_context_code             => l_amb_context_code
59571   , p_side                         => 'NA'
59572   );
59573 
59574 
59575    l_segment := AcctDerRule_5(
59576            p_application_id           => p_application_id
59577          , p_ae_header_id             => l_ae_header_id 
59578 , p_source_4 => p_source_4
59579          , x_transaction_coa_id       => l_adr_transaction_coa_id
59580          , x_accounting_coa_id        => l_adr_accounting_coa_id
59581          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
59582          , x_flex_value_set_id        => l_adr_flex_value_set_id
59583          , x_value_type_code          => l_adr_value_type_code
59584          , x_value_combination_id     => l_adr_value_combination_id
59585          , x_value_segment_code       => l_adr_value_segment_code
59586          , p_side                     => 'NA'
59587          , p_override_seg_flag        => 'Y'
59588    );
59589 
59590    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
59591 
59592       xla_ae_lines_pkg.set_segment(
59593           p_to_segment_code         => 'GL_BALANCING'
59594         , p_segment_value           => l_segment
59595         , p_from_segment_code       => l_adr_value_segment_code
59596         , p_from_combination_id     => l_adr_value_combination_id
59597         , p_value_type_code         => l_adr_value_type_code
59598         , p_transaction_coa_id      => l_adr_transaction_coa_id
59599         , p_accounting_coa_id       => l_adr_accounting_coa_id
59600         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
59601         , p_flex_value_set_id       => l_adr_flex_value_set_id
59602         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
59603         , p_adr_type_code           => 'S'
59604         , p_component_type          => l_component_type
59605         , p_component_code          => l_component_code
59606         , p_component_type_code     => l_component_type_code
59607         , p_component_appl_id       => l_component_appl_id
59608         , p_amb_context_code        => l_amb_context_code
59609         , p_entity_code             => 'RECEIPTS'
59610         , p_event_class_code        => 'RECEIPT'
59611         , p_side                    => 'NA'
59612         );
59613 
59614   END IF;
59615 
59616    --
59617    --
59618    END IF;
59619 
59620        --
59621        -- Update the line information that should be overwritten
59622        --
59623        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
59624                                          p_header_num   => 1);
59625        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
59626 
59627        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
59628 
59629        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
59630           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
59631        END IF;
59632 
59633       --
59634       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
59635       --
59636       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
59637           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
59638       ELSE
59639           ---------------------------------------------------------------------------------------------------
59640           -- 4262811a Switch Sign
59641           ---------------------------------------------------------------------------------------------------
59642           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
59643           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
59644                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
59645           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
59646                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
59647           -- 5132302
59648           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
59649                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
59650 
59651       END IF;
59652 
59653       -- 4955764
59654       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
59658       XLA_AE_LINES_PKG.ValidateCurrentLine;
59655       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
59656 
59657 
59659       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
59660 
59661       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
59662                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
59663                ,p_balance_type_code => l_balance_type_code);
59664 
59665    END IF;
59666 
59667    -----------------------------------------------------------------------------------------
59668    -- 4262811 Multiperiod Accounting
59669    -----------------------------------------------------------------------------------------
59670      -- No MPA option is assigned.
59671 
59672 
59673 END IF;
59674 END IF;
59675 --
59676 
59677 --
59678 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
59679    trace
59680       (p_msg      => 'END of AcctLineType_120'
59681       ,p_level    => C_LEVEL_PROCEDURE
59682       ,p_module   => l_log_module);
59683 END IF;
59684 --
59685 EXCEPTION
59686   WHEN xla_exceptions_pkg.application_exception THEN
59687       RAISE;
59688   WHEN OTHERS THEN
59689        xla_exceptions_pkg.raise_message
59690            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_120');
59691 END AcctLineType_120;
59692 --
59693 
59694 ---------------------------------------
59695 --
59696 -- PRIVATE FUNCTION
59697 --         AcctLineType_121
59698 --
59699 ---------------------------------------
59700 PROCEDURE AcctLineType_121 (
59701   p_application_id        IN NUMBER
59702  ,p_event_id              IN NUMBER
59703  ,p_calculate_acctd_flag  IN VARCHAR2
59704  ,p_calculate_g_l_flag    IN VARCHAR2
59705  ,p_actual_flag           IN OUT VARCHAR2
59706  ,p_balance_type_code     OUT VARCHAR2
59707  ,p_gain_or_loss_ref      OUT VARCHAR2
59708  
59709 --Distribution GL Account
59710  , p_source_3            IN NUMBER
59711 --Distribution Source Type
59712  , p_source_20            IN VARCHAR2
59713 --Distribution Line Identifier
59714  , p_source_22            IN NUMBER
59715 --Distribution Type
59716  , p_source_23            IN VARCHAR2
59717 --Entered Amount
59718  , p_source_24            IN NUMBER
59719 --Exchange Date
59720  , p_source_26            IN DATE
59721 --Exchange Rate
59722  , p_source_27            IN NUMBER
59723 --Exchange Rate Type
59724  , p_source_28            IN VARCHAR2
59725 --Applied To Document Accounting Amount
59726  , p_source_29            IN NUMBER
59727 --Transaction Distribution Identifier
59728  , p_source_34            IN NUMBER
59729 --Transaction Distribution Type
59730  , p_source_35            IN VARCHAR2
59731 --Receipt Applied To Application Identifier
59732  , p_source_58            IN NUMBER
59733 --Transaction Entity Code
59734  , p_source_59            IN VARCHAR2
59735 --Transaction Identifier
59736  , p_source_60            IN NUMBER
59737 --Applying Document Currency Code
59738  , p_source_61            IN VARCHAR2
59739 --Distribution Party Identifier
59740  , p_source_63            IN NUMBER
59741 --Distribution Party Site Id
59742  , p_source_64            IN NUMBER
59743 --Distribution Party Type
59744  , p_source_65            IN VARCHAR2
59745 )
59746 IS
59747 
59748 l_component_type              VARCHAR2(80);
59749 l_component_code              VARCHAR2(30);
59750 l_component_type_code         VARCHAR2(1);
59751 l_component_appl_id           INTEGER;
59752 l_amb_context_code            VARCHAR2(30);
59753 l_entity_code                 VARCHAR2(30);
59754 l_event_class_code            VARCHAR2(30);
59755 l_ae_header_id                NUMBER;
59756 l_event_type_code             VARCHAR2(30);
59757 l_line_definition_code        VARCHAR2(30);
59758 l_line_definition_owner_code  VARCHAR2(1);
59759 --
59760 -- adr variables
59761 l_segment                     VARCHAR2(30);
59762 l_ccid                        NUMBER;
59763 l_adr_transaction_coa_id      NUMBER;
59764 l_adr_accounting_coa_id       NUMBER;
59765 l_adr_flexfield_segment_code  VARCHAR2(30);
59766 l_adr_flex_value_set_id       NUMBER;
59767 l_adr_value_type_code         VARCHAR2(30);
59768 l_adr_value_combination_id    NUMBER;
59769 l_adr_value_segment_code      VARCHAR2(30);
59770 
59771 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
59772 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
59773 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
59774 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
59775 
59776 -- 4262811 Variables ------------------------------------------------------------------------------------------
59777 l_entered_amt_idx             NUMBER;
59778 l_accted_amt_idx              NUMBER;
59779 l_acc_rev_flag                VARCHAR2(1);
59780 l_accrual_line_num            NUMBER;
59781 l_tmp_amt                     NUMBER;
59782 l_acc_rev_natural_side_code   VARCHAR2(1);
59783 
59784 l_num_entries                 NUMBER;
59785 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
59786 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
59787 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
59788 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
59792 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
59789 l_recog_line_1                NUMBER;
59790 l_recog_line_2                NUMBER;
59791 
59793 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
59794 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
59795 
59796 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
59797 
59798 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
59799 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
59800 
59801 ---------------------------------------------------------------------------------------------------------------
59802 
59803 
59804 --
59805 -- bulk performance
59806 --
59807 l_balance_type_code           VARCHAR2(1);
59808 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
59809 l_log_module                  VARCHAR2(240);
59810 
59811 --
59812 -- Upgrade strategy
59813 --
59814 l_actual_upg_option           VARCHAR2(1);
59815 l_enc_upg_option           VARCHAR2(1);
59816 
59817 --
59818 BEGIN
59819 --
59820 IF g_log_enabled THEN
59821       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_121';
59822 END IF;
59823 --
59824 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
59825 
59826       trace
59827          (p_msg      => 'BEGIN of AcctLineType_121'
59828          ,p_level    => C_LEVEL_PROCEDURE
59829          ,p_module   => l_log_module);
59830 
59831 END IF;
59832 --
59833 l_component_type             := 'AMB_JLT';
59834 l_component_code             := 'RCT_EXCH_GAIN';
59835 l_component_type_code        := 'S';
59836 l_component_appl_id          :=  222;
59837 l_amb_context_code           := 'DEFAULT';
59838 l_entity_code                := 'RECEIPTS';
59839 l_event_class_code           := 'RECEIPT';
59840 l_event_type_code            := 'RECEIPT_ALL';
59841 l_line_definition_owner_code := 'S';
59842 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
59843 --
59844 l_balance_type_code          := 'A';
59845 l_segment                     := NULL;
59846 l_ccid                        := NULL;
59847 l_adr_transaction_coa_id      := NULL;
59848 l_adr_accounting_coa_id       := NULL;
59849 l_adr_flexfield_segment_code  := NULL;
59850 l_adr_flex_value_set_id       := NULL;
59851 l_adr_value_type_code         := NULL;
59852 l_adr_value_combination_id    := NULL;
59853 l_adr_value_segment_code      := NULL;
59854 
59855 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
59856 l_bflow_class_code           := '';    -- 4219869 Business Flow
59857 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
59858 l_budgetary_control_flag     := 'N';
59859 
59860 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
59861 l_bflow_applied_to_amt       := NULL; -- 5132302
59862 l_entered_amt_idx            := NULL;          -- 4262811
59863 l_accted_amt_idx             := NULL;          -- 4262811
59864 l_acc_rev_flag               := NULL;          -- 4262811
59865 l_accrual_line_num           := NULL;          -- 4262811
59866 l_tmp_amt                    := NULL;          -- 4262811
59867 --
59868 IF ((p_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
59869             (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')) THEN
59870                return;
59871   END IF;
59872   
59873 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
59874     l_balance_type_code <> 'B' THEN
59875 IF NVL(p_source_20,'
59876 ') =  'EXCH_GAIN'
59877  THEN 
59878 
59879    --
59880    XLA_AE_LINES_PKG.SetNewLine;
59881 
59882    p_balance_type_code          := l_balance_type_code;
59883    -- set the flag so later we will know whether the gain loss line needs to be created
59884    
59885    IF(l_balance_type_code = 'A' ) THEN
59886      p_actual_flag :='G';
59887    END IF;
59888 
59889    --
59890    -- bulk performance
59891    --
59892    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
59893                                       p_header_num   => 0); -- 4262811
59894    --
59895    -- set accounting line options
59896    --
59897    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
59898            p_natural_side_code          => 'C'
59899          , p_gain_or_loss_flag          => 'Y'
59900          , p_gl_transfer_mode_code      => 'S'
59901          , p_acct_entry_type_code       => 'A'
59902          , p_switch_side_flag           => 'Y'
59903          , p_merge_duplicate_code       => 'A'
59904          );
59905    --
59906    l_acc_rev_natural_side_code := 'D';  -- 4262811
59907    -- 
59908    --
59909    -- set accounting line type info
59910    --
59911    xla_ae_lines_pkg.SetAcctLineType
59912       (p_component_type             => l_component_type
59913       ,p_event_type_code            => l_event_type_code
59914       ,p_line_definition_owner_code => l_line_definition_owner_code
59915       ,p_line_definition_code       => l_line_definition_code
59916       ,p_accounting_line_code       => l_component_code
59917       ,p_accounting_line_type_code  => l_component_type_code
59921       ,p_event_class_code           => l_event_class_code);
59918       ,p_accounting_line_appl_id    => l_component_appl_id
59919       ,p_amb_context_code           => l_amb_context_code
59920       ,p_entity_code                => l_entity_code
59922    --
59923    -- set accounting class
59924    --
59925    xla_ae_lines_pkg.SetAcctClass(
59926            p_accounting_class_code  => 'GAIN'
59927          , p_ae_header_id           => l_ae_header_id
59928          );
59929 
59930    --
59931    -- set rounding class
59932    --
59933    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
59934                       'RECEIVABLE';
59935 
59936    --
59937    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
59938    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
59939    --
59940    -- bulk performance
59941    --
59942    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
59943 
59944    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
59945       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
59946 
59947    -- 4955764
59948    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
59949       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
59950 
59951    -- 4458381 Public Sector Enh
59952    
59953    --
59954    -- set accounting attributes for the line type
59955    --
59956    l_entered_amt_idx := 8;
59957    l_accted_amt_idx  := 13;
59958    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
59959    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
59960    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
59961    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
59962    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
59963    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
59964    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
59965    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
59966    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
59967    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
59968    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
59969    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
59970    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
59971    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
59972    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
59973    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
59974    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
59975    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
59976    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
59977    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
59978    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
59979    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
59980    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
59981    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
59982    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
59983    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
59984    l_rec_acct_attrs.array_num_value(13)  := p_source_29;
59985    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
59986    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
59987    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
59988    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
59989    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
59990    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
59991 
59992    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
59993    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
59994 
59995    ---------------------------------------------------------------------------------------------------------------
59996    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
59997    ---------------------------------------------------------------------------------------------------------------
59998    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
59999 
60000    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
60001    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
60002 
60003    IF xla_accounting_cache_pkg.GetValueChar
60004          (p_source_code         => 'LEDGER_CATEGORY_CODE'
60005          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
60006    AND l_bflow_method_code = 'PRIOR_ENTRY'
60007 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
60008    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
60009          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
60010        )
60011    THEN
60012          xla_ae_lines_pkg.BflowUpgEntry
60013            (p_business_method_code    => l_bflow_method_code
60014            ,p_business_class_code     => l_bflow_class_code
60015            ,p_balance_type            => l_balance_type_code);
60016    ELSE
60017       NULL;
60018 -- No business flow processing for business flow method of NONE.
60019    END IF;
60023    --
60020 
60021    --
60022    -- call analytical criteria
60024    
60025    --
60026    -- call description
60027    --
60028    -- No description or it is inherited.
60029    --
60030    -- call ADRs
60031    -- Bug 4922099
60032    --
60033    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
60034         (NVL(l_actual_upg_option, 'N') = 'O') OR
60035         (NVL(l_enc_upg_option, 'N') = 'O')
60036       )
60037    THEN
60038    NULL;
60039    --
60040    --
60041    
60042   l_ccid := AcctDerRule_7(
60043            p_application_id           => p_application_id
60044          , p_ae_header_id             => l_ae_header_id 
60045 , p_source_3 => p_source_3
60046          , x_transaction_coa_id       => l_adr_transaction_coa_id
60047          , x_accounting_coa_id        => l_adr_accounting_coa_id
60048          , x_value_type_code          => l_adr_value_type_code
60049          , p_side                     => 'NA'
60050    );
60051 
60052    xla_ae_lines_pkg.set_ccid(
60053     p_code_combination_id          => l_ccid
60054   , p_value_type_code              => l_adr_value_type_code
60055   , p_transaction_coa_id           => l_adr_transaction_coa_id
60056   , p_accounting_coa_id            => l_adr_accounting_coa_id
60057   , p_adr_code                     => 'DIST_CCID'
60058   , p_adr_type_code                => 'S'
60059   , p_component_type               => l_component_type
60060   , p_component_code               => l_component_code
60061   , p_component_type_code          => l_component_type_code
60062   , p_component_appl_id            => l_component_appl_id
60063   , p_amb_context_code             => l_amb_context_code
60064   , p_side                         => 'NA'
60065   );
60066 
60067 
60068    --
60069    --
60070    END IF;
60071    --
60072    -- Bug 4922099
60073    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
60074           (NVL(l_enc_upg_option, 'N') = 'O')
60075         ) AND
60076         (l_bflow_method_code = 'PRIOR_ENTRY')
60077       )
60078    THEN
60079       IF
60080       --
60081       1 = 2
60082       --
60083       THEN
60084       xla_accounting_err_pkg.build_message
60085                                     (p_appli_s_name            => 'XLA'
60086                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
60087                                     ,p_token_1                 => 'LINE_NUMBER'
60088                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
60089                                     ,p_token_2                 => 'LINE_TYPE_NAME'
60090                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
60091                                                                              l_component_type
60092                                                                             ,l_component_code
60093                                                                             ,l_component_type_code
60094                                                                             ,l_component_appl_id
60095                                                                             ,l_amb_context_code
60096                                                                             ,l_entity_code
60097                                                                             ,l_event_class_code
60098                                                                            )
60099                                     ,p_token_3                 => 'OWNER'
60100                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
60101                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
60102                                                                           ,p_lookup_code    => l_component_type_code
60103                                                                          )
60104                                     ,p_token_4                 => 'PRODUCT_NAME'
60105                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
60106                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
60107                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
60108                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
60109                                     ,p_ae_header_id            =>  NULL
60110                                        );
60111 
60112         IF (C_LEVEL_ERROR>= g_log_level) THEN
60113                  trace
60114                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
60115                       ,p_level    => C_LEVEL_ERROR
60116                       ,p_module   => l_log_module);
60117         END IF;
60118       END IF;
60119    END IF;
60120    --
60121    --
60122    ------------------------------------------------------------------------------------------------
60123    -- 4219869 Business Flow
60124    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
60125    -- Prior Entry.  Currently, the following code is always generated.
60126    ------------------------------------------------------------------------------------------------
60127    XLA_AE_LINES_PKG.ValidateCurrentLine;
60128 
60129    ------------------------------------------------------------------------------------
60133    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
60130    -- 4219869 Business Flow
60131    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
60132    ------------------------------------------------------------------------------------
60134 
60135    ----------------------------------------------------------------------------------
60136    -- 4219869 Business Flow
60137    -- Update journal entry status -- Need to generate this within IF <condition>
60138    ----------------------------------------------------------------------------------
60139    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
60140          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
60141          ,p_balance_type_code => l_balance_type_code
60142          );
60143 
60144    -------------------------------------------------------------------------------------------
60145    -- 4262811 - Generate the Accrual Reversal lines
60146    -------------------------------------------------------------------------------------------
60147    BEGIN
60148       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
60149                               (g_array_event(p_event_id).array_value_num('header_index'));
60150       IF l_acc_rev_flag IS NULL THEN
60151          l_acc_rev_flag := 'N';
60152       END IF;
60153    EXCEPTION
60154       WHEN OTHERS THEN
60155          l_acc_rev_flag := 'N';
60156    END;
60157    --
60158    IF (l_acc_rev_flag = 'Y') THEN
60159 
60160        -- 4645092  ------------------------------------------------------------------------------
60161        -- To allow MPA report to determine if it should generate report process
60162        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
60163        ------------------------------------------------------------------------------------------
60164 
60165        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
60166        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
60167    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
60168    -- call ADRs
60169    -- Bug 4922099
60170    --
60171    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
60172         (NVL(l_actual_upg_option, 'N') = 'O') OR
60173         (NVL(l_enc_upg_option, 'N') = 'O')
60174       )
60175    THEN
60176    NULL;
60177    --
60178    --
60179    
60180   l_ccid := AcctDerRule_7(
60181            p_application_id           => p_application_id
60182          , p_ae_header_id             => l_ae_header_id 
60183 , p_source_3 => p_source_3
60184          , x_transaction_coa_id       => l_adr_transaction_coa_id
60185          , x_accounting_coa_id        => l_adr_accounting_coa_id
60186          , x_value_type_code          => l_adr_value_type_code
60187          , p_side                     => 'NA'
60188    );
60189 
60190    xla_ae_lines_pkg.set_ccid(
60191     p_code_combination_id          => l_ccid
60192   , p_value_type_code              => l_adr_value_type_code
60193   , p_transaction_coa_id           => l_adr_transaction_coa_id
60194   , p_accounting_coa_id            => l_adr_accounting_coa_id
60195   , p_adr_code                     => 'DIST_CCID'
60196   , p_adr_type_code                => 'S'
60197   , p_component_type               => l_component_type
60198   , p_component_code               => l_component_code
60199   , p_component_type_code          => l_component_type_code
60200   , p_component_appl_id            => l_component_appl_id
60201   , p_amb_context_code             => l_amb_context_code
60202   , p_side                         => 'NA'
60203   );
60204 
60205 
60206    --
60207    --
60208    END IF;
60209 
60210        --
60211        -- Update the line information that should be overwritten
60212        --
60213        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
60214                                          p_header_num   => 1);
60215        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
60216 
60217        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
60218 
60219        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
60220           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
60221        END IF;
60222 
60223       --
60224       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
60225       --
60226       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
60227           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
60228       ELSE
60229           ---------------------------------------------------------------------------------------------------
60230           -- 4262811a Switch Sign
60231           ---------------------------------------------------------------------------------------------------
60232           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
60233           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
60234                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
60235           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
60236                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
60237           -- 5132302
60241       END IF;
60238           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
60239                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
60240 
60242 
60243       -- 4955764
60244       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
60245       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
60246 
60247 
60248       XLA_AE_LINES_PKG.ValidateCurrentLine;
60249       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
60250 
60251       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
60252                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
60253                ,p_balance_type_code => l_balance_type_code);
60254 
60255    END IF;
60256 
60257    -----------------------------------------------------------------------------------------
60258    -- 4262811 Multiperiod Accounting
60259    -----------------------------------------------------------------------------------------
60260      -- No MPA option is assigned.
60261 
60262 
60263 END IF;
60264 END IF;
60265 --
60266 
60267 --
60268 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
60269    trace
60270       (p_msg      => 'END of AcctLineType_121'
60271       ,p_level    => C_LEVEL_PROCEDURE
60272       ,p_module   => l_log_module);
60273 END IF;
60274 --
60275 EXCEPTION
60276   WHEN xla_exceptions_pkg.application_exception THEN
60277       RAISE;
60278   WHEN OTHERS THEN
60279        xla_exceptions_pkg.raise_message
60280            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_121');
60281 END AcctLineType_121;
60282 --
60283 
60284 ---------------------------------------
60285 --
60286 -- PRIVATE FUNCTION
60287 --         AcctLineType_122
60288 --
60289 ---------------------------------------
60290 PROCEDURE AcctLineType_122 (
60291   p_application_id        IN NUMBER
60292  ,p_event_id              IN NUMBER
60293  ,p_calculate_acctd_flag  IN VARCHAR2
60294  ,p_calculate_g_l_flag    IN VARCHAR2
60295  ,p_actual_flag           IN OUT VARCHAR2
60296  ,p_balance_type_code     OUT VARCHAR2
60297  ,p_gain_or_loss_ref      OUT VARCHAR2
60298  
60299 --Distribution GL Account
60300  , p_source_3            IN NUMBER
60301 --Distribution Source Type
60302  , p_source_20            IN VARCHAR2
60303 --Distribution Line Identifier
60304  , p_source_22            IN NUMBER
60305 --Distribution Type
60306  , p_source_23            IN VARCHAR2
60307 --Entered Amount
60308  , p_source_24            IN NUMBER
60309 --Exchange Date
60310  , p_source_26            IN DATE
60311 --Exchange Rate
60312  , p_source_27            IN NUMBER
60313 --Exchange Rate Type
60314  , p_source_28            IN VARCHAR2
60315 --Applied To Document Accounting Amount
60316  , p_source_29            IN NUMBER
60317 --Transaction Distribution Identifier
60318  , p_source_34            IN NUMBER
60319 --Transaction Distribution Type
60320  , p_source_35            IN VARCHAR2
60321 --Receipt Applied To Application Identifier
60322  , p_source_58            IN NUMBER
60323 --Transaction Entity Code
60324  , p_source_59            IN VARCHAR2
60325 --Transaction Identifier
60326  , p_source_60            IN NUMBER
60327 --Applying Document Currency Code
60328  , p_source_61            IN VARCHAR2
60329 --Distribution Party Identifier
60330  , p_source_63            IN NUMBER
60331 --Distribution Party Site Id
60332  , p_source_64            IN NUMBER
60333 --Distribution Party Type
60334  , p_source_65            IN VARCHAR2
60335 )
60336 IS
60337 
60338 l_component_type              VARCHAR2(80);
60339 l_component_code              VARCHAR2(30);
60340 l_component_type_code         VARCHAR2(1);
60341 l_component_appl_id           INTEGER;
60342 l_amb_context_code            VARCHAR2(30);
60343 l_entity_code                 VARCHAR2(30);
60344 l_event_class_code            VARCHAR2(30);
60345 l_ae_header_id                NUMBER;
60346 l_event_type_code             VARCHAR2(30);
60347 l_line_definition_code        VARCHAR2(30);
60348 l_line_definition_owner_code  VARCHAR2(1);
60349 --
60350 -- adr variables
60351 l_segment                     VARCHAR2(30);
60352 l_ccid                        NUMBER;
60353 l_adr_transaction_coa_id      NUMBER;
60354 l_adr_accounting_coa_id       NUMBER;
60355 l_adr_flexfield_segment_code  VARCHAR2(30);
60356 l_adr_flex_value_set_id       NUMBER;
60357 l_adr_value_type_code         VARCHAR2(30);
60358 l_adr_value_combination_id    NUMBER;
60359 l_adr_value_segment_code      VARCHAR2(30);
60360 
60361 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
60362 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
60363 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
60364 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
60365 
60366 -- 4262811 Variables ------------------------------------------------------------------------------------------
60367 l_entered_amt_idx             NUMBER;
60368 l_accted_amt_idx              NUMBER;
60369 l_acc_rev_flag                VARCHAR2(1);
60370 l_accrual_line_num            NUMBER;
60371 l_tmp_amt                     NUMBER;
60372 l_acc_rev_natural_side_code   VARCHAR2(1);
60373 
60377 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
60374 l_num_entries                 NUMBER;
60375 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
60376 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
60378 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
60379 l_recog_line_1                NUMBER;
60380 l_recog_line_2                NUMBER;
60381 
60382 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
60383 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
60384 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
60385 
60386 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
60387 
60388 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
60389 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
60390 
60391 ---------------------------------------------------------------------------------------------------------------
60392 
60393 
60394 --
60395 -- bulk performance
60396 --
60397 l_balance_type_code           VARCHAR2(1);
60398 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
60399 l_log_module                  VARCHAR2(240);
60400 
60401 --
60402 -- Upgrade strategy
60403 --
60404 l_actual_upg_option           VARCHAR2(1);
60405 l_enc_upg_option           VARCHAR2(1);
60406 
60407 --
60408 BEGIN
60409 --
60410 IF g_log_enabled THEN
60411       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_122';
60412 END IF;
60413 --
60414 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
60415 
60416       trace
60417          (p_msg      => 'BEGIN of AcctLineType_122'
60418          ,p_level    => C_LEVEL_PROCEDURE
60419          ,p_module   => l_log_module);
60420 
60421 END IF;
60422 --
60423 l_component_type             := 'AMB_JLT';
60424 l_component_code             := 'RCT_EXCH_LOSS';
60425 l_component_type_code        := 'S';
60426 l_component_appl_id          :=  222;
60427 l_amb_context_code           := 'DEFAULT';
60428 l_entity_code                := 'RECEIPTS';
60429 l_event_class_code           := 'RECEIPT';
60430 l_event_type_code            := 'RECEIPT_ALL';
60431 l_line_definition_owner_code := 'S';
60432 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
60433 --
60434 l_balance_type_code          := 'A';
60435 l_segment                     := NULL;
60436 l_ccid                        := NULL;
60437 l_adr_transaction_coa_id      := NULL;
60438 l_adr_accounting_coa_id       := NULL;
60439 l_adr_flexfield_segment_code  := NULL;
60440 l_adr_flex_value_set_id       := NULL;
60441 l_adr_value_type_code         := NULL;
60442 l_adr_value_combination_id    := NULL;
60443 l_adr_value_segment_code      := NULL;
60444 
60445 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
60446 l_bflow_class_code           := '';    -- 4219869 Business Flow
60447 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
60448 l_budgetary_control_flag     := 'N';
60449 
60450 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
60451 l_bflow_applied_to_amt       := NULL; -- 5132302
60452 l_entered_amt_idx            := NULL;          -- 4262811
60453 l_accted_amt_idx             := NULL;          -- 4262811
60454 l_acc_rev_flag               := NULL;          -- 4262811
60455 l_accrual_line_num           := NULL;          -- 4262811
60456 l_tmp_amt                    := NULL;          -- 4262811
60457 --
60458 IF ((p_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
60459             (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')) THEN
60460                return;
60461   END IF;
60462   
60463 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
60464     l_balance_type_code <> 'B' THEN
60465 IF NVL(p_source_20,'
60466 ') =  'EXCH_LOSS'
60467  THEN 
60468 
60469    --
60470    XLA_AE_LINES_PKG.SetNewLine;
60471 
60472    p_balance_type_code          := l_balance_type_code;
60473    -- set the flag so later we will know whether the gain loss line needs to be created
60474    
60475    IF(l_balance_type_code = 'A' ) THEN
60476      p_actual_flag :='G';
60477    END IF;
60478 
60479    --
60480    -- bulk performance
60481    --
60482    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
60483                                       p_header_num   => 0); -- 4262811
60484    --
60485    -- set accounting line options
60486    --
60487    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
60488            p_natural_side_code          => 'C'
60489          , p_gain_or_loss_flag          => 'Y'
60490          , p_gl_transfer_mode_code      => 'S'
60491          , p_acct_entry_type_code       => 'A'
60492          , p_switch_side_flag           => 'Y'
60493          , p_merge_duplicate_code       => 'A'
60494          );
60495    --
60496    l_acc_rev_natural_side_code := 'D';  -- 4262811
60497    -- 
60498    --
60499    -- set accounting line type info
60500    --
60501    xla_ae_lines_pkg.SetAcctLineType
60502       (p_component_type             => l_component_type
60506       ,p_accounting_line_code       => l_component_code
60503       ,p_event_type_code            => l_event_type_code
60504       ,p_line_definition_owner_code => l_line_definition_owner_code
60505       ,p_line_definition_code       => l_line_definition_code
60507       ,p_accounting_line_type_code  => l_component_type_code
60508       ,p_accounting_line_appl_id    => l_component_appl_id
60509       ,p_amb_context_code           => l_amb_context_code
60510       ,p_entity_code                => l_entity_code
60511       ,p_event_class_code           => l_event_class_code);
60512    --
60513    -- set accounting class
60514    --
60515    xla_ae_lines_pkg.SetAcctClass(
60516            p_accounting_class_code  => 'LOSS'
60517          , p_ae_header_id           => l_ae_header_id
60518          );
60519 
60520    --
60521    -- set rounding class
60522    --
60523    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
60524                       'RECEIVABLE';
60525 
60526    --
60527    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
60528    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
60529    --
60530    -- bulk performance
60531    --
60532    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
60533 
60534    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
60535       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
60536 
60537    -- 4955764
60538    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
60539       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
60540 
60541    -- 4458381 Public Sector Enh
60542    
60543    --
60544    -- set accounting attributes for the line type
60545    --
60546    l_entered_amt_idx := 8;
60547    l_accted_amt_idx  := 13;
60548    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
60549    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
60550    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
60551    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
60552    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
60553    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
60554    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
60555    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
60556    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
60557    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
60558    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
60559    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
60560    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
60561    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
60562    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
60563    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
60564    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
60565    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
60566    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
60567    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
60568    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
60569    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
60570    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
60571    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
60572    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
60573    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
60574    l_rec_acct_attrs.array_num_value(13)  := p_source_29;
60575    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
60576    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
60577    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
60578    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
60579    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
60580    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
60581 
60582    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
60583    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
60584 
60585    ---------------------------------------------------------------------------------------------------------------
60586    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
60587    ---------------------------------------------------------------------------------------------------------------
60588    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
60589 
60590    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
60591    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
60592 
60593    IF xla_accounting_cache_pkg.GetValueChar
60594          (p_source_code         => 'LEDGER_CATEGORY_CODE'
60595          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
60596    AND l_bflow_method_code = 'PRIOR_ENTRY'
60597 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
60598    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
60599          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
60600        )
60601    THEN
60602          xla_ae_lines_pkg.BflowUpgEntry
60606    ELSE
60603            (p_business_method_code    => l_bflow_method_code
60604            ,p_business_class_code     => l_bflow_class_code
60605            ,p_balance_type            => l_balance_type_code);
60607       NULL;
60608 -- No business flow processing for business flow method of NONE.
60609    END IF;
60610 
60611    --
60612    -- call analytical criteria
60613    --
60614    
60615    --
60616    -- call description
60617    --
60618    -- No description or it is inherited.
60619    --
60620    -- call ADRs
60621    -- Bug 4922099
60622    --
60623    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
60624         (NVL(l_actual_upg_option, 'N') = 'O') OR
60625         (NVL(l_enc_upg_option, 'N') = 'O')
60626       )
60627    THEN
60628    NULL;
60629    --
60630    --
60631    
60632   l_ccid := AcctDerRule_7(
60633            p_application_id           => p_application_id
60634          , p_ae_header_id             => l_ae_header_id 
60635 , p_source_3 => p_source_3
60636          , x_transaction_coa_id       => l_adr_transaction_coa_id
60637          , x_accounting_coa_id        => l_adr_accounting_coa_id
60638          , x_value_type_code          => l_adr_value_type_code
60639          , p_side                     => 'NA'
60640    );
60641 
60642    xla_ae_lines_pkg.set_ccid(
60643     p_code_combination_id          => l_ccid
60644   , p_value_type_code              => l_adr_value_type_code
60645   , p_transaction_coa_id           => l_adr_transaction_coa_id
60646   , p_accounting_coa_id            => l_adr_accounting_coa_id
60647   , p_adr_code                     => 'DIST_CCID'
60648   , p_adr_type_code                => 'S'
60649   , p_component_type               => l_component_type
60650   , p_component_code               => l_component_code
60651   , p_component_type_code          => l_component_type_code
60652   , p_component_appl_id            => l_component_appl_id
60653   , p_amb_context_code             => l_amb_context_code
60654   , p_side                         => 'NA'
60655   );
60656 
60657 
60658    --
60659    --
60660    END IF;
60661    --
60662    -- Bug 4922099
60663    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
60664           (NVL(l_enc_upg_option, 'N') = 'O')
60665         ) AND
60666         (l_bflow_method_code = 'PRIOR_ENTRY')
60667       )
60668    THEN
60669       IF
60670       --
60671       1 = 2
60672       --
60673       THEN
60674       xla_accounting_err_pkg.build_message
60675                                     (p_appli_s_name            => 'XLA'
60676                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
60677                                     ,p_token_1                 => 'LINE_NUMBER'
60678                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
60679                                     ,p_token_2                 => 'LINE_TYPE_NAME'
60680                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
60681                                                                              l_component_type
60682                                                                             ,l_component_code
60683                                                                             ,l_component_type_code
60684                                                                             ,l_component_appl_id
60685                                                                             ,l_amb_context_code
60686                                                                             ,l_entity_code
60687                                                                             ,l_event_class_code
60688                                                                            )
60689                                     ,p_token_3                 => 'OWNER'
60690                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
60691                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
60692                                                                           ,p_lookup_code    => l_component_type_code
60693                                                                          )
60694                                     ,p_token_4                 => 'PRODUCT_NAME'
60695                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
60696                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
60697                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
60698                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
60699                                     ,p_ae_header_id            =>  NULL
60700                                        );
60701 
60702         IF (C_LEVEL_ERROR>= g_log_level) THEN
60703                  trace
60704                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
60705                       ,p_level    => C_LEVEL_ERROR
60706                       ,p_module   => l_log_module);
60707         END IF;
60708       END IF;
60709    END IF;
60710    --
60711    --
60712    ------------------------------------------------------------------------------------------------
60713    -- 4219869 Business Flow
60714    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
60718 
60715    -- Prior Entry.  Currently, the following code is always generated.
60716    ------------------------------------------------------------------------------------------------
60717    XLA_AE_LINES_PKG.ValidateCurrentLine;
60719    ------------------------------------------------------------------------------------
60720    -- 4219869 Business Flow
60721    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
60722    ------------------------------------------------------------------------------------
60723    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
60724 
60725    ----------------------------------------------------------------------------------
60726    -- 4219869 Business Flow
60727    -- Update journal entry status -- Need to generate this within IF <condition>
60728    ----------------------------------------------------------------------------------
60729    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
60730          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
60731          ,p_balance_type_code => l_balance_type_code
60732          );
60733 
60734    -------------------------------------------------------------------------------------------
60735    -- 4262811 - Generate the Accrual Reversal lines
60736    -------------------------------------------------------------------------------------------
60737    BEGIN
60738       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
60739                               (g_array_event(p_event_id).array_value_num('header_index'));
60740       IF l_acc_rev_flag IS NULL THEN
60741          l_acc_rev_flag := 'N';
60742       END IF;
60743    EXCEPTION
60744       WHEN OTHERS THEN
60745          l_acc_rev_flag := 'N';
60746    END;
60747    --
60748    IF (l_acc_rev_flag = 'Y') THEN
60749 
60750        -- 4645092  ------------------------------------------------------------------------------
60751        -- To allow MPA report to determine if it should generate report process
60752        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
60753        ------------------------------------------------------------------------------------------
60754 
60755        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
60756        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
60757    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
60758    -- call ADRs
60759    -- Bug 4922099
60760    --
60761    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
60762         (NVL(l_actual_upg_option, 'N') = 'O') OR
60763         (NVL(l_enc_upg_option, 'N') = 'O')
60764       )
60765    THEN
60766    NULL;
60767    --
60768    --
60769    
60770   l_ccid := AcctDerRule_7(
60771            p_application_id           => p_application_id
60772          , p_ae_header_id             => l_ae_header_id 
60773 , p_source_3 => p_source_3
60774          , x_transaction_coa_id       => l_adr_transaction_coa_id
60775          , x_accounting_coa_id        => l_adr_accounting_coa_id
60776          , x_value_type_code          => l_adr_value_type_code
60777          , p_side                     => 'NA'
60778    );
60779 
60780    xla_ae_lines_pkg.set_ccid(
60781     p_code_combination_id          => l_ccid
60782   , p_value_type_code              => l_adr_value_type_code
60783   , p_transaction_coa_id           => l_adr_transaction_coa_id
60784   , p_accounting_coa_id            => l_adr_accounting_coa_id
60785   , p_adr_code                     => 'DIST_CCID'
60786   , p_adr_type_code                => 'S'
60787   , p_component_type               => l_component_type
60788   , p_component_code               => l_component_code
60789   , p_component_type_code          => l_component_type_code
60790   , p_component_appl_id            => l_component_appl_id
60791   , p_amb_context_code             => l_amb_context_code
60792   , p_side                         => 'NA'
60793   );
60794 
60795 
60796    --
60797    --
60798    END IF;
60799 
60800        --
60801        -- Update the line information that should be overwritten
60802        --
60803        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
60804                                          p_header_num   => 1);
60805        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
60806 
60807        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
60808 
60809        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
60810           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
60811        END IF;
60812 
60813       --
60814       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
60815       --
60816       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
60817           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
60818       ELSE
60819           ---------------------------------------------------------------------------------------------------
60820           -- 4262811a Switch Sign
60821           ---------------------------------------------------------------------------------------------------
60822           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
60823           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
60827           -- 5132302
60824                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
60825           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
60826                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
60828           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
60829                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
60830 
60831       END IF;
60832 
60833       -- 4955764
60834       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
60835       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
60836 
60837 
60838       XLA_AE_LINES_PKG.ValidateCurrentLine;
60839       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
60840 
60841       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
60842                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
60843                ,p_balance_type_code => l_balance_type_code);
60844 
60845    END IF;
60846 
60847    -----------------------------------------------------------------------------------------
60848    -- 4262811 Multiperiod Accounting
60849    -----------------------------------------------------------------------------------------
60850      -- No MPA option is assigned.
60851 
60852 
60853 END IF;
60854 END IF;
60855 --
60856 
60857 --
60858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
60859    trace
60860       (p_msg      => 'END of AcctLineType_122'
60861       ,p_level    => C_LEVEL_PROCEDURE
60862       ,p_module   => l_log_module);
60863 END IF;
60864 --
60865 EXCEPTION
60866   WHEN xla_exceptions_pkg.application_exception THEN
60867       RAISE;
60868   WHEN OTHERS THEN
60869        xla_exceptions_pkg.raise_message
60870            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_122');
60871 END AcctLineType_122;
60872 --
60873 
60874 ---------------------------------------
60875 --
60876 -- PRIVATE FUNCTION
60877 --         AcctLineType_123
60878 --
60879 ---------------------------------------
60880 PROCEDURE AcctLineType_123 (
60881   p_application_id        IN NUMBER
60882  ,p_event_id              IN NUMBER
60883  ,p_calculate_acctd_flag  IN VARCHAR2
60884  ,p_calculate_g_l_flag    IN VARCHAR2
60885  ,p_actual_flag           IN OUT VARCHAR2
60886  ,p_balance_type_code     OUT VARCHAR2
60887  ,p_gain_or_loss_ref      OUT VARCHAR2
60888  
60889 --Distribution GL Account
60890  , p_source_3            IN NUMBER
60891 --Distribution Source Type
60892  , p_source_20            IN VARCHAR2
60893 --Distribution Line Identifier
60894  , p_source_22            IN NUMBER
60895 --Distribution Type
60896  , p_source_23            IN VARCHAR2
60897 --Exchange Date
60898  , p_source_26            IN DATE
60899 --Exchange Rate
60900  , p_source_27            IN NUMBER
60901 --Exchange Rate Type
60902  , p_source_28            IN VARCHAR2
60903 --Transaction Distribution Identifier
60904  , p_source_34            IN NUMBER
60905 --Transaction Distribution Type
60906  , p_source_35            IN VARCHAR2
60907 --Receipt Applied To Application Identifier
60908  , p_source_58            IN NUMBER
60909 --Transaction Entity Code
60910  , p_source_59            IN VARCHAR2
60911 --Transaction Identifier
60912  , p_source_60            IN NUMBER
60913 --Applying Document Currency Code
60914  , p_source_61            IN VARCHAR2
60915 --Distribution Party Identifier
60916  , p_source_63            IN NUMBER
60917 --Distribution Party Site Id
60918  , p_source_64            IN NUMBER
60919 --Distribution Party Type
60920  , p_source_65            IN VARCHAR2
60921 --Distribution Multi Fund Additional Entry
60922  , p_source_69            IN VARCHAR2
60923 --DIST_ENT_AMT_FROM
60924  , p_source_72            IN NUMBER
60925 --Accounting Amount
60926  , p_source_73            IN NUMBER
60927 --Distribution Source Table
60928  , p_source_75            IN VARCHAR2
60929 )
60930 IS
60931 
60932 l_component_type              VARCHAR2(80);
60933 l_component_code              VARCHAR2(30);
60934 l_component_type_code         VARCHAR2(1);
60935 l_component_appl_id           INTEGER;
60936 l_amb_context_code            VARCHAR2(30);
60937 l_entity_code                 VARCHAR2(30);
60938 l_event_class_code            VARCHAR2(30);
60939 l_ae_header_id                NUMBER;
60940 l_event_type_code             VARCHAR2(30);
60941 l_line_definition_code        VARCHAR2(30);
60942 l_line_definition_owner_code  VARCHAR2(1);
60943 --
60944 -- adr variables
60945 l_segment                     VARCHAR2(30);
60946 l_ccid                        NUMBER;
60947 l_adr_transaction_coa_id      NUMBER;
60948 l_adr_accounting_coa_id       NUMBER;
60949 l_adr_flexfield_segment_code  VARCHAR2(30);
60950 l_adr_flex_value_set_id       NUMBER;
60951 l_adr_value_type_code         VARCHAR2(30);
60952 l_adr_value_combination_id    NUMBER;
60953 l_adr_value_segment_code      VARCHAR2(30);
60954 
60955 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
60956 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
60960 -- 4262811 Variables ------------------------------------------------------------------------------------------
60957 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
60958 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
60959 
60961 l_entered_amt_idx             NUMBER;
60962 l_accted_amt_idx              NUMBER;
60963 l_acc_rev_flag                VARCHAR2(1);
60964 l_accrual_line_num            NUMBER;
60965 l_tmp_amt                     NUMBER;
60966 l_acc_rev_natural_side_code   VARCHAR2(1);
60967 
60968 l_num_entries                 NUMBER;
60969 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
60970 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
60971 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
60972 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
60973 l_recog_line_1                NUMBER;
60974 l_recog_line_2                NUMBER;
60975 
60976 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
60977 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
60978 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
60979 
60980 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
60981 
60982 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
60983 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
60984 
60985 ---------------------------------------------------------------------------------------------------------------
60986 
60987 
60988 --
60989 -- bulk performance
60990 --
60991 l_balance_type_code           VARCHAR2(1);
60992 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
60993 l_log_module                  VARCHAR2(240);
60994 
60995 --
60996 -- Upgrade strategy
60997 --
60998 l_actual_upg_option           VARCHAR2(1);
60999 l_enc_upg_option           VARCHAR2(1);
61000 
61001 --
61002 BEGIN
61003 --
61004 IF g_log_enabled THEN
61005       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_123';
61006 END IF;
61007 --
61008 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
61009 
61010       trace
61011          (p_msg      => 'BEGIN of AcctLineType_123'
61012          ,p_level    => C_LEVEL_PROCEDURE
61013          ,p_module   => l_log_module);
61014 
61015 END IF;
61016 --
61017 l_component_type             := 'AMB_JLT';
61018 l_component_code             := 'RCT_FACTOR';
61019 l_component_type_code        := 'S';
61020 l_component_appl_id          :=  222;
61021 l_amb_context_code           := 'DEFAULT';
61022 l_entity_code                := 'RECEIPTS';
61023 l_event_class_code           := 'RECEIPT';
61024 l_event_type_code            := 'RECEIPT_ALL';
61025 l_line_definition_owner_code := 'S';
61026 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
61027 --
61028 l_balance_type_code          := 'A';
61029 l_segment                     := NULL;
61030 l_ccid                        := NULL;
61031 l_adr_transaction_coa_id      := NULL;
61032 l_adr_accounting_coa_id       := NULL;
61033 l_adr_flexfield_segment_code  := NULL;
61034 l_adr_flex_value_set_id       := NULL;
61035 l_adr_value_type_code         := NULL;
61036 l_adr_value_combination_id    := NULL;
61037 l_adr_value_segment_code      := NULL;
61038 
61039 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
61040 l_bflow_class_code           := '';    -- 4219869 Business Flow
61041 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
61042 l_budgetary_control_flag     := 'N';
61043 
61044 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
61045 l_bflow_applied_to_amt       := NULL; -- 5132302
61046 l_entered_amt_idx            := NULL;          -- 4262811
61047 l_accted_amt_idx             := NULL;          -- 4262811
61048 l_acc_rev_flag               := NULL;          -- 4262811
61049 l_accrual_line_num           := NULL;          -- 4262811
61050 l_tmp_amt                    := NULL;          -- 4262811
61051 --
61052  
61053 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
61054     l_balance_type_code <> 'B' THEN
61055 IF NVL(p_source_20,'
61056 ') =  'FACTOR' AND 
61057 NVL(p_source_75,'
61058 ') =  'CRH' AND 
61059 NVL(p_source_69,'
61060 ') =  'N'
61061  THEN 
61062 
61063    --
61064    XLA_AE_LINES_PKG.SetNewLine;
61065 
61066    p_balance_type_code          := l_balance_type_code;
61067    -- set the flag so later we will know whether the gain loss line needs to be created
61068    
61069    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
61070      p_actual_flag :='A';
61071    END IF;
61072 
61073    --
61074    -- bulk performance
61075    --
61076    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
61077                                       p_header_num   => 0); -- 4262811
61078    --
61079    -- set accounting line options
61080    --
61081    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
61082            p_natural_side_code          => 'C'
61083          , p_gain_or_loss_flag          => 'N'
61084          , p_gl_transfer_mode_code      => 'S'
61085          , p_acct_entry_type_code       => 'A'
61086          , p_switch_side_flag           => 'Y'
61087          , p_merge_duplicate_code       => 'A'
61088          );
61089    --
61093    -- set accounting line type info
61090    l_acc_rev_natural_side_code := 'D';  -- 4262811
61091    -- 
61092    --
61094    --
61095    xla_ae_lines_pkg.SetAcctLineType
61096       (p_component_type             => l_component_type
61097       ,p_event_type_code            => l_event_type_code
61098       ,p_line_definition_owner_code => l_line_definition_owner_code
61099       ,p_line_definition_code       => l_line_definition_code
61100       ,p_accounting_line_code       => l_component_code
61101       ,p_accounting_line_type_code  => l_component_type_code
61102       ,p_accounting_line_appl_id    => l_component_appl_id
61103       ,p_amb_context_code           => l_amb_context_code
61104       ,p_entity_code                => l_entity_code
61105       ,p_event_class_code           => l_event_class_code);
61106    --
61107    -- set accounting class
61108    --
61109    xla_ae_lines_pkg.SetAcctClass(
61110            p_accounting_class_code  => 'FACTOR'
61111          , p_ae_header_id           => l_ae_header_id
61112          );
61113 
61114    --
61115    -- set rounding class
61116    --
61117    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
61118                       'RECEIVABLE';
61119 
61120    --
61121    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
61122    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
61123    --
61124    -- bulk performance
61125    --
61126    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
61127 
61128    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
61129       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
61130 
61131    -- 4955764
61132    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
61133       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
61134 
61135    -- 4458381 Public Sector Enh
61136    
61137    --
61138    -- set accounting attributes for the line type
61139    --
61140    l_entered_amt_idx := 8;
61141    l_accted_amt_idx  := 13;
61142    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
61143    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
61144    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
61145    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
61146    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
61147    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
61148    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
61149    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
61150    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
61151    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
61152    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
61153    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
61154    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
61155    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
61156    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
61157    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
61158    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
61159    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
61160    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
61161    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
61162    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
61163    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
61164    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
61165    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
61166    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
61167    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
61168    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
61169    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
61170    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
61171    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
61172    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
61173    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
61174    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
61175 
61176    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
61177    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
61178 
61179    ---------------------------------------------------------------------------------------------------------------
61180    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
61181    ---------------------------------------------------------------------------------------------------------------
61182    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
61183 
61184    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
61185    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
61186 
61187    IF xla_accounting_cache_pkg.GetValueChar
61188          (p_source_code         => 'LEDGER_CATEGORY_CODE'
61189          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
61190    AND l_bflow_method_code = 'PRIOR_ENTRY'
61194        )
61191 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
61192    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
61193          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
61195    THEN
61196          xla_ae_lines_pkg.BflowUpgEntry
61197            (p_business_method_code    => l_bflow_method_code
61198            ,p_business_class_code     => l_bflow_class_code
61199            ,p_balance_type            => l_balance_type_code);
61200    ELSE
61201       NULL;
61202 -- No business flow processing for business flow method of NONE.
61203    END IF;
61204 
61205    --
61206    -- call analytical criteria
61207    --
61208    
61209    --
61210    -- call description
61211    --
61212    -- No description or it is inherited.
61213    --
61214    -- call ADRs
61215    -- Bug 4922099
61216    --
61217    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
61218         (NVL(l_actual_upg_option, 'N') = 'O') OR
61219         (NVL(l_enc_upg_option, 'N') = 'O')
61220       )
61221    THEN
61222    NULL;
61223    --
61224    --
61225    
61226   l_ccid := AcctDerRule_7(
61227            p_application_id           => p_application_id
61228          , p_ae_header_id             => l_ae_header_id 
61229 , p_source_3 => p_source_3
61230          , x_transaction_coa_id       => l_adr_transaction_coa_id
61231          , x_accounting_coa_id        => l_adr_accounting_coa_id
61232          , x_value_type_code          => l_adr_value_type_code
61233          , p_side                     => 'NA'
61234    );
61235 
61236    xla_ae_lines_pkg.set_ccid(
61237     p_code_combination_id          => l_ccid
61238   , p_value_type_code              => l_adr_value_type_code
61239   , p_transaction_coa_id           => l_adr_transaction_coa_id
61240   , p_accounting_coa_id            => l_adr_accounting_coa_id
61241   , p_adr_code                     => 'DIST_CCID'
61242   , p_adr_type_code                => 'S'
61243   , p_component_type               => l_component_type
61244   , p_component_code               => l_component_code
61245   , p_component_type_code          => l_component_type_code
61246   , p_component_appl_id            => l_component_appl_id
61247   , p_amb_context_code             => l_amb_context_code
61248   , p_side                         => 'NA'
61249   );
61250 
61251 
61252    --
61253    --
61254    END IF;
61255    --
61256    -- Bug 4922099
61257    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
61258           (NVL(l_enc_upg_option, 'N') = 'O')
61259         ) AND
61260         (l_bflow_method_code = 'PRIOR_ENTRY')
61261       )
61262    THEN
61263       IF
61264       --
61265       1 = 2
61266       --
61267       THEN
61268       xla_accounting_err_pkg.build_message
61269                                     (p_appli_s_name            => 'XLA'
61270                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
61271                                     ,p_token_1                 => 'LINE_NUMBER'
61272                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
61273                                     ,p_token_2                 => 'LINE_TYPE_NAME'
61274                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
61275                                                                              l_component_type
61276                                                                             ,l_component_code
61277                                                                             ,l_component_type_code
61278                                                                             ,l_component_appl_id
61279                                                                             ,l_amb_context_code
61280                                                                             ,l_entity_code
61281                                                                             ,l_event_class_code
61282                                                                            )
61283                                     ,p_token_3                 => 'OWNER'
61284                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
61285                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
61286                                                                           ,p_lookup_code    => l_component_type_code
61287                                                                          )
61288                                     ,p_token_4                 => 'PRODUCT_NAME'
61289                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
61290                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
61291                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
61292                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
61293                                     ,p_ae_header_id            =>  NULL
61294                                        );
61295 
61296         IF (C_LEVEL_ERROR>= g_log_level) THEN
61297                  trace
61298                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
61299                       ,p_level    => C_LEVEL_ERROR
61300                       ,p_module   => l_log_module);
61301         END IF;
61302       END IF;
61306    ------------------------------------------------------------------------------------------------
61303    END IF;
61304    --
61305    --
61307    -- 4219869 Business Flow
61308    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
61309    -- Prior Entry.  Currently, the following code is always generated.
61310    ------------------------------------------------------------------------------------------------
61311    XLA_AE_LINES_PKG.ValidateCurrentLine;
61312 
61313    ------------------------------------------------------------------------------------
61314    -- 4219869 Business Flow
61315    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
61316    ------------------------------------------------------------------------------------
61317    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
61318 
61319    ----------------------------------------------------------------------------------
61320    -- 4219869 Business Flow
61321    -- Update journal entry status -- Need to generate this within IF <condition>
61322    ----------------------------------------------------------------------------------
61323    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
61324          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
61325          ,p_balance_type_code => l_balance_type_code
61326          );
61327 
61328    -------------------------------------------------------------------------------------------
61329    -- 4262811 - Generate the Accrual Reversal lines
61330    -------------------------------------------------------------------------------------------
61331    BEGIN
61332       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
61333                               (g_array_event(p_event_id).array_value_num('header_index'));
61334       IF l_acc_rev_flag IS NULL THEN
61335          l_acc_rev_flag := 'N';
61336       END IF;
61337    EXCEPTION
61338       WHEN OTHERS THEN
61339          l_acc_rev_flag := 'N';
61340    END;
61341    --
61342    IF (l_acc_rev_flag = 'Y') THEN
61343 
61344        -- 4645092  ------------------------------------------------------------------------------
61345        -- To allow MPA report to determine if it should generate report process
61346        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
61347        ------------------------------------------------------------------------------------------
61348 
61349        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
61350        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
61351    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
61352    -- call ADRs
61353    -- Bug 4922099
61354    --
61355    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
61356         (NVL(l_actual_upg_option, 'N') = 'O') OR
61357         (NVL(l_enc_upg_option, 'N') = 'O')
61358       )
61359    THEN
61360    NULL;
61361    --
61362    --
61363    
61364   l_ccid := AcctDerRule_7(
61365            p_application_id           => p_application_id
61366          , p_ae_header_id             => l_ae_header_id 
61367 , p_source_3 => p_source_3
61368          , x_transaction_coa_id       => l_adr_transaction_coa_id
61369          , x_accounting_coa_id        => l_adr_accounting_coa_id
61370          , x_value_type_code          => l_adr_value_type_code
61371          , p_side                     => 'NA'
61372    );
61373 
61374    xla_ae_lines_pkg.set_ccid(
61375     p_code_combination_id          => l_ccid
61376   , p_value_type_code              => l_adr_value_type_code
61377   , p_transaction_coa_id           => l_adr_transaction_coa_id
61378   , p_accounting_coa_id            => l_adr_accounting_coa_id
61379   , p_adr_code                     => 'DIST_CCID'
61380   , p_adr_type_code                => 'S'
61381   , p_component_type               => l_component_type
61382   , p_component_code               => l_component_code
61383   , p_component_type_code          => l_component_type_code
61384   , p_component_appl_id            => l_component_appl_id
61385   , p_amb_context_code             => l_amb_context_code
61386   , p_side                         => 'NA'
61387   );
61388 
61389 
61390    --
61391    --
61392    END IF;
61393 
61394        --
61395        -- Update the line information that should be overwritten
61396        --
61397        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
61398                                          p_header_num   => 1);
61399        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
61400 
61401        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
61402 
61403        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
61404           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
61405        END IF;
61406 
61407       --
61408       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
61409       --
61410       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
61411           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
61412       ELSE
61413           ---------------------------------------------------------------------------------------------------
61414           -- 4262811a Switch Sign
61418                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
61415           ---------------------------------------------------------------------------------------------------
61416           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
61417           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
61419           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
61420                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
61421           -- 5132302
61422           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
61423                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
61424 
61425       END IF;
61426 
61427       -- 4955764
61428       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
61429       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
61430 
61431 
61432       XLA_AE_LINES_PKG.ValidateCurrentLine;
61433       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
61434 
61435       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
61436                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
61437                ,p_balance_type_code => l_balance_type_code);
61438 
61439    END IF;
61440 
61441    -----------------------------------------------------------------------------------------
61442    -- 4262811 Multiperiod Accounting
61443    -----------------------------------------------------------------------------------------
61444      -- No MPA option is assigned.
61445 
61446 
61447 END IF;
61448 END IF;
61449 --
61450 
61451 --
61452 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
61453    trace
61454       (p_msg      => 'END of AcctLineType_123'
61455       ,p_level    => C_LEVEL_PROCEDURE
61456       ,p_module   => l_log_module);
61457 END IF;
61458 --
61459 EXCEPTION
61460   WHEN xla_exceptions_pkg.application_exception THEN
61461       RAISE;
61462   WHEN OTHERS THEN
61463        xla_exceptions_pkg.raise_message
61464            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_123');
61465 END AcctLineType_123;
61466 --
61467 
61468 ---------------------------------------
61469 --
61470 -- PRIVATE FUNCTION
61471 --         AcctLineType_124
61472 --
61473 ---------------------------------------
61474 PROCEDURE AcctLineType_124 (
61475   p_application_id        IN NUMBER
61476  ,p_event_id              IN NUMBER
61477  ,p_calculate_acctd_flag  IN VARCHAR2
61478  ,p_calculate_g_l_flag    IN VARCHAR2
61479  ,p_actual_flag           IN OUT VARCHAR2
61480  ,p_balance_type_code     OUT VARCHAR2
61481  ,p_gain_or_loss_ref      OUT VARCHAR2
61482  
61483 --Distribution GL Account
61484  , p_source_3            IN NUMBER
61485 --Distribution Source Type
61486  , p_source_20            IN VARCHAR2
61487 --Distribution Line Identifier
61488  , p_source_22            IN NUMBER
61489 --Distribution Type
61490  , p_source_23            IN VARCHAR2
61491 --Exchange Date
61492  , p_source_26            IN DATE
61493 --Exchange Rate
61494  , p_source_27            IN NUMBER
61495 --Exchange Rate Type
61496  , p_source_28            IN VARCHAR2
61497 --Transaction Distribution Identifier
61498  , p_source_34            IN NUMBER
61499 --Transaction Distribution Type
61500  , p_source_35            IN VARCHAR2
61501 --Receipt Applied To Application Identifier
61502  , p_source_58            IN NUMBER
61503 --Transaction Entity Code
61504  , p_source_59            IN VARCHAR2
61505 --Transaction Identifier
61506  , p_source_60            IN NUMBER
61507 --Applying Document Currency Code
61508  , p_source_61            IN VARCHAR2
61509 --Distribution Party Identifier
61510  , p_source_63            IN NUMBER
61511 --Distribution Party Site Id
61512  , p_source_64            IN NUMBER
61513 --Distribution Party Type
61514  , p_source_65            IN VARCHAR2
61515 --Distribution Multi Fund Additional Entry
61516  , p_source_69            IN VARCHAR2
61517 --DIST_ENT_AMT_FROM
61518  , p_source_72            IN NUMBER
61519 --Accounting Amount
61520  , p_source_73            IN NUMBER
61521 --Distribution Source Table
61522  , p_source_75            IN VARCHAR2
61523 )
61524 IS
61525 
61526 l_component_type              VARCHAR2(80);
61527 l_component_code              VARCHAR2(30);
61528 l_component_type_code         VARCHAR2(1);
61529 l_component_appl_id           INTEGER;
61530 l_amb_context_code            VARCHAR2(30);
61531 l_entity_code                 VARCHAR2(30);
61532 l_event_class_code            VARCHAR2(30);
61533 l_ae_header_id                NUMBER;
61534 l_event_type_code             VARCHAR2(30);
61535 l_line_definition_code        VARCHAR2(30);
61536 l_line_definition_owner_code  VARCHAR2(1);
61537 --
61538 -- adr variables
61539 l_segment                     VARCHAR2(30);
61540 l_ccid                        NUMBER;
61541 l_adr_transaction_coa_id      NUMBER;
61542 l_adr_accounting_coa_id       NUMBER;
61543 l_adr_flexfield_segment_code  VARCHAR2(30);
61544 l_adr_flex_value_set_id       NUMBER;
61545 l_adr_value_type_code         VARCHAR2(30);
61549 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
61546 l_adr_value_combination_id    NUMBER;
61547 l_adr_value_segment_code      VARCHAR2(30);
61548 
61550 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
61551 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
61552 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
61553 
61554 -- 4262811 Variables ------------------------------------------------------------------------------------------
61555 l_entered_amt_idx             NUMBER;
61556 l_accted_amt_idx              NUMBER;
61557 l_acc_rev_flag                VARCHAR2(1);
61558 l_accrual_line_num            NUMBER;
61559 l_tmp_amt                     NUMBER;
61560 l_acc_rev_natural_side_code   VARCHAR2(1);
61561 
61562 l_num_entries                 NUMBER;
61563 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
61564 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
61565 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
61566 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
61567 l_recog_line_1                NUMBER;
61568 l_recog_line_2                NUMBER;
61569 
61570 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
61571 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
61572 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
61573 
61574 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
61575 
61576 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
61577 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
61578 
61579 ---------------------------------------------------------------------------------------------------------------
61580 
61581 
61582 --
61583 -- bulk performance
61584 --
61585 l_balance_type_code           VARCHAR2(1);
61586 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
61587 l_log_module                  VARCHAR2(240);
61588 
61589 --
61590 -- Upgrade strategy
61591 --
61592 l_actual_upg_option           VARCHAR2(1);
61593 l_enc_upg_option           VARCHAR2(1);
61594 
61595 --
61596 BEGIN
61597 --
61598 IF g_log_enabled THEN
61599       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_124';
61600 END IF;
61601 --
61602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
61603 
61604       trace
61605          (p_msg      => 'BEGIN of AcctLineType_124'
61606          ,p_level    => C_LEVEL_PROCEDURE
61607          ,p_module   => l_log_module);
61608 
61609 END IF;
61610 --
61611 l_component_type             := 'AMB_JLT';
61612 l_component_code             := 'RCT_FACTOR_BR';
61613 l_component_type_code        := 'S';
61614 l_component_appl_id          :=  222;
61615 l_amb_context_code           := 'DEFAULT';
61616 l_entity_code                := 'RECEIPTS';
61617 l_event_class_code           := 'RECEIPT';
61618 l_event_type_code            := 'RECEIPT_ALL';
61619 l_line_definition_owner_code := 'S';
61620 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
61621 --
61622 l_balance_type_code          := 'A';
61623 l_segment                     := NULL;
61624 l_ccid                        := NULL;
61625 l_adr_transaction_coa_id      := NULL;
61626 l_adr_accounting_coa_id       := NULL;
61627 l_adr_flexfield_segment_code  := NULL;
61628 l_adr_flex_value_set_id       := NULL;
61629 l_adr_value_type_code         := NULL;
61630 l_adr_value_combination_id    := NULL;
61631 l_adr_value_segment_code      := NULL;
61632 
61633 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
61634 l_bflow_class_code           := '';    -- 4219869 Business Flow
61635 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
61636 l_budgetary_control_flag     := 'N';
61637 
61638 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
61639 l_bflow_applied_to_amt       := NULL; -- 5132302
61640 l_entered_amt_idx            := NULL;          -- 4262811
61641 l_accted_amt_idx             := NULL;          -- 4262811
61642 l_acc_rev_flag               := NULL;          -- 4262811
61643 l_accrual_line_num           := NULL;          -- 4262811
61644 l_tmp_amt                    := NULL;          -- 4262811
61645 --
61646  
61647 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
61648     l_balance_type_code <> 'B' THEN
61649 IF NVL(p_source_20,'
61650 ') =  'FACTOR' AND 
61651 NVL(p_source_75,'
61652 ') =  'RA' AND 
61653 NVL(p_source_69,'
61654 ') =  'N'
61655  THEN 
61656 
61657    --
61658    XLA_AE_LINES_PKG.SetNewLine;
61659 
61660    p_balance_type_code          := l_balance_type_code;
61661    -- set the flag so later we will know whether the gain loss line needs to be created
61662    
61663    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
61664      p_actual_flag :='A';
61665    END IF;
61666 
61667    --
61668    -- bulk performance
61669    --
61670    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
61671                                       p_header_num   => 0); -- 4262811
61672    --
61673    -- set accounting line options
61674    --
61675    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
61676            p_natural_side_code          => 'C'
61677          , p_gain_or_loss_flag          => 'N'
61678          , p_gl_transfer_mode_code      => 'S'
61682          );
61679          , p_acct_entry_type_code       => 'A'
61680          , p_switch_side_flag           => 'Y'
61681          , p_merge_duplicate_code       => 'A'
61683    --
61684    l_acc_rev_natural_side_code := 'D';  -- 4262811
61685    -- 
61686    --
61687    -- set accounting line type info
61688    --
61689    xla_ae_lines_pkg.SetAcctLineType
61690       (p_component_type             => l_component_type
61691       ,p_event_type_code            => l_event_type_code
61692       ,p_line_definition_owner_code => l_line_definition_owner_code
61693       ,p_line_definition_code       => l_line_definition_code
61694       ,p_accounting_line_code       => l_component_code
61695       ,p_accounting_line_type_code  => l_component_type_code
61696       ,p_accounting_line_appl_id    => l_component_appl_id
61697       ,p_amb_context_code           => l_amb_context_code
61698       ,p_entity_code                => l_entity_code
61699       ,p_event_class_code           => l_event_class_code);
61700    --
61701    -- set accounting class
61702    --
61703    xla_ae_lines_pkg.SetAcctClass(
61704            p_accounting_class_code  => 'FAC_BR'
61705          , p_ae_header_id           => l_ae_header_id
61706          );
61707 
61708    --
61709    -- set rounding class
61710    --
61711    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
61712                       'RECEIVABLE';
61713 
61714    --
61715    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
61716    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
61717    --
61718    -- bulk performance
61719    --
61720    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
61721 
61722    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
61723       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
61724 
61725    -- 4955764
61726    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
61727       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
61728 
61729    -- 4458381 Public Sector Enh
61730    
61731    --
61732    -- set accounting attributes for the line type
61733    --
61734    l_entered_amt_idx := 8;
61735    l_accted_amt_idx  := 13;
61736    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
61737    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
61738    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
61739    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
61740    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
61741    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
61742    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
61743    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
61744    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
61745    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
61746    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
61747    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
61748    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
61749    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
61750    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
61751    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
61752    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
61753    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
61754    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
61755    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
61756    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
61757    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
61758    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
61759    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
61760    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
61761    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
61762    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
61763    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
61764    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
61765    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
61766    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
61767    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
61768    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
61769 
61770    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
61771    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
61772 
61773    ---------------------------------------------------------------------------------------------------------------
61774    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
61775    ---------------------------------------------------------------------------------------------------------------
61776    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
61777 
61778    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
61779    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
61780 
61784    AND l_bflow_method_code = 'PRIOR_ENTRY'
61781    IF xla_accounting_cache_pkg.GetValueChar
61782          (p_source_code         => 'LEDGER_CATEGORY_CODE'
61783          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
61785 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
61786    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
61787          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
61788        )
61789    THEN
61790          xla_ae_lines_pkg.BflowUpgEntry
61791            (p_business_method_code    => l_bflow_method_code
61792            ,p_business_class_code     => l_bflow_class_code
61793            ,p_balance_type            => l_balance_type_code);
61794    ELSE
61795       NULL;
61796 -- No business flow processing for business flow method of NONE.
61797    END IF;
61798 
61799    --
61800    -- call analytical criteria
61801    --
61802    
61803    --
61804    -- call description
61805    --
61806    -- No description or it is inherited.
61807    --
61808    -- call ADRs
61809    -- Bug 4922099
61810    --
61811    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
61812         (NVL(l_actual_upg_option, 'N') = 'O') OR
61813         (NVL(l_enc_upg_option, 'N') = 'O')
61814       )
61815    THEN
61816    NULL;
61817    --
61818    --
61819    
61820   l_ccid := AcctDerRule_7(
61821            p_application_id           => p_application_id
61822          , p_ae_header_id             => l_ae_header_id 
61823 , p_source_3 => p_source_3
61824          , x_transaction_coa_id       => l_adr_transaction_coa_id
61825          , x_accounting_coa_id        => l_adr_accounting_coa_id
61826          , x_value_type_code          => l_adr_value_type_code
61827          , p_side                     => 'NA'
61828    );
61829 
61830    xla_ae_lines_pkg.set_ccid(
61831     p_code_combination_id          => l_ccid
61832   , p_value_type_code              => l_adr_value_type_code
61833   , p_transaction_coa_id           => l_adr_transaction_coa_id
61834   , p_accounting_coa_id            => l_adr_accounting_coa_id
61835   , p_adr_code                     => 'DIST_CCID'
61836   , p_adr_type_code                => 'S'
61837   , p_component_type               => l_component_type
61838   , p_component_code               => l_component_code
61839   , p_component_type_code          => l_component_type_code
61840   , p_component_appl_id            => l_component_appl_id
61841   , p_amb_context_code             => l_amb_context_code
61842   , p_side                         => 'NA'
61843   );
61844 
61845 
61846    --
61847    --
61848    END IF;
61849    --
61850    -- Bug 4922099
61851    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
61852           (NVL(l_enc_upg_option, 'N') = 'O')
61853         ) AND
61854         (l_bflow_method_code = 'PRIOR_ENTRY')
61855       )
61856    THEN
61857       IF
61858       --
61859       1 = 2
61860       --
61861       THEN
61862       xla_accounting_err_pkg.build_message
61863                                     (p_appli_s_name            => 'XLA'
61864                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
61865                                     ,p_token_1                 => 'LINE_NUMBER'
61866                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
61867                                     ,p_token_2                 => 'LINE_TYPE_NAME'
61868                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
61869                                                                              l_component_type
61870                                                                             ,l_component_code
61871                                                                             ,l_component_type_code
61872                                                                             ,l_component_appl_id
61873                                                                             ,l_amb_context_code
61874                                                                             ,l_entity_code
61875                                                                             ,l_event_class_code
61876                                                                            )
61877                                     ,p_token_3                 => 'OWNER'
61878                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
61879                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
61880                                                                           ,p_lookup_code    => l_component_type_code
61881                                                                          )
61882                                     ,p_token_4                 => 'PRODUCT_NAME'
61883                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
61884                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
61885                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
61886                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
61887                                     ,p_ae_header_id            =>  NULL
61888                                        );
61889 
61893                       ,p_level    => C_LEVEL_ERROR
61890         IF (C_LEVEL_ERROR>= g_log_level) THEN
61891                  trace
61892                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
61894                       ,p_module   => l_log_module);
61895         END IF;
61896       END IF;
61897    END IF;
61898    --
61899    --
61900    ------------------------------------------------------------------------------------------------
61901    -- 4219869 Business Flow
61902    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
61903    -- Prior Entry.  Currently, the following code is always generated.
61904    ------------------------------------------------------------------------------------------------
61905    XLA_AE_LINES_PKG.ValidateCurrentLine;
61906 
61907    ------------------------------------------------------------------------------------
61908    -- 4219869 Business Flow
61909    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
61910    ------------------------------------------------------------------------------------
61911    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
61912 
61913    ----------------------------------------------------------------------------------
61914    -- 4219869 Business Flow
61915    -- Update journal entry status -- Need to generate this within IF <condition>
61916    ----------------------------------------------------------------------------------
61917    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
61918          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
61919          ,p_balance_type_code => l_balance_type_code
61920          );
61921 
61922    -------------------------------------------------------------------------------------------
61923    -- 4262811 - Generate the Accrual Reversal lines
61924    -------------------------------------------------------------------------------------------
61925    BEGIN
61926       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
61927                               (g_array_event(p_event_id).array_value_num('header_index'));
61928       IF l_acc_rev_flag IS NULL THEN
61929          l_acc_rev_flag := 'N';
61930       END IF;
61931    EXCEPTION
61932       WHEN OTHERS THEN
61933          l_acc_rev_flag := 'N';
61934    END;
61935    --
61936    IF (l_acc_rev_flag = 'Y') THEN
61937 
61938        -- 4645092  ------------------------------------------------------------------------------
61939        -- To allow MPA report to determine if it should generate report process
61940        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
61941        ------------------------------------------------------------------------------------------
61942 
61943        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
61944        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
61945    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
61946    -- call ADRs
61947    -- Bug 4922099
61948    --
61949    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
61950         (NVL(l_actual_upg_option, 'N') = 'O') OR
61951         (NVL(l_enc_upg_option, 'N') = 'O')
61952       )
61953    THEN
61954    NULL;
61955    --
61956    --
61957    
61958   l_ccid := AcctDerRule_7(
61959            p_application_id           => p_application_id
61960          , p_ae_header_id             => l_ae_header_id 
61961 , p_source_3 => p_source_3
61962          , x_transaction_coa_id       => l_adr_transaction_coa_id
61963          , x_accounting_coa_id        => l_adr_accounting_coa_id
61964          , x_value_type_code          => l_adr_value_type_code
61965          , p_side                     => 'NA'
61966    );
61967 
61968    xla_ae_lines_pkg.set_ccid(
61969     p_code_combination_id          => l_ccid
61970   , p_value_type_code              => l_adr_value_type_code
61971   , p_transaction_coa_id           => l_adr_transaction_coa_id
61972   , p_accounting_coa_id            => l_adr_accounting_coa_id
61973   , p_adr_code                     => 'DIST_CCID'
61974   , p_adr_type_code                => 'S'
61975   , p_component_type               => l_component_type
61976   , p_component_code               => l_component_code
61977   , p_component_type_code          => l_component_type_code
61978   , p_component_appl_id            => l_component_appl_id
61979   , p_amb_context_code             => l_amb_context_code
61980   , p_side                         => 'NA'
61981   );
61982 
61983 
61984    --
61985    --
61986    END IF;
61987 
61988        --
61989        -- Update the line information that should be overwritten
61990        --
61991        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
61992                                          p_header_num   => 1);
61993        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
61994 
61995        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
61996 
61997        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
61998           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
61999        END IF;
62000 
62001       --
62002       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
62003       --
62007           ---------------------------------------------------------------------------------------------------
62004       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
62005           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
62006       ELSE
62008           -- 4262811a Switch Sign
62009           ---------------------------------------------------------------------------------------------------
62010           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
62011           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
62012                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
62013           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
62014                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
62015           -- 5132302
62016           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
62017                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
62018 
62019       END IF;
62020 
62021       -- 4955764
62022       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
62023       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
62024 
62025 
62026       XLA_AE_LINES_PKG.ValidateCurrentLine;
62027       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
62028 
62029       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
62030                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
62031                ,p_balance_type_code => l_balance_type_code);
62032 
62033    END IF;
62034 
62035    -----------------------------------------------------------------------------------------
62036    -- 4262811 Multiperiod Accounting
62037    -----------------------------------------------------------------------------------------
62038      -- No MPA option is assigned.
62039 
62040 
62041 END IF;
62042 END IF;
62043 --
62044 
62045 --
62046 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
62047    trace
62048       (p_msg      => 'END of AcctLineType_124'
62049       ,p_level    => C_LEVEL_PROCEDURE
62050       ,p_module   => l_log_module);
62051 END IF;
62052 --
62053 EXCEPTION
62054   WHEN xla_exceptions_pkg.application_exception THEN
62055       RAISE;
62056   WHEN OTHERS THEN
62057        xla_exceptions_pkg.raise_message
62058            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_124');
62059 END AcctLineType_124;
62060 --
62061 
62062 ---------------------------------------
62063 --
62064 -- PRIVATE FUNCTION
62065 --         AcctLineType_125
62066 --
62067 ---------------------------------------
62068 PROCEDURE AcctLineType_125 (
62069   p_application_id        IN NUMBER
62070  ,p_event_id              IN NUMBER
62071  ,p_calculate_acctd_flag  IN VARCHAR2
62072  ,p_calculate_g_l_flag    IN VARCHAR2
62073  ,p_actual_flag           IN OUT VARCHAR2
62074  ,p_balance_type_code     OUT VARCHAR2
62075  ,p_gain_or_loss_ref      OUT VARCHAR2
62076  
62077 --Distribution GL Account
62078  , p_source_3            IN NUMBER
62079 --Distribution Source Type
62080  , p_source_20            IN VARCHAR2
62081 --Receivable Activity Type
62082  , p_source_21            IN VARCHAR2
62083 --Distribution Line Identifier
62084  , p_source_22            IN NUMBER
62085 --Distribution Type
62086  , p_source_23            IN VARCHAR2
62087 --Exchange Date
62088  , p_source_26            IN DATE
62089 --Exchange Rate
62090  , p_source_27            IN NUMBER
62091 --Exchange Rate Type
62092  , p_source_28            IN VARCHAR2
62093 --Applied To Document Accounting Amount
62094  , p_source_29            IN NUMBER
62095 --Transaction Distribution Identifier
62096  , p_source_34            IN NUMBER
62097 --Transaction Distribution Type
62098  , p_source_35            IN VARCHAR2
62099 --Receipt Applied To Application Identifier
62100  , p_source_58            IN NUMBER
62101 --Transaction Entity Code
62102  , p_source_59            IN VARCHAR2
62103 --Transaction Identifier
62104  , p_source_60            IN NUMBER
62105 --Applying Document Currency Code
62106  , p_source_61            IN VARCHAR2
62107 --Distribution Party Identifier
62108  , p_source_63            IN NUMBER
62109 --Distribution Party Site Id
62110  , p_source_64            IN NUMBER
62111 --Distribution Party Type
62112  , p_source_65            IN VARCHAR2
62113 --Distribution Multi Fund Additional Entry
62114  , p_source_69            IN VARCHAR2
62115 --DIST_ENT_AMT_FROM
62116  , p_source_72            IN NUMBER
62117 )
62118 IS
62119 
62120 l_component_type              VARCHAR2(80);
62121 l_component_code              VARCHAR2(30);
62122 l_component_type_code         VARCHAR2(1);
62123 l_component_appl_id           INTEGER;
62124 l_amb_context_code            VARCHAR2(30);
62125 l_entity_code                 VARCHAR2(30);
62126 l_event_class_code            VARCHAR2(30);
62127 l_ae_header_id                NUMBER;
62128 l_event_type_code             VARCHAR2(30);
62129 l_line_definition_code        VARCHAR2(30);
62130 l_line_definition_owner_code  VARCHAR2(1);
62131 --
62132 -- adr variables
62136 l_adr_accounting_coa_id       NUMBER;
62133 l_segment                     VARCHAR2(30);
62134 l_ccid                        NUMBER;
62135 l_adr_transaction_coa_id      NUMBER;
62137 l_adr_flexfield_segment_code  VARCHAR2(30);
62138 l_adr_flex_value_set_id       NUMBER;
62139 l_adr_value_type_code         VARCHAR2(30);
62140 l_adr_value_combination_id    NUMBER;
62141 l_adr_value_segment_code      VARCHAR2(30);
62142 
62143 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
62144 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
62145 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
62146 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
62147 
62148 -- 4262811 Variables ------------------------------------------------------------------------------------------
62149 l_entered_amt_idx             NUMBER;
62150 l_accted_amt_idx              NUMBER;
62151 l_acc_rev_flag                VARCHAR2(1);
62152 l_accrual_line_num            NUMBER;
62153 l_tmp_amt                     NUMBER;
62154 l_acc_rev_natural_side_code   VARCHAR2(1);
62155 
62156 l_num_entries                 NUMBER;
62157 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
62158 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
62159 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
62160 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
62161 l_recog_line_1                NUMBER;
62162 l_recog_line_2                NUMBER;
62163 
62164 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
62165 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
62166 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
62167 
62168 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
62169 
62170 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
62171 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
62172 
62173 ---------------------------------------------------------------------------------------------------------------
62174 
62175 
62176 --
62177 -- bulk performance
62178 --
62179 l_balance_type_code           VARCHAR2(1);
62180 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
62181 l_log_module                  VARCHAR2(240);
62182 
62183 --
62184 -- Upgrade strategy
62185 --
62186 l_actual_upg_option           VARCHAR2(1);
62187 l_enc_upg_option           VARCHAR2(1);
62188 
62189 --
62190 BEGIN
62191 --
62192 IF g_log_enabled THEN
62193       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_125';
62194 END IF;
62195 --
62196 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
62197 
62198       trace
62199          (p_msg      => 'BEGIN of AcctLineType_125'
62200          ,p_level    => C_LEVEL_PROCEDURE
62201          ,p_module   => l_log_module);
62202 
62203 END IF;
62204 --
62205 l_component_type             := 'AMB_JLT';
62206 l_component_code             := 'RCT_PMT_NET';
62207 l_component_type_code        := 'S';
62208 l_component_appl_id          :=  222;
62209 l_amb_context_code           := 'DEFAULT';
62210 l_entity_code                := 'RECEIPTS';
62211 l_event_class_code           := 'RECEIPT';
62212 l_event_type_code            := 'RECEIPT_ALL';
62213 l_line_definition_owner_code := 'S';
62214 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
62215 --
62216 l_balance_type_code          := 'A';
62217 l_segment                     := NULL;
62218 l_ccid                        := NULL;
62219 l_adr_transaction_coa_id      := NULL;
62220 l_adr_accounting_coa_id       := NULL;
62221 l_adr_flexfield_segment_code  := NULL;
62222 l_adr_flex_value_set_id       := NULL;
62223 l_adr_value_type_code         := NULL;
62224 l_adr_value_combination_id    := NULL;
62225 l_adr_value_segment_code      := NULL;
62226 
62227 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
62228 l_bflow_class_code           := '';    -- 4219869 Business Flow
62229 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
62230 l_budgetary_control_flag     := 'N';
62231 
62232 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
62233 l_bflow_applied_to_amt       := NULL; -- 5132302
62234 l_entered_amt_idx            := NULL;          -- 4262811
62235 l_accted_amt_idx             := NULL;          -- 4262811
62236 l_acc_rev_flag               := NULL;          -- 4262811
62237 l_accrual_line_num           := NULL;          -- 4262811
62238 l_tmp_amt                    := NULL;          -- 4262811
62239 --
62240  
62241 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
62242     l_balance_type_code <> 'B' THEN
62243 IF (NVL(p_source_20,'
62244 ') =  'OTHER_ACC' OR 
62245 NVL(p_source_20,'
62246 ') =  'ACTIVITY') AND 
62247 NVL(p_source_21,'
62248 ') =  'NETTING' AND 
62249 NVL(p_source_69,'
62250 ') =  'N'
62251  THEN 
62252 
62253    --
62254    XLA_AE_LINES_PKG.SetNewLine;
62255 
62256    p_balance_type_code          := l_balance_type_code;
62257    -- set the flag so later we will know whether the gain loss line needs to be created
62258    
62259    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
62260      p_actual_flag :='A';
62261    END IF;
62262 
62263    --
62267                                       p_header_num   => 0); -- 4262811
62264    -- bulk performance
62265    --
62266    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
62268    --
62269    -- set accounting line options
62270    --
62271    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
62272            p_natural_side_code          => 'C'
62273          , p_gain_or_loss_flag          => 'N'
62274          , p_gl_transfer_mode_code      => 'S'
62275          , p_acct_entry_type_code       => 'A'
62276          , p_switch_side_flag           => 'Y'
62277          , p_merge_duplicate_code       => 'A'
62278          );
62279    --
62280    l_acc_rev_natural_side_code := 'D';  -- 4262811
62281    -- 
62282    --
62283    -- set accounting line type info
62284    --
62285    xla_ae_lines_pkg.SetAcctLineType
62286       (p_component_type             => l_component_type
62287       ,p_event_type_code            => l_event_type_code
62288       ,p_line_definition_owner_code => l_line_definition_owner_code
62289       ,p_line_definition_code       => l_line_definition_code
62290       ,p_accounting_line_code       => l_component_code
62291       ,p_accounting_line_type_code  => l_component_type_code
62292       ,p_accounting_line_appl_id    => l_component_appl_id
62293       ,p_amb_context_code           => l_amb_context_code
62294       ,p_entity_code                => l_entity_code
62295       ,p_event_class_code           => l_event_class_code);
62296    --
62297    -- set accounting class
62298    --
62299    xla_ae_lines_pkg.SetAcctClass(
62300            p_accounting_class_code  => 'PMT_NET'
62301          , p_ae_header_id           => l_ae_header_id
62302          );
62303 
62304    --
62305    -- set rounding class
62306    --
62307    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
62308                       'RECEIVABLE';
62309 
62310    --
62311    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
62312    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
62313    --
62314    -- bulk performance
62315    --
62316    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
62317 
62318    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
62319       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
62320 
62321    -- 4955764
62322    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
62323       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
62324 
62325    -- 4458381 Public Sector Enh
62326    
62327    --
62328    -- set accounting attributes for the line type
62329    --
62330    l_entered_amt_idx := 8;
62331    l_accted_amt_idx  := 13;
62332    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
62333    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
62334    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
62335    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
62336    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
62337    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
62338    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
62339    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
62340    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
62341    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
62342    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
62343    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
62344    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
62345    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
62346    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
62347    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
62348    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
62349    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
62350    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
62351    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
62352    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
62353    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
62354    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
62355    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
62356    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
62357    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
62358    l_rec_acct_attrs.array_num_value(13)  := p_source_29;
62359    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
62360    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
62361    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
62362    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
62363    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
62364    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
62365 
62366    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
62367    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
62368 
62369    ---------------------------------------------------------------------------------------------------------------
62370    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
62374    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
62371    ---------------------------------------------------------------------------------------------------------------
62372    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
62373 
62375    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
62376 
62377    IF xla_accounting_cache_pkg.GetValueChar
62378          (p_source_code         => 'LEDGER_CATEGORY_CODE'
62379          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
62380    AND l_bflow_method_code = 'PRIOR_ENTRY'
62381 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
62382    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
62383          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
62384        )
62385    THEN
62386          xla_ae_lines_pkg.BflowUpgEntry
62387            (p_business_method_code    => l_bflow_method_code
62388            ,p_business_class_code     => l_bflow_class_code
62389            ,p_balance_type            => l_balance_type_code);
62390    ELSE
62391       NULL;
62392 -- No business flow processing for business flow method of NONE.
62393    END IF;
62394 
62395    --
62396    -- call analytical criteria
62397    --
62398    
62399    --
62400    -- call description
62401    --
62402    -- No description or it is inherited.
62403    --
62404    -- call ADRs
62405    -- Bug 4922099
62406    --
62407    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
62408         (NVL(l_actual_upg_option, 'N') = 'O') OR
62409         (NVL(l_enc_upg_option, 'N') = 'O')
62410       )
62411    THEN
62412    NULL;
62413    --
62414    --
62415    
62416   l_ccid := AcctDerRule_7(
62417            p_application_id           => p_application_id
62418          , p_ae_header_id             => l_ae_header_id 
62419 , p_source_3 => p_source_3
62420          , x_transaction_coa_id       => l_adr_transaction_coa_id
62421          , x_accounting_coa_id        => l_adr_accounting_coa_id
62422          , x_value_type_code          => l_adr_value_type_code
62423          , p_side                     => 'NA'
62424    );
62425 
62426    xla_ae_lines_pkg.set_ccid(
62427     p_code_combination_id          => l_ccid
62428   , p_value_type_code              => l_adr_value_type_code
62429   , p_transaction_coa_id           => l_adr_transaction_coa_id
62430   , p_accounting_coa_id            => l_adr_accounting_coa_id
62431   , p_adr_code                     => 'DIST_CCID'
62432   , p_adr_type_code                => 'S'
62433   , p_component_type               => l_component_type
62434   , p_component_code               => l_component_code
62435   , p_component_type_code          => l_component_type_code
62436   , p_component_appl_id            => l_component_appl_id
62437   , p_amb_context_code             => l_amb_context_code
62438   , p_side                         => 'NA'
62439   );
62440 
62441 
62442    --
62443    --
62444    END IF;
62445    --
62446    -- Bug 4922099
62447    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
62448           (NVL(l_enc_upg_option, 'N') = 'O')
62449         ) AND
62450         (l_bflow_method_code = 'PRIOR_ENTRY')
62451       )
62452    THEN
62453       IF
62454       --
62455       1 = 2
62456       --
62457       THEN
62458       xla_accounting_err_pkg.build_message
62459                                     (p_appli_s_name            => 'XLA'
62460                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
62461                                     ,p_token_1                 => 'LINE_NUMBER'
62462                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
62463                                     ,p_token_2                 => 'LINE_TYPE_NAME'
62464                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
62465                                                                              l_component_type
62466                                                                             ,l_component_code
62467                                                                             ,l_component_type_code
62468                                                                             ,l_component_appl_id
62469                                                                             ,l_amb_context_code
62470                                                                             ,l_entity_code
62471                                                                             ,l_event_class_code
62472                                                                            )
62473                                     ,p_token_3                 => 'OWNER'
62474                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
62475                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
62476                                                                           ,p_lookup_code    => l_component_type_code
62477                                                                          )
62478                                     ,p_token_4                 => 'PRODUCT_NAME'
62479                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
62483                                     ,p_ae_header_id            =>  NULL
62480                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
62481                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
62482                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
62484                                        );
62485 
62486         IF (C_LEVEL_ERROR>= g_log_level) THEN
62487                  trace
62488                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
62489                       ,p_level    => C_LEVEL_ERROR
62490                       ,p_module   => l_log_module);
62491         END IF;
62492       END IF;
62493    END IF;
62494    --
62495    --
62496    ------------------------------------------------------------------------------------------------
62497    -- 4219869 Business Flow
62498    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
62499    -- Prior Entry.  Currently, the following code is always generated.
62500    ------------------------------------------------------------------------------------------------
62501    XLA_AE_LINES_PKG.ValidateCurrentLine;
62502 
62503    ------------------------------------------------------------------------------------
62504    -- 4219869 Business Flow
62505    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
62506    ------------------------------------------------------------------------------------
62507    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
62508 
62509    ----------------------------------------------------------------------------------
62510    -- 4219869 Business Flow
62511    -- Update journal entry status -- Need to generate this within IF <condition>
62512    ----------------------------------------------------------------------------------
62513    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
62514          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
62515          ,p_balance_type_code => l_balance_type_code
62516          );
62517 
62518    -------------------------------------------------------------------------------------------
62519    -- 4262811 - Generate the Accrual Reversal lines
62520    -------------------------------------------------------------------------------------------
62521    BEGIN
62522       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
62523                               (g_array_event(p_event_id).array_value_num('header_index'));
62524       IF l_acc_rev_flag IS NULL THEN
62525          l_acc_rev_flag := 'N';
62526       END IF;
62527    EXCEPTION
62528       WHEN OTHERS THEN
62529          l_acc_rev_flag := 'N';
62530    END;
62531    --
62532    IF (l_acc_rev_flag = 'Y') THEN
62533 
62534        -- 4645092  ------------------------------------------------------------------------------
62535        -- To allow MPA report to determine if it should generate report process
62536        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
62537        ------------------------------------------------------------------------------------------
62538 
62539        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
62540        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
62541    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
62542    -- call ADRs
62543    -- Bug 4922099
62544    --
62545    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
62546         (NVL(l_actual_upg_option, 'N') = 'O') OR
62547         (NVL(l_enc_upg_option, 'N') = 'O')
62548       )
62549    THEN
62550    NULL;
62551    --
62552    --
62553    
62554   l_ccid := AcctDerRule_7(
62555            p_application_id           => p_application_id
62556          , p_ae_header_id             => l_ae_header_id 
62557 , p_source_3 => p_source_3
62558          , x_transaction_coa_id       => l_adr_transaction_coa_id
62559          , x_accounting_coa_id        => l_adr_accounting_coa_id
62560          , x_value_type_code          => l_adr_value_type_code
62561          , p_side                     => 'NA'
62562    );
62563 
62564    xla_ae_lines_pkg.set_ccid(
62565     p_code_combination_id          => l_ccid
62566   , p_value_type_code              => l_adr_value_type_code
62567   , p_transaction_coa_id           => l_adr_transaction_coa_id
62568   , p_accounting_coa_id            => l_adr_accounting_coa_id
62569   , p_adr_code                     => 'DIST_CCID'
62570   , p_adr_type_code                => 'S'
62571   , p_component_type               => l_component_type
62572   , p_component_code               => l_component_code
62573   , p_component_type_code          => l_component_type_code
62574   , p_component_appl_id            => l_component_appl_id
62575   , p_amb_context_code             => l_amb_context_code
62576   , p_side                         => 'NA'
62577   );
62578 
62579 
62580    --
62581    --
62582    END IF;
62583 
62584        --
62585        -- Update the line information that should be overwritten
62586        --
62587        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
62588                                          p_header_num   => 1);
62589        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
62590 
62594           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
62591        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
62592 
62593        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
62595        END IF;
62596 
62597       --
62598       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
62599       --
62600       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
62601           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
62602       ELSE
62603           ---------------------------------------------------------------------------------------------------
62604           -- 4262811a Switch Sign
62605           ---------------------------------------------------------------------------------------------------
62606           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
62607           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
62608                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
62609           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
62610                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
62611           -- 5132302
62612           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
62613                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
62614 
62615       END IF;
62616 
62617       -- 4955764
62618       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
62619       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
62620 
62621 
62622       XLA_AE_LINES_PKG.ValidateCurrentLine;
62623       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
62624 
62625       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
62626                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
62627                ,p_balance_type_code => l_balance_type_code);
62628 
62629    END IF;
62630 
62631    -----------------------------------------------------------------------------------------
62632    -- 4262811 Multiperiod Accounting
62633    -----------------------------------------------------------------------------------------
62634      -- No MPA option is assigned.
62635 
62636 
62637 END IF;
62638 END IF;
62639 --
62640 
62641 --
62642 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
62643    trace
62644       (p_msg      => 'END of AcctLineType_125'
62645       ,p_level    => C_LEVEL_PROCEDURE
62646       ,p_module   => l_log_module);
62647 END IF;
62648 --
62649 EXCEPTION
62650   WHEN xla_exceptions_pkg.application_exception THEN
62651       RAISE;
62652   WHEN OTHERS THEN
62653        xla_exceptions_pkg.raise_message
62654            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_125');
62655 END AcctLineType_125;
62656 --
62657 
62658 ---------------------------------------
62659 --
62660 -- PRIVATE FUNCTION
62661 --         AcctLineType_126
62662 --
62663 ---------------------------------------
62664 PROCEDURE AcctLineType_126 (
62665   p_application_id        IN NUMBER
62666  ,p_event_id              IN NUMBER
62667  ,p_calculate_acctd_flag  IN VARCHAR2
62668  ,p_calculate_g_l_flag    IN VARCHAR2
62669  ,p_actual_flag           IN OUT VARCHAR2
62670  ,p_balance_type_code     OUT VARCHAR2
62671  ,p_gain_or_loss_ref      OUT VARCHAR2
62672  
62673 --Distribution GL Account
62674  , p_source_3            IN NUMBER
62675 --Distribution Source Type
62676  , p_source_20            IN VARCHAR2
62677 --Receivable Activity Type
62678  , p_source_21            IN VARCHAR2
62679 --Distribution Line Identifier
62680  , p_source_22            IN NUMBER
62681 --Distribution Type
62682  , p_source_23            IN VARCHAR2
62683 --Exchange Date
62684  , p_source_26            IN DATE
62685 --Exchange Rate
62686  , p_source_27            IN NUMBER
62687 --Exchange Rate Type
62688  , p_source_28            IN VARCHAR2
62689 --Transaction Distribution Identifier
62690  , p_source_34            IN NUMBER
62691 --Transaction Distribution Type
62692  , p_source_35            IN VARCHAR2
62693 --Receipt Applied To Application Identifier
62694  , p_source_58            IN NUMBER
62695 --Transaction Entity Code
62696  , p_source_59            IN VARCHAR2
62697 --Transaction Identifier
62698  , p_source_60            IN NUMBER
62699 --Applying Document Currency Code
62700  , p_source_61            IN VARCHAR2
62701 --Distribution Party Identifier
62702  , p_source_63            IN NUMBER
62703 --Distribution Party Site Id
62704  , p_source_64            IN NUMBER
62705 --Distribution Party Type
62706  , p_source_65            IN VARCHAR2
62707 --Distribution Multi Fund Additional Entry
62708  , p_source_69            IN VARCHAR2
62709 --DIST_ENT_AMT_FROM
62710  , p_source_72            IN NUMBER
62711 --Accounting Amount
62712  , p_source_73            IN NUMBER
62713 )
62714 IS
62715 
62716 l_component_type              VARCHAR2(80);
62717 l_component_code              VARCHAR2(30);
62718 l_component_type_code         VARCHAR2(1);
62719 l_component_appl_id           INTEGER;
62723 l_ae_header_id                NUMBER;
62720 l_amb_context_code            VARCHAR2(30);
62721 l_entity_code                 VARCHAR2(30);
62722 l_event_class_code            VARCHAR2(30);
62724 l_event_type_code             VARCHAR2(30);
62725 l_line_definition_code        VARCHAR2(30);
62726 l_line_definition_owner_code  VARCHAR2(1);
62727 --
62728 -- adr variables
62729 l_segment                     VARCHAR2(30);
62730 l_ccid                        NUMBER;
62731 l_adr_transaction_coa_id      NUMBER;
62732 l_adr_accounting_coa_id       NUMBER;
62733 l_adr_flexfield_segment_code  VARCHAR2(30);
62734 l_adr_flex_value_set_id       NUMBER;
62735 l_adr_value_type_code         VARCHAR2(30);
62736 l_adr_value_combination_id    NUMBER;
62737 l_adr_value_segment_code      VARCHAR2(30);
62738 
62739 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
62740 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
62741 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
62742 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
62743 
62744 -- 4262811 Variables ------------------------------------------------------------------------------------------
62745 l_entered_amt_idx             NUMBER;
62746 l_accted_amt_idx              NUMBER;
62747 l_acc_rev_flag                VARCHAR2(1);
62748 l_accrual_line_num            NUMBER;
62749 l_tmp_amt                     NUMBER;
62750 l_acc_rev_natural_side_code   VARCHAR2(1);
62751 
62752 l_num_entries                 NUMBER;
62753 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
62754 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
62755 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
62756 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
62757 l_recog_line_1                NUMBER;
62758 l_recog_line_2                NUMBER;
62759 
62760 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
62761 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
62762 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
62763 
62764 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
62765 
62766 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
62767 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
62768 
62769 ---------------------------------------------------------------------------------------------------------------
62770 
62771 
62772 --
62773 -- bulk performance
62774 --
62775 l_balance_type_code           VARCHAR2(1);
62776 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
62777 l_log_module                  VARCHAR2(240);
62778 
62779 --
62780 -- Upgrade strategy
62781 --
62782 l_actual_upg_option           VARCHAR2(1);
62783 l_enc_upg_option           VARCHAR2(1);
62784 
62785 --
62786 BEGIN
62787 --
62788 IF g_log_enabled THEN
62789       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_126';
62790 END IF;
62791 --
62792 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
62793 
62794       trace
62795          (p_msg      => 'BEGIN of AcctLineType_126'
62796          ,p_level    => C_LEVEL_PROCEDURE
62797          ,p_module   => l_log_module);
62798 
62799 END IF;
62800 --
62801 l_component_type             := 'AMB_JLT';
62802 l_component_code             := 'RCT_PREPAYMENT';
62803 l_component_type_code        := 'S';
62804 l_component_appl_id          :=  222;
62805 l_amb_context_code           := 'DEFAULT';
62806 l_entity_code                := 'RECEIPTS';
62807 l_event_class_code           := 'RECEIPT';
62808 l_event_type_code            := 'RECEIPT_ALL';
62809 l_line_definition_owner_code := 'S';
62810 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
62811 --
62812 l_balance_type_code          := 'A';
62813 l_segment                     := NULL;
62814 l_ccid                        := NULL;
62815 l_adr_transaction_coa_id      := NULL;
62816 l_adr_accounting_coa_id       := NULL;
62817 l_adr_flexfield_segment_code  := NULL;
62818 l_adr_flex_value_set_id       := NULL;
62819 l_adr_value_type_code         := NULL;
62820 l_adr_value_combination_id    := NULL;
62821 l_adr_value_segment_code      := NULL;
62822 
62823 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
62824 l_bflow_class_code           := '';    -- 4219869 Business Flow
62825 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
62826 l_budgetary_control_flag     := 'N';
62827 
62828 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
62829 l_bflow_applied_to_amt       := NULL; -- 5132302
62830 l_entered_amt_idx            := NULL;          -- 4262811
62831 l_accted_amt_idx             := NULL;          -- 4262811
62832 l_acc_rev_flag               := NULL;          -- 4262811
62833 l_accrual_line_num           := NULL;          -- 4262811
62834 l_tmp_amt                    := NULL;          -- 4262811
62835 --
62836  
62837 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
62838     l_balance_type_code <> 'B' THEN
62839 IF NVL(p_source_20,'
62840 ') =  'OTHER ACC' AND 
62841 NVL(p_source_21,'
62842 ') =  'PREPAYMENT' AND 
62843 NVL(p_source_69,'
62844 ') =  'N'
62845  THEN 
62846 
62847    --
62851    -- set the flag so later we will know whether the gain loss line needs to be created
62848    XLA_AE_LINES_PKG.SetNewLine;
62849 
62850    p_balance_type_code          := l_balance_type_code;
62852    
62853    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
62854      p_actual_flag :='A';
62855    END IF;
62856 
62857    --
62858    -- bulk performance
62859    --
62860    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
62861                                       p_header_num   => 0); -- 4262811
62862    --
62863    -- set accounting line options
62864    --
62865    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
62866            p_natural_side_code          => 'C'
62867          , p_gain_or_loss_flag          => 'N'
62868          , p_gl_transfer_mode_code      => 'S'
62869          , p_acct_entry_type_code       => 'A'
62870          , p_switch_side_flag           => 'Y'
62871          , p_merge_duplicate_code       => 'A'
62872          );
62873    --
62874    l_acc_rev_natural_side_code := 'D';  -- 4262811
62875    -- 
62876    --
62877    -- set accounting line type info
62878    --
62879    xla_ae_lines_pkg.SetAcctLineType
62880       (p_component_type             => l_component_type
62881       ,p_event_type_code            => l_event_type_code
62882       ,p_line_definition_owner_code => l_line_definition_owner_code
62883       ,p_line_definition_code       => l_line_definition_code
62884       ,p_accounting_line_code       => l_component_code
62885       ,p_accounting_line_type_code  => l_component_type_code
62886       ,p_accounting_line_appl_id    => l_component_appl_id
62887       ,p_amb_context_code           => l_amb_context_code
62888       ,p_entity_code                => l_entity_code
62889       ,p_event_class_code           => l_event_class_code);
62890    --
62891    -- set accounting class
62892    --
62893    xla_ae_lines_pkg.SetAcctClass(
62894            p_accounting_class_code  => 'PREPAY'
62895          , p_ae_header_id           => l_ae_header_id
62896          );
62897 
62898    --
62899    -- set rounding class
62900    --
62901    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
62902                       'RECEIVABLE';
62903 
62904    --
62905    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
62906    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
62907    --
62908    -- bulk performance
62909    --
62910    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
62911 
62912    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
62913       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
62914 
62915    -- 4955764
62916    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
62917       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
62918 
62919    -- 4458381 Public Sector Enh
62920    
62921    --
62922    -- set accounting attributes for the line type
62923    --
62924    l_entered_amt_idx := 8;
62925    l_accted_amt_idx  := 13;
62926    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
62927    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
62928    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
62929    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
62930    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
62931    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
62932    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
62933    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
62934    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
62935    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
62936    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
62937    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
62938    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
62939    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
62940    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
62941    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
62942    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
62943    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
62944    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
62945    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
62946    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
62947    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
62948    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
62949    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
62950    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
62951    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
62952    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
62953    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
62954    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
62955    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
62956    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
62957    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
62958    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
62962 
62959 
62960    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
62961    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
62963    ---------------------------------------------------------------------------------------------------------------
62964    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
62965    ---------------------------------------------------------------------------------------------------------------
62966    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
62967 
62968    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
62969    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
62970 
62971    IF xla_accounting_cache_pkg.GetValueChar
62972          (p_source_code         => 'LEDGER_CATEGORY_CODE'
62973          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
62974    AND l_bflow_method_code = 'PRIOR_ENTRY'
62975 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
62976    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
62977          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
62978        )
62979    THEN
62980          xla_ae_lines_pkg.BflowUpgEntry
62981            (p_business_method_code    => l_bflow_method_code
62982            ,p_business_class_code     => l_bflow_class_code
62983            ,p_balance_type            => l_balance_type_code);
62984    ELSE
62985       NULL;
62986 -- No business flow processing for business flow method of NONE.
62987    END IF;
62988 
62989    --
62990    -- call analytical criteria
62991    --
62992    
62993    --
62994    -- call description
62995    --
62996    -- No description or it is inherited.
62997    --
62998    -- call ADRs
62999    -- Bug 4922099
63000    --
63001    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
63002         (NVL(l_actual_upg_option, 'N') = 'O') OR
63003         (NVL(l_enc_upg_option, 'N') = 'O')
63004       )
63005    THEN
63006    NULL;
63007    --
63008    --
63009    
63010   l_ccid := AcctDerRule_7(
63011            p_application_id           => p_application_id
63012          , p_ae_header_id             => l_ae_header_id 
63013 , p_source_3 => p_source_3
63014          , x_transaction_coa_id       => l_adr_transaction_coa_id
63015          , x_accounting_coa_id        => l_adr_accounting_coa_id
63016          , x_value_type_code          => l_adr_value_type_code
63017          , p_side                     => 'NA'
63018    );
63019 
63020    xla_ae_lines_pkg.set_ccid(
63021     p_code_combination_id          => l_ccid
63022   , p_value_type_code              => l_adr_value_type_code
63023   , p_transaction_coa_id           => l_adr_transaction_coa_id
63024   , p_accounting_coa_id            => l_adr_accounting_coa_id
63025   , p_adr_code                     => 'DIST_CCID'
63026   , p_adr_type_code                => 'S'
63027   , p_component_type               => l_component_type
63028   , p_component_code               => l_component_code
63029   , p_component_type_code          => l_component_type_code
63030   , p_component_appl_id            => l_component_appl_id
63031   , p_amb_context_code             => l_amb_context_code
63032   , p_side                         => 'NA'
63033   );
63034 
63035 
63036    --
63037    --
63038    END IF;
63039    --
63040    -- Bug 4922099
63041    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
63042           (NVL(l_enc_upg_option, 'N') = 'O')
63043         ) AND
63044         (l_bflow_method_code = 'PRIOR_ENTRY')
63045       )
63046    THEN
63047       IF
63048       --
63049       1 = 2
63050       --
63051       THEN
63052       xla_accounting_err_pkg.build_message
63053                                     (p_appli_s_name            => 'XLA'
63054                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
63055                                     ,p_token_1                 => 'LINE_NUMBER'
63056                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
63057                                     ,p_token_2                 => 'LINE_TYPE_NAME'
63058                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
63059                                                                              l_component_type
63060                                                                             ,l_component_code
63061                                                                             ,l_component_type_code
63062                                                                             ,l_component_appl_id
63063                                                                             ,l_amb_context_code
63064                                                                             ,l_entity_code
63065                                                                             ,l_event_class_code
63066                                                                            )
63067                                     ,p_token_3                 => 'OWNER'
63068                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
63072                                     ,p_token_4                 => 'PRODUCT_NAME'
63069                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
63070                                                                           ,p_lookup_code    => l_component_type_code
63071                                                                          )
63073                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
63074                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
63075                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
63076                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
63077                                     ,p_ae_header_id            =>  NULL
63078                                        );
63079 
63080         IF (C_LEVEL_ERROR>= g_log_level) THEN
63081                  trace
63082                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
63083                       ,p_level    => C_LEVEL_ERROR
63084                       ,p_module   => l_log_module);
63085         END IF;
63086       END IF;
63087    END IF;
63088    --
63089    --
63090    ------------------------------------------------------------------------------------------------
63091    -- 4219869 Business Flow
63092    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
63093    -- Prior Entry.  Currently, the following code is always generated.
63094    ------------------------------------------------------------------------------------------------
63095    XLA_AE_LINES_PKG.ValidateCurrentLine;
63096 
63097    ------------------------------------------------------------------------------------
63098    -- 4219869 Business Flow
63099    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
63100    ------------------------------------------------------------------------------------
63101    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
63102 
63103    ----------------------------------------------------------------------------------
63104    -- 4219869 Business Flow
63105    -- Update journal entry status -- Need to generate this within IF <condition>
63106    ----------------------------------------------------------------------------------
63107    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
63108          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
63109          ,p_balance_type_code => l_balance_type_code
63110          );
63111 
63112    -------------------------------------------------------------------------------------------
63113    -- 4262811 - Generate the Accrual Reversal lines
63114    -------------------------------------------------------------------------------------------
63115    BEGIN
63116       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
63117                               (g_array_event(p_event_id).array_value_num('header_index'));
63118       IF l_acc_rev_flag IS NULL THEN
63119          l_acc_rev_flag := 'N';
63120       END IF;
63121    EXCEPTION
63122       WHEN OTHERS THEN
63123          l_acc_rev_flag := 'N';
63124    END;
63125    --
63126    IF (l_acc_rev_flag = 'Y') THEN
63127 
63128        -- 4645092  ------------------------------------------------------------------------------
63129        -- To allow MPA report to determine if it should generate report process
63130        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
63131        ------------------------------------------------------------------------------------------
63132 
63133        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
63134        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
63135    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
63136    -- call ADRs
63137    -- Bug 4922099
63138    --
63139    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
63140         (NVL(l_actual_upg_option, 'N') = 'O') OR
63141         (NVL(l_enc_upg_option, 'N') = 'O')
63142       )
63143    THEN
63144    NULL;
63145    --
63146    --
63147    
63148   l_ccid := AcctDerRule_7(
63149            p_application_id           => p_application_id
63150          , p_ae_header_id             => l_ae_header_id 
63151 , p_source_3 => p_source_3
63152          , x_transaction_coa_id       => l_adr_transaction_coa_id
63153          , x_accounting_coa_id        => l_adr_accounting_coa_id
63154          , x_value_type_code          => l_adr_value_type_code
63155          , p_side                     => 'NA'
63156    );
63157 
63158    xla_ae_lines_pkg.set_ccid(
63159     p_code_combination_id          => l_ccid
63160   , p_value_type_code              => l_adr_value_type_code
63161   , p_transaction_coa_id           => l_adr_transaction_coa_id
63162   , p_accounting_coa_id            => l_adr_accounting_coa_id
63163   , p_adr_code                     => 'DIST_CCID'
63164   , p_adr_type_code                => 'S'
63165   , p_component_type               => l_component_type
63166   , p_component_code               => l_component_code
63167   , p_component_type_code          => l_component_type_code
63168   , p_component_appl_id            => l_component_appl_id
63169   , p_amb_context_code             => l_amb_context_code
63170   , p_side                         => 'NA'
63171   );
63172 
63173 
63174    --
63175    --
63176    END IF;
63177 
63178        --
63182                                          p_header_num   => 1);
63179        -- Update the line information that should be overwritten
63180        --
63181        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
63183        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
63184 
63185        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
63186 
63187        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
63188           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
63189        END IF;
63190 
63191       --
63192       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
63193       --
63194       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
63195           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
63196       ELSE
63197           ---------------------------------------------------------------------------------------------------
63198           -- 4262811a Switch Sign
63199           ---------------------------------------------------------------------------------------------------
63200           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
63201           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
63202                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
63203           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
63204                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
63205           -- 5132302
63206           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
63207                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
63208 
63209       END IF;
63210 
63211       -- 4955764
63212       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
63213       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
63214 
63215 
63216       XLA_AE_LINES_PKG.ValidateCurrentLine;
63217       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
63218 
63219       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
63220                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
63221                ,p_balance_type_code => l_balance_type_code);
63222 
63223    END IF;
63224 
63225    -----------------------------------------------------------------------------------------
63226    -- 4262811 Multiperiod Accounting
63227    -----------------------------------------------------------------------------------------
63228      -- No MPA option is assigned.
63229 
63230 
63231 END IF;
63232 END IF;
63233 --
63234 
63235 --
63236 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
63237    trace
63238       (p_msg      => 'END of AcctLineType_126'
63239       ,p_level    => C_LEVEL_PROCEDURE
63240       ,p_module   => l_log_module);
63241 END IF;
63242 --
63243 EXCEPTION
63244   WHEN xla_exceptions_pkg.application_exception THEN
63245       RAISE;
63246   WHEN OTHERS THEN
63247        xla_exceptions_pkg.raise_message
63248            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_126');
63249 END AcctLineType_126;
63250 --
63251 
63252 ---------------------------------------
63253 --
63254 -- PRIVATE FUNCTION
63255 --         AcctLineType_127
63256 --
63257 ---------------------------------------
63258 PROCEDURE AcctLineType_127 (
63259   p_application_id        IN NUMBER
63260  ,p_event_id              IN NUMBER
63261  ,p_calculate_acctd_flag  IN VARCHAR2
63262  ,p_calculate_g_l_flag    IN VARCHAR2
63263  ,p_actual_flag           IN OUT VARCHAR2
63264  ,p_balance_type_code     OUT VARCHAR2
63265  ,p_gain_or_loss_ref      OUT VARCHAR2
63266  
63267 --Distribution GL Account
63268  , p_source_3            IN NUMBER
63269 --Distribution Source Type
63270  , p_source_20            IN VARCHAR2
63271 --Receivable Activity Type
63272  , p_source_21            IN VARCHAR2
63273 --Distribution Line Identifier
63274  , p_source_22            IN NUMBER
63275 --Distribution Type
63276  , p_source_23            IN VARCHAR2
63277 --Exchange Date
63278  , p_source_26            IN DATE
63279 --Exchange Rate
63280  , p_source_27            IN NUMBER
63281 --Exchange Rate Type
63282  , p_source_28            IN VARCHAR2
63283 --Transaction Distribution Identifier
63284  , p_source_34            IN NUMBER
63285 --Transaction Distribution Type
63286  , p_source_35            IN VARCHAR2
63287 --Receipt Applied To Application Identifier
63288  , p_source_58            IN NUMBER
63289 --Transaction Entity Code
63290  , p_source_59            IN VARCHAR2
63291 --Transaction Identifier
63292  , p_source_60            IN NUMBER
63293 --Applying Document Currency Code
63294  , p_source_61            IN VARCHAR2
63295 --Distribution Party Identifier
63296  , p_source_63            IN NUMBER
63297 --Distribution Party Site Id
63298  , p_source_64            IN NUMBER
63299 --Distribution Party Type
63300  , p_source_65            IN VARCHAR2
63304  , p_source_72            IN NUMBER
63301 --Distribution Multi Fund Additional Entry
63302  , p_source_69            IN VARCHAR2
63303 --DIST_ENT_AMT_FROM
63305 --Accounting Amount
63306  , p_source_73            IN NUMBER
63307 )
63308 IS
63309 
63310 l_component_type              VARCHAR2(80);
63311 l_component_code              VARCHAR2(30);
63312 l_component_type_code         VARCHAR2(1);
63313 l_component_appl_id           INTEGER;
63314 l_amb_context_code            VARCHAR2(30);
63315 l_entity_code                 VARCHAR2(30);
63316 l_event_class_code            VARCHAR2(30);
63317 l_ae_header_id                NUMBER;
63318 l_event_type_code             VARCHAR2(30);
63319 l_line_definition_code        VARCHAR2(30);
63320 l_line_definition_owner_code  VARCHAR2(1);
63321 --
63322 -- adr variables
63323 l_segment                     VARCHAR2(30);
63324 l_ccid                        NUMBER;
63325 l_adr_transaction_coa_id      NUMBER;
63326 l_adr_accounting_coa_id       NUMBER;
63327 l_adr_flexfield_segment_code  VARCHAR2(30);
63328 l_adr_flex_value_set_id       NUMBER;
63329 l_adr_value_type_code         VARCHAR2(30);
63330 l_adr_value_combination_id    NUMBER;
63331 l_adr_value_segment_code      VARCHAR2(30);
63332 
63333 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
63334 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
63335 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
63336 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
63337 
63338 -- 4262811 Variables ------------------------------------------------------------------------------------------
63339 l_entered_amt_idx             NUMBER;
63340 l_accted_amt_idx              NUMBER;
63341 l_acc_rev_flag                VARCHAR2(1);
63342 l_accrual_line_num            NUMBER;
63343 l_tmp_amt                     NUMBER;
63344 l_acc_rev_natural_side_code   VARCHAR2(1);
63345 
63346 l_num_entries                 NUMBER;
63347 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
63348 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
63349 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
63350 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
63351 l_recog_line_1                NUMBER;
63352 l_recog_line_2                NUMBER;
63353 
63354 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
63355 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
63356 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
63357 
63358 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
63359 
63360 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
63361 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
63362 
63363 ---------------------------------------------------------------------------------------------------------------
63364 
63365 
63366 --
63367 -- bulk performance
63368 --
63369 l_balance_type_code           VARCHAR2(1);
63370 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
63371 l_log_module                  VARCHAR2(240);
63372 
63373 --
63374 -- Upgrade strategy
63375 --
63376 l_actual_upg_option           VARCHAR2(1);
63377 l_enc_upg_option           VARCHAR2(1);
63378 
63379 --
63380 BEGIN
63381 --
63382 IF g_log_enabled THEN
63383       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_127';
63384 END IF;
63385 --
63386 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
63387 
63388       trace
63389          (p_msg      => 'BEGIN of AcctLineType_127'
63390          ,p_level    => C_LEVEL_PROCEDURE
63391          ,p_module   => l_log_module);
63392 
63393 END IF;
63394 --
63395 l_component_type             := 'AMB_JLT';
63396 l_component_code             := 'RCT_REFUND';
63397 l_component_type_code        := 'S';
63398 l_component_appl_id          :=  222;
63399 l_amb_context_code           := 'DEFAULT';
63400 l_entity_code                := 'RECEIPTS';
63401 l_event_class_code           := 'RECEIPT';
63402 l_event_type_code            := 'RECEIPT_ALL';
63403 l_line_definition_owner_code := 'S';
63404 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
63405 --
63406 l_balance_type_code          := 'A';
63407 l_segment                     := NULL;
63408 l_ccid                        := NULL;
63409 l_adr_transaction_coa_id      := NULL;
63410 l_adr_accounting_coa_id       := NULL;
63411 l_adr_flexfield_segment_code  := NULL;
63412 l_adr_flex_value_set_id       := NULL;
63413 l_adr_value_type_code         := NULL;
63414 l_adr_value_combination_id    := NULL;
63415 l_adr_value_segment_code      := NULL;
63416 
63417 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
63418 l_bflow_class_code           := '';    -- 4219869 Business Flow
63419 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
63420 l_budgetary_control_flag     := 'N';
63421 
63422 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
63423 l_bflow_applied_to_amt       := NULL; -- 5132302
63424 l_entered_amt_idx            := NULL;          -- 4262811
63425 l_accted_amt_idx             := NULL;          -- 4262811
63426 l_acc_rev_flag               := NULL;          -- 4262811
63427 l_accrual_line_num           := NULL;          -- 4262811
63428 l_tmp_amt                    := NULL;          -- 4262811
63429 --
63430  
63434 ') =  'ACTIVITY' AND 
63431 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
63432     l_balance_type_code <> 'B' THEN
63433 IF (NVL(p_source_20,'
63435 NVL(p_source_21,'
63436 ') =  'CCREFUND' AND 
63437 NVL(p_source_69,'
63438 ') =  'N') OR 
63439 (NVL(p_source_20,'
63440 ') =  'ACTIVITY' AND 
63441 NVL(p_source_21,'
63442 ') =  'CM_REFUND' AND 
63443 NVL(p_source_69,'
63444 ') =  'N')
63445  THEN 
63446 
63447    --
63448    XLA_AE_LINES_PKG.SetNewLine;
63449 
63450    p_balance_type_code          := l_balance_type_code;
63451    -- set the flag so later we will know whether the gain loss line needs to be created
63452    
63453    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
63454      p_actual_flag :='A';
63455    END IF;
63456 
63457    --
63458    -- bulk performance
63459    --
63460    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
63461                                       p_header_num   => 0); -- 4262811
63462    --
63463    -- set accounting line options
63464    --
63465    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
63466            p_natural_side_code          => 'C'
63467          , p_gain_or_loss_flag          => 'N'
63468          , p_gl_transfer_mode_code      => 'S'
63469          , p_acct_entry_type_code       => 'A'
63470          , p_switch_side_flag           => 'Y'
63471          , p_merge_duplicate_code       => 'A'
63472          );
63473    --
63474    l_acc_rev_natural_side_code := 'D';  -- 4262811
63475    -- 
63476    --
63477    -- set accounting line type info
63478    --
63479    xla_ae_lines_pkg.SetAcctLineType
63480       (p_component_type             => l_component_type
63481       ,p_event_type_code            => l_event_type_code
63482       ,p_line_definition_owner_code => l_line_definition_owner_code
63483       ,p_line_definition_code       => l_line_definition_code
63484       ,p_accounting_line_code       => l_component_code
63485       ,p_accounting_line_type_code  => l_component_type_code
63486       ,p_accounting_line_appl_id    => l_component_appl_id
63487       ,p_amb_context_code           => l_amb_context_code
63488       ,p_entity_code                => l_entity_code
63489       ,p_event_class_code           => l_event_class_code);
63490    --
63491    -- set accounting class
63492    --
63493    xla_ae_lines_pkg.SetAcctClass(
63494            p_accounting_class_code  => 'REFUND'
63495          , p_ae_header_id           => l_ae_header_id
63496          );
63497 
63498    --
63499    -- set rounding class
63500    --
63501    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
63502                       'RECEIVABLE';
63503 
63504    --
63505    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
63506    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
63507    --
63508    -- bulk performance
63509    --
63510    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
63511 
63512    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
63513       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
63514 
63515    -- 4955764
63516    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
63517       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
63518 
63519    -- 4458381 Public Sector Enh
63520    
63521    --
63522    -- set accounting attributes for the line type
63523    --
63524    l_entered_amt_idx := 8;
63525    l_accted_amt_idx  := 13;
63526    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
63527    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
63528    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
63529    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
63530    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
63531    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
63532    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
63533    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
63534    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
63535    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
63536    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
63537    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
63538    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
63539    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
63540    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
63541    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
63542    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
63543    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
63544    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
63545    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
63546    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
63547    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
63548    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
63552    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
63549    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
63550    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
63551    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
63553    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
63554    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
63555    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
63556    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
63557    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
63558    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
63559 
63560    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
63561    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
63562 
63563    ---------------------------------------------------------------------------------------------------------------
63564    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
63565    ---------------------------------------------------------------------------------------------------------------
63566    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
63567 
63568    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
63569    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
63570 
63571    IF xla_accounting_cache_pkg.GetValueChar
63572          (p_source_code         => 'LEDGER_CATEGORY_CODE'
63573          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
63574    AND l_bflow_method_code = 'PRIOR_ENTRY'
63575 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
63576    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
63577          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
63578        )
63579    THEN
63580          xla_ae_lines_pkg.BflowUpgEntry
63581            (p_business_method_code    => l_bflow_method_code
63582            ,p_business_class_code     => l_bflow_class_code
63583            ,p_balance_type            => l_balance_type_code);
63584    ELSE
63585       NULL;
63586 -- No business flow processing for business flow method of NONE.
63587    END IF;
63588 
63589    --
63590    -- call analytical criteria
63591    --
63592    
63593    --
63594    -- call description
63595    --
63596    -- No description or it is inherited.
63597    --
63598    -- call ADRs
63599    -- Bug 4922099
63600    --
63601    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
63602         (NVL(l_actual_upg_option, 'N') = 'O') OR
63603         (NVL(l_enc_upg_option, 'N') = 'O')
63604       )
63605    THEN
63606    NULL;
63607    --
63608    --
63609    
63610   l_ccid := AcctDerRule_7(
63611            p_application_id           => p_application_id
63612          , p_ae_header_id             => l_ae_header_id 
63613 , p_source_3 => p_source_3
63614          , x_transaction_coa_id       => l_adr_transaction_coa_id
63615          , x_accounting_coa_id        => l_adr_accounting_coa_id
63616          , x_value_type_code          => l_adr_value_type_code
63617          , p_side                     => 'NA'
63618    );
63619 
63620    xla_ae_lines_pkg.set_ccid(
63621     p_code_combination_id          => l_ccid
63622   , p_value_type_code              => l_adr_value_type_code
63623   , p_transaction_coa_id           => l_adr_transaction_coa_id
63624   , p_accounting_coa_id            => l_adr_accounting_coa_id
63625   , p_adr_code                     => 'DIST_CCID'
63626   , p_adr_type_code                => 'S'
63627   , p_component_type               => l_component_type
63628   , p_component_code               => l_component_code
63629   , p_component_type_code          => l_component_type_code
63630   , p_component_appl_id            => l_component_appl_id
63631   , p_amb_context_code             => l_amb_context_code
63632   , p_side                         => 'NA'
63633   );
63634 
63635 
63636    --
63637    --
63638    END IF;
63639    --
63640    -- Bug 4922099
63641    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
63642           (NVL(l_enc_upg_option, 'N') = 'O')
63643         ) AND
63644         (l_bflow_method_code = 'PRIOR_ENTRY')
63645       )
63646    THEN
63647       IF
63648       --
63649       1 = 2
63650       --
63651       THEN
63652       xla_accounting_err_pkg.build_message
63653                                     (p_appli_s_name            => 'XLA'
63654                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
63655                                     ,p_token_1                 => 'LINE_NUMBER'
63656                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
63657                                     ,p_token_2                 => 'LINE_TYPE_NAME'
63658                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
63659                                                                              l_component_type
63660                                                                             ,l_component_code
63661                                                                             ,l_component_type_code
63662                                                                             ,l_component_appl_id
63666                                                                            )
63663                                                                             ,l_amb_context_code
63664                                                                             ,l_entity_code
63665                                                                             ,l_event_class_code
63667                                     ,p_token_3                 => 'OWNER'
63668                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
63669                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
63670                                                                           ,p_lookup_code    => l_component_type_code
63671                                                                          )
63672                                     ,p_token_4                 => 'PRODUCT_NAME'
63673                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
63674                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
63675                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
63676                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
63677                                     ,p_ae_header_id            =>  NULL
63678                                        );
63679 
63680         IF (C_LEVEL_ERROR>= g_log_level) THEN
63681                  trace
63682                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
63683                       ,p_level    => C_LEVEL_ERROR
63684                       ,p_module   => l_log_module);
63685         END IF;
63686       END IF;
63687    END IF;
63688    --
63689    --
63690    ------------------------------------------------------------------------------------------------
63691    -- 4219869 Business Flow
63692    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
63693    -- Prior Entry.  Currently, the following code is always generated.
63694    ------------------------------------------------------------------------------------------------
63695    XLA_AE_LINES_PKG.ValidateCurrentLine;
63696 
63697    ------------------------------------------------------------------------------------
63698    -- 4219869 Business Flow
63699    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
63700    ------------------------------------------------------------------------------------
63701    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
63702 
63703    ----------------------------------------------------------------------------------
63704    -- 4219869 Business Flow
63705    -- Update journal entry status -- Need to generate this within IF <condition>
63706    ----------------------------------------------------------------------------------
63707    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
63708          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
63709          ,p_balance_type_code => l_balance_type_code
63710          );
63711 
63712    -------------------------------------------------------------------------------------------
63713    -- 4262811 - Generate the Accrual Reversal lines
63714    -------------------------------------------------------------------------------------------
63715    BEGIN
63716       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
63717                               (g_array_event(p_event_id).array_value_num('header_index'));
63718       IF l_acc_rev_flag IS NULL THEN
63719          l_acc_rev_flag := 'N';
63720       END IF;
63721    EXCEPTION
63722       WHEN OTHERS THEN
63723          l_acc_rev_flag := 'N';
63724    END;
63725    --
63726    IF (l_acc_rev_flag = 'Y') THEN
63727 
63728        -- 4645092  ------------------------------------------------------------------------------
63729        -- To allow MPA report to determine if it should generate report process
63730        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
63731        ------------------------------------------------------------------------------------------
63732 
63733        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
63734        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
63735    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
63736    -- call ADRs
63737    -- Bug 4922099
63738    --
63739    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
63740         (NVL(l_actual_upg_option, 'N') = 'O') OR
63741         (NVL(l_enc_upg_option, 'N') = 'O')
63742       )
63743    THEN
63744    NULL;
63745    --
63746    --
63747    
63748   l_ccid := AcctDerRule_7(
63749            p_application_id           => p_application_id
63750          , p_ae_header_id             => l_ae_header_id 
63751 , p_source_3 => p_source_3
63752          , x_transaction_coa_id       => l_adr_transaction_coa_id
63753          , x_accounting_coa_id        => l_adr_accounting_coa_id
63754          , x_value_type_code          => l_adr_value_type_code
63755          , p_side                     => 'NA'
63756    );
63757 
63758    xla_ae_lines_pkg.set_ccid(
63759     p_code_combination_id          => l_ccid
63760   , p_value_type_code              => l_adr_value_type_code
63761   , p_transaction_coa_id           => l_adr_transaction_coa_id
63762   , p_accounting_coa_id            => l_adr_accounting_coa_id
63763   , p_adr_code                     => 'DIST_CCID'
63767   , p_component_type_code          => l_component_type_code
63764   , p_adr_type_code                => 'S'
63765   , p_component_type               => l_component_type
63766   , p_component_code               => l_component_code
63768   , p_component_appl_id            => l_component_appl_id
63769   , p_amb_context_code             => l_amb_context_code
63770   , p_side                         => 'NA'
63771   );
63772 
63773 
63774    --
63775    --
63776    END IF;
63777 
63778        --
63779        -- Update the line information that should be overwritten
63780        --
63781        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
63782                                          p_header_num   => 1);
63783        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
63784 
63785        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
63786 
63787        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
63788           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
63789        END IF;
63790 
63791       --
63792       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
63793       --
63794       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
63795           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
63796       ELSE
63797           ---------------------------------------------------------------------------------------------------
63798           -- 4262811a Switch Sign
63799           ---------------------------------------------------------------------------------------------------
63800           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
63801           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
63802                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
63803           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
63804                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
63805           -- 5132302
63806           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
63807                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
63808 
63809       END IF;
63810 
63811       -- 4955764
63812       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
63813       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
63814 
63815 
63816       XLA_AE_LINES_PKG.ValidateCurrentLine;
63817       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
63818 
63819       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
63820                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
63821                ,p_balance_type_code => l_balance_type_code);
63822 
63823    END IF;
63824 
63825    -----------------------------------------------------------------------------------------
63826    -- 4262811 Multiperiod Accounting
63827    -----------------------------------------------------------------------------------------
63828      -- No MPA option is assigned.
63829 
63830 
63831 END IF;
63832 END IF;
63833 --
63834 
63835 --
63836 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
63837    trace
63838       (p_msg      => 'END of AcctLineType_127'
63839       ,p_level    => C_LEVEL_PROCEDURE
63840       ,p_module   => l_log_module);
63841 END IF;
63842 --
63843 EXCEPTION
63844   WHEN xla_exceptions_pkg.application_exception THEN
63845       RAISE;
63846   WHEN OTHERS THEN
63847        xla_exceptions_pkg.raise_message
63848            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_127');
63849 END AcctLineType_127;
63850 --
63851 
63852 ---------------------------------------
63853 --
63854 -- PRIVATE FUNCTION
63855 --         AcctLineType_128
63856 --
63857 ---------------------------------------
63858 PROCEDURE AcctLineType_128 (
63859   p_application_id        IN NUMBER
63860  ,p_event_id              IN NUMBER
63861  ,p_calculate_acctd_flag  IN VARCHAR2
63862  ,p_calculate_g_l_flag    IN VARCHAR2
63863  ,p_actual_flag           IN OUT VARCHAR2
63864  ,p_balance_type_code     OUT VARCHAR2
63865  ,p_gain_or_loss_ref      OUT VARCHAR2
63866  
63867 --Distribution GL Account
63868  , p_source_3            IN NUMBER
63869 --Distribution Source Type
63870  , p_source_20            IN VARCHAR2
63871 --Distribution Line Identifier
63872  , p_source_22            IN NUMBER
63873 --Distribution Type
63874  , p_source_23            IN VARCHAR2
63875 --Exchange Date
63876  , p_source_26            IN DATE
63877 --Exchange Rate
63878  , p_source_27            IN NUMBER
63879 --Exchange Rate Type
63880  , p_source_28            IN VARCHAR2
63881 --Transaction Distribution Identifier
63882  , p_source_34            IN NUMBER
63883 --Transaction Distribution Type
63884  , p_source_35            IN VARCHAR2
63885 --Receipt Applied To Application Identifier
63886  , p_source_58            IN NUMBER
63887 --Transaction Entity Code
63891 --Applying Document Currency Code
63888  , p_source_59            IN VARCHAR2
63889 --Transaction Identifier
63890  , p_source_60            IN NUMBER
63892  , p_source_61            IN VARCHAR2
63893 --Distribution Party Identifier
63894  , p_source_63            IN NUMBER
63895 --Distribution Party Site Id
63896  , p_source_64            IN NUMBER
63897 --Distribution Party Type
63898  , p_source_65            IN VARCHAR2
63899 --Distribution Multi Fund Additional Entry
63900  , p_source_69            IN VARCHAR2
63901 --DIST_ENT_AMT_FROM
63902  , p_source_72            IN NUMBER
63903 --Accounting Amount
63904  , p_source_73            IN NUMBER
63905 --Distribution Source Table
63906  , p_source_75            IN VARCHAR2
63907 )
63908 IS
63909 
63910 l_component_type              VARCHAR2(80);
63911 l_component_code              VARCHAR2(30);
63912 l_component_type_code         VARCHAR2(1);
63913 l_component_appl_id           INTEGER;
63914 l_amb_context_code            VARCHAR2(30);
63915 l_entity_code                 VARCHAR2(30);
63916 l_event_class_code            VARCHAR2(30);
63917 l_ae_header_id                NUMBER;
63918 l_event_type_code             VARCHAR2(30);
63919 l_line_definition_code        VARCHAR2(30);
63920 l_line_definition_owner_code  VARCHAR2(1);
63921 --
63922 -- adr variables
63923 l_segment                     VARCHAR2(30);
63924 l_ccid                        NUMBER;
63925 l_adr_transaction_coa_id      NUMBER;
63926 l_adr_accounting_coa_id       NUMBER;
63927 l_adr_flexfield_segment_code  VARCHAR2(30);
63928 l_adr_flex_value_set_id       NUMBER;
63929 l_adr_value_type_code         VARCHAR2(30);
63930 l_adr_value_combination_id    NUMBER;
63931 l_adr_value_segment_code      VARCHAR2(30);
63932 
63933 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
63934 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
63935 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
63936 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
63937 
63938 -- 4262811 Variables ------------------------------------------------------------------------------------------
63939 l_entered_amt_idx             NUMBER;
63940 l_accted_amt_idx              NUMBER;
63941 l_acc_rev_flag                VARCHAR2(1);
63942 l_accrual_line_num            NUMBER;
63943 l_tmp_amt                     NUMBER;
63944 l_acc_rev_natural_side_code   VARCHAR2(1);
63945 
63946 l_num_entries                 NUMBER;
63947 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
63948 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
63949 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
63950 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
63951 l_recog_line_1                NUMBER;
63952 l_recog_line_2                NUMBER;
63953 
63954 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
63955 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
63956 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
63957 
63958 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
63959 
63960 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
63961 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
63962 
63963 ---------------------------------------------------------------------------------------------------------------
63964 
63965 
63966 --
63967 -- bulk performance
63968 --
63969 l_balance_type_code           VARCHAR2(1);
63970 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
63971 l_log_module                  VARCHAR2(240);
63972 
63973 --
63974 -- Upgrade strategy
63975 --
63976 l_actual_upg_option           VARCHAR2(1);
63977 l_enc_upg_option           VARCHAR2(1);
63978 
63979 --
63980 BEGIN
63981 --
63982 IF g_log_enabled THEN
63983       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_128';
63984 END IF;
63985 --
63986 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
63987 
63988       trace
63989          (p_msg      => 'BEGIN of AcctLineType_128'
63990          ,p_level    => C_LEVEL_PROCEDURE
63991          ,p_module   => l_log_module);
63992 
63993 END IF;
63994 --
63995 l_component_type             := 'AMB_JLT';
63996 l_component_code             := 'RCT_REMIT';
63997 l_component_type_code        := 'S';
63998 l_component_appl_id          :=  222;
63999 l_amb_context_code           := 'DEFAULT';
64000 l_entity_code                := 'RECEIPTS';
64001 l_event_class_code           := 'RECEIPT';
64002 l_event_type_code            := 'RECEIPT_ALL';
64003 l_line_definition_owner_code := 'S';
64004 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
64005 --
64006 l_balance_type_code          := 'A';
64007 l_segment                     := NULL;
64008 l_ccid                        := NULL;
64009 l_adr_transaction_coa_id      := NULL;
64010 l_adr_accounting_coa_id       := NULL;
64011 l_adr_flexfield_segment_code  := NULL;
64012 l_adr_flex_value_set_id       := NULL;
64013 l_adr_value_type_code         := NULL;
64014 l_adr_value_combination_id    := NULL;
64015 l_adr_value_segment_code      := NULL;
64016 
64017 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
64021 
64018 l_bflow_class_code           := '';    -- 4219869 Business Flow
64019 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
64020 l_budgetary_control_flag     := 'N';
64022 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
64023 l_bflow_applied_to_amt       := NULL; -- 5132302
64024 l_entered_amt_idx            := NULL;          -- 4262811
64025 l_accted_amt_idx             := NULL;          -- 4262811
64026 l_acc_rev_flag               := NULL;          -- 4262811
64027 l_accrual_line_num           := NULL;          -- 4262811
64028 l_tmp_amt                    := NULL;          -- 4262811
64029 --
64030  
64031 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
64032     l_balance_type_code <> 'B' THEN
64033 IF NVL(p_source_20,'
64034 ') =  'REMITTANCE' AND 
64035 NVL(p_source_75,'
64036 ') =  'CRH' AND 
64037 NVL(p_source_69,'
64038 ') =  'N'
64039  THEN 
64040 
64041    --
64042    XLA_AE_LINES_PKG.SetNewLine;
64043 
64044    p_balance_type_code          := l_balance_type_code;
64045    -- set the flag so later we will know whether the gain loss line needs to be created
64046    
64047    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
64048      p_actual_flag :='A';
64049    END IF;
64050 
64051    --
64052    -- bulk performance
64053    --
64054    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
64055                                       p_header_num   => 0); -- 4262811
64056    --
64057    -- set accounting line options
64058    --
64059    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
64060            p_natural_side_code          => 'C'
64061          , p_gain_or_loss_flag          => 'N'
64062          , p_gl_transfer_mode_code      => 'S'
64063          , p_acct_entry_type_code       => 'A'
64064          , p_switch_side_flag           => 'Y'
64065          , p_merge_duplicate_code       => 'A'
64066          );
64067    --
64068    l_acc_rev_natural_side_code := 'D';  -- 4262811
64069    -- 
64070    --
64071    -- set accounting line type info
64072    --
64073    xla_ae_lines_pkg.SetAcctLineType
64074       (p_component_type             => l_component_type
64075       ,p_event_type_code            => l_event_type_code
64076       ,p_line_definition_owner_code => l_line_definition_owner_code
64077       ,p_line_definition_code       => l_line_definition_code
64078       ,p_accounting_line_code       => l_component_code
64079       ,p_accounting_line_type_code  => l_component_type_code
64080       ,p_accounting_line_appl_id    => l_component_appl_id
64081       ,p_amb_context_code           => l_amb_context_code
64082       ,p_entity_code                => l_entity_code
64083       ,p_event_class_code           => l_event_class_code);
64084    --
64085    -- set accounting class
64086    --
64087    xla_ae_lines_pkg.SetAcctClass(
64088            p_accounting_class_code  => 'REMITTANCE'
64089          , p_ae_header_id           => l_ae_header_id
64090          );
64091 
64092    --
64093    -- set rounding class
64094    --
64095    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
64096                       'RECEIVABLE';
64097 
64098    --
64099    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
64100    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
64101    --
64102    -- bulk performance
64103    --
64104    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
64105 
64106    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
64107       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
64108 
64109    -- 4955764
64110    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
64111       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
64112 
64113    -- 4458381 Public Sector Enh
64114    
64115    --
64116    -- set accounting attributes for the line type
64117    --
64118    l_entered_amt_idx := 8;
64119    l_accted_amt_idx  := 13;
64120    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
64121    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
64122    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
64123    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
64124    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
64125    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
64126    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
64127    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
64128    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
64129    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
64130    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
64131    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
64132    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
64133    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
64134    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
64135    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
64136    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
64140    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
64137    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
64138    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
64139    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
64141    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
64142    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
64143    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
64144    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
64145    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
64146    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
64147    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
64148    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
64149    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
64150    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
64151    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
64152    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
64153 
64154    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
64155    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
64156 
64157    ---------------------------------------------------------------------------------------------------------------
64158    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
64159    ---------------------------------------------------------------------------------------------------------------
64160    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
64161 
64162    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
64163    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
64164 
64165    IF xla_accounting_cache_pkg.GetValueChar
64166          (p_source_code         => 'LEDGER_CATEGORY_CODE'
64167          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
64168    AND l_bflow_method_code = 'PRIOR_ENTRY'
64169 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
64170    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
64171          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
64172        )
64173    THEN
64174          xla_ae_lines_pkg.BflowUpgEntry
64175            (p_business_method_code    => l_bflow_method_code
64176            ,p_business_class_code     => l_bflow_class_code
64177            ,p_balance_type            => l_balance_type_code);
64178    ELSE
64179       NULL;
64180 -- No business flow processing for business flow method of NONE.
64181    END IF;
64182 
64183    --
64184    -- call analytical criteria
64185    --
64186    
64187    --
64188    -- call description
64189    --
64190    -- No description or it is inherited.
64191    --
64192    -- call ADRs
64193    -- Bug 4922099
64194    --
64195    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
64196         (NVL(l_actual_upg_option, 'N') = 'O') OR
64197         (NVL(l_enc_upg_option, 'N') = 'O')
64198       )
64199    THEN
64200    NULL;
64201    --
64202    --
64203    
64204   l_ccid := AcctDerRule_7(
64205            p_application_id           => p_application_id
64206          , p_ae_header_id             => l_ae_header_id 
64207 , p_source_3 => p_source_3
64208          , x_transaction_coa_id       => l_adr_transaction_coa_id
64209          , x_accounting_coa_id        => l_adr_accounting_coa_id
64210          , x_value_type_code          => l_adr_value_type_code
64211          , p_side                     => 'NA'
64212    );
64213 
64214    xla_ae_lines_pkg.set_ccid(
64215     p_code_combination_id          => l_ccid
64216   , p_value_type_code              => l_adr_value_type_code
64217   , p_transaction_coa_id           => l_adr_transaction_coa_id
64218   , p_accounting_coa_id            => l_adr_accounting_coa_id
64219   , p_adr_code                     => 'DIST_CCID'
64220   , p_adr_type_code                => 'S'
64221   , p_component_type               => l_component_type
64222   , p_component_code               => l_component_code
64223   , p_component_type_code          => l_component_type_code
64224   , p_component_appl_id            => l_component_appl_id
64225   , p_amb_context_code             => l_amb_context_code
64226   , p_side                         => 'NA'
64227   );
64228 
64229 
64230    --
64231    --
64232    END IF;
64233    --
64234    -- Bug 4922099
64235    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
64236           (NVL(l_enc_upg_option, 'N') = 'O')
64237         ) AND
64238         (l_bflow_method_code = 'PRIOR_ENTRY')
64239       )
64240    THEN
64241       IF
64242       --
64243       1 = 2
64244       --
64245       THEN
64246       xla_accounting_err_pkg.build_message
64247                                     (p_appli_s_name            => 'XLA'
64248                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
64249                                     ,p_token_1                 => 'LINE_NUMBER'
64250                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
64251                                     ,p_token_2                 => 'LINE_TYPE_NAME'
64252                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
64256                                                                             ,l_component_appl_id
64253                                                                              l_component_type
64254                                                                             ,l_component_code
64255                                                                             ,l_component_type_code
64257                                                                             ,l_amb_context_code
64258                                                                             ,l_entity_code
64259                                                                             ,l_event_class_code
64260                                                                            )
64261                                     ,p_token_3                 => 'OWNER'
64262                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
64263                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
64264                                                                           ,p_lookup_code    => l_component_type_code
64265                                                                          )
64266                                     ,p_token_4                 => 'PRODUCT_NAME'
64267                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
64268                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
64269                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
64270                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
64271                                     ,p_ae_header_id            =>  NULL
64272                                        );
64273 
64274         IF (C_LEVEL_ERROR>= g_log_level) THEN
64275                  trace
64276                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
64277                       ,p_level    => C_LEVEL_ERROR
64278                       ,p_module   => l_log_module);
64279         END IF;
64280       END IF;
64281    END IF;
64282    --
64283    --
64284    ------------------------------------------------------------------------------------------------
64285    -- 4219869 Business Flow
64286    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
64287    -- Prior Entry.  Currently, the following code is always generated.
64288    ------------------------------------------------------------------------------------------------
64289    XLA_AE_LINES_PKG.ValidateCurrentLine;
64290 
64291    ------------------------------------------------------------------------------------
64292    -- 4219869 Business Flow
64293    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
64294    ------------------------------------------------------------------------------------
64295    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
64296 
64297    ----------------------------------------------------------------------------------
64298    -- 4219869 Business Flow
64299    -- Update journal entry status -- Need to generate this within IF <condition>
64300    ----------------------------------------------------------------------------------
64301    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
64302          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
64303          ,p_balance_type_code => l_balance_type_code
64304          );
64305 
64306    -------------------------------------------------------------------------------------------
64307    -- 4262811 - Generate the Accrual Reversal lines
64308    -------------------------------------------------------------------------------------------
64309    BEGIN
64310       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
64311                               (g_array_event(p_event_id).array_value_num('header_index'));
64312       IF l_acc_rev_flag IS NULL THEN
64313          l_acc_rev_flag := 'N';
64314       END IF;
64315    EXCEPTION
64316       WHEN OTHERS THEN
64317          l_acc_rev_flag := 'N';
64318    END;
64319    --
64320    IF (l_acc_rev_flag = 'Y') THEN
64321 
64322        -- 4645092  ------------------------------------------------------------------------------
64323        -- To allow MPA report to determine if it should generate report process
64324        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
64325        ------------------------------------------------------------------------------------------
64326 
64327        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
64328        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
64329    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
64330    -- call ADRs
64331    -- Bug 4922099
64332    --
64333    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
64334         (NVL(l_actual_upg_option, 'N') = 'O') OR
64335         (NVL(l_enc_upg_option, 'N') = 'O')
64336       )
64337    THEN
64338    NULL;
64339    --
64340    --
64341    
64342   l_ccid := AcctDerRule_7(
64343            p_application_id           => p_application_id
64344          , p_ae_header_id             => l_ae_header_id 
64345 , p_source_3 => p_source_3
64346          , x_transaction_coa_id       => l_adr_transaction_coa_id
64347          , x_accounting_coa_id        => l_adr_accounting_coa_id
64348          , x_value_type_code          => l_adr_value_type_code
64349          , p_side                     => 'NA'
64353     p_code_combination_id          => l_ccid
64350    );
64351 
64352    xla_ae_lines_pkg.set_ccid(
64354   , p_value_type_code              => l_adr_value_type_code
64355   , p_transaction_coa_id           => l_adr_transaction_coa_id
64356   , p_accounting_coa_id            => l_adr_accounting_coa_id
64357   , p_adr_code                     => 'DIST_CCID'
64358   , p_adr_type_code                => 'S'
64359   , p_component_type               => l_component_type
64360   , p_component_code               => l_component_code
64361   , p_component_type_code          => l_component_type_code
64362   , p_component_appl_id            => l_component_appl_id
64363   , p_amb_context_code             => l_amb_context_code
64364   , p_side                         => 'NA'
64365   );
64366 
64367 
64368    --
64369    --
64370    END IF;
64371 
64372        --
64373        -- Update the line information that should be overwritten
64374        --
64375        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
64376                                          p_header_num   => 1);
64377        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
64378 
64379        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
64380 
64381        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
64382           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
64383        END IF;
64384 
64385       --
64386       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
64387       --
64388       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
64389           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
64390       ELSE
64391           ---------------------------------------------------------------------------------------------------
64392           -- 4262811a Switch Sign
64393           ---------------------------------------------------------------------------------------------------
64394           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
64395           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
64396                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
64397           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
64398                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
64399           -- 5132302
64400           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
64401                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
64402 
64403       END IF;
64404 
64405       -- 4955764
64406       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
64407       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
64408 
64409 
64410       XLA_AE_LINES_PKG.ValidateCurrentLine;
64411       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
64412 
64413       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
64414                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
64415                ,p_balance_type_code => l_balance_type_code);
64416 
64417    END IF;
64418 
64419    -----------------------------------------------------------------------------------------
64420    -- 4262811 Multiperiod Accounting
64421    -----------------------------------------------------------------------------------------
64422      -- No MPA option is assigned.
64423 
64424 
64425 END IF;
64426 END IF;
64427 --
64428 
64429 --
64430 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
64431    trace
64432       (p_msg      => 'END of AcctLineType_128'
64433       ,p_level    => C_LEVEL_PROCEDURE
64434       ,p_module   => l_log_module);
64435 END IF;
64436 --
64437 EXCEPTION
64438   WHEN xla_exceptions_pkg.application_exception THEN
64439       RAISE;
64440   WHEN OTHERS THEN
64441        xla_exceptions_pkg.raise_message
64442            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_128');
64443 END AcctLineType_128;
64444 --
64445 
64446 ---------------------------------------
64447 --
64448 -- PRIVATE FUNCTION
64449 --         AcctLineType_129
64450 --
64451 ---------------------------------------
64452 PROCEDURE AcctLineType_129 (
64453   p_application_id        IN NUMBER
64454  ,p_event_id              IN NUMBER
64455  ,p_calculate_acctd_flag  IN VARCHAR2
64456  ,p_calculate_g_l_flag    IN VARCHAR2
64457  ,p_actual_flag           IN OUT VARCHAR2
64458  ,p_balance_type_code     OUT VARCHAR2
64459  ,p_gain_or_loss_ref      OUT VARCHAR2
64460  
64461 --Distribution GL Account
64462  , p_source_3            IN NUMBER
64463 --Distribution Source Type
64464  , p_source_20            IN VARCHAR2
64465 --Distribution Line Identifier
64466  , p_source_22            IN NUMBER
64467 --Distribution Type
64468  , p_source_23            IN VARCHAR2
64469 --Exchange Date
64470  , p_source_26            IN DATE
64471 --Exchange Rate
64472  , p_source_27            IN NUMBER
64473 --Exchange Rate Type
64477 --Transaction Distribution Type
64474  , p_source_28            IN VARCHAR2
64475 --Transaction Distribution Identifier
64476  , p_source_34            IN NUMBER
64478  , p_source_35            IN VARCHAR2
64479 --Receipt Applied To Application Identifier
64480  , p_source_58            IN NUMBER
64481 --Transaction Entity Code
64482  , p_source_59            IN VARCHAR2
64483 --Transaction Identifier
64484  , p_source_60            IN NUMBER
64485 --Applying Document Currency Code
64486  , p_source_61            IN VARCHAR2
64487 --Distribution Party Identifier
64488  , p_source_63            IN NUMBER
64489 --Distribution Party Site Id
64490  , p_source_64            IN NUMBER
64491 --Distribution Party Type
64492  , p_source_65            IN VARCHAR2
64493 --Distribution Multi Fund Additional Entry
64494  , p_source_69            IN VARCHAR2
64495 --DIST_ENT_AMT_FROM
64496  , p_source_72            IN NUMBER
64497 --Accounting Amount
64498  , p_source_73            IN NUMBER
64499 --Distribution Source Table
64500  , p_source_75            IN VARCHAR2
64501 )
64502 IS
64503 
64504 l_component_type              VARCHAR2(80);
64505 l_component_code              VARCHAR2(30);
64506 l_component_type_code         VARCHAR2(1);
64507 l_component_appl_id           INTEGER;
64508 l_amb_context_code            VARCHAR2(30);
64509 l_entity_code                 VARCHAR2(30);
64510 l_event_class_code            VARCHAR2(30);
64511 l_ae_header_id                NUMBER;
64512 l_event_type_code             VARCHAR2(30);
64513 l_line_definition_code        VARCHAR2(30);
64514 l_line_definition_owner_code  VARCHAR2(1);
64515 --
64516 -- adr variables
64517 l_segment                     VARCHAR2(30);
64518 l_ccid                        NUMBER;
64519 l_adr_transaction_coa_id      NUMBER;
64520 l_adr_accounting_coa_id       NUMBER;
64521 l_adr_flexfield_segment_code  VARCHAR2(30);
64522 l_adr_flex_value_set_id       NUMBER;
64523 l_adr_value_type_code         VARCHAR2(30);
64524 l_adr_value_combination_id    NUMBER;
64525 l_adr_value_segment_code      VARCHAR2(30);
64526 
64527 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
64528 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
64529 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
64530 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
64531 
64532 -- 4262811 Variables ------------------------------------------------------------------------------------------
64533 l_entered_amt_idx             NUMBER;
64534 l_accted_amt_idx              NUMBER;
64535 l_acc_rev_flag                VARCHAR2(1);
64536 l_accrual_line_num            NUMBER;
64537 l_tmp_amt                     NUMBER;
64538 l_acc_rev_natural_side_code   VARCHAR2(1);
64539 
64540 l_num_entries                 NUMBER;
64541 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
64542 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
64543 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
64544 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
64545 l_recog_line_1                NUMBER;
64546 l_recog_line_2                NUMBER;
64547 
64548 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
64549 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
64550 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
64551 
64552 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
64553 
64554 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
64555 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
64556 
64557 ---------------------------------------------------------------------------------------------------------------
64558 
64559 
64560 --
64561 -- bulk performance
64562 --
64563 l_balance_type_code           VARCHAR2(1);
64564 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
64565 l_log_module                  VARCHAR2(240);
64566 
64567 --
64568 -- Upgrade strategy
64569 --
64570 l_actual_upg_option           VARCHAR2(1);
64571 l_enc_upg_option           VARCHAR2(1);
64572 
64573 --
64574 BEGIN
64575 --
64576 IF g_log_enabled THEN
64577       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_129';
64578 END IF;
64579 --
64580 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
64581 
64582       trace
64583          (p_msg      => 'BEGIN of AcctLineType_129'
64584          ,p_level    => C_LEVEL_PROCEDURE
64585          ,p_module   => l_log_module);
64586 
64587 END IF;
64588 --
64589 l_component_type             := 'AMB_JLT';
64590 l_component_code             := 'RCT_REMIT_BR';
64591 l_component_type_code        := 'S';
64592 l_component_appl_id          :=  222;
64593 l_amb_context_code           := 'DEFAULT';
64594 l_entity_code                := 'RECEIPTS';
64595 l_event_class_code           := 'RECEIPT';
64596 l_event_type_code            := 'RECEIPT_ALL';
64597 l_line_definition_owner_code := 'S';
64598 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
64599 --
64600 l_balance_type_code          := 'A';
64601 l_segment                     := NULL;
64602 l_ccid                        := NULL;
64603 l_adr_transaction_coa_id      := NULL;
64607 l_adr_value_type_code         := NULL;
64604 l_adr_accounting_coa_id       := NULL;
64605 l_adr_flexfield_segment_code  := NULL;
64606 l_adr_flex_value_set_id       := NULL;
64608 l_adr_value_combination_id    := NULL;
64609 l_adr_value_segment_code      := NULL;
64610 
64611 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
64612 l_bflow_class_code           := '';    -- 4219869 Business Flow
64613 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
64614 l_budgetary_control_flag     := 'N';
64615 
64616 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
64617 l_bflow_applied_to_amt       := NULL; -- 5132302
64618 l_entered_amt_idx            := NULL;          -- 4262811
64619 l_accted_amt_idx             := NULL;          -- 4262811
64620 l_acc_rev_flag               := NULL;          -- 4262811
64621 l_accrual_line_num           := NULL;          -- 4262811
64622 l_tmp_amt                    := NULL;          -- 4262811
64623 --
64624  
64625 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
64626     l_balance_type_code <> 'B' THEN
64627 IF NVL(p_source_20,'
64628 ') =  'REMITTANCE' AND 
64629 NVL(p_source_75,'
64630 ') =  'RA' AND 
64631 NVL(p_source_69,'
64632 ') =  'N'
64633  THEN 
64634 
64635    --
64636    XLA_AE_LINES_PKG.SetNewLine;
64637 
64638    p_balance_type_code          := l_balance_type_code;
64639    -- set the flag so later we will know whether the gain loss line needs to be created
64640    
64641    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
64642      p_actual_flag :='A';
64643    END IF;
64644 
64645    --
64646    -- bulk performance
64647    --
64648    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
64649                                       p_header_num   => 0); -- 4262811
64650    --
64651    -- set accounting line options
64652    --
64653    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
64654            p_natural_side_code          => 'C'
64655          , p_gain_or_loss_flag          => 'N'
64656          , p_gl_transfer_mode_code      => 'S'
64657          , p_acct_entry_type_code       => 'A'
64658          , p_switch_side_flag           => 'Y'
64659          , p_merge_duplicate_code       => 'A'
64660          );
64661    --
64662    l_acc_rev_natural_side_code := 'D';  -- 4262811
64663    -- 
64664    --
64665    -- set accounting line type info
64666    --
64667    xla_ae_lines_pkg.SetAcctLineType
64668       (p_component_type             => l_component_type
64669       ,p_event_type_code            => l_event_type_code
64670       ,p_line_definition_owner_code => l_line_definition_owner_code
64671       ,p_line_definition_code       => l_line_definition_code
64672       ,p_accounting_line_code       => l_component_code
64673       ,p_accounting_line_type_code  => l_component_type_code
64674       ,p_accounting_line_appl_id    => l_component_appl_id
64675       ,p_amb_context_code           => l_amb_context_code
64676       ,p_entity_code                => l_entity_code
64677       ,p_event_class_code           => l_event_class_code);
64678    --
64679    -- set accounting class
64680    --
64681    xla_ae_lines_pkg.SetAcctClass(
64682            p_accounting_class_code  => 'REM_BR'
64683          , p_ae_header_id           => l_ae_header_id
64684          );
64685 
64686    --
64687    -- set rounding class
64688    --
64689    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
64690                       'RECEIVABLE';
64691 
64692    --
64693    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
64694    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
64695    --
64696    -- bulk performance
64697    --
64698    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
64699 
64700    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
64701       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
64702 
64703    -- 4955764
64704    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
64705       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
64706 
64707    -- 4458381 Public Sector Enh
64708    
64709    --
64710    -- set accounting attributes for the line type
64711    --
64712    l_entered_amt_idx := 8;
64713    l_accted_amt_idx  := 13;
64714    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
64715    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
64716    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
64717    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
64718    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
64719    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
64720    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
64721    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
64722    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
64723    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
64724    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
64725    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
64729    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
64726    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
64727    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
64728    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
64730    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
64731    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
64732    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
64733    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
64734    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
64735    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
64736    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
64737    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
64738    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
64739    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
64740    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
64741    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
64742    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
64743    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
64744    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
64745    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
64746    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
64747 
64748    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
64749    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
64750 
64751    ---------------------------------------------------------------------------------------------------------------
64752    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
64753    ---------------------------------------------------------------------------------------------------------------
64754    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
64755 
64756    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
64757    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
64758 
64759    IF xla_accounting_cache_pkg.GetValueChar
64760          (p_source_code         => 'LEDGER_CATEGORY_CODE'
64761          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
64762    AND l_bflow_method_code = 'PRIOR_ENTRY'
64763 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
64764    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
64765          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
64766        )
64767    THEN
64768          xla_ae_lines_pkg.BflowUpgEntry
64769            (p_business_method_code    => l_bflow_method_code
64770            ,p_business_class_code     => l_bflow_class_code
64771            ,p_balance_type            => l_balance_type_code);
64772    ELSE
64773       NULL;
64774 -- No business flow processing for business flow method of NONE.
64775    END IF;
64776 
64777    --
64778    -- call analytical criteria
64779    --
64780    
64781    --
64782    -- call description
64783    --
64784    -- No description or it is inherited.
64785    --
64786    -- call ADRs
64787    -- Bug 4922099
64788    --
64789    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
64790         (NVL(l_actual_upg_option, 'N') = 'O') OR
64791         (NVL(l_enc_upg_option, 'N') = 'O')
64792       )
64793    THEN
64794    NULL;
64795    --
64796    --
64797    
64798   l_ccid := AcctDerRule_7(
64799            p_application_id           => p_application_id
64800          , p_ae_header_id             => l_ae_header_id 
64801 , p_source_3 => p_source_3
64802          , x_transaction_coa_id       => l_adr_transaction_coa_id
64803          , x_accounting_coa_id        => l_adr_accounting_coa_id
64804          , x_value_type_code          => l_adr_value_type_code
64805          , p_side                     => 'NA'
64806    );
64807 
64808    xla_ae_lines_pkg.set_ccid(
64809     p_code_combination_id          => l_ccid
64810   , p_value_type_code              => l_adr_value_type_code
64811   , p_transaction_coa_id           => l_adr_transaction_coa_id
64812   , p_accounting_coa_id            => l_adr_accounting_coa_id
64813   , p_adr_code                     => 'DIST_CCID'
64814   , p_adr_type_code                => 'S'
64815   , p_component_type               => l_component_type
64816   , p_component_code               => l_component_code
64817   , p_component_type_code          => l_component_type_code
64818   , p_component_appl_id            => l_component_appl_id
64819   , p_amb_context_code             => l_amb_context_code
64820   , p_side                         => 'NA'
64821   );
64822 
64823 
64824    --
64825    --
64826    END IF;
64827    --
64828    -- Bug 4922099
64829    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
64830           (NVL(l_enc_upg_option, 'N') = 'O')
64831         ) AND
64832         (l_bflow_method_code = 'PRIOR_ENTRY')
64833       )
64834    THEN
64835       IF
64836       --
64837       1 = 2
64838       --
64839       THEN
64840       xla_accounting_err_pkg.build_message
64841                                     (p_appli_s_name            => 'XLA'
64842                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
64843                                     ,p_token_1                 => 'LINE_NUMBER'
64847                                                                              l_component_type
64844                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
64845                                     ,p_token_2                 => 'LINE_TYPE_NAME'
64846                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
64848                                                                             ,l_component_code
64849                                                                             ,l_component_type_code
64850                                                                             ,l_component_appl_id
64851                                                                             ,l_amb_context_code
64852                                                                             ,l_entity_code
64853                                                                             ,l_event_class_code
64854                                                                            )
64855                                     ,p_token_3                 => 'OWNER'
64856                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
64857                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
64858                                                                           ,p_lookup_code    => l_component_type_code
64859                                                                          )
64860                                     ,p_token_4                 => 'PRODUCT_NAME'
64861                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
64862                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
64863                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
64864                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
64865                                     ,p_ae_header_id            =>  NULL
64866                                        );
64867 
64868         IF (C_LEVEL_ERROR>= g_log_level) THEN
64869                  trace
64870                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
64871                       ,p_level    => C_LEVEL_ERROR
64872                       ,p_module   => l_log_module);
64873         END IF;
64874       END IF;
64875    END IF;
64876    --
64877    --
64878    ------------------------------------------------------------------------------------------------
64879    -- 4219869 Business Flow
64880    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
64881    -- Prior Entry.  Currently, the following code is always generated.
64882    ------------------------------------------------------------------------------------------------
64883    XLA_AE_LINES_PKG.ValidateCurrentLine;
64884 
64885    ------------------------------------------------------------------------------------
64886    -- 4219869 Business Flow
64887    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
64888    ------------------------------------------------------------------------------------
64889    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
64890 
64891    ----------------------------------------------------------------------------------
64892    -- 4219869 Business Flow
64893    -- Update journal entry status -- Need to generate this within IF <condition>
64894    ----------------------------------------------------------------------------------
64895    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
64896          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
64897          ,p_balance_type_code => l_balance_type_code
64898          );
64899 
64900    -------------------------------------------------------------------------------------------
64901    -- 4262811 - Generate the Accrual Reversal lines
64902    -------------------------------------------------------------------------------------------
64903    BEGIN
64904       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
64905                               (g_array_event(p_event_id).array_value_num('header_index'));
64906       IF l_acc_rev_flag IS NULL THEN
64907          l_acc_rev_flag := 'N';
64908       END IF;
64909    EXCEPTION
64910       WHEN OTHERS THEN
64911          l_acc_rev_flag := 'N';
64912    END;
64913    --
64914    IF (l_acc_rev_flag = 'Y') THEN
64915 
64916        -- 4645092  ------------------------------------------------------------------------------
64917        -- To allow MPA report to determine if it should generate report process
64918        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
64919        ------------------------------------------------------------------------------------------
64920 
64921        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
64922        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
64923    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
64924    -- call ADRs
64925    -- Bug 4922099
64926    --
64927    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
64928         (NVL(l_actual_upg_option, 'N') = 'O') OR
64929         (NVL(l_enc_upg_option, 'N') = 'O')
64930       )
64931    THEN
64932    NULL;
64933    --
64934    --
64935    
64936   l_ccid := AcctDerRule_7(
64940          , x_transaction_coa_id       => l_adr_transaction_coa_id
64937            p_application_id           => p_application_id
64938          , p_ae_header_id             => l_ae_header_id 
64939 , p_source_3 => p_source_3
64941          , x_accounting_coa_id        => l_adr_accounting_coa_id
64942          , x_value_type_code          => l_adr_value_type_code
64943          , p_side                     => 'NA'
64944    );
64945 
64946    xla_ae_lines_pkg.set_ccid(
64947     p_code_combination_id          => l_ccid
64948   , p_value_type_code              => l_adr_value_type_code
64949   , p_transaction_coa_id           => l_adr_transaction_coa_id
64950   , p_accounting_coa_id            => l_adr_accounting_coa_id
64951   , p_adr_code                     => 'DIST_CCID'
64952   , p_adr_type_code                => 'S'
64953   , p_component_type               => l_component_type
64954   , p_component_code               => l_component_code
64955   , p_component_type_code          => l_component_type_code
64956   , p_component_appl_id            => l_component_appl_id
64957   , p_amb_context_code             => l_amb_context_code
64958   , p_side                         => 'NA'
64959   );
64960 
64961 
64962    --
64963    --
64964    END IF;
64965 
64966        --
64967        -- Update the line information that should be overwritten
64968        --
64969        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
64970                                          p_header_num   => 1);
64971        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
64972 
64973        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
64974 
64975        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
64976           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
64977        END IF;
64978 
64979       --
64980       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
64981       --
64982       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
64983           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
64984       ELSE
64985           ---------------------------------------------------------------------------------------------------
64986           -- 4262811a Switch Sign
64987           ---------------------------------------------------------------------------------------------------
64988           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
64989           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
64990                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
64991           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
64992                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
64993           -- 5132302
64994           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
64995                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
64996 
64997       END IF;
64998 
64999       -- 4955764
65000       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
65001       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
65002 
65003 
65004       XLA_AE_LINES_PKG.ValidateCurrentLine;
65005       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
65006 
65007       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
65008                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
65009                ,p_balance_type_code => l_balance_type_code);
65010 
65011    END IF;
65012 
65013    -----------------------------------------------------------------------------------------
65014    -- 4262811 Multiperiod Accounting
65015    -----------------------------------------------------------------------------------------
65016      -- No MPA option is assigned.
65017 
65018 
65019 END IF;
65020 END IF;
65021 --
65022 
65023 --
65024 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
65025    trace
65026       (p_msg      => 'END of AcctLineType_129'
65027       ,p_level    => C_LEVEL_PROCEDURE
65028       ,p_module   => l_log_module);
65029 END IF;
65030 --
65031 EXCEPTION
65032   WHEN xla_exceptions_pkg.application_exception THEN
65033       RAISE;
65034   WHEN OTHERS THEN
65035        xla_exceptions_pkg.raise_message
65036            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_129');
65037 END AcctLineType_129;
65038 --
65039 
65040 ---------------------------------------
65041 --
65042 -- PRIVATE FUNCTION
65043 --         AcctLineType_130
65044 --
65045 ---------------------------------------
65046 PROCEDURE AcctLineType_130 (
65047   p_application_id        IN NUMBER
65048  ,p_event_id              IN NUMBER
65049  ,p_calculate_acctd_flag  IN VARCHAR2
65050  ,p_calculate_g_l_flag    IN VARCHAR2
65051  ,p_actual_flag           IN OUT VARCHAR2
65052  ,p_balance_type_code     OUT VARCHAR2
65053  ,p_gain_or_loss_ref      OUT VARCHAR2
65054  
65055 --Distribution GL Account
65059 --Distribution Line Identifier
65056  , p_source_3            IN NUMBER
65057 --Distribution Source Type
65058  , p_source_20            IN VARCHAR2
65060  , p_source_22            IN NUMBER
65061 --Distribution Type
65062  , p_source_23            IN VARCHAR2
65063 --Entered Amount
65064  , p_source_24            IN NUMBER
65065 --Currency Code
65066  , p_source_25            IN VARCHAR2
65067 --Applied To Document Accounting Amount
65068  , p_source_29            IN NUMBER
65069 --Transaction Distribution Identifier
65070  , p_source_34            IN NUMBER
65071 --Transaction Distribution Type
65072  , p_source_35            IN VARCHAR2
65073 --Applied To Document Exchange Date
65074  , p_source_57            IN DATE
65075 --Receipt Applied To Application Identifier
65076  , p_source_58            IN NUMBER
65077 --Transaction Entity Code
65078  , p_source_59            IN VARCHAR2
65079 --Transaction Identifier
65080  , p_source_60            IN NUMBER
65081 --Applied To Document Exchange Rate
65082  , p_source_62            IN NUMBER
65083 --Distribution Party Identifier
65084  , p_source_63            IN NUMBER
65085 --Distribution Party Site Id
65086  , p_source_64            IN NUMBER
65087 --Distribution Party Type
65088  , p_source_65            IN VARCHAR2
65089 --Distribution Multi Fund Additional Entry
65090  , p_source_69            IN VARCHAR2
65091 --Applied To Document Exchange Rate Type
65092  , p_source_74            IN VARCHAR2
65093 )
65094 IS
65095 
65096 l_component_type              VARCHAR2(80);
65097 l_component_code              VARCHAR2(30);
65098 l_component_type_code         VARCHAR2(1);
65099 l_component_appl_id           INTEGER;
65100 l_amb_context_code            VARCHAR2(30);
65101 l_entity_code                 VARCHAR2(30);
65102 l_event_class_code            VARCHAR2(30);
65103 l_ae_header_id                NUMBER;
65104 l_event_type_code             VARCHAR2(30);
65105 l_line_definition_code        VARCHAR2(30);
65106 l_line_definition_owner_code  VARCHAR2(1);
65107 --
65108 -- adr variables
65109 l_segment                     VARCHAR2(30);
65110 l_ccid                        NUMBER;
65111 l_adr_transaction_coa_id      NUMBER;
65112 l_adr_accounting_coa_id       NUMBER;
65113 l_adr_flexfield_segment_code  VARCHAR2(30);
65114 l_adr_flex_value_set_id       NUMBER;
65115 l_adr_value_type_code         VARCHAR2(30);
65116 l_adr_value_combination_id    NUMBER;
65117 l_adr_value_segment_code      VARCHAR2(30);
65118 
65119 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
65120 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
65121 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
65122 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
65123 
65124 -- 4262811 Variables ------------------------------------------------------------------------------------------
65125 l_entered_amt_idx             NUMBER;
65126 l_accted_amt_idx              NUMBER;
65127 l_acc_rev_flag                VARCHAR2(1);
65128 l_accrual_line_num            NUMBER;
65129 l_tmp_amt                     NUMBER;
65130 l_acc_rev_natural_side_code   VARCHAR2(1);
65131 
65132 l_num_entries                 NUMBER;
65133 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
65134 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
65135 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
65136 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
65137 l_recog_line_1                NUMBER;
65138 l_recog_line_2                NUMBER;
65139 
65140 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
65141 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
65142 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
65143 
65144 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
65145 
65146 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
65147 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
65148 
65149 ---------------------------------------------------------------------------------------------------------------
65150 
65151 
65152 --
65153 -- bulk performance
65154 --
65155 l_balance_type_code           VARCHAR2(1);
65156 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
65157 l_log_module                  VARCHAR2(240);
65158 
65159 --
65160 -- Upgrade strategy
65161 --
65162 l_actual_upg_option           VARCHAR2(1);
65163 l_enc_upg_option           VARCHAR2(1);
65164 
65165 --
65166 BEGIN
65167 --
65168 IF g_log_enabled THEN
65169       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_130';
65170 END IF;
65171 --
65172 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
65173 
65174       trace
65175          (p_msg      => 'BEGIN of AcctLineType_130'
65176          ,p_level    => C_LEVEL_PROCEDURE
65177          ,p_module   => l_log_module);
65178 
65179 END IF;
65180 --
65181 l_component_type             := 'AMB_JLT';
65182 l_component_code             := 'RCT_TAX';
65183 l_component_type_code        := 'S';
65184 l_component_appl_id          :=  222;
65185 l_amb_context_code           := 'DEFAULT';
65189 l_line_definition_owner_code := 'S';
65186 l_entity_code                := 'RECEIPTS';
65187 l_event_class_code           := 'RECEIPT';
65188 l_event_type_code            := 'RECEIPT_ALL';
65190 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
65191 --
65192 l_balance_type_code          := 'A';
65193 l_segment                     := NULL;
65194 l_ccid                        := NULL;
65195 l_adr_transaction_coa_id      := NULL;
65196 l_adr_accounting_coa_id       := NULL;
65197 l_adr_flexfield_segment_code  := NULL;
65198 l_adr_flex_value_set_id       := NULL;
65199 l_adr_value_type_code         := NULL;
65200 l_adr_value_combination_id    := NULL;
65201 l_adr_value_segment_code      := NULL;
65202 
65203 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
65204 l_bflow_class_code           := '';    -- 4219869 Business Flow
65205 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
65206 l_budgetary_control_flag     := 'N';
65207 
65208 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
65209 l_bflow_applied_to_amt       := NULL; -- 5132302
65210 l_entered_amt_idx            := NULL;          -- 4262811
65211 l_accted_amt_idx             := NULL;          -- 4262811
65212 l_acc_rev_flag               := NULL;          -- 4262811
65213 l_accrual_line_num           := NULL;          -- 4262811
65214 l_tmp_amt                    := NULL;          -- 4262811
65215 --
65216  
65217 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
65218     l_balance_type_code <> 'B' THEN
65219 IF NVL(p_source_20,'
65220 ') =  'TAX' AND 
65221 NVL(p_source_69,'
65222 ') =  'N'
65223  THEN 
65224 
65225    --
65226    XLA_AE_LINES_PKG.SetNewLine;
65227 
65228    p_balance_type_code          := l_balance_type_code;
65229    -- set the flag so later we will know whether the gain loss line needs to be created
65230    
65231    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
65232      p_actual_flag :='A';
65233    END IF;
65234 
65235    --
65236    -- bulk performance
65237    --
65238    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
65239                                       p_header_num   => 0); -- 4262811
65240    --
65241    -- set accounting line options
65242    --
65243    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
65244            p_natural_side_code          => 'C'
65245          , p_gain_or_loss_flag          => 'N'
65246          , p_gl_transfer_mode_code      => 'S'
65247          , p_acct_entry_type_code       => 'A'
65248          , p_switch_side_flag           => 'Y'
65249          , p_merge_duplicate_code       => 'A'
65250          );
65251    --
65252    l_acc_rev_natural_side_code := 'D';  -- 4262811
65253    -- 
65254    --
65255    -- set accounting line type info
65256    --
65257    xla_ae_lines_pkg.SetAcctLineType
65258       (p_component_type             => l_component_type
65259       ,p_event_type_code            => l_event_type_code
65260       ,p_line_definition_owner_code => l_line_definition_owner_code
65261       ,p_line_definition_code       => l_line_definition_code
65262       ,p_accounting_line_code       => l_component_code
65263       ,p_accounting_line_type_code  => l_component_type_code
65264       ,p_accounting_line_appl_id    => l_component_appl_id
65265       ,p_amb_context_code           => l_amb_context_code
65266       ,p_entity_code                => l_entity_code
65267       ,p_event_class_code           => l_event_class_code);
65268    --
65269    -- set accounting class
65270    --
65271    xla_ae_lines_pkg.SetAcctClass(
65272            p_accounting_class_code  => 'TAX'
65273          , p_ae_header_id           => l_ae_header_id
65274          );
65275 
65276    --
65277    -- set rounding class
65278    --
65279    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
65280                       'RECEIVABLE';
65281 
65282    --
65283    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
65284    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
65285    --
65286    -- bulk performance
65287    --
65288    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
65289 
65290    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
65291       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
65292 
65293    -- 4955764
65294    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
65295       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
65296 
65297    -- 4458381 Public Sector Enh
65298    
65299    --
65300    -- set accounting attributes for the line type
65301    --
65302    l_entered_amt_idx := 8;
65303    l_accted_amt_idx  := 13;
65304    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
65305    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
65306    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
65307    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
65308    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
65309    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
65310    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
65314    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
65311    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
65312    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
65313    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
65315    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
65316    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
65317    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
65318    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
65319    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
65320    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
65321    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
65322    l_rec_acct_attrs.array_char_value(9)  := p_source_25;
65323    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
65324    l_rec_acct_attrs.array_date_value(10)  := p_source_57;
65325    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
65326    l_rec_acct_attrs.array_num_value(11)  := p_source_62;
65327    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
65328    l_rec_acct_attrs.array_char_value(12)  := p_source_74;
65329    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
65330    l_rec_acct_attrs.array_num_value(13)  := p_source_29;
65331    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
65332    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
65333    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
65334    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
65335    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
65336    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
65337 
65338    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
65339    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
65340 
65341    ---------------------------------------------------------------------------------------------------------------
65342    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
65343    ---------------------------------------------------------------------------------------------------------------
65344    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
65345 
65346    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
65347    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
65348 
65349    IF xla_accounting_cache_pkg.GetValueChar
65350          (p_source_code         => 'LEDGER_CATEGORY_CODE'
65351          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
65352    AND l_bflow_method_code = 'PRIOR_ENTRY'
65353 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
65354    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
65355          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
65356        )
65357    THEN
65358          xla_ae_lines_pkg.BflowUpgEntry
65359            (p_business_method_code    => l_bflow_method_code
65360            ,p_business_class_code     => l_bflow_class_code
65361            ,p_balance_type            => l_balance_type_code);
65362    ELSE
65363       NULL;
65364 -- No business flow processing for business flow method of NONE.
65365    END IF;
65366 
65367    --
65368    -- call analytical criteria
65369    --
65370    
65371    --
65372    -- call description
65373    --
65374    -- No description or it is inherited.
65375    --
65376    -- call ADRs
65377    -- Bug 4922099
65378    --
65379    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
65380         (NVL(l_actual_upg_option, 'N') = 'O') OR
65381         (NVL(l_enc_upg_option, 'N') = 'O')
65382       )
65383    THEN
65384    NULL;
65385    --
65386    --
65387    
65388   l_ccid := AcctDerRule_7(
65389            p_application_id           => p_application_id
65390          , p_ae_header_id             => l_ae_header_id 
65391 , p_source_3 => p_source_3
65392          , x_transaction_coa_id       => l_adr_transaction_coa_id
65393          , x_accounting_coa_id        => l_adr_accounting_coa_id
65394          , x_value_type_code          => l_adr_value_type_code
65395          , p_side                     => 'NA'
65396    );
65397 
65398    xla_ae_lines_pkg.set_ccid(
65399     p_code_combination_id          => l_ccid
65400   , p_value_type_code              => l_adr_value_type_code
65401   , p_transaction_coa_id           => l_adr_transaction_coa_id
65402   , p_accounting_coa_id            => l_adr_accounting_coa_id
65403   , p_adr_code                     => 'DIST_CCID'
65404   , p_adr_type_code                => 'S'
65405   , p_component_type               => l_component_type
65406   , p_component_code               => l_component_code
65407   , p_component_type_code          => l_component_type_code
65408   , p_component_appl_id            => l_component_appl_id
65409   , p_amb_context_code             => l_amb_context_code
65410   , p_side                         => 'NA'
65411   );
65412 
65413 
65414    --
65415    --
65416    END IF;
65417    --
65418    -- Bug 4922099
65419    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
65420           (NVL(l_enc_upg_option, 'N') = 'O')
65421         ) AND
65422         (l_bflow_method_code = 'PRIOR_ENTRY')
65423       )
65424    THEN
65428       --
65425       IF
65426       --
65427       1 = 2
65429       THEN
65430       xla_accounting_err_pkg.build_message
65431                                     (p_appli_s_name            => 'XLA'
65432                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
65433                                     ,p_token_1                 => 'LINE_NUMBER'
65434                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
65435                                     ,p_token_2                 => 'LINE_TYPE_NAME'
65436                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
65437                                                                              l_component_type
65438                                                                             ,l_component_code
65439                                                                             ,l_component_type_code
65440                                                                             ,l_component_appl_id
65441                                                                             ,l_amb_context_code
65442                                                                             ,l_entity_code
65443                                                                             ,l_event_class_code
65444                                                                            )
65445                                     ,p_token_3                 => 'OWNER'
65446                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
65447                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
65448                                                                           ,p_lookup_code    => l_component_type_code
65449                                                                          )
65450                                     ,p_token_4                 => 'PRODUCT_NAME'
65451                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
65452                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
65453                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
65454                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
65455                                     ,p_ae_header_id            =>  NULL
65456                                        );
65457 
65458         IF (C_LEVEL_ERROR>= g_log_level) THEN
65459                  trace
65460                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
65461                       ,p_level    => C_LEVEL_ERROR
65462                       ,p_module   => l_log_module);
65463         END IF;
65464       END IF;
65465    END IF;
65466    --
65467    --
65468    ------------------------------------------------------------------------------------------------
65469    -- 4219869 Business Flow
65470    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
65471    -- Prior Entry.  Currently, the following code is always generated.
65472    ------------------------------------------------------------------------------------------------
65473    XLA_AE_LINES_PKG.ValidateCurrentLine;
65474 
65475    ------------------------------------------------------------------------------------
65476    -- 4219869 Business Flow
65477    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
65478    ------------------------------------------------------------------------------------
65479    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
65480 
65481    ----------------------------------------------------------------------------------
65482    -- 4219869 Business Flow
65483    -- Update journal entry status -- Need to generate this within IF <condition>
65484    ----------------------------------------------------------------------------------
65485    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
65486          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
65487          ,p_balance_type_code => l_balance_type_code
65488          );
65489 
65490    -------------------------------------------------------------------------------------------
65491    -- 4262811 - Generate the Accrual Reversal lines
65492    -------------------------------------------------------------------------------------------
65493    BEGIN
65494       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
65495                               (g_array_event(p_event_id).array_value_num('header_index'));
65496       IF l_acc_rev_flag IS NULL THEN
65497          l_acc_rev_flag := 'N';
65498       END IF;
65499    EXCEPTION
65500       WHEN OTHERS THEN
65501          l_acc_rev_flag := 'N';
65502    END;
65503    --
65504    IF (l_acc_rev_flag = 'Y') THEN
65505 
65506        -- 4645092  ------------------------------------------------------------------------------
65507        -- To allow MPA report to determine if it should generate report process
65508        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
65509        ------------------------------------------------------------------------------------------
65510 
65511        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
65512        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
65513    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
65514    -- call ADRs
65515    -- Bug 4922099
65516    --
65517    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
65521    THEN
65518         (NVL(l_actual_upg_option, 'N') = 'O') OR
65519         (NVL(l_enc_upg_option, 'N') = 'O')
65520       )
65522    NULL;
65523    --
65524    --
65525    
65526   l_ccid := AcctDerRule_7(
65527            p_application_id           => p_application_id
65528          , p_ae_header_id             => l_ae_header_id 
65529 , p_source_3 => p_source_3
65530          , x_transaction_coa_id       => l_adr_transaction_coa_id
65531          , x_accounting_coa_id        => l_adr_accounting_coa_id
65532          , x_value_type_code          => l_adr_value_type_code
65533          , p_side                     => 'NA'
65534    );
65535 
65536    xla_ae_lines_pkg.set_ccid(
65537     p_code_combination_id          => l_ccid
65538   , p_value_type_code              => l_adr_value_type_code
65539   , p_transaction_coa_id           => l_adr_transaction_coa_id
65540   , p_accounting_coa_id            => l_adr_accounting_coa_id
65541   , p_adr_code                     => 'DIST_CCID'
65542   , p_adr_type_code                => 'S'
65543   , p_component_type               => l_component_type
65544   , p_component_code               => l_component_code
65545   , p_component_type_code          => l_component_type_code
65546   , p_component_appl_id            => l_component_appl_id
65547   , p_amb_context_code             => l_amb_context_code
65548   , p_side                         => 'NA'
65549   );
65550 
65551 
65552    --
65553    --
65554    END IF;
65555 
65556        --
65557        -- Update the line information that should be overwritten
65558        --
65559        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
65560                                          p_header_num   => 1);
65561        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
65562 
65563        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
65564 
65565        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
65566           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
65567        END IF;
65568 
65569       --
65570       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
65571       --
65572       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
65573           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
65574       ELSE
65575           ---------------------------------------------------------------------------------------------------
65576           -- 4262811a Switch Sign
65577           ---------------------------------------------------------------------------------------------------
65578           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
65579           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
65580                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
65581           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
65582                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
65583           -- 5132302
65584           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
65585                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
65586 
65587       END IF;
65588 
65589       -- 4955764
65590       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
65591       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
65592 
65593 
65594       XLA_AE_LINES_PKG.ValidateCurrentLine;
65595       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
65596 
65597       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
65598                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
65599                ,p_balance_type_code => l_balance_type_code);
65600 
65601    END IF;
65602 
65603    -----------------------------------------------------------------------------------------
65604    -- 4262811 Multiperiod Accounting
65605    -----------------------------------------------------------------------------------------
65606      -- No MPA option is assigned.
65607 
65608 
65609 END IF;
65610 END IF;
65611 --
65612 
65613 --
65614 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
65615    trace
65616       (p_msg      => 'END of AcctLineType_130'
65617       ,p_level    => C_LEVEL_PROCEDURE
65618       ,p_module   => l_log_module);
65619 END IF;
65620 --
65621 EXCEPTION
65622   WHEN xla_exceptions_pkg.application_exception THEN
65623       RAISE;
65624   WHEN OTHERS THEN
65625        xla_exceptions_pkg.raise_message
65626            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_130');
65627 END AcctLineType_130;
65628 --
65629 
65630 ---------------------------------------
65631 --
65632 -- PRIVATE FUNCTION
65633 --         AcctLineType_131
65634 --
65635 ---------------------------------------
65636 PROCEDURE AcctLineType_131 (
65637   p_application_id        IN NUMBER
65638  ,p_event_id              IN NUMBER
65642  ,p_balance_type_code     OUT VARCHAR2
65639  ,p_calculate_acctd_flag  IN VARCHAR2
65640  ,p_calculate_g_l_flag    IN VARCHAR2
65641  ,p_actual_flag           IN OUT VARCHAR2
65643  ,p_gain_or_loss_ref      OUT VARCHAR2
65644  
65645 --Remittance Bank Account Unapplied Account
65646  , p_source_17            IN NUMBER
65647 --Distribution Source Type
65648  , p_source_20            IN VARCHAR2
65649 --Receivable Activity Type
65650  , p_source_21            IN VARCHAR2
65651 --Distribution Line Identifier
65652  , p_source_22            IN NUMBER
65653 --Distribution Type
65654  , p_source_23            IN VARCHAR2
65655 --Exchange Date
65656  , p_source_26            IN DATE
65657 --Exchange Rate
65658  , p_source_27            IN NUMBER
65659 --Exchange Rate Type
65660  , p_source_28            IN VARCHAR2
65661 --Transaction Distribution Identifier
65662  , p_source_34            IN NUMBER
65663 --Transaction Distribution Type
65664  , p_source_35            IN VARCHAR2
65665 --Receipt Applied To Application Identifier
65666  , p_source_58            IN NUMBER
65667 --Transaction Entity Code
65668  , p_source_59            IN VARCHAR2
65669 --Transaction Identifier
65670  , p_source_60            IN NUMBER
65671 --Applying Document Currency Code
65672  , p_source_61            IN VARCHAR2
65673 --Distribution Party Type
65674  , p_source_65            IN VARCHAR2
65675 --Distribution Multi Fund Additional Entry
65676  , p_source_69            IN VARCHAR2
65677 --DIST_ENT_AMT_FROM
65678  , p_source_72            IN NUMBER
65679 --Accounting Amount
65680  , p_source_73            IN NUMBER
65681 --Distribution Source Table
65682  , p_source_75            IN VARCHAR2
65683 --Receipt Pay From Customer
65684  , p_source_76            IN NUMBER
65685 --Receipt Customer Site Use Identifier
65686  , p_source_77            IN NUMBER
65687 )
65688 IS
65689 
65690 l_component_type              VARCHAR2(80);
65691 l_component_code              VARCHAR2(30);
65692 l_component_type_code         VARCHAR2(1);
65693 l_component_appl_id           INTEGER;
65694 l_amb_context_code            VARCHAR2(30);
65695 l_entity_code                 VARCHAR2(30);
65696 l_event_class_code            VARCHAR2(30);
65697 l_ae_header_id                NUMBER;
65698 l_event_type_code             VARCHAR2(30);
65699 l_line_definition_code        VARCHAR2(30);
65700 l_line_definition_owner_code  VARCHAR2(1);
65701 --
65702 -- adr variables
65703 l_segment                     VARCHAR2(30);
65704 l_ccid                        NUMBER;
65705 l_adr_transaction_coa_id      NUMBER;
65706 l_adr_accounting_coa_id       NUMBER;
65707 l_adr_flexfield_segment_code  VARCHAR2(30);
65708 l_adr_flex_value_set_id       NUMBER;
65709 l_adr_value_type_code         VARCHAR2(30);
65710 l_adr_value_combination_id    NUMBER;
65711 l_adr_value_segment_code      VARCHAR2(30);
65712 
65713 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
65714 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
65715 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
65716 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
65717 
65718 -- 4262811 Variables ------------------------------------------------------------------------------------------
65719 l_entered_amt_idx             NUMBER;
65720 l_accted_amt_idx              NUMBER;
65721 l_acc_rev_flag                VARCHAR2(1);
65722 l_accrual_line_num            NUMBER;
65723 l_tmp_amt                     NUMBER;
65724 l_acc_rev_natural_side_code   VARCHAR2(1);
65725 
65726 l_num_entries                 NUMBER;
65727 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
65728 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
65729 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
65730 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
65731 l_recog_line_1                NUMBER;
65732 l_recog_line_2                NUMBER;
65733 
65734 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
65735 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
65736 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
65737 
65738 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
65739 
65740 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
65741 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
65742 
65743 ---------------------------------------------------------------------------------------------------------------
65744 
65745 
65746 --
65747 -- bulk performance
65748 --
65749 l_balance_type_code           VARCHAR2(1);
65750 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
65751 l_log_module                  VARCHAR2(240);
65752 
65753 --
65754 -- Upgrade strategy
65755 --
65756 l_actual_upg_option           VARCHAR2(1);
65757 l_enc_upg_option           VARCHAR2(1);
65758 
65759 --
65760 BEGIN
65761 --
65762 IF g_log_enabled THEN
65763       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_131';
65764 END IF;
65765 --
65766 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
65767 
65768       trace
65769          (p_msg      => 'BEGIN of AcctLineType_131'
65770          ,p_level    => C_LEVEL_PROCEDURE
65774 --
65771          ,p_module   => l_log_module);
65772 
65773 END IF;
65775 l_component_type             := 'AMB_JLT';
65776 l_component_code             := 'RCT_UNAPP';
65777 l_component_type_code        := 'S';
65778 l_component_appl_id          :=  222;
65779 l_amb_context_code           := 'DEFAULT';
65780 l_entity_code                := 'RECEIPTS';
65781 l_event_class_code           := 'RECEIPT';
65782 l_event_type_code            := 'RECEIPT_ALL';
65783 l_line_definition_owner_code := 'S';
65784 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
65785 --
65786 l_balance_type_code          := 'A';
65787 l_segment                     := NULL;
65788 l_ccid                        := NULL;
65789 l_adr_transaction_coa_id      := NULL;
65790 l_adr_accounting_coa_id       := NULL;
65791 l_adr_flexfield_segment_code  := NULL;
65792 l_adr_flex_value_set_id       := NULL;
65793 l_adr_value_type_code         := NULL;
65794 l_adr_value_combination_id    := NULL;
65795 l_adr_value_segment_code      := NULL;
65796 
65797 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
65798 l_bflow_class_code           := '';    -- 4219869 Business Flow
65799 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
65800 l_budgetary_control_flag     := 'N';
65801 
65802 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
65803 l_bflow_applied_to_amt       := NULL; -- 5132302
65804 l_entered_amt_idx            := NULL;          -- 4262811
65805 l_accted_amt_idx             := NULL;          -- 4262811
65806 l_acc_rev_flag               := NULL;          -- 4262811
65807 l_accrual_line_num           := NULL;          -- 4262811
65808 l_tmp_amt                    := NULL;          -- 4262811
65809 --
65810  
65811 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
65812     l_balance_type_code <> 'B' THEN
65813 IF (NVL(p_source_20,'
65814 ') =  'OTHER ACC' AND 
65815 NVL(p_source_21,'
65816 ') =  'CLAIM_INVESTIGATION' AND 
65817 NVL(p_source_69,'
65818 ') =  'N') OR 
65819 (NVL(p_source_20,'
65820 ') =  'FACTOR' AND 
65821 NVL(p_source_75,'
65822 ') =  'RA' AND 
65823 NVL(p_source_69,'
65824 ') =  'N') OR 
65825 (NVL(p_source_20,'
65826 ') =  'OTHER ACC' AND 
65827 NVL(p_source_69,'
65828 ') =  'N' AND 
65829 NVL(p_source_21,'
65830 ') =  'NETTING') OR 
65831 (NVL(p_source_20,'
65832 ') =  'OTHER ACC' AND 
65833 NVL(p_source_69,'
65834 ') =  'N' AND 
65835 NVL(p_source_21,'
65836 ') =  'PREPAYMENT') OR 
65837 (NVL(p_source_20,'
65838 ') =  'ACTIVITY' AND 
65839 NVL(p_source_69,'
65840 ') =  'N' AND 
65841 NVL(p_source_21,'
65842 ') =  'CCREFUND') OR 
65843 (NVL(p_source_20,'
65844 ') =  'REMITTANCE' AND 
65845 NVL(p_source_69,'
65846 ') =  'N' AND 
65847 NVL(p_source_75,'
65848 ') =  'RA') OR 
65849 (NVL(p_source_20,'
65850 ') =  'ACTIVITY' AND 
65851 NVL(p_source_69,'
65852 ') =  'N' AND 
65853 NVL(p_source_21,'
65854 ') =  'WRITEOFF') OR 
65855 (NVL(p_source_20,'
65856 ') =  'ACTIVITY' AND 
65857 NVL(p_source_69,'
65858 ') =  'N' AND 
65859 NVL(p_source_21,'
65860 ') =  'CM_REFUND') OR 
65861 (NVL(p_source_20,'
65862 ') =  'ACTIVITY' AND 
65863 NVL(p_source_21,'
65864 ') =  'ADJUST' AND 
65865 NVL(p_source_69,'
65866 ') =  'N') OR 
65867 (NVL(p_source_20,'
65868 ') =  'ACTIVITY' AND 
65869 NVL(p_source_69,'
65870 ') =  'N' AND 
65871 NVL(p_source_21,'
65872 ') =  'CC_CHARGEBACK') OR 
65873 (NVL(p_source_20,'
65874 ') =  'ACTIVITY' AND 
65875 NVL(p_source_69,'
65876 ') =  'N' AND 
65877 NVL(p_source_21,'
65878 ') =  'NETTING')
65879  THEN 
65880 
65881    --
65882    XLA_AE_LINES_PKG.SetNewLine;
65883 
65884    p_balance_type_code          := l_balance_type_code;
65885    -- set the flag so later we will know whether the gain loss line needs to be created
65886    
65887    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
65888      p_actual_flag :='A';
65889    END IF;
65890 
65891    --
65892    -- bulk performance
65893    --
65894    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
65895                                       p_header_num   => 0); -- 4262811
65896    --
65897    -- set accounting line options
65898    --
65899    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
65900            p_natural_side_code          => 'D'
65901          , p_gain_or_loss_flag          => 'N'
65902          , p_gl_transfer_mode_code      => 'S'
65903          , p_acct_entry_type_code       => 'A'
65904          , p_switch_side_flag           => 'Y'
65905          , p_merge_duplicate_code       => 'A'
65906          );
65907    --
65908    l_acc_rev_natural_side_code := 'C';  -- 4262811
65909    -- 
65910    --
65911    -- set accounting line type info
65912    --
65913    xla_ae_lines_pkg.SetAcctLineType
65914       (p_component_type             => l_component_type
65915       ,p_event_type_code            => l_event_type_code
65916       ,p_line_definition_owner_code => l_line_definition_owner_code
65917       ,p_line_definition_code       => l_line_definition_code
65918       ,p_accounting_line_code       => l_component_code
65919       ,p_accounting_line_type_code  => l_component_type_code
65920       ,p_accounting_line_appl_id    => l_component_appl_id
65921       ,p_amb_context_code           => l_amb_context_code
65925    -- set accounting class
65922       ,p_entity_code                => l_entity_code
65923       ,p_event_class_code           => l_event_class_code);
65924    --
65926    --
65927    xla_ae_lines_pkg.SetAcctClass(
65928            p_accounting_class_code  => 'UNAPP'
65929          , p_ae_header_id           => l_ae_header_id
65930          );
65931 
65932    --
65933    -- set rounding class
65934    --
65935    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
65936                       'RECEIVABLE';
65937 
65938    --
65939    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
65940    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
65941    --
65942    -- bulk performance
65943    --
65944    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
65945 
65946    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
65947       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
65948 
65949    -- 4955764
65950    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
65951       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
65952 
65953    -- 4458381 Public Sector Enh
65954    
65955    --
65956    -- set accounting attributes for the line type
65957    --
65958    l_entered_amt_idx := 8;
65959    l_accted_amt_idx  := 13;
65960    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
65961    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
65962    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
65963    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
65964    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
65965    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
65966    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
65967    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
65968    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
65969    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
65970    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
65971    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
65972    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
65973    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
65974    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
65975    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
65976    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
65977    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
65978    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
65979    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
65980    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
65981    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
65982    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
65983    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
65984    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
65985    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
65986    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
65987    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
65988    l_rec_acct_attrs.array_num_value(14)  := p_source_76;
65989    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
65990    l_rec_acct_attrs.array_num_value(15)  := p_source_77;
65991    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
65992    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
65993 
65994    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
65995    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
65996 
65997    ---------------------------------------------------------------------------------------------------------------
65998    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
65999    ---------------------------------------------------------------------------------------------------------------
66000    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
66001 
66002    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
66003    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
66004 
66005    IF xla_accounting_cache_pkg.GetValueChar
66006          (p_source_code         => 'LEDGER_CATEGORY_CODE'
66007          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
66008    AND l_bflow_method_code = 'PRIOR_ENTRY'
66009 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
66010    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
66011          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
66012        )
66013    THEN
66014          xla_ae_lines_pkg.BflowUpgEntry
66015            (p_business_method_code    => l_bflow_method_code
66016            ,p_business_class_code     => l_bflow_class_code
66017            ,p_balance_type            => l_balance_type_code);
66018    ELSE
66019       NULL;
66020 -- No business flow processing for business flow method of NONE.
66021    END IF;
66022 
66023    --
66024    -- call analytical criteria
66028    -- call description
66025    --
66026    
66027    --
66029    --
66030    -- No description or it is inherited.
66031    --
66032    -- call ADRs
66033    -- Bug 4922099
66034    --
66035    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
66036         (NVL(l_actual_upg_option, 'N') = 'O') OR
66037         (NVL(l_enc_upg_option, 'N') = 'O')
66038       )
66039    THEN
66040    NULL;
66041    --
66042    --
66043    
66044   l_ccid := AcctDerRule_29(
66045            p_application_id           => p_application_id
66046          , p_ae_header_id             => l_ae_header_id 
66047 , p_source_17 => p_source_17
66048          , x_transaction_coa_id       => l_adr_transaction_coa_id
66049          , x_accounting_coa_id        => l_adr_accounting_coa_id
66050          , x_value_type_code          => l_adr_value_type_code
66051          , p_side                     => 'NA'
66052    );
66053 
66054    xla_ae_lines_pkg.set_ccid(
66055     p_code_combination_id          => l_ccid
66056   , p_value_type_code              => l_adr_value_type_code
66057   , p_transaction_coa_id           => l_adr_transaction_coa_id
66058   , p_accounting_coa_id            => l_adr_accounting_coa_id
66059   , p_adr_code                     => 'RMT_BNK_UNAPP_CCID'
66060   , p_adr_type_code                => 'S'
66061   , p_component_type               => l_component_type
66062   , p_component_code               => l_component_code
66063   , p_component_type_code          => l_component_type_code
66064   , p_component_appl_id            => l_component_appl_id
66065   , p_amb_context_code             => l_amb_context_code
66066   , p_side                         => 'NA'
66067   );
66068 
66069 
66070    --
66071    --
66072    END IF;
66073    --
66074    -- Bug 4922099
66075    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
66076           (NVL(l_enc_upg_option, 'N') = 'O')
66077         ) AND
66078         (l_bflow_method_code = 'PRIOR_ENTRY')
66079       )
66080    THEN
66081       IF
66082       --
66083       1 = 2
66084       --
66085       THEN
66086       xla_accounting_err_pkg.build_message
66087                                     (p_appli_s_name            => 'XLA'
66088                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
66089                                     ,p_token_1                 => 'LINE_NUMBER'
66090                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
66091                                     ,p_token_2                 => 'LINE_TYPE_NAME'
66092                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
66093                                                                              l_component_type
66094                                                                             ,l_component_code
66095                                                                             ,l_component_type_code
66096                                                                             ,l_component_appl_id
66097                                                                             ,l_amb_context_code
66098                                                                             ,l_entity_code
66099                                                                             ,l_event_class_code
66100                                                                            )
66101                                     ,p_token_3                 => 'OWNER'
66102                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
66103                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
66104                                                                           ,p_lookup_code    => l_component_type_code
66105                                                                          )
66106                                     ,p_token_4                 => 'PRODUCT_NAME'
66107                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
66108                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
66109                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
66110                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
66111                                     ,p_ae_header_id            =>  NULL
66112                                        );
66113 
66114         IF (C_LEVEL_ERROR>= g_log_level) THEN
66115                  trace
66116                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
66117                       ,p_level    => C_LEVEL_ERROR
66118                       ,p_module   => l_log_module);
66119         END IF;
66120       END IF;
66121    END IF;
66122    --
66123    --
66124    ------------------------------------------------------------------------------------------------
66125    -- 4219869 Business Flow
66126    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
66127    -- Prior Entry.  Currently, the following code is always generated.
66128    ------------------------------------------------------------------------------------------------
66129    XLA_AE_LINES_PKG.ValidateCurrentLine;
66130 
66134    ------------------------------------------------------------------------------------
66131    ------------------------------------------------------------------------------------
66132    -- 4219869 Business Flow
66133    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
66135    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
66136 
66137    ----------------------------------------------------------------------------------
66138    -- 4219869 Business Flow
66139    -- Update journal entry status -- Need to generate this within IF <condition>
66140    ----------------------------------------------------------------------------------
66141    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
66142          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
66143          ,p_balance_type_code => l_balance_type_code
66144          );
66145 
66146    -------------------------------------------------------------------------------------------
66147    -- 4262811 - Generate the Accrual Reversal lines
66148    -------------------------------------------------------------------------------------------
66149    BEGIN
66150       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
66151                               (g_array_event(p_event_id).array_value_num('header_index'));
66152       IF l_acc_rev_flag IS NULL THEN
66153          l_acc_rev_flag := 'N';
66154       END IF;
66155    EXCEPTION
66156       WHEN OTHERS THEN
66157          l_acc_rev_flag := 'N';
66158    END;
66159    --
66160    IF (l_acc_rev_flag = 'Y') THEN
66161 
66162        -- 4645092  ------------------------------------------------------------------------------
66163        -- To allow MPA report to determine if it should generate report process
66164        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
66165        ------------------------------------------------------------------------------------------
66166 
66167        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
66168        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
66169    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
66170    -- call ADRs
66171    -- Bug 4922099
66172    --
66173    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
66174         (NVL(l_actual_upg_option, 'N') = 'O') OR
66175         (NVL(l_enc_upg_option, 'N') = 'O')
66176       )
66177    THEN
66178    NULL;
66179    --
66180    --
66181    
66182   l_ccid := AcctDerRule_29(
66183            p_application_id           => p_application_id
66184          , p_ae_header_id             => l_ae_header_id 
66185 , p_source_17 => p_source_17
66186          , x_transaction_coa_id       => l_adr_transaction_coa_id
66187          , x_accounting_coa_id        => l_adr_accounting_coa_id
66188          , x_value_type_code          => l_adr_value_type_code
66189          , p_side                     => 'NA'
66190    );
66191 
66192    xla_ae_lines_pkg.set_ccid(
66193     p_code_combination_id          => l_ccid
66194   , p_value_type_code              => l_adr_value_type_code
66195   , p_transaction_coa_id           => l_adr_transaction_coa_id
66196   , p_accounting_coa_id            => l_adr_accounting_coa_id
66197   , p_adr_code                     => 'RMT_BNK_UNAPP_CCID'
66198   , p_adr_type_code                => 'S'
66199   , p_component_type               => l_component_type
66200   , p_component_code               => l_component_code
66201   , p_component_type_code          => l_component_type_code
66202   , p_component_appl_id            => l_component_appl_id
66203   , p_amb_context_code             => l_amb_context_code
66204   , p_side                         => 'NA'
66205   );
66206 
66207 
66208    --
66209    --
66210    END IF;
66211 
66212        --
66213        -- Update the line information that should be overwritten
66214        --
66215        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
66216                                          p_header_num   => 1);
66217        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
66218 
66219        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
66220 
66221        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
66222           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
66223        END IF;
66224 
66225       --
66226       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
66227       --
66228       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
66229           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
66230       ELSE
66231           ---------------------------------------------------------------------------------------------------
66232           -- 4262811a Switch Sign
66233           ---------------------------------------------------------------------------------------------------
66234           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
66235           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
66236                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
66240           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
66237           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
66238                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
66239           -- 5132302
66241                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
66242 
66243       END IF;
66244 
66245       -- 4955764
66246       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
66247       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
66248 
66249 
66250       XLA_AE_LINES_PKG.ValidateCurrentLine;
66251       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
66252 
66253       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
66254                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
66255                ,p_balance_type_code => l_balance_type_code);
66256 
66257    END IF;
66258 
66259    -----------------------------------------------------------------------------------------
66260    -- 4262811 Multiperiod Accounting
66261    -----------------------------------------------------------------------------------------
66262      -- No MPA option is assigned.
66263 
66264 
66265 END IF;
66266 END IF;
66267 --
66268 
66269 --
66270 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
66271    trace
66272       (p_msg      => 'END of AcctLineType_131'
66273       ,p_level    => C_LEVEL_PROCEDURE
66274       ,p_module   => l_log_module);
66275 END IF;
66276 --
66277 EXCEPTION
66278   WHEN xla_exceptions_pkg.application_exception THEN
66279       RAISE;
66280   WHEN OTHERS THEN
66281        xla_exceptions_pkg.raise_message
66282            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_131');
66283 END AcctLineType_131;
66284 --
66285 
66286 ---------------------------------------
66287 --
66288 -- PRIVATE FUNCTION
66289 --         AcctLineType_132
66290 --
66291 ---------------------------------------
66292 PROCEDURE AcctLineType_132 (
66293   p_application_id        IN NUMBER
66294  ,p_event_id              IN NUMBER
66295  ,p_calculate_acctd_flag  IN VARCHAR2
66296  ,p_calculate_g_l_flag    IN VARCHAR2
66297  ,p_actual_flag           IN OUT VARCHAR2
66298  ,p_balance_type_code     OUT VARCHAR2
66299  ,p_gain_or_loss_ref      OUT VARCHAR2
66300  
66301 --Remittance Bank Account Unapplied Account
66302  , p_source_17            IN NUMBER
66303 --Distribution Source Type
66304  , p_source_20            IN VARCHAR2
66305 --Distribution Line Identifier
66306  , p_source_22            IN NUMBER
66307 --Distribution Type
66308  , p_source_23            IN VARCHAR2
66309 --Exchange Date
66310  , p_source_26            IN DATE
66311 --Exchange Rate
66312  , p_source_27            IN NUMBER
66313 --Exchange Rate Type
66314  , p_source_28            IN VARCHAR2
66315 --Transaction Distribution Identifier
66316  , p_source_34            IN NUMBER
66317 --Transaction Distribution Type
66318  , p_source_35            IN VARCHAR2
66319 --Receipt Applied To Application Identifier
66320  , p_source_58            IN NUMBER
66321 --Transaction Entity Code
66322  , p_source_59            IN VARCHAR2
66323 --Transaction Identifier
66324  , p_source_60            IN NUMBER
66325 --Applying Document Currency Code
66326  , p_source_61            IN VARCHAR2
66327 --Distribution Party Type
66328  , p_source_65            IN VARCHAR2
66329 --Distribution Multi Fund Additional Entry
66330  , p_source_69            IN VARCHAR2
66331 --DIST_ENT_AMT_FROM
66332  , p_source_72            IN NUMBER
66333 --Accounting Amount
66334  , p_source_73            IN NUMBER
66335 --Distribution Source Table
66336  , p_source_75            IN VARCHAR2
66337 --Receipt Pay From Customer
66338  , p_source_76            IN NUMBER
66339 --Receipt Customer Site Use Identifier
66340  , p_source_77            IN NUMBER
66341 --Receipt Application Status
66342  , p_source_78            IN VARCHAR2
66343 )
66344 IS
66345 
66346 l_component_type              VARCHAR2(80);
66347 l_component_code              VARCHAR2(30);
66348 l_component_type_code         VARCHAR2(1);
66349 l_component_appl_id           INTEGER;
66350 l_amb_context_code            VARCHAR2(30);
66351 l_entity_code                 VARCHAR2(30);
66352 l_event_class_code            VARCHAR2(30);
66353 l_ae_header_id                NUMBER;
66354 l_event_type_code             VARCHAR2(30);
66355 l_line_definition_code        VARCHAR2(30);
66356 l_line_definition_owner_code  VARCHAR2(1);
66357 --
66358 -- adr variables
66359 l_segment                     VARCHAR2(30);
66360 l_ccid                        NUMBER;
66361 l_adr_transaction_coa_id      NUMBER;
66362 l_adr_accounting_coa_id       NUMBER;
66363 l_adr_flexfield_segment_code  VARCHAR2(30);
66364 l_adr_flex_value_set_id       NUMBER;
66365 l_adr_value_type_code         VARCHAR2(30);
66366 l_adr_value_combination_id    NUMBER;
66367 l_adr_value_segment_code      VARCHAR2(30);
66368 
66369 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
66370 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
66371 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
66375 l_entered_amt_idx             NUMBER;
66372 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
66373 
66374 -- 4262811 Variables ------------------------------------------------------------------------------------------
66376 l_accted_amt_idx              NUMBER;
66377 l_acc_rev_flag                VARCHAR2(1);
66378 l_accrual_line_num            NUMBER;
66379 l_tmp_amt                     NUMBER;
66380 l_acc_rev_natural_side_code   VARCHAR2(1);
66381 
66382 l_num_entries                 NUMBER;
66383 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
66384 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
66385 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
66386 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
66387 l_recog_line_1                NUMBER;
66388 l_recog_line_2                NUMBER;
66389 
66390 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
66391 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
66392 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
66393 
66394 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
66395 
66396 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
66397 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
66398 
66399 ---------------------------------------------------------------------------------------------------------------
66400 
66401 
66402 --
66403 -- bulk performance
66404 --
66405 l_balance_type_code           VARCHAR2(1);
66406 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
66407 l_log_module                  VARCHAR2(240);
66408 
66409 --
66410 -- Upgrade strategy
66411 --
66412 l_actual_upg_option           VARCHAR2(1);
66413 l_enc_upg_option           VARCHAR2(1);
66414 
66415 --
66416 BEGIN
66417 --
66418 IF g_log_enabled THEN
66419       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_132';
66420 END IF;
66421 --
66422 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
66423 
66424       trace
66425          (p_msg      => 'BEGIN of AcctLineType_132'
66426          ,p_level    => C_LEVEL_PROCEDURE
66427          ,p_module   => l_log_module);
66428 
66429 END IF;
66430 --
66431 l_component_type             := 'AMB_JLT';
66432 l_component_code             := 'RCT_UNAPP_DEBIT';
66433 l_component_type_code        := 'S';
66434 l_component_appl_id          :=  222;
66435 l_amb_context_code           := 'DEFAULT';
66436 l_entity_code                := 'RECEIPTS';
66437 l_event_class_code           := 'RECEIPT';
66438 l_event_type_code            := 'RECEIPT_ALL';
66439 l_line_definition_owner_code := 'S';
66440 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
66441 --
66442 l_balance_type_code          := 'A';
66443 l_segment                     := NULL;
66444 l_ccid                        := NULL;
66445 l_adr_transaction_coa_id      := NULL;
66446 l_adr_accounting_coa_id       := NULL;
66447 l_adr_flexfield_segment_code  := NULL;
66448 l_adr_flex_value_set_id       := NULL;
66449 l_adr_value_type_code         := NULL;
66450 l_adr_value_combination_id    := NULL;
66451 l_adr_value_segment_code      := NULL;
66452 
66453 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
66454 l_bflow_class_code           := '';    -- 4219869 Business Flow
66455 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
66456 l_budgetary_control_flag     := 'N';
66457 
66458 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
66459 l_bflow_applied_to_amt       := NULL; -- 5132302
66460 l_entered_amt_idx            := NULL;          -- 4262811
66461 l_accted_amt_idx             := NULL;          -- 4262811
66462 l_acc_rev_flag               := NULL;          -- 4262811
66463 l_accrual_line_num           := NULL;          -- 4262811
66464 l_tmp_amt                    := NULL;          -- 4262811
66465 --
66466  
66467 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
66468     l_balance_type_code <> 'B' THEN
66469 IF ((NVL(p_source_20,'
66470 ') =  'REC' AND 
66471 NVL(p_source_69,'
66472 ') =  'N') OR 
66473 (NVL(p_source_69,'
66474 ') =  'N' AND 
66475 NVL(p_source_20,'
66476 ') =  'CASH') OR 
66477 (NVL(p_source_69,'
66478 ') =  'N' AND 
66479 NVL(p_source_20,'
66480 ') =  'CONFIRMATION') OR 
66481 (NVL(p_source_69,'
66482 ') =  'N' AND 
66483 NVL(p_source_20,'
66484 ') =  'CURR_ROUND') OR 
66485 (NVL(p_source_69,'
66486 ') =  'N' AND 
66487 NVL(p_source_20,'
66488 ') =  'DEFERRED_TAX') OR 
66489 (NVL(p_source_69,'
66490 ') =  'N' AND 
66491 NVL(p_source_75,'
66492 ') =  'CRH' AND 
66493 NVL(p_source_20,'
66494 ') =  'FACTOR') OR 
66495 (NVL(p_source_69,'
66496 ') =  'N' AND 
66497 NVL(p_source_20,'
66498 ') =  'ACC') OR 
66499 (NVL(p_source_69,'
66500 ') =  'N' AND 
66501 NVL(p_source_20,'
66502 ') =  'REMITTANCE' AND 
66503 NVL(p_source_75,'
66504 ') =  'CRH') OR 
66505 (NVL(p_source_69,'
66506 ') =  'N' AND 
66507 NVL(p_source_20,'
66508 ') =  'SHORT_TERM_DEBT') OR 
66509 (NVL(p_source_69,'
66510 ') =  'N' AND 
66511 NVL(p_source_20,'
66512 ') =  'TAX') OR 
66513 (NVL(p_source_69,'
66514 ') =  'N' AND 
66515 NVL(p_source_20,'
66519 NVL(p_source_20,'
66516 ') =  'UNID') OR 
66517 (NVL(p_source_69,'
66518 ') =  'N' AND 
66520 ') =  'BANK_CHARGES') OR 
66521 (NVL(p_source_69,'
66522 ') =  'N' AND 
66523 NVL(p_source_20,'
66524 ') =  'EDISC') OR 
66525 (NVL(p_source_69,'
66526 ') =  'N' AND 
66527 NVL(p_source_20,'
66528 ') =  'UNEDISC')
66529 ) AND NVL(p_source_78,'
66530 ') <>  'UNID'
66531  THEN 
66532 
66533    --
66534    XLA_AE_LINES_PKG.SetNewLine;
66535 
66536    p_balance_type_code          := l_balance_type_code;
66537    -- set the flag so later we will know whether the gain loss line needs to be created
66538    
66539    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
66540      p_actual_flag :='A';
66541    END IF;
66542 
66543    --
66544    -- bulk performance
66545    --
66546    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
66547                                       p_header_num   => 0); -- 4262811
66548    --
66549    -- set accounting line options
66550    --
66551    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
66552            p_natural_side_code          => 'D'
66553          , p_gain_or_loss_flag          => 'N'
66554          , p_gl_transfer_mode_code      => 'S'
66555          , p_acct_entry_type_code       => 'A'
66556          , p_switch_side_flag           => 'Y'
66557          , p_merge_duplicate_code       => 'A'
66558          );
66559    --
66560    l_acc_rev_natural_side_code := 'C';  -- 4262811
66561    -- 
66562    --
66563    -- set accounting line type info
66564    --
66565    xla_ae_lines_pkg.SetAcctLineType
66566       (p_component_type             => l_component_type
66567       ,p_event_type_code            => l_event_type_code
66568       ,p_line_definition_owner_code => l_line_definition_owner_code
66569       ,p_line_definition_code       => l_line_definition_code
66570       ,p_accounting_line_code       => l_component_code
66571       ,p_accounting_line_type_code  => l_component_type_code
66572       ,p_accounting_line_appl_id    => l_component_appl_id
66573       ,p_amb_context_code           => l_amb_context_code
66574       ,p_entity_code                => l_entity_code
66575       ,p_event_class_code           => l_event_class_code);
66576    --
66577    -- set accounting class
66578    --
66579    xla_ae_lines_pkg.SetAcctClass(
66580            p_accounting_class_code  => 'UNAPP'
66581          , p_ae_header_id           => l_ae_header_id
66582          );
66583 
66584    --
66585    -- set rounding class
66586    --
66587    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
66588                       'RECEIVABLE';
66589 
66590    --
66591    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
66592    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
66593    --
66594    -- bulk performance
66595    --
66596    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
66597 
66598    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
66599       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
66600 
66601    -- 4955764
66602    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
66603       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
66604 
66605    -- 4458381 Public Sector Enh
66606    
66607    --
66608    -- set accounting attributes for the line type
66609    --
66610    l_entered_amt_idx := 8;
66611    l_accted_amt_idx  := 13;
66612    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
66613    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
66614    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
66615    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
66616    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
66617    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
66618    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
66619    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
66620    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
66621    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
66622    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
66623    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
66624    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
66625    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
66626    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
66627    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
66628    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
66629    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
66630    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
66631    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
66632    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
66633    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
66634    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
66635    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
66636    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
66637    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
66641    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
66638    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
66639    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
66640    l_rec_acct_attrs.array_num_value(14)  := p_source_76;
66642    l_rec_acct_attrs.array_num_value(15)  := p_source_77;
66643    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
66644    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
66645 
66646    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
66647    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
66648 
66649    ---------------------------------------------------------------------------------------------------------------
66650    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
66651    ---------------------------------------------------------------------------------------------------------------
66652    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
66653 
66654    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
66655    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
66656 
66657    IF xla_accounting_cache_pkg.GetValueChar
66658          (p_source_code         => 'LEDGER_CATEGORY_CODE'
66659          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
66660    AND l_bflow_method_code = 'PRIOR_ENTRY'
66661 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
66662    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
66663          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
66664        )
66665    THEN
66666          xla_ae_lines_pkg.BflowUpgEntry
66667            (p_business_method_code    => l_bflow_method_code
66668            ,p_business_class_code     => l_bflow_class_code
66669            ,p_balance_type            => l_balance_type_code);
66670    ELSE
66671       NULL;
66672 -- No business flow processing for business flow method of NONE.
66673    END IF;
66674 
66675    --
66676    -- call analytical criteria
66677    --
66678    
66679    --
66680    -- call description
66681    --
66682    -- No description or it is inherited.
66683    --
66684    -- call ADRs
66685    -- Bug 4922099
66686    --
66687    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
66688         (NVL(l_actual_upg_option, 'N') = 'O') OR
66689         (NVL(l_enc_upg_option, 'N') = 'O')
66690       )
66691    THEN
66692    NULL;
66693    --
66694    --
66695    
66696   l_ccid := AcctDerRule_29(
66697            p_application_id           => p_application_id
66698          , p_ae_header_id             => l_ae_header_id 
66699 , p_source_17 => p_source_17
66700          , x_transaction_coa_id       => l_adr_transaction_coa_id
66701          , x_accounting_coa_id        => l_adr_accounting_coa_id
66702          , x_value_type_code          => l_adr_value_type_code
66703          , p_side                     => 'NA'
66704    );
66705 
66706    xla_ae_lines_pkg.set_ccid(
66707     p_code_combination_id          => l_ccid
66708   , p_value_type_code              => l_adr_value_type_code
66709   , p_transaction_coa_id           => l_adr_transaction_coa_id
66710   , p_accounting_coa_id            => l_adr_accounting_coa_id
66711   , p_adr_code                     => 'RMT_BNK_UNAPP_CCID'
66712   , p_adr_type_code                => 'S'
66713   , p_component_type               => l_component_type
66714   , p_component_code               => l_component_code
66715   , p_component_type_code          => l_component_type_code
66716   , p_component_appl_id            => l_component_appl_id
66717   , p_amb_context_code             => l_amb_context_code
66718   , p_side                         => 'NA'
66719   );
66720 
66721 
66722    --
66723    --
66724    END IF;
66725    --
66726    -- Bug 4922099
66727    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
66728           (NVL(l_enc_upg_option, 'N') = 'O')
66729         ) AND
66730         (l_bflow_method_code = 'PRIOR_ENTRY')
66731       )
66732    THEN
66733       IF
66734       --
66735       1 = 2
66736       --
66737       THEN
66738       xla_accounting_err_pkg.build_message
66739                                     (p_appli_s_name            => 'XLA'
66740                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
66741                                     ,p_token_1                 => 'LINE_NUMBER'
66742                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
66743                                     ,p_token_2                 => 'LINE_TYPE_NAME'
66744                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
66745                                                                              l_component_type
66746                                                                             ,l_component_code
66747                                                                             ,l_component_type_code
66748                                                                             ,l_component_appl_id
66749                                                                             ,l_amb_context_code
66750                                                                             ,l_entity_code
66754                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
66751                                                                             ,l_event_class_code
66752                                                                            )
66753                                     ,p_token_3                 => 'OWNER'
66755                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
66756                                                                           ,p_lookup_code    => l_component_type_code
66757                                                                          )
66758                                     ,p_token_4                 => 'PRODUCT_NAME'
66759                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
66760                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
66761                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
66762                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
66763                                     ,p_ae_header_id            =>  NULL
66764                                        );
66765 
66766         IF (C_LEVEL_ERROR>= g_log_level) THEN
66767                  trace
66768                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
66769                       ,p_level    => C_LEVEL_ERROR
66770                       ,p_module   => l_log_module);
66771         END IF;
66772       END IF;
66773    END IF;
66774    --
66775    --
66776    ------------------------------------------------------------------------------------------------
66777    -- 4219869 Business Flow
66778    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
66779    -- Prior Entry.  Currently, the following code is always generated.
66780    ------------------------------------------------------------------------------------------------
66781    XLA_AE_LINES_PKG.ValidateCurrentLine;
66782 
66783    ------------------------------------------------------------------------------------
66784    -- 4219869 Business Flow
66785    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
66786    ------------------------------------------------------------------------------------
66787    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
66788 
66789    ----------------------------------------------------------------------------------
66790    -- 4219869 Business Flow
66791    -- Update journal entry status -- Need to generate this within IF <condition>
66792    ----------------------------------------------------------------------------------
66793    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
66794          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
66795          ,p_balance_type_code => l_balance_type_code
66796          );
66797 
66798    -------------------------------------------------------------------------------------------
66799    -- 4262811 - Generate the Accrual Reversal lines
66800    -------------------------------------------------------------------------------------------
66801    BEGIN
66802       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
66803                               (g_array_event(p_event_id).array_value_num('header_index'));
66804       IF l_acc_rev_flag IS NULL THEN
66805          l_acc_rev_flag := 'N';
66806       END IF;
66807    EXCEPTION
66808       WHEN OTHERS THEN
66809          l_acc_rev_flag := 'N';
66810    END;
66811    --
66812    IF (l_acc_rev_flag = 'Y') THEN
66813 
66814        -- 4645092  ------------------------------------------------------------------------------
66815        -- To allow MPA report to determine if it should generate report process
66816        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
66817        ------------------------------------------------------------------------------------------
66818 
66819        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
66820        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
66821    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
66822    -- call ADRs
66823    -- Bug 4922099
66824    --
66825    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
66826         (NVL(l_actual_upg_option, 'N') = 'O') OR
66827         (NVL(l_enc_upg_option, 'N') = 'O')
66828       )
66829    THEN
66830    NULL;
66831    --
66832    --
66833    
66834   l_ccid := AcctDerRule_29(
66835            p_application_id           => p_application_id
66836          , p_ae_header_id             => l_ae_header_id 
66837 , p_source_17 => p_source_17
66838          , x_transaction_coa_id       => l_adr_transaction_coa_id
66839          , x_accounting_coa_id        => l_adr_accounting_coa_id
66840          , x_value_type_code          => l_adr_value_type_code
66841          , p_side                     => 'NA'
66842    );
66843 
66844    xla_ae_lines_pkg.set_ccid(
66845     p_code_combination_id          => l_ccid
66846   , p_value_type_code              => l_adr_value_type_code
66847   , p_transaction_coa_id           => l_adr_transaction_coa_id
66848   , p_accounting_coa_id            => l_adr_accounting_coa_id
66849   , p_adr_code                     => 'RMT_BNK_UNAPP_CCID'
66850   , p_adr_type_code                => 'S'
66854   , p_component_appl_id            => l_component_appl_id
66851   , p_component_type               => l_component_type
66852   , p_component_code               => l_component_code
66853   , p_component_type_code          => l_component_type_code
66855   , p_amb_context_code             => l_amb_context_code
66856   , p_side                         => 'NA'
66857   );
66858 
66859 
66860    --
66861    --
66862    END IF;
66863 
66864        --
66865        -- Update the line information that should be overwritten
66866        --
66867        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
66868                                          p_header_num   => 1);
66869        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
66870 
66871        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
66872 
66873        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
66874           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
66875        END IF;
66876 
66877       --
66878       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
66879       --
66880       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
66881           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
66882       ELSE
66883           ---------------------------------------------------------------------------------------------------
66884           -- 4262811a Switch Sign
66885           ---------------------------------------------------------------------------------------------------
66886           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
66887           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
66888                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
66889           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
66890                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
66891           -- 5132302
66892           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
66893                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
66894 
66895       END IF;
66896 
66897       -- 4955764
66898       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
66899       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
66900 
66901 
66902       XLA_AE_LINES_PKG.ValidateCurrentLine;
66903       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
66904 
66905       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
66906                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
66907                ,p_balance_type_code => l_balance_type_code);
66908 
66909    END IF;
66910 
66911    -----------------------------------------------------------------------------------------
66912    -- 4262811 Multiperiod Accounting
66913    -----------------------------------------------------------------------------------------
66914      -- No MPA option is assigned.
66915 
66916 
66917 END IF;
66918 END IF;
66919 --
66920 
66921 --
66922 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
66923    trace
66924       (p_msg      => 'END of AcctLineType_132'
66925       ,p_level    => C_LEVEL_PROCEDURE
66926       ,p_module   => l_log_module);
66927 END IF;
66928 --
66929 EXCEPTION
66930   WHEN xla_exceptions_pkg.application_exception THEN
66931       RAISE;
66932   WHEN OTHERS THEN
66933        xla_exceptions_pkg.raise_message
66934            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_132');
66935 END AcctLineType_132;
66936 --
66937 
66938 ---------------------------------------
66939 --
66940 -- PRIVATE FUNCTION
66941 --         AcctLineType_133
66942 --
66943 ---------------------------------------
66944 PROCEDURE AcctLineType_133 (
66945   p_application_id        IN NUMBER
66946  ,p_event_id              IN NUMBER
66947  ,p_calculate_acctd_flag  IN VARCHAR2
66948  ,p_calculate_g_l_flag    IN VARCHAR2
66949  ,p_actual_flag           IN OUT VARCHAR2
66950  ,p_balance_type_code     OUT VARCHAR2
66951  ,p_gain_or_loss_ref      OUT VARCHAR2
66952  
66953 --Distribution GL Account
66954  , p_source_3            IN NUMBER
66955 --Transaction Distribution GL Account
66956  , p_source_4            IN NUMBER
66957 --Distribution Source Type
66958  , p_source_20            IN VARCHAR2
66959 --Distribution Line Identifier
66960  , p_source_22            IN NUMBER
66961 --Distribution Type
66962  , p_source_23            IN VARCHAR2
66963 --Entered Amount
66964  , p_source_24            IN NUMBER
66965 --Currency Code
66966  , p_source_25            IN VARCHAR2
66967 --Applied To Document Accounting Amount
66968  , p_source_29            IN NUMBER
66969 --Transaction Distribution Identifier
66970  , p_source_34            IN NUMBER
66971 --Transaction Distribution Type
66972  , p_source_35            IN VARCHAR2
66973 --Applied To Document Exchange Date
66974  , p_source_57            IN DATE
66975 --Receipt Applied To Application Identifier
66979 --Transaction Identifier
66976  , p_source_58            IN NUMBER
66977 --Transaction Entity Code
66978  , p_source_59            IN VARCHAR2
66980  , p_source_60            IN NUMBER
66981 --Applied To Document Exchange Rate
66982  , p_source_62            IN NUMBER
66983 --Distribution Party Identifier
66984  , p_source_63            IN NUMBER
66985 --Distribution Party Site Id
66986  , p_source_64            IN NUMBER
66987 --Distribution Party Type
66988  , p_source_65            IN VARCHAR2
66989 --Distribution Multi Fund Additional Entry
66990  , p_source_69            IN VARCHAR2
66991 --Applied To Document Exchange Rate Type
66992  , p_source_74            IN VARCHAR2
66993 )
66994 IS
66995 
66996 l_component_type              VARCHAR2(80);
66997 l_component_code              VARCHAR2(30);
66998 l_component_type_code         VARCHAR2(1);
66999 l_component_appl_id           INTEGER;
67000 l_amb_context_code            VARCHAR2(30);
67001 l_entity_code                 VARCHAR2(30);
67002 l_event_class_code            VARCHAR2(30);
67003 l_ae_header_id                NUMBER;
67004 l_event_type_code             VARCHAR2(30);
67005 l_line_definition_code        VARCHAR2(30);
67006 l_line_definition_owner_code  VARCHAR2(1);
67007 --
67008 -- adr variables
67009 l_segment                     VARCHAR2(30);
67010 l_ccid                        NUMBER;
67011 l_adr_transaction_coa_id      NUMBER;
67012 l_adr_accounting_coa_id       NUMBER;
67013 l_adr_flexfield_segment_code  VARCHAR2(30);
67014 l_adr_flex_value_set_id       NUMBER;
67015 l_adr_value_type_code         VARCHAR2(30);
67016 l_adr_value_combination_id    NUMBER;
67017 l_adr_value_segment_code      VARCHAR2(30);
67018 
67019 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
67020 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
67021 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
67022 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
67023 
67024 -- 4262811 Variables ------------------------------------------------------------------------------------------
67025 l_entered_amt_idx             NUMBER;
67026 l_accted_amt_idx              NUMBER;
67027 l_acc_rev_flag                VARCHAR2(1);
67028 l_accrual_line_num            NUMBER;
67029 l_tmp_amt                     NUMBER;
67030 l_acc_rev_natural_side_code   VARCHAR2(1);
67031 
67032 l_num_entries                 NUMBER;
67033 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
67034 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
67035 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
67036 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
67037 l_recog_line_1                NUMBER;
67038 l_recog_line_2                NUMBER;
67039 
67040 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
67041 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
67042 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
67043 
67044 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
67045 
67046 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
67047 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
67048 
67049 ---------------------------------------------------------------------------------------------------------------
67050 
67051 
67052 --
67053 -- bulk performance
67054 --
67055 l_balance_type_code           VARCHAR2(1);
67056 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
67057 l_log_module                  VARCHAR2(240);
67058 
67059 --
67060 -- Upgrade strategy
67061 --
67062 l_actual_upg_option           VARCHAR2(1);
67063 l_enc_upg_option           VARCHAR2(1);
67064 
67065 --
67066 BEGIN
67067 --
67068 IF g_log_enabled THEN
67069       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_133';
67070 END IF;
67071 --
67072 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
67073 
67074       trace
67075          (p_msg      => 'BEGIN of AcctLineType_133'
67076          ,p_level    => C_LEVEL_PROCEDURE
67077          ,p_module   => l_log_module);
67078 
67079 END IF;
67080 --
67081 l_component_type             := 'AMB_JLT';
67082 l_component_code             := 'RCT_UNEDISC';
67083 l_component_type_code        := 'S';
67084 l_component_appl_id          :=  222;
67085 l_amb_context_code           := 'DEFAULT';
67086 l_entity_code                := 'RECEIPTS';
67087 l_event_class_code           := 'RECEIPT';
67088 l_event_type_code            := 'RECEIPT_ALL';
67089 l_line_definition_owner_code := 'S';
67090 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
67091 --
67092 l_balance_type_code          := 'A';
67093 l_segment                     := NULL;
67094 l_ccid                        := NULL;
67095 l_adr_transaction_coa_id      := NULL;
67096 l_adr_accounting_coa_id       := NULL;
67097 l_adr_flexfield_segment_code  := NULL;
67098 l_adr_flex_value_set_id       := NULL;
67099 l_adr_value_type_code         := NULL;
67100 l_adr_value_combination_id    := NULL;
67101 l_adr_value_segment_code      := NULL;
67102 
67103 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
67104 l_bflow_class_code           := '';    -- 4219869 Business Flow
67108 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
67105 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
67106 l_budgetary_control_flag     := 'N';
67107 
67109 l_bflow_applied_to_amt       := NULL; -- 5132302
67110 l_entered_amt_idx            := NULL;          -- 4262811
67111 l_accted_amt_idx             := NULL;          -- 4262811
67112 l_acc_rev_flag               := NULL;          -- 4262811
67113 l_accrual_line_num           := NULL;          -- 4262811
67114 l_tmp_amt                    := NULL;          -- 4262811
67115 --
67116  
67117 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
67118     l_balance_type_code <> 'B' THEN
67119 IF NVL(p_source_20,'
67120 ') =  'UNEDISC' AND 
67121 NVL(p_source_69,'
67122 ') =  'N'
67123  THEN 
67124 
67125    --
67126    XLA_AE_LINES_PKG.SetNewLine;
67127 
67128    p_balance_type_code          := l_balance_type_code;
67129    -- set the flag so later we will know whether the gain loss line needs to be created
67130    
67131    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
67132      p_actual_flag :='A';
67133    END IF;
67134 
67135    --
67136    -- bulk performance
67137    --
67138    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
67139                                       p_header_num   => 0); -- 4262811
67140    --
67141    -- set accounting line options
67142    --
67143    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
67144            p_natural_side_code          => 'C'
67145          , p_gain_or_loss_flag          => 'N'
67146          , p_gl_transfer_mode_code      => 'S'
67147          , p_acct_entry_type_code       => 'A'
67148          , p_switch_side_flag           => 'Y'
67149          , p_merge_duplicate_code       => 'A'
67150          );
67151    --
67152    l_acc_rev_natural_side_code := 'D';  -- 4262811
67153    -- 
67154    --
67155    -- set accounting line type info
67156    --
67157    xla_ae_lines_pkg.SetAcctLineType
67158       (p_component_type             => l_component_type
67159       ,p_event_type_code            => l_event_type_code
67160       ,p_line_definition_owner_code => l_line_definition_owner_code
67161       ,p_line_definition_code       => l_line_definition_code
67162       ,p_accounting_line_code       => l_component_code
67163       ,p_accounting_line_type_code  => l_component_type_code
67164       ,p_accounting_line_appl_id    => l_component_appl_id
67165       ,p_amb_context_code           => l_amb_context_code
67166       ,p_entity_code                => l_entity_code
67167       ,p_event_class_code           => l_event_class_code);
67168    --
67169    -- set accounting class
67170    --
67171    xla_ae_lines_pkg.SetAcctClass(
67172            p_accounting_class_code  => 'UNEDISC'
67173          , p_ae_header_id           => l_ae_header_id
67174          );
67175 
67176    --
67177    -- set rounding class
67178    --
67179    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
67180                       'RECEIVABLE';
67181 
67182    --
67183    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
67184    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
67185    --
67186    -- bulk performance
67187    --
67188    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
67189 
67190    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
67191       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
67192 
67193    -- 4955764
67194    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
67195       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
67196 
67197    -- 4458381 Public Sector Enh
67198    
67199    --
67200    -- set accounting attributes for the line type
67201    --
67202    l_entered_amt_idx := 8;
67203    l_accted_amt_idx  := 13;
67204    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
67205    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
67206    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
67207    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
67208    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
67209    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
67210    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
67211    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
67212    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
67213    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
67214    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
67215    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
67216    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
67217    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
67218    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
67219    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
67220    l_rec_acct_attrs.array_num_value(8)  := p_source_24;
67221    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
67225    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
67222    l_rec_acct_attrs.array_char_value(9)  := p_source_25;
67223    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
67224    l_rec_acct_attrs.array_date_value(10)  := p_source_57;
67226    l_rec_acct_attrs.array_num_value(11)  := p_source_62;
67227    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
67228    l_rec_acct_attrs.array_char_value(12)  := p_source_74;
67229    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
67230    l_rec_acct_attrs.array_num_value(13)  := p_source_29;
67231    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
67232    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
67233    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
67234    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
67235    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
67236    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
67237 
67238    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
67239    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
67240 
67241    ---------------------------------------------------------------------------------------------------------------
67242    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
67243    ---------------------------------------------------------------------------------------------------------------
67244    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
67245 
67246    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
67247    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
67248 
67249    IF xla_accounting_cache_pkg.GetValueChar
67250          (p_source_code         => 'LEDGER_CATEGORY_CODE'
67251          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
67252    AND l_bflow_method_code = 'PRIOR_ENTRY'
67253 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
67254    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
67255          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
67256        )
67257    THEN
67258          xla_ae_lines_pkg.BflowUpgEntry
67259            (p_business_method_code    => l_bflow_method_code
67260            ,p_business_class_code     => l_bflow_class_code
67261            ,p_balance_type            => l_balance_type_code);
67262    ELSE
67263       NULL;
67264 -- No business flow processing for business flow method of NONE.
67265    END IF;
67266 
67267    --
67268    -- call analytical criteria
67269    --
67270    
67271    --
67272    -- call description
67273    --
67274    
67275 xla_ae_lines_pkg.SetLineDescription(
67276    p_ae_header_id => l_ae_header_id
67277   ,p_description  => Description_1 (
67278      p_application_id         => p_application_id
67279    , p_ae_header_id           => l_ae_header_id 
67280    )
67281 );
67282 
67283 
67284    --
67285    -- call ADRs
67286    -- Bug 4922099
67287    --
67288    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
67289         (NVL(l_actual_upg_option, 'N') = 'O') OR
67290         (NVL(l_enc_upg_option, 'N') = 'O')
67291       )
67292    THEN
67293    NULL;
67294    --
67295    --
67296    
67297   l_ccid := AcctDerRule_7(
67298            p_application_id           => p_application_id
67299          , p_ae_header_id             => l_ae_header_id 
67300 , p_source_3 => p_source_3
67301          , x_transaction_coa_id       => l_adr_transaction_coa_id
67302          , x_accounting_coa_id        => l_adr_accounting_coa_id
67303          , x_value_type_code          => l_adr_value_type_code
67304          , p_side                     => 'NA'
67305    );
67306 
67307    xla_ae_lines_pkg.set_ccid(
67308     p_code_combination_id          => l_ccid
67309   , p_value_type_code              => l_adr_value_type_code
67310   , p_transaction_coa_id           => l_adr_transaction_coa_id
67311   , p_accounting_coa_id            => l_adr_accounting_coa_id
67312   , p_adr_code                     => 'DIST_CCID'
67313   , p_adr_type_code                => 'S'
67314   , p_component_type               => l_component_type
67315   , p_component_code               => l_component_code
67316   , p_component_type_code          => l_component_type_code
67317   , p_component_appl_id            => l_component_appl_id
67318   , p_amb_context_code             => l_amb_context_code
67319   , p_side                         => 'NA'
67320   );
67321 
67322 
67323    l_segment := AcctDerRule_5(
67324            p_application_id           => p_application_id
67325          , p_ae_header_id             => l_ae_header_id 
67326 , p_source_4 => p_source_4
67327          , x_transaction_coa_id       => l_adr_transaction_coa_id
67328          , x_accounting_coa_id        => l_adr_accounting_coa_id
67329          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
67330          , x_flex_value_set_id        => l_adr_flex_value_set_id
67331          , x_value_type_code          => l_adr_value_type_code
67332          , x_value_combination_id     => l_adr_value_combination_id
67333          , x_value_segment_code       => l_adr_value_segment_code
67334          , p_side                     => 'NA'
67335          , p_override_seg_flag        => 'Y'
67339 
67336    );
67337 
67338    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
67340       xla_ae_lines_pkg.set_segment(
67341           p_to_segment_code         => 'GL_BALANCING'
67342         , p_segment_value           => l_segment
67343         , p_from_segment_code       => l_adr_value_segment_code
67344         , p_from_combination_id     => l_adr_value_combination_id
67345         , p_value_type_code         => l_adr_value_type_code
67346         , p_transaction_coa_id      => l_adr_transaction_coa_id
67347         , p_accounting_coa_id       => l_adr_accounting_coa_id
67348         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
67349         , p_flex_value_set_id       => l_adr_flex_value_set_id
67350         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
67351         , p_adr_type_code           => 'S'
67352         , p_component_type          => l_component_type
67353         , p_component_code          => l_component_code
67354         , p_component_type_code     => l_component_type_code
67355         , p_component_appl_id       => l_component_appl_id
67356         , p_amb_context_code        => l_amb_context_code
67357         , p_entity_code             => 'RECEIPTS'
67358         , p_event_class_code        => 'RECEIPT'
67359         , p_side                    => 'NA'
67360         );
67361 
67362   END IF;
67363 
67364    --
67365    --
67366    END IF;
67367    --
67368    -- Bug 4922099
67369    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
67370           (NVL(l_enc_upg_option, 'N') = 'O')
67371         ) AND
67372         (l_bflow_method_code = 'PRIOR_ENTRY')
67373       )
67374    THEN
67375       IF
67376       --
67377       1 = 2
67378       --
67379       THEN
67380       xla_accounting_err_pkg.build_message
67381                                     (p_appli_s_name            => 'XLA'
67382                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
67383                                     ,p_token_1                 => 'LINE_NUMBER'
67384                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
67385                                     ,p_token_2                 => 'LINE_TYPE_NAME'
67386                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
67387                                                                              l_component_type
67388                                                                             ,l_component_code
67389                                                                             ,l_component_type_code
67390                                                                             ,l_component_appl_id
67391                                                                             ,l_amb_context_code
67392                                                                             ,l_entity_code
67393                                                                             ,l_event_class_code
67394                                                                            )
67395                                     ,p_token_3                 => 'OWNER'
67396                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
67397                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
67398                                                                           ,p_lookup_code    => l_component_type_code
67399                                                                          )
67400                                     ,p_token_4                 => 'PRODUCT_NAME'
67401                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
67402                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
67403                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
67404                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
67405                                     ,p_ae_header_id            =>  NULL
67406                                        );
67407 
67408         IF (C_LEVEL_ERROR>= g_log_level) THEN
67409                  trace
67410                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
67411                       ,p_level    => C_LEVEL_ERROR
67412                       ,p_module   => l_log_module);
67413         END IF;
67414       END IF;
67415    END IF;
67416    --
67417    --
67418    ------------------------------------------------------------------------------------------------
67419    -- 4219869 Business Flow
67420    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
67421    -- Prior Entry.  Currently, the following code is always generated.
67422    ------------------------------------------------------------------------------------------------
67423    XLA_AE_LINES_PKG.ValidateCurrentLine;
67424 
67425    ------------------------------------------------------------------------------------
67426    -- 4219869 Business Flow
67427    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
67428    ------------------------------------------------------------------------------------
67429    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
67430 
67431    ----------------------------------------------------------------------------------
67432    -- 4219869 Business Flow
67436          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
67433    -- Update journal entry status -- Need to generate this within IF <condition>
67434    ----------------------------------------------------------------------------------
67435    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
67437          ,p_balance_type_code => l_balance_type_code
67438          );
67439 
67440    -------------------------------------------------------------------------------------------
67441    -- 4262811 - Generate the Accrual Reversal lines
67442    -------------------------------------------------------------------------------------------
67443    BEGIN
67444       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
67445                               (g_array_event(p_event_id).array_value_num('header_index'));
67446       IF l_acc_rev_flag IS NULL THEN
67447          l_acc_rev_flag := 'N';
67448       END IF;
67449    EXCEPTION
67450       WHEN OTHERS THEN
67451          l_acc_rev_flag := 'N';
67452    END;
67453    --
67454    IF (l_acc_rev_flag = 'Y') THEN
67455 
67456        -- 4645092  ------------------------------------------------------------------------------
67457        -- To allow MPA report to determine if it should generate report process
67458        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
67459        ------------------------------------------------------------------------------------------
67460 
67461        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
67462        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
67463    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
67464    -- call ADRs
67465    -- Bug 4922099
67466    --
67467    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
67468         (NVL(l_actual_upg_option, 'N') = 'O') OR
67469         (NVL(l_enc_upg_option, 'N') = 'O')
67470       )
67471    THEN
67472    NULL;
67473    --
67474    --
67475    
67476   l_ccid := AcctDerRule_7(
67477            p_application_id           => p_application_id
67478          , p_ae_header_id             => l_ae_header_id 
67479 , p_source_3 => p_source_3
67480          , x_transaction_coa_id       => l_adr_transaction_coa_id
67481          , x_accounting_coa_id        => l_adr_accounting_coa_id
67482          , x_value_type_code          => l_adr_value_type_code
67483          , p_side                     => 'NA'
67484    );
67485 
67486    xla_ae_lines_pkg.set_ccid(
67487     p_code_combination_id          => l_ccid
67488   , p_value_type_code              => l_adr_value_type_code
67489   , p_transaction_coa_id           => l_adr_transaction_coa_id
67490   , p_accounting_coa_id            => l_adr_accounting_coa_id
67491   , p_adr_code                     => 'DIST_CCID'
67492   , p_adr_type_code                => 'S'
67493   , p_component_type               => l_component_type
67494   , p_component_code               => l_component_code
67495   , p_component_type_code          => l_component_type_code
67496   , p_component_appl_id            => l_component_appl_id
67497   , p_amb_context_code             => l_amb_context_code
67498   , p_side                         => 'NA'
67499   );
67500 
67501 
67502    l_segment := AcctDerRule_5(
67503            p_application_id           => p_application_id
67504          , p_ae_header_id             => l_ae_header_id 
67505 , p_source_4 => p_source_4
67506          , x_transaction_coa_id       => l_adr_transaction_coa_id
67507          , x_accounting_coa_id        => l_adr_accounting_coa_id
67508          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
67509          , x_flex_value_set_id        => l_adr_flex_value_set_id
67510          , x_value_type_code          => l_adr_value_type_code
67511          , x_value_combination_id     => l_adr_value_combination_id
67512          , x_value_segment_code       => l_adr_value_segment_code
67513          , p_side                     => 'NA'
67514          , p_override_seg_flag        => 'Y'
67515    );
67516 
67517    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
67518 
67519       xla_ae_lines_pkg.set_segment(
67520           p_to_segment_code         => 'GL_BALANCING'
67521         , p_segment_value           => l_segment
67522         , p_from_segment_code       => l_adr_value_segment_code
67523         , p_from_combination_id     => l_adr_value_combination_id
67524         , p_value_type_code         => l_adr_value_type_code
67525         , p_transaction_coa_id      => l_adr_transaction_coa_id
67526         , p_accounting_coa_id       => l_adr_accounting_coa_id
67527         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
67528         , p_flex_value_set_id       => l_adr_flex_value_set_id
67529         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
67530         , p_adr_type_code           => 'S'
67531         , p_component_type          => l_component_type
67532         , p_component_code          => l_component_code
67533         , p_component_type_code     => l_component_type_code
67534         , p_component_appl_id       => l_component_appl_id
67535         , p_amb_context_code        => l_amb_context_code
67536         , p_entity_code             => 'RECEIPTS'
67537         , p_event_class_code        => 'RECEIPT'
67538         , p_side                    => 'NA'
67539         );
67540 
67541   END IF;
67542 
67543    --
67544    --
67545    END IF;
67546 
67547        --
67551                                          p_header_num   => 1);
67548        -- Update the line information that should be overwritten
67549        --
67550        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
67552        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
67553 
67554        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
67555 
67556        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
67557           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
67558        END IF;
67559 
67560       --
67561       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
67562       --
67563       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
67564           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
67565       ELSE
67566           ---------------------------------------------------------------------------------------------------
67567           -- 4262811a Switch Sign
67568           ---------------------------------------------------------------------------------------------------
67569           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
67570           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
67571                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
67572           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
67573                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
67574           -- 5132302
67575           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
67576                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
67577 
67578       END IF;
67579 
67580       -- 4955764
67581       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
67582       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
67583 
67584 
67585       XLA_AE_LINES_PKG.ValidateCurrentLine;
67586       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
67587 
67588       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
67589                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
67590                ,p_balance_type_code => l_balance_type_code);
67591 
67592    END IF;
67593 
67594    -----------------------------------------------------------------------------------------
67595    -- 4262811 Multiperiod Accounting
67596    -----------------------------------------------------------------------------------------
67597      -- No MPA option is assigned.
67598 
67599 
67600 END IF;
67601 END IF;
67602 --
67603 
67604 --
67605 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
67606    trace
67607       (p_msg      => 'END of AcctLineType_133'
67608       ,p_level    => C_LEVEL_PROCEDURE
67609       ,p_module   => l_log_module);
67610 END IF;
67611 --
67612 EXCEPTION
67613   WHEN xla_exceptions_pkg.application_exception THEN
67614       RAISE;
67615   WHEN OTHERS THEN
67616        xla_exceptions_pkg.raise_message
67617            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_133');
67618 END AcctLineType_133;
67619 --
67620 
67621 ---------------------------------------
67622 --
67623 -- PRIVATE FUNCTION
67624 --         AcctLineType_134
67625 --
67626 ---------------------------------------
67627 PROCEDURE AcctLineType_134 (
67628   p_application_id        IN NUMBER
67629  ,p_event_id              IN NUMBER
67630  ,p_calculate_acctd_flag  IN VARCHAR2
67631  ,p_calculate_g_l_flag    IN VARCHAR2
67632  ,p_actual_flag           IN OUT VARCHAR2
67633  ,p_balance_type_code     OUT VARCHAR2
67634  ,p_gain_or_loss_ref      OUT VARCHAR2
67635  
67636 --Distribution GL Account
67637  , p_source_3            IN NUMBER
67638 --Distribution Source Type
67639  , p_source_20            IN VARCHAR2
67640 --Distribution Line Identifier
67641  , p_source_22            IN NUMBER
67642 --Distribution Type
67643  , p_source_23            IN VARCHAR2
67644 --Exchange Date
67645  , p_source_26            IN DATE
67646 --Exchange Rate
67647  , p_source_27            IN NUMBER
67648 --Exchange Rate Type
67649  , p_source_28            IN VARCHAR2
67650 --Transaction Distribution Identifier
67651  , p_source_34            IN NUMBER
67652 --Transaction Distribution Type
67653  , p_source_35            IN VARCHAR2
67654 --Receipt Applied To Application Identifier
67655  , p_source_58            IN NUMBER
67656 --Transaction Entity Code
67657  , p_source_59            IN VARCHAR2
67658 --Transaction Identifier
67659  , p_source_60            IN NUMBER
67660 --Applying Document Currency Code
67661  , p_source_61            IN VARCHAR2
67662 --Distribution Party Identifier
67663  , p_source_63            IN NUMBER
67664 --Distribution Party Site Id
67665  , p_source_64            IN NUMBER
67666 --Distribution Party Type
67667  , p_source_65            IN VARCHAR2
67668 --Distribution Multi Fund Additional Entry
67669  , p_source_69            IN VARCHAR2
67670 --DIST_ENT_AMT_FROM
67674 )
67671  , p_source_72            IN NUMBER
67672 --Accounting Amount
67673  , p_source_73            IN NUMBER
67675 IS
67676 
67677 l_component_type              VARCHAR2(80);
67678 l_component_code              VARCHAR2(30);
67679 l_component_type_code         VARCHAR2(1);
67680 l_component_appl_id           INTEGER;
67681 l_amb_context_code            VARCHAR2(30);
67682 l_entity_code                 VARCHAR2(30);
67683 l_event_class_code            VARCHAR2(30);
67684 l_ae_header_id                NUMBER;
67685 l_event_type_code             VARCHAR2(30);
67686 l_line_definition_code        VARCHAR2(30);
67687 l_line_definition_owner_code  VARCHAR2(1);
67688 --
67689 -- adr variables
67690 l_segment                     VARCHAR2(30);
67691 l_ccid                        NUMBER;
67692 l_adr_transaction_coa_id      NUMBER;
67693 l_adr_accounting_coa_id       NUMBER;
67694 l_adr_flexfield_segment_code  VARCHAR2(30);
67695 l_adr_flex_value_set_id       NUMBER;
67696 l_adr_value_type_code         VARCHAR2(30);
67697 l_adr_value_combination_id    NUMBER;
67698 l_adr_value_segment_code      VARCHAR2(30);
67699 
67700 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
67701 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
67702 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
67703 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
67704 
67705 -- 4262811 Variables ------------------------------------------------------------------------------------------
67706 l_entered_amt_idx             NUMBER;
67707 l_accted_amt_idx              NUMBER;
67708 l_acc_rev_flag                VARCHAR2(1);
67709 l_accrual_line_num            NUMBER;
67710 l_tmp_amt                     NUMBER;
67711 l_acc_rev_natural_side_code   VARCHAR2(1);
67712 
67713 l_num_entries                 NUMBER;
67714 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
67715 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
67716 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
67717 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
67718 l_recog_line_1                NUMBER;
67719 l_recog_line_2                NUMBER;
67720 
67721 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
67722 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
67723 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
67724 
67725 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
67726 
67727 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
67728 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
67729 
67730 ---------------------------------------------------------------------------------------------------------------
67731 
67732 
67733 --
67734 -- bulk performance
67735 --
67736 l_balance_type_code           VARCHAR2(1);
67737 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
67738 l_log_module                  VARCHAR2(240);
67739 
67740 --
67741 -- Upgrade strategy
67742 --
67743 l_actual_upg_option           VARCHAR2(1);
67744 l_enc_upg_option           VARCHAR2(1);
67745 
67746 --
67747 BEGIN
67748 --
67749 IF g_log_enabled THEN
67750       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_134';
67751 END IF;
67752 --
67753 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
67754 
67755       trace
67756          (p_msg      => 'BEGIN of AcctLineType_134'
67757          ,p_level    => C_LEVEL_PROCEDURE
67758          ,p_module   => l_log_module);
67759 
67760 END IF;
67761 --
67762 l_component_type             := 'AMB_JLT';
67763 l_component_code             := 'RCT_UNID';
67764 l_component_type_code        := 'S';
67765 l_component_appl_id          :=  222;
67766 l_amb_context_code           := 'DEFAULT';
67767 l_entity_code                := 'RECEIPTS';
67768 l_event_class_code           := 'RECEIPT';
67769 l_event_type_code            := 'RECEIPT_ALL';
67770 l_line_definition_owner_code := 'S';
67771 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
67772 --
67773 l_balance_type_code          := 'A';
67774 l_segment                     := NULL;
67775 l_ccid                        := NULL;
67776 l_adr_transaction_coa_id      := NULL;
67777 l_adr_accounting_coa_id       := NULL;
67778 l_adr_flexfield_segment_code  := NULL;
67779 l_adr_flex_value_set_id       := NULL;
67780 l_adr_value_type_code         := NULL;
67781 l_adr_value_combination_id    := NULL;
67782 l_adr_value_segment_code      := NULL;
67783 
67784 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
67785 l_bflow_class_code           := '';    -- 4219869 Business Flow
67786 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
67787 l_budgetary_control_flag     := 'N';
67788 
67789 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
67790 l_bflow_applied_to_amt       := NULL; -- 5132302
67791 l_entered_amt_idx            := NULL;          -- 4262811
67792 l_accted_amt_idx             := NULL;          -- 4262811
67793 l_acc_rev_flag               := NULL;          -- 4262811
67794 l_accrual_line_num           := NULL;          -- 4262811
67795 l_tmp_amt                    := NULL;          -- 4262811
67796 --
67797  
67801 ') =  'UNID' AND 
67798 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
67799     l_balance_type_code <> 'B' THEN
67800 IF NVL(p_source_20,'
67802 NVL(p_source_69,'
67803 ') =  'N'
67804  THEN 
67805 
67806    --
67807    XLA_AE_LINES_PKG.SetNewLine;
67808 
67809    p_balance_type_code          := l_balance_type_code;
67810    -- set the flag so later we will know whether the gain loss line needs to be created
67811    
67812    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
67813      p_actual_flag :='A';
67814    END IF;
67815 
67816    --
67817    -- bulk performance
67818    --
67819    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
67820                                       p_header_num   => 0); -- 4262811
67821    --
67822    -- set accounting line options
67823    --
67824    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
67825            p_natural_side_code          => 'C'
67826          , p_gain_or_loss_flag          => 'N'
67827          , p_gl_transfer_mode_code      => 'S'
67828          , p_acct_entry_type_code       => 'A'
67829          , p_switch_side_flag           => 'Y'
67830          , p_merge_duplicate_code       => 'A'
67831          );
67832    --
67833    l_acc_rev_natural_side_code := 'D';  -- 4262811
67834    -- 
67835    --
67836    -- set accounting line type info
67837    --
67838    xla_ae_lines_pkg.SetAcctLineType
67839       (p_component_type             => l_component_type
67840       ,p_event_type_code            => l_event_type_code
67841       ,p_line_definition_owner_code => l_line_definition_owner_code
67842       ,p_line_definition_code       => l_line_definition_code
67843       ,p_accounting_line_code       => l_component_code
67844       ,p_accounting_line_type_code  => l_component_type_code
67845       ,p_accounting_line_appl_id    => l_component_appl_id
67846       ,p_amb_context_code           => l_amb_context_code
67847       ,p_entity_code                => l_entity_code
67848       ,p_event_class_code           => l_event_class_code);
67849    --
67850    -- set accounting class
67851    --
67852    xla_ae_lines_pkg.SetAcctClass(
67853            p_accounting_class_code  => 'UNID'
67854          , p_ae_header_id           => l_ae_header_id
67855          );
67856 
67857    --
67858    -- set rounding class
67859    --
67860    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
67861                       'RECEIVABLE';
67862 
67863    --
67864    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
67865    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
67866    --
67867    -- bulk performance
67868    --
67869    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
67870 
67871    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
67872       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
67873 
67874    -- 4955764
67875    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
67876       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
67877 
67878    -- 4458381 Public Sector Enh
67879    
67880    --
67881    -- set accounting attributes for the line type
67882    --
67883    l_entered_amt_idx := 8;
67884    l_accted_amt_idx  := 13;
67885    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
67886    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
67887    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
67888    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
67889    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
67890    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
67891    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
67892    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
67893    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
67894    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
67895    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
67896    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
67897    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
67898    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
67899    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
67900    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
67901    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
67902    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
67903    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
67904    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
67905    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
67906    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
67907    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
67908    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
67909    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
67910    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
67911    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
67912    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
67916    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
67913    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
67914    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
67915    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
67917    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
67918 
67919    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
67920    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
67921 
67922    ---------------------------------------------------------------------------------------------------------------
67923    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
67924    ---------------------------------------------------------------------------------------------------------------
67925    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
67926 
67927    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
67928    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
67929 
67930    IF xla_accounting_cache_pkg.GetValueChar
67931          (p_source_code         => 'LEDGER_CATEGORY_CODE'
67932          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
67933    AND l_bflow_method_code = 'PRIOR_ENTRY'
67934 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
67935    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
67936          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
67937        )
67938    THEN
67939          xla_ae_lines_pkg.BflowUpgEntry
67940            (p_business_method_code    => l_bflow_method_code
67941            ,p_business_class_code     => l_bflow_class_code
67942            ,p_balance_type            => l_balance_type_code);
67943    ELSE
67944       NULL;
67945 -- No business flow processing for business flow method of NONE.
67946    END IF;
67947 
67948    --
67949    -- call analytical criteria
67950    --
67951    
67952    --
67953    -- call description
67954    --
67955    -- No description or it is inherited.
67956    --
67957    -- call ADRs
67958    -- Bug 4922099
67959    --
67960    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
67961         (NVL(l_actual_upg_option, 'N') = 'O') OR
67962         (NVL(l_enc_upg_option, 'N') = 'O')
67963       )
67964    THEN
67965    NULL;
67966    --
67967    --
67968    
67969   l_ccid := AcctDerRule_7(
67970            p_application_id           => p_application_id
67971          , p_ae_header_id             => l_ae_header_id 
67972 , p_source_3 => p_source_3
67973          , x_transaction_coa_id       => l_adr_transaction_coa_id
67974          , x_accounting_coa_id        => l_adr_accounting_coa_id
67975          , x_value_type_code          => l_adr_value_type_code
67976          , p_side                     => 'NA'
67977    );
67978 
67979    xla_ae_lines_pkg.set_ccid(
67980     p_code_combination_id          => l_ccid
67981   , p_value_type_code              => l_adr_value_type_code
67982   , p_transaction_coa_id           => l_adr_transaction_coa_id
67983   , p_accounting_coa_id            => l_adr_accounting_coa_id
67984   , p_adr_code                     => 'DIST_CCID'
67985   , p_adr_type_code                => 'S'
67986   , p_component_type               => l_component_type
67987   , p_component_code               => l_component_code
67988   , p_component_type_code          => l_component_type_code
67989   , p_component_appl_id            => l_component_appl_id
67990   , p_amb_context_code             => l_amb_context_code
67991   , p_side                         => 'NA'
67992   );
67993 
67994 
67995    --
67996    --
67997    END IF;
67998    --
67999    -- Bug 4922099
68000    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
68001           (NVL(l_enc_upg_option, 'N') = 'O')
68002         ) AND
68003         (l_bflow_method_code = 'PRIOR_ENTRY')
68004       )
68005    THEN
68006       IF
68007       --
68008       1 = 2
68009       --
68010       THEN
68011       xla_accounting_err_pkg.build_message
68012                                     (p_appli_s_name            => 'XLA'
68013                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
68014                                     ,p_token_1                 => 'LINE_NUMBER'
68015                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
68016                                     ,p_token_2                 => 'LINE_TYPE_NAME'
68017                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
68018                                                                              l_component_type
68019                                                                             ,l_component_code
68020                                                                             ,l_component_type_code
68021                                                                             ,l_component_appl_id
68022                                                                             ,l_amb_context_code
68023                                                                             ,l_entity_code
68024                                                                             ,l_event_class_code
68025                                                                            )
68026                                     ,p_token_3                 => 'OWNER'
68030                                                                          )
68027                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
68028                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
68029                                                                           ,p_lookup_code    => l_component_type_code
68031                                     ,p_token_4                 => 'PRODUCT_NAME'
68032                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
68033                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
68034                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
68035                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
68036                                     ,p_ae_header_id            =>  NULL
68037                                        );
68038 
68039         IF (C_LEVEL_ERROR>= g_log_level) THEN
68040                  trace
68041                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
68042                       ,p_level    => C_LEVEL_ERROR
68043                       ,p_module   => l_log_module);
68044         END IF;
68045       END IF;
68046    END IF;
68047    --
68048    --
68049    ------------------------------------------------------------------------------------------------
68050    -- 4219869 Business Flow
68051    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
68052    -- Prior Entry.  Currently, the following code is always generated.
68053    ------------------------------------------------------------------------------------------------
68054    XLA_AE_LINES_PKG.ValidateCurrentLine;
68055 
68056    ------------------------------------------------------------------------------------
68057    -- 4219869 Business Flow
68058    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
68059    ------------------------------------------------------------------------------------
68060    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
68061 
68062    ----------------------------------------------------------------------------------
68063    -- 4219869 Business Flow
68064    -- Update journal entry status -- Need to generate this within IF <condition>
68065    ----------------------------------------------------------------------------------
68066    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
68067          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
68068          ,p_balance_type_code => l_balance_type_code
68069          );
68070 
68071    -------------------------------------------------------------------------------------------
68072    -- 4262811 - Generate the Accrual Reversal lines
68073    -------------------------------------------------------------------------------------------
68074    BEGIN
68075       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
68076                               (g_array_event(p_event_id).array_value_num('header_index'));
68077       IF l_acc_rev_flag IS NULL THEN
68078          l_acc_rev_flag := 'N';
68079       END IF;
68080    EXCEPTION
68081       WHEN OTHERS THEN
68082          l_acc_rev_flag := 'N';
68083    END;
68084    --
68085    IF (l_acc_rev_flag = 'Y') THEN
68086 
68087        -- 4645092  ------------------------------------------------------------------------------
68088        -- To allow MPA report to determine if it should generate report process
68089        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
68090        ------------------------------------------------------------------------------------------
68091 
68092        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
68093        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
68094    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
68095    -- call ADRs
68096    -- Bug 4922099
68097    --
68098    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
68099         (NVL(l_actual_upg_option, 'N') = 'O') OR
68100         (NVL(l_enc_upg_option, 'N') = 'O')
68101       )
68102    THEN
68103    NULL;
68104    --
68105    --
68106    
68107   l_ccid := AcctDerRule_7(
68108            p_application_id           => p_application_id
68109          , p_ae_header_id             => l_ae_header_id 
68110 , p_source_3 => p_source_3
68111          , x_transaction_coa_id       => l_adr_transaction_coa_id
68112          , x_accounting_coa_id        => l_adr_accounting_coa_id
68113          , x_value_type_code          => l_adr_value_type_code
68114          , p_side                     => 'NA'
68115    );
68116 
68117    xla_ae_lines_pkg.set_ccid(
68118     p_code_combination_id          => l_ccid
68119   , p_value_type_code              => l_adr_value_type_code
68120   , p_transaction_coa_id           => l_adr_transaction_coa_id
68121   , p_accounting_coa_id            => l_adr_accounting_coa_id
68122   , p_adr_code                     => 'DIST_CCID'
68123   , p_adr_type_code                => 'S'
68124   , p_component_type               => l_component_type
68125   , p_component_code               => l_component_code
68126   , p_component_type_code          => l_component_type_code
68127   , p_component_appl_id            => l_component_appl_id
68128   , p_amb_context_code             => l_amb_context_code
68132 
68129   , p_side                         => 'NA'
68130   );
68131 
68133    --
68134    --
68135    END IF;
68136 
68137        --
68138        -- Update the line information that should be overwritten
68139        --
68140        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
68141                                          p_header_num   => 1);
68142        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
68143 
68144        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
68145 
68146        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
68147           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
68148        END IF;
68149 
68150       --
68151       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
68152       --
68153       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
68154           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
68155       ELSE
68156           ---------------------------------------------------------------------------------------------------
68157           -- 4262811a Switch Sign
68158           ---------------------------------------------------------------------------------------------------
68159           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
68160           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
68161                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
68162           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
68163                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
68164           -- 5132302
68165           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
68166                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
68167 
68168       END IF;
68169 
68170       -- 4955764
68171       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
68172       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
68173 
68174 
68175       XLA_AE_LINES_PKG.ValidateCurrentLine;
68176       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
68177 
68178       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
68179                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
68180                ,p_balance_type_code => l_balance_type_code);
68181 
68182    END IF;
68183 
68184    -----------------------------------------------------------------------------------------
68185    -- 4262811 Multiperiod Accounting
68186    -----------------------------------------------------------------------------------------
68187      -- No MPA option is assigned.
68188 
68189 
68190 END IF;
68191 END IF;
68192 --
68193 
68194 --
68195 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
68196    trace
68197       (p_msg      => 'END of AcctLineType_134'
68198       ,p_level    => C_LEVEL_PROCEDURE
68199       ,p_module   => l_log_module);
68200 END IF;
68201 --
68202 EXCEPTION
68203   WHEN xla_exceptions_pkg.application_exception THEN
68204       RAISE;
68205   WHEN OTHERS THEN
68206        xla_exceptions_pkg.raise_message
68207            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_134');
68208 END AcctLineType_134;
68209 --
68210 
68211 ---------------------------------------
68212 --
68213 -- PRIVATE FUNCTION
68214 --         AcctLineType_135
68215 --
68216 ---------------------------------------
68217 PROCEDURE AcctLineType_135 (
68218   p_application_id        IN NUMBER
68219  ,p_event_id              IN NUMBER
68220  ,p_calculate_acctd_flag  IN VARCHAR2
68221  ,p_calculate_g_l_flag    IN VARCHAR2
68222  ,p_actual_flag           IN OUT VARCHAR2
68223  ,p_balance_type_code     OUT VARCHAR2
68224  ,p_gain_or_loss_ref      OUT VARCHAR2
68225  
68226 --Distribution GL Account
68227  , p_source_3            IN NUMBER
68228 --Distribution Source Type
68229  , p_source_20            IN VARCHAR2
68230 --Receivable Activity Type
68231  , p_source_21            IN VARCHAR2
68232 --Distribution Line Identifier
68233  , p_source_22            IN NUMBER
68234 --Distribution Type
68235  , p_source_23            IN VARCHAR2
68236 --Exchange Date
68237  , p_source_26            IN DATE
68238 --Exchange Rate
68239  , p_source_27            IN NUMBER
68240 --Exchange Rate Type
68241  , p_source_28            IN VARCHAR2
68242 --Transaction Distribution Identifier
68243  , p_source_34            IN NUMBER
68244 --Transaction Distribution Type
68245  , p_source_35            IN VARCHAR2
68246 --Receipt Applied To Application Identifier
68247  , p_source_58            IN NUMBER
68248 --Transaction Entity Code
68249  , p_source_59            IN VARCHAR2
68250 --Transaction Identifier
68251  , p_source_60            IN NUMBER
68252 --Applying Document Currency Code
68253  , p_source_61            IN VARCHAR2
68254 --Distribution Party Identifier
68258 --Distribution Party Type
68255  , p_source_63            IN NUMBER
68256 --Distribution Party Site Id
68257  , p_source_64            IN NUMBER
68259  , p_source_65            IN VARCHAR2
68260 --Distribution Multi Fund Additional Entry
68261  , p_source_69            IN VARCHAR2
68262 --DIST_ENT_AMT_FROM
68263  , p_source_72            IN NUMBER
68264 --Accounting Amount
68265  , p_source_73            IN NUMBER
68266 )
68267 IS
68268 
68269 l_component_type              VARCHAR2(80);
68270 l_component_code              VARCHAR2(30);
68271 l_component_type_code         VARCHAR2(1);
68272 l_component_appl_id           INTEGER;
68273 l_amb_context_code            VARCHAR2(30);
68274 l_entity_code                 VARCHAR2(30);
68275 l_event_class_code            VARCHAR2(30);
68276 l_ae_header_id                NUMBER;
68277 l_event_type_code             VARCHAR2(30);
68278 l_line_definition_code        VARCHAR2(30);
68279 l_line_definition_owner_code  VARCHAR2(1);
68280 --
68281 -- adr variables
68282 l_segment                     VARCHAR2(30);
68283 l_ccid                        NUMBER;
68284 l_adr_transaction_coa_id      NUMBER;
68285 l_adr_accounting_coa_id       NUMBER;
68286 l_adr_flexfield_segment_code  VARCHAR2(30);
68287 l_adr_flex_value_set_id       NUMBER;
68288 l_adr_value_type_code         VARCHAR2(30);
68289 l_adr_value_combination_id    NUMBER;
68290 l_adr_value_segment_code      VARCHAR2(30);
68291 
68292 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
68293 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
68294 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
68295 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
68296 
68297 -- 4262811 Variables ------------------------------------------------------------------------------------------
68298 l_entered_amt_idx             NUMBER;
68299 l_accted_amt_idx              NUMBER;
68300 l_acc_rev_flag                VARCHAR2(1);
68301 l_accrual_line_num            NUMBER;
68302 l_tmp_amt                     NUMBER;
68303 l_acc_rev_natural_side_code   VARCHAR2(1);
68304 
68305 l_num_entries                 NUMBER;
68306 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
68307 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
68308 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
68309 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
68310 l_recog_line_1                NUMBER;
68311 l_recog_line_2                NUMBER;
68312 
68313 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
68314 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
68315 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
68316 
68317 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
68318 
68319 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
68320 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
68321 
68322 ---------------------------------------------------------------------------------------------------------------
68323 
68324 
68325 --
68326 -- bulk performance
68327 --
68328 l_balance_type_code           VARCHAR2(1);
68329 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
68330 l_log_module                  VARCHAR2(240);
68331 
68332 --
68333 -- Upgrade strategy
68334 --
68335 l_actual_upg_option           VARCHAR2(1);
68336 l_enc_upg_option           VARCHAR2(1);
68337 
68338 --
68339 BEGIN
68340 --
68341 IF g_log_enabled THEN
68342       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_135';
68343 END IF;
68344 --
68345 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
68346 
68347       trace
68348          (p_msg      => 'BEGIN of AcctLineType_135'
68349          ,p_level    => C_LEVEL_PROCEDURE
68350          ,p_module   => l_log_module);
68351 
68352 END IF;
68353 --
68354 l_component_type             := 'AMB_JLT';
68355 l_component_code             := 'RCT_WRITEOFF';
68356 l_component_type_code        := 'S';
68357 l_component_appl_id          :=  222;
68358 l_amb_context_code           := 'DEFAULT';
68359 l_entity_code                := 'RECEIPTS';
68360 l_event_class_code           := 'RECEIPT';
68361 l_event_type_code            := 'RECEIPT_ALL';
68362 l_line_definition_owner_code := 'S';
68363 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
68364 --
68365 l_balance_type_code          := 'A';
68366 l_segment                     := NULL;
68367 l_ccid                        := NULL;
68368 l_adr_transaction_coa_id      := NULL;
68369 l_adr_accounting_coa_id       := NULL;
68370 l_adr_flexfield_segment_code  := NULL;
68371 l_adr_flex_value_set_id       := NULL;
68372 l_adr_value_type_code         := NULL;
68373 l_adr_value_combination_id    := NULL;
68374 l_adr_value_segment_code      := NULL;
68375 
68376 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
68377 l_bflow_class_code           := '';    -- 4219869 Business Flow
68378 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
68379 l_budgetary_control_flag     := 'N';
68380 
68381 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
68382 l_bflow_applied_to_amt       := NULL; -- 5132302
68386 l_accrual_line_num           := NULL;          -- 4262811
68383 l_entered_amt_idx            := NULL;          -- 4262811
68384 l_accted_amt_idx             := NULL;          -- 4262811
68385 l_acc_rev_flag               := NULL;          -- 4262811
68387 l_tmp_amt                    := NULL;          -- 4262811
68388 --
68389  
68390 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
68391     l_balance_type_code <> 'B' THEN
68392 IF NVL(p_source_20,'
68393 ') =  'ACTIVITY' AND 
68394 NVL(p_source_21,'
68395 ') =  'WRITEOFF' AND 
68396 NVL(p_source_69,'
68397 ') =  'N'
68398  THEN 
68399 
68400    --
68401    XLA_AE_LINES_PKG.SetNewLine;
68402 
68403    p_balance_type_code          := l_balance_type_code;
68404    -- set the flag so later we will know whether the gain loss line needs to be created
68405    
68406    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
68407      p_actual_flag :='A';
68408    END IF;
68409 
68410    --
68411    -- bulk performance
68412    --
68413    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
68414                                       p_header_num   => 0); -- 4262811
68415    --
68416    -- set accounting line options
68417    --
68418    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
68419            p_natural_side_code          => 'C'
68420          , p_gain_or_loss_flag          => 'N'
68421          , p_gl_transfer_mode_code      => 'S'
68422          , p_acct_entry_type_code       => 'A'
68423          , p_switch_side_flag           => 'Y'
68424          , p_merge_duplicate_code       => 'A'
68425          );
68426    --
68427    l_acc_rev_natural_side_code := 'D';  -- 4262811
68428    -- 
68429    --
68430    -- set accounting line type info
68431    --
68432    xla_ae_lines_pkg.SetAcctLineType
68433       (p_component_type             => l_component_type
68434       ,p_event_type_code            => l_event_type_code
68435       ,p_line_definition_owner_code => l_line_definition_owner_code
68436       ,p_line_definition_code       => l_line_definition_code
68437       ,p_accounting_line_code       => l_component_code
68438       ,p_accounting_line_type_code  => l_component_type_code
68439       ,p_accounting_line_appl_id    => l_component_appl_id
68440       ,p_amb_context_code           => l_amb_context_code
68441       ,p_entity_code                => l_entity_code
68442       ,p_event_class_code           => l_event_class_code);
68443    --
68444    -- set accounting class
68445    --
68446    xla_ae_lines_pkg.SetAcctClass(
68447            p_accounting_class_code  => 'WRITE_OFF'
68448          , p_ae_header_id           => l_ae_header_id
68449          );
68450 
68451    --
68452    -- set rounding class
68453    --
68454    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
68455                       'RECEIVABLE';
68456 
68457    --
68458    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
68459    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
68460    --
68461    -- bulk performance
68462    --
68463    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
68464 
68465    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
68466       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
68467 
68468    -- 4955764
68469    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
68470       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
68471 
68472    -- 4458381 Public Sector Enh
68473    
68474    --
68475    -- set accounting attributes for the line type
68476    --
68477    l_entered_amt_idx := 8;
68478    l_accted_amt_idx  := 13;
68479    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
68480    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
68481    l_rec_acct_attrs.array_num_value(1)  := p_source_58;
68482    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
68483    l_rec_acct_attrs.array_char_value(2)  := p_source_35;
68484    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
68485    l_rec_acct_attrs.array_char_value(3)  := p_source_59;
68486    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
68487    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_34);
68488    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
68489    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_60);
68490    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
68491    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_22);
68492    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
68493    l_rec_acct_attrs.array_char_value(7)  := p_source_23;
68494    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
68495    l_rec_acct_attrs.array_num_value(8)  := p_source_72;
68496    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
68497    l_rec_acct_attrs.array_char_value(9)  := p_source_61;
68498    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
68499    l_rec_acct_attrs.array_date_value(10)  := p_source_26;
68500    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
68501    l_rec_acct_attrs.array_num_value(11)  := p_source_27;
68505    l_rec_acct_attrs.array_num_value(13)  := p_source_73;
68502    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
68503    l_rec_acct_attrs.array_char_value(12)  := p_source_28;
68504    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
68506    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
68507    l_rec_acct_attrs.array_num_value(14)  := p_source_63;
68508    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
68509    l_rec_acct_attrs.array_num_value(15)  := p_source_64;
68510    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
68511    l_rec_acct_attrs.array_char_value(16)  := p_source_65;
68512 
68513    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
68514    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
68515 
68516    ---------------------------------------------------------------------------------------------------------------
68517    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
68518    ---------------------------------------------------------------------------------------------------------------
68519    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
68520 
68521    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
68522    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
68523 
68524    IF xla_accounting_cache_pkg.GetValueChar
68525          (p_source_code         => 'LEDGER_CATEGORY_CODE'
68526          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
68527    AND l_bflow_method_code = 'PRIOR_ENTRY'
68528 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
68529    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
68530          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
68531        )
68532    THEN
68533          xla_ae_lines_pkg.BflowUpgEntry
68534            (p_business_method_code    => l_bflow_method_code
68535            ,p_business_class_code     => l_bflow_class_code
68536            ,p_balance_type            => l_balance_type_code);
68537    ELSE
68538       NULL;
68539 -- No business flow processing for business flow method of NONE.
68540    END IF;
68541 
68542    --
68543    -- call analytical criteria
68544    --
68545    
68546    --
68547    -- call description
68548    --
68549    -- No description or it is inherited.
68550    --
68551    -- call ADRs
68552    -- Bug 4922099
68553    --
68554    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
68555         (NVL(l_actual_upg_option, 'N') = 'O') OR
68556         (NVL(l_enc_upg_option, 'N') = 'O')
68557       )
68558    THEN
68559    NULL;
68560    --
68561    --
68562    
68563   l_ccid := AcctDerRule_7(
68564            p_application_id           => p_application_id
68565          , p_ae_header_id             => l_ae_header_id 
68566 , p_source_3 => p_source_3
68567          , x_transaction_coa_id       => l_adr_transaction_coa_id
68568          , x_accounting_coa_id        => l_adr_accounting_coa_id
68569          , x_value_type_code          => l_adr_value_type_code
68570          , p_side                     => 'NA'
68571    );
68572 
68573    xla_ae_lines_pkg.set_ccid(
68574     p_code_combination_id          => l_ccid
68575   , p_value_type_code              => l_adr_value_type_code
68576   , p_transaction_coa_id           => l_adr_transaction_coa_id
68577   , p_accounting_coa_id            => l_adr_accounting_coa_id
68578   , p_adr_code                     => 'DIST_CCID'
68579   , p_adr_type_code                => 'S'
68580   , p_component_type               => l_component_type
68581   , p_component_code               => l_component_code
68582   , p_component_type_code          => l_component_type_code
68583   , p_component_appl_id            => l_component_appl_id
68584   , p_amb_context_code             => l_amb_context_code
68585   , p_side                         => 'NA'
68586   );
68587 
68588 
68589    --
68590    --
68591    END IF;
68592    --
68593    -- Bug 4922099
68594    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
68595           (NVL(l_enc_upg_option, 'N') = 'O')
68596         ) AND
68597         (l_bflow_method_code = 'PRIOR_ENTRY')
68598       )
68599    THEN
68600       IF
68601       --
68602       1 = 2
68603       --
68604       THEN
68605       xla_accounting_err_pkg.build_message
68606                                     (p_appli_s_name            => 'XLA'
68607                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
68608                                     ,p_token_1                 => 'LINE_NUMBER'
68609                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
68610                                     ,p_token_2                 => 'LINE_TYPE_NAME'
68611                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
68612                                                                              l_component_type
68613                                                                             ,l_component_code
68614                                                                             ,l_component_type_code
68615                                                                             ,l_component_appl_id
68619                                                                            )
68616                                                                             ,l_amb_context_code
68617                                                                             ,l_entity_code
68618                                                                             ,l_event_class_code
68620                                     ,p_token_3                 => 'OWNER'
68621                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
68622                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
68623                                                                           ,p_lookup_code    => l_component_type_code
68624                                                                          )
68625                                     ,p_token_4                 => 'PRODUCT_NAME'
68626                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
68627                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
68628                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
68629                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
68630                                     ,p_ae_header_id            =>  NULL
68631                                        );
68632 
68633         IF (C_LEVEL_ERROR>= g_log_level) THEN
68634                  trace
68635                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
68636                       ,p_level    => C_LEVEL_ERROR
68637                       ,p_module   => l_log_module);
68638         END IF;
68639       END IF;
68640    END IF;
68641    --
68642    --
68643    ------------------------------------------------------------------------------------------------
68644    -- 4219869 Business Flow
68645    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
68646    -- Prior Entry.  Currently, the following code is always generated.
68647    ------------------------------------------------------------------------------------------------
68648    XLA_AE_LINES_PKG.ValidateCurrentLine;
68649 
68650    ------------------------------------------------------------------------------------
68651    -- 4219869 Business Flow
68652    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
68653    ------------------------------------------------------------------------------------
68654    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
68655 
68656    ----------------------------------------------------------------------------------
68657    -- 4219869 Business Flow
68658    -- Update journal entry status -- Need to generate this within IF <condition>
68659    ----------------------------------------------------------------------------------
68660    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
68661          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
68662          ,p_balance_type_code => l_balance_type_code
68663          );
68664 
68665    -------------------------------------------------------------------------------------------
68666    -- 4262811 - Generate the Accrual Reversal lines
68667    -------------------------------------------------------------------------------------------
68668    BEGIN
68669       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
68670                               (g_array_event(p_event_id).array_value_num('header_index'));
68671       IF l_acc_rev_flag IS NULL THEN
68672          l_acc_rev_flag := 'N';
68673       END IF;
68674    EXCEPTION
68675       WHEN OTHERS THEN
68676          l_acc_rev_flag := 'N';
68677    END;
68678    --
68679    IF (l_acc_rev_flag = 'Y') THEN
68680 
68681        -- 4645092  ------------------------------------------------------------------------------
68682        -- To allow MPA report to determine if it should generate report process
68683        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
68684        ------------------------------------------------------------------------------------------
68685 
68686        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
68687        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
68688    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
68689    -- call ADRs
68690    -- Bug 4922099
68691    --
68692    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
68693         (NVL(l_actual_upg_option, 'N') = 'O') OR
68694         (NVL(l_enc_upg_option, 'N') = 'O')
68695       )
68696    THEN
68697    NULL;
68698    --
68699    --
68700    
68701   l_ccid := AcctDerRule_7(
68702            p_application_id           => p_application_id
68703          , p_ae_header_id             => l_ae_header_id 
68704 , p_source_3 => p_source_3
68705          , x_transaction_coa_id       => l_adr_transaction_coa_id
68706          , x_accounting_coa_id        => l_adr_accounting_coa_id
68707          , x_value_type_code          => l_adr_value_type_code
68708          , p_side                     => 'NA'
68709    );
68710 
68711    xla_ae_lines_pkg.set_ccid(
68712     p_code_combination_id          => l_ccid
68713   , p_value_type_code              => l_adr_value_type_code
68714   , p_transaction_coa_id           => l_adr_transaction_coa_id
68718   , p_component_type               => l_component_type
68715   , p_accounting_coa_id            => l_adr_accounting_coa_id
68716   , p_adr_code                     => 'DIST_CCID'
68717   , p_adr_type_code                => 'S'
68719   , p_component_code               => l_component_code
68720   , p_component_type_code          => l_component_type_code
68721   , p_component_appl_id            => l_component_appl_id
68722   , p_amb_context_code             => l_amb_context_code
68723   , p_side                         => 'NA'
68724   );
68725 
68726 
68727    --
68728    --
68729    END IF;
68730 
68731        --
68732        -- Update the line information that should be overwritten
68733        --
68734        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
68735                                          p_header_num   => 1);
68736        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
68737 
68738        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
68739 
68740        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
68741           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
68742        END IF;
68743 
68744       --
68745       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
68746       --
68747       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
68748           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
68749       ELSE
68750           ---------------------------------------------------------------------------------------------------
68751           -- 4262811a Switch Sign
68752           ---------------------------------------------------------------------------------------------------
68753           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
68754           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
68755                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
68756           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
68757                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
68758           -- 5132302
68759           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
68760                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
68761 
68762       END IF;
68763 
68764       -- 4955764
68765       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
68766       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
68767 
68768 
68769       XLA_AE_LINES_PKG.ValidateCurrentLine;
68770       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
68771 
68772       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
68773                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
68774                ,p_balance_type_code => l_balance_type_code);
68775 
68776    END IF;
68777 
68778    -----------------------------------------------------------------------------------------
68779    -- 4262811 Multiperiod Accounting
68780    -----------------------------------------------------------------------------------------
68781      -- No MPA option is assigned.
68782 
68783 
68784 END IF;
68785 END IF;
68786 --
68787 
68788 --
68789 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
68790    trace
68791       (p_msg      => 'END of AcctLineType_135'
68792       ,p_level    => C_LEVEL_PROCEDURE
68793       ,p_module   => l_log_module);
68794 END IF;
68795 --
68796 EXCEPTION
68797   WHEN xla_exceptions_pkg.application_exception THEN
68798       RAISE;
68799   WHEN OTHERS THEN
68800        xla_exceptions_pkg.raise_message
68801            (p_location => 'XLA_00222_AAD_S_000006_PKG.AcctLineType_135');
68802 END AcctLineType_135;
68803 --
68804 
68805 ---------------------------------------
68806 --
68807 -- PRIVATE PROCEDURE
68808 --         insert_sources_136
68809 --
68810 ----------------------------------------
68811 --
68812 PROCEDURE insert_sources_136(
68813                                 p_target_ledger_id       IN NUMBER
68814                               , p_language               IN VARCHAR2
68815                               , p_sla_ledger_id          IN NUMBER
68816                               , p_pad_start_date         IN DATE
68817                               , p_pad_end_date           IN DATE
68818                          )
68819 IS
68820 
68821 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'ADJUSTMENT_ALL';
68822 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'ADJUSTMENT';
68823 p_apps_owner                   VARCHAR2(30);
68824 l_log_module                   VARCHAR2(240);
68825 BEGIN
68826 IF g_log_enabled THEN
68827       l_log_module := C_DEFAULT_MODULE||'.insert_sources_136';
68828 END IF;
68829 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
68830 
68831       trace
68832          (p_msg      => 'BEGIN of insert_sources_136'
68833          ,p_level    => C_LEVEL_PROCEDURE
68837 
68834          ,p_module   => l_log_module);
68835 
68836 END IF;
68838 -- select APPS owner
68839 SELECT oracle_username
68840   INTO p_apps_owner
68841   FROM fnd_oracle_userid
68842  WHERE read_only_flag = 'U'
68843 ;
68844 
68845 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
68846       trace
68847          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
68848                         ' - p_language = '||p_language||
68849                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
68850                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
68851                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
68852                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
68853          ,p_level    => C_LEVEL_STATEMENT
68854          ,p_module   => l_log_module);
68855 END IF;
68856 
68857 
68858 --
68859 INSERT INTO xla_diag_sources --hdr2
68860 (
68861         event_id
68862       , ledger_id
68863       , sla_ledger_id
68864       , description_language
68865       , object_name
68866       , object_type_code
68867       , line_number
68868       , source_application_id
68869       , source_type_code
68870       , source_code
68871       , source_value
68872       , source_meaning
68873       , created_by
68874       , creation_date
68875       , last_update_date
68876       , last_updated_by
68877       , last_update_login
68878       , program_update_date
68879       , program_application_id
68880       , program_id
68881       , request_id
68882 )
68883 SELECT
68884         event_id
68885       , p_target_ledger_id
68886       , p_sla_ledger_id
68887       , p_language
68888       , object_name
68889       , object_type_code
68890       , line_number
68891       , source_application_id
68892       , source_type_code
68893       , source_code
68894       , SUBSTR(source_value ,1,1996)
68895       , SUBSTR(source_meaning ,1,200)
68896       , xla_environment_pkg.g_Usr_Id
68897       , TRUNC(SYSDATE)
68898       , TRUNC(SYSDATE)
68899       , xla_environment_pkg.g_Usr_Id
68900       , xla_environment_pkg.g_Login_Id
68901       , TRUNC(SYSDATE)
68902       , xla_environment_pkg.g_Prog_Appl_Id
68903       , xla_environment_pkg.g_Prog_Id
68904       , xla_environment_pkg.g_Req_Id
68905   FROM (
68906        SELECT xet.event_id                  event_id
68907             , 0                          line_number
68908             , CASE r
68909                WHEN 1 THEN 'AR_TRANSACTIONS_S_V' 
68910                 WHEN 2 THEN 'AR_RECEIVABLES_TRX_ACT_S_V' 
68911                 WHEN 3 THEN 'AR_BILL_TO_CUSTOMERS_S_V' 
68912                 WHEN 4 THEN 'AR_BILL_TO_SITE_USES_S_V' 
68913                 WHEN 5 THEN 'AR_TRANSACTIONS_S_V' 
68914                 WHEN 6 THEN 'AR_ADJUSTMENTS_H_V' 
68915                 WHEN 7 THEN 'AR_ADJUSTMENTS_H_V' 
68916                 WHEN 8 THEN 'AR_ADJUSTMENTS_H_V' 
68917                 
68918                ELSE null
68919               END                           object_name
68920             , CASE r
68921                 WHEN 1 THEN 'HEADER' 
68922                 WHEN 2 THEN 'HEADER' 
68923                 WHEN 3 THEN 'HEADER' 
68924                 WHEN 4 THEN 'HEADER' 
68925                 WHEN 5 THEN 'HEADER' 
68926                 WHEN 6 THEN 'HEADER' 
68927                 WHEN 7 THEN 'HEADER' 
68928                 WHEN 8 THEN 'HEADER' 
68929                 
68930                 ELSE null
68931               END                           object_type_code
68932             , CASE r
68933                 WHEN 1 THEN '222' 
68934                 WHEN 2 THEN '222' 
68935                 WHEN 3 THEN '222' 
68936                 WHEN 4 THEN '222' 
68937                 WHEN 5 THEN '222' 
68938                 WHEN 6 THEN '222' 
68939                 WHEN 7 THEN '222' 
68940                 WHEN 8 THEN '222' 
68941                 
68942                 ELSE null
68943               END                           source_application_id
68944             , 'S'             source_type_code
68945             , CASE r
68946                 WHEN 1 THEN 'TRX_RECEIVABLE_CCID' 
68947                 WHEN 2 THEN 'REC_ACT_TYPE' 
68948                 WHEN 3 THEN 'BILL_CUST_ACCOUNT_ID' 
68949                 WHEN 4 THEN 'BILL_USES_SITE_USE_ID' 
68950                 WHEN 5 THEN 'XLA_PARTY_TYPE' 
68951                 WHEN 6 THEN 'ADJ_DOC_SEQUENCE_CATEGORY' 
68952                 WHEN 7 THEN 'ADJ_DOC_SEQUENCE_ID' 
68953                 WHEN 8 THEN 'ADJ_DOC_SEQUENCE_VALUE' 
68954                 
68955                 ELSE null
68956               END                           source_code
68957             , CASE r
68958                 WHEN 1 THEN TO_CHAR(h7.TRX_RECEIVABLE_CCID)
68959                 WHEN 2 THEN TO_CHAR(h6.REC_ACT_TYPE)
68960                 WHEN 3 THEN TO_CHAR(h2.BILL_CUST_ACCOUNT_ID)
68961                 WHEN 4 THEN TO_CHAR(h3.BILL_USES_SITE_USE_ID)
68962                 WHEN 5 THEN TO_CHAR(h7.XLA_PARTY_TYPE)
68963                 WHEN 6 THEN TO_CHAR(h1.ADJ_DOC_SEQUENCE_CATEGORY)
68964                 WHEN 7 THEN TO_CHAR(h1.ADJ_DOC_SEQUENCE_ID)
68965                 WHEN 8 THEN TO_CHAR(h1.ADJ_DOC_SEQUENCE_VALUE)
68966                 
68967                 ELSE null
68968               END                           source_value
68969             , null              source_meaning
68970          FROM xla_events_gt     xet  
68974       , AR_RECEIVABLES_TRX_ACT_S_V  h6
68971       , AR_ADJUSTMENTS_H_V  h1
68972       , AR_BILL_TO_CUSTOMERS_S_V  h2
68973       , AR_BILL_TO_SITE_USES_S_V  h3
68975       , AR_TRANSACTIONS_S_V  h7
68976              ,(select rownum r from all_objects where rownum <= 8 and owner = p_apps_owner)
68977          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
68978            AND xet.event_class_code = C_EVENT_CLASS_CODE
68979               AND h1.event_id = xet.event_id
68980   AND h2.event_id  = h1.event_id
68981   AND h3.event_id  = h1.event_id
68982   AND h6.event_id (+) = h1.event_id
68983   AND h7.event_id  = h1.event_id
68984 
68985 )
68986 ;
68987 --
68988 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
68989 
68990       trace
68991          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
68992          ,p_level    => C_LEVEL_STATEMENT
68993          ,p_module   => l_log_module);
68994 
68995 END IF;
68996 --
68997 
68998 
68999 
69000 --
69001 INSERT INTO xla_diag_sources  --line2
69002 (
69003         event_id
69004       , ledger_id
69005       , sla_ledger_id
69006       , description_language
69007       , object_name
69008       , object_type_code
69009       , line_number
69010       , source_application_id
69011       , source_type_code
69012       , source_code
69013       , source_value
69014       , source_meaning
69015       , created_by
69016       , creation_date
69017       , last_update_date
69018       , last_updated_by
69019       , last_update_login
69020       , program_update_date
69021       , program_application_id
69022       , program_id
69023       , request_id
69024 )
69025 SELECT  event_id
69026       , p_target_ledger_id
69027       , p_sla_ledger_id
69028       , p_language
69029       , object_name
69030       , object_type_code
69031       , line_number
69032       , source_application_id
69033       , source_type_code
69034       , source_code
69035       , SUBSTR(source_value,1,1996)
69036       , SUBSTR(source_meaning ,1,200)
69037       , xla_environment_pkg.g_Usr_Id
69038       , TRUNC(SYSDATE)
69039       , TRUNC(SYSDATE)
69040       , xla_environment_pkg.g_Usr_Id
69041       , xla_environment_pkg.g_Login_Id
69042       , TRUNC(SYSDATE)
69043       , xla_environment_pkg.g_Prog_Appl_Id
69044       , xla_environment_pkg.g_Prog_Id
69045       , xla_environment_pkg.g_Req_Id
69046   FROM (
69047        SELECT xet.event_id                  event_id
69048             , l5.line_number                 line_number
69049             , CASE r
69050                WHEN 1 THEN 'AR_DISTRIBUTIONS_L_V' 
69051                 WHEN 2 THEN 'AR_DISTRIBUTIONS_L_V' 
69052                 WHEN 3 THEN 'AR_DISTRIBUTIONS_L_V' 
69053                 WHEN 4 THEN 'AR_DISTRIBUTIONS_L_V' 
69054                 WHEN 5 THEN 'AR_DISTRIBUTIONS_L_V' 
69055                 WHEN 6 THEN 'AR_DISTRIBUTIONS_L_V' 
69056                 WHEN 7 THEN 'AR_DISTRIBUTIONS_BASE_V' 
69057                 WHEN 8 THEN 'AR_DISTRIBUTIONS_BASE_V' 
69058                 WHEN 9 THEN 'AR_DISTRIBUTIONS_BASE_V' 
69059                 WHEN 10 THEN 'AR_DISTRIBUTIONS_BASE_V' 
69060                 
69061                ELSE null
69062               END                           object_name
69063             , CASE r
69064                 WHEN 1 THEN 'LINE' 
69065                 WHEN 2 THEN 'LINE' 
69066                 WHEN 3 THEN 'LINE' 
69067                 WHEN 4 THEN 'LINE' 
69068                 WHEN 5 THEN 'LINE' 
69069                 WHEN 6 THEN 'LINE' 
69070                 WHEN 7 THEN 'LINE' 
69071                 WHEN 8 THEN 'LINE' 
69072                 WHEN 9 THEN 'LINE' 
69073                 WHEN 10 THEN 'LINE' 
69074                 
69075                 ELSE null
69076               END                           object_type_code
69077             , CASE r
69078                 WHEN 1 THEN '222' 
69079                 WHEN 2 THEN '222' 
69080                 WHEN 3 THEN '222' 
69081                 WHEN 4 THEN '222' 
69082                 WHEN 5 THEN '222' 
69083                 WHEN 6 THEN '222' 
69084                 WHEN 7 THEN '222' 
69085                 WHEN 8 THEN '222' 
69086                 WHEN 9 THEN '222' 
69087                 WHEN 10 THEN '222' 
69088                 
69089                 ELSE null
69090               END                           source_application_id
69091             , 'S'             source_type_code
69092             , CASE r
69093                 WHEN 1 THEN 'DIST_CODE_COMBINATION_ID' 
69094                 WHEN 2 THEN 'DIST_SOURCE_TYPE' 
69095                 WHEN 3 THEN 'DIST_LINE_ID' 
69096                 WHEN 4 THEN 'DISTRIBUTION_TYPE' 
69097                 WHEN 5 THEN 'DIST_ENT_AMT' 
69098                 WHEN 6 THEN 'DIST_CURRENCY_CODE' 
69099                 WHEN 7 THEN 'DIST_CUR_CONVERSION_DATE' 
69100                 WHEN 8 THEN 'DIST_CUR_CONVERSION_RATE' 
69101                 WHEN 9 THEN 'DIST_CUR_CONVERSION_TYPE' 
69102                 WHEN 10 THEN 'DIST_TO_ACCTD_AMT' 
69103                 
69104                 ELSE null
69105               END                           source_code
69106             , CASE r
69107                 WHEN 1 THEN TO_CHAR(l5.DIST_CODE_COMBINATION_ID)
69108                 WHEN 2 THEN TO_CHAR(l5.DIST_SOURCE_TYPE)
69109                 WHEN 3 THEN TO_CHAR(l5.DIST_LINE_ID)
69113                 WHEN 7 THEN TO_CHAR(l4.DIST_CUR_CONVERSION_DATE)
69110                 WHEN 4 THEN TO_CHAR(l5.DISTRIBUTION_TYPE)
69111                 WHEN 5 THEN TO_CHAR(l5.DIST_ENT_AMT)
69112                 WHEN 6 THEN TO_CHAR(l5.DIST_CURRENCY_CODE)
69114                 WHEN 8 THEN TO_CHAR(l4.DIST_CUR_CONVERSION_RATE)
69115                 WHEN 9 THEN TO_CHAR(l4.DIST_CUR_CONVERSION_TYPE)
69116                 WHEN 10 THEN TO_CHAR(l4.DIST_TO_ACCTD_AMT)
69117                 
69118                 ELSE null
69119               END                           source_value
69120             , null              source_meaning
69121          FROM  xla_events_gt     xet  
69122         , AR_DISTRIBUTIONS_BASE_V  l4
69123         , AR_DISTRIBUTIONS_L_V  l5
69124             , (select rownum r from all_objects where rownum <= 10 and owner = p_apps_owner)
69125         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
69126           AND xet.event_class_code = C_EVENT_CLASS_CODE
69127             AND l4.event_id          = xet.event_id
69128   AND l5.event_id    = l4.event_id
69129   AND l5.line_number = l4.line_number
69130 
69131 )
69132 ;
69133 --
69134 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
69135 
69136       trace
69137          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
69138          ,p_level    => C_LEVEL_STATEMENT
69139          ,p_module   => l_log_module);
69140 
69141 END IF;
69142 
69143 
69144 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
69145       trace
69146          (p_msg      => 'END of insert_sources_136'
69147          ,p_level    => C_LEVEL_PROCEDURE
69148          ,p_module   => l_log_module);
69149 END IF;
69150 EXCEPTION
69151   WHEN xla_exceptions_pkg.application_exception THEN
69152       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
69153             trace
69154                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
69155                ,p_level    => C_LEVEL_EXCEPTION
69156                ,p_module   => l_log_module);
69157       END IF;
69158       RAISE;
69159   WHEN OTHERS THEN
69160       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
69161             trace
69162                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
69163                ,p_level    => C_LEVEL_EXCEPTION
69164                ,p_module   => l_log_module);
69165        END IF;
69166        xla_exceptions_pkg.raise_message
69167            (p_location => 'XLA_00222_AAD_S_000006_PKG.insert_sources_136');
69168 END insert_sources_136;
69169 --
69170 
69171 ---------------------------------------
69172 --
69173 -- PRIVATE FUNCTION
69174 --         EventClass_136
69175 --
69176 ----------------------------------------
69177 --
69178 FUNCTION EventClass_136
69179        (p_application_id         IN NUMBER
69180        ,p_base_ledger_id         IN NUMBER
69181        ,p_target_ledger_id       IN NUMBER
69182        ,p_language               IN VARCHAR2
69183        ,p_currency_code          IN VARCHAR2
69184        ,p_sla_ledger_id          IN NUMBER
69185        ,p_pad_start_date         IN DATE
69186        ,p_pad_end_date           IN DATE
69187        ,p_primary_ledger_id      IN NUMBER)
69188 RETURN BOOLEAN IS
69189 --
69190 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'ADJUSTMENT_ALL';
69191 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'ADJUSTMENT';
69192 
69193 l_calculate_acctd_flag   VARCHAR2(1) :='N';
69194 l_calculate_g_l_flag     VARCHAR2(1) :='Y';
69195 --
69196 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
69197 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
69198 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
69199 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
69200 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
69201 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
69202 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
69203 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
69204 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
69205 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
69206 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
69207 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
69208 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
69209 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
69210 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
69211 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
69212 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
69213 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
69214 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
69215 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
69216 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
69217 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
69218 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
69219 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
69220 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
69224 l_previous_event_id                    NUMBER;
69221 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
69222 
69223 l_event_id                             NUMBER;
69225 l_first_event_id                       NUMBER;
69226 l_last_event_id                        NUMBER;
69227 
69228 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
69229 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
69230 --
69231 --
69232 l_result                    BOOLEAN := TRUE;
69233 l_rows                      NUMBER  := 1000;
69234 l_event_type_name           VARCHAR2(80) := 'All';
69235 l_event_class_name          VARCHAR2(80) := 'Adjustment';
69236 l_description               VARCHAR2(4000);
69237 l_transaction_reversal      NUMBER;
69238 l_ae_header_id              NUMBER;
69239 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
69240 l_log_module                VARCHAR2(240);
69241 --
69242 l_acct_reversal_source      VARCHAR2(30);
69243 l_trx_reversal_source       VARCHAR2(30);
69244 
69245 l_continue_with_lines       BOOLEAN := TRUE;
69246 --
69247 l_acc_rev_gl_date_source    DATE;                      -- 4262811
69248 --
69249 type t_array_event_id is table of number index by binary_integer;
69250 
69251 l_rec_array_event                    t_rec_array_event;
69252 l_null_rec_array_event               t_rec_array_event;
69253 l_array_ae_header_id                 xla_number_array_type;
69254 l_actual_flag                        VARCHAR2(1) := NULL;
69255 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
69256 l_balance_type_code                  VARCHAR2(1) :=NULL;
69257 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
69258 
69259 --
69260 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
69261 --
69262 
69263 TYPE t_array_source_16 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_RECEIVABLE_CCID%TYPE INDEX BY BINARY_INTEGER;
69264 TYPE t_array_source_21 IS TABLE OF AR_RECEIVABLES_TRX_ACT_S_V.REC_ACT_TYPE%TYPE INDEX BY BINARY_INTEGER;
69265 TYPE t_array_source_30 IS TABLE OF AR_BILL_TO_CUSTOMERS_S_V.BILL_CUST_ACCOUNT_ID%TYPE INDEX BY BINARY_INTEGER;
69266 TYPE t_array_source_31 IS TABLE OF AR_BILL_TO_SITE_USES_S_V.BILL_USES_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
69267 TYPE t_array_source_32 IS TABLE OF AR_TRANSACTIONS_S_V.XLA_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
69268 TYPE t_array_source_79 IS TABLE OF AR_ADJUSTMENTS_H_V.ADJ_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
69269 TYPE t_array_source_80 IS TABLE OF AR_ADJUSTMENTS_H_V.ADJ_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
69270 TYPE t_array_source_81 IS TABLE OF AR_ADJUSTMENTS_H_V.ADJ_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
69271 
69272 TYPE t_array_source_3 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CODE_COMBINATION_ID%TYPE INDEX BY BINARY_INTEGER;
69273 TYPE t_array_source_20 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_SOURCE_TYPE%TYPE INDEX BY BINARY_INTEGER;
69274 TYPE t_array_source_22 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
69275 TYPE t_array_source_23 IS TABLE OF AR_DISTRIBUTIONS_L_V.DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
69276 TYPE t_array_source_24 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_ENT_AMT%TYPE INDEX BY BINARY_INTEGER;
69277 TYPE t_array_source_25 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
69278 TYPE t_array_source_26 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
69279 TYPE t_array_source_27 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
69280 TYPE t_array_source_28 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
69281 TYPE t_array_source_29 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
69282 
69283 l_array_source_16              t_array_source_16;
69284 l_array_source_21              t_array_source_21;
69285 l_array_source_30              t_array_source_30;
69286 l_array_source_31              t_array_source_31;
69287 l_array_source_32              t_array_source_32;
69288 l_array_source_79              t_array_source_79;
69289 l_array_source_80              t_array_source_80;
69290 l_array_source_81              t_array_source_81;
69291 
69292 l_array_source_3      t_array_source_3;
69293 l_array_source_20      t_array_source_20;
69294 l_array_source_22      t_array_source_22;
69295 l_array_source_23      t_array_source_23;
69296 l_array_source_24      t_array_source_24;
69297 l_array_source_25      t_array_source_25;
69298 l_array_source_26      t_array_source_26;
69299 l_array_source_27      t_array_source_27;
69300 l_array_source_28      t_array_source_28;
69301 l_array_source_29      t_array_source_29;
69302 
69303 --
69304 CURSOR header_cur
69305 IS
69306 SELECT /*+ leading(xet) cardinality(xet,1) */
69307 -- Event Class Code: ADJUSTMENT
69308     xet.entity_id
69309    ,xet.legal_entity_id
69310    ,xet.entity_code
69311    ,xet.transaction_number
69312    ,xet.event_id
69313    ,xet.event_class_code
69314    ,xet.event_type_code
69315    ,xet.event_number
69316    ,xet.event_date
69317    ,xet.transaction_date
69318    ,xet.reference_num_1
69319    ,xet.reference_num_2
69320    ,xet.reference_num_3
69321    ,xet.reference_num_4
69322    ,xet.reference_char_1
69323    ,xet.reference_char_2
69324    ,xet.reference_char_3
69325    ,xet.reference_char_4
69326    ,xet.reference_date_1
69327    ,xet.reference_date_2
69328    ,xet.reference_date_3
69332   , h7.TRX_RECEIVABLE_CCID    source_16
69329    ,xet.reference_date_4
69330    ,xet.event_created_by
69331    ,xet.budgetary_control_flag 
69333   , h6.REC_ACT_TYPE    source_21
69334   , h2.BILL_CUST_ACCOUNT_ID    source_30
69335   , h3.BILL_USES_SITE_USE_ID    source_31
69336   , h7.XLA_PARTY_TYPE    source_32
69337   , h1.ADJ_DOC_SEQUENCE_CATEGORY    source_79
69338   , h1.ADJ_DOC_SEQUENCE_ID    source_80
69339   , h1.ADJ_DOC_SEQUENCE_VALUE    source_81
69340   FROM xla_events_gt     xet 
69341   , AR_ADJUSTMENTS_H_V  h1
69342   , AR_BILL_TO_CUSTOMERS_S_V  h2
69343   , AR_BILL_TO_SITE_USES_S_V  h3
69344   , AR_RECEIVABLES_TRX_ACT_S_V  h6
69345   , AR_TRANSACTIONS_S_V  h7
69346  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
69347    and xet.event_class_code = C_EVENT_CLASS_CODE
69348    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
69349   AND h2.event_id  = h1.event_id
69350   AND h3.event_id  = h1.event_id
69351   AND h6.event_id (+) = h1.event_id
69352   AND h7.event_id  = h1.event_id
69353 
69354  ORDER BY event_id
69355 ;
69356 
69357 
69358 --
69359 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
69360 IS
69361 SELECT  /*+ leading(xet) cardinality(xet,1) */
69362 -- Event Class Code: ADJUSTMENT
69363     xet.entity_id
69364    ,xet.legal_entity_id
69365    ,xet.entity_code
69366    ,xet.transaction_number
69367    ,xet.event_id
69368    ,xet.event_class_code
69369    ,xet.event_type_code
69370    ,xet.event_number
69371    ,xet.event_date
69372    ,xet.transaction_date
69373    ,xet.reference_num_1
69374    ,xet.reference_num_2
69375    ,xet.reference_num_3
69376    ,xet.reference_num_4
69377    ,xet.reference_char_1
69378    ,xet.reference_char_2
69379    ,xet.reference_char_3
69380    ,xet.reference_char_4
69381    ,xet.reference_date_1
69382    ,xet.reference_date_2
69383    ,xet.reference_date_3
69384    ,xet.reference_date_4
69385    ,xet.event_created_by
69386    ,xet.budgetary_control_flag
69387  , l4.LINE_NUMBER  
69388   , l5.DIST_CODE_COMBINATION_ID    source_3
69389   , l5.DIST_SOURCE_TYPE    source_20
69390   , l5.DIST_LINE_ID    source_22
69391   , l5.DISTRIBUTION_TYPE    source_23
69392   , l5.DIST_ENT_AMT    source_24
69393   , l5.DIST_CURRENCY_CODE    source_25
69394   , l4.DIST_CUR_CONVERSION_DATE    source_26
69395   , l4.DIST_CUR_CONVERSION_RATE    source_27
69396   , l4.DIST_CUR_CONVERSION_TYPE    source_28
69397   , l4.DIST_TO_ACCTD_AMT    source_29
69398   FROM xla_events_gt     xet 
69399   , AR_DISTRIBUTIONS_BASE_V  l4
69400   , AR_DISTRIBUTIONS_L_V  l5
69401  WHERE xet.event_id between x_first_event_id and x_last_event_id
69402    and xet.event_date between p_pad_start_date and p_pad_end_date
69403    and xet.event_class_code = C_EVENT_CLASS_CODE
69404    and xet.event_status_code <> 'N'   AND l4.event_id      = xet.event_id
69405   AND l5.event_id    = l4.event_id
69406   AND l5.line_number = l4.line_number
69407 ;
69408 
69409 --
69410 BEGIN
69411 IF g_log_enabled THEN
69412    l_log_module := C_DEFAULT_MODULE||'.EventClass_136';
69413 END IF;
69414 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
69415    trace
69416       (p_msg      => 'BEGIN of EventClass_136'
69417       ,p_level    => C_LEVEL_PROCEDURE
69418       ,p_module   => l_log_module);
69419 END IF;
69420 
69421 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
69422    trace
69423       (p_msg      => 'p_application_id = '||p_application_id||
69424                      ' - p_base_ledger_id = '||p_base_ledger_id||
69425                      ' - p_target_ledger_id  = '||p_target_ledger_id||
69426                      ' - p_language = '||p_language||
69427                      ' - p_currency_code = '||p_currency_code||
69428                      ' - p_sla_ledger_id = '||p_sla_ledger_id
69429       ,p_level    => C_LEVEL_STATEMENT
69430       ,p_module   => l_log_module);
69431 END IF;
69432 --
69433 -- initialze arrays
69434 --
69435 g_array_event.DELETE;
69436 l_rec_array_event := l_null_rec_array_event;
69437 --
69438 --------------------------------------
69439 -- 4262811 Initialze MPA Line Number
69440 --------------------------------------
69441 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
69442 
69443 --
69444 
69445 --
69446 OPEN header_cur;
69447 --
69448 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
69449    trace
69450    (p_msg      => 'SQL - FETCH header_cur'
69451    ,p_level    => C_LEVEL_STATEMENT
69452    ,p_module   => l_log_module);
69453 END IF;
69454 --
69455 LOOP
69456 FETCH header_cur BULK COLLECT INTO
69457         l_array_entity_id
69458       , l_array_legal_entity_id
69459       , l_array_entity_code
69460       , l_array_transaction_num
69461       , l_array_event_id
69462       , l_array_class_code
69463       , l_array_event_type
69464       , l_array_event_number
69465       , l_array_event_date
69466       , l_array_transaction_date
69467       , l_array_reference_num_1
69468       , l_array_reference_num_2
69469       , l_array_reference_num_3
69470       , l_array_reference_num_4
69471       , l_array_reference_char_1
69472       , l_array_reference_char_2
69473       , l_array_reference_char_3
69474       , l_array_reference_char_4
69475       , l_array_reference_date_1
69476       , l_array_reference_date_2
69480       , l_array_budgetary_control_flag 
69477       , l_array_reference_date_3
69478       , l_array_reference_date_4
69479       , l_array_event_created_by
69481       , l_array_source_16
69482       , l_array_source_21
69483       , l_array_source_30
69484       , l_array_source_31
69485       , l_array_source_32
69486       , l_array_source_79
69487       , l_array_source_80
69488       , l_array_source_81
69489       LIMIT l_rows;
69490 --
69491 IF (C_LEVEL_EVENT >= g_log_level) THEN
69492    trace
69493    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
69494    ,p_level    => C_LEVEL_EVENT
69495    ,p_module   => l_log_module);
69496 END IF;
69497 --
69498 EXIT WHEN l_array_entity_id.COUNT = 0;
69499 
69500 -- initialize arrays
69501 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
69502 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
69503 
69504 --
69505 -- Bug 4458708
69506 --
69507 XLA_AE_LINES_PKG.g_LineNumber := 0;
69508 
69509 
69510 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
69511 g_last_hdr_idx := l_array_event_id.LAST;
69512 --
69513 -- loop for the headers. Each iteration is for each header extract row
69514 -- fetched in header cursor
69515 --
69516 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
69517 
69518 --
69519 -- set event info as cache for other routines to refer event attributes
69520 --
69521 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
69522    (p_application_id           => p_application_id
69523    ,p_primary_ledger_id        => p_primary_ledger_id
69524    ,p_base_ledger_id           => p_base_ledger_id
69525    ,p_target_ledger_id         => p_target_ledger_id
69526    ,p_entity_id                => l_array_entity_id(hdr_idx)
69527    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
69528    ,p_entity_code              => l_array_entity_code(hdr_idx)
69529    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
69530    ,p_event_id                 => l_array_event_id(hdr_idx)
69531    ,p_event_class_code         => l_array_class_code(hdr_idx)
69532    ,p_event_type_code          => l_array_event_type(hdr_idx)
69533    ,p_event_number             => l_array_event_number(hdr_idx)
69534    ,p_event_date               => l_array_event_date(hdr_idx)
69535    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
69536    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
69537    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
69538    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
69539    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
69540    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
69541    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
69542    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
69543    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
69544    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
69545    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
69546    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
69547    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
69548    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
69549    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
69550 
69551 --
69552 -- set the status of entry to C_VALID (0)
69553 --
69554 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
69555 
69556 --
69557 -- initialize a row for ae header
69558 --
69559 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
69560 
69561 l_event_id := l_array_event_id(hdr_idx);
69562 
69563 --
69564 -- storing the hdr_idx for event. May be used by line cursor.
69565 --
69566 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
69567 
69568 --
69569 -- store sources from header extract. This can be improved to
69570 -- store only those sources from header extract that may be used in lines
69571 --
69572 
69573 g_array_event(l_event_id).array_value_num('source_16') := l_array_source_16(hdr_idx);
69574 g_array_event(l_event_id).array_value_char('source_21') := l_array_source_21(hdr_idx);
69575 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
69576 g_array_event(l_event_id).array_value_num('source_31') := l_array_source_31(hdr_idx);
69577 g_array_event(l_event_id).array_value_char('source_32') := l_array_source_32(hdr_idx);
69578 g_array_event(l_event_id).array_value_char('source_79') := l_array_source_79(hdr_idx);
69579 g_array_event(l_event_id).array_value_num('source_80') := l_array_source_80(hdr_idx);
69580 g_array_event(l_event_id).array_value_num('source_81') := l_array_source_81(hdr_idx);
69581 
69582 --
69583 -- initilaize the status of ae headers for diffrent balance types
69584 -- the status is initialised to C_NOT_CREATED (2)
69585 --
69586 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
69587 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
69588 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
69589 
69590 --
69591 -- call api to validate and store accounting attributes for header
69592 --
69593 
69594 ------------------------------------------------------------
69595 -- Accrual Reversal : to get date for Standard Source (NONE)
69599      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
69596 ------------------------------------------------------------
69597 l_acc_rev_gl_date_source := NULL;
69598 
69600       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_79');
69601      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
69602       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_80');
69603      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
69604       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_81');
69605      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
69606       l_rec_acct_attrs.array_date_value(4) := 
69607 xla_ae_sources_pkg.GetSystemSourceDate(
69608    p_source_code           => 'XLA_EVENT_DATE'
69609  , p_source_type_code      => 'Y'
69610  , p_source_application_id =>  602
69611 );
69612 
69613 
69614 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
69615 
69616 XLA_AE_HEADER_PKG.SetJeCategoryName;
69617 
69618 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
69619 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
69620 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
69621 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
69622 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
69623 
69624 
69625 -- No header level analytical criteria
69626 
69627 --
69628 --accounting attribute enhancement, bug 3612931
69629 --
69630 l_trx_reversal_source := SUBSTR(NULL, 1,30);
69631 
69632 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
69633    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
69634 
69635    xla_accounting_err_pkg.build_message
69636       (p_appli_s_name            => 'XLA'
69637       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
69638       ,p_token_1                 => 'ACCT_ATTR_NAME'
69639       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
69640       ,p_token_2                 => 'PRODUCT_NAME'
69641       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
69642       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
69643       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
69644       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
69645 
69646 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
69647    --
69648    -- following sets the accounting attributes needed to reverse
69649    -- accounting for a distributeion
69650    --
69651    xla_ae_lines_pkg.SetTrxReversalAttrs
69652       (p_event_id              => l_event_id
69653       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
69654       ,p_trx_reversal_source   => l_trx_reversal_source);
69655 
69656 END IF;
69657 
69658 
69659 ----------------------------------------------------------------
69660 -- 4262811 -  update the header statuses to invalid in need be
69661 ----------------------------------------------------------------
69662 --
69663 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
69664 
69665 
69666   -----------------------------------------------
69667   -- No accrual reversal for the event class/type
69668   -----------------------------------------------
69669 ----------------------------------------------------------------
69670 
69671 --
69672 -- this ends the header loop iteration for one bulk fetch
69673 --
69674 END LOOP;
69675 
69676 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
69677 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
69678 
69679 --
69680 -- insert dummy rows into lines gt table that were created due to
69681 -- transaction reversals
69682 --
69683 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
69684    l_result := XLA_AE_LINES_PKG.InsertLines;
69685 END IF;
69686 
69687 --
69688 -- reset the temp_line_num for each set of events fetched from header
69689 -- cursor rather than doing it for each new event in line cursor
69690 -- Bug 3939231
69691 --
69692 xla_ae_lines_pkg.g_temp_line_num := 0;
69693 
69694 
69695 
69696 --
69697 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
69698 --
69699 --
69700 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
69701 
69702       trace
69703          (p_msg      => 'SQL - FETCH line_cur'
69704          ,p_level    => C_LEVEL_STATEMENT
69705          ,p_module   => l_log_module);
69706 
69707 END IF;
69708 --
69709 --
69710 LOOP
69711   --
69712   FETCH line_cur BULK COLLECT INTO
69713         l_array_entity_id
69714       , l_array_legal_entity_id
69715       , l_array_entity_code
69716       , l_array_transaction_num
69717       , l_array_event_id
69718       , l_array_class_code
69719       , l_array_event_type
69720       , l_array_event_number
69721       , l_array_event_date
69722       , l_array_transaction_date
69723       , l_array_reference_num_1
69724       , l_array_reference_num_2
69728       , l_array_reference_char_2
69725       , l_array_reference_num_3
69726       , l_array_reference_num_4
69727       , l_array_reference_char_1
69729       , l_array_reference_char_3
69730       , l_array_reference_char_4
69731       , l_array_reference_date_1
69732       , l_array_reference_date_2
69733       , l_array_reference_date_3
69734       , l_array_reference_date_4
69735       , l_array_event_created_by
69736       , l_array_budgetary_control_flag
69737       , l_array_extract_line_num 
69738       , l_array_source_3
69739       , l_array_source_20
69740       , l_array_source_22
69741       , l_array_source_23
69742       , l_array_source_24
69743       , l_array_source_25
69744       , l_array_source_26
69745       , l_array_source_27
69746       , l_array_source_28
69747       , l_array_source_29
69748       LIMIT l_rows;
69749 
69750   --
69751   IF (C_LEVEL_EVENT >= g_log_level) THEN
69752             trace
69753                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
69754                ,p_level    => C_LEVEL_EVENT
69755                ,p_module   => l_log_module);
69756   END IF;
69757   --
69758   EXIT WHEN l_array_entity_id.count = 0;
69759 
69760   XLA_AE_LINES_PKG.g_rec_lines := null;
69761 
69762 --
69763 -- Bug 4458708
69764 --
69765 XLA_AE_LINES_PKG.g_LineNumber := 0;
69766 --
69767 --
69768 
69769 FOR Idx IN 1..l_array_event_id.count LOOP
69770    --
69771    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
69772    --
69773    l_event_id := l_array_event_id(idx);  -- 5648433
69774 
69775    --
69776    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
69777    --
69778 
69779    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
69780              (g_array_event(l_event_id).array_value_num('header_index'))
69781          ,'N'
69782          ) <> 'Y'
69783    THEN
69784       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
69785          trace
69786             (p_msg      => 'Trancaction revesal option is not Y '
69787             ,p_level    => C_LEVEL_STATEMENT
69788             ,p_module   => l_log_module);
69789       END IF;
69790 
69791 --
69792 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
69793 --
69794 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
69795 --
69796 -- set event info as cache for other routines to refer event attributes
69797 --
69798 
69799 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
69800    l_previous_event_id := l_event_id;
69801 
69802    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
69803       (p_application_id           => p_application_id
69804       ,p_primary_ledger_id        => p_primary_ledger_id
69805       ,p_base_ledger_id           => p_base_ledger_id
69806       ,p_target_ledger_id         => p_target_ledger_id
69807       ,p_entity_id                => l_array_entity_id(Idx)
69808       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
69809       ,p_entity_code              => l_array_entity_code(Idx)
69810       ,p_transaction_num          => l_array_transaction_num(Idx)
69811       ,p_event_id                 => l_array_event_id(Idx)
69812       ,p_event_class_code         => l_array_class_code(Idx)
69813       ,p_event_type_code          => l_array_event_type(Idx)
69814       ,p_event_number             => l_array_event_number(Idx)
69815       ,p_event_date               => l_array_event_date(Idx)
69816       ,p_transaction_date         => l_array_transaction_date(Idx)
69817       ,p_reference_num_1          => l_array_reference_num_1(Idx)
69818       ,p_reference_num_2          => l_array_reference_num_2(Idx)
69819       ,p_reference_num_3          => l_array_reference_num_3(Idx)
69820       ,p_reference_num_4          => l_array_reference_num_4(Idx)
69821       ,p_reference_char_1         => l_array_reference_char_1(Idx)
69822       ,p_reference_char_2         => l_array_reference_char_2(Idx)
69823       ,p_reference_char_3         => l_array_reference_char_3(Idx)
69824       ,p_reference_char_4         => l_array_reference_char_4(Idx)
69825       ,p_reference_date_1         => l_array_reference_date_1(Idx)
69826       ,p_reference_date_2         => l_array_reference_date_2(Idx)
69827       ,p_reference_date_3         => l_array_reference_date_3(Idx)
69828       ,p_reference_date_4         => l_array_reference_date_4(Idx)
69829       ,p_event_created_by         => l_array_event_created_by(Idx)
69830       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
69831        --
69832 END IF;
69833 
69834 
69835 
69836 --
69837 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
69838 
69839 l_acct_reversal_source := SUBSTR(NULL, 1,30);
69840 
69841 IF l_continue_with_lines THEN
69842    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
69843       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
69844 
69845       xla_accounting_err_pkg.build_message
69846          (p_appli_s_name            => 'XLA'
69847          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
69848          ,p_token_1                 => 'LINE_NUMBER'
69849          ,p_value_1                 => l_array_extract_line_num(Idx)
69850          ,p_token_2                 => 'PRODUCT_NAME'
69854          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
69851          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
69852          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
69853          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
69855 
69856    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
69857       --
69858       -- following sets the accounting attributes needed to reverse
69859       -- accounting for a distributeion
69860       --
69861 
69862       --
69863       -- 5217187
69864       --
69865       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
69866       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
69867                                        g_array_event(l_event_id).array_value_num('header_index'));
69868       --
69869       --
69870 
69871       -- No reversal code generated
69872 
69873       xla_ae_lines_pkg.SetAcctReversalAttrs
69874          (p_event_id             => l_event_id
69875          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
69876          ,p_calculate_acctd_flag => l_calculate_acctd_flag
69877          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
69878    END IF;
69879 
69880    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
69881        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
69882 
69883 --
69884 AcctLineType_33 (
69885  p_application_id  => p_application_id
69886  ,p_event_id     => l_event_id
69887  ,p_calculate_acctd_flag => l_calculate_acctd_flag
69888  ,p_calculate_g_l_flag => l_calculate_g_l_flag
69889  ,p_actual_flag => l_actual_flag
69890  ,p_balance_type_code => l_balance_type_code
69891  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
69892  
69893  , p_source_3 => l_array_source_3(Idx)
69894  , p_source_20 => l_array_source_20(Idx)
69895  , p_source_21 => g_array_event(l_event_id).array_value_char('source_21')
69896  , p_source_22 => l_array_source_22(Idx)
69897  , p_source_23 => l_array_source_23(Idx)
69898  , p_source_24 => l_array_source_24(Idx)
69899  , p_source_25 => l_array_source_25(Idx)
69900  , p_source_26 => l_array_source_26(Idx)
69901  , p_source_27 => l_array_source_27(Idx)
69902  , p_source_28 => l_array_source_28(Idx)
69903  , p_source_29 => l_array_source_29(Idx)
69904  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
69905  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
69906  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
69907  );
69908 If(l_balance_type_code = 'A') THEN
69909   l_actual_gain_loss_ref := l_gain_or_loss_ref;
69910 END IF;
69911 
69912 --
69913 
69914 
69915 --
69916 AcctLineType_34 (
69917  p_application_id  => p_application_id
69918  ,p_event_id     => l_event_id
69919  ,p_calculate_acctd_flag => l_calculate_acctd_flag
69920  ,p_calculate_g_l_flag => l_calculate_g_l_flag
69921  ,p_actual_flag => l_actual_flag
69922  ,p_balance_type_code => l_balance_type_code
69923  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
69924  
69925  , p_source_3 => l_array_source_3(Idx)
69926  , p_source_20 => l_array_source_20(Idx)
69927  , p_source_21 => g_array_event(l_event_id).array_value_char('source_21')
69928  , p_source_22 => l_array_source_22(Idx)
69929  , p_source_23 => l_array_source_23(Idx)
69930  , p_source_24 => l_array_source_24(Idx)
69931  , p_source_25 => l_array_source_25(Idx)
69932  , p_source_26 => l_array_source_26(Idx)
69933  , p_source_27 => l_array_source_27(Idx)
69934  , p_source_28 => l_array_source_28(Idx)
69935  , p_source_29 => l_array_source_29(Idx)
69936  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
69937  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
69938  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
69939  );
69940 If(l_balance_type_code = 'A') THEN
69941   l_actual_gain_loss_ref := l_gain_or_loss_ref;
69942 END IF;
69943 
69944 --
69945 
69946 
69947 --
69948 AcctLineType_35 (
69949  p_application_id  => p_application_id
69950  ,p_event_id     => l_event_id
69951  ,p_calculate_acctd_flag => l_calculate_acctd_flag
69952  ,p_calculate_g_l_flag => l_calculate_g_l_flag
69953  ,p_actual_flag => l_actual_flag
69954  ,p_balance_type_code => l_balance_type_code
69955  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
69956  
69957  , p_source_3 => l_array_source_3(Idx)
69958  , p_source_20 => l_array_source_20(Idx)
69959  , p_source_22 => l_array_source_22(Idx)
69960  , p_source_23 => l_array_source_23(Idx)
69961  , p_source_24 => l_array_source_24(Idx)
69962  , p_source_25 => l_array_source_25(Idx)
69963  , p_source_26 => l_array_source_26(Idx)
69964  , p_source_27 => l_array_source_27(Idx)
69965  , p_source_28 => l_array_source_28(Idx)
69966  , p_source_29 => l_array_source_29(Idx)
69967  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
69968  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
69969  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
69970  );
69971 If(l_balance_type_code = 'A') THEN
69972   l_actual_gain_loss_ref := l_gain_or_loss_ref;
69973 END IF;
69974 
69975 --
69976 
69977 
69978 --
69979 AcctLineType_36 (
69980  p_application_id  => p_application_id
69984  ,p_actual_flag => l_actual_flag
69981  ,p_event_id     => l_event_id
69982  ,p_calculate_acctd_flag => l_calculate_acctd_flag
69983  ,p_calculate_g_l_flag => l_calculate_g_l_flag
69985  ,p_balance_type_code => l_balance_type_code
69986  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
69987  
69988  , p_source_3 => l_array_source_3(Idx)
69989  , p_source_20 => l_array_source_20(Idx)
69990  , p_source_22 => l_array_source_22(Idx)
69991  , p_source_23 => l_array_source_23(Idx)
69992  , p_source_24 => l_array_source_24(Idx)
69993  , p_source_25 => l_array_source_25(Idx)
69994  , p_source_26 => l_array_source_26(Idx)
69995  , p_source_27 => l_array_source_27(Idx)
69996  , p_source_28 => l_array_source_28(Idx)
69997  , p_source_29 => l_array_source_29(Idx)
69998  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
69999  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
70000  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
70001  );
70002 If(l_balance_type_code = 'A') THEN
70003   l_actual_gain_loss_ref := l_gain_or_loss_ref;
70004 END IF;
70005 
70006 --
70007 
70008 
70009 --
70010 AcctLineType_37 (
70011  p_application_id  => p_application_id
70012  ,p_event_id     => l_event_id
70013  ,p_calculate_acctd_flag => l_calculate_acctd_flag
70014  ,p_calculate_g_l_flag => l_calculate_g_l_flag
70015  ,p_actual_flag => l_actual_flag
70016  ,p_balance_type_code => l_balance_type_code
70017  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
70018  
70019  , p_source_3 => l_array_source_3(Idx)
70020  , p_source_20 => l_array_source_20(Idx)
70021  , p_source_22 => l_array_source_22(Idx)
70022  , p_source_23 => l_array_source_23(Idx)
70023  , p_source_24 => l_array_source_24(Idx)
70024  , p_source_25 => l_array_source_25(Idx)
70025  , p_source_26 => l_array_source_26(Idx)
70026  , p_source_27 => l_array_source_27(Idx)
70027  , p_source_28 => l_array_source_28(Idx)
70028  , p_source_29 => l_array_source_29(Idx)
70029  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
70030  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
70031  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
70032  );
70033 If(l_balance_type_code = 'A') THEN
70034   l_actual_gain_loss_ref := l_gain_or_loss_ref;
70035 END IF;
70036 
70037 --
70038 
70039 
70040 --
70041 AcctLineType_86 (
70042  p_application_id  => p_application_id
70043  ,p_event_id     => l_event_id
70044  ,p_calculate_acctd_flag => l_calculate_acctd_flag
70045  ,p_calculate_g_l_flag => l_calculate_g_l_flag
70046  ,p_actual_flag => l_actual_flag
70047  ,p_balance_type_code => l_balance_type_code
70048  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
70049  
70050  , p_source_3 => l_array_source_3(Idx)
70051  , p_source_16 => g_array_event(l_event_id).array_value_num('source_16')
70052  , p_source_20 => l_array_source_20(Idx)
70053  , p_source_21 => g_array_event(l_event_id).array_value_char('source_21')
70054  , p_source_22 => l_array_source_22(Idx)
70055  , p_source_23 => l_array_source_23(Idx)
70056  , p_source_24 => l_array_source_24(Idx)
70057  , p_source_25 => l_array_source_25(Idx)
70058  , p_source_26 => l_array_source_26(Idx)
70059  , p_source_27 => l_array_source_27(Idx)
70060  , p_source_28 => l_array_source_28(Idx)
70061  , p_source_29 => l_array_source_29(Idx)
70062  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
70063  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
70064  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
70065  );
70066 If(l_balance_type_code = 'A') THEN
70067   l_actual_gain_loss_ref := l_gain_or_loss_ref;
70068 END IF;
70069 
70070 --
70071 
70072       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
70073       -- or secondary ledger that has different currency with primary
70074       -- or alc that is calculated by sla
70075       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
70076             (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'))
70077 
70078 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
70079 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
70080           AND (l_actual_flag = 'A')) THEN
70081         XLA_AE_LINES_PKG.CreateGainOrLossLines(
70082           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
70083          ,p_application_id   => p_application_id
70084          ,p_amb_context_code => 'DEFAULT'
70085          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
70086          ,p_event_class_code => C_EVENT_CLASS_CODE
70087          ,p_event_type_code  => C_EVENT_TYPE_CODE
70088          
70089          ,p_gain_ccid        => -1
70090          ,p_loss_ccid        => -1
70091 
70092          ,p_actual_flag      => l_actual_flag
70093          ,p_enc_flag         => null
70094          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
70095          ,p_enc_g_l_ref      => null
70096          );
70097       END IF;
70098    END IF;
70099 END IF;
70100 
70101    ELSE
70102       --
70103       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
70104       --
70108             ,p_level    => C_LEVEL_STATEMENT
70105       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
70106          trace
70107             (p_msg      => 'Trancaction revesal option is Y'
70109             ,p_module   => l_log_module);
70110       END IF;
70111    END IF;
70112 
70113 END LOOP;
70114 l_result := XLA_AE_LINES_PKG.InsertLines ;
70115 end loop;
70116 close line_cur;
70117 
70118 
70119 --
70120 -- insert headers into xla_ae_headers_gt table
70121 --
70122 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
70123 
70124 -- insert into errors table here.
70125 
70126 END LOOP;
70127 
70128 --
70129 -- 4865292
70130 --
70131 -- Compare g_hdr_extract_count with event count in
70132 -- CreateHeadersAndLines.
70133 --
70134 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
70135 
70136 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
70137    trace (p_msg     => '# rows extracted from header extract objects '
70138                     || ' (running total): '
70139                     || g_hdr_extract_count
70140          ,p_level   => C_LEVEL_STATEMENT
70141          ,p_module  => l_log_module);
70142 END IF;
70143 
70144 CLOSE header_cur;
70145 --
70146 
70147 --
70148 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
70149    trace
70150       (p_msg      => 'END of EventClass_136'
70151       ,p_level    => C_LEVEL_PROCEDURE
70152       ,p_module   => l_log_module);
70153 END IF;
70154 --
70155 RETURN l_result;
70156 EXCEPTION
70157 WHEN xla_exceptions_pkg.application_exception THEN
70158    
70159 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
70160 
70161    
70162 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
70163 
70164    RAISE;
70165 
70166 WHEN NO_DATA_FOUND THEN
70167 
70168 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
70169 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
70170 
70171 FOR header_record IN header_cur
70172 LOOP
70173     l_array_header_events(header_record.event_id) := header_record.event_id;
70174 END LOOP;
70175 
70176 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
70177 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
70178 
70179 fnd_file.put_line(fnd_file.LOG, '                    ');
70180 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
70181 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
70182 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
70183 
70184 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
70185 LOOP
70186 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
70187 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
70188         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
70189 	END IF;
70190 END LOOP;
70191 
70192 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
70193 fnd_file.put_line(fnd_file.LOG, '                    ');
70194 
70195 
70196 xla_exceptions_pkg.raise_message
70197       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_136');
70198 
70199 
70200 WHEN OTHERS THEN
70201    xla_exceptions_pkg.raise_message
70202       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_136');
70203 END EventClass_136;
70204 --
70205 
70206 ---------------------------------------
70207 --
70208 -- PRIVATE PROCEDURE
70209 --         insert_sources_137
70210 --
70211 ----------------------------------------
70212 --
70213 PROCEDURE insert_sources_137(
70214                                 p_target_ledger_id       IN NUMBER
70215                               , p_language               IN VARCHAR2
70216                               , p_sla_ledger_id          IN NUMBER
70217                               , p_pad_start_date         IN DATE
70218                               , p_pad_end_date           IN DATE
70219                          )
70220 IS
70221 
70222 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CHARGEBACK_ALL';
70223 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CHARGEBACK';
70224 p_apps_owner                   VARCHAR2(30);
70225 l_log_module                   VARCHAR2(240);
70226 BEGIN
70227 IF g_log_enabled THEN
70228       l_log_module := C_DEFAULT_MODULE||'.insert_sources_137';
70229 END IF;
70230 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
70231 
70232       trace
70233          (p_msg      => 'BEGIN of insert_sources_137'
70234          ,p_level    => C_LEVEL_PROCEDURE
70235          ,p_module   => l_log_module);
70236 
70237 END IF;
70238 
70239 -- select APPS owner
70240 SELECT oracle_username
70241   INTO p_apps_owner
70242   FROM fnd_oracle_userid
70243  WHERE read_only_flag = 'U'
70244 ;
70245 
70246 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
70247       trace
70248          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
70249                         ' - p_language = '||p_language||
70250                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
70251                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
70255          ,p_module   => l_log_module);
70252                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
70253                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
70254          ,p_level    => C_LEVEL_STATEMENT
70256 END IF;
70257 
70258 
70259 --
70260 INSERT INTO xla_diag_sources --hdr2
70261 (
70262         event_id
70263       , ledger_id
70264       , sla_ledger_id
70265       , description_language
70266       , object_name
70267       , object_type_code
70268       , line_number
70269       , source_application_id
70270       , source_type_code
70271       , source_code
70272       , source_value
70273       , source_meaning
70274       , created_by
70275       , creation_date
70276       , last_update_date
70277       , last_updated_by
70278       , last_update_login
70279       , program_update_date
70280       , program_application_id
70281       , program_id
70282       , request_id
70283 )
70284 SELECT
70285         event_id
70286       , p_target_ledger_id
70287       , p_sla_ledger_id
70288       , p_language
70289       , object_name
70290       , object_type_code
70291       , line_number
70292       , source_application_id
70293       , source_type_code
70294       , source_code
70295       , SUBSTR(source_value ,1,1996)
70296       , SUBSTR(source_meaning ,1,200)
70297       , xla_environment_pkg.g_Usr_Id
70298       , TRUNC(SYSDATE)
70299       , TRUNC(SYSDATE)
70300       , xla_environment_pkg.g_Usr_Id
70301       , xla_environment_pkg.g_Login_Id
70302       , TRUNC(SYSDATE)
70303       , xla_environment_pkg.g_Prog_Appl_Id
70304       , xla_environment_pkg.g_Prog_Id
70305       , xla_environment_pkg.g_Req_Id
70306   FROM (
70307        SELECT xet.event_id                  event_id
70308             , 0                          line_number
70309             , CASE r
70310                WHEN 1 THEN 'AR_BILL_TO_CUSTOMERS_S_V' 
70311                 WHEN 2 THEN 'AR_BILL_TO_SITE_USES_S_V' 
70312                 WHEN 3 THEN 'AR_TRANSACTIONS_S_V' 
70313                 WHEN 4 THEN 'AR_TRANSACTIONS_S_V' 
70314                 WHEN 5 THEN 'AR_TRANSACTIONS_S_V' 
70315                 WHEN 6 THEN 'AR_TRANSACTIONS_S_V' 
70316                 WHEN 7 THEN 'AR_TRANSACTIONS_S_V' 
70317                 
70318                ELSE null
70319               END                           object_name
70320             , CASE r
70321                 WHEN 1 THEN 'HEADER' 
70322                 WHEN 2 THEN 'HEADER' 
70323                 WHEN 3 THEN 'HEADER' 
70324                 WHEN 4 THEN 'HEADER' 
70325                 WHEN 5 THEN 'HEADER' 
70326                 WHEN 6 THEN 'HEADER' 
70327                 WHEN 7 THEN 'HEADER' 
70328                 
70329                 ELSE null
70330               END                           object_type_code
70331             , CASE r
70332                 WHEN 1 THEN '222' 
70333                 WHEN 2 THEN '222' 
70334                 WHEN 3 THEN '222' 
70335                 WHEN 4 THEN '222' 
70336                 WHEN 5 THEN '222' 
70337                 WHEN 6 THEN '222' 
70338                 WHEN 7 THEN '222' 
70339                 
70340                 ELSE null
70341               END                           source_application_id
70342             , 'S'             source_type_code
70343             , CASE r
70344                 WHEN 1 THEN 'BILL_CUST_ACCOUNT_ID' 
70345                 WHEN 2 THEN 'BILL_USES_SITE_USE_ID' 
70346                 WHEN 3 THEN 'XLA_PARTY_TYPE' 
70347                 WHEN 4 THEN 'TRX_INVOICE_CURRENCY_CODE' 
70348                 WHEN 5 THEN 'TRX_DOC_SEQUENCE_CATEGORY' 
70349                 WHEN 6 THEN 'TRX_DOC_SEQUENCE_ID' 
70350                 WHEN 7 THEN 'TRX_DOC_SEQUENCE_VALUE' 
70351                 
70352                 ELSE null
70353               END                           source_code
70354             , CASE r
70355                 WHEN 1 THEN TO_CHAR(h1.BILL_CUST_ACCOUNT_ID)
70356                 WHEN 2 THEN TO_CHAR(h2.BILL_USES_SITE_USE_ID)
70357                 WHEN 3 THEN TO_CHAR(h5.XLA_PARTY_TYPE)
70358                 WHEN 4 THEN TO_CHAR(h5.TRX_INVOICE_CURRENCY_CODE)
70359                 WHEN 5 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_CATEGORY)
70360                 WHEN 6 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_ID)
70361                 WHEN 7 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_VALUE)
70362                 
70363                 ELSE null
70364               END                           source_value
70365             , null              source_meaning
70366          FROM xla_events_gt     xet  
70367       , AR_BILL_TO_CUSTOMERS_S_V  h1
70368       , AR_BILL_TO_SITE_USES_S_V  h2
70369       , AR_TRANSACTIONS_S_V  h5
70370              ,(select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
70371          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
70372            AND xet.event_class_code = C_EVENT_CLASS_CODE
70373               AND h1.event_id = xet.event_id
70374   AND h2.event_id  = h1.event_id
70375   AND h5.event_id  = h1.event_id
70376 
70377 )
70378 ;
70379 --
70380 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
70381 
70382       trace
70383          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
70384          ,p_level    => C_LEVEL_STATEMENT
70385          ,p_module   => l_log_module);
70386 
70387 END IF;
70391 
70388 --
70389 
70390 
70392 --
70393 INSERT INTO xla_diag_sources  --line2
70394 (
70395         event_id
70396       , ledger_id
70397       , sla_ledger_id
70398       , description_language
70399       , object_name
70400       , object_type_code
70401       , line_number
70402       , source_application_id
70403       , source_type_code
70404       , source_code
70405       , source_value
70406       , source_meaning
70407       , created_by
70408       , creation_date
70409       , last_update_date
70410       , last_updated_by
70411       , last_update_login
70412       , program_update_date
70413       , program_application_id
70414       , program_id
70415       , request_id
70416 )
70417 SELECT  event_id
70418       , p_target_ledger_id
70419       , p_sla_ledger_id
70420       , p_language
70421       , object_name
70422       , object_type_code
70423       , line_number
70424       , source_application_id
70425       , source_type_code
70426       , source_code
70427       , SUBSTR(source_value,1,1996)
70428       , SUBSTR(source_meaning ,1,200)
70429       , xla_environment_pkg.g_Usr_Id
70430       , TRUNC(SYSDATE)
70431       , TRUNC(SYSDATE)
70432       , xla_environment_pkg.g_Usr_Id
70433       , xla_environment_pkg.g_Login_Id
70434       , TRUNC(SYSDATE)
70435       , xla_environment_pkg.g_Prog_Appl_Id
70436       , xla_environment_pkg.g_Prog_Id
70437       , xla_environment_pkg.g_Req_Id
70438   FROM (
70439        SELECT xet.event_id                  event_id
70440             , l4.line_number                 line_number
70441             , CASE r
70442                WHEN 1 THEN 'AR_CUST_TRX_LINES_L_V' 
70443                 WHEN 2 THEN 'AR_CUST_TRX_LINES_L_V' 
70444                 WHEN 3 THEN 'AR_CUST_TRX_LINES_L_V' 
70445                 WHEN 4 THEN 'AR_CUST_TRX_LINES_L_V' 
70446                 WHEN 5 THEN 'AR_CUST_TRX_LINES_L_V' 
70447                 WHEN 6 THEN 'AR_CUST_TRX_LINES_BASE_V' 
70448                 WHEN 7 THEN 'AR_CUST_TRX_LINES_BASE_V' 
70449                 WHEN 8 THEN 'AR_CUST_TRX_LINES_BASE_V' 
70450                 WHEN 9 THEN 'AR_CUST_TRX_LINES_BASE_V' 
70451                 
70452                ELSE null
70453               END                           object_name
70454             , CASE r
70455                 WHEN 1 THEN 'LINE' 
70456                 WHEN 2 THEN 'LINE' 
70457                 WHEN 3 THEN 'LINE' 
70458                 WHEN 4 THEN 'LINE' 
70459                 WHEN 5 THEN 'LINE' 
70460                 WHEN 6 THEN 'LINE' 
70461                 WHEN 7 THEN 'LINE' 
70462                 WHEN 8 THEN 'LINE' 
70463                 WHEN 9 THEN 'LINE' 
70464                 
70465                 ELSE null
70466               END                           object_type_code
70467             , CASE r
70468                 WHEN 1 THEN '222' 
70469                 WHEN 2 THEN '222' 
70470                 WHEN 3 THEN '222' 
70471                 WHEN 4 THEN '222' 
70472                 WHEN 5 THEN '222' 
70473                 WHEN 6 THEN '222' 
70474                 WHEN 7 THEN '222' 
70475                 WHEN 8 THEN '222' 
70476                 WHEN 9 THEN '222' 
70477                 
70478                 ELSE null
70479               END                           source_application_id
70480             , 'S'             source_type_code
70481             , CASE r
70482                 WHEN 1 THEN 'TRX_LINE_DIST_CCID' 
70483                 WHEN 2 THEN 'TRX_LINE_DIST_ACCOUNT_CLASS' 
70484                 WHEN 3 THEN 'TRX_LINE_DIST_ID' 
70485                 WHEN 4 THEN 'TRX_DISTRIBUTION_TYPE' 
70486                 WHEN 5 THEN 'TRX_LINE_DIST_AMT' 
70487                 WHEN 6 THEN 'TRX_LINE_CUR_CONVERSION_DATE' 
70488                 WHEN 7 THEN 'TRX_LINE_CUR_CONVERSION_RATE' 
70489                 WHEN 8 THEN 'TRX_LINE_CUR_CONVERSION_TYPE' 
70490                 WHEN 9 THEN 'TRX_LINE_ACCTD_AMT' 
70491                 
70492                 ELSE null
70493               END                           source_code
70494             , CASE r
70495                 WHEN 1 THEN TO_CHAR(l4.TRX_LINE_DIST_CCID)
70496                 WHEN 2 THEN TO_CHAR(l4.TRX_LINE_DIST_ACCOUNT_CLASS)
70497                 WHEN 3 THEN TO_CHAR(l4.TRX_LINE_DIST_ID)
70498                 WHEN 4 THEN TO_CHAR(l4.TRX_DISTRIBUTION_TYPE)
70499                 WHEN 5 THEN TO_CHAR(l4.TRX_LINE_DIST_AMT)
70500                 WHEN 6 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_DATE)
70501                 WHEN 7 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_RATE)
70502                 WHEN 8 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_TYPE)
70503                 WHEN 9 THEN TO_CHAR(l3.TRX_LINE_ACCTD_AMT)
70504                 
70505                 ELSE null
70506               END                           source_value
70507             , null              source_meaning
70508          FROM  xla_events_gt     xet  
70509         , AR_CUST_TRX_LINES_BASE_V  l3
70510         , AR_CUST_TRX_LINES_L_V  l4
70511             , (select rownum r from all_objects where rownum <= 9 and owner = p_apps_owner)
70512         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
70513           AND xet.event_class_code = C_EVENT_CLASS_CODE
70514             AND l3.event_id          = xet.event_id
70515   AND l4.event_id    = l3.event_id
70516   AND l4.line_number = l3.line_number
70517 
70518 )
70519 ;
70520 --
70524          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
70521 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
70522 
70523       trace
70525          ,p_level    => C_LEVEL_STATEMENT
70526          ,p_module   => l_log_module);
70527 
70528 END IF;
70529 
70530 
70531 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
70532       trace
70533          (p_msg      => 'END of insert_sources_137'
70534          ,p_level    => C_LEVEL_PROCEDURE
70535          ,p_module   => l_log_module);
70536 END IF;
70537 EXCEPTION
70538   WHEN xla_exceptions_pkg.application_exception THEN
70539       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
70540             trace
70541                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
70542                ,p_level    => C_LEVEL_EXCEPTION
70543                ,p_module   => l_log_module);
70544       END IF;
70545       RAISE;
70546   WHEN OTHERS THEN
70547       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
70548             trace
70549                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
70550                ,p_level    => C_LEVEL_EXCEPTION
70551                ,p_module   => l_log_module);
70552        END IF;
70553        xla_exceptions_pkg.raise_message
70554            (p_location => 'XLA_00222_AAD_S_000006_PKG.insert_sources_137');
70555 END insert_sources_137;
70556 --
70557 
70558 ---------------------------------------
70559 --
70560 -- PRIVATE FUNCTION
70561 --         EventClass_137
70562 --
70563 ----------------------------------------
70564 --
70565 FUNCTION EventClass_137
70566        (p_application_id         IN NUMBER
70567        ,p_base_ledger_id         IN NUMBER
70568        ,p_target_ledger_id       IN NUMBER
70569        ,p_language               IN VARCHAR2
70570        ,p_currency_code          IN VARCHAR2
70571        ,p_sla_ledger_id          IN NUMBER
70572        ,p_pad_start_date         IN DATE
70573        ,p_pad_end_date           IN DATE
70574        ,p_primary_ledger_id      IN NUMBER)
70575 RETURN BOOLEAN IS
70576 --
70577 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CHARGEBACK_ALL';
70578 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CHARGEBACK';
70579 
70580 l_calculate_acctd_flag   VARCHAR2(1) :='N';
70581 l_calculate_g_l_flag     VARCHAR2(1) :='N';
70582 --
70583 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
70584 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
70585 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
70586 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
70587 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
70588 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
70589 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
70590 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
70591 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
70592 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
70593 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
70594 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
70595 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
70596 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
70597 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
70598 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
70599 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
70600 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
70601 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
70602 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
70603 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
70604 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
70605 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
70606 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
70607 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
70608 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
70609 
70610 l_event_id                             NUMBER;
70611 l_previous_event_id                    NUMBER;
70612 l_first_event_id                       NUMBER;
70613 l_last_event_id                        NUMBER;
70614 
70615 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
70616 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
70617 --
70618 --
70619 l_result                    BOOLEAN := TRUE;
70620 l_rows                      NUMBER  := 1000;
70621 l_event_type_name           VARCHAR2(80) := 'All';
70622 l_event_class_name          VARCHAR2(80) := 'Chargeback';
70623 l_description               VARCHAR2(4000);
70624 l_transaction_reversal      NUMBER;
70625 l_ae_header_id              NUMBER;
70626 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
70627 l_log_module                VARCHAR2(240);
70628 --
70629 l_acct_reversal_source      VARCHAR2(30);
70630 l_trx_reversal_source       VARCHAR2(30);
70631 
70632 l_continue_with_lines       BOOLEAN := TRUE;
70633 --
70637 
70634 l_acc_rev_gl_date_source    DATE;                      -- 4262811
70635 --
70636 type t_array_event_id is table of number index by binary_integer;
70638 l_rec_array_event                    t_rec_array_event;
70639 l_null_rec_array_event               t_rec_array_event;
70640 l_array_ae_header_id                 xla_number_array_type;
70641 l_actual_flag                        VARCHAR2(1) := NULL;
70642 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
70643 l_balance_type_code                  VARCHAR2(1) :=NULL;
70644 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
70645 
70646 --
70647 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
70648 --
70649 
70650 TYPE t_array_source_30 IS TABLE OF AR_BILL_TO_CUSTOMERS_S_V.BILL_CUST_ACCOUNT_ID%TYPE INDEX BY BINARY_INTEGER;
70651 TYPE t_array_source_31 IS TABLE OF AR_BILL_TO_SITE_USES_S_V.BILL_USES_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
70652 TYPE t_array_source_32 IS TABLE OF AR_TRANSACTIONS_S_V.XLA_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
70653 TYPE t_array_source_37 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_INVOICE_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
70654 TYPE t_array_source_83 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
70655 TYPE t_array_source_84 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
70656 TYPE t_array_source_85 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
70657 
70658 TYPE t_array_source_4 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
70659 TYPE t_array_source_33 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ACCOUNT_CLASS%TYPE INDEX BY BINARY_INTEGER;
70660 TYPE t_array_source_34 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ID%TYPE INDEX BY BINARY_INTEGER;
70661 TYPE t_array_source_35 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
70662 TYPE t_array_source_36 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_AMT%TYPE INDEX BY BINARY_INTEGER;
70663 TYPE t_array_source_38 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
70664 TYPE t_array_source_39 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
70665 TYPE t_array_source_40 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
70666 TYPE t_array_source_41 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
70667 
70668 l_array_source_30              t_array_source_30;
70669 l_array_source_31              t_array_source_31;
70670 l_array_source_32              t_array_source_32;
70671 l_array_source_37              t_array_source_37;
70672 l_array_source_83              t_array_source_83;
70673 l_array_source_84              t_array_source_84;
70674 l_array_source_85              t_array_source_85;
70675 
70676 l_array_source_4      t_array_source_4;
70677 l_array_source_33      t_array_source_33;
70678 l_array_source_34      t_array_source_34;
70679 l_array_source_35      t_array_source_35;
70680 l_array_source_36      t_array_source_36;
70681 l_array_source_38      t_array_source_38;
70682 l_array_source_39      t_array_source_39;
70683 l_array_source_40      t_array_source_40;
70684 l_array_source_41      t_array_source_41;
70685 
70686 --
70687 CURSOR header_cur
70688 IS
70689 SELECT /*+ leading(xet) cardinality(xet,1) */
70690 -- Event Class Code: CHARGEBACK
70691     xet.entity_id
70692    ,xet.legal_entity_id
70693    ,xet.entity_code
70694    ,xet.transaction_number
70695    ,xet.event_id
70696    ,xet.event_class_code
70697    ,xet.event_type_code
70698    ,xet.event_number
70699    ,xet.event_date
70700    ,xet.transaction_date
70701    ,xet.reference_num_1
70702    ,xet.reference_num_2
70703    ,xet.reference_num_3
70704    ,xet.reference_num_4
70705    ,xet.reference_char_1
70706    ,xet.reference_char_2
70707    ,xet.reference_char_3
70708    ,xet.reference_char_4
70709    ,xet.reference_date_1
70710    ,xet.reference_date_2
70711    ,xet.reference_date_3
70712    ,xet.reference_date_4
70713    ,xet.event_created_by
70714    ,xet.budgetary_control_flag 
70715   , h1.BILL_CUST_ACCOUNT_ID    source_30
70716   , h2.BILL_USES_SITE_USE_ID    source_31
70717   , h5.XLA_PARTY_TYPE    source_32
70718   , h5.TRX_INVOICE_CURRENCY_CODE    source_37
70719   , h5.TRX_DOC_SEQUENCE_CATEGORY    source_83
70720   , h5.TRX_DOC_SEQUENCE_ID    source_84
70721   , h5.TRX_DOC_SEQUENCE_VALUE    source_85
70722   FROM xla_events_gt     xet 
70723   , AR_BILL_TO_CUSTOMERS_S_V  h1
70724   , AR_BILL_TO_SITE_USES_S_V  h2
70725   , AR_TRANSACTIONS_S_V  h5
70726  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
70727    and xet.event_class_code = C_EVENT_CLASS_CODE
70728    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
70729   AND h2.event_id  = h1.event_id
70730   AND h5.event_id  = h1.event_id
70731 
70732  ORDER BY event_id
70733 ;
70734 
70735 
70736 --
70737 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
70738 IS
70739 SELECT  /*+ leading(xet) cardinality(xet,1) */
70740 -- Event Class Code: CHARGEBACK
70741     xet.entity_id
70742    ,xet.legal_entity_id
70743    ,xet.entity_code
70744    ,xet.transaction_number
70745    ,xet.event_id
70746    ,xet.event_class_code
70747    ,xet.event_type_code
70748    ,xet.event_number
70749    ,xet.event_date
70750    ,xet.transaction_date
70754    ,xet.reference_num_4
70751    ,xet.reference_num_1
70752    ,xet.reference_num_2
70753    ,xet.reference_num_3
70755    ,xet.reference_char_1
70756    ,xet.reference_char_2
70757    ,xet.reference_char_3
70758    ,xet.reference_char_4
70759    ,xet.reference_date_1
70760    ,xet.reference_date_2
70761    ,xet.reference_date_3
70762    ,xet.reference_date_4
70763    ,xet.event_created_by
70764    ,xet.budgetary_control_flag
70765  , l3.LINE_NUMBER  
70766   , l4.TRX_LINE_DIST_CCID    source_4
70767   , l4.TRX_LINE_DIST_ACCOUNT_CLASS    source_33
70768   , l4.TRX_LINE_DIST_ID    source_34
70769   , l4.TRX_DISTRIBUTION_TYPE    source_35
70770   , l4.TRX_LINE_DIST_AMT    source_36
70771   , l3.TRX_LINE_CUR_CONVERSION_DATE    source_38
70772   , l3.TRX_LINE_CUR_CONVERSION_RATE    source_39
70773   , l3.TRX_LINE_CUR_CONVERSION_TYPE    source_40
70774   , l3.TRX_LINE_ACCTD_AMT    source_41
70775   FROM xla_events_gt     xet 
70776   , AR_CUST_TRX_LINES_BASE_V  l3
70777   , AR_CUST_TRX_LINES_L_V  l4
70778  WHERE xet.event_id between x_first_event_id and x_last_event_id
70779    and xet.event_date between p_pad_start_date and p_pad_end_date
70780    and xet.event_class_code = C_EVENT_CLASS_CODE
70781    and xet.event_status_code <> 'N'   AND l3.event_id      = xet.event_id
70782   AND l4.event_id    = l3.event_id
70783   AND l4.line_number = l3.line_number
70784 ;
70785 
70786 --
70787 BEGIN
70788 IF g_log_enabled THEN
70789    l_log_module := C_DEFAULT_MODULE||'.EventClass_137';
70790 END IF;
70791 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
70792    trace
70793       (p_msg      => 'BEGIN of EventClass_137'
70794       ,p_level    => C_LEVEL_PROCEDURE
70795       ,p_module   => l_log_module);
70796 END IF;
70797 
70798 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
70799    trace
70800       (p_msg      => 'p_application_id = '||p_application_id||
70801                      ' - p_base_ledger_id = '||p_base_ledger_id||
70802                      ' - p_target_ledger_id  = '||p_target_ledger_id||
70803                      ' - p_language = '||p_language||
70804                      ' - p_currency_code = '||p_currency_code||
70805                      ' - p_sla_ledger_id = '||p_sla_ledger_id
70806       ,p_level    => C_LEVEL_STATEMENT
70807       ,p_module   => l_log_module);
70808 END IF;
70809 --
70810 -- initialze arrays
70811 --
70812 g_array_event.DELETE;
70813 l_rec_array_event := l_null_rec_array_event;
70814 --
70815 --------------------------------------
70816 -- 4262811 Initialze MPA Line Number
70817 --------------------------------------
70818 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
70819 
70820 --
70821 
70822 --
70823 OPEN header_cur;
70824 --
70825 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
70826    trace
70827    (p_msg      => 'SQL - FETCH header_cur'
70828    ,p_level    => C_LEVEL_STATEMENT
70829    ,p_module   => l_log_module);
70830 END IF;
70831 --
70832 LOOP
70833 FETCH header_cur BULK COLLECT INTO
70834         l_array_entity_id
70835       , l_array_legal_entity_id
70836       , l_array_entity_code
70837       , l_array_transaction_num
70838       , l_array_event_id
70839       , l_array_class_code
70840       , l_array_event_type
70841       , l_array_event_number
70842       , l_array_event_date
70843       , l_array_transaction_date
70844       , l_array_reference_num_1
70845       , l_array_reference_num_2
70846       , l_array_reference_num_3
70847       , l_array_reference_num_4
70848       , l_array_reference_char_1
70849       , l_array_reference_char_2
70850       , l_array_reference_char_3
70851       , l_array_reference_char_4
70852       , l_array_reference_date_1
70853       , l_array_reference_date_2
70854       , l_array_reference_date_3
70855       , l_array_reference_date_4
70856       , l_array_event_created_by
70857       , l_array_budgetary_control_flag 
70858       , l_array_source_30
70859       , l_array_source_31
70860       , l_array_source_32
70861       , l_array_source_37
70862       , l_array_source_83
70863       , l_array_source_84
70864       , l_array_source_85
70865       LIMIT l_rows;
70866 --
70867 IF (C_LEVEL_EVENT >= g_log_level) THEN
70868    trace
70869    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
70870    ,p_level    => C_LEVEL_EVENT
70871    ,p_module   => l_log_module);
70872 END IF;
70873 --
70874 EXIT WHEN l_array_entity_id.COUNT = 0;
70875 
70876 -- initialize arrays
70877 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
70878 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
70879 
70880 --
70881 -- Bug 4458708
70882 --
70883 XLA_AE_LINES_PKG.g_LineNumber := 0;
70884 
70885 
70886 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
70887 g_last_hdr_idx := l_array_event_id.LAST;
70888 --
70889 -- loop for the headers. Each iteration is for each header extract row
70890 -- fetched in header cursor
70891 --
70892 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
70893 
70894 --
70895 -- set event info as cache for other routines to refer event attributes
70896 --
70897 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
70901    ,p_target_ledger_id         => p_target_ledger_id
70898    (p_application_id           => p_application_id
70899    ,p_primary_ledger_id        => p_primary_ledger_id
70900    ,p_base_ledger_id           => p_base_ledger_id
70902    ,p_entity_id                => l_array_entity_id(hdr_idx)
70903    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
70904    ,p_entity_code              => l_array_entity_code(hdr_idx)
70905    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
70906    ,p_event_id                 => l_array_event_id(hdr_idx)
70907    ,p_event_class_code         => l_array_class_code(hdr_idx)
70908    ,p_event_type_code          => l_array_event_type(hdr_idx)
70909    ,p_event_number             => l_array_event_number(hdr_idx)
70910    ,p_event_date               => l_array_event_date(hdr_idx)
70911    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
70912    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
70913    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
70914    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
70915    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
70916    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
70917    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
70918    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
70919    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
70920    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
70921    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
70922    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
70923    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
70924    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
70925    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
70926 
70927 --
70928 -- set the status of entry to C_VALID (0)
70929 --
70930 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
70931 
70932 --
70933 -- initialize a row for ae header
70934 --
70935 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
70936 
70937 l_event_id := l_array_event_id(hdr_idx);
70938 
70939 --
70940 -- storing the hdr_idx for event. May be used by line cursor.
70941 --
70942 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
70943 
70944 --
70945 -- store sources from header extract. This can be improved to
70946 -- store only those sources from header extract that may be used in lines
70947 --
70948 
70949 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
70950 g_array_event(l_event_id).array_value_num('source_31') := l_array_source_31(hdr_idx);
70951 g_array_event(l_event_id).array_value_char('source_32') := l_array_source_32(hdr_idx);
70952 g_array_event(l_event_id).array_value_char('source_37') := l_array_source_37(hdr_idx);
70953 g_array_event(l_event_id).array_value_char('source_83') := l_array_source_83(hdr_idx);
70954 g_array_event(l_event_id).array_value_num('source_84') := l_array_source_84(hdr_idx);
70955 g_array_event(l_event_id).array_value_num('source_85') := l_array_source_85(hdr_idx);
70956 
70957 --
70958 -- initilaize the status of ae headers for diffrent balance types
70959 -- the status is initialised to C_NOT_CREATED (2)
70960 --
70961 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
70962 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
70963 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
70964 
70965 --
70966 -- call api to validate and store accounting attributes for header
70967 --
70968 
70969 ------------------------------------------------------------
70970 -- Accrual Reversal : to get date for Standard Source (NONE)
70971 ------------------------------------------------------------
70972 l_acc_rev_gl_date_source := NULL;
70973 
70974      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
70975       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_83');
70976      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
70977       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_84');
70978      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
70979       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_85');
70980      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
70981       l_rec_acct_attrs.array_date_value(4) := 
70982 xla_ae_sources_pkg.GetSystemSourceDate(
70983    p_source_code           => 'XLA_EVENT_DATE'
70984  , p_source_type_code      => 'Y'
70985  , p_source_application_id =>  602
70986 );
70987 
70988 
70989 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
70990 
70991 XLA_AE_HEADER_PKG.SetJeCategoryName;
70992 
70993 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
70994 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
70995 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
70996 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
70997 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
70998 
70999 
71003 --accounting attribute enhancement, bug 3612931
71000 -- No header level analytical criteria
71001 
71002 --
71004 --
71005 l_trx_reversal_source := SUBSTR(NULL, 1,30);
71006 
71007 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
71008    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
71009 
71010    xla_accounting_err_pkg.build_message
71011       (p_appli_s_name            => 'XLA'
71012       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
71013       ,p_token_1                 => 'ACCT_ATTR_NAME'
71014       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
71015       ,p_token_2                 => 'PRODUCT_NAME'
71016       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
71017       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
71018       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
71019       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
71020 
71021 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
71022    --
71023    -- following sets the accounting attributes needed to reverse
71024    -- accounting for a distributeion
71025    --
71026    xla_ae_lines_pkg.SetTrxReversalAttrs
71027       (p_event_id              => l_event_id
71028       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
71029       ,p_trx_reversal_source   => l_trx_reversal_source);
71030 
71031 END IF;
71032 
71033 
71034 ----------------------------------------------------------------
71035 -- 4262811 -  update the header statuses to invalid in need be
71036 ----------------------------------------------------------------
71037 --
71038 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
71039 
71040 
71041   -----------------------------------------------
71042   -- No accrual reversal for the event class/type
71043   -----------------------------------------------
71044 ----------------------------------------------------------------
71045 
71046 --
71047 -- this ends the header loop iteration for one bulk fetch
71048 --
71049 END LOOP;
71050 
71051 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
71052 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
71053 
71054 --
71055 -- insert dummy rows into lines gt table that were created due to
71056 -- transaction reversals
71057 --
71058 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
71059    l_result := XLA_AE_LINES_PKG.InsertLines;
71060 END IF;
71061 
71062 --
71063 -- reset the temp_line_num for each set of events fetched from header
71064 -- cursor rather than doing it for each new event in line cursor
71065 -- Bug 3939231
71066 --
71067 xla_ae_lines_pkg.g_temp_line_num := 0;
71068 
71069 
71070 
71071 --
71072 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
71073 --
71074 --
71075 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
71076 
71077       trace
71078          (p_msg      => 'SQL - FETCH line_cur'
71079          ,p_level    => C_LEVEL_STATEMENT
71080          ,p_module   => l_log_module);
71081 
71082 END IF;
71083 --
71084 --
71085 LOOP
71086   --
71087   FETCH line_cur BULK COLLECT INTO
71088         l_array_entity_id
71089       , l_array_legal_entity_id
71090       , l_array_entity_code
71091       , l_array_transaction_num
71092       , l_array_event_id
71093       , l_array_class_code
71094       , l_array_event_type
71095       , l_array_event_number
71096       , l_array_event_date
71097       , l_array_transaction_date
71098       , l_array_reference_num_1
71099       , l_array_reference_num_2
71100       , l_array_reference_num_3
71101       , l_array_reference_num_4
71102       , l_array_reference_char_1
71103       , l_array_reference_char_2
71104       , l_array_reference_char_3
71105       , l_array_reference_char_4
71106       , l_array_reference_date_1
71107       , l_array_reference_date_2
71108       , l_array_reference_date_3
71109       , l_array_reference_date_4
71110       , l_array_event_created_by
71111       , l_array_budgetary_control_flag
71112       , l_array_extract_line_num 
71113       , l_array_source_4
71114       , l_array_source_33
71115       , l_array_source_34
71116       , l_array_source_35
71117       , l_array_source_36
71118       , l_array_source_38
71119       , l_array_source_39
71120       , l_array_source_40
71121       , l_array_source_41
71122       LIMIT l_rows;
71123 
71124   --
71125   IF (C_LEVEL_EVENT >= g_log_level) THEN
71126             trace
71127                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
71128                ,p_level    => C_LEVEL_EVENT
71129                ,p_module   => l_log_module);
71130   END IF;
71131   --
71132   EXIT WHEN l_array_entity_id.count = 0;
71133 
71134   XLA_AE_LINES_PKG.g_rec_lines := null;
71135 
71136 --
71137 -- Bug 4458708
71138 --
71139 XLA_AE_LINES_PKG.g_LineNumber := 0;
71140 --
71141 --
71142 
71143 FOR Idx IN 1..l_array_event_id.count LOOP
71144    --
71148 
71145    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
71146    --
71147    l_event_id := l_array_event_id(idx);  -- 5648433
71149    --
71150    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
71151    --
71152 
71153    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
71154              (g_array_event(l_event_id).array_value_num('header_index'))
71155          ,'N'
71156          ) <> 'Y'
71157    THEN
71158       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
71159          trace
71160             (p_msg      => 'Trancaction revesal option is not Y '
71161             ,p_level    => C_LEVEL_STATEMENT
71162             ,p_module   => l_log_module);
71163       END IF;
71164 
71165 --
71166 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
71167 --
71168 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
71169 --
71170 -- set event info as cache for other routines to refer event attributes
71171 --
71172 
71173 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
71174    l_previous_event_id := l_event_id;
71175 
71176    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
71177       (p_application_id           => p_application_id
71178       ,p_primary_ledger_id        => p_primary_ledger_id
71179       ,p_base_ledger_id           => p_base_ledger_id
71180       ,p_target_ledger_id         => p_target_ledger_id
71181       ,p_entity_id                => l_array_entity_id(Idx)
71182       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
71183       ,p_entity_code              => l_array_entity_code(Idx)
71184       ,p_transaction_num          => l_array_transaction_num(Idx)
71185       ,p_event_id                 => l_array_event_id(Idx)
71186       ,p_event_class_code         => l_array_class_code(Idx)
71187       ,p_event_type_code          => l_array_event_type(Idx)
71188       ,p_event_number             => l_array_event_number(Idx)
71189       ,p_event_date               => l_array_event_date(Idx)
71190       ,p_transaction_date         => l_array_transaction_date(Idx)
71191       ,p_reference_num_1          => l_array_reference_num_1(Idx)
71192       ,p_reference_num_2          => l_array_reference_num_2(Idx)
71193       ,p_reference_num_3          => l_array_reference_num_3(Idx)
71194       ,p_reference_num_4          => l_array_reference_num_4(Idx)
71195       ,p_reference_char_1         => l_array_reference_char_1(Idx)
71196       ,p_reference_char_2         => l_array_reference_char_2(Idx)
71197       ,p_reference_char_3         => l_array_reference_char_3(Idx)
71198       ,p_reference_char_4         => l_array_reference_char_4(Idx)
71199       ,p_reference_date_1         => l_array_reference_date_1(Idx)
71200       ,p_reference_date_2         => l_array_reference_date_2(Idx)
71201       ,p_reference_date_3         => l_array_reference_date_3(Idx)
71202       ,p_reference_date_4         => l_array_reference_date_4(Idx)
71203       ,p_event_created_by         => l_array_event_created_by(Idx)
71204       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
71205        --
71206 END IF;
71207 
71208 
71209 
71210 --
71211 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
71212 
71213 l_acct_reversal_source := SUBSTR(NULL, 1,30);
71214 
71215 IF l_continue_with_lines THEN
71216    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
71217       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
71218 
71219       xla_accounting_err_pkg.build_message
71220          (p_appli_s_name            => 'XLA'
71221          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
71222          ,p_token_1                 => 'LINE_NUMBER'
71223          ,p_value_1                 => l_array_extract_line_num(Idx)
71224          ,p_token_2                 => 'PRODUCT_NAME'
71225          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
71226          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
71227          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
71228          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
71229 
71230    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
71231       --
71232       -- following sets the accounting attributes needed to reverse
71233       -- accounting for a distributeion
71234       --
71235 
71236       --
71237       -- 5217187
71238       --
71239       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
71240       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
71241                                        g_array_event(l_event_id).array_value_num('header_index'));
71242       --
71243       --
71244 
71245       -- No reversal code generated
71246 
71247       xla_ae_lines_pkg.SetAcctReversalAttrs
71248          (p_event_id             => l_event_id
71249          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
71250          ,p_calculate_acctd_flag => l_calculate_acctd_flag
71251          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
71252    END IF;
71253 
71254    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
71255        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
71256 
71257 --
71258 AcctLineType_38 (
71259  p_application_id  => p_application_id
71263  ,p_actual_flag => l_actual_flag
71260  ,p_event_id     => l_event_id
71261  ,p_calculate_acctd_flag => l_calculate_acctd_flag
71262  ,p_calculate_g_l_flag => l_calculate_g_l_flag
71264  ,p_balance_type_code => l_balance_type_code
71265  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
71266  
71267  , p_source_4 => l_array_source_4(Idx)
71268  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
71269  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
71270  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
71271  , p_source_33 => l_array_source_33(Idx)
71272  , p_source_34 => l_array_source_34(Idx)
71273  , p_source_35 => l_array_source_35(Idx)
71274  , p_source_36 => l_array_source_36(Idx)
71275  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
71276  , p_source_38 => l_array_source_38(Idx)
71277  , p_source_39 => l_array_source_39(Idx)
71278  , p_source_40 => l_array_source_40(Idx)
71279  , p_source_41 => l_array_source_41(Idx)
71280  );
71281 If(l_balance_type_code = 'A') THEN
71282   l_actual_gain_loss_ref := l_gain_or_loss_ref;
71283 END IF;
71284 
71285 --
71286 
71287 
71288 --
71289 AcctLineType_39 (
71290  p_application_id  => p_application_id
71291  ,p_event_id     => l_event_id
71292  ,p_calculate_acctd_flag => l_calculate_acctd_flag
71293  ,p_calculate_g_l_flag => l_calculate_g_l_flag
71294  ,p_actual_flag => l_actual_flag
71295  ,p_balance_type_code => l_balance_type_code
71296  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
71297  
71298  , p_source_4 => l_array_source_4(Idx)
71299  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
71300  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
71301  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
71302  , p_source_33 => l_array_source_33(Idx)
71303  , p_source_34 => l_array_source_34(Idx)
71304  , p_source_35 => l_array_source_35(Idx)
71305  , p_source_36 => l_array_source_36(Idx)
71306  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
71307  , p_source_38 => l_array_source_38(Idx)
71308  , p_source_39 => l_array_source_39(Idx)
71309  , p_source_40 => l_array_source_40(Idx)
71310  , p_source_41 => l_array_source_41(Idx)
71311  );
71312 If(l_balance_type_code = 'A') THEN
71313   l_actual_gain_loss_ref := l_gain_or_loss_ref;
71314 END IF;
71315 
71316 --
71317 
71318       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
71319       -- or secondary ledger that has different currency with primary
71320       -- or alc that is calculated by sla
71321       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
71322             (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'))
71323 
71324 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
71325 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
71326           AND (l_actual_flag = 'A')) THEN
71327         XLA_AE_LINES_PKG.CreateGainOrLossLines(
71328           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
71329          ,p_application_id   => p_application_id
71330          ,p_amb_context_code => 'DEFAULT'
71331          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
71332          ,p_event_class_code => C_EVENT_CLASS_CODE
71333          ,p_event_type_code  => C_EVENT_TYPE_CODE
71334          
71335          ,p_gain_ccid        => -1
71336          ,p_loss_ccid        => -1
71337 
71338          ,p_actual_flag      => l_actual_flag
71339          ,p_enc_flag         => null
71340          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
71341          ,p_enc_g_l_ref      => null
71342          );
71343       END IF;
71344    END IF;
71345 END IF;
71346 
71347    ELSE
71348       --
71349       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
71350       --
71351       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
71352          trace
71353             (p_msg      => 'Trancaction revesal option is Y'
71354             ,p_level    => C_LEVEL_STATEMENT
71355             ,p_module   => l_log_module);
71356       END IF;
71357    END IF;
71358 
71359 END LOOP;
71360 l_result := XLA_AE_LINES_PKG.InsertLines ;
71361 end loop;
71362 close line_cur;
71363 
71364 
71365 --
71366 -- insert headers into xla_ae_headers_gt table
71367 --
71368 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
71369 
71370 -- insert into errors table here.
71371 
71372 END LOOP;
71373 
71374 --
71375 -- 4865292
71376 --
71377 -- Compare g_hdr_extract_count with event count in
71378 -- CreateHeadersAndLines.
71379 --
71380 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
71381 
71382 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
71383    trace (p_msg     => '# rows extracted from header extract objects '
71384                     || ' (running total): '
71385                     || g_hdr_extract_count
71386          ,p_level   => C_LEVEL_STATEMENT
71387          ,p_module  => l_log_module);
71388 END IF;
71389 
71390 CLOSE header_cur;
71391 --
71392 
71393 --
71397       ,p_level    => C_LEVEL_PROCEDURE
71394 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
71395    trace
71396       (p_msg      => 'END of EventClass_137'
71398       ,p_module   => l_log_module);
71399 END IF;
71400 --
71401 RETURN l_result;
71402 EXCEPTION
71403 WHEN xla_exceptions_pkg.application_exception THEN
71404    
71405 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
71406 
71407    
71408 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
71409 
71410    RAISE;
71411 
71412 WHEN NO_DATA_FOUND THEN
71413 
71414 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
71415 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
71416 
71417 FOR header_record IN header_cur
71418 LOOP
71419     l_array_header_events(header_record.event_id) := header_record.event_id;
71420 END LOOP;
71421 
71422 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
71423 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
71424 
71425 fnd_file.put_line(fnd_file.LOG, '                    ');
71426 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
71427 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
71428 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
71429 
71430 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
71431 LOOP
71432 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
71433 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
71434         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
71435 	END IF;
71436 END LOOP;
71437 
71438 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
71439 fnd_file.put_line(fnd_file.LOG, '                    ');
71440 
71441 
71442 xla_exceptions_pkg.raise_message
71443       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_137');
71444 
71445 
71446 WHEN OTHERS THEN
71447    xla_exceptions_pkg.raise_message
71448       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_137');
71449 END EventClass_137;
71450 --
71451 
71452 ---------------------------------------
71453 --
71454 -- PRIVATE PROCEDURE
71455 --         insert_sources_138
71456 --
71457 ----------------------------------------
71458 --
71459 PROCEDURE insert_sources_138(
71460                                 p_target_ledger_id       IN NUMBER
71461                               , p_language               IN VARCHAR2
71462                               , p_sla_ledger_id          IN NUMBER
71463                               , p_pad_start_date         IN DATE
71464                               , p_pad_end_date           IN DATE
71465                          )
71466 IS
71467 
71468 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CREDIT_MEMO_ALL';
71469 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CREDIT_MEMO';
71470 p_apps_owner                   VARCHAR2(30);
71471 l_log_module                   VARCHAR2(240);
71472 BEGIN
71473 IF g_log_enabled THEN
71474       l_log_module := C_DEFAULT_MODULE||'.insert_sources_138';
71475 END IF;
71476 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
71477 
71478       trace
71479          (p_msg      => 'BEGIN of insert_sources_138'
71480          ,p_level    => C_LEVEL_PROCEDURE
71481          ,p_module   => l_log_module);
71482 
71483 END IF;
71484 
71485 -- select APPS owner
71486 SELECT oracle_username
71487   INTO p_apps_owner
71488   FROM fnd_oracle_userid
71489  WHERE read_only_flag = 'U'
71490 ;
71491 
71492 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
71493       trace
71494          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
71495                         ' - p_language = '||p_language||
71496                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
71497                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
71498                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
71499                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
71500          ,p_level    => C_LEVEL_STATEMENT
71501          ,p_module   => l_log_module);
71502 END IF;
71503 
71504 
71505 --
71506 INSERT INTO xla_diag_sources --hdr2
71507 (
71508         event_id
71509       , ledger_id
71510       , sla_ledger_id
71511       , description_language
71512       , object_name
71513       , object_type_code
71514       , line_number
71515       , source_application_id
71516       , source_type_code
71517       , source_code
71518       , source_value
71519       , source_meaning
71520       , created_by
71521       , creation_date
71522       , last_update_date
71523       , last_updated_by
71524       , last_update_login
71525       , program_update_date
71526       , program_application_id
71527       , program_id
71528       , request_id
71529 )
71530 SELECT
71531         event_id
71532       , p_target_ledger_id
71533       , p_sla_ledger_id
71534       , p_language
71535       , object_name
71536       , object_type_code
71537       , line_number
71541       , SUBSTR(source_value ,1,1996)
71538       , source_application_id
71539       , source_type_code
71540       , source_code
71542       , SUBSTR(source_meaning ,1,200)
71543       , xla_environment_pkg.g_Usr_Id
71544       , TRUNC(SYSDATE)
71545       , TRUNC(SYSDATE)
71546       , xla_environment_pkg.g_Usr_Id
71547       , xla_environment_pkg.g_Login_Id
71548       , TRUNC(SYSDATE)
71549       , xla_environment_pkg.g_Prog_Appl_Id
71550       , xla_environment_pkg.g_Prog_Id
71551       , xla_environment_pkg.g_Req_Id
71552   FROM (
71553        SELECT xet.event_id                  event_id
71554             , 0                          line_number
71555             , CASE r
71556                WHEN 1 THEN 'AR_CREDIT_MEMO_H_V' 
71557                 WHEN 2 THEN 'AR_SYSTEM_PARAM_H_V' 
71558                 WHEN 3 THEN 'AR_SYSTEM_PARAM_H_V' 
71559                 WHEN 4 THEN 'AR_CREDIT_MEMO_H_V' 
71560                 WHEN 5 THEN 'AR_CREDIT_MEMO_H_V' 
71561                 WHEN 6 THEN 'AR_CM_BILL_TO_CUST_H_V' 
71562                 WHEN 7 THEN 'AR_CM_BILL_SITE_USES_H_V' 
71563                 WHEN 8 THEN 'AR_CREDIT_MEMO_H_V' 
71564                 
71565                ELSE null
71566               END                           object_name
71567             , CASE r
71568                 WHEN 1 THEN 'HEADER' 
71569                 WHEN 2 THEN 'HEADER' 
71570                 WHEN 3 THEN 'HEADER' 
71571                 WHEN 4 THEN 'HEADER' 
71572                 WHEN 5 THEN 'HEADER' 
71573                 WHEN 6 THEN 'HEADER' 
71574                 WHEN 7 THEN 'HEADER' 
71575                 WHEN 8 THEN 'HEADER' 
71576                 
71577                 ELSE null
71578               END                           object_type_code
71579             , CASE r
71580                 WHEN 1 THEN '222' 
71581                 WHEN 2 THEN '222' 
71582                 WHEN 3 THEN '222' 
71583                 WHEN 4 THEN '222' 
71584                 WHEN 5 THEN '222' 
71585                 WHEN 6 THEN '222' 
71586                 WHEN 7 THEN '222' 
71587                 WHEN 8 THEN '222' 
71588                 
71589                 ELSE null
71590               END                           source_application_id
71591             , 'S'             source_type_code
71592             , CASE r
71593                 WHEN 1 THEN 'CM_RECEIVABLE_CCID' 
71594                 WHEN 2 THEN 'CODE_COMBINATION_ID_GAIN' 
71595                 WHEN 3 THEN 'CODE_COMBINATION_ID_LOSS' 
71596                 WHEN 4 THEN 'XLA_PARTY_TYPE' 
71597                 WHEN 5 THEN 'CM_INVOICE_CURRENCY_CODE' 
71598                 WHEN 6 THEN 'CM_BILL_CUST_ACCOUNT_ID' 
71599                 WHEN 7 THEN 'CM_BILL_USES_SITE_USE_ID' 
71600                 WHEN 8 THEN 'CM_INVOICING_RULE_ID' 
71601                 
71602                 ELSE null
71603               END                           source_code
71604             , CASE r
71605                 WHEN 1 THEN TO_CHAR(h5.CM_RECEIVABLE_CCID)
71606                 WHEN 2 THEN TO_CHAR(h8.CODE_COMBINATION_ID_GAIN)
71607                 WHEN 3 THEN TO_CHAR(h8.CODE_COMBINATION_ID_LOSS)
71608                 WHEN 4 THEN TO_CHAR(h5.XLA_PARTY_TYPE)
71609                 WHEN 5 THEN TO_CHAR(h5.CM_INVOICE_CURRENCY_CODE)
71610                 WHEN 6 THEN TO_CHAR(h2.CM_BILL_CUST_ACCOUNT_ID)
71611                 WHEN 7 THEN TO_CHAR(h1.CM_BILL_USES_SITE_USE_ID)
71612                 WHEN 8 THEN TO_CHAR(h5.CM_INVOICING_RULE_ID)
71613                 
71614                 ELSE null
71615               END                           source_value
71616             , null              source_meaning
71617          FROM xla_events_gt     xet  
71618       , AR_CM_BILL_SITE_USES_H_V  h1
71619       , AR_CM_BILL_TO_CUST_H_V  h2
71620       , AR_CREDIT_MEMO_H_V  h5
71621       , AR_SYSTEM_PARAM_H_V  h8
71622              ,(select rownum r from all_objects where rownum <= 8 and owner = p_apps_owner)
71623          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
71624            AND xet.event_class_code = C_EVENT_CLASS_CODE
71625               AND h1.event_id = xet.event_id
71626   AND h2.event_id  = h1.event_id
71627   AND h5.event_id  = h1.event_id
71628   AND h8.event_id (+) = h1.event_id
71629 
71630 )
71631 ;
71632 --
71633 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
71634 
71635       trace
71636          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
71637          ,p_level    => C_LEVEL_STATEMENT
71638          ,p_module   => l_log_module);
71639 
71640 END IF;
71641 --
71642 
71643 
71644 
71645 --
71646 INSERT INTO xla_diag_sources  --line2
71647 (
71648         event_id
71649       , ledger_id
71650       , sla_ledger_id
71651       , description_language
71652       , object_name
71653       , object_type_code
71654       , line_number
71655       , source_application_id
71656       , source_type_code
71657       , source_code
71658       , source_value
71659       , source_meaning
71660       , created_by
71661       , creation_date
71662       , last_update_date
71663       , last_updated_by
71664       , last_update_login
71665       , program_update_date
71666       , program_application_id
71667       , program_id
71668       , request_id
71669 )
71670 SELECT  event_id
71671       , p_target_ledger_id
71675       , object_type_code
71672       , p_sla_ledger_id
71673       , p_language
71674       , object_name
71676       , line_number
71677       , source_application_id
71678       , source_type_code
71679       , source_code
71680       , SUBSTR(source_value,1,1996)
71681       , SUBSTR(source_meaning ,1,200)
71682       , xla_environment_pkg.g_Usr_Id
71683       , TRUNC(SYSDATE)
71684       , TRUNC(SYSDATE)
71685       , xla_environment_pkg.g_Usr_Id
71686       , xla_environment_pkg.g_Login_Id
71687       , TRUNC(SYSDATE)
71688       , xla_environment_pkg.g_Prog_Appl_Id
71689       , xla_environment_pkg.g_Prog_Id
71690       , xla_environment_pkg.g_Req_Id
71691   FROM (
71692        SELECT xet.event_id                  event_id
71693             , l3.line_number                 line_number
71694             , CASE r
71695                WHEN 1 THEN 'AR_CM_LINES_L_V' 
71696                 WHEN 2 THEN 'AR_DISTRIBUTIONS_L_V' 
71697                 WHEN 3 THEN 'AR_DISTRIBUTIONS_L_V' 
71698                 WHEN 4 THEN 'AR_RECEIVABLES_TRX_ACT_S_V' 
71699                 WHEN 5 THEN 'AR_DISTRIBUTIONS_L_V' 
71700                 WHEN 6 THEN 'AR_CM_LINES_BASE_V' 
71701                 WHEN 7 THEN 'AR_CM_LINES_BASE_V' 
71702                 WHEN 8 THEN 'AR_CM_LINES_BASE_V' 
71703                 WHEN 9 THEN 'AR_CM_LINES_BASE_V' 
71704                 WHEN 10 THEN 'AR_CM_LINES_BASE_V' 
71705                 WHEN 11 THEN 'AR_CM_LINES_BASE_V' 
71706                 WHEN 12 THEN 'AR_CM_LINES_BASE_V' 
71707                 WHEN 13 THEN 'AR_CM_LINES_L_V' 
71708                 WHEN 14 THEN 'AR_CM_LINES_L_V' 
71709                 WHEN 15 THEN 'AR_CM_LINES_L_V' 
71710                 
71711                ELSE null
71712               END                           object_name
71713             , CASE r
71714                 WHEN 1 THEN 'LINE' 
71715                 WHEN 2 THEN 'LINE' 
71716                 WHEN 3 THEN 'LINE' 
71717                 WHEN 4 THEN 'LINE' 
71718                 WHEN 5 THEN 'LINE' 
71719                 WHEN 6 THEN 'LINE' 
71720                 WHEN 7 THEN 'LINE' 
71721                 WHEN 8 THEN 'LINE' 
71722                 WHEN 9 THEN 'LINE' 
71723                 WHEN 10 THEN 'LINE' 
71724                 WHEN 11 THEN 'LINE' 
71725                 WHEN 12 THEN 'LINE' 
71726                 WHEN 13 THEN 'LINE' 
71727                 WHEN 14 THEN 'LINE' 
71728                 WHEN 15 THEN 'LINE' 
71729                 
71730                 ELSE null
71731               END                           object_type_code
71732             , CASE r
71733                 WHEN 1 THEN '222' 
71734                 WHEN 2 THEN '222' 
71735                 WHEN 3 THEN '222' 
71736                 WHEN 4 THEN '222' 
71737                 WHEN 5 THEN '222' 
71738                 WHEN 6 THEN '222' 
71739                 WHEN 7 THEN '222' 
71740                 WHEN 8 THEN '222' 
71741                 WHEN 9 THEN '222' 
71742                 WHEN 10 THEN '222' 
71743                 WHEN 11 THEN '222' 
71744                 WHEN 12 THEN '222' 
71745                 WHEN 13 THEN '222' 
71746                 WHEN 14 THEN '222' 
71747                 WHEN 15 THEN '222' 
71748                 
71749                 ELSE null
71750               END                           source_application_id
71751             , 'S'             source_type_code
71752             , CASE r
71753                 WHEN 1 THEN 'CM_LINE_DIST_CCID' 
71754                 WHEN 2 THEN 'DIST_CODE_COMBINATION_ID' 
71755                 WHEN 3 THEN 'DIST_SOURCE_TYPE' 
71756                 WHEN 4 THEN 'REC_ACT_TYPE' 
71757                 WHEN 5 THEN 'DIST_ENT_AMT' 
71758                 WHEN 6 THEN 'CM_DIST_IDENTIFER' 
71759                 WHEN 7 THEN 'CM_DIST_TYPE' 
71760                 WHEN 8 THEN 'CM_LINE_CUR_CONVERSION_DATE' 
71761                 WHEN 9 THEN 'CM_LINE_CUR_CONVERSION_RATE' 
71762                 WHEN 10 THEN 'CM_LINE_CUR_CONVERSION_TYPE' 
71763                 WHEN 11 THEN 'GAIN_LOSS_REF' 
71764                 WHEN 12 THEN 'CM_LINE_ACCTD_AMT' 
71765                 WHEN 13 THEN 'CM_TAX_LINE_ID' 
71766                 WHEN 14 THEN 'CM_LINE_DIST_ACCOUNT_CLASS' 
71767                 WHEN 15 THEN 'CM_LINE_DIST_AMT' 
71768                 
71769                 ELSE null
71770               END                           source_code
71771             , CASE r
71772                 WHEN 1 THEN TO_CHAR(l4.CM_LINE_DIST_CCID)
71773                 WHEN 2 THEN TO_CHAR(l6.DIST_CODE_COMBINATION_ID)
71774                 WHEN 3 THEN TO_CHAR(l6.DIST_SOURCE_TYPE)
71775                 WHEN 4 THEN TO_CHAR(l7.REC_ACT_TYPE)
71776                 WHEN 5 THEN TO_CHAR(l6.DIST_ENT_AMT)
71777                 WHEN 6 THEN TO_CHAR(l3.CM_DIST_IDENTIFER)
71778                 WHEN 7 THEN TO_CHAR(l3.CM_DIST_TYPE)
71779                 WHEN 8 THEN TO_CHAR(l3.CM_LINE_CUR_CONVERSION_DATE)
71780                 WHEN 9 THEN TO_CHAR(l3.CM_LINE_CUR_CONVERSION_RATE)
71781                 WHEN 10 THEN TO_CHAR(l3.CM_LINE_CUR_CONVERSION_TYPE)
71782                 WHEN 11 THEN TO_CHAR(l3.GAIN_LOSS_REF)
71783                 WHEN 12 THEN TO_CHAR(l3.CM_LINE_ACCTD_AMT)
71784                 WHEN 13 THEN TO_CHAR(l4.CM_TAX_LINE_ID)
71785                 WHEN 14 THEN TO_CHAR(l4.CM_LINE_DIST_ACCOUNT_CLASS)
71786                 WHEN 15 THEN TO_CHAR(l4.CM_LINE_DIST_AMT)
71787                 
71788                 ELSE null
71789               END                           source_value
71793         , AR_CM_LINES_L_V  l4
71790             , null              source_meaning
71791          FROM  xla_events_gt     xet  
71792         , AR_CM_LINES_BASE_V  l3
71794         , AR_DISTRIBUTIONS_L_V  l6
71795         , AR_RECEIVABLES_TRX_ACT_S_V  l7
71796             , (select rownum r from all_objects where rownum <= 15 and owner = p_apps_owner)
71797         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
71798           AND xet.event_class_code = C_EVENT_CLASS_CODE
71799             AND l3.event_id          = xet.event_id
71800   AND l4.event_id (+)    = l3.event_id
71801   AND l4.line_number (+) = l3.line_number
71802   AND l6.event_id (+)    = l3.event_id
71803   AND l6.line_number (+) = l3.line_number
71804   AND l7.event_id (+)    = l3.event_id
71805   AND l7.line_number (+) = l3.line_number
71806 
71807 )
71808 ;
71809 --
71810 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
71811 
71812       trace
71813          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
71814          ,p_level    => C_LEVEL_STATEMENT
71815          ,p_module   => l_log_module);
71816 
71817 END IF;
71818 
71819 
71820 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
71821       trace
71822          (p_msg      => 'END of insert_sources_138'
71823          ,p_level    => C_LEVEL_PROCEDURE
71824          ,p_module   => l_log_module);
71825 END IF;
71826 EXCEPTION
71827   WHEN xla_exceptions_pkg.application_exception THEN
71828       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
71829             trace
71830                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
71831                ,p_level    => C_LEVEL_EXCEPTION
71832                ,p_module   => l_log_module);
71833       END IF;
71834       RAISE;
71835   WHEN OTHERS THEN
71836       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
71837             trace
71838                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
71839                ,p_level    => C_LEVEL_EXCEPTION
71840                ,p_module   => l_log_module);
71841        END IF;
71842        xla_exceptions_pkg.raise_message
71843            (p_location => 'XLA_00222_AAD_S_000006_PKG.insert_sources_138');
71844 END insert_sources_138;
71845 --
71846 
71847 ---------------------------------------
71848 --
71849 -- PRIVATE FUNCTION
71850 --         EventClass_138
71851 --
71852 ----------------------------------------
71853 --
71854 FUNCTION EventClass_138
71855        (p_application_id         IN NUMBER
71856        ,p_base_ledger_id         IN NUMBER
71857        ,p_target_ledger_id       IN NUMBER
71858        ,p_language               IN VARCHAR2
71859        ,p_currency_code          IN VARCHAR2
71860        ,p_sla_ledger_id          IN NUMBER
71861        ,p_pad_start_date         IN DATE
71862        ,p_pad_end_date           IN DATE
71863        ,p_primary_ledger_id      IN NUMBER)
71864 RETURN BOOLEAN IS
71865 --
71866 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CREDIT_MEMO_ALL';
71867 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CREDIT_MEMO';
71868 
71869 l_calculate_acctd_flag   VARCHAR2(1) :='N';
71870 l_calculate_g_l_flag     VARCHAR2(1) :='Y';
71871 --
71872 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
71873 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
71874 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
71875 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
71876 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
71877 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
71878 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
71879 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
71880 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
71881 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
71882 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
71883 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
71884 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
71885 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
71886 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
71887 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
71888 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
71889 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
71890 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
71891 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
71892 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
71893 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
71894 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
71895 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
71896 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
71897 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
71898 
71899 l_event_id                             NUMBER;
71900 l_previous_event_id                    NUMBER;
71901 l_first_event_id                       NUMBER;
71905 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
71902 l_last_event_id                        NUMBER;
71903 
71904 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
71906 --
71907 --
71908 l_result                    BOOLEAN := TRUE;
71909 l_rows                      NUMBER  := 1000;
71910 l_event_type_name           VARCHAR2(80) := 'All';
71911 l_event_class_name          VARCHAR2(80) := 'Credit Memo';
71912 l_description               VARCHAR2(4000);
71913 l_transaction_reversal      NUMBER;
71914 l_ae_header_id              NUMBER;
71915 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
71916 l_log_module                VARCHAR2(240);
71917 --
71918 l_acct_reversal_source      VARCHAR2(30);
71919 l_trx_reversal_source       VARCHAR2(30);
71920 
71921 l_continue_with_lines       BOOLEAN := TRUE;
71922 --
71923 l_acc_rev_gl_date_source    DATE;                      -- 4262811
71924 --
71925 type t_array_event_id is table of number index by binary_integer;
71926 
71927 l_rec_array_event                    t_rec_array_event;
71928 l_null_rec_array_event               t_rec_array_event;
71929 l_array_ae_header_id                 xla_number_array_type;
71930 l_actual_flag                        VARCHAR2(1) := NULL;
71931 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
71932 l_balance_type_code                  VARCHAR2(1) :=NULL;
71933 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
71934 
71935 --
71936 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
71937 --
71938 
71939 TYPE t_array_source_12 IS TABLE OF AR_CREDIT_MEMO_H_V.CM_RECEIVABLE_CCID%TYPE INDEX BY BINARY_INTEGER;
71940 TYPE t_array_source_18 IS TABLE OF AR_SYSTEM_PARAM_H_V.CODE_COMBINATION_ID_GAIN%TYPE INDEX BY BINARY_INTEGER;
71941 TYPE t_array_source_19 IS TABLE OF AR_SYSTEM_PARAM_H_V.CODE_COMBINATION_ID_LOSS%TYPE INDEX BY BINARY_INTEGER;
71942 TYPE t_array_source_32 IS TABLE OF AR_CREDIT_MEMO_H_V.XLA_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
71943 TYPE t_array_source_44 IS TABLE OF AR_CREDIT_MEMO_H_V.CM_INVOICE_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
71944 TYPE t_array_source_50 IS TABLE OF AR_CM_BILL_TO_CUST_H_V.CM_BILL_CUST_ACCOUNT_ID%TYPE INDEX BY BINARY_INTEGER;
71945 TYPE t_array_source_51 IS TABLE OF AR_CM_BILL_SITE_USES_H_V.CM_BILL_USES_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
71946 TYPE t_array_source_67 IS TABLE OF AR_CREDIT_MEMO_H_V.CM_INVOICING_RULE_ID%TYPE INDEX BY BINARY_INTEGER;
71947 
71948 TYPE t_array_source_2 IS TABLE OF AR_CM_LINES_L_V.CM_LINE_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
71949 TYPE t_array_source_3 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CODE_COMBINATION_ID%TYPE INDEX BY BINARY_INTEGER;
71950 TYPE t_array_source_20 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_SOURCE_TYPE%TYPE INDEX BY BINARY_INTEGER;
71951 TYPE t_array_source_21 IS TABLE OF AR_RECEIVABLES_TRX_ACT_S_V.REC_ACT_TYPE%TYPE INDEX BY BINARY_INTEGER;
71952 TYPE t_array_source_24 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_ENT_AMT%TYPE INDEX BY BINARY_INTEGER;
71953 TYPE t_array_source_42 IS TABLE OF AR_CM_LINES_BASE_V.CM_DIST_IDENTIFER%TYPE INDEX BY BINARY_INTEGER;
71954 TYPE t_array_source_43 IS TABLE OF AR_CM_LINES_BASE_V.CM_DIST_TYPE%TYPE INDEX BY BINARY_INTEGER;
71955 TYPE t_array_source_45 IS TABLE OF AR_CM_LINES_BASE_V.CM_LINE_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
71956 TYPE t_array_source_46 IS TABLE OF AR_CM_LINES_BASE_V.CM_LINE_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
71957 TYPE t_array_source_47 IS TABLE OF AR_CM_LINES_BASE_V.CM_LINE_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
71958 TYPE t_array_source_48 IS TABLE OF AR_CM_LINES_BASE_V.GAIN_LOSS_REF%TYPE INDEX BY BINARY_INTEGER;
71959 TYPE t_array_source_49 IS TABLE OF AR_CM_LINES_BASE_V.CM_LINE_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
71960 TYPE t_array_source_52 IS TABLE OF AR_CM_LINES_L_V.CM_TAX_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
71961 TYPE t_array_source_53 IS TABLE OF AR_CM_LINES_L_V.CM_LINE_DIST_ACCOUNT_CLASS%TYPE INDEX BY BINARY_INTEGER;
71962 TYPE t_array_source_54 IS TABLE OF AR_CM_LINES_L_V.CM_LINE_DIST_AMT%TYPE INDEX BY BINARY_INTEGER;
71963 
71964 l_array_source_12              t_array_source_12;
71965 l_array_source_18              t_array_source_18;
71966 l_array_source_19              t_array_source_19;
71967 l_array_source_32              t_array_source_32;
71968 l_array_source_44              t_array_source_44;
71969 l_array_source_50              t_array_source_50;
71970 l_array_source_51              t_array_source_51;
71971 l_array_source_67              t_array_source_67;
71972 
71973 l_array_source_2      t_array_source_2;
71974 l_array_source_3      t_array_source_3;
71975 l_array_source_20      t_array_source_20;
71976 l_array_source_21      t_array_source_21;
71977 l_array_source_24      t_array_source_24;
71978 l_array_source_42      t_array_source_42;
71979 l_array_source_43      t_array_source_43;
71980 l_array_source_45      t_array_source_45;
71981 l_array_source_46      t_array_source_46;
71982 l_array_source_47      t_array_source_47;
71983 l_array_source_48      t_array_source_48;
71984 l_array_source_49      t_array_source_49;
71985 l_array_source_52      t_array_source_52;
71986 l_array_source_53      t_array_source_53;
71987 l_array_source_54      t_array_source_54;
71988 
71989 --
71990 CURSOR header_cur
71991 IS
71992 SELECT /*+ leading(xet) cardinality(xet,1) */
71993 -- Event Class Code: CREDIT_MEMO
71994     xet.entity_id
71995    ,xet.legal_entity_id
71996    ,xet.entity_code
71997    ,xet.transaction_number
71998    ,xet.event_id
71999    ,xet.event_class_code
72000    ,xet.event_type_code
72001    ,xet.event_number
72005    ,xet.reference_num_2
72002    ,xet.event_date
72003    ,xet.transaction_date
72004    ,xet.reference_num_1
72006    ,xet.reference_num_3
72007    ,xet.reference_num_4
72008    ,xet.reference_char_1
72009    ,xet.reference_char_2
72010    ,xet.reference_char_3
72011    ,xet.reference_char_4
72012    ,xet.reference_date_1
72013    ,xet.reference_date_2
72014    ,xet.reference_date_3
72015    ,xet.reference_date_4
72016    ,xet.event_created_by
72017    ,xet.budgetary_control_flag 
72018   , h5.CM_RECEIVABLE_CCID    source_12
72019   , h8.CODE_COMBINATION_ID_GAIN    source_18
72020   , h8.CODE_COMBINATION_ID_LOSS    source_19
72021   , h5.XLA_PARTY_TYPE    source_32
72022   , h5.CM_INVOICE_CURRENCY_CODE    source_44
72023   , h2.CM_BILL_CUST_ACCOUNT_ID    source_50
72024   , h1.CM_BILL_USES_SITE_USE_ID    source_51
72025   , h5.CM_INVOICING_RULE_ID    source_67
72026   FROM xla_events_gt     xet 
72027   , AR_CM_BILL_SITE_USES_H_V  h1
72028   , AR_CM_BILL_TO_CUST_H_V  h2
72029   , AR_CREDIT_MEMO_H_V  h5
72030   , AR_SYSTEM_PARAM_H_V  h8
72031  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
72032    and xet.event_class_code = C_EVENT_CLASS_CODE
72033    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
72034   AND h2.event_id  = h1.event_id
72035   AND h5.event_id  = h1.event_id
72036   AND h8.event_id (+) = h1.event_id
72037 
72038  ORDER BY event_id
72039 ;
72040 
72041 
72042 --
72043 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
72044 IS
72045 SELECT  /*+ leading(xet) cardinality(xet,1) */
72046 -- Event Class Code: CREDIT_MEMO
72047     xet.entity_id
72048    ,xet.legal_entity_id
72049    ,xet.entity_code
72050    ,xet.transaction_number
72051    ,xet.event_id
72052    ,xet.event_class_code
72053    ,xet.event_type_code
72054    ,xet.event_number
72055    ,xet.event_date
72056    ,xet.transaction_date
72057    ,xet.reference_num_1
72058    ,xet.reference_num_2
72059    ,xet.reference_num_3
72060    ,xet.reference_num_4
72061    ,xet.reference_char_1
72062    ,xet.reference_char_2
72063    ,xet.reference_char_3
72064    ,xet.reference_char_4
72065    ,xet.reference_date_1
72066    ,xet.reference_date_2
72067    ,xet.reference_date_3
72068    ,xet.reference_date_4
72069    ,xet.event_created_by
72070    ,xet.budgetary_control_flag
72071  , l3.LINE_NUMBER  
72072   , l4.CM_LINE_DIST_CCID    source_2
72073   , l6.DIST_CODE_COMBINATION_ID    source_3
72074   , l6.DIST_SOURCE_TYPE    source_20
72075   , l7.REC_ACT_TYPE    source_21
72076   , l6.DIST_ENT_AMT    source_24
72077   , l3.CM_DIST_IDENTIFER    source_42
72078   , l3.CM_DIST_TYPE    source_43
72079   , l3.CM_LINE_CUR_CONVERSION_DATE    source_45
72080   , l3.CM_LINE_CUR_CONVERSION_RATE    source_46
72081   , l3.CM_LINE_CUR_CONVERSION_TYPE    source_47
72082   , l3.GAIN_LOSS_REF    source_48
72083   , l3.CM_LINE_ACCTD_AMT    source_49
72084   , l4.CM_TAX_LINE_ID    source_52
72085   , l4.CM_LINE_DIST_ACCOUNT_CLASS    source_53
72086   , l4.CM_LINE_DIST_AMT    source_54
72087   FROM xla_events_gt     xet 
72088   , AR_CM_LINES_BASE_V  l3
72089   , AR_CM_LINES_L_V  l4
72090   , AR_DISTRIBUTIONS_L_V  l6
72091   , AR_RECEIVABLES_TRX_ACT_S_V  l7
72092  WHERE xet.event_id between x_first_event_id and x_last_event_id
72093    and xet.event_date between p_pad_start_date and p_pad_end_date
72094    and xet.event_class_code = C_EVENT_CLASS_CODE
72095    and xet.event_status_code <> 'N'   AND l3.event_id      = xet.event_id
72096   AND l4.event_id (+)    = l3.event_id
72097   AND l4.line_number (+) = l3.line_number
72098   AND l6.event_id (+)    = l3.event_id
72099   AND l6.line_number (+) = l3.line_number
72100   AND l7.event_id (+)    = l3.event_id
72101   AND l7.line_number (+) = l3.line_number
72102 ;
72103 
72104 --
72105 BEGIN
72106 IF g_log_enabled THEN
72107    l_log_module := C_DEFAULT_MODULE||'.EventClass_138';
72108 END IF;
72109 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
72110    trace
72111       (p_msg      => 'BEGIN of EventClass_138'
72112       ,p_level    => C_LEVEL_PROCEDURE
72113       ,p_module   => l_log_module);
72114 END IF;
72115 
72116 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
72117    trace
72118       (p_msg      => 'p_application_id = '||p_application_id||
72119                      ' - p_base_ledger_id = '||p_base_ledger_id||
72120                      ' - p_target_ledger_id  = '||p_target_ledger_id||
72121                      ' - p_language = '||p_language||
72122                      ' - p_currency_code = '||p_currency_code||
72123                      ' - p_sla_ledger_id = '||p_sla_ledger_id
72124       ,p_level    => C_LEVEL_STATEMENT
72125       ,p_module   => l_log_module);
72126 END IF;
72127 --
72128 -- initialze arrays
72129 --
72130 g_array_event.DELETE;
72131 l_rec_array_event := l_null_rec_array_event;
72132 --
72133 --------------------------------------
72134 -- 4262811 Initialze MPA Line Number
72135 --------------------------------------
72136 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
72137 
72138 --
72139 
72140 --
72141 OPEN header_cur;
72142 --
72143 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
72144    trace
72145    (p_msg      => 'SQL - FETCH header_cur'
72146    ,p_level    => C_LEVEL_STATEMENT
72147    ,p_module   => l_log_module);
72151 FETCH header_cur BULK COLLECT INTO
72148 END IF;
72149 --
72150 LOOP
72152         l_array_entity_id
72153       , l_array_legal_entity_id
72154       , l_array_entity_code
72155       , l_array_transaction_num
72156       , l_array_event_id
72157       , l_array_class_code
72158       , l_array_event_type
72159       , l_array_event_number
72160       , l_array_event_date
72161       , l_array_transaction_date
72162       , l_array_reference_num_1
72163       , l_array_reference_num_2
72164       , l_array_reference_num_3
72165       , l_array_reference_num_4
72166       , l_array_reference_char_1
72167       , l_array_reference_char_2
72168       , l_array_reference_char_3
72169       , l_array_reference_char_4
72170       , l_array_reference_date_1
72171       , l_array_reference_date_2
72172       , l_array_reference_date_3
72173       , l_array_reference_date_4
72174       , l_array_event_created_by
72175       , l_array_budgetary_control_flag 
72176       , l_array_source_12
72177       , l_array_source_18
72178       , l_array_source_19
72179       , l_array_source_32
72180       , l_array_source_44
72181       , l_array_source_50
72182       , l_array_source_51
72183       , l_array_source_67
72184       LIMIT l_rows;
72185 --
72186 IF (C_LEVEL_EVENT >= g_log_level) THEN
72187    trace
72188    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
72189    ,p_level    => C_LEVEL_EVENT
72190    ,p_module   => l_log_module);
72191 END IF;
72192 --
72193 EXIT WHEN l_array_entity_id.COUNT = 0;
72194 
72195 -- initialize arrays
72196 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
72197 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
72198 
72199 --
72200 -- Bug 4458708
72201 --
72202 XLA_AE_LINES_PKG.g_LineNumber := 0;
72203 
72204 
72205 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
72206 g_last_hdr_idx := l_array_event_id.LAST;
72207 --
72208 -- loop for the headers. Each iteration is for each header extract row
72209 -- fetched in header cursor
72210 --
72211 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
72212 
72213 --
72214 -- set event info as cache for other routines to refer event attributes
72215 --
72216 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
72217    (p_application_id           => p_application_id
72218    ,p_primary_ledger_id        => p_primary_ledger_id
72219    ,p_base_ledger_id           => p_base_ledger_id
72220    ,p_target_ledger_id         => p_target_ledger_id
72221    ,p_entity_id                => l_array_entity_id(hdr_idx)
72222    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
72223    ,p_entity_code              => l_array_entity_code(hdr_idx)
72224    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
72225    ,p_event_id                 => l_array_event_id(hdr_idx)
72226    ,p_event_class_code         => l_array_class_code(hdr_idx)
72227    ,p_event_type_code          => l_array_event_type(hdr_idx)
72228    ,p_event_number             => l_array_event_number(hdr_idx)
72229    ,p_event_date               => l_array_event_date(hdr_idx)
72230    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
72231    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
72232    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
72233    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
72234    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
72235    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
72236    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
72237    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
72238    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
72239    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
72240    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
72241    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
72242    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
72243    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
72244    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
72245 
72246 --
72247 -- set the status of entry to C_VALID (0)
72248 --
72249 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
72250 
72251 --
72252 -- initialize a row for ae header
72253 --
72254 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
72255 
72256 l_event_id := l_array_event_id(hdr_idx);
72257 
72258 --
72259 -- storing the hdr_idx for event. May be used by line cursor.
72260 --
72261 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
72262 
72263 --
72264 -- store sources from header extract. This can be improved to
72265 -- store only those sources from header extract that may be used in lines
72266 --
72267 
72268 g_array_event(l_event_id).array_value_num('source_12') := l_array_source_12(hdr_idx);
72269 g_array_event(l_event_id).array_value_num('source_18') := l_array_source_18(hdr_idx);
72270 g_array_event(l_event_id).array_value_num('source_19') := l_array_source_19(hdr_idx);
72271 g_array_event(l_event_id).array_value_char('source_32') := l_array_source_32(hdr_idx);
72272 g_array_event(l_event_id).array_value_char('source_44') := l_array_source_44(hdr_idx);
72276 
72273 g_array_event(l_event_id).array_value_num('source_50') := l_array_source_50(hdr_idx);
72274 g_array_event(l_event_id).array_value_num('source_51') := l_array_source_51(hdr_idx);
72275 g_array_event(l_event_id).array_value_num('source_67') := l_array_source_67(hdr_idx);
72277 --
72278 -- initilaize the status of ae headers for diffrent balance types
72279 -- the status is initialised to C_NOT_CREATED (2)
72280 --
72281 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
72282 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
72283 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
72284 
72285 --
72286 -- call api to validate and store accounting attributes for header
72287 --
72288 
72289 ------------------------------------------------------------
72290 -- Accrual Reversal : to get date for Standard Source (NONE)
72291 ------------------------------------------------------------
72292 l_acc_rev_gl_date_source := NULL;
72293 
72294      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
72295       l_rec_acct_attrs.array_date_value(1) := 
72296 xla_ae_sources_pkg.GetSystemSourceDate(
72297    p_source_code           => 'XLA_EVENT_DATE'
72298  , p_source_type_code      => 'Y'
72299  , p_source_application_id =>  602
72300 );
72301 
72302 
72303 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
72304 
72305 XLA_AE_HEADER_PKG.SetJeCategoryName;
72306 
72307 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
72308 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
72309 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
72310 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
72311 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
72312 
72313 
72314 -- No header level analytical criteria
72315 
72316 --
72317 --accounting attribute enhancement, bug 3612931
72318 --
72319 l_trx_reversal_source := SUBSTR(NULL, 1,30);
72320 
72321 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
72322    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
72323 
72324    xla_accounting_err_pkg.build_message
72325       (p_appli_s_name            => 'XLA'
72326       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
72327       ,p_token_1                 => 'ACCT_ATTR_NAME'
72328       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
72329       ,p_token_2                 => 'PRODUCT_NAME'
72330       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
72331       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
72332       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
72333       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
72334 
72335 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
72336    --
72337    -- following sets the accounting attributes needed to reverse
72338    -- accounting for a distributeion
72339    --
72340    xla_ae_lines_pkg.SetTrxReversalAttrs
72341       (p_event_id              => l_event_id
72342       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
72343       ,p_trx_reversal_source   => l_trx_reversal_source);
72344 
72345 END IF;
72346 
72347 
72348 ----------------------------------------------------------------
72349 -- 4262811 -  update the header statuses to invalid in need be
72350 ----------------------------------------------------------------
72351 --
72352 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
72353 
72354 
72355   -----------------------------------------------
72356   -- No accrual reversal for the event class/type
72357   -----------------------------------------------
72358 ----------------------------------------------------------------
72359 
72360 --
72361 -- this ends the header loop iteration for one bulk fetch
72362 --
72363 END LOOP;
72364 
72365 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
72366 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
72367 
72368 --
72369 -- insert dummy rows into lines gt table that were created due to
72370 -- transaction reversals
72371 --
72372 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
72373    l_result := XLA_AE_LINES_PKG.InsertLines;
72374 END IF;
72375 
72376 --
72377 -- reset the temp_line_num for each set of events fetched from header
72378 -- cursor rather than doing it for each new event in line cursor
72379 -- Bug 3939231
72380 --
72381 xla_ae_lines_pkg.g_temp_line_num := 0;
72382 
72383 
72384 
72385 --
72386 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
72387 --
72388 --
72389 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
72390 
72391       trace
72392          (p_msg      => 'SQL - FETCH line_cur'
72393          ,p_level    => C_LEVEL_STATEMENT
72394          ,p_module   => l_log_module);
72395 
72396 END IF;
72397 --
72398 --
72399 LOOP
72403       , l_array_legal_entity_id
72400   --
72401   FETCH line_cur BULK COLLECT INTO
72402         l_array_entity_id
72404       , l_array_entity_code
72405       , l_array_transaction_num
72406       , l_array_event_id
72407       , l_array_class_code
72408       , l_array_event_type
72409       , l_array_event_number
72410       , l_array_event_date
72411       , l_array_transaction_date
72412       , l_array_reference_num_1
72413       , l_array_reference_num_2
72414       , l_array_reference_num_3
72415       , l_array_reference_num_4
72416       , l_array_reference_char_1
72417       , l_array_reference_char_2
72418       , l_array_reference_char_3
72419       , l_array_reference_char_4
72420       , l_array_reference_date_1
72421       , l_array_reference_date_2
72422       , l_array_reference_date_3
72423       , l_array_reference_date_4
72424       , l_array_event_created_by
72425       , l_array_budgetary_control_flag
72426       , l_array_extract_line_num 
72427       , l_array_source_2
72428       , l_array_source_3
72429       , l_array_source_20
72430       , l_array_source_21
72431       , l_array_source_24
72432       , l_array_source_42
72433       , l_array_source_43
72434       , l_array_source_45
72435       , l_array_source_46
72436       , l_array_source_47
72437       , l_array_source_48
72438       , l_array_source_49
72439       , l_array_source_52
72440       , l_array_source_53
72441       , l_array_source_54
72442       LIMIT l_rows;
72443 
72444   --
72445   IF (C_LEVEL_EVENT >= g_log_level) THEN
72446             trace
72447                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
72448                ,p_level    => C_LEVEL_EVENT
72449                ,p_module   => l_log_module);
72450   END IF;
72451   --
72452   EXIT WHEN l_array_entity_id.count = 0;
72453 
72454   XLA_AE_LINES_PKG.g_rec_lines := null;
72455 
72456 --
72457 -- Bug 4458708
72458 --
72459 XLA_AE_LINES_PKG.g_LineNumber := 0;
72460 --
72461 --
72462 
72463 FOR Idx IN 1..l_array_event_id.count LOOP
72464    --
72465    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
72466    --
72467    l_event_id := l_array_event_id(idx);  -- 5648433
72468 
72469    --
72470    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
72471    --
72472 
72473    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
72474              (g_array_event(l_event_id).array_value_num('header_index'))
72475          ,'N'
72476          ) <> 'Y'
72477    THEN
72478       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
72479          trace
72480             (p_msg      => 'Trancaction revesal option is not Y '
72481             ,p_level    => C_LEVEL_STATEMENT
72482             ,p_module   => l_log_module);
72483       END IF;
72484 
72485 --
72486 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
72487 --
72488 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
72489 --
72490 -- set event info as cache for other routines to refer event attributes
72491 --
72492 
72493 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
72494    l_previous_event_id := l_event_id;
72495 
72496    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
72497       (p_application_id           => p_application_id
72498       ,p_primary_ledger_id        => p_primary_ledger_id
72499       ,p_base_ledger_id           => p_base_ledger_id
72500       ,p_target_ledger_id         => p_target_ledger_id
72501       ,p_entity_id                => l_array_entity_id(Idx)
72502       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
72503       ,p_entity_code              => l_array_entity_code(Idx)
72504       ,p_transaction_num          => l_array_transaction_num(Idx)
72505       ,p_event_id                 => l_array_event_id(Idx)
72506       ,p_event_class_code         => l_array_class_code(Idx)
72507       ,p_event_type_code          => l_array_event_type(Idx)
72508       ,p_event_number             => l_array_event_number(Idx)
72509       ,p_event_date               => l_array_event_date(Idx)
72510       ,p_transaction_date         => l_array_transaction_date(Idx)
72511       ,p_reference_num_1          => l_array_reference_num_1(Idx)
72512       ,p_reference_num_2          => l_array_reference_num_2(Idx)
72513       ,p_reference_num_3          => l_array_reference_num_3(Idx)
72514       ,p_reference_num_4          => l_array_reference_num_4(Idx)
72515       ,p_reference_char_1         => l_array_reference_char_1(Idx)
72516       ,p_reference_char_2         => l_array_reference_char_2(Idx)
72517       ,p_reference_char_3         => l_array_reference_char_3(Idx)
72518       ,p_reference_char_4         => l_array_reference_char_4(Idx)
72519       ,p_reference_date_1         => l_array_reference_date_1(Idx)
72520       ,p_reference_date_2         => l_array_reference_date_2(Idx)
72521       ,p_reference_date_3         => l_array_reference_date_3(Idx)
72522       ,p_reference_date_4         => l_array_reference_date_4(Idx)
72523       ,p_event_created_by         => l_array_event_created_by(Idx)
72524       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
72525        --
72526 END IF;
72527 
72528 
72529 
72530 --
72531 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
72535 IF l_continue_with_lines THEN
72532 
72533 l_acct_reversal_source := SUBSTR(NULL, 1,30);
72534 
72536    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
72537       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
72538 
72539       xla_accounting_err_pkg.build_message
72540          (p_appli_s_name            => 'XLA'
72541          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
72542          ,p_token_1                 => 'LINE_NUMBER'
72543          ,p_value_1                 => l_array_extract_line_num(Idx)
72544          ,p_token_2                 => 'PRODUCT_NAME'
72545          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
72546          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
72547          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
72548          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
72549 
72550    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
72551       --
72552       -- following sets the accounting attributes needed to reverse
72553       -- accounting for a distributeion
72554       --
72555 
72556       --
72557       -- 5217187
72558       --
72559       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
72560       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
72561                                        g_array_event(l_event_id).array_value_num('header_index'));
72562       --
72563       --
72564 
72565       -- No reversal code generated
72566 
72567       xla_ae_lines_pkg.SetAcctReversalAttrs
72568          (p_event_id             => l_event_id
72569          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
72570          ,p_calculate_acctd_flag => l_calculate_acctd_flag
72571          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
72572    END IF;
72573 
72574    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
72575        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
72576 
72577 --
72578 AcctLineType_40 (
72579  p_application_id  => p_application_id
72580  ,p_event_id     => l_event_id
72581  ,p_calculate_acctd_flag => l_calculate_acctd_flag
72582  ,p_calculate_g_l_flag => l_calculate_g_l_flag
72583  ,p_actual_flag => l_actual_flag
72584  ,p_balance_type_code => l_balance_type_code
72585  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
72586  
72587  , p_source_3 => l_array_source_3(Idx)
72588  , p_source_20 => l_array_source_20(Idx)
72589  , p_source_24 => l_array_source_24(Idx)
72590  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
72591  , p_source_42 => l_array_source_42(Idx)
72592  , p_source_43 => l_array_source_43(Idx)
72593  , p_source_44 => g_array_event(l_event_id).array_value_char('source_44')
72594  , p_source_45 => l_array_source_45(Idx)
72595  , p_source_46 => l_array_source_46(Idx)
72596  , p_source_47 => l_array_source_47(Idx)
72597  , p_source_48 => l_array_source_48(Idx)
72598  , p_source_49 => l_array_source_49(Idx)
72599  , p_source_50 => g_array_event(l_event_id).array_value_num('source_50')
72600  , p_source_51 => g_array_event(l_event_id).array_value_num('source_51')
72601  , p_source_52 => l_array_source_52(Idx)
72602  );
72603 If(l_balance_type_code = 'A') THEN
72604   l_actual_gain_loss_ref := l_gain_or_loss_ref;
72605 END IF;
72606 
72607 --
72608 
72609 
72610 --
72611 AcctLineType_41 (
72612  p_application_id  => p_application_id
72613  ,p_event_id     => l_event_id
72614  ,p_calculate_acctd_flag => l_calculate_acctd_flag
72615  ,p_calculate_g_l_flag => l_calculate_g_l_flag
72616  ,p_actual_flag => l_actual_flag
72617  ,p_balance_type_code => l_balance_type_code
72618  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
72619  
72620  , p_source_3 => l_array_source_3(Idx)
72621  , p_source_20 => l_array_source_20(Idx)
72622  , p_source_21 => l_array_source_21(Idx)
72623  , p_source_24 => l_array_source_24(Idx)
72624  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
72625  , p_source_42 => l_array_source_42(Idx)
72626  , p_source_43 => l_array_source_43(Idx)
72627  , p_source_44 => g_array_event(l_event_id).array_value_char('source_44')
72628  , p_source_45 => l_array_source_45(Idx)
72629  , p_source_46 => l_array_source_46(Idx)
72630  , p_source_47 => l_array_source_47(Idx)
72631  , p_source_48 => l_array_source_48(Idx)
72632  , p_source_49 => l_array_source_49(Idx)
72633  , p_source_50 => g_array_event(l_event_id).array_value_num('source_50')
72634  , p_source_51 => g_array_event(l_event_id).array_value_num('source_51')
72635  , p_source_52 => l_array_source_52(Idx)
72636  );
72637 If(l_balance_type_code = 'A') THEN
72638   l_actual_gain_loss_ref := l_gain_or_loss_ref;
72639 END IF;
72640 
72641 --
72642 
72643 
72644 --
72645 AcctLineType_42 (
72646  p_application_id  => p_application_id
72647  ,p_event_id     => l_event_id
72648  ,p_calculate_acctd_flag => l_calculate_acctd_flag
72649  ,p_calculate_g_l_flag => l_calculate_g_l_flag
72650  ,p_actual_flag => l_actual_flag
72651  ,p_balance_type_code => l_balance_type_code
72652  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
72653  
72654  , p_source_2 => l_array_source_2(Idx)
72655  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
72656  , p_source_42 => l_array_source_42(Idx)
72660  , p_source_46 => l_array_source_46(Idx)
72657  , p_source_43 => l_array_source_43(Idx)
72658  , p_source_44 => g_array_event(l_event_id).array_value_char('source_44')
72659  , p_source_45 => l_array_source_45(Idx)
72661  , p_source_47 => l_array_source_47(Idx)
72662  , p_source_48 => l_array_source_48(Idx)
72663  , p_source_49 => l_array_source_49(Idx)
72664  , p_source_50 => g_array_event(l_event_id).array_value_num('source_50')
72665  , p_source_51 => g_array_event(l_event_id).array_value_num('source_51')
72666  , p_source_52 => l_array_source_52(Idx)
72667  , p_source_53 => l_array_source_53(Idx)
72668  , p_source_54 => l_array_source_54(Idx)
72669  );
72670 If(l_balance_type_code = 'A') THEN
72671   l_actual_gain_loss_ref := l_gain_or_loss_ref;
72672 END IF;
72673 
72674 --
72675 
72676 
72677 --
72678 AcctLineType_43 (
72679  p_application_id  => p_application_id
72680  ,p_event_id     => l_event_id
72681  ,p_calculate_acctd_flag => l_calculate_acctd_flag
72682  ,p_calculate_g_l_flag => l_calculate_g_l_flag
72683  ,p_actual_flag => l_actual_flag
72684  ,p_balance_type_code => l_balance_type_code
72685  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
72686  
72687  , p_source_2 => l_array_source_2(Idx)
72688  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
72689  , p_source_42 => l_array_source_42(Idx)
72690  , p_source_43 => l_array_source_43(Idx)
72691  , p_source_44 => g_array_event(l_event_id).array_value_char('source_44')
72692  , p_source_45 => l_array_source_45(Idx)
72693  , p_source_46 => l_array_source_46(Idx)
72694  , p_source_47 => l_array_source_47(Idx)
72695  , p_source_48 => l_array_source_48(Idx)
72696  , p_source_49 => l_array_source_49(Idx)
72697  , p_source_50 => g_array_event(l_event_id).array_value_num('source_50')
72698  , p_source_51 => g_array_event(l_event_id).array_value_num('source_51')
72699  , p_source_52 => l_array_source_52(Idx)
72700  , p_source_53 => l_array_source_53(Idx)
72701  , p_source_54 => l_array_source_54(Idx)
72702  );
72703 If(l_balance_type_code = 'A') THEN
72704   l_actual_gain_loss_ref := l_gain_or_loss_ref;
72705 END IF;
72706 
72707 --
72708 
72709 
72710 --
72711 AcctLineType_44 (
72712  p_application_id  => p_application_id
72713  ,p_event_id     => l_event_id
72714  ,p_calculate_acctd_flag => l_calculate_acctd_flag
72715  ,p_calculate_g_l_flag => l_calculate_g_l_flag
72716  ,p_actual_flag => l_actual_flag
72717  ,p_balance_type_code => l_balance_type_code
72718  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
72719  
72720  , p_source_2 => l_array_source_2(Idx)
72721  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
72722  , p_source_42 => l_array_source_42(Idx)
72723  , p_source_43 => l_array_source_43(Idx)
72724  , p_source_44 => g_array_event(l_event_id).array_value_char('source_44')
72725  , p_source_45 => l_array_source_45(Idx)
72726  , p_source_46 => l_array_source_46(Idx)
72727  , p_source_47 => l_array_source_47(Idx)
72728  , p_source_48 => l_array_source_48(Idx)
72729  , p_source_49 => l_array_source_49(Idx)
72730  , p_source_50 => g_array_event(l_event_id).array_value_num('source_50')
72731  , p_source_51 => g_array_event(l_event_id).array_value_num('source_51')
72732  , p_source_52 => l_array_source_52(Idx)
72733  , p_source_53 => l_array_source_53(Idx)
72734  , p_source_54 => l_array_source_54(Idx)
72735  );
72736 If(l_balance_type_code = 'A') THEN
72737   l_actual_gain_loss_ref := l_gain_or_loss_ref;
72738 END IF;
72739 
72740 --
72741 
72742 
72743 --
72744 AcctLineType_45 (
72745  p_application_id  => p_application_id
72746  ,p_event_id     => l_event_id
72747  ,p_calculate_acctd_flag => l_calculate_acctd_flag
72748  ,p_calculate_g_l_flag => l_calculate_g_l_flag
72749  ,p_actual_flag => l_actual_flag
72750  ,p_balance_type_code => l_balance_type_code
72751  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
72752  
72753  , p_source_2 => l_array_source_2(Idx)
72754  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
72755  , p_source_42 => l_array_source_42(Idx)
72756  , p_source_43 => l_array_source_43(Idx)
72757  , p_source_44 => g_array_event(l_event_id).array_value_char('source_44')
72758  , p_source_45 => l_array_source_45(Idx)
72759  , p_source_46 => l_array_source_46(Idx)
72760  , p_source_47 => l_array_source_47(Idx)
72761  , p_source_48 => l_array_source_48(Idx)
72762  , p_source_49 => l_array_source_49(Idx)
72763  , p_source_50 => g_array_event(l_event_id).array_value_num('source_50')
72764  , p_source_51 => g_array_event(l_event_id).array_value_num('source_51')
72765  , p_source_52 => l_array_source_52(Idx)
72766  , p_source_53 => l_array_source_53(Idx)
72767  , p_source_54 => l_array_source_54(Idx)
72768  );
72769 If(l_balance_type_code = 'A') THEN
72770   l_actual_gain_loss_ref := l_gain_or_loss_ref;
72771 END IF;
72772 
72773 --
72774 
72775 
72776 --
72777 AcctLineType_46 (
72778  p_application_id  => p_application_id
72779  ,p_event_id     => l_event_id
72780  ,p_calculate_acctd_flag => l_calculate_acctd_flag
72781  ,p_calculate_g_l_flag => l_calculate_g_l_flag
72782  ,p_actual_flag => l_actual_flag
72783  ,p_balance_type_code => l_balance_type_code
72784  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
72785  
72786  , p_source_18 => g_array_event(l_event_id).array_value_num('source_18')
72787  , p_source_19 => g_array_event(l_event_id).array_value_num('source_19')
72791  , p_source_48 => l_array_source_48(Idx)
72788  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
72789  , p_source_42 => l_array_source_42(Idx)
72790  , p_source_43 => l_array_source_43(Idx)
72792  , p_source_49 => l_array_source_49(Idx)
72793  , p_source_50 => g_array_event(l_event_id).array_value_num('source_50')
72794  , p_source_51 => g_array_event(l_event_id).array_value_num('source_51')
72795  , p_source_52 => l_array_source_52(Idx)
72796  );
72797 If(l_balance_type_code = 'A') THEN
72798   l_actual_gain_loss_ref := l_gain_or_loss_ref;
72799 END IF;
72800 
72801 --
72802 
72803 
72804 --
72805 AcctLineType_47 (
72806  p_application_id  => p_application_id
72807  ,p_event_id     => l_event_id
72808  ,p_calculate_acctd_flag => l_calculate_acctd_flag
72809  ,p_calculate_g_l_flag => l_calculate_g_l_flag
72810  ,p_actual_flag => l_actual_flag
72811  ,p_balance_type_code => l_balance_type_code
72812  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
72813  
72814  , p_source_2 => l_array_source_2(Idx)
72815  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
72816  , p_source_42 => l_array_source_42(Idx)
72817  , p_source_43 => l_array_source_43(Idx)
72818  , p_source_44 => g_array_event(l_event_id).array_value_char('source_44')
72819  , p_source_45 => l_array_source_45(Idx)
72820  , p_source_46 => l_array_source_46(Idx)
72821  , p_source_47 => l_array_source_47(Idx)
72822  , p_source_48 => l_array_source_48(Idx)
72823  , p_source_49 => l_array_source_49(Idx)
72824  , p_source_50 => g_array_event(l_event_id).array_value_num('source_50')
72825  , p_source_51 => g_array_event(l_event_id).array_value_num('source_51')
72826  , p_source_52 => l_array_source_52(Idx)
72827  , p_source_53 => l_array_source_53(Idx)
72828  , p_source_54 => l_array_source_54(Idx)
72829  );
72830 If(l_balance_type_code = 'A') THEN
72831   l_actual_gain_loss_ref := l_gain_or_loss_ref;
72832 END IF;
72833 
72834 --
72835 
72836 
72837 --
72838 AcctLineType_48 (
72839  p_application_id  => p_application_id
72840  ,p_event_id     => l_event_id
72841  ,p_calculate_acctd_flag => l_calculate_acctd_flag
72842  ,p_calculate_g_l_flag => l_calculate_g_l_flag
72843  ,p_actual_flag => l_actual_flag
72844  ,p_balance_type_code => l_balance_type_code
72845  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
72846  
72847  , p_source_2 => l_array_source_2(Idx)
72848  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
72849  , p_source_42 => l_array_source_42(Idx)
72850  , p_source_43 => l_array_source_43(Idx)
72851  , p_source_44 => g_array_event(l_event_id).array_value_char('source_44')
72852  , p_source_45 => l_array_source_45(Idx)
72853  , p_source_46 => l_array_source_46(Idx)
72854  , p_source_47 => l_array_source_47(Idx)
72855  , p_source_48 => l_array_source_48(Idx)
72856  , p_source_49 => l_array_source_49(Idx)
72857  , p_source_50 => g_array_event(l_event_id).array_value_num('source_50')
72858  , p_source_51 => g_array_event(l_event_id).array_value_num('source_51')
72859  , p_source_52 => l_array_source_52(Idx)
72860  , p_source_53 => l_array_source_53(Idx)
72861  , p_source_54 => l_array_source_54(Idx)
72862  );
72863 If(l_balance_type_code = 'A') THEN
72864   l_actual_gain_loss_ref := l_gain_or_loss_ref;
72865 END IF;
72866 
72867 --
72868 
72869 
72870 --
72871 AcctLineType_49 (
72872  p_application_id  => p_application_id
72873  ,p_event_id     => l_event_id
72874  ,p_calculate_acctd_flag => l_calculate_acctd_flag
72875  ,p_calculate_g_l_flag => l_calculate_g_l_flag
72876  ,p_actual_flag => l_actual_flag
72877  ,p_balance_type_code => l_balance_type_code
72878  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
72879  
72880  , p_source_2 => l_array_source_2(Idx)
72881  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
72882  , p_source_42 => l_array_source_42(Idx)
72883  , p_source_43 => l_array_source_43(Idx)
72884  , p_source_44 => g_array_event(l_event_id).array_value_char('source_44')
72885  , p_source_45 => l_array_source_45(Idx)
72886  , p_source_46 => l_array_source_46(Idx)
72887  , p_source_47 => l_array_source_47(Idx)
72888  , p_source_48 => l_array_source_48(Idx)
72889  , p_source_49 => l_array_source_49(Idx)
72890  , p_source_50 => g_array_event(l_event_id).array_value_num('source_50')
72891  , p_source_51 => g_array_event(l_event_id).array_value_num('source_51')
72892  , p_source_52 => l_array_source_52(Idx)
72893  , p_source_53 => l_array_source_53(Idx)
72894  , p_source_54 => l_array_source_54(Idx)
72895  );
72896 If(l_balance_type_code = 'A') THEN
72897   l_actual_gain_loss_ref := l_gain_or_loss_ref;
72898 END IF;
72899 
72900 --
72901 
72902 
72903 --
72904 AcctLineType_87 (
72905  p_application_id  => p_application_id
72906  ,p_event_id     => l_event_id
72907  ,p_calculate_acctd_flag => l_calculate_acctd_flag
72908  ,p_calculate_g_l_flag => l_calculate_g_l_flag
72909  ,p_actual_flag => l_actual_flag
72910  ,p_balance_type_code => l_balance_type_code
72911  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
72912  
72913  , p_source_2 => l_array_source_2(Idx)
72914  , p_source_12 => g_array_event(l_event_id).array_value_num('source_12')
72915  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
72916  , p_source_42 => l_array_source_42(Idx)
72917  , p_source_43 => l_array_source_43(Idx)
72921  , p_source_47 => l_array_source_47(Idx)
72918  , p_source_44 => g_array_event(l_event_id).array_value_char('source_44')
72919  , p_source_45 => l_array_source_45(Idx)
72920  , p_source_46 => l_array_source_46(Idx)
72922  , p_source_48 => l_array_source_48(Idx)
72923  , p_source_49 => l_array_source_49(Idx)
72924  , p_source_50 => g_array_event(l_event_id).array_value_num('source_50')
72925  , p_source_51 => g_array_event(l_event_id).array_value_num('source_51')
72926  , p_source_52 => l_array_source_52(Idx)
72927  , p_source_53 => l_array_source_53(Idx)
72928  , p_source_54 => l_array_source_54(Idx)
72929  , p_source_67 => g_array_event(l_event_id).array_value_num('source_67')
72930  );
72931 If(l_balance_type_code = 'A') THEN
72932   l_actual_gain_loss_ref := l_gain_or_loss_ref;
72933 END IF;
72934 
72935 --
72936 
72937       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
72938       -- or secondary ledger that has different currency with primary
72939       -- or alc that is calculated by sla
72940       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
72941             (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'))
72942 
72943 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
72944 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
72945           AND (l_actual_flag = 'A')) THEN
72946         XLA_AE_LINES_PKG.CreateGainOrLossLines(
72947           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
72948          ,p_application_id   => p_application_id
72949          ,p_amb_context_code => 'DEFAULT'
72950          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
72951          ,p_event_class_code => C_EVENT_CLASS_CODE
72952          ,p_event_type_code  => C_EVENT_TYPE_CODE
72953          
72954          ,p_gain_ccid        => -1
72955          ,p_loss_ccid        => -1
72956 
72957          ,p_actual_flag      => l_actual_flag
72958          ,p_enc_flag         => null
72959          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
72960          ,p_enc_g_l_ref      => null
72961          );
72962       END IF;
72963    END IF;
72964 END IF;
72965 
72966    ELSE
72967       --
72968       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
72969       --
72970       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
72971          trace
72972             (p_msg      => 'Trancaction revesal option is Y'
72973             ,p_level    => C_LEVEL_STATEMENT
72974             ,p_module   => l_log_module);
72975       END IF;
72976    END IF;
72977 
72978 END LOOP;
72979 l_result := XLA_AE_LINES_PKG.InsertLines ;
72980 end loop;
72981 close line_cur;
72982 
72983 
72984 --
72985 -- insert headers into xla_ae_headers_gt table
72986 --
72987 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
72988 
72989 -- insert into errors table here.
72990 
72991 END LOOP;
72992 
72993 --
72994 -- 4865292
72995 --
72996 -- Compare g_hdr_extract_count with event count in
72997 -- CreateHeadersAndLines.
72998 --
72999 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
73000 
73001 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
73002    trace (p_msg     => '# rows extracted from header extract objects '
73003                     || ' (running total): '
73004                     || g_hdr_extract_count
73005          ,p_level   => C_LEVEL_STATEMENT
73006          ,p_module  => l_log_module);
73007 END IF;
73008 
73009 CLOSE header_cur;
73010 --
73011 
73012 --
73013 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
73014    trace
73015       (p_msg      => 'END of EventClass_138'
73016       ,p_level    => C_LEVEL_PROCEDURE
73017       ,p_module   => l_log_module);
73018 END IF;
73019 --
73020 RETURN l_result;
73021 EXCEPTION
73022 WHEN xla_exceptions_pkg.application_exception THEN
73023    
73024 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
73025 
73026    
73027 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
73028 
73029    RAISE;
73030 
73031 WHEN NO_DATA_FOUND THEN
73032 
73033 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
73034 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
73035 
73036 FOR header_record IN header_cur
73037 LOOP
73038     l_array_header_events(header_record.event_id) := header_record.event_id;
73039 END LOOP;
73040 
73041 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
73042 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
73043 
73044 fnd_file.put_line(fnd_file.LOG, '                    ');
73045 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
73046 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
73047 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
73048 
73049 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
73050 LOOP
73051 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
73055 END LOOP;
73052 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
73053         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
73054 	END IF;
73056 
73057 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
73058 fnd_file.put_line(fnd_file.LOG, '                    ');
73059 
73060 
73061 xla_exceptions_pkg.raise_message
73062       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_138');
73063 
73064 
73065 WHEN OTHERS THEN
73066    xla_exceptions_pkg.raise_message
73067       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_138');
73068 END EventClass_138;
73069 --
73070 
73071 ---------------------------------------
73072 --
73073 -- PRIVATE PROCEDURE
73074 --         insert_sources_139
73075 --
73076 ----------------------------------------
73077 --
73078 PROCEDURE insert_sources_139(
73079                                 p_target_ledger_id       IN NUMBER
73080                               , p_language               IN VARCHAR2
73081                               , p_sla_ledger_id          IN NUMBER
73082                               , p_pad_start_date         IN DATE
73083                               , p_pad_end_date           IN DATE
73084                          )
73085 IS
73086 
73087 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'DEBIT_MEMO_ALL';
73088 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'DEBIT_MEMO';
73089 p_apps_owner                   VARCHAR2(30);
73090 l_log_module                   VARCHAR2(240);
73091 BEGIN
73092 IF g_log_enabled THEN
73093       l_log_module := C_DEFAULT_MODULE||'.insert_sources_139';
73094 END IF;
73095 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
73096 
73097       trace
73098          (p_msg      => 'BEGIN of insert_sources_139'
73099          ,p_level    => C_LEVEL_PROCEDURE
73100          ,p_module   => l_log_module);
73101 
73102 END IF;
73103 
73104 -- select APPS owner
73105 SELECT oracle_username
73106   INTO p_apps_owner
73107   FROM fnd_oracle_userid
73108  WHERE read_only_flag = 'U'
73109 ;
73110 
73111 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
73112       trace
73113          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
73114                         ' - p_language = '||p_language||
73115                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
73116                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
73117                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
73118                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
73119          ,p_level    => C_LEVEL_STATEMENT
73120          ,p_module   => l_log_module);
73121 END IF;
73122 
73123 
73124 --
73125 INSERT INTO xla_diag_sources --hdr2
73126 (
73127         event_id
73128       , ledger_id
73129       , sla_ledger_id
73130       , description_language
73131       , object_name
73132       , object_type_code
73133       , line_number
73134       , source_application_id
73135       , source_type_code
73136       , source_code
73137       , source_value
73138       , source_meaning
73139       , created_by
73140       , creation_date
73141       , last_update_date
73142       , last_updated_by
73143       , last_update_login
73144       , program_update_date
73145       , program_application_id
73146       , program_id
73147       , request_id
73148 )
73149 SELECT
73150         event_id
73151       , p_target_ledger_id
73152       , p_sla_ledger_id
73153       , p_language
73154       , object_name
73155       , object_type_code
73156       , line_number
73157       , source_application_id
73158       , source_type_code
73159       , source_code
73160       , SUBSTR(source_value ,1,1996)
73161       , SUBSTR(source_meaning ,1,200)
73162       , xla_environment_pkg.g_Usr_Id
73163       , TRUNC(SYSDATE)
73164       , TRUNC(SYSDATE)
73165       , xla_environment_pkg.g_Usr_Id
73166       , xla_environment_pkg.g_Login_Id
73167       , TRUNC(SYSDATE)
73168       , xla_environment_pkg.g_Prog_Appl_Id
73169       , xla_environment_pkg.g_Prog_Id
73170       , xla_environment_pkg.g_Req_Id
73171   FROM (
73172        SELECT xet.event_id                  event_id
73173             , 0                          line_number
73174             , CASE r
73175                WHEN 1 THEN 'AR_TRANSACTIONS_S_V' 
73176                 WHEN 2 THEN 'AR_BILL_TO_CUSTOMERS_S_V' 
73177                 WHEN 3 THEN 'AR_BILL_TO_SITE_USES_S_V' 
73178                 WHEN 4 THEN 'AR_TRANSACTIONS_S_V' 
73179                 WHEN 5 THEN 'AR_TRANSACTIONS_S_V' 
73180                 WHEN 6 THEN 'AR_TRANSACTIONS_S_V' 
73181                 WHEN 7 THEN 'AR_TRANSACTIONS_S_V' 
73182                 WHEN 8 THEN 'AR_TRANSACTIONS_S_V' 
73183                 WHEN 9 THEN 'AR_TRANSACTIONS_S_V' 
73184                 
73185                ELSE null
73186               END                           object_name
73187             , CASE r
73188                 WHEN 1 THEN 'HEADER' 
73189                 WHEN 2 THEN 'HEADER' 
73190                 WHEN 3 THEN 'HEADER' 
73191                 WHEN 4 THEN 'HEADER' 
73192                 WHEN 5 THEN 'HEADER' 
73193                 WHEN 6 THEN 'HEADER' 
73194                 WHEN 7 THEN 'HEADER' 
73195                 WHEN 8 THEN 'HEADER' 
73199               END                           object_type_code
73196                 WHEN 9 THEN 'HEADER' 
73197                 
73198                 ELSE null
73200             , CASE r
73201                 WHEN 1 THEN '222' 
73202                 WHEN 2 THEN '222' 
73203                 WHEN 3 THEN '222' 
73204                 WHEN 4 THEN '222' 
73205                 WHEN 5 THEN '222' 
73206                 WHEN 6 THEN '222' 
73207                 WHEN 7 THEN '222' 
73208                 WHEN 8 THEN '222' 
73209                 WHEN 9 THEN '222' 
73210                 
73211                 ELSE null
73212               END                           source_application_id
73213             , 'S'             source_type_code
73214             , CASE r
73215                 WHEN 1 THEN 'TRX_RECEIVABLE_CCID' 
73216                 WHEN 2 THEN 'BILL_CUST_ACCOUNT_ID' 
73217                 WHEN 3 THEN 'BILL_USES_SITE_USE_ID' 
73218                 WHEN 4 THEN 'XLA_PARTY_TYPE' 
73219                 WHEN 5 THEN 'TRX_INVOICE_CURRENCY_CODE' 
73220                 WHEN 6 THEN 'TRX_INVOICING_RULE_ID' 
73221                 WHEN 7 THEN 'TRX_DOC_SEQUENCE_CATEGORY' 
73222                 WHEN 8 THEN 'TRX_DOC_SEQUENCE_ID' 
73223                 WHEN 9 THEN 'TRX_DOC_SEQUENCE_VALUE' 
73224                 
73225                 ELSE null
73226               END                           source_code
73227             , CASE r
73228                 WHEN 1 THEN TO_CHAR(h5.TRX_RECEIVABLE_CCID)
73229                 WHEN 2 THEN TO_CHAR(h1.BILL_CUST_ACCOUNT_ID)
73230                 WHEN 3 THEN TO_CHAR(h2.BILL_USES_SITE_USE_ID)
73231                 WHEN 4 THEN TO_CHAR(h5.XLA_PARTY_TYPE)
73232                 WHEN 5 THEN TO_CHAR(h5.TRX_INVOICE_CURRENCY_CODE)
73233                 WHEN 6 THEN TO_CHAR(h5.TRX_INVOICING_RULE_ID)
73234                 WHEN 7 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_CATEGORY)
73235                 WHEN 8 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_ID)
73236                 WHEN 9 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_VALUE)
73237                 
73238                 ELSE null
73239               END                           source_value
73240             , null              source_meaning
73241          FROM xla_events_gt     xet  
73242       , AR_BILL_TO_CUSTOMERS_S_V  h1
73243       , AR_BILL_TO_SITE_USES_S_V  h2
73244       , AR_TRANSACTIONS_S_V  h5
73245              ,(select rownum r from all_objects where rownum <= 9 and owner = p_apps_owner)
73246          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
73247            AND xet.event_class_code = C_EVENT_CLASS_CODE
73248               AND h1.event_id = xet.event_id
73249   AND h2.event_id  = h1.event_id
73250   AND h5.event_id  = h1.event_id
73251 
73252 )
73253 ;
73254 --
73255 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
73256 
73257       trace
73258          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
73259          ,p_level    => C_LEVEL_STATEMENT
73260          ,p_module   => l_log_module);
73261 
73262 END IF;
73263 --
73264 
73265 
73266 
73267 --
73268 INSERT INTO xla_diag_sources  --line2
73269 (
73270         event_id
73271       , ledger_id
73272       , sla_ledger_id
73273       , description_language
73274       , object_name
73275       , object_type_code
73276       , line_number
73277       , source_application_id
73278       , source_type_code
73279       , source_code
73280       , source_value
73281       , source_meaning
73282       , created_by
73283       , creation_date
73284       , last_update_date
73285       , last_updated_by
73286       , last_update_login
73287       , program_update_date
73288       , program_application_id
73289       , program_id
73290       , request_id
73291 )
73292 SELECT  event_id
73293       , p_target_ledger_id
73294       , p_sla_ledger_id
73295       , p_language
73296       , object_name
73297       , object_type_code
73298       , line_number
73299       , source_application_id
73300       , source_type_code
73301       , source_code
73302       , SUBSTR(source_value,1,1996)
73303       , SUBSTR(source_meaning ,1,200)
73304       , xla_environment_pkg.g_Usr_Id
73305       , TRUNC(SYSDATE)
73306       , TRUNC(SYSDATE)
73307       , xla_environment_pkg.g_Usr_Id
73308       , xla_environment_pkg.g_Login_Id
73309       , TRUNC(SYSDATE)
73310       , xla_environment_pkg.g_Prog_Appl_Id
73311       , xla_environment_pkg.g_Prog_Id
73312       , xla_environment_pkg.g_Req_Id
73313   FROM (
73314        SELECT xet.event_id                  event_id
73315             , l4.line_number                 line_number
73316             , CASE r
73317                WHEN 1 THEN 'AR_CUST_TRX_LINES_L_V' 
73318                 WHEN 2 THEN 'AR_CUST_TRX_LINES_L_V' 
73319                 WHEN 3 THEN 'AR_CUST_TRX_LINES_L_V' 
73320                 WHEN 4 THEN 'AR_CUST_TRX_LINES_L_V' 
73321                 WHEN 5 THEN 'AR_CUST_TRX_LINES_L_V' 
73322                 WHEN 6 THEN 'AR_CUST_TRX_LINES_BASE_V' 
73323                 WHEN 7 THEN 'AR_CUST_TRX_LINES_BASE_V' 
73324                 WHEN 8 THEN 'AR_CUST_TRX_LINES_BASE_V' 
73325                 WHEN 9 THEN 'AR_CUST_TRX_LINES_BASE_V' 
73326                 WHEN 10 THEN 'AR_CUST_TRX_LINES_L_V' 
73327                 
73328                ELSE null
73329               END                           object_name
73330             , CASE r
73334                 WHEN 4 THEN 'LINE' 
73331                 WHEN 1 THEN 'LINE' 
73332                 WHEN 2 THEN 'LINE' 
73333                 WHEN 3 THEN 'LINE' 
73335                 WHEN 5 THEN 'LINE' 
73336                 WHEN 6 THEN 'LINE' 
73337                 WHEN 7 THEN 'LINE' 
73338                 WHEN 8 THEN 'LINE' 
73339                 WHEN 9 THEN 'LINE' 
73340                 WHEN 10 THEN 'LINE' 
73341                 
73342                 ELSE null
73343               END                           object_type_code
73344             , CASE r
73345                 WHEN 1 THEN '222' 
73346                 WHEN 2 THEN '222' 
73347                 WHEN 3 THEN '222' 
73348                 WHEN 4 THEN '222' 
73349                 WHEN 5 THEN '222' 
73350                 WHEN 6 THEN '222' 
73351                 WHEN 7 THEN '222' 
73352                 WHEN 8 THEN '222' 
73353                 WHEN 9 THEN '222' 
73354                 WHEN 10 THEN '222' 
73355                 
73356                 ELSE null
73357               END                           source_application_id
73358             , 'S'             source_type_code
73359             , CASE r
73360                 WHEN 1 THEN 'TRX_LINE_DIST_CCID' 
73361                 WHEN 2 THEN 'TRX_LINE_DIST_ACCOUNT_CLASS' 
73362                 WHEN 3 THEN 'TRX_LINE_DIST_ID' 
73363                 WHEN 4 THEN 'TRX_DISTRIBUTION_TYPE' 
73364                 WHEN 5 THEN 'TRX_LINE_DIST_AMT' 
73365                 WHEN 6 THEN 'TRX_LINE_CUR_CONVERSION_DATE' 
73366                 WHEN 7 THEN 'TRX_LINE_CUR_CONVERSION_RATE' 
73367                 WHEN 8 THEN 'TRX_LINE_CUR_CONVERSION_TYPE' 
73368                 WHEN 9 THEN 'TRX_LINE_ACCTD_AMT' 
73369                 WHEN 10 THEN 'TRX_TAX_LINE_ID' 
73370                 
73371                 ELSE null
73372               END                           source_code
73373             , CASE r
73374                 WHEN 1 THEN TO_CHAR(l4.TRX_LINE_DIST_CCID)
73375                 WHEN 2 THEN TO_CHAR(l4.TRX_LINE_DIST_ACCOUNT_CLASS)
73376                 WHEN 3 THEN TO_CHAR(l4.TRX_LINE_DIST_ID)
73377                 WHEN 4 THEN TO_CHAR(l4.TRX_DISTRIBUTION_TYPE)
73378                 WHEN 5 THEN TO_CHAR(l4.TRX_LINE_DIST_AMT)
73379                 WHEN 6 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_DATE)
73380                 WHEN 7 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_RATE)
73381                 WHEN 8 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_TYPE)
73382                 WHEN 9 THEN TO_CHAR(l3.TRX_LINE_ACCTD_AMT)
73383                 WHEN 10 THEN TO_CHAR(l4.TRX_TAX_LINE_ID)
73384                 
73385                 ELSE null
73386               END                           source_value
73387             , null              source_meaning
73388          FROM  xla_events_gt     xet  
73389         , AR_CUST_TRX_LINES_BASE_V  l3
73390         , AR_CUST_TRX_LINES_L_V  l4
73391             , (select rownum r from all_objects where rownum <= 10 and owner = p_apps_owner)
73392         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
73393           AND xet.event_class_code = C_EVENT_CLASS_CODE
73394             AND l3.event_id          = xet.event_id
73395   AND l4.event_id    = l3.event_id
73396   AND l4.line_number = l3.line_number
73397 
73398 )
73399 ;
73400 --
73401 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
73402 
73403       trace
73404          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
73405          ,p_level    => C_LEVEL_STATEMENT
73406          ,p_module   => l_log_module);
73407 
73408 END IF;
73409 
73410 
73411 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
73412       trace
73413          (p_msg      => 'END of insert_sources_139'
73414          ,p_level    => C_LEVEL_PROCEDURE
73415          ,p_module   => l_log_module);
73416 END IF;
73417 EXCEPTION
73418   WHEN xla_exceptions_pkg.application_exception THEN
73419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
73420             trace
73421                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
73422                ,p_level    => C_LEVEL_EXCEPTION
73423                ,p_module   => l_log_module);
73424       END IF;
73425       RAISE;
73426   WHEN OTHERS THEN
73427       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
73428             trace
73429                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
73430                ,p_level    => C_LEVEL_EXCEPTION
73431                ,p_module   => l_log_module);
73432        END IF;
73433        xla_exceptions_pkg.raise_message
73434            (p_location => 'XLA_00222_AAD_S_000006_PKG.insert_sources_139');
73435 END insert_sources_139;
73436 --
73437 
73438 ---------------------------------------
73439 --
73440 -- PRIVATE FUNCTION
73441 --         EventClass_139
73442 --
73443 ----------------------------------------
73444 --
73445 FUNCTION EventClass_139
73446        (p_application_id         IN NUMBER
73447        ,p_base_ledger_id         IN NUMBER
73448        ,p_target_ledger_id       IN NUMBER
73449        ,p_language               IN VARCHAR2
73450        ,p_currency_code          IN VARCHAR2
73451        ,p_sla_ledger_id          IN NUMBER
73452        ,p_pad_start_date         IN DATE
73453        ,p_pad_end_date           IN DATE
73454        ,p_primary_ledger_id      IN NUMBER)
73455 RETURN BOOLEAN IS
73456 --
73457 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'DEBIT_MEMO_ALL';
73461 l_calculate_g_l_flag     VARCHAR2(1) :='N';
73458 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'DEBIT_MEMO';
73459 
73460 l_calculate_acctd_flag   VARCHAR2(1) :='N';
73462 --
73463 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
73464 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
73465 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
73466 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
73467 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
73468 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
73469 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
73470 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
73471 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
73472 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
73473 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
73474 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
73475 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
73476 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
73477 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
73478 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
73479 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
73480 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
73481 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
73482 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
73483 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
73484 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
73485 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
73486 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
73487 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
73488 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
73489 
73490 l_event_id                             NUMBER;
73491 l_previous_event_id                    NUMBER;
73492 l_first_event_id                       NUMBER;
73493 l_last_event_id                        NUMBER;
73494 
73495 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
73496 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
73497 --
73498 --
73499 l_result                    BOOLEAN := TRUE;
73500 l_rows                      NUMBER  := 1000;
73501 l_event_type_name           VARCHAR2(80) := 'All';
73502 l_event_class_name          VARCHAR2(80) := 'Debit Memo';
73503 l_description               VARCHAR2(4000);
73504 l_transaction_reversal      NUMBER;
73505 l_ae_header_id              NUMBER;
73506 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
73507 l_log_module                VARCHAR2(240);
73508 --
73509 l_acct_reversal_source      VARCHAR2(30);
73510 l_trx_reversal_source       VARCHAR2(30);
73511 
73512 l_continue_with_lines       BOOLEAN := TRUE;
73513 --
73514 l_acc_rev_gl_date_source    DATE;                      -- 4262811
73515 --
73516 type t_array_event_id is table of number index by binary_integer;
73517 
73518 l_rec_array_event                    t_rec_array_event;
73519 l_null_rec_array_event               t_rec_array_event;
73520 l_array_ae_header_id                 xla_number_array_type;
73521 l_actual_flag                        VARCHAR2(1) := NULL;
73522 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
73523 l_balance_type_code                  VARCHAR2(1) :=NULL;
73524 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
73525 
73526 --
73527 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
73528 --
73529 
73530 TYPE t_array_source_16 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_RECEIVABLE_CCID%TYPE INDEX BY BINARY_INTEGER;
73531 TYPE t_array_source_30 IS TABLE OF AR_BILL_TO_CUSTOMERS_S_V.BILL_CUST_ACCOUNT_ID%TYPE INDEX BY BINARY_INTEGER;
73532 TYPE t_array_source_31 IS TABLE OF AR_BILL_TO_SITE_USES_S_V.BILL_USES_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
73533 TYPE t_array_source_32 IS TABLE OF AR_TRANSACTIONS_S_V.XLA_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
73534 TYPE t_array_source_37 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_INVOICE_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
73535 TYPE t_array_source_68 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_INVOICING_RULE_ID%TYPE INDEX BY BINARY_INTEGER;
73536 TYPE t_array_source_83 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
73537 TYPE t_array_source_84 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
73538 TYPE t_array_source_85 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
73539 
73540 TYPE t_array_source_4 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
73541 TYPE t_array_source_33 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ACCOUNT_CLASS%TYPE INDEX BY BINARY_INTEGER;
73542 TYPE t_array_source_34 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ID%TYPE INDEX BY BINARY_INTEGER;
73543 TYPE t_array_source_35 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
73544 TYPE t_array_source_36 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_AMT%TYPE INDEX BY BINARY_INTEGER;
73548 TYPE t_array_source_41 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
73545 TYPE t_array_source_38 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
73546 TYPE t_array_source_39 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
73547 TYPE t_array_source_40 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
73549 TYPE t_array_source_55 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_TAX_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
73550 
73551 l_array_source_16              t_array_source_16;
73552 l_array_source_30              t_array_source_30;
73553 l_array_source_31              t_array_source_31;
73554 l_array_source_32              t_array_source_32;
73555 l_array_source_37              t_array_source_37;
73556 l_array_source_68              t_array_source_68;
73557 l_array_source_83              t_array_source_83;
73558 l_array_source_84              t_array_source_84;
73559 l_array_source_85              t_array_source_85;
73560 
73561 l_array_source_4      t_array_source_4;
73562 l_array_source_33      t_array_source_33;
73563 l_array_source_34      t_array_source_34;
73564 l_array_source_35      t_array_source_35;
73565 l_array_source_36      t_array_source_36;
73566 l_array_source_38      t_array_source_38;
73567 l_array_source_39      t_array_source_39;
73568 l_array_source_40      t_array_source_40;
73569 l_array_source_41      t_array_source_41;
73570 l_array_source_55      t_array_source_55;
73571 
73572 --
73573 CURSOR header_cur
73574 IS
73575 SELECT /*+ leading(xet) cardinality(xet,1) */
73576 -- Event Class Code: DEBIT_MEMO
73577     xet.entity_id
73578    ,xet.legal_entity_id
73579    ,xet.entity_code
73580    ,xet.transaction_number
73581    ,xet.event_id
73582    ,xet.event_class_code
73583    ,xet.event_type_code
73584    ,xet.event_number
73585    ,xet.event_date
73586    ,xet.transaction_date
73587    ,xet.reference_num_1
73588    ,xet.reference_num_2
73589    ,xet.reference_num_3
73590    ,xet.reference_num_4
73591    ,xet.reference_char_1
73592    ,xet.reference_char_2
73593    ,xet.reference_char_3
73594    ,xet.reference_char_4
73595    ,xet.reference_date_1
73596    ,xet.reference_date_2
73597    ,xet.reference_date_3
73598    ,xet.reference_date_4
73599    ,xet.event_created_by
73600    ,xet.budgetary_control_flag 
73601   , h5.TRX_RECEIVABLE_CCID    source_16
73602   , h1.BILL_CUST_ACCOUNT_ID    source_30
73603   , h2.BILL_USES_SITE_USE_ID    source_31
73604   , h5.XLA_PARTY_TYPE    source_32
73605   , h5.TRX_INVOICE_CURRENCY_CODE    source_37
73606   , h5.TRX_INVOICING_RULE_ID    source_68
73607   , h5.TRX_DOC_SEQUENCE_CATEGORY    source_83
73608   , h5.TRX_DOC_SEQUENCE_ID    source_84
73609   , h5.TRX_DOC_SEQUENCE_VALUE    source_85
73610   FROM xla_events_gt     xet 
73611   , AR_BILL_TO_CUSTOMERS_S_V  h1
73612   , AR_BILL_TO_SITE_USES_S_V  h2
73613   , AR_TRANSACTIONS_S_V  h5
73614  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
73615    and xet.event_class_code = C_EVENT_CLASS_CODE
73616    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
73617   AND h2.event_id  = h1.event_id
73618   AND h5.event_id  = h1.event_id
73619 
73620  ORDER BY event_id
73621 ;
73622 
73623 
73624 --
73625 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
73626 IS
73627 SELECT  /*+ leading(xet) cardinality(xet,1) */
73628 -- Event Class Code: DEBIT_MEMO
73629     xet.entity_id
73630    ,xet.legal_entity_id
73631    ,xet.entity_code
73632    ,xet.transaction_number
73633    ,xet.event_id
73634    ,xet.event_class_code
73635    ,xet.event_type_code
73636    ,xet.event_number
73637    ,xet.event_date
73638    ,xet.transaction_date
73639    ,xet.reference_num_1
73640    ,xet.reference_num_2
73641    ,xet.reference_num_3
73642    ,xet.reference_num_4
73643    ,xet.reference_char_1
73644    ,xet.reference_char_2
73645    ,xet.reference_char_3
73646    ,xet.reference_char_4
73647    ,xet.reference_date_1
73648    ,xet.reference_date_2
73649    ,xet.reference_date_3
73650    ,xet.reference_date_4
73651    ,xet.event_created_by
73652    ,xet.budgetary_control_flag
73653  , l3.LINE_NUMBER  
73654   , l4.TRX_LINE_DIST_CCID    source_4
73655   , l4.TRX_LINE_DIST_ACCOUNT_CLASS    source_33
73656   , l4.TRX_LINE_DIST_ID    source_34
73657   , l4.TRX_DISTRIBUTION_TYPE    source_35
73658   , l4.TRX_LINE_DIST_AMT    source_36
73659   , l3.TRX_LINE_CUR_CONVERSION_DATE    source_38
73660   , l3.TRX_LINE_CUR_CONVERSION_RATE    source_39
73661   , l3.TRX_LINE_CUR_CONVERSION_TYPE    source_40
73662   , l3.TRX_LINE_ACCTD_AMT    source_41
73663   , l4.TRX_TAX_LINE_ID    source_55
73664   FROM xla_events_gt     xet 
73665   , AR_CUST_TRX_LINES_BASE_V  l3
73666   , AR_CUST_TRX_LINES_L_V  l4
73667  WHERE xet.event_id between x_first_event_id and x_last_event_id
73668    and xet.event_date between p_pad_start_date and p_pad_end_date
73669    and xet.event_class_code = C_EVENT_CLASS_CODE
73670    and xet.event_status_code <> 'N'   AND l3.event_id      = xet.event_id
73671   AND l4.event_id    = l3.event_id
73672   AND l4.line_number = l3.line_number
73673 ;
73674 
73675 --
73676 BEGIN
73677 IF g_log_enabled THEN
73678    l_log_module := C_DEFAULT_MODULE||'.EventClass_139';
73679 END IF;
73683       ,p_level    => C_LEVEL_PROCEDURE
73680 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
73681    trace
73682       (p_msg      => 'BEGIN of EventClass_139'
73684       ,p_module   => l_log_module);
73685 END IF;
73686 
73687 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
73688    trace
73689       (p_msg      => 'p_application_id = '||p_application_id||
73690                      ' - p_base_ledger_id = '||p_base_ledger_id||
73691                      ' - p_target_ledger_id  = '||p_target_ledger_id||
73692                      ' - p_language = '||p_language||
73693                      ' - p_currency_code = '||p_currency_code||
73694                      ' - p_sla_ledger_id = '||p_sla_ledger_id
73695       ,p_level    => C_LEVEL_STATEMENT
73696       ,p_module   => l_log_module);
73697 END IF;
73698 --
73699 -- initialze arrays
73700 --
73701 g_array_event.DELETE;
73702 l_rec_array_event := l_null_rec_array_event;
73703 --
73704 --------------------------------------
73705 -- 4262811 Initialze MPA Line Number
73706 --------------------------------------
73707 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
73708 
73709 --
73710 
73711 --
73712 OPEN header_cur;
73713 --
73714 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
73715    trace
73716    (p_msg      => 'SQL - FETCH header_cur'
73717    ,p_level    => C_LEVEL_STATEMENT
73718    ,p_module   => l_log_module);
73719 END IF;
73720 --
73721 LOOP
73722 FETCH header_cur BULK COLLECT INTO
73723         l_array_entity_id
73724       , l_array_legal_entity_id
73725       , l_array_entity_code
73726       , l_array_transaction_num
73727       , l_array_event_id
73728       , l_array_class_code
73729       , l_array_event_type
73730       , l_array_event_number
73731       , l_array_event_date
73732       , l_array_transaction_date
73733       , l_array_reference_num_1
73734       , l_array_reference_num_2
73735       , l_array_reference_num_3
73736       , l_array_reference_num_4
73737       , l_array_reference_char_1
73738       , l_array_reference_char_2
73739       , l_array_reference_char_3
73740       , l_array_reference_char_4
73741       , l_array_reference_date_1
73742       , l_array_reference_date_2
73743       , l_array_reference_date_3
73744       , l_array_reference_date_4
73745       , l_array_event_created_by
73746       , l_array_budgetary_control_flag 
73747       , l_array_source_16
73748       , l_array_source_30
73749       , l_array_source_31
73750       , l_array_source_32
73751       , l_array_source_37
73752       , l_array_source_68
73753       , l_array_source_83
73754       , l_array_source_84
73755       , l_array_source_85
73756       LIMIT l_rows;
73757 --
73758 IF (C_LEVEL_EVENT >= g_log_level) THEN
73759    trace
73760    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
73761    ,p_level    => C_LEVEL_EVENT
73762    ,p_module   => l_log_module);
73763 END IF;
73764 --
73765 EXIT WHEN l_array_entity_id.COUNT = 0;
73766 
73767 -- initialize arrays
73768 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
73769 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
73770 
73771 --
73772 -- Bug 4458708
73773 --
73774 XLA_AE_LINES_PKG.g_LineNumber := 0;
73775 
73776 
73777 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
73778 g_last_hdr_idx := l_array_event_id.LAST;
73779 --
73780 -- loop for the headers. Each iteration is for each header extract row
73781 -- fetched in header cursor
73782 --
73783 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
73784 
73785 --
73786 -- set event info as cache for other routines to refer event attributes
73787 --
73788 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
73789    (p_application_id           => p_application_id
73790    ,p_primary_ledger_id        => p_primary_ledger_id
73791    ,p_base_ledger_id           => p_base_ledger_id
73792    ,p_target_ledger_id         => p_target_ledger_id
73793    ,p_entity_id                => l_array_entity_id(hdr_idx)
73794    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
73795    ,p_entity_code              => l_array_entity_code(hdr_idx)
73796    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
73797    ,p_event_id                 => l_array_event_id(hdr_idx)
73798    ,p_event_class_code         => l_array_class_code(hdr_idx)
73799    ,p_event_type_code          => l_array_event_type(hdr_idx)
73800    ,p_event_number             => l_array_event_number(hdr_idx)
73801    ,p_event_date               => l_array_event_date(hdr_idx)
73802    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
73803    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
73804    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
73805    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
73806    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
73807    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
73808    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
73809    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
73810    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
73811    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
73815    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
73812    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
73813    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
73814    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
73816    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
73817 
73818 --
73819 -- set the status of entry to C_VALID (0)
73820 --
73821 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
73822 
73823 --
73824 -- initialize a row for ae header
73825 --
73826 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
73827 
73828 l_event_id := l_array_event_id(hdr_idx);
73829 
73830 --
73831 -- storing the hdr_idx for event. May be used by line cursor.
73832 --
73833 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
73834 
73835 --
73836 -- store sources from header extract. This can be improved to
73837 -- store only those sources from header extract that may be used in lines
73838 --
73839 
73840 g_array_event(l_event_id).array_value_num('source_16') := l_array_source_16(hdr_idx);
73841 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
73842 g_array_event(l_event_id).array_value_num('source_31') := l_array_source_31(hdr_idx);
73843 g_array_event(l_event_id).array_value_char('source_32') := l_array_source_32(hdr_idx);
73844 g_array_event(l_event_id).array_value_char('source_37') := l_array_source_37(hdr_idx);
73845 g_array_event(l_event_id).array_value_num('source_68') := l_array_source_68(hdr_idx);
73846 g_array_event(l_event_id).array_value_char('source_83') := l_array_source_83(hdr_idx);
73847 g_array_event(l_event_id).array_value_num('source_84') := l_array_source_84(hdr_idx);
73848 g_array_event(l_event_id).array_value_num('source_85') := l_array_source_85(hdr_idx);
73849 
73850 --
73851 -- initilaize the status of ae headers for diffrent balance types
73852 -- the status is initialised to C_NOT_CREATED (2)
73853 --
73854 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
73855 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
73856 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
73857 
73858 --
73859 -- call api to validate and store accounting attributes for header
73860 --
73861 
73862 ------------------------------------------------------------
73863 -- Accrual Reversal : to get date for Standard Source (NONE)
73864 ------------------------------------------------------------
73865 l_acc_rev_gl_date_source := NULL;
73866 
73867      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
73868       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_83');
73869      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
73870       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_84');
73871      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
73872       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_85');
73873      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
73874       l_rec_acct_attrs.array_date_value(4) := 
73875 xla_ae_sources_pkg.GetSystemSourceDate(
73876    p_source_code           => 'XLA_EVENT_DATE'
73877  , p_source_type_code      => 'Y'
73878  , p_source_application_id =>  602
73879 );
73880 
73881 
73882 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
73883 
73884 XLA_AE_HEADER_PKG.SetJeCategoryName;
73885 
73886 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
73887 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
73888 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
73889 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
73890 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
73891 
73892 
73893 -- No header level analytical criteria
73894 
73895 --
73896 --accounting attribute enhancement, bug 3612931
73897 --
73898 l_trx_reversal_source := SUBSTR(NULL, 1,30);
73899 
73900 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
73901    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
73902 
73903    xla_accounting_err_pkg.build_message
73904       (p_appli_s_name            => 'XLA'
73905       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
73906       ,p_token_1                 => 'ACCT_ATTR_NAME'
73907       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
73908       ,p_token_2                 => 'PRODUCT_NAME'
73909       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
73910       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
73911       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
73912       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
73913 
73914 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
73915    --
73916    -- following sets the accounting attributes needed to reverse
73917    -- accounting for a distributeion
73918    --
73922       ,p_trx_reversal_source   => l_trx_reversal_source);
73919    xla_ae_lines_pkg.SetTrxReversalAttrs
73920       (p_event_id              => l_event_id
73921       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
73923 
73924 END IF;
73925 
73926 
73927 ----------------------------------------------------------------
73928 -- 4262811 -  update the header statuses to invalid in need be
73929 ----------------------------------------------------------------
73930 --
73931 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
73932 
73933 
73934   -----------------------------------------------
73935   -- No accrual reversal for the event class/type
73936   -----------------------------------------------
73937 ----------------------------------------------------------------
73938 
73939 --
73940 -- this ends the header loop iteration for one bulk fetch
73941 --
73942 END LOOP;
73943 
73944 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
73945 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
73946 
73947 --
73948 -- insert dummy rows into lines gt table that were created due to
73949 -- transaction reversals
73950 --
73951 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
73952    l_result := XLA_AE_LINES_PKG.InsertLines;
73953 END IF;
73954 
73955 --
73956 -- reset the temp_line_num for each set of events fetched from header
73957 -- cursor rather than doing it for each new event in line cursor
73958 -- Bug 3939231
73959 --
73960 xla_ae_lines_pkg.g_temp_line_num := 0;
73961 
73962 
73963 
73964 --
73965 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
73966 --
73967 --
73968 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
73969 
73970       trace
73971          (p_msg      => 'SQL - FETCH line_cur'
73972          ,p_level    => C_LEVEL_STATEMENT
73973          ,p_module   => l_log_module);
73974 
73975 END IF;
73976 --
73977 --
73978 LOOP
73979   --
73980   FETCH line_cur BULK COLLECT INTO
73981         l_array_entity_id
73982       , l_array_legal_entity_id
73983       , l_array_entity_code
73984       , l_array_transaction_num
73985       , l_array_event_id
73986       , l_array_class_code
73987       , l_array_event_type
73988       , l_array_event_number
73989       , l_array_event_date
73990       , l_array_transaction_date
73991       , l_array_reference_num_1
73992       , l_array_reference_num_2
73993       , l_array_reference_num_3
73994       , l_array_reference_num_4
73995       , l_array_reference_char_1
73996       , l_array_reference_char_2
73997       , l_array_reference_char_3
73998       , l_array_reference_char_4
73999       , l_array_reference_date_1
74000       , l_array_reference_date_2
74001       , l_array_reference_date_3
74002       , l_array_reference_date_4
74003       , l_array_event_created_by
74004       , l_array_budgetary_control_flag
74005       , l_array_extract_line_num 
74006       , l_array_source_4
74007       , l_array_source_33
74008       , l_array_source_34
74009       , l_array_source_35
74010       , l_array_source_36
74011       , l_array_source_38
74012       , l_array_source_39
74013       , l_array_source_40
74014       , l_array_source_41
74015       , l_array_source_55
74016       LIMIT l_rows;
74017 
74018   --
74019   IF (C_LEVEL_EVENT >= g_log_level) THEN
74020             trace
74021                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
74022                ,p_level    => C_LEVEL_EVENT
74023                ,p_module   => l_log_module);
74024   END IF;
74025   --
74026   EXIT WHEN l_array_entity_id.count = 0;
74027 
74028   XLA_AE_LINES_PKG.g_rec_lines := null;
74029 
74030 --
74031 -- Bug 4458708
74032 --
74033 XLA_AE_LINES_PKG.g_LineNumber := 0;
74034 --
74035 --
74036 
74037 FOR Idx IN 1..l_array_event_id.count LOOP
74038    --
74039    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
74040    --
74041    l_event_id := l_array_event_id(idx);  -- 5648433
74042 
74043    --
74044    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
74045    --
74046 
74047    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
74048              (g_array_event(l_event_id).array_value_num('header_index'))
74049          ,'N'
74050          ) <> 'Y'
74051    THEN
74052       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
74053          trace
74054             (p_msg      => 'Trancaction revesal option is not Y '
74055             ,p_level    => C_LEVEL_STATEMENT
74056             ,p_module   => l_log_module);
74057       END IF;
74058 
74059 --
74060 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
74061 --
74062 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
74063 --
74064 -- set event info as cache for other routines to refer event attributes
74065 --
74066 
74067 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
74068    l_previous_event_id := l_event_id;
74069 
74070    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
74071       (p_application_id           => p_application_id
74072       ,p_primary_ledger_id        => p_primary_ledger_id
74073       ,p_base_ledger_id           => p_base_ledger_id
74074       ,p_target_ledger_id         => p_target_ledger_id
74075       ,p_entity_id                => l_array_entity_id(Idx)
74076       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
74077       ,p_entity_code              => l_array_entity_code(Idx)
74078       ,p_transaction_num          => l_array_transaction_num(Idx)
74079       ,p_event_id                 => l_array_event_id(Idx)
74080       ,p_event_class_code         => l_array_class_code(Idx)
74081       ,p_event_type_code          => l_array_event_type(Idx)
74082       ,p_event_number             => l_array_event_number(Idx)
74083       ,p_event_date               => l_array_event_date(Idx)
74084       ,p_transaction_date         => l_array_transaction_date(Idx)
74085       ,p_reference_num_1          => l_array_reference_num_1(Idx)
74086       ,p_reference_num_2          => l_array_reference_num_2(Idx)
74087       ,p_reference_num_3          => l_array_reference_num_3(Idx)
74088       ,p_reference_num_4          => l_array_reference_num_4(Idx)
74089       ,p_reference_char_1         => l_array_reference_char_1(Idx)
74090       ,p_reference_char_2         => l_array_reference_char_2(Idx)
74091       ,p_reference_char_3         => l_array_reference_char_3(Idx)
74092       ,p_reference_char_4         => l_array_reference_char_4(Idx)
74093       ,p_reference_date_1         => l_array_reference_date_1(Idx)
74094       ,p_reference_date_2         => l_array_reference_date_2(Idx)
74095       ,p_reference_date_3         => l_array_reference_date_3(Idx)
74096       ,p_reference_date_4         => l_array_reference_date_4(Idx)
74097       ,p_event_created_by         => l_array_event_created_by(Idx)
74098       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
74099        --
74100 END IF;
74101 
74102 
74103 
74104 --
74105 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
74106 
74107 l_acct_reversal_source := SUBSTR(NULL, 1,30);
74108 
74112 
74109 IF l_continue_with_lines THEN
74110    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
74111       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
74113       xla_accounting_err_pkg.build_message
74114          (p_appli_s_name            => 'XLA'
74115          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
74116          ,p_token_1                 => 'LINE_NUMBER'
74117          ,p_value_1                 => l_array_extract_line_num(Idx)
74118          ,p_token_2                 => 'PRODUCT_NAME'
74119          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
74120          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
74121          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
74122          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
74123 
74124    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
74125       --
74126       -- following sets the accounting attributes needed to reverse
74127       -- accounting for a distributeion
74128       --
74129 
74130       --
74131       -- 5217187
74132       --
74133       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
74134       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
74135                                        g_array_event(l_event_id).array_value_num('header_index'));
74136       --
74137       --
74138 
74139       -- No reversal code generated
74140 
74141       xla_ae_lines_pkg.SetAcctReversalAttrs
74142          (p_event_id             => l_event_id
74143          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
74144          ,p_calculate_acctd_flag => l_calculate_acctd_flag
74145          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
74146    END IF;
74147 
74148    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
74149        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
74150 
74151 --
74152 AcctLineType_52 (
74153  p_application_id  => p_application_id
74154  ,p_event_id     => l_event_id
74155  ,p_calculate_acctd_flag => l_calculate_acctd_flag
74156  ,p_calculate_g_l_flag => l_calculate_g_l_flag
74157  ,p_actual_flag => l_actual_flag
74158  ,p_balance_type_code => l_balance_type_code
74159  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
74160  
74161  , p_source_4 => l_array_source_4(Idx)
74162  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
74163  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
74164  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
74165  , p_source_33 => l_array_source_33(Idx)
74166  , p_source_34 => l_array_source_34(Idx)
74167  , p_source_35 => l_array_source_35(Idx)
74168  , p_source_36 => l_array_source_36(Idx)
74169  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
74170  , p_source_38 => l_array_source_38(Idx)
74171  , p_source_39 => l_array_source_39(Idx)
74172  , p_source_40 => l_array_source_40(Idx)
74173  , p_source_41 => l_array_source_41(Idx)
74174  , p_source_55 => l_array_source_55(Idx)
74175  );
74176 If(l_balance_type_code = 'A') THEN
74177   l_actual_gain_loss_ref := l_gain_or_loss_ref;
74178 END IF;
74179 
74180 --
74181 
74182 
74183 --
74184 AcctLineType_53 (
74185  p_application_id  => p_application_id
74186  ,p_event_id     => l_event_id
74187  ,p_calculate_acctd_flag => l_calculate_acctd_flag
74188  ,p_calculate_g_l_flag => l_calculate_g_l_flag
74189  ,p_actual_flag => l_actual_flag
74190  ,p_balance_type_code => l_balance_type_code
74191  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
74192  
74193  , p_source_4 => l_array_source_4(Idx)
74194  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
74195  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
74196  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
74197  , p_source_33 => l_array_source_33(Idx)
74198  , p_source_34 => l_array_source_34(Idx)
74199  , p_source_35 => l_array_source_35(Idx)
74200  , p_source_36 => l_array_source_36(Idx)
74201  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
74202  , p_source_38 => l_array_source_38(Idx)
74203  , p_source_39 => l_array_source_39(Idx)
74204  , p_source_40 => l_array_source_40(Idx)
74205  , p_source_41 => l_array_source_41(Idx)
74206  , p_source_55 => l_array_source_55(Idx)
74207  );
74208 If(l_balance_type_code = 'A') THEN
74209   l_actual_gain_loss_ref := l_gain_or_loss_ref;
74210 END IF;
74211 
74212 --
74213 
74214 
74215 --
74216 AcctLineType_54 (
74217  p_application_id  => p_application_id
74218  ,p_event_id     => l_event_id
74219  ,p_calculate_acctd_flag => l_calculate_acctd_flag
74220  ,p_calculate_g_l_flag => l_calculate_g_l_flag
74221  ,p_actual_flag => l_actual_flag
74222  ,p_balance_type_code => l_balance_type_code
74223  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
74224  
74225  , p_source_4 => l_array_source_4(Idx)
74226  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
74227  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
74228  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
74229  , p_source_33 => l_array_source_33(Idx)
74230  , p_source_34 => l_array_source_34(Idx)
74231  , p_source_35 => l_array_source_35(Idx)
74232  , p_source_36 => l_array_source_36(Idx)
74233  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
74234  , p_source_38 => l_array_source_38(Idx)
74235  , p_source_39 => l_array_source_39(Idx)
74236  , p_source_40 => l_array_source_40(Idx)
74237  , p_source_41 => l_array_source_41(Idx)
74238  , p_source_55 => l_array_source_55(Idx)
74239  );
74240 If(l_balance_type_code = 'A') THEN
74241   l_actual_gain_loss_ref := l_gain_or_loss_ref;
74245 
74242 END IF;
74243 
74244 --
74246 
74247 --
74248 AcctLineType_55 (
74249  p_application_id  => p_application_id
74250  ,p_event_id     => l_event_id
74251  ,p_calculate_acctd_flag => l_calculate_acctd_flag
74252  ,p_calculate_g_l_flag => l_calculate_g_l_flag
74253  ,p_actual_flag => l_actual_flag
74254  ,p_balance_type_code => l_balance_type_code
74255  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
74256  
74257  , p_source_4 => l_array_source_4(Idx)
74258  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
74259  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
74260  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
74261  , p_source_33 => l_array_source_33(Idx)
74262  , p_source_34 => l_array_source_34(Idx)
74263  , p_source_35 => l_array_source_35(Idx)
74264  , p_source_36 => l_array_source_36(Idx)
74265  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
74266  , p_source_38 => l_array_source_38(Idx)
74267  , p_source_39 => l_array_source_39(Idx)
74268  , p_source_40 => l_array_source_40(Idx)
74269  , p_source_41 => l_array_source_41(Idx)
74270  , p_source_55 => l_array_source_55(Idx)
74271  );
74272 If(l_balance_type_code = 'A') THEN
74273   l_actual_gain_loss_ref := l_gain_or_loss_ref;
74274 END IF;
74275 
74276 --
74277 
74278 
74279 --
74280 AcctLineType_56 (
74281  p_application_id  => p_application_id
74282  ,p_event_id     => l_event_id
74283  ,p_calculate_acctd_flag => l_calculate_acctd_flag
74284  ,p_calculate_g_l_flag => l_calculate_g_l_flag
74285  ,p_actual_flag => l_actual_flag
74286  ,p_balance_type_code => l_balance_type_code
74287  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
74288  
74289  , p_source_4 => l_array_source_4(Idx)
74290  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
74291  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
74292  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
74293  , p_source_33 => l_array_source_33(Idx)
74294  , p_source_34 => l_array_source_34(Idx)
74295  , p_source_35 => l_array_source_35(Idx)
74296  , p_source_36 => l_array_source_36(Idx)
74297  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
74298  , p_source_38 => l_array_source_38(Idx)
74299  , p_source_39 => l_array_source_39(Idx)
74300  , p_source_40 => l_array_source_40(Idx)
74301  , p_source_41 => l_array_source_41(Idx)
74302  , p_source_55 => l_array_source_55(Idx)
74303  );
74304 If(l_balance_type_code = 'A') THEN
74305   l_actual_gain_loss_ref := l_gain_or_loss_ref;
74306 END IF;
74307 
74308 --
74309 
74310 
74311 --
74312 AcctLineType_57 (
74313  p_application_id  => p_application_id
74314  ,p_event_id     => l_event_id
74315  ,p_calculate_acctd_flag => l_calculate_acctd_flag
74316  ,p_calculate_g_l_flag => l_calculate_g_l_flag
74317  ,p_actual_flag => l_actual_flag
74318  ,p_balance_type_code => l_balance_type_code
74319  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
74320  
74321  , p_source_4 => l_array_source_4(Idx)
74322  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
74323  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
74324  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
74325  , p_source_33 => l_array_source_33(Idx)
74326  , p_source_34 => l_array_source_34(Idx)
74327  , p_source_35 => l_array_source_35(Idx)
74328  , p_source_36 => l_array_source_36(Idx)
74329  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
74330  , p_source_38 => l_array_source_38(Idx)
74331  , p_source_39 => l_array_source_39(Idx)
74332  , p_source_40 => l_array_source_40(Idx)
74333  , p_source_41 => l_array_source_41(Idx)
74334  , p_source_55 => l_array_source_55(Idx)
74335  );
74336 If(l_balance_type_code = 'A') THEN
74337   l_actual_gain_loss_ref := l_gain_or_loss_ref;
74338 END IF;
74339 
74340 --
74341 
74342 
74343 --
74344 AcctLineType_58 (
74345  p_application_id  => p_application_id
74346  ,p_event_id     => l_event_id
74347  ,p_calculate_acctd_flag => l_calculate_acctd_flag
74348  ,p_calculate_g_l_flag => l_calculate_g_l_flag
74349  ,p_actual_flag => l_actual_flag
74350  ,p_balance_type_code => l_balance_type_code
74351  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
74352  
74353  , p_source_4 => l_array_source_4(Idx)
74354  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
74355  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
74356  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
74357  , p_source_33 => l_array_source_33(Idx)
74358  , p_source_34 => l_array_source_34(Idx)
74359  , p_source_35 => l_array_source_35(Idx)
74360  , p_source_36 => l_array_source_36(Idx)
74361  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
74362  , p_source_38 => l_array_source_38(Idx)
74363  , p_source_39 => l_array_source_39(Idx)
74364  , p_source_40 => l_array_source_40(Idx)
74365  , p_source_41 => l_array_source_41(Idx)
74366  , p_source_55 => l_array_source_55(Idx)
74367  );
74368 If(l_balance_type_code = 'A') THEN
74369   l_actual_gain_loss_ref := l_gain_or_loss_ref;
74370 END IF;
74371 
74372 --
74373 
74374 
74375 --
74376 AcctLineType_88 (
74377  p_application_id  => p_application_id
74378  ,p_event_id     => l_event_id
74379  ,p_calculate_acctd_flag => l_calculate_acctd_flag
74380  ,p_calculate_g_l_flag => l_calculate_g_l_flag
74381  ,p_actual_flag => l_actual_flag
74382  ,p_balance_type_code => l_balance_type_code
74383  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
74384  
74385  , p_source_4 => l_array_source_4(Idx)
74386  , p_source_16 => g_array_event(l_event_id).array_value_num('source_16')
74390  , p_source_33 => l_array_source_33(Idx)
74387  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
74388  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
74389  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
74391  , p_source_34 => l_array_source_34(Idx)
74392  , p_source_35 => l_array_source_35(Idx)
74393  , p_source_36 => l_array_source_36(Idx)
74394  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
74395  , p_source_38 => l_array_source_38(Idx)
74396  , p_source_39 => l_array_source_39(Idx)
74397  , p_source_40 => l_array_source_40(Idx)
74398  , p_source_41 => l_array_source_41(Idx)
74399  , p_source_55 => l_array_source_55(Idx)
74400  , p_source_68 => g_array_event(l_event_id).array_value_num('source_68')
74401  );
74402 If(l_balance_type_code = 'A') THEN
74403   l_actual_gain_loss_ref := l_gain_or_loss_ref;
74404 END IF;
74405 
74406 --
74407 
74408       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
74409       -- or secondary ledger that has different currency with primary
74410       -- or alc that is calculated by sla
74411       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
74412             (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'))
74413 
74414 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
74415 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
74416           AND (l_actual_flag = 'A')) THEN
74417         XLA_AE_LINES_PKG.CreateGainOrLossLines(
74418           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
74419          ,p_application_id   => p_application_id
74420          ,p_amb_context_code => 'DEFAULT'
74421          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
74422          ,p_event_class_code => C_EVENT_CLASS_CODE
74423          ,p_event_type_code  => C_EVENT_TYPE_CODE
74424          
74425          ,p_gain_ccid        => -1
74426          ,p_loss_ccid        => -1
74427 
74428          ,p_actual_flag      => l_actual_flag
74429          ,p_enc_flag         => null
74430          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
74431          ,p_enc_g_l_ref      => null
74432          );
74433       END IF;
74434    END IF;
74435 END IF;
74436 
74437    ELSE
74438       --
74439       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
74440       --
74441       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
74442          trace
74443             (p_msg      => 'Trancaction revesal option is Y'
74444             ,p_level    => C_LEVEL_STATEMENT
74445             ,p_module   => l_log_module);
74446       END IF;
74447    END IF;
74448 
74449 END LOOP;
74450 l_result := XLA_AE_LINES_PKG.InsertLines ;
74451 end loop;
74452 close line_cur;
74453 
74454 
74455 --
74456 -- insert headers into xla_ae_headers_gt table
74457 --
74458 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
74459 
74460 -- insert into errors table here.
74461 
74462 END LOOP;
74463 
74464 --
74465 -- 4865292
74466 --
74467 -- Compare g_hdr_extract_count with event count in
74468 -- CreateHeadersAndLines.
74469 --
74470 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
74471 
74472 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
74473    trace (p_msg     => '# rows extracted from header extract objects '
74474                     || ' (running total): '
74475                     || g_hdr_extract_count
74476          ,p_level   => C_LEVEL_STATEMENT
74477          ,p_module  => l_log_module);
74478 END IF;
74479 
74480 CLOSE header_cur;
74481 --
74482 
74483 --
74484 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
74485    trace
74486       (p_msg      => 'END of EventClass_139'
74487       ,p_level    => C_LEVEL_PROCEDURE
74488       ,p_module   => l_log_module);
74489 END IF;
74490 --
74491 RETURN l_result;
74492 EXCEPTION
74493 WHEN xla_exceptions_pkg.application_exception THEN
74494    
74495 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
74496 
74497    
74498 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
74499 
74500    RAISE;
74501 
74502 WHEN NO_DATA_FOUND THEN
74503 
74504 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
74505 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
74506 
74507 FOR header_record IN header_cur
74508 LOOP
74509     l_array_header_events(header_record.event_id) := header_record.event_id;
74510 END LOOP;
74511 
74512 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
74513 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
74514 
74515 fnd_file.put_line(fnd_file.LOG, '                    ');
74516 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
74517 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
74518 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
74519 
74520 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
74521 LOOP
74522 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
74523 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
74524         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
74525 	END IF;
74526 END LOOP;
74527 
74528 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
74532 xla_exceptions_pkg.raise_message
74529 fnd_file.put_line(fnd_file.LOG, '                    ');
74530 
74531 
74533       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_139');
74534 
74535 
74536 WHEN OTHERS THEN
74537    xla_exceptions_pkg.raise_message
74538       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_139');
74539 END EventClass_139;
74540 --
74541 
74542 ---------------------------------------
74543 --
74544 -- PRIVATE PROCEDURE
74545 --         insert_sources_140
74546 --
74547 ----------------------------------------
74548 --
74549 PROCEDURE insert_sources_140(
74550                                 p_target_ledger_id       IN NUMBER
74551                               , p_language               IN VARCHAR2
74552                               , p_sla_ledger_id          IN NUMBER
74553                               , p_pad_start_date         IN DATE
74554                               , p_pad_end_date           IN DATE
74555                          )
74556 IS
74557 
74558 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'DEPOSIT_ALL';
74559 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'DEPOSIT';
74560 p_apps_owner                   VARCHAR2(30);
74561 l_log_module                   VARCHAR2(240);
74562 BEGIN
74563 IF g_log_enabled THEN
74564       l_log_module := C_DEFAULT_MODULE||'.insert_sources_140';
74565 END IF;
74566 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
74567 
74568       trace
74569          (p_msg      => 'BEGIN of insert_sources_140'
74570          ,p_level    => C_LEVEL_PROCEDURE
74571          ,p_module   => l_log_module);
74572 
74573 END IF;
74574 
74575 -- select APPS owner
74576 SELECT oracle_username
74577   INTO p_apps_owner
74578   FROM fnd_oracle_userid
74579  WHERE read_only_flag = 'U'
74580 ;
74581 
74582 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
74583       trace
74584          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
74585                         ' - p_language = '||p_language||
74586                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
74587                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
74588                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
74589                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
74590          ,p_level    => C_LEVEL_STATEMENT
74591          ,p_module   => l_log_module);
74592 END IF;
74593 
74594 
74595 --
74596 INSERT INTO xla_diag_sources --hdr2
74597 (
74598         event_id
74599       , ledger_id
74600       , sla_ledger_id
74601       , description_language
74602       , object_name
74603       , object_type_code
74604       , line_number
74605       , source_application_id
74606       , source_type_code
74607       , source_code
74608       , source_value
74609       , source_meaning
74610       , created_by
74611       , creation_date
74612       , last_update_date
74613       , last_updated_by
74614       , last_update_login
74615       , program_update_date
74616       , program_application_id
74617       , program_id
74618       , request_id
74619 )
74620 SELECT
74621         event_id
74622       , p_target_ledger_id
74623       , p_sla_ledger_id
74624       , p_language
74625       , object_name
74626       , object_type_code
74627       , line_number
74628       , source_application_id
74629       , source_type_code
74630       , source_code
74631       , SUBSTR(source_value ,1,1996)
74632       , SUBSTR(source_meaning ,1,200)
74633       , xla_environment_pkg.g_Usr_Id
74634       , TRUNC(SYSDATE)
74635       , TRUNC(SYSDATE)
74636       , xla_environment_pkg.g_Usr_Id
74637       , xla_environment_pkg.g_Login_Id
74638       , TRUNC(SYSDATE)
74639       , xla_environment_pkg.g_Prog_Appl_Id
74640       , xla_environment_pkg.g_Prog_Id
74641       , xla_environment_pkg.g_Req_Id
74642   FROM (
74643        SELECT xet.event_id                  event_id
74644             , 0                          line_number
74645             , CASE r
74646                WHEN 1 THEN 'AR_BILL_TO_CUSTOMERS_S_V' 
74647                 WHEN 2 THEN 'AR_BILL_TO_SITE_USES_S_V' 
74648                 WHEN 3 THEN 'AR_TRANSACTIONS_S_V' 
74649                 WHEN 4 THEN 'AR_TRANSACTIONS_S_V' 
74650                 WHEN 5 THEN 'AR_TRANSACTIONS_S_V' 
74651                 WHEN 6 THEN 'AR_TRANSACTIONS_S_V' 
74652                 WHEN 7 THEN 'AR_TRANSACTIONS_S_V' 
74653                 
74654                ELSE null
74655               END                           object_name
74656             , CASE r
74657                 WHEN 1 THEN 'HEADER' 
74658                 WHEN 2 THEN 'HEADER' 
74659                 WHEN 3 THEN 'HEADER' 
74660                 WHEN 4 THEN 'HEADER' 
74661                 WHEN 5 THEN 'HEADER' 
74662                 WHEN 6 THEN 'HEADER' 
74663                 WHEN 7 THEN 'HEADER' 
74664                 
74665                 ELSE null
74666               END                           object_type_code
74667             , CASE r
74668                 WHEN 1 THEN '222' 
74669                 WHEN 2 THEN '222' 
74670                 WHEN 3 THEN '222' 
74671                 WHEN 4 THEN '222' 
74672                 WHEN 5 THEN '222' 
74673                 WHEN 6 THEN '222' 
74674                 WHEN 7 THEN '222' 
74675                 
74676                 ELSE null
74677               END                           source_application_id
74678             , 'S'             source_type_code
74679             , CASE r
74680                 WHEN 1 THEN 'BILL_CUST_ACCOUNT_ID' 
74681                 WHEN 2 THEN 'BILL_USES_SITE_USE_ID' 
74682                 WHEN 3 THEN 'XLA_PARTY_TYPE' 
74683                 WHEN 4 THEN 'TRX_INVOICE_CURRENCY_CODE' 
74687                 
74684                 WHEN 5 THEN 'TRX_DOC_SEQUENCE_CATEGORY' 
74685                 WHEN 6 THEN 'TRX_DOC_SEQUENCE_ID' 
74686                 WHEN 7 THEN 'TRX_DOC_SEQUENCE_VALUE' 
74688                 ELSE null
74689               END                           source_code
74690             , CASE r
74691                 WHEN 1 THEN TO_CHAR(h1.BILL_CUST_ACCOUNT_ID)
74692                 WHEN 2 THEN TO_CHAR(h2.BILL_USES_SITE_USE_ID)
74693                 WHEN 3 THEN TO_CHAR(h5.XLA_PARTY_TYPE)
74694                 WHEN 4 THEN TO_CHAR(h5.TRX_INVOICE_CURRENCY_CODE)
74695                 WHEN 5 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_CATEGORY)
74696                 WHEN 6 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_ID)
74697                 WHEN 7 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_VALUE)
74698                 
74699                 ELSE null
74700               END                           source_value
74701             , null              source_meaning
74702          FROM xla_events_gt     xet  
74703       , AR_BILL_TO_CUSTOMERS_S_V  h1
74704       , AR_BILL_TO_SITE_USES_S_V  h2
74705       , AR_TRANSACTIONS_S_V  h5
74706              ,(select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
74707          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
74708            AND xet.event_class_code = C_EVENT_CLASS_CODE
74709               AND h1.event_id = xet.event_id
74710   AND h2.event_id  = h1.event_id
74711   AND h5.event_id  = h1.event_id
74712 
74713 )
74714 ;
74715 --
74716 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
74717 
74718       trace
74719          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
74720          ,p_level    => C_LEVEL_STATEMENT
74721          ,p_module   => l_log_module);
74722 
74723 END IF;
74724 --
74725 
74726 
74727 
74728 --
74729 INSERT INTO xla_diag_sources  --line2
74730 (
74731         event_id
74732       , ledger_id
74733       , sla_ledger_id
74734       , description_language
74735       , object_name
74736       , object_type_code
74737       , line_number
74738       , source_application_id
74739       , source_type_code
74740       , source_code
74741       , source_value
74742       , source_meaning
74743       , created_by
74744       , creation_date
74745       , last_update_date
74746       , last_updated_by
74747       , last_update_login
74748       , program_update_date
74749       , program_application_id
74750       , program_id
74751       , request_id
74752 )
74753 SELECT  event_id
74754       , p_target_ledger_id
74755       , p_sla_ledger_id
74756       , p_language
74757       , object_name
74758       , object_type_code
74759       , line_number
74760       , source_application_id
74761       , source_type_code
74762       , source_code
74763       , SUBSTR(source_value,1,1996)
74764       , SUBSTR(source_meaning ,1,200)
74765       , xla_environment_pkg.g_Usr_Id
74766       , TRUNC(SYSDATE)
74767       , TRUNC(SYSDATE)
74768       , xla_environment_pkg.g_Usr_Id
74769       , xla_environment_pkg.g_Login_Id
74770       , TRUNC(SYSDATE)
74771       , xla_environment_pkg.g_Prog_Appl_Id
74772       , xla_environment_pkg.g_Prog_Id
74773       , xla_environment_pkg.g_Req_Id
74774   FROM (
74775        SELECT xet.event_id                  event_id
74776             , l4.line_number                 line_number
74777             , CASE r
74778                WHEN 1 THEN 'AR_CUST_TRX_LINES_L_V' 
74779                 WHEN 2 THEN 'AR_CUST_TRX_LINES_L_V' 
74780                 WHEN 3 THEN 'AR_CUST_TRX_LINES_L_V' 
74781                 WHEN 4 THEN 'AR_CUST_TRX_LINES_L_V' 
74782                 WHEN 5 THEN 'AR_CUST_TRX_LINES_L_V' 
74783                 WHEN 6 THEN 'AR_CUST_TRX_LINES_BASE_V' 
74784                 WHEN 7 THEN 'AR_CUST_TRX_LINES_BASE_V' 
74785                 WHEN 8 THEN 'AR_CUST_TRX_LINES_BASE_V' 
74786                 WHEN 9 THEN 'AR_CUST_TRX_LINES_BASE_V' 
74787                 
74788                ELSE null
74789               END                           object_name
74790             , CASE r
74791                 WHEN 1 THEN 'LINE' 
74792                 WHEN 2 THEN 'LINE' 
74793                 WHEN 3 THEN 'LINE' 
74794                 WHEN 4 THEN 'LINE' 
74795                 WHEN 5 THEN 'LINE' 
74796                 WHEN 6 THEN 'LINE' 
74797                 WHEN 7 THEN 'LINE' 
74798                 WHEN 8 THEN 'LINE' 
74799                 WHEN 9 THEN 'LINE' 
74800                 
74801                 ELSE null
74802               END                           object_type_code
74803             , CASE r
74804                 WHEN 1 THEN '222' 
74805                 WHEN 2 THEN '222' 
74806                 WHEN 3 THEN '222' 
74807                 WHEN 4 THEN '222' 
74808                 WHEN 5 THEN '222' 
74809                 WHEN 6 THEN '222' 
74810                 WHEN 7 THEN '222' 
74811                 WHEN 8 THEN '222' 
74812                 WHEN 9 THEN '222' 
74813                 
74814                 ELSE null
74815               END                           source_application_id
74816             , 'S'             source_type_code
74817             , CASE r
74818                 WHEN 1 THEN 'TRX_LINE_DIST_CCID' 
74819                 WHEN 2 THEN 'TRX_LINE_DIST_ACCOUNT_CLASS' 
74820                 WHEN 3 THEN 'TRX_LINE_DIST_ID' 
74821                 WHEN 4 THEN 'TRX_DISTRIBUTION_TYPE' 
74822                 WHEN 5 THEN 'TRX_LINE_DIST_AMT' 
74823                 WHEN 6 THEN 'TRX_LINE_CUR_CONVERSION_DATE' 
74824                 WHEN 7 THEN 'TRX_LINE_CUR_CONVERSION_RATE' 
74825                 WHEN 8 THEN 'TRX_LINE_CUR_CONVERSION_TYPE' 
74826                 WHEN 9 THEN 'TRX_LINE_ACCTD_AMT' 
74827                 
74828                 ELSE null
74832                 WHEN 2 THEN TO_CHAR(l4.TRX_LINE_DIST_ACCOUNT_CLASS)
74829               END                           source_code
74830             , CASE r
74831                 WHEN 1 THEN TO_CHAR(l4.TRX_LINE_DIST_CCID)
74833                 WHEN 3 THEN TO_CHAR(l4.TRX_LINE_DIST_ID)
74834                 WHEN 4 THEN TO_CHAR(l4.TRX_DISTRIBUTION_TYPE)
74835                 WHEN 5 THEN TO_CHAR(l4.TRX_LINE_DIST_AMT)
74836                 WHEN 6 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_DATE)
74837                 WHEN 7 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_RATE)
74838                 WHEN 8 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_TYPE)
74839                 WHEN 9 THEN TO_CHAR(l3.TRX_LINE_ACCTD_AMT)
74840                 
74841                 ELSE null
74842               END                           source_value
74843             , null              source_meaning
74844          FROM  xla_events_gt     xet  
74845         , AR_CUST_TRX_LINES_BASE_V  l3
74846         , AR_CUST_TRX_LINES_L_V  l4
74847             , (select rownum r from all_objects where rownum <= 9 and owner = p_apps_owner)
74848         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
74849           AND xet.event_class_code = C_EVENT_CLASS_CODE
74850             AND l3.event_id          = xet.event_id
74851   AND l4.event_id    = l3.event_id
74852   AND l4.line_number = l3.line_number
74853 
74854 )
74855 ;
74856 --
74857 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
74858 
74859       trace
74860          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
74861          ,p_level    => C_LEVEL_STATEMENT
74862          ,p_module   => l_log_module);
74863 
74864 END IF;
74865 
74866 
74867 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
74868       trace
74869          (p_msg      => 'END of insert_sources_140'
74870          ,p_level    => C_LEVEL_PROCEDURE
74871          ,p_module   => l_log_module);
74872 END IF;
74873 EXCEPTION
74874   WHEN xla_exceptions_pkg.application_exception THEN
74875       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
74876             trace
74877                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
74878                ,p_level    => C_LEVEL_EXCEPTION
74879                ,p_module   => l_log_module);
74880       END IF;
74881       RAISE;
74882   WHEN OTHERS THEN
74883       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
74884             trace
74885                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
74886                ,p_level    => C_LEVEL_EXCEPTION
74887                ,p_module   => l_log_module);
74888        END IF;
74889        xla_exceptions_pkg.raise_message
74890            (p_location => 'XLA_00222_AAD_S_000006_PKG.insert_sources_140');
74891 END insert_sources_140;
74892 --
74893 
74894 ---------------------------------------
74895 --
74896 -- PRIVATE FUNCTION
74897 --         EventClass_140
74898 --
74899 ----------------------------------------
74900 --
74901 FUNCTION EventClass_140
74902        (p_application_id         IN NUMBER
74903        ,p_base_ledger_id         IN NUMBER
74904        ,p_target_ledger_id       IN NUMBER
74905        ,p_language               IN VARCHAR2
74906        ,p_currency_code          IN VARCHAR2
74907        ,p_sla_ledger_id          IN NUMBER
74908        ,p_pad_start_date         IN DATE
74909        ,p_pad_end_date           IN DATE
74910        ,p_primary_ledger_id      IN NUMBER)
74911 RETURN BOOLEAN IS
74912 --
74913 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'DEPOSIT_ALL';
74914 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'DEPOSIT';
74915 
74916 l_calculate_acctd_flag   VARCHAR2(1) :='N';
74917 l_calculate_g_l_flag     VARCHAR2(1) :='N';
74918 --
74919 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
74920 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
74921 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
74922 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
74923 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
74924 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
74925 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
74926 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
74927 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
74928 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
74929 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
74930 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
74931 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
74932 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
74933 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
74934 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
74935 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
74936 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
74937 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
74938 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
74939 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
74940 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
74941 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
74942 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
74943 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
74944 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
74945 
74946 l_event_id                             NUMBER;
74947 l_previous_event_id                    NUMBER;
74951 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
74948 l_first_event_id                       NUMBER;
74949 l_last_event_id                        NUMBER;
74950 
74952 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
74953 --
74954 --
74955 l_result                    BOOLEAN := TRUE;
74956 l_rows                      NUMBER  := 1000;
74957 l_event_type_name           VARCHAR2(80) := 'All';
74958 l_event_class_name          VARCHAR2(80) := 'Deposit';
74959 l_description               VARCHAR2(4000);
74960 l_transaction_reversal      NUMBER;
74961 l_ae_header_id              NUMBER;
74962 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
74963 l_log_module                VARCHAR2(240);
74964 --
74965 l_acct_reversal_source      VARCHAR2(30);
74966 l_trx_reversal_source       VARCHAR2(30);
74967 
74968 l_continue_with_lines       BOOLEAN := TRUE;
74969 --
74970 l_acc_rev_gl_date_source    DATE;                      -- 4262811
74971 --
74972 type t_array_event_id is table of number index by binary_integer;
74973 
74974 l_rec_array_event                    t_rec_array_event;
74975 l_null_rec_array_event               t_rec_array_event;
74976 l_array_ae_header_id                 xla_number_array_type;
74977 l_actual_flag                        VARCHAR2(1) := NULL;
74978 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
74979 l_balance_type_code                  VARCHAR2(1) :=NULL;
74980 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
74981 
74982 --
74983 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
74984 --
74985 
74986 TYPE t_array_source_30 IS TABLE OF AR_BILL_TO_CUSTOMERS_S_V.BILL_CUST_ACCOUNT_ID%TYPE INDEX BY BINARY_INTEGER;
74987 TYPE t_array_source_31 IS TABLE OF AR_BILL_TO_SITE_USES_S_V.BILL_USES_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
74988 TYPE t_array_source_32 IS TABLE OF AR_TRANSACTIONS_S_V.XLA_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
74989 TYPE t_array_source_37 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_INVOICE_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
74990 TYPE t_array_source_83 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
74991 TYPE t_array_source_84 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
74992 TYPE t_array_source_85 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
74993 
74994 TYPE t_array_source_4 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
74995 TYPE t_array_source_33 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ACCOUNT_CLASS%TYPE INDEX BY BINARY_INTEGER;
74996 TYPE t_array_source_34 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ID%TYPE INDEX BY BINARY_INTEGER;
74997 TYPE t_array_source_35 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
74998 TYPE t_array_source_36 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_AMT%TYPE INDEX BY BINARY_INTEGER;
74999 TYPE t_array_source_38 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
75000 TYPE t_array_source_39 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
75001 TYPE t_array_source_40 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
75002 TYPE t_array_source_41 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
75003 
75004 l_array_source_30              t_array_source_30;
75005 l_array_source_31              t_array_source_31;
75006 l_array_source_32              t_array_source_32;
75007 l_array_source_37              t_array_source_37;
75008 l_array_source_83              t_array_source_83;
75009 l_array_source_84              t_array_source_84;
75010 l_array_source_85              t_array_source_85;
75011 
75012 l_array_source_4      t_array_source_4;
75013 l_array_source_33      t_array_source_33;
75014 l_array_source_34      t_array_source_34;
75015 l_array_source_35      t_array_source_35;
75016 l_array_source_36      t_array_source_36;
75017 l_array_source_38      t_array_source_38;
75018 l_array_source_39      t_array_source_39;
75019 l_array_source_40      t_array_source_40;
75020 l_array_source_41      t_array_source_41;
75021 
75022 --
75023 CURSOR header_cur
75024 IS
75025 SELECT /*+ leading(xet) cardinality(xet,1) */
75026 -- Event Class Code: DEPOSIT
75027     xet.entity_id
75028    ,xet.legal_entity_id
75029    ,xet.entity_code
75030    ,xet.transaction_number
75031    ,xet.event_id
75032    ,xet.event_class_code
75033    ,xet.event_type_code
75034    ,xet.event_number
75035    ,xet.event_date
75036    ,xet.transaction_date
75037    ,xet.reference_num_1
75038    ,xet.reference_num_2
75039    ,xet.reference_num_3
75040    ,xet.reference_num_4
75041    ,xet.reference_char_1
75042    ,xet.reference_char_2
75043    ,xet.reference_char_3
75044    ,xet.reference_char_4
75045    ,xet.reference_date_1
75046    ,xet.reference_date_2
75047    ,xet.reference_date_3
75048    ,xet.reference_date_4
75049    ,xet.event_created_by
75050    ,xet.budgetary_control_flag 
75051   , h1.BILL_CUST_ACCOUNT_ID    source_30
75052   , h2.BILL_USES_SITE_USE_ID    source_31
75053   , h5.XLA_PARTY_TYPE    source_32
75054   , h5.TRX_INVOICE_CURRENCY_CODE    source_37
75055   , h5.TRX_DOC_SEQUENCE_CATEGORY    source_83
75056   , h5.TRX_DOC_SEQUENCE_ID    source_84
75057   , h5.TRX_DOC_SEQUENCE_VALUE    source_85
75058   FROM xla_events_gt     xet 
75059   , AR_BILL_TO_CUSTOMERS_S_V  h1
75060   , AR_BILL_TO_SITE_USES_S_V  h2
75061   , AR_TRANSACTIONS_S_V  h5
75062  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
75063    and xet.event_class_code = C_EVENT_CLASS_CODE
75064    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
75065   AND h2.event_id  = h1.event_id
75066   AND h5.event_id  = h1.event_id
75067 
75068  ORDER BY event_id
75069 ;
75070 
75071 
75075 SELECT  /*+ leading(xet) cardinality(xet,1) */
75072 --
75073 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
75074 IS
75076 -- Event Class Code: DEPOSIT
75077     xet.entity_id
75078    ,xet.legal_entity_id
75079    ,xet.entity_code
75080    ,xet.transaction_number
75081    ,xet.event_id
75082    ,xet.event_class_code
75083    ,xet.event_type_code
75084    ,xet.event_number
75085    ,xet.event_date
75086    ,xet.transaction_date
75087    ,xet.reference_num_1
75088    ,xet.reference_num_2
75089    ,xet.reference_num_3
75090    ,xet.reference_num_4
75091    ,xet.reference_char_1
75092    ,xet.reference_char_2
75093    ,xet.reference_char_3
75094    ,xet.reference_char_4
75095    ,xet.reference_date_1
75096    ,xet.reference_date_2
75097    ,xet.reference_date_3
75098    ,xet.reference_date_4
75099    ,xet.event_created_by
75100    ,xet.budgetary_control_flag
75101  , l3.LINE_NUMBER  
75102   , l4.TRX_LINE_DIST_CCID    source_4
75103   , l4.TRX_LINE_DIST_ACCOUNT_CLASS    source_33
75104   , l4.TRX_LINE_DIST_ID    source_34
75105   , l4.TRX_DISTRIBUTION_TYPE    source_35
75106   , l4.TRX_LINE_DIST_AMT    source_36
75107   , l3.TRX_LINE_CUR_CONVERSION_DATE    source_38
75108   , l3.TRX_LINE_CUR_CONVERSION_RATE    source_39
75109   , l3.TRX_LINE_CUR_CONVERSION_TYPE    source_40
75110   , l3.TRX_LINE_ACCTD_AMT    source_41
75111   FROM xla_events_gt     xet 
75112   , AR_CUST_TRX_LINES_BASE_V  l3
75113   , AR_CUST_TRX_LINES_L_V  l4
75114  WHERE xet.event_id between x_first_event_id and x_last_event_id
75115    and xet.event_date between p_pad_start_date and p_pad_end_date
75116    and xet.event_class_code = C_EVENT_CLASS_CODE
75117    and xet.event_status_code <> 'N'   AND l3.event_id      = xet.event_id
75118   AND l4.event_id    = l3.event_id
75119   AND l4.line_number = l3.line_number
75120 ;
75121 
75122 --
75123 BEGIN
75124 IF g_log_enabled THEN
75125    l_log_module := C_DEFAULT_MODULE||'.EventClass_140';
75126 END IF;
75127 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
75128    trace
75129       (p_msg      => 'BEGIN of EventClass_140'
75130       ,p_level    => C_LEVEL_PROCEDURE
75131       ,p_module   => l_log_module);
75132 END IF;
75133 
75134 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
75135    trace
75136       (p_msg      => 'p_application_id = '||p_application_id||
75137                      ' - p_base_ledger_id = '||p_base_ledger_id||
75138                      ' - p_target_ledger_id  = '||p_target_ledger_id||
75139                      ' - p_language = '||p_language||
75140                      ' - p_currency_code = '||p_currency_code||
75141                      ' - p_sla_ledger_id = '||p_sla_ledger_id
75142       ,p_level    => C_LEVEL_STATEMENT
75143       ,p_module   => l_log_module);
75144 END IF;
75145 --
75146 -- initialze arrays
75147 --
75148 g_array_event.DELETE;
75149 l_rec_array_event := l_null_rec_array_event;
75150 --
75151 --------------------------------------
75152 -- 4262811 Initialze MPA Line Number
75153 --------------------------------------
75154 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
75155 
75156 --
75157 
75158 --
75159 OPEN header_cur;
75160 --
75161 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
75162    trace
75163    (p_msg      => 'SQL - FETCH header_cur'
75164    ,p_level    => C_LEVEL_STATEMENT
75165    ,p_module   => l_log_module);
75166 END IF;
75167 --
75168 LOOP
75169 FETCH header_cur BULK COLLECT INTO
75170         l_array_entity_id
75171       , l_array_legal_entity_id
75172       , l_array_entity_code
75173       , l_array_transaction_num
75174       , l_array_event_id
75175       , l_array_class_code
75176       , l_array_event_type
75177       , l_array_event_number
75178       , l_array_event_date
75179       , l_array_transaction_date
75180       , l_array_reference_num_1
75181       , l_array_reference_num_2
75182       , l_array_reference_num_3
75183       , l_array_reference_num_4
75184       , l_array_reference_char_1
75185       , l_array_reference_char_2
75186       , l_array_reference_char_3
75187       , l_array_reference_char_4
75188       , l_array_reference_date_1
75189       , l_array_reference_date_2
75190       , l_array_reference_date_3
75191       , l_array_reference_date_4
75192       , l_array_event_created_by
75193       , l_array_budgetary_control_flag 
75194       , l_array_source_30
75195       , l_array_source_31
75196       , l_array_source_32
75197       , l_array_source_37
75198       , l_array_source_83
75199       , l_array_source_84
75200       , l_array_source_85
75201       LIMIT l_rows;
75202 --
75203 IF (C_LEVEL_EVENT >= g_log_level) THEN
75204    trace
75205    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
75206    ,p_level    => C_LEVEL_EVENT
75207    ,p_module   => l_log_module);
75208 END IF;
75209 --
75210 EXIT WHEN l_array_entity_id.COUNT = 0;
75211 
75212 -- initialize arrays
75213 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
75214 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
75215 
75216 --
75217 -- Bug 4458708
75218 --
75219 XLA_AE_LINES_PKG.g_LineNumber := 0;
75220 
75221 
75222 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
75223 g_last_hdr_idx := l_array_event_id.LAST;
75224 --
75225 -- loop for the headers. Each iteration is for each header extract row
75226 -- fetched in header cursor
75227 --
75228 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
75229 
75230 --
75231 -- set event info as cache for other routines to refer event attributes
75232 --
75233 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
75237    ,p_target_ledger_id         => p_target_ledger_id
75234    (p_application_id           => p_application_id
75235    ,p_primary_ledger_id        => p_primary_ledger_id
75236    ,p_base_ledger_id           => p_base_ledger_id
75238    ,p_entity_id                => l_array_entity_id(hdr_idx)
75239    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
75240    ,p_entity_code              => l_array_entity_code(hdr_idx)
75241    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
75242    ,p_event_id                 => l_array_event_id(hdr_idx)
75243    ,p_event_class_code         => l_array_class_code(hdr_idx)
75244    ,p_event_type_code          => l_array_event_type(hdr_idx)
75245    ,p_event_number             => l_array_event_number(hdr_idx)
75246    ,p_event_date               => l_array_event_date(hdr_idx)
75247    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
75248    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
75249    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
75250    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
75251    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
75252    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
75253    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
75254    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
75255    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
75256    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
75257    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
75258    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
75259    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
75260    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
75261    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
75262 
75263 --
75264 -- set the status of entry to C_VALID (0)
75265 --
75266 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
75267 
75268 --
75269 -- initialize a row for ae header
75270 --
75271 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
75272 
75273 l_event_id := l_array_event_id(hdr_idx);
75274 
75275 --
75276 -- storing the hdr_idx for event. May be used by line cursor.
75277 --
75278 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
75279 
75280 --
75281 -- store sources from header extract. This can be improved to
75282 -- store only those sources from header extract that may be used in lines
75283 --
75284 
75285 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
75286 g_array_event(l_event_id).array_value_num('source_31') := l_array_source_31(hdr_idx);
75287 g_array_event(l_event_id).array_value_char('source_32') := l_array_source_32(hdr_idx);
75288 g_array_event(l_event_id).array_value_char('source_37') := l_array_source_37(hdr_idx);
75289 g_array_event(l_event_id).array_value_char('source_83') := l_array_source_83(hdr_idx);
75290 g_array_event(l_event_id).array_value_num('source_84') := l_array_source_84(hdr_idx);
75291 g_array_event(l_event_id).array_value_num('source_85') := l_array_source_85(hdr_idx);
75292 
75293 --
75294 -- initilaize the status of ae headers for diffrent balance types
75295 -- the status is initialised to C_NOT_CREATED (2)
75296 --
75297 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
75298 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
75299 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
75300 
75301 --
75302 -- call api to validate and store accounting attributes for header
75303 --
75304 
75305 ------------------------------------------------------------
75306 -- Accrual Reversal : to get date for Standard Source (NONE)
75307 ------------------------------------------------------------
75308 l_acc_rev_gl_date_source := NULL;
75309 
75310      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
75311       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_83');
75312      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
75313       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_84');
75314      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
75315       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_85');
75316      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
75317       l_rec_acct_attrs.array_date_value(4) := 
75318 xla_ae_sources_pkg.GetSystemSourceDate(
75319    p_source_code           => 'XLA_EVENT_DATE'
75320  , p_source_type_code      => 'Y'
75321  , p_source_application_id =>  602
75322 );
75323 
75324 
75325 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
75326 
75327 XLA_AE_HEADER_PKG.SetJeCategoryName;
75328 
75329 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
75330 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
75331 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
75332 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
75333 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
75334 
75335 
75336 -- No header level analytical criteria
75337 
75338 --
75339 --accounting attribute enhancement, bug 3612931
75340 --
75341 l_trx_reversal_source := SUBSTR(NULL, 1,30);
75342 
75343 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
75344    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
75345 
75346    xla_accounting_err_pkg.build_message
75347       (p_appli_s_name            => 'XLA'
75351       ,p_token_2                 => 'PRODUCT_NAME'
75348       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
75349       ,p_token_1                 => 'ACCT_ATTR_NAME'
75350       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
75352       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
75353       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
75354       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
75355       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
75356 
75357 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
75358    --
75359    -- following sets the accounting attributes needed to reverse
75360    -- accounting for a distributeion
75361    --
75362    xla_ae_lines_pkg.SetTrxReversalAttrs
75363       (p_event_id              => l_event_id
75364       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
75365       ,p_trx_reversal_source   => l_trx_reversal_source);
75366 
75367 END IF;
75368 
75369 
75370 ----------------------------------------------------------------
75371 -- 4262811 -  update the header statuses to invalid in need be
75372 ----------------------------------------------------------------
75373 --
75374 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
75375 
75376 
75377   -----------------------------------------------
75378   -- No accrual reversal for the event class/type
75379   -----------------------------------------------
75380 ----------------------------------------------------------------
75381 
75382 --
75383 -- this ends the header loop iteration for one bulk fetch
75384 --
75385 END LOOP;
75386 
75387 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
75388 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
75389 
75390 --
75391 -- insert dummy rows into lines gt table that were created due to
75392 -- transaction reversals
75393 --
75394 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
75395    l_result := XLA_AE_LINES_PKG.InsertLines;
75396 END IF;
75397 
75398 --
75399 -- reset the temp_line_num for each set of events fetched from header
75400 -- cursor rather than doing it for each new event in line cursor
75401 -- Bug 3939231
75402 --
75403 xla_ae_lines_pkg.g_temp_line_num := 0;
75404 
75405 
75406 
75407 --
75408 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
75409 --
75410 --
75411 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
75412 
75413       trace
75414          (p_msg      => 'SQL - FETCH line_cur'
75415          ,p_level    => C_LEVEL_STATEMENT
75416          ,p_module   => l_log_module);
75417 
75418 END IF;
75419 --
75420 --
75421 LOOP
75422   --
75423   FETCH line_cur BULK COLLECT INTO
75424         l_array_entity_id
75425       , l_array_legal_entity_id
75426       , l_array_entity_code
75427       , l_array_transaction_num
75428       , l_array_event_id
75429       , l_array_class_code
75430       , l_array_event_type
75431       , l_array_event_number
75432       , l_array_event_date
75433       , l_array_transaction_date
75434       , l_array_reference_num_1
75435       , l_array_reference_num_2
75436       , l_array_reference_num_3
75437       , l_array_reference_num_4
75438       , l_array_reference_char_1
75439       , l_array_reference_char_2
75440       , l_array_reference_char_3
75441       , l_array_reference_char_4
75442       , l_array_reference_date_1
75443       , l_array_reference_date_2
75444       , l_array_reference_date_3
75445       , l_array_reference_date_4
75446       , l_array_event_created_by
75447       , l_array_budgetary_control_flag
75448       , l_array_extract_line_num 
75449       , l_array_source_4
75450       , l_array_source_33
75451       , l_array_source_34
75452       , l_array_source_35
75453       , l_array_source_36
75454       , l_array_source_38
75455       , l_array_source_39
75456       , l_array_source_40
75457       , l_array_source_41
75458       LIMIT l_rows;
75459 
75460   --
75461   IF (C_LEVEL_EVENT >= g_log_level) THEN
75462             trace
75463                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
75464                ,p_level    => C_LEVEL_EVENT
75465                ,p_module   => l_log_module);
75466   END IF;
75467   --
75468   EXIT WHEN l_array_entity_id.count = 0;
75469 
75470   XLA_AE_LINES_PKG.g_rec_lines := null;
75471 
75472 --
75473 -- Bug 4458708
75474 --
75475 XLA_AE_LINES_PKG.g_LineNumber := 0;
75476 --
75477 --
75478 
75479 FOR Idx IN 1..l_array_event_id.count LOOP
75480    --
75481    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
75482    --
75483    l_event_id := l_array_event_id(idx);  -- 5648433
75484 
75485    --
75486    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
75487    --
75488 
75489    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
75490              (g_array_event(l_event_id).array_value_num('header_index'))
75491          ,'N'
75492          ) <> 'Y'
75493    THEN
75494       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
75495          trace
75496             (p_msg      => 'Trancaction revesal option is not Y '
75497             ,p_level    => C_LEVEL_STATEMENT
75498             ,p_module   => l_log_module);
75499       END IF;
75500 
75501 --
75502 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
75503 --
75507 --
75504 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
75505 --
75506 -- set event info as cache for other routines to refer event attributes
75508 
75509 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
75510    l_previous_event_id := l_event_id;
75511 
75512    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
75513       (p_application_id           => p_application_id
75514       ,p_primary_ledger_id        => p_primary_ledger_id
75515       ,p_base_ledger_id           => p_base_ledger_id
75516       ,p_target_ledger_id         => p_target_ledger_id
75517       ,p_entity_id                => l_array_entity_id(Idx)
75518       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
75519       ,p_entity_code              => l_array_entity_code(Idx)
75520       ,p_transaction_num          => l_array_transaction_num(Idx)
75521       ,p_event_id                 => l_array_event_id(Idx)
75522       ,p_event_class_code         => l_array_class_code(Idx)
75523       ,p_event_type_code          => l_array_event_type(Idx)
75524       ,p_event_number             => l_array_event_number(Idx)
75525       ,p_event_date               => l_array_event_date(Idx)
75526       ,p_transaction_date         => l_array_transaction_date(Idx)
75527       ,p_reference_num_1          => l_array_reference_num_1(Idx)
75528       ,p_reference_num_2          => l_array_reference_num_2(Idx)
75529       ,p_reference_num_3          => l_array_reference_num_3(Idx)
75530       ,p_reference_num_4          => l_array_reference_num_4(Idx)
75531       ,p_reference_char_1         => l_array_reference_char_1(Idx)
75532       ,p_reference_char_2         => l_array_reference_char_2(Idx)
75533       ,p_reference_char_3         => l_array_reference_char_3(Idx)
75534       ,p_reference_char_4         => l_array_reference_char_4(Idx)
75535       ,p_reference_date_1         => l_array_reference_date_1(Idx)
75536       ,p_reference_date_2         => l_array_reference_date_2(Idx)
75537       ,p_reference_date_3         => l_array_reference_date_3(Idx)
75538       ,p_reference_date_4         => l_array_reference_date_4(Idx)
75539       ,p_event_created_by         => l_array_event_created_by(Idx)
75540       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
75541        --
75542 END IF;
75543 
75544 
75545 
75546 --
75547 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
75548 
75549 l_acct_reversal_source := SUBSTR(NULL, 1,30);
75550 
75551 IF l_continue_with_lines THEN
75552    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
75553       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
75554 
75555       xla_accounting_err_pkg.build_message
75556          (p_appli_s_name            => 'XLA'
75557          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
75558          ,p_token_1                 => 'LINE_NUMBER'
75559          ,p_value_1                 => l_array_extract_line_num(Idx)
75560          ,p_token_2                 => 'PRODUCT_NAME'
75561          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
75562          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
75563          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
75564          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
75565 
75566    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
75567       --
75568       -- following sets the accounting attributes needed to reverse
75569       -- accounting for a distributeion
75570       --
75571 
75572       --
75573       -- 5217187
75574       --
75575       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
75576       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
75577                                        g_array_event(l_event_id).array_value_num('header_index'));
75578       --
75579       --
75580 
75581       -- No reversal code generated
75582 
75583       xla_ae_lines_pkg.SetAcctReversalAttrs
75584          (p_event_id             => l_event_id
75585          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
75586          ,p_calculate_acctd_flag => l_calculate_acctd_flag
75587          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
75588    END IF;
75589 
75590    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
75591        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
75592 
75593 --
75594 AcctLineType_50 (
75595  p_application_id  => p_application_id
75596  ,p_event_id     => l_event_id
75597  ,p_calculate_acctd_flag => l_calculate_acctd_flag
75598  ,p_calculate_g_l_flag => l_calculate_g_l_flag
75599  ,p_actual_flag => l_actual_flag
75600  ,p_balance_type_code => l_balance_type_code
75601  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
75602  
75603  , p_source_4 => l_array_source_4(Idx)
75604  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
75605  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
75606  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
75607  , p_source_33 => l_array_source_33(Idx)
75608  , p_source_34 => l_array_source_34(Idx)
75609  , p_source_35 => l_array_source_35(Idx)
75610  , p_source_36 => l_array_source_36(Idx)
75611  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
75612  , p_source_38 => l_array_source_38(Idx)
75613  , p_source_39 => l_array_source_39(Idx)
75614  , p_source_40 => l_array_source_40(Idx)
75615  , p_source_41 => l_array_source_41(Idx)
75616  );
75617 If(l_balance_type_code = 'A') THEN
75618   l_actual_gain_loss_ref := l_gain_or_loss_ref;
75619 END IF;
75620 
75621 --
75622 
75623 
75624 --
75625 AcctLineType_51 (
75626  p_application_id  => p_application_id
75627  ,p_event_id     => l_event_id
75628  ,p_calculate_acctd_flag => l_calculate_acctd_flag
75632  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
75629  ,p_calculate_g_l_flag => l_calculate_g_l_flag
75630  ,p_actual_flag => l_actual_flag
75631  ,p_balance_type_code => l_balance_type_code
75633  
75634  , p_source_4 => l_array_source_4(Idx)
75635  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
75636  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
75637  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
75638  , p_source_33 => l_array_source_33(Idx)
75639  , p_source_34 => l_array_source_34(Idx)
75640  , p_source_35 => l_array_source_35(Idx)
75641  , p_source_36 => l_array_source_36(Idx)
75642  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
75643  , p_source_38 => l_array_source_38(Idx)
75644  , p_source_39 => l_array_source_39(Idx)
75645  , p_source_40 => l_array_source_40(Idx)
75646  , p_source_41 => l_array_source_41(Idx)
75647  );
75648 If(l_balance_type_code = 'A') THEN
75649   l_actual_gain_loss_ref := l_gain_or_loss_ref;
75650 END IF;
75651 
75652 --
75653 
75654       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
75655       -- or secondary ledger that has different currency with primary
75656       -- or alc that is calculated by sla
75657       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
75658             (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'))
75659 
75660 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
75661 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
75662           AND (l_actual_flag = 'A')) THEN
75663         XLA_AE_LINES_PKG.CreateGainOrLossLines(
75664           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
75665          ,p_application_id   => p_application_id
75666          ,p_amb_context_code => 'DEFAULT'
75667          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
75668          ,p_event_class_code => C_EVENT_CLASS_CODE
75669          ,p_event_type_code  => C_EVENT_TYPE_CODE
75670          
75671          ,p_gain_ccid        => -1
75672          ,p_loss_ccid        => -1
75673 
75674          ,p_actual_flag      => l_actual_flag
75675          ,p_enc_flag         => null
75676          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
75677          ,p_enc_g_l_ref      => null
75678          );
75679       END IF;
75680    END IF;
75681 END IF;
75682 
75683    ELSE
75684       --
75685       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
75686       --
75687       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
75688          trace
75689             (p_msg      => 'Trancaction revesal option is Y'
75690             ,p_level    => C_LEVEL_STATEMENT
75691             ,p_module   => l_log_module);
75692       END IF;
75693    END IF;
75694 
75695 END LOOP;
75696 l_result := XLA_AE_LINES_PKG.InsertLines ;
75697 end loop;
75698 close line_cur;
75699 
75700 
75701 --
75702 -- insert headers into xla_ae_headers_gt table
75703 --
75704 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
75705 
75706 -- insert into errors table here.
75707 
75708 END LOOP;
75709 
75710 --
75711 -- 4865292
75712 --
75713 -- Compare g_hdr_extract_count with event count in
75714 -- CreateHeadersAndLines.
75715 --
75716 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
75717 
75718 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
75719    trace (p_msg     => '# rows extracted from header extract objects '
75720                     || ' (running total): '
75721                     || g_hdr_extract_count
75722          ,p_level   => C_LEVEL_STATEMENT
75723          ,p_module  => l_log_module);
75724 END IF;
75725 
75726 CLOSE header_cur;
75727 --
75728 
75729 --
75730 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
75731    trace
75732       (p_msg      => 'END of EventClass_140'
75733       ,p_level    => C_LEVEL_PROCEDURE
75734       ,p_module   => l_log_module);
75735 END IF;
75736 --
75737 RETURN l_result;
75738 EXCEPTION
75739 WHEN xla_exceptions_pkg.application_exception THEN
75740    
75741 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
75742 
75743    
75744 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
75745 
75746    RAISE;
75747 
75748 WHEN NO_DATA_FOUND THEN
75749 
75750 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
75751 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
75752 
75753 FOR header_record IN header_cur
75754 LOOP
75755     l_array_header_events(header_record.event_id) := header_record.event_id;
75756 END LOOP;
75757 
75758 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
75759 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
75760 
75761 fnd_file.put_line(fnd_file.LOG, '                    ');
75762 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
75763 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
75764 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
75765 
75766 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
75767 LOOP
75768 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
75769 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
75770         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
75771 	END IF;
75772 END LOOP;
75773 
75777 
75774 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
75775 fnd_file.put_line(fnd_file.LOG, '                    ');
75776 
75778 xla_exceptions_pkg.raise_message
75779       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_140');
75780 
75781 
75782 WHEN OTHERS THEN
75783    xla_exceptions_pkg.raise_message
75784       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_140');
75785 END EventClass_140;
75786 --
75787 
75788 ---------------------------------------
75789 --
75790 -- PRIVATE PROCEDURE
75791 --         insert_sources_141
75792 --
75793 ----------------------------------------
75794 --
75795 PROCEDURE insert_sources_141(
75796                                 p_target_ledger_id       IN NUMBER
75797                               , p_language               IN VARCHAR2
75798                               , p_sla_ledger_id          IN NUMBER
75799                               , p_pad_start_date         IN DATE
75800                               , p_pad_end_date           IN DATE
75801                          )
75802 IS
75803 
75804 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'GUARANTEE_ALL';
75805 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'GUARANTEE';
75806 p_apps_owner                   VARCHAR2(30);
75807 l_log_module                   VARCHAR2(240);
75808 BEGIN
75809 IF g_log_enabled THEN
75810       l_log_module := C_DEFAULT_MODULE||'.insert_sources_141';
75811 END IF;
75812 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
75813 
75814       trace
75815          (p_msg      => 'BEGIN of insert_sources_141'
75816          ,p_level    => C_LEVEL_PROCEDURE
75817          ,p_module   => l_log_module);
75818 
75819 END IF;
75820 
75821 -- select APPS owner
75822 SELECT oracle_username
75823   INTO p_apps_owner
75824   FROM fnd_oracle_userid
75825  WHERE read_only_flag = 'U'
75826 ;
75827 
75828 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
75829       trace
75830          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
75831                         ' - p_language = '||p_language||
75832                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
75833                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
75834                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
75835                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
75836          ,p_level    => C_LEVEL_STATEMENT
75837          ,p_module   => l_log_module);
75838 END IF;
75839 
75840 
75841 --
75842 INSERT INTO xla_diag_sources --hdr2
75843 (
75844         event_id
75845       , ledger_id
75846       , sla_ledger_id
75847       , description_language
75848       , object_name
75849       , object_type_code
75850       , line_number
75851       , source_application_id
75852       , source_type_code
75853       , source_code
75854       , source_value
75855       , source_meaning
75856       , created_by
75857       , creation_date
75858       , last_update_date
75859       , last_updated_by
75860       , last_update_login
75861       , program_update_date
75862       , program_application_id
75863       , program_id
75864       , request_id
75865 )
75866 SELECT
75867         event_id
75868       , p_target_ledger_id
75869       , p_sla_ledger_id
75870       , p_language
75871       , object_name
75872       , object_type_code
75873       , line_number
75874       , source_application_id
75875       , source_type_code
75876       , source_code
75877       , SUBSTR(source_value ,1,1996)
75878       , SUBSTR(source_meaning ,1,200)
75879       , xla_environment_pkg.g_Usr_Id
75880       , TRUNC(SYSDATE)
75881       , TRUNC(SYSDATE)
75882       , xla_environment_pkg.g_Usr_Id
75883       , xla_environment_pkg.g_Login_Id
75884       , TRUNC(SYSDATE)
75885       , xla_environment_pkg.g_Prog_Appl_Id
75886       , xla_environment_pkg.g_Prog_Id
75887       , xla_environment_pkg.g_Req_Id
75888   FROM (
75889        SELECT xet.event_id                  event_id
75890             , 0                          line_number
75891             , CASE r
75892                WHEN 1 THEN 'AR_BILL_TO_CUSTOMERS_S_V' 
75893                 WHEN 2 THEN 'AR_BILL_TO_SITE_USES_S_V' 
75894                 WHEN 3 THEN 'AR_TRANSACTIONS_S_V' 
75895                 WHEN 4 THEN 'AR_TRANSACTIONS_S_V' 
75896                 WHEN 5 THEN 'AR_TRANSACTIONS_S_V' 
75897                 WHEN 6 THEN 'AR_TRANSACTIONS_S_V' 
75898                 WHEN 7 THEN 'AR_TRANSACTIONS_S_V' 
75899                 
75900                ELSE null
75901               END                           object_name
75902             , CASE r
75903                 WHEN 1 THEN 'HEADER' 
75904                 WHEN 2 THEN 'HEADER' 
75905                 WHEN 3 THEN 'HEADER' 
75906                 WHEN 4 THEN 'HEADER' 
75907                 WHEN 5 THEN 'HEADER' 
75908                 WHEN 6 THEN 'HEADER' 
75909                 WHEN 7 THEN 'HEADER' 
75910                 
75911                 ELSE null
75912               END                           object_type_code
75913             , CASE r
75914                 WHEN 1 THEN '222' 
75915                 WHEN 2 THEN '222' 
75916                 WHEN 3 THEN '222' 
75917                 WHEN 4 THEN '222' 
75918                 WHEN 5 THEN '222' 
75919                 WHEN 6 THEN '222' 
75920                 WHEN 7 THEN '222' 
75921                 
75922                 ELSE null
75923               END                           source_application_id
75924             , 'S'             source_type_code
75925             , CASE r
75926                 WHEN 1 THEN 'BILL_CUST_ACCOUNT_ID' 
75927                 WHEN 2 THEN 'BILL_USES_SITE_USE_ID' 
75931                 WHEN 6 THEN 'TRX_DOC_SEQUENCE_ID' 
75928                 WHEN 3 THEN 'XLA_PARTY_TYPE' 
75929                 WHEN 4 THEN 'TRX_INVOICE_CURRENCY_CODE' 
75930                 WHEN 5 THEN 'TRX_DOC_SEQUENCE_CATEGORY' 
75932                 WHEN 7 THEN 'TRX_DOC_SEQUENCE_VALUE' 
75933                 
75934                 ELSE null
75935               END                           source_code
75936             , CASE r
75937                 WHEN 1 THEN TO_CHAR(h1.BILL_CUST_ACCOUNT_ID)
75938                 WHEN 2 THEN TO_CHAR(h2.BILL_USES_SITE_USE_ID)
75939                 WHEN 3 THEN TO_CHAR(h5.XLA_PARTY_TYPE)
75940                 WHEN 4 THEN TO_CHAR(h5.TRX_INVOICE_CURRENCY_CODE)
75941                 WHEN 5 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_CATEGORY)
75942                 WHEN 6 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_ID)
75943                 WHEN 7 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_VALUE)
75944                 
75945                 ELSE null
75946               END                           source_value
75947             , null              source_meaning
75948          FROM xla_events_gt     xet  
75949       , AR_BILL_TO_CUSTOMERS_S_V  h1
75950       , AR_BILL_TO_SITE_USES_S_V  h2
75951       , AR_TRANSACTIONS_S_V  h5
75952              ,(select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
75953          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
75954            AND xet.event_class_code = C_EVENT_CLASS_CODE
75955               AND h1.event_id = xet.event_id
75956   AND h2.event_id  = h1.event_id
75957   AND h5.event_id  = h1.event_id
75958 
75959 )
75960 ;
75961 --
75962 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
75963 
75964       trace
75965          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
75966          ,p_level    => C_LEVEL_STATEMENT
75967          ,p_module   => l_log_module);
75968 
75969 END IF;
75970 --
75971 
75972 
75973 
75974 --
75975 INSERT INTO xla_diag_sources  --line2
75976 (
75977         event_id
75978       , ledger_id
75979       , sla_ledger_id
75980       , description_language
75981       , object_name
75982       , object_type_code
75983       , line_number
75984       , source_application_id
75985       , source_type_code
75986       , source_code
75987       , source_value
75988       , source_meaning
75989       , created_by
75990       , creation_date
75991       , last_update_date
75992       , last_updated_by
75993       , last_update_login
75994       , program_update_date
75995       , program_application_id
75996       , program_id
75997       , request_id
75998 )
75999 SELECT  event_id
76000       , p_target_ledger_id
76001       , p_sla_ledger_id
76002       , p_language
76003       , object_name
76004       , object_type_code
76005       , line_number
76006       , source_application_id
76007       , source_type_code
76008       , source_code
76009       , SUBSTR(source_value,1,1996)
76010       , SUBSTR(source_meaning ,1,200)
76011       , xla_environment_pkg.g_Usr_Id
76012       , TRUNC(SYSDATE)
76013       , TRUNC(SYSDATE)
76014       , xla_environment_pkg.g_Usr_Id
76015       , xla_environment_pkg.g_Login_Id
76016       , TRUNC(SYSDATE)
76017       , xla_environment_pkg.g_Prog_Appl_Id
76018       , xla_environment_pkg.g_Prog_Id
76019       , xla_environment_pkg.g_Req_Id
76020   FROM (
76021        SELECT xet.event_id                  event_id
76022             , l4.line_number                 line_number
76023             , CASE r
76024                WHEN 1 THEN 'AR_CUST_TRX_LINES_L_V' 
76025                 WHEN 2 THEN 'AR_CUST_TRX_LINES_L_V' 
76026                 WHEN 3 THEN 'AR_CUST_TRX_LINES_L_V' 
76027                 WHEN 4 THEN 'AR_CUST_TRX_LINES_L_V' 
76028                 WHEN 5 THEN 'AR_CUST_TRX_LINES_L_V' 
76029                 WHEN 6 THEN 'AR_CUST_TRX_LINES_BASE_V' 
76030                 WHEN 7 THEN 'AR_CUST_TRX_LINES_BASE_V' 
76031                 WHEN 8 THEN 'AR_CUST_TRX_LINES_BASE_V' 
76032                 WHEN 9 THEN 'AR_CUST_TRX_LINES_BASE_V' 
76033                 
76034                ELSE null
76035               END                           object_name
76036             , CASE r
76037                 WHEN 1 THEN 'LINE' 
76038                 WHEN 2 THEN 'LINE' 
76039                 WHEN 3 THEN 'LINE' 
76040                 WHEN 4 THEN 'LINE' 
76041                 WHEN 5 THEN 'LINE' 
76042                 WHEN 6 THEN 'LINE' 
76043                 WHEN 7 THEN 'LINE' 
76044                 WHEN 8 THEN 'LINE' 
76045                 WHEN 9 THEN 'LINE' 
76046                 
76047                 ELSE null
76048               END                           object_type_code
76049             , CASE r
76050                 WHEN 1 THEN '222' 
76051                 WHEN 2 THEN '222' 
76052                 WHEN 3 THEN '222' 
76053                 WHEN 4 THEN '222' 
76054                 WHEN 5 THEN '222' 
76055                 WHEN 6 THEN '222' 
76056                 WHEN 7 THEN '222' 
76057                 WHEN 8 THEN '222' 
76058                 WHEN 9 THEN '222' 
76059                 
76060                 ELSE null
76061               END                           source_application_id
76062             , 'S'             source_type_code
76063             , CASE r
76064                 WHEN 1 THEN 'TRX_LINE_DIST_CCID' 
76065                 WHEN 2 THEN 'TRX_LINE_DIST_ACCOUNT_CLASS' 
76066                 WHEN 3 THEN 'TRX_LINE_DIST_ID' 
76067                 WHEN 4 THEN 'TRX_DISTRIBUTION_TYPE' 
76068                 WHEN 5 THEN 'TRX_LINE_DIST_AMT' 
76069                 WHEN 6 THEN 'TRX_LINE_CUR_CONVERSION_DATE' 
76070                 WHEN 7 THEN 'TRX_LINE_CUR_CONVERSION_RATE' 
76071                 WHEN 8 THEN 'TRX_LINE_CUR_CONVERSION_TYPE' 
76075               END                           source_code
76072                 WHEN 9 THEN 'TRX_LINE_ACCTD_AMT' 
76073                 
76074                 ELSE null
76076             , CASE r
76077                 WHEN 1 THEN TO_CHAR(l4.TRX_LINE_DIST_CCID)
76078                 WHEN 2 THEN TO_CHAR(l4.TRX_LINE_DIST_ACCOUNT_CLASS)
76079                 WHEN 3 THEN TO_CHAR(l4.TRX_LINE_DIST_ID)
76080                 WHEN 4 THEN TO_CHAR(l4.TRX_DISTRIBUTION_TYPE)
76081                 WHEN 5 THEN TO_CHAR(l4.TRX_LINE_DIST_AMT)
76082                 WHEN 6 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_DATE)
76083                 WHEN 7 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_RATE)
76084                 WHEN 8 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_TYPE)
76085                 WHEN 9 THEN TO_CHAR(l3.TRX_LINE_ACCTD_AMT)
76086                 
76087                 ELSE null
76088               END                           source_value
76089             , null              source_meaning
76090          FROM  xla_events_gt     xet  
76091         , AR_CUST_TRX_LINES_BASE_V  l3
76092         , AR_CUST_TRX_LINES_L_V  l4
76093             , (select rownum r from all_objects where rownum <= 9 and owner = p_apps_owner)
76094         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
76095           AND xet.event_class_code = C_EVENT_CLASS_CODE
76096             AND l3.event_id          = xet.event_id
76097   AND l4.event_id    = l3.event_id
76098   AND l4.line_number = l3.line_number
76099 
76100 )
76101 ;
76102 --
76103 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
76104 
76105       trace
76106          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
76107          ,p_level    => C_LEVEL_STATEMENT
76108          ,p_module   => l_log_module);
76109 
76110 END IF;
76111 
76112 
76113 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
76114       trace
76115          (p_msg      => 'END of insert_sources_141'
76116          ,p_level    => C_LEVEL_PROCEDURE
76117          ,p_module   => l_log_module);
76118 END IF;
76119 EXCEPTION
76120   WHEN xla_exceptions_pkg.application_exception THEN
76121       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
76122             trace
76123                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
76124                ,p_level    => C_LEVEL_EXCEPTION
76125                ,p_module   => l_log_module);
76126       END IF;
76127       RAISE;
76128   WHEN OTHERS THEN
76129       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
76130             trace
76131                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
76132                ,p_level    => C_LEVEL_EXCEPTION
76133                ,p_module   => l_log_module);
76134        END IF;
76135        xla_exceptions_pkg.raise_message
76136            (p_location => 'XLA_00222_AAD_S_000006_PKG.insert_sources_141');
76137 END insert_sources_141;
76138 --
76139 
76140 ---------------------------------------
76141 --
76142 -- PRIVATE FUNCTION
76143 --         EventClass_141
76144 --
76145 ----------------------------------------
76146 --
76147 FUNCTION EventClass_141
76148        (p_application_id         IN NUMBER
76149        ,p_base_ledger_id         IN NUMBER
76150        ,p_target_ledger_id       IN NUMBER
76151        ,p_language               IN VARCHAR2
76152        ,p_currency_code          IN VARCHAR2
76153        ,p_sla_ledger_id          IN NUMBER
76154        ,p_pad_start_date         IN DATE
76155        ,p_pad_end_date           IN DATE
76156        ,p_primary_ledger_id      IN NUMBER)
76157 RETURN BOOLEAN IS
76158 --
76159 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'GUARANTEE_ALL';
76160 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'GUARANTEE';
76161 
76162 l_calculate_acctd_flag   VARCHAR2(1) :='N';
76163 l_calculate_g_l_flag     VARCHAR2(1) :='N';
76164 --
76165 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
76166 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
76167 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
76168 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
76169 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
76170 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
76171 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
76172 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
76173 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
76174 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
76175 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
76176 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
76177 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
76178 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
76179 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
76180 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
76181 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
76182 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
76183 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
76184 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
76185 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
76186 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
76187 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
76188 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
76189 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
76190 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
76191 
76195 l_last_event_id                        NUMBER;
76192 l_event_id                             NUMBER;
76193 l_previous_event_id                    NUMBER;
76194 l_first_event_id                       NUMBER;
76196 
76197 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
76198 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
76199 --
76200 --
76201 l_result                    BOOLEAN := TRUE;
76202 l_rows                      NUMBER  := 1000;
76203 l_event_type_name           VARCHAR2(80) := 'All';
76204 l_event_class_name          VARCHAR2(80) := 'Guarantee';
76205 l_description               VARCHAR2(4000);
76206 l_transaction_reversal      NUMBER;
76207 l_ae_header_id              NUMBER;
76208 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
76209 l_log_module                VARCHAR2(240);
76210 --
76211 l_acct_reversal_source      VARCHAR2(30);
76212 l_trx_reversal_source       VARCHAR2(30);
76213 
76214 l_continue_with_lines       BOOLEAN := TRUE;
76215 --
76216 l_acc_rev_gl_date_source    DATE;                      -- 4262811
76217 --
76218 type t_array_event_id is table of number index by binary_integer;
76219 
76220 l_rec_array_event                    t_rec_array_event;
76221 l_null_rec_array_event               t_rec_array_event;
76222 l_array_ae_header_id                 xla_number_array_type;
76223 l_actual_flag                        VARCHAR2(1) := NULL;
76224 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
76225 l_balance_type_code                  VARCHAR2(1) :=NULL;
76226 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
76227 
76228 --
76229 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
76230 --
76231 
76232 TYPE t_array_source_30 IS TABLE OF AR_BILL_TO_CUSTOMERS_S_V.BILL_CUST_ACCOUNT_ID%TYPE INDEX BY BINARY_INTEGER;
76233 TYPE t_array_source_31 IS TABLE OF AR_BILL_TO_SITE_USES_S_V.BILL_USES_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
76234 TYPE t_array_source_32 IS TABLE OF AR_TRANSACTIONS_S_V.XLA_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
76235 TYPE t_array_source_37 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_INVOICE_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
76236 TYPE t_array_source_83 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
76237 TYPE t_array_source_84 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
76238 TYPE t_array_source_85 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
76239 
76240 TYPE t_array_source_4 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
76241 TYPE t_array_source_33 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ACCOUNT_CLASS%TYPE INDEX BY BINARY_INTEGER;
76242 TYPE t_array_source_34 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ID%TYPE INDEX BY BINARY_INTEGER;
76243 TYPE t_array_source_35 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
76244 TYPE t_array_source_36 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_AMT%TYPE INDEX BY BINARY_INTEGER;
76245 TYPE t_array_source_38 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
76246 TYPE t_array_source_39 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
76247 TYPE t_array_source_40 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
76248 TYPE t_array_source_41 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
76249 
76250 l_array_source_30              t_array_source_30;
76251 l_array_source_31              t_array_source_31;
76252 l_array_source_32              t_array_source_32;
76253 l_array_source_37              t_array_source_37;
76254 l_array_source_83              t_array_source_83;
76255 l_array_source_84              t_array_source_84;
76256 l_array_source_85              t_array_source_85;
76257 
76258 l_array_source_4      t_array_source_4;
76259 l_array_source_33      t_array_source_33;
76260 l_array_source_34      t_array_source_34;
76261 l_array_source_35      t_array_source_35;
76262 l_array_source_36      t_array_source_36;
76263 l_array_source_38      t_array_source_38;
76264 l_array_source_39      t_array_source_39;
76265 l_array_source_40      t_array_source_40;
76266 l_array_source_41      t_array_source_41;
76267 
76268 --
76269 CURSOR header_cur
76270 IS
76271 SELECT /*+ leading(xet) cardinality(xet,1) */
76272 -- Event Class Code: GUARANTEE
76273     xet.entity_id
76274    ,xet.legal_entity_id
76275    ,xet.entity_code
76276    ,xet.transaction_number
76277    ,xet.event_id
76278    ,xet.event_class_code
76279    ,xet.event_type_code
76280    ,xet.event_number
76281    ,xet.event_date
76282    ,xet.transaction_date
76283    ,xet.reference_num_1
76284    ,xet.reference_num_2
76285    ,xet.reference_num_3
76286    ,xet.reference_num_4
76287    ,xet.reference_char_1
76288    ,xet.reference_char_2
76289    ,xet.reference_char_3
76290    ,xet.reference_char_4
76291    ,xet.reference_date_1
76292    ,xet.reference_date_2
76293    ,xet.reference_date_3
76294    ,xet.reference_date_4
76295    ,xet.event_created_by
76296    ,xet.budgetary_control_flag 
76297   , h1.BILL_CUST_ACCOUNT_ID    source_30
76298   , h2.BILL_USES_SITE_USE_ID    source_31
76299   , h5.XLA_PARTY_TYPE    source_32
76300   , h5.TRX_INVOICE_CURRENCY_CODE    source_37
76301   , h5.TRX_DOC_SEQUENCE_CATEGORY    source_83
76302   , h5.TRX_DOC_SEQUENCE_ID    source_84
76303   , h5.TRX_DOC_SEQUENCE_VALUE    source_85
76304   FROM xla_events_gt     xet 
76305   , AR_BILL_TO_CUSTOMERS_S_V  h1
76306   , AR_BILL_TO_SITE_USES_S_V  h2
76307   , AR_TRANSACTIONS_S_V  h5
76308  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
76309    and xet.event_class_code = C_EVENT_CLASS_CODE
76310    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
76311   AND h2.event_id  = h1.event_id
76315 ;
76312   AND h5.event_id  = h1.event_id
76313 
76314  ORDER BY event_id
76316 
76317 
76318 --
76319 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
76320 IS
76321 SELECT  /*+ leading(xet) cardinality(xet,1) */
76322 -- Event Class Code: GUARANTEE
76323     xet.entity_id
76324    ,xet.legal_entity_id
76325    ,xet.entity_code
76326    ,xet.transaction_number
76327    ,xet.event_id
76328    ,xet.event_class_code
76329    ,xet.event_type_code
76330    ,xet.event_number
76331    ,xet.event_date
76332    ,xet.transaction_date
76333    ,xet.reference_num_1
76334    ,xet.reference_num_2
76335    ,xet.reference_num_3
76336    ,xet.reference_num_4
76337    ,xet.reference_char_1
76338    ,xet.reference_char_2
76339    ,xet.reference_char_3
76340    ,xet.reference_char_4
76341    ,xet.reference_date_1
76342    ,xet.reference_date_2
76343    ,xet.reference_date_3
76344    ,xet.reference_date_4
76345    ,xet.event_created_by
76346    ,xet.budgetary_control_flag
76347  , l3.LINE_NUMBER  
76348   , l4.TRX_LINE_DIST_CCID    source_4
76349   , l4.TRX_LINE_DIST_ACCOUNT_CLASS    source_33
76350   , l4.TRX_LINE_DIST_ID    source_34
76351   , l4.TRX_DISTRIBUTION_TYPE    source_35
76352   , l4.TRX_LINE_DIST_AMT    source_36
76353   , l3.TRX_LINE_CUR_CONVERSION_DATE    source_38
76354   , l3.TRX_LINE_CUR_CONVERSION_RATE    source_39
76355   , l3.TRX_LINE_CUR_CONVERSION_TYPE    source_40
76356   , l3.TRX_LINE_ACCTD_AMT    source_41
76357   FROM xla_events_gt     xet 
76358   , AR_CUST_TRX_LINES_BASE_V  l3
76359   , AR_CUST_TRX_LINES_L_V  l4
76360  WHERE xet.event_id between x_first_event_id and x_last_event_id
76361    and xet.event_date between p_pad_start_date and p_pad_end_date
76362    and xet.event_class_code = C_EVENT_CLASS_CODE
76363    and xet.event_status_code <> 'N'   AND l3.event_id      = xet.event_id
76364   AND l4.event_id    = l3.event_id
76365   AND l4.line_number = l3.line_number
76366 ;
76367 
76368 --
76369 BEGIN
76370 IF g_log_enabled THEN
76371    l_log_module := C_DEFAULT_MODULE||'.EventClass_141';
76372 END IF;
76373 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
76374    trace
76375       (p_msg      => 'BEGIN of EventClass_141'
76376       ,p_level    => C_LEVEL_PROCEDURE
76377       ,p_module   => l_log_module);
76378 END IF;
76379 
76380 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
76381    trace
76382       (p_msg      => 'p_application_id = '||p_application_id||
76383                      ' - p_base_ledger_id = '||p_base_ledger_id||
76384                      ' - p_target_ledger_id  = '||p_target_ledger_id||
76385                      ' - p_language = '||p_language||
76386                      ' - p_currency_code = '||p_currency_code||
76387                      ' - p_sla_ledger_id = '||p_sla_ledger_id
76388       ,p_level    => C_LEVEL_STATEMENT
76389       ,p_module   => l_log_module);
76390 END IF;
76391 --
76392 -- initialze arrays
76393 --
76394 g_array_event.DELETE;
76395 l_rec_array_event := l_null_rec_array_event;
76396 --
76397 --------------------------------------
76398 -- 4262811 Initialze MPA Line Number
76399 --------------------------------------
76400 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
76401 
76402 --
76403 
76404 --
76405 OPEN header_cur;
76406 --
76407 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
76408    trace
76409    (p_msg      => 'SQL - FETCH header_cur'
76410    ,p_level    => C_LEVEL_STATEMENT
76411    ,p_module   => l_log_module);
76412 END IF;
76413 --
76414 LOOP
76415 FETCH header_cur BULK COLLECT INTO
76416         l_array_entity_id
76417       , l_array_legal_entity_id
76418       , l_array_entity_code
76419       , l_array_transaction_num
76420       , l_array_event_id
76421       , l_array_class_code
76422       , l_array_event_type
76423       , l_array_event_number
76424       , l_array_event_date
76425       , l_array_transaction_date
76426       , l_array_reference_num_1
76427       , l_array_reference_num_2
76428       , l_array_reference_num_3
76429       , l_array_reference_num_4
76430       , l_array_reference_char_1
76431       , l_array_reference_char_2
76432       , l_array_reference_char_3
76433       , l_array_reference_char_4
76434       , l_array_reference_date_1
76435       , l_array_reference_date_2
76436       , l_array_reference_date_3
76437       , l_array_reference_date_4
76438       , l_array_event_created_by
76439       , l_array_budgetary_control_flag 
76440       , l_array_source_30
76441       , l_array_source_31
76442       , l_array_source_32
76443       , l_array_source_37
76444       , l_array_source_83
76445       , l_array_source_84
76446       , l_array_source_85
76447       LIMIT l_rows;
76448 --
76449 IF (C_LEVEL_EVENT >= g_log_level) THEN
76450    trace
76451    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
76452    ,p_level    => C_LEVEL_EVENT
76453    ,p_module   => l_log_module);
76454 END IF;
76455 --
76456 EXIT WHEN l_array_entity_id.COUNT = 0;
76457 
76458 -- initialize arrays
76459 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
76460 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
76461 
76462 --
76463 -- Bug 4458708
76464 --
76465 XLA_AE_LINES_PKG.g_LineNumber := 0;
76466 
76467 
76468 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
76469 g_last_hdr_idx := l_array_event_id.LAST;
76470 --
76471 -- loop for the headers. Each iteration is for each header extract row
76472 -- fetched in header cursor
76473 --
76474 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
76475 
76476 --
76480    (p_application_id           => p_application_id
76477 -- set event info as cache for other routines to refer event attributes
76478 --
76479 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
76481    ,p_primary_ledger_id        => p_primary_ledger_id
76482    ,p_base_ledger_id           => p_base_ledger_id
76483    ,p_target_ledger_id         => p_target_ledger_id
76484    ,p_entity_id                => l_array_entity_id(hdr_idx)
76485    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
76486    ,p_entity_code              => l_array_entity_code(hdr_idx)
76487    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
76488    ,p_event_id                 => l_array_event_id(hdr_idx)
76489    ,p_event_class_code         => l_array_class_code(hdr_idx)
76490    ,p_event_type_code          => l_array_event_type(hdr_idx)
76491    ,p_event_number             => l_array_event_number(hdr_idx)
76492    ,p_event_date               => l_array_event_date(hdr_idx)
76493    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
76494    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
76495    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
76496    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
76497    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
76498    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
76499    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
76500    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
76501    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
76502    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
76503    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
76504    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
76505    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
76506    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
76507    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
76508 
76509 --
76510 -- set the status of entry to C_VALID (0)
76511 --
76512 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
76513 
76514 --
76515 -- initialize a row for ae header
76516 --
76517 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
76518 
76519 l_event_id := l_array_event_id(hdr_idx);
76520 
76521 --
76522 -- storing the hdr_idx for event. May be used by line cursor.
76523 --
76524 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
76525 
76526 --
76527 -- store sources from header extract. This can be improved to
76528 -- store only those sources from header extract that may be used in lines
76529 --
76530 
76531 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
76532 g_array_event(l_event_id).array_value_num('source_31') := l_array_source_31(hdr_idx);
76533 g_array_event(l_event_id).array_value_char('source_32') := l_array_source_32(hdr_idx);
76534 g_array_event(l_event_id).array_value_char('source_37') := l_array_source_37(hdr_idx);
76535 g_array_event(l_event_id).array_value_char('source_83') := l_array_source_83(hdr_idx);
76536 g_array_event(l_event_id).array_value_num('source_84') := l_array_source_84(hdr_idx);
76537 g_array_event(l_event_id).array_value_num('source_85') := l_array_source_85(hdr_idx);
76538 
76539 --
76540 -- initilaize the status of ae headers for diffrent balance types
76541 -- the status is initialised to C_NOT_CREATED (2)
76542 --
76543 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
76544 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
76545 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
76546 
76547 --
76548 -- call api to validate and store accounting attributes for header
76549 --
76550 
76551 ------------------------------------------------------------
76552 -- Accrual Reversal : to get date for Standard Source (NONE)
76553 ------------------------------------------------------------
76554 l_acc_rev_gl_date_source := NULL;
76555 
76556      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
76557       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_83');
76558      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
76559       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_84');
76560      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
76561       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_85');
76562      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
76563       l_rec_acct_attrs.array_date_value(4) := 
76564 xla_ae_sources_pkg.GetSystemSourceDate(
76565    p_source_code           => 'XLA_EVENT_DATE'
76566  , p_source_type_code      => 'Y'
76567  , p_source_application_id =>  602
76568 );
76569 
76570 
76571 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
76572 
76573 XLA_AE_HEADER_PKG.SetJeCategoryName;
76574 
76575 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
76576 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
76577 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
76578 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
76579 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
76580 
76581 
76582 -- No header level analytical criteria
76583 
76584 --
76585 --accounting attribute enhancement, bug 3612931
76586 --
76587 l_trx_reversal_source := SUBSTR(NULL, 1,30);
76588 
76589 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
76590    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
76594       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
76591 
76592    xla_accounting_err_pkg.build_message
76593       (p_appli_s_name            => 'XLA'
76595       ,p_token_1                 => 'ACCT_ATTR_NAME'
76596       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
76597       ,p_token_2                 => 'PRODUCT_NAME'
76598       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
76599       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
76600       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
76601       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
76602 
76603 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
76604    --
76605    -- following sets the accounting attributes needed to reverse
76606    -- accounting for a distributeion
76607    --
76608    xla_ae_lines_pkg.SetTrxReversalAttrs
76609       (p_event_id              => l_event_id
76610       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
76611       ,p_trx_reversal_source   => l_trx_reversal_source);
76612 
76613 END IF;
76614 
76615 
76616 ----------------------------------------------------------------
76617 -- 4262811 -  update the header statuses to invalid in need be
76618 ----------------------------------------------------------------
76619 --
76620 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
76621 
76622 
76623   -----------------------------------------------
76624   -- No accrual reversal for the event class/type
76625   -----------------------------------------------
76626 ----------------------------------------------------------------
76627 
76628 --
76629 -- this ends the header loop iteration for one bulk fetch
76630 --
76631 END LOOP;
76632 
76633 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
76634 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
76635 
76636 --
76637 -- insert dummy rows into lines gt table that were created due to
76638 -- transaction reversals
76639 --
76640 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
76641    l_result := XLA_AE_LINES_PKG.InsertLines;
76642 END IF;
76643 
76644 --
76645 -- reset the temp_line_num for each set of events fetched from header
76646 -- cursor rather than doing it for each new event in line cursor
76647 -- Bug 3939231
76648 --
76649 xla_ae_lines_pkg.g_temp_line_num := 0;
76650 
76651 
76652 
76653 --
76654 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
76655 --
76656 --
76657 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
76658 
76659       trace
76660          (p_msg      => 'SQL - FETCH line_cur'
76661          ,p_level    => C_LEVEL_STATEMENT
76662          ,p_module   => l_log_module);
76663 
76664 END IF;
76665 --
76666 --
76667 LOOP
76668   --
76669   FETCH line_cur BULK COLLECT INTO
76670         l_array_entity_id
76671       , l_array_legal_entity_id
76672       , l_array_entity_code
76673       , l_array_transaction_num
76674       , l_array_event_id
76675       , l_array_class_code
76676       , l_array_event_type
76677       , l_array_event_number
76678       , l_array_event_date
76679       , l_array_transaction_date
76680       , l_array_reference_num_1
76681       , l_array_reference_num_2
76682       , l_array_reference_num_3
76683       , l_array_reference_num_4
76684       , l_array_reference_char_1
76685       , l_array_reference_char_2
76686       , l_array_reference_char_3
76687       , l_array_reference_char_4
76688       , l_array_reference_date_1
76689       , l_array_reference_date_2
76690       , l_array_reference_date_3
76691       , l_array_reference_date_4
76692       , l_array_event_created_by
76693       , l_array_budgetary_control_flag
76694       , l_array_extract_line_num 
76695       , l_array_source_4
76696       , l_array_source_33
76697       , l_array_source_34
76698       , l_array_source_35
76699       , l_array_source_36
76700       , l_array_source_38
76701       , l_array_source_39
76702       , l_array_source_40
76703       , l_array_source_41
76704       LIMIT l_rows;
76705 
76706   --
76707   IF (C_LEVEL_EVENT >= g_log_level) THEN
76708             trace
76709                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
76710                ,p_level    => C_LEVEL_EVENT
76711                ,p_module   => l_log_module);
76712   END IF;
76713   --
76714   EXIT WHEN l_array_entity_id.count = 0;
76715 
76716   XLA_AE_LINES_PKG.g_rec_lines := null;
76717 
76718 --
76719 -- Bug 4458708
76720 --
76721 XLA_AE_LINES_PKG.g_LineNumber := 0;
76722 --
76723 --
76724 
76725 FOR Idx IN 1..l_array_event_id.count LOOP
76726    --
76727    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
76728    --
76729    l_event_id := l_array_event_id(idx);  -- 5648433
76730 
76731    --
76732    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
76733    --
76734 
76735    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
76736              (g_array_event(l_event_id).array_value_num('header_index'))
76737          ,'N'
76738          ) <> 'Y'
76739    THEN
76740       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
76741          trace
76742             (p_msg      => 'Trancaction revesal option is not Y '
76743             ,p_level    => C_LEVEL_STATEMENT
76744             ,p_module   => l_log_module);
76745       END IF;
76746 
76747 --
76751 --
76748 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
76749 --
76750 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
76752 -- set event info as cache for other routines to refer event attributes
76753 --
76754 
76755 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
76756    l_previous_event_id := l_event_id;
76757 
76758    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
76759       (p_application_id           => p_application_id
76760       ,p_primary_ledger_id        => p_primary_ledger_id
76761       ,p_base_ledger_id           => p_base_ledger_id
76762       ,p_target_ledger_id         => p_target_ledger_id
76763       ,p_entity_id                => l_array_entity_id(Idx)
76764       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
76765       ,p_entity_code              => l_array_entity_code(Idx)
76766       ,p_transaction_num          => l_array_transaction_num(Idx)
76767       ,p_event_id                 => l_array_event_id(Idx)
76768       ,p_event_class_code         => l_array_class_code(Idx)
76769       ,p_event_type_code          => l_array_event_type(Idx)
76770       ,p_event_number             => l_array_event_number(Idx)
76771       ,p_event_date               => l_array_event_date(Idx)
76772       ,p_transaction_date         => l_array_transaction_date(Idx)
76773       ,p_reference_num_1          => l_array_reference_num_1(Idx)
76774       ,p_reference_num_2          => l_array_reference_num_2(Idx)
76775       ,p_reference_num_3          => l_array_reference_num_3(Idx)
76776       ,p_reference_num_4          => l_array_reference_num_4(Idx)
76777       ,p_reference_char_1         => l_array_reference_char_1(Idx)
76778       ,p_reference_char_2         => l_array_reference_char_2(Idx)
76779       ,p_reference_char_3         => l_array_reference_char_3(Idx)
76780       ,p_reference_char_4         => l_array_reference_char_4(Idx)
76781       ,p_reference_date_1         => l_array_reference_date_1(Idx)
76782       ,p_reference_date_2         => l_array_reference_date_2(Idx)
76783       ,p_reference_date_3         => l_array_reference_date_3(Idx)
76784       ,p_reference_date_4         => l_array_reference_date_4(Idx)
76785       ,p_event_created_by         => l_array_event_created_by(Idx)
76786       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
76787        --
76788 END IF;
76789 
76790 
76791 
76792 --
76793 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
76794 
76795 l_acct_reversal_source := SUBSTR(NULL, 1,30);
76796 
76797 IF l_continue_with_lines THEN
76798    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
76799       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
76800 
76801       xla_accounting_err_pkg.build_message
76802          (p_appli_s_name            => 'XLA'
76803          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
76804          ,p_token_1                 => 'LINE_NUMBER'
76805          ,p_value_1                 => l_array_extract_line_num(Idx)
76806          ,p_token_2                 => 'PRODUCT_NAME'
76807          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
76808          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
76809          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
76810          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
76811 
76812    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
76813       --
76814       -- following sets the accounting attributes needed to reverse
76815       -- accounting for a distributeion
76816       --
76817 
76818       --
76819       -- 5217187
76820       --
76821       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
76822       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
76823                                        g_array_event(l_event_id).array_value_num('header_index'));
76824       --
76825       --
76826 
76827       -- No reversal code generated
76828 
76829       xla_ae_lines_pkg.SetAcctReversalAttrs
76830          (p_event_id             => l_event_id
76831          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
76832          ,p_calculate_acctd_flag => l_calculate_acctd_flag
76833          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
76834    END IF;
76835 
76836    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
76837        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
76838 
76839 --
76840 AcctLineType_77 (
76841  p_application_id  => p_application_id
76842  ,p_event_id     => l_event_id
76843  ,p_calculate_acctd_flag => l_calculate_acctd_flag
76844  ,p_calculate_g_l_flag => l_calculate_g_l_flag
76845  ,p_actual_flag => l_actual_flag
76846  ,p_balance_type_code => l_balance_type_code
76847  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
76848  
76849  , p_source_4 => l_array_source_4(Idx)
76850  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
76851  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
76852  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
76853  , p_source_33 => l_array_source_33(Idx)
76854  , p_source_34 => l_array_source_34(Idx)
76855  , p_source_35 => l_array_source_35(Idx)
76856  , p_source_36 => l_array_source_36(Idx)
76857  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
76858  , p_source_38 => l_array_source_38(Idx)
76859  , p_source_39 => l_array_source_39(Idx)
76860  , p_source_40 => l_array_source_40(Idx)
76861  , p_source_41 => l_array_source_41(Idx)
76862  );
76863 If(l_balance_type_code = 'A') THEN
76864   l_actual_gain_loss_ref := l_gain_or_loss_ref;
76865 END IF;
76866 
76867 --
76868 
76869 
76870 --
76871 AcctLineType_78 (
76872  p_application_id  => p_application_id
76876  ,p_actual_flag => l_actual_flag
76873  ,p_event_id     => l_event_id
76874  ,p_calculate_acctd_flag => l_calculate_acctd_flag
76875  ,p_calculate_g_l_flag => l_calculate_g_l_flag
76877  ,p_balance_type_code => l_balance_type_code
76878  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
76879  
76880  , p_source_4 => l_array_source_4(Idx)
76881  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
76882  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
76883  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
76884  , p_source_33 => l_array_source_33(Idx)
76885  , p_source_34 => l_array_source_34(Idx)
76886  , p_source_35 => l_array_source_35(Idx)
76887  , p_source_36 => l_array_source_36(Idx)
76888  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
76889  , p_source_38 => l_array_source_38(Idx)
76890  , p_source_39 => l_array_source_39(Idx)
76891  , p_source_40 => l_array_source_40(Idx)
76892  , p_source_41 => l_array_source_41(Idx)
76893  );
76894 If(l_balance_type_code = 'A') THEN
76895   l_actual_gain_loss_ref := l_gain_or_loss_ref;
76896 END IF;
76897 
76898 --
76899 
76900       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
76901       -- or secondary ledger that has different currency with primary
76902       -- or alc that is calculated by sla
76903       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
76904             (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'))
76905 
76906 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
76907 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
76908           AND (l_actual_flag = 'A')) THEN
76909         XLA_AE_LINES_PKG.CreateGainOrLossLines(
76910           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
76911          ,p_application_id   => p_application_id
76912          ,p_amb_context_code => 'DEFAULT'
76913          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
76914          ,p_event_class_code => C_EVENT_CLASS_CODE
76915          ,p_event_type_code  => C_EVENT_TYPE_CODE
76916          
76917          ,p_gain_ccid        => -1
76918          ,p_loss_ccid        => -1
76919 
76920          ,p_actual_flag      => l_actual_flag
76921          ,p_enc_flag         => null
76922          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
76923          ,p_enc_g_l_ref      => null
76924          );
76925       END IF;
76926    END IF;
76927 END IF;
76928 
76929    ELSE
76930       --
76931       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
76932       --
76933       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
76934          trace
76935             (p_msg      => 'Trancaction revesal option is Y'
76936             ,p_level    => C_LEVEL_STATEMENT
76937             ,p_module   => l_log_module);
76938       END IF;
76939    END IF;
76940 
76941 END LOOP;
76942 l_result := XLA_AE_LINES_PKG.InsertLines ;
76943 end loop;
76944 close line_cur;
76945 
76946 
76947 --
76948 -- insert headers into xla_ae_headers_gt table
76949 --
76950 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
76951 
76952 -- insert into errors table here.
76953 
76954 END LOOP;
76955 
76956 --
76957 -- 4865292
76958 --
76959 -- Compare g_hdr_extract_count with event count in
76960 -- CreateHeadersAndLines.
76961 --
76962 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
76963 
76964 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
76965    trace (p_msg     => '# rows extracted from header extract objects '
76966                     || ' (running total): '
76967                     || g_hdr_extract_count
76968          ,p_level   => C_LEVEL_STATEMENT
76969          ,p_module  => l_log_module);
76970 END IF;
76971 
76972 CLOSE header_cur;
76973 --
76974 
76975 --
76976 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
76977    trace
76978       (p_msg      => 'END of EventClass_141'
76979       ,p_level    => C_LEVEL_PROCEDURE
76980       ,p_module   => l_log_module);
76981 END IF;
76982 --
76983 RETURN l_result;
76984 EXCEPTION
76985 WHEN xla_exceptions_pkg.application_exception THEN
76986    
76987 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
76988 
76989    
76990 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
76991 
76992    RAISE;
76993 
76994 WHEN NO_DATA_FOUND THEN
76995 
76996 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
76997 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
76998 
76999 FOR header_record IN header_cur
77000 LOOP
77001     l_array_header_events(header_record.event_id) := header_record.event_id;
77002 END LOOP;
77003 
77004 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
77005 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
77006 
77007 fnd_file.put_line(fnd_file.LOG, '                    ');
77008 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
77009 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
77010 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
77011 
77012 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
77013 LOOP
77014 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
77015 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
77019 
77016         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
77017 	END IF;
77018 END LOOP;
77020 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
77021 fnd_file.put_line(fnd_file.LOG, '                    ');
77022 
77023 
77024 xla_exceptions_pkg.raise_message
77025       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_141');
77026 
77027 
77028 WHEN OTHERS THEN
77029    xla_exceptions_pkg.raise_message
77030       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_141');
77031 END EventClass_141;
77032 --
77033 
77034 ---------------------------------------
77035 --
77036 -- PRIVATE PROCEDURE
77037 --         insert_sources_142
77038 --
77039 ----------------------------------------
77040 --
77041 PROCEDURE insert_sources_142(
77042                                 p_target_ledger_id       IN NUMBER
77043                               , p_language               IN VARCHAR2
77044                               , p_sla_ledger_id          IN NUMBER
77045                               , p_pad_start_date         IN DATE
77046                               , p_pad_end_date           IN DATE
77047                          )
77048 IS
77049 
77050 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'INVOICE_ALL';
77051 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'INVOICE';
77052 p_apps_owner                   VARCHAR2(30);
77053 l_log_module                   VARCHAR2(240);
77054 BEGIN
77055 IF g_log_enabled THEN
77056       l_log_module := C_DEFAULT_MODULE||'.insert_sources_142';
77057 END IF;
77058 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
77059 
77060       trace
77061          (p_msg      => 'BEGIN of insert_sources_142'
77062          ,p_level    => C_LEVEL_PROCEDURE
77063          ,p_module   => l_log_module);
77064 
77065 END IF;
77066 
77067 -- select APPS owner
77068 SELECT oracle_username
77069   INTO p_apps_owner
77070   FROM fnd_oracle_userid
77071  WHERE read_only_flag = 'U'
77072 ;
77073 
77074 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
77075       trace
77076          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
77077                         ' - p_language = '||p_language||
77078                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
77079                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
77080                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
77081                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
77082          ,p_level    => C_LEVEL_STATEMENT
77083          ,p_module   => l_log_module);
77084 END IF;
77085 
77086 
77087 --
77088 INSERT INTO xla_diag_sources --hdr2
77089 (
77090         event_id
77091       , ledger_id
77092       , sla_ledger_id
77093       , description_language
77094       , object_name
77095       , object_type_code
77096       , line_number
77097       , source_application_id
77098       , source_type_code
77099       , source_code
77100       , source_value
77101       , source_meaning
77102       , created_by
77103       , creation_date
77104       , last_update_date
77105       , last_updated_by
77106       , last_update_login
77107       , program_update_date
77108       , program_application_id
77109       , program_id
77110       , request_id
77111 )
77112 SELECT
77113         event_id
77114       , p_target_ledger_id
77115       , p_sla_ledger_id
77116       , p_language
77117       , object_name
77118       , object_type_code
77119       , line_number
77120       , source_application_id
77121       , source_type_code
77122       , source_code
77123       , SUBSTR(source_value ,1,1996)
77124       , SUBSTR(source_meaning ,1,200)
77125       , xla_environment_pkg.g_Usr_Id
77126       , TRUNC(SYSDATE)
77127       , TRUNC(SYSDATE)
77128       , xla_environment_pkg.g_Usr_Id
77129       , xla_environment_pkg.g_Login_Id
77130       , TRUNC(SYSDATE)
77131       , xla_environment_pkg.g_Prog_Appl_Id
77132       , xla_environment_pkg.g_Prog_Id
77133       , xla_environment_pkg.g_Req_Id
77134   FROM (
77135        SELECT xet.event_id                  event_id
77136             , 0                          line_number
77137             , CASE r
77138                WHEN 1 THEN 'AR_BILL_TO_CUSTOMERS_S_V' 
77139                 WHEN 2 THEN 'AR_TRANSACTIONS_S_V' 
77140                 WHEN 3 THEN 'AR_BILL_TO_CUSTOMERS_S_V' 
77141                 WHEN 4 THEN 'AR_BILL_TO_SITE_USES_S_V' 
77142                 WHEN 5 THEN 'AR_TRANSACTIONS_S_V' 
77143                 WHEN 6 THEN 'AR_TRANSACTIONS_S_V' 
77144                 WHEN 7 THEN 'AR_TRANSACTIONS_S_V' 
77145                 WHEN 8 THEN 'AR_TRANSACTIONS_S_V' 
77146                 WHEN 9 THEN 'AR_TRANSACTIONS_S_V' 
77147                 WHEN 10 THEN 'AR_TRANSACTIONS_S_V' 
77148                 
77149                ELSE null
77150               END                           object_name
77151             , CASE r
77152                 WHEN 1 THEN 'HEADER' 
77153                 WHEN 2 THEN 'HEADER' 
77154                 WHEN 3 THEN 'HEADER' 
77155                 WHEN 4 THEN 'HEADER' 
77156                 WHEN 5 THEN 'HEADER' 
77157                 WHEN 6 THEN 'HEADER' 
77158                 WHEN 7 THEN 'HEADER' 
77159                 WHEN 8 THEN 'HEADER' 
77160                 WHEN 9 THEN 'HEADER' 
77161                 WHEN 10 THEN 'HEADER' 
77162                 
77163                 ELSE null
77164               END                           object_type_code
77165             , CASE r
77166                 WHEN 1 THEN '222' 
77167                 WHEN 2 THEN '222' 
77168                 WHEN 3 THEN '222' 
77169                 WHEN 4 THEN '222' 
77173                 WHEN 8 THEN '222' 
77170                 WHEN 5 THEN '222' 
77171                 WHEN 6 THEN '222' 
77172                 WHEN 7 THEN '222' 
77174                 WHEN 9 THEN '222' 
77175                 WHEN 10 THEN '222' 
77176                 
77177                 ELSE null
77178               END                           source_application_id
77179             , 'S'             source_type_code
77180             , CASE r
77181                 WHEN 1 THEN 'BILL_CUSTOMER_CLASS_CODE' 
77182                 WHEN 2 THEN 'TRX_RECEIVABLE_CCID' 
77183                 WHEN 3 THEN 'BILL_CUST_ACCOUNT_ID' 
77184                 WHEN 4 THEN 'BILL_USES_SITE_USE_ID' 
77185                 WHEN 5 THEN 'XLA_PARTY_TYPE' 
77186                 WHEN 6 THEN 'TRX_INVOICE_CURRENCY_CODE' 
77187                 WHEN 7 THEN 'TRX_INVOICING_RULE_ID' 
77188                 WHEN 8 THEN 'TRX_DOC_SEQUENCE_CATEGORY' 
77189                 WHEN 9 THEN 'TRX_DOC_SEQUENCE_ID' 
77190                 WHEN 10 THEN 'TRX_DOC_SEQUENCE_VALUE' 
77191                 
77192                 ELSE null
77193               END                           source_code
77194             , CASE r
77195                 WHEN 1 THEN TO_CHAR(h1.BILL_CUSTOMER_CLASS_CODE)
77196                 WHEN 2 THEN TO_CHAR(h5.TRX_RECEIVABLE_CCID)
77197                 WHEN 3 THEN TO_CHAR(h1.BILL_CUST_ACCOUNT_ID)
77198                 WHEN 4 THEN TO_CHAR(h2.BILL_USES_SITE_USE_ID)
77199                 WHEN 5 THEN TO_CHAR(h5.XLA_PARTY_TYPE)
77200                 WHEN 6 THEN TO_CHAR(h5.TRX_INVOICE_CURRENCY_CODE)
77201                 WHEN 7 THEN TO_CHAR(h5.TRX_INVOICING_RULE_ID)
77202                 WHEN 8 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_CATEGORY)
77203                 WHEN 9 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_ID)
77204                 WHEN 10 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_VALUE)
77205                 
77206                 ELSE null
77207               END                           source_value
77208             , null              source_meaning
77209          FROM xla_events_gt     xet  
77210       , AR_BILL_TO_CUSTOMERS_S_V  h1
77211       , AR_BILL_TO_SITE_USES_S_V  h2
77212       , AR_TRANSACTIONS_S_V  h5
77213              ,(select rownum r from all_objects where rownum <= 10 and owner = p_apps_owner)
77214          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
77215            AND xet.event_class_code = C_EVENT_CLASS_CODE
77216               AND h1.event_id = xet.event_id
77217   AND h2.event_id  = h1.event_id
77218   AND h5.event_id  = h1.event_id
77219 
77220 )
77221 ;
77222 --
77223 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
77224 
77225       trace
77226          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
77227          ,p_level    => C_LEVEL_STATEMENT
77228          ,p_module   => l_log_module);
77229 
77230 END IF;
77231 --
77232 
77233 
77234 
77235 --
77236 INSERT INTO xla_diag_sources  --line2
77237 (
77238         event_id
77239       , ledger_id
77240       , sla_ledger_id
77241       , description_language
77242       , object_name
77243       , object_type_code
77244       , line_number
77245       , source_application_id
77246       , source_type_code
77247       , source_code
77248       , source_value
77249       , source_meaning
77250       , created_by
77251       , creation_date
77252       , last_update_date
77253       , last_updated_by
77254       , last_update_login
77255       , program_update_date
77256       , program_application_id
77257       , program_id
77258       , request_id
77259 )
77260 SELECT  event_id
77261       , p_target_ledger_id
77262       , p_sla_ledger_id
77263       , p_language
77264       , object_name
77265       , object_type_code
77266       , line_number
77267       , source_application_id
77268       , source_type_code
77269       , source_code
77270       , SUBSTR(source_value,1,1996)
77271       , SUBSTR(source_meaning ,1,200)
77272       , xla_environment_pkg.g_Usr_Id
77273       , TRUNC(SYSDATE)
77274       , TRUNC(SYSDATE)
77275       , xla_environment_pkg.g_Usr_Id
77276       , xla_environment_pkg.g_Login_Id
77277       , TRUNC(SYSDATE)
77278       , xla_environment_pkg.g_Prog_Appl_Id
77279       , xla_environment_pkg.g_Prog_Id
77280       , xla_environment_pkg.g_Req_Id
77281   FROM (
77282        SELECT xet.event_id                  event_id
77283             , l4.line_number                 line_number
77284             , CASE r
77285                WHEN 1 THEN 'AR_CUST_TRX_LINES_L_V' 
77286                 WHEN 2 THEN 'FV_XLA_AR_REF_V' 
77287                 WHEN 3 THEN 'AR_CUST_TRX_LINES_L_V' 
77288                 WHEN 4 THEN 'AR_CUST_TRX_LINES_L_V' 
77289                 WHEN 5 THEN 'AR_CUST_TRX_LINES_L_V' 
77290                 WHEN 6 THEN 'AR_CUST_TRX_LINES_L_V' 
77291                 WHEN 7 THEN 'AR_CUST_TRX_LINES_BASE_V' 
77292                 WHEN 8 THEN 'AR_CUST_TRX_LINES_BASE_V' 
77293                 WHEN 9 THEN 'AR_CUST_TRX_LINES_BASE_V' 
77294                 WHEN 10 THEN 'AR_CUST_TRX_LINES_BASE_V' 
77295                 WHEN 11 THEN 'AR_CUST_TRX_LINES_L_V' 
77296                 WHEN 12 THEN 'FV_XLA_AR_REF_V' 
77297                 WHEN 13 THEN 'AR_CUST_TRX_LINES_BASE_V' 
77298                 
77299                ELSE null
77300               END                           object_name
77301             , CASE r
77302                 WHEN 1 THEN 'LINE' 
77303                 WHEN 2 THEN 'LINE' 
77304                 WHEN 3 THEN 'LINE' 
77305                 WHEN 4 THEN 'LINE' 
77306                 WHEN 5 THEN 'LINE' 
77307                 WHEN 6 THEN 'LINE' 
77308                 WHEN 7 THEN 'LINE' 
77309                 WHEN 8 THEN 'LINE' 
77310                 WHEN 9 THEN 'LINE' 
77311                 WHEN 10 THEN 'LINE' 
77312                 WHEN 11 THEN 'LINE' 
77316                 ELSE null
77313                 WHEN 12 THEN 'LINE' 
77314                 WHEN 13 THEN 'LINE' 
77315                 
77317               END                           object_type_code
77318             , CASE r
77319                 WHEN 1 THEN '222' 
77320                 WHEN 2 THEN '8901' 
77321                 WHEN 3 THEN '222' 
77322                 WHEN 4 THEN '222' 
77323                 WHEN 5 THEN '222' 
77324                 WHEN 6 THEN '222' 
77325                 WHEN 7 THEN '222' 
77326                 WHEN 8 THEN '222' 
77327                 WHEN 9 THEN '222' 
77328                 WHEN 10 THEN '222' 
77329                 WHEN 11 THEN '222' 
77330                 WHEN 12 THEN '8901' 
77331                 WHEN 13 THEN '222' 
77332                 
77333                 ELSE null
77334               END                           source_application_id
77335             , 'S'             source_type_code
77336             , CASE r
77337                 WHEN 1 THEN 'TRX_LINE_DIST_CCID' 
77338                 WHEN 2 THEN 'FEDERAL_FUND_CATEGORY' 
77339                 WHEN 3 THEN 'TRX_LINE_DIST_ACCOUNT_CLASS' 
77340                 WHEN 4 THEN 'TRX_LINE_DIST_ID' 
77341                 WHEN 5 THEN 'TRX_DISTRIBUTION_TYPE' 
77342                 WHEN 6 THEN 'TRX_LINE_DIST_AMT' 
77343                 WHEN 7 THEN 'TRX_LINE_CUR_CONVERSION_DATE' 
77344                 WHEN 8 THEN 'TRX_LINE_CUR_CONVERSION_RATE' 
77345                 WHEN 9 THEN 'TRX_LINE_CUR_CONVERSION_TYPE' 
77346                 WHEN 10 THEN 'TRX_LINE_ACCTD_AMT' 
77347                 WHEN 11 THEN 'TRX_TAX_LINE_ID' 
77348                 WHEN 12 THEN 'FEDERAL_ACCOUNT_VALID_FLAG' 
77349                 WHEN 13 THEN 'ROUNDING_CORRECTION_FLAG' 
77350                 
77351                 ELSE null
77352               END                           source_code
77353             , CASE r
77354                 WHEN 1 THEN TO_CHAR(l4.TRX_LINE_DIST_CCID)
77355                 WHEN 2 THEN TO_CHAR(l6.FEDERAL_FUND_CATEGORY)
77356                 WHEN 3 THEN TO_CHAR(l4.TRX_LINE_DIST_ACCOUNT_CLASS)
77357                 WHEN 4 THEN TO_CHAR(l4.TRX_LINE_DIST_ID)
77358                 WHEN 5 THEN TO_CHAR(l4.TRX_DISTRIBUTION_TYPE)
77359                 WHEN 6 THEN TO_CHAR(l4.TRX_LINE_DIST_AMT)
77360                 WHEN 7 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_DATE)
77361                 WHEN 8 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_RATE)
77362                 WHEN 9 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_TYPE)
77363                 WHEN 10 THEN TO_CHAR(l3.TRX_LINE_ACCTD_AMT)
77364                 WHEN 11 THEN TO_CHAR(l4.TRX_TAX_LINE_ID)
77365                 WHEN 12 THEN TO_CHAR(l6.FEDERAL_ACCOUNT_VALID_FLAG)
77366                 WHEN 13 THEN TO_CHAR(l3.ROUNDING_CORRECTION_FLAG)
77367                 
77368                 ELSE null
77369               END                           source_value
77370             , null              source_meaning
77371          FROM  xla_events_gt     xet  
77372         , AR_CUST_TRX_LINES_BASE_V  l3
77373         , AR_CUST_TRX_LINES_L_V  l4
77374         , FV_XLA_AR_REF_V  l6
77375             , (select rownum r from all_objects where rownum <= 13 and owner = p_apps_owner)
77376         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
77377           AND xet.event_class_code = C_EVENT_CLASS_CODE
77378             AND l3.event_id          = xet.event_id
77379   AND l4.event_id    = l3.event_id
77380   AND l4.line_number = l3.line_number
77381  AND l6.federal_event_id   (+) =  l4.event_id  and l6.federal_line_number   (+) =  l4.line_number
77382 )
77383 ;
77384 --
77385 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
77386 
77387       trace
77388          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
77389          ,p_level    => C_LEVEL_STATEMENT
77390          ,p_module   => l_log_module);
77391 
77392 END IF;
77393 
77394 
77395 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
77396       trace
77397          (p_msg      => 'END of insert_sources_142'
77398          ,p_level    => C_LEVEL_PROCEDURE
77399          ,p_module   => l_log_module);
77400 END IF;
77401 EXCEPTION
77402   WHEN xla_exceptions_pkg.application_exception THEN
77403       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
77404             trace
77405                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
77406                ,p_level    => C_LEVEL_EXCEPTION
77407                ,p_module   => l_log_module);
77408       END IF;
77409       RAISE;
77410   WHEN OTHERS THEN
77411       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
77412             trace
77413                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
77414                ,p_level    => C_LEVEL_EXCEPTION
77415                ,p_module   => l_log_module);
77416        END IF;
77417        xla_exceptions_pkg.raise_message
77418            (p_location => 'XLA_00222_AAD_S_000006_PKG.insert_sources_142');
77419 END insert_sources_142;
77420 --
77421 
77422 ---------------------------------------
77423 --
77424 -- PRIVATE FUNCTION
77425 --         EventClass_142
77426 --
77427 ----------------------------------------
77428 --
77429 FUNCTION EventClass_142
77430        (p_application_id         IN NUMBER
77431        ,p_base_ledger_id         IN NUMBER
77432        ,p_target_ledger_id       IN NUMBER
77433        ,p_language               IN VARCHAR2
77434        ,p_currency_code          IN VARCHAR2
77435        ,p_sla_ledger_id          IN NUMBER
77436        ,p_pad_start_date         IN DATE
77437        ,p_pad_end_date           IN DATE
77438        ,p_primary_ledger_id      IN NUMBER)
77439 RETURN BOOLEAN IS
77440 --
77441 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'INVOICE_ALL';
77442 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'INVOICE';
77443 
77444 l_calculate_acctd_flag   VARCHAR2(1) :='N';
77448 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
77445 l_calculate_g_l_flag     VARCHAR2(1) :='N';
77446 --
77447 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
77449 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
77450 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
77451 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
77452 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
77453 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
77454 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
77455 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
77456 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
77457 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
77458 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
77459 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
77460 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
77461 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
77462 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
77463 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
77464 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
77465 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
77466 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
77467 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
77468 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
77469 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
77470 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
77471 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
77472 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
77473 
77474 l_event_id                             NUMBER;
77475 l_previous_event_id                    NUMBER;
77476 l_first_event_id                       NUMBER;
77477 l_last_event_id                        NUMBER;
77478 
77479 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
77480 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
77481 --
77482 --
77483 l_result                    BOOLEAN := TRUE;
77484 l_rows                      NUMBER  := 1000;
77485 l_event_type_name           VARCHAR2(80) := 'All';
77486 l_event_class_name          VARCHAR2(80) := 'Invoice';
77487 l_description               VARCHAR2(4000);
77488 l_transaction_reversal      NUMBER;
77489 l_ae_header_id              NUMBER;
77490 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
77491 l_log_module                VARCHAR2(240);
77492 --
77493 l_acct_reversal_source      VARCHAR2(30);
77494 l_trx_reversal_source       VARCHAR2(30);
77495 
77496 l_continue_with_lines       BOOLEAN := TRUE;
77497 --
77498 l_acc_rev_gl_date_source    DATE;                      -- 4262811
77499 --
77500 type t_array_event_id is table of number index by binary_integer;
77501 
77502 l_rec_array_event                    t_rec_array_event;
77503 l_null_rec_array_event               t_rec_array_event;
77504 l_array_ae_header_id                 xla_number_array_type;
77505 l_actual_flag                        VARCHAR2(1) := NULL;
77506 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
77507 l_balance_type_code                  VARCHAR2(1) :=NULL;
77508 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
77509 
77510 --
77511 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
77512 --
77513 
77514 TYPE t_array_source_6 IS TABLE OF AR_BILL_TO_CUSTOMERS_S_V.BILL_CUSTOMER_CLASS_CODE%TYPE INDEX BY BINARY_INTEGER;
77515 TYPE t_array_source_16 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_RECEIVABLE_CCID%TYPE INDEX BY BINARY_INTEGER;
77516 TYPE t_array_source_30 IS TABLE OF AR_BILL_TO_CUSTOMERS_S_V.BILL_CUST_ACCOUNT_ID%TYPE INDEX BY BINARY_INTEGER;
77517 TYPE t_array_source_31 IS TABLE OF AR_BILL_TO_SITE_USES_S_V.BILL_USES_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
77518 TYPE t_array_source_32 IS TABLE OF AR_TRANSACTIONS_S_V.XLA_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
77519 TYPE t_array_source_37 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_INVOICE_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
77520 TYPE t_array_source_68 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_INVOICING_RULE_ID%TYPE INDEX BY BINARY_INTEGER;
77521 TYPE t_array_source_83 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
77522 TYPE t_array_source_84 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
77523 TYPE t_array_source_85 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
77524 
77525 TYPE t_array_source_4 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
77526 TYPE t_array_source_5 IS TABLE OF FV_XLA_AR_REF_V.FEDERAL_FUND_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
77527 TYPE t_array_source_33 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ACCOUNT_CLASS%TYPE INDEX BY BINARY_INTEGER;
77528 TYPE t_array_source_34 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ID%TYPE INDEX BY BINARY_INTEGER;
77529 TYPE t_array_source_35 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
77530 TYPE t_array_source_36 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_AMT%TYPE INDEX BY BINARY_INTEGER;
77531 TYPE t_array_source_38 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
77532 TYPE t_array_source_39 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
77533 TYPE t_array_source_40 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
77534 TYPE t_array_source_41 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
77538 
77535 TYPE t_array_source_55 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_TAX_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
77536 TYPE t_array_source_56 IS TABLE OF FV_XLA_AR_REF_V.FEDERAL_ACCOUNT_VALID_FLAG%TYPE INDEX BY BINARY_INTEGER;
77537 TYPE t_array_source_66 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.ROUNDING_CORRECTION_FLAG%TYPE INDEX BY BINARY_INTEGER;
77539 l_array_source_6              t_array_source_6;
77540 l_array_source_16              t_array_source_16;
77541 l_array_source_30              t_array_source_30;
77542 l_array_source_31              t_array_source_31;
77543 l_array_source_32              t_array_source_32;
77544 l_array_source_37              t_array_source_37;
77545 l_array_source_68              t_array_source_68;
77546 l_array_source_83              t_array_source_83;
77547 l_array_source_84              t_array_source_84;
77548 l_array_source_85              t_array_source_85;
77549 
77550 l_array_source_4      t_array_source_4;
77551 l_array_source_5      t_array_source_5;
77552 l_array_source_33      t_array_source_33;
77553 l_array_source_34      t_array_source_34;
77554 l_array_source_35      t_array_source_35;
77555 l_array_source_36      t_array_source_36;
77556 l_array_source_38      t_array_source_38;
77557 l_array_source_39      t_array_source_39;
77558 l_array_source_40      t_array_source_40;
77559 l_array_source_41      t_array_source_41;
77560 l_array_source_55      t_array_source_55;
77561 l_array_source_56      t_array_source_56;
77562 l_array_source_66      t_array_source_66;
77563 
77564 --
77565 CURSOR header_cur
77566 IS
77567 SELECT /*+ leading(xet) cardinality(xet,1) */
77568 -- Event Class Code: INVOICE
77569     xet.entity_id
77570    ,xet.legal_entity_id
77571    ,xet.entity_code
77572    ,xet.transaction_number
77573    ,xet.event_id
77574    ,xet.event_class_code
77575    ,xet.event_type_code
77576    ,xet.event_number
77577    ,xet.event_date
77578    ,xet.transaction_date
77579    ,xet.reference_num_1
77580    ,xet.reference_num_2
77581    ,xet.reference_num_3
77582    ,xet.reference_num_4
77583    ,xet.reference_char_1
77584    ,xet.reference_char_2
77585    ,xet.reference_char_3
77586    ,xet.reference_char_4
77587    ,xet.reference_date_1
77588    ,xet.reference_date_2
77589    ,xet.reference_date_3
77590    ,xet.reference_date_4
77591    ,xet.event_created_by
77592    ,xet.budgetary_control_flag 
77593   , h1.BILL_CUSTOMER_CLASS_CODE    source_6
77594   , h5.TRX_RECEIVABLE_CCID    source_16
77595   , h1.BILL_CUST_ACCOUNT_ID    source_30
77596   , h2.BILL_USES_SITE_USE_ID    source_31
77597   , h5.XLA_PARTY_TYPE    source_32
77598   , h5.TRX_INVOICE_CURRENCY_CODE    source_37
77599   , h5.TRX_INVOICING_RULE_ID    source_68
77600   , h5.TRX_DOC_SEQUENCE_CATEGORY    source_83
77601   , h5.TRX_DOC_SEQUENCE_ID    source_84
77602   , h5.TRX_DOC_SEQUENCE_VALUE    source_85
77603   FROM xla_events_gt     xet 
77604   , AR_BILL_TO_CUSTOMERS_S_V  h1
77605   , AR_BILL_TO_SITE_USES_S_V  h2
77606   , AR_TRANSACTIONS_S_V  h5
77607  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
77608    and xet.event_class_code = C_EVENT_CLASS_CODE
77609    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
77610   AND h2.event_id  = h1.event_id
77611   AND h5.event_id  = h1.event_id
77612 
77613  ORDER BY event_id
77614 ;
77615 
77616 
77617 --
77618 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
77619 IS
77620 SELECT  /*+ leading(xet) cardinality(xet,1) */
77621 -- Event Class Code: INVOICE
77622     xet.entity_id
77623    ,xet.legal_entity_id
77624    ,xet.entity_code
77625    ,xet.transaction_number
77626    ,xet.event_id
77627    ,xet.event_class_code
77628    ,xet.event_type_code
77629    ,xet.event_number
77630    ,xet.event_date
77631    ,xet.transaction_date
77632    ,xet.reference_num_1
77633    ,xet.reference_num_2
77634    ,xet.reference_num_3
77635    ,xet.reference_num_4
77636    ,xet.reference_char_1
77637    ,xet.reference_char_2
77638    ,xet.reference_char_3
77639    ,xet.reference_char_4
77640    ,xet.reference_date_1
77641    ,xet.reference_date_2
77642    ,xet.reference_date_3
77643    ,xet.reference_date_4
77644    ,xet.event_created_by
77645    ,xet.budgetary_control_flag
77646  , l3.LINE_NUMBER  
77647   , l4.TRX_LINE_DIST_CCID    source_4
77648   , l6.FEDERAL_FUND_CATEGORY    source_5
77649   , l4.TRX_LINE_DIST_ACCOUNT_CLASS    source_33
77650   , l4.TRX_LINE_DIST_ID    source_34
77651   , l4.TRX_DISTRIBUTION_TYPE    source_35
77652   , l4.TRX_LINE_DIST_AMT    source_36
77653   , l3.TRX_LINE_CUR_CONVERSION_DATE    source_38
77654   , l3.TRX_LINE_CUR_CONVERSION_RATE    source_39
77655   , l3.TRX_LINE_CUR_CONVERSION_TYPE    source_40
77656   , l3.TRX_LINE_ACCTD_AMT    source_41
77657   , l4.TRX_TAX_LINE_ID    source_55
77658   , l6.FEDERAL_ACCOUNT_VALID_FLAG    source_56
77659   , l3.ROUNDING_CORRECTION_FLAG    source_66
77660   FROM xla_events_gt     xet 
77661   , AR_CUST_TRX_LINES_BASE_V  l3
77662   , AR_CUST_TRX_LINES_L_V  l4
77663   , FV_XLA_AR_REF_V  l6
77664  WHERE xet.event_id between x_first_event_id and x_last_event_id
77665    and xet.event_date between p_pad_start_date and p_pad_end_date
77666    and xet.event_class_code = C_EVENT_CLASS_CODE
77667    and xet.event_status_code <> 'N'   AND l3.event_id      = xet.event_id
77668   AND l4.event_id    = l3.event_id
77669   AND l4.line_number = l3.line_number
77670  AND l6.federal_event_id   (+) =  l4.event_id  AND l6.federal_line_number   (+) =  l4.line_number;
77671 
77672 --
77673 BEGIN
77674 IF g_log_enabled THEN
77675    l_log_module := C_DEFAULT_MODULE||'.EventClass_142';
77676 END IF;
77677 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
77678    trace
77679       (p_msg      => 'BEGIN of EventClass_142'
77680       ,p_level    => C_LEVEL_PROCEDURE
77684 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
77681       ,p_module   => l_log_module);
77682 END IF;
77683 
77685    trace
77686       (p_msg      => 'p_application_id = '||p_application_id||
77687                      ' - p_base_ledger_id = '||p_base_ledger_id||
77688                      ' - p_target_ledger_id  = '||p_target_ledger_id||
77689                      ' - p_language = '||p_language||
77690                      ' - p_currency_code = '||p_currency_code||
77691                      ' - p_sla_ledger_id = '||p_sla_ledger_id
77692       ,p_level    => C_LEVEL_STATEMENT
77693       ,p_module   => l_log_module);
77694 END IF;
77695 --
77696 -- initialze arrays
77697 --
77698 g_array_event.DELETE;
77699 l_rec_array_event := l_null_rec_array_event;
77700 --
77701 --------------------------------------
77702 -- 4262811 Initialze MPA Line Number
77703 --------------------------------------
77704 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
77705 
77706 --
77707 
77708 --
77709 OPEN header_cur;
77710 --
77711 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
77712    trace
77713    (p_msg      => 'SQL - FETCH header_cur'
77714    ,p_level    => C_LEVEL_STATEMENT
77715    ,p_module   => l_log_module);
77716 END IF;
77717 --
77718 LOOP
77719 FETCH header_cur BULK COLLECT INTO
77720         l_array_entity_id
77721       , l_array_legal_entity_id
77722       , l_array_entity_code
77723       , l_array_transaction_num
77724       , l_array_event_id
77725       , l_array_class_code
77726       , l_array_event_type
77727       , l_array_event_number
77728       , l_array_event_date
77729       , l_array_transaction_date
77730       , l_array_reference_num_1
77731       , l_array_reference_num_2
77732       , l_array_reference_num_3
77733       , l_array_reference_num_4
77734       , l_array_reference_char_1
77735       , l_array_reference_char_2
77736       , l_array_reference_char_3
77737       , l_array_reference_char_4
77738       , l_array_reference_date_1
77739       , l_array_reference_date_2
77740       , l_array_reference_date_3
77741       , l_array_reference_date_4
77742       , l_array_event_created_by
77743       , l_array_budgetary_control_flag 
77744       , l_array_source_6
77745       , l_array_source_16
77746       , l_array_source_30
77747       , l_array_source_31
77748       , l_array_source_32
77749       , l_array_source_37
77750       , l_array_source_68
77751       , l_array_source_83
77752       , l_array_source_84
77753       , l_array_source_85
77754       LIMIT l_rows;
77755 --
77756 IF (C_LEVEL_EVENT >= g_log_level) THEN
77757    trace
77758    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
77759    ,p_level    => C_LEVEL_EVENT
77760    ,p_module   => l_log_module);
77761 END IF;
77762 --
77763 EXIT WHEN l_array_entity_id.COUNT = 0;
77764 
77765 -- initialize arrays
77766 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
77767 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
77768 
77769 --
77770 -- Bug 4458708
77771 --
77772 XLA_AE_LINES_PKG.g_LineNumber := 0;
77773 
77774 
77775 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
77776 g_last_hdr_idx := l_array_event_id.LAST;
77777 --
77778 -- loop for the headers. Each iteration is for each header extract row
77779 -- fetched in header cursor
77780 --
77781 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
77782 
77783 --
77784 -- set event info as cache for other routines to refer event attributes
77785 --
77786 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
77787    (p_application_id           => p_application_id
77788    ,p_primary_ledger_id        => p_primary_ledger_id
77789    ,p_base_ledger_id           => p_base_ledger_id
77790    ,p_target_ledger_id         => p_target_ledger_id
77791    ,p_entity_id                => l_array_entity_id(hdr_idx)
77792    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
77793    ,p_entity_code              => l_array_entity_code(hdr_idx)
77794    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
77795    ,p_event_id                 => l_array_event_id(hdr_idx)
77796    ,p_event_class_code         => l_array_class_code(hdr_idx)
77797    ,p_event_type_code          => l_array_event_type(hdr_idx)
77798    ,p_event_number             => l_array_event_number(hdr_idx)
77799    ,p_event_date               => l_array_event_date(hdr_idx)
77800    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
77801    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
77802    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
77803    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
77804    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
77805    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
77806    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
77807    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
77808    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
77809    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
77810    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
77811    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
77812    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
77813    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
77814    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
77815 
77816 --
77817 -- set the status of entry to C_VALID (0)
77818 --
77819 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
77820 
77821 --
77822 -- initialize a row for ae header
77823 --
77824 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
77828 --
77825 
77826 l_event_id := l_array_event_id(hdr_idx);
77827 
77829 -- storing the hdr_idx for event. May be used by line cursor.
77830 --
77831 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
77832 
77833 --
77834 -- store sources from header extract. This can be improved to
77835 -- store only those sources from header extract that may be used in lines
77836 --
77837 
77838 g_array_event(l_event_id).array_value_char('source_6') := l_array_source_6(hdr_idx);
77839 g_array_event(l_event_id).array_value_num('source_16') := l_array_source_16(hdr_idx);
77840 g_array_event(l_event_id).array_value_num('source_30') := l_array_source_30(hdr_idx);
77841 g_array_event(l_event_id).array_value_num('source_31') := l_array_source_31(hdr_idx);
77842 g_array_event(l_event_id).array_value_char('source_32') := l_array_source_32(hdr_idx);
77843 g_array_event(l_event_id).array_value_char('source_37') := l_array_source_37(hdr_idx);
77844 g_array_event(l_event_id).array_value_num('source_68') := l_array_source_68(hdr_idx);
77845 g_array_event(l_event_id).array_value_char('source_83') := l_array_source_83(hdr_idx);
77846 g_array_event(l_event_id).array_value_num('source_84') := l_array_source_84(hdr_idx);
77847 g_array_event(l_event_id).array_value_num('source_85') := l_array_source_85(hdr_idx);
77848 
77849 --
77850 -- initilaize the status of ae headers for diffrent balance types
77851 -- the status is initialised to C_NOT_CREATED (2)
77852 --
77853 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
77854 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
77855 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
77856 
77857 --
77858 -- call api to validate and store accounting attributes for header
77859 --
77860 
77861 ------------------------------------------------------------
77862 -- Accrual Reversal : to get date for Standard Source (NONE)
77863 ------------------------------------------------------------
77864 l_acc_rev_gl_date_source := NULL;
77865 
77866      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
77867       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_83');
77868      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
77869       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_84');
77870      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
77871       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_85');
77872      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
77873       l_rec_acct_attrs.array_date_value(4) := 
77874 xla_ae_sources_pkg.GetSystemSourceDate(
77875    p_source_code           => 'XLA_EVENT_DATE'
77876  , p_source_type_code      => 'Y'
77877  , p_source_application_id =>  602
77878 );
77879 
77880 
77881 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
77882 
77883 XLA_AE_HEADER_PKG.SetJeCategoryName;
77884 
77885 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
77886 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
77887 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
77888 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
77889 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
77890 
77891 
77892 -- No header level analytical criteria
77893 
77894 --
77895 --accounting attribute enhancement, bug 3612931
77896 --
77897 l_trx_reversal_source := SUBSTR(NULL, 1,30);
77898 
77899 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
77900    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
77901 
77902    xla_accounting_err_pkg.build_message
77903       (p_appli_s_name            => 'XLA'
77904       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
77905       ,p_token_1                 => 'ACCT_ATTR_NAME'
77906       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
77907       ,p_token_2                 => 'PRODUCT_NAME'
77908       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
77909       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
77910       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
77911       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
77912 
77913 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
77914    --
77915    -- following sets the accounting attributes needed to reverse
77916    -- accounting for a distributeion
77917    --
77918    xla_ae_lines_pkg.SetTrxReversalAttrs
77919       (p_event_id              => l_event_id
77920       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
77921       ,p_trx_reversal_source   => l_trx_reversal_source);
77922 
77923 END IF;
77924 
77925 
77926 ----------------------------------------------------------------
77927 -- 4262811 -  update the header statuses to invalid in need be
77928 ----------------------------------------------------------------
77929 --
77930 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
77931 
77932 
77933   -----------------------------------------------
77934   -- No accrual reversal for the event class/type
77935   -----------------------------------------------
77936 ----------------------------------------------------------------
77937 
77938 --
77939 -- this ends the header loop iteration for one bulk fetch
77940 --
77941 END LOOP;
77942 
77943 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
77947 -- insert dummy rows into lines gt table that were created due to
77944 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
77945 
77946 --
77948 -- transaction reversals
77949 --
77950 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
77951    l_result := XLA_AE_LINES_PKG.InsertLines;
77952 END IF;
77953 
77954 --
77955 -- reset the temp_line_num for each set of events fetched from header
77956 -- cursor rather than doing it for each new event in line cursor
77957 -- Bug 3939231
77958 --
77959 xla_ae_lines_pkg.g_temp_line_num := 0;
77960 
77961 
77962 
77963 --
77964 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
77965 --
77966 --
77967 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
77968 
77969       trace
77970          (p_msg      => 'SQL - FETCH line_cur'
77971          ,p_level    => C_LEVEL_STATEMENT
77972          ,p_module   => l_log_module);
77973 
77974 END IF;
77975 --
77976 --
77977 LOOP
77978   --
77979   FETCH line_cur BULK COLLECT INTO
77980         l_array_entity_id
77981       , l_array_legal_entity_id
77982       , l_array_entity_code
77983       , l_array_transaction_num
77984       , l_array_event_id
77985       , l_array_class_code
77986       , l_array_event_type
77987       , l_array_event_number
77988       , l_array_event_date
77989       , l_array_transaction_date
77990       , l_array_reference_num_1
77991       , l_array_reference_num_2
77992       , l_array_reference_num_3
77993       , l_array_reference_num_4
77994       , l_array_reference_char_1
77995       , l_array_reference_char_2
77996       , l_array_reference_char_3
77997       , l_array_reference_char_4
77998       , l_array_reference_date_1
77999       , l_array_reference_date_2
78000       , l_array_reference_date_3
78001       , l_array_reference_date_4
78002       , l_array_event_created_by
78003       , l_array_budgetary_control_flag
78004       , l_array_extract_line_num 
78005       , l_array_source_4
78006       , l_array_source_5
78007       , l_array_source_33
78008       , l_array_source_34
78009       , l_array_source_35
78010       , l_array_source_36
78011       , l_array_source_38
78012       , l_array_source_39
78013       , l_array_source_40
78014       , l_array_source_41
78015       , l_array_source_55
78016       , l_array_source_56
78017       , l_array_source_66
78018       LIMIT l_rows;
78019 
78020   --
78021   IF (C_LEVEL_EVENT >= g_log_level) THEN
78022             trace
78023                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
78024                ,p_level    => C_LEVEL_EVENT
78025                ,p_module   => l_log_module);
78026   END IF;
78027   --
78028   EXIT WHEN l_array_entity_id.count = 0;
78029 
78030   XLA_AE_LINES_PKG.g_rec_lines := null;
78031 
78032 --
78033 -- Bug 4458708
78034 --
78035 XLA_AE_LINES_PKG.g_LineNumber := 0;
78036 --
78037 --
78038 
78039 FOR Idx IN 1..l_array_event_id.count LOOP
78040    --
78041    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
78042    --
78043    l_event_id := l_array_event_id(idx);  -- 5648433
78044 
78045    --
78046    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
78047    --
78048 
78049    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
78050              (g_array_event(l_event_id).array_value_num('header_index'))
78051          ,'N'
78052          ) <> 'Y'
78053    THEN
78054       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
78055          trace
78056             (p_msg      => 'Trancaction revesal option is not Y '
78057             ,p_level    => C_LEVEL_STATEMENT
78058             ,p_module   => l_log_module);
78059       END IF;
78060 
78061 --
78062 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
78063 --
78064 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
78065 --
78066 -- set event info as cache for other routines to refer event attributes
78067 --
78068 
78069 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
78070    l_previous_event_id := l_event_id;
78071 
78072    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
78073       (p_application_id           => p_application_id
78074       ,p_primary_ledger_id        => p_primary_ledger_id
78075       ,p_base_ledger_id           => p_base_ledger_id
78076       ,p_target_ledger_id         => p_target_ledger_id
78077       ,p_entity_id                => l_array_entity_id(Idx)
78078       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
78079       ,p_entity_code              => l_array_entity_code(Idx)
78080       ,p_transaction_num          => l_array_transaction_num(Idx)
78081       ,p_event_id                 => l_array_event_id(Idx)
78082       ,p_event_class_code         => l_array_class_code(Idx)
78083       ,p_event_type_code          => l_array_event_type(Idx)
78084       ,p_event_number             => l_array_event_number(Idx)
78085       ,p_event_date               => l_array_event_date(Idx)
78086       ,p_transaction_date         => l_array_transaction_date(Idx)
78087       ,p_reference_num_1          => l_array_reference_num_1(Idx)
78088       ,p_reference_num_2          => l_array_reference_num_2(Idx)
78089       ,p_reference_num_3          => l_array_reference_num_3(Idx)
78090       ,p_reference_num_4          => l_array_reference_num_4(Idx)
78091       ,p_reference_char_1         => l_array_reference_char_1(Idx)
78092       ,p_reference_char_2         => l_array_reference_char_2(Idx)
78093       ,p_reference_char_3         => l_array_reference_char_3(Idx)
78094       ,p_reference_char_4         => l_array_reference_char_4(Idx)
78098       ,p_reference_date_4         => l_array_reference_date_4(Idx)
78095       ,p_reference_date_1         => l_array_reference_date_1(Idx)
78096       ,p_reference_date_2         => l_array_reference_date_2(Idx)
78097       ,p_reference_date_3         => l_array_reference_date_3(Idx)
78099       ,p_event_created_by         => l_array_event_created_by(Idx)
78100       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
78101        --
78102 END IF;
78103 
78104 
78105 
78106 --
78107 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
78108 
78109 l_acct_reversal_source := SUBSTR(NULL, 1,30);
78110 
78111 IF l_continue_with_lines THEN
78112    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
78113       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
78114 
78115       xla_accounting_err_pkg.build_message
78116          (p_appli_s_name            => 'XLA'
78117          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
78118          ,p_token_1                 => 'LINE_NUMBER'
78119          ,p_value_1                 => l_array_extract_line_num(Idx)
78120          ,p_token_2                 => 'PRODUCT_NAME'
78121          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
78122          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
78123          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
78124          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
78125 
78126    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
78127       --
78128       -- following sets the accounting attributes needed to reverse
78129       -- accounting for a distributeion
78130       --
78131 
78132       --
78133       -- 5217187
78134       --
78135       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
78136       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
78137                                        g_array_event(l_event_id).array_value_num('header_index'));
78138       --
78139       --
78140 
78141       -- No reversal code generated
78142 
78143       xla_ae_lines_pkg.SetAcctReversalAttrs
78144          (p_event_id             => l_event_id
78145          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
78146          ,p_calculate_acctd_flag => l_calculate_acctd_flag
78147          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
78148    END IF;
78149 
78150    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
78151        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
78152 
78153 --
78154 AcctLineType_59 (
78155  p_application_id  => p_application_id
78156  ,p_event_id     => l_event_id
78157  ,p_calculate_acctd_flag => l_calculate_acctd_flag
78158  ,p_calculate_g_l_flag => l_calculate_g_l_flag
78159  ,p_actual_flag => l_actual_flag
78160  ,p_balance_type_code => l_balance_type_code
78161  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
78162  
78163  , p_source_4 => l_array_source_4(Idx)
78164  , p_source_5 => l_array_source_5(Idx)
78165  , p_source_6 => g_array_event(l_event_id).array_value_char('source_6')
78166  , p_source_16 => g_array_event(l_event_id).array_value_num('source_16')
78167  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
78168  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
78169  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
78170  , p_source_33 => l_array_source_33(Idx)
78171  , p_source_34 => l_array_source_34(Idx)
78172  , p_source_35 => l_array_source_35(Idx)
78173  , p_source_36 => l_array_source_36(Idx)
78174  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
78175  , p_source_38 => l_array_source_38(Idx)
78176  , p_source_39 => l_array_source_39(Idx)
78177  , p_source_40 => l_array_source_40(Idx)
78178  , p_source_41 => l_array_source_41(Idx)
78179  , p_source_55 => l_array_source_55(Idx)
78180  , p_source_56 => l_array_source_56(Idx)
78181  );
78182 If(l_balance_type_code = 'A') THEN
78183   l_actual_gain_loss_ref := l_gain_or_loss_ref;
78184 END IF;
78185 
78186 --
78187 
78188 
78189 --
78190 AcctLineType_60 (
78191  p_application_id  => p_application_id
78192  ,p_event_id     => l_event_id
78193  ,p_calculate_acctd_flag => l_calculate_acctd_flag
78194  ,p_calculate_g_l_flag => l_calculate_g_l_flag
78195  ,p_actual_flag => l_actual_flag
78196  ,p_balance_type_code => l_balance_type_code
78197  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
78198  
78199  , p_source_4 => l_array_source_4(Idx)
78200  , p_source_5 => l_array_source_5(Idx)
78201  , p_source_6 => g_array_event(l_event_id).array_value_char('source_6')
78202  , p_source_16 => g_array_event(l_event_id).array_value_num('source_16')
78203  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
78204  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
78205  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
78206  , p_source_33 => l_array_source_33(Idx)
78207  , p_source_34 => l_array_source_34(Idx)
78208  , p_source_35 => l_array_source_35(Idx)
78209  , p_source_36 => l_array_source_36(Idx)
78210  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
78211  , p_source_38 => l_array_source_38(Idx)
78212  , p_source_39 => l_array_source_39(Idx)
78213  , p_source_40 => l_array_source_40(Idx)
78214  , p_source_41 => l_array_source_41(Idx)
78215  , p_source_55 => l_array_source_55(Idx)
78216  , p_source_56 => l_array_source_56(Idx)
78217  );
78218 If(l_balance_type_code = 'A') THEN
78219   l_actual_gain_loss_ref := l_gain_or_loss_ref;
78220 END IF;
78221 
78222 --
78223 
78224 
78225 --
78226 AcctLineType_79 (
78227  p_application_id  => p_application_id
78231  ,p_actual_flag => l_actual_flag
78228  ,p_event_id     => l_event_id
78229  ,p_calculate_acctd_flag => l_calculate_acctd_flag
78230  ,p_calculate_g_l_flag => l_calculate_g_l_flag
78232  ,p_balance_type_code => l_balance_type_code
78233  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
78234  
78235  , p_source_4 => l_array_source_4(Idx)
78236  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
78237  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
78238  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
78239  , p_source_33 => l_array_source_33(Idx)
78240  , p_source_34 => l_array_source_34(Idx)
78241  , p_source_35 => l_array_source_35(Idx)
78242  , p_source_36 => l_array_source_36(Idx)
78243  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
78244  , p_source_38 => l_array_source_38(Idx)
78245  , p_source_39 => l_array_source_39(Idx)
78246  , p_source_40 => l_array_source_40(Idx)
78247  , p_source_41 => l_array_source_41(Idx)
78248  , p_source_55 => l_array_source_55(Idx)
78249  );
78250 If(l_balance_type_code = 'A') THEN
78251   l_actual_gain_loss_ref := l_gain_or_loss_ref;
78252 END IF;
78253 
78254 --
78255 
78256 
78257 --
78258 AcctLineType_80 (
78259  p_application_id  => p_application_id
78260  ,p_event_id     => l_event_id
78261  ,p_calculate_acctd_flag => l_calculate_acctd_flag
78262  ,p_calculate_g_l_flag => l_calculate_g_l_flag
78263  ,p_actual_flag => l_actual_flag
78264  ,p_balance_type_code => l_balance_type_code
78265  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
78266  
78267  , p_source_4 => l_array_source_4(Idx)
78268  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
78269  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
78270  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
78271  , p_source_33 => l_array_source_33(Idx)
78272  , p_source_34 => l_array_source_34(Idx)
78273  , p_source_35 => l_array_source_35(Idx)
78274  , p_source_36 => l_array_source_36(Idx)
78275  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
78276  , p_source_38 => l_array_source_38(Idx)
78277  , p_source_39 => l_array_source_39(Idx)
78278  , p_source_40 => l_array_source_40(Idx)
78279  , p_source_41 => l_array_source_41(Idx)
78280  , p_source_55 => l_array_source_55(Idx)
78281  );
78282 If(l_balance_type_code = 'A') THEN
78283   l_actual_gain_loss_ref := l_gain_or_loss_ref;
78284 END IF;
78285 
78286 --
78287 
78288 
78289 --
78290 AcctLineType_81 (
78291  p_application_id  => p_application_id
78292  ,p_event_id     => l_event_id
78293  ,p_calculate_acctd_flag => l_calculate_acctd_flag
78294  ,p_calculate_g_l_flag => l_calculate_g_l_flag
78295  ,p_actual_flag => l_actual_flag
78296  ,p_balance_type_code => l_balance_type_code
78297  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
78298  
78299  , p_source_4 => l_array_source_4(Idx)
78300  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
78301  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
78302  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
78303  , p_source_33 => l_array_source_33(Idx)
78304  , p_source_34 => l_array_source_34(Idx)
78305  , p_source_35 => l_array_source_35(Idx)
78306  , p_source_36 => l_array_source_36(Idx)
78307  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
78308  , p_source_38 => l_array_source_38(Idx)
78309  , p_source_39 => l_array_source_39(Idx)
78310  , p_source_40 => l_array_source_40(Idx)
78311  , p_source_41 => l_array_source_41(Idx)
78312  , p_source_55 => l_array_source_55(Idx)
78313  , p_source_66 => l_array_source_66(Idx)
78314  );
78315 If(l_balance_type_code = 'A') THEN
78316   l_actual_gain_loss_ref := l_gain_or_loss_ref;
78317 END IF;
78318 
78319 --
78320 
78321 
78322 --
78323 AcctLineType_82 (
78324  p_application_id  => p_application_id
78325  ,p_event_id     => l_event_id
78326  ,p_calculate_acctd_flag => l_calculate_acctd_flag
78327  ,p_calculate_g_l_flag => l_calculate_g_l_flag
78328  ,p_actual_flag => l_actual_flag
78329  ,p_balance_type_code => l_balance_type_code
78330  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
78331  
78332  , p_source_4 => l_array_source_4(Idx)
78333  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
78334  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
78335  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
78336  , p_source_33 => l_array_source_33(Idx)
78337  , p_source_34 => l_array_source_34(Idx)
78338  , p_source_35 => l_array_source_35(Idx)
78339  , p_source_36 => l_array_source_36(Idx)
78340  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
78341  , p_source_38 => l_array_source_38(Idx)
78342  , p_source_39 => l_array_source_39(Idx)
78343  , p_source_40 => l_array_source_40(Idx)
78344  , p_source_41 => l_array_source_41(Idx)
78345  , p_source_55 => l_array_source_55(Idx)
78346  );
78347 If(l_balance_type_code = 'A') THEN
78348   l_actual_gain_loss_ref := l_gain_or_loss_ref;
78349 END IF;
78350 
78351 --
78352 
78353 
78354 --
78355 AcctLineType_83 (
78356  p_application_id  => p_application_id
78357  ,p_event_id     => l_event_id
78358  ,p_calculate_acctd_flag => l_calculate_acctd_flag
78359  ,p_calculate_g_l_flag => l_calculate_g_l_flag
78360  ,p_actual_flag => l_actual_flag
78361  ,p_balance_type_code => l_balance_type_code
78362  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
78363  
78364  , p_source_4 => l_array_source_4(Idx)
78365  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
78366  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
78367  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
78371  , p_source_36 => l_array_source_36(Idx)
78368  , p_source_33 => l_array_source_33(Idx)
78369  , p_source_34 => l_array_source_34(Idx)
78370  , p_source_35 => l_array_source_35(Idx)
78372  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
78373  , p_source_38 => l_array_source_38(Idx)
78374  , p_source_39 => l_array_source_39(Idx)
78375  , p_source_40 => l_array_source_40(Idx)
78376  , p_source_41 => l_array_source_41(Idx)
78377  , p_source_55 => l_array_source_55(Idx)
78378  );
78379 If(l_balance_type_code = 'A') THEN
78380   l_actual_gain_loss_ref := l_gain_or_loss_ref;
78381 END IF;
78382 
78383 --
78384 
78385 
78386 --
78387 AcctLineType_84 (
78388  p_application_id  => p_application_id
78389  ,p_event_id     => l_event_id
78390  ,p_calculate_acctd_flag => l_calculate_acctd_flag
78391  ,p_calculate_g_l_flag => l_calculate_g_l_flag
78392  ,p_actual_flag => l_actual_flag
78393  ,p_balance_type_code => l_balance_type_code
78394  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
78395  
78396  , p_source_4 => l_array_source_4(Idx)
78397  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
78398  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
78399  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
78400  , p_source_33 => l_array_source_33(Idx)
78401  , p_source_34 => l_array_source_34(Idx)
78402  , p_source_35 => l_array_source_35(Idx)
78403  , p_source_36 => l_array_source_36(Idx)
78404  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
78405  , p_source_38 => l_array_source_38(Idx)
78406  , p_source_39 => l_array_source_39(Idx)
78407  , p_source_40 => l_array_source_40(Idx)
78408  , p_source_41 => l_array_source_41(Idx)
78409  , p_source_55 => l_array_source_55(Idx)
78410  , p_source_66 => l_array_source_66(Idx)
78411  );
78412 If(l_balance_type_code = 'A') THEN
78413   l_actual_gain_loss_ref := l_gain_or_loss_ref;
78414 END IF;
78415 
78416 --
78417 
78418 
78419 --
78420 AcctLineType_85 (
78421  p_application_id  => p_application_id
78422  ,p_event_id     => l_event_id
78423  ,p_calculate_acctd_flag => l_calculate_acctd_flag
78424  ,p_calculate_g_l_flag => l_calculate_g_l_flag
78425  ,p_actual_flag => l_actual_flag
78426  ,p_balance_type_code => l_balance_type_code
78427  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
78428  
78429  , p_source_4 => l_array_source_4(Idx)
78430  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
78431  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
78432  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
78433  , p_source_33 => l_array_source_33(Idx)
78434  , p_source_34 => l_array_source_34(Idx)
78435  , p_source_35 => l_array_source_35(Idx)
78436  , p_source_36 => l_array_source_36(Idx)
78437  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
78438  , p_source_38 => l_array_source_38(Idx)
78439  , p_source_39 => l_array_source_39(Idx)
78440  , p_source_40 => l_array_source_40(Idx)
78441  , p_source_41 => l_array_source_41(Idx)
78442  , p_source_55 => l_array_source_55(Idx)
78443  , p_source_66 => l_array_source_66(Idx)
78444  );
78445 If(l_balance_type_code = 'A') THEN
78446   l_actual_gain_loss_ref := l_gain_or_loss_ref;
78447 END IF;
78448 
78449 --
78450 
78451 
78452 --
78453 AcctLineType_89 (
78454  p_application_id  => p_application_id
78455  ,p_event_id     => l_event_id
78456  ,p_calculate_acctd_flag => l_calculate_acctd_flag
78457  ,p_calculate_g_l_flag => l_calculate_g_l_flag
78458  ,p_actual_flag => l_actual_flag
78459  ,p_balance_type_code => l_balance_type_code
78460  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
78461  
78462  , p_source_4 => l_array_source_4(Idx)
78463  , p_source_16 => g_array_event(l_event_id).array_value_num('source_16')
78464  , p_source_30 => g_array_event(l_event_id).array_value_num('source_30')
78465  , p_source_31 => g_array_event(l_event_id).array_value_num('source_31')
78466  , p_source_32 => g_array_event(l_event_id).array_value_char('source_32')
78467  , p_source_33 => l_array_source_33(Idx)
78468  , p_source_34 => l_array_source_34(Idx)
78469  , p_source_35 => l_array_source_35(Idx)
78470  , p_source_36 => l_array_source_36(Idx)
78471  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
78472  , p_source_38 => l_array_source_38(Idx)
78473  , p_source_39 => l_array_source_39(Idx)
78474  , p_source_40 => l_array_source_40(Idx)
78475  , p_source_41 => l_array_source_41(Idx)
78476  , p_source_55 => l_array_source_55(Idx)
78477  , p_source_68 => g_array_event(l_event_id).array_value_num('source_68')
78478  );
78479 If(l_balance_type_code = 'A') THEN
78480   l_actual_gain_loss_ref := l_gain_or_loss_ref;
78481 END IF;
78482 
78483 --
78484 
78485       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
78486       -- or secondary ledger that has different currency with primary
78487       -- or alc that is calculated by sla
78488       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
78489             (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'))
78490 
78491 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
78492 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
78493           AND (l_actual_flag = 'A')) THEN
78494         XLA_AE_LINES_PKG.CreateGainOrLossLines(
78495           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
78496          ,p_application_id   => p_application_id
78497          ,p_amb_context_code => 'DEFAULT'
78498          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
78502          ,p_gain_ccid        => -1
78499          ,p_event_class_code => C_EVENT_CLASS_CODE
78500          ,p_event_type_code  => C_EVENT_TYPE_CODE
78501          
78503          ,p_loss_ccid        => -1
78504 
78505          ,p_actual_flag      => l_actual_flag
78506          ,p_enc_flag         => null
78507          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
78508          ,p_enc_g_l_ref      => null
78509          );
78510       END IF;
78511    END IF;
78512 END IF;
78513 
78514    ELSE
78515       --
78516       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
78517       --
78518       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
78519          trace
78520             (p_msg      => 'Trancaction revesal option is Y'
78521             ,p_level    => C_LEVEL_STATEMENT
78522             ,p_module   => l_log_module);
78523       END IF;
78524    END IF;
78525 
78526 END LOOP;
78527 l_result := XLA_AE_LINES_PKG.InsertLines ;
78528 end loop;
78529 close line_cur;
78530 
78531 
78532 --
78533 -- insert headers into xla_ae_headers_gt table
78534 --
78535 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
78536 
78537 -- insert into errors table here.
78538 
78539 END LOOP;
78540 
78541 --
78542 -- 4865292
78543 --
78544 -- Compare g_hdr_extract_count with event count in
78545 -- CreateHeadersAndLines.
78546 --
78547 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
78548 
78549 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
78550    trace (p_msg     => '# rows extracted from header extract objects '
78551                     || ' (running total): '
78552                     || g_hdr_extract_count
78553          ,p_level   => C_LEVEL_STATEMENT
78554          ,p_module  => l_log_module);
78555 END IF;
78556 
78557 CLOSE header_cur;
78558 --
78559 
78560 --
78561 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
78562    trace
78563       (p_msg      => 'END of EventClass_142'
78564       ,p_level    => C_LEVEL_PROCEDURE
78565       ,p_module   => l_log_module);
78566 END IF;
78567 --
78568 RETURN l_result;
78569 EXCEPTION
78570 WHEN xla_exceptions_pkg.application_exception THEN
78571    
78572 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
78573 
78574    
78575 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
78576 
78577    RAISE;
78578 
78579 WHEN NO_DATA_FOUND THEN
78580 
78581 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
78582 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
78583 
78584 FOR header_record IN header_cur
78585 LOOP
78586     l_array_header_events(header_record.event_id) := header_record.event_id;
78587 END LOOP;
78588 
78589 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
78590 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
78591 
78592 fnd_file.put_line(fnd_file.LOG, '                    ');
78593 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
78594 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
78595 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
78596 
78597 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
78598 LOOP
78599 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
78600 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
78601         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
78602 	END IF;
78603 END LOOP;
78604 
78605 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
78606 fnd_file.put_line(fnd_file.LOG, '                    ');
78607 
78608 
78609 xla_exceptions_pkg.raise_message
78610       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_142');
78611 
78612 
78613 WHEN OTHERS THEN
78614    xla_exceptions_pkg.raise_message
78615       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_142');
78616 END EventClass_142;
78617 --
78618 
78619 ---------------------------------------
78620 --
78621 -- PRIVATE PROCEDURE
78622 --         insert_sources_143
78623 --
78624 ----------------------------------------
78625 --
78626 PROCEDURE insert_sources_143(
78627                                 p_target_ledger_id       IN NUMBER
78628                               , p_language               IN VARCHAR2
78629                               , p_sla_ledger_id          IN NUMBER
78630                               , p_pad_start_date         IN DATE
78631                               , p_pad_end_date           IN DATE
78632                          )
78633 IS
78634 
78635 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'MISC_RECEIPT_ALL';
78636 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'MISC_RECEIPT';
78637 p_apps_owner                   VARCHAR2(30);
78638 l_log_module                   VARCHAR2(240);
78639 BEGIN
78640 IF g_log_enabled THEN
78641       l_log_module := C_DEFAULT_MODULE||'.insert_sources_143';
78642 END IF;
78643 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
78644 
78645       trace
78646          (p_msg      => 'BEGIN of insert_sources_143'
78647          ,p_level    => C_LEVEL_PROCEDURE
78648          ,p_module   => l_log_module);
78649 
78650 END IF;
78651 
78652 -- select APPS owner
78653 SELECT oracle_username
78654   INTO p_apps_owner
78655   FROM fnd_oracle_userid
78656  WHERE read_only_flag = 'U'
78657 ;
78658 
78659 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
78660       trace
78664                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
78661          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
78662                         ' - p_language = '||p_language||
78663                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
78665                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
78666                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
78667          ,p_level    => C_LEVEL_STATEMENT
78668          ,p_module   => l_log_module);
78669 END IF;
78670 
78671 
78672 --
78673 INSERT INTO xla_diag_sources --hdr2
78674 (
78675         event_id
78676       , ledger_id
78677       , sla_ledger_id
78678       , description_language
78679       , object_name
78680       , object_type_code
78681       , line_number
78682       , source_application_id
78683       , source_type_code
78684       , source_code
78685       , source_value
78686       , source_meaning
78687       , created_by
78688       , creation_date
78689       , last_update_date
78690       , last_updated_by
78691       , last_update_login
78692       , program_update_date
78693       , program_application_id
78694       , program_id
78695       , request_id
78696 )
78697 SELECT
78698         event_id
78699       , p_target_ledger_id
78700       , p_sla_ledger_id
78701       , p_language
78702       , object_name
78703       , object_type_code
78704       , line_number
78705       , source_application_id
78706       , source_type_code
78707       , source_code
78708       , SUBSTR(source_value ,1,1996)
78709       , SUBSTR(source_meaning ,1,200)
78710       , xla_environment_pkg.g_Usr_Id
78711       , TRUNC(SYSDATE)
78712       , TRUNC(SYSDATE)
78713       , xla_environment_pkg.g_Usr_Id
78714       , xla_environment_pkg.g_Login_Id
78715       , TRUNC(SYSDATE)
78716       , xla_environment_pkg.g_Prog_Appl_Id
78717       , xla_environment_pkg.g_Prog_Id
78718       , xla_environment_pkg.g_Req_Id
78719   FROM (
78720        SELECT xet.event_id                  event_id
78721             , 0                          line_number
78722             , CASE r
78723                WHEN 1 THEN 'AR_REMIT_BANK_ACCT_H_V' 
78724                 WHEN 2 THEN 'AR_REMIT_BANK_ACCT_H_V' 
78725                 WHEN 3 THEN 'AR_REMIT_BANK_ACCT_H_V' 
78726                 WHEN 4 THEN 'AR_REMIT_BANK_ACCT_H_V' 
78727                 WHEN 5 THEN 'AR_RCT_METHOD_H_V' 
78728                 WHEN 6 THEN 'AR_RCT_METHOD_H_V' 
78729                 WHEN 7 THEN 'AR_CASH_RECEIPTS_H_V' 
78730                 WHEN 8 THEN 'AR_CASH_RECEIPTS_H_V' 
78731                 WHEN 9 THEN 'AR_CASH_RECEIPTS_H_V' 
78732                 WHEN 10 THEN 'AR_CASH_RECEIPTS_H_V' 
78733                 
78734                ELSE null
78735               END                           object_name
78736             , CASE r
78737                 WHEN 1 THEN 'HEADER' 
78738                 WHEN 2 THEN 'HEADER' 
78739                 WHEN 3 THEN 'HEADER' 
78740                 WHEN 4 THEN 'HEADER' 
78741                 WHEN 5 THEN 'HEADER' 
78742                 WHEN 6 THEN 'HEADER' 
78743                 WHEN 7 THEN 'HEADER' 
78744                 WHEN 8 THEN 'HEADER' 
78745                 WHEN 9 THEN 'HEADER' 
78746                 WHEN 10 THEN 'HEADER' 
78747                 
78748                 ELSE null
78749               END                           object_type_code
78750             , CASE r
78751                 WHEN 1 THEN '222' 
78752                 WHEN 2 THEN '222' 
78753                 WHEN 3 THEN '222' 
78754                 WHEN 4 THEN '222' 
78755                 WHEN 5 THEN '222' 
78756                 WHEN 6 THEN '222' 
78757                 WHEN 7 THEN '222' 
78758                 WHEN 8 THEN '222' 
78759                 WHEN 9 THEN '222' 
78760                 WHEN 10 THEN '222' 
78761                 
78762                 ELSE null
78763               END                           source_application_id
78764             , 'S'             source_type_code
78765             , CASE r
78766                 WHEN 1 THEN 'RMT_BNK_BANK_CHARGES_CCID' 
78767                 WHEN 2 THEN 'RMT_BNK_CASH_CCID' 
78768                 WHEN 3 THEN 'RMT_BNK_CONFIRMATION_CCID' 
78769                 WHEN 4 THEN 'RMT_BNK_REMITTANCE_CCID' 
78770                 WHEN 5 THEN 'RCT_CLASS_REMIT_FLAG' 
78771                 WHEN 6 THEN 'RCT_CLASS_CONFIRM_FLAG' 
78772                 WHEN 7 THEN 'RCT_DOC_SEQUENCE_CATEGORY' 
78773                 WHEN 8 THEN 'RCT_DOC_SEQUENCE_ID' 
78774                 WHEN 9 THEN 'RCT_DOC_SEQUENCE_VALUE' 
78775                 WHEN 10 THEN 'RCT_TRX_ACCT_REVERSAL' 
78776                 
78777                 ELSE null
78778               END                           source_code
78779             , CASE r
78780                 WHEN 1 THEN TO_CHAR(h5.RMT_BNK_BANK_CHARGES_CCID)
78781                 WHEN 2 THEN TO_CHAR(h5.RMT_BNK_CASH_CCID)
78782                 WHEN 3 THEN TO_CHAR(h5.RMT_BNK_CONFIRMATION_CCID)
78783                 WHEN 4 THEN TO_CHAR(h5.RMT_BNK_REMITTANCE_CCID)
78784                 WHEN 5 THEN TO_CHAR(h4.RCT_CLASS_REMIT_FLAG)
78785                 WHEN 6 THEN TO_CHAR(h4.RCT_CLASS_CONFIRM_FLAG)
78786                 WHEN 7 THEN TO_CHAR(h1.RCT_DOC_SEQUENCE_CATEGORY)
78787                 WHEN 8 THEN TO_CHAR(h1.RCT_DOC_SEQUENCE_ID)
78788                 WHEN 9 THEN TO_CHAR(h1.RCT_DOC_SEQUENCE_VALUE)
78789                 WHEN 10 THEN TO_CHAR(h1.RCT_TRX_ACCT_REVERSAL)
78790                 
78791                 ELSE null
78792               END                           source_value
78793             , null              source_meaning
78794          FROM xla_events_gt     xet  
78795       , AR_CASH_RECEIPTS_H_V  h1
78796       , AR_RCT_METHOD_H_V  h4
78797       , AR_REMIT_BANK_ACCT_H_V  h5
78801             
78798              ,(select rownum r from all_objects where rownum <= 10 and owner = p_apps_owner)
78799          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
78800            AND xet.event_class_code = C_EVENT_CLASS_CODE
78802 )
78803 ;
78804 --
78805 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
78806 
78807       trace
78808          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
78809          ,p_level    => C_LEVEL_STATEMENT
78810          ,p_module   => l_log_module);
78811 
78812 END IF;
78813 --
78814 
78815 
78816 
78817 --
78818 INSERT INTO xla_diag_sources  --line2
78819 (
78820         event_id
78821       , ledger_id
78822       , sla_ledger_id
78823       , description_language
78824       , object_name
78825       , object_type_code
78826       , line_number
78827       , source_application_id
78828       , source_type_code
78829       , source_code
78830       , source_value
78831       , source_meaning
78832       , created_by
78833       , creation_date
78834       , last_update_date
78835       , last_updated_by
78836       , last_update_login
78837       , program_update_date
78838       , program_application_id
78839       , program_id
78840       , request_id
78841 )
78842 SELECT  event_id
78843       , p_target_ledger_id
78844       , p_sla_ledger_id
78845       , p_language
78846       , object_name
78847       , object_type_code
78848       , line_number
78849       , source_application_id
78850       , source_type_code
78851       , source_code
78852       , SUBSTR(source_value,1,1996)
78853       , SUBSTR(source_meaning ,1,200)
78854       , xla_environment_pkg.g_Usr_Id
78855       , TRUNC(SYSDATE)
78856       , TRUNC(SYSDATE)
78857       , xla_environment_pkg.g_Usr_Id
78858       , xla_environment_pkg.g_Login_Id
78859       , TRUNC(SYSDATE)
78860       , xla_environment_pkg.g_Prog_Appl_Id
78861       , xla_environment_pkg.g_Prog_Id
78862       , xla_environment_pkg.g_Req_Id
78863   FROM (
78864        SELECT xet.event_id                  event_id
78865             , l3.line_number                 line_number
78866             , CASE r
78867                WHEN 1 THEN 'AR_DISTRIBUTIONS_L_V' 
78868                 WHEN 2 THEN 'FV_XLA_AR_REF_V' 
78869                 WHEN 3 THEN 'FV_XLA_AR_REF_V' 
78870                 WHEN 4 THEN 'FV_XLA_AR_REF_V' 
78871                 WHEN 5 THEN 'FV_XLA_AR_REF_V' 
78872                 WHEN 6 THEN 'FV_XLA_AR_REF_V' 
78873                 WHEN 7 THEN 'AR_DISTRIBUTIONS_L_V' 
78874                 WHEN 8 THEN 'AR_DISTRIBUTIONS_L_V' 
78875                 WHEN 9 THEN 'AR_DISTRIBUTIONS_L_V' 
78876                 WHEN 10 THEN 'AR_DISTRIBUTIONS_L_V' 
78877                 WHEN 11 THEN 'AR_DISTRIBUTIONS_L_V' 
78878                 WHEN 12 THEN 'AR_DISTRIBUTIONS_BASE_V' 
78879                 WHEN 13 THEN 'AR_DISTRIBUTIONS_BASE_V' 
78880                 WHEN 14 THEN 'AR_DISTRIBUTIONS_BASE_V' 
78881                 WHEN 15 THEN 'FV_XLA_AR_REF_V' 
78882                 WHEN 16 THEN 'AR_DISTRIBUTIONS_BASE_V' 
78883                 WHEN 17 THEN 'AR_DISTRIBUTIONS_L_V' 
78884                 
78885                ELSE null
78886               END                           object_name
78887             , CASE r
78888                 WHEN 1 THEN 'LINE' 
78889                 WHEN 2 THEN 'LINE' 
78890                 WHEN 3 THEN 'LINE' 
78891                 WHEN 4 THEN 'LINE' 
78892                 WHEN 5 THEN 'LINE' 
78893                 WHEN 6 THEN 'LINE' 
78894                 WHEN 7 THEN 'LINE' 
78895                 WHEN 8 THEN 'LINE' 
78896                 WHEN 9 THEN 'LINE' 
78897                 WHEN 10 THEN 'LINE' 
78898                 WHEN 11 THEN 'LINE' 
78899                 WHEN 12 THEN 'LINE' 
78900                 WHEN 13 THEN 'LINE' 
78901                 WHEN 14 THEN 'LINE' 
78902                 WHEN 15 THEN 'LINE' 
78903                 WHEN 16 THEN 'LINE' 
78904                 WHEN 17 THEN 'LINE' 
78905                 
78906                 ELSE null
78907               END                           object_type_code
78908             , CASE r
78909                 WHEN 1 THEN '222' 
78910                 WHEN 2 THEN '8901' 
78911                 WHEN 3 THEN '8901' 
78912                 WHEN 4 THEN '8901' 
78913                 WHEN 5 THEN '8901' 
78914                 WHEN 6 THEN '8901' 
78915                 WHEN 7 THEN '222' 
78916                 WHEN 8 THEN '222' 
78917                 WHEN 9 THEN '222' 
78918                 WHEN 10 THEN '222' 
78919                 WHEN 11 THEN '222' 
78920                 WHEN 12 THEN '222' 
78921                 WHEN 13 THEN '222' 
78922                 WHEN 14 THEN '222' 
78923                 WHEN 15 THEN '8901' 
78924                 WHEN 16 THEN '222' 
78925                 WHEN 17 THEN '222' 
78926                 
78927                 ELSE null
78928               END                           source_application_id
78929             , 'S'             source_type_code
78930             , CASE r
78931                 WHEN 1 THEN 'DIST_CODE_COMBINATION_ID' 
78932                 WHEN 2 THEN 'FEDERAL_FUND_CATEGORY' 
78933                 WHEN 3 THEN 'FEDERAL_FUND_EXPIRED_STATUS' 
78934                 WHEN 4 THEN 'FEDERAL_PRIOR_YEAR_FLAG' 
78935                 WHEN 5 THEN 'FEDERAL_FUND_TIME_FRAME' 
78936                 WHEN 6 THEN 'FEDERAL_APPORTIONMENT_CATEGORY' 
78937                 WHEN 7 THEN 'DIST_SOURCE_TYPE' 
78938                 WHEN 8 THEN 'DIST_LINE_ID' 
78939                 WHEN 9 THEN 'DISTRIBUTION_TYPE' 
78940                 WHEN 10 THEN 'DIST_ENT_AMT' 
78941                 WHEN 11 THEN 'DIST_CURRENCY_CODE' 
78942                 WHEN 12 THEN 'DIST_CUR_CONVERSION_RATE' 
78943                 WHEN 13 THEN 'DIST_CUR_CONVERSION_TYPE' 
78947                 WHEN 17 THEN 'DIST_MFAR_ADDITIONAL_ENTRY' 
78944                 WHEN 14 THEN 'DIST_TO_ACCTD_AMT' 
78945                 WHEN 15 THEN 'FEDERAL_ACCOUNT_VALID_FLAG' 
78946                 WHEN 16 THEN 'DIST_TO_CUR_CONVERSION_DATE' 
78948                 
78949                 ELSE null
78950               END                           source_code
78951             , CASE r
78952                 WHEN 1 THEN TO_CHAR(l3.DIST_CODE_COMBINATION_ID)
78953                 WHEN 2 THEN TO_CHAR(l6.FEDERAL_FUND_CATEGORY)
78954                 WHEN 3 THEN TO_CHAR(l6.FEDERAL_FUND_EXPIRED_STATUS)
78955                 WHEN 4 THEN TO_CHAR(l6.FEDERAL_PRIOR_YEAR_FLAG)
78956                 WHEN 5 THEN TO_CHAR(l6.FEDERAL_FUND_TIME_FRAME)
78957                 WHEN 6 THEN TO_CHAR(l6.FEDERAL_APPORTIONMENT_CATEGORY)
78958                 WHEN 7 THEN TO_CHAR(l3.DIST_SOURCE_TYPE)
78959                 WHEN 8 THEN TO_CHAR(l3.DIST_LINE_ID)
78960                 WHEN 9 THEN TO_CHAR(l3.DISTRIBUTION_TYPE)
78961                 WHEN 10 THEN TO_CHAR(l3.DIST_ENT_AMT)
78962                 WHEN 11 THEN TO_CHAR(l3.DIST_CURRENCY_CODE)
78963                 WHEN 12 THEN TO_CHAR(l2.DIST_CUR_CONVERSION_RATE)
78964                 WHEN 13 THEN TO_CHAR(l2.DIST_CUR_CONVERSION_TYPE)
78965                 WHEN 14 THEN TO_CHAR(l2.DIST_TO_ACCTD_AMT)
78966                 WHEN 15 THEN TO_CHAR(l6.FEDERAL_ACCOUNT_VALID_FLAG)
78967                 WHEN 16 THEN TO_CHAR(l2.DIST_TO_CUR_CONVERSION_DATE)
78968                 WHEN 17 THEN TO_CHAR(l3.DIST_MFAR_ADDITIONAL_ENTRY)
78969                 
78970                 ELSE null
78971               END                           source_value
78972             , null              source_meaning
78973          FROM  xla_events_gt     xet  
78974         , AR_DISTRIBUTIONS_BASE_V  l2
78975         , AR_DISTRIBUTIONS_L_V  l3
78976         , FV_XLA_AR_REF_V  l6
78977             , (select rownum r from all_objects where rownum <= 17 and owner = p_apps_owner)
78978         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
78979           AND xet.event_class_code = C_EVENT_CLASS_CODE
78980             AND l2.event_id          = xet.event_id
78981   AND l3.event_id    = l2.event_id
78982   AND l3.line_number = l2.line_number
78983  AND l6.federal_event_id   (+) =  l3.event_id  and l6.federal_line_number   (+) =  l3.line_number
78984 )
78985 ;
78986 --
78987 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
78988 
78989       trace
78990          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
78991          ,p_level    => C_LEVEL_STATEMENT
78992          ,p_module   => l_log_module);
78993 
78994 END IF;
78995 
78996 
78997 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
78998       trace
78999          (p_msg      => 'END of insert_sources_143'
79000          ,p_level    => C_LEVEL_PROCEDURE
79001          ,p_module   => l_log_module);
79002 END IF;
79003 EXCEPTION
79004   WHEN xla_exceptions_pkg.application_exception THEN
79005       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
79006             trace
79007                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
79008                ,p_level    => C_LEVEL_EXCEPTION
79009                ,p_module   => l_log_module);
79010       END IF;
79011       RAISE;
79012   WHEN OTHERS THEN
79013       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
79014             trace
79015                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
79016                ,p_level    => C_LEVEL_EXCEPTION
79017                ,p_module   => l_log_module);
79018        END IF;
79019        xla_exceptions_pkg.raise_message
79020            (p_location => 'XLA_00222_AAD_S_000006_PKG.insert_sources_143');
79021 END insert_sources_143;
79022 --
79023 
79024 ---------------------------------------
79025 --
79026 -- PRIVATE FUNCTION
79027 --         EventClass_143
79028 --
79029 ----------------------------------------
79030 --
79031 FUNCTION EventClass_143
79032        (p_application_id         IN NUMBER
79033        ,p_base_ledger_id         IN NUMBER
79034        ,p_target_ledger_id       IN NUMBER
79035        ,p_language               IN VARCHAR2
79036        ,p_currency_code          IN VARCHAR2
79037        ,p_sla_ledger_id          IN NUMBER
79038        ,p_pad_start_date         IN DATE
79039        ,p_pad_end_date           IN DATE
79040        ,p_primary_ledger_id      IN NUMBER)
79041 RETURN BOOLEAN IS
79042 --
79043 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'MISC_RECEIPT_ALL';
79044 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'MISC_RECEIPT';
79045 
79046 l_calculate_acctd_flag   VARCHAR2(1) :='N';
79047 l_calculate_g_l_flag     VARCHAR2(1) :='N';
79048 --
79049 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
79050 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
79051 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
79052 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
79053 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
79054 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
79055 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
79056 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
79057 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
79058 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
79059 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
79060 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
79061 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
79062 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
79063 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
79064 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
79068 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
79065 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
79066 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
79067 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
79069 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
79070 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
79071 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
79072 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
79073 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
79074 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
79075 
79076 l_event_id                             NUMBER;
79077 l_previous_event_id                    NUMBER;
79078 l_first_event_id                       NUMBER;
79079 l_last_event_id                        NUMBER;
79080 
79081 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
79082 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
79083 --
79084 --
79085 l_result                    BOOLEAN := TRUE;
79086 l_rows                      NUMBER  := 1000;
79087 l_event_type_name           VARCHAR2(80) := 'All';
79088 l_event_class_name          VARCHAR2(80) := 'Miscellaneous Receipt';
79089 l_description               VARCHAR2(4000);
79090 l_transaction_reversal      NUMBER;
79091 l_ae_header_id              NUMBER;
79092 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
79093 l_log_module                VARCHAR2(240);
79094 --
79095 l_acct_reversal_source      VARCHAR2(30);
79096 l_trx_reversal_source       VARCHAR2(30);
79097 
79098 l_continue_with_lines       BOOLEAN := TRUE;
79099 --
79100 l_acc_rev_gl_date_source    DATE;                      -- 4262811
79101 --
79102 type t_array_event_id is table of number index by binary_integer;
79103 
79104 l_rec_array_event                    t_rec_array_event;
79105 l_null_rec_array_event               t_rec_array_event;
79106 l_array_ae_header_id                 xla_number_array_type;
79107 l_actual_flag                        VARCHAR2(1) := NULL;
79108 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
79109 l_balance_type_code                  VARCHAR2(1) :=NULL;
79110 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
79111 
79112 --
79113 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
79114 --
79115 
79116 TYPE t_array_source_1 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_BANK_CHARGES_CCID%TYPE INDEX BY BINARY_INTEGER;
79117 TYPE t_array_source_13 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_CASH_CCID%TYPE INDEX BY BINARY_INTEGER;
79118 TYPE t_array_source_14 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_CONFIRMATION_CCID%TYPE INDEX BY BINARY_INTEGER;
79119 TYPE t_array_source_15 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_REMITTANCE_CCID%TYPE INDEX BY BINARY_INTEGER;
79120 TYPE t_array_source_70 IS TABLE OF AR_RCT_METHOD_H_V.RCT_CLASS_REMIT_FLAG%TYPE INDEX BY BINARY_INTEGER;
79121 TYPE t_array_source_71 IS TABLE OF AR_RCT_METHOD_H_V.RCT_CLASS_CONFIRM_FLAG%TYPE INDEX BY BINARY_INTEGER;
79122 TYPE t_array_source_86 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
79123 TYPE t_array_source_87 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
79124 TYPE t_array_source_88 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
79125 TYPE t_array_source_89 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_TRX_ACCT_REVERSAL%TYPE INDEX BY BINARY_INTEGER;
79126 
79127 TYPE t_array_source_3 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CODE_COMBINATION_ID%TYPE INDEX BY BINARY_INTEGER;
79128 TYPE t_array_source_5 IS TABLE OF FV_XLA_AR_REF_V.FEDERAL_FUND_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
79129 TYPE t_array_source_8 IS TABLE OF FV_XLA_AR_REF_V.FEDERAL_FUND_EXPIRED_STATUS%TYPE INDEX BY BINARY_INTEGER;
79130 TYPE t_array_source_9 IS TABLE OF FV_XLA_AR_REF_V.FEDERAL_PRIOR_YEAR_FLAG%TYPE INDEX BY BINARY_INTEGER;
79131 TYPE t_array_source_10 IS TABLE OF FV_XLA_AR_REF_V.FEDERAL_FUND_TIME_FRAME%TYPE INDEX BY BINARY_INTEGER;
79132 TYPE t_array_source_11 IS TABLE OF FV_XLA_AR_REF_V.FEDERAL_APPORTIONMENT_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
79133 TYPE t_array_source_20 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_SOURCE_TYPE%TYPE INDEX BY BINARY_INTEGER;
79134 TYPE t_array_source_22 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
79135 TYPE t_array_source_23 IS TABLE OF AR_DISTRIBUTIONS_L_V.DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
79136 TYPE t_array_source_24 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_ENT_AMT%TYPE INDEX BY BINARY_INTEGER;
79137 TYPE t_array_source_25 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
79138 TYPE t_array_source_27 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
79139 TYPE t_array_source_28 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
79140 TYPE t_array_source_29 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
79141 TYPE t_array_source_56 IS TABLE OF FV_XLA_AR_REF_V.FEDERAL_ACCOUNT_VALID_FLAG%TYPE INDEX BY BINARY_INTEGER;
79142 TYPE t_array_source_57 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
79143 TYPE t_array_source_69 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_MFAR_ADDITIONAL_ENTRY%TYPE INDEX BY BINARY_INTEGER;
79144 
79145 l_array_source_1              t_array_source_1;
79146 l_array_source_13              t_array_source_13;
79147 l_array_source_14              t_array_source_14;
79148 l_array_source_15              t_array_source_15;
79149 l_array_source_70              t_array_source_70;
79150 l_array_source_71              t_array_source_71;
79151 l_array_source_86              t_array_source_86;
79152 l_array_source_87              t_array_source_87;
79153 l_array_source_88              t_array_source_88;
79154 l_array_source_89              t_array_source_89;
79155 
79156 l_array_source_3      t_array_source_3;
79160 l_array_source_10      t_array_source_10;
79157 l_array_source_5      t_array_source_5;
79158 l_array_source_8      t_array_source_8;
79159 l_array_source_9      t_array_source_9;
79161 l_array_source_11      t_array_source_11;
79162 l_array_source_20      t_array_source_20;
79163 l_array_source_22      t_array_source_22;
79164 l_array_source_23      t_array_source_23;
79165 l_array_source_24      t_array_source_24;
79166 l_array_source_25      t_array_source_25;
79167 l_array_source_27      t_array_source_27;
79168 l_array_source_28      t_array_source_28;
79169 l_array_source_29      t_array_source_29;
79170 l_array_source_56      t_array_source_56;
79171 l_array_source_57      t_array_source_57;
79172 l_array_source_69      t_array_source_69;
79173 
79174 --
79175 CURSOR header_cur
79176 IS
79177 SELECT /*+ leading(xet) cardinality(xet,1) */
79178 -- Event Class Code: MISC_RECEIPT
79179     xet.entity_id
79180    ,xet.legal_entity_id
79181    ,xet.entity_code
79182    ,xet.transaction_number
79183    ,xet.event_id
79184    ,xet.event_class_code
79185    ,xet.event_type_code
79186    ,xet.event_number
79187    ,xet.event_date
79188    ,xet.transaction_date
79189    ,xet.reference_num_1
79190    ,xet.reference_num_2
79191    ,xet.reference_num_3
79192    ,xet.reference_num_4
79193    ,xet.reference_char_1
79194    ,xet.reference_char_2
79195    ,xet.reference_char_3
79196    ,xet.reference_char_4
79197    ,xet.reference_date_1
79198    ,xet.reference_date_2
79199    ,xet.reference_date_3
79200    ,xet.reference_date_4
79201    ,xet.event_created_by
79202    ,xet.budgetary_control_flag 
79203   , h5.RMT_BNK_BANK_CHARGES_CCID    source_1
79204   , h5.RMT_BNK_CASH_CCID    source_13
79205   , h5.RMT_BNK_CONFIRMATION_CCID    source_14
79206   , h5.RMT_BNK_REMITTANCE_CCID    source_15
79207   , h4.RCT_CLASS_REMIT_FLAG    source_70
79208   , h4.RCT_CLASS_CONFIRM_FLAG    source_71
79209   , h1.RCT_DOC_SEQUENCE_CATEGORY    source_86
79210   , h1.RCT_DOC_SEQUENCE_ID    source_87
79211   , h1.RCT_DOC_SEQUENCE_VALUE    source_88
79212   , h1.RCT_TRX_ACCT_REVERSAL    source_89
79213   FROM xla_events_gt     xet 
79214   , AR_CASH_RECEIPTS_H_V  h1
79215   , AR_RCT_METHOD_H_V  h4
79216   , AR_REMIT_BANK_ACCT_H_V  h5
79217  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
79218    and xet.event_class_code = C_EVENT_CLASS_CODE
79219    and xet.event_status_code <> 'N'   AND h1.event_id (+) = xet.event_id
79220   AND h4.event_id (+) = xet.event_id
79221   AND h5.event_id (+) = xet.event_id
79222 
79223  ORDER BY event_id
79224 ;
79225 
79226 
79227 --
79228 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
79229 IS
79230 SELECT  /*+ leading(xet) cardinality(xet,1) */
79231 -- Event Class Code: MISC_RECEIPT
79232     xet.entity_id
79233    ,xet.legal_entity_id
79234    ,xet.entity_code
79235    ,xet.transaction_number
79236    ,xet.event_id
79237    ,xet.event_class_code
79238    ,xet.event_type_code
79239    ,xet.event_number
79240    ,xet.event_date
79241    ,xet.transaction_date
79242    ,xet.reference_num_1
79243    ,xet.reference_num_2
79244    ,xet.reference_num_3
79245    ,xet.reference_num_4
79246    ,xet.reference_char_1
79247    ,xet.reference_char_2
79248    ,xet.reference_char_3
79249    ,xet.reference_char_4
79250    ,xet.reference_date_1
79251    ,xet.reference_date_2
79252    ,xet.reference_date_3
79253    ,xet.reference_date_4
79254    ,xet.event_created_by
79255    ,xet.budgetary_control_flag
79256  , l2.LINE_NUMBER  
79257   , l3.DIST_CODE_COMBINATION_ID    source_3
79258   , l6.FEDERAL_FUND_CATEGORY    source_5
79259   , l6.FEDERAL_FUND_EXPIRED_STATUS    source_8
79260   , l6.FEDERAL_PRIOR_YEAR_FLAG    source_9
79261   , l6.FEDERAL_FUND_TIME_FRAME    source_10
79262   , l6.FEDERAL_APPORTIONMENT_CATEGORY    source_11
79263   , l3.DIST_SOURCE_TYPE    source_20
79264   , l3.DIST_LINE_ID    source_22
79265   , l3.DISTRIBUTION_TYPE    source_23
79266   , l3.DIST_ENT_AMT    source_24
79267   , l3.DIST_CURRENCY_CODE    source_25
79268   , l2.DIST_CUR_CONVERSION_RATE    source_27
79269   , l2.DIST_CUR_CONVERSION_TYPE    source_28
79270   , l2.DIST_TO_ACCTD_AMT    source_29
79271   , l6.FEDERAL_ACCOUNT_VALID_FLAG    source_56
79272   , l2.DIST_TO_CUR_CONVERSION_DATE    source_57
79273   , l3.DIST_MFAR_ADDITIONAL_ENTRY    source_69
79274   FROM xla_events_gt     xet 
79275   , AR_DISTRIBUTIONS_BASE_V  l2
79276   , AR_DISTRIBUTIONS_L_V  l3
79277   , FV_XLA_AR_REF_V  l6
79278  WHERE xet.event_id between x_first_event_id and x_last_event_id
79279    and xet.event_date between p_pad_start_date and p_pad_end_date
79280    and xet.event_class_code = C_EVENT_CLASS_CODE
79281    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
79282   AND l3.event_id    = l2.event_id
79283   AND l3.line_number = l2.line_number
79284  AND l6.federal_event_id   (+) =  l3.event_id  AND l6.federal_line_number   (+) =  l3.line_number;
79285 
79286 --
79287 BEGIN
79288 IF g_log_enabled THEN
79289    l_log_module := C_DEFAULT_MODULE||'.EventClass_143';
79290 END IF;
79291 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
79292    trace
79293       (p_msg      => 'BEGIN of EventClass_143'
79294       ,p_level    => C_LEVEL_PROCEDURE
79295       ,p_module   => l_log_module);
79296 END IF;
79297 
79298 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
79299    trace
79300       (p_msg      => 'p_application_id = '||p_application_id||
79301                      ' - p_base_ledger_id = '||p_base_ledger_id||
79302                      ' - p_target_ledger_id  = '||p_target_ledger_id||
79303                      ' - p_language = '||p_language||
79304                      ' - p_currency_code = '||p_currency_code||
79305                      ' - p_sla_ledger_id = '||p_sla_ledger_id
79309 --
79306       ,p_level    => C_LEVEL_STATEMENT
79307       ,p_module   => l_log_module);
79308 END IF;
79310 -- initialze arrays
79311 --
79312 g_array_event.DELETE;
79313 l_rec_array_event := l_null_rec_array_event;
79314 --
79315 --------------------------------------
79316 -- 4262811 Initialze MPA Line Number
79317 --------------------------------------
79318 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
79319 
79320 --
79321 
79322 --
79323 OPEN header_cur;
79324 --
79325 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
79326    trace
79327    (p_msg      => 'SQL - FETCH header_cur'
79328    ,p_level    => C_LEVEL_STATEMENT
79329    ,p_module   => l_log_module);
79330 END IF;
79331 --
79332 LOOP
79333 FETCH header_cur BULK COLLECT INTO
79334         l_array_entity_id
79335       , l_array_legal_entity_id
79336       , l_array_entity_code
79337       , l_array_transaction_num
79338       , l_array_event_id
79339       , l_array_class_code
79340       , l_array_event_type
79341       , l_array_event_number
79342       , l_array_event_date
79343       , l_array_transaction_date
79344       , l_array_reference_num_1
79345       , l_array_reference_num_2
79346       , l_array_reference_num_3
79347       , l_array_reference_num_4
79348       , l_array_reference_char_1
79349       , l_array_reference_char_2
79350       , l_array_reference_char_3
79351       , l_array_reference_char_4
79352       , l_array_reference_date_1
79353       , l_array_reference_date_2
79354       , l_array_reference_date_3
79355       , l_array_reference_date_4
79356       , l_array_event_created_by
79357       , l_array_budgetary_control_flag 
79358       , l_array_source_1
79359       , l_array_source_13
79360       , l_array_source_14
79361       , l_array_source_15
79362       , l_array_source_70
79363       , l_array_source_71
79364       , l_array_source_86
79365       , l_array_source_87
79366       , l_array_source_88
79367       , l_array_source_89
79368       LIMIT l_rows;
79369 --
79370 IF (C_LEVEL_EVENT >= g_log_level) THEN
79371    trace
79372    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
79373    ,p_level    => C_LEVEL_EVENT
79374    ,p_module   => l_log_module);
79375 END IF;
79376 --
79377 EXIT WHEN l_array_entity_id.COUNT = 0;
79378 
79379 -- initialize arrays
79380 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
79381 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
79382 
79383 --
79384 -- Bug 4458708
79385 --
79386 XLA_AE_LINES_PKG.g_LineNumber := 0;
79387 
79388 
79389 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
79390 g_last_hdr_idx := l_array_event_id.LAST;
79391 --
79392 -- loop for the headers. Each iteration is for each header extract row
79393 -- fetched in header cursor
79394 --
79395 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
79396 
79397 --
79398 -- set event info as cache for other routines to refer event attributes
79399 --
79400 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
79401    (p_application_id           => p_application_id
79402    ,p_primary_ledger_id        => p_primary_ledger_id
79403    ,p_base_ledger_id           => p_base_ledger_id
79404    ,p_target_ledger_id         => p_target_ledger_id
79405    ,p_entity_id                => l_array_entity_id(hdr_idx)
79406    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
79407    ,p_entity_code              => l_array_entity_code(hdr_idx)
79408    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
79409    ,p_event_id                 => l_array_event_id(hdr_idx)
79410    ,p_event_class_code         => l_array_class_code(hdr_idx)
79411    ,p_event_type_code          => l_array_event_type(hdr_idx)
79412    ,p_event_number             => l_array_event_number(hdr_idx)
79413    ,p_event_date               => l_array_event_date(hdr_idx)
79414    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
79415    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
79416    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
79417    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
79418    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
79419    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
79420    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
79421    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
79422    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
79423    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
79424    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
79425    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
79426    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
79427    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
79428    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
79429 
79430 --
79431 -- set the status of entry to C_VALID (0)
79432 --
79433 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
79434 
79435 --
79436 -- initialize a row for ae header
79437 --
79438 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
79439 
79440 l_event_id := l_array_event_id(hdr_idx);
79441 
79442 --
79443 -- storing the hdr_idx for event. May be used by line cursor.
79444 --
79445 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
79446 
79447 --
79448 -- store sources from header extract. This can be improved to
79449 -- store only those sources from header extract that may be used in lines
79450 --
79451 
79452 g_array_event(l_event_id).array_value_num('source_1') := l_array_source_1(hdr_idx);
79456 g_array_event(l_event_id).array_value_char('source_70') := l_array_source_70(hdr_idx);
79453 g_array_event(l_event_id).array_value_num('source_13') := l_array_source_13(hdr_idx);
79454 g_array_event(l_event_id).array_value_num('source_14') := l_array_source_14(hdr_idx);
79455 g_array_event(l_event_id).array_value_num('source_15') := l_array_source_15(hdr_idx);
79457 g_array_event(l_event_id).array_value_char('source_71') := l_array_source_71(hdr_idx);
79458 g_array_event(l_event_id).array_value_char('source_86') := l_array_source_86(hdr_idx);
79459 g_array_event(l_event_id).array_value_num('source_87') := l_array_source_87(hdr_idx);
79460 g_array_event(l_event_id).array_value_num('source_88') := l_array_source_88(hdr_idx);
79461 g_array_event(l_event_id).array_value_char('source_89') := l_array_source_89(hdr_idx);
79462 
79463 --
79464 -- initilaize the status of ae headers for diffrent balance types
79465 -- the status is initialised to C_NOT_CREATED (2)
79466 --
79467 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
79468 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
79469 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
79470 
79471 --
79472 -- call api to validate and store accounting attributes for header
79473 --
79474 
79475 ------------------------------------------------------------
79476 -- Accrual Reversal : to get date for Standard Source (NONE)
79477 ------------------------------------------------------------
79478 l_acc_rev_gl_date_source := NULL;
79479 
79480      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
79481       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_86');
79482      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
79483       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_87');
79484      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
79485       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_88');
79486      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
79487       l_rec_acct_attrs.array_date_value(4) := 
79488 xla_ae_sources_pkg.GetSystemSourceDate(
79489    p_source_code           => 'XLA_EVENT_DATE'
79490  , p_source_type_code      => 'Y'
79491  , p_source_application_id =>  602
79492 );
79493      l_rec_acct_attrs.array_acct_attr_code(5)   := 'TRX_ACCT_REVERSAL_OPTION';
79494       l_rec_acct_attrs.array_char_value(5) := g_array_event(l_event_id).array_value_char('source_89');
79495 
79496 
79497 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
79498 
79499 XLA_AE_HEADER_PKG.SetJeCategoryName;
79500 
79501 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
79502 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
79503 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
79504 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
79505 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
79506 
79507 
79508 -- No header level analytical criteria
79509 
79510 --
79511 --accounting attribute enhancement, bug 3612931
79512 --
79513 l_trx_reversal_source := SUBSTR(g_array_event(l_event_id).array_value_char('source_89'), 1,30);
79514 
79515 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
79516    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
79517 
79518    xla_accounting_err_pkg.build_message
79519       (p_appli_s_name            => 'XLA'
79520       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
79521       ,p_token_1                 => 'ACCT_ATTR_NAME'
79522       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
79523       ,p_token_2                 => 'PRODUCT_NAME'
79524       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
79525       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
79526       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
79527       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
79528 
79529 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
79530    --
79531    -- following sets the accounting attributes needed to reverse
79532    -- accounting for a distributeion
79533    --
79534    xla_ae_lines_pkg.SetTrxReversalAttrs
79535       (p_event_id              => l_event_id
79536       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
79537       ,p_trx_reversal_source   => l_trx_reversal_source);
79538 
79539 END IF;
79540 
79541 
79542 ----------------------------------------------------------------
79543 -- 4262811 -  update the header statuses to invalid in need be
79544 ----------------------------------------------------------------
79545 --
79546 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
79547 
79548 
79549   -----------------------------------------------
79550   -- No accrual reversal for the event class/type
79551   -----------------------------------------------
79552 ----------------------------------------------------------------
79553 
79554 --
79555 -- this ends the header loop iteration for one bulk fetch
79556 --
79557 END LOOP;
79558 
79559 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
79560 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
79561 
79562 --
79563 -- insert dummy rows into lines gt table that were created due to
79564 -- transaction reversals
79565 --
79566 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
79567    l_result := XLA_AE_LINES_PKG.InsertLines;
79568 END IF;
79572 -- cursor rather than doing it for each new event in line cursor
79569 
79570 --
79571 -- reset the temp_line_num for each set of events fetched from header
79573 -- Bug 3939231
79574 --
79575 xla_ae_lines_pkg.g_temp_line_num := 0;
79576 
79577 
79578 
79579 --
79580 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
79581 --
79582 --
79583 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
79584 
79585       trace
79586          (p_msg      => 'SQL - FETCH line_cur'
79587          ,p_level    => C_LEVEL_STATEMENT
79588          ,p_module   => l_log_module);
79589 
79590 END IF;
79591 --
79592 --
79593 LOOP
79594   --
79595   FETCH line_cur BULK COLLECT INTO
79596         l_array_entity_id
79597       , l_array_legal_entity_id
79598       , l_array_entity_code
79599       , l_array_transaction_num
79600       , l_array_event_id
79601       , l_array_class_code
79602       , l_array_event_type
79603       , l_array_event_number
79604       , l_array_event_date
79605       , l_array_transaction_date
79606       , l_array_reference_num_1
79607       , l_array_reference_num_2
79608       , l_array_reference_num_3
79609       , l_array_reference_num_4
79610       , l_array_reference_char_1
79611       , l_array_reference_char_2
79612       , l_array_reference_char_3
79613       , l_array_reference_char_4
79614       , l_array_reference_date_1
79615       , l_array_reference_date_2
79616       , l_array_reference_date_3
79617       , l_array_reference_date_4
79618       , l_array_event_created_by
79619       , l_array_budgetary_control_flag
79620       , l_array_extract_line_num 
79621       , l_array_source_3
79622       , l_array_source_5
79623       , l_array_source_8
79624       , l_array_source_9
79625       , l_array_source_10
79626       , l_array_source_11
79627       , l_array_source_20
79628       , l_array_source_22
79629       , l_array_source_23
79630       , l_array_source_24
79631       , l_array_source_25
79632       , l_array_source_27
79633       , l_array_source_28
79634       , l_array_source_29
79635       , l_array_source_56
79636       , l_array_source_57
79637       , l_array_source_69
79638       LIMIT l_rows;
79639 
79640   --
79641   IF (C_LEVEL_EVENT >= g_log_level) THEN
79642             trace
79643                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
79644                ,p_level    => C_LEVEL_EVENT
79645                ,p_module   => l_log_module);
79646   END IF;
79647   --
79648   EXIT WHEN l_array_entity_id.count = 0;
79649 
79650   XLA_AE_LINES_PKG.g_rec_lines := null;
79651 
79652 --
79653 -- Bug 4458708
79654 --
79655 XLA_AE_LINES_PKG.g_LineNumber := 0;
79656 --
79657 --
79658 
79659 FOR Idx IN 1..l_array_event_id.count LOOP
79660    --
79661    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
79662    --
79663    l_event_id := l_array_event_id(idx);  -- 5648433
79664 
79665    --
79666    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
79667    --
79668 
79669    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
79670              (g_array_event(l_event_id).array_value_num('header_index'))
79671          ,'N'
79672          ) <> 'Y'
79673    THEN
79674       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
79675          trace
79676             (p_msg      => 'Trancaction revesal option is not Y '
79677             ,p_level    => C_LEVEL_STATEMENT
79678             ,p_module   => l_log_module);
79679       END IF;
79680 
79681 --
79682 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
79683 --
79684 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
79685 --
79686 -- set event info as cache for other routines to refer event attributes
79687 --
79688 
79689 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
79690    l_previous_event_id := l_event_id;
79691 
79692    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
79693       (p_application_id           => p_application_id
79694       ,p_primary_ledger_id        => p_primary_ledger_id
79695       ,p_base_ledger_id           => p_base_ledger_id
79696       ,p_target_ledger_id         => p_target_ledger_id
79697       ,p_entity_id                => l_array_entity_id(Idx)
79698       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
79699       ,p_entity_code              => l_array_entity_code(Idx)
79700       ,p_transaction_num          => l_array_transaction_num(Idx)
79701       ,p_event_id                 => l_array_event_id(Idx)
79702       ,p_event_class_code         => l_array_class_code(Idx)
79703       ,p_event_type_code          => l_array_event_type(Idx)
79704       ,p_event_number             => l_array_event_number(Idx)
79705       ,p_event_date               => l_array_event_date(Idx)
79706       ,p_transaction_date         => l_array_transaction_date(Idx)
79707       ,p_reference_num_1          => l_array_reference_num_1(Idx)
79708       ,p_reference_num_2          => l_array_reference_num_2(Idx)
79709       ,p_reference_num_3          => l_array_reference_num_3(Idx)
79710       ,p_reference_num_4          => l_array_reference_num_4(Idx)
79711       ,p_reference_char_1         => l_array_reference_char_1(Idx)
79712       ,p_reference_char_2         => l_array_reference_char_2(Idx)
79713       ,p_reference_char_3         => l_array_reference_char_3(Idx)
79714       ,p_reference_char_4         => l_array_reference_char_4(Idx)
79715       ,p_reference_date_1         => l_array_reference_date_1(Idx)
79716       ,p_reference_date_2         => l_array_reference_date_2(Idx)
79717       ,p_reference_date_3         => l_array_reference_date_3(Idx)
79721        --
79718       ,p_reference_date_4         => l_array_reference_date_4(Idx)
79719       ,p_event_created_by         => l_array_event_created_by(Idx)
79720       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
79722 END IF;
79723 
79724 
79725 
79726 --
79727 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
79728 
79729 l_acct_reversal_source := SUBSTR(NULL, 1,30);
79730 
79731 IF l_continue_with_lines THEN
79732    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
79733       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
79734 
79735       xla_accounting_err_pkg.build_message
79736          (p_appli_s_name            => 'XLA'
79737          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
79738          ,p_token_1                 => 'LINE_NUMBER'
79739          ,p_value_1                 => l_array_extract_line_num(Idx)
79740          ,p_token_2                 => 'PRODUCT_NAME'
79741          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
79742          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
79743          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
79744          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
79745 
79746    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
79747       --
79748       -- following sets the accounting attributes needed to reverse
79749       -- accounting for a distributeion
79750       --
79751 
79752       --
79753       -- 5217187
79754       --
79755       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
79756       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
79757                                        g_array_event(l_event_id).array_value_num('header_index'));
79758       --
79759       --
79760 
79761       -- No reversal code generated
79762 
79763       xla_ae_lines_pkg.SetAcctReversalAttrs
79764          (p_event_id             => l_event_id
79765          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
79766          ,p_calculate_acctd_flag => l_calculate_acctd_flag
79767          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
79768    END IF;
79769 
79770    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
79771        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
79772 
79773 --
79774 AcctLineType_61 (
79775  p_application_id  => p_application_id
79776  ,p_event_id     => l_event_id
79777  ,p_calculate_acctd_flag => l_calculate_acctd_flag
79778  ,p_calculate_g_l_flag => l_calculate_g_l_flag
79779  ,p_actual_flag => l_actual_flag
79780  ,p_balance_type_code => l_balance_type_code
79781  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
79782  
79783  , p_source_3 => l_array_source_3(Idx)
79784  , p_source_8 => l_array_source_8(Idx)
79785  , p_source_9 => l_array_source_9(Idx)
79786  , p_source_10 => l_array_source_10(Idx)
79787  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
79788  , p_source_20 => l_array_source_20(Idx)
79789  , p_source_22 => l_array_source_22(Idx)
79790  , p_source_23 => l_array_source_23(Idx)
79791  , p_source_24 => l_array_source_24(Idx)
79792  , p_source_25 => l_array_source_25(Idx)
79793  , p_source_27 => l_array_source_27(Idx)
79794  , p_source_28 => l_array_source_28(Idx)
79795  , p_source_29 => l_array_source_29(Idx)
79796  , p_source_56 => l_array_source_56(Idx)
79797  , p_source_57 => l_array_source_57(Idx)
79798  );
79799 If(l_balance_type_code = 'A') THEN
79800   l_actual_gain_loss_ref := l_gain_or_loss_ref;
79801 END IF;
79802 
79803 --
79804 
79805 
79806 --
79807 AcctLineType_62 (
79808  p_application_id  => p_application_id
79809  ,p_event_id     => l_event_id
79810  ,p_calculate_acctd_flag => l_calculate_acctd_flag
79811  ,p_calculate_g_l_flag => l_calculate_g_l_flag
79812  ,p_actual_flag => l_actual_flag
79813  ,p_balance_type_code => l_balance_type_code
79814  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
79815  
79816  , p_source_3 => l_array_source_3(Idx)
79817  , p_source_8 => l_array_source_8(Idx)
79818  , p_source_9 => l_array_source_9(Idx)
79819  , p_source_10 => l_array_source_10(Idx)
79820  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
79821  , p_source_20 => l_array_source_20(Idx)
79822  , p_source_22 => l_array_source_22(Idx)
79823  , p_source_23 => l_array_source_23(Idx)
79824  , p_source_24 => l_array_source_24(Idx)
79825  , p_source_25 => l_array_source_25(Idx)
79826  , p_source_27 => l_array_source_27(Idx)
79827  , p_source_28 => l_array_source_28(Idx)
79828  , p_source_29 => l_array_source_29(Idx)
79829  , p_source_56 => l_array_source_56(Idx)
79830  , p_source_57 => l_array_source_57(Idx)
79831  );
79832 If(l_balance_type_code = 'A') THEN
79833   l_actual_gain_loss_ref := l_gain_or_loss_ref;
79834 END IF;
79835 
79836 --
79837 
79838 
79839 --
79840 AcctLineType_63 (
79841  p_application_id  => p_application_id
79842  ,p_event_id     => l_event_id
79843  ,p_calculate_acctd_flag => l_calculate_acctd_flag
79844  ,p_calculate_g_l_flag => l_calculate_g_l_flag
79845  ,p_actual_flag => l_actual_flag
79846  ,p_balance_type_code => l_balance_type_code
79847  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
79848  
79849  , p_source_3 => l_array_source_3(Idx)
79850  , p_source_8 => l_array_source_8(Idx)
79851  , p_source_9 => l_array_source_9(Idx)
79852  , p_source_10 => l_array_source_10(Idx)
79853  , p_source_11 => l_array_source_11(Idx)
79854  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
79855  , p_source_20 => l_array_source_20(Idx)
79856  , p_source_22 => l_array_source_22(Idx)
79857  , p_source_23 => l_array_source_23(Idx)
79861  , p_source_28 => l_array_source_28(Idx)
79858  , p_source_24 => l_array_source_24(Idx)
79859  , p_source_25 => l_array_source_25(Idx)
79860  , p_source_27 => l_array_source_27(Idx)
79862  , p_source_29 => l_array_source_29(Idx)
79863  , p_source_56 => l_array_source_56(Idx)
79864  , p_source_57 => l_array_source_57(Idx)
79865  );
79866 If(l_balance_type_code = 'A') THEN
79867   l_actual_gain_loss_ref := l_gain_or_loss_ref;
79868 END IF;
79869 
79870 --
79871 
79872 
79873 --
79874 AcctLineType_64 (
79875  p_application_id  => p_application_id
79876  ,p_event_id     => l_event_id
79877  ,p_calculate_acctd_flag => l_calculate_acctd_flag
79878  ,p_calculate_g_l_flag => l_calculate_g_l_flag
79879  ,p_actual_flag => l_actual_flag
79880  ,p_balance_type_code => l_balance_type_code
79881  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
79882  
79883  , p_source_3 => l_array_source_3(Idx)
79884  , p_source_8 => l_array_source_8(Idx)
79885  , p_source_9 => l_array_source_9(Idx)
79886  , p_source_10 => l_array_source_10(Idx)
79887  , p_source_11 => l_array_source_11(Idx)
79888  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
79889  , p_source_20 => l_array_source_20(Idx)
79890  , p_source_22 => l_array_source_22(Idx)
79891  , p_source_23 => l_array_source_23(Idx)
79892  , p_source_24 => l_array_source_24(Idx)
79893  , p_source_25 => l_array_source_25(Idx)
79894  , p_source_27 => l_array_source_27(Idx)
79895  , p_source_28 => l_array_source_28(Idx)
79896  , p_source_29 => l_array_source_29(Idx)
79897  , p_source_56 => l_array_source_56(Idx)
79898  , p_source_57 => l_array_source_57(Idx)
79899  );
79900 If(l_balance_type_code = 'A') THEN
79901   l_actual_gain_loss_ref := l_gain_or_loss_ref;
79902 END IF;
79903 
79904 --
79905 
79906 
79907 --
79908 AcctLineType_65 (
79909  p_application_id  => p_application_id
79910  ,p_event_id     => l_event_id
79911  ,p_calculate_acctd_flag => l_calculate_acctd_flag
79912  ,p_calculate_g_l_flag => l_calculate_g_l_flag
79913  ,p_actual_flag => l_actual_flag
79914  ,p_balance_type_code => l_balance_type_code
79915  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
79916  
79917  , p_source_3 => l_array_source_3(Idx)
79918  , p_source_8 => l_array_source_8(Idx)
79919  , p_source_9 => l_array_source_9(Idx)
79920  , p_source_10 => l_array_source_10(Idx)
79921  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
79922  , p_source_20 => l_array_source_20(Idx)
79923  , p_source_22 => l_array_source_22(Idx)
79924  , p_source_23 => l_array_source_23(Idx)
79925  , p_source_24 => l_array_source_24(Idx)
79926  , p_source_25 => l_array_source_25(Idx)
79927  , p_source_27 => l_array_source_27(Idx)
79928  , p_source_28 => l_array_source_28(Idx)
79929  , p_source_29 => l_array_source_29(Idx)
79930  , p_source_56 => l_array_source_56(Idx)
79931  , p_source_57 => l_array_source_57(Idx)
79932  );
79933 If(l_balance_type_code = 'A') THEN
79934   l_actual_gain_loss_ref := l_gain_or_loss_ref;
79935 END IF;
79936 
79937 --
79938 
79939 
79940 --
79941 AcctLineType_66 (
79942  p_application_id  => p_application_id
79943  ,p_event_id     => l_event_id
79944  ,p_calculate_acctd_flag => l_calculate_acctd_flag
79945  ,p_calculate_g_l_flag => l_calculate_g_l_flag
79946  ,p_actual_flag => l_actual_flag
79947  ,p_balance_type_code => l_balance_type_code
79948  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
79949  
79950  , p_source_3 => l_array_source_3(Idx)
79951  , p_source_8 => l_array_source_8(Idx)
79952  , p_source_9 => l_array_source_9(Idx)
79953  , p_source_10 => l_array_source_10(Idx)
79954  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
79955  , p_source_20 => l_array_source_20(Idx)
79956  , p_source_22 => l_array_source_22(Idx)
79957  , p_source_23 => l_array_source_23(Idx)
79958  , p_source_24 => l_array_source_24(Idx)
79959  , p_source_25 => l_array_source_25(Idx)
79960  , p_source_27 => l_array_source_27(Idx)
79961  , p_source_28 => l_array_source_28(Idx)
79962  , p_source_29 => l_array_source_29(Idx)
79963  , p_source_56 => l_array_source_56(Idx)
79964  , p_source_57 => l_array_source_57(Idx)
79965  );
79966 If(l_balance_type_code = 'A') THEN
79967   l_actual_gain_loss_ref := l_gain_or_loss_ref;
79968 END IF;
79969 
79970 --
79971 
79972 
79973 --
79974 AcctLineType_67 (
79975  p_application_id  => p_application_id
79976  ,p_event_id     => l_event_id
79977  ,p_calculate_acctd_flag => l_calculate_acctd_flag
79978  ,p_calculate_g_l_flag => l_calculate_g_l_flag
79979  ,p_actual_flag => l_actual_flag
79980  ,p_balance_type_code => l_balance_type_code
79981  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
79982  
79983  , p_source_3 => l_array_source_3(Idx)
79984  , p_source_5 => l_array_source_5(Idx)
79985  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
79986  , p_source_20 => l_array_source_20(Idx)
79987  , p_source_22 => l_array_source_22(Idx)
79988  , p_source_23 => l_array_source_23(Idx)
79989  , p_source_24 => l_array_source_24(Idx)
79990  , p_source_25 => l_array_source_25(Idx)
79991  , p_source_27 => l_array_source_27(Idx)
79992  , p_source_28 => l_array_source_28(Idx)
79993  , p_source_29 => l_array_source_29(Idx)
79994  , p_source_56 => l_array_source_56(Idx)
79995  , p_source_57 => l_array_source_57(Idx)
79996  );
79997 If(l_balance_type_code = 'A') THEN
79998   l_actual_gain_loss_ref := l_gain_or_loss_ref;
79999 END IF;
80000 
80001 --
80002 
80003 
80004 --
80005 AcctLineType_68 (
80006  p_application_id  => p_application_id
80007  ,p_event_id     => l_event_id
80008  ,p_calculate_acctd_flag => l_calculate_acctd_flag
80009  ,p_calculate_g_l_flag => l_calculate_g_l_flag
80010  ,p_actual_flag => l_actual_flag
80011  ,p_balance_type_code => l_balance_type_code
80015  , p_source_5 => l_array_source_5(Idx)
80012  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
80013  
80014  , p_source_3 => l_array_source_3(Idx)
80016  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
80017  , p_source_20 => l_array_source_20(Idx)
80018  , p_source_22 => l_array_source_22(Idx)
80019  , p_source_23 => l_array_source_23(Idx)
80020  , p_source_24 => l_array_source_24(Idx)
80021  , p_source_25 => l_array_source_25(Idx)
80022  , p_source_27 => l_array_source_27(Idx)
80023  , p_source_28 => l_array_source_28(Idx)
80024  , p_source_29 => l_array_source_29(Idx)
80025  , p_source_56 => l_array_source_56(Idx)
80026  , p_source_57 => l_array_source_57(Idx)
80027  );
80028 If(l_balance_type_code = 'A') THEN
80029   l_actual_gain_loss_ref := l_gain_or_loss_ref;
80030 END IF;
80031 
80032 --
80033 
80034 
80035 --
80036 AcctLineType_90 (
80037  p_application_id  => p_application_id
80038  ,p_event_id     => l_event_id
80039  ,p_calculate_acctd_flag => l_calculate_acctd_flag
80040  ,p_calculate_g_l_flag => l_calculate_g_l_flag
80041  ,p_actual_flag => l_actual_flag
80042  ,p_balance_type_code => l_balance_type_code
80043  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
80044  
80045  , p_source_1 => g_array_event(l_event_id).array_value_num('source_1')
80046  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
80047  , p_source_20 => l_array_source_20(Idx)
80048  , p_source_22 => l_array_source_22(Idx)
80049  , p_source_23 => l_array_source_23(Idx)
80050  , p_source_24 => l_array_source_24(Idx)
80051  , p_source_25 => l_array_source_25(Idx)
80052  , p_source_27 => l_array_source_27(Idx)
80053  , p_source_28 => l_array_source_28(Idx)
80054  , p_source_29 => l_array_source_29(Idx)
80055  , p_source_57 => l_array_source_57(Idx)
80056  , p_source_69 => l_array_source_69(Idx)
80057  );
80058 If(l_balance_type_code = 'A') THEN
80059   l_actual_gain_loss_ref := l_gain_or_loss_ref;
80060 END IF;
80061 
80062 --
80063 
80064 
80065 --
80066 AcctLineType_91 (
80067  p_application_id  => p_application_id
80068  ,p_event_id     => l_event_id
80069  ,p_calculate_acctd_flag => l_calculate_acctd_flag
80070  ,p_calculate_g_l_flag => l_calculate_g_l_flag
80071  ,p_actual_flag => l_actual_flag
80072  ,p_balance_type_code => l_balance_type_code
80073  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
80074  
80075  , p_source_3 => l_array_source_3(Idx)
80076  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
80077  , p_source_20 => l_array_source_20(Idx)
80078  , p_source_22 => l_array_source_22(Idx)
80079  , p_source_23 => l_array_source_23(Idx)
80080  , p_source_24 => l_array_source_24(Idx)
80081  , p_source_25 => l_array_source_25(Idx)
80082  , p_source_27 => l_array_source_27(Idx)
80083  , p_source_28 => l_array_source_28(Idx)
80084  , p_source_29 => l_array_source_29(Idx)
80085  , p_source_57 => l_array_source_57(Idx)
80086  , p_source_69 => l_array_source_69(Idx)
80087  , p_source_70 => g_array_event(l_event_id).array_value_char('source_70')
80088  , p_source_71 => g_array_event(l_event_id).array_value_char('source_71')
80089  );
80090 If(l_balance_type_code = 'A') THEN
80091   l_actual_gain_loss_ref := l_gain_or_loss_ref;
80092 END IF;
80093 
80094 --
80095 
80096 
80097 --
80098 AcctLineType_92 (
80099  p_application_id  => p_application_id
80100  ,p_event_id     => l_event_id
80101  ,p_calculate_acctd_flag => l_calculate_acctd_flag
80102  ,p_calculate_g_l_flag => l_calculate_g_l_flag
80103  ,p_actual_flag => l_actual_flag
80104  ,p_balance_type_code => l_balance_type_code
80105  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
80106  
80107  , p_source_3 => l_array_source_3(Idx)
80108  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
80109  , p_source_20 => l_array_source_20(Idx)
80110  , p_source_22 => l_array_source_22(Idx)
80111  , p_source_23 => l_array_source_23(Idx)
80112  , p_source_24 => l_array_source_24(Idx)
80113  , p_source_25 => l_array_source_25(Idx)
80114  , p_source_27 => l_array_source_27(Idx)
80115  , p_source_28 => l_array_source_28(Idx)
80116  , p_source_29 => l_array_source_29(Idx)
80117  , p_source_57 => l_array_source_57(Idx)
80118  , p_source_69 => l_array_source_69(Idx)
80119  , p_source_70 => g_array_event(l_event_id).array_value_char('source_70')
80120  );
80121 If(l_balance_type_code = 'A') THEN
80122   l_actual_gain_loss_ref := l_gain_or_loss_ref;
80123 END IF;
80124 
80125 --
80126 
80127 
80128 --
80129 AcctLineType_93 (
80130  p_application_id  => p_application_id
80131  ,p_event_id     => l_event_id
80132  ,p_calculate_acctd_flag => l_calculate_acctd_flag
80133  ,p_calculate_g_l_flag => l_calculate_g_l_flag
80134  ,p_actual_flag => l_actual_flag
80135  ,p_balance_type_code => l_balance_type_code
80136  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
80137  
80138  , p_source_3 => l_array_source_3(Idx)
80139  , p_source_14 => g_array_event(l_event_id).array_value_num('source_14')
80140  , p_source_20 => l_array_source_20(Idx)
80141  , p_source_22 => l_array_source_22(Idx)
80142  , p_source_23 => l_array_source_23(Idx)
80143  , p_source_24 => l_array_source_24(Idx)
80144  , p_source_25 => l_array_source_25(Idx)
80145  , p_source_27 => l_array_source_27(Idx)
80146  , p_source_28 => l_array_source_28(Idx)
80147  , p_source_29 => l_array_source_29(Idx)
80148  , p_source_57 => l_array_source_57(Idx)
80149  , p_source_69 => l_array_source_69(Idx)
80150  );
80151 If(l_balance_type_code = 'A') THEN
80152   l_actual_gain_loss_ref := l_gain_or_loss_ref;
80153 END IF;
80154 
80155 --
80156 
80157 
80158 --
80159 AcctLineType_94 (
80160  p_application_id  => p_application_id
80161  ,p_event_id     => l_event_id
80162  ,p_calculate_acctd_flag => l_calculate_acctd_flag
80166  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
80163  ,p_calculate_g_l_flag => l_calculate_g_l_flag
80164  ,p_actual_flag => l_actual_flag
80165  ,p_balance_type_code => l_balance_type_code
80167  
80168  , p_source_3 => l_array_source_3(Idx)
80169  , p_source_15 => g_array_event(l_event_id).array_value_num('source_15')
80170  , p_source_20 => l_array_source_20(Idx)
80171  , p_source_22 => l_array_source_22(Idx)
80172  , p_source_23 => l_array_source_23(Idx)
80173  , p_source_24 => l_array_source_24(Idx)
80174  , p_source_25 => l_array_source_25(Idx)
80175  , p_source_27 => l_array_source_27(Idx)
80176  , p_source_28 => l_array_source_28(Idx)
80177  , p_source_29 => l_array_source_29(Idx)
80178  , p_source_57 => l_array_source_57(Idx)
80179  , p_source_69 => l_array_source_69(Idx)
80180  );
80181 If(l_balance_type_code = 'A') THEN
80182   l_actual_gain_loss_ref := l_gain_or_loss_ref;
80183 END IF;
80184 
80185 --
80186 
80187 
80188 --
80189 AcctLineType_102 (
80190  p_application_id  => p_application_id
80191  ,p_event_id     => l_event_id
80192  ,p_calculate_acctd_flag => l_calculate_acctd_flag
80193  ,p_calculate_g_l_flag => l_calculate_g_l_flag
80194  ,p_actual_flag => l_actual_flag
80195  ,p_balance_type_code => l_balance_type_code
80196  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
80197  
80198  , p_source_3 => l_array_source_3(Idx)
80199  , p_source_20 => l_array_source_20(Idx)
80200  , p_source_22 => l_array_source_22(Idx)
80201  , p_source_23 => l_array_source_23(Idx)
80202  , p_source_24 => l_array_source_24(Idx)
80203  , p_source_25 => l_array_source_25(Idx)
80204  , p_source_27 => l_array_source_27(Idx)
80205  , p_source_28 => l_array_source_28(Idx)
80206  , p_source_29 => l_array_source_29(Idx)
80207  , p_source_57 => l_array_source_57(Idx)
80208  , p_source_69 => l_array_source_69(Idx)
80209  );
80210 If(l_balance_type_code = 'A') THEN
80211   l_actual_gain_loss_ref := l_gain_or_loss_ref;
80212 END IF;
80213 
80214 --
80215 
80216 
80217 --
80218 AcctLineType_103 (
80219  p_application_id  => p_application_id
80220  ,p_event_id     => l_event_id
80221  ,p_calculate_acctd_flag => l_calculate_acctd_flag
80222  ,p_calculate_g_l_flag => l_calculate_g_l_flag
80223  ,p_actual_flag => l_actual_flag
80224  ,p_balance_type_code => l_balance_type_code
80225  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
80226  
80227  , p_source_3 => l_array_source_3(Idx)
80228  , p_source_20 => l_array_source_20(Idx)
80229  , p_source_22 => l_array_source_22(Idx)
80230  , p_source_23 => l_array_source_23(Idx)
80231  , p_source_24 => l_array_source_24(Idx)
80232  , p_source_25 => l_array_source_25(Idx)
80233  , p_source_27 => l_array_source_27(Idx)
80234  , p_source_28 => l_array_source_28(Idx)
80235  , p_source_29 => l_array_source_29(Idx)
80236  , p_source_57 => l_array_source_57(Idx)
80237  , p_source_69 => l_array_source_69(Idx)
80238  );
80239 If(l_balance_type_code = 'A') THEN
80240   l_actual_gain_loss_ref := l_gain_or_loss_ref;
80241 END IF;
80242 
80243 --
80244 
80245 
80246 --
80247 AcctLineType_104 (
80248  p_application_id  => p_application_id
80249  ,p_event_id     => l_event_id
80250  ,p_calculate_acctd_flag => l_calculate_acctd_flag
80251  ,p_calculate_g_l_flag => l_calculate_g_l_flag
80252  ,p_actual_flag => l_actual_flag
80253  ,p_balance_type_code => l_balance_type_code
80254  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
80255  
80256  , p_source_3 => l_array_source_3(Idx)
80257  , p_source_20 => l_array_source_20(Idx)
80258  , p_source_22 => l_array_source_22(Idx)
80259  , p_source_23 => l_array_source_23(Idx)
80260  , p_source_24 => l_array_source_24(Idx)
80261  , p_source_25 => l_array_source_25(Idx)
80262  , p_source_27 => l_array_source_27(Idx)
80263  , p_source_28 => l_array_source_28(Idx)
80264  , p_source_29 => l_array_source_29(Idx)
80265  , p_source_57 => l_array_source_57(Idx)
80266  , p_source_69 => l_array_source_69(Idx)
80267  );
80268 If(l_balance_type_code = 'A') THEN
80269   l_actual_gain_loss_ref := l_gain_or_loss_ref;
80270 END IF;
80271 
80272 --
80273 
80274 
80275 --
80276 AcctLineType_105 (
80277  p_application_id  => p_application_id
80278  ,p_event_id     => l_event_id
80279  ,p_calculate_acctd_flag => l_calculate_acctd_flag
80280  ,p_calculate_g_l_flag => l_calculate_g_l_flag
80281  ,p_actual_flag => l_actual_flag
80282  ,p_balance_type_code => l_balance_type_code
80283  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
80284  
80285  , p_source_3 => l_array_source_3(Idx)
80286  , p_source_20 => l_array_source_20(Idx)
80287  , p_source_22 => l_array_source_22(Idx)
80288  , p_source_23 => l_array_source_23(Idx)
80289  , p_source_24 => l_array_source_24(Idx)
80290  , p_source_25 => l_array_source_25(Idx)
80291  , p_source_27 => l_array_source_27(Idx)
80292  , p_source_28 => l_array_source_28(Idx)
80293  , p_source_29 => l_array_source_29(Idx)
80294  , p_source_57 => l_array_source_57(Idx)
80295  , p_source_69 => l_array_source_69(Idx)
80296  );
80297 If(l_balance_type_code = 'A') THEN
80298   l_actual_gain_loss_ref := l_gain_or_loss_ref;
80299 END IF;
80300 
80301 --
80302 
80303 
80304 --
80305 AcctLineType_106 (
80306  p_application_id  => p_application_id
80307  ,p_event_id     => l_event_id
80308  ,p_calculate_acctd_flag => l_calculate_acctd_flag
80309  ,p_calculate_g_l_flag => l_calculate_g_l_flag
80310  ,p_actual_flag => l_actual_flag
80311  ,p_balance_type_code => l_balance_type_code
80312  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
80313  
80314  , p_source_3 => l_array_source_3(Idx)
80315  , p_source_20 => l_array_source_20(Idx)
80316  , p_source_22 => l_array_source_22(Idx)
80317  , p_source_23 => l_array_source_23(Idx)
80318  , p_source_24 => l_array_source_24(Idx)
80322  , p_source_29 => l_array_source_29(Idx)
80319  , p_source_25 => l_array_source_25(Idx)
80320  , p_source_27 => l_array_source_27(Idx)
80321  , p_source_28 => l_array_source_28(Idx)
80323  , p_source_57 => l_array_source_57(Idx)
80324  , p_source_69 => l_array_source_69(Idx)
80325  );
80326 If(l_balance_type_code = 'A') THEN
80327   l_actual_gain_loss_ref := l_gain_or_loss_ref;
80328 END IF;
80329 
80330 --
80331 
80332       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
80333       -- or secondary ledger that has different currency with primary
80334       -- or alc that is calculated by sla
80335       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
80336             (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'))
80337 
80338 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
80339 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
80340           AND (l_actual_flag = 'A')) THEN
80341         XLA_AE_LINES_PKG.CreateGainOrLossLines(
80342           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
80343          ,p_application_id   => p_application_id
80344          ,p_amb_context_code => 'DEFAULT'
80345          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
80346          ,p_event_class_code => C_EVENT_CLASS_CODE
80347          ,p_event_type_code  => C_EVENT_TYPE_CODE
80348          
80349          ,p_gain_ccid        => -1
80350          ,p_loss_ccid        => -1
80351 
80352          ,p_actual_flag      => l_actual_flag
80353          ,p_enc_flag         => null
80354          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
80355          ,p_enc_g_l_ref      => null
80356          );
80357       END IF;
80358    END IF;
80359 END IF;
80360 
80361    ELSE
80362       --
80363       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
80364       --
80365       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
80366          trace
80367             (p_msg      => 'Trancaction revesal option is Y'
80368             ,p_level    => C_LEVEL_STATEMENT
80369             ,p_module   => l_log_module);
80370       END IF;
80371    END IF;
80372 
80373 END LOOP;
80374 l_result := XLA_AE_LINES_PKG.InsertLines ;
80375 end loop;
80376 close line_cur;
80377 
80378 
80379 --
80380 -- insert headers into xla_ae_headers_gt table
80381 --
80382 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
80383 
80384 -- insert into errors table here.
80385 
80386 END LOOP;
80387 
80388 --
80389 -- 4865292
80390 --
80391 -- Compare g_hdr_extract_count with event count in
80392 -- CreateHeadersAndLines.
80393 --
80394 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
80395 
80396 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
80397    trace (p_msg     => '# rows extracted from header extract objects '
80398                     || ' (running total): '
80399                     || g_hdr_extract_count
80400          ,p_level   => C_LEVEL_STATEMENT
80401          ,p_module  => l_log_module);
80402 END IF;
80403 
80404 CLOSE header_cur;
80405 --
80406 
80407 --
80408 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
80409    trace
80410       (p_msg      => 'END of EventClass_143'
80411       ,p_level    => C_LEVEL_PROCEDURE
80412       ,p_module   => l_log_module);
80413 END IF;
80414 --
80415 RETURN l_result;
80416 EXCEPTION
80417 WHEN xla_exceptions_pkg.application_exception THEN
80418    
80419 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
80420 
80421    
80422 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
80423 
80424    RAISE;
80425 
80426 WHEN NO_DATA_FOUND THEN
80427 
80428 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
80429 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
80430 
80431 FOR header_record IN header_cur
80432 LOOP
80433     l_array_header_events(header_record.event_id) := header_record.event_id;
80434 END LOOP;
80435 
80436 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
80437 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
80438 
80439 fnd_file.put_line(fnd_file.LOG, '                    ');
80440 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
80441 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
80442 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
80443 
80444 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
80445 LOOP
80446 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
80447 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
80448         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
80449 	END IF;
80450 END LOOP;
80451 
80452 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
80453 fnd_file.put_line(fnd_file.LOG, '                    ');
80454 
80455 
80456 xla_exceptions_pkg.raise_message
80457       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_143');
80458 
80459 
80460 WHEN OTHERS THEN
80461    xla_exceptions_pkg.raise_message
80462       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_143');
80463 END EventClass_143;
80464 --
80465 
80466 ---------------------------------------
80467 --
80468 -- PRIVATE PROCEDURE
80469 --         insert_sources_144
80473 PROCEDURE insert_sources_144(
80470 --
80471 ----------------------------------------
80472 --
80474                                 p_target_ledger_id       IN NUMBER
80475                               , p_language               IN VARCHAR2
80476                               , p_sla_ledger_id          IN NUMBER
80477                               , p_pad_start_date         IN DATE
80478                               , p_pad_end_date           IN DATE
80479                          )
80480 IS
80481 
80482 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'RECEIPT_ALL';
80483 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'RECEIPT';
80484 p_apps_owner                   VARCHAR2(30);
80485 l_log_module                   VARCHAR2(240);
80486 BEGIN
80487 IF g_log_enabled THEN
80488       l_log_module := C_DEFAULT_MODULE||'.insert_sources_144';
80489 END IF;
80490 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
80491 
80492       trace
80493          (p_msg      => 'BEGIN of insert_sources_144'
80494          ,p_level    => C_LEVEL_PROCEDURE
80495          ,p_module   => l_log_module);
80496 
80497 END IF;
80498 
80499 -- select APPS owner
80500 SELECT oracle_username
80501   INTO p_apps_owner
80502   FROM fnd_oracle_userid
80503  WHERE read_only_flag = 'U'
80504 ;
80505 
80506 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
80507       trace
80508          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
80509                         ' - p_language = '||p_language||
80510                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
80511                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
80512                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
80513                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
80514          ,p_level    => C_LEVEL_STATEMENT
80515          ,p_module   => l_log_module);
80516 END IF;
80517 
80518 
80519 --
80520 INSERT INTO xla_diag_sources --hdr2
80521 (
80522         event_id
80523       , ledger_id
80524       , sla_ledger_id
80525       , description_language
80526       , object_name
80527       , object_type_code
80528       , line_number
80529       , source_application_id
80530       , source_type_code
80531       , source_code
80532       , source_value
80533       , source_meaning
80534       , created_by
80535       , creation_date
80536       , last_update_date
80537       , last_updated_by
80538       , last_update_login
80539       , program_update_date
80540       , program_application_id
80541       , program_id
80542       , request_id
80543 )
80544 SELECT
80545         event_id
80546       , p_target_ledger_id
80547       , p_sla_ledger_id
80548       , p_language
80549       , object_name
80550       , object_type_code
80551       , line_number
80552       , source_application_id
80553       , source_type_code
80554       , source_code
80555       , SUBSTR(source_value ,1,1996)
80556       , SUBSTR(source_meaning ,1,200)
80557       , xla_environment_pkg.g_Usr_Id
80558       , TRUNC(SYSDATE)
80559       , TRUNC(SYSDATE)
80560       , xla_environment_pkg.g_Usr_Id
80561       , xla_environment_pkg.g_Login_Id
80562       , TRUNC(SYSDATE)
80563       , xla_environment_pkg.g_Prog_Appl_Id
80564       , xla_environment_pkg.g_Prog_Id
80565       , xla_environment_pkg.g_Req_Id
80566   FROM (
80567        SELECT xet.event_id                  event_id
80568             , 0                          line_number
80569             , CASE r
80570                WHEN 1 THEN 'AR_REMIT_BANK_ACCT_H_V' 
80571                 WHEN 2 THEN 'AR_REMIT_BANK_ACCT_H_V' 
80572                 WHEN 3 THEN 'AR_REMIT_BANK_ACCT_H_V' 
80573                 WHEN 4 THEN 'AR_REMIT_BANK_ACCT_H_V' 
80574                 WHEN 5 THEN 'AR_REMIT_BANK_ACCT_H_V' 
80575                 WHEN 6 THEN 'AR_SYSTEM_PARAM_H_V' 
80576                 WHEN 7 THEN 'AR_SYSTEM_PARAM_H_V' 
80577                 WHEN 8 THEN 'AR_CASH_RECEIPTS_H_V' 
80578                 WHEN 9 THEN 'AR_RCT_METHOD_H_V' 
80579                 WHEN 10 THEN 'AR_RCT_METHOD_H_V' 
80580                 WHEN 11 THEN 'AR_CASH_RECEIPTS_H_V' 
80581                 WHEN 12 THEN 'AR_RCT_SITE_USES_H_V' 
80582                 WHEN 13 THEN 'AR_CASH_RECEIPTS_H_V' 
80583                 WHEN 14 THEN 'AR_CASH_RECEIPTS_H_V' 
80584                 WHEN 15 THEN 'AR_CASH_RECEIPTS_H_V' 
80585                 WHEN 16 THEN 'AR_CASH_RECEIPTS_H_V' 
80586                 WHEN 17 THEN 'AR_CASH_RECEIPTS_H_V' 
80587                 
80588                ELSE null
80589               END                           object_name
80590             , CASE r
80591                 WHEN 1 THEN 'HEADER' 
80592                 WHEN 2 THEN 'HEADER' 
80593                 WHEN 3 THEN 'HEADER' 
80594                 WHEN 4 THEN 'HEADER' 
80595                 WHEN 5 THEN 'HEADER' 
80596                 WHEN 6 THEN 'HEADER' 
80597                 WHEN 7 THEN 'HEADER' 
80598                 WHEN 8 THEN 'HEADER' 
80599                 WHEN 9 THEN 'HEADER' 
80600                 WHEN 10 THEN 'HEADER' 
80601                 WHEN 11 THEN 'HEADER' 
80602                 WHEN 12 THEN 'HEADER' 
80603                 WHEN 13 THEN 'HEADER' 
80604                 WHEN 14 THEN 'HEADER' 
80605                 WHEN 15 THEN 'HEADER' 
80606                 WHEN 16 THEN 'HEADER' 
80607                 WHEN 17 THEN 'HEADER' 
80608                 
80609                 ELSE null
80610               END                           object_type_code
80611             , CASE r
80612                 WHEN 1 THEN '222' 
80613                 WHEN 2 THEN '222' 
80614                 WHEN 3 THEN '222' 
80615                 WHEN 4 THEN '222' 
80616                 WHEN 5 THEN '222' 
80617                 WHEN 6 THEN '222' 
80621                 WHEN 10 THEN '222' 
80618                 WHEN 7 THEN '222' 
80619                 WHEN 8 THEN '222' 
80620                 WHEN 9 THEN '222' 
80622                 WHEN 11 THEN '222' 
80623                 WHEN 12 THEN '222' 
80624                 WHEN 13 THEN '222' 
80625                 WHEN 14 THEN '222' 
80626                 WHEN 15 THEN '222' 
80627                 WHEN 16 THEN '222' 
80628                 WHEN 17 THEN '222' 
80629                 
80630                 ELSE null
80631               END                           source_application_id
80632             , 'S'             source_type_code
80633             , CASE r
80634                 WHEN 1 THEN 'RMT_BNK_BANK_CHARGES_CCID' 
80635                 WHEN 2 THEN 'RMT_BNK_CASH_CCID' 
80636                 WHEN 3 THEN 'RMT_BNK_CONFIRMATION_CCID' 
80637                 WHEN 4 THEN 'RMT_BNK_REMITTANCE_CCID' 
80638                 WHEN 5 THEN 'RMT_BNK_UNAPPLIED_CCID' 
80639                 WHEN 6 THEN 'CODE_COMBINATION_ID_GAIN' 
80640                 WHEN 7 THEN 'CODE_COMBINATION_ID_LOSS' 
80641                 WHEN 8 THEN 'RCT_XLA_APPLIED_TO_APP_ID' 
80642                 WHEN 9 THEN 'RCT_CLASS_REMIT_FLAG' 
80643                 WHEN 10 THEN 'RCT_CLASS_CONFIRM_FLAG' 
80644                 WHEN 11 THEN 'RCT_PAY_FROM_CUSTOMER' 
80645                 WHEN 12 THEN 'RCT_SITE_SITE_USE_ID' 
80646                 WHEN 13 THEN 'RCT_APP_STATUS' 
80647                 WHEN 14 THEN 'RCT_DOC_SEQUENCE_CATEGORY' 
80648                 WHEN 15 THEN 'RCT_DOC_SEQUENCE_ID' 
80649                 WHEN 16 THEN 'RCT_DOC_SEQUENCE_VALUE' 
80650                 WHEN 17 THEN 'RCT_TRX_ACCT_REVERSAL' 
80651                 
80652                 ELSE null
80653               END                           source_code
80654             , CASE r
80655                 WHEN 1 THEN TO_CHAR(h9.RMT_BNK_BANK_CHARGES_CCID)
80656                 WHEN 2 THEN TO_CHAR(h9.RMT_BNK_CASH_CCID)
80657                 WHEN 3 THEN TO_CHAR(h9.RMT_BNK_CONFIRMATION_CCID)
80658                 WHEN 4 THEN TO_CHAR(h9.RMT_BNK_REMITTANCE_CCID)
80659                 WHEN 5 THEN TO_CHAR(h9.RMT_BNK_UNAPPLIED_CCID)
80660                 WHEN 6 THEN TO_CHAR(h10.CODE_COMBINATION_ID_GAIN)
80661                 WHEN 7 THEN TO_CHAR(h10.CODE_COMBINATION_ID_LOSS)
80662                 WHEN 8 THEN TO_CHAR(h2.RCT_XLA_APPLIED_TO_APP_ID)
80663                 WHEN 9 THEN TO_CHAR(h6.RCT_CLASS_REMIT_FLAG)
80664                 WHEN 10 THEN TO_CHAR(h6.RCT_CLASS_CONFIRM_FLAG)
80665                 WHEN 11 THEN TO_CHAR(h2.RCT_PAY_FROM_CUSTOMER)
80666                 WHEN 12 THEN TO_CHAR(h7.RCT_SITE_SITE_USE_ID)
80667                 WHEN 13 THEN TO_CHAR(h2.RCT_APP_STATUS)
80668                 WHEN 14 THEN TO_CHAR(h2.RCT_DOC_SEQUENCE_CATEGORY)
80669                 WHEN 15 THEN TO_CHAR(h2.RCT_DOC_SEQUENCE_ID)
80670                 WHEN 16 THEN TO_CHAR(h2.RCT_DOC_SEQUENCE_VALUE)
80671                 WHEN 17 THEN TO_CHAR(h2.RCT_TRX_ACCT_REVERSAL)
80672                 
80673                 ELSE null
80674               END                           source_value
80675             , null              source_meaning
80676          FROM xla_events_gt     xet  
80677       , AR_CASH_RECEIPTS_H_V  h2
80678       , AR_RCT_METHOD_H_V  h6
80679       , AR_RCT_SITE_USES_H_V  h7
80680       , AR_REMIT_BANK_ACCT_H_V  h9
80681       , AR_SYSTEM_PARAM_H_V  h10
80682              ,(select rownum r from all_objects where rownum <= 17 and owner = p_apps_owner)
80683          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
80684            AND xet.event_class_code = C_EVENT_CLASS_CODE
80685               AND h2.event_id = xet.event_id
80686   AND h6.event_id (+) = h2.event_id
80687   AND h7.event_id (+) = h2.event_id
80688   AND h9.event_id (+) = h2.event_id
80689   AND h10.event_id (+) = h2.event_id
80690 
80691 )
80692 ;
80693 --
80694 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
80695 
80696       trace
80697          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
80698          ,p_level    => C_LEVEL_STATEMENT
80699          ,p_module   => l_log_module);
80700 
80701 END IF;
80702 --
80703 
80704 
80705 
80706 --
80707 INSERT INTO xla_diag_sources  --line2
80708 (
80709         event_id
80710       , ledger_id
80711       , sla_ledger_id
80712       , description_language
80713       , object_name
80714       , object_type_code
80715       , line_number
80716       , source_application_id
80717       , source_type_code
80718       , source_code
80719       , source_value
80720       , source_meaning
80721       , created_by
80722       , creation_date
80723       , last_update_date
80724       , last_updated_by
80725       , last_update_login
80726       , program_update_date
80727       , program_application_id
80728       , program_id
80729       , request_id
80730 )
80731 SELECT  event_id
80732       , p_target_ledger_id
80733       , p_sla_ledger_id
80734       , p_language
80735       , object_name
80736       , object_type_code
80737       , line_number
80738       , source_application_id
80739       , source_type_code
80740       , source_code
80741       , SUBSTR(source_value,1,1996)
80742       , SUBSTR(source_meaning ,1,200)
80743       , xla_environment_pkg.g_Usr_Id
80744       , TRUNC(SYSDATE)
80745       , TRUNC(SYSDATE)
80746       , xla_environment_pkg.g_Usr_Id
80747       , xla_environment_pkg.g_Login_Id
80748       , TRUNC(SYSDATE)
80749       , xla_environment_pkg.g_Prog_Appl_Id
80750       , xla_environment_pkg.g_Prog_Id
80751       , xla_environment_pkg.g_Req_Id
80752   FROM (
80753        SELECT xet.event_id                  event_id
80754             , l5.line_number                 line_number
80755             , CASE r
80756                WHEN 1 THEN 'AR_DISTRIBUTIONS_L_V' 
80760                 WHEN 5 THEN 'FV_XLA_AR_REF_V' 
80757                 WHEN 2 THEN 'AR_CUST_TRX_LINES_L_V' 
80758                 WHEN 3 THEN 'AR_BILL_TO_CUSTOMERS_S_V' 
80759                 WHEN 4 THEN 'FV_XLA_AR_REF_V' 
80761                 WHEN 6 THEN 'FV_XLA_AR_REF_V' 
80762                 WHEN 7 THEN 'FV_XLA_AR_REF_V' 
80763                 WHEN 8 THEN 'FV_XLA_AR_REF_V' 
80764                 WHEN 9 THEN 'AR_DISTRIBUTIONS_L_V' 
80765                 WHEN 10 THEN 'AR_RECEIVABLES_TRX_ACT_S_V' 
80766                 WHEN 11 THEN 'AR_DISTRIBUTIONS_L_V' 
80767                 WHEN 12 THEN 'AR_DISTRIBUTIONS_L_V' 
80768                 WHEN 13 THEN 'AR_DISTRIBUTIONS_L_V' 
80769                 WHEN 14 THEN 'AR_DISTRIBUTIONS_L_V' 
80770                 WHEN 15 THEN 'AR_DISTRIBUTIONS_BASE_V' 
80771                 WHEN 16 THEN 'AR_DISTRIBUTIONS_BASE_V' 
80772                 WHEN 17 THEN 'AR_DISTRIBUTIONS_BASE_V' 
80773                 WHEN 18 THEN 'AR_DISTRIBUTIONS_BASE_V' 
80774                 WHEN 19 THEN 'AR_CUST_TRX_LINES_L_V' 
80775                 WHEN 20 THEN 'AR_CUST_TRX_LINES_L_V' 
80776                 WHEN 21 THEN 'AR_CUST_TRX_LINES_L_V' 
80777                 WHEN 22 THEN 'FV_XLA_AR_REF_V' 
80778                 WHEN 23 THEN 'AR_DISTRIBUTIONS_BASE_V' 
80779                 WHEN 24 THEN 'AR_TRANSACTIONS_S_V' 
80780                 WHEN 25 THEN 'AR_TRANSACTIONS_S_V' 
80781                 WHEN 26 THEN 'AR_DISTRIBUTIONS_L_V' 
80782                 WHEN 27 THEN 'AR_DISTRIBUTIONS_BASE_V' 
80783                 WHEN 28 THEN 'AR_DISTRIBUTIONS_L_V' 
80784                 WHEN 29 THEN 'AR_DISTRIBUTIONS_L_V' 
80785                 WHEN 30 THEN 'AR_DISTRIBUTIONS_L_V' 
80786                 WHEN 31 THEN 'AR_DISTRIBUTIONS_L_V' 
80787                 WHEN 32 THEN 'AR_DISTRIBUTIONS_L_V' 
80788                 WHEN 33 THEN 'AR_DISTRIBUTIONS_BASE_V' 
80789                 WHEN 34 THEN 'AR_DISTRIBUTIONS_BASE_V' 
80790                 WHEN 35 THEN 'AR_DISTRIBUTIONS_L_V' 
80791                 
80792                ELSE null
80793               END                           object_name
80794             , CASE r
80795                 WHEN 1 THEN 'LINE' 
80796                 WHEN 2 THEN 'LINE' 
80797                 WHEN 3 THEN 'LINE' 
80798                 WHEN 4 THEN 'LINE' 
80799                 WHEN 5 THEN 'LINE' 
80800                 WHEN 6 THEN 'LINE' 
80801                 WHEN 7 THEN 'LINE' 
80802                 WHEN 8 THEN 'LINE' 
80803                 WHEN 9 THEN 'LINE' 
80804                 WHEN 10 THEN 'LINE' 
80805                 WHEN 11 THEN 'LINE' 
80806                 WHEN 12 THEN 'LINE' 
80807                 WHEN 13 THEN 'LINE' 
80808                 WHEN 14 THEN 'LINE' 
80809                 WHEN 15 THEN 'LINE' 
80810                 WHEN 16 THEN 'LINE' 
80811                 WHEN 17 THEN 'LINE' 
80812                 WHEN 18 THEN 'LINE' 
80813                 WHEN 19 THEN 'LINE' 
80814                 WHEN 20 THEN 'LINE' 
80815                 WHEN 21 THEN 'LINE' 
80816                 WHEN 22 THEN 'LINE' 
80817                 WHEN 23 THEN 'LINE' 
80818                 WHEN 24 THEN 'LINE' 
80819                 WHEN 25 THEN 'LINE' 
80820                 WHEN 26 THEN 'LINE' 
80821                 WHEN 27 THEN 'LINE' 
80822                 WHEN 28 THEN 'LINE' 
80823                 WHEN 29 THEN 'LINE' 
80824                 WHEN 30 THEN 'LINE' 
80825                 WHEN 31 THEN 'LINE' 
80826                 WHEN 32 THEN 'LINE' 
80827                 WHEN 33 THEN 'LINE' 
80828                 WHEN 34 THEN 'LINE' 
80829                 WHEN 35 THEN 'LINE' 
80830                 
80831                 ELSE null
80832               END                           object_type_code
80833             , CASE r
80834                 WHEN 1 THEN '222' 
80835                 WHEN 2 THEN '222' 
80836                 WHEN 3 THEN '222' 
80837                 WHEN 4 THEN '8901' 
80838                 WHEN 5 THEN '8901' 
80839                 WHEN 6 THEN '8901' 
80840                 WHEN 7 THEN '8901' 
80841                 WHEN 8 THEN '8901' 
80842                 WHEN 9 THEN '222' 
80843                 WHEN 10 THEN '222' 
80844                 WHEN 11 THEN '222' 
80845                 WHEN 12 THEN '222' 
80846                 WHEN 13 THEN '222' 
80847                 WHEN 14 THEN '222' 
80848                 WHEN 15 THEN '222' 
80849                 WHEN 16 THEN '222' 
80850                 WHEN 17 THEN '222' 
80851                 WHEN 18 THEN '222' 
80852                 WHEN 19 THEN '222' 
80853                 WHEN 20 THEN '222' 
80854                 WHEN 21 THEN '222' 
80855                 WHEN 22 THEN '8901' 
80856                 WHEN 23 THEN '222' 
80857                 WHEN 24 THEN '222' 
80858                 WHEN 25 THEN '222' 
80859                 WHEN 26 THEN '222' 
80860                 WHEN 27 THEN '222' 
80861                 WHEN 28 THEN '222' 
80862                 WHEN 29 THEN '222' 
80863                 WHEN 30 THEN '222' 
80864                 WHEN 31 THEN '222' 
80865                 WHEN 32 THEN '222' 
80866                 WHEN 33 THEN '222' 
80867                 WHEN 34 THEN '222' 
80868                 WHEN 35 THEN '222' 
80869                 
80870                 ELSE null
80871               END                           source_application_id
80872             , 'S'             source_type_code
80873             , CASE r
80874                 WHEN 1 THEN 'DIST_CODE_COMBINATION_ID' 
80875                 WHEN 2 THEN 'TRX_LINE_DIST_CCID' 
80876                 WHEN 3 THEN 'BILL_CUSTOMER_CLASS_CODE' 
80877                 WHEN 4 THEN 'FEDERAL_ACCOUNT_RULE' 
80878                 WHEN 5 THEN 'FEDERAL_FUND_EXPIRED_STATUS' 
80879                 WHEN 6 THEN 'FEDERAL_PRIOR_YEAR_FLAG' 
80880                 WHEN 7 THEN 'FEDERAL_FUND_TIME_FRAME' 
80881                 WHEN 8 THEN 'FEDERAL_APPORTIONMENT_CATEGORY' 
80882                 WHEN 9 THEN 'DIST_SOURCE_TYPE' 
80886                 WHEN 13 THEN 'DIST_ENT_AMT' 
80883                 WHEN 10 THEN 'REC_ACT_TYPE' 
80884                 WHEN 11 THEN 'DIST_LINE_ID' 
80885                 WHEN 12 THEN 'DISTRIBUTION_TYPE' 
80887                 WHEN 14 THEN 'DIST_CURRENCY_CODE' 
80888                 WHEN 15 THEN 'DIST_CUR_CONVERSION_DATE' 
80889                 WHEN 16 THEN 'DIST_CUR_CONVERSION_RATE' 
80890                 WHEN 17 THEN 'DIST_CUR_CONVERSION_TYPE' 
80891                 WHEN 18 THEN 'DIST_TO_ACCTD_AMT' 
80892                 WHEN 19 THEN 'TRX_LINE_DIST_ACCOUNT_CLASS' 
80893                 WHEN 20 THEN 'TRX_LINE_DIST_ID' 
80894                 WHEN 21 THEN 'TRX_DISTRIBUTION_TYPE' 
80895                 WHEN 22 THEN 'FEDERAL_ACCOUNT_VALID_FLAG' 
80896                 WHEN 23 THEN 'DIST_TO_CUR_CONVERSION_DATE' 
80897                 WHEN 24 THEN 'TRX_ENTITY_CODE' 
80898                 WHEN 25 THEN 'TRX_CUSTOMER_TRX_ID' 
80899                 WHEN 26 THEN 'DIST_CURRENCY_CODE_FROM' 
80900                 WHEN 27 THEN 'DIST_TO_CUR_CONVERSION_RATE' 
80901                 WHEN 28 THEN 'DIST_PARTY_ID' 
80902                 WHEN 29 THEN 'DIST_PARTY_SITE_ID' 
80903                 WHEN 30 THEN 'DIST_PARTY_TYPE' 
80904                 WHEN 31 THEN 'DIST_MFAR_ADDITIONAL_ENTRY' 
80905                 WHEN 32 THEN 'DIST_ENT_AMT_FROM' 
80906                 WHEN 33 THEN 'DIST_ACCTD_AMT' 
80907                 WHEN 34 THEN 'DIST_TO_CUR_CONVERSION_TYPE' 
80908                 WHEN 35 THEN 'DIST_SOURCE_TABLE' 
80909                 
80910                 ELSE null
80911               END                           source_code
80912             , CASE r
80913                 WHEN 1 THEN TO_CHAR(l5.DIST_CODE_COMBINATION_ID)
80914                 WHEN 2 THEN TO_CHAR(l3.TRX_LINE_DIST_CCID)
80915                 WHEN 3 THEN TO_CHAR(l1.BILL_CUSTOMER_CLASS_CODE)
80916                 WHEN 4 THEN TO_CHAR(l12.FEDERAL_ACCOUNT_RULE)
80917                 WHEN 5 THEN TO_CHAR(l12.FEDERAL_FUND_EXPIRED_STATUS)
80918                 WHEN 6 THEN TO_CHAR(l12.FEDERAL_PRIOR_YEAR_FLAG)
80919                 WHEN 7 THEN TO_CHAR(l12.FEDERAL_FUND_TIME_FRAME)
80920                 WHEN 8 THEN TO_CHAR(l12.FEDERAL_APPORTIONMENT_CATEGORY)
80921                 WHEN 9 THEN TO_CHAR(l5.DIST_SOURCE_TYPE)
80922                 WHEN 10 THEN TO_CHAR(l8.REC_ACT_TYPE)
80923                 WHEN 11 THEN TO_CHAR(l5.DIST_LINE_ID)
80924                 WHEN 12 THEN TO_CHAR(l5.DISTRIBUTION_TYPE)
80925                 WHEN 13 THEN TO_CHAR(l5.DIST_ENT_AMT)
80926                 WHEN 14 THEN TO_CHAR(l5.DIST_CURRENCY_CODE)
80927                 WHEN 15 THEN TO_CHAR(l4.DIST_CUR_CONVERSION_DATE)
80928                 WHEN 16 THEN TO_CHAR(l4.DIST_CUR_CONVERSION_RATE)
80929                 WHEN 17 THEN TO_CHAR(l4.DIST_CUR_CONVERSION_TYPE)
80930                 WHEN 18 THEN TO_CHAR(l4.DIST_TO_ACCTD_AMT)
80931                 WHEN 19 THEN TO_CHAR(l3.TRX_LINE_DIST_ACCOUNT_CLASS)
80932                 WHEN 20 THEN TO_CHAR(l3.TRX_LINE_DIST_ID)
80933                 WHEN 21 THEN TO_CHAR(l3.TRX_DISTRIBUTION_TYPE)
80934                 WHEN 22 THEN TO_CHAR(l12.FEDERAL_ACCOUNT_VALID_FLAG)
80935                 WHEN 23 THEN TO_CHAR(l4.DIST_TO_CUR_CONVERSION_DATE)
80936                 WHEN 24 THEN TO_CHAR(l11.TRX_ENTITY_CODE)
80937                 WHEN 25 THEN TO_CHAR(l11.TRX_CUSTOMER_TRX_ID)
80938                 WHEN 26 THEN TO_CHAR(l5.DIST_CURRENCY_CODE_FROM)
80939                 WHEN 27 THEN TO_CHAR(l4.DIST_TO_CUR_CONVERSION_RATE)
80940                 WHEN 28 THEN TO_CHAR(l5.DIST_PARTY_ID)
80941                 WHEN 29 THEN TO_CHAR(l5.DIST_PARTY_SITE_ID)
80942                 WHEN 30 THEN TO_CHAR(l5.DIST_PARTY_TYPE)
80943                 WHEN 31 THEN TO_CHAR(l5.DIST_MFAR_ADDITIONAL_ENTRY)
80944                 WHEN 32 THEN TO_CHAR(l5.DIST_ENT_AMT_FROM)
80945                 WHEN 33 THEN TO_CHAR(l4.DIST_ACCTD_AMT)
80946                 WHEN 34 THEN TO_CHAR(l4.DIST_TO_CUR_CONVERSION_TYPE)
80947                 WHEN 35 THEN TO_CHAR(l5.DIST_SOURCE_TABLE)
80948                 
80949                 ELSE null
80950               END                           source_value
80951             , null              source_meaning
80952          FROM  xla_events_gt     xet  
80953         , AR_BILL_TO_CUSTOMERS_S_V  l1
80954         , AR_CUST_TRX_LINES_L_V  l3
80955         , AR_DISTRIBUTIONS_BASE_V  l4
80956         , AR_DISTRIBUTIONS_L_V  l5
80957         , AR_RECEIVABLES_TRX_ACT_S_V  l8
80958         , AR_TRANSACTIONS_S_V  l11
80959         , FV_XLA_AR_REF_V  l12
80960             , (select rownum r from all_objects where rownum <= 35 and owner = p_apps_owner)
80961         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
80962           AND xet.event_class_code = C_EVENT_CLASS_CODE
80963             AND l4.event_id          = xet.event_id
80964   AND l1.event_id (+)    = l4.event_id
80965   AND l1.line_number (+) = l4.line_number
80966   AND l3.event_id (+)    = l4.event_id
80967   AND l3.line_number (+) = l4.line_number
80968   AND l5.event_id    = l4.event_id
80969   AND l5.line_number = l4.line_number
80970   AND l8.event_id (+)    = l4.event_id
80971   AND l8.line_number (+) = l4.line_number
80972   AND l11.event_id (+)    = l4.event_id
80973   AND l11.line_number (+) = l4.line_number
80974  AND l12.federal_event_id   (+) =  l5.event_id  and l12.federal_line_number   (+) =  l5.line_number
80975 )
80976 ;
80977 --
80978 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
80979 
80980       trace
80981          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
80982          ,p_level    => C_LEVEL_STATEMENT
80983          ,p_module   => l_log_module);
80984 
80985 END IF;
80986 
80987 
80988 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
80989       trace
80990          (p_msg      => 'END of insert_sources_144'
80991          ,p_level    => C_LEVEL_PROCEDURE
80992          ,p_module   => l_log_module);
80993 END IF;
80994 EXCEPTION
80995   WHEN xla_exceptions_pkg.application_exception THEN
80996       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
80997             trace
81001       END IF;
80998                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
80999                ,p_level    => C_LEVEL_EXCEPTION
81000                ,p_module   => l_log_module);
81002       RAISE;
81003   WHEN OTHERS THEN
81004       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
81005             trace
81006                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
81007                ,p_level    => C_LEVEL_EXCEPTION
81008                ,p_module   => l_log_module);
81009        END IF;
81010        xla_exceptions_pkg.raise_message
81011            (p_location => 'XLA_00222_AAD_S_000006_PKG.insert_sources_144');
81012 END insert_sources_144;
81013 --
81014 
81015 ---------------------------------------
81016 --
81017 -- PRIVATE FUNCTION
81018 --         EventClass_144
81019 --
81020 ----------------------------------------
81021 --
81022 FUNCTION EventClass_144
81023        (p_application_id         IN NUMBER
81024        ,p_base_ledger_id         IN NUMBER
81025        ,p_target_ledger_id       IN NUMBER
81026        ,p_language               IN VARCHAR2
81027        ,p_currency_code          IN VARCHAR2
81028        ,p_sla_ledger_id          IN NUMBER
81029        ,p_pad_start_date         IN DATE
81030        ,p_pad_end_date           IN DATE
81031        ,p_primary_ledger_id      IN NUMBER)
81032 RETURN BOOLEAN IS
81033 --
81034 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'RECEIPT_ALL';
81035 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'RECEIPT';
81036 
81037 l_calculate_acctd_flag   VARCHAR2(1) :='N';
81038 l_calculate_g_l_flag     VARCHAR2(1) :='Y';
81039 --
81040 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
81041 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
81042 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
81043 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
81044 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
81045 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
81046 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
81047 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
81048 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
81049 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
81050 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
81051 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
81052 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
81053 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
81054 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
81055 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
81056 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
81057 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
81058 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
81059 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
81060 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
81061 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
81062 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
81063 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
81064 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
81065 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
81066 
81067 l_event_id                             NUMBER;
81068 l_previous_event_id                    NUMBER;
81069 l_first_event_id                       NUMBER;
81070 l_last_event_id                        NUMBER;
81071 
81072 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
81073 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
81074 --
81075 --
81076 l_result                    BOOLEAN := TRUE;
81077 l_rows                      NUMBER  := 1000;
81078 l_event_type_name           VARCHAR2(80) := 'All';
81079 l_event_class_name          VARCHAR2(80) := 'Receipt';
81080 l_description               VARCHAR2(4000);
81081 l_transaction_reversal      NUMBER;
81082 l_ae_header_id              NUMBER;
81083 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
81084 l_log_module                VARCHAR2(240);
81085 --
81086 l_acct_reversal_source      VARCHAR2(30);
81087 l_trx_reversal_source       VARCHAR2(30);
81088 
81089 l_continue_with_lines       BOOLEAN := TRUE;
81090 --
81091 l_acc_rev_gl_date_source    DATE;                      -- 4262811
81092 --
81093 type t_array_event_id is table of number index by binary_integer;
81094 
81095 l_rec_array_event                    t_rec_array_event;
81096 l_null_rec_array_event               t_rec_array_event;
81097 l_array_ae_header_id                 xla_number_array_type;
81098 l_actual_flag                        VARCHAR2(1) := NULL;
81099 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
81100 l_balance_type_code                  VARCHAR2(1) :=NULL;
81101 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
81102 
81103 --
81104 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
81105 --
81106 
81107 TYPE t_array_source_1 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_BANK_CHARGES_CCID%TYPE INDEX BY BINARY_INTEGER;
81108 TYPE t_array_source_13 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_CASH_CCID%TYPE INDEX BY BINARY_INTEGER;
81109 TYPE t_array_source_14 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_CONFIRMATION_CCID%TYPE INDEX BY BINARY_INTEGER;
81110 TYPE t_array_source_15 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_REMITTANCE_CCID%TYPE INDEX BY BINARY_INTEGER;
81114 TYPE t_array_source_58 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_XLA_APPLIED_TO_APP_ID%TYPE INDEX BY BINARY_INTEGER;
81111 TYPE t_array_source_17 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_UNAPPLIED_CCID%TYPE INDEX BY BINARY_INTEGER;
81112 TYPE t_array_source_18 IS TABLE OF AR_SYSTEM_PARAM_H_V.CODE_COMBINATION_ID_GAIN%TYPE INDEX BY BINARY_INTEGER;
81113 TYPE t_array_source_19 IS TABLE OF AR_SYSTEM_PARAM_H_V.CODE_COMBINATION_ID_LOSS%TYPE INDEX BY BINARY_INTEGER;
81115 TYPE t_array_source_70 IS TABLE OF AR_RCT_METHOD_H_V.RCT_CLASS_REMIT_FLAG%TYPE INDEX BY BINARY_INTEGER;
81116 TYPE t_array_source_71 IS TABLE OF AR_RCT_METHOD_H_V.RCT_CLASS_CONFIRM_FLAG%TYPE INDEX BY BINARY_INTEGER;
81117 TYPE t_array_source_76 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_PAY_FROM_CUSTOMER%TYPE INDEX BY BINARY_INTEGER;
81118 TYPE t_array_source_77 IS TABLE OF AR_RCT_SITE_USES_H_V.RCT_SITE_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
81119 TYPE t_array_source_78 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_APP_STATUS%TYPE INDEX BY BINARY_INTEGER;
81120 TYPE t_array_source_86 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
81121 TYPE t_array_source_87 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
81122 TYPE t_array_source_88 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
81123 TYPE t_array_source_89 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_TRX_ACCT_REVERSAL%TYPE INDEX BY BINARY_INTEGER;
81124 
81125 TYPE t_array_source_3 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CODE_COMBINATION_ID%TYPE INDEX BY BINARY_INTEGER;
81126 TYPE t_array_source_4 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
81127 TYPE t_array_source_6 IS TABLE OF AR_BILL_TO_CUSTOMERS_S_V.BILL_CUSTOMER_CLASS_CODE%TYPE INDEX BY BINARY_INTEGER;
81128 TYPE t_array_source_7 IS TABLE OF FV_XLA_AR_REF_V.FEDERAL_ACCOUNT_RULE%TYPE INDEX BY BINARY_INTEGER;
81129 TYPE t_array_source_8 IS TABLE OF FV_XLA_AR_REF_V.FEDERAL_FUND_EXPIRED_STATUS%TYPE INDEX BY BINARY_INTEGER;
81130 TYPE t_array_source_9 IS TABLE OF FV_XLA_AR_REF_V.FEDERAL_PRIOR_YEAR_FLAG%TYPE INDEX BY BINARY_INTEGER;
81131 TYPE t_array_source_10 IS TABLE OF FV_XLA_AR_REF_V.FEDERAL_FUND_TIME_FRAME%TYPE INDEX BY BINARY_INTEGER;
81132 TYPE t_array_source_11 IS TABLE OF FV_XLA_AR_REF_V.FEDERAL_APPORTIONMENT_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
81133 TYPE t_array_source_20 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_SOURCE_TYPE%TYPE INDEX BY BINARY_INTEGER;
81134 TYPE t_array_source_21 IS TABLE OF AR_RECEIVABLES_TRX_ACT_S_V.REC_ACT_TYPE%TYPE INDEX BY BINARY_INTEGER;
81135 TYPE t_array_source_22 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
81136 TYPE t_array_source_23 IS TABLE OF AR_DISTRIBUTIONS_L_V.DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
81137 TYPE t_array_source_24 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_ENT_AMT%TYPE INDEX BY BINARY_INTEGER;
81138 TYPE t_array_source_25 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
81139 TYPE t_array_source_26 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
81140 TYPE t_array_source_27 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
81141 TYPE t_array_source_28 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
81142 TYPE t_array_source_29 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
81143 TYPE t_array_source_33 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ACCOUNT_CLASS%TYPE INDEX BY BINARY_INTEGER;
81144 TYPE t_array_source_34 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ID%TYPE INDEX BY BINARY_INTEGER;
81145 TYPE t_array_source_35 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
81146 TYPE t_array_source_56 IS TABLE OF FV_XLA_AR_REF_V.FEDERAL_ACCOUNT_VALID_FLAG%TYPE INDEX BY BINARY_INTEGER;
81147 TYPE t_array_source_57 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
81148 TYPE t_array_source_59 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_ENTITY_CODE%TYPE INDEX BY BINARY_INTEGER;
81149 TYPE t_array_source_60 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_CUSTOMER_TRX_ID%TYPE INDEX BY BINARY_INTEGER;
81150 TYPE t_array_source_61 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CURRENCY_CODE_FROM%TYPE INDEX BY BINARY_INTEGER;
81151 TYPE t_array_source_62 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
81152 TYPE t_array_source_63 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_PARTY_ID%TYPE INDEX BY BINARY_INTEGER;
81153 TYPE t_array_source_64 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_PARTY_SITE_ID%TYPE INDEX BY BINARY_INTEGER;
81154 TYPE t_array_source_65 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
81155 TYPE t_array_source_69 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_MFAR_ADDITIONAL_ENTRY%TYPE INDEX BY BINARY_INTEGER;
81156 TYPE t_array_source_72 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_ENT_AMT_FROM%TYPE INDEX BY BINARY_INTEGER;
81157 TYPE t_array_source_73 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
81158 TYPE t_array_source_74 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
81159 TYPE t_array_source_75 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_SOURCE_TABLE%TYPE INDEX BY BINARY_INTEGER;
81160 
81161 l_array_source_1              t_array_source_1;
81162 l_array_source_13              t_array_source_13;
81163 l_array_source_14              t_array_source_14;
81164 l_array_source_15              t_array_source_15;
81165 l_array_source_17              t_array_source_17;
81166 l_array_source_18              t_array_source_18;
81167 l_array_source_19              t_array_source_19;
81168 l_array_source_58              t_array_source_58;
81169 l_array_source_70              t_array_source_70;
81170 l_array_source_71              t_array_source_71;
81171 l_array_source_76              t_array_source_76;
81172 l_array_source_77              t_array_source_77;
81173 l_array_source_78              t_array_source_78;
81174 l_array_source_86              t_array_source_86;
81175 l_array_source_87              t_array_source_87;
81176 l_array_source_88              t_array_source_88;
81177 l_array_source_89              t_array_source_89;
81178 
81179 l_array_source_3      t_array_source_3;
81180 l_array_source_4      t_array_source_4;
81181 l_array_source_6      t_array_source_6;
81185 l_array_source_10      t_array_source_10;
81182 l_array_source_7      t_array_source_7;
81183 l_array_source_8      t_array_source_8;
81184 l_array_source_9      t_array_source_9;
81186 l_array_source_11      t_array_source_11;
81187 l_array_source_20      t_array_source_20;
81188 l_array_source_21      t_array_source_21;
81189 l_array_source_22      t_array_source_22;
81190 l_array_source_23      t_array_source_23;
81191 l_array_source_24      t_array_source_24;
81192 l_array_source_25      t_array_source_25;
81193 l_array_source_26      t_array_source_26;
81194 l_array_source_27      t_array_source_27;
81195 l_array_source_28      t_array_source_28;
81196 l_array_source_29      t_array_source_29;
81197 l_array_source_33      t_array_source_33;
81198 l_array_source_34      t_array_source_34;
81199 l_array_source_35      t_array_source_35;
81200 l_array_source_56      t_array_source_56;
81201 l_array_source_57      t_array_source_57;
81202 l_array_source_59      t_array_source_59;
81203 l_array_source_60      t_array_source_60;
81204 l_array_source_61      t_array_source_61;
81205 l_array_source_62      t_array_source_62;
81206 l_array_source_63      t_array_source_63;
81207 l_array_source_64      t_array_source_64;
81208 l_array_source_65      t_array_source_65;
81209 l_array_source_69      t_array_source_69;
81210 l_array_source_72      t_array_source_72;
81211 l_array_source_73      t_array_source_73;
81212 l_array_source_74      t_array_source_74;
81213 l_array_source_75      t_array_source_75;
81214 
81215 --
81216 CURSOR header_cur
81217 IS
81218 SELECT /*+ leading(xet) cardinality(xet,1) */
81219 -- Event Class Code: RECEIPT
81220     xet.entity_id
81221    ,xet.legal_entity_id
81222    ,xet.entity_code
81223    ,xet.transaction_number
81224    ,xet.event_id
81225    ,xet.event_class_code
81226    ,xet.event_type_code
81227    ,xet.event_number
81228    ,xet.event_date
81229    ,xet.transaction_date
81230    ,xet.reference_num_1
81231    ,xet.reference_num_2
81232    ,xet.reference_num_3
81233    ,xet.reference_num_4
81234    ,xet.reference_char_1
81235    ,xet.reference_char_2
81236    ,xet.reference_char_3
81237    ,xet.reference_char_4
81238    ,xet.reference_date_1
81239    ,xet.reference_date_2
81240    ,xet.reference_date_3
81241    ,xet.reference_date_4
81242    ,xet.event_created_by
81243    ,xet.budgetary_control_flag 
81244   , h9.RMT_BNK_BANK_CHARGES_CCID    source_1
81245   , h9.RMT_BNK_CASH_CCID    source_13
81246   , h9.RMT_BNK_CONFIRMATION_CCID    source_14
81247   , h9.RMT_BNK_REMITTANCE_CCID    source_15
81248   , h9.RMT_BNK_UNAPPLIED_CCID    source_17
81249   , h10.CODE_COMBINATION_ID_GAIN    source_18
81250   , h10.CODE_COMBINATION_ID_LOSS    source_19
81251   , h2.RCT_XLA_APPLIED_TO_APP_ID    source_58
81252   , h6.RCT_CLASS_REMIT_FLAG    source_70
81253   , h6.RCT_CLASS_CONFIRM_FLAG    source_71
81254   , h2.RCT_PAY_FROM_CUSTOMER    source_76
81255   , h7.RCT_SITE_SITE_USE_ID    source_77
81256   , h2.RCT_APP_STATUS    source_78
81257   , h2.RCT_DOC_SEQUENCE_CATEGORY    source_86
81258   , h2.RCT_DOC_SEQUENCE_ID    source_87
81259   , h2.RCT_DOC_SEQUENCE_VALUE    source_88
81260   , h2.RCT_TRX_ACCT_REVERSAL    source_89
81261   FROM xla_events_gt     xet 
81262   , AR_CASH_RECEIPTS_H_V  h2
81263   , AR_RCT_METHOD_H_V  h6
81264   , AR_RCT_SITE_USES_H_V  h7
81265   , AR_REMIT_BANK_ACCT_H_V  h9
81266   , AR_SYSTEM_PARAM_H_V  h10
81267  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
81268    and xet.event_class_code = C_EVENT_CLASS_CODE
81269    and xet.event_status_code <> 'N'  AND h2.event_id = xet.event_id
81270   AND h6.event_id (+) = h2.event_id
81271   AND h7.event_id (+) = h2.event_id
81272   AND h9.event_id (+) = h2.event_id
81273   AND h10.event_id (+) = h2.event_id
81274 
81275  ORDER BY event_id
81276 ;
81277 
81278 
81279 --
81280 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
81281 IS
81282 SELECT  /*+ leading(xet) cardinality(xet,1) */
81283 -- Event Class Code: RECEIPT
81284     xet.entity_id
81285    ,xet.legal_entity_id
81286    ,xet.entity_code
81287    ,xet.transaction_number
81288    ,xet.event_id
81289    ,xet.event_class_code
81290    ,xet.event_type_code
81291    ,xet.event_number
81292    ,xet.event_date
81293    ,xet.transaction_date
81294    ,xet.reference_num_1
81295    ,xet.reference_num_2
81296    ,xet.reference_num_3
81297    ,xet.reference_num_4
81298    ,xet.reference_char_1
81299    ,xet.reference_char_2
81300    ,xet.reference_char_3
81301    ,xet.reference_char_4
81302    ,xet.reference_date_1
81303    ,xet.reference_date_2
81304    ,xet.reference_date_3
81305    ,xet.reference_date_4
81306    ,xet.event_created_by
81307    ,xet.budgetary_control_flag
81308  , l4.LINE_NUMBER  
81309   , l5.DIST_CODE_COMBINATION_ID    source_3
81310   , l3.TRX_LINE_DIST_CCID    source_4
81311   , l1.BILL_CUSTOMER_CLASS_CODE    source_6
81312   , l12.FEDERAL_ACCOUNT_RULE    source_7
81313   , l12.FEDERAL_FUND_EXPIRED_STATUS    source_8
81314   , l12.FEDERAL_PRIOR_YEAR_FLAG    source_9
81315   , l12.FEDERAL_FUND_TIME_FRAME    source_10
81316   , l12.FEDERAL_APPORTIONMENT_CATEGORY    source_11
81317   , l5.DIST_SOURCE_TYPE    source_20
81318   , l8.REC_ACT_TYPE    source_21
81319   , l5.DIST_LINE_ID    source_22
81320   , l5.DISTRIBUTION_TYPE    source_23
81321   , l5.DIST_ENT_AMT    source_24
81322   , l5.DIST_CURRENCY_CODE    source_25
81323   , l4.DIST_CUR_CONVERSION_DATE    source_26
81324   , l4.DIST_CUR_CONVERSION_RATE    source_27
81325   , l4.DIST_CUR_CONVERSION_TYPE    source_28
81326   , l4.DIST_TO_ACCTD_AMT    source_29
81327   , l3.TRX_LINE_DIST_ACCOUNT_CLASS    source_33
81328   , l3.TRX_LINE_DIST_ID    source_34
81329   , l3.TRX_DISTRIBUTION_TYPE    source_35
81333   , l11.TRX_CUSTOMER_TRX_ID    source_60
81330   , l12.FEDERAL_ACCOUNT_VALID_FLAG    source_56
81331   , l4.DIST_TO_CUR_CONVERSION_DATE    source_57
81332   , l11.TRX_ENTITY_CODE    source_59
81334   , l5.DIST_CURRENCY_CODE_FROM    source_61
81335   , l4.DIST_TO_CUR_CONVERSION_RATE    source_62
81336   , l5.DIST_PARTY_ID    source_63
81337   , l5.DIST_PARTY_SITE_ID    source_64
81338   , l5.DIST_PARTY_TYPE    source_65
81339   , l5.DIST_MFAR_ADDITIONAL_ENTRY    source_69
81340   , l5.DIST_ENT_AMT_FROM    source_72
81341   , l4.DIST_ACCTD_AMT    source_73
81342   , l4.DIST_TO_CUR_CONVERSION_TYPE    source_74
81343   , l5.DIST_SOURCE_TABLE    source_75
81344   FROM xla_events_gt     xet 
81345   , AR_BILL_TO_CUSTOMERS_S_V  l1
81346   , AR_CUST_TRX_LINES_L_V  l3
81347   , AR_DISTRIBUTIONS_BASE_V  l4
81348   , AR_DISTRIBUTIONS_L_V  l5
81349   , AR_RECEIVABLES_TRX_ACT_S_V  l8
81350   , AR_TRANSACTIONS_S_V  l11
81351   , FV_XLA_AR_REF_V  l12
81352  WHERE xet.event_id between x_first_event_id and x_last_event_id
81353    and xet.event_date between p_pad_start_date and p_pad_end_date
81354    and xet.event_class_code = C_EVENT_CLASS_CODE
81355    and xet.event_status_code <> 'N'   AND l4.event_id      = xet.event_id
81356   AND l1.event_id (+)    = l4.event_id
81357   AND l1.line_number (+) = l4.line_number
81358   AND l3.event_id (+)    = l4.event_id
81359   AND l3.line_number (+) = l4.line_number
81360   AND l5.event_id    = l4.event_id
81361   AND l5.line_number = l4.line_number
81362   AND l8.event_id (+)    = l4.event_id
81363   AND l8.line_number (+) = l4.line_number
81364   AND l11.event_id (+)    = l4.event_id
81365   AND l11.line_number (+) = l4.line_number
81366  AND l12.federal_event_id   (+) =  l5.event_id  AND l12.federal_line_number   (+) =  l5.line_number;
81367 
81368 --
81369 BEGIN
81370 IF g_log_enabled THEN
81371    l_log_module := C_DEFAULT_MODULE||'.EventClass_144';
81372 END IF;
81373 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
81374    trace
81375       (p_msg      => 'BEGIN of EventClass_144'
81376       ,p_level    => C_LEVEL_PROCEDURE
81377       ,p_module   => l_log_module);
81378 END IF;
81379 
81380 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
81381    trace
81382       (p_msg      => 'p_application_id = '||p_application_id||
81383                      ' - p_base_ledger_id = '||p_base_ledger_id||
81384                      ' - p_target_ledger_id  = '||p_target_ledger_id||
81385                      ' - p_language = '||p_language||
81386                      ' - p_currency_code = '||p_currency_code||
81387                      ' - p_sla_ledger_id = '||p_sla_ledger_id
81388       ,p_level    => C_LEVEL_STATEMENT
81389       ,p_module   => l_log_module);
81390 END IF;
81391 --
81392 -- initialze arrays
81393 --
81394 g_array_event.DELETE;
81395 l_rec_array_event := l_null_rec_array_event;
81396 --
81397 --------------------------------------
81398 -- 4262811 Initialze MPA Line Number
81399 --------------------------------------
81400 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
81401 
81402 --
81403 
81404 --
81405 OPEN header_cur;
81406 --
81407 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
81408    trace
81409    (p_msg      => 'SQL - FETCH header_cur'
81410    ,p_level    => C_LEVEL_STATEMENT
81411    ,p_module   => l_log_module);
81412 END IF;
81413 --
81414 LOOP
81415 FETCH header_cur BULK COLLECT INTO
81416         l_array_entity_id
81417       , l_array_legal_entity_id
81418       , l_array_entity_code
81419       , l_array_transaction_num
81420       , l_array_event_id
81421       , l_array_class_code
81422       , l_array_event_type
81423       , l_array_event_number
81424       , l_array_event_date
81425       , l_array_transaction_date
81426       , l_array_reference_num_1
81427       , l_array_reference_num_2
81428       , l_array_reference_num_3
81429       , l_array_reference_num_4
81430       , l_array_reference_char_1
81431       , l_array_reference_char_2
81432       , l_array_reference_char_3
81433       , l_array_reference_char_4
81434       , l_array_reference_date_1
81435       , l_array_reference_date_2
81436       , l_array_reference_date_3
81437       , l_array_reference_date_4
81438       , l_array_event_created_by
81439       , l_array_budgetary_control_flag 
81440       , l_array_source_1
81441       , l_array_source_13
81442       , l_array_source_14
81443       , l_array_source_15
81444       , l_array_source_17
81445       , l_array_source_18
81446       , l_array_source_19
81447       , l_array_source_58
81448       , l_array_source_70
81449       , l_array_source_71
81450       , l_array_source_76
81451       , l_array_source_77
81452       , l_array_source_78
81453       , l_array_source_86
81454       , l_array_source_87
81455       , l_array_source_88
81456       , l_array_source_89
81457       LIMIT l_rows;
81458 --
81459 IF (C_LEVEL_EVENT >= g_log_level) THEN
81460    trace
81461    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
81462    ,p_level    => C_LEVEL_EVENT
81463    ,p_module   => l_log_module);
81464 END IF;
81465 --
81466 EXIT WHEN l_array_entity_id.COUNT = 0;
81467 
81468 -- initialize arrays
81469 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
81470 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
81471 
81472 --
81473 -- Bug 4458708
81474 --
81475 XLA_AE_LINES_PKG.g_LineNumber := 0;
81476 
81477 
81478 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
81479 g_last_hdr_idx := l_array_event_id.LAST;
81480 --
81481 -- loop for the headers. Each iteration is for each header extract row
81482 -- fetched in header cursor
81483 --
81487 -- set event info as cache for other routines to refer event attributes
81484 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
81485 
81486 --
81488 --
81489 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
81490    (p_application_id           => p_application_id
81491    ,p_primary_ledger_id        => p_primary_ledger_id
81492    ,p_base_ledger_id           => p_base_ledger_id
81493    ,p_target_ledger_id         => p_target_ledger_id
81494    ,p_entity_id                => l_array_entity_id(hdr_idx)
81495    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
81496    ,p_entity_code              => l_array_entity_code(hdr_idx)
81497    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
81498    ,p_event_id                 => l_array_event_id(hdr_idx)
81499    ,p_event_class_code         => l_array_class_code(hdr_idx)
81500    ,p_event_type_code          => l_array_event_type(hdr_idx)
81501    ,p_event_number             => l_array_event_number(hdr_idx)
81502    ,p_event_date               => l_array_event_date(hdr_idx)
81503    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
81504    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
81505    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
81506    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
81507    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
81508    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
81509    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
81510    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
81511    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
81512    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
81513    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
81514    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
81515    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
81516    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
81517    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
81518 
81519 --
81520 -- set the status of entry to C_VALID (0)
81521 --
81522 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
81523 
81524 --
81525 -- initialize a row for ae header
81526 --
81527 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
81528 
81529 l_event_id := l_array_event_id(hdr_idx);
81530 
81531 --
81532 -- storing the hdr_idx for event. May be used by line cursor.
81533 --
81534 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
81535 
81536 --
81537 -- store sources from header extract. This can be improved to
81538 -- store only those sources from header extract that may be used in lines
81539 --
81540 
81541 g_array_event(l_event_id).array_value_num('source_1') := l_array_source_1(hdr_idx);
81542 g_array_event(l_event_id).array_value_num('source_13') := l_array_source_13(hdr_idx);
81543 g_array_event(l_event_id).array_value_num('source_14') := l_array_source_14(hdr_idx);
81544 g_array_event(l_event_id).array_value_num('source_15') := l_array_source_15(hdr_idx);
81545 g_array_event(l_event_id).array_value_num('source_17') := l_array_source_17(hdr_idx);
81546 g_array_event(l_event_id).array_value_num('source_18') := l_array_source_18(hdr_idx);
81547 g_array_event(l_event_id).array_value_num('source_19') := l_array_source_19(hdr_idx);
81548 g_array_event(l_event_id).array_value_num('source_58') := l_array_source_58(hdr_idx);
81549 g_array_event(l_event_id).array_value_char('source_70') := l_array_source_70(hdr_idx);
81550 g_array_event(l_event_id).array_value_char('source_71') := l_array_source_71(hdr_idx);
81551 g_array_event(l_event_id).array_value_num('source_76') := l_array_source_76(hdr_idx);
81552 g_array_event(l_event_id).array_value_num('source_77') := l_array_source_77(hdr_idx);
81553 g_array_event(l_event_id).array_value_char('source_78') := l_array_source_78(hdr_idx);
81554 g_array_event(l_event_id).array_value_char('source_86') := l_array_source_86(hdr_idx);
81555 g_array_event(l_event_id).array_value_num('source_87') := l_array_source_87(hdr_idx);
81556 g_array_event(l_event_id).array_value_num('source_88') := l_array_source_88(hdr_idx);
81557 g_array_event(l_event_id).array_value_char('source_89') := l_array_source_89(hdr_idx);
81558 
81559 --
81560 -- initilaize the status of ae headers for diffrent balance types
81561 -- the status is initialised to C_NOT_CREATED (2)
81562 --
81563 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
81564 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
81565 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
81566 
81567 --
81568 -- call api to validate and store accounting attributes for header
81569 --
81570 
81571 ------------------------------------------------------------
81572 -- Accrual Reversal : to get date for Standard Source (NONE)
81573 ------------------------------------------------------------
81574 l_acc_rev_gl_date_source := NULL;
81575 
81576      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
81577       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_86');
81578      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
81579       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_87');
81580      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
81581       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_88');
81582      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
81583       l_rec_acct_attrs.array_date_value(4) := 
81584 xla_ae_sources_pkg.GetSystemSourceDate(
81585    p_source_code           => 'XLA_EVENT_DATE'
81586  , p_source_type_code      => 'Y'
81587  , p_source_application_id =>  602
81588 );
81589      l_rec_acct_attrs.array_acct_attr_code(5)   := 'TRX_ACCT_REVERSAL_OPTION';
81593 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
81590       l_rec_acct_attrs.array_char_value(5) := g_array_event(l_event_id).array_value_char('source_89');
81591 
81592 
81594 
81595 XLA_AE_HEADER_PKG.SetJeCategoryName;
81596 
81597 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
81598 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
81599 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
81600 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
81601 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
81602 
81603 
81604 -- No header level analytical criteria
81605 
81606 --
81607 --accounting attribute enhancement, bug 3612931
81608 --
81609 l_trx_reversal_source := SUBSTR(g_array_event(l_event_id).array_value_char('source_89'), 1,30);
81610 
81611 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
81612    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
81613 
81614    xla_accounting_err_pkg.build_message
81615       (p_appli_s_name            => 'XLA'
81616       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
81617       ,p_token_1                 => 'ACCT_ATTR_NAME'
81618       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
81619       ,p_token_2                 => 'PRODUCT_NAME'
81620       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
81621       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
81622       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
81623       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
81624 
81625 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
81626    --
81627    -- following sets the accounting attributes needed to reverse
81628    -- accounting for a distributeion
81629    --
81630    xla_ae_lines_pkg.SetTrxReversalAttrs
81631       (p_event_id              => l_event_id
81632       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
81633       ,p_trx_reversal_source   => l_trx_reversal_source);
81634 
81635 END IF;
81636 
81637 
81638 ----------------------------------------------------------------
81639 -- 4262811 -  update the header statuses to invalid in need be
81640 ----------------------------------------------------------------
81641 --
81642 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
81643 
81644 
81645   -----------------------------------------------
81646   -- No accrual reversal for the event class/type
81647   -----------------------------------------------
81648 ----------------------------------------------------------------
81649 
81650 --
81651 -- this ends the header loop iteration for one bulk fetch
81652 --
81653 END LOOP;
81654 
81655 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
81656 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
81657 
81658 --
81659 -- insert dummy rows into lines gt table that were created due to
81660 -- transaction reversals
81661 --
81662 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
81663    l_result := XLA_AE_LINES_PKG.InsertLines;
81664 END IF;
81665 
81666 --
81667 -- reset the temp_line_num for each set of events fetched from header
81668 -- cursor rather than doing it for each new event in line cursor
81669 -- Bug 3939231
81670 --
81671 xla_ae_lines_pkg.g_temp_line_num := 0;
81672 
81673 
81674 
81675 --
81676 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
81677 --
81678 --
81679 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
81680 
81681       trace
81682          (p_msg      => 'SQL - FETCH line_cur'
81683          ,p_level    => C_LEVEL_STATEMENT
81684          ,p_module   => l_log_module);
81685 
81686 END IF;
81687 --
81688 --
81689 LOOP
81690   --
81691   FETCH line_cur BULK COLLECT INTO
81692         l_array_entity_id
81693       , l_array_legal_entity_id
81694       , l_array_entity_code
81695       , l_array_transaction_num
81696       , l_array_event_id
81697       , l_array_class_code
81698       , l_array_event_type
81699       , l_array_event_number
81700       , l_array_event_date
81701       , l_array_transaction_date
81702       , l_array_reference_num_1
81703       , l_array_reference_num_2
81704       , l_array_reference_num_3
81705       , l_array_reference_num_4
81706       , l_array_reference_char_1
81707       , l_array_reference_char_2
81708       , l_array_reference_char_3
81709       , l_array_reference_char_4
81710       , l_array_reference_date_1
81711       , l_array_reference_date_2
81712       , l_array_reference_date_3
81713       , l_array_reference_date_4
81714       , l_array_event_created_by
81715       , l_array_budgetary_control_flag
81716       , l_array_extract_line_num 
81717       , l_array_source_3
81718       , l_array_source_4
81719       , l_array_source_6
81720       , l_array_source_7
81721       , l_array_source_8
81722       , l_array_source_9
81723       , l_array_source_10
81724       , l_array_source_11
81725       , l_array_source_20
81726       , l_array_source_21
81727       , l_array_source_22
81728       , l_array_source_23
81729       , l_array_source_24
81730       , l_array_source_25
81731       , l_array_source_26
81732       , l_array_source_27
81733       , l_array_source_28
81734       , l_array_source_29
81735       , l_array_source_33
81736       , l_array_source_34
81737       , l_array_source_35
81741       , l_array_source_60
81738       , l_array_source_56
81739       , l_array_source_57
81740       , l_array_source_59
81742       , l_array_source_61
81743       , l_array_source_62
81744       , l_array_source_63
81745       , l_array_source_64
81746       , l_array_source_65
81747       , l_array_source_69
81748       , l_array_source_72
81749       , l_array_source_73
81750       , l_array_source_74
81751       , l_array_source_75
81752       LIMIT l_rows;
81753 
81754   --
81755   IF (C_LEVEL_EVENT >= g_log_level) THEN
81756             trace
81757                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
81758                ,p_level    => C_LEVEL_EVENT
81759                ,p_module   => l_log_module);
81760   END IF;
81761   --
81762   EXIT WHEN l_array_entity_id.count = 0;
81763 
81764   XLA_AE_LINES_PKG.g_rec_lines := null;
81765 
81766 --
81767 -- Bug 4458708
81768 --
81769 XLA_AE_LINES_PKG.g_LineNumber := 0;
81770 --
81771 --
81772 
81773 FOR Idx IN 1..l_array_event_id.count LOOP
81774    --
81775    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
81776    --
81777    l_event_id := l_array_event_id(idx);  -- 5648433
81778 
81779    --
81780    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
81781    --
81782 
81783    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
81784              (g_array_event(l_event_id).array_value_num('header_index'))
81785          ,'N'
81786          ) <> 'Y'
81787    THEN
81788       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
81789          trace
81790             (p_msg      => 'Trancaction revesal option is not Y '
81791             ,p_level    => C_LEVEL_STATEMENT
81792             ,p_module   => l_log_module);
81793       END IF;
81794 
81795 --
81796 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
81797 --
81798 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
81799 --
81800 -- set event info as cache for other routines to refer event attributes
81801 --
81802 
81803 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
81804    l_previous_event_id := l_event_id;
81805 
81806    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
81807       (p_application_id           => p_application_id
81808       ,p_primary_ledger_id        => p_primary_ledger_id
81809       ,p_base_ledger_id           => p_base_ledger_id
81810       ,p_target_ledger_id         => p_target_ledger_id
81811       ,p_entity_id                => l_array_entity_id(Idx)
81812       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
81813       ,p_entity_code              => l_array_entity_code(Idx)
81814       ,p_transaction_num          => l_array_transaction_num(Idx)
81815       ,p_event_id                 => l_array_event_id(Idx)
81816       ,p_event_class_code         => l_array_class_code(Idx)
81817       ,p_event_type_code          => l_array_event_type(Idx)
81818       ,p_event_number             => l_array_event_number(Idx)
81819       ,p_event_date               => l_array_event_date(Idx)
81820       ,p_transaction_date         => l_array_transaction_date(Idx)
81821       ,p_reference_num_1          => l_array_reference_num_1(Idx)
81822       ,p_reference_num_2          => l_array_reference_num_2(Idx)
81823       ,p_reference_num_3          => l_array_reference_num_3(Idx)
81824       ,p_reference_num_4          => l_array_reference_num_4(Idx)
81825       ,p_reference_char_1         => l_array_reference_char_1(Idx)
81826       ,p_reference_char_2         => l_array_reference_char_2(Idx)
81827       ,p_reference_char_3         => l_array_reference_char_3(Idx)
81828       ,p_reference_char_4         => l_array_reference_char_4(Idx)
81829       ,p_reference_date_1         => l_array_reference_date_1(Idx)
81830       ,p_reference_date_2         => l_array_reference_date_2(Idx)
81831       ,p_reference_date_3         => l_array_reference_date_3(Idx)
81832       ,p_reference_date_4         => l_array_reference_date_4(Idx)
81833       ,p_event_created_by         => l_array_event_created_by(Idx)
81834       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
81835        --
81836 END IF;
81837 
81838 
81839 
81840 --
81841 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
81842 
81843 l_acct_reversal_source := SUBSTR(NULL, 1,30);
81844 
81845 IF l_continue_with_lines THEN
81846    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
81847       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
81848 
81849       xla_accounting_err_pkg.build_message
81850          (p_appli_s_name            => 'XLA'
81851          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
81852          ,p_token_1                 => 'LINE_NUMBER'
81853          ,p_value_1                 => l_array_extract_line_num(Idx)
81854          ,p_token_2                 => 'PRODUCT_NAME'
81855          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
81856          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
81857          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
81858          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
81859 
81860    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
81861       --
81862       -- following sets the accounting attributes needed to reverse
81863       -- accounting for a distributeion
81864       --
81865 
81866       --
81867       -- 5217187
81868       --
81869       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
81870       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
81874 
81871                                        g_array_event(l_event_id).array_value_num('header_index'));
81872       --
81873       --
81875       -- No reversal code generated
81876 
81877       xla_ae_lines_pkg.SetAcctReversalAttrs
81878          (p_event_id             => l_event_id
81879          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
81880          ,p_calculate_acctd_flag => l_calculate_acctd_flag
81881          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
81882    END IF;
81883 
81884    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
81885        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
81886 
81887 --
81888 AcctLineType_69 (
81889  p_application_id  => p_application_id
81890  ,p_event_id     => l_event_id
81891  ,p_calculate_acctd_flag => l_calculate_acctd_flag
81892  ,p_calculate_g_l_flag => l_calculate_g_l_flag
81893  ,p_actual_flag => l_actual_flag
81894  ,p_balance_type_code => l_balance_type_code
81895  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
81896  
81897  , p_source_3 => l_array_source_3(Idx)
81898  , p_source_4 => l_array_source_4(Idx)
81899  , p_source_7 => l_array_source_7(Idx)
81900  , p_source_8 => l_array_source_8(Idx)
81901  , p_source_9 => l_array_source_9(Idx)
81902  , p_source_10 => l_array_source_10(Idx)
81903  , p_source_20 => l_array_source_20(Idx)
81904  , p_source_22 => l_array_source_22(Idx)
81905  , p_source_23 => l_array_source_23(Idx)
81906  , p_source_24 => l_array_source_24(Idx)
81907  , p_source_28 => l_array_source_28(Idx)
81908  , p_source_29 => l_array_source_29(Idx)
81909  , p_source_33 => l_array_source_33(Idx)
81910  , p_source_34 => l_array_source_34(Idx)
81911  , p_source_35 => l_array_source_35(Idx)
81912  , p_source_56 => l_array_source_56(Idx)
81913  , p_source_57 => l_array_source_57(Idx)
81914  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
81915  , p_source_59 => l_array_source_59(Idx)
81916  , p_source_60 => l_array_source_60(Idx)
81917  , p_source_61 => l_array_source_61(Idx)
81918  , p_source_62 => l_array_source_62(Idx)
81919  , p_source_63 => l_array_source_63(Idx)
81920  , p_source_64 => l_array_source_64(Idx)
81921  , p_source_65 => l_array_source_65(Idx)
81922  );
81923 If(l_balance_type_code = 'A') THEN
81924   l_actual_gain_loss_ref := l_gain_or_loss_ref;
81925 END IF;
81926 
81927 --
81928 
81929 
81930 --
81931 AcctLineType_70 (
81932  p_application_id  => p_application_id
81933  ,p_event_id     => l_event_id
81934  ,p_calculate_acctd_flag => l_calculate_acctd_flag
81935  ,p_calculate_g_l_flag => l_calculate_g_l_flag
81936  ,p_actual_flag => l_actual_flag
81937  ,p_balance_type_code => l_balance_type_code
81938  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
81939  
81940  , p_source_3 => l_array_source_3(Idx)
81941  , p_source_4 => l_array_source_4(Idx)
81942  , p_source_7 => l_array_source_7(Idx)
81943  , p_source_8 => l_array_source_8(Idx)
81944  , p_source_9 => l_array_source_9(Idx)
81945  , p_source_10 => l_array_source_10(Idx)
81946  , p_source_20 => l_array_source_20(Idx)
81947  , p_source_22 => l_array_source_22(Idx)
81948  , p_source_23 => l_array_source_23(Idx)
81949  , p_source_24 => l_array_source_24(Idx)
81950  , p_source_28 => l_array_source_28(Idx)
81951  , p_source_29 => l_array_source_29(Idx)
81952  , p_source_33 => l_array_source_33(Idx)
81953  , p_source_34 => l_array_source_34(Idx)
81954  , p_source_35 => l_array_source_35(Idx)
81955  , p_source_56 => l_array_source_56(Idx)
81956  , p_source_57 => l_array_source_57(Idx)
81957  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
81958  , p_source_59 => l_array_source_59(Idx)
81959  , p_source_60 => l_array_source_60(Idx)
81960  , p_source_61 => l_array_source_61(Idx)
81961  , p_source_62 => l_array_source_62(Idx)
81962  , p_source_63 => l_array_source_63(Idx)
81963  , p_source_64 => l_array_source_64(Idx)
81964  , p_source_65 => l_array_source_65(Idx)
81965  );
81966 If(l_balance_type_code = 'A') THEN
81967   l_actual_gain_loss_ref := l_gain_or_loss_ref;
81968 END IF;
81969 
81970 --
81971 
81972 
81973 --
81974 AcctLineType_71 (
81975  p_application_id  => p_application_id
81976  ,p_event_id     => l_event_id
81977  ,p_calculate_acctd_flag => l_calculate_acctd_flag
81978  ,p_calculate_g_l_flag => l_calculate_g_l_flag
81979  ,p_actual_flag => l_actual_flag
81980  ,p_balance_type_code => l_balance_type_code
81981  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
81982  
81983  , p_source_3 => l_array_source_3(Idx)
81984  , p_source_4 => l_array_source_4(Idx)
81985  , p_source_7 => l_array_source_7(Idx)
81986  , p_source_8 => l_array_source_8(Idx)
81987  , p_source_9 => l_array_source_9(Idx)
81988  , p_source_10 => l_array_source_10(Idx)
81989  , p_source_11 => l_array_source_11(Idx)
81990  , p_source_20 => l_array_source_20(Idx)
81991  , p_source_22 => l_array_source_22(Idx)
81992  , p_source_23 => l_array_source_23(Idx)
81993  , p_source_24 => l_array_source_24(Idx)
81994  , p_source_28 => l_array_source_28(Idx)
81995  , p_source_29 => l_array_source_29(Idx)
81996  , p_source_33 => l_array_source_33(Idx)
81997  , p_source_34 => l_array_source_34(Idx)
81998  , p_source_35 => l_array_source_35(Idx)
81999  , p_source_56 => l_array_source_56(Idx)
82000  , p_source_57 => l_array_source_57(Idx)
82001  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82002  , p_source_59 => l_array_source_59(Idx)
82003  , p_source_60 => l_array_source_60(Idx)
82004  , p_source_61 => l_array_source_61(Idx)
82005  , p_source_62 => l_array_source_62(Idx)
82006  , p_source_63 => l_array_source_63(Idx)
82007  , p_source_64 => l_array_source_64(Idx)
82008  , p_source_65 => l_array_source_65(Idx)
82009  );
82010 If(l_balance_type_code = 'A') THEN
82011   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82012 END IF;
82013 
82014 --
82015 
82019  p_application_id  => p_application_id
82016 
82017 --
82018 AcctLineType_72 (
82020  ,p_event_id     => l_event_id
82021  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82022  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82023  ,p_actual_flag => l_actual_flag
82024  ,p_balance_type_code => l_balance_type_code
82025  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82026  
82027  , p_source_3 => l_array_source_3(Idx)
82028  , p_source_4 => l_array_source_4(Idx)
82029  , p_source_7 => l_array_source_7(Idx)
82030  , p_source_8 => l_array_source_8(Idx)
82031  , p_source_9 => l_array_source_9(Idx)
82032  , p_source_10 => l_array_source_10(Idx)
82033  , p_source_11 => l_array_source_11(Idx)
82034  , p_source_20 => l_array_source_20(Idx)
82035  , p_source_22 => l_array_source_22(Idx)
82036  , p_source_23 => l_array_source_23(Idx)
82037  , p_source_24 => l_array_source_24(Idx)
82038  , p_source_28 => l_array_source_28(Idx)
82039  , p_source_29 => l_array_source_29(Idx)
82040  , p_source_33 => l_array_source_33(Idx)
82041  , p_source_34 => l_array_source_34(Idx)
82042  , p_source_35 => l_array_source_35(Idx)
82043  , p_source_56 => l_array_source_56(Idx)
82044  , p_source_57 => l_array_source_57(Idx)
82045  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82046  , p_source_59 => l_array_source_59(Idx)
82047  , p_source_60 => l_array_source_60(Idx)
82048  , p_source_61 => l_array_source_61(Idx)
82049  , p_source_62 => l_array_source_62(Idx)
82050  , p_source_63 => l_array_source_63(Idx)
82051  , p_source_64 => l_array_source_64(Idx)
82052  , p_source_65 => l_array_source_65(Idx)
82053  );
82054 If(l_balance_type_code = 'A') THEN
82055   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82056 END IF;
82057 
82058 --
82059 
82060 
82061 --
82062 AcctLineType_73 (
82063  p_application_id  => p_application_id
82064  ,p_event_id     => l_event_id
82065  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82066  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82067  ,p_actual_flag => l_actual_flag
82068  ,p_balance_type_code => l_balance_type_code
82069  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82070  
82071  , p_source_3 => l_array_source_3(Idx)
82072  , p_source_4 => l_array_source_4(Idx)
82073  , p_source_7 => l_array_source_7(Idx)
82074  , p_source_8 => l_array_source_8(Idx)
82075  , p_source_9 => l_array_source_9(Idx)
82076  , p_source_10 => l_array_source_10(Idx)
82077  , p_source_20 => l_array_source_20(Idx)
82078  , p_source_22 => l_array_source_22(Idx)
82079  , p_source_23 => l_array_source_23(Idx)
82080  , p_source_24 => l_array_source_24(Idx)
82081  , p_source_28 => l_array_source_28(Idx)
82082  , p_source_29 => l_array_source_29(Idx)
82083  , p_source_33 => l_array_source_33(Idx)
82084  , p_source_34 => l_array_source_34(Idx)
82085  , p_source_35 => l_array_source_35(Idx)
82086  , p_source_56 => l_array_source_56(Idx)
82087  , p_source_57 => l_array_source_57(Idx)
82088  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82089  , p_source_59 => l_array_source_59(Idx)
82090  , p_source_60 => l_array_source_60(Idx)
82091  , p_source_61 => l_array_source_61(Idx)
82092  , p_source_62 => l_array_source_62(Idx)
82093  , p_source_63 => l_array_source_63(Idx)
82094  , p_source_64 => l_array_source_64(Idx)
82095  , p_source_65 => l_array_source_65(Idx)
82096  );
82097 If(l_balance_type_code = 'A') THEN
82098   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82099 END IF;
82100 
82101 --
82102 
82103 
82104 --
82105 AcctLineType_74 (
82106  p_application_id  => p_application_id
82107  ,p_event_id     => l_event_id
82108  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82109  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82110  ,p_actual_flag => l_actual_flag
82111  ,p_balance_type_code => l_balance_type_code
82112  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82113  
82114  , p_source_3 => l_array_source_3(Idx)
82115  , p_source_4 => l_array_source_4(Idx)
82116  , p_source_7 => l_array_source_7(Idx)
82117  , p_source_8 => l_array_source_8(Idx)
82118  , p_source_9 => l_array_source_9(Idx)
82119  , p_source_10 => l_array_source_10(Idx)
82120  , p_source_20 => l_array_source_20(Idx)
82121  , p_source_22 => l_array_source_22(Idx)
82122  , p_source_23 => l_array_source_23(Idx)
82123  , p_source_24 => l_array_source_24(Idx)
82124  , p_source_28 => l_array_source_28(Idx)
82125  , p_source_29 => l_array_source_29(Idx)
82126  , p_source_33 => l_array_source_33(Idx)
82127  , p_source_34 => l_array_source_34(Idx)
82128  , p_source_35 => l_array_source_35(Idx)
82129  , p_source_56 => l_array_source_56(Idx)
82130  , p_source_57 => l_array_source_57(Idx)
82131  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82132  , p_source_59 => l_array_source_59(Idx)
82133  , p_source_60 => l_array_source_60(Idx)
82134  , p_source_61 => l_array_source_61(Idx)
82135  , p_source_62 => l_array_source_62(Idx)
82136  , p_source_63 => l_array_source_63(Idx)
82137  , p_source_64 => l_array_source_64(Idx)
82138  , p_source_65 => l_array_source_65(Idx)
82139  );
82140 If(l_balance_type_code = 'A') THEN
82141   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82142 END IF;
82143 
82144 --
82145 
82146 
82147 --
82148 AcctLineType_75 (
82149  p_application_id  => p_application_id
82150  ,p_event_id     => l_event_id
82151  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82152  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82153  ,p_actual_flag => l_actual_flag
82154  ,p_balance_type_code => l_balance_type_code
82155  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82156  
82157  , p_source_3 => l_array_source_3(Idx)
82158  , p_source_4 => l_array_source_4(Idx)
82159  , p_source_6 => l_array_source_6(Idx)
82160  , p_source_7 => l_array_source_7(Idx)
82161  , p_source_20 => l_array_source_20(Idx)
82165  , p_source_26 => l_array_source_26(Idx)
82162  , p_source_22 => l_array_source_22(Idx)
82163  , p_source_23 => l_array_source_23(Idx)
82164  , p_source_24 => l_array_source_24(Idx)
82166  , p_source_27 => l_array_source_27(Idx)
82167  , p_source_28 => l_array_source_28(Idx)
82168  , p_source_29 => l_array_source_29(Idx)
82169  , p_source_33 => l_array_source_33(Idx)
82170  , p_source_34 => l_array_source_34(Idx)
82171  , p_source_35 => l_array_source_35(Idx)
82172  , p_source_56 => l_array_source_56(Idx)
82173  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82174  , p_source_59 => l_array_source_59(Idx)
82175  , p_source_60 => l_array_source_60(Idx)
82176  , p_source_61 => l_array_source_61(Idx)
82177  , p_source_63 => l_array_source_63(Idx)
82178  , p_source_64 => l_array_source_64(Idx)
82179  , p_source_65 => l_array_source_65(Idx)
82180  );
82181 If(l_balance_type_code = 'A') THEN
82182   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82183 END IF;
82184 
82185 --
82186 
82187 
82188 --
82189 AcctLineType_76 (
82190  p_application_id  => p_application_id
82191  ,p_event_id     => l_event_id
82192  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82193  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82194  ,p_actual_flag => l_actual_flag
82195  ,p_balance_type_code => l_balance_type_code
82196  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82197  
82198  , p_source_3 => l_array_source_3(Idx)
82199  , p_source_4 => l_array_source_4(Idx)
82200  , p_source_6 => l_array_source_6(Idx)
82201  , p_source_7 => l_array_source_7(Idx)
82202  , p_source_20 => l_array_source_20(Idx)
82203  , p_source_22 => l_array_source_22(Idx)
82204  , p_source_23 => l_array_source_23(Idx)
82205  , p_source_24 => l_array_source_24(Idx)
82206  , p_source_28 => l_array_source_28(Idx)
82207  , p_source_29 => l_array_source_29(Idx)
82208  , p_source_33 => l_array_source_33(Idx)
82209  , p_source_34 => l_array_source_34(Idx)
82210  , p_source_35 => l_array_source_35(Idx)
82211  , p_source_56 => l_array_source_56(Idx)
82212  , p_source_57 => l_array_source_57(Idx)
82213  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82214  , p_source_59 => l_array_source_59(Idx)
82215  , p_source_60 => l_array_source_60(Idx)
82216  , p_source_61 => l_array_source_61(Idx)
82217  , p_source_62 => l_array_source_62(Idx)
82218  , p_source_63 => l_array_source_63(Idx)
82219  , p_source_64 => l_array_source_64(Idx)
82220  , p_source_65 => l_array_source_65(Idx)
82221  );
82222 If(l_balance_type_code = 'A') THEN
82223   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82224 END IF;
82225 
82226 --
82227 
82228 
82229 --
82230 AcctLineType_95 (
82231  p_application_id  => p_application_id
82232  ,p_event_id     => l_event_id
82233  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82234  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82235  ,p_actual_flag => l_actual_flag
82236  ,p_balance_type_code => l_balance_type_code
82237  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82238  
82239  , p_source_1 => g_array_event(l_event_id).array_value_num('source_1')
82240  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
82241  , p_source_20 => l_array_source_20(Idx)
82242  , p_source_22 => l_array_source_22(Idx)
82243  , p_source_23 => l_array_source_23(Idx)
82244  , p_source_26 => l_array_source_26(Idx)
82245  , p_source_27 => l_array_source_27(Idx)
82246  , p_source_28 => l_array_source_28(Idx)
82247  , p_source_34 => l_array_source_34(Idx)
82248  , p_source_35 => l_array_source_35(Idx)
82249  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82250  , p_source_59 => l_array_source_59(Idx)
82251  , p_source_60 => l_array_source_60(Idx)
82252  , p_source_61 => l_array_source_61(Idx)
82253  , p_source_63 => l_array_source_63(Idx)
82254  , p_source_64 => l_array_source_64(Idx)
82255  , p_source_65 => l_array_source_65(Idx)
82256  , p_source_69 => l_array_source_69(Idx)
82257  , p_source_72 => l_array_source_72(Idx)
82258  , p_source_73 => l_array_source_73(Idx)
82259  );
82260 If(l_balance_type_code = 'A') THEN
82261   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82262 END IF;
82263 
82264 --
82265 
82266 
82267 --
82268 AcctLineType_96 (
82269  p_application_id  => p_application_id
82270  ,p_event_id     => l_event_id
82271  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82272  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82273  ,p_actual_flag => l_actual_flag
82274  ,p_balance_type_code => l_balance_type_code
82275  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82276  
82277  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
82278  , p_source_20 => l_array_source_20(Idx)
82279  , p_source_22 => l_array_source_22(Idx)
82280  , p_source_23 => l_array_source_23(Idx)
82281  , p_source_26 => l_array_source_26(Idx)
82282  , p_source_27 => l_array_source_27(Idx)
82283  , p_source_28 => l_array_source_28(Idx)
82284  , p_source_33 => l_array_source_33(Idx)
82285  , p_source_34 => l_array_source_34(Idx)
82286  , p_source_35 => l_array_source_35(Idx)
82287  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82288  , p_source_59 => l_array_source_59(Idx)
82289  , p_source_60 => l_array_source_60(Idx)
82290  , p_source_61 => l_array_source_61(Idx)
82291  , p_source_63 => l_array_source_63(Idx)
82292  , p_source_64 => l_array_source_64(Idx)
82293  , p_source_65 => l_array_source_65(Idx)
82294  , p_source_69 => l_array_source_69(Idx)
82295  , p_source_70 => g_array_event(l_event_id).array_value_char('source_70')
82296  , p_source_71 => g_array_event(l_event_id).array_value_char('source_71')
82297  , p_source_72 => l_array_source_72(Idx)
82298  , p_source_73 => l_array_source_73(Idx)
82299  );
82300 If(l_balance_type_code = 'A') THEN
82301   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82302 END IF;
82303 
82307 --
82304 --
82305 
82306 
82308 AcctLineType_97 (
82309  p_application_id  => p_application_id
82310  ,p_event_id     => l_event_id
82311  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82312  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82313  ,p_actual_flag => l_actual_flag
82314  ,p_balance_type_code => l_balance_type_code
82315  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82316  
82317  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
82318  , p_source_20 => l_array_source_20(Idx)
82319  , p_source_22 => l_array_source_22(Idx)
82320  , p_source_23 => l_array_source_23(Idx)
82321  , p_source_26 => l_array_source_26(Idx)
82322  , p_source_27 => l_array_source_27(Idx)
82323  , p_source_28 => l_array_source_28(Idx)
82324  , p_source_34 => l_array_source_34(Idx)
82325  , p_source_35 => l_array_source_35(Idx)
82326  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82327  , p_source_59 => l_array_source_59(Idx)
82328  , p_source_60 => l_array_source_60(Idx)
82329  , p_source_61 => l_array_source_61(Idx)
82330  , p_source_63 => l_array_source_63(Idx)
82331  , p_source_64 => l_array_source_64(Idx)
82332  , p_source_65 => l_array_source_65(Idx)
82333  , p_source_69 => l_array_source_69(Idx)
82334  , p_source_70 => g_array_event(l_event_id).array_value_char('source_70')
82335  , p_source_72 => l_array_source_72(Idx)
82336  , p_source_73 => l_array_source_73(Idx)
82337  );
82338 If(l_balance_type_code = 'A') THEN
82339   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82340 END IF;
82341 
82342 --
82343 
82344 
82345 --
82346 AcctLineType_98 (
82347  p_application_id  => p_application_id
82348  ,p_event_id     => l_event_id
82349  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82350  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82351  ,p_actual_flag => l_actual_flag
82352  ,p_balance_type_code => l_balance_type_code
82353  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82354  
82355  , p_source_14 => g_array_event(l_event_id).array_value_num('source_14')
82356  , p_source_20 => l_array_source_20(Idx)
82357  , p_source_22 => l_array_source_22(Idx)
82358  , p_source_23 => l_array_source_23(Idx)
82359  , p_source_26 => l_array_source_26(Idx)
82360  , p_source_27 => l_array_source_27(Idx)
82361  , p_source_28 => l_array_source_28(Idx)
82362  , p_source_34 => l_array_source_34(Idx)
82363  , p_source_35 => l_array_source_35(Idx)
82364  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82365  , p_source_59 => l_array_source_59(Idx)
82366  , p_source_60 => l_array_source_60(Idx)
82367  , p_source_61 => l_array_source_61(Idx)
82368  , p_source_63 => l_array_source_63(Idx)
82369  , p_source_64 => l_array_source_64(Idx)
82370  , p_source_65 => l_array_source_65(Idx)
82371  , p_source_69 => l_array_source_69(Idx)
82372  , p_source_72 => l_array_source_72(Idx)
82373  , p_source_73 => l_array_source_73(Idx)
82374  );
82375 If(l_balance_type_code = 'A') THEN
82376   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82377 END IF;
82378 
82379 --
82380 
82381 
82382 --
82383 AcctLineType_99 (
82384  p_application_id  => p_application_id
82385  ,p_event_id     => l_event_id
82386  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82387  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82388  ,p_actual_flag => l_actual_flag
82389  ,p_balance_type_code => l_balance_type_code
82390  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82391  
82392  , p_source_20 => l_array_source_20(Idx)
82393  , p_source_22 => l_array_source_22(Idx)
82394  , p_source_23 => l_array_source_23(Idx)
82395  , p_source_24 => l_array_source_24(Idx)
82396  , p_source_25 => l_array_source_25(Idx)
82397  , p_source_29 => l_array_source_29(Idx)
82398  , p_source_34 => l_array_source_34(Idx)
82399  , p_source_35 => l_array_source_35(Idx)
82400  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82401  , p_source_59 => l_array_source_59(Idx)
82402  , p_source_60 => l_array_source_60(Idx)
82403  , p_source_65 => l_array_source_65(Idx)
82404  , p_source_69 => l_array_source_69(Idx)
82405  );
82406 If(l_balance_type_code = 'A') THEN
82407   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82408 END IF;
82409 
82410 --
82411 
82412 
82413 --
82414 AcctLineType_100 (
82415  p_application_id  => p_application_id
82416  ,p_event_id     => l_event_id
82417  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82418  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82419  ,p_actual_flag => l_actual_flag
82420  ,p_balance_type_code => l_balance_type_code
82421  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82422  
82423  , p_source_15 => g_array_event(l_event_id).array_value_num('source_15')
82424  , p_source_20 => l_array_source_20(Idx)
82425  , p_source_22 => l_array_source_22(Idx)
82426  , p_source_23 => l_array_source_23(Idx)
82427  , p_source_26 => l_array_source_26(Idx)
82428  , p_source_27 => l_array_source_27(Idx)
82429  , p_source_28 => l_array_source_28(Idx)
82430  , p_source_34 => l_array_source_34(Idx)
82431  , p_source_35 => l_array_source_35(Idx)
82432  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82433  , p_source_59 => l_array_source_59(Idx)
82434  , p_source_60 => l_array_source_60(Idx)
82435  , p_source_61 => l_array_source_61(Idx)
82436  , p_source_63 => l_array_source_63(Idx)
82437  , p_source_64 => l_array_source_64(Idx)
82438  , p_source_65 => l_array_source_65(Idx)
82439  , p_source_69 => l_array_source_69(Idx)
82440  , p_source_72 => l_array_source_72(Idx)
82441  , p_source_73 => l_array_source_73(Idx)
82442  );
82443 If(l_balance_type_code = 'A') THEN
82444   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82445 END IF;
82446 
82447 --
82448 
82449 
82450 --
82451 AcctLineType_101 (
82452  p_application_id  => p_application_id
82456  ,p_actual_flag => l_actual_flag
82453  ,p_event_id     => l_event_id
82454  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82455  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82457  ,p_balance_type_code => l_balance_type_code
82458  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82459  
82460  , p_source_20 => l_array_source_20(Idx)
82461  , p_source_22 => l_array_source_22(Idx)
82462  , p_source_23 => l_array_source_23(Idx)
82463  , p_source_24 => l_array_source_24(Idx)
82464  , p_source_25 => l_array_source_25(Idx)
82465  , p_source_29 => l_array_source_29(Idx)
82466  , p_source_34 => l_array_source_34(Idx)
82467  , p_source_35 => l_array_source_35(Idx)
82468  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82469  , p_source_59 => l_array_source_59(Idx)
82470  , p_source_60 => l_array_source_60(Idx)
82471  , p_source_65 => l_array_source_65(Idx)
82472  , p_source_69 => l_array_source_69(Idx)
82473  );
82474 If(l_balance_type_code = 'A') THEN
82475   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82476 END IF;
82477 
82478 --
82479 
82480 
82481 --
82482 AcctLineType_107 (
82483  p_application_id  => p_application_id
82484  ,p_event_id     => l_event_id
82485  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82486  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82487  ,p_actual_flag => l_actual_flag
82488  ,p_balance_type_code => l_balance_type_code
82489  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82490  
82491  , p_source_3 => l_array_source_3(Idx)
82492  , p_source_20 => l_array_source_20(Idx)
82493  , p_source_22 => l_array_source_22(Idx)
82494  , p_source_23 => l_array_source_23(Idx)
82495  , p_source_26 => l_array_source_26(Idx)
82496  , p_source_27 => l_array_source_27(Idx)
82497  , p_source_28 => l_array_source_28(Idx)
82498  , p_source_34 => l_array_source_34(Idx)
82499  , p_source_35 => l_array_source_35(Idx)
82500  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82501  , p_source_59 => l_array_source_59(Idx)
82502  , p_source_60 => l_array_source_60(Idx)
82503  , p_source_61 => l_array_source_61(Idx)
82504  , p_source_63 => l_array_source_63(Idx)
82505  , p_source_64 => l_array_source_64(Idx)
82506  , p_source_65 => l_array_source_65(Idx)
82507  , p_source_69 => l_array_source_69(Idx)
82508  , p_source_72 => l_array_source_72(Idx)
82509  , p_source_73 => l_array_source_73(Idx)
82510  );
82511 If(l_balance_type_code = 'A') THEN
82512   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82513 END IF;
82514 
82515 --
82516 
82517 
82518 --
82519 AcctLineType_108 (
82520  p_application_id  => p_application_id
82521  ,p_event_id     => l_event_id
82522  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82523  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82524  ,p_actual_flag => l_actual_flag
82525  ,p_balance_type_code => l_balance_type_code
82526  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82527  
82528  , p_source_4 => l_array_source_4(Idx)
82529  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
82530  , p_source_20 => l_array_source_20(Idx)
82531  , p_source_22 => l_array_source_22(Idx)
82532  , p_source_23 => l_array_source_23(Idx)
82533  , p_source_26 => l_array_source_26(Idx)
82534  , p_source_27 => l_array_source_27(Idx)
82535  , p_source_28 => l_array_source_28(Idx)
82536  , p_source_33 => l_array_source_33(Idx)
82537  , p_source_34 => l_array_source_34(Idx)
82538  , p_source_35 => l_array_source_35(Idx)
82539  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82540  , p_source_59 => l_array_source_59(Idx)
82541  , p_source_60 => l_array_source_60(Idx)
82542  , p_source_61 => l_array_source_61(Idx)
82543  , p_source_63 => l_array_source_63(Idx)
82544  , p_source_64 => l_array_source_64(Idx)
82545  , p_source_65 => l_array_source_65(Idx)
82546  , p_source_69 => l_array_source_69(Idx)
82547  , p_source_70 => g_array_event(l_event_id).array_value_char('source_70')
82548  , p_source_71 => g_array_event(l_event_id).array_value_char('source_71')
82549  , p_source_72 => l_array_source_72(Idx)
82550  , p_source_73 => l_array_source_73(Idx)
82551  );
82552 If(l_balance_type_code = 'A') THEN
82553   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82554 END IF;
82555 
82556 --
82557 
82558 
82559 --
82560 AcctLineType_109 (
82561  p_application_id  => p_application_id
82562  ,p_event_id     => l_event_id
82563  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82564  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82565  ,p_actual_flag => l_actual_flag
82566  ,p_balance_type_code => l_balance_type_code
82567  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82568  
82569  , p_source_4 => l_array_source_4(Idx)
82570  , p_source_13 => g_array_event(l_event_id).array_value_num('source_13')
82571  , p_source_20 => l_array_source_20(Idx)
82572  , p_source_22 => l_array_source_22(Idx)
82573  , p_source_23 => l_array_source_23(Idx)
82574  , p_source_26 => l_array_source_26(Idx)
82575  , p_source_27 => l_array_source_27(Idx)
82576  , p_source_28 => l_array_source_28(Idx)
82577  , p_source_34 => l_array_source_34(Idx)
82578  , p_source_35 => l_array_source_35(Idx)
82579  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82580  , p_source_59 => l_array_source_59(Idx)
82581  , p_source_60 => l_array_source_60(Idx)
82582  , p_source_61 => l_array_source_61(Idx)
82583  , p_source_63 => l_array_source_63(Idx)
82584  , p_source_64 => l_array_source_64(Idx)
82585  , p_source_65 => l_array_source_65(Idx)
82586  , p_source_69 => l_array_source_69(Idx)
82587  , p_source_70 => g_array_event(l_event_id).array_value_char('source_70')
82588  , p_source_72 => l_array_source_72(Idx)
82589  , p_source_73 => l_array_source_73(Idx)
82590  );
82591 If(l_balance_type_code = 'A') THEN
82592   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82593 END IF;
82594 
82595 --
82599 AcctLineType_110 (
82596 
82597 
82598 --
82600  p_application_id  => p_application_id
82601  ,p_event_id     => l_event_id
82602  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82603  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82604  ,p_actual_flag => l_actual_flag
82605  ,p_balance_type_code => l_balance_type_code
82606  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82607  
82608  , p_source_4 => l_array_source_4(Idx)
82609  , p_source_14 => g_array_event(l_event_id).array_value_num('source_14')
82610  , p_source_20 => l_array_source_20(Idx)
82611  , p_source_22 => l_array_source_22(Idx)
82612  , p_source_23 => l_array_source_23(Idx)
82613  , p_source_26 => l_array_source_26(Idx)
82614  , p_source_27 => l_array_source_27(Idx)
82615  , p_source_28 => l_array_source_28(Idx)
82616  , p_source_34 => l_array_source_34(Idx)
82617  , p_source_35 => l_array_source_35(Idx)
82618  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82619  , p_source_59 => l_array_source_59(Idx)
82620  , p_source_60 => l_array_source_60(Idx)
82621  , p_source_61 => l_array_source_61(Idx)
82622  , p_source_63 => l_array_source_63(Idx)
82623  , p_source_64 => l_array_source_64(Idx)
82624  , p_source_65 => l_array_source_65(Idx)
82625  , p_source_69 => l_array_source_69(Idx)
82626  , p_source_72 => l_array_source_72(Idx)
82627  , p_source_73 => l_array_source_73(Idx)
82628  );
82629 If(l_balance_type_code = 'A') THEN
82630   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82631 END IF;
82632 
82633 --
82634 
82635 
82636 --
82637 AcctLineType_111 (
82638  p_application_id  => p_application_id
82639  ,p_event_id     => l_event_id
82640  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82641  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82642  ,p_actual_flag => l_actual_flag
82643  ,p_balance_type_code => l_balance_type_code
82644  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82645  
82646  , p_source_20 => l_array_source_20(Idx)
82647  , p_source_22 => l_array_source_22(Idx)
82648  , p_source_23 => l_array_source_23(Idx)
82649  , p_source_24 => l_array_source_24(Idx)
82650  , p_source_25 => l_array_source_25(Idx)
82651  , p_source_29 => l_array_source_29(Idx)
82652  , p_source_33 => l_array_source_33(Idx)
82653  , p_source_34 => l_array_source_34(Idx)
82654  , p_source_35 => l_array_source_35(Idx)
82655  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82656  , p_source_59 => l_array_source_59(Idx)
82657  , p_source_60 => l_array_source_60(Idx)
82658  , p_source_65 => l_array_source_65(Idx)
82659  , p_source_69 => l_array_source_69(Idx)
82660  );
82661 If(l_balance_type_code = 'A') THEN
82662   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82663 END IF;
82664 
82665 --
82666 
82667 
82668 --
82669 AcctLineType_112 (
82670  p_application_id  => p_application_id
82671  ,p_event_id     => l_event_id
82672  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82673  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82674  ,p_actual_flag => l_actual_flag
82675  ,p_balance_type_code => l_balance_type_code
82676  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82677  
82678  , p_source_4 => l_array_source_4(Idx)
82679  , p_source_15 => g_array_event(l_event_id).array_value_num('source_15')
82680  , p_source_20 => l_array_source_20(Idx)
82681  , p_source_22 => l_array_source_22(Idx)
82682  , p_source_23 => l_array_source_23(Idx)
82683  , p_source_26 => l_array_source_26(Idx)
82684  , p_source_27 => l_array_source_27(Idx)
82685  , p_source_28 => l_array_source_28(Idx)
82686  , p_source_34 => l_array_source_34(Idx)
82687  , p_source_35 => l_array_source_35(Idx)
82688  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82689  , p_source_59 => l_array_source_59(Idx)
82690  , p_source_60 => l_array_source_60(Idx)
82691  , p_source_61 => l_array_source_61(Idx)
82692  , p_source_63 => l_array_source_63(Idx)
82693  , p_source_64 => l_array_source_64(Idx)
82694  , p_source_65 => l_array_source_65(Idx)
82695  , p_source_69 => l_array_source_69(Idx)
82696  , p_source_72 => l_array_source_72(Idx)
82697  , p_source_73 => l_array_source_73(Idx)
82698  );
82699 If(l_balance_type_code = 'A') THEN
82700   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82701 END IF;
82702 
82703 --
82704 
82705 
82706 --
82707 AcctLineType_113 (
82708  p_application_id  => p_application_id
82709  ,p_event_id     => l_event_id
82710  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82711  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82712  ,p_actual_flag => l_actual_flag
82713  ,p_balance_type_code => l_balance_type_code
82714  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82715  
82716  , p_source_3 => l_array_source_3(Idx)
82717  , p_source_20 => l_array_source_20(Idx)
82718  , p_source_22 => l_array_source_22(Idx)
82719  , p_source_23 => l_array_source_23(Idx)
82720  , p_source_26 => l_array_source_26(Idx)
82721  , p_source_27 => l_array_source_27(Idx)
82722  , p_source_28 => l_array_source_28(Idx)
82723  , p_source_34 => l_array_source_34(Idx)
82724  , p_source_35 => l_array_source_35(Idx)
82725  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82726  , p_source_59 => l_array_source_59(Idx)
82727  , p_source_60 => l_array_source_60(Idx)
82728  , p_source_61 => l_array_source_61(Idx)
82729  , p_source_63 => l_array_source_63(Idx)
82730  , p_source_64 => l_array_source_64(Idx)
82731  , p_source_65 => l_array_source_65(Idx)
82732  , p_source_69 => l_array_source_69(Idx)
82733  , p_source_72 => l_array_source_72(Idx)
82734  , p_source_73 => l_array_source_73(Idx)
82735  );
82736 If(l_balance_type_code = 'A') THEN
82737   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82738 END IF;
82739 
82740 --
82741 
82742 
82743 --
82744 AcctLineType_114 (
82745  p_application_id  => p_application_id
82749  ,p_actual_flag => l_actual_flag
82746  ,p_event_id     => l_event_id
82747  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82748  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82750  ,p_balance_type_code => l_balance_type_code
82751  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82752  
82753  , p_source_3 => l_array_source_3(Idx)
82754  , p_source_20 => l_array_source_20(Idx)
82755  , p_source_22 => l_array_source_22(Idx)
82756  , p_source_23 => l_array_source_23(Idx)
82757  , p_source_26 => l_array_source_26(Idx)
82758  , p_source_27 => l_array_source_27(Idx)
82759  , p_source_28 => l_array_source_28(Idx)
82760  , p_source_34 => l_array_source_34(Idx)
82761  , p_source_35 => l_array_source_35(Idx)
82762  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82763  , p_source_59 => l_array_source_59(Idx)
82764  , p_source_60 => l_array_source_60(Idx)
82765  , p_source_61 => l_array_source_61(Idx)
82766  , p_source_63 => l_array_source_63(Idx)
82767  , p_source_64 => l_array_source_64(Idx)
82768  , p_source_65 => l_array_source_65(Idx)
82769  , p_source_69 => l_array_source_69(Idx)
82770  , p_source_72 => l_array_source_72(Idx)
82771  , p_source_73 => l_array_source_73(Idx)
82772  );
82773 If(l_balance_type_code = 'A') THEN
82774   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82775 END IF;
82776 
82777 --
82778 
82779 
82780 --
82781 AcctLineType_115 (
82782  p_application_id  => p_application_id
82783  ,p_event_id     => l_event_id
82784  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82785  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82786  ,p_actual_flag => l_actual_flag
82787  ,p_balance_type_code => l_balance_type_code
82788  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82789  
82790  , p_source_3 => l_array_source_3(Idx)
82791  , p_source_20 => l_array_source_20(Idx)
82792  , p_source_21 => l_array_source_21(Idx)
82793  , p_source_22 => l_array_source_22(Idx)
82794  , p_source_23 => l_array_source_23(Idx)
82795  , p_source_26 => l_array_source_26(Idx)
82796  , p_source_27 => l_array_source_27(Idx)
82797  , p_source_34 => l_array_source_34(Idx)
82798  , p_source_35 => l_array_source_35(Idx)
82799  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82800  , p_source_59 => l_array_source_59(Idx)
82801  , p_source_60 => l_array_source_60(Idx)
82802  , p_source_61 => l_array_source_61(Idx)
82803  , p_source_63 => l_array_source_63(Idx)
82804  , p_source_64 => l_array_source_64(Idx)
82805  , p_source_65 => l_array_source_65(Idx)
82806  , p_source_69 => l_array_source_69(Idx)
82807  , p_source_72 => l_array_source_72(Idx)
82808  , p_source_73 => l_array_source_73(Idx)
82809  , p_source_74 => l_array_source_74(Idx)
82810  );
82811 If(l_balance_type_code = 'A') THEN
82812   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82813 END IF;
82814 
82815 --
82816 
82817 
82818 --
82819 AcctLineType_116 (
82820  p_application_id  => p_application_id
82821  ,p_event_id     => l_event_id
82822  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82823  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82824  ,p_actual_flag => l_actual_flag
82825  ,p_balance_type_code => l_balance_type_code
82826  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82827  
82828  , p_source_3 => l_array_source_3(Idx)
82829  , p_source_20 => l_array_source_20(Idx)
82830  , p_source_22 => l_array_source_22(Idx)
82831  , p_source_23 => l_array_source_23(Idx)
82832  , p_source_26 => l_array_source_26(Idx)
82833  , p_source_27 => l_array_source_27(Idx)
82834  , p_source_28 => l_array_source_28(Idx)
82835  , p_source_34 => l_array_source_34(Idx)
82836  , p_source_35 => l_array_source_35(Idx)
82837  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82838  , p_source_59 => l_array_source_59(Idx)
82839  , p_source_60 => l_array_source_60(Idx)
82840  , p_source_61 => l_array_source_61(Idx)
82841  , p_source_63 => l_array_source_63(Idx)
82842  , p_source_64 => l_array_source_64(Idx)
82843  , p_source_65 => l_array_source_65(Idx)
82844  , p_source_69 => l_array_source_69(Idx)
82845  , p_source_72 => l_array_source_72(Idx)
82846  , p_source_73 => l_array_source_73(Idx)
82847  );
82848 If(l_balance_type_code = 'A') THEN
82849   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82850 END IF;
82851 
82852 --
82853 
82854 
82855 --
82856 AcctLineType_117 (
82857  p_application_id  => p_application_id
82858  ,p_event_id     => l_event_id
82859  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82860  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82861  ,p_actual_flag => l_actual_flag
82862  ,p_balance_type_code => l_balance_type_code
82863  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82864  
82865  , p_source_3 => l_array_source_3(Idx)
82866  , p_source_20 => l_array_source_20(Idx)
82867  , p_source_22 => l_array_source_22(Idx)
82868  , p_source_23 => l_array_source_23(Idx)
82869  , p_source_26 => l_array_source_26(Idx)
82870  , p_source_27 => l_array_source_27(Idx)
82871  , p_source_28 => l_array_source_28(Idx)
82872  , p_source_34 => l_array_source_34(Idx)
82873  , p_source_35 => l_array_source_35(Idx)
82874  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82875  , p_source_59 => l_array_source_59(Idx)
82876  , p_source_60 => l_array_source_60(Idx)
82877  , p_source_61 => l_array_source_61(Idx)
82878  , p_source_63 => l_array_source_63(Idx)
82879  , p_source_64 => l_array_source_64(Idx)
82880  , p_source_65 => l_array_source_65(Idx)
82881  , p_source_69 => l_array_source_69(Idx)
82882  , p_source_72 => l_array_source_72(Idx)
82883  , p_source_73 => l_array_source_73(Idx)
82884  );
82885 If(l_balance_type_code = 'A') THEN
82886   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82887 END IF;
82888 
82889 --
82890 
82891 
82892 --
82893 AcctLineType_118 (
82897  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82894  p_application_id  => p_application_id
82895  ,p_event_id     => l_event_id
82896  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82898  ,p_actual_flag => l_actual_flag
82899  ,p_balance_type_code => l_balance_type_code
82900  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82901  
82902  , p_source_3 => l_array_source_3(Idx)
82903  , p_source_20 => l_array_source_20(Idx)
82904  , p_source_22 => l_array_source_22(Idx)
82905  , p_source_23 => l_array_source_23(Idx)
82906  , p_source_26 => l_array_source_26(Idx)
82907  , p_source_27 => l_array_source_27(Idx)
82908  , p_source_28 => l_array_source_28(Idx)
82909  , p_source_34 => l_array_source_34(Idx)
82910  , p_source_35 => l_array_source_35(Idx)
82911  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82912  , p_source_59 => l_array_source_59(Idx)
82913  , p_source_60 => l_array_source_60(Idx)
82914  , p_source_61 => l_array_source_61(Idx)
82915  , p_source_63 => l_array_source_63(Idx)
82916  , p_source_64 => l_array_source_64(Idx)
82917  , p_source_65 => l_array_source_65(Idx)
82918  , p_source_69 => l_array_source_69(Idx)
82919  , p_source_72 => l_array_source_72(Idx)
82920  , p_source_73 => l_array_source_73(Idx)
82921  );
82922 If(l_balance_type_code = 'A') THEN
82923   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82924 END IF;
82925 
82926 --
82927 
82928 
82929 --
82930 AcctLineType_119 (
82931  p_application_id  => p_application_id
82932  ,p_event_id     => l_event_id
82933  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82934  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82935  ,p_actual_flag => l_actual_flag
82936  ,p_balance_type_code => l_balance_type_code
82937  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82938  
82939  , p_source_3 => l_array_source_3(Idx)
82940  , p_source_20 => l_array_source_20(Idx)
82941  , p_source_22 => l_array_source_22(Idx)
82942  , p_source_23 => l_array_source_23(Idx)
82943  , p_source_24 => l_array_source_24(Idx)
82944  , p_source_25 => l_array_source_25(Idx)
82945  , p_source_29 => l_array_source_29(Idx)
82946  , p_source_34 => l_array_source_34(Idx)
82947  , p_source_35 => l_array_source_35(Idx)
82948  , p_source_57 => l_array_source_57(Idx)
82949  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82950  , p_source_59 => l_array_source_59(Idx)
82951  , p_source_60 => l_array_source_60(Idx)
82952  , p_source_62 => l_array_source_62(Idx)
82953  , p_source_63 => l_array_source_63(Idx)
82954  , p_source_64 => l_array_source_64(Idx)
82955  , p_source_65 => l_array_source_65(Idx)
82956  , p_source_69 => l_array_source_69(Idx)
82957  , p_source_74 => l_array_source_74(Idx)
82958  );
82959 If(l_balance_type_code = 'A') THEN
82960   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82961 END IF;
82962 
82963 --
82964 
82965 
82966 --
82967 AcctLineType_120 (
82968  p_application_id  => p_application_id
82969  ,p_event_id     => l_event_id
82970  ,p_calculate_acctd_flag => l_calculate_acctd_flag
82971  ,p_calculate_g_l_flag => l_calculate_g_l_flag
82972  ,p_actual_flag => l_actual_flag
82973  ,p_balance_type_code => l_balance_type_code
82974  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
82975  
82976  , p_source_3 => l_array_source_3(Idx)
82977  , p_source_4 => l_array_source_4(Idx)
82978  , p_source_20 => l_array_source_20(Idx)
82979  , p_source_22 => l_array_source_22(Idx)
82980  , p_source_23 => l_array_source_23(Idx)
82981  , p_source_24 => l_array_source_24(Idx)
82982  , p_source_25 => l_array_source_25(Idx)
82983  , p_source_29 => l_array_source_29(Idx)
82984  , p_source_34 => l_array_source_34(Idx)
82985  , p_source_35 => l_array_source_35(Idx)
82986  , p_source_57 => l_array_source_57(Idx)
82987  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
82988  , p_source_59 => l_array_source_59(Idx)
82989  , p_source_60 => l_array_source_60(Idx)
82990  , p_source_62 => l_array_source_62(Idx)
82991  , p_source_63 => l_array_source_63(Idx)
82992  , p_source_64 => l_array_source_64(Idx)
82993  , p_source_65 => l_array_source_65(Idx)
82994  , p_source_69 => l_array_source_69(Idx)
82995  , p_source_74 => l_array_source_74(Idx)
82996  );
82997 If(l_balance_type_code = 'A') THEN
82998   l_actual_gain_loss_ref := l_gain_or_loss_ref;
82999 END IF;
83000 
83001 --
83002 
83003 
83004 --
83005 AcctLineType_121 (
83006  p_application_id  => p_application_id
83007  ,p_event_id     => l_event_id
83008  ,p_calculate_acctd_flag => l_calculate_acctd_flag
83009  ,p_calculate_g_l_flag => l_calculate_g_l_flag
83010  ,p_actual_flag => l_actual_flag
83011  ,p_balance_type_code => l_balance_type_code
83012  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
83013  
83014  , p_source_3 => l_array_source_3(Idx)
83015  , p_source_20 => l_array_source_20(Idx)
83016  , p_source_22 => l_array_source_22(Idx)
83017  , p_source_23 => l_array_source_23(Idx)
83018  , p_source_24 => l_array_source_24(Idx)
83019  , p_source_26 => l_array_source_26(Idx)
83020  , p_source_27 => l_array_source_27(Idx)
83021  , p_source_28 => l_array_source_28(Idx)
83022  , p_source_29 => l_array_source_29(Idx)
83023  , p_source_34 => l_array_source_34(Idx)
83024  , p_source_35 => l_array_source_35(Idx)
83025  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
83026  , p_source_59 => l_array_source_59(Idx)
83027  , p_source_60 => l_array_source_60(Idx)
83028  , p_source_61 => l_array_source_61(Idx)
83029  , p_source_63 => l_array_source_63(Idx)
83030  , p_source_64 => l_array_source_64(Idx)
83031  , p_source_65 => l_array_source_65(Idx)
83032  );
83033 If(l_balance_type_code = 'A') THEN
83034   l_actual_gain_loss_ref := l_gain_or_loss_ref;
83035 END IF;
83036 
83037 --
83038 
83039 
83040 --
83041 AcctLineType_122 (
83045  ,p_calculate_g_l_flag => l_calculate_g_l_flag
83042  p_application_id  => p_application_id
83043  ,p_event_id     => l_event_id
83044  ,p_calculate_acctd_flag => l_calculate_acctd_flag
83046  ,p_actual_flag => l_actual_flag
83047  ,p_balance_type_code => l_balance_type_code
83048  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
83049  
83050  , p_source_3 => l_array_source_3(Idx)
83051  , p_source_20 => l_array_source_20(Idx)
83052  , p_source_22 => l_array_source_22(Idx)
83053  , p_source_23 => l_array_source_23(Idx)
83054  , p_source_24 => l_array_source_24(Idx)
83055  , p_source_26 => l_array_source_26(Idx)
83056  , p_source_27 => l_array_source_27(Idx)
83057  , p_source_28 => l_array_source_28(Idx)
83058  , p_source_29 => l_array_source_29(Idx)
83059  , p_source_34 => l_array_source_34(Idx)
83060  , p_source_35 => l_array_source_35(Idx)
83061  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
83062  , p_source_59 => l_array_source_59(Idx)
83063  , p_source_60 => l_array_source_60(Idx)
83064  , p_source_61 => l_array_source_61(Idx)
83065  , p_source_63 => l_array_source_63(Idx)
83066  , p_source_64 => l_array_source_64(Idx)
83067  , p_source_65 => l_array_source_65(Idx)
83068  );
83069 If(l_balance_type_code = 'A') THEN
83070   l_actual_gain_loss_ref := l_gain_or_loss_ref;
83071 END IF;
83072 
83073 --
83074 
83075 
83076 --
83077 AcctLineType_123 (
83078  p_application_id  => p_application_id
83079  ,p_event_id     => l_event_id
83080  ,p_calculate_acctd_flag => l_calculate_acctd_flag
83081  ,p_calculate_g_l_flag => l_calculate_g_l_flag
83082  ,p_actual_flag => l_actual_flag
83083  ,p_balance_type_code => l_balance_type_code
83084  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
83085  
83086  , p_source_3 => l_array_source_3(Idx)
83087  , p_source_20 => l_array_source_20(Idx)
83088  , p_source_22 => l_array_source_22(Idx)
83089  , p_source_23 => l_array_source_23(Idx)
83090  , p_source_26 => l_array_source_26(Idx)
83091  , p_source_27 => l_array_source_27(Idx)
83092  , p_source_28 => l_array_source_28(Idx)
83093  , p_source_34 => l_array_source_34(Idx)
83094  , p_source_35 => l_array_source_35(Idx)
83095  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
83096  , p_source_59 => l_array_source_59(Idx)
83097  , p_source_60 => l_array_source_60(Idx)
83098  , p_source_61 => l_array_source_61(Idx)
83099  , p_source_63 => l_array_source_63(Idx)
83100  , p_source_64 => l_array_source_64(Idx)
83101  , p_source_65 => l_array_source_65(Idx)
83102  , p_source_69 => l_array_source_69(Idx)
83103  , p_source_72 => l_array_source_72(Idx)
83104  , p_source_73 => l_array_source_73(Idx)
83105  , p_source_75 => l_array_source_75(Idx)
83106  );
83107 If(l_balance_type_code = 'A') THEN
83108   l_actual_gain_loss_ref := l_gain_or_loss_ref;
83109 END IF;
83110 
83111 --
83112 
83113 
83114 --
83115 AcctLineType_124 (
83116  p_application_id  => p_application_id
83117  ,p_event_id     => l_event_id
83118  ,p_calculate_acctd_flag => l_calculate_acctd_flag
83119  ,p_calculate_g_l_flag => l_calculate_g_l_flag
83120  ,p_actual_flag => l_actual_flag
83121  ,p_balance_type_code => l_balance_type_code
83122  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
83123  
83124  , p_source_3 => l_array_source_3(Idx)
83125  , p_source_20 => l_array_source_20(Idx)
83126  , p_source_22 => l_array_source_22(Idx)
83127  , p_source_23 => l_array_source_23(Idx)
83128  , p_source_26 => l_array_source_26(Idx)
83129  , p_source_27 => l_array_source_27(Idx)
83130  , p_source_28 => l_array_source_28(Idx)
83131  , p_source_34 => l_array_source_34(Idx)
83132  , p_source_35 => l_array_source_35(Idx)
83133  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
83134  , p_source_59 => l_array_source_59(Idx)
83135  , p_source_60 => l_array_source_60(Idx)
83136  , p_source_61 => l_array_source_61(Idx)
83137  , p_source_63 => l_array_source_63(Idx)
83138  , p_source_64 => l_array_source_64(Idx)
83139  , p_source_65 => l_array_source_65(Idx)
83140  , p_source_69 => l_array_source_69(Idx)
83141  , p_source_72 => l_array_source_72(Idx)
83142  , p_source_73 => l_array_source_73(Idx)
83143  , p_source_75 => l_array_source_75(Idx)
83144  );
83145 If(l_balance_type_code = 'A') THEN
83146   l_actual_gain_loss_ref := l_gain_or_loss_ref;
83147 END IF;
83148 
83149 --
83150 
83151 
83152 --
83153 AcctLineType_125 (
83154  p_application_id  => p_application_id
83155  ,p_event_id     => l_event_id
83156  ,p_calculate_acctd_flag => l_calculate_acctd_flag
83157  ,p_calculate_g_l_flag => l_calculate_g_l_flag
83158  ,p_actual_flag => l_actual_flag
83159  ,p_balance_type_code => l_balance_type_code
83160  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
83161  
83162  , p_source_3 => l_array_source_3(Idx)
83163  , p_source_20 => l_array_source_20(Idx)
83164  , p_source_21 => l_array_source_21(Idx)
83165  , p_source_22 => l_array_source_22(Idx)
83166  , p_source_23 => l_array_source_23(Idx)
83167  , p_source_26 => l_array_source_26(Idx)
83168  , p_source_27 => l_array_source_27(Idx)
83169  , p_source_28 => l_array_source_28(Idx)
83170  , p_source_29 => l_array_source_29(Idx)
83171  , p_source_34 => l_array_source_34(Idx)
83172  , p_source_35 => l_array_source_35(Idx)
83173  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
83174  , p_source_59 => l_array_source_59(Idx)
83175  , p_source_60 => l_array_source_60(Idx)
83176  , p_source_61 => l_array_source_61(Idx)
83177  , p_source_63 => l_array_source_63(Idx)
83178  , p_source_64 => l_array_source_64(Idx)
83179  , p_source_65 => l_array_source_65(Idx)
83180  , p_source_69 => l_array_source_69(Idx)
83181  , p_source_72 => l_array_source_72(Idx)
83182  );
83183 If(l_balance_type_code = 'A') THEN
83184   l_actual_gain_loss_ref := l_gain_or_loss_ref;
83185 END IF;
83186 
83187 --
83191 AcctLineType_126 (
83188 
83189 
83190 --
83192  p_application_id  => p_application_id
83193  ,p_event_id     => l_event_id
83194  ,p_calculate_acctd_flag => l_calculate_acctd_flag
83195  ,p_calculate_g_l_flag => l_calculate_g_l_flag
83196  ,p_actual_flag => l_actual_flag
83197  ,p_balance_type_code => l_balance_type_code
83198  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
83199  
83200  , p_source_3 => l_array_source_3(Idx)
83201  , p_source_20 => l_array_source_20(Idx)
83202  , p_source_21 => l_array_source_21(Idx)
83203  , p_source_22 => l_array_source_22(Idx)
83204  , p_source_23 => l_array_source_23(Idx)
83205  , p_source_26 => l_array_source_26(Idx)
83206  , p_source_27 => l_array_source_27(Idx)
83207  , p_source_28 => l_array_source_28(Idx)
83208  , p_source_34 => l_array_source_34(Idx)
83209  , p_source_35 => l_array_source_35(Idx)
83210  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
83211  , p_source_59 => l_array_source_59(Idx)
83212  , p_source_60 => l_array_source_60(Idx)
83213  , p_source_61 => l_array_source_61(Idx)
83214  , p_source_63 => l_array_source_63(Idx)
83215  , p_source_64 => l_array_source_64(Idx)
83216  , p_source_65 => l_array_source_65(Idx)
83217  , p_source_69 => l_array_source_69(Idx)
83218  , p_source_72 => l_array_source_72(Idx)
83219  , p_source_73 => l_array_source_73(Idx)
83220  );
83221 If(l_balance_type_code = 'A') THEN
83222   l_actual_gain_loss_ref := l_gain_or_loss_ref;
83223 END IF;
83224 
83225 --
83226 
83227 
83228 --
83229 AcctLineType_127 (
83230  p_application_id  => p_application_id
83231  ,p_event_id     => l_event_id
83232  ,p_calculate_acctd_flag => l_calculate_acctd_flag
83233  ,p_calculate_g_l_flag => l_calculate_g_l_flag
83234  ,p_actual_flag => l_actual_flag
83235  ,p_balance_type_code => l_balance_type_code
83236  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
83237  
83238  , p_source_3 => l_array_source_3(Idx)
83239  , p_source_20 => l_array_source_20(Idx)
83240  , p_source_21 => l_array_source_21(Idx)
83241  , p_source_22 => l_array_source_22(Idx)
83242  , p_source_23 => l_array_source_23(Idx)
83243  , p_source_26 => l_array_source_26(Idx)
83244  , p_source_27 => l_array_source_27(Idx)
83245  , p_source_28 => l_array_source_28(Idx)
83246  , p_source_34 => l_array_source_34(Idx)
83247  , p_source_35 => l_array_source_35(Idx)
83248  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
83249  , p_source_59 => l_array_source_59(Idx)
83250  , p_source_60 => l_array_source_60(Idx)
83251  , p_source_61 => l_array_source_61(Idx)
83252  , p_source_63 => l_array_source_63(Idx)
83253  , p_source_64 => l_array_source_64(Idx)
83254  , p_source_65 => l_array_source_65(Idx)
83255  , p_source_69 => l_array_source_69(Idx)
83256  , p_source_72 => l_array_source_72(Idx)
83257  , p_source_73 => l_array_source_73(Idx)
83258  );
83259 If(l_balance_type_code = 'A') THEN
83260   l_actual_gain_loss_ref := l_gain_or_loss_ref;
83261 END IF;
83262 
83263 --
83264 
83265 
83266 --
83267 AcctLineType_128 (
83268  p_application_id  => p_application_id
83269  ,p_event_id     => l_event_id
83270  ,p_calculate_acctd_flag => l_calculate_acctd_flag
83271  ,p_calculate_g_l_flag => l_calculate_g_l_flag
83272  ,p_actual_flag => l_actual_flag
83273  ,p_balance_type_code => l_balance_type_code
83274  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
83275  
83276  , p_source_3 => l_array_source_3(Idx)
83277  , p_source_20 => l_array_source_20(Idx)
83278  , p_source_22 => l_array_source_22(Idx)
83279  , p_source_23 => l_array_source_23(Idx)
83280  , p_source_26 => l_array_source_26(Idx)
83281  , p_source_27 => l_array_source_27(Idx)
83282  , p_source_28 => l_array_source_28(Idx)
83283  , p_source_34 => l_array_source_34(Idx)
83284  , p_source_35 => l_array_source_35(Idx)
83285  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
83286  , p_source_59 => l_array_source_59(Idx)
83287  , p_source_60 => l_array_source_60(Idx)
83288  , p_source_61 => l_array_source_61(Idx)
83289  , p_source_63 => l_array_source_63(Idx)
83290  , p_source_64 => l_array_source_64(Idx)
83291  , p_source_65 => l_array_source_65(Idx)
83292  , p_source_69 => l_array_source_69(Idx)
83293  , p_source_72 => l_array_source_72(Idx)
83294  , p_source_73 => l_array_source_73(Idx)
83295  , p_source_75 => l_array_source_75(Idx)
83296  );
83297 If(l_balance_type_code = 'A') THEN
83298   l_actual_gain_loss_ref := l_gain_or_loss_ref;
83299 END IF;
83300 
83301 --
83302 
83303 
83304 --
83305 AcctLineType_129 (
83306  p_application_id  => p_application_id
83307  ,p_event_id     => l_event_id
83308  ,p_calculate_acctd_flag => l_calculate_acctd_flag
83309  ,p_calculate_g_l_flag => l_calculate_g_l_flag
83310  ,p_actual_flag => l_actual_flag
83311  ,p_balance_type_code => l_balance_type_code
83312  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
83313  
83314  , p_source_3 => l_array_source_3(Idx)
83315  , p_source_20 => l_array_source_20(Idx)
83316  , p_source_22 => l_array_source_22(Idx)
83317  , p_source_23 => l_array_source_23(Idx)
83318  , p_source_26 => l_array_source_26(Idx)
83319  , p_source_27 => l_array_source_27(Idx)
83320  , p_source_28 => l_array_source_28(Idx)
83321  , p_source_34 => l_array_source_34(Idx)
83322  , p_source_35 => l_array_source_35(Idx)
83323  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
83324  , p_source_59 => l_array_source_59(Idx)
83325  , p_source_60 => l_array_source_60(Idx)
83326  , p_source_61 => l_array_source_61(Idx)
83327  , p_source_63 => l_array_source_63(Idx)
83328  , p_source_64 => l_array_source_64(Idx)
83329  , p_source_65 => l_array_source_65(Idx)
83330  , p_source_69 => l_array_source_69(Idx)
83331  , p_source_72 => l_array_source_72(Idx)
83332  , p_source_73 => l_array_source_73(Idx)
83333  , p_source_75 => l_array_source_75(Idx)
83337 END IF;
83334  );
83335 If(l_balance_type_code = 'A') THEN
83336   l_actual_gain_loss_ref := l_gain_or_loss_ref;
83338 
83339 --
83340 
83341 
83342 --
83343 AcctLineType_130 (
83344  p_application_id  => p_application_id
83345  ,p_event_id     => l_event_id
83346  ,p_calculate_acctd_flag => l_calculate_acctd_flag
83347  ,p_calculate_g_l_flag => l_calculate_g_l_flag
83348  ,p_actual_flag => l_actual_flag
83349  ,p_balance_type_code => l_balance_type_code
83350  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
83351  
83352  , p_source_3 => l_array_source_3(Idx)
83353  , p_source_20 => l_array_source_20(Idx)
83354  , p_source_22 => l_array_source_22(Idx)
83355  , p_source_23 => l_array_source_23(Idx)
83356  , p_source_24 => l_array_source_24(Idx)
83357  , p_source_25 => l_array_source_25(Idx)
83358  , p_source_29 => l_array_source_29(Idx)
83359  , p_source_34 => l_array_source_34(Idx)
83360  , p_source_35 => l_array_source_35(Idx)
83361  , p_source_57 => l_array_source_57(Idx)
83362  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
83363  , p_source_59 => l_array_source_59(Idx)
83364  , p_source_60 => l_array_source_60(Idx)
83365  , p_source_62 => l_array_source_62(Idx)
83366  , p_source_63 => l_array_source_63(Idx)
83367  , p_source_64 => l_array_source_64(Idx)
83368  , p_source_65 => l_array_source_65(Idx)
83369  , p_source_69 => l_array_source_69(Idx)
83370  , p_source_74 => l_array_source_74(Idx)
83371  );
83372 If(l_balance_type_code = 'A') THEN
83373   l_actual_gain_loss_ref := l_gain_or_loss_ref;
83374 END IF;
83375 
83376 --
83377 
83378 
83379 --
83380 AcctLineType_131 (
83381  p_application_id  => p_application_id
83382  ,p_event_id     => l_event_id
83383  ,p_calculate_acctd_flag => l_calculate_acctd_flag
83384  ,p_calculate_g_l_flag => l_calculate_g_l_flag
83385  ,p_actual_flag => l_actual_flag
83386  ,p_balance_type_code => l_balance_type_code
83387  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
83388  
83389  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
83390  , p_source_20 => l_array_source_20(Idx)
83391  , p_source_21 => l_array_source_21(Idx)
83392  , p_source_22 => l_array_source_22(Idx)
83393  , p_source_23 => l_array_source_23(Idx)
83394  , p_source_26 => l_array_source_26(Idx)
83395  , p_source_27 => l_array_source_27(Idx)
83396  , p_source_28 => l_array_source_28(Idx)
83397  , p_source_34 => l_array_source_34(Idx)
83398  , p_source_35 => l_array_source_35(Idx)
83399  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
83400  , p_source_59 => l_array_source_59(Idx)
83401  , p_source_60 => l_array_source_60(Idx)
83402  , p_source_61 => l_array_source_61(Idx)
83403  , p_source_65 => l_array_source_65(Idx)
83404  , p_source_69 => l_array_source_69(Idx)
83405  , p_source_72 => l_array_source_72(Idx)
83406  , p_source_73 => l_array_source_73(Idx)
83407  , p_source_75 => l_array_source_75(Idx)
83408  , p_source_76 => g_array_event(l_event_id).array_value_num('source_76')
83409  , p_source_77 => g_array_event(l_event_id).array_value_num('source_77')
83410  );
83411 If(l_balance_type_code = 'A') THEN
83412   l_actual_gain_loss_ref := l_gain_or_loss_ref;
83413 END IF;
83414 
83415 --
83416 
83417 
83418 --
83419 AcctLineType_132 (
83420  p_application_id  => p_application_id
83421  ,p_event_id     => l_event_id
83422  ,p_calculate_acctd_flag => l_calculate_acctd_flag
83423  ,p_calculate_g_l_flag => l_calculate_g_l_flag
83424  ,p_actual_flag => l_actual_flag
83425  ,p_balance_type_code => l_balance_type_code
83426  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
83427  
83428  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
83429  , p_source_20 => l_array_source_20(Idx)
83430  , p_source_22 => l_array_source_22(Idx)
83431  , p_source_23 => l_array_source_23(Idx)
83432  , p_source_26 => l_array_source_26(Idx)
83433  , p_source_27 => l_array_source_27(Idx)
83434  , p_source_28 => l_array_source_28(Idx)
83435  , p_source_34 => l_array_source_34(Idx)
83436  , p_source_35 => l_array_source_35(Idx)
83437  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
83438  , p_source_59 => l_array_source_59(Idx)
83439  , p_source_60 => l_array_source_60(Idx)
83440  , p_source_61 => l_array_source_61(Idx)
83441  , p_source_65 => l_array_source_65(Idx)
83442  , p_source_69 => l_array_source_69(Idx)
83443  , p_source_72 => l_array_source_72(Idx)
83444  , p_source_73 => l_array_source_73(Idx)
83445  , p_source_75 => l_array_source_75(Idx)
83446  , p_source_76 => g_array_event(l_event_id).array_value_num('source_76')
83447  , p_source_77 => g_array_event(l_event_id).array_value_num('source_77')
83448  , p_source_78 => g_array_event(l_event_id).array_value_char('source_78')
83449  );
83450 If(l_balance_type_code = 'A') THEN
83451   l_actual_gain_loss_ref := l_gain_or_loss_ref;
83452 END IF;
83453 
83454 --
83455 
83456 
83457 --
83458 AcctLineType_133 (
83459  p_application_id  => p_application_id
83460  ,p_event_id     => l_event_id
83461  ,p_calculate_acctd_flag => l_calculate_acctd_flag
83462  ,p_calculate_g_l_flag => l_calculate_g_l_flag
83463  ,p_actual_flag => l_actual_flag
83464  ,p_balance_type_code => l_balance_type_code
83465  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
83466  
83467  , p_source_3 => l_array_source_3(Idx)
83468  , p_source_4 => l_array_source_4(Idx)
83469  , p_source_20 => l_array_source_20(Idx)
83470  , p_source_22 => l_array_source_22(Idx)
83471  , p_source_23 => l_array_source_23(Idx)
83472  , p_source_24 => l_array_source_24(Idx)
83473  , p_source_25 => l_array_source_25(Idx)
83474  , p_source_29 => l_array_source_29(Idx)
83475  , p_source_34 => l_array_source_34(Idx)
83476  , p_source_35 => l_array_source_35(Idx)
83477  , p_source_57 => l_array_source_57(Idx)
83481  , p_source_62 => l_array_source_62(Idx)
83478  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
83479  , p_source_59 => l_array_source_59(Idx)
83480  , p_source_60 => l_array_source_60(Idx)
83482  , p_source_63 => l_array_source_63(Idx)
83483  , p_source_64 => l_array_source_64(Idx)
83484  , p_source_65 => l_array_source_65(Idx)
83485  , p_source_69 => l_array_source_69(Idx)
83486  , p_source_74 => l_array_source_74(Idx)
83487  );
83488 If(l_balance_type_code = 'A') THEN
83489   l_actual_gain_loss_ref := l_gain_or_loss_ref;
83490 END IF;
83491 
83492 --
83493 
83494 
83495 --
83496 AcctLineType_134 (
83497  p_application_id  => p_application_id
83498  ,p_event_id     => l_event_id
83499  ,p_calculate_acctd_flag => l_calculate_acctd_flag
83500  ,p_calculate_g_l_flag => l_calculate_g_l_flag
83501  ,p_actual_flag => l_actual_flag
83502  ,p_balance_type_code => l_balance_type_code
83503  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
83504  
83505  , p_source_3 => l_array_source_3(Idx)
83506  , p_source_20 => l_array_source_20(Idx)
83507  , p_source_22 => l_array_source_22(Idx)
83508  , p_source_23 => l_array_source_23(Idx)
83509  , p_source_26 => l_array_source_26(Idx)
83510  , p_source_27 => l_array_source_27(Idx)
83511  , p_source_28 => l_array_source_28(Idx)
83512  , p_source_34 => l_array_source_34(Idx)
83513  , p_source_35 => l_array_source_35(Idx)
83514  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
83515  , p_source_59 => l_array_source_59(Idx)
83516  , p_source_60 => l_array_source_60(Idx)
83517  , p_source_61 => l_array_source_61(Idx)
83518  , p_source_63 => l_array_source_63(Idx)
83519  , p_source_64 => l_array_source_64(Idx)
83520  , p_source_65 => l_array_source_65(Idx)
83521  , p_source_69 => l_array_source_69(Idx)
83522  , p_source_72 => l_array_source_72(Idx)
83523  , p_source_73 => l_array_source_73(Idx)
83524  );
83525 If(l_balance_type_code = 'A') THEN
83526   l_actual_gain_loss_ref := l_gain_or_loss_ref;
83527 END IF;
83528 
83529 --
83530 
83531 
83532 --
83533 AcctLineType_135 (
83534  p_application_id  => p_application_id
83535  ,p_event_id     => l_event_id
83536  ,p_calculate_acctd_flag => l_calculate_acctd_flag
83537  ,p_calculate_g_l_flag => l_calculate_g_l_flag
83538  ,p_actual_flag => l_actual_flag
83539  ,p_balance_type_code => l_balance_type_code
83540  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
83541  
83542  , p_source_3 => l_array_source_3(Idx)
83543  , p_source_20 => l_array_source_20(Idx)
83544  , p_source_21 => l_array_source_21(Idx)
83545  , p_source_22 => l_array_source_22(Idx)
83546  , p_source_23 => l_array_source_23(Idx)
83547  , p_source_26 => l_array_source_26(Idx)
83548  , p_source_27 => l_array_source_27(Idx)
83549  , p_source_28 => l_array_source_28(Idx)
83550  , p_source_34 => l_array_source_34(Idx)
83551  , p_source_35 => l_array_source_35(Idx)
83552  , p_source_58 => g_array_event(l_event_id).array_value_num('source_58')
83553  , p_source_59 => l_array_source_59(Idx)
83554  , p_source_60 => l_array_source_60(Idx)
83555  , p_source_61 => l_array_source_61(Idx)
83556  , p_source_63 => l_array_source_63(Idx)
83557  , p_source_64 => l_array_source_64(Idx)
83558  , p_source_65 => l_array_source_65(Idx)
83559  , p_source_69 => l_array_source_69(Idx)
83560  , p_source_72 => l_array_source_72(Idx)
83561  , p_source_73 => l_array_source_73(Idx)
83562  );
83563 If(l_balance_type_code = 'A') THEN
83564   l_actual_gain_loss_ref := l_gain_or_loss_ref;
83565 END IF;
83566 
83567 --
83568 
83569       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
83570       -- or secondary ledger that has different currency with primary
83571       -- or alc that is calculated by sla
83572       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
83573             (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'))
83574 
83575 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
83576 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
83577           AND (l_actual_flag = 'A')) THEN
83578         XLA_AE_LINES_PKG.CreateGainOrLossLines(
83579           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
83580          ,p_application_id   => p_application_id
83581          ,p_amb_context_code => 'DEFAULT'
83582          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
83583          ,p_event_class_code => C_EVENT_CLASS_CODE
83584          ,p_event_type_code  => C_EVENT_TYPE_CODE
83585          
83586          ,p_gain_ccid        => TO_NUMBER(g_array_event(l_event_id).array_value_num('source_18'))
83587          ,p_loss_ccid        => TO_NUMBER(g_array_event(l_event_id).array_value_num('source_19'))
83588 
83589          ,p_actual_flag      => l_actual_flag
83590          ,p_enc_flag         => null
83591          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
83592          ,p_enc_g_l_ref      => null
83593          );
83594       END IF;
83595    END IF;
83596 END IF;
83597 
83598    ELSE
83599       --
83600       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
83601       --
83602       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
83603          trace
83604             (p_msg      => 'Trancaction revesal option is Y'
83605             ,p_level    => C_LEVEL_STATEMENT
83606             ,p_module   => l_log_module);
83607       END IF;
83608    END IF;
83609 
83610 END LOOP;
83611 l_result := XLA_AE_LINES_PKG.InsertLines ;
83612 end loop;
83613 close line_cur;
83614 
83615 
83616 --
83617 -- insert headers into xla_ae_headers_gt table
83618 --
83622 
83619 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
83620 
83621 -- insert into errors table here.
83623 END LOOP;
83624 
83625 --
83626 -- 4865292
83627 --
83628 -- Compare g_hdr_extract_count with event count in
83629 -- CreateHeadersAndLines.
83630 --
83631 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
83632 
83633 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
83634    trace (p_msg     => '# rows extracted from header extract objects '
83635                     || ' (running total): '
83636                     || g_hdr_extract_count
83637          ,p_level   => C_LEVEL_STATEMENT
83638          ,p_module  => l_log_module);
83639 END IF;
83640 
83641 CLOSE header_cur;
83642 --
83643 
83644 --
83645 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
83646    trace
83647       (p_msg      => 'END of EventClass_144'
83648       ,p_level    => C_LEVEL_PROCEDURE
83649       ,p_module   => l_log_module);
83650 END IF;
83651 --
83652 RETURN l_result;
83653 EXCEPTION
83654 WHEN xla_exceptions_pkg.application_exception THEN
83655    
83656 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
83657 
83658    
83659 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
83660 
83661    RAISE;
83662 
83663 WHEN NO_DATA_FOUND THEN
83664 
83665 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
83666 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
83667 
83668 FOR header_record IN header_cur
83669 LOOP
83670     l_array_header_events(header_record.event_id) := header_record.event_id;
83671 END LOOP;
83672 
83673 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
83674 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
83675 
83676 fnd_file.put_line(fnd_file.LOG, '                    ');
83677 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
83678 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
83679 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
83680 
83681 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
83682 LOOP
83683 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
83684 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
83685         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
83686 	END IF;
83687 END LOOP;
83688 
83689 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
83690 fnd_file.put_line(fnd_file.LOG, '                    ');
83691 
83692 
83693 xla_exceptions_pkg.raise_message
83694       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_144');
83695 
83696 
83697 WHEN OTHERS THEN
83698    xla_exceptions_pkg.raise_message
83699       (p_location => 'XLA_00222_AAD_S_000006_PKG.EventClass_144');
83700 END EventClass_144;
83701 --
83702 
83703 --
83704 --+============================================+
83705 --|                                            |
83706 --|  PRIVATE FUNCTION                          |
83707 --|                                            |
83708 --+============================================+
83709 --
83710 FUNCTION CreateHeadersAndLines
83711        (p_application_id         IN NUMBER
83712        ,p_base_ledger_id         IN NUMBER
83713        ,p_target_ledger_id       IN NUMBER
83714        ,p_pad_start_date         IN DATE
83715        ,p_pad_end_date           IN DATE
83716        ,p_primary_ledger_id      IN NUMBER)
83717 RETURN BOOLEAN IS
83718 l_created                   BOOLEAN:=FALSE;
83719 l_event_id                  NUMBER;
83720 l_event_date                DATE;
83721 l_language                  VARCHAR2(30);
83722 l_currency_code             VARCHAR2(30);
83723 l_sla_ledger_id             NUMBER;
83724 l_log_module                VARCHAR2(240);
83725 
83726 BEGIN
83727 --
83728 IF g_log_enabled THEN
83729    l_log_module := C_DEFAULT_MODULE||'.CreateHeadersAndLines';
83730 END IF;
83731 --
83732 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
83733    trace
83734       (p_msg      => 'BEGIN of CreateHeadersAndLines'
83735       ,p_level    => C_LEVEL_PROCEDURE
83736       ,p_module   => l_log_module);
83737 END IF;
83738 
83739 l_language         := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
83740 l_currency_code    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.currency_code;
83741 l_sla_ledger_id    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.sla_ledger_id;
83742 
83743 --
83744 -- initialize array of lines with NULL
83745 --
83746 xla_ae_lines_pkg.SetNullLine;
83747 
83748 --
83749 -- initialize header extract count -- Bug 4865292
83750 --
83751 g_hdr_extract_count:= 0;
83752 
83753 
83754 l_created := EventClass_136(
83755    p_application_id         => p_application_id
83756  , p_base_ledger_id         => p_base_ledger_id
83757  , p_target_ledger_id       => p_target_ledger_id
83758  , p_language               => l_language
83759  , p_currency_code          => l_currency_code
83760  , p_sla_ledger_id          => l_sla_ledger_id
83761  , p_pad_start_date         => p_pad_start_date
83762  , p_pad_end_date           => p_pad_end_date
83763  , p_primary_ledger_id      => p_primary_ledger_id
83764 );
83765 
83766 
83767 
83768      IF ( g_diagnostics_mode ='Y' ) THEN
83769 
83770          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
83771           trace
83772               (p_msg      => 'CALL Transaction Objects Diagnostics'
83773               ,p_level    => C_LEVEL_STATEMENT
83774               ,p_module   => l_log_module);
83778          insert_sources_136(
83775 
83776          END IF;
83777 
83779                           p_target_ledger_id => p_target_ledger_id
83780                         , p_language         => l_language
83781                         , p_sla_ledger_id    => l_sla_ledger_id
83782                         , p_pad_start_date   => p_pad_start_date
83783                         , p_pad_end_date     => p_pad_end_date
83784                           );
83785 
83786      END IF;
83787 
83788 l_created := EventClass_137(
83789    p_application_id         => p_application_id
83790  , p_base_ledger_id         => p_base_ledger_id
83791  , p_target_ledger_id       => p_target_ledger_id
83792  , p_language               => l_language
83793  , p_currency_code          => l_currency_code
83794  , p_sla_ledger_id          => l_sla_ledger_id
83795  , p_pad_start_date         => p_pad_start_date
83796  , p_pad_end_date           => p_pad_end_date
83797  , p_primary_ledger_id      => p_primary_ledger_id
83798 );
83799 
83800 
83801 
83802      IF ( g_diagnostics_mode ='Y' ) THEN
83803 
83804          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
83805           trace
83806               (p_msg      => 'CALL Transaction Objects Diagnostics'
83807               ,p_level    => C_LEVEL_STATEMENT
83808               ,p_module   => l_log_module);
83809 
83810          END IF;
83811 
83812          insert_sources_137(
83813                           p_target_ledger_id => p_target_ledger_id
83814                         , p_language         => l_language
83815                         , p_sla_ledger_id    => l_sla_ledger_id
83816                         , p_pad_start_date   => p_pad_start_date
83817                         , p_pad_end_date     => p_pad_end_date
83818                           );
83819 
83820      END IF;
83821 
83822 l_created := EventClass_138(
83823    p_application_id         => p_application_id
83824  , p_base_ledger_id         => p_base_ledger_id
83825  , p_target_ledger_id       => p_target_ledger_id
83826  , p_language               => l_language
83827  , p_currency_code          => l_currency_code
83828  , p_sla_ledger_id          => l_sla_ledger_id
83829  , p_pad_start_date         => p_pad_start_date
83830  , p_pad_end_date           => p_pad_end_date
83831  , p_primary_ledger_id      => p_primary_ledger_id
83832 );
83833 
83834 
83835 
83836      IF ( g_diagnostics_mode ='Y' ) THEN
83837 
83838          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
83839           trace
83840               (p_msg      => 'CALL Transaction Objects Diagnostics'
83841               ,p_level    => C_LEVEL_STATEMENT
83842               ,p_module   => l_log_module);
83843 
83844          END IF;
83845 
83846          insert_sources_138(
83847                           p_target_ledger_id => p_target_ledger_id
83848                         , p_language         => l_language
83849                         , p_sla_ledger_id    => l_sla_ledger_id
83850                         , p_pad_start_date   => p_pad_start_date
83851                         , p_pad_end_date     => p_pad_end_date
83852                           );
83853 
83854      END IF;
83855 
83856 l_created := EventClass_139(
83857    p_application_id         => p_application_id
83858  , p_base_ledger_id         => p_base_ledger_id
83859  , p_target_ledger_id       => p_target_ledger_id
83860  , p_language               => l_language
83861  , p_currency_code          => l_currency_code
83862  , p_sla_ledger_id          => l_sla_ledger_id
83863  , p_pad_start_date         => p_pad_start_date
83864  , p_pad_end_date           => p_pad_end_date
83865  , p_primary_ledger_id      => p_primary_ledger_id
83866 );
83867 
83868 
83869 
83870      IF ( g_diagnostics_mode ='Y' ) THEN
83871 
83872          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
83873           trace
83874               (p_msg      => 'CALL Transaction Objects Diagnostics'
83875               ,p_level    => C_LEVEL_STATEMENT
83876               ,p_module   => l_log_module);
83877 
83878          END IF;
83879 
83880          insert_sources_139(
83881                           p_target_ledger_id => p_target_ledger_id
83882                         , p_language         => l_language
83883                         , p_sla_ledger_id    => l_sla_ledger_id
83884                         , p_pad_start_date   => p_pad_start_date
83885                         , p_pad_end_date     => p_pad_end_date
83886                           );
83887 
83888      END IF;
83889 
83890 l_created := EventClass_140(
83891    p_application_id         => p_application_id
83892  , p_base_ledger_id         => p_base_ledger_id
83893  , p_target_ledger_id       => p_target_ledger_id
83894  , p_language               => l_language
83895  , p_currency_code          => l_currency_code
83896  , p_sla_ledger_id          => l_sla_ledger_id
83897  , p_pad_start_date         => p_pad_start_date
83898  , p_pad_end_date           => p_pad_end_date
83899  , p_primary_ledger_id      => p_primary_ledger_id
83900 );
83901 
83902 
83903 
83904      IF ( g_diagnostics_mode ='Y' ) THEN
83905 
83906          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
83907           trace
83908               (p_msg      => 'CALL Transaction Objects Diagnostics'
83909               ,p_level    => C_LEVEL_STATEMENT
83910               ,p_module   => l_log_module);
83911 
83912          END IF;
83913 
83914          insert_sources_140(
83915                           p_target_ledger_id => p_target_ledger_id
83916                         , p_language         => l_language
83917                         , p_sla_ledger_id    => l_sla_ledger_id
83918                         , p_pad_start_date   => p_pad_start_date
83919                         , p_pad_end_date     => p_pad_end_date
83923 
83920                           );
83921 
83922      END IF;
83924 l_created := EventClass_141(
83925    p_application_id         => p_application_id
83926  , p_base_ledger_id         => p_base_ledger_id
83927  , p_target_ledger_id       => p_target_ledger_id
83928  , p_language               => l_language
83929  , p_currency_code          => l_currency_code
83930  , p_sla_ledger_id          => l_sla_ledger_id
83931  , p_pad_start_date         => p_pad_start_date
83932  , p_pad_end_date           => p_pad_end_date
83933  , p_primary_ledger_id      => p_primary_ledger_id
83934 );
83935 
83936 
83937 
83938      IF ( g_diagnostics_mode ='Y' ) THEN
83939 
83940          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
83941           trace
83942               (p_msg      => 'CALL Transaction Objects Diagnostics'
83943               ,p_level    => C_LEVEL_STATEMENT
83944               ,p_module   => l_log_module);
83945 
83946          END IF;
83947 
83948          insert_sources_141(
83949                           p_target_ledger_id => p_target_ledger_id
83950                         , p_language         => l_language
83951                         , p_sla_ledger_id    => l_sla_ledger_id
83952                         , p_pad_start_date   => p_pad_start_date
83953                         , p_pad_end_date     => p_pad_end_date
83954                           );
83955 
83956      END IF;
83957 
83958 l_created := EventClass_142(
83959    p_application_id         => p_application_id
83960  , p_base_ledger_id         => p_base_ledger_id
83961  , p_target_ledger_id       => p_target_ledger_id
83962  , p_language               => l_language
83963  , p_currency_code          => l_currency_code
83964  , p_sla_ledger_id          => l_sla_ledger_id
83965  , p_pad_start_date         => p_pad_start_date
83966  , p_pad_end_date           => p_pad_end_date
83967  , p_primary_ledger_id      => p_primary_ledger_id
83968 );
83969 
83970 
83971 
83972      IF ( g_diagnostics_mode ='Y' ) THEN
83973 
83974          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
83975           trace
83976               (p_msg      => 'CALL Transaction Objects Diagnostics'
83977               ,p_level    => C_LEVEL_STATEMENT
83978               ,p_module   => l_log_module);
83979 
83980          END IF;
83981 
83982          insert_sources_142(
83983                           p_target_ledger_id => p_target_ledger_id
83984                         , p_language         => l_language
83985                         , p_sla_ledger_id    => l_sla_ledger_id
83986                         , p_pad_start_date   => p_pad_start_date
83987                         , p_pad_end_date     => p_pad_end_date
83988                           );
83989 
83990      END IF;
83991 
83992 l_created := EventClass_143(
83993    p_application_id         => p_application_id
83994  , p_base_ledger_id         => p_base_ledger_id
83995  , p_target_ledger_id       => p_target_ledger_id
83996  , p_language               => l_language
83997  , p_currency_code          => l_currency_code
83998  , p_sla_ledger_id          => l_sla_ledger_id
83999  , p_pad_start_date         => p_pad_start_date
84000  , p_pad_end_date           => p_pad_end_date
84001  , p_primary_ledger_id      => p_primary_ledger_id
84002 );
84003 
84004 
84005 
84006      IF ( g_diagnostics_mode ='Y' ) THEN
84007 
84008          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
84009           trace
84010               (p_msg      => 'CALL Transaction Objects Diagnostics'
84011               ,p_level    => C_LEVEL_STATEMENT
84012               ,p_module   => l_log_module);
84013 
84014          END IF;
84015 
84016          insert_sources_143(
84017                           p_target_ledger_id => p_target_ledger_id
84018                         , p_language         => l_language
84019                         , p_sla_ledger_id    => l_sla_ledger_id
84020                         , p_pad_start_date   => p_pad_start_date
84021                         , p_pad_end_date     => p_pad_end_date
84022                           );
84023 
84024      END IF;
84025 
84026 l_created := EventClass_144(
84027    p_application_id         => p_application_id
84028  , p_base_ledger_id         => p_base_ledger_id
84029  , p_target_ledger_id       => p_target_ledger_id
84030  , p_language               => l_language
84031  , p_currency_code          => l_currency_code
84032  , p_sla_ledger_id          => l_sla_ledger_id
84033  , p_pad_start_date         => p_pad_start_date
84034  , p_pad_end_date           => p_pad_end_date
84035  , p_primary_ledger_id      => p_primary_ledger_id
84036 );
84037 
84038 
84039 
84040      IF ( g_diagnostics_mode ='Y' ) THEN
84041 
84042          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
84043           trace
84044               (p_msg      => 'CALL Transaction Objects Diagnostics'
84045               ,p_level    => C_LEVEL_STATEMENT
84046               ,p_module   => l_log_module);
84047 
84048          END IF;
84049 
84050          insert_sources_144(
84051                           p_target_ledger_id => p_target_ledger_id
84052                         , p_language         => l_language
84053                         , p_sla_ledger_id    => l_sla_ledger_id
84054                         , p_pad_start_date   => p_pad_start_date
84055                         , p_pad_end_date     => p_pad_end_date
84056                           );
84057 
84058      END IF;
84059 
84060 
84061  --
84062  -- Bug 4865292
84063  -- When the number of events and that of header extract do not match,
84064  -- set the no header extract flag to indicate there are some issues
84065  -- in header extract.
84066  --
84067  -- Event count context is set in xla_accounting_pkg.unit_processor.
84071  IF  xla_context_pkg.get_event_count_context <> g_hdr_extract_count
84068  -- Build_Message for this error is called in xla_accounting_pkg.post_accounting
84069  -- to report it as a general error.
84070  --
84072  AND xla_context_pkg.get_event_nohdr_context <> 'Y' THEN
84073 
84074      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
84075         trace
84076           (p_msg      => '# of extracted headers and events does not match'
84077           ,p_level    => C_LEVEL_STATEMENT
84078           ,p_module   => l_log_module);
84079 
84080         trace
84081           (p_msg      => '# of extracted headers: '
84082                          ||g_hdr_extract_count
84083           ,p_level    => C_LEVEL_STATEMENT
84084           ,p_module   => l_log_module);
84085 
84086         trace
84087           (p_msg      => '# of events in xla_events_gt: '
84088                          ||xla_context_pkg.get_event_count_context
84089           ,p_level    => C_LEVEL_STATEMENT
84090           ,p_module   => l_log_module);
84091 
84092         trace
84093           (p_msg      => 'Event No Header Extract Context: '
84094                          ||xla_context_pkg.get_event_nohdr_context
84095           ,p_level    => C_LEVEL_STATEMENT
84096           ,p_module   => l_log_module);
84097 
84098      END IF;
84099 
84100 
84101      xla_context_pkg.set_event_nohdr_context
84102        (p_nohdr_extract_flag => 'Y'
84103        ,p_client_id => sys_context('USERENV','CLIENT_IDENTIFIER'));
84104 
84105      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
84106         trace
84107           (p_msg      => 'No Header Extract Flag is set to Y'
84108           ,p_level    => C_LEVEL_STATEMENT
84109           ,p_module   => l_log_module);
84110      END IF;
84111 
84112  END IF;
84113 
84114 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
84115    trace
84116       (p_msg      => 'END of CreateHeadersAndLines'
84117       ,p_level    => C_LEVEL_PROCEDURE
84118       ,p_module   => l_log_module);
84119 END IF;
84120 
84121 RETURN l_created;
84122 EXCEPTION
84123 WHEN xla_exceptions_pkg.application_exception THEN
84124    RAISE;
84125 WHEN OTHERS THEN
84126    xla_exceptions_pkg.raise_message
84127       (p_location => 'XLA_00222_AAD_S_000006_PKG.CreateHeadersAndLines');
84128 END CreateHeadersAndLines;
84129 --
84130 --
84131 
84132 --
84133 --+============================================+
84134 --|                                            |
84135 --|  PUBLIC FUNCTION                           |
84136 --|                                            |
84137 --+============================================+
84138 --
84139 FUNCTION CreateJournalEntries
84140        (p_application_id         IN NUMBER
84141        ,p_base_ledger_id         IN NUMBER
84142        ,p_pad_start_date         IN DATE
84143        ,p_pad_end_date           IN DATE
84144        ,p_primary_ledger_id      IN NUMBER)
84145 RETURN NUMBER IS
84146 l_log_module                   VARCHAR2(240);
84147 l_array_ledgers                xla_accounting_cache_pkg.t_array_ledger_id;
84148 l_temp_result                  BOOLEAN;
84149 l_result                       NUMBER;
84150 BEGIN
84151 --
84152 IF g_log_enabled THEN
84153    l_log_module := C_DEFAULT_MODULE||'.CreateJournalEntries';
84154 END IF;
84155 --
84156 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
84157    trace
84158       (p_msg      => 'BEGIN of CreateJournalEntries'||
84159                      ' - p_base_ledger_id = '||TO_CHAR(p_base_ledger_id)
84160       ,p_level    => C_LEVEL_PROCEDURE
84161       ,p_module   => l_log_module);
84162 
84163 END IF;
84164 
84165 --
84166 g_diagnostics_mode:= xla_accounting_engine_pkg.g_diagnostics_mode;
84167 
84168 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
84169    trace
84170       (p_msg      => 'g_diagnostics_mode = '||g_diagnostics_mode
84171       ,p_level    => C_LEVEL_STATEMENT
84172       ,p_module   => l_log_module);
84173 END IF;
84174 --
84175 xla_ae_journal_entry_pkg.SetProductAcctDefinition
84176    (p_product_rule_code      => 'MFAR_FED_AR_ACCRUAL_BALANCING'
84177    ,p_product_rule_type_code => 'S'
84178    ,p_product_rule_version   => ''
84179    ,p_product_rule_name      => 'Multi-Fund Federal Receivables Accrual - Balancing Method'
84180    ,p_amb_context_code       => 'DEFAULT'
84181    );
84182 
84183 l_array_ledgers :=
84184    xla_ae_journal_entry_pkg.GetAlternateCurrencyLedger
84185       (p_base_ledger_id  => p_base_ledger_id);
84186 
84187 FOR Idx IN 1 .. l_array_ledgers.COUNT LOOP
84188    l_temp_result :=
84189       XLA_AE_JOURNAL_ENTRY_PKG.GetLedgersInfo
84190          (p_application_id           => p_application_id
84191          ,p_base_ledger_id           => p_base_ledger_id
84192          ,p_target_ledger_id         => l_array_ledgers(Idx)
84193          ,p_primary_ledger_id        => p_primary_ledger_id
84194          ,p_pad_start_date           => p_pad_start_date
84195          ,p_pad_end_date             => p_pad_end_date);
84196 
84197    l_temp_result :=
84198       l_temp_result AND
84199       CreateHeadersAndLines
84200          (p_application_id             => p_application_id
84201          ,p_base_ledger_id             => p_base_ledger_id
84202          ,p_target_ledger_id           => l_array_ledgers(Idx)
84203          ,p_pad_start_date             => p_pad_start_date
84204          ,p_pad_end_date               => p_pad_end_date
84205          ,p_primary_ledger_id          => p_primary_ledger_id
84206          );
84207 END LOOP;
84208 
84209 
84210 IF (g_diagnostics_mode = 'Y' AND
84211     C_LEVEL_UNEXPECTED >= g_log_level AND
84212     xla_environment_pkg.g_Req_Id IS NOT NULL ) THEN
84213 
84214    xla_accounting_dump_pkg.acctg_event_extract_log(
84215     p_application_id  => p_application_id
84216     ,p_request_id     => xla_environment_pkg.g_Req_Id
84217    );
84218 
84219 END IF;
84220 
84221 CASE l_temp_result
84222   WHEN TRUE THEN l_result := 0;
84223   ELSE l_result := 2;
84224 END CASE;
84225 
84226 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
84227    trace
84228       (p_msg      => 'return value. = '||TO_CHAR(l_result)
84229       ,p_level    => C_LEVEL_PROCEDURE
84230       ,p_module   => l_log_module);
84231    trace
84232       (p_msg      => 'END of CreateJournalEntries '
84233       ,p_level    => C_LEVEL_PROCEDURE
84234       ,p_module   => l_log_module);
84235 END IF;
84236 
84237 RETURN l_result;
84238 EXCEPTION
84239 WHEN xla_exceptions_pkg.application_exception THEN
84240    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
84241    trace
84242       (p_msg      => 'ERROR. = '||sqlerrm
84243       ,p_level    => C_LEVEL_PROCEDURE
84244       ,p_module   => l_log_module);
84245    END IF;
84246    RAISE;
84247 WHEN OTHERS THEN
84248    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
84249    trace
84250       (p_msg      => 'ERROR. = '||sqlerrm
84251       ,p_level    => C_LEVEL_PROCEDURE
84252       ,p_module   => l_log_module);
84253    END IF;
84254    xla_exceptions_pkg.raise_message
84255       (p_location => 'XLA_00222_AAD_S_000006_PKG.CreateJournalEntries');
84256 END CreateJournalEntries;
84257 --
84258 --=============================================================================
84259 --
84260 --
84261 --
84262 --
84263 --
84264 --
84265 --
84266 --
84267 --
84268 --
84269 --
84270 --
84271 --
84272 --
84273 --
84274 --
84275 --
84276 --
84277 --
84278 --
84279 --
84280 --
84281 --=============================================================================
84282 --=============================================================================
84283 --          *********** Initialization routine **********
84284 --=============================================================================
84285 
84286 BEGIN
84287    g_log_level      := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
84288    g_log_enabled    := fnd_log.test
84289                           (log_level  => g_log_level
84290                           ,module     => C_DEFAULT_MODULE);
84291 
84292    IF NOT g_log_enabled  THEN
84293       g_log_level := C_LEVEL_LOG_DISABLED;
84294    END IF;
84295 --
84296 END XLA_00222_AAD_S_000006_PKG;
84297 --