DBA Data[Home] [Help]

PACKAGE BODY: APPS.XLA_00222_AAD_S_000008_PKG

Source


1 PACKAGE BODY XLA_00222_AAD_S_000008_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_000008_PKG                                        |
10 |                                                                       |
11 | DESCRIPTION                                                           |
12 |     Package generated From Product Accounting Definition              |
13 |      Name    : Multi-Fund Account Receivables Accrual - Balancing Meth|
14 |      Code    : MFAR_ACCRUAL_BALANCING                                 |
15 |      Owner   : PRODUCT                                                |
16 |      Version :                                                        |
17 |      AMB Context Code: DEFAULT                                        |
18 | HISTORY                                                               |
19 |     Generated at 30-03-2009 at 05:03:56 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_000008_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);
102 
99 ELSIF p_level >= g_log_level THEN
100           fnd_log.string(p_level, p_module, p_msg);
101 END IF;
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_000008_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_000008_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_000008_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_000008_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;
368 x_flexfield_segment_code := 'GL_BALANCING';
369 x_flex_value_set_id      :=  null ;
370 
371 
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_000008_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
461 RETURN VARCHAR2
458 , x_value_combination_id       OUT NOCOPY NUMBER
459 , x_value_segment_code         OUT NOCOPY VARCHAR2
460 )
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;
490 x_flexfield_segment_code := 'GL_BALANCING';
491 x_flex_value_set_id      :=  null ;
492 
493 
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_000008_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 --
617   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
618 
619       trace
620          (p_msg      => 'END of AcctDerRule_4'
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;
681 END AcctDerRule_4;
678   WHEN OTHERS THEN
679        xla_exceptions_pkg.raise_message
680            (p_location => 'XLA_00222_AAD_S_000008_PKG.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
742          (p_msg      => 'END of AcctDerRule_5'
743          ,p_level    => C_LEVEL_PROCEDURE
744          ,p_module   => l_log_module);
745 
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_000008_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
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;
870 x_value_type_code := null;
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_000008_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
983                                                           , l_component_type_code
984                                                           , l_component_appl_id
985                                                           , l_amb_context_code
986                                                           )
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_000008_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 --Credit Memo Default Receivable Account
1025  , p_source_5            IN NUMBER
1026 , x_transaction_coa_id         OUT NOCOPY NUMBER
1027 , x_accounting_coa_id          OUT NOCOPY NUMBER
1028 , x_value_type_code            OUT NOCOPY VARCHAR2
1029 )
1030 RETURN NUMBER
1031 IS
1032 l_component_type       VARCHAR2(80)  ;
1033 l_component_code       VARCHAR2(30)  ;
1034 l_component_type_code  VARCHAR2(1)   ;
1035 l_component_appl_id    INTEGER       ;
1036 l_amb_context_code     VARCHAR2(30)  ;
1037 l_log_module           VARCHAR2(240) ;
1038 l_output_value         NUMBER        ;
1039 BEGIN
1040 IF g_log_enabled THEN
1041       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_8';
1042 END IF;
1043 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1044       trace
1045          (p_msg      => 'BEGIN of AcctDerRule_8'
1046          ,p_level    => C_LEVEL_PROCEDURE
1047          ,p_module   => l_log_module);
1048 END IF;
1049 --
1050 l_component_type         := 'AMB_ADR';
1051 l_component_code         := 'MFAR_CM_DEF_REC_CCID';
1052 l_component_type_code    := 'S';
1053 l_component_appl_id      :=  222;
1054 l_amb_context_code       := 'DEFAULT';
1055 x_transaction_coa_id     :=  null;
1056 x_accounting_coa_id      :=  null;
1057 --
1058 
1059  --
1060   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1061       trace
1062          (p_msg      => 'END of AcctDerRule_8'
1063          ,p_level    => C_LEVEL_PROCEDURE
1064          ,p_module   => l_log_module);
1065   END IF;
1066   x_value_type_code := 'S';
1067   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_5));
1071 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1068   RETURN l_output_value;
1069 
1070 --
1072       trace
1073          (p_msg      => 'END of AcctDerRule_8(invalid)'
1074          ,p_level    => C_LEVEL_PROCEDURE
1075          ,p_module   => l_log_module);
1076 END IF;
1077 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1078 x_value_type_code := null;
1079 l_output_value    := null;
1080 xla_accounting_err_pkg.build_message
1081                  (p_appli_s_name            => 'XLA'
1082                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1083                  ,p_token_1                 => 'COMPONENT_NAME'
1084                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1085                                                             l_component_type
1086                                                           , l_component_code
1087                                                           , l_component_type_code
1088                                                           , l_component_appl_id
1089                                                           , l_amb_context_code
1090                                                           )
1091                  ,p_token_2                 => 'OWNER'
1092                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1093                                                         'XLA_OWNER_TYPE'
1094                                                         ,l_component_type_code
1095                                                         )
1096                  ,p_token_3                 => 'PAD_NAME'
1097                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1098                  ,p_token_4                 => 'PAD_OWNER'
1099                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1100                                                         'XLA_OWNER_TYPE'
1101                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1102                                                         )
1103                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1104                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1105                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1106                  ,p_ae_header_id            => NULL
1107 );
1108 RETURN l_output_value;
1109 EXCEPTION
1110   WHEN xla_exceptions_pkg.application_exception THEN
1111       RAISE;
1112   WHEN OTHERS THEN
1113        xla_exceptions_pkg.raise_message
1114            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctDerRule_8');
1115 END AcctDerRule_8;
1116 --
1117 
1118 ---------------------------------------
1119 --
1120 -- PRIVATE FUNCTION
1121 --         AcctDerRule_9
1122 --
1123 ---------------------------------------
1124 FUNCTION AcctDerRule_9 (
1125   p_application_id              IN NUMBER
1126 , p_ae_header_id                IN NUMBER
1127 , p_side                        IN VARCHAR2 
1128 --Remittance Bank Account Cash Account
1129  , p_source_6            IN NUMBER
1130 , x_transaction_coa_id         OUT NOCOPY NUMBER
1131 , x_accounting_coa_id          OUT NOCOPY NUMBER
1132 , x_value_type_code            OUT NOCOPY VARCHAR2
1133 )
1134 RETURN NUMBER
1135 IS
1136 l_component_type       VARCHAR2(80)  ;
1137 l_component_code       VARCHAR2(30)  ;
1138 l_component_type_code  VARCHAR2(1)   ;
1139 l_component_appl_id    INTEGER       ;
1140 l_amb_context_code     VARCHAR2(30)  ;
1141 l_log_module           VARCHAR2(240) ;
1142 l_output_value         NUMBER        ;
1143 BEGIN
1144 IF g_log_enabled THEN
1145       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_9';
1146 END IF;
1147 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1148       trace
1149          (p_msg      => 'BEGIN of AcctDerRule_9'
1150          ,p_level    => C_LEVEL_PROCEDURE
1151          ,p_module   => l_log_module);
1152 END IF;
1153 --
1154 l_component_type         := 'AMB_ADR';
1155 l_component_code         := 'MFAR_RCT_DEF_CASH_CCID';
1156 l_component_type_code    := 'S';
1157 l_component_appl_id      :=  222;
1158 l_amb_context_code       := 'DEFAULT';
1159 x_transaction_coa_id     :=  null;
1160 x_accounting_coa_id      :=  null;
1161 --
1162 
1163  --
1164   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1165       trace
1166          (p_msg      => 'END of AcctDerRule_9'
1167          ,p_level    => C_LEVEL_PROCEDURE
1168          ,p_module   => l_log_module);
1169   END IF;
1170   x_value_type_code := 'S';
1171   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_6));
1172   RETURN l_output_value;
1173 
1174 --
1175 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1176       trace
1177          (p_msg      => 'END of AcctDerRule_9(invalid)'
1178          ,p_level    => C_LEVEL_PROCEDURE
1179          ,p_module   => l_log_module);
1180 END IF;
1181 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1182 x_value_type_code := null;
1183 l_output_value    := null;
1184 xla_accounting_err_pkg.build_message
1185                  (p_appli_s_name            => 'XLA'
1186                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1187                  ,p_token_1                 => 'COMPONENT_NAME'
1188                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1189                                                             l_component_type
1190                                                           , l_component_code
1191                                                           , l_component_type_code
1192                                                           , l_component_appl_id
1196                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1193                                                           , l_amb_context_code
1194                                                           )
1195                  ,p_token_2                 => 'OWNER'
1197                                                         'XLA_OWNER_TYPE'
1198                                                         ,l_component_type_code
1199                                                         )
1200                  ,p_token_3                 => 'PAD_NAME'
1201                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1202                  ,p_token_4                 => 'PAD_OWNER'
1203                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1204                                                         'XLA_OWNER_TYPE'
1205                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1206                                                         )
1207                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1208                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1209                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1210                  ,p_ae_header_id            => NULL
1211 );
1212 RETURN l_output_value;
1213 EXCEPTION
1214   WHEN xla_exceptions_pkg.application_exception THEN
1215       RAISE;
1216   WHEN OTHERS THEN
1217        xla_exceptions_pkg.raise_message
1218            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctDerRule_9');
1219 END AcctDerRule_9;
1220 --
1221 
1222 ---------------------------------------
1223 --
1224 -- PRIVATE FUNCTION
1225 --         AcctDerRule_10
1226 --
1227 ---------------------------------------
1228 FUNCTION AcctDerRule_10 (
1229   p_application_id              IN NUMBER
1230 , p_ae_header_id                IN NUMBER
1231 , p_side                        IN VARCHAR2 
1232 --Remittance Bank Account Confirmation Account
1233  , p_source_7            IN NUMBER
1234 , x_transaction_coa_id         OUT NOCOPY NUMBER
1235 , x_accounting_coa_id          OUT NOCOPY NUMBER
1236 , x_value_type_code            OUT NOCOPY VARCHAR2
1237 )
1238 RETURN NUMBER
1239 IS
1240 l_component_type       VARCHAR2(80)  ;
1241 l_component_code       VARCHAR2(30)  ;
1242 l_component_type_code  VARCHAR2(1)   ;
1243 l_component_appl_id    INTEGER       ;
1244 l_amb_context_code     VARCHAR2(30)  ;
1245 l_log_module           VARCHAR2(240) ;
1246 l_output_value         NUMBER        ;
1247 BEGIN
1248 IF g_log_enabled THEN
1249       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_10';
1250 END IF;
1251 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1252       trace
1253          (p_msg      => 'BEGIN of AcctDerRule_10'
1254          ,p_level    => C_LEVEL_PROCEDURE
1255          ,p_module   => l_log_module);
1256 END IF;
1257 --
1258 l_component_type         := 'AMB_ADR';
1259 l_component_code         := 'MFAR_RCT_DEF_CONFIRMATION_CCID';
1260 l_component_type_code    := 'S';
1261 l_component_appl_id      :=  222;
1262 l_amb_context_code       := 'DEFAULT';
1263 x_transaction_coa_id     :=  null;
1264 x_accounting_coa_id      :=  null;
1265 --
1266 
1267  --
1268   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1269       trace
1270          (p_msg      => 'END of AcctDerRule_10'
1271          ,p_level    => C_LEVEL_PROCEDURE
1272          ,p_module   => l_log_module);
1273   END IF;
1274   x_value_type_code := 'S';
1275   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_7));
1276   RETURN l_output_value;
1277 
1278 --
1279 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1280       trace
1281          (p_msg      => 'END of AcctDerRule_10(invalid)'
1282          ,p_level    => C_LEVEL_PROCEDURE
1283          ,p_module   => l_log_module);
1284 END IF;
1285 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1286 x_value_type_code := null;
1287 l_output_value    := null;
1288 xla_accounting_err_pkg.build_message
1289                  (p_appli_s_name            => 'XLA'
1290                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1291                  ,p_token_1                 => 'COMPONENT_NAME'
1292                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1293                                                             l_component_type
1294                                                           , l_component_code
1295                                                           , l_component_type_code
1296                                                           , l_component_appl_id
1297                                                           , l_amb_context_code
1298                                                           )
1299                  ,p_token_2                 => 'OWNER'
1300                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1301                                                         'XLA_OWNER_TYPE'
1302                                                         ,l_component_type_code
1303                                                         )
1304                  ,p_token_3                 => 'PAD_NAME'
1305                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1306                  ,p_token_4                 => 'PAD_OWNER'
1307                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1308                                                         'XLA_OWNER_TYPE'
1309                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1310                                                         )
1311                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1312                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1313                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1314                  ,p_ae_header_id            => NULL
1315 );
1316 RETURN l_output_value;
1317 EXCEPTION
1318   WHEN xla_exceptions_pkg.application_exception THEN
1319       RAISE;
1320   WHEN OTHERS THEN
1321        xla_exceptions_pkg.raise_message
1322            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctDerRule_10');
1323 END AcctDerRule_10;
1324 --
1325 
1326 ---------------------------------------
1327 --
1328 -- PRIVATE FUNCTION
1329 --         AcctDerRule_11
1330 --
1331 ---------------------------------------
1332 FUNCTION AcctDerRule_11 (
1333   p_application_id              IN NUMBER
1334 , p_ae_header_id                IN NUMBER
1335 , p_side                        IN VARCHAR2 
1336 --Remittance Bank Account Remittance Account
1337  , p_source_8            IN NUMBER
1338 , x_transaction_coa_id         OUT NOCOPY NUMBER
1339 , x_accounting_coa_id          OUT NOCOPY NUMBER
1340 , x_value_type_code            OUT NOCOPY VARCHAR2
1341 )
1342 RETURN NUMBER
1343 IS
1344 l_component_type       VARCHAR2(80)  ;
1345 l_component_code       VARCHAR2(30)  ;
1346 l_component_type_code  VARCHAR2(1)   ;
1347 l_component_appl_id    INTEGER       ;
1348 l_amb_context_code     VARCHAR2(30)  ;
1349 l_log_module           VARCHAR2(240) ;
1350 l_output_value         NUMBER        ;
1351 BEGIN
1352 IF g_log_enabled THEN
1353       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_11';
1354 END IF;
1355 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1356       trace
1357          (p_msg      => 'BEGIN of AcctDerRule_11'
1358          ,p_level    => C_LEVEL_PROCEDURE
1359          ,p_module   => l_log_module);
1360 END IF;
1361 --
1362 l_component_type         := 'AMB_ADR';
1363 l_component_code         := 'MFAR_RCT_DEF_REMITTANCE_CCID';
1364 l_component_type_code    := 'S';
1365 l_component_appl_id      :=  222;
1366 l_amb_context_code       := 'DEFAULT';
1367 x_transaction_coa_id     :=  null;
1368 x_accounting_coa_id      :=  null;
1369 --
1370 
1371  --
1372   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1373       trace
1374          (p_msg      => 'END of AcctDerRule_11'
1375          ,p_level    => C_LEVEL_PROCEDURE
1376          ,p_module   => l_log_module);
1377   END IF;
1378   x_value_type_code := 'S';
1379   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_8));
1380   RETURN l_output_value;
1381 
1382 --
1383 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1384       trace
1385          (p_msg      => 'END of AcctDerRule_11(invalid)'
1386          ,p_level    => C_LEVEL_PROCEDURE
1387          ,p_module   => l_log_module);
1388 END IF;
1389 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1390 x_value_type_code := null;
1391 l_output_value    := null;
1392 xla_accounting_err_pkg.build_message
1393                  (p_appli_s_name            => 'XLA'
1394                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1395                  ,p_token_1                 => 'COMPONENT_NAME'
1396                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1397                                                             l_component_type
1398                                                           , l_component_code
1399                                                           , l_component_type_code
1400                                                           , l_component_appl_id
1401                                                           , l_amb_context_code
1402                                                           )
1403                  ,p_token_2                 => 'OWNER'
1404                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1405                                                         'XLA_OWNER_TYPE'
1406                                                         ,l_component_type_code
1407                                                         )
1408                  ,p_token_3                 => 'PAD_NAME'
1409                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1410                  ,p_token_4                 => 'PAD_OWNER'
1411                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1412                                                         'XLA_OWNER_TYPE'
1413                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1414                                                         )
1415                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1416                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1417                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1418                  ,p_ae_header_id            => NULL
1419 );
1420 RETURN l_output_value;
1421 EXCEPTION
1422   WHEN xla_exceptions_pkg.application_exception THEN
1423       RAISE;
1424   WHEN OTHERS THEN
1425        xla_exceptions_pkg.raise_message
1426            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctDerRule_11');
1427 END AcctDerRule_11;
1428 --
1429 
1430 ---------------------------------------
1431 --
1432 -- PRIVATE FUNCTION
1433 --         AcctDerRule_12
1434 --
1435 ---------------------------------------
1436 FUNCTION AcctDerRule_12 (
1437   p_application_id              IN NUMBER
1438 , p_ae_header_id                IN NUMBER
1439 , p_side                        IN VARCHAR2 
1440 --Transaction Default Receivable Account
1441  , p_source_9            IN NUMBER
1442 , x_transaction_coa_id         OUT NOCOPY NUMBER
1443 , x_accounting_coa_id          OUT NOCOPY NUMBER
1444 , x_value_type_code            OUT NOCOPY VARCHAR2
1445 )
1446 RETURN NUMBER
1447 IS
1448 l_component_type       VARCHAR2(80)  ;
1449 l_component_code       VARCHAR2(30)  ;
1450 l_component_type_code  VARCHAR2(1)   ;
1451 l_component_appl_id    INTEGER       ;
1452 l_amb_context_code     VARCHAR2(30)  ;
1453 l_log_module           VARCHAR2(240) ;
1454 l_output_value         NUMBER        ;
1455 BEGIN
1456 IF g_log_enabled THEN
1457       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_12';
1458 END IF;
1459 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1460       trace
1461          (p_msg      => 'BEGIN of AcctDerRule_12'
1462          ,p_level    => C_LEVEL_PROCEDURE
1463          ,p_module   => l_log_module);
1464 END IF;
1465 --
1466 l_component_type         := 'AMB_ADR';
1467 l_component_code         := 'MFAR_TRX_DEF_REC_CCID';
1468 l_component_type_code    := 'S';
1469 l_component_appl_id      :=  222;
1470 l_amb_context_code       := 'DEFAULT';
1471 x_transaction_coa_id     :=  null;
1472 x_accounting_coa_id      :=  null;
1473 --
1474 
1475  --
1476   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1477       trace
1478          (p_msg      => 'END of AcctDerRule_12'
1479          ,p_level    => C_LEVEL_PROCEDURE
1480          ,p_module   => l_log_module);
1481   END IF;
1482   x_value_type_code := 'S';
1483   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_9));
1484   RETURN l_output_value;
1485 
1486 --
1487 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1488       trace
1489          (p_msg      => 'END of AcctDerRule_12(invalid)'
1490          ,p_level    => C_LEVEL_PROCEDURE
1491          ,p_module   => l_log_module);
1492 END IF;
1493 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1494 x_value_type_code := null;
1495 l_output_value    := null;
1496 xla_accounting_err_pkg.build_message
1497                  (p_appli_s_name            => 'XLA'
1498                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1499                  ,p_token_1                 => 'COMPONENT_NAME'
1500                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1501                                                             l_component_type
1502                                                           , l_component_code
1503                                                           , l_component_type_code
1504                                                           , l_component_appl_id
1505                                                           , l_amb_context_code
1506                                                           )
1507                  ,p_token_2                 => 'OWNER'
1508                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1509                                                         'XLA_OWNER_TYPE'
1513                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1510                                                         ,l_component_type_code
1511                                                         )
1512                  ,p_token_3                 => 'PAD_NAME'
1514                  ,p_token_4                 => 'PAD_OWNER'
1515                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1516                                                         'XLA_OWNER_TYPE'
1517                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1518                                                         )
1519                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1520                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1521                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1522                  ,p_ae_header_id            => NULL
1523 );
1524 RETURN l_output_value;
1525 EXCEPTION
1526   WHEN xla_exceptions_pkg.application_exception THEN
1527       RAISE;
1528   WHEN OTHERS THEN
1529        xla_exceptions_pkg.raise_message
1530            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctDerRule_12');
1531 END AcctDerRule_12;
1532 --
1533 
1534 ---------------------------------------
1535 --
1536 -- PRIVATE FUNCTION
1537 --         AcctDerRule_13
1538 --
1539 ---------------------------------------
1540 FUNCTION AcctDerRule_13 (
1541   p_application_id              IN NUMBER
1542 , p_ae_header_id                IN NUMBER
1543 , p_side                        IN VARCHAR2 
1544 --Remittance Bank Account Unapplied Account
1545  , p_source_10            IN NUMBER
1546 , x_transaction_coa_id         OUT NOCOPY NUMBER
1547 , x_accounting_coa_id          OUT NOCOPY NUMBER
1548 , x_value_type_code            OUT NOCOPY VARCHAR2
1549 )
1550 RETURN NUMBER
1551 IS
1552 l_component_type       VARCHAR2(80)  ;
1553 l_component_code       VARCHAR2(30)  ;
1554 l_component_type_code  VARCHAR2(1)   ;
1555 l_component_appl_id    INTEGER       ;
1556 l_amb_context_code     VARCHAR2(30)  ;
1557 l_log_module           VARCHAR2(240) ;
1558 l_output_value         NUMBER        ;
1559 BEGIN
1560 IF g_log_enabled THEN
1561       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_13';
1562 END IF;
1563 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1564       trace
1565          (p_msg      => 'BEGIN of AcctDerRule_13'
1566          ,p_level    => C_LEVEL_PROCEDURE
1567          ,p_module   => l_log_module);
1568 END IF;
1569 --
1570 l_component_type         := 'AMB_ADR';
1571 l_component_code         := 'RMT_BNK_UNAPP_CCID';
1572 l_component_type_code    := 'S';
1573 l_component_appl_id      :=  222;
1574 l_amb_context_code       := 'DEFAULT';
1575 x_transaction_coa_id     :=  null;
1576 x_accounting_coa_id      :=  null;
1577 --
1578 
1579  --
1580   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1581       trace
1582          (p_msg      => 'END of AcctDerRule_13'
1583          ,p_level    => C_LEVEL_PROCEDURE
1584          ,p_module   => l_log_module);
1585   END IF;
1586   x_value_type_code := 'S';
1587   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_10));
1588   RETURN l_output_value;
1589 
1590 --
1591 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1592       trace
1593          (p_msg      => 'END of AcctDerRule_13(invalid)'
1594          ,p_level    => C_LEVEL_PROCEDURE
1595          ,p_module   => l_log_module);
1596 END IF;
1597 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1598 x_value_type_code := null;
1599 l_output_value    := null;
1600 xla_accounting_err_pkg.build_message
1601                  (p_appli_s_name            => 'XLA'
1602                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1603                  ,p_token_1                 => 'COMPONENT_NAME'
1604                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1605                                                             l_component_type
1606                                                           , l_component_code
1607                                                           , l_component_type_code
1608                                                           , l_component_appl_id
1609                                                           , l_amb_context_code
1610                                                           )
1611                  ,p_token_2                 => 'OWNER'
1612                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1613                                                         'XLA_OWNER_TYPE'
1614                                                         ,l_component_type_code
1615                                                         )
1616                  ,p_token_3                 => 'PAD_NAME'
1617                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1618                  ,p_token_4                 => 'PAD_OWNER'
1619                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1620                                                         'XLA_OWNER_TYPE'
1621                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1622                                                         )
1623                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1624                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1625                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1626                  ,p_ae_header_id            => NULL
1627 );
1628 RETURN l_output_value;
1629 EXCEPTION
1630   WHEN xla_exceptions_pkg.application_exception THEN
1631       RAISE;
1632   WHEN OTHERS THEN
1633        xla_exceptions_pkg.raise_message
1634            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctDerRule_13');
1635 END AcctDerRule_13;
1636 --
1637 
1638 ---------------------------------------
1639 --
1640 -- PRIVATE FUNCTION
1641 --         AcctDerRule_14
1642 --
1643 ---------------------------------------
1644 FUNCTION AcctDerRule_14 (
1645   p_application_id              IN NUMBER
1646 , p_ae_header_id                IN NUMBER
1647 , p_side                        IN VARCHAR2 
1648 --System Gain Account
1649  , p_source_11            IN NUMBER
1650 , x_transaction_coa_id         OUT NOCOPY NUMBER
1651 , x_accounting_coa_id          OUT NOCOPY NUMBER
1652 , x_value_type_code            OUT NOCOPY VARCHAR2
1653 )
1654 RETURN NUMBER
1655 IS
1656 l_component_type       VARCHAR2(80)  ;
1657 l_component_code       VARCHAR2(30)  ;
1658 l_component_type_code  VARCHAR2(1)   ;
1659 l_component_appl_id    INTEGER       ;
1660 l_amb_context_code     VARCHAR2(30)  ;
1661 l_log_module           VARCHAR2(240) ;
1662 l_output_value         NUMBER        ;
1663 BEGIN
1664 IF g_log_enabled THEN
1665       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_14';
1666 END IF;
1667 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1668       trace
1669          (p_msg      => 'BEGIN of AcctDerRule_14'
1670          ,p_level    => C_LEVEL_PROCEDURE
1671          ,p_module   => l_log_module);
1672 END IF;
1673 --
1674 l_component_type         := 'AMB_ADR';
1675 l_component_code         := 'SYS_GAIN_CCID';
1676 l_component_type_code    := 'S';
1677 l_component_appl_id      :=  222;
1678 l_amb_context_code       := 'DEFAULT';
1679 x_transaction_coa_id     :=  null;
1680 x_accounting_coa_id      :=  null;
1681 --
1682 
1683  --
1684   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1685       trace
1686          (p_msg      => 'END of AcctDerRule_14'
1687          ,p_level    => C_LEVEL_PROCEDURE
1688          ,p_module   => l_log_module);
1689   END IF;
1690   x_value_type_code := 'S';
1691   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_11));
1692   RETURN l_output_value;
1693 
1694 --
1695 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1696       trace
1697          (p_msg      => 'END of AcctDerRule_14(invalid)'
1698          ,p_level    => C_LEVEL_PROCEDURE
1699          ,p_module   => l_log_module);
1700 END IF;
1701 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1702 x_value_type_code := null;
1703 l_output_value    := null;
1704 xla_accounting_err_pkg.build_message
1705                  (p_appli_s_name            => 'XLA'
1706                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1707                  ,p_token_1                 => 'COMPONENT_NAME'
1708                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1709                                                             l_component_type
1710                                                           , l_component_code
1711                                                           , l_component_type_code
1712                                                           , l_component_appl_id
1713                                                           , l_amb_context_code
1714                                                           )
1715                  ,p_token_2                 => 'OWNER'
1716                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1717                                                         'XLA_OWNER_TYPE'
1718                                                         ,l_component_type_code
1719                                                         )
1720                  ,p_token_3                 => 'PAD_NAME'
1721                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1722                  ,p_token_4                 => 'PAD_OWNER'
1723                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1724                                                         'XLA_OWNER_TYPE'
1725                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1726                                                         )
1727                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1728                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1729                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1730                  ,p_ae_header_id            => NULL
1731 );
1732 RETURN l_output_value;
1733 EXCEPTION
1734   WHEN xla_exceptions_pkg.application_exception THEN
1735       RAISE;
1736   WHEN OTHERS THEN
1737        xla_exceptions_pkg.raise_message
1738            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctDerRule_14');
1739 END AcctDerRule_14;
1740 --
1741 
1742 ---------------------------------------
1743 --
1744 -- PRIVATE FUNCTION
1745 --         AcctDerRule_15
1746 --
1747 ---------------------------------------
1748 FUNCTION AcctDerRule_15 (
1749   p_application_id              IN NUMBER
1750 , p_ae_header_id                IN NUMBER
1751 , p_side                        IN VARCHAR2 
1752 --System Loss Account
1753  , p_source_12            IN NUMBER
1754 , x_transaction_coa_id         OUT NOCOPY NUMBER
1755 , x_accounting_coa_id          OUT NOCOPY NUMBER
1756 , x_value_type_code            OUT NOCOPY VARCHAR2
1757 )
1758 RETURN NUMBER
1759 IS
1760 l_component_type       VARCHAR2(80)  ;
1761 l_component_code       VARCHAR2(30)  ;
1762 l_component_type_code  VARCHAR2(1)   ;
1763 l_component_appl_id    INTEGER       ;
1764 l_amb_context_code     VARCHAR2(30)  ;
1765 l_log_module           VARCHAR2(240) ;
1766 l_output_value         NUMBER        ;
1767 BEGIN
1768 IF g_log_enabled THEN
1769       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_15';
1770 END IF;
1771 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1772       trace
1773          (p_msg      => 'BEGIN of AcctDerRule_15'
1774          ,p_level    => C_LEVEL_PROCEDURE
1775          ,p_module   => l_log_module);
1776 END IF;
1777 --
1778 l_component_type         := 'AMB_ADR';
1779 l_component_code         := 'SYS_LOSS_CCID';
1780 l_component_type_code    := 'S';
1781 l_component_appl_id      :=  222;
1782 l_amb_context_code       := 'DEFAULT';
1783 x_transaction_coa_id     :=  null;
1784 x_accounting_coa_id      :=  null;
1785 --
1786 
1787  --
1788   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1789       trace
1790          (p_msg      => 'END of AcctDerRule_15'
1791          ,p_level    => C_LEVEL_PROCEDURE
1792          ,p_module   => l_log_module);
1793   END IF;
1794   x_value_type_code := 'S';
1795   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_12));
1796   RETURN l_output_value;
1797 
1798 --
1799 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1800       trace
1801          (p_msg      => 'END of AcctDerRule_15(invalid)'
1802          ,p_level    => C_LEVEL_PROCEDURE
1803          ,p_module   => l_log_module);
1804 END IF;
1805 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1806 x_value_type_code := null;
1807 l_output_value    := null;
1808 xla_accounting_err_pkg.build_message
1809                  (p_appli_s_name            => 'XLA'
1810                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1811                  ,p_token_1                 => 'COMPONENT_NAME'
1812                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1813                                                             l_component_type
1814                                                           , l_component_code
1815                                                           , l_component_type_code
1816                                                           , l_component_appl_id
1817                                                           , l_amb_context_code
1818                                                           )
1819                  ,p_token_2                 => 'OWNER'
1823                                                         )
1820                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1821                                                         'XLA_OWNER_TYPE'
1822                                                         ,l_component_type_code
1824                  ,p_token_3                 => 'PAD_NAME'
1825                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1826                  ,p_token_4                 => 'PAD_OWNER'
1827                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1828                                                         'XLA_OWNER_TYPE'
1829                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1830                                                         )
1831                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1832                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1833                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1834                  ,p_ae_header_id            => NULL
1835 );
1836 RETURN l_output_value;
1837 EXCEPTION
1838   WHEN xla_exceptions_pkg.application_exception THEN
1839       RAISE;
1840   WHEN OTHERS THEN
1841        xla_exceptions_pkg.raise_message
1842            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctDerRule_15');
1843 END AcctDerRule_15;
1844 --
1845 
1846 ---------------------------------------
1847 --
1848 -- PRIVATE FUNCTION
1849 --         AcctDerRule_16
1850 --
1851 ---------------------------------------
1852 FUNCTION AcctDerRule_16 (
1853   p_application_id              IN NUMBER
1854 , p_ae_header_id                IN NUMBER
1855 , p_side                        IN VARCHAR2 
1856 --Transaction Distribution GL Account
1857  , p_source_4            IN NUMBER
1858 , x_transaction_coa_id         OUT NOCOPY NUMBER
1859 , x_accounting_coa_id          OUT NOCOPY NUMBER
1860 , x_value_type_code            OUT NOCOPY VARCHAR2
1861 )
1862 RETURN NUMBER
1863 IS
1864 l_component_type       VARCHAR2(80)  ;
1865 l_component_code       VARCHAR2(30)  ;
1866 l_component_type_code  VARCHAR2(1)   ;
1867 l_component_appl_id    INTEGER       ;
1868 l_amb_context_code     VARCHAR2(30)  ;
1869 l_log_module           VARCHAR2(240) ;
1870 l_output_value         NUMBER        ;
1871 BEGIN
1872 IF g_log_enabled THEN
1873       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_16';
1874 END IF;
1875 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1876       trace
1877          (p_msg      => 'BEGIN of AcctDerRule_16'
1878          ,p_level    => C_LEVEL_PROCEDURE
1879          ,p_module   => l_log_module);
1880 END IF;
1881 --
1882 l_component_type         := 'AMB_ADR';
1883 l_component_code         := 'TRX_DIST_CCID';
1884 l_component_type_code    := 'S';
1885 l_component_appl_id      :=  222;
1886 l_amb_context_code       := 'DEFAULT';
1887 x_transaction_coa_id     :=  null;
1888 x_accounting_coa_id      :=  null;
1889 --
1890 
1891  --
1892   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1893       trace
1894          (p_msg      => 'END of AcctDerRule_16'
1895          ,p_level    => C_LEVEL_PROCEDURE
1896          ,p_module   => l_log_module);
1897   END IF;
1898   x_value_type_code := 'S';
1899   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_4));
1900   RETURN l_output_value;
1901 
1902 --
1903 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1904       trace
1905          (p_msg      => 'END of AcctDerRule_16(invalid)'
1906          ,p_level    => C_LEVEL_PROCEDURE
1907          ,p_module   => l_log_module);
1908 END IF;
1909 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
1910 x_value_type_code := null;
1911 l_output_value    := null;
1912 xla_accounting_err_pkg.build_message
1913                  (p_appli_s_name            => 'XLA'
1914                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
1915                  ,p_token_1                 => 'COMPONENT_NAME'
1916                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
1917                                                             l_component_type
1918                                                           , l_component_code
1919                                                           , l_component_type_code
1920                                                           , l_component_appl_id
1921                                                           , l_amb_context_code
1922                                                           )
1923                  ,p_token_2                 => 'OWNER'
1924                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
1925                                                         'XLA_OWNER_TYPE'
1926                                                         ,l_component_type_code
1927                                                         )
1928                  ,p_token_3                 => 'PAD_NAME'
1929                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
1930                  ,p_token_4                 => 'PAD_OWNER'
1931                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
1932                                                         'XLA_OWNER_TYPE'
1933                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
1934                                                         )
1935                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
1936                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
1937                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
1938                  ,p_ae_header_id            => NULL
1939 );
1940 RETURN l_output_value;
1941 EXCEPTION
1942   WHEN xla_exceptions_pkg.application_exception THEN
1943       RAISE;
1944   WHEN OTHERS THEN
1945        xla_exceptions_pkg.raise_message
1946            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctDerRule_16');
1947 END AcctDerRule_16;
1948 --
1949 
1950 ---------------------------------------
1951 --
1952 -- PRIVATE FUNCTION
1953 --         AcctLineType_17
1954 --
1955 ---------------------------------------
1956 PROCEDURE AcctLineType_17 (
1957   p_application_id        IN NUMBER
1958  ,p_event_id              IN NUMBER
1959  ,p_calculate_acctd_flag  IN VARCHAR2
1960  ,p_calculate_g_l_flag    IN VARCHAR2
1961  ,p_actual_flag           IN OUT VARCHAR2
1962  ,p_balance_type_code     OUT VARCHAR2
1963  ,p_gain_or_loss_ref      OUT VARCHAR2
1964  
1965 --Distribution GL Account
1966  , p_source_3            IN NUMBER
1967 --Distribution Source Type
1968  , p_source_13            IN VARCHAR2
1969 --Receivable Activity Type
1970  , p_source_14            IN VARCHAR2
1971 --Distribution Line Identifier
1972  , p_source_15            IN NUMBER
1973 --Distribution Type
1974  , p_source_16            IN VARCHAR2
1975 --Entered Amount
1976  , p_source_17            IN NUMBER
1977 --Currency Code
1978  , p_source_18            IN VARCHAR2
1979 --Exchange Date
1980  , p_source_19            IN DATE
1981 --Exchange Rate
1982  , p_source_20            IN NUMBER
1983 --Exchange Rate Type
1984  , p_source_21            IN VARCHAR2
1985 --Applied To Document Accounting Amount
1986  , p_source_22            IN NUMBER
1987 --Bill To Customer Account Identifier
1988  , p_source_23            IN NUMBER
1989 --Bill To Customer Site Use Identifier
1990  , p_source_24            IN NUMBER
1991 --SLA Party Type
1992  , p_source_25            IN VARCHAR2
1993 )
1994 IS
1995 
1996 l_component_type              VARCHAR2(80);
1997 l_component_code              VARCHAR2(30);
1998 l_component_type_code         VARCHAR2(1);
1999 l_component_appl_id           INTEGER;
2000 l_amb_context_code            VARCHAR2(30);
2001 l_entity_code                 VARCHAR2(30);
2002 l_event_class_code            VARCHAR2(30);
2003 l_ae_header_id                NUMBER;
2004 l_event_type_code             VARCHAR2(30);
2005 l_line_definition_code        VARCHAR2(30);
2006 l_line_definition_owner_code  VARCHAR2(1);
2007 --
2008 -- adr variables
2009 l_segment                     VARCHAR2(30);
2010 l_ccid                        NUMBER;
2011 l_adr_transaction_coa_id      NUMBER;
2012 l_adr_accounting_coa_id       NUMBER;
2013 l_adr_flexfield_segment_code  VARCHAR2(30);
2014 l_adr_flex_value_set_id       NUMBER;
2015 l_adr_value_type_code         VARCHAR2(30);
2016 l_adr_value_combination_id    NUMBER;
2017 l_adr_value_segment_code      VARCHAR2(30);
2018 
2019 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
2020 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
2021 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
2022 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
2023 
2024 -- 4262811 Variables ------------------------------------------------------------------------------------------
2025 l_entered_amt_idx             NUMBER;
2026 l_accted_amt_idx              NUMBER;
2027 l_acc_rev_flag                VARCHAR2(1);
2028 l_accrual_line_num            NUMBER;
2029 l_tmp_amt                     NUMBER;
2030 l_acc_rev_natural_side_code   VARCHAR2(1);
2031 
2032 l_num_entries                 NUMBER;
2033 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
2034 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
2035 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
2036 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
2037 l_recog_line_1                NUMBER;
2038 l_recog_line_2                NUMBER;
2039 
2040 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
2041 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
2042 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
2043 
2044 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
2045 
2046 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
2047 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
2048 
2049 ---------------------------------------------------------------------------------------------------------------
2050 
2051 
2052 --
2053 -- bulk performance
2054 --
2055 l_balance_type_code           VARCHAR2(1);
2056 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
2057 l_log_module                  VARCHAR2(240);
2058 
2059 --
2060 -- Upgrade strategy
2061 --
2062 l_actual_upg_option           VARCHAR2(1);
2063 l_enc_upg_option           VARCHAR2(1);
2064 
2065 --
2066 BEGIN
2067 --
2068 IF g_log_enabled THEN
2069       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_17';
2070 END IF;
2071 --
2072 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2073 
2074       trace
2075          (p_msg      => 'BEGIN of AcctLineType_17'
2076          ,p_level    => C_LEVEL_PROCEDURE
2077          ,p_module   => l_log_module);
2078 
2079 END IF;
2080 --
2081 l_component_type             := 'AMB_JLT';
2082 l_component_code             := 'ADJ';
2083 l_component_type_code        := 'S';
2084 l_component_appl_id          :=  222;
2085 l_amb_context_code           := 'DEFAULT';
2086 l_entity_code                := 'ADJUSTMENTS';
2087 l_event_class_code           := 'ADJUSTMENT';
2088 l_event_type_code            := 'ADJUSTMENT_ALL';
2089 l_line_definition_owner_code := 'S';
2090 l_line_definition_code       := 'MFAR_ADJ_ACCRUAL_BALANCING';
2091 --
2092 l_balance_type_code          := 'A';
2093 l_segment                     := NULL;
2094 l_ccid                        := NULL;
2095 l_adr_transaction_coa_id      := NULL;
2096 l_adr_accounting_coa_id       := NULL;
2097 l_adr_flexfield_segment_code  := NULL;
2098 l_adr_flex_value_set_id       := NULL;
2099 l_adr_value_type_code         := NULL;
2100 l_adr_value_combination_id    := NULL;
2101 l_adr_value_segment_code      := NULL;
2102 
2103 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
2104 l_bflow_class_code           := '';    -- 4219869 Business Flow
2105 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
2106 l_budgetary_control_flag     := 'N';
2107 
2108 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
2109 l_bflow_applied_to_amt       := NULL; -- 5132302
2110 l_entered_amt_idx            := NULL;          -- 4262811
2111 l_accted_amt_idx             := NULL;          -- 4262811
2112 l_acc_rev_flag               := NULL;          -- 4262811
2113 l_accrual_line_num           := NULL;          -- 4262811
2114 l_tmp_amt                    := NULL;          -- 4262811
2115 --
2116  
2117 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
2118     l_balance_type_code <> 'B' THEN
2119 IF NVL(p_source_13,'
2120 ') =  'ADJ' AND 
2121 NVL(p_source_14,'
2122 ') <>  'ENDORSEMENT'
2123  THEN 
2124 
2125    --
2126    XLA_AE_LINES_PKG.SetNewLine;
2127 
2128    p_balance_type_code          := l_balance_type_code;
2129    -- set the flag so later we will know whether the gain loss line needs to be created
2130    
2131    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
2132      p_actual_flag :='A';
2133    END IF;
2134 
2135    --
2136    -- bulk performance
2137    --
2138    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
2139                                       p_header_num   => 0); -- 4262811
2140    --
2141    -- set accounting line options
2142    --
2143    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
2144            p_natural_side_code          => 'C'
2145          , p_gain_or_loss_flag          => 'N'
2146          , p_gl_transfer_mode_code      => 'S'
2147          , p_acct_entry_type_code       => 'A'
2148          , p_switch_side_flag           => 'Y'
2149          , p_merge_duplicate_code       => 'A'
2150          );
2151    --
2152    l_acc_rev_natural_side_code := 'D';  -- 4262811
2153    -- 
2154    --
2155    -- set accounting line type info
2156    --
2157    xla_ae_lines_pkg.SetAcctLineType
2158       (p_component_type             => l_component_type
2159       ,p_event_type_code            => l_event_type_code
2160       ,p_line_definition_owner_code => l_line_definition_owner_code
2161       ,p_line_definition_code       => l_line_definition_code
2162       ,p_accounting_line_code       => l_component_code
2163       ,p_accounting_line_type_code  => l_component_type_code
2164       ,p_accounting_line_appl_id    => l_component_appl_id
2165       ,p_amb_context_code           => l_amb_context_code
2166       ,p_entity_code                => l_entity_code
2167       ,p_event_class_code           => l_event_class_code);
2168    --
2169    -- set accounting class
2170    --
2171    xla_ae_lines_pkg.SetAcctClass(
2172            p_accounting_class_code  => 'ADJ'
2173          , p_ae_header_id           => l_ae_header_id
2174          );
2175 
2176    --
2177    -- set rounding class
2178    --
2179    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
2180                       'RECEIVABLE';
2181 
2182    --
2183    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
2184    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
2185    --
2186    -- bulk performance
2187    --
2188    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
2189 
2190    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
2191       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
2192 
2193    -- 4955764
2194    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2195       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
2196 
2197    -- 4458381 Public Sector Enh
2198    
2199    --
2200    -- set accounting attributes for the line type
2201    --
2202    l_entered_amt_idx := 3;
2203    l_accted_amt_idx  := 8;
2204    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
2205    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
2206    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
2207    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
2208    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
2209    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
2210    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
2211    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
2212    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
2213    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
2214    l_rec_acct_attrs.array_date_value(5)  := p_source_19;
2215    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
2216    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
2217    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
2218    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
2219    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
2220    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
2221    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
2222    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
2223    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
2224    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
2225    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
2226    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
2227 
2228    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
2229    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
2230 
2231    ---------------------------------------------------------------------------------------------------------------
2232    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
2233    ---------------------------------------------------------------------------------------------------------------
2234    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
2235 
2236    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2237    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2238 
2239    IF xla_accounting_cache_pkg.GetValueChar
2240          (p_source_code         => 'LEDGER_CATEGORY_CODE'
2241          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
2242    AND l_bflow_method_code = 'PRIOR_ENTRY'
2243 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
2244    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
2245          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
2246        )
2247    THEN
2248          xla_ae_lines_pkg.BflowUpgEntry
2249            (p_business_method_code    => l_bflow_method_code
2250            ,p_business_class_code     => l_bflow_class_code
2251            ,p_balance_type            => l_balance_type_code);
2252    ELSE
2253       NULL;
2254 -- No business flow processing for business flow method of NONE.
2255    END IF;
2256 
2257    --
2258    -- call analytical criteria
2259    --
2260    
2261    --
2262    -- call description
2263    --
2264    -- No description or it is inherited.
2265    --
2266    -- call ADRs
2267    -- Bug 4922099
2268    --
2269    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
2270         (NVL(l_actual_upg_option, 'N') = 'O') OR
2271         (NVL(l_enc_upg_option, 'N') = 'O')
2272       )
2273    THEN
2274    NULL;
2275    --
2276    --
2277    
2278   l_ccid := AcctDerRule_7(
2279            p_application_id           => p_application_id
2280          , p_ae_header_id             => l_ae_header_id 
2281 , p_source_3 => p_source_3
2282          , x_transaction_coa_id       => l_adr_transaction_coa_id
2283          , x_accounting_coa_id        => l_adr_accounting_coa_id
2284          , x_value_type_code          => l_adr_value_type_code
2285          , p_side                     => 'NA'
2286    );
2287 
2288    xla_ae_lines_pkg.set_ccid(
2289     p_code_combination_id          => l_ccid
2290   , p_value_type_code              => l_adr_value_type_code
2291   , p_transaction_coa_id           => l_adr_transaction_coa_id
2292   , p_accounting_coa_id            => l_adr_accounting_coa_id
2293   , p_adr_code                     => 'DIST_CCID'
2294   , p_adr_type_code                => 'S'
2295   , p_component_type               => l_component_type
2296   , p_component_code               => l_component_code
2297   , p_component_type_code          => l_component_type_code
2298   , p_component_appl_id            => l_component_appl_id
2299   , p_amb_context_code             => l_amb_context_code
2300   , p_side                         => 'NA'
2301   );
2302 
2303 
2304    --
2305    --
2306    END IF;
2307    --
2308    -- Bug 4922099
2309    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
2310           (NVL(l_enc_upg_option, 'N') = 'O')
2311         ) AND
2312         (l_bflow_method_code = 'PRIOR_ENTRY')
2313       )
2314    THEN
2315       IF
2316       --
2317       1 = 2
2318       --
2319       THEN
2320       xla_accounting_err_pkg.build_message
2321                                     (p_appli_s_name            => 'XLA'
2322                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2323                                     ,p_token_1                 => 'LINE_NUMBER'
2324                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
2325                                     ,p_token_2                 => 'LINE_TYPE_NAME'
2326                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
2327                                                                              l_component_type
2328                                                                             ,l_component_code
2329                                                                             ,l_component_type_code
2330                                                                             ,l_component_appl_id
2331                                                                             ,l_amb_context_code
2332                                                                             ,l_entity_code
2333                                                                             ,l_event_class_code
2334                                                                            )
2335                                     ,p_token_3                 => 'OWNER'
2336                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
2337                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
2338                                                                           ,p_lookup_code    => l_component_type_code
2339                                                                          )
2340                                     ,p_token_4                 => 'PRODUCT_NAME'
2341                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
2342                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
2343                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
2344                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
2345                                     ,p_ae_header_id            =>  NULL
2346                                        );
2347 
2348         IF (C_LEVEL_ERROR>= g_log_level) THEN
2349                  trace
2350                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2351                       ,p_level    => C_LEVEL_ERROR
2352                       ,p_module   => l_log_module);
2353         END IF;
2354       END IF;
2355    END IF;
2356    --
2357    --
2358    ------------------------------------------------------------------------------------------------
2359    -- 4219869 Business Flow
2360    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
2361    -- Prior Entry.  Currently, the following code is always generated.
2362    ------------------------------------------------------------------------------------------------
2363    XLA_AE_LINES_PKG.ValidateCurrentLine;
2364 
2365    ------------------------------------------------------------------------------------
2366    -- 4219869 Business Flow
2367    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
2368    ------------------------------------------------------------------------------------
2369    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2370 
2371    ----------------------------------------------------------------------------------
2372    -- 4219869 Business Flow
2373    -- Update journal entry status -- Need to generate this within IF <condition>
2374    ----------------------------------------------------------------------------------
2375    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2376          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
2377          ,p_balance_type_code => l_balance_type_code
2378          );
2379 
2380    -------------------------------------------------------------------------------------------
2381    -- 4262811 - Generate the Accrual Reversal lines
2382    -------------------------------------------------------------------------------------------
2383    BEGIN
2384       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
2385                               (g_array_event(p_event_id).array_value_num('header_index'));
2386       IF l_acc_rev_flag IS NULL THEN
2387          l_acc_rev_flag := 'N';
2388       END IF;
2389    EXCEPTION
2390       WHEN OTHERS THEN
2391          l_acc_rev_flag := 'N';
2392    END;
2393    --
2394    IF (l_acc_rev_flag = 'Y') THEN
2395 
2396        -- 4645092  ------------------------------------------------------------------------------
2397        -- To allow MPA report to determine if it should generate report process
2398        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
2399        ------------------------------------------------------------------------------------------
2400 
2401        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
2402        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
2403    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
2404    -- call ADRs
2405    -- Bug 4922099
2406    --
2407    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
2408         (NVL(l_actual_upg_option, 'N') = 'O') OR
2409         (NVL(l_enc_upg_option, 'N') = 'O')
2410       )
2411    THEN
2412    NULL;
2413    --
2414    --
2415    
2416   l_ccid := AcctDerRule_7(
2417            p_application_id           => p_application_id
2418          , p_ae_header_id             => l_ae_header_id 
2419 , p_source_3 => p_source_3
2420          , x_transaction_coa_id       => l_adr_transaction_coa_id
2421          , x_accounting_coa_id        => l_adr_accounting_coa_id
2422          , x_value_type_code          => l_adr_value_type_code
2423          , p_side                     => 'NA'
2424    );
2425 
2426    xla_ae_lines_pkg.set_ccid(
2427     p_code_combination_id          => l_ccid
2428   , p_value_type_code              => l_adr_value_type_code
2429   , p_transaction_coa_id           => l_adr_transaction_coa_id
2430   , p_accounting_coa_id            => l_adr_accounting_coa_id
2431   , p_adr_code                     => 'DIST_CCID'
2432   , p_adr_type_code                => 'S'
2433   , p_component_type               => l_component_type
2434   , p_component_code               => l_component_code
2435   , p_component_type_code          => l_component_type_code
2436   , p_component_appl_id            => l_component_appl_id
2437   , p_amb_context_code             => l_amb_context_code
2438   , p_side                         => 'NA'
2439   );
2440 
2441 
2442    --
2443    --
2444    END IF;
2445 
2446        --
2447        -- Update the line information that should be overwritten
2448        --
2449        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
2450                                          p_header_num   => 1);
2451        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
2452 
2453        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
2454 
2455        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
2456           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
2457        END IF;
2458 
2459       --
2460       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
2461       --
2462       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
2463           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
2464       ELSE
2465           ---------------------------------------------------------------------------------------------------
2466           -- 4262811a Switch Sign
2467           ---------------------------------------------------------------------------------------------------
2468           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
2469           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2470                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2471           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2472                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2473           -- 5132302
2474           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
2475                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2476 
2477       END IF;
2478 
2479       -- 4955764
2480       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2481       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
2482 
2483 
2484       XLA_AE_LINES_PKG.ValidateCurrentLine;
2485       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2486 
2487       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2488                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
2489                ,p_balance_type_code => l_balance_type_code);
2490 
2491    END IF;
2492 
2493    -----------------------------------------------------------------------------------------
2494    -- 4262811 Multiperiod Accounting
2495    -----------------------------------------------------------------------------------------
2496      -- No MPA option is assigned.
2497 
2498 
2499 END IF;
2500 END IF;
2501 --
2502 
2503 --
2504 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2505    trace
2506       (p_msg      => 'END of AcctLineType_17'
2507       ,p_level    => C_LEVEL_PROCEDURE
2508       ,p_module   => l_log_module);
2509 END IF;
2510 --
2511 EXCEPTION
2512   WHEN xla_exceptions_pkg.application_exception THEN
2513       RAISE;
2514   WHEN OTHERS THEN
2515        xla_exceptions_pkg.raise_message
2516            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_17');
2517 END AcctLineType_17;
2518 --
2519 
2520 ---------------------------------------
2521 --
2522 -- PRIVATE FUNCTION
2523 --         AcctLineType_18
2524 --
2525 ---------------------------------------
2526 PROCEDURE AcctLineType_18 (
2527   p_application_id        IN NUMBER
2528  ,p_event_id              IN NUMBER
2529  ,p_calculate_acctd_flag  IN VARCHAR2
2530  ,p_calculate_g_l_flag    IN VARCHAR2
2531  ,p_actual_flag           IN OUT VARCHAR2
2532  ,p_balance_type_code     OUT VARCHAR2
2533  ,p_gain_or_loss_ref      OUT VARCHAR2
2534  
2535 --Distribution GL Account
2536  , p_source_3            IN NUMBER
2537 --Distribution Source Type
2538  , p_source_13            IN VARCHAR2
2539 --Receivable Activity Type
2540  , p_source_14            IN VARCHAR2
2541 --Distribution Line Identifier
2542  , p_source_15            IN NUMBER
2543 --Distribution Type
2544  , p_source_16            IN VARCHAR2
2545 --Entered Amount
2546  , p_source_17            IN NUMBER
2547 --Currency Code
2548  , p_source_18            IN VARCHAR2
2549 --Exchange Date
2550  , p_source_19            IN DATE
2551 --Exchange Rate
2552  , p_source_20            IN NUMBER
2553 --Exchange Rate Type
2554  , p_source_21            IN VARCHAR2
2555 --Applied To Document Accounting Amount
2556  , p_source_22            IN NUMBER
2557 --Bill To Customer Account Identifier
2558  , p_source_23            IN NUMBER
2559 --Bill To Customer Site Use Identifier
2560  , p_source_24            IN NUMBER
2561 --SLA Party Type
2562  , p_source_25            IN VARCHAR2
2563 )
2564 IS
2565 
2566 l_component_type              VARCHAR2(80);
2567 l_component_code              VARCHAR2(30);
2568 l_component_type_code         VARCHAR2(1);
2569 l_component_appl_id           INTEGER;
2570 l_amb_context_code            VARCHAR2(30);
2571 l_entity_code                 VARCHAR2(30);
2572 l_event_class_code            VARCHAR2(30);
2573 l_ae_header_id                NUMBER;
2574 l_event_type_code             VARCHAR2(30);
2575 l_line_definition_code        VARCHAR2(30);
2576 l_line_definition_owner_code  VARCHAR2(1);
2577 --
2578 -- adr variables
2579 l_segment                     VARCHAR2(30);
2580 l_ccid                        NUMBER;
2581 l_adr_transaction_coa_id      NUMBER;
2582 l_adr_accounting_coa_id       NUMBER;
2583 l_adr_flexfield_segment_code  VARCHAR2(30);
2584 l_adr_flex_value_set_id       NUMBER;
2585 l_adr_value_type_code         VARCHAR2(30);
2586 l_adr_value_combination_id    NUMBER;
2587 l_adr_value_segment_code      VARCHAR2(30);
2588 
2589 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
2590 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
2591 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
2592 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
2593 
2594 -- 4262811 Variables ------------------------------------------------------------------------------------------
2595 l_entered_amt_idx             NUMBER;
2596 l_accted_amt_idx              NUMBER;
2597 l_acc_rev_flag                VARCHAR2(1);
2598 l_accrual_line_num            NUMBER;
2599 l_tmp_amt                     NUMBER;
2600 l_acc_rev_natural_side_code   VARCHAR2(1);
2601 
2602 l_num_entries                 NUMBER;
2603 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
2604 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
2605 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
2606 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
2607 l_recog_line_1                NUMBER;
2608 l_recog_line_2                NUMBER;
2609 
2610 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
2611 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
2612 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
2613 
2614 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
2615 
2616 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
2617 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
2621 
2618 
2619 ---------------------------------------------------------------------------------------------------------------
2620 
2622 --
2623 -- bulk performance
2624 --
2625 l_balance_type_code           VARCHAR2(1);
2626 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
2627 l_log_module                  VARCHAR2(240);
2628 
2629 --
2630 -- Upgrade strategy
2631 --
2632 l_actual_upg_option           VARCHAR2(1);
2633 l_enc_upg_option           VARCHAR2(1);
2634 
2635 --
2636 BEGIN
2637 --
2638 IF g_log_enabled THEN
2639       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_18';
2640 END IF;
2641 --
2642 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2643 
2644       trace
2645          (p_msg      => 'BEGIN of AcctLineType_18'
2646          ,p_level    => C_LEVEL_PROCEDURE
2647          ,p_module   => l_log_module);
2648 
2649 END IF;
2650 --
2651 l_component_type             := 'AMB_JLT';
2652 l_component_code             := 'ADJ_BR_ENDORSE';
2653 l_component_type_code        := 'S';
2654 l_component_appl_id          :=  222;
2655 l_amb_context_code           := 'DEFAULT';
2656 l_entity_code                := 'ADJUSTMENTS';
2657 l_event_class_code           := 'ADJUSTMENT';
2658 l_event_type_code            := 'ADJUSTMENT_ALL';
2659 l_line_definition_owner_code := 'S';
2660 l_line_definition_code       := 'MFAR_ADJ_ACCRUAL_BALANCING';
2661 --
2662 l_balance_type_code          := 'A';
2663 l_segment                     := NULL;
2664 l_ccid                        := NULL;
2665 l_adr_transaction_coa_id      := NULL;
2666 l_adr_accounting_coa_id       := NULL;
2667 l_adr_flexfield_segment_code  := NULL;
2668 l_adr_flex_value_set_id       := NULL;
2669 l_adr_value_type_code         := NULL;
2670 l_adr_value_combination_id    := NULL;
2671 l_adr_value_segment_code      := NULL;
2672 
2673 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
2674 l_bflow_class_code           := '';    -- 4219869 Business Flow
2675 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
2676 l_budgetary_control_flag     := 'N';
2677 
2678 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
2679 l_bflow_applied_to_amt       := NULL; -- 5132302
2680 l_entered_amt_idx            := NULL;          -- 4262811
2681 l_accted_amt_idx             := NULL;          -- 4262811
2682 l_acc_rev_flag               := NULL;          -- 4262811
2683 l_accrual_line_num           := NULL;          -- 4262811
2684 l_tmp_amt                    := NULL;          -- 4262811
2685 --
2686  
2687 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
2688     l_balance_type_code <> 'B' THEN
2689 IF NVL(p_source_13,'
2690 ') =  'ADJ' AND 
2691 NVL(p_source_14,'
2692 ') =  'ENDORSEMENT'
2693  THEN 
2694 
2695    --
2696    XLA_AE_LINES_PKG.SetNewLine;
2697 
2698    p_balance_type_code          := l_balance_type_code;
2699    -- set the flag so later we will know whether the gain loss line needs to be created
2700    
2701    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
2702      p_actual_flag :='A';
2703    END IF;
2704 
2705    --
2706    -- bulk performance
2707    --
2708    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
2709                                       p_header_num   => 0); -- 4262811
2710    --
2711    -- set accounting line options
2712    --
2713    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
2714            p_natural_side_code          => 'C'
2715          , p_gain_or_loss_flag          => 'N'
2716          , p_gl_transfer_mode_code      => 'S'
2717          , p_acct_entry_type_code       => 'A'
2718          , p_switch_side_flag           => 'Y'
2719          , p_merge_duplicate_code       => 'A'
2720          );
2721    --
2722    l_acc_rev_natural_side_code := 'D';  -- 4262811
2723    -- 
2724    --
2725    -- set accounting line type info
2726    --
2727    xla_ae_lines_pkg.SetAcctLineType
2728       (p_component_type             => l_component_type
2729       ,p_event_type_code            => l_event_type_code
2730       ,p_line_definition_owner_code => l_line_definition_owner_code
2731       ,p_line_definition_code       => l_line_definition_code
2732       ,p_accounting_line_code       => l_component_code
2733       ,p_accounting_line_type_code  => l_component_type_code
2734       ,p_accounting_line_appl_id    => l_component_appl_id
2735       ,p_amb_context_code           => l_amb_context_code
2736       ,p_entity_code                => l_entity_code
2737       ,p_event_class_code           => l_event_class_code);
2738    --
2739    -- set accounting class
2740    --
2741    xla_ae_lines_pkg.SetAcctClass(
2742            p_accounting_class_code  => 'ENDORSEMENT'
2743          , p_ae_header_id           => l_ae_header_id
2744          );
2745 
2746    --
2747    -- set rounding class
2748    --
2749    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
2750                       'RECEIVABLE';
2751 
2752    --
2753    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
2754    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
2755    --
2756    -- bulk performance
2757    --
2758    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
2759 
2760    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
2761       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
2762 
2763    -- 4955764
2764    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2765       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
2766 
2767    -- 4458381 Public Sector Enh
2768    
2769    --
2770    -- set accounting attributes for the line type
2771    --
2772    l_entered_amt_idx := 3;
2773    l_accted_amt_idx  := 8;
2774    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
2775    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
2776    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
2777    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
2778    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
2779    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
2780    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
2781    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
2782    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
2783    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
2784    l_rec_acct_attrs.array_date_value(5)  := p_source_19;
2785    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
2786    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
2787    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
2788    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
2789    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
2790    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
2791    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
2792    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
2793    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
2794    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
2795    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
2796    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
2797 
2798    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
2799    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
2800 
2801    ---------------------------------------------------------------------------------------------------------------
2802    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
2803    ---------------------------------------------------------------------------------------------------------------
2804    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
2805 
2806    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2807    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2808 
2809    IF xla_accounting_cache_pkg.GetValueChar
2810          (p_source_code         => 'LEDGER_CATEGORY_CODE'
2811          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
2812    AND l_bflow_method_code = 'PRIOR_ENTRY'
2813 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
2814    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
2815          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
2816        )
2817    THEN
2818          xla_ae_lines_pkg.BflowUpgEntry
2819            (p_business_method_code    => l_bflow_method_code
2820            ,p_business_class_code     => l_bflow_class_code
2821            ,p_balance_type            => l_balance_type_code);
2822    ELSE
2823       NULL;
2824 -- No business flow processing for business flow method of NONE.
2825    END IF;
2826 
2827    --
2828    -- call analytical criteria
2829    --
2830    
2831    --
2832    -- call description
2833    --
2834    -- No description or it is inherited.
2835    --
2836    -- call ADRs
2837    -- Bug 4922099
2838    --
2839    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
2840         (NVL(l_actual_upg_option, 'N') = 'O') OR
2841         (NVL(l_enc_upg_option, 'N') = 'O')
2842       )
2843    THEN
2844    NULL;
2845    --
2846    --
2847    
2848   l_ccid := AcctDerRule_7(
2849            p_application_id           => p_application_id
2850          , p_ae_header_id             => l_ae_header_id 
2851 , p_source_3 => p_source_3
2852          , x_transaction_coa_id       => l_adr_transaction_coa_id
2853          , x_accounting_coa_id        => l_adr_accounting_coa_id
2854          , x_value_type_code          => l_adr_value_type_code
2855          , p_side                     => 'NA'
2856    );
2857 
2858    xla_ae_lines_pkg.set_ccid(
2859     p_code_combination_id          => l_ccid
2860   , p_value_type_code              => l_adr_value_type_code
2861   , p_transaction_coa_id           => l_adr_transaction_coa_id
2862   , p_accounting_coa_id            => l_adr_accounting_coa_id
2863   , p_adr_code                     => 'DIST_CCID'
2864   , p_adr_type_code                => 'S'
2865   , p_component_type               => l_component_type
2866   , p_component_code               => l_component_code
2867   , p_component_type_code          => l_component_type_code
2868   , p_component_appl_id            => l_component_appl_id
2869   , p_amb_context_code             => l_amb_context_code
2870   , p_side                         => 'NA'
2871   );
2872 
2873 
2874    --
2875    --
2876    END IF;
2877    --
2878    -- Bug 4922099
2879    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
2880           (NVL(l_enc_upg_option, 'N') = 'O')
2881         ) AND
2882         (l_bflow_method_code = 'PRIOR_ENTRY')
2883       )
2884    THEN
2885       IF
2886       --
2887       1 = 2
2888       --
2889       THEN
2890       xla_accounting_err_pkg.build_message
2891                                     (p_appli_s_name            => 'XLA'
2892                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2893                                     ,p_token_1                 => 'LINE_NUMBER'
2894                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
2895                                     ,p_token_2                 => 'LINE_TYPE_NAME'
2896                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
2897                                                                              l_component_type
2898                                                                             ,l_component_code
2899                                                                             ,l_component_type_code
2900                                                                             ,l_component_appl_id
2901                                                                             ,l_amb_context_code
2902                                                                             ,l_entity_code
2903                                                                             ,l_event_class_code
2904                                                                            )
2905                                     ,p_token_3                 => 'OWNER'
2906                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
2907                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
2908                                                                           ,p_lookup_code    => l_component_type_code
2909                                                                          )
2910                                     ,p_token_4                 => 'PRODUCT_NAME'
2911                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
2912                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
2913                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
2914                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
2915                                     ,p_ae_header_id            =>  NULL
2916                                        );
2917 
2918         IF (C_LEVEL_ERROR>= g_log_level) THEN
2919                  trace
2920                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2921                       ,p_level    => C_LEVEL_ERROR
2922                       ,p_module   => l_log_module);
2923         END IF;
2924       END IF;
2925    END IF;
2926    --
2927    --
2928    ------------------------------------------------------------------------------------------------
2929    -- 4219869 Business Flow
2930    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
2931    -- Prior Entry.  Currently, the following code is always generated.
2932    ------------------------------------------------------------------------------------------------
2933    XLA_AE_LINES_PKG.ValidateCurrentLine;
2934 
2935    ------------------------------------------------------------------------------------
2936    -- 4219869 Business Flow
2937    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
2938    ------------------------------------------------------------------------------------
2939    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2940 
2941    ----------------------------------------------------------------------------------
2942    -- 4219869 Business Flow
2943    -- Update journal entry status -- Need to generate this within IF <condition>
2944    ----------------------------------------------------------------------------------
2945    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2946          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
2947          ,p_balance_type_code => l_balance_type_code
2948          );
2949 
2950    -------------------------------------------------------------------------------------------
2951    -- 4262811 - Generate the Accrual Reversal lines
2952    -------------------------------------------------------------------------------------------
2953    BEGIN
2954       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
2955                               (g_array_event(p_event_id).array_value_num('header_index'));
2956       IF l_acc_rev_flag IS NULL THEN
2957          l_acc_rev_flag := 'N';
2958       END IF;
2959    EXCEPTION
2960       WHEN OTHERS THEN
2961          l_acc_rev_flag := 'N';
2962    END;
2963    --
2964    IF (l_acc_rev_flag = 'Y') THEN
2965 
2966        -- 4645092  ------------------------------------------------------------------------------
2967        -- To allow MPA report to determine if it should generate report process
2968        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
2969        ------------------------------------------------------------------------------------------
2970 
2971        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
2972        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
2973    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
2974    -- call ADRs
2975    -- Bug 4922099
2976    --
2977    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
2978         (NVL(l_actual_upg_option, 'N') = 'O') OR
2979         (NVL(l_enc_upg_option, 'N') = 'O')
2980       )
2981    THEN
2982    NULL;
2983    --
2984    --
2985    
2986   l_ccid := AcctDerRule_7(
2987            p_application_id           => p_application_id
2988          , p_ae_header_id             => l_ae_header_id 
2989 , p_source_3 => p_source_3
2990          , x_transaction_coa_id       => l_adr_transaction_coa_id
2991          , x_accounting_coa_id        => l_adr_accounting_coa_id
2992          , x_value_type_code          => l_adr_value_type_code
2993          , p_side                     => 'NA'
2994    );
2995 
2996    xla_ae_lines_pkg.set_ccid(
2997     p_code_combination_id          => l_ccid
2998   , p_value_type_code              => l_adr_value_type_code
2999   , p_transaction_coa_id           => l_adr_transaction_coa_id
3000   , p_accounting_coa_id            => l_adr_accounting_coa_id
3001   , p_adr_code                     => 'DIST_CCID'
3002   , p_adr_type_code                => 'S'
3003   , p_component_type               => l_component_type
3004   , p_component_code               => l_component_code
3005   , p_component_type_code          => l_component_type_code
3006   , p_component_appl_id            => l_component_appl_id
3007   , p_amb_context_code             => l_amb_context_code
3008   , p_side                         => 'NA'
3009   );
3010 
3011 
3012    --
3013    --
3014    END IF;
3015 
3016        --
3017        -- Update the line information that should be overwritten
3018        --
3019        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
3020                                          p_header_num   => 1);
3021        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
3022 
3023        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
3024 
3025        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
3026           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
3027        END IF;
3028 
3029       --
3030       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
3031       --
3032       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
3033           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
3034       ELSE
3035           ---------------------------------------------------------------------------------------------------
3036           -- 4262811a Switch Sign
3037           ---------------------------------------------------------------------------------------------------
3038           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
3039           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3040                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3041           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3042                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3043           -- 5132302
3044           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
3045                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3046 
3047       END IF;
3048 
3049       -- 4955764
3050       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3051       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
3052 
3053 
3054       XLA_AE_LINES_PKG.ValidateCurrentLine;
3055       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3056 
3057       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3058                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
3059                ,p_balance_type_code => l_balance_type_code);
3060 
3061    END IF;
3062 
3063    -----------------------------------------------------------------------------------------
3064    -- 4262811 Multiperiod Accounting
3065    -----------------------------------------------------------------------------------------
3066      -- No MPA option is assigned.
3067 
3068 
3069 END IF;
3070 END IF;
3071 --
3072 
3073 --
3074 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3075    trace
3076       (p_msg      => 'END of AcctLineType_18'
3077       ,p_level    => C_LEVEL_PROCEDURE
3078       ,p_module   => l_log_module);
3079 END IF;
3080 --
3081 EXCEPTION
3082   WHEN xla_exceptions_pkg.application_exception THEN
3083       RAISE;
3084   WHEN OTHERS THEN
3085        xla_exceptions_pkg.raise_message
3086            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_18');
3087 END AcctLineType_18;
3088 --
3089 
3090 ---------------------------------------
3091 --
3092 -- PRIVATE FUNCTION
3093 --         AcctLineType_19
3094 --
3095 ---------------------------------------
3096 PROCEDURE AcctLineType_19 (
3097   p_application_id        IN NUMBER
3098  ,p_event_id              IN NUMBER
3099  ,p_calculate_acctd_flag  IN VARCHAR2
3100  ,p_calculate_g_l_flag    IN VARCHAR2
3101  ,p_actual_flag           IN OUT VARCHAR2
3102  ,p_balance_type_code     OUT VARCHAR2
3103  ,p_gain_or_loss_ref      OUT VARCHAR2
3104  
3105 --Distribution GL Account
3106  , p_source_3            IN NUMBER
3107 --Distribution Source Type
3108  , p_source_13            IN VARCHAR2
3109 --Distribution Line Identifier
3110  , p_source_15            IN NUMBER
3111 --Distribution Type
3112  , p_source_16            IN VARCHAR2
3113 --Entered Amount
3114  , p_source_17            IN NUMBER
3115 --Currency Code
3116  , p_source_18            IN VARCHAR2
3117 --Exchange Date
3118  , p_source_19            IN DATE
3119 --Exchange Rate
3120  , p_source_20            IN NUMBER
3121 --Exchange Rate Type
3122  , p_source_21            IN VARCHAR2
3123 --Applied To Document Accounting Amount
3124  , p_source_22            IN NUMBER
3125 --Bill To Customer Account Identifier
3126  , p_source_23            IN NUMBER
3127 --Bill To Customer Site Use Identifier
3128  , p_source_24            IN NUMBER
3129 --SLA Party Type
3130  , p_source_25            IN VARCHAR2
3131 )
3132 IS
3133 
3134 l_component_type              VARCHAR2(80);
3135 l_component_code              VARCHAR2(30);
3136 l_component_type_code         VARCHAR2(1);
3137 l_component_appl_id           INTEGER;
3138 l_amb_context_code            VARCHAR2(30);
3139 l_entity_code                 VARCHAR2(30);
3140 l_event_class_code            VARCHAR2(30);
3141 l_ae_header_id                NUMBER;
3142 l_event_type_code             VARCHAR2(30);
3143 l_line_definition_code        VARCHAR2(30);
3144 l_line_definition_owner_code  VARCHAR2(1);
3145 --
3146 -- adr variables
3147 l_segment                     VARCHAR2(30);
3148 l_ccid                        NUMBER;
3149 l_adr_transaction_coa_id      NUMBER;
3150 l_adr_accounting_coa_id       NUMBER;
3151 l_adr_flexfield_segment_code  VARCHAR2(30);
3152 l_adr_flex_value_set_id       NUMBER;
3153 l_adr_value_type_code         VARCHAR2(30);
3154 l_adr_value_combination_id    NUMBER;
3155 l_adr_value_segment_code      VARCHAR2(30);
3156 
3157 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
3158 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
3159 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
3160 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
3161 
3162 -- 4262811 Variables ------------------------------------------------------------------------------------------
3163 l_entered_amt_idx             NUMBER;
3164 l_accted_amt_idx              NUMBER;
3165 l_acc_rev_flag                VARCHAR2(1);
3166 l_accrual_line_num            NUMBER;
3167 l_tmp_amt                     NUMBER;
3168 l_acc_rev_natural_side_code   VARCHAR2(1);
3169 
3170 l_num_entries                 NUMBER;
3171 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
3172 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
3173 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
3174 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
3175 l_recog_line_1                NUMBER;
3176 l_recog_line_2                NUMBER;
3177 
3178 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
3179 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
3180 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
3181 
3182 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
3183 
3184 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
3185 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
3186 
3187 ---------------------------------------------------------------------------------------------------------------
3188 
3189 
3190 --
3191 -- bulk performance
3192 --
3193 l_balance_type_code           VARCHAR2(1);
3194 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
3195 l_log_module                  VARCHAR2(240);
3196 
3197 --
3198 -- Upgrade strategy
3199 --
3200 l_actual_upg_option           VARCHAR2(1);
3201 l_enc_upg_option           VARCHAR2(1);
3202 
3203 --
3204 BEGIN
3205 --
3206 IF g_log_enabled THEN
3207       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_19';
3208 END IF;
3209 --
3210 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3211 
3212       trace
3213          (p_msg      => 'BEGIN of AcctLineType_19'
3214          ,p_level    => C_LEVEL_PROCEDURE
3215          ,p_module   => l_log_module);
3216 
3217 END IF;
3218 --
3219 l_component_type             := 'AMB_JLT';
3220 l_component_code             := 'ADJ_CHRG';
3221 l_component_type_code        := 'S';
3222 l_component_appl_id          :=  222;
3223 l_amb_context_code           := 'DEFAULT';
3227 l_line_definition_owner_code := 'S';
3224 l_entity_code                := 'ADJUSTMENTS';
3225 l_event_class_code           := 'ADJUSTMENT';
3226 l_event_type_code            := 'ADJUSTMENT_ALL';
3228 l_line_definition_code       := 'MFAR_ADJ_ACCRUAL_BALANCING';
3229 --
3230 l_balance_type_code          := 'A';
3231 l_segment                     := NULL;
3232 l_ccid                        := NULL;
3233 l_adr_transaction_coa_id      := NULL;
3234 l_adr_accounting_coa_id       := NULL;
3235 l_adr_flexfield_segment_code  := NULL;
3236 l_adr_flex_value_set_id       := NULL;
3237 l_adr_value_type_code         := NULL;
3238 l_adr_value_combination_id    := NULL;
3239 l_adr_value_segment_code      := NULL;
3240 
3241 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
3242 l_bflow_class_code           := '';    -- 4219869 Business Flow
3243 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
3244 l_budgetary_control_flag     := 'N';
3245 
3246 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
3247 l_bflow_applied_to_amt       := NULL; -- 5132302
3248 l_entered_amt_idx            := NULL;          -- 4262811
3249 l_accted_amt_idx             := NULL;          -- 4262811
3250 l_acc_rev_flag               := NULL;          -- 4262811
3251 l_accrual_line_num           := NULL;          -- 4262811
3252 l_tmp_amt                    := NULL;          -- 4262811
3253 --
3254  
3255 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
3256     l_balance_type_code <> 'B' THEN
3257 IF NVL(p_source_13,'
3258 ') =  'FINCHRG' OR 
3259 NVL(p_source_13,'
3260 ') =  'FINCHRG_NON_REC_TAX'
3261  THEN 
3262 
3263    --
3264    XLA_AE_LINES_PKG.SetNewLine;
3265 
3266    p_balance_type_code          := l_balance_type_code;
3267    -- set the flag so later we will know whether the gain loss line needs to be created
3268    
3269    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
3270      p_actual_flag :='A';
3271    END IF;
3272 
3273    --
3274    -- bulk performance
3275    --
3276    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
3277                                       p_header_num   => 0); -- 4262811
3278    --
3279    -- set accounting line options
3280    --
3281    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
3282            p_natural_side_code          => 'C'
3283          , p_gain_or_loss_flag          => 'N'
3284          , p_gl_transfer_mode_code      => 'S'
3285          , p_acct_entry_type_code       => 'A'
3286          , p_switch_side_flag           => 'Y'
3287          , p_merge_duplicate_code       => 'A'
3288          );
3289    --
3290    l_acc_rev_natural_side_code := 'D';  -- 4262811
3291    -- 
3292    --
3293    -- set accounting line type info
3294    --
3295    xla_ae_lines_pkg.SetAcctLineType
3296       (p_component_type             => l_component_type
3297       ,p_event_type_code            => l_event_type_code
3298       ,p_line_definition_owner_code => l_line_definition_owner_code
3299       ,p_line_definition_code       => l_line_definition_code
3300       ,p_accounting_line_code       => l_component_code
3301       ,p_accounting_line_type_code  => l_component_type_code
3302       ,p_accounting_line_appl_id    => l_component_appl_id
3303       ,p_amb_context_code           => l_amb_context_code
3304       ,p_entity_code                => l_entity_code
3305       ,p_event_class_code           => l_event_class_code);
3306    --
3307    -- set accounting class
3308    --
3309    xla_ae_lines_pkg.SetAcctClass(
3310            p_accounting_class_code  => 'CHARGES'
3311          , p_ae_header_id           => l_ae_header_id
3312          );
3313 
3314    --
3315    -- set rounding class
3316    --
3317    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
3318                       'RECEIVABLE';
3319 
3320    --
3321    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
3322    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
3323    --
3324    -- bulk performance
3325    --
3326    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
3327 
3328    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
3329       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
3330 
3331    -- 4955764
3332    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3333       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
3334 
3335    -- 4458381 Public Sector Enh
3336    
3337    --
3338    -- set accounting attributes for the line type
3339    --
3340    l_entered_amt_idx := 3;
3341    l_accted_amt_idx  := 8;
3342    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
3343    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
3344    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
3345    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
3346    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
3347    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
3348    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
3349    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
3350    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
3351    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
3352    l_rec_acct_attrs.array_date_value(5)  := p_source_19;
3353    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
3354    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
3358    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
3355    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
3356    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
3357    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
3359    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
3360    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
3361    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
3362    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
3363    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
3364    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
3365 
3366    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
3367    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
3368 
3369    ---------------------------------------------------------------------------------------------------------------
3370    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
3371    ---------------------------------------------------------------------------------------------------------------
3372    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
3373 
3374    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3375    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3376 
3377    IF xla_accounting_cache_pkg.GetValueChar
3378          (p_source_code         => 'LEDGER_CATEGORY_CODE'
3379          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
3380    AND l_bflow_method_code = 'PRIOR_ENTRY'
3381 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
3382    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
3383          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
3384        )
3385    THEN
3386          xla_ae_lines_pkg.BflowUpgEntry
3387            (p_business_method_code    => l_bflow_method_code
3388            ,p_business_class_code     => l_bflow_class_code
3389            ,p_balance_type            => l_balance_type_code);
3390    ELSE
3391       NULL;
3392 -- No business flow processing for business flow method of NONE.
3393    END IF;
3394 
3395    --
3396    -- call analytical criteria
3397    --
3398    
3399    --
3400    -- call description
3401    --
3402    -- No description or it is inherited.
3403    --
3404    -- call ADRs
3405    -- Bug 4922099
3406    --
3407    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
3408         (NVL(l_actual_upg_option, 'N') = 'O') OR
3409         (NVL(l_enc_upg_option, 'N') = 'O')
3410       )
3411    THEN
3412    NULL;
3413    --
3414    --
3415    
3416   l_ccid := AcctDerRule_7(
3417            p_application_id           => p_application_id
3418          , p_ae_header_id             => l_ae_header_id 
3419 , p_source_3 => p_source_3
3420          , x_transaction_coa_id       => l_adr_transaction_coa_id
3421          , x_accounting_coa_id        => l_adr_accounting_coa_id
3422          , x_value_type_code          => l_adr_value_type_code
3423          , p_side                     => 'NA'
3424    );
3425 
3426    xla_ae_lines_pkg.set_ccid(
3427     p_code_combination_id          => l_ccid
3428   , p_value_type_code              => l_adr_value_type_code
3429   , p_transaction_coa_id           => l_adr_transaction_coa_id
3430   , p_accounting_coa_id            => l_adr_accounting_coa_id
3431   , p_adr_code                     => 'DIST_CCID'
3432   , p_adr_type_code                => 'S'
3433   , p_component_type               => l_component_type
3434   , p_component_code               => l_component_code
3435   , p_component_type_code          => l_component_type_code
3436   , p_component_appl_id            => l_component_appl_id
3437   , p_amb_context_code             => l_amb_context_code
3438   , p_side                         => 'NA'
3439   );
3440 
3441 
3442    --
3443    --
3444    END IF;
3445    --
3446    -- Bug 4922099
3447    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
3448           (NVL(l_enc_upg_option, 'N') = 'O')
3449         ) AND
3450         (l_bflow_method_code = 'PRIOR_ENTRY')
3451       )
3452    THEN
3453       IF
3454       --
3455       1 = 2
3456       --
3457       THEN
3458       xla_accounting_err_pkg.build_message
3459                                     (p_appli_s_name            => 'XLA'
3460                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3461                                     ,p_token_1                 => 'LINE_NUMBER'
3462                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
3463                                     ,p_token_2                 => 'LINE_TYPE_NAME'
3464                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
3465                                                                              l_component_type
3466                                                                             ,l_component_code
3467                                                                             ,l_component_type_code
3468                                                                             ,l_component_appl_id
3469                                                                             ,l_amb_context_code
3470                                                                             ,l_entity_code
3471                                                                             ,l_event_class_code
3472                                                                            )
3473                                     ,p_token_3                 => 'OWNER'
3474                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
3475                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
3476                                                                           ,p_lookup_code    => l_component_type_code
3477                                                                          )
3478                                     ,p_token_4                 => 'PRODUCT_NAME'
3479                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
3480                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
3481                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
3482                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
3483                                     ,p_ae_header_id            =>  NULL
3484                                        );
3485 
3486         IF (C_LEVEL_ERROR>= g_log_level) THEN
3487                  trace
3488                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3489                       ,p_level    => C_LEVEL_ERROR
3490                       ,p_module   => l_log_module);
3491         END IF;
3492       END IF;
3493    END IF;
3494    --
3495    --
3496    ------------------------------------------------------------------------------------------------
3497    -- 4219869 Business Flow
3498    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
3499    -- Prior Entry.  Currently, the following code is always generated.
3500    ------------------------------------------------------------------------------------------------
3501    XLA_AE_LINES_PKG.ValidateCurrentLine;
3502 
3503    ------------------------------------------------------------------------------------
3504    -- 4219869 Business Flow
3505    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
3506    ------------------------------------------------------------------------------------
3507    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3508 
3509    ----------------------------------------------------------------------------------
3510    -- 4219869 Business Flow
3511    -- Update journal entry status -- Need to generate this within IF <condition>
3512    ----------------------------------------------------------------------------------
3513    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3514          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
3515          ,p_balance_type_code => l_balance_type_code
3516          );
3517 
3518    -------------------------------------------------------------------------------------------
3519    -- 4262811 - Generate the Accrual Reversal lines
3520    -------------------------------------------------------------------------------------------
3521    BEGIN
3522       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
3523                               (g_array_event(p_event_id).array_value_num('header_index'));
3524       IF l_acc_rev_flag IS NULL THEN
3525          l_acc_rev_flag := 'N';
3526       END IF;
3527    EXCEPTION
3528       WHEN OTHERS THEN
3529          l_acc_rev_flag := 'N';
3530    END;
3531    --
3532    IF (l_acc_rev_flag = 'Y') THEN
3533 
3534        -- 4645092  ------------------------------------------------------------------------------
3535        -- To allow MPA report to determine if it should generate report process
3536        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
3537        ------------------------------------------------------------------------------------------
3538 
3539        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
3540        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
3541    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
3542    -- call ADRs
3543    -- Bug 4922099
3544    --
3545    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
3546         (NVL(l_actual_upg_option, 'N') = 'O') OR
3547         (NVL(l_enc_upg_option, 'N') = 'O')
3548       )
3549    THEN
3550    NULL;
3551    --
3552    --
3553    
3554   l_ccid := AcctDerRule_7(
3555            p_application_id           => p_application_id
3556          , p_ae_header_id             => l_ae_header_id 
3557 , p_source_3 => p_source_3
3558          , x_transaction_coa_id       => l_adr_transaction_coa_id
3559          , x_accounting_coa_id        => l_adr_accounting_coa_id
3560          , x_value_type_code          => l_adr_value_type_code
3561          , p_side                     => 'NA'
3562    );
3563 
3564    xla_ae_lines_pkg.set_ccid(
3565     p_code_combination_id          => l_ccid
3566   , p_value_type_code              => l_adr_value_type_code
3567   , p_transaction_coa_id           => l_adr_transaction_coa_id
3568   , p_accounting_coa_id            => l_adr_accounting_coa_id
3569   , p_adr_code                     => 'DIST_CCID'
3570   , p_adr_type_code                => 'S'
3571   , p_component_type               => l_component_type
3572   , p_component_code               => l_component_code
3573   , p_component_type_code          => l_component_type_code
3574   , p_component_appl_id            => l_component_appl_id
3575   , p_amb_context_code             => l_amb_context_code
3576   , p_side                         => 'NA'
3577   );
3578 
3579 
3580    --
3581    --
3582    END IF;
3583 
3584        --
3585        -- Update the line information that should be overwritten
3586        --
3587        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
3588                                          p_header_num   => 1);
3589        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
3590 
3591        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
3592 
3593        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
3594           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
3595        END IF;
3596 
3597       --
3598       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
3599       --
3600       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
3601           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
3602       ELSE
3603           ---------------------------------------------------------------------------------------------------
3604           -- 4262811a Switch Sign
3605           ---------------------------------------------------------------------------------------------------
3606           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
3607           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3608                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3609           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3610                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3611           -- 5132302
3612           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
3613                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3614 
3615       END IF;
3616 
3617       -- 4955764
3618       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3619       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
3620 
3621 
3622       XLA_AE_LINES_PKG.ValidateCurrentLine;
3623       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3624 
3625       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3626                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
3627                ,p_balance_type_code => l_balance_type_code);
3628 
3629    END IF;
3630 
3631    -----------------------------------------------------------------------------------------
3632    -- 4262811 Multiperiod Accounting
3633    -----------------------------------------------------------------------------------------
3634      -- No MPA option is assigned.
3635 
3636 
3637 END IF;
3638 END IF;
3639 --
3640 
3641 --
3642 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3643    trace
3644       (p_msg      => 'END of AcctLineType_19'
3645       ,p_level    => C_LEVEL_PROCEDURE
3646       ,p_module   => l_log_module);
3647 END IF;
3648 --
3649 EXCEPTION
3650   WHEN xla_exceptions_pkg.application_exception THEN
3651       RAISE;
3652   WHEN OTHERS THEN
3653        xla_exceptions_pkg.raise_message
3654            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_19');
3655 END AcctLineType_19;
3656 --
3657 
3658 ---------------------------------------
3659 --
3660 -- PRIVATE FUNCTION
3661 --         AcctLineType_20
3662 --
3663 ---------------------------------------
3664 PROCEDURE AcctLineType_20 (
3665   p_application_id        IN NUMBER
3666  ,p_event_id              IN NUMBER
3667  ,p_calculate_acctd_flag  IN VARCHAR2
3668  ,p_calculate_g_l_flag    IN VARCHAR2
3669  ,p_actual_flag           IN OUT VARCHAR2
3670  ,p_balance_type_code     OUT VARCHAR2
3671  ,p_gain_or_loss_ref      OUT VARCHAR2
3672  
3673 --Distribution GL Account
3674  , p_source_3            IN NUMBER
3675 --Distribution Source Type
3676  , p_source_13            IN VARCHAR2
3677 --Distribution Line Identifier
3678  , p_source_15            IN NUMBER
3679 --Distribution Type
3680  , p_source_16            IN VARCHAR2
3681 --Entered Amount
3682  , p_source_17            IN NUMBER
3683 --Currency Code
3684  , p_source_18            IN VARCHAR2
3685 --Exchange Date
3686  , p_source_19            IN DATE
3687 --Exchange Rate
3688  , p_source_20            IN NUMBER
3689 --Exchange Rate Type
3690  , p_source_21            IN VARCHAR2
3691 --Applied To Document Accounting Amount
3692  , p_source_22            IN NUMBER
3693 --Bill To Customer Account Identifier
3694  , p_source_23            IN NUMBER
3695 --Bill To Customer Site Use Identifier
3696  , p_source_24            IN NUMBER
3697 --SLA Party Type
3698  , p_source_25            IN VARCHAR2
3699 )
3700 IS
3701 
3702 l_component_type              VARCHAR2(80);
3703 l_component_code              VARCHAR2(30);
3704 l_component_type_code         VARCHAR2(1);
3705 l_component_appl_id           INTEGER;
3706 l_amb_context_code            VARCHAR2(30);
3707 l_entity_code                 VARCHAR2(30);
3708 l_event_class_code            VARCHAR2(30);
3709 l_ae_header_id                NUMBER;
3710 l_event_type_code             VARCHAR2(30);
3711 l_line_definition_code        VARCHAR2(30);
3712 l_line_definition_owner_code  VARCHAR2(1);
3713 --
3714 -- adr variables
3715 l_segment                     VARCHAR2(30);
3716 l_ccid                        NUMBER;
3717 l_adr_transaction_coa_id      NUMBER;
3718 l_adr_accounting_coa_id       NUMBER;
3719 l_adr_flexfield_segment_code  VARCHAR2(30);
3720 l_adr_flex_value_set_id       NUMBER;
3721 l_adr_value_type_code         VARCHAR2(30);
3722 l_adr_value_combination_id    NUMBER;
3726 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
3723 l_adr_value_segment_code      VARCHAR2(30);
3724 
3725 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
3727 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
3728 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
3729 
3730 -- 4262811 Variables ------------------------------------------------------------------------------------------
3731 l_entered_amt_idx             NUMBER;
3732 l_accted_amt_idx              NUMBER;
3733 l_acc_rev_flag                VARCHAR2(1);
3734 l_accrual_line_num            NUMBER;
3735 l_tmp_amt                     NUMBER;
3736 l_acc_rev_natural_side_code   VARCHAR2(1);
3737 
3738 l_num_entries                 NUMBER;
3739 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
3740 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
3741 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
3742 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
3743 l_recog_line_1                NUMBER;
3744 l_recog_line_2                NUMBER;
3745 
3746 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
3747 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
3748 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
3749 
3750 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
3751 
3752 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
3753 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
3754 
3755 ---------------------------------------------------------------------------------------------------------------
3756 
3757 
3758 --
3759 -- bulk performance
3760 --
3761 l_balance_type_code           VARCHAR2(1);
3762 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
3763 l_log_module                  VARCHAR2(240);
3764 
3765 --
3766 -- Upgrade strategy
3767 --
3768 l_actual_upg_option           VARCHAR2(1);
3769 l_enc_upg_option           VARCHAR2(1);
3770 
3771 --
3772 BEGIN
3773 --
3774 IF g_log_enabled THEN
3775       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_20';
3776 END IF;
3777 --
3778 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3779 
3780       trace
3781          (p_msg      => 'BEGIN of AcctLineType_20'
3782          ,p_level    => C_LEVEL_PROCEDURE
3783          ,p_module   => l_log_module);
3784 
3785 END IF;
3786 --
3787 l_component_type             := 'AMB_JLT';
3788 l_component_code             := 'ADJ_DEFERRED_TAX';
3789 l_component_type_code        := 'S';
3790 l_component_appl_id          :=  222;
3791 l_amb_context_code           := 'DEFAULT';
3792 l_entity_code                := 'ADJUSTMENTS';
3793 l_event_class_code           := 'ADJUSTMENT';
3794 l_event_type_code            := 'ADJUSTMENT_ALL';
3795 l_line_definition_owner_code := 'S';
3796 l_line_definition_code       := 'MFAR_ADJ_ACCRUAL_BALANCING';
3797 --
3798 l_balance_type_code          := 'A';
3799 l_segment                     := NULL;
3800 l_ccid                        := NULL;
3801 l_adr_transaction_coa_id      := NULL;
3802 l_adr_accounting_coa_id       := NULL;
3803 l_adr_flexfield_segment_code  := NULL;
3804 l_adr_flex_value_set_id       := NULL;
3805 l_adr_value_type_code         := NULL;
3806 l_adr_value_combination_id    := NULL;
3807 l_adr_value_segment_code      := NULL;
3808 
3809 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
3810 l_bflow_class_code           := '';    -- 4219869 Business Flow
3811 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
3812 l_budgetary_control_flag     := 'N';
3813 
3814 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
3815 l_bflow_applied_to_amt       := NULL; -- 5132302
3816 l_entered_amt_idx            := NULL;          -- 4262811
3817 l_accted_amt_idx             := NULL;          -- 4262811
3818 l_acc_rev_flag               := NULL;          -- 4262811
3819 l_accrual_line_num           := NULL;          -- 4262811
3820 l_tmp_amt                    := NULL;          -- 4262811
3821 --
3822  
3823 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
3824     l_balance_type_code <> 'B' THEN
3825 IF NVL(p_source_13,'
3826 ') =  'DEFERRED_TAX'
3827  THEN 
3828 
3829    --
3830    XLA_AE_LINES_PKG.SetNewLine;
3831 
3832    p_balance_type_code          := l_balance_type_code;
3833    -- set the flag so later we will know whether the gain loss line needs to be created
3834    
3835    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
3836      p_actual_flag :='A';
3837    END IF;
3838 
3839    --
3840    -- bulk performance
3841    --
3842    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
3843                                       p_header_num   => 0); -- 4262811
3844    --
3845    -- set accounting line options
3846    --
3847    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
3848            p_natural_side_code          => 'C'
3849          , p_gain_or_loss_flag          => 'N'
3850          , p_gl_transfer_mode_code      => 'S'
3851          , p_acct_entry_type_code       => 'A'
3852          , p_switch_side_flag           => 'Y'
3853          , p_merge_duplicate_code       => 'A'
3854          );
3855    --
3856    l_acc_rev_natural_side_code := 'D';  -- 4262811
3857    -- 
3858    --
3859    -- set accounting line type info
3860    --
3861    xla_ae_lines_pkg.SetAcctLineType
3862       (p_component_type             => l_component_type
3863       ,p_event_type_code            => l_event_type_code
3864       ,p_line_definition_owner_code => l_line_definition_owner_code
3865       ,p_line_definition_code       => l_line_definition_code
3866       ,p_accounting_line_code       => l_component_code
3867       ,p_accounting_line_type_code  => l_component_type_code
3868       ,p_accounting_line_appl_id    => l_component_appl_id
3869       ,p_amb_context_code           => l_amb_context_code
3870       ,p_entity_code                => l_entity_code
3871       ,p_event_class_code           => l_event_class_code);
3872    --
3873    -- set accounting class
3874    --
3875    xla_ae_lines_pkg.SetAcctClass(
3876            p_accounting_class_code  => 'DEFERRED_TAX'
3877          , p_ae_header_id           => l_ae_header_id
3878          );
3879 
3880    --
3881    -- set rounding class
3882    --
3883    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
3884                       'RECEIVABLE';
3885 
3886    --
3887    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
3888    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
3889    --
3890    -- bulk performance
3891    --
3892    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
3893 
3894    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
3895       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
3896 
3897    -- 4955764
3898    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3899       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
3900 
3901    -- 4458381 Public Sector Enh
3902    
3903    --
3904    -- set accounting attributes for the line type
3905    --
3906    l_entered_amt_idx := 3;
3907    l_accted_amt_idx  := 8;
3908    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
3909    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
3910    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
3911    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
3912    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
3913    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
3914    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
3915    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
3916    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
3917    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
3918    l_rec_acct_attrs.array_date_value(5)  := p_source_19;
3919    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
3920    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
3921    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
3922    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
3923    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
3924    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
3925    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
3926    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
3927    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
3928    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
3929    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
3930    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
3931 
3932    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
3936    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
3933    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
3934 
3935    ---------------------------------------------------------------------------------------------------------------
3937    ---------------------------------------------------------------------------------------------------------------
3938    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
3939 
3940    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3941    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3942 
3943    IF xla_accounting_cache_pkg.GetValueChar
3944          (p_source_code         => 'LEDGER_CATEGORY_CODE'
3945          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
3946    AND l_bflow_method_code = 'PRIOR_ENTRY'
3947 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
3948    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
3949          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
3950        )
3951    THEN
3952          xla_ae_lines_pkg.BflowUpgEntry
3953            (p_business_method_code    => l_bflow_method_code
3954            ,p_business_class_code     => l_bflow_class_code
3955            ,p_balance_type            => l_balance_type_code);
3956    ELSE
3957       NULL;
3958 -- No business flow processing for business flow method of NONE.
3959    END IF;
3960 
3961    --
3962    -- call analytical criteria
3963    --
3964    
3965    --
3966    -- call description
3967    --
3968    -- No description or it is inherited.
3969    --
3970    -- call ADRs
3971    -- Bug 4922099
3972    --
3973    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
3974         (NVL(l_actual_upg_option, 'N') = 'O') OR
3975         (NVL(l_enc_upg_option, 'N') = 'O')
3976       )
3977    THEN
3978    NULL;
3979    --
3980    --
3981    
3982   l_ccid := AcctDerRule_7(
3983            p_application_id           => p_application_id
3984          , p_ae_header_id             => l_ae_header_id 
3985 , p_source_3 => p_source_3
3986          , x_transaction_coa_id       => l_adr_transaction_coa_id
3987          , x_accounting_coa_id        => l_adr_accounting_coa_id
3988          , x_value_type_code          => l_adr_value_type_code
3989          , p_side                     => 'NA'
3990    );
3991 
3992    xla_ae_lines_pkg.set_ccid(
3993     p_code_combination_id          => l_ccid
3994   , p_value_type_code              => l_adr_value_type_code
3995   , p_transaction_coa_id           => l_adr_transaction_coa_id
3996   , p_accounting_coa_id            => l_adr_accounting_coa_id
3997   , p_adr_code                     => 'DIST_CCID'
3998   , p_adr_type_code                => 'S'
3999   , p_component_type               => l_component_type
4000   , p_component_code               => l_component_code
4001   , p_component_type_code          => l_component_type_code
4002   , p_component_appl_id            => l_component_appl_id
4003   , p_amb_context_code             => l_amb_context_code
4004   , p_side                         => 'NA'
4005   );
4006 
4007 
4008    --
4009    --
4010    END IF;
4011    --
4012    -- Bug 4922099
4013    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
4014           (NVL(l_enc_upg_option, 'N') = 'O')
4015         ) AND
4016         (l_bflow_method_code = 'PRIOR_ENTRY')
4017       )
4018    THEN
4019       IF
4020       --
4021       1 = 2
4022       --
4023       THEN
4024       xla_accounting_err_pkg.build_message
4025                                     (p_appli_s_name            => 'XLA'
4026                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4027                                     ,p_token_1                 => 'LINE_NUMBER'
4028                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
4029                                     ,p_token_2                 => 'LINE_TYPE_NAME'
4030                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
4031                                                                              l_component_type
4032                                                                             ,l_component_code
4033                                                                             ,l_component_type_code
4034                                                                             ,l_component_appl_id
4035                                                                             ,l_amb_context_code
4036                                                                             ,l_entity_code
4037                                                                             ,l_event_class_code
4038                                                                            )
4039                                     ,p_token_3                 => 'OWNER'
4040                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
4041                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
4042                                                                           ,p_lookup_code    => l_component_type_code
4043                                                                          )
4044                                     ,p_token_4                 => 'PRODUCT_NAME'
4045                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
4046                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
4050                                        );
4047                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
4048                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
4049                                     ,p_ae_header_id            =>  NULL
4051 
4052         IF (C_LEVEL_ERROR>= g_log_level) THEN
4053                  trace
4054                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4055                       ,p_level    => C_LEVEL_ERROR
4056                       ,p_module   => l_log_module);
4057         END IF;
4058       END IF;
4059    END IF;
4060    --
4061    --
4062    ------------------------------------------------------------------------------------------------
4063    -- 4219869 Business Flow
4064    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
4065    -- Prior Entry.  Currently, the following code is always generated.
4066    ------------------------------------------------------------------------------------------------
4067    XLA_AE_LINES_PKG.ValidateCurrentLine;
4068 
4069    ------------------------------------------------------------------------------------
4070    -- 4219869 Business Flow
4071    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
4072    ------------------------------------------------------------------------------------
4073    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4074 
4075    ----------------------------------------------------------------------------------
4076    -- 4219869 Business Flow
4077    -- Update journal entry status -- Need to generate this within IF <condition>
4078    ----------------------------------------------------------------------------------
4079    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4080          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
4081          ,p_balance_type_code => l_balance_type_code
4082          );
4083 
4084    -------------------------------------------------------------------------------------------
4085    -- 4262811 - Generate the Accrual Reversal lines
4086    -------------------------------------------------------------------------------------------
4087    BEGIN
4088       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
4089                               (g_array_event(p_event_id).array_value_num('header_index'));
4090       IF l_acc_rev_flag IS NULL THEN
4091          l_acc_rev_flag := 'N';
4092       END IF;
4093    EXCEPTION
4094       WHEN OTHERS THEN
4095          l_acc_rev_flag := 'N';
4096    END;
4097    --
4098    IF (l_acc_rev_flag = 'Y') THEN
4099 
4100        -- 4645092  ------------------------------------------------------------------------------
4101        -- To allow MPA report to determine if it should generate report process
4102        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
4103        ------------------------------------------------------------------------------------------
4104 
4105        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
4106        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
4107    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
4108    -- call ADRs
4109    -- Bug 4922099
4110    --
4111    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4112         (NVL(l_actual_upg_option, 'N') = 'O') OR
4113         (NVL(l_enc_upg_option, 'N') = 'O')
4114       )
4115    THEN
4116    NULL;
4117    --
4118    --
4119    
4120   l_ccid := AcctDerRule_7(
4121            p_application_id           => p_application_id
4122          , p_ae_header_id             => l_ae_header_id 
4123 , p_source_3 => p_source_3
4124          , x_transaction_coa_id       => l_adr_transaction_coa_id
4125          , x_accounting_coa_id        => l_adr_accounting_coa_id
4126          , x_value_type_code          => l_adr_value_type_code
4127          , p_side                     => 'NA'
4128    );
4129 
4130    xla_ae_lines_pkg.set_ccid(
4131     p_code_combination_id          => l_ccid
4132   , p_value_type_code              => l_adr_value_type_code
4133   , p_transaction_coa_id           => l_adr_transaction_coa_id
4134   , p_accounting_coa_id            => l_adr_accounting_coa_id
4135   , p_adr_code                     => 'DIST_CCID'
4136   , p_adr_type_code                => 'S'
4137   , p_component_type               => l_component_type
4138   , p_component_code               => l_component_code
4139   , p_component_type_code          => l_component_type_code
4140   , p_component_appl_id            => l_component_appl_id
4141   , p_amb_context_code             => l_amb_context_code
4142   , p_side                         => 'NA'
4143   );
4144 
4145 
4146    --
4147    --
4148    END IF;
4149 
4150        --
4151        -- Update the line information that should be overwritten
4152        --
4153        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
4154                                          p_header_num   => 1);
4155        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
4156 
4157        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
4158 
4159        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
4160           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
4161        END IF;
4162 
4163       --
4164       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
4165       --
4166       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
4167           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
4168       ELSE
4169           ---------------------------------------------------------------------------------------------------
4170           -- 4262811a Switch Sign
4171           ---------------------------------------------------------------------------------------------------
4172           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
4173           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4174                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4175           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4176                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4177           -- 5132302
4178           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
4179                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4180 
4181       END IF;
4182 
4183       -- 4955764
4184       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4185       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
4186 
4187 
4188       XLA_AE_LINES_PKG.ValidateCurrentLine;
4189       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4190 
4191       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4192                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
4193                ,p_balance_type_code => l_balance_type_code);
4194 
4195    END IF;
4196 
4197    -----------------------------------------------------------------------------------------
4198    -- 4262811 Multiperiod Accounting
4199    -----------------------------------------------------------------------------------------
4200      -- No MPA option is assigned.
4201 
4202 
4203 END IF;
4204 END IF;
4205 --
4206 
4207 --
4208 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4209    trace
4210       (p_msg      => 'END of AcctLineType_20'
4211       ,p_level    => C_LEVEL_PROCEDURE
4212       ,p_module   => l_log_module);
4213 END IF;
4214 --
4215 EXCEPTION
4216   WHEN xla_exceptions_pkg.application_exception THEN
4217       RAISE;
4218   WHEN OTHERS THEN
4219        xla_exceptions_pkg.raise_message
4220            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_20');
4221 END AcctLineType_20;
4222 --
4223 
4224 ---------------------------------------
4225 --
4226 -- PRIVATE FUNCTION
4227 --         AcctLineType_21
4228 --
4229 ---------------------------------------
4230 PROCEDURE AcctLineType_21 (
4231   p_application_id        IN NUMBER
4232  ,p_event_id              IN NUMBER
4233  ,p_calculate_acctd_flag  IN VARCHAR2
4234  ,p_calculate_g_l_flag    IN VARCHAR2
4235  ,p_actual_flag           IN OUT VARCHAR2
4236  ,p_balance_type_code     OUT VARCHAR2
4237  ,p_gain_or_loss_ref      OUT VARCHAR2
4238  
4239 --Distribution GL Account
4240  , p_source_3            IN NUMBER
4241 --Distribution Source Type
4242  , p_source_13            IN VARCHAR2
4243 --Distribution Line Identifier
4244  , p_source_15            IN NUMBER
4245 --Distribution Type
4246  , p_source_16            IN VARCHAR2
4247 --Entered Amount
4248  , p_source_17            IN NUMBER
4249 --Currency Code
4250  , p_source_18            IN VARCHAR2
4251 --Exchange Date
4252  , p_source_19            IN DATE
4253 --Exchange Rate
4254  , p_source_20            IN NUMBER
4255 --Exchange Rate Type
4256  , p_source_21            IN VARCHAR2
4257 --Applied To Document Accounting Amount
4258  , p_source_22            IN NUMBER
4259 --Bill To Customer Account Identifier
4260  , p_source_23            IN NUMBER
4261 --Bill To Customer Site Use Identifier
4262  , p_source_24            IN NUMBER
4263 --SLA Party Type
4264  , p_source_25            IN VARCHAR2
4265 )
4266 IS
4267 
4268 l_component_type              VARCHAR2(80);
4269 l_component_code              VARCHAR2(30);
4270 l_component_type_code         VARCHAR2(1);
4271 l_component_appl_id           INTEGER;
4272 l_amb_context_code            VARCHAR2(30);
4273 l_entity_code                 VARCHAR2(30);
4274 l_event_class_code            VARCHAR2(30);
4275 l_ae_header_id                NUMBER;
4276 l_event_type_code             VARCHAR2(30);
4277 l_line_definition_code        VARCHAR2(30);
4278 l_line_definition_owner_code  VARCHAR2(1);
4279 --
4280 -- adr variables
4281 l_segment                     VARCHAR2(30);
4282 l_ccid                        NUMBER;
4283 l_adr_transaction_coa_id      NUMBER;
4284 l_adr_accounting_coa_id       NUMBER;
4285 l_adr_flexfield_segment_code  VARCHAR2(30);
4286 l_adr_flex_value_set_id       NUMBER;
4287 l_adr_value_type_code         VARCHAR2(30);
4288 l_adr_value_combination_id    NUMBER;
4289 l_adr_value_segment_code      VARCHAR2(30);
4290 
4291 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
4292 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
4296 -- 4262811 Variables ------------------------------------------------------------------------------------------
4293 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
4294 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
4295 
4297 l_entered_amt_idx             NUMBER;
4298 l_accted_amt_idx              NUMBER;
4299 l_acc_rev_flag                VARCHAR2(1);
4300 l_accrual_line_num            NUMBER;
4301 l_tmp_amt                     NUMBER;
4302 l_acc_rev_natural_side_code   VARCHAR2(1);
4303 
4304 l_num_entries                 NUMBER;
4305 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
4306 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
4307 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
4308 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
4309 l_recog_line_1                NUMBER;
4310 l_recog_line_2                NUMBER;
4311 
4312 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
4313 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
4314 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
4315 
4316 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
4317 
4318 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
4319 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
4320 
4321 ---------------------------------------------------------------------------------------------------------------
4322 
4323 
4324 --
4325 -- bulk performance
4326 --
4327 l_balance_type_code           VARCHAR2(1);
4328 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
4329 l_log_module                  VARCHAR2(240);
4330 
4331 --
4332 -- Upgrade strategy
4333 --
4334 l_actual_upg_option           VARCHAR2(1);
4335 l_enc_upg_option           VARCHAR2(1);
4336 
4337 --
4338 BEGIN
4339 --
4340 IF g_log_enabled THEN
4341       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_21';
4342 END IF;
4343 --
4344 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4345 
4346       trace
4347          (p_msg      => 'BEGIN of AcctLineType_21'
4348          ,p_level    => C_LEVEL_PROCEDURE
4349          ,p_module   => l_log_module);
4350 
4351 END IF;
4352 --
4353 l_component_type             := 'AMB_JLT';
4354 l_component_code             := 'ADJ_TAX';
4355 l_component_type_code        := 'S';
4356 l_component_appl_id          :=  222;
4357 l_amb_context_code           := 'DEFAULT';
4358 l_entity_code                := 'ADJUSTMENTS';
4359 l_event_class_code           := 'ADJUSTMENT';
4360 l_event_type_code            := 'ADJUSTMENT_ALL';
4361 l_line_definition_owner_code := 'S';
4362 l_line_definition_code       := 'MFAR_ADJ_ACCRUAL_BALANCING';
4363 --
4364 l_balance_type_code          := 'A';
4365 l_segment                     := NULL;
4366 l_ccid                        := NULL;
4367 l_adr_transaction_coa_id      := NULL;
4368 l_adr_accounting_coa_id       := NULL;
4369 l_adr_flexfield_segment_code  := NULL;
4370 l_adr_flex_value_set_id       := NULL;
4371 l_adr_value_type_code         := NULL;
4372 l_adr_value_combination_id    := NULL;
4373 l_adr_value_segment_code      := NULL;
4374 
4375 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
4376 l_bflow_class_code           := '';    -- 4219869 Business Flow
4377 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
4378 l_budgetary_control_flag     := 'N';
4379 
4380 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
4381 l_bflow_applied_to_amt       := NULL; -- 5132302
4382 l_entered_amt_idx            := NULL;          -- 4262811
4383 l_accted_amt_idx             := NULL;          -- 4262811
4384 l_acc_rev_flag               := NULL;          -- 4262811
4385 l_accrual_line_num           := NULL;          -- 4262811
4386 l_tmp_amt                    := NULL;          -- 4262811
4387 --
4388  
4389 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
4390     l_balance_type_code <> 'B' THEN
4391 IF NVL(p_source_13,'
4392 ') =  'TAX'
4393  THEN 
4394 
4395    --
4396    XLA_AE_LINES_PKG.SetNewLine;
4397 
4398    p_balance_type_code          := l_balance_type_code;
4399    -- set the flag so later we will know whether the gain loss line needs to be created
4400    
4401    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
4402      p_actual_flag :='A';
4403    END IF;
4404 
4405    --
4406    -- bulk performance
4407    --
4408    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
4409                                       p_header_num   => 0); -- 4262811
4410    --
4411    -- set accounting line options
4412    --
4413    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
4414            p_natural_side_code          => 'C'
4415          , p_gain_or_loss_flag          => 'N'
4416          , p_gl_transfer_mode_code      => 'S'
4417          , p_acct_entry_type_code       => 'A'
4418          , p_switch_side_flag           => 'Y'
4419          , p_merge_duplicate_code       => 'A'
4420          );
4421    --
4422    l_acc_rev_natural_side_code := 'D';  -- 4262811
4423    -- 
4424    --
4425    -- set accounting line type info
4426    --
4427    xla_ae_lines_pkg.SetAcctLineType
4428       (p_component_type             => l_component_type
4429       ,p_event_type_code            => l_event_type_code
4430       ,p_line_definition_owner_code => l_line_definition_owner_code
4431       ,p_line_definition_code       => l_line_definition_code
4435       ,p_amb_context_code           => l_amb_context_code
4432       ,p_accounting_line_code       => l_component_code
4433       ,p_accounting_line_type_code  => l_component_type_code
4434       ,p_accounting_line_appl_id    => l_component_appl_id
4436       ,p_entity_code                => l_entity_code
4437       ,p_event_class_code           => l_event_class_code);
4438    --
4439    -- set accounting class
4440    --
4441    xla_ae_lines_pkg.SetAcctClass(
4442            p_accounting_class_code  => 'TAX'
4443          , p_ae_header_id           => l_ae_header_id
4444          );
4445 
4446    --
4447    -- set rounding class
4448    --
4449    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
4450                       'RECEIVABLE';
4451 
4452    --
4453    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
4454    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
4455    --
4456    -- bulk performance
4457    --
4458    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
4459 
4460    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
4461       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
4462 
4463    -- 4955764
4464    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4465       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
4466 
4467    -- 4458381 Public Sector Enh
4468    
4469    --
4470    -- set accounting attributes for the line type
4471    --
4472    l_entered_amt_idx := 3;
4473    l_accted_amt_idx  := 8;
4474    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
4475    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
4476    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
4477    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
4478    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
4479    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
4480    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
4481    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
4482    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
4483    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
4484    l_rec_acct_attrs.array_date_value(5)  := p_source_19;
4485    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
4486    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
4487    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
4488    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
4489    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
4490    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
4491    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
4492    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
4493    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
4494    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
4495    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
4496    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
4497 
4498    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
4499    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
4500 
4501    ---------------------------------------------------------------------------------------------------------------
4502    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
4503    ---------------------------------------------------------------------------------------------------------------
4504    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
4505 
4506    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4507    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4508 
4509    IF xla_accounting_cache_pkg.GetValueChar
4510          (p_source_code         => 'LEDGER_CATEGORY_CODE'
4511          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
4512    AND l_bflow_method_code = 'PRIOR_ENTRY'
4513 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
4514    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
4515          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
4516        )
4517    THEN
4518          xla_ae_lines_pkg.BflowUpgEntry
4519            (p_business_method_code    => l_bflow_method_code
4520            ,p_business_class_code     => l_bflow_class_code
4521            ,p_balance_type            => l_balance_type_code);
4522    ELSE
4523       NULL;
4524 -- No business flow processing for business flow method of NONE.
4525    END IF;
4526 
4527    --
4528    -- call analytical criteria
4529    --
4530    
4531    --
4532    -- call description
4533    --
4534    -- No description or it is inherited.
4535    --
4536    -- call ADRs
4537    -- Bug 4922099
4538    --
4539    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4540         (NVL(l_actual_upg_option, 'N') = 'O') OR
4541         (NVL(l_enc_upg_option, 'N') = 'O')
4542       )
4543    THEN
4544    NULL;
4545    --
4546    --
4547    
4548   l_ccid := AcctDerRule_7(
4549            p_application_id           => p_application_id
4550          , p_ae_header_id             => l_ae_header_id 
4551 , p_source_3 => p_source_3
4552          , x_transaction_coa_id       => l_adr_transaction_coa_id
4553          , x_accounting_coa_id        => l_adr_accounting_coa_id
4557 
4554          , x_value_type_code          => l_adr_value_type_code
4555          , p_side                     => 'NA'
4556    );
4558    xla_ae_lines_pkg.set_ccid(
4559     p_code_combination_id          => l_ccid
4560   , p_value_type_code              => l_adr_value_type_code
4561   , p_transaction_coa_id           => l_adr_transaction_coa_id
4562   , p_accounting_coa_id            => l_adr_accounting_coa_id
4563   , p_adr_code                     => 'DIST_CCID'
4564   , p_adr_type_code                => 'S'
4565   , p_component_type               => l_component_type
4566   , p_component_code               => l_component_code
4567   , p_component_type_code          => l_component_type_code
4568   , p_component_appl_id            => l_component_appl_id
4569   , p_amb_context_code             => l_amb_context_code
4570   , p_side                         => 'NA'
4571   );
4572 
4573 
4574    --
4575    --
4576    END IF;
4577    --
4578    -- Bug 4922099
4579    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
4580           (NVL(l_enc_upg_option, 'N') = 'O')
4581         ) AND
4582         (l_bflow_method_code = 'PRIOR_ENTRY')
4583       )
4584    THEN
4585       IF
4586       --
4587       1 = 2
4588       --
4589       THEN
4590       xla_accounting_err_pkg.build_message
4591                                     (p_appli_s_name            => 'XLA'
4592                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4593                                     ,p_token_1                 => 'LINE_NUMBER'
4594                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
4595                                     ,p_token_2                 => 'LINE_TYPE_NAME'
4596                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
4597                                                                              l_component_type
4598                                                                             ,l_component_code
4599                                                                             ,l_component_type_code
4600                                                                             ,l_component_appl_id
4601                                                                             ,l_amb_context_code
4602                                                                             ,l_entity_code
4603                                                                             ,l_event_class_code
4604                                                                            )
4605                                     ,p_token_3                 => 'OWNER'
4606                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
4607                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
4608                                                                           ,p_lookup_code    => l_component_type_code
4609                                                                          )
4610                                     ,p_token_4                 => 'PRODUCT_NAME'
4611                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
4612                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
4613                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
4614                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
4615                                     ,p_ae_header_id            =>  NULL
4616                                        );
4617 
4618         IF (C_LEVEL_ERROR>= g_log_level) THEN
4619                  trace
4620                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4621                       ,p_level    => C_LEVEL_ERROR
4622                       ,p_module   => l_log_module);
4623         END IF;
4624       END IF;
4625    END IF;
4626    --
4627    --
4628    ------------------------------------------------------------------------------------------------
4629    -- 4219869 Business Flow
4630    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
4631    -- Prior Entry.  Currently, the following code is always generated.
4632    ------------------------------------------------------------------------------------------------
4633    XLA_AE_LINES_PKG.ValidateCurrentLine;
4634 
4635    ------------------------------------------------------------------------------------
4636    -- 4219869 Business Flow
4637    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
4638    ------------------------------------------------------------------------------------
4639    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4640 
4641    ----------------------------------------------------------------------------------
4642    -- 4219869 Business Flow
4643    -- Update journal entry status -- Need to generate this within IF <condition>
4644    ----------------------------------------------------------------------------------
4645    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4646          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
4647          ,p_balance_type_code => l_balance_type_code
4648          );
4649 
4650    -------------------------------------------------------------------------------------------
4651    -- 4262811 - Generate the Accrual Reversal lines
4652    -------------------------------------------------------------------------------------------
4653    BEGIN
4654       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
4655                               (g_array_event(p_event_id).array_value_num('header_index'));
4659    EXCEPTION
4656       IF l_acc_rev_flag IS NULL THEN
4657          l_acc_rev_flag := 'N';
4658       END IF;
4660       WHEN OTHERS THEN
4661          l_acc_rev_flag := 'N';
4662    END;
4663    --
4664    IF (l_acc_rev_flag = 'Y') THEN
4665 
4666        -- 4645092  ------------------------------------------------------------------------------
4667        -- To allow MPA report to determine if it should generate report process
4668        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
4669        ------------------------------------------------------------------------------------------
4670 
4671        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
4672        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
4673    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
4674    -- call ADRs
4675    -- Bug 4922099
4676    --
4677    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4678         (NVL(l_actual_upg_option, 'N') = 'O') OR
4679         (NVL(l_enc_upg_option, 'N') = 'O')
4680       )
4681    THEN
4682    NULL;
4683    --
4684    --
4685    
4686   l_ccid := AcctDerRule_7(
4687            p_application_id           => p_application_id
4688          , p_ae_header_id             => l_ae_header_id 
4689 , p_source_3 => p_source_3
4690          , x_transaction_coa_id       => l_adr_transaction_coa_id
4691          , x_accounting_coa_id        => l_adr_accounting_coa_id
4692          , x_value_type_code          => l_adr_value_type_code
4693          , p_side                     => 'NA'
4694    );
4695 
4696    xla_ae_lines_pkg.set_ccid(
4697     p_code_combination_id          => l_ccid
4698   , p_value_type_code              => l_adr_value_type_code
4699   , p_transaction_coa_id           => l_adr_transaction_coa_id
4700   , p_accounting_coa_id            => l_adr_accounting_coa_id
4701   , p_adr_code                     => 'DIST_CCID'
4702   , p_adr_type_code                => 'S'
4703   , p_component_type               => l_component_type
4704   , p_component_code               => l_component_code
4705   , p_component_type_code          => l_component_type_code
4706   , p_component_appl_id            => l_component_appl_id
4707   , p_amb_context_code             => l_amb_context_code
4708   , p_side                         => 'NA'
4709   );
4710 
4711 
4712    --
4713    --
4714    END IF;
4715 
4716        --
4717        -- Update the line information that should be overwritten
4718        --
4719        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
4720                                          p_header_num   => 1);
4721        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
4722 
4723        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
4724 
4725        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
4726           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
4727        END IF;
4728 
4729       --
4730       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
4731       --
4732       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
4733           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
4734       ELSE
4735           ---------------------------------------------------------------------------------------------------
4736           -- 4262811a Switch Sign
4737           ---------------------------------------------------------------------------------------------------
4738           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
4739           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4740                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4741           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4742                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4743           -- 5132302
4744           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
4745                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4746 
4747       END IF;
4748 
4749       -- 4955764
4750       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4751       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
4752 
4753 
4754       XLA_AE_LINES_PKG.ValidateCurrentLine;
4755       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4756 
4757       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4758                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
4759                ,p_balance_type_code => l_balance_type_code);
4760 
4761    END IF;
4762 
4763    -----------------------------------------------------------------------------------------
4764    -- 4262811 Multiperiod Accounting
4765    -----------------------------------------------------------------------------------------
4766      -- No MPA option is assigned.
4767 
4768 
4769 END IF;
4770 END IF;
4771 --
4772 
4773 --
4774 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4775    trace
4776       (p_msg      => 'END of AcctLineType_21'
4777       ,p_level    => C_LEVEL_PROCEDURE
4778       ,p_module   => l_log_module);
4779 END IF;
4780 --
4781 EXCEPTION
4782   WHEN xla_exceptions_pkg.application_exception THEN
4783       RAISE;
4787 END AcctLineType_21;
4784   WHEN OTHERS THEN
4785        xla_exceptions_pkg.raise_message
4786            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_21');
4788 --
4789 
4790 ---------------------------------------
4791 --
4792 -- PRIVATE FUNCTION
4793 --         AcctLineType_22
4794 --
4795 ---------------------------------------
4796 PROCEDURE AcctLineType_22 (
4797   p_application_id        IN NUMBER
4798  ,p_event_id              IN NUMBER
4799  ,p_calculate_acctd_flag  IN VARCHAR2
4800  ,p_calculate_g_l_flag    IN VARCHAR2
4801  ,p_actual_flag           IN OUT VARCHAR2
4802  ,p_balance_type_code     OUT VARCHAR2
4803  ,p_gain_or_loss_ref      OUT VARCHAR2
4804  
4805 --Transaction Distribution GL Account
4806  , p_source_4            IN NUMBER
4807 --Bill To Customer Account Identifier
4808  , p_source_23            IN NUMBER
4809 --Bill To Customer Site Use Identifier
4810  , p_source_24            IN NUMBER
4811 --SLA Party Type
4812  , p_source_25            IN VARCHAR2
4813 --Transaction Distribution Account Class
4814  , p_source_26            IN VARCHAR2
4815 --Transaction Distribution Identifier
4816  , p_source_27            IN NUMBER
4817 --Transaction Distribution Type
4818  , p_source_28            IN VARCHAR2
4819 --Transaction Distribution Entered Amount
4820  , p_source_29            IN NUMBER
4821 --Transaction Currency Code
4822  , p_source_30            IN VARCHAR2
4823 --Transaction Exchange Date
4824  , p_source_31            IN DATE
4825 --Transaction Exchange Rate
4826  , p_source_32            IN NUMBER
4827 --Transaction Exchange Rate Type
4828  , p_source_33            IN VARCHAR2
4829 --Transaction Accounting Amount
4830  , p_source_34            IN NUMBER
4831 )
4832 IS
4833 
4834 l_component_type              VARCHAR2(80);
4835 l_component_code              VARCHAR2(30);
4836 l_component_type_code         VARCHAR2(1);
4837 l_component_appl_id           INTEGER;
4838 l_amb_context_code            VARCHAR2(30);
4839 l_entity_code                 VARCHAR2(30);
4840 l_event_class_code            VARCHAR2(30);
4841 l_ae_header_id                NUMBER;
4842 l_event_type_code             VARCHAR2(30);
4843 l_line_definition_code        VARCHAR2(30);
4844 l_line_definition_owner_code  VARCHAR2(1);
4845 --
4846 -- adr variables
4847 l_segment                     VARCHAR2(30);
4848 l_ccid                        NUMBER;
4849 l_adr_transaction_coa_id      NUMBER;
4850 l_adr_accounting_coa_id       NUMBER;
4851 l_adr_flexfield_segment_code  VARCHAR2(30);
4852 l_adr_flex_value_set_id       NUMBER;
4853 l_adr_value_type_code         VARCHAR2(30);
4854 l_adr_value_combination_id    NUMBER;
4855 l_adr_value_segment_code      VARCHAR2(30);
4856 
4857 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
4858 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
4859 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
4860 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
4861 
4862 -- 4262811 Variables ------------------------------------------------------------------------------------------
4863 l_entered_amt_idx             NUMBER;
4864 l_accted_amt_idx              NUMBER;
4865 l_acc_rev_flag                VARCHAR2(1);
4866 l_accrual_line_num            NUMBER;
4867 l_tmp_amt                     NUMBER;
4868 l_acc_rev_natural_side_code   VARCHAR2(1);
4869 
4870 l_num_entries                 NUMBER;
4871 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
4872 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
4873 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
4874 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
4875 l_recog_line_1                NUMBER;
4876 l_recog_line_2                NUMBER;
4877 
4878 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
4879 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
4880 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
4881 
4882 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
4883 
4884 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
4885 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
4886 
4887 ---------------------------------------------------------------------------------------------------------------
4888 
4889 
4890 --
4891 -- bulk performance
4892 --
4893 l_balance_type_code           VARCHAR2(1);
4894 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
4895 l_log_module                  VARCHAR2(240);
4896 
4897 --
4898 -- Upgrade strategy
4899 --
4900 l_actual_upg_option           VARCHAR2(1);
4901 l_enc_upg_option           VARCHAR2(1);
4902 
4903 --
4904 BEGIN
4905 --
4906 IF g_log_enabled THEN
4907       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_22';
4908 END IF;
4909 --
4910 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4911 
4912       trace
4913          (p_msg      => 'BEGIN of AcctLineType_22'
4914          ,p_level    => C_LEVEL_PROCEDURE
4915          ,p_module   => l_log_module);
4916 
4917 END IF;
4918 --
4919 l_component_type             := 'AMB_JLT';
4920 l_component_code             := 'CB_DEFAULT_REC';
4921 l_component_type_code        := 'S';
4922 l_component_appl_id          :=  222;
4923 l_amb_context_code           := 'DEFAULT';
4924 l_entity_code                := 'TRANSACTIONS';
4925 l_event_class_code           := 'CHARGEBACK';
4926 l_event_type_code            := 'CHARGEBACK_ALL';
4930 l_balance_type_code          := 'A';
4927 l_line_definition_owner_code := 'S';
4928 l_line_definition_code       := 'AR_CB_DEFAULT_ACCRUAL';
4929 --
4931 l_segment                     := NULL;
4932 l_ccid                        := NULL;
4933 l_adr_transaction_coa_id      := NULL;
4934 l_adr_accounting_coa_id       := NULL;
4935 l_adr_flexfield_segment_code  := NULL;
4936 l_adr_flex_value_set_id       := NULL;
4937 l_adr_value_type_code         := NULL;
4938 l_adr_value_combination_id    := NULL;
4939 l_adr_value_segment_code      := NULL;
4940 
4941 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
4942 l_bflow_class_code           := '';    -- 4219869 Business Flow
4943 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
4944 l_budgetary_control_flag     := 'N';
4945 
4946 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
4947 l_bflow_applied_to_amt       := NULL; -- 5132302
4948 l_entered_amt_idx            := NULL;          -- 4262811
4949 l_accted_amt_idx             := NULL;          -- 4262811
4950 l_acc_rev_flag               := NULL;          -- 4262811
4951 l_accrual_line_num           := NULL;          -- 4262811
4952 l_tmp_amt                    := NULL;          -- 4262811
4953 --
4954  
4955 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
4956     l_balance_type_code <> 'B' THEN
4957 IF NVL(p_source_26,'
4958 ') =  'REC'
4959  THEN 
4960 
4961    --
4962    XLA_AE_LINES_PKG.SetNewLine;
4963 
4964    p_balance_type_code          := l_balance_type_code;
4965    -- set the flag so later we will know whether the gain loss line needs to be created
4966    
4967    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
4968      p_actual_flag :='A';
4969    END IF;
4970 
4971    --
4972    -- bulk performance
4973    --
4974    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
4975                                       p_header_num   => 0); -- 4262811
4976    --
4977    -- set accounting line options
4978    --
4979    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
4980            p_natural_side_code          => 'D'
4981          , p_gain_or_loss_flag          => 'N'
4982          , p_gl_transfer_mode_code      => 'S'
4983          , p_acct_entry_type_code       => 'A'
4984          , p_switch_side_flag           => 'Y'
4985          , p_merge_duplicate_code       => 'A'
4986          );
4987    --
4988    l_acc_rev_natural_side_code := 'C';  -- 4262811
4989    -- 
4990    --
4991    -- set accounting line type info
4992    --
4993    xla_ae_lines_pkg.SetAcctLineType
4994       (p_component_type             => l_component_type
4995       ,p_event_type_code            => l_event_type_code
4996       ,p_line_definition_owner_code => l_line_definition_owner_code
4997       ,p_line_definition_code       => l_line_definition_code
4998       ,p_accounting_line_code       => l_component_code
4999       ,p_accounting_line_type_code  => l_component_type_code
5000       ,p_accounting_line_appl_id    => l_component_appl_id
5001       ,p_amb_context_code           => l_amb_context_code
5002       ,p_entity_code                => l_entity_code
5003       ,p_event_class_code           => l_event_class_code);
5004    --
5005    -- set accounting class
5006    --
5007    xla_ae_lines_pkg.SetAcctClass(
5008            p_accounting_class_code  => 'RECEIVABLE'
5009          , p_ae_header_id           => l_ae_header_id
5010          );
5011 
5012    --
5013    -- set rounding class
5014    --
5015    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
5016                       'RECEIVABLE';
5017 
5018    --
5019    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
5020    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
5021    --
5022    -- bulk performance
5023    --
5024    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
5025 
5026    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
5027       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
5028 
5029    -- 4955764
5030    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5031       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
5032 
5033    -- 4458381 Public Sector Enh
5034    
5035    --
5036    -- set accounting attributes for the line type
5037    --
5038    l_entered_amt_idx := 3;
5039    l_accted_amt_idx  := 8;
5040    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
5041    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
5042    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
5043    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
5044    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
5045    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
5046    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
5047    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
5048    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
5049    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
5050    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
5051    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
5052    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
5053    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
5057    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
5054    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
5055    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
5056    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
5058    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
5059    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
5060    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
5061    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
5062    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
5063 
5064    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
5065    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
5066 
5067    ---------------------------------------------------------------------------------------------------------------
5068    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
5069    ---------------------------------------------------------------------------------------------------------------
5070    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
5071 
5072    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5073    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5074 
5075    IF xla_accounting_cache_pkg.GetValueChar
5076          (p_source_code         => 'LEDGER_CATEGORY_CODE'
5077          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
5078    AND l_bflow_method_code = 'PRIOR_ENTRY'
5079 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
5080    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
5081          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
5082        )
5083    THEN
5084          xla_ae_lines_pkg.BflowUpgEntry
5085            (p_business_method_code    => l_bflow_method_code
5086            ,p_business_class_code     => l_bflow_class_code
5087            ,p_balance_type            => l_balance_type_code);
5088    ELSE
5089       NULL;
5090 -- No business flow processing for business flow method of NONE.
5091    END IF;
5092 
5093    --
5094    -- call analytical criteria
5095    --
5096    
5097    --
5098    -- call description
5099    --
5100    -- No description or it is inherited.
5101    --
5102    -- call ADRs
5103    -- Bug 4922099
5104    --
5105    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5106         (NVL(l_actual_upg_option, 'N') = 'O') OR
5107         (NVL(l_enc_upg_option, 'N') = 'O')
5108       )
5109    THEN
5110    NULL;
5111    --
5112    --
5113    
5114   l_ccid := AcctDerRule_16(
5115            p_application_id           => p_application_id
5116          , p_ae_header_id             => l_ae_header_id 
5117 , p_source_4 => p_source_4
5118          , x_transaction_coa_id       => l_adr_transaction_coa_id
5119          , x_accounting_coa_id        => l_adr_accounting_coa_id
5120          , x_value_type_code          => l_adr_value_type_code
5121          , p_side                     => 'NA'
5122    );
5123 
5124    xla_ae_lines_pkg.set_ccid(
5125     p_code_combination_id          => l_ccid
5126   , p_value_type_code              => l_adr_value_type_code
5127   , p_transaction_coa_id           => l_adr_transaction_coa_id
5128   , p_accounting_coa_id            => l_adr_accounting_coa_id
5129   , p_adr_code                     => 'TRX_DIST_CCID'
5130   , p_adr_type_code                => 'S'
5131   , p_component_type               => l_component_type
5132   , p_component_code               => l_component_code
5133   , p_component_type_code          => l_component_type_code
5134   , p_component_appl_id            => l_component_appl_id
5135   , p_amb_context_code             => l_amb_context_code
5136   , p_side                         => 'NA'
5137   );
5138 
5139 
5140    --
5141    --
5142    END IF;
5143    --
5144    -- Bug 4922099
5145    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
5146           (NVL(l_enc_upg_option, 'N') = 'O')
5147         ) AND
5148         (l_bflow_method_code = 'PRIOR_ENTRY')
5149       )
5150    THEN
5151       IF
5152       --
5153       1 = 2
5154       --
5155       THEN
5156       xla_accounting_err_pkg.build_message
5157                                     (p_appli_s_name            => 'XLA'
5158                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5159                                     ,p_token_1                 => 'LINE_NUMBER'
5160                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
5161                                     ,p_token_2                 => 'LINE_TYPE_NAME'
5162                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
5163                                                                              l_component_type
5164                                                                             ,l_component_code
5165                                                                             ,l_component_type_code
5166                                                                             ,l_component_appl_id
5167                                                                             ,l_amb_context_code
5168                                                                             ,l_entity_code
5169                                                                             ,l_event_class_code
5170                                                                            )
5171                                     ,p_token_3                 => 'OWNER'
5172                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
5173                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
5174                                                                           ,p_lookup_code    => l_component_type_code
5175                                                                          )
5176                                     ,p_token_4                 => 'PRODUCT_NAME'
5177                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
5178                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
5179                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
5180                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
5181                                     ,p_ae_header_id            =>  NULL
5182                                        );
5183 
5184         IF (C_LEVEL_ERROR>= g_log_level) THEN
5185                  trace
5186                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5187                       ,p_level    => C_LEVEL_ERROR
5188                       ,p_module   => l_log_module);
5189         END IF;
5190       END IF;
5191    END IF;
5192    --
5193    --
5194    ------------------------------------------------------------------------------------------------
5195    -- 4219869 Business Flow
5196    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
5197    -- Prior Entry.  Currently, the following code is always generated.
5198    ------------------------------------------------------------------------------------------------
5199    XLA_AE_LINES_PKG.ValidateCurrentLine;
5200 
5201    ------------------------------------------------------------------------------------
5202    -- 4219869 Business Flow
5203    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
5204    ------------------------------------------------------------------------------------
5205    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5206 
5207    ----------------------------------------------------------------------------------
5208    -- 4219869 Business Flow
5209    -- Update journal entry status -- Need to generate this within IF <condition>
5210    ----------------------------------------------------------------------------------
5211    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5212          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
5213          ,p_balance_type_code => l_balance_type_code
5214          );
5215 
5216    -------------------------------------------------------------------------------------------
5217    -- 4262811 - Generate the Accrual Reversal lines
5218    -------------------------------------------------------------------------------------------
5219    BEGIN
5220       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
5221                               (g_array_event(p_event_id).array_value_num('header_index'));
5222       IF l_acc_rev_flag IS NULL THEN
5223          l_acc_rev_flag := 'N';
5224       END IF;
5225    EXCEPTION
5226       WHEN OTHERS THEN
5227          l_acc_rev_flag := 'N';
5228    END;
5229    --
5230    IF (l_acc_rev_flag = 'Y') THEN
5231 
5232        -- 4645092  ------------------------------------------------------------------------------
5233        -- To allow MPA report to determine if it should generate report process
5234        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
5235        ------------------------------------------------------------------------------------------
5236 
5237        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
5238        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
5239    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
5240    -- call ADRs
5241    -- Bug 4922099
5242    --
5243    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5244         (NVL(l_actual_upg_option, 'N') = 'O') OR
5245         (NVL(l_enc_upg_option, 'N') = 'O')
5246       )
5247    THEN
5248    NULL;
5249    --
5250    --
5251    
5252   l_ccid := AcctDerRule_16(
5253            p_application_id           => p_application_id
5254          , p_ae_header_id             => l_ae_header_id 
5255 , p_source_4 => p_source_4
5256          , x_transaction_coa_id       => l_adr_transaction_coa_id
5257          , x_accounting_coa_id        => l_adr_accounting_coa_id
5258          , x_value_type_code          => l_adr_value_type_code
5259          , p_side                     => 'NA'
5260    );
5261 
5262    xla_ae_lines_pkg.set_ccid(
5266   , p_accounting_coa_id            => l_adr_accounting_coa_id
5263     p_code_combination_id          => l_ccid
5264   , p_value_type_code              => l_adr_value_type_code
5265   , p_transaction_coa_id           => l_adr_transaction_coa_id
5267   , p_adr_code                     => 'TRX_DIST_CCID'
5268   , p_adr_type_code                => 'S'
5269   , p_component_type               => l_component_type
5270   , p_component_code               => l_component_code
5271   , p_component_type_code          => l_component_type_code
5272   , p_component_appl_id            => l_component_appl_id
5273   , p_amb_context_code             => l_amb_context_code
5274   , p_side                         => 'NA'
5275   );
5276 
5277 
5278    --
5279    --
5280    END IF;
5281 
5282        --
5283        -- Update the line information that should be overwritten
5284        --
5285        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
5286                                          p_header_num   => 1);
5287        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
5288 
5289        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
5290 
5291        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
5292           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
5293        END IF;
5294 
5295       --
5296       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
5297       --
5298       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
5299           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
5300       ELSE
5301           ---------------------------------------------------------------------------------------------------
5302           -- 4262811a Switch Sign
5303           ---------------------------------------------------------------------------------------------------
5304           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
5305           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5306                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5307           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5308                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5309           -- 5132302
5310           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
5311                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5312 
5313       END IF;
5314 
5315       -- 4955764
5316       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5317       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
5318 
5319 
5320       XLA_AE_LINES_PKG.ValidateCurrentLine;
5321       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5322 
5323       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5324                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
5325                ,p_balance_type_code => l_balance_type_code);
5326 
5327    END IF;
5328 
5329    -----------------------------------------------------------------------------------------
5330    -- 4262811 Multiperiod Accounting
5331    -----------------------------------------------------------------------------------------
5332      -- No MPA option is assigned.
5333 
5334 
5335 END IF;
5336 END IF;
5337 --
5338 
5339 --
5340 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5341    trace
5342       (p_msg      => 'END of AcctLineType_22'
5343       ,p_level    => C_LEVEL_PROCEDURE
5344       ,p_module   => l_log_module);
5345 END IF;
5346 --
5347 EXCEPTION
5348   WHEN xla_exceptions_pkg.application_exception THEN
5349       RAISE;
5350   WHEN OTHERS THEN
5351        xla_exceptions_pkg.raise_message
5352            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_22');
5353 END AcctLineType_22;
5354 --
5355 
5356 ---------------------------------------
5357 --
5358 -- PRIVATE FUNCTION
5359 --         AcctLineType_23
5360 --
5361 ---------------------------------------
5362 PROCEDURE AcctLineType_23 (
5363   p_application_id        IN NUMBER
5364  ,p_event_id              IN NUMBER
5365  ,p_calculate_acctd_flag  IN VARCHAR2
5366  ,p_calculate_g_l_flag    IN VARCHAR2
5367  ,p_actual_flag           IN OUT VARCHAR2
5368  ,p_balance_type_code     OUT VARCHAR2
5369  ,p_gain_or_loss_ref      OUT VARCHAR2
5370  
5371 --Transaction Distribution GL Account
5372  , p_source_4            IN NUMBER
5373 --Bill To Customer Account Identifier
5374  , p_source_23            IN NUMBER
5375 --Bill To Customer Site Use Identifier
5376  , p_source_24            IN NUMBER
5377 --SLA Party Type
5378  , p_source_25            IN VARCHAR2
5379 --Transaction Distribution Account Class
5380  , p_source_26            IN VARCHAR2
5381 --Transaction Distribution Identifier
5382  , p_source_27            IN NUMBER
5383 --Transaction Distribution Type
5384  , p_source_28            IN VARCHAR2
5385 --Transaction Distribution Entered Amount
5386  , p_source_29            IN NUMBER
5387 --Transaction Currency Code
5388  , p_source_30            IN VARCHAR2
5389 --Transaction Exchange Date
5390  , p_source_31            IN DATE
5391 --Transaction Exchange Rate
5392  , p_source_32            IN NUMBER
5396  , p_source_34            IN NUMBER
5393 --Transaction Exchange Rate Type
5394  , p_source_33            IN VARCHAR2
5395 --Transaction Accounting Amount
5397 )
5398 IS
5399 
5400 l_component_type              VARCHAR2(80);
5401 l_component_code              VARCHAR2(30);
5402 l_component_type_code         VARCHAR2(1);
5403 l_component_appl_id           INTEGER;
5404 l_amb_context_code            VARCHAR2(30);
5405 l_entity_code                 VARCHAR2(30);
5406 l_event_class_code            VARCHAR2(30);
5407 l_ae_header_id                NUMBER;
5408 l_event_type_code             VARCHAR2(30);
5409 l_line_definition_code        VARCHAR2(30);
5410 l_line_definition_owner_code  VARCHAR2(1);
5411 --
5412 -- adr variables
5413 l_segment                     VARCHAR2(30);
5414 l_ccid                        NUMBER;
5415 l_adr_transaction_coa_id      NUMBER;
5416 l_adr_accounting_coa_id       NUMBER;
5417 l_adr_flexfield_segment_code  VARCHAR2(30);
5418 l_adr_flex_value_set_id       NUMBER;
5419 l_adr_value_type_code         VARCHAR2(30);
5420 l_adr_value_combination_id    NUMBER;
5421 l_adr_value_segment_code      VARCHAR2(30);
5422 
5423 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
5424 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
5425 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
5426 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
5427 
5428 -- 4262811 Variables ------------------------------------------------------------------------------------------
5429 l_entered_amt_idx             NUMBER;
5430 l_accted_amt_idx              NUMBER;
5431 l_acc_rev_flag                VARCHAR2(1);
5432 l_accrual_line_num            NUMBER;
5433 l_tmp_amt                     NUMBER;
5434 l_acc_rev_natural_side_code   VARCHAR2(1);
5435 
5436 l_num_entries                 NUMBER;
5437 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
5438 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
5439 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
5440 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
5441 l_recog_line_1                NUMBER;
5442 l_recog_line_2                NUMBER;
5443 
5444 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
5445 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
5446 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
5447 
5448 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
5449 
5450 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
5451 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
5452 
5453 ---------------------------------------------------------------------------------------------------------------
5454 
5455 
5456 --
5457 -- bulk performance
5458 --
5459 l_balance_type_code           VARCHAR2(1);
5460 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
5461 l_log_module                  VARCHAR2(240);
5462 
5463 --
5464 -- Upgrade strategy
5465 --
5466 l_actual_upg_option           VARCHAR2(1);
5467 l_enc_upg_option           VARCHAR2(1);
5468 
5469 --
5470 BEGIN
5471 --
5472 IF g_log_enabled THEN
5473       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_23';
5474 END IF;
5475 --
5476 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5477 
5478       trace
5479          (p_msg      => 'BEGIN of AcctLineType_23'
5480          ,p_level    => C_LEVEL_PROCEDURE
5481          ,p_module   => l_log_module);
5482 
5483 END IF;
5484 --
5485 l_component_type             := 'AMB_JLT';
5486 l_component_code             := 'CB_REV';
5487 l_component_type_code        := 'S';
5488 l_component_appl_id          :=  222;
5489 l_amb_context_code           := 'DEFAULT';
5490 l_entity_code                := 'TRANSACTIONS';
5491 l_event_class_code           := 'CHARGEBACK';
5492 l_event_type_code            := 'CHARGEBACK_ALL';
5493 l_line_definition_owner_code := 'S';
5494 l_line_definition_code       := 'AR_CB_DEFAULT_ACCRUAL';
5495 --
5496 l_balance_type_code          := 'A';
5497 l_segment                     := NULL;
5498 l_ccid                        := NULL;
5499 l_adr_transaction_coa_id      := NULL;
5500 l_adr_accounting_coa_id       := NULL;
5501 l_adr_flexfield_segment_code  := NULL;
5502 l_adr_flex_value_set_id       := NULL;
5503 l_adr_value_type_code         := NULL;
5504 l_adr_value_combination_id    := NULL;
5505 l_adr_value_segment_code      := NULL;
5506 
5507 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
5508 l_bflow_class_code           := '';    -- 4219869 Business Flow
5509 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
5510 l_budgetary_control_flag     := 'N';
5511 
5512 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
5513 l_bflow_applied_to_amt       := NULL; -- 5132302
5514 l_entered_amt_idx            := NULL;          -- 4262811
5515 l_accted_amt_idx             := NULL;          -- 4262811
5516 l_acc_rev_flag               := NULL;          -- 4262811
5517 l_accrual_line_num           := NULL;          -- 4262811
5518 l_tmp_amt                    := NULL;          -- 4262811
5519 --
5520  
5521 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
5522     l_balance_type_code <> 'B' THEN
5523 IF NVL(p_source_26,'
5524 ') =  'REV'
5525  THEN 
5526 
5527    --
5528    XLA_AE_LINES_PKG.SetNewLine;
5529 
5530    p_balance_type_code          := l_balance_type_code;
5531    -- set the flag so later we will know whether the gain loss line needs to be created
5532    
5533    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
5534      p_actual_flag :='A';
5535    END IF;
5536 
5537    --
5538    -- bulk performance
5539    --
5540    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
5541                                       p_header_num   => 0); -- 4262811
5542    --
5543    -- set accounting line options
5544    --
5545    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
5546            p_natural_side_code          => 'C'
5547          , p_gain_or_loss_flag          => 'N'
5548          , p_gl_transfer_mode_code      => 'S'
5549          , p_acct_entry_type_code       => 'A'
5550          , p_switch_side_flag           => 'Y'
5551          , p_merge_duplicate_code       => 'A'
5552          );
5553    --
5554    l_acc_rev_natural_side_code := 'D';  -- 4262811
5555    -- 
5556    --
5557    -- set accounting line type info
5558    --
5559    xla_ae_lines_pkg.SetAcctLineType
5560       (p_component_type             => l_component_type
5561       ,p_event_type_code            => l_event_type_code
5562       ,p_line_definition_owner_code => l_line_definition_owner_code
5563       ,p_line_definition_code       => l_line_definition_code
5564       ,p_accounting_line_code       => l_component_code
5565       ,p_accounting_line_type_code  => l_component_type_code
5566       ,p_accounting_line_appl_id    => l_component_appl_id
5567       ,p_amb_context_code           => l_amb_context_code
5568       ,p_entity_code                => l_entity_code
5569       ,p_event_class_code           => l_event_class_code);
5570    --
5571    -- set accounting class
5572    --
5573    xla_ae_lines_pkg.SetAcctClass(
5574            p_accounting_class_code  => 'REVENUE'
5575          , p_ae_header_id           => l_ae_header_id
5576          );
5577 
5578    --
5579    -- set rounding class
5580    --
5581    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
5582                       'RECEIVABLE';
5583 
5584    --
5585    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
5586    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
5587    --
5588    -- bulk performance
5589    --
5590    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
5591 
5592    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
5593       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
5594 
5595    -- 4955764
5596    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5597       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
5598 
5599    -- 4458381 Public Sector Enh
5600    
5601    --
5602    -- set accounting attributes for the line type
5603    --
5604    l_entered_amt_idx := 3;
5605    l_accted_amt_idx  := 8;
5606    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
5607    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
5608    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
5609    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
5610    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
5611    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
5612    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
5613    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
5614    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
5615    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
5616    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
5617    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
5618    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
5619    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
5620    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
5621    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
5622    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
5623    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
5624    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
5625    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
5626    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
5627    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
5628    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
5629 
5630    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
5631    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
5632 
5633    ---------------------------------------------------------------------------------------------------------------
5634    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
5635    ---------------------------------------------------------------------------------------------------------------
5636    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
5637 
5638    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5639    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5640 
5641    IF xla_accounting_cache_pkg.GetValueChar
5642          (p_source_code         => 'LEDGER_CATEGORY_CODE'
5643          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
5644    AND l_bflow_method_code = 'PRIOR_ENTRY'
5645 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
5646    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
5647          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
5648        )
5649    THEN
5650          xla_ae_lines_pkg.BflowUpgEntry
5651            (p_business_method_code    => l_bflow_method_code
5652            ,p_business_class_code     => l_bflow_class_code
5653            ,p_balance_type            => l_balance_type_code);
5654    ELSE
5655       NULL;
5656 -- No business flow processing for business flow method of NONE.
5657    END IF;
5658 
5659    --
5660    -- call analytical criteria
5661    --
5662    
5663    --
5664    -- call description
5665    --
5666    -- No description or it is inherited.
5667    --
5668    -- call ADRs
5669    -- Bug 4922099
5670    --
5671    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5672         (NVL(l_actual_upg_option, 'N') = 'O') OR
5673         (NVL(l_enc_upg_option, 'N') = 'O')
5674       )
5675    THEN
5676    NULL;
5677    --
5678    --
5679    
5680   l_ccid := AcctDerRule_16(
5681            p_application_id           => p_application_id
5682          , p_ae_header_id             => l_ae_header_id 
5683 , p_source_4 => p_source_4
5684          , x_transaction_coa_id       => l_adr_transaction_coa_id
5685          , x_accounting_coa_id        => l_adr_accounting_coa_id
5686          , x_value_type_code          => l_adr_value_type_code
5687          , p_side                     => 'NA'
5688    );
5689 
5690    xla_ae_lines_pkg.set_ccid(
5691     p_code_combination_id          => l_ccid
5692   , p_value_type_code              => l_adr_value_type_code
5693   , p_transaction_coa_id           => l_adr_transaction_coa_id
5694   , p_accounting_coa_id            => l_adr_accounting_coa_id
5695   , p_adr_code                     => 'TRX_DIST_CCID'
5696   , p_adr_type_code                => 'S'
5697   , p_component_type               => l_component_type
5698   , p_component_code               => l_component_code
5699   , p_component_type_code          => l_component_type_code
5700   , p_component_appl_id            => l_component_appl_id
5701   , p_amb_context_code             => l_amb_context_code
5702   , p_side                         => 'NA'
5703   );
5704 
5705 
5706    --
5707    --
5708    END IF;
5709    --
5710    -- Bug 4922099
5711    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
5712           (NVL(l_enc_upg_option, 'N') = 'O')
5713         ) AND
5714         (l_bflow_method_code = 'PRIOR_ENTRY')
5715       )
5716    THEN
5717       IF
5718       --
5719       1 = 2
5720       --
5721       THEN
5722       xla_accounting_err_pkg.build_message
5723                                     (p_appli_s_name            => 'XLA'
5724                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5725                                     ,p_token_1                 => 'LINE_NUMBER'
5726                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
5727                                     ,p_token_2                 => 'LINE_TYPE_NAME'
5728                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
5729                                                                              l_component_type
5730                                                                             ,l_component_code
5731                                                                             ,l_component_type_code
5732                                                                             ,l_component_appl_id
5733                                                                             ,l_amb_context_code
5734                                                                             ,l_entity_code
5735                                                                             ,l_event_class_code
5736                                                                            )
5737                                     ,p_token_3                 => 'OWNER'
5738                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
5739                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
5740                                                                           ,p_lookup_code    => l_component_type_code
5741                                                                          )
5742                                     ,p_token_4                 => 'PRODUCT_NAME'
5743                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
5744                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
5745                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
5746                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
5747                                     ,p_ae_header_id            =>  NULL
5748                                        );
5749 
5750         IF (C_LEVEL_ERROR>= g_log_level) THEN
5751                  trace
5752                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5753                       ,p_level    => C_LEVEL_ERROR
5754                       ,p_module   => l_log_module);
5755         END IF;
5756       END IF;
5757    END IF;
5758    --
5759    --
5760    ------------------------------------------------------------------------------------------------
5761    -- 4219869 Business Flow
5762    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
5763    -- Prior Entry.  Currently, the following code is always generated.
5764    ------------------------------------------------------------------------------------------------
5765    XLA_AE_LINES_PKG.ValidateCurrentLine;
5766 
5767    ------------------------------------------------------------------------------------
5768    -- 4219869 Business Flow
5769    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
5770    ------------------------------------------------------------------------------------
5771    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5772 
5773    ----------------------------------------------------------------------------------
5774    -- 4219869 Business Flow
5775    -- Update journal entry status -- Need to generate this within IF <condition>
5776    ----------------------------------------------------------------------------------
5777    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5778          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
5779          ,p_balance_type_code => l_balance_type_code
5780          );
5781 
5782    -------------------------------------------------------------------------------------------
5783    -- 4262811 - Generate the Accrual Reversal lines
5784    -------------------------------------------------------------------------------------------
5785    BEGIN
5786       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
5787                               (g_array_event(p_event_id).array_value_num('header_index'));
5788       IF l_acc_rev_flag IS NULL THEN
5789          l_acc_rev_flag := 'N';
5790       END IF;
5791    EXCEPTION
5792       WHEN OTHERS THEN
5793          l_acc_rev_flag := 'N';
5794    END;
5795    --
5796    IF (l_acc_rev_flag = 'Y') THEN
5797 
5798        -- 4645092  ------------------------------------------------------------------------------
5799        -- To allow MPA report to determine if it should generate report process
5800        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
5801        ------------------------------------------------------------------------------------------
5802 
5803        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
5804        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
5805    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
5806    -- call ADRs
5807    -- Bug 4922099
5808    --
5809    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5810         (NVL(l_actual_upg_option, 'N') = 'O') OR
5811         (NVL(l_enc_upg_option, 'N') = 'O')
5812       )
5813    THEN
5814    NULL;
5815    --
5816    --
5817    
5818   l_ccid := AcctDerRule_16(
5819            p_application_id           => p_application_id
5820          , p_ae_header_id             => l_ae_header_id 
5821 , p_source_4 => p_source_4
5822          , x_transaction_coa_id       => l_adr_transaction_coa_id
5823          , x_accounting_coa_id        => l_adr_accounting_coa_id
5824          , x_value_type_code          => l_adr_value_type_code
5825          , p_side                     => 'NA'
5826    );
5827 
5828    xla_ae_lines_pkg.set_ccid(
5829     p_code_combination_id          => l_ccid
5830   , p_value_type_code              => l_adr_value_type_code
5831   , p_transaction_coa_id           => l_adr_transaction_coa_id
5832   , p_accounting_coa_id            => l_adr_accounting_coa_id
5833   , p_adr_code                     => 'TRX_DIST_CCID'
5834   , p_adr_type_code                => 'S'
5835   , p_component_type               => l_component_type
5836   , p_component_code               => l_component_code
5837   , p_component_type_code          => l_component_type_code
5838   , p_component_appl_id            => l_component_appl_id
5839   , p_amb_context_code             => l_amb_context_code
5840   , p_side                         => 'NA'
5841   );
5842 
5843 
5844    --
5845    --
5846    END IF;
5847 
5848        --
5849        -- Update the line information that should be overwritten
5850        --
5851        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
5852                                          p_header_num   => 1);
5853        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
5854 
5855        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
5856 
5857        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
5858           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
5859        END IF;
5860 
5861       --
5862       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
5863       --
5864       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
5865           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
5866       ELSE
5867           ---------------------------------------------------------------------------------------------------
5868           -- 4262811a Switch Sign
5869           ---------------------------------------------------------------------------------------------------
5870           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
5871           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5872                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5873           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5874                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5875           -- 5132302
5876           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
5877                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5878 
5879       END IF;
5880 
5881       -- 4955764
5882       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5883       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
5884 
5885 
5886       XLA_AE_LINES_PKG.ValidateCurrentLine;
5887       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5888 
5889       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5890                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
5891                ,p_balance_type_code => l_balance_type_code);
5892 
5893    END IF;
5894 
5895    -----------------------------------------------------------------------------------------
5896    -- 4262811 Multiperiod Accounting
5897    -----------------------------------------------------------------------------------------
5898      -- No MPA option is assigned.
5899 
5900 
5901 END IF;
5902 END IF;
5903 --
5904 
5905 --
5906 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5907    trace
5908       (p_msg      => 'END of AcctLineType_23'
5909       ,p_level    => C_LEVEL_PROCEDURE
5910       ,p_module   => l_log_module);
5911 END IF;
5912 --
5913 EXCEPTION
5914   WHEN xla_exceptions_pkg.application_exception THEN
5915       RAISE;
5916   WHEN OTHERS THEN
5917        xla_exceptions_pkg.raise_message
5918            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_23');
5919 END AcctLineType_23;
5920 --
5921 
5922 ---------------------------------------
5923 --
5924 -- PRIVATE FUNCTION
5925 --         AcctLineType_24
5926 --
5927 ---------------------------------------
5928 PROCEDURE AcctLineType_24 (
5929   p_application_id        IN NUMBER
5930  ,p_event_id              IN NUMBER
5931  ,p_calculate_acctd_flag  IN VARCHAR2
5932  ,p_calculate_g_l_flag    IN VARCHAR2
5933  ,p_actual_flag           IN OUT VARCHAR2
5934  ,p_balance_type_code     OUT VARCHAR2
5935  ,p_gain_or_loss_ref      OUT VARCHAR2
5936  
5937 --Distribution GL Account
5938  , p_source_3            IN NUMBER
5939 --Distribution Source Type
5940  , p_source_13            IN VARCHAR2
5941 --Entered Amount
5942  , p_source_17            IN NUMBER
5943 --SLA Party Type
5944  , p_source_25            IN VARCHAR2
5945 --Credit Memo Distribution Identifier
5946  , p_source_35            IN NUMBER
5947 --Credit memo distributions type
5948  , p_source_36            IN VARCHAR2
5949 --Credit Memo Currency Code
5950  , p_source_37            IN VARCHAR2
5951 --Credit Memo Exchange Date
5952  , p_source_38            IN DATE
5953 --Credit Memo Exchange Rate
5954  , p_source_39            IN NUMBER
5955 --Credit Memo Exchange Rate Type
5956  , p_source_40            IN VARCHAR2
5957 --Gain Loss Reference
5958  , p_source_41            IN VARCHAR2
5959 --Credit Memo Accounting Amount
5960  , p_source_42            IN NUMBER
5961 --Credit Memo Bill To Customer Account Identifier
5962  , p_source_43            IN NUMBER
5963 --Credit Memo Bill To Customer Site Use Identifier
5964  , p_source_44            IN NUMBER
5965 --Credit Memo Tax Line Identifier
5966  , p_source_45            IN NUMBER
5967 )
5968 IS
5969 
5970 l_component_type              VARCHAR2(80);
5971 l_component_code              VARCHAR2(30);
5972 l_component_type_code         VARCHAR2(1);
5973 l_component_appl_id           INTEGER;
5974 l_amb_context_code            VARCHAR2(30);
5975 l_entity_code                 VARCHAR2(30);
5976 l_event_class_code            VARCHAR2(30);
5977 l_ae_header_id                NUMBER;
5978 l_event_type_code             VARCHAR2(30);
5979 l_line_definition_code        VARCHAR2(30);
5980 l_line_definition_owner_code  VARCHAR2(1);
5981 --
5982 -- adr variables
5983 l_segment                     VARCHAR2(30);
5984 l_ccid                        NUMBER;
5985 l_adr_transaction_coa_id      NUMBER;
5986 l_adr_accounting_coa_id       NUMBER;
5987 l_adr_flexfield_segment_code  VARCHAR2(30);
5988 l_adr_flex_value_set_id       NUMBER;
5989 l_adr_value_type_code         VARCHAR2(30);
5990 l_adr_value_combination_id    NUMBER;
5991 l_adr_value_segment_code      VARCHAR2(30);
5992 
5993 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
5994 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
5998 -- 4262811 Variables ------------------------------------------------------------------------------------------
5995 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
5996 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
5997 
5999 l_entered_amt_idx             NUMBER;
6000 l_accted_amt_idx              NUMBER;
6001 l_acc_rev_flag                VARCHAR2(1);
6002 l_accrual_line_num            NUMBER;
6003 l_tmp_amt                     NUMBER;
6004 l_acc_rev_natural_side_code   VARCHAR2(1);
6005 
6006 l_num_entries                 NUMBER;
6007 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
6008 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
6009 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
6010 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
6011 l_recog_line_1                NUMBER;
6012 l_recog_line_2                NUMBER;
6013 
6014 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
6015 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
6016 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
6017 
6018 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
6019 
6020 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
6021 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
6022 
6023 ---------------------------------------------------------------------------------------------------------------
6024 
6025 
6026 --
6027 -- bulk performance
6028 --
6029 l_balance_type_code           VARCHAR2(1);
6030 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
6031 l_log_module                  VARCHAR2(240);
6032 
6033 --
6034 -- Upgrade strategy
6035 --
6036 l_actual_upg_option           VARCHAR2(1);
6037 l_enc_upg_option           VARCHAR2(1);
6038 
6039 --
6040 BEGIN
6041 --
6042 IF g_log_enabled THEN
6043       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_24';
6044 END IF;
6045 --
6046 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6047 
6048       trace
6049          (p_msg      => 'BEGIN of AcctLineType_24'
6050          ,p_level    => C_LEVEL_PROCEDURE
6051          ,p_module   => l_log_module);
6052 
6053 END IF;
6054 --
6055 l_component_type             := 'AMB_JLT';
6056 l_component_code             := 'CM_APP_DEFAULT_REC';
6057 l_component_type_code        := 'S';
6058 l_component_appl_id          :=  222;
6059 l_amb_context_code           := 'DEFAULT';
6060 l_entity_code                := 'TRANSACTIONS';
6061 l_event_class_code           := 'CREDIT_MEMO';
6062 l_event_type_code            := 'CREDIT_MEMO_ALL';
6063 l_line_definition_owner_code := 'S';
6064 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
6065 --
6066 l_balance_type_code          := 'A';
6067 l_segment                     := NULL;
6068 l_ccid                        := NULL;
6069 l_adr_transaction_coa_id      := NULL;
6070 l_adr_accounting_coa_id       := NULL;
6071 l_adr_flexfield_segment_code  := NULL;
6072 l_adr_flex_value_set_id       := NULL;
6073 l_adr_value_type_code         := NULL;
6074 l_adr_value_combination_id    := NULL;
6075 l_adr_value_segment_code      := NULL;
6076 
6077 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
6078 l_bflow_class_code           := '';    -- 4219869 Business Flow
6079 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
6080 l_budgetary_control_flag     := 'N';
6081 
6082 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
6083 l_bflow_applied_to_amt       := NULL; -- 5132302
6084 l_entered_amt_idx            := NULL;          -- 4262811
6085 l_accted_amt_idx             := NULL;          -- 4262811
6086 l_acc_rev_flag               := NULL;          -- 4262811
6087 l_accrual_line_num           := NULL;          -- 4262811
6088 l_tmp_amt                    := NULL;          -- 4262811
6089 --
6090  
6091 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
6092     l_balance_type_code <> 'B' THEN
6093 IF NVL(p_source_13,'
6094 ') =  'REC'
6095  THEN 
6096 
6097    --
6098    XLA_AE_LINES_PKG.SetNewLine;
6099 
6100    p_balance_type_code          := l_balance_type_code;
6101    -- set the flag so later we will know whether the gain loss line needs to be created
6102    
6103    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
6104      p_actual_flag :='A';
6105    END IF;
6106 
6107    --
6108    -- bulk performance
6109    --
6110    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
6111                                       p_header_num   => 0); -- 4262811
6112    --
6113    -- set accounting line options
6114    --
6115    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
6116            p_natural_side_code          => 'C'
6117          , p_gain_or_loss_flag          => 'N'
6118          , p_gl_transfer_mode_code      => 'S'
6119          , p_acct_entry_type_code       => 'A'
6120          , p_switch_side_flag           => 'Y'
6121          , p_merge_duplicate_code       => 'A'
6122          );
6123    --
6124    l_acc_rev_natural_side_code := 'D';  -- 4262811
6125    -- 
6126    --
6127    -- set accounting line type info
6128    --
6129    xla_ae_lines_pkg.SetAcctLineType
6130       (p_component_type             => l_component_type
6131       ,p_event_type_code            => l_event_type_code
6132       ,p_line_definition_owner_code => l_line_definition_owner_code
6133       ,p_line_definition_code       => l_line_definition_code
6134       ,p_accounting_line_code       => l_component_code
6135       ,p_accounting_line_type_code  => l_component_type_code
6136       ,p_accounting_line_appl_id    => l_component_appl_id
6137       ,p_amb_context_code           => l_amb_context_code
6138       ,p_entity_code                => l_entity_code
6139       ,p_event_class_code           => l_event_class_code);
6140    --
6141    -- set accounting class
6142    --
6143    xla_ae_lines_pkg.SetAcctClass(
6144            p_accounting_class_code  => 'RECEIVABLE'
6145          , p_ae_header_id           => l_ae_header_id
6146          );
6147 
6148    --
6149    -- set rounding class
6150    --
6151    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
6152                       'RECEIVABLE';
6153 
6154    --
6155    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
6156    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
6157    --
6158    -- bulk performance
6159    --
6160    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
6161 
6162    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
6163       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
6164 
6165    -- 4955764
6166    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6167       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
6168 
6169    -- 4458381 Public Sector Enh
6170    
6171    --
6172    -- set accounting attributes for the line type
6173    --
6174    l_entered_amt_idx := 3;
6175    l_accted_amt_idx  := 9;
6176    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
6177    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
6178    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_35);
6179    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
6180    l_rec_acct_attrs.array_char_value(2)  := p_source_36;
6181    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
6182    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
6183    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
6184    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
6185    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
6186    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
6187    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
6188    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
6189    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
6190    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
6191    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
6192    l_rec_acct_attrs.array_char_value(8)  := p_source_41;
6193    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
6194    l_rec_acct_attrs.array_num_value(9)  := p_source_42;
6195    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
6196    l_rec_acct_attrs.array_num_value(10)  := p_source_43;
6197    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
6198    l_rec_acct_attrs.array_num_value(11)  := p_source_44;
6199    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
6200    l_rec_acct_attrs.array_char_value(12)  := p_source_25;
6201    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
6202    l_rec_acct_attrs.array_num_value(13)  := p_source_45;
6203 
6204    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
6205    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
6206 
6207    ---------------------------------------------------------------------------------------------------------------
6208    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
6209    ---------------------------------------------------------------------------------------------------------------
6210    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
6211 
6212    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6213    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6214 
6215    IF xla_accounting_cache_pkg.GetValueChar
6216          (p_source_code         => 'LEDGER_CATEGORY_CODE'
6217          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
6218    AND l_bflow_method_code = 'PRIOR_ENTRY'
6219 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
6220    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
6221          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
6222        )
6223    THEN
6224          xla_ae_lines_pkg.BflowUpgEntry
6225            (p_business_method_code    => l_bflow_method_code
6226            ,p_business_class_code     => l_bflow_class_code
6227            ,p_balance_type            => l_balance_type_code);
6228    ELSE
6229       NULL;
6230 -- No business flow processing for business flow method of NONE.
6231    END IF;
6232 
6233    --
6234    -- call analytical criteria
6235    --
6236    
6237    --
6238    -- call description
6239    --
6240    -- No description or it is inherited.
6241    --
6242    -- call ADRs
6243    -- Bug 4922099
6244    --
6245    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
6246         (NVL(l_actual_upg_option, 'N') = 'O') OR
6247         (NVL(l_enc_upg_option, 'N') = 'O')
6248       )
6249    THEN
6250    NULL;
6251    --
6252    --
6253    
6254   l_ccid := AcctDerRule_7(
6255            p_application_id           => p_application_id
6256          , p_ae_header_id             => l_ae_header_id 
6257 , p_source_3 => p_source_3
6258          , x_transaction_coa_id       => l_adr_transaction_coa_id
6259          , x_accounting_coa_id        => l_adr_accounting_coa_id
6260          , x_value_type_code          => l_adr_value_type_code
6261          , p_side                     => 'NA'
6262    );
6263 
6264    xla_ae_lines_pkg.set_ccid(
6265     p_code_combination_id          => l_ccid
6266   , p_value_type_code              => l_adr_value_type_code
6267   , p_transaction_coa_id           => l_adr_transaction_coa_id
6268   , p_accounting_coa_id            => l_adr_accounting_coa_id
6269   , p_adr_code                     => 'DIST_CCID'
6270   , p_adr_type_code                => 'S'
6271   , p_component_type               => l_component_type
6272   , p_component_code               => l_component_code
6273   , p_component_type_code          => l_component_type_code
6274   , p_component_appl_id            => l_component_appl_id
6275   , p_amb_context_code             => l_amb_context_code
6276   , p_side                         => 'NA'
6277   );
6278 
6279 
6280    --
6281    --
6282    END IF;
6283    --
6284    -- Bug 4922099
6285    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
6286           (NVL(l_enc_upg_option, 'N') = 'O')
6287         ) AND
6288         (l_bflow_method_code = 'PRIOR_ENTRY')
6289       )
6290    THEN
6291       IF
6292       --
6293       1 = 2
6294       --
6295       THEN
6296       xla_accounting_err_pkg.build_message
6297                                     (p_appli_s_name            => 'XLA'
6298                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6299                                     ,p_token_1                 => 'LINE_NUMBER'
6300                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
6301                                     ,p_token_2                 => 'LINE_TYPE_NAME'
6302                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
6303                                                                              l_component_type
6304                                                                             ,l_component_code
6305                                                                             ,l_component_type_code
6306                                                                             ,l_component_appl_id
6307                                                                             ,l_amb_context_code
6308                                                                             ,l_entity_code
6309                                                                             ,l_event_class_code
6310                                                                            )
6311                                     ,p_token_3                 => 'OWNER'
6312                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
6313                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
6314                                                                           ,p_lookup_code    => l_component_type_code
6315                                                                          )
6316                                     ,p_token_4                 => 'PRODUCT_NAME'
6317                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
6318                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
6319                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
6320                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
6321                                     ,p_ae_header_id            =>  NULL
6322                                        );
6323 
6324         IF (C_LEVEL_ERROR>= g_log_level) THEN
6325                  trace
6326                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6327                       ,p_level    => C_LEVEL_ERROR
6328                       ,p_module   => l_log_module);
6329         END IF;
6330       END IF;
6331    END IF;
6332    --
6333    --
6334    ------------------------------------------------------------------------------------------------
6335    -- 4219869 Business Flow
6336    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
6337    -- Prior Entry.  Currently, the following code is always generated.
6338    ------------------------------------------------------------------------------------------------
6339    XLA_AE_LINES_PKG.ValidateCurrentLine;
6340 
6341    ------------------------------------------------------------------------------------
6342    -- 4219869 Business Flow
6343    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
6344    ------------------------------------------------------------------------------------
6345    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6346 
6347    ----------------------------------------------------------------------------------
6348    -- 4219869 Business Flow
6349    -- Update journal entry status -- Need to generate this within IF <condition>
6350    ----------------------------------------------------------------------------------
6351    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6352          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
6353          ,p_balance_type_code => l_balance_type_code
6354          );
6358    -------------------------------------------------------------------------------------------
6355 
6356    -------------------------------------------------------------------------------------------
6357    -- 4262811 - Generate the Accrual Reversal lines
6359    BEGIN
6360       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
6361                               (g_array_event(p_event_id).array_value_num('header_index'));
6362       IF l_acc_rev_flag IS NULL THEN
6363          l_acc_rev_flag := 'N';
6364       END IF;
6365    EXCEPTION
6366       WHEN OTHERS THEN
6367          l_acc_rev_flag := 'N';
6368    END;
6369    --
6370    IF (l_acc_rev_flag = 'Y') THEN
6371 
6372        -- 4645092  ------------------------------------------------------------------------------
6373        -- To allow MPA report to determine if it should generate report process
6374        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
6375        ------------------------------------------------------------------------------------------
6376 
6377        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
6378        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
6379    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
6380    -- call ADRs
6381    -- Bug 4922099
6382    --
6383    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
6384         (NVL(l_actual_upg_option, 'N') = 'O') OR
6385         (NVL(l_enc_upg_option, 'N') = 'O')
6386       )
6387    THEN
6388    NULL;
6389    --
6390    --
6391    
6392   l_ccid := AcctDerRule_7(
6393            p_application_id           => p_application_id
6394          , p_ae_header_id             => l_ae_header_id 
6395 , p_source_3 => p_source_3
6396          , x_transaction_coa_id       => l_adr_transaction_coa_id
6397          , x_accounting_coa_id        => l_adr_accounting_coa_id
6398          , x_value_type_code          => l_adr_value_type_code
6399          , p_side                     => 'NA'
6400    );
6401 
6402    xla_ae_lines_pkg.set_ccid(
6403     p_code_combination_id          => l_ccid
6404   , p_value_type_code              => l_adr_value_type_code
6405   , p_transaction_coa_id           => l_adr_transaction_coa_id
6406   , p_accounting_coa_id            => l_adr_accounting_coa_id
6407   , p_adr_code                     => 'DIST_CCID'
6408   , p_adr_type_code                => 'S'
6409   , p_component_type               => l_component_type
6410   , p_component_code               => l_component_code
6411   , p_component_type_code          => l_component_type_code
6412   , p_component_appl_id            => l_component_appl_id
6413   , p_amb_context_code             => l_amb_context_code
6414   , p_side                         => 'NA'
6415   );
6416 
6417 
6418    --
6419    --
6420    END IF;
6421 
6422        --
6423        -- Update the line information that should be overwritten
6424        --
6425        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
6426                                          p_header_num   => 1);
6427        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
6428 
6429        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
6430 
6431        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
6432           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
6433        END IF;
6434 
6435       --
6436       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
6437       --
6438       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
6439           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
6440       ELSE
6441           ---------------------------------------------------------------------------------------------------
6442           -- 4262811a Switch Sign
6443           ---------------------------------------------------------------------------------------------------
6444           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
6445           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6446                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6447           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6448                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6449           -- 5132302
6450           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
6451                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6452 
6453       END IF;
6454 
6455       -- 4955764
6456       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6457       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
6458 
6459 
6460       XLA_AE_LINES_PKG.ValidateCurrentLine;
6461       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6462 
6463       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6464                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
6465                ,p_balance_type_code => l_balance_type_code);
6466 
6467    END IF;
6468 
6469    -----------------------------------------------------------------------------------------
6470    -- 4262811 Multiperiod Accounting
6471    -----------------------------------------------------------------------------------------
6475 END IF;
6472      -- No MPA option is assigned.
6473 
6474 
6476 END IF;
6477 --
6478 
6479 --
6480 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6481    trace
6482       (p_msg      => 'END of AcctLineType_24'
6483       ,p_level    => C_LEVEL_PROCEDURE
6484       ,p_module   => l_log_module);
6485 END IF;
6486 --
6487 EXCEPTION
6488   WHEN xla_exceptions_pkg.application_exception THEN
6489       RAISE;
6490   WHEN OTHERS THEN
6491        xla_exceptions_pkg.raise_message
6492            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_24');
6493 END AcctLineType_24;
6494 --
6495 
6496 ---------------------------------------
6497 --
6498 -- PRIVATE FUNCTION
6499 --         AcctLineType_25
6500 --
6501 ---------------------------------------
6502 PROCEDURE AcctLineType_25 (
6503   p_application_id        IN NUMBER
6504  ,p_event_id              IN NUMBER
6505  ,p_calculate_acctd_flag  IN VARCHAR2
6506  ,p_calculate_g_l_flag    IN VARCHAR2
6507  ,p_actual_flag           IN OUT VARCHAR2
6508  ,p_balance_type_code     OUT VARCHAR2
6509  ,p_gain_or_loss_ref      OUT VARCHAR2
6510  
6511 --Distribution GL Account
6512  , p_source_3            IN NUMBER
6513 --Distribution Source Type
6514  , p_source_13            IN VARCHAR2
6515 --Receivable Activity Type
6516  , p_source_14            IN VARCHAR2
6517 --Entered Amount
6518  , p_source_17            IN NUMBER
6519 --SLA Party Type
6520  , p_source_25            IN VARCHAR2
6521 --Credit Memo Distribution Identifier
6522  , p_source_35            IN NUMBER
6523 --Credit memo distributions type
6524  , p_source_36            IN VARCHAR2
6525 --Credit Memo Currency Code
6526  , p_source_37            IN VARCHAR2
6527 --Credit Memo Exchange Date
6528  , p_source_38            IN DATE
6529 --Credit Memo Exchange Rate
6530  , p_source_39            IN NUMBER
6531 --Credit Memo Exchange Rate Type
6532  , p_source_40            IN VARCHAR2
6533 --Gain Loss Reference
6534  , p_source_41            IN VARCHAR2
6535 --Credit Memo Accounting Amount
6536  , p_source_42            IN NUMBER
6537 --Credit Memo Bill To Customer Account Identifier
6538  , p_source_43            IN NUMBER
6539 --Credit Memo Bill To Customer Site Use Identifier
6540  , p_source_44            IN NUMBER
6541 --Credit Memo Tax Line Identifier
6542  , p_source_45            IN NUMBER
6543 )
6544 IS
6545 
6546 l_component_type              VARCHAR2(80);
6547 l_component_code              VARCHAR2(30);
6548 l_component_type_code         VARCHAR2(1);
6549 l_component_appl_id           INTEGER;
6550 l_amb_context_code            VARCHAR2(30);
6551 l_entity_code                 VARCHAR2(30);
6552 l_event_class_code            VARCHAR2(30);
6553 l_ae_header_id                NUMBER;
6554 l_event_type_code             VARCHAR2(30);
6555 l_line_definition_code        VARCHAR2(30);
6556 l_line_definition_owner_code  VARCHAR2(1);
6557 --
6558 -- adr variables
6559 l_segment                     VARCHAR2(30);
6560 l_ccid                        NUMBER;
6561 l_adr_transaction_coa_id      NUMBER;
6562 l_adr_accounting_coa_id       NUMBER;
6563 l_adr_flexfield_segment_code  VARCHAR2(30);
6564 l_adr_flex_value_set_id       NUMBER;
6565 l_adr_value_type_code         VARCHAR2(30);
6566 l_adr_value_combination_id    NUMBER;
6567 l_adr_value_segment_code      VARCHAR2(30);
6568 
6569 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
6570 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
6571 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
6572 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
6573 
6574 -- 4262811 Variables ------------------------------------------------------------------------------------------
6575 l_entered_amt_idx             NUMBER;
6576 l_accted_amt_idx              NUMBER;
6577 l_acc_rev_flag                VARCHAR2(1);
6578 l_accrual_line_num            NUMBER;
6579 l_tmp_amt                     NUMBER;
6580 l_acc_rev_natural_side_code   VARCHAR2(1);
6581 
6582 l_num_entries                 NUMBER;
6583 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
6584 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
6585 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
6586 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
6587 l_recog_line_1                NUMBER;
6588 l_recog_line_2                NUMBER;
6589 
6590 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
6591 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
6592 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
6593 
6594 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
6595 
6596 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
6597 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
6598 
6599 ---------------------------------------------------------------------------------------------------------------
6600 
6601 
6602 --
6603 -- bulk performance
6604 --
6605 l_balance_type_code           VARCHAR2(1);
6606 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
6607 l_log_module                  VARCHAR2(240);
6608 
6609 --
6610 -- Upgrade strategy
6611 --
6612 l_actual_upg_option           VARCHAR2(1);
6613 l_enc_upg_option           VARCHAR2(1);
6614 
6615 --
6616 BEGIN
6617 --
6618 IF g_log_enabled THEN
6619       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_25';
6620 END IF;
6624       trace
6621 --
6622 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6623 
6625          (p_msg      => 'BEGIN of AcctLineType_25'
6626          ,p_level    => C_LEVEL_PROCEDURE
6627          ,p_module   => l_log_module);
6628 
6629 END IF;
6630 --
6631 l_component_type             := 'AMB_JLT';
6632 l_component_code             := 'CM_APP_REFUND';
6633 l_component_type_code        := 'S';
6634 l_component_appl_id          :=  222;
6635 l_amb_context_code           := 'DEFAULT';
6636 l_entity_code                := 'TRANSACTIONS';
6637 l_event_class_code           := 'CREDIT_MEMO';
6638 l_event_type_code            := 'CREDIT_MEMO_ALL';
6639 l_line_definition_owner_code := 'S';
6640 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
6641 --
6642 l_balance_type_code          := 'A';
6643 l_segment                     := NULL;
6644 l_ccid                        := NULL;
6645 l_adr_transaction_coa_id      := NULL;
6646 l_adr_accounting_coa_id       := NULL;
6647 l_adr_flexfield_segment_code  := NULL;
6648 l_adr_flex_value_set_id       := NULL;
6649 l_adr_value_type_code         := NULL;
6650 l_adr_value_combination_id    := NULL;
6651 l_adr_value_segment_code      := NULL;
6652 
6653 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
6654 l_bflow_class_code           := '';    -- 4219869 Business Flow
6655 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
6656 l_budgetary_control_flag     := 'N';
6657 
6658 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
6659 l_bflow_applied_to_amt       := NULL; -- 5132302
6660 l_entered_amt_idx            := NULL;          -- 4262811
6661 l_accted_amt_idx             := NULL;          -- 4262811
6662 l_acc_rev_flag               := NULL;          -- 4262811
6663 l_accrual_line_num           := NULL;          -- 4262811
6664 l_tmp_amt                    := NULL;          -- 4262811
6665 --
6666  
6667 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
6668     l_balance_type_code <> 'B' THEN
6669 IF (NVL(p_source_13,'
6670 ') =  'ACTIVITY' AND 
6671 NVL(p_source_14,'
6672 ') =  'REFUND') OR 
6673 (NVL(p_source_13,'
6674 ') =  'ACTIVITY' AND 
6675 NVL(p_source_14,'
6676 ') =  'CM_REFUND')
6677  THEN 
6678 
6679    --
6680    XLA_AE_LINES_PKG.SetNewLine;
6681 
6682    p_balance_type_code          := l_balance_type_code;
6683    -- set the flag so later we will know whether the gain loss line needs to be created
6684    
6685    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
6686      p_actual_flag :='A';
6687    END IF;
6688 
6689    --
6690    -- bulk performance
6691    --
6692    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
6693                                       p_header_num   => 0); -- 4262811
6694    --
6695    -- set accounting line options
6696    --
6697    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
6698            p_natural_side_code          => 'C'
6699          , p_gain_or_loss_flag          => 'N'
6700          , p_gl_transfer_mode_code      => 'S'
6701          , p_acct_entry_type_code       => 'A'
6702          , p_switch_side_flag           => 'Y'
6703          , p_merge_duplicate_code       => 'A'
6704          );
6705    --
6706    l_acc_rev_natural_side_code := 'D';  -- 4262811
6707    -- 
6708    --
6709    -- set accounting line type info
6710    --
6711    xla_ae_lines_pkg.SetAcctLineType
6712       (p_component_type             => l_component_type
6713       ,p_event_type_code            => l_event_type_code
6714       ,p_line_definition_owner_code => l_line_definition_owner_code
6715       ,p_line_definition_code       => l_line_definition_code
6716       ,p_accounting_line_code       => l_component_code
6717       ,p_accounting_line_type_code  => l_component_type_code
6718       ,p_accounting_line_appl_id    => l_component_appl_id
6719       ,p_amb_context_code           => l_amb_context_code
6720       ,p_entity_code                => l_entity_code
6721       ,p_event_class_code           => l_event_class_code);
6722    --
6723    -- set accounting class
6724    --
6725    xla_ae_lines_pkg.SetAcctClass(
6726            p_accounting_class_code  => 'REFUND'
6727          , p_ae_header_id           => l_ae_header_id
6728          );
6729 
6730    --
6731    -- set rounding class
6732    --
6733    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
6734                       'REFUND';
6735 
6736    --
6737    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
6738    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
6739    --
6740    -- bulk performance
6741    --
6742    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
6743 
6744    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
6745       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
6746 
6747    -- 4955764
6748    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6749       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
6750 
6751    -- 4458381 Public Sector Enh
6752    
6753    --
6754    -- set accounting attributes for the line type
6755    --
6756    l_entered_amt_idx := 3;
6757    l_accted_amt_idx  := 9;
6758    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
6759    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
6760    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_35);
6764    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
6761    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
6762    l_rec_acct_attrs.array_char_value(2)  := p_source_36;
6763    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
6765    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
6766    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
6767    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
6768    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
6769    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
6770    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
6771    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
6772    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
6773    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
6774    l_rec_acct_attrs.array_char_value(8)  := p_source_41;
6775    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
6776    l_rec_acct_attrs.array_num_value(9)  := p_source_42;
6777    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
6778    l_rec_acct_attrs.array_num_value(10)  := p_source_43;
6779    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
6780    l_rec_acct_attrs.array_num_value(11)  := p_source_44;
6781    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
6782    l_rec_acct_attrs.array_char_value(12)  := p_source_25;
6783    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
6784    l_rec_acct_attrs.array_num_value(13)  := p_source_45;
6785 
6786    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
6787    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
6788 
6789    ---------------------------------------------------------------------------------------------------------------
6790    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
6791    ---------------------------------------------------------------------------------------------------------------
6792    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
6793 
6794    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6795    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6796 
6797    IF xla_accounting_cache_pkg.GetValueChar
6798          (p_source_code         => 'LEDGER_CATEGORY_CODE'
6799          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
6800    AND l_bflow_method_code = 'PRIOR_ENTRY'
6801 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
6802    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
6803          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
6804        )
6805    THEN
6806          xla_ae_lines_pkg.BflowUpgEntry
6807            (p_business_method_code    => l_bflow_method_code
6808            ,p_business_class_code     => l_bflow_class_code
6809            ,p_balance_type            => l_balance_type_code);
6810    ELSE
6811       NULL;
6812 -- No business flow processing for business flow method of NONE.
6813    END IF;
6814 
6815    --
6816    -- call analytical criteria
6817    --
6818    
6819    --
6820    -- call description
6821    --
6822    -- No description or it is inherited.
6823    --
6824    -- call ADRs
6825    -- Bug 4922099
6826    --
6827    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
6828         (NVL(l_actual_upg_option, 'N') = 'O') OR
6829         (NVL(l_enc_upg_option, 'N') = 'O')
6830       )
6831    THEN
6832    NULL;
6833    --
6834    --
6835    
6836   l_ccid := AcctDerRule_7(
6837            p_application_id           => p_application_id
6838          , p_ae_header_id             => l_ae_header_id 
6839 , p_source_3 => p_source_3
6840          , x_transaction_coa_id       => l_adr_transaction_coa_id
6841          , x_accounting_coa_id        => l_adr_accounting_coa_id
6842          , x_value_type_code          => l_adr_value_type_code
6843          , p_side                     => 'NA'
6844    );
6845 
6846    xla_ae_lines_pkg.set_ccid(
6847     p_code_combination_id          => l_ccid
6848   , p_value_type_code              => l_adr_value_type_code
6849   , p_transaction_coa_id           => l_adr_transaction_coa_id
6850   , p_accounting_coa_id            => l_adr_accounting_coa_id
6851   , p_adr_code                     => 'DIST_CCID'
6852   , p_adr_type_code                => 'S'
6853   , p_component_type               => l_component_type
6854   , p_component_code               => l_component_code
6855   , p_component_type_code          => l_component_type_code
6856   , p_component_appl_id            => l_component_appl_id
6857   , p_amb_context_code             => l_amb_context_code
6858   , p_side                         => 'NA'
6859   );
6860 
6861 
6862    --
6863    --
6864    END IF;
6865    --
6866    -- Bug 4922099
6867    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
6868           (NVL(l_enc_upg_option, 'N') = 'O')
6869         ) AND
6870         (l_bflow_method_code = 'PRIOR_ENTRY')
6871       )
6872    THEN
6873       IF
6874       --
6875       1 = 2
6876       --
6877       THEN
6878       xla_accounting_err_pkg.build_message
6879                                     (p_appli_s_name            => 'XLA'
6880                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6881                                     ,p_token_1                 => 'LINE_NUMBER'
6882                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
6883                                     ,p_token_2                 => 'LINE_TYPE_NAME'
6887                                                                             ,l_component_type_code
6884                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
6885                                                                              l_component_type
6886                                                                             ,l_component_code
6888                                                                             ,l_component_appl_id
6889                                                                             ,l_amb_context_code
6890                                                                             ,l_entity_code
6891                                                                             ,l_event_class_code
6892                                                                            )
6893                                     ,p_token_3                 => 'OWNER'
6894                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
6895                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
6896                                                                           ,p_lookup_code    => l_component_type_code
6897                                                                          )
6898                                     ,p_token_4                 => 'PRODUCT_NAME'
6899                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
6900                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
6901                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
6902                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
6903                                     ,p_ae_header_id            =>  NULL
6904                                        );
6905 
6906         IF (C_LEVEL_ERROR>= g_log_level) THEN
6907                  trace
6908                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6909                       ,p_level    => C_LEVEL_ERROR
6910                       ,p_module   => l_log_module);
6911         END IF;
6912       END IF;
6913    END IF;
6914    --
6915    --
6916    ------------------------------------------------------------------------------------------------
6917    -- 4219869 Business Flow
6918    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
6919    -- Prior Entry.  Currently, the following code is always generated.
6920    ------------------------------------------------------------------------------------------------
6921    XLA_AE_LINES_PKG.ValidateCurrentLine;
6922 
6923    ------------------------------------------------------------------------------------
6924    -- 4219869 Business Flow
6925    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
6926    ------------------------------------------------------------------------------------
6927    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6928 
6929    ----------------------------------------------------------------------------------
6930    -- 4219869 Business Flow
6931    -- Update journal entry status -- Need to generate this within IF <condition>
6932    ----------------------------------------------------------------------------------
6933    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6934          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
6935          ,p_balance_type_code => l_balance_type_code
6936          );
6937 
6938    -------------------------------------------------------------------------------------------
6939    -- 4262811 - Generate the Accrual Reversal lines
6940    -------------------------------------------------------------------------------------------
6941    BEGIN
6942       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
6943                               (g_array_event(p_event_id).array_value_num('header_index'));
6944       IF l_acc_rev_flag IS NULL THEN
6945          l_acc_rev_flag := 'N';
6946       END IF;
6947    EXCEPTION
6948       WHEN OTHERS THEN
6949          l_acc_rev_flag := 'N';
6950    END;
6951    --
6952    IF (l_acc_rev_flag = 'Y') THEN
6953 
6954        -- 4645092  ------------------------------------------------------------------------------
6955        -- To allow MPA report to determine if it should generate report process
6956        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
6957        ------------------------------------------------------------------------------------------
6958 
6959        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
6960        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
6961    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
6962    -- call ADRs
6963    -- Bug 4922099
6964    --
6965    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
6966         (NVL(l_actual_upg_option, 'N') = 'O') OR
6967         (NVL(l_enc_upg_option, 'N') = 'O')
6968       )
6969    THEN
6970    NULL;
6971    --
6972    --
6973    
6974   l_ccid := AcctDerRule_7(
6975            p_application_id           => p_application_id
6976          , p_ae_header_id             => l_ae_header_id 
6977 , p_source_3 => p_source_3
6978          , x_transaction_coa_id       => l_adr_transaction_coa_id
6979          , x_accounting_coa_id        => l_adr_accounting_coa_id
6980          , x_value_type_code          => l_adr_value_type_code
6981          , p_side                     => 'NA'
6982    );
6983 
6984    xla_ae_lines_pkg.set_ccid(
6985     p_code_combination_id          => l_ccid
6986   , p_value_type_code              => l_adr_value_type_code
6987   , p_transaction_coa_id           => l_adr_transaction_coa_id
6991   , p_component_type               => l_component_type
6988   , p_accounting_coa_id            => l_adr_accounting_coa_id
6989   , p_adr_code                     => 'DIST_CCID'
6990   , p_adr_type_code                => 'S'
6992   , p_component_code               => l_component_code
6993   , p_component_type_code          => l_component_type_code
6994   , p_component_appl_id            => l_component_appl_id
6995   , p_amb_context_code             => l_amb_context_code
6996   , p_side                         => 'NA'
6997   );
6998 
6999 
7000    --
7001    --
7002    END IF;
7003 
7004        --
7005        -- Update the line information that should be overwritten
7006        --
7007        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
7008                                          p_header_num   => 1);
7009        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
7010 
7011        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
7012 
7013        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
7014           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
7015        END IF;
7016 
7017       --
7018       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
7019       --
7020       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
7021           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
7022       ELSE
7023           ---------------------------------------------------------------------------------------------------
7024           -- 4262811a Switch Sign
7025           ---------------------------------------------------------------------------------------------------
7026           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
7027           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
7028                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7029           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
7030                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7031           -- 5132302
7032           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
7033                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7034 
7035       END IF;
7036 
7037       -- 4955764
7038       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
7039       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
7040 
7041 
7042       XLA_AE_LINES_PKG.ValidateCurrentLine;
7043       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
7044 
7045       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
7046                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
7047                ,p_balance_type_code => l_balance_type_code);
7048 
7049    END IF;
7050 
7051    -----------------------------------------------------------------------------------------
7052    -- 4262811 Multiperiod Accounting
7053    -----------------------------------------------------------------------------------------
7054      -- No MPA option is assigned.
7055 
7056 
7057 END IF;
7058 END IF;
7059 --
7060 
7061 --
7062 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7063    trace
7064       (p_msg      => 'END of AcctLineType_25'
7065       ,p_level    => C_LEVEL_PROCEDURE
7066       ,p_module   => l_log_module);
7067 END IF;
7068 --
7069 EXCEPTION
7070   WHEN xla_exceptions_pkg.application_exception THEN
7071       RAISE;
7072   WHEN OTHERS THEN
7073        xla_exceptions_pkg.raise_message
7074            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_25');
7075 END AcctLineType_25;
7076 --
7077 
7078 ---------------------------------------
7079 --
7080 -- PRIVATE FUNCTION
7081 --         AcctLineType_26
7082 --
7083 ---------------------------------------
7084 PROCEDURE AcctLineType_26 (
7085   p_application_id        IN NUMBER
7086  ,p_event_id              IN NUMBER
7087  ,p_calculate_acctd_flag  IN VARCHAR2
7088  ,p_calculate_g_l_flag    IN VARCHAR2
7089  ,p_actual_flag           IN OUT VARCHAR2
7090  ,p_balance_type_code     OUT VARCHAR2
7091  ,p_gain_or_loss_ref      OUT VARCHAR2
7092  
7093 --Credit Memo Distribution GL Account
7094  , p_source_2            IN NUMBER
7095 --SLA Party Type
7096  , p_source_25            IN VARCHAR2
7097 --Credit Memo Distribution Identifier
7098  , p_source_35            IN NUMBER
7099 --Credit memo distributions type
7100  , p_source_36            IN VARCHAR2
7101 --Credit Memo Currency Code
7102  , p_source_37            IN VARCHAR2
7103 --Credit Memo Exchange Date
7104  , p_source_38            IN DATE
7105 --Credit Memo Exchange Rate
7106  , p_source_39            IN NUMBER
7107 --Credit Memo Exchange Rate Type
7108  , p_source_40            IN VARCHAR2
7109 --Gain Loss Reference
7110  , p_source_41            IN VARCHAR2
7111 --Credit Memo Accounting Amount
7112  , p_source_42            IN NUMBER
7113 --Credit Memo Bill To Customer Account Identifier
7114  , p_source_43            IN NUMBER
7115 --Credit Memo Bill To Customer Site Use Identifier
7116  , p_source_44            IN NUMBER
7117 --Credit Memo Tax Line Identifier
7118  , p_source_45            IN NUMBER
7119 --Credit Memo Distribution Account Class
7123 )
7120  , p_source_46            IN VARCHAR2
7121 --Credit Memo Distribution Entered Amount
7122  , p_source_47            IN NUMBER
7124 IS
7125 
7126 l_component_type              VARCHAR2(80);
7127 l_component_code              VARCHAR2(30);
7128 l_component_type_code         VARCHAR2(1);
7129 l_component_appl_id           INTEGER;
7130 l_amb_context_code            VARCHAR2(30);
7131 l_entity_code                 VARCHAR2(30);
7132 l_event_class_code            VARCHAR2(30);
7133 l_ae_header_id                NUMBER;
7134 l_event_type_code             VARCHAR2(30);
7135 l_line_definition_code        VARCHAR2(30);
7136 l_line_definition_owner_code  VARCHAR2(1);
7137 --
7138 -- adr variables
7139 l_segment                     VARCHAR2(30);
7140 l_ccid                        NUMBER;
7141 l_adr_transaction_coa_id      NUMBER;
7142 l_adr_accounting_coa_id       NUMBER;
7143 l_adr_flexfield_segment_code  VARCHAR2(30);
7144 l_adr_flex_value_set_id       NUMBER;
7145 l_adr_value_type_code         VARCHAR2(30);
7146 l_adr_value_combination_id    NUMBER;
7147 l_adr_value_segment_code      VARCHAR2(30);
7148 
7149 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
7150 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
7151 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
7152 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
7153 
7154 -- 4262811 Variables ------------------------------------------------------------------------------------------
7155 l_entered_amt_idx             NUMBER;
7156 l_accted_amt_idx              NUMBER;
7157 l_acc_rev_flag                VARCHAR2(1);
7158 l_accrual_line_num            NUMBER;
7159 l_tmp_amt                     NUMBER;
7160 l_acc_rev_natural_side_code   VARCHAR2(1);
7161 
7162 l_num_entries                 NUMBER;
7163 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
7164 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
7165 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
7166 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
7167 l_recog_line_1                NUMBER;
7168 l_recog_line_2                NUMBER;
7169 
7170 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
7171 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
7172 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
7173 
7174 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
7175 
7176 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
7177 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
7178 
7179 ---------------------------------------------------------------------------------------------------------------
7180 
7181 
7182 --
7183 -- bulk performance
7184 --
7185 l_balance_type_code           VARCHAR2(1);
7186 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
7187 l_log_module                  VARCHAR2(240);
7188 
7189 --
7190 -- Upgrade strategy
7191 --
7192 l_actual_upg_option           VARCHAR2(1);
7193 l_enc_upg_option           VARCHAR2(1);
7194 
7195 --
7196 BEGIN
7197 --
7198 IF g_log_enabled THEN
7199       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_26';
7200 END IF;
7201 --
7202 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7203 
7204       trace
7205          (p_msg      => 'BEGIN of AcctLineType_26'
7206          ,p_level    => C_LEVEL_PROCEDURE
7207          ,p_module   => l_log_module);
7208 
7209 END IF;
7210 --
7211 l_component_type             := 'AMB_JLT';
7212 l_component_code             := 'CM_CHARGES';
7213 l_component_type_code        := 'S';
7214 l_component_appl_id          :=  222;
7215 l_amb_context_code           := 'DEFAULT';
7216 l_entity_code                := 'TRANSACTIONS';
7217 l_event_class_code           := 'CREDIT_MEMO';
7218 l_event_type_code            := 'CREDIT_MEMO_ALL';
7219 l_line_definition_owner_code := 'S';
7220 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
7221 --
7222 l_balance_type_code          := 'A';
7223 l_segment                     := NULL;
7224 l_ccid                        := NULL;
7225 l_adr_transaction_coa_id      := NULL;
7226 l_adr_accounting_coa_id       := NULL;
7227 l_adr_flexfield_segment_code  := NULL;
7228 l_adr_flex_value_set_id       := NULL;
7229 l_adr_value_type_code         := NULL;
7230 l_adr_value_combination_id    := NULL;
7231 l_adr_value_segment_code      := NULL;
7232 
7233 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
7234 l_bflow_class_code           := '';    -- 4219869 Business Flow
7235 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
7236 l_budgetary_control_flag     := 'N';
7237 
7238 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
7239 l_bflow_applied_to_amt       := NULL; -- 5132302
7240 l_entered_amt_idx            := NULL;          -- 4262811
7241 l_accted_amt_idx             := NULL;          -- 4262811
7242 l_acc_rev_flag               := NULL;          -- 4262811
7243 l_accrual_line_num           := NULL;          -- 4262811
7244 l_tmp_amt                    := NULL;          -- 4262811
7245 --
7246  
7247 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
7248     l_balance_type_code <> 'B' THEN
7249 IF NVL(p_source_46,'
7250 ') =  'CHARGES'
7251  THEN 
7252 
7253    --
7254    XLA_AE_LINES_PKG.SetNewLine;
7255 
7256    p_balance_type_code          := l_balance_type_code;
7257    -- set the flag so later we will know whether the gain loss line needs to be created
7261    END IF;
7258    
7259    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
7260      p_actual_flag :='A';
7262 
7263    --
7264    -- bulk performance
7265    --
7266    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
7267                                       p_header_num   => 0); -- 4262811
7268    --
7269    -- set accounting line options
7270    --
7271    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
7272            p_natural_side_code          => 'C'
7273          , p_gain_or_loss_flag          => 'N'
7274          , p_gl_transfer_mode_code      => 'S'
7275          , p_acct_entry_type_code       => 'A'
7276          , p_switch_side_flag           => 'Y'
7277          , p_merge_duplicate_code       => 'A'
7278          );
7279    --
7280    l_acc_rev_natural_side_code := 'D';  -- 4262811
7281    -- 
7282    --
7283    -- set accounting line type info
7284    --
7285    xla_ae_lines_pkg.SetAcctLineType
7286       (p_component_type             => l_component_type
7287       ,p_event_type_code            => l_event_type_code
7288       ,p_line_definition_owner_code => l_line_definition_owner_code
7289       ,p_line_definition_code       => l_line_definition_code
7290       ,p_accounting_line_code       => l_component_code
7291       ,p_accounting_line_type_code  => l_component_type_code
7292       ,p_accounting_line_appl_id    => l_component_appl_id
7293       ,p_amb_context_code           => l_amb_context_code
7294       ,p_entity_code                => l_entity_code
7295       ,p_event_class_code           => l_event_class_code);
7296    --
7297    -- set accounting class
7298    --
7299    xla_ae_lines_pkg.SetAcctClass(
7300            p_accounting_class_code  => 'CHARGES'
7301          , p_ae_header_id           => l_ae_header_id
7302          );
7303 
7304    --
7305    -- set rounding class
7306    --
7307    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
7308                       'RECEIVABLE';
7309 
7310    --
7311    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
7312    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
7313    --
7314    -- bulk performance
7315    --
7316    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
7317 
7318    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
7319       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
7320 
7321    -- 4955764
7322    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
7323       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
7324 
7325    -- 4458381 Public Sector Enh
7326    
7327    --
7328    -- set accounting attributes for the line type
7329    --
7330    l_entered_amt_idx := 3;
7331    l_accted_amt_idx  := 9;
7332    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
7333    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
7334    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_35);
7335    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
7336    l_rec_acct_attrs.array_char_value(2)  := p_source_36;
7337    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
7338    l_rec_acct_attrs.array_num_value(3)  := p_source_47;
7339    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
7340    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
7341    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
7342    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
7343    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
7344    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
7345    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
7346    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
7347    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
7348    l_rec_acct_attrs.array_char_value(8)  := p_source_41;
7349    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
7350    l_rec_acct_attrs.array_num_value(9)  := p_source_42;
7351    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
7352    l_rec_acct_attrs.array_num_value(10)  := p_source_43;
7353    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
7354    l_rec_acct_attrs.array_num_value(11)  := p_source_44;
7355    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
7356    l_rec_acct_attrs.array_char_value(12)  := p_source_25;
7357    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
7358    l_rec_acct_attrs.array_num_value(13)  := p_source_45;
7359 
7360    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
7361    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
7362 
7363    ---------------------------------------------------------------------------------------------------------------
7364    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
7365    ---------------------------------------------------------------------------------------------------------------
7366    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
7367 
7368    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
7369    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
7370 
7371    IF xla_accounting_cache_pkg.GetValueChar
7372          (p_source_code         => 'LEDGER_CATEGORY_CODE'
7373          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
7377          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
7374    AND l_bflow_method_code = 'PRIOR_ENTRY'
7375 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
7376    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
7378        )
7379    THEN
7380          xla_ae_lines_pkg.BflowUpgEntry
7381            (p_business_method_code    => l_bflow_method_code
7382            ,p_business_class_code     => l_bflow_class_code
7383            ,p_balance_type            => l_balance_type_code);
7384    ELSE
7385       NULL;
7386 -- No business flow processing for business flow method of NONE.
7387    END IF;
7388 
7389    --
7390    -- call analytical criteria
7391    --
7392    
7393    --
7394    -- call description
7395    --
7396    -- No description or it is inherited.
7397    --
7398    -- call ADRs
7399    -- Bug 4922099
7400    --
7401    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
7402         (NVL(l_actual_upg_option, 'N') = 'O') OR
7403         (NVL(l_enc_upg_option, 'N') = 'O')
7404       )
7405    THEN
7406    NULL;
7407    --
7408    --
7409    
7410   l_ccid := AcctDerRule_6(
7411            p_application_id           => p_application_id
7412          , p_ae_header_id             => l_ae_header_id 
7413 , p_source_2 => p_source_2
7414          , x_transaction_coa_id       => l_adr_transaction_coa_id
7415          , x_accounting_coa_id        => l_adr_accounting_coa_id
7416          , x_value_type_code          => l_adr_value_type_code
7417          , p_side                     => 'NA'
7418    );
7419 
7420    xla_ae_lines_pkg.set_ccid(
7421     p_code_combination_id          => l_ccid
7422   , p_value_type_code              => l_adr_value_type_code
7423   , p_transaction_coa_id           => l_adr_transaction_coa_id
7424   , p_accounting_coa_id            => l_adr_accounting_coa_id
7425   , p_adr_code                     => 'CM_DIST_CCID'
7426   , p_adr_type_code                => 'S'
7427   , p_component_type               => l_component_type
7428   , p_component_code               => l_component_code
7429   , p_component_type_code          => l_component_type_code
7430   , p_component_appl_id            => l_component_appl_id
7431   , p_amb_context_code             => l_amb_context_code
7432   , p_side                         => 'NA'
7433   );
7434 
7435 
7436    --
7437    --
7438    END IF;
7439    --
7440    -- Bug 4922099
7441    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
7442           (NVL(l_enc_upg_option, 'N') = 'O')
7443         ) AND
7444         (l_bflow_method_code = 'PRIOR_ENTRY')
7445       )
7446    THEN
7447       IF
7448       --
7449       1 = 2
7450       --
7451       THEN
7452       xla_accounting_err_pkg.build_message
7453                                     (p_appli_s_name            => 'XLA'
7454                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
7455                                     ,p_token_1                 => 'LINE_NUMBER'
7456                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
7457                                     ,p_token_2                 => 'LINE_TYPE_NAME'
7458                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
7459                                                                              l_component_type
7460                                                                             ,l_component_code
7461                                                                             ,l_component_type_code
7462                                                                             ,l_component_appl_id
7463                                                                             ,l_amb_context_code
7464                                                                             ,l_entity_code
7465                                                                             ,l_event_class_code
7466                                                                            )
7467                                     ,p_token_3                 => 'OWNER'
7468                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
7469                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
7470                                                                           ,p_lookup_code    => l_component_type_code
7471                                                                          )
7472                                     ,p_token_4                 => 'PRODUCT_NAME'
7473                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
7474                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
7475                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
7476                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
7477                                     ,p_ae_header_id            =>  NULL
7478                                        );
7479 
7480         IF (C_LEVEL_ERROR>= g_log_level) THEN
7481                  trace
7482                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
7483                       ,p_level    => C_LEVEL_ERROR
7484                       ,p_module   => l_log_module);
7485         END IF;
7486       END IF;
7487    END IF;
7488    --
7489    --
7490    ------------------------------------------------------------------------------------------------
7491    -- 4219869 Business Flow
7492    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
7493    -- Prior Entry.  Currently, the following code is always generated.
7497    ------------------------------------------------------------------------------------
7494    ------------------------------------------------------------------------------------------------
7495    XLA_AE_LINES_PKG.ValidateCurrentLine;
7496 
7498    -- 4219869 Business Flow
7499    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
7500    ------------------------------------------------------------------------------------
7501    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
7502 
7503    ----------------------------------------------------------------------------------
7504    -- 4219869 Business Flow
7505    -- Update journal entry status -- Need to generate this within IF <condition>
7506    ----------------------------------------------------------------------------------
7507    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
7508          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
7509          ,p_balance_type_code => l_balance_type_code
7510          );
7511 
7512    -------------------------------------------------------------------------------------------
7513    -- 4262811 - Generate the Accrual Reversal lines
7514    -------------------------------------------------------------------------------------------
7515    BEGIN
7516       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
7517                               (g_array_event(p_event_id).array_value_num('header_index'));
7518       IF l_acc_rev_flag IS NULL THEN
7519          l_acc_rev_flag := 'N';
7520       END IF;
7521    EXCEPTION
7522       WHEN OTHERS THEN
7523          l_acc_rev_flag := 'N';
7524    END;
7525    --
7526    IF (l_acc_rev_flag = 'Y') THEN
7527 
7528        -- 4645092  ------------------------------------------------------------------------------
7529        -- To allow MPA report to determine if it should generate report process
7530        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
7531        ------------------------------------------------------------------------------------------
7532 
7533        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
7534        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
7535    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
7536    -- call ADRs
7537    -- Bug 4922099
7538    --
7539    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
7540         (NVL(l_actual_upg_option, 'N') = 'O') OR
7541         (NVL(l_enc_upg_option, 'N') = 'O')
7542       )
7543    THEN
7544    NULL;
7545    --
7546    --
7547    
7548   l_ccid := AcctDerRule_6(
7549            p_application_id           => p_application_id
7550          , p_ae_header_id             => l_ae_header_id 
7551 , p_source_2 => p_source_2
7552          , x_transaction_coa_id       => l_adr_transaction_coa_id
7553          , x_accounting_coa_id        => l_adr_accounting_coa_id
7554          , x_value_type_code          => l_adr_value_type_code
7555          , p_side                     => 'NA'
7556    );
7557 
7558    xla_ae_lines_pkg.set_ccid(
7559     p_code_combination_id          => l_ccid
7560   , p_value_type_code              => l_adr_value_type_code
7561   , p_transaction_coa_id           => l_adr_transaction_coa_id
7562   , p_accounting_coa_id            => l_adr_accounting_coa_id
7563   , p_adr_code                     => 'CM_DIST_CCID'
7564   , p_adr_type_code                => 'S'
7565   , p_component_type               => l_component_type
7566   , p_component_code               => l_component_code
7567   , p_component_type_code          => l_component_type_code
7568   , p_component_appl_id            => l_component_appl_id
7569   , p_amb_context_code             => l_amb_context_code
7570   , p_side                         => 'NA'
7571   );
7572 
7573 
7574    --
7575    --
7576    END IF;
7577 
7578        --
7579        -- Update the line information that should be overwritten
7580        --
7581        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
7582                                          p_header_num   => 1);
7583        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
7584 
7585        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
7586 
7587        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
7588           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
7589        END IF;
7590 
7591       --
7592       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
7593       --
7594       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
7595           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
7596       ELSE
7597           ---------------------------------------------------------------------------------------------------
7598           -- 4262811a Switch Sign
7599           ---------------------------------------------------------------------------------------------------
7600           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
7601           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
7602                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7603           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
7604                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7605           -- 5132302
7606           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
7610 
7607                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7608 
7609       END IF;
7611       -- 4955764
7612       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
7613       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
7614 
7615 
7616       XLA_AE_LINES_PKG.ValidateCurrentLine;
7617       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
7618 
7619       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
7620                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
7621                ,p_balance_type_code => l_balance_type_code);
7622 
7623    END IF;
7624 
7625    -----------------------------------------------------------------------------------------
7626    -- 4262811 Multiperiod Accounting
7627    -----------------------------------------------------------------------------------------
7628      -- No MPA option is assigned.
7629 
7630 
7631 END IF;
7632 END IF;
7633 --
7634 
7635 --
7636 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7637    trace
7638       (p_msg      => 'END of AcctLineType_26'
7639       ,p_level    => C_LEVEL_PROCEDURE
7640       ,p_module   => l_log_module);
7641 END IF;
7642 --
7643 EXCEPTION
7644   WHEN xla_exceptions_pkg.application_exception THEN
7645       RAISE;
7646   WHEN OTHERS THEN
7647        xla_exceptions_pkg.raise_message
7648            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_26');
7649 END AcctLineType_26;
7650 --
7651 
7652 ---------------------------------------
7653 --
7654 -- PRIVATE FUNCTION
7655 --         AcctLineType_27
7656 --
7657 ---------------------------------------
7658 PROCEDURE AcctLineType_27 (
7659   p_application_id        IN NUMBER
7660  ,p_event_id              IN NUMBER
7661  ,p_calculate_acctd_flag  IN VARCHAR2
7662  ,p_calculate_g_l_flag    IN VARCHAR2
7663  ,p_actual_flag           IN OUT VARCHAR2
7664  ,p_balance_type_code     OUT VARCHAR2
7665  ,p_gain_or_loss_ref      OUT VARCHAR2
7666  
7667 --Credit Memo Distribution GL Account
7668  , p_source_2            IN NUMBER
7669 --SLA Party Type
7670  , p_source_25            IN VARCHAR2
7671 --Credit Memo Distribution Identifier
7672  , p_source_35            IN NUMBER
7673 --Credit memo distributions type
7674  , p_source_36            IN VARCHAR2
7675 --Credit Memo Currency Code
7676  , p_source_37            IN VARCHAR2
7677 --Credit Memo Exchange Date
7678  , p_source_38            IN DATE
7679 --Credit Memo Exchange Rate
7680  , p_source_39            IN NUMBER
7681 --Credit Memo Exchange Rate Type
7682  , p_source_40            IN VARCHAR2
7683 --Gain Loss Reference
7684  , p_source_41            IN VARCHAR2
7685 --Credit Memo Accounting Amount
7686  , p_source_42            IN NUMBER
7687 --Credit Memo Bill To Customer Account Identifier
7688  , p_source_43            IN NUMBER
7689 --Credit Memo Bill To Customer Site Use Identifier
7690  , p_source_44            IN NUMBER
7691 --Credit Memo Tax Line Identifier
7692  , p_source_45            IN NUMBER
7693 --Credit Memo Distribution Account Class
7694  , p_source_46            IN VARCHAR2
7695 --Credit Memo Distribution Entered Amount
7696  , p_source_47            IN NUMBER
7697 )
7698 IS
7699 
7700 l_component_type              VARCHAR2(80);
7701 l_component_code              VARCHAR2(30);
7702 l_component_type_code         VARCHAR2(1);
7703 l_component_appl_id           INTEGER;
7704 l_amb_context_code            VARCHAR2(30);
7705 l_entity_code                 VARCHAR2(30);
7706 l_event_class_code            VARCHAR2(30);
7707 l_ae_header_id                NUMBER;
7708 l_event_type_code             VARCHAR2(30);
7709 l_line_definition_code        VARCHAR2(30);
7710 l_line_definition_owner_code  VARCHAR2(1);
7711 --
7712 -- adr variables
7713 l_segment                     VARCHAR2(30);
7714 l_ccid                        NUMBER;
7715 l_adr_transaction_coa_id      NUMBER;
7716 l_adr_accounting_coa_id       NUMBER;
7717 l_adr_flexfield_segment_code  VARCHAR2(30);
7718 l_adr_flex_value_set_id       NUMBER;
7719 l_adr_value_type_code         VARCHAR2(30);
7720 l_adr_value_combination_id    NUMBER;
7721 l_adr_value_segment_code      VARCHAR2(30);
7722 
7723 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
7724 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
7725 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
7726 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
7727 
7728 -- 4262811 Variables ------------------------------------------------------------------------------------------
7729 l_entered_amt_idx             NUMBER;
7730 l_accted_amt_idx              NUMBER;
7731 l_acc_rev_flag                VARCHAR2(1);
7732 l_accrual_line_num            NUMBER;
7733 l_tmp_amt                     NUMBER;
7734 l_acc_rev_natural_side_code   VARCHAR2(1);
7735 
7736 l_num_entries                 NUMBER;
7737 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
7738 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
7739 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
7740 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
7741 l_recog_line_1                NUMBER;
7742 l_recog_line_2                NUMBER;
7743 
7744 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
7748 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
7745 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
7746 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
7747 
7749 
7750 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
7751 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
7752 
7753 ---------------------------------------------------------------------------------------------------------------
7754 
7755 
7756 --
7757 -- bulk performance
7758 --
7759 l_balance_type_code           VARCHAR2(1);
7760 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
7761 l_log_module                  VARCHAR2(240);
7762 
7763 --
7764 -- Upgrade strategy
7765 --
7766 l_actual_upg_option           VARCHAR2(1);
7767 l_enc_upg_option           VARCHAR2(1);
7768 
7769 --
7770 BEGIN
7771 --
7772 IF g_log_enabled THEN
7773       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_27';
7774 END IF;
7775 --
7776 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7777 
7778       trace
7779          (p_msg      => 'BEGIN of AcctLineType_27'
7780          ,p_level    => C_LEVEL_PROCEDURE
7781          ,p_module   => l_log_module);
7782 
7783 END IF;
7784 --
7785 l_component_type             := 'AMB_JLT';
7786 l_component_code             := 'CM_DEFAULT_FREIGHT';
7787 l_component_type_code        := 'S';
7788 l_component_appl_id          :=  222;
7789 l_amb_context_code           := 'DEFAULT';
7790 l_entity_code                := 'TRANSACTIONS';
7791 l_event_class_code           := 'CREDIT_MEMO';
7792 l_event_type_code            := 'CREDIT_MEMO_ALL';
7793 l_line_definition_owner_code := 'S';
7794 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
7795 --
7796 l_balance_type_code          := 'A';
7797 l_segment                     := NULL;
7798 l_ccid                        := NULL;
7799 l_adr_transaction_coa_id      := NULL;
7800 l_adr_accounting_coa_id       := NULL;
7801 l_adr_flexfield_segment_code  := NULL;
7802 l_adr_flex_value_set_id       := NULL;
7803 l_adr_value_type_code         := NULL;
7804 l_adr_value_combination_id    := NULL;
7805 l_adr_value_segment_code      := NULL;
7806 
7807 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
7808 l_bflow_class_code           := '';    -- 4219869 Business Flow
7809 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
7810 l_budgetary_control_flag     := 'N';
7811 
7812 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
7813 l_bflow_applied_to_amt       := NULL; -- 5132302
7814 l_entered_amt_idx            := NULL;          -- 4262811
7815 l_accted_amt_idx             := NULL;          -- 4262811
7816 l_acc_rev_flag               := NULL;          -- 4262811
7817 l_accrual_line_num           := NULL;          -- 4262811
7818 l_tmp_amt                    := NULL;          -- 4262811
7819 --
7820  
7821 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
7822     l_balance_type_code <> 'B' THEN
7823 IF NVL(p_source_46,'
7824 ') =  'FREIGHT'
7825  THEN 
7826 
7827    --
7828    XLA_AE_LINES_PKG.SetNewLine;
7829 
7830    p_balance_type_code          := l_balance_type_code;
7831    -- set the flag so later we will know whether the gain loss line needs to be created
7832    
7833    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
7834      p_actual_flag :='A';
7835    END IF;
7836 
7837    --
7838    -- bulk performance
7839    --
7840    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
7841                                       p_header_num   => 0); -- 4262811
7842    --
7843    -- set accounting line options
7844    --
7845    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
7846            p_natural_side_code          => 'C'
7847          , p_gain_or_loss_flag          => 'N'
7848          , p_gl_transfer_mode_code      => 'S'
7849          , p_acct_entry_type_code       => 'A'
7850          , p_switch_side_flag           => 'Y'
7851          , p_merge_duplicate_code       => 'A'
7852          );
7853    --
7854    l_acc_rev_natural_side_code := 'D';  -- 4262811
7855    -- 
7856    --
7857    -- set accounting line type info
7858    --
7859    xla_ae_lines_pkg.SetAcctLineType
7860       (p_component_type             => l_component_type
7861       ,p_event_type_code            => l_event_type_code
7862       ,p_line_definition_owner_code => l_line_definition_owner_code
7863       ,p_line_definition_code       => l_line_definition_code
7864       ,p_accounting_line_code       => l_component_code
7865       ,p_accounting_line_type_code  => l_component_type_code
7866       ,p_accounting_line_appl_id    => l_component_appl_id
7867       ,p_amb_context_code           => l_amb_context_code
7868       ,p_entity_code                => l_entity_code
7869       ,p_event_class_code           => l_event_class_code);
7870    --
7871    -- set accounting class
7872    --
7873    xla_ae_lines_pkg.SetAcctClass(
7874            p_accounting_class_code  => 'FREIGHT'
7875          , p_ae_header_id           => l_ae_header_id
7876          );
7877 
7878    --
7879    -- set rounding class
7880    --
7881    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
7882                       'RECEIVABLE';
7883 
7884    --
7885    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
7889    --
7886    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
7887    --
7888    -- bulk performance
7890    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
7891 
7892    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
7893       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
7894 
7895    -- 4955764
7896    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
7897       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
7898 
7899    -- 4458381 Public Sector Enh
7900    
7901    --
7902    -- set accounting attributes for the line type
7903    --
7904    l_entered_amt_idx := 3;
7905    l_accted_amt_idx  := 9;
7906    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
7907    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
7908    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_35);
7909    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
7910    l_rec_acct_attrs.array_char_value(2)  := p_source_36;
7911    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
7912    l_rec_acct_attrs.array_num_value(3)  := p_source_47;
7913    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
7914    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
7915    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
7916    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
7917    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
7918    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
7919    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
7920    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
7921    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
7922    l_rec_acct_attrs.array_char_value(8)  := p_source_41;
7923    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
7924    l_rec_acct_attrs.array_num_value(9)  := p_source_42;
7925    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
7926    l_rec_acct_attrs.array_num_value(10)  := p_source_43;
7927    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
7928    l_rec_acct_attrs.array_num_value(11)  := p_source_44;
7929    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
7930    l_rec_acct_attrs.array_char_value(12)  := p_source_25;
7931    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
7932    l_rec_acct_attrs.array_num_value(13)  := p_source_45;
7933 
7934    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
7935    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
7936 
7937    ---------------------------------------------------------------------------------------------------------------
7938    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
7939    ---------------------------------------------------------------------------------------------------------------
7940    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
7941 
7942    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
7943    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
7944 
7945    IF xla_accounting_cache_pkg.GetValueChar
7946          (p_source_code         => 'LEDGER_CATEGORY_CODE'
7947          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
7948    AND l_bflow_method_code = 'PRIOR_ENTRY'
7949 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
7950    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
7951          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
7952        )
7953    THEN
7954          xla_ae_lines_pkg.BflowUpgEntry
7955            (p_business_method_code    => l_bflow_method_code
7956            ,p_business_class_code     => l_bflow_class_code
7957            ,p_balance_type            => l_balance_type_code);
7958    ELSE
7959       NULL;
7960 -- No business flow processing for business flow method of NONE.
7961    END IF;
7962 
7963    --
7964    -- call analytical criteria
7965    --
7966    
7967    --
7968    -- call description
7969    --
7970    -- No description or it is inherited.
7971    --
7972    -- call ADRs
7973    -- Bug 4922099
7974    --
7975    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
7976         (NVL(l_actual_upg_option, 'N') = 'O') OR
7977         (NVL(l_enc_upg_option, 'N') = 'O')
7978       )
7979    THEN
7980    NULL;
7981    --
7982    --
7983    
7984   l_ccid := AcctDerRule_6(
7985            p_application_id           => p_application_id
7986          , p_ae_header_id             => l_ae_header_id 
7987 , p_source_2 => p_source_2
7988          , x_transaction_coa_id       => l_adr_transaction_coa_id
7989          , x_accounting_coa_id        => l_adr_accounting_coa_id
7990          , x_value_type_code          => l_adr_value_type_code
7991          , p_side                     => 'NA'
7992    );
7993 
7994    xla_ae_lines_pkg.set_ccid(
7995     p_code_combination_id          => l_ccid
7996   , p_value_type_code              => l_adr_value_type_code
7997   , p_transaction_coa_id           => l_adr_transaction_coa_id
7998   , p_accounting_coa_id            => l_adr_accounting_coa_id
7999   , p_adr_code                     => 'CM_DIST_CCID'
8000   , p_adr_type_code                => 'S'
8001   , p_component_type               => l_component_type
8002   , p_component_code               => l_component_code
8006   , p_side                         => 'NA'
8003   , p_component_type_code          => l_component_type_code
8004   , p_component_appl_id            => l_component_appl_id
8005   , p_amb_context_code             => l_amb_context_code
8007   );
8008 
8009 
8010    --
8011    --
8012    END IF;
8013    --
8014    -- Bug 4922099
8015    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
8016           (NVL(l_enc_upg_option, 'N') = 'O')
8017         ) AND
8018         (l_bflow_method_code = 'PRIOR_ENTRY')
8019       )
8020    THEN
8021       IF
8022       --
8023       1 = 2
8024       --
8025       THEN
8026       xla_accounting_err_pkg.build_message
8027                                     (p_appli_s_name            => 'XLA'
8028                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
8029                                     ,p_token_1                 => 'LINE_NUMBER'
8030                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
8031                                     ,p_token_2                 => 'LINE_TYPE_NAME'
8032                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
8033                                                                              l_component_type
8034                                                                             ,l_component_code
8035                                                                             ,l_component_type_code
8036                                                                             ,l_component_appl_id
8037                                                                             ,l_amb_context_code
8038                                                                             ,l_entity_code
8039                                                                             ,l_event_class_code
8040                                                                            )
8041                                     ,p_token_3                 => 'OWNER'
8042                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
8043                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
8044                                                                           ,p_lookup_code    => l_component_type_code
8045                                                                          )
8046                                     ,p_token_4                 => 'PRODUCT_NAME'
8047                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
8048                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
8049                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
8050                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
8051                                     ,p_ae_header_id            =>  NULL
8052                                        );
8053 
8054         IF (C_LEVEL_ERROR>= g_log_level) THEN
8055                  trace
8056                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
8057                       ,p_level    => C_LEVEL_ERROR
8058                       ,p_module   => l_log_module);
8059         END IF;
8060       END IF;
8061    END IF;
8062    --
8063    --
8064    ------------------------------------------------------------------------------------------------
8065    -- 4219869 Business Flow
8066    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
8067    -- Prior Entry.  Currently, the following code is always generated.
8068    ------------------------------------------------------------------------------------------------
8069    XLA_AE_LINES_PKG.ValidateCurrentLine;
8070 
8071    ------------------------------------------------------------------------------------
8072    -- 4219869 Business Flow
8073    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
8074    ------------------------------------------------------------------------------------
8075    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
8076 
8077    ----------------------------------------------------------------------------------
8078    -- 4219869 Business Flow
8079    -- Update journal entry status -- Need to generate this within IF <condition>
8080    ----------------------------------------------------------------------------------
8081    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
8082          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
8083          ,p_balance_type_code => l_balance_type_code
8084          );
8085 
8086    -------------------------------------------------------------------------------------------
8087    -- 4262811 - Generate the Accrual Reversal lines
8088    -------------------------------------------------------------------------------------------
8089    BEGIN
8090       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
8091                               (g_array_event(p_event_id).array_value_num('header_index'));
8092       IF l_acc_rev_flag IS NULL THEN
8093          l_acc_rev_flag := 'N';
8094       END IF;
8095    EXCEPTION
8096       WHEN OTHERS THEN
8097          l_acc_rev_flag := 'N';
8098    END;
8099    --
8100    IF (l_acc_rev_flag = 'Y') THEN
8101 
8102        -- 4645092  ------------------------------------------------------------------------------
8103        -- To allow MPA report to determine if it should generate report process
8104        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
8105        ------------------------------------------------------------------------------------------
8106 
8107        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
8111    -- Bug 4922099
8108        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
8109    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
8110    -- call ADRs
8112    --
8113    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
8114         (NVL(l_actual_upg_option, 'N') = 'O') OR
8115         (NVL(l_enc_upg_option, 'N') = 'O')
8116       )
8117    THEN
8118    NULL;
8119    --
8120    --
8121    
8122   l_ccid := AcctDerRule_6(
8123            p_application_id           => p_application_id
8124          , p_ae_header_id             => l_ae_header_id 
8125 , p_source_2 => p_source_2
8126          , x_transaction_coa_id       => l_adr_transaction_coa_id
8127          , x_accounting_coa_id        => l_adr_accounting_coa_id
8128          , x_value_type_code          => l_adr_value_type_code
8129          , p_side                     => 'NA'
8130    );
8131 
8132    xla_ae_lines_pkg.set_ccid(
8133     p_code_combination_id          => l_ccid
8134   , p_value_type_code              => l_adr_value_type_code
8135   , p_transaction_coa_id           => l_adr_transaction_coa_id
8136   , p_accounting_coa_id            => l_adr_accounting_coa_id
8137   , p_adr_code                     => 'CM_DIST_CCID'
8138   , p_adr_type_code                => 'S'
8139   , p_component_type               => l_component_type
8140   , p_component_code               => l_component_code
8141   , p_component_type_code          => l_component_type_code
8142   , p_component_appl_id            => l_component_appl_id
8143   , p_amb_context_code             => l_amb_context_code
8144   , p_side                         => 'NA'
8145   );
8146 
8147 
8148    --
8149    --
8150    END IF;
8151 
8152        --
8153        -- Update the line information that should be overwritten
8154        --
8155        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
8156                                          p_header_num   => 1);
8157        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
8158 
8159        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
8160 
8161        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
8162           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
8163        END IF;
8164 
8165       --
8166       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
8167       --
8168       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
8169           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
8170       ELSE
8171           ---------------------------------------------------------------------------------------------------
8172           -- 4262811a Switch Sign
8173           ---------------------------------------------------------------------------------------------------
8174           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
8175           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
8176                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8177           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
8178                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8179           -- 5132302
8180           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
8181                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8182 
8183       END IF;
8184 
8185       -- 4955764
8186       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
8187       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
8188 
8189 
8190       XLA_AE_LINES_PKG.ValidateCurrentLine;
8191       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
8192 
8193       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
8194                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
8195                ,p_balance_type_code => l_balance_type_code);
8196 
8197    END IF;
8198 
8199    -----------------------------------------------------------------------------------------
8200    -- 4262811 Multiperiod Accounting
8201    -----------------------------------------------------------------------------------------
8202      -- No MPA option is assigned.
8203 
8204 
8205 END IF;
8206 END IF;
8207 --
8208 
8209 --
8210 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8211    trace
8212       (p_msg      => 'END of AcctLineType_27'
8213       ,p_level    => C_LEVEL_PROCEDURE
8214       ,p_module   => l_log_module);
8215 END IF;
8216 --
8217 EXCEPTION
8218   WHEN xla_exceptions_pkg.application_exception THEN
8219       RAISE;
8220   WHEN OTHERS THEN
8221        xla_exceptions_pkg.raise_message
8222            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_27');
8223 END AcctLineType_27;
8224 --
8225 
8226 ---------------------------------------
8227 --
8228 -- PRIVATE FUNCTION
8229 --         AcctLineType_28
8230 --
8231 ---------------------------------------
8232 PROCEDURE AcctLineType_28 (
8233   p_application_id        IN NUMBER
8234  ,p_event_id              IN NUMBER
8235  ,p_calculate_acctd_flag  IN VARCHAR2
8236  ,p_calculate_g_l_flag    IN VARCHAR2
8237  ,p_actual_flag           IN OUT VARCHAR2
8238  ,p_balance_type_code     OUT VARCHAR2
8239  ,p_gain_or_loss_ref      OUT VARCHAR2
8240  
8241 --Credit Memo Distribution GL Account
8242  , p_source_2            IN NUMBER
8243 --SLA Party Type
8244  , p_source_25            IN VARCHAR2
8245 --Credit Memo Distribution Identifier
8246  , p_source_35            IN NUMBER
8247 --Credit memo distributions type
8248  , p_source_36            IN VARCHAR2
8249 --Credit Memo Currency Code
8250  , p_source_37            IN VARCHAR2
8251 --Credit Memo Exchange Date
8252  , p_source_38            IN DATE
8253 --Credit Memo Exchange Rate
8254  , p_source_39            IN NUMBER
8255 --Credit Memo Exchange Rate Type
8256  , p_source_40            IN VARCHAR2
8257 --Gain Loss Reference
8258  , p_source_41            IN VARCHAR2
8259 --Credit Memo Accounting Amount
8260  , p_source_42            IN NUMBER
8261 --Credit Memo Bill To Customer Account Identifier
8262  , p_source_43            IN NUMBER
8263 --Credit Memo Bill To Customer Site Use Identifier
8264  , p_source_44            IN NUMBER
8265 --Credit Memo Tax Line Identifier
8266  , p_source_45            IN NUMBER
8267 --Credit Memo Distribution Account Class
8268  , p_source_46            IN VARCHAR2
8269 --Credit Memo Distribution Entered Amount
8270  , p_source_47            IN NUMBER
8271 )
8272 IS
8273 
8274 l_component_type              VARCHAR2(80);
8275 l_component_code              VARCHAR2(30);
8276 l_component_type_code         VARCHAR2(1);
8277 l_component_appl_id           INTEGER;
8278 l_amb_context_code            VARCHAR2(30);
8279 l_entity_code                 VARCHAR2(30);
8280 l_event_class_code            VARCHAR2(30);
8281 l_ae_header_id                NUMBER;
8282 l_event_type_code             VARCHAR2(30);
8283 l_line_definition_code        VARCHAR2(30);
8284 l_line_definition_owner_code  VARCHAR2(1);
8285 --
8286 -- adr variables
8287 l_segment                     VARCHAR2(30);
8288 l_ccid                        NUMBER;
8289 l_adr_transaction_coa_id      NUMBER;
8290 l_adr_accounting_coa_id       NUMBER;
8291 l_adr_flexfield_segment_code  VARCHAR2(30);
8292 l_adr_flex_value_set_id       NUMBER;
8293 l_adr_value_type_code         VARCHAR2(30);
8294 l_adr_value_combination_id    NUMBER;
8295 l_adr_value_segment_code      VARCHAR2(30);
8296 
8297 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
8298 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
8299 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
8300 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
8301 
8302 -- 4262811 Variables ------------------------------------------------------------------------------------------
8303 l_entered_amt_idx             NUMBER;
8304 l_accted_amt_idx              NUMBER;
8305 l_acc_rev_flag                VARCHAR2(1);
8306 l_accrual_line_num            NUMBER;
8307 l_tmp_amt                     NUMBER;
8308 l_acc_rev_natural_side_code   VARCHAR2(1);
8309 
8310 l_num_entries                 NUMBER;
8311 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
8312 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
8313 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
8314 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
8315 l_recog_line_1                NUMBER;
8316 l_recog_line_2                NUMBER;
8317 
8318 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
8319 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
8320 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
8321 
8322 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
8323 
8324 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
8325 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
8326 
8327 ---------------------------------------------------------------------------------------------------------------
8328 
8329 
8330 --
8331 -- bulk performance
8332 --
8333 l_balance_type_code           VARCHAR2(1);
8334 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
8335 l_log_module                  VARCHAR2(240);
8336 
8337 --
8338 -- Upgrade strategy
8339 --
8340 l_actual_upg_option           VARCHAR2(1);
8341 l_enc_upg_option           VARCHAR2(1);
8342 
8343 --
8344 BEGIN
8345 --
8346 IF g_log_enabled THEN
8347       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_28';
8348 END IF;
8349 --
8350 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8351 
8352       trace
8353          (p_msg      => 'BEGIN of AcctLineType_28'
8354          ,p_level    => C_LEVEL_PROCEDURE
8355          ,p_module   => l_log_module);
8356 
8357 END IF;
8358 --
8359 l_component_type             := 'AMB_JLT';
8360 l_component_code             := 'CM_DEFAULT_REV';
8361 l_component_type_code        := 'S';
8362 l_component_appl_id          :=  222;
8363 l_amb_context_code           := 'DEFAULT';
8364 l_entity_code                := 'TRANSACTIONS';
8365 l_event_class_code           := 'CREDIT_MEMO';
8366 l_event_type_code            := 'CREDIT_MEMO_ALL';
8367 l_line_definition_owner_code := 'S';
8368 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
8369 --
8370 l_balance_type_code          := 'A';
8371 l_segment                     := NULL;
8372 l_ccid                        := NULL;
8373 l_adr_transaction_coa_id      := NULL;
8374 l_adr_accounting_coa_id       := NULL;
8375 l_adr_flexfield_segment_code  := NULL;
8376 l_adr_flex_value_set_id       := NULL;
8377 l_adr_value_type_code         := NULL;
8378 l_adr_value_combination_id    := NULL;
8379 l_adr_value_segment_code      := NULL;
8380 
8381 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
8382 l_bflow_class_code           := '';    -- 4219869 Business Flow
8383 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
8384 l_budgetary_control_flag     := 'N';
8385 
8386 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
8387 l_bflow_applied_to_amt       := NULL; -- 5132302
8388 l_entered_amt_idx            := NULL;          -- 4262811
8389 l_accted_amt_idx             := NULL;          -- 4262811
8390 l_acc_rev_flag               := NULL;          -- 4262811
8391 l_accrual_line_num           := NULL;          -- 4262811
8392 l_tmp_amt                    := NULL;          -- 4262811
8393 --
8394  
8395 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
8396     l_balance_type_code <> 'B' THEN
8397 IF NVL(p_source_46,'
8398 ') =  'REV'
8399  THEN 
8400 
8401    --
8402    XLA_AE_LINES_PKG.SetNewLine;
8403 
8404    p_balance_type_code          := l_balance_type_code;
8405    -- set the flag so later we will know whether the gain loss line needs to be created
8406    
8407    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
8408      p_actual_flag :='A';
8409    END IF;
8410 
8411    --
8412    -- bulk performance
8413    --
8414    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
8415                                       p_header_num   => 0); -- 4262811
8416    --
8417    -- set accounting line options
8418    --
8419    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
8420            p_natural_side_code          => 'C'
8421          , p_gain_or_loss_flag          => 'N'
8422          , p_gl_transfer_mode_code      => 'S'
8423          , p_acct_entry_type_code       => 'A'
8424          , p_switch_side_flag           => 'Y'
8425          , p_merge_duplicate_code       => 'A'
8426          );
8427    --
8428    l_acc_rev_natural_side_code := 'D';  -- 4262811
8429    -- 
8430    --
8431    -- set accounting line type info
8432    --
8433    xla_ae_lines_pkg.SetAcctLineType
8434       (p_component_type             => l_component_type
8435       ,p_event_type_code            => l_event_type_code
8436       ,p_line_definition_owner_code => l_line_definition_owner_code
8437       ,p_line_definition_code       => l_line_definition_code
8438       ,p_accounting_line_code       => l_component_code
8439       ,p_accounting_line_type_code  => l_component_type_code
8440       ,p_accounting_line_appl_id    => l_component_appl_id
8441       ,p_amb_context_code           => l_amb_context_code
8442       ,p_entity_code                => l_entity_code
8443       ,p_event_class_code           => l_event_class_code);
8444    --
8445    -- set accounting class
8446    --
8447    xla_ae_lines_pkg.SetAcctClass(
8448            p_accounting_class_code  => 'REVENUE'
8449          , p_ae_header_id           => l_ae_header_id
8450          );
8451 
8452    --
8453    -- set rounding class
8454    --
8455    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
8456                       'RECEIVABLE';
8457 
8458    --
8459    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
8460    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
8461    --
8462    -- bulk performance
8463    --
8464    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
8465 
8466    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
8467       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
8468 
8469    -- 4955764
8470    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
8471       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
8472 
8473    -- 4458381 Public Sector Enh
8474    
8475    --
8476    -- set accounting attributes for the line type
8477    --
8478    l_entered_amt_idx := 3;
8479    l_accted_amt_idx  := 9;
8480    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
8481    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
8482    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_35);
8483    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
8484    l_rec_acct_attrs.array_char_value(2)  := p_source_36;
8485    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
8486    l_rec_acct_attrs.array_num_value(3)  := p_source_47;
8487    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
8488    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
8489    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
8490    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
8491    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
8492    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
8493    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
8494    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
8495    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
8496    l_rec_acct_attrs.array_char_value(8)  := p_source_41;
8497    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
8498    l_rec_acct_attrs.array_num_value(9)  := p_source_42;
8499    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
8500    l_rec_acct_attrs.array_num_value(10)  := p_source_43;
8501    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
8502    l_rec_acct_attrs.array_num_value(11)  := p_source_44;
8503    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
8504    l_rec_acct_attrs.array_char_value(12)  := p_source_25;
8505    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
8506    l_rec_acct_attrs.array_num_value(13)  := p_source_45;
8507 
8508    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
8509    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
8510 
8511    ---------------------------------------------------------------------------------------------------------------
8512    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
8513    ---------------------------------------------------------------------------------------------------------------
8514    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
8515 
8516    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
8517    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
8518 
8519    IF xla_accounting_cache_pkg.GetValueChar
8520          (p_source_code         => 'LEDGER_CATEGORY_CODE'
8521          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
8522    AND l_bflow_method_code = 'PRIOR_ENTRY'
8523 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
8524    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
8525          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
8526        )
8527    THEN
8528          xla_ae_lines_pkg.BflowUpgEntry
8529            (p_business_method_code    => l_bflow_method_code
8530            ,p_business_class_code     => l_bflow_class_code
8531            ,p_balance_type            => l_balance_type_code);
8532    ELSE
8533       NULL;
8534 -- No business flow processing for business flow method of NONE.
8535    END IF;
8536 
8537    --
8538    -- call analytical criteria
8539    --
8540    
8541    --
8542    -- call description
8543    --
8544    -- No description or it is inherited.
8545    --
8546    -- call ADRs
8547    -- Bug 4922099
8548    --
8549    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
8550         (NVL(l_actual_upg_option, 'N') = 'O') OR
8551         (NVL(l_enc_upg_option, 'N') = 'O')
8552       )
8553    THEN
8554    NULL;
8555    --
8556    --
8557    
8558   l_ccid := AcctDerRule_6(
8559            p_application_id           => p_application_id
8560          , p_ae_header_id             => l_ae_header_id 
8561 , p_source_2 => p_source_2
8562          , x_transaction_coa_id       => l_adr_transaction_coa_id
8563          , x_accounting_coa_id        => l_adr_accounting_coa_id
8564          , x_value_type_code          => l_adr_value_type_code
8565          , p_side                     => 'NA'
8566    );
8567 
8568    xla_ae_lines_pkg.set_ccid(
8569     p_code_combination_id          => l_ccid
8570   , p_value_type_code              => l_adr_value_type_code
8571   , p_transaction_coa_id           => l_adr_transaction_coa_id
8572   , p_accounting_coa_id            => l_adr_accounting_coa_id
8573   , p_adr_code                     => 'CM_DIST_CCID'
8574   , p_adr_type_code                => 'S'
8575   , p_component_type               => l_component_type
8576   , p_component_code               => l_component_code
8577   , p_component_type_code          => l_component_type_code
8578   , p_component_appl_id            => l_component_appl_id
8579   , p_amb_context_code             => l_amb_context_code
8580   , p_side                         => 'NA'
8581   );
8582 
8583 
8584    --
8585    --
8586    END IF;
8587    --
8588    -- Bug 4922099
8589    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
8590           (NVL(l_enc_upg_option, 'N') = 'O')
8591         ) AND
8592         (l_bflow_method_code = 'PRIOR_ENTRY')
8593       )
8594    THEN
8595       IF
8596       --
8597       1 = 2
8598       --
8599       THEN
8600       xla_accounting_err_pkg.build_message
8601                                     (p_appli_s_name            => 'XLA'
8602                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
8603                                     ,p_token_1                 => 'LINE_NUMBER'
8604                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
8605                                     ,p_token_2                 => 'LINE_TYPE_NAME'
8606                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
8607                                                                              l_component_type
8608                                                                             ,l_component_code
8609                                                                             ,l_component_type_code
8610                                                                             ,l_component_appl_id
8611                                                                             ,l_amb_context_code
8612                                                                             ,l_entity_code
8613                                                                             ,l_event_class_code
8614                                                                            )
8615                                     ,p_token_3                 => 'OWNER'
8616                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
8617                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
8618                                                                           ,p_lookup_code    => l_component_type_code
8619                                                                          )
8623                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
8620                                     ,p_token_4                 => 'PRODUCT_NAME'
8621                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
8622                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
8624                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
8625                                     ,p_ae_header_id            =>  NULL
8626                                        );
8627 
8628         IF (C_LEVEL_ERROR>= g_log_level) THEN
8629                  trace
8630                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
8631                       ,p_level    => C_LEVEL_ERROR
8632                       ,p_module   => l_log_module);
8633         END IF;
8634       END IF;
8635    END IF;
8636    --
8637    --
8638    ------------------------------------------------------------------------------------------------
8639    -- 4219869 Business Flow
8640    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
8641    -- Prior Entry.  Currently, the following code is always generated.
8642    ------------------------------------------------------------------------------------------------
8643    XLA_AE_LINES_PKG.ValidateCurrentLine;
8644 
8645    ------------------------------------------------------------------------------------
8646    -- 4219869 Business Flow
8647    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
8648    ------------------------------------------------------------------------------------
8649    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
8650 
8651    ----------------------------------------------------------------------------------
8652    -- 4219869 Business Flow
8653    -- Update journal entry status -- Need to generate this within IF <condition>
8654    ----------------------------------------------------------------------------------
8655    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
8656          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
8657          ,p_balance_type_code => l_balance_type_code
8658          );
8659 
8660    -------------------------------------------------------------------------------------------
8661    -- 4262811 - Generate the Accrual Reversal lines
8662    -------------------------------------------------------------------------------------------
8663    BEGIN
8664       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
8665                               (g_array_event(p_event_id).array_value_num('header_index'));
8666       IF l_acc_rev_flag IS NULL THEN
8667          l_acc_rev_flag := 'N';
8668       END IF;
8669    EXCEPTION
8670       WHEN OTHERS THEN
8671          l_acc_rev_flag := 'N';
8672    END;
8673    --
8674    IF (l_acc_rev_flag = 'Y') THEN
8675 
8676        -- 4645092  ------------------------------------------------------------------------------
8677        -- To allow MPA report to determine if it should generate report process
8678        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
8679        ------------------------------------------------------------------------------------------
8680 
8681        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
8682        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
8683    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
8684    -- call ADRs
8685    -- Bug 4922099
8686    --
8687    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
8688         (NVL(l_actual_upg_option, 'N') = 'O') OR
8689         (NVL(l_enc_upg_option, 'N') = 'O')
8690       )
8691    THEN
8692    NULL;
8693    --
8694    --
8695    
8696   l_ccid := AcctDerRule_6(
8697            p_application_id           => p_application_id
8698          , p_ae_header_id             => l_ae_header_id 
8699 , p_source_2 => p_source_2
8700          , x_transaction_coa_id       => l_adr_transaction_coa_id
8701          , x_accounting_coa_id        => l_adr_accounting_coa_id
8702          , x_value_type_code          => l_adr_value_type_code
8703          , p_side                     => 'NA'
8704    );
8705 
8706    xla_ae_lines_pkg.set_ccid(
8707     p_code_combination_id          => l_ccid
8708   , p_value_type_code              => l_adr_value_type_code
8709   , p_transaction_coa_id           => l_adr_transaction_coa_id
8710   , p_accounting_coa_id            => l_adr_accounting_coa_id
8711   , p_adr_code                     => 'CM_DIST_CCID'
8712   , p_adr_type_code                => 'S'
8713   , p_component_type               => l_component_type
8714   , p_component_code               => l_component_code
8715   , p_component_type_code          => l_component_type_code
8716   , p_component_appl_id            => l_component_appl_id
8717   , p_amb_context_code             => l_amb_context_code
8718   , p_side                         => 'NA'
8719   );
8720 
8721 
8722    --
8723    --
8724    END IF;
8725 
8726        --
8727        -- Update the line information that should be overwritten
8728        --
8729        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
8730                                          p_header_num   => 1);
8731        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
8732 
8733        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
8734 
8735        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
8736           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
8740       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
8737        END IF;
8738 
8739       --
8741       --
8742       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
8743           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
8744       ELSE
8745           ---------------------------------------------------------------------------------------------------
8746           -- 4262811a Switch Sign
8747           ---------------------------------------------------------------------------------------------------
8748           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
8749           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
8750                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8751           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
8752                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8753           -- 5132302
8754           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
8755                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8756 
8757       END IF;
8758 
8759       -- 4955764
8760       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
8761       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
8762 
8763 
8764       XLA_AE_LINES_PKG.ValidateCurrentLine;
8765       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
8766 
8767       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
8768                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
8769                ,p_balance_type_code => l_balance_type_code);
8770 
8771    END IF;
8772 
8773    -----------------------------------------------------------------------------------------
8774    -- 4262811 Multiperiod Accounting
8775    -----------------------------------------------------------------------------------------
8776      -- No MPA option is assigned.
8777 
8778 
8779 END IF;
8780 END IF;
8781 --
8782 
8783 --
8784 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8785    trace
8786       (p_msg      => 'END of AcctLineType_28'
8787       ,p_level    => C_LEVEL_PROCEDURE
8788       ,p_module   => l_log_module);
8789 END IF;
8790 --
8791 EXCEPTION
8792   WHEN xla_exceptions_pkg.application_exception THEN
8793       RAISE;
8794   WHEN OTHERS THEN
8795        xla_exceptions_pkg.raise_message
8796            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_28');
8797 END AcctLineType_28;
8798 --
8799 
8800 ---------------------------------------
8801 --
8802 -- PRIVATE FUNCTION
8803 --         AcctLineType_29
8804 --
8805 ---------------------------------------
8806 PROCEDURE AcctLineType_29 (
8807   p_application_id        IN NUMBER
8808  ,p_event_id              IN NUMBER
8809  ,p_calculate_acctd_flag  IN VARCHAR2
8810  ,p_calculate_g_l_flag    IN VARCHAR2
8811  ,p_actual_flag           IN OUT VARCHAR2
8812  ,p_balance_type_code     OUT VARCHAR2
8813  ,p_gain_or_loss_ref      OUT VARCHAR2
8814  
8815 --Credit Memo Distribution GL Account
8816  , p_source_2            IN NUMBER
8817 --SLA Party Type
8818  , p_source_25            IN VARCHAR2
8819 --Credit Memo Distribution Identifier
8820  , p_source_35            IN NUMBER
8821 --Credit memo distributions type
8822  , p_source_36            IN VARCHAR2
8823 --Credit Memo Currency Code
8824  , p_source_37            IN VARCHAR2
8825 --Credit Memo Exchange Date
8826  , p_source_38            IN DATE
8827 --Credit Memo Exchange Rate
8828  , p_source_39            IN NUMBER
8829 --Credit Memo Exchange Rate Type
8830  , p_source_40            IN VARCHAR2
8831 --Gain Loss Reference
8832  , p_source_41            IN VARCHAR2
8833 --Credit Memo Accounting Amount
8834  , p_source_42            IN NUMBER
8835 --Credit Memo Bill To Customer Account Identifier
8836  , p_source_43            IN NUMBER
8837 --Credit Memo Bill To Customer Site Use Identifier
8838  , p_source_44            IN NUMBER
8839 --Credit Memo Tax Line Identifier
8840  , p_source_45            IN NUMBER
8841 --Credit Memo Distribution Account Class
8842  , p_source_46            IN VARCHAR2
8843 --Credit Memo Distribution Entered Amount
8844  , p_source_47            IN NUMBER
8845 )
8846 IS
8847 
8848 l_component_type              VARCHAR2(80);
8849 l_component_code              VARCHAR2(30);
8850 l_component_type_code         VARCHAR2(1);
8851 l_component_appl_id           INTEGER;
8852 l_amb_context_code            VARCHAR2(30);
8853 l_entity_code                 VARCHAR2(30);
8854 l_event_class_code            VARCHAR2(30);
8855 l_ae_header_id                NUMBER;
8856 l_event_type_code             VARCHAR2(30);
8857 l_line_definition_code        VARCHAR2(30);
8858 l_line_definition_owner_code  VARCHAR2(1);
8859 --
8860 -- adr variables
8861 l_segment                     VARCHAR2(30);
8862 l_ccid                        NUMBER;
8863 l_adr_transaction_coa_id      NUMBER;
8864 l_adr_accounting_coa_id       NUMBER;
8865 l_adr_flexfield_segment_code  VARCHAR2(30);
8866 l_adr_flex_value_set_id       NUMBER;
8867 l_adr_value_type_code         VARCHAR2(30);
8868 l_adr_value_combination_id    NUMBER;
8869 l_adr_value_segment_code      VARCHAR2(30);
8870 
8871 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
8872 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
8873 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
8874 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
8875 
8876 -- 4262811 Variables ------------------------------------------------------------------------------------------
8877 l_entered_amt_idx             NUMBER;
8878 l_accted_amt_idx              NUMBER;
8879 l_acc_rev_flag                VARCHAR2(1);
8880 l_accrual_line_num            NUMBER;
8881 l_tmp_amt                     NUMBER;
8882 l_acc_rev_natural_side_code   VARCHAR2(1);
8883 
8884 l_num_entries                 NUMBER;
8885 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
8886 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
8887 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
8888 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
8889 l_recog_line_1                NUMBER;
8890 l_recog_line_2                NUMBER;
8891 
8892 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
8893 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
8894 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
8895 
8896 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
8897 
8898 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
8899 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
8900 
8901 ---------------------------------------------------------------------------------------------------------------
8902 
8903 
8904 --
8905 -- bulk performance
8906 --
8907 l_balance_type_code           VARCHAR2(1);
8908 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
8909 l_log_module                  VARCHAR2(240);
8910 
8911 --
8912 -- Upgrade strategy
8913 --
8914 l_actual_upg_option           VARCHAR2(1);
8915 l_enc_upg_option           VARCHAR2(1);
8916 
8917 --
8918 BEGIN
8919 --
8920 IF g_log_enabled THEN
8921       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_29';
8922 END IF;
8923 --
8924 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8925 
8926       trace
8927          (p_msg      => 'BEGIN of AcctLineType_29'
8928          ,p_level    => C_LEVEL_PROCEDURE
8929          ,p_module   => l_log_module);
8930 
8931 END IF;
8932 --
8933 l_component_type             := 'AMB_JLT';
8934 l_component_code             := 'CM_DEFAULT_TAX';
8935 l_component_type_code        := 'S';
8936 l_component_appl_id          :=  222;
8937 l_amb_context_code           := 'DEFAULT';
8938 l_entity_code                := 'TRANSACTIONS';
8939 l_event_class_code           := 'CREDIT_MEMO';
8940 l_event_type_code            := 'CREDIT_MEMO_ALL';
8941 l_line_definition_owner_code := 'S';
8942 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
8943 --
8944 l_balance_type_code          := 'A';
8945 l_segment                     := NULL;
8946 l_ccid                        := NULL;
8947 l_adr_transaction_coa_id      := NULL;
8948 l_adr_accounting_coa_id       := NULL;
8949 l_adr_flexfield_segment_code  := NULL;
8950 l_adr_flex_value_set_id       := NULL;
8951 l_adr_value_type_code         := NULL;
8952 l_adr_value_combination_id    := NULL;
8953 l_adr_value_segment_code      := NULL;
8954 
8955 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
8956 l_bflow_class_code           := '';    -- 4219869 Business Flow
8957 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
8958 l_budgetary_control_flag     := 'N';
8959 
8960 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
8961 l_bflow_applied_to_amt       := NULL; -- 5132302
8962 l_entered_amt_idx            := NULL;          -- 4262811
8963 l_accted_amt_idx             := NULL;          -- 4262811
8964 l_acc_rev_flag               := NULL;          -- 4262811
8965 l_accrual_line_num           := NULL;          -- 4262811
8966 l_tmp_amt                    := NULL;          -- 4262811
8967 --
8968  
8969 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
8970     l_balance_type_code <> 'B' THEN
8971 IF NVL(p_source_46,'
8972 ') =  'TAX'
8973  THEN 
8974 
8975    --
8976    XLA_AE_LINES_PKG.SetNewLine;
8977 
8978    p_balance_type_code          := l_balance_type_code;
8979    -- set the flag so later we will know whether the gain loss line needs to be created
8980    
8981    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
8982      p_actual_flag :='A';
8983    END IF;
8984 
8985    --
8986    -- bulk performance
8987    --
8988    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
8989                                       p_header_num   => 0); -- 4262811
8990    --
8991    -- set accounting line options
8992    --
8993    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
8994            p_natural_side_code          => 'C'
8995          , p_gain_or_loss_flag          => 'N'
8996          , p_gl_transfer_mode_code      => 'S'
8997          , p_acct_entry_type_code       => 'A'
8998          , p_switch_side_flag           => 'Y'
8999          , p_merge_duplicate_code       => 'A'
9000          );
9001    --
9002    l_acc_rev_natural_side_code := 'D';  -- 4262811
9003    -- 
9004    --
9005    -- set accounting line type info
9006    --
9007    xla_ae_lines_pkg.SetAcctLineType
9008       (p_component_type             => l_component_type
9009       ,p_event_type_code            => l_event_type_code
9010       ,p_line_definition_owner_code => l_line_definition_owner_code
9011       ,p_line_definition_code       => l_line_definition_code
9012       ,p_accounting_line_code       => l_component_code
9013       ,p_accounting_line_type_code  => l_component_type_code
9014       ,p_accounting_line_appl_id    => l_component_appl_id
9015       ,p_amb_context_code           => l_amb_context_code
9016       ,p_entity_code                => l_entity_code
9017       ,p_event_class_code           => l_event_class_code);
9018    --
9019    -- set accounting class
9020    --
9021    xla_ae_lines_pkg.SetAcctClass(
9022            p_accounting_class_code  => 'TAX'
9023          , p_ae_header_id           => l_ae_header_id
9024          );
9025 
9026    --
9027    -- set rounding class
9028    --
9029    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
9030                       'RECEIVABLE';
9031 
9032    --
9033    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
9034    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
9035    --
9036    -- bulk performance
9037    --
9038    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
9039 
9040    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
9041       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
9042 
9043    -- 4955764
9044    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
9045       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
9046 
9047    -- 4458381 Public Sector Enh
9048    
9049    --
9050    -- set accounting attributes for the line type
9051    --
9052    l_entered_amt_idx := 3;
9053    l_accted_amt_idx  := 9;
9054    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
9055    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
9056    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_35);
9057    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
9058    l_rec_acct_attrs.array_char_value(2)  := p_source_36;
9059    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
9060    l_rec_acct_attrs.array_num_value(3)  := p_source_47;
9061    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
9062    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
9063    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
9064    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
9065    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
9066    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
9067    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
9068    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
9069    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
9070    l_rec_acct_attrs.array_char_value(8)  := p_source_41;
9071    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
9072    l_rec_acct_attrs.array_num_value(9)  := p_source_42;
9073    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
9074    l_rec_acct_attrs.array_num_value(10)  := p_source_43;
9075    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
9076    l_rec_acct_attrs.array_num_value(11)  := p_source_44;
9077    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
9078    l_rec_acct_attrs.array_char_value(12)  := p_source_25;
9079    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
9080    l_rec_acct_attrs.array_num_value(13)  := p_source_45;
9081 
9082    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
9083    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
9084 
9085    ---------------------------------------------------------------------------------------------------------------
9086    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
9087    ---------------------------------------------------------------------------------------------------------------
9088    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
9089 
9090    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
9091    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
9092 
9093    IF xla_accounting_cache_pkg.GetValueChar
9094          (p_source_code         => 'LEDGER_CATEGORY_CODE'
9095          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
9096    AND l_bflow_method_code = 'PRIOR_ENTRY'
9097 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
9098    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
9099          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
9100        )
9101    THEN
9102          xla_ae_lines_pkg.BflowUpgEntry
9103            (p_business_method_code    => l_bflow_method_code
9104            ,p_business_class_code     => l_bflow_class_code
9105            ,p_balance_type            => l_balance_type_code);
9106    ELSE
9107       NULL;
9108 -- No business flow processing for business flow method of NONE.
9109    END IF;
9110 
9111    --
9112    -- call analytical criteria
9113    --
9114    
9115    --
9116    -- call description
9117    --
9118    -- No description or it is inherited.
9119    --
9120    -- call ADRs
9121    -- Bug 4922099
9122    --
9123    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
9127    THEN
9124         (NVL(l_actual_upg_option, 'N') = 'O') OR
9125         (NVL(l_enc_upg_option, 'N') = 'O')
9126       )
9128    NULL;
9129    --
9130    --
9131    
9132   l_ccid := AcctDerRule_6(
9133            p_application_id           => p_application_id
9134          , p_ae_header_id             => l_ae_header_id 
9135 , p_source_2 => p_source_2
9136          , x_transaction_coa_id       => l_adr_transaction_coa_id
9137          , x_accounting_coa_id        => l_adr_accounting_coa_id
9138          , x_value_type_code          => l_adr_value_type_code
9139          , p_side                     => 'NA'
9140    );
9141 
9142    xla_ae_lines_pkg.set_ccid(
9143     p_code_combination_id          => l_ccid
9144   , p_value_type_code              => l_adr_value_type_code
9145   , p_transaction_coa_id           => l_adr_transaction_coa_id
9146   , p_accounting_coa_id            => l_adr_accounting_coa_id
9147   , p_adr_code                     => 'CM_DIST_CCID'
9148   , p_adr_type_code                => 'S'
9149   , p_component_type               => l_component_type
9150   , p_component_code               => l_component_code
9151   , p_component_type_code          => l_component_type_code
9152   , p_component_appl_id            => l_component_appl_id
9153   , p_amb_context_code             => l_amb_context_code
9154   , p_side                         => 'NA'
9155   );
9156 
9157 
9158    --
9159    --
9160    END IF;
9161    --
9162    -- Bug 4922099
9163    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
9164           (NVL(l_enc_upg_option, 'N') = 'O')
9165         ) AND
9166         (l_bflow_method_code = 'PRIOR_ENTRY')
9167       )
9168    THEN
9169       IF
9170       --
9171       1 = 2
9172       --
9173       THEN
9174       xla_accounting_err_pkg.build_message
9175                                     (p_appli_s_name            => 'XLA'
9176                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
9177                                     ,p_token_1                 => 'LINE_NUMBER'
9178                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
9179                                     ,p_token_2                 => 'LINE_TYPE_NAME'
9180                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
9181                                                                              l_component_type
9182                                                                             ,l_component_code
9183                                                                             ,l_component_type_code
9184                                                                             ,l_component_appl_id
9185                                                                             ,l_amb_context_code
9186                                                                             ,l_entity_code
9187                                                                             ,l_event_class_code
9188                                                                            )
9189                                     ,p_token_3                 => 'OWNER'
9190                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
9191                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
9192                                                                           ,p_lookup_code    => l_component_type_code
9193                                                                          )
9194                                     ,p_token_4                 => 'PRODUCT_NAME'
9195                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
9196                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
9197                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
9198                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
9199                                     ,p_ae_header_id            =>  NULL
9200                                        );
9201 
9202         IF (C_LEVEL_ERROR>= g_log_level) THEN
9203                  trace
9204                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
9205                       ,p_level    => C_LEVEL_ERROR
9206                       ,p_module   => l_log_module);
9207         END IF;
9208       END IF;
9209    END IF;
9210    --
9211    --
9212    ------------------------------------------------------------------------------------------------
9213    -- 4219869 Business Flow
9214    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
9215    -- Prior Entry.  Currently, the following code is always generated.
9216    ------------------------------------------------------------------------------------------------
9217    XLA_AE_LINES_PKG.ValidateCurrentLine;
9218 
9219    ------------------------------------------------------------------------------------
9220    -- 4219869 Business Flow
9221    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
9222    ------------------------------------------------------------------------------------
9223    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
9224 
9225    ----------------------------------------------------------------------------------
9226    -- 4219869 Business Flow
9227    -- Update journal entry status -- Need to generate this within IF <condition>
9228    ----------------------------------------------------------------------------------
9229    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
9230          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
9231          ,p_balance_type_code => l_balance_type_code
9232          );
9233 
9234    -------------------------------------------------------------------------------------------
9235    -- 4262811 - Generate the Accrual Reversal lines
9236    -------------------------------------------------------------------------------------------
9237    BEGIN
9238       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
9239                               (g_array_event(p_event_id).array_value_num('header_index'));
9240       IF l_acc_rev_flag IS NULL THEN
9241          l_acc_rev_flag := 'N';
9242       END IF;
9243    EXCEPTION
9244       WHEN OTHERS THEN
9245          l_acc_rev_flag := 'N';
9246    END;
9247    --
9248    IF (l_acc_rev_flag = 'Y') THEN
9249 
9250        -- 4645092  ------------------------------------------------------------------------------
9251        -- To allow MPA report to determine if it should generate report process
9252        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
9253        ------------------------------------------------------------------------------------------
9254 
9255        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
9256        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
9257    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
9258    -- call ADRs
9259    -- Bug 4922099
9260    --
9261    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
9262         (NVL(l_actual_upg_option, 'N') = 'O') OR
9263         (NVL(l_enc_upg_option, 'N') = 'O')
9264       )
9265    THEN
9266    NULL;
9267    --
9268    --
9269    
9270   l_ccid := AcctDerRule_6(
9271            p_application_id           => p_application_id
9272          , p_ae_header_id             => l_ae_header_id 
9273 , p_source_2 => p_source_2
9274          , x_transaction_coa_id       => l_adr_transaction_coa_id
9275          , x_accounting_coa_id        => l_adr_accounting_coa_id
9276          , x_value_type_code          => l_adr_value_type_code
9277          , p_side                     => 'NA'
9278    );
9279 
9280    xla_ae_lines_pkg.set_ccid(
9281     p_code_combination_id          => l_ccid
9282   , p_value_type_code              => l_adr_value_type_code
9283   , p_transaction_coa_id           => l_adr_transaction_coa_id
9284   , p_accounting_coa_id            => l_adr_accounting_coa_id
9285   , p_adr_code                     => 'CM_DIST_CCID'
9286   , p_adr_type_code                => 'S'
9287   , p_component_type               => l_component_type
9288   , p_component_code               => l_component_code
9289   , p_component_type_code          => l_component_type_code
9290   , p_component_appl_id            => l_component_appl_id
9291   , p_amb_context_code             => l_amb_context_code
9292   , p_side                         => 'NA'
9293   );
9294 
9295 
9296    --
9297    --
9298    END IF;
9299 
9300        --
9301        -- Update the line information that should be overwritten
9302        --
9303        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
9304                                          p_header_num   => 1);
9305        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
9306 
9307        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
9308 
9309        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
9310           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
9311        END IF;
9312 
9313       --
9314       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
9315       --
9316       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
9317           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
9318       ELSE
9319           ---------------------------------------------------------------------------------------------------
9320           -- 4262811a Switch Sign
9321           ---------------------------------------------------------------------------------------------------
9322           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
9323           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
9324                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
9325           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
9326                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
9327           -- 5132302
9328           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
9329                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
9330 
9331       END IF;
9332 
9333       -- 4955764
9334       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
9335       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
9336 
9337 
9338       XLA_AE_LINES_PKG.ValidateCurrentLine;
9339       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
9340 
9341       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
9342                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
9343                ,p_balance_type_code => l_balance_type_code);
9344 
9345    END IF;
9346 
9347    -----------------------------------------------------------------------------------------
9348    -- 4262811 Multiperiod Accounting
9352 
9349    -----------------------------------------------------------------------------------------
9350      -- No MPA option is assigned.
9351 
9353 END IF;
9354 END IF;
9355 --
9356 
9357 --
9358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9359    trace
9360       (p_msg      => 'END of AcctLineType_29'
9361       ,p_level    => C_LEVEL_PROCEDURE
9362       ,p_module   => l_log_module);
9363 END IF;
9364 --
9365 EXCEPTION
9366   WHEN xla_exceptions_pkg.application_exception THEN
9367       RAISE;
9368   WHEN OTHERS THEN
9369        xla_exceptions_pkg.raise_message
9370            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_29');
9371 END AcctLineType_29;
9372 --
9373 
9374 ---------------------------------------
9375 --
9376 -- PRIVATE FUNCTION
9377 --         AcctLineType_30
9378 --
9379 ---------------------------------------
9380 PROCEDURE AcctLineType_30 (
9381   p_application_id        IN NUMBER
9382  ,p_event_id              IN NUMBER
9383  ,p_calculate_acctd_flag  IN VARCHAR2
9384  ,p_calculate_g_l_flag    IN VARCHAR2
9385  ,p_actual_flag           IN OUT VARCHAR2
9386  ,p_balance_type_code     OUT VARCHAR2
9387  ,p_gain_or_loss_ref      OUT VARCHAR2
9388  
9389 --System Gain Account
9390  , p_source_11            IN NUMBER
9391 --System Loss Account
9392  , p_source_12            IN NUMBER
9393 --SLA Party Type
9394  , p_source_25            IN VARCHAR2
9395 --Credit Memo Distribution Identifier
9396  , p_source_35            IN NUMBER
9397 --Credit memo distributions type
9398  , p_source_36            IN VARCHAR2
9399 --Gain Loss Reference
9400  , p_source_41            IN VARCHAR2
9401 --Credit Memo Accounting Amount
9402  , p_source_42            IN NUMBER
9403 --Credit Memo Bill To Customer Account Identifier
9404  , p_source_43            IN NUMBER
9405 --Credit Memo Bill To Customer Site Use Identifier
9406  , p_source_44            IN NUMBER
9407 --Credit Memo Tax Line Identifier
9408  , p_source_45            IN NUMBER
9409 )
9410 IS
9411 
9412 l_component_type              VARCHAR2(80);
9413 l_component_code              VARCHAR2(30);
9414 l_component_type_code         VARCHAR2(1);
9415 l_component_appl_id           INTEGER;
9416 l_amb_context_code            VARCHAR2(30);
9417 l_entity_code                 VARCHAR2(30);
9418 l_event_class_code            VARCHAR2(30);
9419 l_ae_header_id                NUMBER;
9420 l_event_type_code             VARCHAR2(30);
9421 l_line_definition_code        VARCHAR2(30);
9422 l_line_definition_owner_code  VARCHAR2(1);
9423 --
9424 -- adr variables
9425 l_segment                     VARCHAR2(30);
9426 l_ccid                        NUMBER;
9427 l_adr_transaction_coa_id      NUMBER;
9428 l_adr_accounting_coa_id       NUMBER;
9429 l_adr_flexfield_segment_code  VARCHAR2(30);
9430 l_adr_flex_value_set_id       NUMBER;
9431 l_adr_value_type_code         VARCHAR2(30);
9432 l_adr_value_combination_id    NUMBER;
9433 l_adr_value_segment_code      VARCHAR2(30);
9434 
9435 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
9436 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
9437 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
9438 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
9439 
9440 -- 4262811 Variables ------------------------------------------------------------------------------------------
9441 l_entered_amt_idx             NUMBER;
9442 l_accted_amt_idx              NUMBER;
9443 l_acc_rev_flag                VARCHAR2(1);
9444 l_accrual_line_num            NUMBER;
9445 l_tmp_amt                     NUMBER;
9446 l_acc_rev_natural_side_code   VARCHAR2(1);
9447 
9448 l_num_entries                 NUMBER;
9449 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
9450 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
9451 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
9452 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
9453 l_recog_line_1                NUMBER;
9454 l_recog_line_2                NUMBER;
9455 
9456 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
9457 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
9458 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
9459 
9460 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
9461 
9462 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
9463 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
9464 
9465 ---------------------------------------------------------------------------------------------------------------
9466 
9467 
9468 --
9469 -- bulk performance
9470 --
9471 l_balance_type_code           VARCHAR2(1);
9472 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
9473 l_log_module                  VARCHAR2(240);
9474 
9475 --
9476 -- Upgrade strategy
9477 --
9478 l_actual_upg_option           VARCHAR2(1);
9479 l_enc_upg_option           VARCHAR2(1);
9480 
9481 --
9482 BEGIN
9483 --
9484 IF g_log_enabled THEN
9485       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_30';
9486 END IF;
9487 --
9488 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9489 
9490       trace
9491          (p_msg      => 'BEGIN of AcctLineType_30'
9492          ,p_level    => C_LEVEL_PROCEDURE
9493          ,p_module   => l_log_module);
9494 
9495 END IF;
9496 --
9497 l_component_type             := 'AMB_JLT';
9498 l_component_code             := 'CM_EXCH_GAIN_LOSS';
9499 l_component_type_code        := 'S';
9500 l_component_appl_id          :=  222;
9501 l_amb_context_code           := 'DEFAULT';
9502 l_entity_code                := 'TRANSACTIONS';
9503 l_event_class_code           := 'CREDIT_MEMO';
9504 l_event_type_code            := 'CREDIT_MEMO_ALL';
9505 l_line_definition_owner_code := 'S';
9506 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
9507 --
9508 l_balance_type_code          := 'A';
9509 l_segment                     := NULL;
9510 l_ccid                        := NULL;
9511 l_adr_transaction_coa_id      := NULL;
9512 l_adr_accounting_coa_id       := NULL;
9513 l_adr_flexfield_segment_code  := NULL;
9514 l_adr_flex_value_set_id       := NULL;
9515 l_adr_value_type_code         := NULL;
9516 l_adr_value_combination_id    := NULL;
9517 l_adr_value_segment_code      := NULL;
9518 
9519 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
9520 l_bflow_class_code           := '';    -- 4219869 Business Flow
9521 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
9522 l_budgetary_control_flag     := 'N';
9523 
9524 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
9525 l_bflow_applied_to_amt       := NULL; -- 5132302
9526 l_entered_amt_idx            := NULL;          -- 4262811
9527 l_accted_amt_idx             := NULL;          -- 4262811
9528 l_acc_rev_flag               := NULL;          -- 4262811
9529 l_accrual_line_num           := NULL;          -- 4262811
9530 l_tmp_amt                    := NULL;          -- 4262811
9531 --
9532 IF NOT ((p_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
9533             (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
9534                return;
9535   END IF;
9536   
9537 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
9538     l_balance_type_code <> 'B' THEN
9539 
9540    --
9541    XLA_AE_LINES_PKG.SetNewLine;
9542 
9543    p_balance_type_code          := l_balance_type_code;
9544    -- set the flag so later we will know whether the gain loss line needs to be created
9545    
9546    IF(l_balance_type_code = 'A' ) THEN
9547      p_actual_flag :='G';
9548    END IF;
9549 
9550    --
9551    -- bulk performance
9552    --
9553    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
9554                                       p_header_num   => 0); -- 4262811
9555    --
9556    -- set accounting line options
9557    --
9558    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
9559            p_natural_side_code          => 'G'
9560          , p_gain_or_loss_flag          => 'N'
9561          , p_gl_transfer_mode_code      => 'S'
9562          , p_acct_entry_type_code       => 'A'
9563          , p_switch_side_flag           => ''
9564          , p_merge_duplicate_code       => 'A'
9565          );
9566    --
9567    l_acc_rev_natural_side_code := 'C';  -- 4262811
9568    -- 
9569    --
9570    -- set accounting line type info
9571    --
9572    xla_ae_lines_pkg.SetAcctLineType
9573       (p_component_type             => l_component_type
9574       ,p_event_type_code            => l_event_type_code
9575       ,p_line_definition_owner_code => l_line_definition_owner_code
9576       ,p_line_definition_code       => l_line_definition_code
9577       ,p_accounting_line_code       => l_component_code
9578       ,p_accounting_line_type_code  => l_component_type_code
9579       ,p_accounting_line_appl_id    => l_component_appl_id
9580       ,p_amb_context_code           => l_amb_context_code
9581       ,p_entity_code                => l_entity_code
9582       ,p_event_class_code           => l_event_class_code);
9583    --
9584    -- set accounting class
9585    --
9586    xla_ae_lines_pkg.SetAcctClass(
9587            p_accounting_class_code  => 'EXCHANGE_GAIN_LOSS'
9588          , p_ae_header_id           => l_ae_header_id
9589          );
9590 
9591    --
9592    -- set rounding class
9593    --
9594    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
9595                       'EXCHANGE_GAIN_LOSS';
9596 
9597    --
9598    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
9602    --
9599    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
9600    --
9601    -- bulk performance
9603    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
9604 
9605    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
9606       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
9607 
9608    -- 4955764
9609    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
9610       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
9611 
9612    -- 4458381 Public Sector Enh
9613    
9614    --
9615    -- set accounting attributes for the line type
9616    --
9617    l_entered_amt_idx := NULL;
9618    l_accted_amt_idx  := 4;
9619    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
9620    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
9621    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_35);
9622    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
9623    l_rec_acct_attrs.array_char_value(2)  := p_source_36;
9624    l_rec_acct_attrs.array_acct_attr_code(3) := 'GAIN_LOSS_REFERENCE';
9625    l_rec_acct_attrs.array_char_value(3)  := p_source_41;
9626    l_rec_acct_attrs.array_acct_attr_code(4) := 'LEDGER_AMOUNT';
9627    l_rec_acct_attrs.array_num_value(4)  := p_source_42;
9628    l_rec_acct_attrs.array_acct_attr_code(5) := 'PARTY_ID';
9629    l_rec_acct_attrs.array_num_value(5)  := p_source_43;
9630    l_rec_acct_attrs.array_acct_attr_code(6) := 'PARTY_SITE_ID';
9631    l_rec_acct_attrs.array_num_value(6)  := p_source_44;
9632    l_rec_acct_attrs.array_acct_attr_code(7) := 'PARTY_TYPE';
9633    l_rec_acct_attrs.array_char_value(7)  := p_source_25;
9634    l_rec_acct_attrs.array_acct_attr_code(8) := 'TAX_LINE_REF_ID';
9635    l_rec_acct_attrs.array_num_value(8)  := p_source_45;
9636 
9637    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
9638    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
9639 
9640    ---------------------------------------------------------------------------------------------------------------
9641    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
9642    ---------------------------------------------------------------------------------------------------------------
9643    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
9644 
9645    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
9646    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
9647 
9648    IF xla_accounting_cache_pkg.GetValueChar
9649          (p_source_code         => 'LEDGER_CATEGORY_CODE'
9650          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
9651    AND l_bflow_method_code = 'PRIOR_ENTRY'
9652 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
9653    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
9654          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
9655        )
9656    THEN
9657          xla_ae_lines_pkg.BflowUpgEntry
9658            (p_business_method_code    => l_bflow_method_code
9659            ,p_business_class_code     => l_bflow_class_code
9660            ,p_balance_type            => l_balance_type_code);
9661    ELSE
9662       NULL;
9663 -- No business flow processing for business flow method of NONE.
9664    END IF;
9665 
9666    --
9667    -- call analytical criteria
9668    --
9669    
9670    --
9671    -- call description
9672    --
9673    -- No description or it is inherited.
9674    --
9675    -- call ADRs
9676    -- Bug 4922099
9677    --
9678    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
9679         (NVL(l_actual_upg_option, 'N') = 'O') OR
9680         (NVL(l_enc_upg_option, 'N') = 'O')
9681       )
9682    THEN
9683    NULL;
9684    --
9685    --
9686    
9687   l_ccid := AcctDerRule_14(
9688            p_application_id           => p_application_id
9689          , p_ae_header_id             => l_ae_header_id 
9690 , p_source_11 => p_source_11
9691          , x_transaction_coa_id       => l_adr_transaction_coa_id
9692          , x_accounting_coa_id        => l_adr_accounting_coa_id
9693          , x_value_type_code          => l_adr_value_type_code
9694          , p_side                     => 'CREDIT'
9695    );
9696 
9697    xla_ae_lines_pkg.set_ccid(
9698     p_code_combination_id          => l_ccid
9699   , p_value_type_code              => l_adr_value_type_code
9700   , p_transaction_coa_id           => l_adr_transaction_coa_id
9701   , p_accounting_coa_id            => l_adr_accounting_coa_id
9702   , p_adr_code                     => 'SYS_GAIN_CCID'
9703   , p_adr_type_code                => 'S'
9704   , p_component_type               => l_component_type
9705   , p_component_code               => l_component_code
9706   , p_component_type_code          => l_component_type_code
9707   , p_component_appl_id            => l_component_appl_id
9708   , p_amb_context_code             => l_amb_context_code
9709   , p_side                         => 'CREDIT'
9710   );
9711 
9712 
9713   l_ccid := AcctDerRule_15(
9714            p_application_id           => p_application_id
9715          , p_ae_header_id             => l_ae_header_id 
9716 , p_source_12 => p_source_12
9717          , x_transaction_coa_id       => l_adr_transaction_coa_id
9718          , x_accounting_coa_id        => l_adr_accounting_coa_id
9719          , x_value_type_code          => l_adr_value_type_code
9720          , p_side                     => 'DEBIT'
9721    );
9722 
9723    xla_ae_lines_pkg.set_ccid(
9724     p_code_combination_id          => l_ccid
9725   , p_value_type_code              => l_adr_value_type_code
9726   , p_transaction_coa_id           => l_adr_transaction_coa_id
9727   , p_accounting_coa_id            => l_adr_accounting_coa_id
9728   , p_adr_code                     => 'SYS_LOSS_CCID'
9729   , p_adr_type_code                => 'S'
9730   , p_component_type               => l_component_type
9731   , p_component_code               => l_component_code
9732   , p_component_type_code          => l_component_type_code
9733   , p_component_appl_id            => l_component_appl_id
9734   , p_amb_context_code             => l_amb_context_code
9735   , p_side                         => 'DEBIT'
9736   );
9737 
9738 
9739    --
9740    --
9741    END IF;
9742    --
9743    -- Bug 4922099
9744    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
9745           (NVL(l_enc_upg_option, 'N') = 'O')
9746         ) AND
9747         (l_bflow_method_code = 'PRIOR_ENTRY')
9748       )
9749    THEN
9750       IF
9751       --
9752       1 = 2
9753       --
9754       THEN
9755       xla_accounting_err_pkg.build_message
9756                                     (p_appli_s_name            => 'XLA'
9757                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
9758                                     ,p_token_1                 => 'LINE_NUMBER'
9759                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
9760                                     ,p_token_2                 => 'LINE_TYPE_NAME'
9761                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
9762                                                                              l_component_type
9763                                                                             ,l_component_code
9764                                                                             ,l_component_type_code
9765                                                                             ,l_component_appl_id
9766                                                                             ,l_amb_context_code
9767                                                                             ,l_entity_code
9768                                                                             ,l_event_class_code
9769                                                                            )
9770                                     ,p_token_3                 => 'OWNER'
9771                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
9772                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
9773                                                                           ,p_lookup_code    => l_component_type_code
9774                                                                          )
9775                                     ,p_token_4                 => 'PRODUCT_NAME'
9776                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
9777                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
9778                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
9779                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
9780                                     ,p_ae_header_id            =>  NULL
9781                                        );
9782 
9783         IF (C_LEVEL_ERROR>= g_log_level) THEN
9784                  trace
9785                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
9786                       ,p_level    => C_LEVEL_ERROR
9787                       ,p_module   => l_log_module);
9788         END IF;
9789       END IF;
9790    END IF;
9791    --
9792    --
9793    ------------------------------------------------------------------------------------------------
9794    -- 4219869 Business Flow
9795    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
9796    -- Prior Entry.  Currently, the following code is always generated.
9797    ------------------------------------------------------------------------------------------------
9798    XLA_AE_LINES_PKG.ValidateCurrentLine;
9799 
9800    ------------------------------------------------------------------------------------
9801    -- 4219869 Business Flow
9802    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
9803    ------------------------------------------------------------------------------------
9804    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
9805 
9806    ----------------------------------------------------------------------------------
9807    -- 4219869 Business Flow
9808    -- Update journal entry status -- Need to generate this within IF <condition>
9809    ----------------------------------------------------------------------------------
9810    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
9811          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
9812          ,p_balance_type_code => l_balance_type_code
9813          );
9814 
9815    -------------------------------------------------------------------------------------------
9816    -- 4262811 - Generate the Accrual Reversal lines
9817    -------------------------------------------------------------------------------------------
9818    BEGIN
9819       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
9820                               (g_array_event(p_event_id).array_value_num('header_index'));
9821       IF l_acc_rev_flag IS NULL THEN
9822          l_acc_rev_flag := 'N';
9823       END IF;
9824    EXCEPTION
9825       WHEN OTHERS THEN
9826          l_acc_rev_flag := 'N';
9827    END;
9828    --
9829    IF (l_acc_rev_flag = 'Y') THEN
9830 
9831        -- 4645092  ------------------------------------------------------------------------------
9832        -- To allow MPA report to determine if it should generate report process
9833        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
9834        ------------------------------------------------------------------------------------------
9835 
9836        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
9837        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
9838    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
9839    -- call ADRs
9840    -- Bug 4922099
9841    --
9842    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
9843         (NVL(l_actual_upg_option, 'N') = 'O') OR
9844         (NVL(l_enc_upg_option, 'N') = 'O')
9845       )
9846    THEN
9847    NULL;
9848    --
9849    --
9850    
9851   l_ccid := AcctDerRule_14(
9852            p_application_id           => p_application_id
9853          , p_ae_header_id             => l_ae_header_id 
9854 , p_source_11 => p_source_11
9855          , x_transaction_coa_id       => l_adr_transaction_coa_id
9856          , x_accounting_coa_id        => l_adr_accounting_coa_id
9857          , x_value_type_code          => l_adr_value_type_code
9861    xla_ae_lines_pkg.set_ccid(
9858          , p_side                     => 'CREDIT'
9859    );
9860 
9862     p_code_combination_id          => l_ccid
9863   , p_value_type_code              => l_adr_value_type_code
9864   , p_transaction_coa_id           => l_adr_transaction_coa_id
9865   , p_accounting_coa_id            => l_adr_accounting_coa_id
9866   , p_adr_code                     => 'SYS_GAIN_CCID'
9867   , p_adr_type_code                => 'S'
9868   , p_component_type               => l_component_type
9869   , p_component_code               => l_component_code
9870   , p_component_type_code          => l_component_type_code
9871   , p_component_appl_id            => l_component_appl_id
9872   , p_amb_context_code             => l_amb_context_code
9873   , p_side                         => 'CREDIT'
9874   );
9875 
9876 
9877   l_ccid := AcctDerRule_15(
9878            p_application_id           => p_application_id
9879          , p_ae_header_id             => l_ae_header_id 
9880 , p_source_12 => p_source_12
9881          , x_transaction_coa_id       => l_adr_transaction_coa_id
9882          , x_accounting_coa_id        => l_adr_accounting_coa_id
9883          , x_value_type_code          => l_adr_value_type_code
9884          , p_side                     => 'DEBIT'
9885    );
9886 
9887    xla_ae_lines_pkg.set_ccid(
9888     p_code_combination_id          => l_ccid
9889   , p_value_type_code              => l_adr_value_type_code
9890   , p_transaction_coa_id           => l_adr_transaction_coa_id
9891   , p_accounting_coa_id            => l_adr_accounting_coa_id
9892   , p_adr_code                     => 'SYS_LOSS_CCID'
9893   , p_adr_type_code                => 'S'
9894   , p_component_type               => l_component_type
9895   , p_component_code               => l_component_code
9896   , p_component_type_code          => l_component_type_code
9897   , p_component_appl_id            => l_component_appl_id
9898   , p_amb_context_code             => l_amb_context_code
9899   , p_side                         => 'DEBIT'
9900   );
9901 
9902 
9903    --
9904    --
9905    END IF;
9906 
9907        --
9908        -- Update the line information that should be overwritten
9909        --
9910        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
9911                                          p_header_num   => 1);
9912        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
9913 
9914        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
9915 
9916        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
9917           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
9918        END IF;
9919 
9920       --
9921       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
9922       --
9923       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
9924           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
9925       ELSE
9926           ---------------------------------------------------------------------------------------------------
9927           -- 4262811a Switch Sign
9928           ---------------------------------------------------------------------------------------------------
9929           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
9930           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
9931                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
9932           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
9933                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
9934           -- 5132302
9935           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
9936                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
9937 
9938       END IF;
9939 
9940       -- 4955764
9941       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
9942       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
9943 
9944 
9945       XLA_AE_LINES_PKG.ValidateCurrentLine;
9946       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
9947 
9948       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
9949                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
9950                ,p_balance_type_code => l_balance_type_code);
9951 
9952    END IF;
9953 
9954    -----------------------------------------------------------------------------------------
9955    -- 4262811 Multiperiod Accounting
9956    -----------------------------------------------------------------------------------------
9957      -- No MPA option is assigned.
9958 
9959 
9960 END IF;
9961 --
9962 
9963 --
9964 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9965    trace
9966       (p_msg      => 'END of AcctLineType_30'
9967       ,p_level    => C_LEVEL_PROCEDURE
9968       ,p_module   => l_log_module);
9969 END IF;
9970 --
9971 EXCEPTION
9972   WHEN xla_exceptions_pkg.application_exception THEN
9973       RAISE;
9974   WHEN OTHERS THEN
9975        xla_exceptions_pkg.raise_message
9976            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_30');
9977 END AcctLineType_30;
9978 --
9979 
9980 ---------------------------------------
9981 --
9982 -- PRIVATE FUNCTION
9983 --         AcctLineType_31
9984 --
9985 ---------------------------------------
9986 PROCEDURE AcctLineType_31 (
9987   p_application_id        IN NUMBER
9988  ,p_event_id              IN NUMBER
9989  ,p_calculate_acctd_flag  IN VARCHAR2
9990  ,p_calculate_g_l_flag    IN VARCHAR2
9991  ,p_actual_flag           IN OUT VARCHAR2
9992  ,p_balance_type_code     OUT VARCHAR2
9993  ,p_gain_or_loss_ref      OUT VARCHAR2
9994  
9995 --Credit Memo Distribution GL Account
9996  , p_source_2            IN NUMBER
9997 --SLA Party Type
9998  , p_source_25            IN VARCHAR2
9999 --Credit Memo Distribution Identifier
10000  , p_source_35            IN NUMBER
10001 --Credit memo distributions type
10002  , p_source_36            IN VARCHAR2
10003 --Credit Memo Currency Code
10004  , p_source_37            IN VARCHAR2
10005 --Credit Memo Exchange Date
10006  , p_source_38            IN DATE
10007 --Credit Memo Exchange Rate
10008  , p_source_39            IN NUMBER
10009 --Credit Memo Exchange Rate Type
10010  , p_source_40            IN VARCHAR2
10011 --Gain Loss Reference
10012  , p_source_41            IN VARCHAR2
10013 --Credit Memo Accounting Amount
10014  , p_source_42            IN NUMBER
10015 --Credit Memo Bill To Customer Account Identifier
10016  , p_source_43            IN NUMBER
10017 --Credit Memo Bill To Customer Site Use Identifier
10018  , p_source_44            IN NUMBER
10019 --Credit Memo Tax Line Identifier
10020  , p_source_45            IN NUMBER
10021 --Credit Memo Distribution Account Class
10022  , p_source_46            IN VARCHAR2
10023 --Credit Memo Distribution Entered Amount
10024  , p_source_47            IN NUMBER
10025 )
10026 IS
10027 
10028 l_component_type              VARCHAR2(80);
10029 l_component_code              VARCHAR2(30);
10030 l_component_type_code         VARCHAR2(1);
10031 l_component_appl_id           INTEGER;
10032 l_amb_context_code            VARCHAR2(30);
10033 l_entity_code                 VARCHAR2(30);
10034 l_event_class_code            VARCHAR2(30);
10035 l_ae_header_id                NUMBER;
10036 l_event_type_code             VARCHAR2(30);
10037 l_line_definition_code        VARCHAR2(30);
10038 l_line_definition_owner_code  VARCHAR2(1);
10039 --
10040 -- adr variables
10041 l_segment                     VARCHAR2(30);
10042 l_ccid                        NUMBER;
10043 l_adr_transaction_coa_id      NUMBER;
10044 l_adr_accounting_coa_id       NUMBER;
10045 l_adr_flexfield_segment_code  VARCHAR2(30);
10046 l_adr_flex_value_set_id       NUMBER;
10047 l_adr_value_type_code         VARCHAR2(30);
10048 l_adr_value_combination_id    NUMBER;
10049 l_adr_value_segment_code      VARCHAR2(30);
10050 
10051 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
10052 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
10053 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
10054 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
10055 
10056 -- 4262811 Variables ------------------------------------------------------------------------------------------
10057 l_entered_amt_idx             NUMBER;
10058 l_accted_amt_idx              NUMBER;
10059 l_acc_rev_flag                VARCHAR2(1);
10060 l_accrual_line_num            NUMBER;
10061 l_tmp_amt                     NUMBER;
10062 l_acc_rev_natural_side_code   VARCHAR2(1);
10063 
10064 l_num_entries                 NUMBER;
10065 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
10066 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
10067 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
10068 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
10069 l_recog_line_1                NUMBER;
10070 l_recog_line_2                NUMBER;
10071 
10072 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
10073 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
10074 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
10075 
10076 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
10077 
10078 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
10079 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
10080 
10081 ---------------------------------------------------------------------------------------------------------------
10082 
10083 
10084 --
10085 -- bulk performance
10086 --
10087 l_balance_type_code           VARCHAR2(1);
10088 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
10089 l_log_module                  VARCHAR2(240);
10090 
10091 --
10092 -- Upgrade strategy
10093 --
10094 l_actual_upg_option           VARCHAR2(1);
10095 l_enc_upg_option           VARCHAR2(1);
10096 
10097 --
10098 BEGIN
10099 --
10100 IF g_log_enabled THEN
10101       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_31';
10102 END IF;
10103 --
10104 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10105 
10106       trace
10107          (p_msg      => 'BEGIN of AcctLineType_31'
10108          ,p_level    => C_LEVEL_PROCEDURE
10109          ,p_module   => l_log_module);
10110 
10111 END IF;
10112 --
10113 l_component_type             := 'AMB_JLT';
10114 l_component_code             := 'CM_ROUND';
10115 l_component_type_code        := 'S';
10116 l_component_appl_id          :=  222;
10117 l_amb_context_code           := 'DEFAULT';
10118 l_entity_code                := 'TRANSACTIONS';
10119 l_event_class_code           := 'CREDIT_MEMO';
10120 l_event_type_code            := 'CREDIT_MEMO_ALL';
10121 l_line_definition_owner_code := 'S';
10122 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
10123 --
10124 l_balance_type_code          := 'A';
10125 l_segment                     := NULL;
10126 l_ccid                        := NULL;
10127 l_adr_transaction_coa_id      := NULL;
10128 l_adr_accounting_coa_id       := NULL;
10129 l_adr_flexfield_segment_code  := NULL;
10130 l_adr_flex_value_set_id       := NULL;
10131 l_adr_value_type_code         := NULL;
10132 l_adr_value_combination_id    := NULL;
10133 l_adr_value_segment_code      := NULL;
10134 
10135 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
10136 l_bflow_class_code           := '';    -- 4219869 Business Flow
10137 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
10138 l_budgetary_control_flag     := 'N';
10139 
10140 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
10141 l_bflow_applied_to_amt       := NULL; -- 5132302
10142 l_entered_amt_idx            := NULL;          -- 4262811
10143 l_accted_amt_idx             := NULL;          -- 4262811
10144 l_acc_rev_flag               := NULL;          -- 4262811
10145 l_accrual_line_num           := NULL;          -- 4262811
10146 l_tmp_amt                    := NULL;          -- 4262811
10147 --
10148  
10149 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
10150     l_balance_type_code <> 'B' THEN
10151 IF NVL(p_source_46,'
10152 ') =  'ROUND'
10153  THEN 
10154 
10155    --
10156    XLA_AE_LINES_PKG.SetNewLine;
10157 
10158    p_balance_type_code          := l_balance_type_code;
10159    -- set the flag so later we will know whether the gain loss line needs to be created
10160    
10161    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
10162      p_actual_flag :='A';
10163    END IF;
10164 
10165    --
10166    -- bulk performance
10167    --
10168    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
10169                                       p_header_num   => 0); -- 4262811
10170    --
10171    -- set accounting line options
10172    --
10173    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
10174            p_natural_side_code          => 'C'
10175          , p_gain_or_loss_flag          => 'N'
10176          , p_gl_transfer_mode_code      => 'S'
10177          , p_acct_entry_type_code       => 'A'
10181    --
10178          , p_switch_side_flag           => 'Y'
10179          , p_merge_duplicate_code       => 'A'
10180          );
10182    l_acc_rev_natural_side_code := 'D';  -- 4262811
10183    -- 
10184    --
10185    -- set accounting line type info
10186    --
10187    xla_ae_lines_pkg.SetAcctLineType
10188       (p_component_type             => l_component_type
10189       ,p_event_type_code            => l_event_type_code
10190       ,p_line_definition_owner_code => l_line_definition_owner_code
10191       ,p_line_definition_code       => l_line_definition_code
10192       ,p_accounting_line_code       => l_component_code
10193       ,p_accounting_line_type_code  => l_component_type_code
10194       ,p_accounting_line_appl_id    => l_component_appl_id
10195       ,p_amb_context_code           => l_amb_context_code
10196       ,p_entity_code                => l_entity_code
10197       ,p_event_class_code           => l_event_class_code);
10198    --
10199    -- set accounting class
10200    --
10201    xla_ae_lines_pkg.SetAcctClass(
10202            p_accounting_class_code  => 'ROUNDING'
10203          , p_ae_header_id           => l_ae_header_id
10204          );
10205 
10206    --
10207    -- set rounding class
10208    --
10209    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
10210                       'RECEIVABLE';
10211 
10212    --
10213    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
10214    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
10215    --
10216    -- bulk performance
10217    --
10218    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
10219 
10220    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
10221       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
10222 
10223    -- 4955764
10224    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
10225       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
10226 
10227    -- 4458381 Public Sector Enh
10228    
10229    --
10230    -- set accounting attributes for the line type
10231    --
10232    l_entered_amt_idx := 3;
10233    l_accted_amt_idx  := 9;
10234    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
10235    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
10236    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_35);
10237    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
10238    l_rec_acct_attrs.array_char_value(2)  := p_source_36;
10239    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
10240    l_rec_acct_attrs.array_num_value(3)  := p_source_47;
10241    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
10242    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
10243    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
10244    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
10245    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
10246    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
10247    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
10248    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
10249    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
10250    l_rec_acct_attrs.array_char_value(8)  := p_source_41;
10251    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
10252    l_rec_acct_attrs.array_num_value(9)  := p_source_42;
10253    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
10254    l_rec_acct_attrs.array_num_value(10)  := p_source_43;
10255    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
10256    l_rec_acct_attrs.array_num_value(11)  := p_source_44;
10257    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
10258    l_rec_acct_attrs.array_char_value(12)  := p_source_25;
10259    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
10260    l_rec_acct_attrs.array_num_value(13)  := p_source_45;
10261 
10262    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
10263    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
10264 
10265    ---------------------------------------------------------------------------------------------------------------
10266    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
10267    ---------------------------------------------------------------------------------------------------------------
10268    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
10269 
10270    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
10271    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
10272 
10273    IF xla_accounting_cache_pkg.GetValueChar
10274          (p_source_code         => 'LEDGER_CATEGORY_CODE'
10275          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
10276    AND l_bflow_method_code = 'PRIOR_ENTRY'
10277 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
10278    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
10279          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
10280        )
10281    THEN
10282          xla_ae_lines_pkg.BflowUpgEntry
10283            (p_business_method_code    => l_bflow_method_code
10284            ,p_business_class_code     => l_bflow_class_code
10285            ,p_balance_type            => l_balance_type_code);
10286    ELSE
10287       NULL;
10288 -- No business flow processing for business flow method of NONE.
10289    END IF;
10290 
10291    --
10292    -- call analytical criteria
10293    --
10294    
10295    --
10296    -- call description
10297    --
10298    -- No description or it is inherited.
10299    --
10300    -- call ADRs
10301    -- Bug 4922099
10302    --
10303    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
10304         (NVL(l_actual_upg_option, 'N') = 'O') OR
10305         (NVL(l_enc_upg_option, 'N') = 'O')
10306       )
10307    THEN
10308    NULL;
10309    --
10310    --
10311    
10312   l_ccid := AcctDerRule_6(
10313            p_application_id           => p_application_id
10314          , p_ae_header_id             => l_ae_header_id 
10315 , p_source_2 => p_source_2
10316          , x_transaction_coa_id       => l_adr_transaction_coa_id
10317          , x_accounting_coa_id        => l_adr_accounting_coa_id
10318          , x_value_type_code          => l_adr_value_type_code
10319          , p_side                     => 'NA'
10320    );
10321 
10322    xla_ae_lines_pkg.set_ccid(
10323     p_code_combination_id          => l_ccid
10324   , p_value_type_code              => l_adr_value_type_code
10325   , p_transaction_coa_id           => l_adr_transaction_coa_id
10326   , p_accounting_coa_id            => l_adr_accounting_coa_id
10327   , p_adr_code                     => 'CM_DIST_CCID'
10328   , p_adr_type_code                => 'S'
10329   , p_component_type               => l_component_type
10330   , p_component_code               => l_component_code
10331   , p_component_type_code          => l_component_type_code
10332   , p_component_appl_id            => l_component_appl_id
10333   , p_amb_context_code             => l_amb_context_code
10334   , p_side                         => 'NA'
10335   );
10336 
10337 
10338    --
10339    --
10340    END IF;
10341    --
10342    -- Bug 4922099
10343    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
10344           (NVL(l_enc_upg_option, 'N') = 'O')
10345         ) AND
10346         (l_bflow_method_code = 'PRIOR_ENTRY')
10347       )
10348    THEN
10349       IF
10350       --
10351       1 = 2
10352       --
10353       THEN
10354       xla_accounting_err_pkg.build_message
10355                                     (p_appli_s_name            => 'XLA'
10356                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
10357                                     ,p_token_1                 => 'LINE_NUMBER'
10358                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
10359                                     ,p_token_2                 => 'LINE_TYPE_NAME'
10360                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
10361                                                                              l_component_type
10362                                                                             ,l_component_code
10363                                                                             ,l_component_type_code
10364                                                                             ,l_component_appl_id
10365                                                                             ,l_amb_context_code
10366                                                                             ,l_entity_code
10367                                                                             ,l_event_class_code
10368                                                                            )
10369                                     ,p_token_3                 => 'OWNER'
10370                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
10371                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
10372                                                                           ,p_lookup_code    => l_component_type_code
10373                                                                          )
10374                                     ,p_token_4                 => 'PRODUCT_NAME'
10375                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
10376                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
10377                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
10378                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
10379                                     ,p_ae_header_id            =>  NULL
10380                                        );
10381 
10382         IF (C_LEVEL_ERROR>= g_log_level) THEN
10383                  trace
10384                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
10385                       ,p_level    => C_LEVEL_ERROR
10386                       ,p_module   => l_log_module);
10387         END IF;
10388       END IF;
10389    END IF;
10390    --
10391    --
10392    ------------------------------------------------------------------------------------------------
10393    -- 4219869 Business Flow
10394    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
10395    -- Prior Entry.  Currently, the following code is always generated.
10396    ------------------------------------------------------------------------------------------------
10397    XLA_AE_LINES_PKG.ValidateCurrentLine;
10398 
10399    ------------------------------------------------------------------------------------
10400    -- 4219869 Business Flow
10401    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
10402    ------------------------------------------------------------------------------------
10403    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
10404 
10405    ----------------------------------------------------------------------------------
10406    -- 4219869 Business Flow
10407    -- Update journal entry status -- Need to generate this within IF <condition>
10408    ----------------------------------------------------------------------------------
10409    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
10410          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
10411          ,p_balance_type_code => l_balance_type_code
10412          );
10413 
10414    -------------------------------------------------------------------------------------------
10415    -- 4262811 - Generate the Accrual Reversal lines
10416    -------------------------------------------------------------------------------------------
10417    BEGIN
10418       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
10419                               (g_array_event(p_event_id).array_value_num('header_index'));
10420       IF l_acc_rev_flag IS NULL THEN
10421          l_acc_rev_flag := 'N';
10422       END IF;
10423    EXCEPTION
10424       WHEN OTHERS THEN
10425          l_acc_rev_flag := 'N';
10426    END;
10427    --
10428    IF (l_acc_rev_flag = 'Y') THEN
10429 
10430        -- 4645092  ------------------------------------------------------------------------------
10431        -- To allow MPA report to determine if it should generate report process
10432        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
10433        ------------------------------------------------------------------------------------------
10434 
10435        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
10436        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
10437    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
10438    -- call ADRs
10439    -- Bug 4922099
10440    --
10441    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
10442         (NVL(l_actual_upg_option, 'N') = 'O') OR
10443         (NVL(l_enc_upg_option, 'N') = 'O')
10444       )
10445    THEN
10446    NULL;
10447    --
10448    --
10449    
10450   l_ccid := AcctDerRule_6(
10451            p_application_id           => p_application_id
10452          , p_ae_header_id             => l_ae_header_id 
10453 , p_source_2 => p_source_2
10454          , x_transaction_coa_id       => l_adr_transaction_coa_id
10455          , x_accounting_coa_id        => l_adr_accounting_coa_id
10456          , x_value_type_code          => l_adr_value_type_code
10457          , p_side                     => 'NA'
10458    );
10459 
10460    xla_ae_lines_pkg.set_ccid(
10461     p_code_combination_id          => l_ccid
10462   , p_value_type_code              => l_adr_value_type_code
10463   , p_transaction_coa_id           => l_adr_transaction_coa_id
10464   , p_accounting_coa_id            => l_adr_accounting_coa_id
10465   , p_adr_code                     => 'CM_DIST_CCID'
10466   , p_adr_type_code                => 'S'
10467   , p_component_type               => l_component_type
10468   , p_component_code               => l_component_code
10469   , p_component_type_code          => l_component_type_code
10470   , p_component_appl_id            => l_component_appl_id
10471   , p_amb_context_code             => l_amb_context_code
10472   , p_side                         => 'NA'
10473   );
10474 
10475 
10476    --
10477    --
10478    END IF;
10479 
10480        --
10481        -- Update the line information that should be overwritten
10482        --
10483        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
10484                                          p_header_num   => 1);
10485        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
10486 
10487        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
10488 
10489        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
10490           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
10491        END IF;
10492 
10493       --
10494       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
10495       --
10496       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
10497           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
10498       ELSE
10499           ---------------------------------------------------------------------------------------------------
10500           -- 4262811a Switch Sign
10501           ---------------------------------------------------------------------------------------------------
10502           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
10503           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
10504                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
10505           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
10506                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
10507           -- 5132302
10508           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
10509                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
10510 
10511       END IF;
10512 
10513       -- 4955764
10514       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
10515       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
10516 
10517 
10518       XLA_AE_LINES_PKG.ValidateCurrentLine;
10519       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
10520 
10521       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
10522                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
10523                ,p_balance_type_code => l_balance_type_code);
10524 
10525    END IF;
10526 
10527    -----------------------------------------------------------------------------------------
10528    -- 4262811 Multiperiod Accounting
10529    -----------------------------------------------------------------------------------------
10530      -- No MPA option is assigned.
10531 
10532 
10533 END IF;
10534 END IF;
10535 --
10536 
10537 --
10538 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10539    trace
10540       (p_msg      => 'END of AcctLineType_31'
10541       ,p_level    => C_LEVEL_PROCEDURE
10542       ,p_module   => l_log_module);
10543 END IF;
10544 --
10545 EXCEPTION
10546   WHEN xla_exceptions_pkg.application_exception THEN
10547       RAISE;
10548   WHEN OTHERS THEN
10549        xla_exceptions_pkg.raise_message
10550            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_31');
10551 END AcctLineType_31;
10552 --
10553 
10554 ---------------------------------------
10555 --
10556 -- PRIVATE FUNCTION
10557 --         AcctLineType_32
10558 --
10559 ---------------------------------------
10560 PROCEDURE AcctLineType_32 (
10561   p_application_id        IN NUMBER
10562  ,p_event_id              IN NUMBER
10563  ,p_calculate_acctd_flag  IN VARCHAR2
10564  ,p_calculate_g_l_flag    IN VARCHAR2
10565  ,p_actual_flag           IN OUT VARCHAR2
10566  ,p_balance_type_code     OUT VARCHAR2
10567  ,p_gain_or_loss_ref      OUT VARCHAR2
10568  
10569 --Credit Memo Distribution GL Account
10570  , p_source_2            IN NUMBER
10571 --SLA Party Type
10572  , p_source_25            IN VARCHAR2
10573 --Credit Memo Distribution Identifier
10574  , p_source_35            IN NUMBER
10575 --Credit memo distributions type
10576  , p_source_36            IN VARCHAR2
10577 --Credit Memo Currency Code
10578  , p_source_37            IN VARCHAR2
10579 --Credit Memo Exchange Date
10580  , p_source_38            IN DATE
10581 --Credit Memo Exchange Rate
10582  , p_source_39            IN NUMBER
10583 --Credit Memo Exchange Rate Type
10584  , p_source_40            IN VARCHAR2
10585 --Gain Loss Reference
10586  , p_source_41            IN VARCHAR2
10587 --Credit Memo Accounting Amount
10588  , p_source_42            IN NUMBER
10589 --Credit Memo Bill To Customer Account Identifier
10590  , p_source_43            IN NUMBER
10591 --Credit Memo Bill To Customer Site Use Identifier
10592  , p_source_44            IN NUMBER
10593 --Credit Memo Tax Line Identifier
10594  , p_source_45            IN NUMBER
10595 --Credit Memo Distribution Account Class
10596  , p_source_46            IN VARCHAR2
10597 --Credit Memo Distribution Entered Amount
10598  , p_source_47            IN NUMBER
10599 )
10600 IS
10601 
10602 l_component_type              VARCHAR2(80);
10603 l_component_code              VARCHAR2(30);
10604 l_component_type_code         VARCHAR2(1);
10605 l_component_appl_id           INTEGER;
10606 l_amb_context_code            VARCHAR2(30);
10607 l_entity_code                 VARCHAR2(30);
10608 l_event_class_code            VARCHAR2(30);
10609 l_ae_header_id                NUMBER;
10610 l_event_type_code             VARCHAR2(30);
10611 l_line_definition_code        VARCHAR2(30);
10612 l_line_definition_owner_code  VARCHAR2(1);
10613 --
10614 -- adr variables
10615 l_segment                     VARCHAR2(30);
10616 l_ccid                        NUMBER;
10617 l_adr_transaction_coa_id      NUMBER;
10618 l_adr_accounting_coa_id       NUMBER;
10619 l_adr_flexfield_segment_code  VARCHAR2(30);
10620 l_adr_flex_value_set_id       NUMBER;
10621 l_adr_value_type_code         VARCHAR2(30);
10622 l_adr_value_combination_id    NUMBER;
10623 l_adr_value_segment_code      VARCHAR2(30);
10624 
10625 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
10626 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
10627 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
10628 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
10629 
10630 -- 4262811 Variables ------------------------------------------------------------------------------------------
10631 l_entered_amt_idx             NUMBER;
10632 l_accted_amt_idx              NUMBER;
10633 l_acc_rev_flag                VARCHAR2(1);
10634 l_accrual_line_num            NUMBER;
10635 l_tmp_amt                     NUMBER;
10636 l_acc_rev_natural_side_code   VARCHAR2(1);
10637 
10638 l_num_entries                 NUMBER;
10639 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
10640 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
10641 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
10642 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
10643 l_recog_line_1                NUMBER;
10644 l_recog_line_2                NUMBER;
10645 
10646 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
10647 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
10648 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
10649 
10650 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
10651 
10652 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
10653 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
10654 
10655 ---------------------------------------------------------------------------------------------------------------
10656 
10657 
10658 --
10659 -- bulk performance
10660 --
10661 l_balance_type_code           VARCHAR2(1);
10662 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
10663 l_log_module                  VARCHAR2(240);
10664 
10665 --
10666 -- Upgrade strategy
10667 --
10668 l_actual_upg_option           VARCHAR2(1);
10669 l_enc_upg_option           VARCHAR2(1);
10670 
10671 --
10672 BEGIN
10673 --
10674 IF g_log_enabled THEN
10675       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_32';
10676 END IF;
10677 --
10678 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10679 
10680       trace
10681          (p_msg      => 'BEGIN of AcctLineType_32'
10682          ,p_level    => C_LEVEL_PROCEDURE
10683          ,p_module   => l_log_module);
10684 
10685 END IF;
10686 --
10687 l_component_type             := 'AMB_JLT';
10688 l_component_code             := 'CM_UNBILL';
10689 l_component_type_code        := 'S';
10690 l_component_appl_id          :=  222;
10691 l_amb_context_code           := 'DEFAULT';
10692 l_entity_code                := 'TRANSACTIONS';
10693 l_event_class_code           := 'CREDIT_MEMO';
10694 l_event_type_code            := 'CREDIT_MEMO_ALL';
10695 l_line_definition_owner_code := 'S';
10696 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
10697 --
10698 l_balance_type_code          := 'A';
10699 l_segment                     := NULL;
10700 l_ccid                        := NULL;
10701 l_adr_transaction_coa_id      := NULL;
10702 l_adr_accounting_coa_id       := NULL;
10703 l_adr_flexfield_segment_code  := NULL;
10704 l_adr_flex_value_set_id       := NULL;
10705 l_adr_value_type_code         := NULL;
10706 l_adr_value_combination_id    := NULL;
10707 l_adr_value_segment_code      := NULL;
10708 
10709 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
10710 l_bflow_class_code           := '';    -- 4219869 Business Flow
10711 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
10712 l_budgetary_control_flag     := 'N';
10713 
10714 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
10715 l_bflow_applied_to_amt       := NULL; -- 5132302
10716 l_entered_amt_idx            := NULL;          -- 4262811
10720 l_tmp_amt                    := NULL;          -- 4262811
10717 l_accted_amt_idx             := NULL;          -- 4262811
10718 l_acc_rev_flag               := NULL;          -- 4262811
10719 l_accrual_line_num           := NULL;          -- 4262811
10721 --
10722  
10723 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
10724     l_balance_type_code <> 'B' THEN
10725 IF NVL(p_source_46,'
10726 ') =  'UNBILL'
10727  THEN 
10728 
10729    --
10730    XLA_AE_LINES_PKG.SetNewLine;
10731 
10732    p_balance_type_code          := l_balance_type_code;
10733    -- set the flag so later we will know whether the gain loss line needs to be created
10734    
10735    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
10736      p_actual_flag :='A';
10737    END IF;
10738 
10739    --
10740    -- bulk performance
10741    --
10742    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
10743                                       p_header_num   => 0); -- 4262811
10744    --
10745    -- set accounting line options
10746    --
10747    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
10748            p_natural_side_code          => 'C'
10749          , p_gain_or_loss_flag          => 'N'
10750          , p_gl_transfer_mode_code      => 'S'
10751          , p_acct_entry_type_code       => 'A'
10752          , p_switch_side_flag           => 'Y'
10753          , p_merge_duplicate_code       => 'A'
10754          );
10755    --
10756    l_acc_rev_natural_side_code := 'D';  -- 4262811
10757    -- 
10758    --
10759    -- set accounting line type info
10760    --
10761    xla_ae_lines_pkg.SetAcctLineType
10762       (p_component_type             => l_component_type
10763       ,p_event_type_code            => l_event_type_code
10764       ,p_line_definition_owner_code => l_line_definition_owner_code
10765       ,p_line_definition_code       => l_line_definition_code
10766       ,p_accounting_line_code       => l_component_code
10767       ,p_accounting_line_type_code  => l_component_type_code
10768       ,p_accounting_line_appl_id    => l_component_appl_id
10769       ,p_amb_context_code           => l_amb_context_code
10770       ,p_entity_code                => l_entity_code
10771       ,p_event_class_code           => l_event_class_code);
10772    --
10773    -- set accounting class
10774    --
10775    xla_ae_lines_pkg.SetAcctClass(
10776            p_accounting_class_code  => 'UNBILL'
10777          , p_ae_header_id           => l_ae_header_id
10778          );
10779 
10780    --
10781    -- set rounding class
10782    --
10783    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
10784                       'RECEIVABLE';
10785 
10786    --
10787    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
10788    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
10789    --
10790    -- bulk performance
10791    --
10792    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
10793 
10794    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
10795       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
10796 
10797    -- 4955764
10798    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
10799       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
10800 
10801    -- 4458381 Public Sector Enh
10802    
10803    --
10804    -- set accounting attributes for the line type
10805    --
10806    l_entered_amt_idx := 3;
10807    l_accted_amt_idx  := 9;
10808    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
10809    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
10810    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_35);
10811    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
10812    l_rec_acct_attrs.array_char_value(2)  := p_source_36;
10813    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
10814    l_rec_acct_attrs.array_num_value(3)  := p_source_47;
10815    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
10816    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
10817    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
10818    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
10819    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
10820    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
10821    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
10822    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
10823    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
10824    l_rec_acct_attrs.array_char_value(8)  := p_source_41;
10825    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
10826    l_rec_acct_attrs.array_num_value(9)  := p_source_42;
10827    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
10828    l_rec_acct_attrs.array_num_value(10)  := p_source_43;
10829    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
10830    l_rec_acct_attrs.array_num_value(11)  := p_source_44;
10831    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
10832    l_rec_acct_attrs.array_char_value(12)  := p_source_25;
10833    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
10834    l_rec_acct_attrs.array_num_value(13)  := p_source_45;
10835 
10836    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
10837    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
10838 
10839    ---------------------------------------------------------------------------------------------------------------
10840    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
10841    ---------------------------------------------------------------------------------------------------------------
10842    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
10843 
10844    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
10845    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
10846 
10847    IF xla_accounting_cache_pkg.GetValueChar
10848          (p_source_code         => 'LEDGER_CATEGORY_CODE'
10849          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
10850    AND l_bflow_method_code = 'PRIOR_ENTRY'
10851 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
10852    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
10853          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
10854        )
10855    THEN
10856          xla_ae_lines_pkg.BflowUpgEntry
10857            (p_business_method_code    => l_bflow_method_code
10858            ,p_business_class_code     => l_bflow_class_code
10859            ,p_balance_type            => l_balance_type_code);
10860    ELSE
10861       NULL;
10862 -- No business flow processing for business flow method of NONE.
10863    END IF;
10864 
10865    --
10866    -- call analytical criteria
10867    --
10868    
10869    --
10870    -- call description
10871    --
10872    -- No description or it is inherited.
10873    --
10874    -- call ADRs
10875    -- Bug 4922099
10876    --
10877    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
10878         (NVL(l_actual_upg_option, 'N') = 'O') OR
10879         (NVL(l_enc_upg_option, 'N') = 'O')
10880       )
10881    THEN
10882    NULL;
10883    --
10884    --
10885    
10886   l_ccid := AcctDerRule_6(
10887            p_application_id           => p_application_id
10888          , p_ae_header_id             => l_ae_header_id 
10889 , p_source_2 => p_source_2
10890          , x_transaction_coa_id       => l_adr_transaction_coa_id
10891          , x_accounting_coa_id        => l_adr_accounting_coa_id
10892          , x_value_type_code          => l_adr_value_type_code
10893          , p_side                     => 'NA'
10894    );
10895 
10896    xla_ae_lines_pkg.set_ccid(
10897     p_code_combination_id          => l_ccid
10898   , p_value_type_code              => l_adr_value_type_code
10899   , p_transaction_coa_id           => l_adr_transaction_coa_id
10900   , p_accounting_coa_id            => l_adr_accounting_coa_id
10901   , p_adr_code                     => 'CM_DIST_CCID'
10902   , p_adr_type_code                => 'S'
10903   , p_component_type               => l_component_type
10904   , p_component_code               => l_component_code
10905   , p_component_type_code          => l_component_type_code
10906   , p_component_appl_id            => l_component_appl_id
10907   , p_amb_context_code             => l_amb_context_code
10908   , p_side                         => 'NA'
10909   );
10910 
10911 
10912    --
10913    --
10914    END IF;
10915    --
10916    -- Bug 4922099
10917    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
10918           (NVL(l_enc_upg_option, 'N') = 'O')
10919         ) AND
10920         (l_bflow_method_code = 'PRIOR_ENTRY')
10921       )
10922    THEN
10923       IF
10924       --
10925       1 = 2
10926       --
10927       THEN
10928       xla_accounting_err_pkg.build_message
10929                                     (p_appli_s_name            => 'XLA'
10930                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
10931                                     ,p_token_1                 => 'LINE_NUMBER'
10932                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
10933                                     ,p_token_2                 => 'LINE_TYPE_NAME'
10934                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
10935                                                                              l_component_type
10936                                                                             ,l_component_code
10937                                                                             ,l_component_type_code
10938                                                                             ,l_component_appl_id
10939                                                                             ,l_amb_context_code
10940                                                                             ,l_entity_code
10941                                                                             ,l_event_class_code
10942                                                                            )
10943                                     ,p_token_3                 => 'OWNER'
10944                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
10945                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
10946                                                                           ,p_lookup_code    => l_component_type_code
10947                                                                          )
10948                                     ,p_token_4                 => 'PRODUCT_NAME'
10949                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
10950                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
10951                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
10952                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
10953                                     ,p_ae_header_id            =>  NULL
10954                                        );
10955 
10956         IF (C_LEVEL_ERROR>= g_log_level) THEN
10957                  trace
10958                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
10959                       ,p_level    => C_LEVEL_ERROR
10960                       ,p_module   => l_log_module);
10961         END IF;
10962       END IF;
10963    END IF;
10964    --
10965    --
10966    ------------------------------------------------------------------------------------------------
10967    -- 4219869 Business Flow
10968    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
10969    -- Prior Entry.  Currently, the following code is always generated.
10970    ------------------------------------------------------------------------------------------------
10971    XLA_AE_LINES_PKG.ValidateCurrentLine;
10972 
10973    ------------------------------------------------------------------------------------
10974    -- 4219869 Business Flow
10975    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
10976    ------------------------------------------------------------------------------------
10977    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
10978 
10979    ----------------------------------------------------------------------------------
10980    -- 4219869 Business Flow
10981    -- Update journal entry status -- Need to generate this within IF <condition>
10982    ----------------------------------------------------------------------------------
10983    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
10984          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
10985          ,p_balance_type_code => l_balance_type_code
10986          );
10987 
10988    -------------------------------------------------------------------------------------------
10989    -- 4262811 - Generate the Accrual Reversal lines
10990    -------------------------------------------------------------------------------------------
10991    BEGIN
10992       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
10993                               (g_array_event(p_event_id).array_value_num('header_index'));
10994       IF l_acc_rev_flag IS NULL THEN
10995          l_acc_rev_flag := 'N';
10996       END IF;
10997    EXCEPTION
10998       WHEN OTHERS THEN
10999          l_acc_rev_flag := 'N';
11000    END;
11001    --
11002    IF (l_acc_rev_flag = 'Y') THEN
11003 
11004        -- 4645092  ------------------------------------------------------------------------------
11005        -- To allow MPA report to determine if it should generate report process
11006        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
11007        ------------------------------------------------------------------------------------------
11008 
11009        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
11010        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
11011    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
11012    -- call ADRs
11013    -- Bug 4922099
11014    --
11015    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
11016         (NVL(l_actual_upg_option, 'N') = 'O') OR
11017         (NVL(l_enc_upg_option, 'N') = 'O')
11018       )
11019    THEN
11020    NULL;
11021    --
11022    --
11023    
11024   l_ccid := AcctDerRule_6(
11025            p_application_id           => p_application_id
11026          , p_ae_header_id             => l_ae_header_id 
11027 , p_source_2 => p_source_2
11028          , x_transaction_coa_id       => l_adr_transaction_coa_id
11029          , x_accounting_coa_id        => l_adr_accounting_coa_id
11030          , x_value_type_code          => l_adr_value_type_code
11031          , p_side                     => 'NA'
11032    );
11033 
11034    xla_ae_lines_pkg.set_ccid(
11035     p_code_combination_id          => l_ccid
11036   , p_value_type_code              => l_adr_value_type_code
11037   , p_transaction_coa_id           => l_adr_transaction_coa_id
11038   , p_accounting_coa_id            => l_adr_accounting_coa_id
11039   , p_adr_code                     => 'CM_DIST_CCID'
11040   , p_adr_type_code                => 'S'
11041   , p_component_type               => l_component_type
11042   , p_component_code               => l_component_code
11043   , p_component_type_code          => l_component_type_code
11047   );
11044   , p_component_appl_id            => l_component_appl_id
11045   , p_amb_context_code             => l_amb_context_code
11046   , p_side                         => 'NA'
11048 
11049 
11050    --
11051    --
11052    END IF;
11053 
11054        --
11055        -- Update the line information that should be overwritten
11056        --
11057        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
11058                                          p_header_num   => 1);
11059        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
11060 
11061        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
11062 
11063        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
11064           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
11065        END IF;
11066 
11067       --
11068       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
11069       --
11070       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
11071           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
11072       ELSE
11073           ---------------------------------------------------------------------------------------------------
11074           -- 4262811a Switch Sign
11075           ---------------------------------------------------------------------------------------------------
11076           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
11077           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
11078                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11079           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
11080                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11081           -- 5132302
11082           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
11083                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11084 
11085       END IF;
11086 
11087       -- 4955764
11088       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
11089       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
11090 
11091 
11092       XLA_AE_LINES_PKG.ValidateCurrentLine;
11093       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
11094 
11095       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
11096                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
11097                ,p_balance_type_code => l_balance_type_code);
11098 
11099    END IF;
11100 
11101    -----------------------------------------------------------------------------------------
11102    -- 4262811 Multiperiod Accounting
11103    -----------------------------------------------------------------------------------------
11104      -- No MPA option is assigned.
11105 
11106 
11107 END IF;
11108 END IF;
11109 --
11110 
11111 --
11112 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11113    trace
11114       (p_msg      => 'END of AcctLineType_32'
11115       ,p_level    => C_LEVEL_PROCEDURE
11116       ,p_module   => l_log_module);
11117 END IF;
11118 --
11119 EXCEPTION
11120   WHEN xla_exceptions_pkg.application_exception THEN
11121       RAISE;
11122   WHEN OTHERS THEN
11123        xla_exceptions_pkg.raise_message
11124            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_32');
11125 END AcctLineType_32;
11126 --
11127 
11128 ---------------------------------------
11129 --
11130 -- PRIVATE FUNCTION
11131 --         AcctLineType_33
11132 --
11133 ---------------------------------------
11134 PROCEDURE AcctLineType_33 (
11135   p_application_id        IN NUMBER
11136  ,p_event_id              IN NUMBER
11137  ,p_calculate_acctd_flag  IN VARCHAR2
11138  ,p_calculate_g_l_flag    IN VARCHAR2
11139  ,p_actual_flag           IN OUT VARCHAR2
11140  ,p_balance_type_code     OUT VARCHAR2
11141  ,p_gain_or_loss_ref      OUT VARCHAR2
11142  
11143 --Credit Memo Distribution GL Account
11144  , p_source_2            IN NUMBER
11145 --SLA Party Type
11146  , p_source_25            IN VARCHAR2
11147 --Credit Memo Distribution Identifier
11148  , p_source_35            IN NUMBER
11149 --Credit memo distributions type
11150  , p_source_36            IN VARCHAR2
11151 --Credit Memo Currency Code
11152  , p_source_37            IN VARCHAR2
11153 --Credit Memo Exchange Date
11154  , p_source_38            IN DATE
11155 --Credit Memo Exchange Rate
11156  , p_source_39            IN NUMBER
11157 --Credit Memo Exchange Rate Type
11158  , p_source_40            IN VARCHAR2
11159 --Gain Loss Reference
11160  , p_source_41            IN VARCHAR2
11161 --Credit Memo Accounting Amount
11162  , p_source_42            IN NUMBER
11163 --Credit Memo Bill To Customer Account Identifier
11164  , p_source_43            IN NUMBER
11165 --Credit Memo Bill To Customer Site Use Identifier
11166  , p_source_44            IN NUMBER
11167 --Credit Memo Tax Line Identifier
11168  , p_source_45            IN NUMBER
11169 --Credit Memo Distribution Account Class
11170  , p_source_46            IN VARCHAR2
11174 IS
11171 --Credit Memo Distribution Entered Amount
11172  , p_source_47            IN NUMBER
11173 )
11175 
11176 l_component_type              VARCHAR2(80);
11177 l_component_code              VARCHAR2(30);
11178 l_component_type_code         VARCHAR2(1);
11179 l_component_appl_id           INTEGER;
11180 l_amb_context_code            VARCHAR2(30);
11181 l_entity_code                 VARCHAR2(30);
11182 l_event_class_code            VARCHAR2(30);
11183 l_ae_header_id                NUMBER;
11184 l_event_type_code             VARCHAR2(30);
11185 l_line_definition_code        VARCHAR2(30);
11186 l_line_definition_owner_code  VARCHAR2(1);
11187 --
11188 -- adr variables
11189 l_segment                     VARCHAR2(30);
11190 l_ccid                        NUMBER;
11191 l_adr_transaction_coa_id      NUMBER;
11192 l_adr_accounting_coa_id       NUMBER;
11193 l_adr_flexfield_segment_code  VARCHAR2(30);
11194 l_adr_flex_value_set_id       NUMBER;
11195 l_adr_value_type_code         VARCHAR2(30);
11196 l_adr_value_combination_id    NUMBER;
11197 l_adr_value_segment_code      VARCHAR2(30);
11198 
11199 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
11200 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
11201 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
11202 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
11203 
11204 -- 4262811 Variables ------------------------------------------------------------------------------------------
11205 l_entered_amt_idx             NUMBER;
11206 l_accted_amt_idx              NUMBER;
11207 l_acc_rev_flag                VARCHAR2(1);
11208 l_accrual_line_num            NUMBER;
11209 l_tmp_amt                     NUMBER;
11210 l_acc_rev_natural_side_code   VARCHAR2(1);
11211 
11212 l_num_entries                 NUMBER;
11213 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
11214 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
11215 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
11216 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
11217 l_recog_line_1                NUMBER;
11218 l_recog_line_2                NUMBER;
11219 
11220 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
11221 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
11222 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
11223 
11224 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
11225 
11226 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
11227 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
11228 
11229 ---------------------------------------------------------------------------------------------------------------
11230 
11231 
11232 --
11233 -- bulk performance
11234 --
11235 l_balance_type_code           VARCHAR2(1);
11236 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
11237 l_log_module                  VARCHAR2(240);
11238 
11239 --
11240 -- Upgrade strategy
11241 --
11242 l_actual_upg_option           VARCHAR2(1);
11243 l_enc_upg_option           VARCHAR2(1);
11244 
11245 --
11246 BEGIN
11247 --
11248 IF g_log_enabled THEN
11249       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_33';
11250 END IF;
11251 --
11252 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11253 
11254       trace
11255          (p_msg      => 'BEGIN of AcctLineType_33'
11256          ,p_level    => C_LEVEL_PROCEDURE
11257          ,p_module   => l_log_module);
11258 
11259 END IF;
11260 --
11261 l_component_type             := 'AMB_JLT';
11262 l_component_code             := 'CM_UNEARN';
11263 l_component_type_code        := 'S';
11264 l_component_appl_id          :=  222;
11265 l_amb_context_code           := 'DEFAULT';
11266 l_entity_code                := 'TRANSACTIONS';
11267 l_event_class_code           := 'CREDIT_MEMO';
11268 l_event_type_code            := 'CREDIT_MEMO_ALL';
11269 l_line_definition_owner_code := 'S';
11270 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
11271 --
11272 l_balance_type_code          := 'A';
11273 l_segment                     := NULL;
11274 l_ccid                        := NULL;
11275 l_adr_transaction_coa_id      := NULL;
11276 l_adr_accounting_coa_id       := NULL;
11277 l_adr_flexfield_segment_code  := NULL;
11278 l_adr_flex_value_set_id       := NULL;
11279 l_adr_value_type_code         := NULL;
11280 l_adr_value_combination_id    := NULL;
11281 l_adr_value_segment_code      := NULL;
11282 
11283 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
11284 l_bflow_class_code           := '';    -- 4219869 Business Flow
11285 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
11286 l_budgetary_control_flag     := 'N';
11287 
11288 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
11289 l_bflow_applied_to_amt       := NULL; -- 5132302
11290 l_entered_amt_idx            := NULL;          -- 4262811
11291 l_accted_amt_idx             := NULL;          -- 4262811
11292 l_acc_rev_flag               := NULL;          -- 4262811
11293 l_accrual_line_num           := NULL;          -- 4262811
11294 l_tmp_amt                    := NULL;          -- 4262811
11295 --
11296  
11297 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
11298     l_balance_type_code <> 'B' THEN
11299 IF NVL(p_source_46,'
11303    --
11300 ') =  'UNEARN'
11301  THEN 
11302 
11304    XLA_AE_LINES_PKG.SetNewLine;
11305 
11306    p_balance_type_code          := l_balance_type_code;
11307    -- set the flag so later we will know whether the gain loss line needs to be created
11308    
11309    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
11310      p_actual_flag :='A';
11311    END IF;
11312 
11313    --
11314    -- bulk performance
11315    --
11316    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
11317                                       p_header_num   => 0); -- 4262811
11318    --
11319    -- set accounting line options
11320    --
11321    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
11322            p_natural_side_code          => 'C'
11323          , p_gain_or_loss_flag          => 'N'
11324          , p_gl_transfer_mode_code      => 'S'
11325          , p_acct_entry_type_code       => 'A'
11326          , p_switch_side_flag           => 'Y'
11327          , p_merge_duplicate_code       => 'A'
11328          );
11329    --
11330    l_acc_rev_natural_side_code := 'D';  -- 4262811
11331    -- 
11332    --
11333    -- set accounting line type info
11334    --
11335    xla_ae_lines_pkg.SetAcctLineType
11336       (p_component_type             => l_component_type
11337       ,p_event_type_code            => l_event_type_code
11338       ,p_line_definition_owner_code => l_line_definition_owner_code
11339       ,p_line_definition_code       => l_line_definition_code
11340       ,p_accounting_line_code       => l_component_code
11341       ,p_accounting_line_type_code  => l_component_type_code
11342       ,p_accounting_line_appl_id    => l_component_appl_id
11343       ,p_amb_context_code           => l_amb_context_code
11344       ,p_entity_code                => l_entity_code
11345       ,p_event_class_code           => l_event_class_code);
11346    --
11347    -- set accounting class
11348    --
11349    xla_ae_lines_pkg.SetAcctClass(
11350            p_accounting_class_code  => 'UNEARNED_REVENUE'
11351          , p_ae_header_id           => l_ae_header_id
11352          );
11353 
11354    --
11355    -- set rounding class
11356    --
11357    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
11358                       'RECEIVABLE';
11359 
11360    --
11361    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
11362    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
11363    --
11364    -- bulk performance
11365    --
11366    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
11367 
11368    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
11369       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
11370 
11371    -- 4955764
11372    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
11373       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
11374 
11375    -- 4458381 Public Sector Enh
11376    
11377    --
11378    -- set accounting attributes for the line type
11379    --
11380    l_entered_amt_idx := 3;
11381    l_accted_amt_idx  := 9;
11382    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
11383    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
11384    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_35);
11385    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
11386    l_rec_acct_attrs.array_char_value(2)  := p_source_36;
11387    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
11388    l_rec_acct_attrs.array_num_value(3)  := p_source_47;
11389    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
11390    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
11391    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
11392    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
11393    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
11394    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
11395    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
11396    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
11397    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
11398    l_rec_acct_attrs.array_char_value(8)  := p_source_41;
11399    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
11400    l_rec_acct_attrs.array_num_value(9)  := p_source_42;
11401    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
11402    l_rec_acct_attrs.array_num_value(10)  := p_source_43;
11403    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
11404    l_rec_acct_attrs.array_num_value(11)  := p_source_44;
11405    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
11406    l_rec_acct_attrs.array_char_value(12)  := p_source_25;
11407    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
11408    l_rec_acct_attrs.array_num_value(13)  := p_source_45;
11409 
11410    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
11411    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
11412 
11413    ---------------------------------------------------------------------------------------------------------------
11414    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
11415    ---------------------------------------------------------------------------------------------------------------
11416    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
11417 
11421    IF xla_accounting_cache_pkg.GetValueChar
11418    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
11419    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
11420 
11422          (p_source_code         => 'LEDGER_CATEGORY_CODE'
11423          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
11424    AND l_bflow_method_code = 'PRIOR_ENTRY'
11425 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
11426    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
11427          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
11428        )
11429    THEN
11430          xla_ae_lines_pkg.BflowUpgEntry
11431            (p_business_method_code    => l_bflow_method_code
11432            ,p_business_class_code     => l_bflow_class_code
11433            ,p_balance_type            => l_balance_type_code);
11434    ELSE
11435       NULL;
11436 -- No business flow processing for business flow method of NONE.
11437    END IF;
11438 
11439    --
11440    -- call analytical criteria
11441    --
11442    
11443    --
11444    -- call description
11445    --
11446    -- No description or it is inherited.
11447    --
11448    -- call ADRs
11449    -- Bug 4922099
11450    --
11451    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
11452         (NVL(l_actual_upg_option, 'N') = 'O') OR
11453         (NVL(l_enc_upg_option, 'N') = 'O')
11454       )
11455    THEN
11456    NULL;
11457    --
11458    --
11459    
11460   l_ccid := AcctDerRule_6(
11461            p_application_id           => p_application_id
11462          , p_ae_header_id             => l_ae_header_id 
11463 , p_source_2 => p_source_2
11464          , x_transaction_coa_id       => l_adr_transaction_coa_id
11465          , x_accounting_coa_id        => l_adr_accounting_coa_id
11466          , x_value_type_code          => l_adr_value_type_code
11467          , p_side                     => 'NA'
11468    );
11469 
11470    xla_ae_lines_pkg.set_ccid(
11471     p_code_combination_id          => l_ccid
11472   , p_value_type_code              => l_adr_value_type_code
11473   , p_transaction_coa_id           => l_adr_transaction_coa_id
11474   , p_accounting_coa_id            => l_adr_accounting_coa_id
11475   , p_adr_code                     => 'CM_DIST_CCID'
11476   , p_adr_type_code                => 'S'
11477   , p_component_type               => l_component_type
11478   , p_component_code               => l_component_code
11479   , p_component_type_code          => l_component_type_code
11480   , p_component_appl_id            => l_component_appl_id
11481   , p_amb_context_code             => l_amb_context_code
11482   , p_side                         => 'NA'
11483   );
11484 
11485 
11486    --
11487    --
11488    END IF;
11489    --
11490    -- Bug 4922099
11491    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
11492           (NVL(l_enc_upg_option, 'N') = 'O')
11493         ) AND
11494         (l_bflow_method_code = 'PRIOR_ENTRY')
11495       )
11496    THEN
11497       IF
11498       --
11499       1 = 2
11500       --
11501       THEN
11502       xla_accounting_err_pkg.build_message
11503                                     (p_appli_s_name            => 'XLA'
11504                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
11505                                     ,p_token_1                 => 'LINE_NUMBER'
11506                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
11507                                     ,p_token_2                 => 'LINE_TYPE_NAME'
11508                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
11509                                                                              l_component_type
11510                                                                             ,l_component_code
11511                                                                             ,l_component_type_code
11512                                                                             ,l_component_appl_id
11513                                                                             ,l_amb_context_code
11514                                                                             ,l_entity_code
11515                                                                             ,l_event_class_code
11516                                                                            )
11517                                     ,p_token_3                 => 'OWNER'
11518                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
11519                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
11520                                                                           ,p_lookup_code    => l_component_type_code
11521                                                                          )
11522                                     ,p_token_4                 => 'PRODUCT_NAME'
11523                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
11524                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
11525                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
11526                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
11527                                     ,p_ae_header_id            =>  NULL
11528                                        );
11529 
11530         IF (C_LEVEL_ERROR>= g_log_level) THEN
11531                  trace
11532                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
11533                       ,p_level    => C_LEVEL_ERROR
11534                       ,p_module   => l_log_module);
11535         END IF;
11536       END IF;
11537    END IF;
11538    --
11539    --
11540    ------------------------------------------------------------------------------------------------
11541    -- 4219869 Business Flow
11542    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
11543    -- Prior Entry.  Currently, the following code is always generated.
11544    ------------------------------------------------------------------------------------------------
11545    XLA_AE_LINES_PKG.ValidateCurrentLine;
11546 
11547    ------------------------------------------------------------------------------------
11548    -- 4219869 Business Flow
11549    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
11550    ------------------------------------------------------------------------------------
11551    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
11552 
11553    ----------------------------------------------------------------------------------
11554    -- 4219869 Business Flow
11555    -- Update journal entry status -- Need to generate this within IF <condition>
11556    ----------------------------------------------------------------------------------
11557    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
11558          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
11559          ,p_balance_type_code => l_balance_type_code
11560          );
11561 
11562    -------------------------------------------------------------------------------------------
11563    -- 4262811 - Generate the Accrual Reversal lines
11564    -------------------------------------------------------------------------------------------
11565    BEGIN
11566       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
11567                               (g_array_event(p_event_id).array_value_num('header_index'));
11568       IF l_acc_rev_flag IS NULL THEN
11569          l_acc_rev_flag := 'N';
11570       END IF;
11571    EXCEPTION
11572       WHEN OTHERS THEN
11573          l_acc_rev_flag := 'N';
11574    END;
11575    --
11576    IF (l_acc_rev_flag = 'Y') THEN
11577 
11578        -- 4645092  ------------------------------------------------------------------------------
11579        -- To allow MPA report to determine if it should generate report process
11580        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
11581        ------------------------------------------------------------------------------------------
11582 
11583        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
11584        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
11585    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
11586    -- call ADRs
11587    -- Bug 4922099
11588    --
11592       )
11589    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
11590         (NVL(l_actual_upg_option, 'N') = 'O') OR
11591         (NVL(l_enc_upg_option, 'N') = 'O')
11593    THEN
11594    NULL;
11595    --
11596    --
11597    
11598   l_ccid := AcctDerRule_6(
11599            p_application_id           => p_application_id
11600          , p_ae_header_id             => l_ae_header_id 
11601 , p_source_2 => p_source_2
11602          , x_transaction_coa_id       => l_adr_transaction_coa_id
11603          , x_accounting_coa_id        => l_adr_accounting_coa_id
11604          , x_value_type_code          => l_adr_value_type_code
11605          , p_side                     => 'NA'
11606    );
11607 
11608    xla_ae_lines_pkg.set_ccid(
11609     p_code_combination_id          => l_ccid
11610   , p_value_type_code              => l_adr_value_type_code
11611   , p_transaction_coa_id           => l_adr_transaction_coa_id
11612   , p_accounting_coa_id            => l_adr_accounting_coa_id
11613   , p_adr_code                     => 'CM_DIST_CCID'
11614   , p_adr_type_code                => 'S'
11615   , p_component_type               => l_component_type
11616   , p_component_code               => l_component_code
11617   , p_component_type_code          => l_component_type_code
11618   , p_component_appl_id            => l_component_appl_id
11619   , p_amb_context_code             => l_amb_context_code
11620   , p_side                         => 'NA'
11621   );
11622 
11623 
11624    --
11625    --
11626    END IF;
11627 
11628        --
11629        -- Update the line information that should be overwritten
11630        --
11631        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
11632                                          p_header_num   => 1);
11633        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
11634 
11635        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
11636 
11637        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
11638           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
11639        END IF;
11640 
11641       --
11642       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
11643       --
11644       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
11645           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
11646       ELSE
11647           ---------------------------------------------------------------------------------------------------
11648           -- 4262811a Switch Sign
11649           ---------------------------------------------------------------------------------------------------
11650           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
11651           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
11652                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11653           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
11654                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11655           -- 5132302
11656           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
11657                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11658 
11659       END IF;
11660 
11661       -- 4955764
11662       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
11663       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
11664 
11665 
11666       XLA_AE_LINES_PKG.ValidateCurrentLine;
11667       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
11668 
11669       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
11670                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
11671                ,p_balance_type_code => l_balance_type_code);
11672 
11673    END IF;
11674 
11675    -----------------------------------------------------------------------------------------
11676    -- 4262811 Multiperiod Accounting
11677    -----------------------------------------------------------------------------------------
11678      -- No MPA option is assigned.
11679 
11680 
11681 END IF;
11682 END IF;
11683 --
11684 
11685 --
11686 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11687    trace
11688       (p_msg      => 'END of AcctLineType_33'
11689       ,p_level    => C_LEVEL_PROCEDURE
11690       ,p_module   => l_log_module);
11691 END IF;
11692 --
11693 EXCEPTION
11694   WHEN xla_exceptions_pkg.application_exception THEN
11695       RAISE;
11696   WHEN OTHERS THEN
11697        xla_exceptions_pkg.raise_message
11698            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_33');
11699 END AcctLineType_33;
11700 --
11701 
11702 ---------------------------------------
11703 --
11704 -- PRIVATE FUNCTION
11705 --         AcctLineType_34
11706 --
11707 ---------------------------------------
11708 PROCEDURE AcctLineType_34 (
11709   p_application_id        IN NUMBER
11710  ,p_event_id              IN NUMBER
11711  ,p_calculate_acctd_flag  IN VARCHAR2
11712  ,p_calculate_g_l_flag    IN VARCHAR2
11713  ,p_actual_flag           IN OUT VARCHAR2
11714  ,p_balance_type_code     OUT VARCHAR2
11715  ,p_gain_or_loss_ref      OUT VARCHAR2
11716  
11717 --Transaction Distribution GL Account
11718  , p_source_4            IN NUMBER
11719 --Bill To Customer Account Identifier
11720  , p_source_23            IN NUMBER
11721 --Bill To Customer Site Use Identifier
11722  , p_source_24            IN NUMBER
11723 --SLA Party Type
11724  , p_source_25            IN VARCHAR2
11725 --Transaction Distribution Account Class
11726  , p_source_26            IN VARCHAR2
11727 --Transaction Distribution Identifier
11728  , p_source_27            IN NUMBER
11729 --Transaction Distribution Type
11730  , p_source_28            IN VARCHAR2
11731 --Transaction Distribution Entered Amount
11732  , p_source_29            IN NUMBER
11733 --Transaction Currency Code
11734  , p_source_30            IN VARCHAR2
11735 --Transaction Exchange Date
11736  , p_source_31            IN DATE
11737 --Transaction Exchange Rate
11738  , p_source_32            IN NUMBER
11739 --Transaction Exchange Rate Type
11740  , p_source_33            IN VARCHAR2
11741 --Transaction Accounting Amount
11742  , p_source_34            IN NUMBER
11743 )
11744 IS
11745 
11746 l_component_type              VARCHAR2(80);
11747 l_component_code              VARCHAR2(30);
11748 l_component_type_code         VARCHAR2(1);
11749 l_component_appl_id           INTEGER;
11750 l_amb_context_code            VARCHAR2(30);
11751 l_entity_code                 VARCHAR2(30);
11752 l_event_class_code            VARCHAR2(30);
11753 l_ae_header_id                NUMBER;
11754 l_event_type_code             VARCHAR2(30);
11755 l_line_definition_code        VARCHAR2(30);
11756 l_line_definition_owner_code  VARCHAR2(1);
11757 --
11758 -- adr variables
11759 l_segment                     VARCHAR2(30);
11760 l_ccid                        NUMBER;
11761 l_adr_transaction_coa_id      NUMBER;
11762 l_adr_accounting_coa_id       NUMBER;
11763 l_adr_flexfield_segment_code  VARCHAR2(30);
11764 l_adr_flex_value_set_id       NUMBER;
11765 l_adr_value_type_code         VARCHAR2(30);
11766 l_adr_value_combination_id    NUMBER;
11767 l_adr_value_segment_code      VARCHAR2(30);
11768 
11769 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
11770 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
11771 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
11772 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
11773 
11774 -- 4262811 Variables ------------------------------------------------------------------------------------------
11775 l_entered_amt_idx             NUMBER;
11776 l_accted_amt_idx              NUMBER;
11777 l_acc_rev_flag                VARCHAR2(1);
11778 l_accrual_line_num            NUMBER;
11779 l_tmp_amt                     NUMBER;
11780 l_acc_rev_natural_side_code   VARCHAR2(1);
11781 
11782 l_num_entries                 NUMBER;
11783 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
11784 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
11785 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
11786 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
11787 l_recog_line_1                NUMBER;
11788 l_recog_line_2                NUMBER;
11789 
11790 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
11791 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
11792 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
11793 
11794 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
11795 
11796 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
11797 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
11798 
11799 ---------------------------------------------------------------------------------------------------------------
11800 
11801 
11802 --
11803 -- bulk performance
11804 --
11805 l_balance_type_code           VARCHAR2(1);
11806 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
11807 l_log_module                  VARCHAR2(240);
11808 
11809 --
11810 -- Upgrade strategy
11811 --
11812 l_actual_upg_option           VARCHAR2(1);
11813 l_enc_upg_option           VARCHAR2(1);
11814 
11815 --
11816 BEGIN
11817 --
11818 IF g_log_enabled THEN
11819       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_34';
11820 END IF;
11821 --
11822 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11823 
11824       trace
11825          (p_msg      => 'BEGIN of AcctLineType_34'
11826          ,p_level    => C_LEVEL_PROCEDURE
11827          ,p_module   => l_log_module);
11828 
11829 END IF;
11830 --
11831 l_component_type             := 'AMB_JLT';
11832 l_component_code             := 'DEP_DEFAULT_REC';
11833 l_component_type_code        := 'S';
11834 l_component_appl_id          :=  222;
11835 l_amb_context_code           := 'DEFAULT';
11836 l_entity_code                := 'TRANSACTIONS';
11837 l_event_class_code           := 'DEPOSIT';
11838 l_event_type_code            := 'DEPOSIT_ALL';
11839 l_line_definition_owner_code := 'S';
11840 l_line_definition_code       := 'AR_DEP_DEFAULT_ACCRUAL';
11841 --
11842 l_balance_type_code          := 'A';
11843 l_segment                     := NULL;
11844 l_ccid                        := NULL;
11845 l_adr_transaction_coa_id      := NULL;
11846 l_adr_accounting_coa_id       := NULL;
11847 l_adr_flexfield_segment_code  := NULL;
11848 l_adr_flex_value_set_id       := NULL;
11849 l_adr_value_type_code         := NULL;
11850 l_adr_value_combination_id    := NULL;
11851 l_adr_value_segment_code      := NULL;
11852 
11853 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
11854 l_bflow_class_code           := '';    -- 4219869 Business Flow
11855 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
11856 l_budgetary_control_flag     := 'N';
11857 
11858 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
11859 l_bflow_applied_to_amt       := NULL; -- 5132302
11860 l_entered_amt_idx            := NULL;          -- 4262811
11861 l_accted_amt_idx             := NULL;          -- 4262811
11862 l_acc_rev_flag               := NULL;          -- 4262811
11863 l_accrual_line_num           := NULL;          -- 4262811
11864 l_tmp_amt                    := NULL;          -- 4262811
11865 --
11866  
11867 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
11868     l_balance_type_code <> 'B' THEN
11869 IF NVL(p_source_26,'
11870 ') =  'REC'
11871  THEN 
11872 
11873    --
11874    XLA_AE_LINES_PKG.SetNewLine;
11875 
11876    p_balance_type_code          := l_balance_type_code;
11877    -- set the flag so later we will know whether the gain loss line needs to be created
11878    
11879    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
11880      p_actual_flag :='A';
11881    END IF;
11882 
11883    --
11884    -- bulk performance
11885    --
11886    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
11887                                       p_header_num   => 0); -- 4262811
11888    --
11889    -- set accounting line options
11890    --
11891    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
11892            p_natural_side_code          => 'D'
11893          , p_gain_or_loss_flag          => 'N'
11894          , p_gl_transfer_mode_code      => 'S'
11895          , p_acct_entry_type_code       => 'A'
11896          , p_switch_side_flag           => 'Y'
11897          , p_merge_duplicate_code       => 'A'
11898          );
11899    --
11900    l_acc_rev_natural_side_code := 'C';  -- 4262811
11901    -- 
11902    --
11903    -- set accounting line type info
11904    --
11905    xla_ae_lines_pkg.SetAcctLineType
11906       (p_component_type             => l_component_type
11907       ,p_event_type_code            => l_event_type_code
11908       ,p_line_definition_owner_code => l_line_definition_owner_code
11909       ,p_line_definition_code       => l_line_definition_code
11910       ,p_accounting_line_code       => l_component_code
11911       ,p_accounting_line_type_code  => l_component_type_code
11912       ,p_accounting_line_appl_id    => l_component_appl_id
11913       ,p_amb_context_code           => l_amb_context_code
11914       ,p_entity_code                => l_entity_code
11915       ,p_event_class_code           => l_event_class_code);
11916    --
11917    -- set accounting class
11918    --
11919    xla_ae_lines_pkg.SetAcctClass(
11920            p_accounting_class_code  => 'RECEIVABLE'
11921          , p_ae_header_id           => l_ae_header_id
11922          );
11923 
11924    --
11925    -- set rounding class
11926    --
11927    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
11928                       'RECEIVABLE';
11929 
11930    --
11931    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
11932    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
11933    --
11934    -- bulk performance
11935    --
11936    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
11937 
11938    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
11939       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
11940 
11941    -- 4955764
11942    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
11943       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
11944 
11945    -- 4458381 Public Sector Enh
11946    
11947    --
11948    -- set accounting attributes for the line type
11949    --
11950    l_entered_amt_idx := 3;
11951    l_accted_amt_idx  := 8;
11952    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
11953    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
11954    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
11955    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
11956    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
11957    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
11958    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
11959    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
11960    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
11961    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
11962    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
11963    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
11964    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
11965    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
11966    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
11967    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
11968    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
11969    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
11970    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
11971    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
11972    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
11973    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
11974    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
11975 
11976    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
11977    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
11978 
11979    ---------------------------------------------------------------------------------------------------------------
11980    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
11981    ---------------------------------------------------------------------------------------------------------------
11982    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
11983 
11984    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
11985    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
11986 
11987    IF xla_accounting_cache_pkg.GetValueChar
11988          (p_source_code         => 'LEDGER_CATEGORY_CODE'
11989          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
11990    AND l_bflow_method_code = 'PRIOR_ENTRY'
11991 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
11992    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
11993          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
11994        )
11995    THEN
11996          xla_ae_lines_pkg.BflowUpgEntry
11997            (p_business_method_code    => l_bflow_method_code
11998            ,p_business_class_code     => l_bflow_class_code
11999            ,p_balance_type            => l_balance_type_code);
12000    ELSE
12001       NULL;
12002 -- No business flow processing for business flow method of NONE.
12003    END IF;
12004 
12005    --
12006    -- call analytical criteria
12007    --
12008    
12009    --
12010    -- call description
12011    --
12012    -- No description or it is inherited.
12013    --
12014    -- call ADRs
12015    -- Bug 4922099
12016    --
12017    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
12018         (NVL(l_actual_upg_option, 'N') = 'O') OR
12019         (NVL(l_enc_upg_option, 'N') = 'O')
12020       )
12021    THEN
12022    NULL;
12023    --
12024    --
12025    
12026   l_ccid := AcctDerRule_16(
12027            p_application_id           => p_application_id
12028          , p_ae_header_id             => l_ae_header_id 
12029 , p_source_4 => p_source_4
12030          , x_transaction_coa_id       => l_adr_transaction_coa_id
12031          , x_accounting_coa_id        => l_adr_accounting_coa_id
12032          , x_value_type_code          => l_adr_value_type_code
12033          , p_side                     => 'NA'
12034    );
12035 
12036    xla_ae_lines_pkg.set_ccid(
12037     p_code_combination_id          => l_ccid
12038   , p_value_type_code              => l_adr_value_type_code
12039   , p_transaction_coa_id           => l_adr_transaction_coa_id
12040   , p_accounting_coa_id            => l_adr_accounting_coa_id
12041   , p_adr_code                     => 'TRX_DIST_CCID'
12042   , p_adr_type_code                => 'S'
12043   , p_component_type               => l_component_type
12044   , p_component_code               => l_component_code
12045   , p_component_type_code          => l_component_type_code
12046   , p_component_appl_id            => l_component_appl_id
12047   , p_amb_context_code             => l_amb_context_code
12048   , p_side                         => 'NA'
12049   );
12050 
12051 
12052    --
12053    --
12054    END IF;
12055    --
12056    -- Bug 4922099
12057    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
12058           (NVL(l_enc_upg_option, 'N') = 'O')
12059         ) AND
12060         (l_bflow_method_code = 'PRIOR_ENTRY')
12061       )
12062    THEN
12063       IF
12064       --
12065       1 = 2
12066       --
12067       THEN
12068       xla_accounting_err_pkg.build_message
12069                                     (p_appli_s_name            => 'XLA'
12070                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
12071                                     ,p_token_1                 => 'LINE_NUMBER'
12072                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
12073                                     ,p_token_2                 => 'LINE_TYPE_NAME'
12074                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
12075                                                                              l_component_type
12076                                                                             ,l_component_code
12077                                                                             ,l_component_type_code
12078                                                                             ,l_component_appl_id
12079                                                                             ,l_amb_context_code
12080                                                                             ,l_entity_code
12081                                                                             ,l_event_class_code
12082                                                                            )
12083                                     ,p_token_3                 => 'OWNER'
12084                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
12085                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
12086                                                                           ,p_lookup_code    => l_component_type_code
12087                                                                          )
12088                                     ,p_token_4                 => 'PRODUCT_NAME'
12089                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
12090                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
12091                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
12092                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
12093                                     ,p_ae_header_id            =>  NULL
12094                                        );
12095 
12096         IF (C_LEVEL_ERROR>= g_log_level) THEN
12097                  trace
12098                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
12099                       ,p_level    => C_LEVEL_ERROR
12100                       ,p_module   => l_log_module);
12101         END IF;
12102       END IF;
12103    END IF;
12104    --
12105    --
12106    ------------------------------------------------------------------------------------------------
12107    -- 4219869 Business Flow
12108    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
12109    -- Prior Entry.  Currently, the following code is always generated.
12110    ------------------------------------------------------------------------------------------------
12111    XLA_AE_LINES_PKG.ValidateCurrentLine;
12112 
12113    ------------------------------------------------------------------------------------
12114    -- 4219869 Business Flow
12115    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
12116    ------------------------------------------------------------------------------------
12117    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
12118 
12119    ----------------------------------------------------------------------------------
12120    -- 4219869 Business Flow
12121    -- Update journal entry status -- Need to generate this within IF <condition>
12122    ----------------------------------------------------------------------------------
12123    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
12124          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
12125          ,p_balance_type_code => l_balance_type_code
12126          );
12127 
12128    -------------------------------------------------------------------------------------------
12129    -- 4262811 - Generate the Accrual Reversal lines
12130    -------------------------------------------------------------------------------------------
12131    BEGIN
12132       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
12133                               (g_array_event(p_event_id).array_value_num('header_index'));
12134       IF l_acc_rev_flag IS NULL THEN
12135          l_acc_rev_flag := 'N';
12136       END IF;
12137    EXCEPTION
12138       WHEN OTHERS THEN
12139          l_acc_rev_flag := 'N';
12140    END;
12141    --
12142    IF (l_acc_rev_flag = 'Y') THEN
12143 
12144        -- 4645092  ------------------------------------------------------------------------------
12145        -- To allow MPA report to determine if it should generate report process
12146        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
12147        ------------------------------------------------------------------------------------------
12148 
12149        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
12150        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
12151    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
12152    -- call ADRs
12153    -- Bug 4922099
12154    --
12155    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
12156         (NVL(l_actual_upg_option, 'N') = 'O') OR
12157         (NVL(l_enc_upg_option, 'N') = 'O')
12158       )
12159    THEN
12160    NULL;
12161    --
12162    --
12163    
12164   l_ccid := AcctDerRule_16(
12165            p_application_id           => p_application_id
12166          , p_ae_header_id             => l_ae_header_id 
12167 , p_source_4 => p_source_4
12168          , x_transaction_coa_id       => l_adr_transaction_coa_id
12169          , x_accounting_coa_id        => l_adr_accounting_coa_id
12170          , x_value_type_code          => l_adr_value_type_code
12171          , p_side                     => 'NA'
12172    );
12173 
12174    xla_ae_lines_pkg.set_ccid(
12175     p_code_combination_id          => l_ccid
12176   , p_value_type_code              => l_adr_value_type_code
12177   , p_transaction_coa_id           => l_adr_transaction_coa_id
12178   , p_accounting_coa_id            => l_adr_accounting_coa_id
12179   , p_adr_code                     => 'TRX_DIST_CCID'
12180   , p_adr_type_code                => 'S'
12181   , p_component_type               => l_component_type
12182   , p_component_code               => l_component_code
12183   , p_component_type_code          => l_component_type_code
12184   , p_component_appl_id            => l_component_appl_id
12185   , p_amb_context_code             => l_amb_context_code
12186   , p_side                         => 'NA'
12187   );
12188 
12189 
12190    --
12191    --
12192    END IF;
12193 
12194        --
12195        -- Update the line information that should be overwritten
12196        --
12197        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
12198                                          p_header_num   => 1);
12199        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
12200 
12201        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
12202 
12203        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
12204           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
12205        END IF;
12206 
12207       --
12208       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
12209       --
12210       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
12211           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
12212       ELSE
12213           ---------------------------------------------------------------------------------------------------
12214           -- 4262811a Switch Sign
12215           ---------------------------------------------------------------------------------------------------
12216           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
12217           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
12218                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12219           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
12220                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12221           -- 5132302
12222           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
12223                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12224 
12225       END IF;
12226 
12227       -- 4955764
12228       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
12229       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
12230 
12231 
12232       XLA_AE_LINES_PKG.ValidateCurrentLine;
12233       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
12234 
12235       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
12236                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
12237                ,p_balance_type_code => l_balance_type_code);
12238 
12239    END IF;
12240 
12241    -----------------------------------------------------------------------------------------
12242    -- 4262811 Multiperiod Accounting
12243    -----------------------------------------------------------------------------------------
12244      -- No MPA option is assigned.
12245 
12246 
12247 END IF;
12248 END IF;
12249 --
12250 
12251 --
12252 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12253    trace
12254       (p_msg      => 'END of AcctLineType_34'
12255       ,p_level    => C_LEVEL_PROCEDURE
12256       ,p_module   => l_log_module);
12257 END IF;
12258 --
12259 EXCEPTION
12260   WHEN xla_exceptions_pkg.application_exception THEN
12261       RAISE;
12262   WHEN OTHERS THEN
12263        xla_exceptions_pkg.raise_message
12264            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_34');
12265 END AcctLineType_34;
12266 --
12267 
12268 ---------------------------------------
12269 --
12270 -- PRIVATE FUNCTION
12271 --         AcctLineType_35
12272 --
12273 ---------------------------------------
12274 PROCEDURE AcctLineType_35 (
12275   p_application_id        IN NUMBER
12276  ,p_event_id              IN NUMBER
12277  ,p_calculate_acctd_flag  IN VARCHAR2
12278  ,p_calculate_g_l_flag    IN VARCHAR2
12279  ,p_actual_flag           IN OUT VARCHAR2
12280  ,p_balance_type_code     OUT VARCHAR2
12281  ,p_gain_or_loss_ref      OUT VARCHAR2
12282  
12283 --Transaction Distribution GL Account
12284  , p_source_4            IN NUMBER
12285 --Bill To Customer Account Identifier
12286  , p_source_23            IN NUMBER
12287 --Bill To Customer Site Use Identifier
12288  , p_source_24            IN NUMBER
12289 --SLA Party Type
12290  , p_source_25            IN VARCHAR2
12291 --Transaction Distribution Account Class
12292  , p_source_26            IN VARCHAR2
12293 --Transaction Distribution Identifier
12294  , p_source_27            IN NUMBER
12295 --Transaction Distribution Type
12296  , p_source_28            IN VARCHAR2
12297 --Transaction Distribution Entered Amount
12298  , p_source_29            IN NUMBER
12299 --Transaction Currency Code
12300  , p_source_30            IN VARCHAR2
12301 --Transaction Exchange Date
12302  , p_source_31            IN DATE
12303 --Transaction Exchange Rate
12304  , p_source_32            IN NUMBER
12305 --Transaction Exchange Rate Type
12306  , p_source_33            IN VARCHAR2
12307 --Transaction Accounting Amount
12308  , p_source_34            IN NUMBER
12309 )
12310 IS
12311 
12312 l_component_type              VARCHAR2(80);
12313 l_component_code              VARCHAR2(30);
12314 l_component_type_code         VARCHAR2(1);
12315 l_component_appl_id           INTEGER;
12316 l_amb_context_code            VARCHAR2(30);
12317 l_entity_code                 VARCHAR2(30);
12318 l_event_class_code            VARCHAR2(30);
12319 l_ae_header_id                NUMBER;
12320 l_event_type_code             VARCHAR2(30);
12321 l_line_definition_code        VARCHAR2(30);
12322 l_line_definition_owner_code  VARCHAR2(1);
12323 --
12324 -- adr variables
12325 l_segment                     VARCHAR2(30);
12326 l_ccid                        NUMBER;
12327 l_adr_transaction_coa_id      NUMBER;
12328 l_adr_accounting_coa_id       NUMBER;
12329 l_adr_flexfield_segment_code  VARCHAR2(30);
12330 l_adr_flex_value_set_id       NUMBER;
12331 l_adr_value_type_code         VARCHAR2(30);
12332 l_adr_value_combination_id    NUMBER;
12333 l_adr_value_segment_code      VARCHAR2(30);
12334 
12335 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
12336 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
12337 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
12338 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
12339 
12340 -- 4262811 Variables ------------------------------------------------------------------------------------------
12341 l_entered_amt_idx             NUMBER;
12342 l_accted_amt_idx              NUMBER;
12343 l_acc_rev_flag                VARCHAR2(1);
12344 l_accrual_line_num            NUMBER;
12345 l_tmp_amt                     NUMBER;
12346 l_acc_rev_natural_side_code   VARCHAR2(1);
12347 
12348 l_num_entries                 NUMBER;
12349 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
12350 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
12351 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
12352 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
12353 l_recog_line_1                NUMBER;
12354 l_recog_line_2                NUMBER;
12355 
12356 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
12357 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
12358 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
12359 
12360 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
12361 
12362 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
12363 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
12364 
12365 ---------------------------------------------------------------------------------------------------------------
12366 
12367 
12368 --
12369 -- bulk performance
12370 --
12371 l_balance_type_code           VARCHAR2(1);
12372 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
12373 l_log_module                  VARCHAR2(240);
12374 
12375 --
12376 -- Upgrade strategy
12377 --
12378 l_actual_upg_option           VARCHAR2(1);
12379 l_enc_upg_option           VARCHAR2(1);
12380 
12381 --
12382 BEGIN
12383 --
12384 IF g_log_enabled THEN
12385       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_35';
12386 END IF;
12387 --
12388 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12389 
12390       trace
12391          (p_msg      => 'BEGIN of AcctLineType_35'
12392          ,p_level    => C_LEVEL_PROCEDURE
12393          ,p_module   => l_log_module);
12394 
12395 END IF;
12396 --
12397 l_component_type             := 'AMB_JLT';
12398 l_component_code             := 'DEP_OFFSET';
12399 l_component_type_code        := 'S';
12400 l_component_appl_id          :=  222;
12401 l_amb_context_code           := 'DEFAULT';
12402 l_entity_code                := 'TRANSACTIONS';
12403 l_event_class_code           := 'DEPOSIT';
12404 l_event_type_code            := 'DEPOSIT_ALL';
12405 l_line_definition_owner_code := 'S';
12406 l_line_definition_code       := 'AR_DEP_DEFAULT_ACCRUAL';
12407 --
12408 l_balance_type_code          := 'A';
12409 l_segment                     := NULL;
12410 l_ccid                        := NULL;
12411 l_adr_transaction_coa_id      := NULL;
12412 l_adr_accounting_coa_id       := NULL;
12413 l_adr_flexfield_segment_code  := NULL;
12414 l_adr_flex_value_set_id       := NULL;
12415 l_adr_value_type_code         := NULL;
12416 l_adr_value_combination_id    := NULL;
12417 l_adr_value_segment_code      := NULL;
12418 
12419 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
12420 l_bflow_class_code           := '';    -- 4219869 Business Flow
12421 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
12422 l_budgetary_control_flag     := 'N';
12423 
12424 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
12425 l_bflow_applied_to_amt       := NULL; -- 5132302
12426 l_entered_amt_idx            := NULL;          -- 4262811
12427 l_accted_amt_idx             := NULL;          -- 4262811
12428 l_acc_rev_flag               := NULL;          -- 4262811
12429 l_accrual_line_num           := NULL;          -- 4262811
12430 l_tmp_amt                    := NULL;          -- 4262811
12431 --
12432  
12433 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
12434     l_balance_type_code <> 'B' THEN
12435 IF NVL(p_source_26,'
12436 ') =  'REV'
12437  THEN 
12438 
12439    --
12440    XLA_AE_LINES_PKG.SetNewLine;
12441 
12442    p_balance_type_code          := l_balance_type_code;
12443    -- set the flag so later we will know whether the gain loss line needs to be created
12444    
12445    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
12446      p_actual_flag :='A';
12447    END IF;
12448 
12449    --
12450    -- bulk performance
12451    --
12452    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
12453                                       p_header_num   => 0); -- 4262811
12454    --
12455    -- set accounting line options
12456    --
12457    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
12458            p_natural_side_code          => 'C'
12459          , p_gain_or_loss_flag          => 'N'
12460          , p_gl_transfer_mode_code      => 'S'
12461          , p_acct_entry_type_code       => 'A'
12462          , p_switch_side_flag           => 'Y'
12463          , p_merge_duplicate_code       => 'A'
12464          );
12465    --
12466    l_acc_rev_natural_side_code := 'D';  -- 4262811
12467    -- 
12468    --
12469    -- set accounting line type info
12470    --
12471    xla_ae_lines_pkg.SetAcctLineType
12472       (p_component_type             => l_component_type
12473       ,p_event_type_code            => l_event_type_code
12474       ,p_line_definition_owner_code => l_line_definition_owner_code
12475       ,p_line_definition_code       => l_line_definition_code
12476       ,p_accounting_line_code       => l_component_code
12477       ,p_accounting_line_type_code  => l_component_type_code
12478       ,p_accounting_line_appl_id    => l_component_appl_id
12479       ,p_amb_context_code           => l_amb_context_code
12480       ,p_entity_code                => l_entity_code
12481       ,p_event_class_code           => l_event_class_code);
12482    --
12483    -- set accounting class
12484    --
12485    xla_ae_lines_pkg.SetAcctClass(
12486            p_accounting_class_code  => 'ACCRUAL'
12487          , p_ae_header_id           => l_ae_header_id
12488          );
12489 
12490    --
12491    -- set rounding class
12492    --
12493    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
12494                       'RECEIVABLE';
12495 
12496    --
12497    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
12498    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
12499    --
12500    -- bulk performance
12501    --
12502    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
12503 
12504    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
12505       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
12506 
12507    -- 4955764
12508    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
12509       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
12510 
12511    -- 4458381 Public Sector Enh
12512    
12513    --
12514    -- set accounting attributes for the line type
12515    --
12516    l_entered_amt_idx := 3;
12517    l_accted_amt_idx  := 8;
12518    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
12519    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
12520    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
12521    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
12522    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
12523    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
12524    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
12525    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
12526    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
12527    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
12528    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
12529    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
12530    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
12531    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
12532    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
12533    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
12534    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
12535    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
12536    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
12537    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
12538    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
12539    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
12540    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
12541 
12542    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
12543    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
12544 
12545    ---------------------------------------------------------------------------------------------------------------
12546    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
12547    ---------------------------------------------------------------------------------------------------------------
12548    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
12549 
12550    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
12551    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
12552 
12553    IF xla_accounting_cache_pkg.GetValueChar
12554          (p_source_code         => 'LEDGER_CATEGORY_CODE'
12555          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
12556    AND l_bflow_method_code = 'PRIOR_ENTRY'
12557 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
12558    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
12559          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
12560        )
12561    THEN
12562          xla_ae_lines_pkg.BflowUpgEntry
12563            (p_business_method_code    => l_bflow_method_code
12564            ,p_business_class_code     => l_bflow_class_code
12565            ,p_balance_type            => l_balance_type_code);
12566    ELSE
12567       NULL;
12568 -- No business flow processing for business flow method of NONE.
12569    END IF;
12570 
12571    --
12572    -- call analytical criteria
12573    --
12574    
12575    --
12576    -- call description
12577    --
12578    -- No description or it is inherited.
12579    --
12580    -- call ADRs
12581    -- Bug 4922099
12582    --
12583    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
12584         (NVL(l_actual_upg_option, 'N') = 'O') OR
12585         (NVL(l_enc_upg_option, 'N') = 'O')
12586       )
12587    THEN
12588    NULL;
12589    --
12590    --
12591    
12592   l_ccid := AcctDerRule_16(
12593            p_application_id           => p_application_id
12594          , p_ae_header_id             => l_ae_header_id 
12595 , p_source_4 => p_source_4
12596          , x_transaction_coa_id       => l_adr_transaction_coa_id
12597          , x_accounting_coa_id        => l_adr_accounting_coa_id
12598          , x_value_type_code          => l_adr_value_type_code
12599          , p_side                     => 'NA'
12600    );
12601 
12602    xla_ae_lines_pkg.set_ccid(
12603     p_code_combination_id          => l_ccid
12604   , p_value_type_code              => l_adr_value_type_code
12605   , p_transaction_coa_id           => l_adr_transaction_coa_id
12606   , p_accounting_coa_id            => l_adr_accounting_coa_id
12607   , p_adr_code                     => 'TRX_DIST_CCID'
12608   , p_adr_type_code                => 'S'
12609   , p_component_type               => l_component_type
12610   , p_component_code               => l_component_code
12611   , p_component_type_code          => l_component_type_code
12612   , p_component_appl_id            => l_component_appl_id
12613   , p_amb_context_code             => l_amb_context_code
12614   , p_side                         => 'NA'
12615   );
12616 
12617 
12618    --
12619    --
12620    END IF;
12621    --
12622    -- Bug 4922099
12623    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
12624           (NVL(l_enc_upg_option, 'N') = 'O')
12625         ) AND
12626         (l_bflow_method_code = 'PRIOR_ENTRY')
12627       )
12628    THEN
12629       IF
12630       --
12631       1 = 2
12632       --
12633       THEN
12634       xla_accounting_err_pkg.build_message
12635                                     (p_appli_s_name            => 'XLA'
12636                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
12637                                     ,p_token_1                 => 'LINE_NUMBER'
12638                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
12639                                     ,p_token_2                 => 'LINE_TYPE_NAME'
12640                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
12641                                                                              l_component_type
12642                                                                             ,l_component_code
12643                                                                             ,l_component_type_code
12644                                                                             ,l_component_appl_id
12645                                                                             ,l_amb_context_code
12646                                                                             ,l_entity_code
12647                                                                             ,l_event_class_code
12648                                                                            )
12649                                     ,p_token_3                 => 'OWNER'
12650                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
12651                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
12652                                                                           ,p_lookup_code    => l_component_type_code
12653                                                                          )
12654                                     ,p_token_4                 => 'PRODUCT_NAME'
12655                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
12656                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
12657                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
12658                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
12659                                     ,p_ae_header_id            =>  NULL
12660                                        );
12661 
12662         IF (C_LEVEL_ERROR>= g_log_level) THEN
12663                  trace
12664                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
12665                       ,p_level    => C_LEVEL_ERROR
12666                       ,p_module   => l_log_module);
12667         END IF;
12668       END IF;
12669    END IF;
12670    --
12671    --
12672    ------------------------------------------------------------------------------------------------
12673    -- 4219869 Business Flow
12674    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
12675    -- Prior Entry.  Currently, the following code is always generated.
12676    ------------------------------------------------------------------------------------------------
12677    XLA_AE_LINES_PKG.ValidateCurrentLine;
12678 
12679    ------------------------------------------------------------------------------------
12680    -- 4219869 Business Flow
12681    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
12682    ------------------------------------------------------------------------------------
12683    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
12684 
12685    ----------------------------------------------------------------------------------
12686    -- 4219869 Business Flow
12687    -- Update journal entry status -- Need to generate this within IF <condition>
12688    ----------------------------------------------------------------------------------
12689    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
12690          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
12691          ,p_balance_type_code => l_balance_type_code
12692          );
12693 
12694    -------------------------------------------------------------------------------------------
12695    -- 4262811 - Generate the Accrual Reversal lines
12696    -------------------------------------------------------------------------------------------
12697    BEGIN
12698       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
12699                               (g_array_event(p_event_id).array_value_num('header_index'));
12700       IF l_acc_rev_flag IS NULL THEN
12701          l_acc_rev_flag := 'N';
12702       END IF;
12703    EXCEPTION
12704       WHEN OTHERS THEN
12705          l_acc_rev_flag := 'N';
12706    END;
12707    --
12708    IF (l_acc_rev_flag = 'Y') THEN
12709 
12710        -- 4645092  ------------------------------------------------------------------------------
12711        -- To allow MPA report to determine if it should generate report process
12712        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
12713        ------------------------------------------------------------------------------------------
12714 
12715        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
12716        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
12717    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
12718    -- call ADRs
12719    -- Bug 4922099
12720    --
12721    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
12722         (NVL(l_actual_upg_option, 'N') = 'O') OR
12723         (NVL(l_enc_upg_option, 'N') = 'O')
12724       )
12725    THEN
12726    NULL;
12727    --
12728    --
12729    
12730   l_ccid := AcctDerRule_16(
12731            p_application_id           => p_application_id
12732          , p_ae_header_id             => l_ae_header_id 
12733 , p_source_4 => p_source_4
12734          , x_transaction_coa_id       => l_adr_transaction_coa_id
12735          , x_accounting_coa_id        => l_adr_accounting_coa_id
12736          , x_value_type_code          => l_adr_value_type_code
12737          , p_side                     => 'NA'
12738    );
12739 
12740    xla_ae_lines_pkg.set_ccid(
12741     p_code_combination_id          => l_ccid
12742   , p_value_type_code              => l_adr_value_type_code
12743   , p_transaction_coa_id           => l_adr_transaction_coa_id
12744   , p_accounting_coa_id            => l_adr_accounting_coa_id
12745   , p_adr_code                     => 'TRX_DIST_CCID'
12746   , p_adr_type_code                => 'S'
12747   , p_component_type               => l_component_type
12748   , p_component_code               => l_component_code
12749   , p_component_type_code          => l_component_type_code
12750   , p_component_appl_id            => l_component_appl_id
12751   , p_amb_context_code             => l_amb_context_code
12752   , p_side                         => 'NA'
12753   );
12754 
12755 
12756    --
12757    --
12758    END IF;
12759 
12760        --
12761        -- Update the line information that should be overwritten
12762        --
12763        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
12764                                          p_header_num   => 1);
12765        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
12766 
12767        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
12768 
12769        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
12770           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
12771        END IF;
12772 
12773       --
12774       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
12775       --
12776       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
12777           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
12778       ELSE
12779           ---------------------------------------------------------------------------------------------------
12780           -- 4262811a Switch Sign
12781           ---------------------------------------------------------------------------------------------------
12782           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
12783           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
12784                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12785           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
12786                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12787           -- 5132302
12788           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
12789                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12790 
12791       END IF;
12792 
12793       -- 4955764
12794       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
12795       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
12796 
12797 
12798       XLA_AE_LINES_PKG.ValidateCurrentLine;
12799       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
12800 
12801       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
12802                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
12803                ,p_balance_type_code => l_balance_type_code);
12804 
12805    END IF;
12806 
12807    -----------------------------------------------------------------------------------------
12808    -- 4262811 Multiperiod Accounting
12809    -----------------------------------------------------------------------------------------
12810      -- No MPA option is assigned.
12811 
12812 
12813 END IF;
12814 END IF;
12815 --
12816 
12817 --
12818 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12819    trace
12820       (p_msg      => 'END of AcctLineType_35'
12821       ,p_level    => C_LEVEL_PROCEDURE
12822       ,p_module   => l_log_module);
12823 END IF;
12824 --
12825 EXCEPTION
12826   WHEN xla_exceptions_pkg.application_exception THEN
12827       RAISE;
12828   WHEN OTHERS THEN
12829        xla_exceptions_pkg.raise_message
12830            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_35');
12831 END AcctLineType_35;
12832 --
12833 
12834 ---------------------------------------
12835 --
12836 -- PRIVATE FUNCTION
12837 --         AcctLineType_36
12838 --
12839 ---------------------------------------
12840 PROCEDURE AcctLineType_36 (
12841   p_application_id        IN NUMBER
12842  ,p_event_id              IN NUMBER
12843  ,p_calculate_acctd_flag  IN VARCHAR2
12844  ,p_calculate_g_l_flag    IN VARCHAR2
12845  ,p_actual_flag           IN OUT VARCHAR2
12846  ,p_balance_type_code     OUT VARCHAR2
12847  ,p_gain_or_loss_ref      OUT VARCHAR2
12848  
12849 --Transaction Distribution GL Account
12850  , p_source_4            IN NUMBER
12851 --Bill To Customer Account Identifier
12852  , p_source_23            IN NUMBER
12853 --Bill To Customer Site Use Identifier
12854  , p_source_24            IN NUMBER
12855 --SLA Party Type
12856  , p_source_25            IN VARCHAR2
12857 --Transaction Distribution Account Class
12858  , p_source_26            IN VARCHAR2
12859 --Transaction Distribution Identifier
12860  , p_source_27            IN NUMBER
12861 --Transaction Distribution Type
12862  , p_source_28            IN VARCHAR2
12863 --Transaction Distribution Entered Amount
12864  , p_source_29            IN NUMBER
12865 --Transaction Currency Code
12866  , p_source_30            IN VARCHAR2
12867 --Transaction Exchange Date
12868  , p_source_31            IN DATE
12869 --Transaction Exchange Rate
12870  , p_source_32            IN NUMBER
12871 --Transaction Exchange Rate Type
12872  , p_source_33            IN VARCHAR2
12873 --Transaction Accounting Amount
12874  , p_source_34            IN NUMBER
12875 --Transaction Tax Line Identifier
12876  , p_source_48            IN NUMBER
12877 )
12878 IS
12879 
12880 l_component_type              VARCHAR2(80);
12881 l_component_code              VARCHAR2(30);
12882 l_component_type_code         VARCHAR2(1);
12883 l_component_appl_id           INTEGER;
12884 l_amb_context_code            VARCHAR2(30);
12885 l_entity_code                 VARCHAR2(30);
12889 l_line_definition_code        VARCHAR2(30);
12886 l_event_class_code            VARCHAR2(30);
12887 l_ae_header_id                NUMBER;
12888 l_event_type_code             VARCHAR2(30);
12890 l_line_definition_owner_code  VARCHAR2(1);
12891 --
12892 -- adr variables
12893 l_segment                     VARCHAR2(30);
12894 l_ccid                        NUMBER;
12895 l_adr_transaction_coa_id      NUMBER;
12896 l_adr_accounting_coa_id       NUMBER;
12897 l_adr_flexfield_segment_code  VARCHAR2(30);
12898 l_adr_flex_value_set_id       NUMBER;
12899 l_adr_value_type_code         VARCHAR2(30);
12900 l_adr_value_combination_id    NUMBER;
12901 l_adr_value_segment_code      VARCHAR2(30);
12902 
12903 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
12904 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
12905 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
12906 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
12907 
12908 -- 4262811 Variables ------------------------------------------------------------------------------------------
12909 l_entered_amt_idx             NUMBER;
12910 l_accted_amt_idx              NUMBER;
12911 l_acc_rev_flag                VARCHAR2(1);
12912 l_accrual_line_num            NUMBER;
12913 l_tmp_amt                     NUMBER;
12914 l_acc_rev_natural_side_code   VARCHAR2(1);
12915 
12916 l_num_entries                 NUMBER;
12917 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
12918 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
12919 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
12920 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
12921 l_recog_line_1                NUMBER;
12922 l_recog_line_2                NUMBER;
12923 
12924 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
12925 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
12926 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
12927 
12928 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
12929 
12930 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
12931 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
12932 
12933 ---------------------------------------------------------------------------------------------------------------
12934 
12935 
12936 --
12937 -- bulk performance
12938 --
12939 l_balance_type_code           VARCHAR2(1);
12940 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
12941 l_log_module                  VARCHAR2(240);
12942 
12943 --
12944 -- Upgrade strategy
12945 --
12946 l_actual_upg_option           VARCHAR2(1);
12947 l_enc_upg_option           VARCHAR2(1);
12948 
12949 --
12950 BEGIN
12951 --
12952 IF g_log_enabled THEN
12953       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_36';
12954 END IF;
12955 --
12956 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12957 
12958       trace
12959          (p_msg      => 'BEGIN of AcctLineType_36'
12960          ,p_level    => C_LEVEL_PROCEDURE
12961          ,p_module   => l_log_module);
12962 
12963 END IF;
12964 --
12965 l_component_type             := 'AMB_JLT';
12966 l_component_code             := 'DM_CHARGES';
12967 l_component_type_code        := 'S';
12968 l_component_appl_id          :=  222;
12969 l_amb_context_code           := 'DEFAULT';
12970 l_entity_code                := 'TRANSACTIONS';
12971 l_event_class_code           := 'DEBIT_MEMO';
12972 l_event_type_code            := 'DEBIT_MEMO_ALL';
12973 l_line_definition_owner_code := 'S';
12974 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
12975 --
12976 l_balance_type_code          := 'A';
12977 l_segment                     := NULL;
12978 l_ccid                        := NULL;
12979 l_adr_transaction_coa_id      := NULL;
12980 l_adr_accounting_coa_id       := NULL;
12981 l_adr_flexfield_segment_code  := NULL;
12982 l_adr_flex_value_set_id       := NULL;
12983 l_adr_value_type_code         := NULL;
12984 l_adr_value_combination_id    := NULL;
12985 l_adr_value_segment_code      := NULL;
12986 
12987 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
12988 l_bflow_class_code           := '';    -- 4219869 Business Flow
12989 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
12990 l_budgetary_control_flag     := 'N';
12991 
12992 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
12993 l_bflow_applied_to_amt       := NULL; -- 5132302
12994 l_entered_amt_idx            := NULL;          -- 4262811
12995 l_accted_amt_idx             := NULL;          -- 4262811
12996 l_acc_rev_flag               := NULL;          -- 4262811
12997 l_accrual_line_num           := NULL;          -- 4262811
12998 l_tmp_amt                    := NULL;          -- 4262811
12999 --
13000  
13001 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
13002     l_balance_type_code <> 'B' THEN
13003 IF NVL(p_source_26,'
13004 ') =  'CHARGES'
13005  THEN 
13006 
13007    --
13008    XLA_AE_LINES_PKG.SetNewLine;
13009 
13010    p_balance_type_code          := l_balance_type_code;
13011    -- set the flag so later we will know whether the gain loss line needs to be created
13012    
13013    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
13014      p_actual_flag :='A';
13015    END IF;
13016 
13017    --
13018    -- bulk performance
13019    --
13020    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
13024    --
13021                                       p_header_num   => 0); -- 4262811
13022    --
13023    -- set accounting line options
13025    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
13026            p_natural_side_code          => 'C'
13027          , p_gain_or_loss_flag          => 'N'
13028          , p_gl_transfer_mode_code      => 'S'
13029          , p_acct_entry_type_code       => 'A'
13030          , p_switch_side_flag           => 'Y'
13031          , p_merge_duplicate_code       => 'A'
13032          );
13033    --
13034    l_acc_rev_natural_side_code := 'D';  -- 4262811
13035    -- 
13036    --
13037    -- set accounting line type info
13038    --
13039    xla_ae_lines_pkg.SetAcctLineType
13040       (p_component_type             => l_component_type
13041       ,p_event_type_code            => l_event_type_code
13042       ,p_line_definition_owner_code => l_line_definition_owner_code
13043       ,p_line_definition_code       => l_line_definition_code
13044       ,p_accounting_line_code       => l_component_code
13045       ,p_accounting_line_type_code  => l_component_type_code
13046       ,p_accounting_line_appl_id    => l_component_appl_id
13047       ,p_amb_context_code           => l_amb_context_code
13048       ,p_entity_code                => l_entity_code
13049       ,p_event_class_code           => l_event_class_code);
13050    --
13051    -- set accounting class
13052    --
13053    xla_ae_lines_pkg.SetAcctClass(
13054            p_accounting_class_code  => 'CHARGES'
13055          , p_ae_header_id           => l_ae_header_id
13056          );
13057 
13058    --
13059    -- set rounding class
13060    --
13061    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
13062                       'RECEIVABLE';
13063 
13064    --
13065    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
13066    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
13067    --
13068    -- bulk performance
13069    --
13070    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
13071 
13072    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
13073       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
13074 
13075    -- 4955764
13076    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
13077       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
13078 
13079    -- 4458381 Public Sector Enh
13080    
13081    --
13082    -- set accounting attributes for the line type
13083    --
13084    l_entered_amt_idx := 3;
13085    l_accted_amt_idx  := 8;
13086    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
13087    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
13088    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
13089    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
13090    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
13091    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
13092    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
13093    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
13094    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
13095    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
13096    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
13097    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
13098    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
13099    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
13100    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
13101    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
13102    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
13103    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
13104    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
13105    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
13106    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
13107    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
13108    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
13109    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
13110    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
13111 
13112    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
13113    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
13114 
13115    ---------------------------------------------------------------------------------------------------------------
13116    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
13117    ---------------------------------------------------------------------------------------------------------------
13118    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
13119 
13120    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
13121    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
13122 
13123    IF xla_accounting_cache_pkg.GetValueChar
13124          (p_source_code         => 'LEDGER_CATEGORY_CODE'
13125          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
13126    AND l_bflow_method_code = 'PRIOR_ENTRY'
13127 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
13128    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
13129          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
13130        )
13131    THEN
13132          xla_ae_lines_pkg.BflowUpgEntry
13136    ELSE
13133            (p_business_method_code    => l_bflow_method_code
13134            ,p_business_class_code     => l_bflow_class_code
13135            ,p_balance_type            => l_balance_type_code);
13137       NULL;
13138 -- No business flow processing for business flow method of NONE.
13139    END IF;
13140 
13141    --
13142    -- call analytical criteria
13143    --
13144    
13145    --
13146    -- call description
13147    --
13148    -- No description or it is inherited.
13149    --
13150    -- call ADRs
13151    -- Bug 4922099
13152    --
13153    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
13154         (NVL(l_actual_upg_option, 'N') = 'O') OR
13155         (NVL(l_enc_upg_option, 'N') = 'O')
13156       )
13157    THEN
13158    NULL;
13159    --
13160    --
13161    
13162   l_ccid := AcctDerRule_16(
13163            p_application_id           => p_application_id
13164          , p_ae_header_id             => l_ae_header_id 
13165 , p_source_4 => p_source_4
13166          , x_transaction_coa_id       => l_adr_transaction_coa_id
13167          , x_accounting_coa_id        => l_adr_accounting_coa_id
13168          , x_value_type_code          => l_adr_value_type_code
13169          , p_side                     => 'NA'
13170    );
13171 
13172    xla_ae_lines_pkg.set_ccid(
13173     p_code_combination_id          => l_ccid
13174   , p_value_type_code              => l_adr_value_type_code
13175   , p_transaction_coa_id           => l_adr_transaction_coa_id
13176   , p_accounting_coa_id            => l_adr_accounting_coa_id
13177   , p_adr_code                     => 'TRX_DIST_CCID'
13178   , p_adr_type_code                => 'S'
13179   , p_component_type               => l_component_type
13180   , p_component_code               => l_component_code
13181   , p_component_type_code          => l_component_type_code
13182   , p_component_appl_id            => l_component_appl_id
13183   , p_amb_context_code             => l_amb_context_code
13184   , p_side                         => 'NA'
13185   );
13186 
13187 
13188    --
13189    --
13190    END IF;
13191    --
13192    -- Bug 4922099
13193    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
13194           (NVL(l_enc_upg_option, 'N') = 'O')
13195         ) AND
13196         (l_bflow_method_code = 'PRIOR_ENTRY')
13197       )
13198    THEN
13199       IF
13200       --
13201       1 = 2
13202       --
13203       THEN
13204       xla_accounting_err_pkg.build_message
13205                                     (p_appli_s_name            => 'XLA'
13206                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
13207                                     ,p_token_1                 => 'LINE_NUMBER'
13208                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
13209                                     ,p_token_2                 => 'LINE_TYPE_NAME'
13210                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
13211                                                                              l_component_type
13212                                                                             ,l_component_code
13213                                                                             ,l_component_type_code
13214                                                                             ,l_component_appl_id
13215                                                                             ,l_amb_context_code
13216                                                                             ,l_entity_code
13217                                                                             ,l_event_class_code
13218                                                                            )
13219                                     ,p_token_3                 => 'OWNER'
13220                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
13221                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
13222                                                                           ,p_lookup_code    => l_component_type_code
13223                                                                          )
13224                                     ,p_token_4                 => 'PRODUCT_NAME'
13225                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
13226                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
13227                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
13228                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
13229                                     ,p_ae_header_id            =>  NULL
13230                                        );
13231 
13232         IF (C_LEVEL_ERROR>= g_log_level) THEN
13233                  trace
13234                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
13235                       ,p_level    => C_LEVEL_ERROR
13236                       ,p_module   => l_log_module);
13237         END IF;
13238       END IF;
13239    END IF;
13240    --
13241    --
13242    ------------------------------------------------------------------------------------------------
13243    -- 4219869 Business Flow
13244    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
13245    -- Prior Entry.  Currently, the following code is always generated.
13246    ------------------------------------------------------------------------------------------------
13247    XLA_AE_LINES_PKG.ValidateCurrentLine;
13248 
13252    ------------------------------------------------------------------------------------
13249    ------------------------------------------------------------------------------------
13250    -- 4219869 Business Flow
13251    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
13253    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
13254 
13255    ----------------------------------------------------------------------------------
13256    -- 4219869 Business Flow
13257    -- Update journal entry status -- Need to generate this within IF <condition>
13258    ----------------------------------------------------------------------------------
13259    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
13260          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
13261          ,p_balance_type_code => l_balance_type_code
13262          );
13263 
13264    -------------------------------------------------------------------------------------------
13265    -- 4262811 - Generate the Accrual Reversal lines
13266    -------------------------------------------------------------------------------------------
13267    BEGIN
13268       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
13269                               (g_array_event(p_event_id).array_value_num('header_index'));
13270       IF l_acc_rev_flag IS NULL THEN
13271          l_acc_rev_flag := 'N';
13272       END IF;
13273    EXCEPTION
13274       WHEN OTHERS THEN
13275          l_acc_rev_flag := 'N';
13276    END;
13277    --
13278    IF (l_acc_rev_flag = 'Y') THEN
13279 
13280        -- 4645092  ------------------------------------------------------------------------------
13281        -- To allow MPA report to determine if it should generate report process
13282        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
13283        ------------------------------------------------------------------------------------------
13284 
13285        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
13286        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
13287    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
13288    -- call ADRs
13289    -- Bug 4922099
13290    --
13291    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
13292         (NVL(l_actual_upg_option, 'N') = 'O') OR
13293         (NVL(l_enc_upg_option, 'N') = 'O')
13294       )
13295    THEN
13296    NULL;
13297    --
13298    --
13299    
13300   l_ccid := AcctDerRule_16(
13301            p_application_id           => p_application_id
13302          , p_ae_header_id             => l_ae_header_id 
13303 , p_source_4 => p_source_4
13304          , x_transaction_coa_id       => l_adr_transaction_coa_id
13305          , x_accounting_coa_id        => l_adr_accounting_coa_id
13306          , x_value_type_code          => l_adr_value_type_code
13307          , p_side                     => 'NA'
13308    );
13309 
13310    xla_ae_lines_pkg.set_ccid(
13311     p_code_combination_id          => l_ccid
13312   , p_value_type_code              => l_adr_value_type_code
13313   , p_transaction_coa_id           => l_adr_transaction_coa_id
13314   , p_accounting_coa_id            => l_adr_accounting_coa_id
13315   , p_adr_code                     => 'TRX_DIST_CCID'
13316   , p_adr_type_code                => 'S'
13317   , p_component_type               => l_component_type
13318   , p_component_code               => l_component_code
13319   , p_component_type_code          => l_component_type_code
13320   , p_component_appl_id            => l_component_appl_id
13321   , p_amb_context_code             => l_amb_context_code
13322   , p_side                         => 'NA'
13323   );
13324 
13325 
13326    --
13327    --
13328    END IF;
13329 
13330        --
13331        -- Update the line information that should be overwritten
13332        --
13333        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
13334                                          p_header_num   => 1);
13335        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
13336 
13337        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
13338 
13339        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
13340           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
13341        END IF;
13342 
13343       --
13344       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
13345       --
13346       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
13347           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
13348       ELSE
13349           ---------------------------------------------------------------------------------------------------
13350           -- 4262811a Switch Sign
13351           ---------------------------------------------------------------------------------------------------
13352           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
13353           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
13354                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
13355           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
13356                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
13357           -- 5132302
13358           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
13359                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
13360 
13364       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
13361       END IF;
13362 
13363       -- 4955764
13365       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
13366 
13367 
13368       XLA_AE_LINES_PKG.ValidateCurrentLine;
13369       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
13370 
13371       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
13372                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
13373                ,p_balance_type_code => l_balance_type_code);
13374 
13375    END IF;
13376 
13377    -----------------------------------------------------------------------------------------
13378    -- 4262811 Multiperiod Accounting
13379    -----------------------------------------------------------------------------------------
13380      -- No MPA option is assigned.
13381 
13382 
13383 END IF;
13384 END IF;
13385 --
13386 
13387 --
13388 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13389    trace
13390       (p_msg      => 'END of AcctLineType_36'
13391       ,p_level    => C_LEVEL_PROCEDURE
13392       ,p_module   => l_log_module);
13393 END IF;
13394 --
13395 EXCEPTION
13396   WHEN xla_exceptions_pkg.application_exception THEN
13397       RAISE;
13398   WHEN OTHERS THEN
13399        xla_exceptions_pkg.raise_message
13400            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_36');
13401 END AcctLineType_36;
13402 --
13403 
13404 ---------------------------------------
13405 --
13406 -- PRIVATE FUNCTION
13407 --         AcctLineType_37
13408 --
13409 ---------------------------------------
13410 PROCEDURE AcctLineType_37 (
13411   p_application_id        IN NUMBER
13412  ,p_event_id              IN NUMBER
13413  ,p_calculate_acctd_flag  IN VARCHAR2
13414  ,p_calculate_g_l_flag    IN VARCHAR2
13415  ,p_actual_flag           IN OUT VARCHAR2
13416  ,p_balance_type_code     OUT VARCHAR2
13417  ,p_gain_or_loss_ref      OUT VARCHAR2
13418  
13419 --Transaction Distribution GL Account
13420  , p_source_4            IN NUMBER
13421 --Bill To Customer Account Identifier
13422  , p_source_23            IN NUMBER
13423 --Bill To Customer Site Use Identifier
13424  , p_source_24            IN NUMBER
13425 --SLA Party Type
13426  , p_source_25            IN VARCHAR2
13427 --Transaction Distribution Account Class
13428  , p_source_26            IN VARCHAR2
13429 --Transaction Distribution Identifier
13430  , p_source_27            IN NUMBER
13431 --Transaction Distribution Type
13432  , p_source_28            IN VARCHAR2
13433 --Transaction Distribution Entered Amount
13434  , p_source_29            IN NUMBER
13435 --Transaction Currency Code
13436  , p_source_30            IN VARCHAR2
13437 --Transaction Exchange Date
13438  , p_source_31            IN DATE
13439 --Transaction Exchange Rate
13440  , p_source_32            IN NUMBER
13441 --Transaction Exchange Rate Type
13442  , p_source_33            IN VARCHAR2
13443 --Transaction Accounting Amount
13444  , p_source_34            IN NUMBER
13445 --Transaction Tax Line Identifier
13446  , p_source_48            IN NUMBER
13447 )
13448 IS
13449 
13450 l_component_type              VARCHAR2(80);
13451 l_component_code              VARCHAR2(30);
13452 l_component_type_code         VARCHAR2(1);
13453 l_component_appl_id           INTEGER;
13454 l_amb_context_code            VARCHAR2(30);
13455 l_entity_code                 VARCHAR2(30);
13456 l_event_class_code            VARCHAR2(30);
13457 l_ae_header_id                NUMBER;
13458 l_event_type_code             VARCHAR2(30);
13459 l_line_definition_code        VARCHAR2(30);
13460 l_line_definition_owner_code  VARCHAR2(1);
13461 --
13462 -- adr variables
13463 l_segment                     VARCHAR2(30);
13464 l_ccid                        NUMBER;
13465 l_adr_transaction_coa_id      NUMBER;
13466 l_adr_accounting_coa_id       NUMBER;
13467 l_adr_flexfield_segment_code  VARCHAR2(30);
13468 l_adr_flex_value_set_id       NUMBER;
13469 l_adr_value_type_code         VARCHAR2(30);
13470 l_adr_value_combination_id    NUMBER;
13471 l_adr_value_segment_code      VARCHAR2(30);
13472 
13473 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
13474 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
13475 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
13476 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
13477 
13478 -- 4262811 Variables ------------------------------------------------------------------------------------------
13479 l_entered_amt_idx             NUMBER;
13480 l_accted_amt_idx              NUMBER;
13481 l_acc_rev_flag                VARCHAR2(1);
13482 l_accrual_line_num            NUMBER;
13483 l_tmp_amt                     NUMBER;
13484 l_acc_rev_natural_side_code   VARCHAR2(1);
13485 
13486 l_num_entries                 NUMBER;
13487 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
13488 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
13489 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
13490 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
13491 l_recog_line_1                NUMBER;
13492 l_recog_line_2                NUMBER;
13493 
13494 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
13495 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
13496 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
13497 
13498 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
13502 
13499 
13500 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
13501 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
13503 ---------------------------------------------------------------------------------------------------------------
13504 
13505 
13506 --
13507 -- bulk performance
13508 --
13509 l_balance_type_code           VARCHAR2(1);
13510 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
13511 l_log_module                  VARCHAR2(240);
13512 
13513 --
13514 -- Upgrade strategy
13515 --
13516 l_actual_upg_option           VARCHAR2(1);
13517 l_enc_upg_option           VARCHAR2(1);
13518 
13519 --
13520 BEGIN
13521 --
13522 IF g_log_enabled THEN
13523       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_37';
13524 END IF;
13525 --
13526 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13527 
13528       trace
13529          (p_msg      => 'BEGIN of AcctLineType_37'
13530          ,p_level    => C_LEVEL_PROCEDURE
13531          ,p_module   => l_log_module);
13532 
13533 END IF;
13534 --
13535 l_component_type             := 'AMB_JLT';
13536 l_component_code             := 'DM_FREIGHT';
13537 l_component_type_code        := 'S';
13538 l_component_appl_id          :=  222;
13539 l_amb_context_code           := 'DEFAULT';
13540 l_entity_code                := 'TRANSACTIONS';
13541 l_event_class_code           := 'DEBIT_MEMO';
13542 l_event_type_code            := 'DEBIT_MEMO_ALL';
13543 l_line_definition_owner_code := 'S';
13544 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
13545 --
13546 l_balance_type_code          := 'A';
13547 l_segment                     := NULL;
13548 l_ccid                        := NULL;
13549 l_adr_transaction_coa_id      := NULL;
13550 l_adr_accounting_coa_id       := NULL;
13551 l_adr_flexfield_segment_code  := NULL;
13552 l_adr_flex_value_set_id       := NULL;
13553 l_adr_value_type_code         := NULL;
13554 l_adr_value_combination_id    := NULL;
13555 l_adr_value_segment_code      := NULL;
13556 
13557 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
13558 l_bflow_class_code           := '';    -- 4219869 Business Flow
13559 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
13560 l_budgetary_control_flag     := 'N';
13561 
13562 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
13563 l_bflow_applied_to_amt       := NULL; -- 5132302
13564 l_entered_amt_idx            := NULL;          -- 4262811
13565 l_accted_amt_idx             := NULL;          -- 4262811
13566 l_acc_rev_flag               := NULL;          -- 4262811
13567 l_accrual_line_num           := NULL;          -- 4262811
13568 l_tmp_amt                    := NULL;          -- 4262811
13569 --
13570  
13571 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
13572     l_balance_type_code <> 'B' THEN
13573 IF NVL(p_source_26,'
13574 ') =  'FREIGHT'
13575  THEN 
13576 
13577    --
13578    XLA_AE_LINES_PKG.SetNewLine;
13579 
13580    p_balance_type_code          := l_balance_type_code;
13581    -- set the flag so later we will know whether the gain loss line needs to be created
13582    
13583    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
13584      p_actual_flag :='A';
13585    END IF;
13586 
13587    --
13588    -- bulk performance
13589    --
13590    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
13591                                       p_header_num   => 0); -- 4262811
13592    --
13593    -- set accounting line options
13594    --
13595    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
13596            p_natural_side_code          => 'C'
13597          , p_gain_or_loss_flag          => 'N'
13598          , p_gl_transfer_mode_code      => 'S'
13599          , p_acct_entry_type_code       => 'A'
13600          , p_switch_side_flag           => 'Y'
13601          , p_merge_duplicate_code       => 'A'
13602          );
13603    --
13604    l_acc_rev_natural_side_code := 'D';  -- 4262811
13605    -- 
13606    --
13607    -- set accounting line type info
13608    --
13609    xla_ae_lines_pkg.SetAcctLineType
13610       (p_component_type             => l_component_type
13611       ,p_event_type_code            => l_event_type_code
13612       ,p_line_definition_owner_code => l_line_definition_owner_code
13613       ,p_line_definition_code       => l_line_definition_code
13614       ,p_accounting_line_code       => l_component_code
13615       ,p_accounting_line_type_code  => l_component_type_code
13616       ,p_accounting_line_appl_id    => l_component_appl_id
13617       ,p_amb_context_code           => l_amb_context_code
13618       ,p_entity_code                => l_entity_code
13619       ,p_event_class_code           => l_event_class_code);
13620    --
13621    -- set accounting class
13622    --
13623    xla_ae_lines_pkg.SetAcctClass(
13624            p_accounting_class_code  => 'FREIGHT'
13625          , p_ae_header_id           => l_ae_header_id
13626          );
13627 
13628    --
13629    -- set rounding class
13630    --
13631    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
13632                       'RECEIVABLE';
13633 
13634    --
13635    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
13636    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
13637    --
13638    -- bulk performance
13639    --
13643       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
13640    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
13641 
13642    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
13644 
13645    -- 4955764
13646    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
13647       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
13648 
13649    -- 4458381 Public Sector Enh
13650    
13651    --
13652    -- set accounting attributes for the line type
13653    --
13654    l_entered_amt_idx := 3;
13655    l_accted_amt_idx  := 8;
13656    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
13657    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
13658    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
13659    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
13660    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
13661    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
13662    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
13663    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
13664    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
13665    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
13666    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
13667    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
13668    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
13669    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
13670    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
13671    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
13672    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
13673    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
13674    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
13675    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
13676    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
13677    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
13678    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
13679    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
13680    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
13681 
13682    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
13683    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
13684 
13685    ---------------------------------------------------------------------------------------------------------------
13686    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
13687    ---------------------------------------------------------------------------------------------------------------
13688    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
13689 
13690    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
13691    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
13692 
13693    IF xla_accounting_cache_pkg.GetValueChar
13694          (p_source_code         => 'LEDGER_CATEGORY_CODE'
13695          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
13696    AND l_bflow_method_code = 'PRIOR_ENTRY'
13697 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
13698    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
13699          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
13700        )
13701    THEN
13702          xla_ae_lines_pkg.BflowUpgEntry
13703            (p_business_method_code    => l_bflow_method_code
13704            ,p_business_class_code     => l_bflow_class_code
13705            ,p_balance_type            => l_balance_type_code);
13706    ELSE
13707       NULL;
13708 -- No business flow processing for business flow method of NONE.
13709    END IF;
13710 
13711    --
13712    -- call analytical criteria
13713    --
13714    
13715    --
13716    -- call description
13717    --
13718    -- No description or it is inherited.
13719    --
13720    -- call ADRs
13721    -- Bug 4922099
13722    --
13723    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
13724         (NVL(l_actual_upg_option, 'N') = 'O') OR
13725         (NVL(l_enc_upg_option, 'N') = 'O')
13726       )
13727    THEN
13728    NULL;
13729    --
13730    --
13731    
13732   l_ccid := AcctDerRule_16(
13733            p_application_id           => p_application_id
13734          , p_ae_header_id             => l_ae_header_id 
13735 , p_source_4 => p_source_4
13736          , x_transaction_coa_id       => l_adr_transaction_coa_id
13737          , x_accounting_coa_id        => l_adr_accounting_coa_id
13738          , x_value_type_code          => l_adr_value_type_code
13739          , p_side                     => 'NA'
13740    );
13741 
13742    xla_ae_lines_pkg.set_ccid(
13743     p_code_combination_id          => l_ccid
13744   , p_value_type_code              => l_adr_value_type_code
13745   , p_transaction_coa_id           => l_adr_transaction_coa_id
13746   , p_accounting_coa_id            => l_adr_accounting_coa_id
13747   , p_adr_code                     => 'TRX_DIST_CCID'
13748   , p_adr_type_code                => 'S'
13749   , p_component_type               => l_component_type
13750   , p_component_code               => l_component_code
13751   , p_component_type_code          => l_component_type_code
13752   , p_component_appl_id            => l_component_appl_id
13756 
13753   , p_amb_context_code             => l_amb_context_code
13754   , p_side                         => 'NA'
13755   );
13757 
13758    --
13759    --
13760    END IF;
13761    --
13762    -- Bug 4922099
13763    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
13764           (NVL(l_enc_upg_option, 'N') = 'O')
13765         ) AND
13766         (l_bflow_method_code = 'PRIOR_ENTRY')
13767       )
13768    THEN
13769       IF
13770       --
13771       1 = 2
13772       --
13773       THEN
13774       xla_accounting_err_pkg.build_message
13775                                     (p_appli_s_name            => 'XLA'
13776                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
13777                                     ,p_token_1                 => 'LINE_NUMBER'
13778                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
13779                                     ,p_token_2                 => 'LINE_TYPE_NAME'
13780                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
13781                                                                              l_component_type
13782                                                                             ,l_component_code
13783                                                                             ,l_component_type_code
13784                                                                             ,l_component_appl_id
13785                                                                             ,l_amb_context_code
13786                                                                             ,l_entity_code
13787                                                                             ,l_event_class_code
13788                                                                            )
13789                                     ,p_token_3                 => 'OWNER'
13790                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
13791                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
13792                                                                           ,p_lookup_code    => l_component_type_code
13793                                                                          )
13794                                     ,p_token_4                 => 'PRODUCT_NAME'
13795                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
13796                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
13797                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
13798                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
13799                                     ,p_ae_header_id            =>  NULL
13800                                        );
13801 
13802         IF (C_LEVEL_ERROR>= g_log_level) THEN
13803                  trace
13804                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
13805                       ,p_level    => C_LEVEL_ERROR
13806                       ,p_module   => l_log_module);
13807         END IF;
13808       END IF;
13809    END IF;
13810    --
13811    --
13812    ------------------------------------------------------------------------------------------------
13813    -- 4219869 Business Flow
13814    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
13815    -- Prior Entry.  Currently, the following code is always generated.
13816    ------------------------------------------------------------------------------------------------
13817    XLA_AE_LINES_PKG.ValidateCurrentLine;
13818 
13819    ------------------------------------------------------------------------------------
13820    -- 4219869 Business Flow
13821    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
13822    ------------------------------------------------------------------------------------
13823    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
13824 
13825    ----------------------------------------------------------------------------------
13826    -- 4219869 Business Flow
13827    -- Update journal entry status -- Need to generate this within IF <condition>
13828    ----------------------------------------------------------------------------------
13829    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
13830          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
13831          ,p_balance_type_code => l_balance_type_code
13832          );
13833 
13834    -------------------------------------------------------------------------------------------
13835    -- 4262811 - Generate the Accrual Reversal lines
13836    -------------------------------------------------------------------------------------------
13837    BEGIN
13838       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
13839                               (g_array_event(p_event_id).array_value_num('header_index'));
13840       IF l_acc_rev_flag IS NULL THEN
13841          l_acc_rev_flag := 'N';
13842       END IF;
13843    EXCEPTION
13844       WHEN OTHERS THEN
13845          l_acc_rev_flag := 'N';
13846    END;
13847    --
13848    IF (l_acc_rev_flag = 'Y') THEN
13849 
13850        -- 4645092  ------------------------------------------------------------------------------
13851        -- To allow MPA report to determine if it should generate report process
13852        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
13853        ------------------------------------------------------------------------------------------
13854 
13855        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
13856        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
13860    --
13857    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
13858    -- call ADRs
13859    -- Bug 4922099
13861    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
13862         (NVL(l_actual_upg_option, 'N') = 'O') OR
13863         (NVL(l_enc_upg_option, 'N') = 'O')
13864       )
13865    THEN
13866    NULL;
13867    --
13868    --
13869    
13870   l_ccid := AcctDerRule_16(
13871            p_application_id           => p_application_id
13872          , p_ae_header_id             => l_ae_header_id 
13873 , p_source_4 => p_source_4
13874          , x_transaction_coa_id       => l_adr_transaction_coa_id
13875          , x_accounting_coa_id        => l_adr_accounting_coa_id
13876          , x_value_type_code          => l_adr_value_type_code
13877          , p_side                     => 'NA'
13878    );
13879 
13880    xla_ae_lines_pkg.set_ccid(
13881     p_code_combination_id          => l_ccid
13882   , p_value_type_code              => l_adr_value_type_code
13883   , p_transaction_coa_id           => l_adr_transaction_coa_id
13884   , p_accounting_coa_id            => l_adr_accounting_coa_id
13885   , p_adr_code                     => 'TRX_DIST_CCID'
13886   , p_adr_type_code                => 'S'
13887   , p_component_type               => l_component_type
13888   , p_component_code               => l_component_code
13889   , p_component_type_code          => l_component_type_code
13890   , p_component_appl_id            => l_component_appl_id
13891   , p_amb_context_code             => l_amb_context_code
13892   , p_side                         => 'NA'
13893   );
13894 
13895 
13896    --
13897    --
13898    END IF;
13899 
13900        --
13901        -- Update the line information that should be overwritten
13902        --
13903        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
13904                                          p_header_num   => 1);
13905        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
13906 
13907        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
13908 
13909        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
13910           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
13911        END IF;
13912 
13913       --
13914       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
13915       --
13916       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
13917           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
13918       ELSE
13919           ---------------------------------------------------------------------------------------------------
13920           -- 4262811a Switch Sign
13921           ---------------------------------------------------------------------------------------------------
13922           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
13923           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
13924                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
13925           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
13926                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
13927           -- 5132302
13928           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
13929                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
13930 
13931       END IF;
13932 
13933       -- 4955764
13934       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
13935       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
13936 
13937 
13938       XLA_AE_LINES_PKG.ValidateCurrentLine;
13939       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
13940 
13941       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
13942                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
13943                ,p_balance_type_code => l_balance_type_code);
13944 
13945    END IF;
13946 
13947    -----------------------------------------------------------------------------------------
13948    -- 4262811 Multiperiod Accounting
13949    -----------------------------------------------------------------------------------------
13950      -- No MPA option is assigned.
13951 
13952 
13953 END IF;
13954 END IF;
13955 --
13956 
13957 --
13958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13959    trace
13960       (p_msg      => 'END of AcctLineType_37'
13961       ,p_level    => C_LEVEL_PROCEDURE
13962       ,p_module   => l_log_module);
13963 END IF;
13964 --
13965 EXCEPTION
13966   WHEN xla_exceptions_pkg.application_exception THEN
13967       RAISE;
13968   WHEN OTHERS THEN
13969        xla_exceptions_pkg.raise_message
13970            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_37');
13971 END AcctLineType_37;
13972 --
13973 
13974 ---------------------------------------
13975 --
13976 -- PRIVATE FUNCTION
13980 PROCEDURE AcctLineType_38 (
13977 --         AcctLineType_38
13978 --
13979 ---------------------------------------
13981   p_application_id        IN NUMBER
13982  ,p_event_id              IN NUMBER
13983  ,p_calculate_acctd_flag  IN VARCHAR2
13984  ,p_calculate_g_l_flag    IN VARCHAR2
13985  ,p_actual_flag           IN OUT VARCHAR2
13986  ,p_balance_type_code     OUT VARCHAR2
13987  ,p_gain_or_loss_ref      OUT VARCHAR2
13988  
13989 --Transaction Distribution GL Account
13990  , p_source_4            IN NUMBER
13991 --Bill To Customer Account Identifier
13992  , p_source_23            IN NUMBER
13993 --Bill To Customer Site Use Identifier
13994  , p_source_24            IN NUMBER
13995 --SLA Party Type
13996  , p_source_25            IN VARCHAR2
13997 --Transaction Distribution Account Class
13998  , p_source_26            IN VARCHAR2
13999 --Transaction Distribution Identifier
14000  , p_source_27            IN NUMBER
14001 --Transaction Distribution Type
14002  , p_source_28            IN VARCHAR2
14003 --Transaction Distribution Entered Amount
14004  , p_source_29            IN NUMBER
14005 --Transaction Currency Code
14006  , p_source_30            IN VARCHAR2
14007 --Transaction Exchange Date
14008  , p_source_31            IN DATE
14009 --Transaction Exchange Rate
14010  , p_source_32            IN NUMBER
14011 --Transaction Exchange Rate Type
14012  , p_source_33            IN VARCHAR2
14013 --Transaction Accounting Amount
14014  , p_source_34            IN NUMBER
14015 --Transaction Tax Line Identifier
14016  , p_source_48            IN NUMBER
14017 )
14018 IS
14019 
14020 l_component_type              VARCHAR2(80);
14021 l_component_code              VARCHAR2(30);
14022 l_component_type_code         VARCHAR2(1);
14023 l_component_appl_id           INTEGER;
14024 l_amb_context_code            VARCHAR2(30);
14025 l_entity_code                 VARCHAR2(30);
14026 l_event_class_code            VARCHAR2(30);
14027 l_ae_header_id                NUMBER;
14028 l_event_type_code             VARCHAR2(30);
14029 l_line_definition_code        VARCHAR2(30);
14030 l_line_definition_owner_code  VARCHAR2(1);
14031 --
14032 -- adr variables
14033 l_segment                     VARCHAR2(30);
14034 l_ccid                        NUMBER;
14035 l_adr_transaction_coa_id      NUMBER;
14036 l_adr_accounting_coa_id       NUMBER;
14037 l_adr_flexfield_segment_code  VARCHAR2(30);
14038 l_adr_flex_value_set_id       NUMBER;
14039 l_adr_value_type_code         VARCHAR2(30);
14040 l_adr_value_combination_id    NUMBER;
14041 l_adr_value_segment_code      VARCHAR2(30);
14042 
14043 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
14044 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
14045 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
14046 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
14047 
14048 -- 4262811 Variables ------------------------------------------------------------------------------------------
14049 l_entered_amt_idx             NUMBER;
14050 l_accted_amt_idx              NUMBER;
14051 l_acc_rev_flag                VARCHAR2(1);
14052 l_accrual_line_num            NUMBER;
14053 l_tmp_amt                     NUMBER;
14054 l_acc_rev_natural_side_code   VARCHAR2(1);
14055 
14056 l_num_entries                 NUMBER;
14057 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
14058 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
14059 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
14060 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
14061 l_recog_line_1                NUMBER;
14062 l_recog_line_2                NUMBER;
14063 
14064 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
14065 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
14066 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
14067 
14068 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
14069 
14070 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
14071 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
14072 
14073 ---------------------------------------------------------------------------------------------------------------
14074 
14075 
14076 --
14077 -- bulk performance
14078 --
14079 l_balance_type_code           VARCHAR2(1);
14080 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
14081 l_log_module                  VARCHAR2(240);
14082 
14083 --
14084 -- Upgrade strategy
14085 --
14086 l_actual_upg_option           VARCHAR2(1);
14087 l_enc_upg_option           VARCHAR2(1);
14088 
14089 --
14090 BEGIN
14091 --
14092 IF g_log_enabled THEN
14093       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_38';
14094 END IF;
14095 --
14096 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14097 
14098       trace
14099          (p_msg      => 'BEGIN of AcctLineType_38'
14100          ,p_level    => C_LEVEL_PROCEDURE
14104 --
14101          ,p_module   => l_log_module);
14102 
14103 END IF;
14105 l_component_type             := 'AMB_JLT';
14106 l_component_code             := 'DM_REV';
14107 l_component_type_code        := 'S';
14108 l_component_appl_id          :=  222;
14109 l_amb_context_code           := 'DEFAULT';
14110 l_entity_code                := 'TRANSACTIONS';
14111 l_event_class_code           := 'DEBIT_MEMO';
14112 l_event_type_code            := 'DEBIT_MEMO_ALL';
14113 l_line_definition_owner_code := 'S';
14114 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
14115 --
14116 l_balance_type_code          := 'A';
14117 l_segment                     := NULL;
14118 l_ccid                        := NULL;
14119 l_adr_transaction_coa_id      := NULL;
14120 l_adr_accounting_coa_id       := NULL;
14121 l_adr_flexfield_segment_code  := NULL;
14122 l_adr_flex_value_set_id       := NULL;
14123 l_adr_value_type_code         := NULL;
14124 l_adr_value_combination_id    := NULL;
14125 l_adr_value_segment_code      := NULL;
14126 
14127 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
14128 l_bflow_class_code           := '';    -- 4219869 Business Flow
14129 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
14130 l_budgetary_control_flag     := 'N';
14131 
14132 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
14133 l_bflow_applied_to_amt       := NULL; -- 5132302
14134 l_entered_amt_idx            := NULL;          -- 4262811
14135 l_accted_amt_idx             := NULL;          -- 4262811
14136 l_acc_rev_flag               := NULL;          -- 4262811
14137 l_accrual_line_num           := NULL;          -- 4262811
14138 l_tmp_amt                    := NULL;          -- 4262811
14139 --
14140  
14141 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
14142     l_balance_type_code <> 'B' THEN
14143 IF NVL(p_source_26,'
14144 ') =  'REV'
14145  THEN 
14146 
14147    --
14148    XLA_AE_LINES_PKG.SetNewLine;
14149 
14150    p_balance_type_code          := l_balance_type_code;
14151    -- set the flag so later we will know whether the gain loss line needs to be created
14152    
14153    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
14154      p_actual_flag :='A';
14155    END IF;
14156 
14157    --
14158    -- bulk performance
14159    --
14160    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
14161                                       p_header_num   => 0); -- 4262811
14162    --
14163    -- set accounting line options
14164    --
14165    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
14166            p_natural_side_code          => 'C'
14167          , p_gain_or_loss_flag          => 'N'
14168          , p_gl_transfer_mode_code      => 'S'
14169          , p_acct_entry_type_code       => 'A'
14170          , p_switch_side_flag           => 'Y'
14171          , p_merge_duplicate_code       => 'A'
14172          );
14173    --
14174    l_acc_rev_natural_side_code := 'D';  -- 4262811
14175    -- 
14176    --
14177    -- set accounting line type info
14178    --
14179    xla_ae_lines_pkg.SetAcctLineType
14180       (p_component_type             => l_component_type
14181       ,p_event_type_code            => l_event_type_code
14182       ,p_line_definition_owner_code => l_line_definition_owner_code
14183       ,p_line_definition_code       => l_line_definition_code
14184       ,p_accounting_line_code       => l_component_code
14185       ,p_accounting_line_type_code  => l_component_type_code
14186       ,p_accounting_line_appl_id    => l_component_appl_id
14187       ,p_amb_context_code           => l_amb_context_code
14188       ,p_entity_code                => l_entity_code
14189       ,p_event_class_code           => l_event_class_code);
14190    --
14191    -- set accounting class
14192    --
14193    xla_ae_lines_pkg.SetAcctClass(
14194            p_accounting_class_code  => 'REVENUE'
14195          , p_ae_header_id           => l_ae_header_id
14196          );
14197 
14198    --
14199    -- set rounding class
14200    --
14201    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
14202                       'RECEIVABLE';
14203 
14204    --
14205    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
14206    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
14207    --
14208    -- bulk performance
14209    --
14210    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
14211 
14212    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
14213       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
14214 
14215    -- 4955764
14216    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
14217       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
14218 
14219    -- 4458381 Public Sector Enh
14220    
14221    --
14222    -- set accounting attributes for the line type
14223    --
14224    l_entered_amt_idx := 3;
14225    l_accted_amt_idx  := 8;
14226    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
14227    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
14228    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
14229    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
14230    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
14231    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
14232    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
14236    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
14233    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
14234    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
14235    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
14237    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
14238    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
14239    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
14240    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
14241    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
14242    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
14243    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
14244    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
14245    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
14246    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
14247    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
14248    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
14249    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
14250    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
14251 
14252    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
14253    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
14254 
14255    ---------------------------------------------------------------------------------------------------------------
14256    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
14257    ---------------------------------------------------------------------------------------------------------------
14258    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
14259 
14260    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
14261    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
14262 
14263    IF xla_accounting_cache_pkg.GetValueChar
14264          (p_source_code         => 'LEDGER_CATEGORY_CODE'
14265          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
14266    AND l_bflow_method_code = 'PRIOR_ENTRY'
14267 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
14268    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
14269          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
14270        )
14271    THEN
14272          xla_ae_lines_pkg.BflowUpgEntry
14273            (p_business_method_code    => l_bflow_method_code
14274            ,p_business_class_code     => l_bflow_class_code
14275            ,p_balance_type            => l_balance_type_code);
14276    ELSE
14277       NULL;
14278 -- No business flow processing for business flow method of NONE.
14279    END IF;
14280 
14281    --
14282    -- call analytical criteria
14283    --
14284    
14285    --
14286    -- call description
14287    --
14288    -- No description or it is inherited.
14289    --
14290    -- call ADRs
14291    -- Bug 4922099
14292    --
14293    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
14294         (NVL(l_actual_upg_option, 'N') = 'O') OR
14295         (NVL(l_enc_upg_option, 'N') = 'O')
14296       )
14297    THEN
14298    NULL;
14299    --
14300    --
14301    
14302   l_ccid := AcctDerRule_16(
14303            p_application_id           => p_application_id
14304          , p_ae_header_id             => l_ae_header_id 
14305 , p_source_4 => p_source_4
14306          , x_transaction_coa_id       => l_adr_transaction_coa_id
14307          , x_accounting_coa_id        => l_adr_accounting_coa_id
14308          , x_value_type_code          => l_adr_value_type_code
14309          , p_side                     => 'NA'
14310    );
14311 
14312    xla_ae_lines_pkg.set_ccid(
14313     p_code_combination_id          => l_ccid
14314   , p_value_type_code              => l_adr_value_type_code
14315   , p_transaction_coa_id           => l_adr_transaction_coa_id
14316   , p_accounting_coa_id            => l_adr_accounting_coa_id
14317   , p_adr_code                     => 'TRX_DIST_CCID'
14318   , p_adr_type_code                => 'S'
14319   , p_component_type               => l_component_type
14320   , p_component_code               => l_component_code
14321   , p_component_type_code          => l_component_type_code
14322   , p_component_appl_id            => l_component_appl_id
14323   , p_amb_context_code             => l_amb_context_code
14324   , p_side                         => 'NA'
14325   );
14326 
14327 
14328    --
14329    --
14330    END IF;
14331    --
14332    -- Bug 4922099
14333    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
14334           (NVL(l_enc_upg_option, 'N') = 'O')
14335         ) AND
14336         (l_bflow_method_code = 'PRIOR_ENTRY')
14337       )
14338    THEN
14339       IF
14340       --
14341       1 = 2
14342       --
14343       THEN
14344       xla_accounting_err_pkg.build_message
14345                                     (p_appli_s_name            => 'XLA'
14346                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
14347                                     ,p_token_1                 => 'LINE_NUMBER'
14348                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
14349                                     ,p_token_2                 => 'LINE_TYPE_NAME'
14353                                                                             ,l_component_type_code
14350                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
14351                                                                              l_component_type
14352                                                                             ,l_component_code
14354                                                                             ,l_component_appl_id
14355                                                                             ,l_amb_context_code
14356                                                                             ,l_entity_code
14357                                                                             ,l_event_class_code
14358                                                                            )
14359                                     ,p_token_3                 => 'OWNER'
14360                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
14361                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
14362                                                                           ,p_lookup_code    => l_component_type_code
14363                                                                          )
14364                                     ,p_token_4                 => 'PRODUCT_NAME'
14365                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
14366                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
14367                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
14368                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
14369                                     ,p_ae_header_id            =>  NULL
14370                                        );
14371 
14372         IF (C_LEVEL_ERROR>= g_log_level) THEN
14373                  trace
14374                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
14375                       ,p_level    => C_LEVEL_ERROR
14376                       ,p_module   => l_log_module);
14377         END IF;
14378       END IF;
14379    END IF;
14380    --
14381    --
14382    ------------------------------------------------------------------------------------------------
14383    -- 4219869 Business Flow
14384    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
14385    -- Prior Entry.  Currently, the following code is always generated.
14386    ------------------------------------------------------------------------------------------------
14387    XLA_AE_LINES_PKG.ValidateCurrentLine;
14388 
14389    ------------------------------------------------------------------------------------
14390    -- 4219869 Business Flow
14391    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
14392    ------------------------------------------------------------------------------------
14393    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
14394 
14395    ----------------------------------------------------------------------------------
14396    -- 4219869 Business Flow
14397    -- Update journal entry status -- Need to generate this within IF <condition>
14398    ----------------------------------------------------------------------------------
14399    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
14400          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
14401          ,p_balance_type_code => l_balance_type_code
14402          );
14403 
14404    -------------------------------------------------------------------------------------------
14405    -- 4262811 - Generate the Accrual Reversal lines
14406    -------------------------------------------------------------------------------------------
14407    BEGIN
14408       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
14409                               (g_array_event(p_event_id).array_value_num('header_index'));
14410       IF l_acc_rev_flag IS NULL THEN
14411          l_acc_rev_flag := 'N';
14412       END IF;
14413    EXCEPTION
14414       WHEN OTHERS THEN
14415          l_acc_rev_flag := 'N';
14416    END;
14417    --
14418    IF (l_acc_rev_flag = 'Y') THEN
14419 
14420        -- 4645092  ------------------------------------------------------------------------------
14421        -- To allow MPA report to determine if it should generate report process
14422        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
14423        ------------------------------------------------------------------------------------------
14424 
14425        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
14426        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
14427    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
14428    -- call ADRs
14429    -- Bug 4922099
14430    --
14431    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
14432         (NVL(l_actual_upg_option, 'N') = 'O') OR
14433         (NVL(l_enc_upg_option, 'N') = 'O')
14434       )
14435    THEN
14436    NULL;
14437    --
14438    --
14439    
14440   l_ccid := AcctDerRule_16(
14441            p_application_id           => p_application_id
14442          , p_ae_header_id             => l_ae_header_id 
14443 , p_source_4 => p_source_4
14444          , x_transaction_coa_id       => l_adr_transaction_coa_id
14445          , x_accounting_coa_id        => l_adr_accounting_coa_id
14446          , x_value_type_code          => l_adr_value_type_code
14450    xla_ae_lines_pkg.set_ccid(
14447          , p_side                     => 'NA'
14448    );
14449 
14451     p_code_combination_id          => l_ccid
14452   , p_value_type_code              => l_adr_value_type_code
14453   , p_transaction_coa_id           => l_adr_transaction_coa_id
14454   , p_accounting_coa_id            => l_adr_accounting_coa_id
14455   , p_adr_code                     => 'TRX_DIST_CCID'
14456   , p_adr_type_code                => 'S'
14457   , p_component_type               => l_component_type
14458   , p_component_code               => l_component_code
14459   , p_component_type_code          => l_component_type_code
14460   , p_component_appl_id            => l_component_appl_id
14461   , p_amb_context_code             => l_amb_context_code
14462   , p_side                         => 'NA'
14463   );
14464 
14465 
14466    --
14467    --
14468    END IF;
14469 
14470        --
14471        -- Update the line information that should be overwritten
14472        --
14473        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
14474                                          p_header_num   => 1);
14475        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
14476 
14477        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
14478 
14479        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
14480           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
14481        END IF;
14482 
14483       --
14484       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
14485       --
14486       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
14487           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
14488       ELSE
14489           ---------------------------------------------------------------------------------------------------
14490           -- 4262811a Switch Sign
14491           ---------------------------------------------------------------------------------------------------
14492           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
14493           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
14494                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
14495           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
14496                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
14497           -- 5132302
14498           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
14499                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
14500 
14501       END IF;
14502 
14503       -- 4955764
14504       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
14505       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
14506 
14507 
14508       XLA_AE_LINES_PKG.ValidateCurrentLine;
14509       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
14510 
14511       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
14512                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
14513                ,p_balance_type_code => l_balance_type_code);
14514 
14515    END IF;
14516 
14517    -----------------------------------------------------------------------------------------
14518    -- 4262811 Multiperiod Accounting
14519    -----------------------------------------------------------------------------------------
14520      -- No MPA option is assigned.
14521 
14522 
14523 END IF;
14524 END IF;
14525 --
14526 
14527 --
14528 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14529    trace
14530       (p_msg      => 'END of AcctLineType_38'
14531       ,p_level    => C_LEVEL_PROCEDURE
14532       ,p_module   => l_log_module);
14533 END IF;
14534 --
14535 EXCEPTION
14536   WHEN xla_exceptions_pkg.application_exception THEN
14537       RAISE;
14538   WHEN OTHERS THEN
14539        xla_exceptions_pkg.raise_message
14540            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_38');
14541 END AcctLineType_38;
14542 --
14543 
14544 ---------------------------------------
14545 --
14546 -- PRIVATE FUNCTION
14547 --         AcctLineType_39
14548 --
14549 ---------------------------------------
14550 PROCEDURE AcctLineType_39 (
14551   p_application_id        IN NUMBER
14552  ,p_event_id              IN NUMBER
14553  ,p_calculate_acctd_flag  IN VARCHAR2
14554  ,p_calculate_g_l_flag    IN VARCHAR2
14555  ,p_actual_flag           IN OUT VARCHAR2
14556  ,p_balance_type_code     OUT VARCHAR2
14557  ,p_gain_or_loss_ref      OUT VARCHAR2
14558  
14559 --Transaction Distribution GL Account
14560  , p_source_4            IN NUMBER
14561 --Bill To Customer Account Identifier
14562  , p_source_23            IN NUMBER
14563 --Bill To Customer Site Use Identifier
14564  , p_source_24            IN NUMBER
14565 --SLA Party Type
14566  , p_source_25            IN VARCHAR2
14567 --Transaction Distribution Account Class
14568  , p_source_26            IN VARCHAR2
14569 --Transaction Distribution Identifier
14570  , p_source_27            IN NUMBER
14571 --Transaction Distribution Type
14572  , p_source_28            IN VARCHAR2
14573 --Transaction Distribution Entered Amount
14574  , p_source_29            IN NUMBER
14578  , p_source_31            IN DATE
14575 --Transaction Currency Code
14576  , p_source_30            IN VARCHAR2
14577 --Transaction Exchange Date
14579 --Transaction Exchange Rate
14580  , p_source_32            IN NUMBER
14581 --Transaction Exchange Rate Type
14582  , p_source_33            IN VARCHAR2
14583 --Transaction Accounting Amount
14584  , p_source_34            IN NUMBER
14585 --Transaction Tax Line Identifier
14586  , p_source_48            IN NUMBER
14587 )
14588 IS
14589 
14590 l_component_type              VARCHAR2(80);
14591 l_component_code              VARCHAR2(30);
14592 l_component_type_code         VARCHAR2(1);
14593 l_component_appl_id           INTEGER;
14594 l_amb_context_code            VARCHAR2(30);
14595 l_entity_code                 VARCHAR2(30);
14596 l_event_class_code            VARCHAR2(30);
14597 l_ae_header_id                NUMBER;
14598 l_event_type_code             VARCHAR2(30);
14599 l_line_definition_code        VARCHAR2(30);
14600 l_line_definition_owner_code  VARCHAR2(1);
14601 --
14602 -- adr variables
14603 l_segment                     VARCHAR2(30);
14604 l_ccid                        NUMBER;
14605 l_adr_transaction_coa_id      NUMBER;
14606 l_adr_accounting_coa_id       NUMBER;
14607 l_adr_flexfield_segment_code  VARCHAR2(30);
14608 l_adr_flex_value_set_id       NUMBER;
14609 l_adr_value_type_code         VARCHAR2(30);
14610 l_adr_value_combination_id    NUMBER;
14611 l_adr_value_segment_code      VARCHAR2(30);
14612 
14613 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
14614 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
14615 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
14616 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
14617 
14618 -- 4262811 Variables ------------------------------------------------------------------------------------------
14619 l_entered_amt_idx             NUMBER;
14620 l_accted_amt_idx              NUMBER;
14621 l_acc_rev_flag                VARCHAR2(1);
14622 l_accrual_line_num            NUMBER;
14623 l_tmp_amt                     NUMBER;
14624 l_acc_rev_natural_side_code   VARCHAR2(1);
14625 
14626 l_num_entries                 NUMBER;
14627 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
14628 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
14629 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
14630 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
14631 l_recog_line_1                NUMBER;
14632 l_recog_line_2                NUMBER;
14633 
14634 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
14635 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
14636 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
14637 
14638 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
14639 
14640 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
14641 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
14642 
14643 ---------------------------------------------------------------------------------------------------------------
14644 
14645 
14646 --
14647 -- bulk performance
14648 --
14649 l_balance_type_code           VARCHAR2(1);
14650 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
14651 l_log_module                  VARCHAR2(240);
14652 
14653 --
14654 -- Upgrade strategy
14655 --
14656 l_actual_upg_option           VARCHAR2(1);
14657 l_enc_upg_option           VARCHAR2(1);
14658 
14659 --
14660 BEGIN
14661 --
14662 IF g_log_enabled THEN
14663       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_39';
14664 END IF;
14665 --
14666 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14667 
14668       trace
14669          (p_msg      => 'BEGIN of AcctLineType_39'
14670          ,p_level    => C_LEVEL_PROCEDURE
14671          ,p_module   => l_log_module);
14672 
14673 END IF;
14674 --
14675 l_component_type             := 'AMB_JLT';
14676 l_component_code             := 'DM_ROUND';
14677 l_component_type_code        := 'S';
14678 l_component_appl_id          :=  222;
14679 l_amb_context_code           := 'DEFAULT';
14680 l_entity_code                := 'TRANSACTIONS';
14681 l_event_class_code           := 'DEBIT_MEMO';
14682 l_event_type_code            := 'DEBIT_MEMO_ALL';
14683 l_line_definition_owner_code := 'S';
14684 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
14685 --
14686 l_balance_type_code          := 'A';
14687 l_segment                     := NULL;
14688 l_ccid                        := NULL;
14689 l_adr_transaction_coa_id      := NULL;
14690 l_adr_accounting_coa_id       := NULL;
14691 l_adr_flexfield_segment_code  := NULL;
14692 l_adr_flex_value_set_id       := NULL;
14693 l_adr_value_type_code         := NULL;
14694 l_adr_value_combination_id    := NULL;
14695 l_adr_value_segment_code      := NULL;
14696 
14697 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
14698 l_bflow_class_code           := '';    -- 4219869 Business Flow
14699 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
14700 l_budgetary_control_flag     := 'N';
14701 
14702 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
14703 l_bflow_applied_to_amt       := NULL; -- 5132302
14704 l_entered_amt_idx            := NULL;          -- 4262811
14705 l_accted_amt_idx             := NULL;          -- 4262811
14706 l_acc_rev_flag               := NULL;          -- 4262811
14707 l_accrual_line_num           := NULL;          -- 4262811
14708 l_tmp_amt                    := NULL;          -- 4262811
14709 --
14710  
14711 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
14712     l_balance_type_code <> 'B' THEN
14713 IF NVL(p_source_26,'
14714 ') =  'ROUND'
14715  THEN 
14716 
14717    --
14718    XLA_AE_LINES_PKG.SetNewLine;
14719 
14720    p_balance_type_code          := l_balance_type_code;
14721    -- set the flag so later we will know whether the gain loss line needs to be created
14722    
14723    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
14724      p_actual_flag :='A';
14725    END IF;
14726 
14727    --
14728    -- bulk performance
14729    --
14730    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
14731                                       p_header_num   => 0); -- 4262811
14732    --
14733    -- set accounting line options
14734    --
14735    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
14736            p_natural_side_code          => 'C'
14737          , p_gain_or_loss_flag          => 'N'
14738          , p_gl_transfer_mode_code      => 'S'
14739          , p_acct_entry_type_code       => 'A'
14740          , p_switch_side_flag           => 'Y'
14741          , p_merge_duplicate_code       => 'A'
14742          );
14743    --
14744    l_acc_rev_natural_side_code := 'D';  -- 4262811
14745    -- 
14746    --
14747    -- set accounting line type info
14748    --
14749    xla_ae_lines_pkg.SetAcctLineType
14750       (p_component_type             => l_component_type
14751       ,p_event_type_code            => l_event_type_code
14752       ,p_line_definition_owner_code => l_line_definition_owner_code
14753       ,p_line_definition_code       => l_line_definition_code
14754       ,p_accounting_line_code       => l_component_code
14755       ,p_accounting_line_type_code  => l_component_type_code
14756       ,p_accounting_line_appl_id    => l_component_appl_id
14757       ,p_amb_context_code           => l_amb_context_code
14758       ,p_entity_code                => l_entity_code
14759       ,p_event_class_code           => l_event_class_code);
14760    --
14761    -- set accounting class
14762    --
14763    xla_ae_lines_pkg.SetAcctClass(
14764            p_accounting_class_code  => 'ROUNDING'
14765          , p_ae_header_id           => l_ae_header_id
14766          );
14767 
14768    --
14769    -- set rounding class
14770    --
14771    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
14772                       'RECEIVABLE';
14773 
14774    --
14775    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
14776    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
14777    --
14778    -- bulk performance
14779    --
14780    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
14781 
14782    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
14783       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
14784 
14785    -- 4955764
14786    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
14787       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
14788 
14789    -- 4458381 Public Sector Enh
14790    
14791    --
14792    -- set accounting attributes for the line type
14793    --
14794    l_entered_amt_idx := 3;
14795    l_accted_amt_idx  := 8;
14796    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
14797    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
14798    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
14799    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
14800    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
14801    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
14802    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
14803    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
14804    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
14805    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
14806    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
14807    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
14808    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
14809    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
14810    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
14811    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
14812    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
14813    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
14814    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
14815    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
14816    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
14817    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
14818    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
14819    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
14820    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
14821 
14822    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
14823    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
14824 
14825    ---------------------------------------------------------------------------------------------------------------
14826    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
14827    ---------------------------------------------------------------------------------------------------------------
14828    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
14829 
14830    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
14831    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
14832 
14833    IF xla_accounting_cache_pkg.GetValueChar
14834          (p_source_code         => 'LEDGER_CATEGORY_CODE'
14835          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
14836    AND l_bflow_method_code = 'PRIOR_ENTRY'
14837 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
14838    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
14839          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
14840        )
14841    THEN
14842          xla_ae_lines_pkg.BflowUpgEntry
14843            (p_business_method_code    => l_bflow_method_code
14844            ,p_business_class_code     => l_bflow_class_code
14845            ,p_balance_type            => l_balance_type_code);
14846    ELSE
14847       NULL;
14848 -- No business flow processing for business flow method of NONE.
14849    END IF;
14850 
14851    --
14852    -- call analytical criteria
14853    --
14854    
14855    --
14856    -- call description
14857    --
14858    -- No description or it is inherited.
14859    --
14860    -- call ADRs
14861    -- Bug 4922099
14862    --
14863    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
14864         (NVL(l_actual_upg_option, 'N') = 'O') OR
14865         (NVL(l_enc_upg_option, 'N') = 'O')
14866       )
14867    THEN
14868    NULL;
14869    --
14870    --
14871    
14872   l_ccid := AcctDerRule_16(
14873            p_application_id           => p_application_id
14874          , p_ae_header_id             => l_ae_header_id 
14875 , p_source_4 => p_source_4
14876          , x_transaction_coa_id       => l_adr_transaction_coa_id
14877          , x_accounting_coa_id        => l_adr_accounting_coa_id
14878          , x_value_type_code          => l_adr_value_type_code
14879          , p_side                     => 'NA'
14880    );
14881 
14882    xla_ae_lines_pkg.set_ccid(
14883     p_code_combination_id          => l_ccid
14884   , p_value_type_code              => l_adr_value_type_code
14885   , p_transaction_coa_id           => l_adr_transaction_coa_id
14886   , p_accounting_coa_id            => l_adr_accounting_coa_id
14887   , p_adr_code                     => 'TRX_DIST_CCID'
14888   , p_adr_type_code                => 'S'
14889   , p_component_type               => l_component_type
14890   , p_component_code               => l_component_code
14891   , p_component_type_code          => l_component_type_code
14892   , p_component_appl_id            => l_component_appl_id
14893   , p_amb_context_code             => l_amb_context_code
14897 
14894   , p_side                         => 'NA'
14895   );
14896 
14898    --
14899    --
14900    END IF;
14901    --
14902    -- Bug 4922099
14903    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
14904           (NVL(l_enc_upg_option, 'N') = 'O')
14905         ) AND
14906         (l_bflow_method_code = 'PRIOR_ENTRY')
14907       )
14908    THEN
14909       IF
14910       --
14911       1 = 2
14912       --
14913       THEN
14914       xla_accounting_err_pkg.build_message
14915                                     (p_appli_s_name            => 'XLA'
14916                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
14917                                     ,p_token_1                 => 'LINE_NUMBER'
14918                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
14919                                     ,p_token_2                 => 'LINE_TYPE_NAME'
14920                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
14921                                                                              l_component_type
14922                                                                             ,l_component_code
14923                                                                             ,l_component_type_code
14924                                                                             ,l_component_appl_id
14925                                                                             ,l_amb_context_code
14926                                                                             ,l_entity_code
14927                                                                             ,l_event_class_code
14928                                                                            )
14929                                     ,p_token_3                 => 'OWNER'
14930                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
14931                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
14932                                                                           ,p_lookup_code    => l_component_type_code
14933                                                                          )
14934                                     ,p_token_4                 => 'PRODUCT_NAME'
14935                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
14936                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
14937                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
14938                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
14939                                     ,p_ae_header_id            =>  NULL
14940                                        );
14941 
14942         IF (C_LEVEL_ERROR>= g_log_level) THEN
14943                  trace
14944                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
14945                       ,p_level    => C_LEVEL_ERROR
14946                       ,p_module   => l_log_module);
14947         END IF;
14948       END IF;
14949    END IF;
14950    --
14951    --
14952    ------------------------------------------------------------------------------------------------
14953    -- 4219869 Business Flow
14954    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
14955    -- Prior Entry.  Currently, the following code is always generated.
14956    ------------------------------------------------------------------------------------------------
14957    XLA_AE_LINES_PKG.ValidateCurrentLine;
14958 
14959    ------------------------------------------------------------------------------------
14960    -- 4219869 Business Flow
14961    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
14962    ------------------------------------------------------------------------------------
14963    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
14964 
14965    ----------------------------------------------------------------------------------
14966    -- 4219869 Business Flow
14967    -- Update journal entry status -- Need to generate this within IF <condition>
14968    ----------------------------------------------------------------------------------
14969    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
14970          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
14971          ,p_balance_type_code => l_balance_type_code
14972          );
14973 
14974    -------------------------------------------------------------------------------------------
14975    -- 4262811 - Generate the Accrual Reversal lines
14976    -------------------------------------------------------------------------------------------
14977    BEGIN
14978       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
14979                               (g_array_event(p_event_id).array_value_num('header_index'));
14980       IF l_acc_rev_flag IS NULL THEN
14981          l_acc_rev_flag := 'N';
14982       END IF;
14983    EXCEPTION
14984       WHEN OTHERS THEN
14985          l_acc_rev_flag := 'N';
14986    END;
14987    --
14988    IF (l_acc_rev_flag = 'Y') THEN
14989 
14990        -- 4645092  ------------------------------------------------------------------------------
14991        -- To allow MPA report to determine if it should generate report process
14992        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
14993        ------------------------------------------------------------------------------------------
14994 
14995        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
14999    -- Bug 4922099
14996        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
14997    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
14998    -- call ADRs
15000    --
15001    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
15002         (NVL(l_actual_upg_option, 'N') = 'O') OR
15003         (NVL(l_enc_upg_option, 'N') = 'O')
15004       )
15005    THEN
15006    NULL;
15007    --
15008    --
15009    
15010   l_ccid := AcctDerRule_16(
15011            p_application_id           => p_application_id
15012          , p_ae_header_id             => l_ae_header_id 
15013 , p_source_4 => p_source_4
15014          , x_transaction_coa_id       => l_adr_transaction_coa_id
15015          , x_accounting_coa_id        => l_adr_accounting_coa_id
15016          , x_value_type_code          => l_adr_value_type_code
15017          , p_side                     => 'NA'
15018    );
15019 
15020    xla_ae_lines_pkg.set_ccid(
15021     p_code_combination_id          => l_ccid
15022   , p_value_type_code              => l_adr_value_type_code
15023   , p_transaction_coa_id           => l_adr_transaction_coa_id
15024   , p_accounting_coa_id            => l_adr_accounting_coa_id
15025   , p_adr_code                     => 'TRX_DIST_CCID'
15026   , p_adr_type_code                => 'S'
15027   , p_component_type               => l_component_type
15028   , p_component_code               => l_component_code
15029   , p_component_type_code          => l_component_type_code
15030   , p_component_appl_id            => l_component_appl_id
15031   , p_amb_context_code             => l_amb_context_code
15032   , p_side                         => 'NA'
15033   );
15034 
15035 
15036    --
15037    --
15038    END IF;
15039 
15040        --
15041        -- Update the line information that should be overwritten
15042        --
15043        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
15044                                          p_header_num   => 1);
15045        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
15046 
15047        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
15048 
15049        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
15050           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
15051        END IF;
15052 
15053       --
15054       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
15055       --
15056       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
15057           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
15058       ELSE
15059           ---------------------------------------------------------------------------------------------------
15060           -- 4262811a Switch Sign
15061           ---------------------------------------------------------------------------------------------------
15062           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
15063           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
15064                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15065           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
15066                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15067           -- 5132302
15068           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
15069                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15070 
15071       END IF;
15072 
15073       -- 4955764
15074       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
15075       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
15076 
15077 
15078       XLA_AE_LINES_PKG.ValidateCurrentLine;
15079       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
15080 
15081       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
15082                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
15083                ,p_balance_type_code => l_balance_type_code);
15084 
15085    END IF;
15086 
15087    -----------------------------------------------------------------------------------------
15088    -- 4262811 Multiperiod Accounting
15089    -----------------------------------------------------------------------------------------
15090      -- No MPA option is assigned.
15091 
15092 
15093 END IF;
15094 END IF;
15095 --
15096 
15097 --
15098 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15099    trace
15100       (p_msg      => 'END of AcctLineType_39'
15101       ,p_level    => C_LEVEL_PROCEDURE
15102       ,p_module   => l_log_module);
15103 END IF;
15104 --
15105 EXCEPTION
15106   WHEN xla_exceptions_pkg.application_exception THEN
15107       RAISE;
15108   WHEN OTHERS THEN
15109        xla_exceptions_pkg.raise_message
15110            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_39');
15111 END AcctLineType_39;
15112 --
15113 
15114 ---------------------------------------
15115 --
15116 -- PRIVATE FUNCTION
15117 --         AcctLineType_40
15118 --
15119 ---------------------------------------
15120 PROCEDURE AcctLineType_40 (
15121   p_application_id        IN NUMBER
15122  ,p_event_id              IN NUMBER
15123  ,p_calculate_acctd_flag  IN VARCHAR2
15124  ,p_calculate_g_l_flag    IN VARCHAR2
15128  
15125  ,p_actual_flag           IN OUT VARCHAR2
15126  ,p_balance_type_code     OUT VARCHAR2
15127  ,p_gain_or_loss_ref      OUT VARCHAR2
15129 --Transaction Distribution GL Account
15130  , p_source_4            IN NUMBER
15131 --Bill To Customer Account Identifier
15132  , p_source_23            IN NUMBER
15133 --Bill To Customer Site Use Identifier
15134  , p_source_24            IN NUMBER
15135 --SLA Party Type
15136  , p_source_25            IN VARCHAR2
15137 --Transaction Distribution Account Class
15138  , p_source_26            IN VARCHAR2
15139 --Transaction Distribution Identifier
15140  , p_source_27            IN NUMBER
15141 --Transaction Distribution Type
15142  , p_source_28            IN VARCHAR2
15143 --Transaction Distribution Entered Amount
15144  , p_source_29            IN NUMBER
15145 --Transaction Currency Code
15146  , p_source_30            IN VARCHAR2
15147 --Transaction Exchange Date
15148  , p_source_31            IN DATE
15149 --Transaction Exchange Rate
15150  , p_source_32            IN NUMBER
15151 --Transaction Exchange Rate Type
15152  , p_source_33            IN VARCHAR2
15153 --Transaction Accounting Amount
15154  , p_source_34            IN NUMBER
15155 --Transaction Tax Line Identifier
15156  , p_source_48            IN NUMBER
15157 )
15158 IS
15159 
15160 l_component_type              VARCHAR2(80);
15161 l_component_code              VARCHAR2(30);
15162 l_component_type_code         VARCHAR2(1);
15163 l_component_appl_id           INTEGER;
15164 l_amb_context_code            VARCHAR2(30);
15165 l_entity_code                 VARCHAR2(30);
15166 l_event_class_code            VARCHAR2(30);
15167 l_ae_header_id                NUMBER;
15168 l_event_type_code             VARCHAR2(30);
15169 l_line_definition_code        VARCHAR2(30);
15170 l_line_definition_owner_code  VARCHAR2(1);
15171 --
15172 -- adr variables
15173 l_segment                     VARCHAR2(30);
15174 l_ccid                        NUMBER;
15175 l_adr_transaction_coa_id      NUMBER;
15176 l_adr_accounting_coa_id       NUMBER;
15177 l_adr_flexfield_segment_code  VARCHAR2(30);
15178 l_adr_flex_value_set_id       NUMBER;
15179 l_adr_value_type_code         VARCHAR2(30);
15180 l_adr_value_combination_id    NUMBER;
15181 l_adr_value_segment_code      VARCHAR2(30);
15182 
15183 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
15184 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
15185 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
15186 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
15187 
15188 -- 4262811 Variables ------------------------------------------------------------------------------------------
15189 l_entered_amt_idx             NUMBER;
15190 l_accted_amt_idx              NUMBER;
15191 l_acc_rev_flag                VARCHAR2(1);
15192 l_accrual_line_num            NUMBER;
15193 l_tmp_amt                     NUMBER;
15194 l_acc_rev_natural_side_code   VARCHAR2(1);
15195 
15196 l_num_entries                 NUMBER;
15197 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
15198 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
15199 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
15200 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
15201 l_recog_line_1                NUMBER;
15202 l_recog_line_2                NUMBER;
15203 
15204 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
15205 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
15206 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
15207 
15208 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
15209 
15210 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
15211 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
15212 
15213 ---------------------------------------------------------------------------------------------------------------
15214 
15215 
15216 --
15217 -- bulk performance
15218 --
15219 l_balance_type_code           VARCHAR2(1);
15220 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
15221 l_log_module                  VARCHAR2(240);
15222 
15223 --
15224 -- Upgrade strategy
15225 --
15226 l_actual_upg_option           VARCHAR2(1);
15227 l_enc_upg_option           VARCHAR2(1);
15228 
15229 --
15230 BEGIN
15231 --
15232 IF g_log_enabled THEN
15233       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_40';
15234 END IF;
15235 --
15236 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15237 
15238       trace
15239          (p_msg      => 'BEGIN of AcctLineType_40'
15240          ,p_level    => C_LEVEL_PROCEDURE
15241          ,p_module   => l_log_module);
15242 
15243 END IF;
15244 --
15245 l_component_type             := 'AMB_JLT';
15246 l_component_code             := 'DM_TAX';
15247 l_component_type_code        := 'S';
15248 l_component_appl_id          :=  222;
15249 l_amb_context_code           := 'DEFAULT';
15250 l_entity_code                := 'TRANSACTIONS';
15251 l_event_class_code           := 'DEBIT_MEMO';
15252 l_event_type_code            := 'DEBIT_MEMO_ALL';
15253 l_line_definition_owner_code := 'S';
15254 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
15255 --
15256 l_balance_type_code          := 'A';
15257 l_segment                     := NULL;
15258 l_ccid                        := NULL;
15259 l_adr_transaction_coa_id      := NULL;
15260 l_adr_accounting_coa_id       := NULL;
15261 l_adr_flexfield_segment_code  := NULL;
15262 l_adr_flex_value_set_id       := NULL;
15263 l_adr_value_type_code         := NULL;
15264 l_adr_value_combination_id    := NULL;
15265 l_adr_value_segment_code      := NULL;
15266 
15267 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
15268 l_bflow_class_code           := '';    -- 4219869 Business Flow
15269 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
15270 l_budgetary_control_flag     := 'N';
15271 
15272 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
15273 l_bflow_applied_to_amt       := NULL; -- 5132302
15274 l_entered_amt_idx            := NULL;          -- 4262811
15275 l_accted_amt_idx             := NULL;          -- 4262811
15276 l_acc_rev_flag               := NULL;          -- 4262811
15277 l_accrual_line_num           := NULL;          -- 4262811
15278 l_tmp_amt                    := NULL;          -- 4262811
15279 --
15280  
15281 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
15282     l_balance_type_code <> 'B' THEN
15283 IF NVL(p_source_26,'
15284 ') =  'TAX'
15285  THEN 
15286 
15287    --
15288    XLA_AE_LINES_PKG.SetNewLine;
15289 
15290    p_balance_type_code          := l_balance_type_code;
15291    -- set the flag so later we will know whether the gain loss line needs to be created
15292    
15293    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
15294      p_actual_flag :='A';
15295    END IF;
15296 
15297    --
15298    -- bulk performance
15299    --
15300    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
15301                                       p_header_num   => 0); -- 4262811
15302    --
15303    -- set accounting line options
15304    --
15305    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
15306            p_natural_side_code          => 'C'
15307          , p_gain_or_loss_flag          => 'N'
15308          , p_gl_transfer_mode_code      => 'S'
15309          , p_acct_entry_type_code       => 'A'
15310          , p_switch_side_flag           => 'Y'
15311          , p_merge_duplicate_code       => 'A'
15312          );
15313    --
15314    l_acc_rev_natural_side_code := 'D';  -- 4262811
15315    -- 
15316    --
15317    -- set accounting line type info
15318    --
15319    xla_ae_lines_pkg.SetAcctLineType
15320       (p_component_type             => l_component_type
15321       ,p_event_type_code            => l_event_type_code
15322       ,p_line_definition_owner_code => l_line_definition_owner_code
15323       ,p_line_definition_code       => l_line_definition_code
15324       ,p_accounting_line_code       => l_component_code
15325       ,p_accounting_line_type_code  => l_component_type_code
15326       ,p_accounting_line_appl_id    => l_component_appl_id
15327       ,p_amb_context_code           => l_amb_context_code
15328       ,p_entity_code                => l_entity_code
15329       ,p_event_class_code           => l_event_class_code);
15330    --
15331    -- set accounting class
15332    --
15333    xla_ae_lines_pkg.SetAcctClass(
15334            p_accounting_class_code  => 'TAX'
15335          , p_ae_header_id           => l_ae_header_id
15336          );
15337 
15338    --
15339    -- set rounding class
15340    --
15341    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
15342                       'RECEIVABLE';
15343 
15344    --
15345    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
15346    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
15347    --
15348    -- bulk performance
15349    --
15350    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
15351 
15352    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
15353       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
15354 
15355    -- 4955764
15356    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
15357       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
15358 
15359    -- 4458381 Public Sector Enh
15360    
15361    --
15362    -- set accounting attributes for the line type
15363    --
15364    l_entered_amt_idx := 3;
15365    l_accted_amt_idx  := 8;
15366    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
15367    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
15368    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
15369    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
15370    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
15371    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
15372    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
15373    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
15374    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
15375    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
15376    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
15377    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
15378    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
15379    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
15380    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
15381    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
15382    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
15383    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
15384    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
15385    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
15386    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
15387    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
15388    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
15389    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
15390    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
15391 
15392    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
15393    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
15394 
15395    ---------------------------------------------------------------------------------------------------------------
15396    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
15397    ---------------------------------------------------------------------------------------------------------------
15398    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
15399 
15400    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
15401    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
15402 
15403    IF xla_accounting_cache_pkg.GetValueChar
15404          (p_source_code         => 'LEDGER_CATEGORY_CODE'
15405          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
15406    AND l_bflow_method_code = 'PRIOR_ENTRY'
15407 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
15408    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
15409          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
15410        )
15411    THEN
15412          xla_ae_lines_pkg.BflowUpgEntry
15413            (p_business_method_code    => l_bflow_method_code
15414            ,p_business_class_code     => l_bflow_class_code
15415            ,p_balance_type            => l_balance_type_code);
15416    ELSE
15417       NULL;
15418 -- No business flow processing for business flow method of NONE.
15419    END IF;
15420 
15421    --
15422    -- call analytical criteria
15423    --
15424    
15425    --
15426    -- call description
15427    --
15428    -- No description or it is inherited.
15429    --
15430    -- call ADRs
15431    -- Bug 4922099
15432    --
15433    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
15434         (NVL(l_actual_upg_option, 'N') = 'O') OR
15435         (NVL(l_enc_upg_option, 'N') = 'O')
15436       )
15437    THEN
15438    NULL;
15439    --
15440    --
15441    
15442   l_ccid := AcctDerRule_16(
15443            p_application_id           => p_application_id
15444          , p_ae_header_id             => l_ae_header_id 
15445 , p_source_4 => p_source_4
15446          , x_transaction_coa_id       => l_adr_transaction_coa_id
15447          , x_accounting_coa_id        => l_adr_accounting_coa_id
15448          , x_value_type_code          => l_adr_value_type_code
15449          , p_side                     => 'NA'
15450    );
15451 
15452    xla_ae_lines_pkg.set_ccid(
15453     p_code_combination_id          => l_ccid
15454   , p_value_type_code              => l_adr_value_type_code
15458   , p_adr_type_code                => 'S'
15455   , p_transaction_coa_id           => l_adr_transaction_coa_id
15456   , p_accounting_coa_id            => l_adr_accounting_coa_id
15457   , p_adr_code                     => 'TRX_DIST_CCID'
15459   , p_component_type               => l_component_type
15460   , p_component_code               => l_component_code
15461   , p_component_type_code          => l_component_type_code
15462   , p_component_appl_id            => l_component_appl_id
15463   , p_amb_context_code             => l_amb_context_code
15464   , p_side                         => 'NA'
15465   );
15466 
15467 
15468    --
15469    --
15470    END IF;
15471    --
15472    -- Bug 4922099
15473    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
15474           (NVL(l_enc_upg_option, 'N') = 'O')
15475         ) AND
15476         (l_bflow_method_code = 'PRIOR_ENTRY')
15477       )
15478    THEN
15479       IF
15480       --
15481       1 = 2
15482       --
15483       THEN
15484       xla_accounting_err_pkg.build_message
15485                                     (p_appli_s_name            => 'XLA'
15486                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
15487                                     ,p_token_1                 => 'LINE_NUMBER'
15488                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
15489                                     ,p_token_2                 => 'LINE_TYPE_NAME'
15490                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
15491                                                                              l_component_type
15492                                                                             ,l_component_code
15493                                                                             ,l_component_type_code
15494                                                                             ,l_component_appl_id
15495                                                                             ,l_amb_context_code
15496                                                                             ,l_entity_code
15497                                                                             ,l_event_class_code
15498                                                                            )
15499                                     ,p_token_3                 => 'OWNER'
15500                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
15501                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
15502                                                                           ,p_lookup_code    => l_component_type_code
15503                                                                          )
15504                                     ,p_token_4                 => 'PRODUCT_NAME'
15505                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
15506                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
15507                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
15508                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
15509                                     ,p_ae_header_id            =>  NULL
15513                  trace
15510                                        );
15511 
15512         IF (C_LEVEL_ERROR>= g_log_level) THEN
15514                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
15515                       ,p_level    => C_LEVEL_ERROR
15516                       ,p_module   => l_log_module);
15517         END IF;
15518       END IF;
15519    END IF;
15520    --
15521    --
15522    ------------------------------------------------------------------------------------------------
15523    -- 4219869 Business Flow
15524    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
15525    -- Prior Entry.  Currently, the following code is always generated.
15526    ------------------------------------------------------------------------------------------------
15527    XLA_AE_LINES_PKG.ValidateCurrentLine;
15528 
15529    ------------------------------------------------------------------------------------
15530    -- 4219869 Business Flow
15531    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
15532    ------------------------------------------------------------------------------------
15533    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
15534 
15535    ----------------------------------------------------------------------------------
15536    -- 4219869 Business Flow
15537    -- Update journal entry status -- Need to generate this within IF <condition>
15538    ----------------------------------------------------------------------------------
15539    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
15540          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
15541          ,p_balance_type_code => l_balance_type_code
15542          );
15543 
15544    -------------------------------------------------------------------------------------------
15545    -- 4262811 - Generate the Accrual Reversal lines
15546    -------------------------------------------------------------------------------------------
15547    BEGIN
15548       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
15549                               (g_array_event(p_event_id).array_value_num('header_index'));
15550       IF l_acc_rev_flag IS NULL THEN
15551          l_acc_rev_flag := 'N';
15552       END IF;
15553    EXCEPTION
15554       WHEN OTHERS THEN
15555          l_acc_rev_flag := 'N';
15556    END;
15557    --
15558    IF (l_acc_rev_flag = 'Y') THEN
15559 
15560        -- 4645092  ------------------------------------------------------------------------------
15561        -- To allow MPA report to determine if it should generate report process
15562        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
15563        ------------------------------------------------------------------------------------------
15564 
15565        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
15566        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
15567    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
15568    -- call ADRs
15569    -- Bug 4922099
15570    --
15571    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
15572         (NVL(l_actual_upg_option, 'N') = 'O') OR
15573         (NVL(l_enc_upg_option, 'N') = 'O')
15574       )
15575    THEN
15576    NULL;
15577    --
15578    --
15579    
15580   l_ccid := AcctDerRule_16(
15581            p_application_id           => p_application_id
15582          , p_ae_header_id             => l_ae_header_id 
15583 , p_source_4 => p_source_4
15584          , x_transaction_coa_id       => l_adr_transaction_coa_id
15585          , x_accounting_coa_id        => l_adr_accounting_coa_id
15586          , x_value_type_code          => l_adr_value_type_code
15587          , p_side                     => 'NA'
15588    );
15589 
15590    xla_ae_lines_pkg.set_ccid(
15591     p_code_combination_id          => l_ccid
15592   , p_value_type_code              => l_adr_value_type_code
15593   , p_transaction_coa_id           => l_adr_transaction_coa_id
15594   , p_accounting_coa_id            => l_adr_accounting_coa_id
15595   , p_adr_code                     => 'TRX_DIST_CCID'
15596   , p_adr_type_code                => 'S'
15597   , p_component_type               => l_component_type
15598   , p_component_code               => l_component_code
15599   , p_component_type_code          => l_component_type_code
15600   , p_component_appl_id            => l_component_appl_id
15601   , p_amb_context_code             => l_amb_context_code
15602   , p_side                         => 'NA'
15603   );
15604 
15605 
15606    --
15607    --
15608    END IF;
15609 
15610        --
15611        -- Update the line information that should be overwritten
15612        --
15613        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
15614                                          p_header_num   => 1);
15615        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
15616 
15617        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
15618 
15619        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
15620           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
15621        END IF;
15622 
15623       --
15624       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
15625       --
15626       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
15627           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
15628       ELSE
15629           ---------------------------------------------------------------------------------------------------
15630           -- 4262811a Switch Sign
15631           ---------------------------------------------------------------------------------------------------
15632           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
15633           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
15634                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15635           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
15636                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15637           -- 5132302
15638           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
15639                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15640 
15641       END IF;
15642 
15643       -- 4955764
15644       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
15645       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
15646 
15647 
15648       XLA_AE_LINES_PKG.ValidateCurrentLine;
15649       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
15650 
15651       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
15652                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
15653                ,p_balance_type_code => l_balance_type_code);
15654 
15655    END IF;
15656 
15657    -----------------------------------------------------------------------------------------
15658    -- 4262811 Multiperiod Accounting
15659    -----------------------------------------------------------------------------------------
15660      -- No MPA option is assigned.
15661 
15662 
15663 END IF;
15664 END IF;
15665 --
15666 
15667 --
15668 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15669    trace
15670       (p_msg      => 'END of AcctLineType_40'
15671       ,p_level    => C_LEVEL_PROCEDURE
15672       ,p_module   => l_log_module);
15673 END IF;
15674 --
15675 EXCEPTION
15676   WHEN xla_exceptions_pkg.application_exception THEN
15677       RAISE;
15678   WHEN OTHERS THEN
15679        xla_exceptions_pkg.raise_message
15680            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_40');
15681 END AcctLineType_40;
15682 --
15683 
15684 ---------------------------------------
15685 --
15686 -- PRIVATE FUNCTION
15687 --         AcctLineType_41
15688 --
15689 ---------------------------------------
15690 PROCEDURE AcctLineType_41 (
15691   p_application_id        IN NUMBER
15692  ,p_event_id              IN NUMBER
15693  ,p_calculate_acctd_flag  IN VARCHAR2
15694  ,p_calculate_g_l_flag    IN VARCHAR2
15695  ,p_actual_flag           IN OUT VARCHAR2
15696  ,p_balance_type_code     OUT VARCHAR2
15697  ,p_gain_or_loss_ref      OUT VARCHAR2
15698  
15699 --Transaction Distribution GL Account
15700  , p_source_4            IN NUMBER
15701 --Bill To Customer Account Identifier
15702  , p_source_23            IN NUMBER
15703 --Bill To Customer Site Use Identifier
15704  , p_source_24            IN NUMBER
15705 --SLA Party Type
15706  , p_source_25            IN VARCHAR2
15707 --Transaction Distribution Account Class
15708  , p_source_26            IN VARCHAR2
15709 --Transaction Distribution Identifier
15710  , p_source_27            IN NUMBER
15711 --Transaction Distribution Type
15712  , p_source_28            IN VARCHAR2
15713 --Transaction Distribution Entered Amount
15714  , p_source_29            IN NUMBER
15715 --Transaction Currency Code
15716  , p_source_30            IN VARCHAR2
15717 --Transaction Exchange Date
15718  , p_source_31            IN DATE
15719 --Transaction Exchange Rate
15720  , p_source_32            IN NUMBER
15721 --Transaction Exchange Rate Type
15722  , p_source_33            IN VARCHAR2
15723 --Transaction Accounting Amount
15724  , p_source_34            IN NUMBER
15725 --Transaction Tax Line Identifier
15726  , p_source_48            IN NUMBER
15727 )
15728 IS
15729 
15730 l_component_type              VARCHAR2(80);
15731 l_component_code              VARCHAR2(30);
15732 l_component_type_code         VARCHAR2(1);
15733 l_component_appl_id           INTEGER;
15734 l_amb_context_code            VARCHAR2(30);
15735 l_entity_code                 VARCHAR2(30);
15736 l_event_class_code            VARCHAR2(30);
15737 l_ae_header_id                NUMBER;
15738 l_event_type_code             VARCHAR2(30);
15739 l_line_definition_code        VARCHAR2(30);
15740 l_line_definition_owner_code  VARCHAR2(1);
15741 --
15742 -- adr variables
15743 l_segment                     VARCHAR2(30);
15744 l_ccid                        NUMBER;
15745 l_adr_transaction_coa_id      NUMBER;
15746 l_adr_accounting_coa_id       NUMBER;
15747 l_adr_flexfield_segment_code  VARCHAR2(30);
15748 l_adr_flex_value_set_id       NUMBER;
15749 l_adr_value_type_code         VARCHAR2(30);
15750 l_adr_value_combination_id    NUMBER;
15751 l_adr_value_segment_code      VARCHAR2(30);
15752 
15753 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
15754 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
15755 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
15756 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
15757 
15758 -- 4262811 Variables ------------------------------------------------------------------------------------------
15759 l_entered_amt_idx             NUMBER;
15760 l_accted_amt_idx              NUMBER;
15764 l_acc_rev_natural_side_code   VARCHAR2(1);
15761 l_acc_rev_flag                VARCHAR2(1);
15762 l_accrual_line_num            NUMBER;
15763 l_tmp_amt                     NUMBER;
15765 
15766 l_num_entries                 NUMBER;
15767 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
15768 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
15769 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
15770 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
15771 l_recog_line_1                NUMBER;
15772 l_recog_line_2                NUMBER;
15773 
15774 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
15775 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
15776 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
15777 
15778 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
15779 
15780 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
15781 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
15782 
15783 ---------------------------------------------------------------------------------------------------------------
15784 
15785 
15786 --
15787 -- bulk performance
15788 --
15789 l_balance_type_code           VARCHAR2(1);
15790 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
15791 l_log_module                  VARCHAR2(240);
15792 
15793 --
15794 -- Upgrade strategy
15795 --
15796 l_actual_upg_option           VARCHAR2(1);
15797 l_enc_upg_option           VARCHAR2(1);
15798 
15799 --
15800 BEGIN
15801 --
15802 IF g_log_enabled THEN
15803       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_41';
15804 END IF;
15805 --
15806 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15807 
15808       trace
15809          (p_msg      => 'BEGIN of AcctLineType_41'
15810          ,p_level    => C_LEVEL_PROCEDURE
15811          ,p_module   => l_log_module);
15812 
15813 END IF;
15814 --
15815 l_component_type             := 'AMB_JLT';
15816 l_component_code             := 'DM_UNBILL';
15817 l_component_type_code        := 'S';
15818 l_component_appl_id          :=  222;
15819 l_amb_context_code           := 'DEFAULT';
15820 l_entity_code                := 'TRANSACTIONS';
15821 l_event_class_code           := 'DEBIT_MEMO';
15822 l_event_type_code            := 'DEBIT_MEMO_ALL';
15823 l_line_definition_owner_code := 'S';
15824 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
15825 --
15826 l_balance_type_code          := 'A';
15827 l_segment                     := NULL;
15828 l_ccid                        := NULL;
15829 l_adr_transaction_coa_id      := NULL;
15830 l_adr_accounting_coa_id       := NULL;
15831 l_adr_flexfield_segment_code  := NULL;
15832 l_adr_flex_value_set_id       := NULL;
15833 l_adr_value_type_code         := NULL;
15834 l_adr_value_combination_id    := NULL;
15835 l_adr_value_segment_code      := NULL;
15836 
15837 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
15838 l_bflow_class_code           := '';    -- 4219869 Business Flow
15839 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
15840 l_budgetary_control_flag     := 'N';
15841 
15842 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
15843 l_bflow_applied_to_amt       := NULL; -- 5132302
15844 l_entered_amt_idx            := NULL;          -- 4262811
15845 l_accted_amt_idx             := NULL;          -- 4262811
15846 l_acc_rev_flag               := NULL;          -- 4262811
15847 l_accrual_line_num           := NULL;          -- 4262811
15848 l_tmp_amt                    := NULL;          -- 4262811
15849 --
15850  
15851 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
15852     l_balance_type_code <> 'B' THEN
15853 IF NVL(p_source_26,'
15854 ') =  'UNBILL'
15855  THEN 
15856 
15857    --
15858    XLA_AE_LINES_PKG.SetNewLine;
15859 
15860    p_balance_type_code          := l_balance_type_code;
15861    -- set the flag so later we will know whether the gain loss line needs to be created
15862    
15863    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
15864      p_actual_flag :='A';
15865    END IF;
15866 
15867    --
15868    -- bulk performance
15869    --
15870    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
15871                                       p_header_num   => 0); -- 4262811
15872    --
15873    -- set accounting line options
15874    --
15875    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
15876            p_natural_side_code          => 'D'
15877          , p_gain_or_loss_flag          => 'N'
15878          , p_gl_transfer_mode_code      => 'S'
15879          , p_acct_entry_type_code       => 'A'
15880          , p_switch_side_flag           => 'Y'
15881          , p_merge_duplicate_code       => 'A'
15882          );
15883    --
15884    l_acc_rev_natural_side_code := 'C';  -- 4262811
15885    -- 
15886    --
15887    -- set accounting line type info
15888    --
15889    xla_ae_lines_pkg.SetAcctLineType
15890       (p_component_type             => l_component_type
15891       ,p_event_type_code            => l_event_type_code
15892       ,p_line_definition_owner_code => l_line_definition_owner_code
15893       ,p_line_definition_code       => l_line_definition_code
15894       ,p_accounting_line_code       => l_component_code
15895       ,p_accounting_line_type_code  => l_component_type_code
15896       ,p_accounting_line_appl_id    => l_component_appl_id
15897       ,p_amb_context_code           => l_amb_context_code
15901    -- set accounting class
15898       ,p_entity_code                => l_entity_code
15899       ,p_event_class_code           => l_event_class_code);
15900    --
15902    --
15903    xla_ae_lines_pkg.SetAcctClass(
15904            p_accounting_class_code  => 'UNBILL'
15905          , p_ae_header_id           => l_ae_header_id
15906          );
15907 
15908    --
15909    -- set rounding class
15910    --
15911    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
15912                       'RECEIVABLE';
15913 
15914    --
15915    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
15916    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
15917    --
15918    -- bulk performance
15919    --
15920    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
15921 
15922    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
15923       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
15924 
15925    -- 4955764
15926    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
15927       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
15928 
15929    -- 4458381 Public Sector Enh
15930    
15931    --
15932    -- set accounting attributes for the line type
15933    --
15934    l_entered_amt_idx := 3;
15935    l_accted_amt_idx  := 8;
15936    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
15937    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
15938    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
15939    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
15940    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
15941    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
15942    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
15943    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
15944    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
15945    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
15946    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
15947    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
15948    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
15949    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
15950    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
15951    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
15952    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
15953    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
15954    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
15955    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
15956    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
15957    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
15958    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
15959    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
15960    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
15961 
15962    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
15963    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
15964 
15965    ---------------------------------------------------------------------------------------------------------------
15966    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
15967    ---------------------------------------------------------------------------------------------------------------
15968    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
15969 
15970    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
15971    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
15972 
15973    IF xla_accounting_cache_pkg.GetValueChar
15974          (p_source_code         => 'LEDGER_CATEGORY_CODE'
15975          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
15976    AND l_bflow_method_code = 'PRIOR_ENTRY'
15977 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
15978    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
15979          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
15980        )
15981    THEN
15982          xla_ae_lines_pkg.BflowUpgEntry
15983            (p_business_method_code    => l_bflow_method_code
15984            ,p_business_class_code     => l_bflow_class_code
15985            ,p_balance_type            => l_balance_type_code);
15986    ELSE
15987       NULL;
15988 -- No business flow processing for business flow method of NONE.
15989    END IF;
15990 
15991    --
15992    -- call analytical criteria
15993    --
15994    
15995    --
15996    -- call description
15997    --
15998    -- No description or it is inherited.
15999    --
16000    -- call ADRs
16001    -- Bug 4922099
16002    --
16003    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
16004         (NVL(l_actual_upg_option, 'N') = 'O') OR
16005         (NVL(l_enc_upg_option, 'N') = 'O')
16006       )
16007    THEN
16008    NULL;
16009    --
16010    --
16011    
16012   l_ccid := AcctDerRule_16(
16013            p_application_id           => p_application_id
16014          , p_ae_header_id             => l_ae_header_id 
16015 , p_source_4 => p_source_4
16016          , x_transaction_coa_id       => l_adr_transaction_coa_id
16017          , x_accounting_coa_id        => l_adr_accounting_coa_id
16018          , x_value_type_code          => l_adr_value_type_code
16022    xla_ae_lines_pkg.set_ccid(
16019          , p_side                     => 'NA'
16020    );
16021 
16023     p_code_combination_id          => l_ccid
16024   , p_value_type_code              => l_adr_value_type_code
16025   , p_transaction_coa_id           => l_adr_transaction_coa_id
16026   , p_accounting_coa_id            => l_adr_accounting_coa_id
16027   , p_adr_code                     => 'TRX_DIST_CCID'
16028   , p_adr_type_code                => 'S'
16029   , p_component_type               => l_component_type
16030   , p_component_code               => l_component_code
16031   , p_component_type_code          => l_component_type_code
16032   , p_component_appl_id            => l_component_appl_id
16033   , p_amb_context_code             => l_amb_context_code
16034   , p_side                         => 'NA'
16035   );
16036 
16037 
16038    --
16039    --
16040    END IF;
16041    --
16042    -- Bug 4922099
16043    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
16044           (NVL(l_enc_upg_option, 'N') = 'O')
16045         ) AND
16046         (l_bflow_method_code = 'PRIOR_ENTRY')
16047       )
16048    THEN
16049       IF
16050       --
16051       1 = 2
16052       --
16053       THEN
16054       xla_accounting_err_pkg.build_message
16055                                     (p_appli_s_name            => 'XLA'
16056                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
16057                                     ,p_token_1                 => 'LINE_NUMBER'
16058                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
16059                                     ,p_token_2                 => 'LINE_TYPE_NAME'
16060                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
16061                                                                              l_component_type
16062                                                                             ,l_component_code
16063                                                                             ,l_component_type_code
16064                                                                             ,l_component_appl_id
16065                                                                             ,l_amb_context_code
16066                                                                             ,l_entity_code
16067                                                                             ,l_event_class_code
16068                                                                            )
16069                                     ,p_token_3                 => 'OWNER'
16070                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
16071                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
16072                                                                           ,p_lookup_code    => l_component_type_code
16073                                                                          )
16074                                     ,p_token_4                 => 'PRODUCT_NAME'
16075                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
16076                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
16077                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
16078                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
16079                                     ,p_ae_header_id            =>  NULL
16080                                        );
16081 
16082         IF (C_LEVEL_ERROR>= g_log_level) THEN
16083                  trace
16087         END IF;
16084                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
16085                       ,p_level    => C_LEVEL_ERROR
16086                       ,p_module   => l_log_module);
16088       END IF;
16089    END IF;
16090    --
16091    --
16092    ------------------------------------------------------------------------------------------------
16093    -- 4219869 Business Flow
16094    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
16095    -- Prior Entry.  Currently, the following code is always generated.
16096    ------------------------------------------------------------------------------------------------
16097    XLA_AE_LINES_PKG.ValidateCurrentLine;
16098 
16099    ------------------------------------------------------------------------------------
16100    -- 4219869 Business Flow
16101    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
16102    ------------------------------------------------------------------------------------
16103    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
16104 
16105    ----------------------------------------------------------------------------------
16106    -- 4219869 Business Flow
16107    -- Update journal entry status -- Need to generate this within IF <condition>
16108    ----------------------------------------------------------------------------------
16109    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
16110          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
16111          ,p_balance_type_code => l_balance_type_code
16112          );
16113 
16114    -------------------------------------------------------------------------------------------
16115    -- 4262811 - Generate the Accrual Reversal lines
16116    -------------------------------------------------------------------------------------------
16117    BEGIN
16118       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
16119                               (g_array_event(p_event_id).array_value_num('header_index'));
16120       IF l_acc_rev_flag IS NULL THEN
16121          l_acc_rev_flag := 'N';
16122       END IF;
16123    EXCEPTION
16124       WHEN OTHERS THEN
16125          l_acc_rev_flag := 'N';
16126    END;
16127    --
16128    IF (l_acc_rev_flag = 'Y') THEN
16129 
16130        -- 4645092  ------------------------------------------------------------------------------
16131        -- To allow MPA report to determine if it should generate report process
16132        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
16133        ------------------------------------------------------------------------------------------
16134 
16135        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
16136        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
16137    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
16138    -- call ADRs
16139    -- Bug 4922099
16140    --
16141    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
16142         (NVL(l_actual_upg_option, 'N') = 'O') OR
16143         (NVL(l_enc_upg_option, 'N') = 'O')
16144       )
16145    THEN
16146    NULL;
16147    --
16148    --
16149    
16150   l_ccid := AcctDerRule_16(
16151            p_application_id           => p_application_id
16152          , p_ae_header_id             => l_ae_header_id 
16153 , p_source_4 => p_source_4
16154          , x_transaction_coa_id       => l_adr_transaction_coa_id
16155          , x_accounting_coa_id        => l_adr_accounting_coa_id
16156          , x_value_type_code          => l_adr_value_type_code
16157          , p_side                     => 'NA'
16158    );
16159 
16160    xla_ae_lines_pkg.set_ccid(
16161     p_code_combination_id          => l_ccid
16162   , p_value_type_code              => l_adr_value_type_code
16163   , p_transaction_coa_id           => l_adr_transaction_coa_id
16164   , p_accounting_coa_id            => l_adr_accounting_coa_id
16165   , p_adr_code                     => 'TRX_DIST_CCID'
16166   , p_adr_type_code                => 'S'
16167   , p_component_type               => l_component_type
16168   , p_component_code               => l_component_code
16169   , p_component_type_code          => l_component_type_code
16170   , p_component_appl_id            => l_component_appl_id
16171   , p_amb_context_code             => l_amb_context_code
16172   , p_side                         => 'NA'
16173   );
16174 
16175 
16176    --
16177    --
16178    END IF;
16179 
16180        --
16181        -- Update the line information that should be overwritten
16182        --
16183        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
16184                                          p_header_num   => 1);
16185        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
16186 
16187        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
16188 
16189        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
16190           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
16191        END IF;
16192 
16193       --
16194       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
16195       --
16196       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
16197           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
16198       ELSE
16199           ---------------------------------------------------------------------------------------------------
16200           -- 4262811a Switch Sign
16204                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
16201           ---------------------------------------------------------------------------------------------------
16202           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
16203           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
16205           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
16206                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
16207           -- 5132302
16208           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
16209                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
16210 
16211       END IF;
16212 
16213       -- 4955764
16214       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
16215       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
16216 
16217 
16218       XLA_AE_LINES_PKG.ValidateCurrentLine;
16219       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
16220 
16221       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
16222                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
16223                ,p_balance_type_code => l_balance_type_code);
16224 
16225    END IF;
16226 
16227    -----------------------------------------------------------------------------------------
16228    -- 4262811 Multiperiod Accounting
16229    -----------------------------------------------------------------------------------------
16230      -- No MPA option is assigned.
16231 
16232 
16233 END IF;
16234 END IF;
16235 --
16236 
16237 --
16238 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16239    trace
16240       (p_msg      => 'END of AcctLineType_41'
16241       ,p_level    => C_LEVEL_PROCEDURE
16242       ,p_module   => l_log_module);
16243 END IF;
16244 --
16245 EXCEPTION
16246   WHEN xla_exceptions_pkg.application_exception THEN
16247       RAISE;
16248   WHEN OTHERS THEN
16249        xla_exceptions_pkg.raise_message
16250            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_41');
16251 END AcctLineType_41;
16252 --
16253 
16254 ---------------------------------------
16255 --
16256 -- PRIVATE FUNCTION
16257 --         AcctLineType_42
16258 --
16259 ---------------------------------------
16260 PROCEDURE AcctLineType_42 (
16261   p_application_id        IN NUMBER
16262  ,p_event_id              IN NUMBER
16263  ,p_calculate_acctd_flag  IN VARCHAR2
16264  ,p_calculate_g_l_flag    IN VARCHAR2
16265  ,p_actual_flag           IN OUT VARCHAR2
16266  ,p_balance_type_code     OUT VARCHAR2
16267  ,p_gain_or_loss_ref      OUT VARCHAR2
16268  
16269 --Transaction Distribution GL Account
16270  , p_source_4            IN NUMBER
16271 --Bill To Customer Account Identifier
16272  , p_source_23            IN NUMBER
16273 --Bill To Customer Site Use Identifier
16274  , p_source_24            IN NUMBER
16275 --SLA Party Type
16276  , p_source_25            IN VARCHAR2
16277 --Transaction Distribution Account Class
16278  , p_source_26            IN VARCHAR2
16279 --Transaction Distribution Identifier
16280  , p_source_27            IN NUMBER
16281 --Transaction Distribution Type
16282  , p_source_28            IN VARCHAR2
16283 --Transaction Distribution Entered Amount
16284  , p_source_29            IN NUMBER
16285 --Transaction Currency Code
16286  , p_source_30            IN VARCHAR2
16287 --Transaction Exchange Date
16288  , p_source_31            IN DATE
16289 --Transaction Exchange Rate
16290  , p_source_32            IN NUMBER
16291 --Transaction Exchange Rate Type
16292  , p_source_33            IN VARCHAR2
16293 --Transaction Accounting Amount
16294  , p_source_34            IN NUMBER
16295 --Transaction Tax Line Identifier
16296  , p_source_48            IN NUMBER
16297 )
16298 IS
16299 
16300 l_component_type              VARCHAR2(80);
16301 l_component_code              VARCHAR2(30);
16302 l_component_type_code         VARCHAR2(1);
16303 l_component_appl_id           INTEGER;
16304 l_amb_context_code            VARCHAR2(30);
16305 l_entity_code                 VARCHAR2(30);
16306 l_event_class_code            VARCHAR2(30);
16307 l_ae_header_id                NUMBER;
16308 l_event_type_code             VARCHAR2(30);
16309 l_line_definition_code        VARCHAR2(30);
16310 l_line_definition_owner_code  VARCHAR2(1);
16311 --
16312 -- adr variables
16313 l_segment                     VARCHAR2(30);
16314 l_ccid                        NUMBER;
16315 l_adr_transaction_coa_id      NUMBER;
16316 l_adr_accounting_coa_id       NUMBER;
16317 l_adr_flexfield_segment_code  VARCHAR2(30);
16318 l_adr_flex_value_set_id       NUMBER;
16319 l_adr_value_type_code         VARCHAR2(30);
16320 l_adr_value_combination_id    NUMBER;
16321 l_adr_value_segment_code      VARCHAR2(30);
16322 
16323 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
16324 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
16325 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
16326 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
16327 
16328 -- 4262811 Variables ------------------------------------------------------------------------------------------
16332 l_accrual_line_num            NUMBER;
16329 l_entered_amt_idx             NUMBER;
16330 l_accted_amt_idx              NUMBER;
16331 l_acc_rev_flag                VARCHAR2(1);
16333 l_tmp_amt                     NUMBER;
16334 l_acc_rev_natural_side_code   VARCHAR2(1);
16335 
16336 l_num_entries                 NUMBER;
16337 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
16338 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
16339 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
16340 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
16341 l_recog_line_1                NUMBER;
16342 l_recog_line_2                NUMBER;
16343 
16344 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
16345 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
16346 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
16347 
16348 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
16349 
16350 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
16351 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
16352 
16353 ---------------------------------------------------------------------------------------------------------------
16354 
16355 
16356 --
16357 -- bulk performance
16358 --
16359 l_balance_type_code           VARCHAR2(1);
16360 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
16361 l_log_module                  VARCHAR2(240);
16362 
16363 --
16364 -- Upgrade strategy
16365 --
16366 l_actual_upg_option           VARCHAR2(1);
16367 l_enc_upg_option           VARCHAR2(1);
16368 
16369 --
16370 BEGIN
16371 --
16372 IF g_log_enabled THEN
16373       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_42';
16374 END IF;
16375 --
16376 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16377 
16378       trace
16379          (p_msg      => 'BEGIN of AcctLineType_42'
16380          ,p_level    => C_LEVEL_PROCEDURE
16381          ,p_module   => l_log_module);
16382 
16383 END IF;
16384 --
16385 l_component_type             := 'AMB_JLT';
16386 l_component_code             := 'DM_UNEARN';
16387 l_component_type_code        := 'S';
16388 l_component_appl_id          :=  222;
16389 l_amb_context_code           := 'DEFAULT';
16390 l_entity_code                := 'TRANSACTIONS';
16391 l_event_class_code           := 'DEBIT_MEMO';
16392 l_event_type_code            := 'DEBIT_MEMO_ALL';
16393 l_line_definition_owner_code := 'S';
16394 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
16395 --
16396 l_balance_type_code          := 'A';
16397 l_segment                     := NULL;
16398 l_ccid                        := NULL;
16399 l_adr_transaction_coa_id      := NULL;
16400 l_adr_accounting_coa_id       := NULL;
16401 l_adr_flexfield_segment_code  := NULL;
16402 l_adr_flex_value_set_id       := NULL;
16403 l_adr_value_type_code         := NULL;
16404 l_adr_value_combination_id    := NULL;
16405 l_adr_value_segment_code      := NULL;
16406 
16407 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
16408 l_bflow_class_code           := '';    -- 4219869 Business Flow
16409 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
16410 l_budgetary_control_flag     := 'N';
16411 
16412 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
16413 l_bflow_applied_to_amt       := NULL; -- 5132302
16414 l_entered_amt_idx            := NULL;          -- 4262811
16415 l_accted_amt_idx             := NULL;          -- 4262811
16416 l_acc_rev_flag               := NULL;          -- 4262811
16417 l_accrual_line_num           := NULL;          -- 4262811
16418 l_tmp_amt                    := NULL;          -- 4262811
16419 --
16420  
16421 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
16422     l_balance_type_code <> 'B' THEN
16423 IF NVL(p_source_26,'
16424 ') =  'UNEARN'
16425  THEN 
16426 
16427    --
16428    XLA_AE_LINES_PKG.SetNewLine;
16429 
16430    p_balance_type_code          := l_balance_type_code;
16431    -- set the flag so later we will know whether the gain loss line needs to be created
16432    
16433    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
16434      p_actual_flag :='A';
16435    END IF;
16436 
16437    --
16438    -- bulk performance
16439    --
16440    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
16441                                       p_header_num   => 0); -- 4262811
16442    --
16443    -- set accounting line options
16444    --
16445    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
16446            p_natural_side_code          => 'C'
16447          , p_gain_or_loss_flag          => 'N'
16448          , p_gl_transfer_mode_code      => 'S'
16449          , p_acct_entry_type_code       => 'A'
16450          , p_switch_side_flag           => 'Y'
16451          , p_merge_duplicate_code       => 'A'
16452          );
16453    --
16454    l_acc_rev_natural_side_code := 'D';  -- 4262811
16455    -- 
16456    --
16457    -- set accounting line type info
16458    --
16459    xla_ae_lines_pkg.SetAcctLineType
16460       (p_component_type             => l_component_type
16461       ,p_event_type_code            => l_event_type_code
16462       ,p_line_definition_owner_code => l_line_definition_owner_code
16463       ,p_line_definition_code       => l_line_definition_code
16464       ,p_accounting_line_code       => l_component_code
16465       ,p_accounting_line_type_code  => l_component_type_code
16466       ,p_accounting_line_appl_id    => l_component_appl_id
16470    --
16467       ,p_amb_context_code           => l_amb_context_code
16468       ,p_entity_code                => l_entity_code
16469       ,p_event_class_code           => l_event_class_code);
16471    -- set accounting class
16472    --
16473    xla_ae_lines_pkg.SetAcctClass(
16474            p_accounting_class_code  => 'UNEARNED_REVENUE'
16475          , p_ae_header_id           => l_ae_header_id
16476          );
16477 
16478    --
16479    -- set rounding class
16480    --
16481    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
16482                       'RECEIVABLE';
16483 
16484    --
16485    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
16486    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
16487    --
16488    -- bulk performance
16489    --
16490    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
16491 
16492    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
16493       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
16494 
16495    -- 4955764
16496    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
16497       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
16498 
16499    -- 4458381 Public Sector Enh
16500    
16501    --
16502    -- set accounting attributes for the line type
16503    --
16504    l_entered_amt_idx := 3;
16505    l_accted_amt_idx  := 8;
16506    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
16507    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
16508    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
16509    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
16510    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
16511    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
16512    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
16513    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
16514    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
16515    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
16516    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
16517    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
16518    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
16519    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
16520    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
16521    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
16522    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
16523    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
16524    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
16525    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
16526    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
16527    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
16528    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
16529    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
16530    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
16531 
16532    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
16533    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
16534 
16535    ---------------------------------------------------------------------------------------------------------------
16536    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
16537    ---------------------------------------------------------------------------------------------------------------
16538    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
16539 
16540    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
16541    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
16542 
16543    IF xla_accounting_cache_pkg.GetValueChar
16544          (p_source_code         => 'LEDGER_CATEGORY_CODE'
16545          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
16546    AND l_bflow_method_code = 'PRIOR_ENTRY'
16547 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
16548    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
16549          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
16550        )
16551    THEN
16552          xla_ae_lines_pkg.BflowUpgEntry
16553            (p_business_method_code    => l_bflow_method_code
16554            ,p_business_class_code     => l_bflow_class_code
16555            ,p_balance_type            => l_balance_type_code);
16556    ELSE
16557       NULL;
16558 -- No business flow processing for business flow method of NONE.
16559    END IF;
16560 
16561    --
16562    -- call analytical criteria
16563    --
16564    
16565    --
16566    -- call description
16567    --
16568    -- No description or it is inherited.
16569    --
16570    -- call ADRs
16571    -- Bug 4922099
16572    --
16573    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
16574         (NVL(l_actual_upg_option, 'N') = 'O') OR
16575         (NVL(l_enc_upg_option, 'N') = 'O')
16576       )
16577    THEN
16578    NULL;
16579    --
16580    --
16581    
16582   l_ccid := AcctDerRule_16(
16583            p_application_id           => p_application_id
16584          , p_ae_header_id             => l_ae_header_id 
16585 , p_source_4 => p_source_4
16586          , x_transaction_coa_id       => l_adr_transaction_coa_id
16590    );
16587          , x_accounting_coa_id        => l_adr_accounting_coa_id
16588          , x_value_type_code          => l_adr_value_type_code
16589          , p_side                     => 'NA'
16591 
16592    xla_ae_lines_pkg.set_ccid(
16593     p_code_combination_id          => l_ccid
16594   , p_value_type_code              => l_adr_value_type_code
16595   , p_transaction_coa_id           => l_adr_transaction_coa_id
16596   , p_accounting_coa_id            => l_adr_accounting_coa_id
16597   , p_adr_code                     => 'TRX_DIST_CCID'
16598   , p_adr_type_code                => 'S'
16599   , p_component_type               => l_component_type
16600   , p_component_code               => l_component_code
16601   , p_component_type_code          => l_component_type_code
16602   , p_component_appl_id            => l_component_appl_id
16603   , p_amb_context_code             => l_amb_context_code
16604   , p_side                         => 'NA'
16605   );
16606 
16607 
16608    --
16609    --
16610    END IF;
16611    --
16612    -- Bug 4922099
16613    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
16614           (NVL(l_enc_upg_option, 'N') = 'O')
16615         ) AND
16616         (l_bflow_method_code = 'PRIOR_ENTRY')
16617       )
16618    THEN
16619       IF
16620       --
16621       1 = 2
16622       --
16623       THEN
16624       xla_accounting_err_pkg.build_message
16625                                     (p_appli_s_name            => 'XLA'
16626                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
16627                                     ,p_token_1                 => 'LINE_NUMBER'
16628                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
16629                                     ,p_token_2                 => 'LINE_TYPE_NAME'
16630                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
16631                                                                              l_component_type
16632                                                                             ,l_component_code
16633                                                                             ,l_component_type_code
16634                                                                             ,l_component_appl_id
16635                                                                             ,l_amb_context_code
16636                                                                             ,l_entity_code
16637                                                                             ,l_event_class_code
16638                                                                            )
16639                                     ,p_token_3                 => 'OWNER'
16640                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
16641                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
16642                                                                           ,p_lookup_code    => l_component_type_code
16643                                                                          )
16644                                     ,p_token_4                 => 'PRODUCT_NAME'
16645                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
16646                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
16647                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
16648                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
16649                                     ,p_ae_header_id            =>  NULL
16650                                        );
16651 
16652         IF (C_LEVEL_ERROR>= g_log_level) THEN
16653                  trace
16654                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
16655                       ,p_level    => C_LEVEL_ERROR
16656                       ,p_module   => l_log_module);
16657         END IF;
16658       END IF;
16659    END IF;
16660    --
16661    --
16662    ------------------------------------------------------------------------------------------------
16663    -- 4219869 Business Flow
16664    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
16665    -- Prior Entry.  Currently, the following code is always generated.
16666    ------------------------------------------------------------------------------------------------
16667    XLA_AE_LINES_PKG.ValidateCurrentLine;
16668 
16669    ------------------------------------------------------------------------------------
16670    -- 4219869 Business Flow
16671    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
16672    ------------------------------------------------------------------------------------
16673    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
16674 
16675    ----------------------------------------------------------------------------------
16676    -- 4219869 Business Flow
16677    -- Update journal entry status -- Need to generate this within IF <condition>
16678    ----------------------------------------------------------------------------------
16679    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
16680          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
16681          ,p_balance_type_code => l_balance_type_code
16682          );
16683 
16684    -------------------------------------------------------------------------------------------
16685    -- 4262811 - Generate the Accrual Reversal lines
16689                               (g_array_event(p_event_id).array_value_num('header_index'));
16686    -------------------------------------------------------------------------------------------
16687    BEGIN
16688       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
16690       IF l_acc_rev_flag IS NULL THEN
16691          l_acc_rev_flag := 'N';
16692       END IF;
16693    EXCEPTION
16694       WHEN OTHERS THEN
16695          l_acc_rev_flag := 'N';
16696    END;
16697    --
16698    IF (l_acc_rev_flag = 'Y') THEN
16699 
16700        -- 4645092  ------------------------------------------------------------------------------
16701        -- To allow MPA report to determine if it should generate report process
16702        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
16703        ------------------------------------------------------------------------------------------
16704 
16705        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
16706        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
16707    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
16708    -- call ADRs
16709    -- Bug 4922099
16710    --
16711    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
16712         (NVL(l_actual_upg_option, 'N') = 'O') OR
16713         (NVL(l_enc_upg_option, 'N') = 'O')
16714       )
16715    THEN
16716    NULL;
16717    --
16718    --
16719    
16720   l_ccid := AcctDerRule_16(
16721            p_application_id           => p_application_id
16722          , p_ae_header_id             => l_ae_header_id 
16723 , p_source_4 => p_source_4
16724          , x_transaction_coa_id       => l_adr_transaction_coa_id
16725          , x_accounting_coa_id        => l_adr_accounting_coa_id
16726          , x_value_type_code          => l_adr_value_type_code
16727          , p_side                     => 'NA'
16728    );
16729 
16730    xla_ae_lines_pkg.set_ccid(
16731     p_code_combination_id          => l_ccid
16732   , p_value_type_code              => l_adr_value_type_code
16733   , p_transaction_coa_id           => l_adr_transaction_coa_id
16734   , p_accounting_coa_id            => l_adr_accounting_coa_id
16735   , p_adr_code                     => 'TRX_DIST_CCID'
16736   , p_adr_type_code                => 'S'
16737   , p_component_type               => l_component_type
16738   , p_component_code               => l_component_code
16739   , p_component_type_code          => l_component_type_code
16740   , p_component_appl_id            => l_component_appl_id
16741   , p_amb_context_code             => l_amb_context_code
16742   , p_side                         => 'NA'
16743   );
16744 
16745 
16746    --
16747    --
16748    END IF;
16749 
16750        --
16751        -- Update the line information that should be overwritten
16752        --
16753        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
16754                                          p_header_num   => 1);
16755        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
16756 
16757        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
16758 
16759        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
16760           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
16761        END IF;
16762 
16763       --
16764       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
16765       --
16766       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
16767           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
16768       ELSE
16769           ---------------------------------------------------------------------------------------------------
16770           -- 4262811a Switch Sign
16771           ---------------------------------------------------------------------------------------------------
16772           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
16773           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
16774                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
16775           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
16776                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
16777           -- 5132302
16778           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
16779                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
16780 
16781       END IF;
16782 
16783       -- 4955764
16784       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
16785       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
16786 
16787 
16788       XLA_AE_LINES_PKG.ValidateCurrentLine;
16789       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
16790 
16791       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
16792                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
16793                ,p_balance_type_code => l_balance_type_code);
16794 
16795    END IF;
16796 
16797    -----------------------------------------------------------------------------------------
16798    -- 4262811 Multiperiod Accounting
16799    -----------------------------------------------------------------------------------------
16800      -- No MPA option is assigned.
16801 
16802 
16803 END IF;
16804 END IF;
16805 --
16806 
16807 --
16811       ,p_level    => C_LEVEL_PROCEDURE
16808 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16809    trace
16810       (p_msg      => 'END of AcctLineType_42'
16812       ,p_module   => l_log_module);
16813 END IF;
16814 --
16815 EXCEPTION
16816   WHEN xla_exceptions_pkg.application_exception THEN
16817       RAISE;
16818   WHEN OTHERS THEN
16819        xla_exceptions_pkg.raise_message
16820            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_42');
16821 END AcctLineType_42;
16822 --
16823 
16824 ---------------------------------------
16825 --
16826 -- PRIVATE FUNCTION
16827 --         AcctLineType_43
16828 --
16829 ---------------------------------------
16830 PROCEDURE AcctLineType_43 (
16831   p_application_id        IN NUMBER
16832  ,p_event_id              IN NUMBER
16833  ,p_calculate_acctd_flag  IN VARCHAR2
16834  ,p_calculate_g_l_flag    IN VARCHAR2
16835  ,p_actual_flag           IN OUT VARCHAR2
16836  ,p_balance_type_code     OUT VARCHAR2
16837  ,p_gain_or_loss_ref      OUT VARCHAR2
16838  
16839 --Transaction Distribution GL Account
16840  , p_source_4            IN NUMBER
16841 --Bill To Customer Account Identifier
16842  , p_source_23            IN NUMBER
16843 --Bill To Customer Site Use Identifier
16844  , p_source_24            IN NUMBER
16845 --SLA Party Type
16846  , p_source_25            IN VARCHAR2
16847 --Transaction Distribution Account Class
16848  , p_source_26            IN VARCHAR2
16849 --Transaction Distribution Identifier
16850  , p_source_27            IN NUMBER
16851 --Transaction Distribution Type
16852  , p_source_28            IN VARCHAR2
16853 --Transaction Distribution Entered Amount
16854  , p_source_29            IN NUMBER
16855 --Transaction Currency Code
16856  , p_source_30            IN VARCHAR2
16857 --Transaction Exchange Date
16858  , p_source_31            IN DATE
16859 --Transaction Exchange Rate
16860  , p_source_32            IN NUMBER
16861 --Transaction Exchange Rate Type
16862  , p_source_33            IN VARCHAR2
16863 --Transaction Accounting Amount
16864  , p_source_34            IN NUMBER
16865 )
16866 IS
16867 
16868 l_component_type              VARCHAR2(80);
16869 l_component_code              VARCHAR2(30);
16870 l_component_type_code         VARCHAR2(1);
16871 l_component_appl_id           INTEGER;
16872 l_amb_context_code            VARCHAR2(30);
16873 l_entity_code                 VARCHAR2(30);
16874 l_event_class_code            VARCHAR2(30);
16875 l_ae_header_id                NUMBER;
16876 l_event_type_code             VARCHAR2(30);
16877 l_line_definition_code        VARCHAR2(30);
16878 l_line_definition_owner_code  VARCHAR2(1);
16879 --
16880 -- adr variables
16881 l_segment                     VARCHAR2(30);
16882 l_ccid                        NUMBER;
16883 l_adr_transaction_coa_id      NUMBER;
16884 l_adr_accounting_coa_id       NUMBER;
16885 l_adr_flexfield_segment_code  VARCHAR2(30);
16886 l_adr_flex_value_set_id       NUMBER;
16887 l_adr_value_type_code         VARCHAR2(30);
16888 l_adr_value_combination_id    NUMBER;
16889 l_adr_value_segment_code      VARCHAR2(30);
16890 
16891 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
16892 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
16893 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
16894 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
16895 
16896 -- 4262811 Variables ------------------------------------------------------------------------------------------
16897 l_entered_amt_idx             NUMBER;
16898 l_accted_amt_idx              NUMBER;
16899 l_acc_rev_flag                VARCHAR2(1);
16900 l_accrual_line_num            NUMBER;
16901 l_tmp_amt                     NUMBER;
16902 l_acc_rev_natural_side_code   VARCHAR2(1);
16903 
16904 l_num_entries                 NUMBER;
16905 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
16906 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
16907 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
16908 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
16909 l_recog_line_1                NUMBER;
16910 l_recog_line_2                NUMBER;
16911 
16912 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
16913 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
16914 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
16915 
16916 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
16917 
16918 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
16919 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
16920 
16921 ---------------------------------------------------------------------------------------------------------------
16922 
16923 
16924 --
16925 -- bulk performance
16926 --
16927 l_balance_type_code           VARCHAR2(1);
16928 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
16929 l_log_module                  VARCHAR2(240);
16930 
16931 --
16932 -- Upgrade strategy
16933 --
16934 l_actual_upg_option           VARCHAR2(1);
16935 l_enc_upg_option           VARCHAR2(1);
16936 
16937 --
16938 BEGIN
16939 --
16940 IF g_log_enabled THEN
16941       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_43';
16942 END IF;
16943 --
16944 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16945 
16946       trace
16947          (p_msg      => 'BEGIN of AcctLineType_43'
16948          ,p_level    => C_LEVEL_PROCEDURE
16949          ,p_module   => l_log_module);
16953 l_component_type             := 'AMB_JLT';
16950 
16951 END IF;
16952 --
16954 l_component_code             := 'GUAR_DEFAULT_REC';
16955 l_component_type_code        := 'S';
16956 l_component_appl_id          :=  222;
16957 l_amb_context_code           := 'DEFAULT';
16958 l_entity_code                := 'TRANSACTIONS';
16959 l_event_class_code           := 'GUARANTEE';
16960 l_event_type_code            := 'GUARANTEE_ALL';
16961 l_line_definition_owner_code := 'S';
16962 l_line_definition_code       := 'AR_GUAR_DEFAULT_ACCRUAL';
16963 --
16964 l_balance_type_code          := 'A';
16965 l_segment                     := NULL;
16966 l_ccid                        := NULL;
16967 l_adr_transaction_coa_id      := NULL;
16968 l_adr_accounting_coa_id       := NULL;
16969 l_adr_flexfield_segment_code  := NULL;
16970 l_adr_flex_value_set_id       := NULL;
16971 l_adr_value_type_code         := NULL;
16972 l_adr_value_combination_id    := NULL;
16973 l_adr_value_segment_code      := NULL;
16974 
16975 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
16976 l_bflow_class_code           := '';    -- 4219869 Business Flow
16977 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
16978 l_budgetary_control_flag     := 'N';
16979 
16980 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
16981 l_bflow_applied_to_amt       := NULL; -- 5132302
16982 l_entered_amt_idx            := NULL;          -- 4262811
16983 l_accted_amt_idx             := NULL;          -- 4262811
16984 l_acc_rev_flag               := NULL;          -- 4262811
16985 l_accrual_line_num           := NULL;          -- 4262811
16986 l_tmp_amt                    := NULL;          -- 4262811
16987 --
16988  
16989 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
16990     l_balance_type_code <> 'B' THEN
16991 IF NVL(p_source_26,'
16992 ') =  'REC'
16993  THEN 
16994 
16995    --
16996    XLA_AE_LINES_PKG.SetNewLine;
16997 
16998    p_balance_type_code          := l_balance_type_code;
16999    -- set the flag so later we will know whether the gain loss line needs to be created
17000    
17001    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
17002      p_actual_flag :='A';
17003    END IF;
17004 
17005    --
17006    -- bulk performance
17007    --
17008    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
17009                                       p_header_num   => 0); -- 4262811
17010    --
17011    -- set accounting line options
17012    --
17013    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
17014            p_natural_side_code          => 'D'
17015          , p_gain_or_loss_flag          => 'N'
17016          , p_gl_transfer_mode_code      => 'S'
17017          , p_acct_entry_type_code       => 'A'
17018          , p_switch_side_flag           => 'Y'
17019          , p_merge_duplicate_code       => 'A'
17020          );
17021    --
17022    l_acc_rev_natural_side_code := 'C';  -- 4262811
17023    -- 
17024    --
17025    -- set accounting line type info
17026    --
17027    xla_ae_lines_pkg.SetAcctLineType
17028       (p_component_type             => l_component_type
17029       ,p_event_type_code            => l_event_type_code
17030       ,p_line_definition_owner_code => l_line_definition_owner_code
17031       ,p_line_definition_code       => l_line_definition_code
17032       ,p_accounting_line_code       => l_component_code
17033       ,p_accounting_line_type_code  => l_component_type_code
17034       ,p_accounting_line_appl_id    => l_component_appl_id
17035       ,p_amb_context_code           => l_amb_context_code
17036       ,p_entity_code                => l_entity_code
17037       ,p_event_class_code           => l_event_class_code);
17038    --
17039    -- set accounting class
17040    --
17041    xla_ae_lines_pkg.SetAcctClass(
17042            p_accounting_class_code  => 'RECEIVABLE'
17043          , p_ae_header_id           => l_ae_header_id
17044          );
17045 
17046    --
17047    -- set rounding class
17048    --
17049    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
17050                       'RECEIVABLE';
17051 
17052    --
17053    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
17054    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
17055    --
17056    -- bulk performance
17057    --
17058    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
17059 
17060    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
17061       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
17062 
17063    -- 4955764
17064    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
17065       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
17066 
17067    -- 4458381 Public Sector Enh
17068    
17069    --
17070    -- set accounting attributes for the line type
17071    --
17072    l_entered_amt_idx := 3;
17073    l_accted_amt_idx  := 8;
17074    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
17075    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
17076    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
17077    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
17078    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
17079    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
17080    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
17081    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
17085    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
17082    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
17083    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
17084    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
17086    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
17087    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
17088    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
17089    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
17090    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
17091    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
17092    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
17093    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
17094    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
17095    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
17096    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
17097 
17098    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
17099    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
17100 
17101    ---------------------------------------------------------------------------------------------------------------
17102    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
17103    ---------------------------------------------------------------------------------------------------------------
17104    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
17105 
17106    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
17107    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
17108 
17109    IF xla_accounting_cache_pkg.GetValueChar
17110          (p_source_code         => 'LEDGER_CATEGORY_CODE'
17111          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
17112    AND l_bflow_method_code = 'PRIOR_ENTRY'
17113 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
17114    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
17115          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
17116        )
17117    THEN
17118          xla_ae_lines_pkg.BflowUpgEntry
17119            (p_business_method_code    => l_bflow_method_code
17120            ,p_business_class_code     => l_bflow_class_code
17121            ,p_balance_type            => l_balance_type_code);
17122    ELSE
17123       NULL;
17124 -- No business flow processing for business flow method of NONE.
17125    END IF;
17126 
17127    --
17128    -- call analytical criteria
17129    --
17130    
17131    --
17132    -- call description
17133    --
17134    -- No description or it is inherited.
17135    --
17136    -- call ADRs
17137    -- Bug 4922099
17138    --
17139    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
17140         (NVL(l_actual_upg_option, 'N') = 'O') OR
17141         (NVL(l_enc_upg_option, 'N') = 'O')
17142       )
17143    THEN
17144    NULL;
17145    --
17146    --
17147    
17148   l_ccid := AcctDerRule_16(
17149            p_application_id           => p_application_id
17150          , p_ae_header_id             => l_ae_header_id 
17151 , p_source_4 => p_source_4
17152          , x_transaction_coa_id       => l_adr_transaction_coa_id
17153          , x_accounting_coa_id        => l_adr_accounting_coa_id
17154          , x_value_type_code          => l_adr_value_type_code
17155          , p_side                     => 'NA'
17156    );
17157 
17158    xla_ae_lines_pkg.set_ccid(
17159     p_code_combination_id          => l_ccid
17160   , p_value_type_code              => l_adr_value_type_code
17161   , p_transaction_coa_id           => l_adr_transaction_coa_id
17162   , p_accounting_coa_id            => l_adr_accounting_coa_id
17163   , p_adr_code                     => 'TRX_DIST_CCID'
17164   , p_adr_type_code                => 'S'
17165   , p_component_type               => l_component_type
17166   , p_component_code               => l_component_code
17167   , p_component_type_code          => l_component_type_code
17168   , p_component_appl_id            => l_component_appl_id
17169   , p_amb_context_code             => l_amb_context_code
17170   , p_side                         => 'NA'
17171   );
17172 
17173 
17174    --
17175    --
17176    END IF;
17177    --
17178    -- Bug 4922099
17179    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
17180           (NVL(l_enc_upg_option, 'N') = 'O')
17181         ) AND
17182         (l_bflow_method_code = 'PRIOR_ENTRY')
17183       )
17184    THEN
17185       IF
17186       --
17187       1 = 2
17188       --
17189       THEN
17190       xla_accounting_err_pkg.build_message
17191                                     (p_appli_s_name            => 'XLA'
17192                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
17193                                     ,p_token_1                 => 'LINE_NUMBER'
17194                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
17195                                     ,p_token_2                 => 'LINE_TYPE_NAME'
17196                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
17197                                                                              l_component_type
17198                                                                             ,l_component_code
17199                                                                             ,l_component_type_code
17200                                                                             ,l_component_appl_id
17201                                                                             ,l_amb_context_code
17202                                                                             ,l_entity_code
17203                                                                             ,l_event_class_code
17204                                                                            )
17205                                     ,p_token_3                 => 'OWNER'
17206                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
17207                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
17208                                                                           ,p_lookup_code    => l_component_type_code
17209                                                                          )
17210                                     ,p_token_4                 => 'PRODUCT_NAME'
17211                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
17212                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
17213                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
17214                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
17215                                     ,p_ae_header_id            =>  NULL
17216                                        );
17217 
17218         IF (C_LEVEL_ERROR>= g_log_level) THEN
17219                  trace
17220                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
17221                       ,p_level    => C_LEVEL_ERROR
17222                       ,p_module   => l_log_module);
17223         END IF;
17224       END IF;
17225    END IF;
17226    --
17227    --
17228    ------------------------------------------------------------------------------------------------
17229    -- 4219869 Business Flow
17230    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
17231    -- Prior Entry.  Currently, the following code is always generated.
17232    ------------------------------------------------------------------------------------------------
17233    XLA_AE_LINES_PKG.ValidateCurrentLine;
17234 
17235    ------------------------------------------------------------------------------------
17236    -- 4219869 Business Flow
17237    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
17238    ------------------------------------------------------------------------------------
17239    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
17240 
17241    ----------------------------------------------------------------------------------
17242    -- 4219869 Business Flow
17243    -- Update journal entry status -- Need to generate this within IF <condition>
17244    ----------------------------------------------------------------------------------
17245    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
17246          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
17247          ,p_balance_type_code => l_balance_type_code
17248          );
17249 
17250    -------------------------------------------------------------------------------------------
17251    -- 4262811 - Generate the Accrual Reversal lines
17252    -------------------------------------------------------------------------------------------
17253    BEGIN
17254       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
17255                               (g_array_event(p_event_id).array_value_num('header_index'));
17256       IF l_acc_rev_flag IS NULL THEN
17257          l_acc_rev_flag := 'N';
17258       END IF;
17259    EXCEPTION
17260       WHEN OTHERS THEN
17261          l_acc_rev_flag := 'N';
17262    END;
17263    --
17264    IF (l_acc_rev_flag = 'Y') THEN
17265 
17266        -- 4645092  ------------------------------------------------------------------------------
17267        -- To allow MPA report to determine if it should generate report process
17268        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
17269        ------------------------------------------------------------------------------------------
17270 
17271        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
17272        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
17273    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
17274    -- call ADRs
17275    -- Bug 4922099
17276    --
17277    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
17278         (NVL(l_actual_upg_option, 'N') = 'O') OR
17279         (NVL(l_enc_upg_option, 'N') = 'O')
17280       )
17281    THEN
17282    NULL;
17283    --
17284    --
17285    
17286   l_ccid := AcctDerRule_16(
17287            p_application_id           => p_application_id
17288          , p_ae_header_id             => l_ae_header_id 
17289 , p_source_4 => p_source_4
17290          , x_transaction_coa_id       => l_adr_transaction_coa_id
17291          , x_accounting_coa_id        => l_adr_accounting_coa_id
17292          , x_value_type_code          => l_adr_value_type_code
17293          , p_side                     => 'NA'
17294    );
17295 
17296    xla_ae_lines_pkg.set_ccid(
17297     p_code_combination_id          => l_ccid
17298   , p_value_type_code              => l_adr_value_type_code
17299   , p_transaction_coa_id           => l_adr_transaction_coa_id
17300   , p_accounting_coa_id            => l_adr_accounting_coa_id
17301   , p_adr_code                     => 'TRX_DIST_CCID'
17302   , p_adr_type_code                => 'S'
17306   , p_component_appl_id            => l_component_appl_id
17303   , p_component_type               => l_component_type
17304   , p_component_code               => l_component_code
17305   , p_component_type_code          => l_component_type_code
17307   , p_amb_context_code             => l_amb_context_code
17308   , p_side                         => 'NA'
17309   );
17310 
17311 
17312    --
17313    --
17314    END IF;
17315 
17316        --
17317        -- Update the line information that should be overwritten
17318        --
17319        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
17320                                          p_header_num   => 1);
17321        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
17322 
17323        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
17324 
17325        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
17326           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
17327        END IF;
17328 
17329       --
17330       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
17331       --
17332       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
17333           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
17334       ELSE
17335           ---------------------------------------------------------------------------------------------------
17336           -- 4262811a Switch Sign
17337           ---------------------------------------------------------------------------------------------------
17338           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
17339           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
17340                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
17341           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
17342                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
17343           -- 5132302
17344           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
17345                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
17346 
17347       END IF;
17348 
17349       -- 4955764
17350       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
17351       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
17352 
17353 
17354       XLA_AE_LINES_PKG.ValidateCurrentLine;
17355       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
17356 
17357       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
17358                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
17359                ,p_balance_type_code => l_balance_type_code);
17360 
17361    END IF;
17362 
17363    -----------------------------------------------------------------------------------------
17364    -- 4262811 Multiperiod Accounting
17365    -----------------------------------------------------------------------------------------
17366      -- No MPA option is assigned.
17367 
17368 
17369 END IF;
17370 END IF;
17371 --
17372 
17373 --
17374 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17375    trace
17376       (p_msg      => 'END of AcctLineType_43'
17377       ,p_level    => C_LEVEL_PROCEDURE
17378       ,p_module   => l_log_module);
17379 END IF;
17380 --
17381 EXCEPTION
17382   WHEN xla_exceptions_pkg.application_exception THEN
17383       RAISE;
17384   WHEN OTHERS THEN
17385        xla_exceptions_pkg.raise_message
17386            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_43');
17387 END AcctLineType_43;
17388 --
17389 
17390 ---------------------------------------
17391 --
17392 -- PRIVATE FUNCTION
17393 --         AcctLineType_44
17394 --
17395 ---------------------------------------
17396 PROCEDURE AcctLineType_44 (
17397   p_application_id        IN NUMBER
17398  ,p_event_id              IN NUMBER
17399  ,p_calculate_acctd_flag  IN VARCHAR2
17400  ,p_calculate_g_l_flag    IN VARCHAR2
17401  ,p_actual_flag           IN OUT VARCHAR2
17402  ,p_balance_type_code     OUT VARCHAR2
17403  ,p_gain_or_loss_ref      OUT VARCHAR2
17404  
17405 --Transaction Distribution GL Account
17406  , p_source_4            IN NUMBER
17407 --Bill To Customer Account Identifier
17408  , p_source_23            IN NUMBER
17409 --Bill To Customer Site Use Identifier
17410  , p_source_24            IN NUMBER
17411 --SLA Party Type
17412  , p_source_25            IN VARCHAR2
17413 --Transaction Distribution Account Class
17414  , p_source_26            IN VARCHAR2
17415 --Transaction Distribution Identifier
17416  , p_source_27            IN NUMBER
17417 --Transaction Distribution Type
17418  , p_source_28            IN VARCHAR2
17419 --Transaction Distribution Entered Amount
17420  , p_source_29            IN NUMBER
17421 --Transaction Currency Code
17422  , p_source_30            IN VARCHAR2
17423 --Transaction Exchange Date
17424  , p_source_31            IN DATE
17425 --Transaction Exchange Rate
17426  , p_source_32            IN NUMBER
17427 --Transaction Exchange Rate Type
17428  , p_source_33            IN VARCHAR2
17429 --Transaction Accounting Amount
17430  , p_source_34            IN NUMBER
17431 )
17432 IS
17433 
17434 l_component_type              VARCHAR2(80);
17435 l_component_code              VARCHAR2(30);
17436 l_component_type_code         VARCHAR2(1);
17437 l_component_appl_id           INTEGER;
17438 l_amb_context_code            VARCHAR2(30);
17439 l_entity_code                 VARCHAR2(30);
17440 l_event_class_code            VARCHAR2(30);
17441 l_ae_header_id                NUMBER;
17442 l_event_type_code             VARCHAR2(30);
17443 l_line_definition_code        VARCHAR2(30);
17444 l_line_definition_owner_code  VARCHAR2(1);
17445 --
17446 -- adr variables
17447 l_segment                     VARCHAR2(30);
17448 l_ccid                        NUMBER;
17449 l_adr_transaction_coa_id      NUMBER;
17450 l_adr_accounting_coa_id       NUMBER;
17451 l_adr_flexfield_segment_code  VARCHAR2(30);
17452 l_adr_flex_value_set_id       NUMBER;
17453 l_adr_value_type_code         VARCHAR2(30);
17454 l_adr_value_combination_id    NUMBER;
17455 l_adr_value_segment_code      VARCHAR2(30);
17456 
17457 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
17458 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
17459 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
17460 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
17461 
17462 -- 4262811 Variables ------------------------------------------------------------------------------------------
17463 l_entered_amt_idx             NUMBER;
17464 l_accted_amt_idx              NUMBER;
17465 l_acc_rev_flag                VARCHAR2(1);
17466 l_accrual_line_num            NUMBER;
17467 l_tmp_amt                     NUMBER;
17468 l_acc_rev_natural_side_code   VARCHAR2(1);
17469 
17470 l_num_entries                 NUMBER;
17471 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
17472 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
17473 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
17474 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
17475 l_recog_line_1                NUMBER;
17476 l_recog_line_2                NUMBER;
17477 
17478 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
17479 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
17480 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
17481 
17482 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
17483 
17484 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
17485 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
17486 
17487 ---------------------------------------------------------------------------------------------------------------
17488 
17489 
17490 --
17491 -- bulk performance
17492 --
17493 l_balance_type_code           VARCHAR2(1);
17494 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
17495 l_log_module                  VARCHAR2(240);
17496 
17497 --
17498 -- Upgrade strategy
17499 --
17500 l_actual_upg_option           VARCHAR2(1);
17501 l_enc_upg_option           VARCHAR2(1);
17502 
17503 --
17504 BEGIN
17505 --
17506 IF g_log_enabled THEN
17510 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17507       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_44';
17508 END IF;
17509 --
17511 
17512       trace
17513          (p_msg      => 'BEGIN of AcctLineType_44'
17514          ,p_level    => C_LEVEL_PROCEDURE
17515          ,p_module   => l_log_module);
17516 
17517 END IF;
17518 --
17519 l_component_type             := 'AMB_JLT';
17520 l_component_code             := 'GUAR_REV';
17521 l_component_type_code        := 'S';
17522 l_component_appl_id          :=  222;
17523 l_amb_context_code           := 'DEFAULT';
17524 l_entity_code                := 'TRANSACTIONS';
17525 l_event_class_code           := 'GUARANTEE';
17526 l_event_type_code            := 'GUARANTEE_ALL';
17527 l_line_definition_owner_code := 'S';
17528 l_line_definition_code       := 'AR_GUAR_DEFAULT_ACCRUAL';
17529 --
17530 l_balance_type_code          := 'A';
17531 l_segment                     := NULL;
17532 l_ccid                        := NULL;
17533 l_adr_transaction_coa_id      := NULL;
17534 l_adr_accounting_coa_id       := NULL;
17535 l_adr_flexfield_segment_code  := NULL;
17536 l_adr_flex_value_set_id       := NULL;
17537 l_adr_value_type_code         := NULL;
17538 l_adr_value_combination_id    := NULL;
17539 l_adr_value_segment_code      := NULL;
17540 
17541 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
17542 l_bflow_class_code           := '';    -- 4219869 Business Flow
17543 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
17544 l_budgetary_control_flag     := 'N';
17545 
17546 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
17547 l_bflow_applied_to_amt       := NULL; -- 5132302
17548 l_entered_amt_idx            := NULL;          -- 4262811
17549 l_accted_amt_idx             := NULL;          -- 4262811
17550 l_acc_rev_flag               := NULL;          -- 4262811
17551 l_accrual_line_num           := NULL;          -- 4262811
17552 l_tmp_amt                    := NULL;          -- 4262811
17553 --
17554  
17555 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
17556     l_balance_type_code <> 'B' THEN
17557 IF NVL(p_source_26,'
17558 ') =  'REV'
17559  THEN 
17560 
17561    --
17562    XLA_AE_LINES_PKG.SetNewLine;
17563 
17564    p_balance_type_code          := l_balance_type_code;
17565    -- set the flag so later we will know whether the gain loss line needs to be created
17566    
17567    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
17568      p_actual_flag :='A';
17569    END IF;
17570 
17571    --
17572    -- bulk performance
17573    --
17574    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
17575                                       p_header_num   => 0); -- 4262811
17576    --
17577    -- set accounting line options
17578    --
17579    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
17580            p_natural_side_code          => 'C'
17581          , p_gain_or_loss_flag          => 'N'
17582          , p_gl_transfer_mode_code      => 'S'
17583          , p_acct_entry_type_code       => 'A'
17584          , p_switch_side_flag           => 'Y'
17585          , p_merge_duplicate_code       => 'A'
17586          );
17587    --
17588    l_acc_rev_natural_side_code := 'D';  -- 4262811
17589    -- 
17590    --
17591    -- set accounting line type info
17592    --
17593    xla_ae_lines_pkg.SetAcctLineType
17594       (p_component_type             => l_component_type
17595       ,p_event_type_code            => l_event_type_code
17596       ,p_line_definition_owner_code => l_line_definition_owner_code
17597       ,p_line_definition_code       => l_line_definition_code
17598       ,p_accounting_line_code       => l_component_code
17599       ,p_accounting_line_type_code  => l_component_type_code
17600       ,p_accounting_line_appl_id    => l_component_appl_id
17601       ,p_amb_context_code           => l_amb_context_code
17602       ,p_entity_code                => l_entity_code
17603       ,p_event_class_code           => l_event_class_code);
17604    --
17605    -- set accounting class
17606    --
17607    xla_ae_lines_pkg.SetAcctClass(
17608            p_accounting_class_code  => 'REVENUE'
17609          , p_ae_header_id           => l_ae_header_id
17610          );
17611 
17612    --
17613    -- set rounding class
17614    --
17615    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
17616                       'RECEIVABLE';
17617 
17618    --
17619    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
17620    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
17621    --
17622    -- bulk performance
17623    --
17624    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
17625 
17626    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
17627       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
17628 
17629    -- 4955764
17630    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
17631       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
17632 
17633    -- 4458381 Public Sector Enh
17634    
17635    --
17636    -- set accounting attributes for the line type
17637    --
17638    l_entered_amt_idx := 3;
17639    l_accted_amt_idx  := 8;
17640    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
17641    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
17642    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
17643    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
17644    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
17645    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
17646    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
17647    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
17648    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
17649    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
17650    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
17651    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
17652    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
17653    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
17654    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
17655    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
17656    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
17657    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
17658    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
17659    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
17660    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
17661    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
17662    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
17663 
17664    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
17665    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
17666 
17667    ---------------------------------------------------------------------------------------------------------------
17668    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
17669    ---------------------------------------------------------------------------------------------------------------
17670    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
17671 
17672    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
17673    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
17674 
17675    IF xla_accounting_cache_pkg.GetValueChar
17676          (p_source_code         => 'LEDGER_CATEGORY_CODE'
17677          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
17678    AND l_bflow_method_code = 'PRIOR_ENTRY'
17679 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
17680    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
17681          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
17682        )
17683    THEN
17684          xla_ae_lines_pkg.BflowUpgEntry
17685            (p_business_method_code    => l_bflow_method_code
17686            ,p_business_class_code     => l_bflow_class_code
17687            ,p_balance_type            => l_balance_type_code);
17688    ELSE
17689       NULL;
17690 -- No business flow processing for business flow method of NONE.
17691    END IF;
17692 
17693    --
17694    -- call analytical criteria
17695    --
17696    
17697    --
17698    -- call description
17699    --
17700    -- No description or it is inherited.
17701    --
17702    -- call ADRs
17703    -- Bug 4922099
17704    --
17705    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
17706         (NVL(l_actual_upg_option, 'N') = 'O') OR
17707         (NVL(l_enc_upg_option, 'N') = 'O')
17708       )
17709    THEN
17710    NULL;
17711    --
17712    --
17713    
17714   l_ccid := AcctDerRule_16(
17715            p_application_id           => p_application_id
17716          , p_ae_header_id             => l_ae_header_id 
17717 , p_source_4 => p_source_4
17718          , x_transaction_coa_id       => l_adr_transaction_coa_id
17719          , x_accounting_coa_id        => l_adr_accounting_coa_id
17720          , x_value_type_code          => l_adr_value_type_code
17721          , p_side                     => 'NA'
17722    );
17723 
17724    xla_ae_lines_pkg.set_ccid(
17725     p_code_combination_id          => l_ccid
17726   , p_value_type_code              => l_adr_value_type_code
17727   , p_transaction_coa_id           => l_adr_transaction_coa_id
17728   , p_accounting_coa_id            => l_adr_accounting_coa_id
17729   , p_adr_code                     => 'TRX_DIST_CCID'
17730   , p_adr_type_code                => 'S'
17731   , p_component_type               => l_component_type
17732   , p_component_code               => l_component_code
17733   , p_component_type_code          => l_component_type_code
17734   , p_component_appl_id            => l_component_appl_id
17735   , p_amb_context_code             => l_amb_context_code
17736   , p_side                         => 'NA'
17737   );
17738 
17739 
17740    --
17741    --
17742    END IF;
17743    --
17744    -- Bug 4922099
17745    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
17746           (NVL(l_enc_upg_option, 'N') = 'O')
17747         ) AND
17748         (l_bflow_method_code = 'PRIOR_ENTRY')
17749       )
17750    THEN
17751       IF
17752       --
17753       1 = 2
17754       --
17755       THEN
17756       xla_accounting_err_pkg.build_message
17757                                     (p_appli_s_name            => 'XLA'
17758                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
17759                                     ,p_token_1                 => 'LINE_NUMBER'
17760                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
17761                                     ,p_token_2                 => 'LINE_TYPE_NAME'
17762                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
17763                                                                              l_component_type
17764                                                                             ,l_component_code
17765                                                                             ,l_component_type_code
17766                                                                             ,l_component_appl_id
17767                                                                             ,l_amb_context_code
17768                                                                             ,l_entity_code
17769                                                                             ,l_event_class_code
17770                                                                            )
17771                                     ,p_token_3                 => 'OWNER'
17772                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
17773                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
17774                                                                           ,p_lookup_code    => l_component_type_code
17775                                                                          )
17776                                     ,p_token_4                 => 'PRODUCT_NAME'
17777                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
17778                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
17779                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
17780                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
17781                                     ,p_ae_header_id            =>  NULL
17782                                        );
17783 
17784         IF (C_LEVEL_ERROR>= g_log_level) THEN
17785                  trace
17786                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
17787                       ,p_level    => C_LEVEL_ERROR
17788                       ,p_module   => l_log_module);
17789         END IF;
17790       END IF;
17791    END IF;
17792    --
17793    --
17794    ------------------------------------------------------------------------------------------------
17795    -- 4219869 Business Flow
17796    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
17797    -- Prior Entry.  Currently, the following code is always generated.
17798    ------------------------------------------------------------------------------------------------
17799    XLA_AE_LINES_PKG.ValidateCurrentLine;
17800 
17801    ------------------------------------------------------------------------------------
17802    -- 4219869 Business Flow
17803    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
17804    ------------------------------------------------------------------------------------
17805    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
17806 
17807    ----------------------------------------------------------------------------------
17808    -- 4219869 Business Flow
17809    -- Update journal entry status -- Need to generate this within IF <condition>
17810    ----------------------------------------------------------------------------------
17811    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
17812          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
17813          ,p_balance_type_code => l_balance_type_code
17814          );
17815 
17816    -------------------------------------------------------------------------------------------
17817    -- 4262811 - Generate the Accrual Reversal lines
17818    -------------------------------------------------------------------------------------------
17819    BEGIN
17820       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
17821                               (g_array_event(p_event_id).array_value_num('header_index'));
17822       IF l_acc_rev_flag IS NULL THEN
17823          l_acc_rev_flag := 'N';
17824       END IF;
17825    EXCEPTION
17826       WHEN OTHERS THEN
17827          l_acc_rev_flag := 'N';
17828    END;
17829    --
17830    IF (l_acc_rev_flag = 'Y') THEN
17831 
17832        -- 4645092  ------------------------------------------------------------------------------
17833        -- To allow MPA report to determine if it should generate report process
17834        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
17835        ------------------------------------------------------------------------------------------
17836 
17837        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
17838        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
17839    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
17840    -- call ADRs
17841    -- Bug 4922099
17842    --
17843    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
17844         (NVL(l_actual_upg_option, 'N') = 'O') OR
17845         (NVL(l_enc_upg_option, 'N') = 'O')
17846       )
17847    THEN
17848    NULL;
17849    --
17850    --
17851    
17852   l_ccid := AcctDerRule_16(
17853            p_application_id           => p_application_id
17854          , p_ae_header_id             => l_ae_header_id 
17855 , p_source_4 => p_source_4
17856          , x_transaction_coa_id       => l_adr_transaction_coa_id
17857          , x_accounting_coa_id        => l_adr_accounting_coa_id
17858          , x_value_type_code          => l_adr_value_type_code
17859          , p_side                     => 'NA'
17860    );
17861 
17862    xla_ae_lines_pkg.set_ccid(
17863     p_code_combination_id          => l_ccid
17864   , p_value_type_code              => l_adr_value_type_code
17865   , p_transaction_coa_id           => l_adr_transaction_coa_id
17866   , p_accounting_coa_id            => l_adr_accounting_coa_id
17867   , p_adr_code                     => 'TRX_DIST_CCID'
17868   , p_adr_type_code                => 'S'
17869   , p_component_type               => l_component_type
17870   , p_component_code               => l_component_code
17871   , p_component_type_code          => l_component_type_code
17872   , p_component_appl_id            => l_component_appl_id
17873   , p_amb_context_code             => l_amb_context_code
17874   , p_side                         => 'NA'
17875   );
17876 
17877 
17878    --
17879    --
17880    END IF;
17881 
17882        --
17883        -- Update the line information that should be overwritten
17884        --
17885        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
17886                                          p_header_num   => 1);
17887        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
17888 
17889        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
17890 
17891        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
17892           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
17893        END IF;
17894 
17895       --
17896       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
17897       --
17898       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
17899           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
17900       ELSE
17901           ---------------------------------------------------------------------------------------------------
17902           -- 4262811a Switch Sign
17903           ---------------------------------------------------------------------------------------------------
17904           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
17905           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
17906                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
17907           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
17908                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
17909           -- 5132302
17910           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
17911                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
17912 
17913       END IF;
17914 
17915       -- 4955764
17916       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
17917       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
17918 
17919 
17920       XLA_AE_LINES_PKG.ValidateCurrentLine;
17921       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
17922 
17923       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
17924                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
17925                ,p_balance_type_code => l_balance_type_code);
17926 
17927    END IF;
17928 
17929    -----------------------------------------------------------------------------------------
17930    -- 4262811 Multiperiod Accounting
17931    -----------------------------------------------------------------------------------------
17932      -- No MPA option is assigned.
17933 
17934 
17935 END IF;
17936 END IF;
17937 --
17938 
17939 --
17940 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17941    trace
17942       (p_msg      => 'END of AcctLineType_44'
17943       ,p_level    => C_LEVEL_PROCEDURE
17944       ,p_module   => l_log_module);
17945 END IF;
17946 --
17947 EXCEPTION
17948   WHEN xla_exceptions_pkg.application_exception THEN
17949       RAISE;
17950   WHEN OTHERS THEN
17951        xla_exceptions_pkg.raise_message
17952            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_44');
17953 END AcctLineType_44;
17954 --
17955 
17956 ---------------------------------------
17957 --
17958 -- PRIVATE FUNCTION
17959 --         AcctLineType_45
17960 --
17961 ---------------------------------------
17962 PROCEDURE AcctLineType_45 (
17963   p_application_id        IN NUMBER
17964  ,p_event_id              IN NUMBER
17965  ,p_calculate_acctd_flag  IN VARCHAR2
17966  ,p_calculate_g_l_flag    IN VARCHAR2
17967  ,p_actual_flag           IN OUT VARCHAR2
17968  ,p_balance_type_code     OUT VARCHAR2
17969  ,p_gain_or_loss_ref      OUT VARCHAR2
17970  
17971 --Transaction Distribution GL Account
17972  , p_source_4            IN NUMBER
17973 --Bill To Customer Account Identifier
17974  , p_source_23            IN NUMBER
17975 --Bill To Customer Site Use Identifier
17976  , p_source_24            IN NUMBER
17977 --SLA Party Type
17978  , p_source_25            IN VARCHAR2
17979 --Transaction Distribution Account Class
17980  , p_source_26            IN VARCHAR2
17981 --Transaction Distribution Identifier
17982  , p_source_27            IN NUMBER
17983 --Transaction Distribution Type
17984  , p_source_28            IN VARCHAR2
17985 --Transaction Distribution Entered Amount
17986  , p_source_29            IN NUMBER
17987 --Transaction Currency Code
17988  , p_source_30            IN VARCHAR2
17989 --Transaction Exchange Date
17990  , p_source_31            IN DATE
17991 --Transaction Exchange Rate
17992  , p_source_32            IN NUMBER
17993 --Transaction Exchange Rate Type
17994  , p_source_33            IN VARCHAR2
17995 --Transaction Accounting Amount
17996  , p_source_34            IN NUMBER
17997 --Transaction Tax Line Identifier
17998  , p_source_48            IN NUMBER
17999 )
18000 IS
18001 
18002 l_component_type              VARCHAR2(80);
18003 l_component_code              VARCHAR2(30);
18004 l_component_type_code         VARCHAR2(1);
18005 l_component_appl_id           INTEGER;
18006 l_amb_context_code            VARCHAR2(30);
18007 l_entity_code                 VARCHAR2(30);
18008 l_event_class_code            VARCHAR2(30);
18009 l_ae_header_id                NUMBER;
18010 l_event_type_code             VARCHAR2(30);
18011 l_line_definition_code        VARCHAR2(30);
18012 l_line_definition_owner_code  VARCHAR2(1);
18013 --
18014 -- adr variables
18015 l_segment                     VARCHAR2(30);
18016 l_ccid                        NUMBER;
18017 l_adr_transaction_coa_id      NUMBER;
18018 l_adr_accounting_coa_id       NUMBER;
18019 l_adr_flexfield_segment_code  VARCHAR2(30);
18020 l_adr_flex_value_set_id       NUMBER;
18021 l_adr_value_type_code         VARCHAR2(30);
18022 l_adr_value_combination_id    NUMBER;
18023 l_adr_value_segment_code      VARCHAR2(30);
18024 
18025 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
18026 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
18027 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
18028 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
18029 
18030 -- 4262811 Variables ------------------------------------------------------------------------------------------
18031 l_entered_amt_idx             NUMBER;
18032 l_accted_amt_idx              NUMBER;
18033 l_acc_rev_flag                VARCHAR2(1);
18034 l_accrual_line_num            NUMBER;
18035 l_tmp_amt                     NUMBER;
18036 l_acc_rev_natural_side_code   VARCHAR2(1);
18037 
18038 l_num_entries                 NUMBER;
18039 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
18040 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
18041 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
18042 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
18043 l_recog_line_1                NUMBER;
18044 l_recog_line_2                NUMBER;
18045 
18046 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
18047 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
18048 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
18049 
18050 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
18051 
18052 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
18053 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
18054 
18055 ---------------------------------------------------------------------------------------------------------------
18056 
18057 
18058 --
18059 -- bulk performance
18060 --
18061 l_balance_type_code           VARCHAR2(1);
18062 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
18063 l_log_module                  VARCHAR2(240);
18064 
18065 --
18066 -- Upgrade strategy
18067 --
18068 l_actual_upg_option           VARCHAR2(1);
18069 l_enc_upg_option           VARCHAR2(1);
18070 
18071 --
18072 BEGIN
18073 --
18074 IF g_log_enabled THEN
18075       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_45';
18076 END IF;
18077 --
18078 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18079 
18080       trace
18081          (p_msg      => 'BEGIN of AcctLineType_45'
18082          ,p_level    => C_LEVEL_PROCEDURE
18083          ,p_module   => l_log_module);
18084 
18085 END IF;
18086 --
18087 l_component_type             := 'AMB_JLT';
18088 l_component_code             := 'INV_CHARGES';
18089 l_component_type_code        := 'S';
18090 l_component_appl_id          :=  222;
18091 l_amb_context_code           := 'DEFAULT';
18092 l_entity_code                := 'TRANSACTIONS';
18093 l_event_class_code           := 'INVOICE';
18094 l_event_type_code            := 'INVOICE_ALL';
18095 l_line_definition_owner_code := 'S';
18096 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
18097 --
18098 l_balance_type_code          := 'A';
18099 l_segment                     := NULL;
18100 l_ccid                        := NULL;
18101 l_adr_transaction_coa_id      := NULL;
18102 l_adr_accounting_coa_id       := NULL;
18103 l_adr_flexfield_segment_code  := NULL;
18104 l_adr_flex_value_set_id       := NULL;
18105 l_adr_value_type_code         := NULL;
18106 l_adr_value_combination_id    := NULL;
18107 l_adr_value_segment_code      := NULL;
18108 
18109 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
18110 l_bflow_class_code           := '';    -- 4219869 Business Flow
18111 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
18112 l_budgetary_control_flag     := 'N';
18113 
18114 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
18115 l_bflow_applied_to_amt       := NULL; -- 5132302
18116 l_entered_amt_idx            := NULL;          -- 4262811
18117 l_accted_amt_idx             := NULL;          -- 4262811
18118 l_acc_rev_flag               := NULL;          -- 4262811
18119 l_accrual_line_num           := NULL;          -- 4262811
18120 l_tmp_amt                    := NULL;          -- 4262811
18121 --
18122  
18123 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
18124     l_balance_type_code <> 'B' THEN
18125 IF NVL(p_source_26,'
18126 ') =  'CHARGES'
18127  THEN 
18128 
18129    --
18130    XLA_AE_LINES_PKG.SetNewLine;
18131 
18132    p_balance_type_code          := l_balance_type_code;
18133    -- set the flag so later we will know whether the gain loss line needs to be created
18134    
18135    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
18136      p_actual_flag :='A';
18137    END IF;
18138 
18139    --
18140    -- bulk performance
18141    --
18142    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
18143                                       p_header_num   => 0); -- 4262811
18144    --
18145    -- set accounting line options
18146    --
18147    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
18148            p_natural_side_code          => 'C'
18149          , p_gain_or_loss_flag          => 'N'
18150          , p_gl_transfer_mode_code      => 'S'
18151          , p_acct_entry_type_code       => 'A'
18152          , p_switch_side_flag           => 'Y'
18153          , p_merge_duplicate_code       => 'A'
18154          );
18155    --
18156    l_acc_rev_natural_side_code := 'D';  -- 4262811
18157    -- 
18158    --
18159    -- set accounting line type info
18160    --
18161    xla_ae_lines_pkg.SetAcctLineType
18162       (p_component_type             => l_component_type
18163       ,p_event_type_code            => l_event_type_code
18164       ,p_line_definition_owner_code => l_line_definition_owner_code
18165       ,p_line_definition_code       => l_line_definition_code
18166       ,p_accounting_line_code       => l_component_code
18167       ,p_accounting_line_type_code  => l_component_type_code
18168       ,p_accounting_line_appl_id    => l_component_appl_id
18169       ,p_amb_context_code           => l_amb_context_code
18170       ,p_entity_code                => l_entity_code
18171       ,p_event_class_code           => l_event_class_code);
18172    --
18173    -- set accounting class
18174    --
18175    xla_ae_lines_pkg.SetAcctClass(
18176            p_accounting_class_code  => 'CHARGES'
18177          , p_ae_header_id           => l_ae_header_id
18178          );
18179 
18180    --
18181    -- set rounding class
18182    --
18183    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
18184                       'RECEIVABLE';
18185 
18186    --
18187    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
18188    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
18189    --
18190    -- bulk performance
18191    --
18192    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
18193 
18194    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
18195       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
18196 
18197    -- 4955764
18198    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
18199       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
18200 
18201    -- 4458381 Public Sector Enh
18202    
18203    --
18204    -- set accounting attributes for the line type
18205    --
18206    l_entered_amt_idx := 3;
18207    l_accted_amt_idx  := 8;
18208    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
18209    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
18210    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
18211    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
18212    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
18213    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
18214    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
18215    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
18216    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
18217    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
18218    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
18219    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
18220    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
18221    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
18222    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
18223    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
18224    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
18225    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
18226    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
18227    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
18228    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
18229    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
18230    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
18231    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
18232    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
18233 
18234    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
18235    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
18236 
18237    ---------------------------------------------------------------------------------------------------------------
18238    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
18239    ---------------------------------------------------------------------------------------------------------------
18240    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
18241 
18242    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
18243    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
18244 
18245    IF xla_accounting_cache_pkg.GetValueChar
18246          (p_source_code         => 'LEDGER_CATEGORY_CODE'
18247          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
18248    AND l_bflow_method_code = 'PRIOR_ENTRY'
18249 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
18250    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
18251          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
18252        )
18253    THEN
18254          xla_ae_lines_pkg.BflowUpgEntry
18255            (p_business_method_code    => l_bflow_method_code
18256            ,p_business_class_code     => l_bflow_class_code
18257            ,p_balance_type            => l_balance_type_code);
18258    ELSE
18259       NULL;
18260 -- No business flow processing for business flow method of NONE.
18261    END IF;
18262 
18263    --
18264    -- call analytical criteria
18265    --
18266    
18267    --
18268    -- call description
18269    --
18270    -- No description or it is inherited.
18271    --
18272    -- call ADRs
18273    -- Bug 4922099
18274    --
18275    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
18276         (NVL(l_actual_upg_option, 'N') = 'O') OR
18277         (NVL(l_enc_upg_option, 'N') = 'O')
18278       )
18279    THEN
18280    NULL;
18281    --
18282    --
18283    
18284   l_ccid := AcctDerRule_16(
18285            p_application_id           => p_application_id
18286          , p_ae_header_id             => l_ae_header_id 
18287 , p_source_4 => p_source_4
18288          , x_transaction_coa_id       => l_adr_transaction_coa_id
18289          , x_accounting_coa_id        => l_adr_accounting_coa_id
18290          , x_value_type_code          => l_adr_value_type_code
18291          , p_side                     => 'NA'
18292    );
18293 
18294    xla_ae_lines_pkg.set_ccid(
18295     p_code_combination_id          => l_ccid
18296   , p_value_type_code              => l_adr_value_type_code
18297   , p_transaction_coa_id           => l_adr_transaction_coa_id
18298   , p_accounting_coa_id            => l_adr_accounting_coa_id
18299   , p_adr_code                     => 'TRX_DIST_CCID'
18300   , p_adr_type_code                => 'S'
18301   , p_component_type               => l_component_type
18302   , p_component_code               => l_component_code
18303   , p_component_type_code          => l_component_type_code
18304   , p_component_appl_id            => l_component_appl_id
18305   , p_amb_context_code             => l_amb_context_code
18306   , p_side                         => 'NA'
18307   );
18308 
18309 
18310    --
18311    --
18312    END IF;
18313    --
18314    -- Bug 4922099
18315    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
18316           (NVL(l_enc_upg_option, 'N') = 'O')
18317         ) AND
18318         (l_bflow_method_code = 'PRIOR_ENTRY')
18319       )
18320    THEN
18321       IF
18322       --
18323       1 = 2
18324       --
18325       THEN
18326       xla_accounting_err_pkg.build_message
18327                                     (p_appli_s_name            => 'XLA'
18328                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
18329                                     ,p_token_1                 => 'LINE_NUMBER'
18330                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
18331                                     ,p_token_2                 => 'LINE_TYPE_NAME'
18332                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
18333                                                                              l_component_type
18334                                                                             ,l_component_code
18335                                                                             ,l_component_type_code
18336                                                                             ,l_component_appl_id
18337                                                                             ,l_amb_context_code
18338                                                                             ,l_entity_code
18339                                                                             ,l_event_class_code
18340                                                                            )
18341                                     ,p_token_3                 => 'OWNER'
18342                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
18343                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
18344                                                                           ,p_lookup_code    => l_component_type_code
18345                                                                          )
18346                                     ,p_token_4                 => 'PRODUCT_NAME'
18347                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
18348                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
18349                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
18350                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
18351                                     ,p_ae_header_id            =>  NULL
18352                                        );
18353 
18354         IF (C_LEVEL_ERROR>= g_log_level) THEN
18355                  trace
18356                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
18357                       ,p_level    => C_LEVEL_ERROR
18358                       ,p_module   => l_log_module);
18359         END IF;
18360       END IF;
18361    END IF;
18362    --
18363    --
18364    ------------------------------------------------------------------------------------------------
18365    -- 4219869 Business Flow
18366    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
18367    -- Prior Entry.  Currently, the following code is always generated.
18368    ------------------------------------------------------------------------------------------------
18369    XLA_AE_LINES_PKG.ValidateCurrentLine;
18370 
18371    ------------------------------------------------------------------------------------
18372    -- 4219869 Business Flow
18373    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
18374    ------------------------------------------------------------------------------------
18375    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
18376 
18377    ----------------------------------------------------------------------------------
18378    -- 4219869 Business Flow
18379    -- Update journal entry status -- Need to generate this within IF <condition>
18380    ----------------------------------------------------------------------------------
18381    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
18382          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
18383          ,p_balance_type_code => l_balance_type_code
18384          );
18385 
18386    -------------------------------------------------------------------------------------------
18387    -- 4262811 - Generate the Accrual Reversal lines
18388    -------------------------------------------------------------------------------------------
18389    BEGIN
18390       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
18391                               (g_array_event(p_event_id).array_value_num('header_index'));
18392       IF l_acc_rev_flag IS NULL THEN
18393          l_acc_rev_flag := 'N';
18394       END IF;
18395    EXCEPTION
18396       WHEN OTHERS THEN
18397          l_acc_rev_flag := 'N';
18398    END;
18399    --
18400    IF (l_acc_rev_flag = 'Y') THEN
18401 
18402        -- 4645092  ------------------------------------------------------------------------------
18403        -- To allow MPA report to determine if it should generate report process
18404        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
18405        ------------------------------------------------------------------------------------------
18406 
18407        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
18408        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
18409    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
18410    -- call ADRs
18411    -- Bug 4922099
18412    --
18413    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
18414         (NVL(l_actual_upg_option, 'N') = 'O') OR
18415         (NVL(l_enc_upg_option, 'N') = 'O')
18416       )
18417    THEN
18418    NULL;
18419    --
18420    --
18421    
18422   l_ccid := AcctDerRule_16(
18423            p_application_id           => p_application_id
18424          , p_ae_header_id             => l_ae_header_id 
18425 , p_source_4 => p_source_4
18426          , x_transaction_coa_id       => l_adr_transaction_coa_id
18427          , x_accounting_coa_id        => l_adr_accounting_coa_id
18428          , x_value_type_code          => l_adr_value_type_code
18429          , p_side                     => 'NA'
18430    );
18431 
18432    xla_ae_lines_pkg.set_ccid(
18433     p_code_combination_id          => l_ccid
18434   , p_value_type_code              => l_adr_value_type_code
18435   , p_transaction_coa_id           => l_adr_transaction_coa_id
18436   , p_accounting_coa_id            => l_adr_accounting_coa_id
18437   , p_adr_code                     => 'TRX_DIST_CCID'
18438   , p_adr_type_code                => 'S'
18439   , p_component_type               => l_component_type
18440   , p_component_code               => l_component_code
18441   , p_component_type_code          => l_component_type_code
18442   , p_component_appl_id            => l_component_appl_id
18443   , p_amb_context_code             => l_amb_context_code
18444   , p_side                         => 'NA'
18445   );
18446 
18447 
18448    --
18449    --
18450    END IF;
18451 
18452        --
18453        -- Update the line information that should be overwritten
18454        --
18455        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
18456                                          p_header_num   => 1);
18457        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
18458 
18459        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
18460 
18461        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
18462           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
18463        END IF;
18464 
18465       --
18466       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
18467       --
18468       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
18469           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
18470       ELSE
18471           ---------------------------------------------------------------------------------------------------
18472           -- 4262811a Switch Sign
18473           ---------------------------------------------------------------------------------------------------
18474           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
18475           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
18476                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
18477           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
18478                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
18479           -- 5132302
18480           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
18481                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
18482 
18483       END IF;
18484 
18485       -- 4955764
18486       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
18487       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
18488 
18489 
18490       XLA_AE_LINES_PKG.ValidateCurrentLine;
18491       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
18492 
18493       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
18494                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
18495                ,p_balance_type_code => l_balance_type_code);
18496 
18497    END IF;
18498 
18499    -----------------------------------------------------------------------------------------
18500    -- 4262811 Multiperiod Accounting
18501    -----------------------------------------------------------------------------------------
18502      -- No MPA option is assigned.
18503 
18504 
18505 END IF;
18506 END IF;
18507 --
18508 
18509 --
18510 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18511    trace
18512       (p_msg      => 'END of AcctLineType_45'
18513       ,p_level    => C_LEVEL_PROCEDURE
18514       ,p_module   => l_log_module);
18515 END IF;
18516 --
18517 EXCEPTION
18518   WHEN xla_exceptions_pkg.application_exception THEN
18519       RAISE;
18520   WHEN OTHERS THEN
18521        xla_exceptions_pkg.raise_message
18522            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_45');
18523 END AcctLineType_45;
18524 --
18525 
18526 ---------------------------------------
18527 --
18528 -- PRIVATE FUNCTION
18529 --         AcctLineType_46
18530 --
18531 ---------------------------------------
18532 PROCEDURE AcctLineType_46 (
18533   p_application_id        IN NUMBER
18534  ,p_event_id              IN NUMBER
18535  ,p_calculate_acctd_flag  IN VARCHAR2
18536  ,p_calculate_g_l_flag    IN VARCHAR2
18537  ,p_actual_flag           IN OUT VARCHAR2
18538  ,p_balance_type_code     OUT VARCHAR2
18539  ,p_gain_or_loss_ref      OUT VARCHAR2
18540  
18541 --Transaction Distribution GL Account
18542  , p_source_4            IN NUMBER
18543 --Bill To Customer Account Identifier
18544  , p_source_23            IN NUMBER
18545 --Bill To Customer Site Use Identifier
18546  , p_source_24            IN NUMBER
18547 --SLA Party Type
18548  , p_source_25            IN VARCHAR2
18549 --Transaction Distribution Account Class
18550  , p_source_26            IN VARCHAR2
18551 --Transaction Distribution Identifier
18552  , p_source_27            IN NUMBER
18553 --Transaction Distribution Type
18554  , p_source_28            IN VARCHAR2
18555 --Transaction Distribution Entered Amount
18556  , p_source_29            IN NUMBER
18557 --Transaction Currency Code
18558  , p_source_30            IN VARCHAR2
18559 --Transaction Exchange Date
18560  , p_source_31            IN DATE
18561 --Transaction Exchange Rate
18562  , p_source_32            IN NUMBER
18563 --Transaction Exchange Rate Type
18564  , p_source_33            IN VARCHAR2
18565 --Transaction Accounting Amount
18566  , p_source_34            IN NUMBER
18567 --Transaction Tax Line Identifier
18568  , p_source_48            IN NUMBER
18569 )
18570 IS
18571 
18572 l_component_type              VARCHAR2(80);
18573 l_component_code              VARCHAR2(30);
18574 l_component_type_code         VARCHAR2(1);
18575 l_component_appl_id           INTEGER;
18576 l_amb_context_code            VARCHAR2(30);
18577 l_entity_code                 VARCHAR2(30);
18578 l_event_class_code            VARCHAR2(30);
18579 l_ae_header_id                NUMBER;
18580 l_event_type_code             VARCHAR2(30);
18581 l_line_definition_code        VARCHAR2(30);
18582 l_line_definition_owner_code  VARCHAR2(1);
18583 --
18584 -- adr variables
18585 l_segment                     VARCHAR2(30);
18586 l_ccid                        NUMBER;
18587 l_adr_transaction_coa_id      NUMBER;
18588 l_adr_accounting_coa_id       NUMBER;
18589 l_adr_flexfield_segment_code  VARCHAR2(30);
18590 l_adr_flex_value_set_id       NUMBER;
18591 l_adr_value_type_code         VARCHAR2(30);
18592 l_adr_value_combination_id    NUMBER;
18593 l_adr_value_segment_code      VARCHAR2(30);
18594 
18595 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
18596 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
18597 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
18598 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
18599 
18600 -- 4262811 Variables ------------------------------------------------------------------------------------------
18601 l_entered_amt_idx             NUMBER;
18602 l_accted_amt_idx              NUMBER;
18603 l_acc_rev_flag                VARCHAR2(1);
18604 l_accrual_line_num            NUMBER;
18605 l_tmp_amt                     NUMBER;
18606 l_acc_rev_natural_side_code   VARCHAR2(1);
18607 
18608 l_num_entries                 NUMBER;
18609 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
18610 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
18611 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
18612 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
18613 l_recog_line_1                NUMBER;
18614 l_recog_line_2                NUMBER;
18615 
18616 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
18617 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
18618 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
18619 
18620 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
18621 
18622 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
18623 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
18624 
18625 ---------------------------------------------------------------------------------------------------------------
18626 
18627 
18628 --
18629 -- bulk performance
18630 --
18631 l_balance_type_code           VARCHAR2(1);
18632 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
18633 l_log_module                  VARCHAR2(240);
18634 
18635 --
18636 -- Upgrade strategy
18637 --
18638 l_actual_upg_option           VARCHAR2(1);
18639 l_enc_upg_option           VARCHAR2(1);
18640 
18641 --
18642 BEGIN
18643 --
18644 IF g_log_enabled THEN
18645       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_46';
18646 END IF;
18647 --
18648 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18649 
18650       trace
18651          (p_msg      => 'BEGIN of AcctLineType_46'
18652          ,p_level    => C_LEVEL_PROCEDURE
18653          ,p_module   => l_log_module);
18654 
18655 END IF;
18656 --
18657 l_component_type             := 'AMB_JLT';
18658 l_component_code             := 'INV_FREIGHT';
18659 l_component_type_code        := 'S';
18660 l_component_appl_id          :=  222;
18661 l_amb_context_code           := 'DEFAULT';
18662 l_entity_code                := 'TRANSACTIONS';
18663 l_event_class_code           := 'INVOICE';
18664 l_event_type_code            := 'INVOICE_ALL';
18665 l_line_definition_owner_code := 'S';
18666 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
18667 --
18668 l_balance_type_code          := 'A';
18669 l_segment                     := NULL;
18670 l_ccid                        := NULL;
18671 l_adr_transaction_coa_id      := NULL;
18672 l_adr_accounting_coa_id       := NULL;
18673 l_adr_flexfield_segment_code  := NULL;
18674 l_adr_flex_value_set_id       := NULL;
18675 l_adr_value_type_code         := NULL;
18676 l_adr_value_combination_id    := NULL;
18677 l_adr_value_segment_code      := NULL;
18678 
18679 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
18680 l_bflow_class_code           := 'FREIGHT';    -- 4219869 Business Flow
18681 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
18682 l_budgetary_control_flag     := 'N';
18683 
18684 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
18685 l_bflow_applied_to_amt       := NULL; -- 5132302
18686 l_entered_amt_idx            := NULL;          -- 4262811
18690 l_tmp_amt                    := NULL;          -- 4262811
18687 l_accted_amt_idx             := NULL;          -- 4262811
18688 l_acc_rev_flag               := NULL;          -- 4262811
18689 l_accrual_line_num           := NULL;          -- 4262811
18691 --
18692  
18693 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
18694     l_balance_type_code <> 'B' THEN
18695 IF NVL(p_source_26,'
18696 ') =  'FREIGHT'
18697  THEN 
18698 
18699    --
18700    XLA_AE_LINES_PKG.SetNewLine;
18701 
18702    p_balance_type_code          := l_balance_type_code;
18703    -- set the flag so later we will know whether the gain loss line needs to be created
18704    
18705    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
18706      p_actual_flag :='A';
18707    END IF;
18708 
18709    --
18710    -- bulk performance
18711    --
18712    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
18713                                       p_header_num   => 0); -- 4262811
18714    --
18715    -- set accounting line options
18716    --
18717    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
18718            p_natural_side_code          => 'C'
18719          , p_gain_or_loss_flag          => 'N'
18720          , p_gl_transfer_mode_code      => 'S'
18721          , p_acct_entry_type_code       => 'A'
18722          , p_switch_side_flag           => 'Y'
18723          , p_merge_duplicate_code       => 'A'
18724          );
18725    --
18726    l_acc_rev_natural_side_code := 'D';  -- 4262811
18727    -- 
18728    --
18729    -- set accounting line type info
18730    --
18731    xla_ae_lines_pkg.SetAcctLineType
18732       (p_component_type             => l_component_type
18733       ,p_event_type_code            => l_event_type_code
18734       ,p_line_definition_owner_code => l_line_definition_owner_code
18735       ,p_line_definition_code       => l_line_definition_code
18736       ,p_accounting_line_code       => l_component_code
18737       ,p_accounting_line_type_code  => l_component_type_code
18738       ,p_accounting_line_appl_id    => l_component_appl_id
18739       ,p_amb_context_code           => l_amb_context_code
18740       ,p_entity_code                => l_entity_code
18741       ,p_event_class_code           => l_event_class_code);
18742    --
18743    -- set accounting class
18744    --
18745    xla_ae_lines_pkg.SetAcctClass(
18746            p_accounting_class_code  => 'FREIGHT'
18747          , p_ae_header_id           => l_ae_header_id
18748          );
18749 
18750    --
18751    -- set rounding class
18752    --
18753    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
18754                       'RECEIVABLE';
18755 
18756    --
18757    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
18758    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
18759    --
18760    -- bulk performance
18761    --
18762    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
18763 
18764    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
18765       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
18766 
18767    -- 4955764
18768    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
18769       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
18770 
18771    -- 4458381 Public Sector Enh
18772    
18773    --
18774    -- set accounting attributes for the line type
18775    --
18776    l_entered_amt_idx := 3;
18777    l_accted_amt_idx  := 8;
18778    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
18779    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
18780    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
18781    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
18782    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
18783    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
18784    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
18785    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
18786    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
18787    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
18788    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
18789    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
18790    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
18791    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
18792    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
18793    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
18794    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
18795    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
18796    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
18797    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
18798    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
18799    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
18800    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
18801    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
18802    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
18803 
18804    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
18805    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
18806 
18807    ---------------------------------------------------------------------------------------------------------------
18808    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
18809    ---------------------------------------------------------------------------------------------------------------
18810    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
18811 
18812    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
18813    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
18814 
18815    IF xla_accounting_cache_pkg.GetValueChar
18816          (p_source_code         => 'LEDGER_CATEGORY_CODE'
18817          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
18818    AND l_bflow_method_code = 'PRIOR_ENTRY'
18819 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
18820    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
18821          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
18822        )
18823    THEN
18824          xla_ae_lines_pkg.BflowUpgEntry
18825            (p_business_method_code    => l_bflow_method_code
18826            ,p_business_class_code     => l_bflow_class_code
18827            ,p_balance_type            => l_balance_type_code);
18828    ELSE
18829       NULL;
18830 -- No business flow processing for business flow method of NONE.
18831    END IF;
18832 
18833    --
18834    -- call analytical criteria
18835    --
18836    
18837    --
18838    -- call description
18839    --
18840    -- No description or it is inherited.
18841    --
18842    -- call ADRs
18843    -- Bug 4922099
18844    --
18845    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
18846         (NVL(l_actual_upg_option, 'N') = 'O') OR
18847         (NVL(l_enc_upg_option, 'N') = 'O')
18848       )
18849    THEN
18850    NULL;
18851    --
18852    --
18853    
18854   l_ccid := AcctDerRule_16(
18855            p_application_id           => p_application_id
18856          , p_ae_header_id             => l_ae_header_id 
18857 , p_source_4 => p_source_4
18858          , x_transaction_coa_id       => l_adr_transaction_coa_id
18859          , x_accounting_coa_id        => l_adr_accounting_coa_id
18860          , x_value_type_code          => l_adr_value_type_code
18861          , p_side                     => 'NA'
18862    );
18863 
18864    xla_ae_lines_pkg.set_ccid(
18865     p_code_combination_id          => l_ccid
18866   , p_value_type_code              => l_adr_value_type_code
18867   , p_transaction_coa_id           => l_adr_transaction_coa_id
18868   , p_accounting_coa_id            => l_adr_accounting_coa_id
18869   , p_adr_code                     => 'TRX_DIST_CCID'
18870   , p_adr_type_code                => 'S'
18871   , p_component_type               => l_component_type
18872   , p_component_code               => l_component_code
18873   , p_component_type_code          => l_component_type_code
18874   , p_component_appl_id            => l_component_appl_id
18875   , p_amb_context_code             => l_amb_context_code
18876   , p_side                         => 'NA'
18877   );
18878 
18879 
18880    --
18881    --
18882    END IF;
18883    --
18884    -- Bug 4922099
18885    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
18886           (NVL(l_enc_upg_option, 'N') = 'O')
18887         ) AND
18888         (l_bflow_method_code = 'PRIOR_ENTRY')
18889       )
18890    THEN
18891       IF
18892       --
18893       1 = 2
18894       --
18895       THEN
18896       xla_accounting_err_pkg.build_message
18897                                     (p_appli_s_name            => 'XLA'
18898                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
18899                                     ,p_token_1                 => 'LINE_NUMBER'
18900                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
18901                                     ,p_token_2                 => 'LINE_TYPE_NAME'
18902                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
18903                                                                              l_component_type
18904                                                                             ,l_component_code
18905                                                                             ,l_component_type_code
18906                                                                             ,l_component_appl_id
18907                                                                             ,l_amb_context_code
18908                                                                             ,l_entity_code
18909                                                                             ,l_event_class_code
18910                                                                            )
18911                                     ,p_token_3                 => 'OWNER'
18912                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
18913                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
18914                                                                           ,p_lookup_code    => l_component_type_code
18915                                                                          )
18916                                     ,p_token_4                 => 'PRODUCT_NAME'
18917                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
18918                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
18919                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
18920                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
18921                                     ,p_ae_header_id            =>  NULL
18922                                        );
18923 
18924         IF (C_LEVEL_ERROR>= g_log_level) THEN
18925                  trace
18926                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
18927                       ,p_level    => C_LEVEL_ERROR
18928                       ,p_module   => l_log_module);
18929         END IF;
18930       END IF;
18931    END IF;
18932    --
18933    --
18934    ------------------------------------------------------------------------------------------------
18935    -- 4219869 Business Flow
18936    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
18937    -- Prior Entry.  Currently, the following code is always generated.
18938    ------------------------------------------------------------------------------------------------
18939    XLA_AE_LINES_PKG.ValidateCurrentLine;
18940 
18941    ------------------------------------------------------------------------------------
18942    -- 4219869 Business Flow
18943    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
18944    ------------------------------------------------------------------------------------
18945    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
18946 
18947    ----------------------------------------------------------------------------------
18948    -- 4219869 Business Flow
18949    -- Update journal entry status -- Need to generate this within IF <condition>
18950    ----------------------------------------------------------------------------------
18951    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
18952          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
18953          ,p_balance_type_code => l_balance_type_code
18954          );
18955 
18956    -------------------------------------------------------------------------------------------
18957    -- 4262811 - Generate the Accrual Reversal lines
18958    -------------------------------------------------------------------------------------------
18959    BEGIN
18960       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
18961                               (g_array_event(p_event_id).array_value_num('header_index'));
18962       IF l_acc_rev_flag IS NULL THEN
18963          l_acc_rev_flag := 'N';
18964       END IF;
18965    EXCEPTION
18966       WHEN OTHERS THEN
18967          l_acc_rev_flag := 'N';
18968    END;
18969    --
18970    IF (l_acc_rev_flag = 'Y') THEN
18971 
18972        -- 4645092  ------------------------------------------------------------------------------
18973        -- To allow MPA report to determine if it should generate report process
18974        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
18975        ------------------------------------------------------------------------------------------
18976 
18977        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
18978        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
18979    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
18980    -- call ADRs
18981    -- Bug 4922099
18982    --
18983    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
18984         (NVL(l_actual_upg_option, 'N') = 'O') OR
18985         (NVL(l_enc_upg_option, 'N') = 'O')
18986       )
18987    THEN
18988    NULL;
18989    --
18990    --
18991    
18992   l_ccid := AcctDerRule_16(
18993            p_application_id           => p_application_id
18994          , p_ae_header_id             => l_ae_header_id 
18995 , p_source_4 => p_source_4
18996          , x_transaction_coa_id       => l_adr_transaction_coa_id
18997          , x_accounting_coa_id        => l_adr_accounting_coa_id
18998          , x_value_type_code          => l_adr_value_type_code
18999          , p_side                     => 'NA'
19000    );
19001 
19002    xla_ae_lines_pkg.set_ccid(
19003     p_code_combination_id          => l_ccid
19004   , p_value_type_code              => l_adr_value_type_code
19005   , p_transaction_coa_id           => l_adr_transaction_coa_id
19006   , p_accounting_coa_id            => l_adr_accounting_coa_id
19007   , p_adr_code                     => 'TRX_DIST_CCID'
19008   , p_adr_type_code                => 'S'
19009   , p_component_type               => l_component_type
19010   , p_component_code               => l_component_code
19011   , p_component_type_code          => l_component_type_code
19012   , p_component_appl_id            => l_component_appl_id
19013   , p_amb_context_code             => l_amb_context_code
19014   , p_side                         => 'NA'
19015   );
19016 
19017 
19018    --
19019    --
19020    END IF;
19021 
19022        --
19023        -- Update the line information that should be overwritten
19024        --
19025        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
19026                                          p_header_num   => 1);
19027        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
19028 
19029        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
19030 
19031        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
19032           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
19033        END IF;
19034 
19035       --
19036       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
19037       --
19038       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
19039           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
19040       ELSE
19041           ---------------------------------------------------------------------------------------------------
19042           -- 4262811a Switch Sign
19043           ---------------------------------------------------------------------------------------------------
19044           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
19045           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
19046                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19047           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
19048                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19049           -- 5132302
19050           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
19051                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19052 
19053       END IF;
19054 
19055       -- 4955764
19056       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
19057       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
19058 
19059 
19060       XLA_AE_LINES_PKG.ValidateCurrentLine;
19061       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
19062 
19063       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
19064                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
19065                ,p_balance_type_code => l_balance_type_code);
19066 
19067    END IF;
19068 
19069    -----------------------------------------------------------------------------------------
19070    -- 4262811 Multiperiod Accounting
19071    -----------------------------------------------------------------------------------------
19072      -- No MPA option is assigned.
19073 
19074 
19075 END IF;
19076 END IF;
19077 --
19078 
19079 --
19080 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19081    trace
19082       (p_msg      => 'END of AcctLineType_46'
19083       ,p_level    => C_LEVEL_PROCEDURE
19084       ,p_module   => l_log_module);
19085 END IF;
19086 --
19087 EXCEPTION
19088   WHEN xla_exceptions_pkg.application_exception THEN
19089       RAISE;
19090   WHEN OTHERS THEN
19091        xla_exceptions_pkg.raise_message
19092            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_46');
19093 END AcctLineType_46;
19094 --
19095 
19096 ---------------------------------------
19097 --
19098 -- PRIVATE FUNCTION
19099 --         AcctLineType_47
19100 --
19101 ---------------------------------------
19102 PROCEDURE AcctLineType_47 (
19103   p_application_id        IN NUMBER
19104  ,p_event_id              IN NUMBER
19105  ,p_calculate_acctd_flag  IN VARCHAR2
19106  ,p_calculate_g_l_flag    IN VARCHAR2
19107  ,p_actual_flag           IN OUT VARCHAR2
19108  ,p_balance_type_code     OUT VARCHAR2
19109  ,p_gain_or_loss_ref      OUT VARCHAR2
19110  
19111 --Transaction Distribution GL Account
19112  , p_source_4            IN NUMBER
19113 --Bill To Customer Account Identifier
19114  , p_source_23            IN NUMBER
19115 --Bill To Customer Site Use Identifier
19116  , p_source_24            IN NUMBER
19117 --SLA Party Type
19118  , p_source_25            IN VARCHAR2
19119 --Transaction Distribution Account Class
19120  , p_source_26            IN VARCHAR2
19121 --Transaction Distribution Identifier
19122  , p_source_27            IN NUMBER
19123 --Transaction Distribution Type
19124  , p_source_28            IN VARCHAR2
19125 --Transaction Distribution Entered Amount
19126  , p_source_29            IN NUMBER
19127 --Transaction Currency Code
19128  , p_source_30            IN VARCHAR2
19129 --Transaction Exchange Date
19130  , p_source_31            IN DATE
19131 --Transaction Exchange Rate
19132  , p_source_32            IN NUMBER
19133 --Transaction Exchange Rate Type
19134  , p_source_33            IN VARCHAR2
19135 --Transaction Accounting Amount
19136  , p_source_34            IN NUMBER
19137 --Transaction Tax Line Identifier
19138  , p_source_48            IN NUMBER
19139 --Rounding Correction Flag
19140  , p_source_49            IN VARCHAR2
19141 )
19142 IS
19143 
19144 l_component_type              VARCHAR2(80);
19145 l_component_code              VARCHAR2(30);
19146 l_component_type_code         VARCHAR2(1);
19147 l_component_appl_id           INTEGER;
19148 l_amb_context_code            VARCHAR2(30);
19149 l_entity_code                 VARCHAR2(30);
19150 l_event_class_code            VARCHAR2(30);
19151 l_ae_header_id                NUMBER;
19152 l_event_type_code             VARCHAR2(30);
19153 l_line_definition_code        VARCHAR2(30);
19154 l_line_definition_owner_code  VARCHAR2(1);
19155 --
19156 -- adr variables
19157 l_segment                     VARCHAR2(30);
19158 l_ccid                        NUMBER;
19159 l_adr_transaction_coa_id      NUMBER;
19160 l_adr_accounting_coa_id       NUMBER;
19161 l_adr_flexfield_segment_code  VARCHAR2(30);
19162 l_adr_flex_value_set_id       NUMBER;
19163 l_adr_value_type_code         VARCHAR2(30);
19164 l_adr_value_combination_id    NUMBER;
19165 l_adr_value_segment_code      VARCHAR2(30);
19166 
19167 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
19168 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
19169 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
19170 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
19171 
19172 -- 4262811 Variables ------------------------------------------------------------------------------------------
19173 l_entered_amt_idx             NUMBER;
19174 l_accted_amt_idx              NUMBER;
19175 l_acc_rev_flag                VARCHAR2(1);
19176 l_accrual_line_num            NUMBER;
19177 l_tmp_amt                     NUMBER;
19178 l_acc_rev_natural_side_code   VARCHAR2(1);
19179 
19180 l_num_entries                 NUMBER;
19181 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
19182 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
19183 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
19184 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
19185 l_recog_line_1                NUMBER;
19186 l_recog_line_2                NUMBER;
19187 
19188 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
19189 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
19190 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
19191 
19192 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
19193 
19194 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
19195 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
19196 
19197 ---------------------------------------------------------------------------------------------------------------
19198 
19199 
19200 --
19201 -- bulk performance
19202 --
19203 l_balance_type_code           VARCHAR2(1);
19204 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
19205 l_log_module                  VARCHAR2(240);
19206 
19207 --
19208 -- Upgrade strategy
19209 --
19210 l_actual_upg_option           VARCHAR2(1);
19211 l_enc_upg_option           VARCHAR2(1);
19212 
19213 --
19214 BEGIN
19215 --
19216 IF g_log_enabled THEN
19217       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_47';
19218 END IF;
19219 --
19220 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19221 
19222       trace
19223          (p_msg      => 'BEGIN of AcctLineType_47'
19224          ,p_level    => C_LEVEL_PROCEDURE
19225          ,p_module   => l_log_module);
19226 
19227 END IF;
19228 --
19229 l_component_type             := 'AMB_JLT';
19230 l_component_code             := 'INV_REV';
19231 l_component_type_code        := 'S';
19232 l_component_appl_id          :=  222;
19233 l_amb_context_code           := 'DEFAULT';
19234 l_entity_code                := 'TRANSACTIONS';
19235 l_event_class_code           := 'INVOICE';
19236 l_event_type_code            := 'INVOICE_ALL';
19237 l_line_definition_owner_code := 'S';
19238 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
19239 --
19240 l_balance_type_code          := 'A';
19241 l_segment                     := NULL;
19242 l_ccid                        := NULL;
19243 l_adr_transaction_coa_id      := NULL;
19244 l_adr_accounting_coa_id       := NULL;
19245 l_adr_flexfield_segment_code  := NULL;
19246 l_adr_flex_value_set_id       := NULL;
19247 l_adr_value_type_code         := NULL;
19248 l_adr_value_combination_id    := NULL;
19249 l_adr_value_segment_code      := NULL;
19250 
19251 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
19252 l_bflow_class_code           := 'REVENUE';    -- 4219869 Business Flow
19253 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
19254 l_budgetary_control_flag     := 'N';
19255 
19256 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
19257 l_bflow_applied_to_amt       := NULL; -- 5132302
19258 l_entered_amt_idx            := NULL;          -- 4262811
19259 l_accted_amt_idx             := NULL;          -- 4262811
19260 l_acc_rev_flag               := NULL;          -- 4262811
19261 l_accrual_line_num           := NULL;          -- 4262811
19262 l_tmp_amt                    := NULL;          -- 4262811
19263 --
19264  
19265 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
19266     l_balance_type_code <> 'B' THEN
19267 IF NVL(p_source_26,'
19268 ') =  'REV' AND 
19269 p_source_49 IS NULL 
19270  THEN 
19271 
19272    --
19273    XLA_AE_LINES_PKG.SetNewLine;
19274 
19275    p_balance_type_code          := l_balance_type_code;
19276    -- set the flag so later we will know whether the gain loss line needs to be created
19277    
19278    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
19279      p_actual_flag :='A';
19280    END IF;
19281 
19282    --
19283    -- bulk performance
19284    --
19285    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
19286                                       p_header_num   => 0); -- 4262811
19287    --
19288    -- set accounting line options
19289    --
19290    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
19291            p_natural_side_code          => 'C'
19292          , p_gain_or_loss_flag          => 'N'
19293          , p_gl_transfer_mode_code      => 'S'
19294          , p_acct_entry_type_code       => 'A'
19295          , p_switch_side_flag           => 'Y'
19296          , p_merge_duplicate_code       => 'A'
19297          );
19298    --
19299    l_acc_rev_natural_side_code := 'D';  -- 4262811
19300    -- 
19301    --
19302    -- set accounting line type info
19303    --
19304    xla_ae_lines_pkg.SetAcctLineType
19305       (p_component_type             => l_component_type
19306       ,p_event_type_code            => l_event_type_code
19307       ,p_line_definition_owner_code => l_line_definition_owner_code
19308       ,p_line_definition_code       => l_line_definition_code
19309       ,p_accounting_line_code       => l_component_code
19310       ,p_accounting_line_type_code  => l_component_type_code
19311       ,p_accounting_line_appl_id    => l_component_appl_id
19312       ,p_amb_context_code           => l_amb_context_code
19313       ,p_entity_code                => l_entity_code
19314       ,p_event_class_code           => l_event_class_code);
19315    --
19316    -- set accounting class
19317    --
19318    xla_ae_lines_pkg.SetAcctClass(
19319            p_accounting_class_code  => 'REVENUE'
19320          , p_ae_header_id           => l_ae_header_id
19321          );
19322 
19323    --
19324    -- set rounding class
19325    --
19326    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
19327                       'RECEIVABLE';
19328 
19329    --
19330    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
19331    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
19332    --
19333    -- bulk performance
19334    --
19335    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
19336 
19337    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
19338       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
19339 
19340    -- 4955764
19341    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
19342       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
19343 
19344    -- 4458381 Public Sector Enh
19345    
19346    --
19347    -- set accounting attributes for the line type
19348    --
19349    l_entered_amt_idx := 3;
19350    l_accted_amt_idx  := 8;
19351    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
19352    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
19353    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
19354    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
19355    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
19356    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
19357    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
19358    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
19359    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
19360    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
19361    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
19362    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
19363    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
19364    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
19365    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
19366    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
19367    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
19368    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
19369    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
19370    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
19371    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
19372    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
19373    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
19374    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
19375    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
19376 
19377    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
19378    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
19379 
19380    ---------------------------------------------------------------------------------------------------------------
19381    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
19382    ---------------------------------------------------------------------------------------------------------------
19383    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
19384 
19385    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
19386    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
19387 
19388    IF xla_accounting_cache_pkg.GetValueChar
19389          (p_source_code         => 'LEDGER_CATEGORY_CODE'
19390          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
19391    AND l_bflow_method_code = 'PRIOR_ENTRY'
19392 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
19393    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
19394          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
19395        )
19396    THEN
19397          xla_ae_lines_pkg.BflowUpgEntry
19398            (p_business_method_code    => l_bflow_method_code
19399            ,p_business_class_code     => l_bflow_class_code
19400            ,p_balance_type            => l_balance_type_code);
19401    ELSE
19402       NULL;
19403 -- No business flow processing for business flow method of NONE.
19404    END IF;
19405 
19406    --
19407    -- call analytical criteria
19408    --
19409    
19410    --
19411    -- call description
19412    --
19413    -- No description or it is inherited.
19414    --
19415    -- call ADRs
19416    -- Bug 4922099
19417    --
19418    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
19419         (NVL(l_actual_upg_option, 'N') = 'O') OR
19420         (NVL(l_enc_upg_option, 'N') = 'O')
19421       )
19422    THEN
19423    NULL;
19424    --
19425    --
19426    
19427   l_ccid := AcctDerRule_16(
19428            p_application_id           => p_application_id
19429          , p_ae_header_id             => l_ae_header_id 
19430 , p_source_4 => p_source_4
19431          , x_transaction_coa_id       => l_adr_transaction_coa_id
19432          , x_accounting_coa_id        => l_adr_accounting_coa_id
19433          , x_value_type_code          => l_adr_value_type_code
19434          , p_side                     => 'NA'
19435    );
19436 
19437    xla_ae_lines_pkg.set_ccid(
19438     p_code_combination_id          => l_ccid
19439   , p_value_type_code              => l_adr_value_type_code
19440   , p_transaction_coa_id           => l_adr_transaction_coa_id
19441   , p_accounting_coa_id            => l_adr_accounting_coa_id
19442   , p_adr_code                     => 'TRX_DIST_CCID'
19443   , p_adr_type_code                => 'S'
19444   , p_component_type               => l_component_type
19445   , p_component_code               => l_component_code
19446   , p_component_type_code          => l_component_type_code
19447   , p_component_appl_id            => l_component_appl_id
19448   , p_amb_context_code             => l_amb_context_code
19449   , p_side                         => 'NA'
19450   );
19451 
19452 
19453    --
19454    --
19455    END IF;
19456    --
19457    -- Bug 4922099
19458    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
19459           (NVL(l_enc_upg_option, 'N') = 'O')
19460         ) AND
19461         (l_bflow_method_code = 'PRIOR_ENTRY')
19462       )
19463    THEN
19464       IF
19465       --
19466       1 = 2
19467       --
19468       THEN
19469       xla_accounting_err_pkg.build_message
19470                                     (p_appli_s_name            => 'XLA'
19471                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
19472                                     ,p_token_1                 => 'LINE_NUMBER'
19473                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
19474                                     ,p_token_2                 => 'LINE_TYPE_NAME'
19475                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
19476                                                                              l_component_type
19477                                                                             ,l_component_code
19478                                                                             ,l_component_type_code
19479                                                                             ,l_component_appl_id
19480                                                                             ,l_amb_context_code
19481                                                                             ,l_entity_code
19482                                                                             ,l_event_class_code
19483                                                                            )
19484                                     ,p_token_3                 => 'OWNER'
19485                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
19486                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
19487                                                                           ,p_lookup_code    => l_component_type_code
19488                                                                          )
19489                                     ,p_token_4                 => 'PRODUCT_NAME'
19490                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
19491                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
19492                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
19493                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
19494                                     ,p_ae_header_id            =>  NULL
19495                                        );
19496 
19497         IF (C_LEVEL_ERROR>= g_log_level) THEN
19498                  trace
19499                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
19500                       ,p_level    => C_LEVEL_ERROR
19501                       ,p_module   => l_log_module);
19502         END IF;
19503       END IF;
19504    END IF;
19505    --
19506    --
19507    ------------------------------------------------------------------------------------------------
19508    -- 4219869 Business Flow
19509    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
19510    -- Prior Entry.  Currently, the following code is always generated.
19511    ------------------------------------------------------------------------------------------------
19512    XLA_AE_LINES_PKG.ValidateCurrentLine;
19513 
19514    ------------------------------------------------------------------------------------
19515    -- 4219869 Business Flow
19516    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
19517    ------------------------------------------------------------------------------------
19518    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
19519 
19520    ----------------------------------------------------------------------------------
19521    -- 4219869 Business Flow
19522    -- Update journal entry status -- Need to generate this within IF <condition>
19523    ----------------------------------------------------------------------------------
19524    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
19525          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
19526          ,p_balance_type_code => l_balance_type_code
19527          );
19528 
19529    -------------------------------------------------------------------------------------------
19530    -- 4262811 - Generate the Accrual Reversal lines
19531    -------------------------------------------------------------------------------------------
19532    BEGIN
19533       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
19534                               (g_array_event(p_event_id).array_value_num('header_index'));
19535       IF l_acc_rev_flag IS NULL THEN
19536          l_acc_rev_flag := 'N';
19537       END IF;
19538    EXCEPTION
19539       WHEN OTHERS THEN
19540          l_acc_rev_flag := 'N';
19541    END;
19542    --
19543    IF (l_acc_rev_flag = 'Y') THEN
19544 
19545        -- 4645092  ------------------------------------------------------------------------------
19546        -- To allow MPA report to determine if it should generate report process
19547        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
19548        ------------------------------------------------------------------------------------------
19549 
19550        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
19551        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
19552    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
19553    -- call ADRs
19554    -- Bug 4922099
19555    --
19556    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
19557         (NVL(l_actual_upg_option, 'N') = 'O') OR
19558         (NVL(l_enc_upg_option, 'N') = 'O')
19559       )
19560    THEN
19561    NULL;
19562    --
19563    --
19564    
19565   l_ccid := AcctDerRule_16(
19566            p_application_id           => p_application_id
19567          , p_ae_header_id             => l_ae_header_id 
19568 , p_source_4 => p_source_4
19569          , x_transaction_coa_id       => l_adr_transaction_coa_id
19570          , x_accounting_coa_id        => l_adr_accounting_coa_id
19571          , x_value_type_code          => l_adr_value_type_code
19572          , p_side                     => 'NA'
19573    );
19574 
19575    xla_ae_lines_pkg.set_ccid(
19576     p_code_combination_id          => l_ccid
19577   , p_value_type_code              => l_adr_value_type_code
19578   , p_transaction_coa_id           => l_adr_transaction_coa_id
19579   , p_accounting_coa_id            => l_adr_accounting_coa_id
19580   , p_adr_code                     => 'TRX_DIST_CCID'
19581   , p_adr_type_code                => 'S'
19582   , p_component_type               => l_component_type
19583   , p_component_code               => l_component_code
19584   , p_component_type_code          => l_component_type_code
19585   , p_component_appl_id            => l_component_appl_id
19586   , p_amb_context_code             => l_amb_context_code
19587   , p_side                         => 'NA'
19588   );
19589 
19590 
19591    --
19592    --
19593    END IF;
19594 
19595        --
19596        -- Update the line information that should be overwritten
19597        --
19598        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
19599                                          p_header_num   => 1);
19600        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
19601 
19602        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
19603 
19604        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
19605           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
19606        END IF;
19607 
19608       --
19609       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
19610       --
19611       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
19612           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
19613       ELSE
19614           ---------------------------------------------------------------------------------------------------
19615           -- 4262811a Switch Sign
19616           ---------------------------------------------------------------------------------------------------
19617           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
19618           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
19619                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19620           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
19621                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19622           -- 5132302
19623           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
19624                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19625 
19626       END IF;
19627 
19628       -- 4955764
19629       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
19630       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
19631 
19632 
19633       XLA_AE_LINES_PKG.ValidateCurrentLine;
19634       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
19635 
19636       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
19637                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
19638                ,p_balance_type_code => l_balance_type_code);
19639 
19640    END IF;
19641 
19642    -----------------------------------------------------------------------------------------
19643    -- 4262811 Multiperiod Accounting
19644    -----------------------------------------------------------------------------------------
19645      -- No MPA option is assigned.
19646 
19647 
19648 END IF;
19649 END IF;
19650 --
19651 
19652 --
19653 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19654    trace
19655       (p_msg      => 'END of AcctLineType_47'
19656       ,p_level    => C_LEVEL_PROCEDURE
19657       ,p_module   => l_log_module);
19658 END IF;
19659 --
19660 EXCEPTION
19661   WHEN xla_exceptions_pkg.application_exception THEN
19662       RAISE;
19663   WHEN OTHERS THEN
19664        xla_exceptions_pkg.raise_message
19665            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_47');
19666 END AcctLineType_47;
19667 --
19668 
19669 ---------------------------------------
19670 --
19671 -- PRIVATE FUNCTION
19672 --         AcctLineType_48
19673 --
19674 ---------------------------------------
19675 PROCEDURE AcctLineType_48 (
19676   p_application_id        IN NUMBER
19677  ,p_event_id              IN NUMBER
19678  ,p_calculate_acctd_flag  IN VARCHAR2
19679  ,p_calculate_g_l_flag    IN VARCHAR2
19680  ,p_actual_flag           IN OUT VARCHAR2
19681  ,p_balance_type_code     OUT VARCHAR2
19682  ,p_gain_or_loss_ref      OUT VARCHAR2
19683  
19684 --Transaction Distribution GL Account
19685  , p_source_4            IN NUMBER
19686 --Bill To Customer Account Identifier
19687  , p_source_23            IN NUMBER
19688 --Bill To Customer Site Use Identifier
19689  , p_source_24            IN NUMBER
19690 --SLA Party Type
19691  , p_source_25            IN VARCHAR2
19692 --Transaction Distribution Account Class
19693  , p_source_26            IN VARCHAR2
19694 --Transaction Distribution Identifier
19695  , p_source_27            IN NUMBER
19696 --Transaction Distribution Type
19697  , p_source_28            IN VARCHAR2
19698 --Transaction Distribution Entered Amount
19699  , p_source_29            IN NUMBER
19700 --Transaction Currency Code
19701  , p_source_30            IN VARCHAR2
19702 --Transaction Exchange Date
19703  , p_source_31            IN DATE
19704 --Transaction Exchange Rate
19705  , p_source_32            IN NUMBER
19706 --Transaction Exchange Rate Type
19707  , p_source_33            IN VARCHAR2
19708 --Transaction Accounting Amount
19709  , p_source_34            IN NUMBER
19710 --Transaction Tax Line Identifier
19711  , p_source_48            IN NUMBER
19712 )
19713 IS
19714 
19715 l_component_type              VARCHAR2(80);
19716 l_component_code              VARCHAR2(30);
19717 l_component_type_code         VARCHAR2(1);
19718 l_component_appl_id           INTEGER;
19719 l_amb_context_code            VARCHAR2(30);
19720 l_entity_code                 VARCHAR2(30);
19721 l_event_class_code            VARCHAR2(30);
19722 l_ae_header_id                NUMBER;
19723 l_event_type_code             VARCHAR2(30);
19724 l_line_definition_code        VARCHAR2(30);
19725 l_line_definition_owner_code  VARCHAR2(1);
19726 --
19727 -- adr variables
19728 l_segment                     VARCHAR2(30);
19729 l_ccid                        NUMBER;
19730 l_adr_transaction_coa_id      NUMBER;
19731 l_adr_accounting_coa_id       NUMBER;
19732 l_adr_flexfield_segment_code  VARCHAR2(30);
19733 l_adr_flex_value_set_id       NUMBER;
19734 l_adr_value_type_code         VARCHAR2(30);
19735 l_adr_value_combination_id    NUMBER;
19736 l_adr_value_segment_code      VARCHAR2(30);
19737 
19738 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
19739 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
19740 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
19741 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
19742 
19743 -- 4262811 Variables ------------------------------------------------------------------------------------------
19744 l_entered_amt_idx             NUMBER;
19745 l_accted_amt_idx              NUMBER;
19746 l_acc_rev_flag                VARCHAR2(1);
19747 l_accrual_line_num            NUMBER;
19748 l_tmp_amt                     NUMBER;
19749 l_acc_rev_natural_side_code   VARCHAR2(1);
19750 
19751 l_num_entries                 NUMBER;
19752 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
19753 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
19754 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
19755 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
19756 l_recog_line_1                NUMBER;
19757 l_recog_line_2                NUMBER;
19758 
19759 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
19760 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
19761 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
19762 
19763 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
19764 
19765 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
19766 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
19767 
19768 ---------------------------------------------------------------------------------------------------------------
19769 
19770 
19771 --
19772 -- bulk performance
19773 --
19774 l_balance_type_code           VARCHAR2(1);
19775 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
19776 l_log_module                  VARCHAR2(240);
19777 
19778 --
19779 -- Upgrade strategy
19780 --
19781 l_actual_upg_option           VARCHAR2(1);
19782 l_enc_upg_option           VARCHAR2(1);
19783 
19784 --
19785 BEGIN
19786 --
19787 IF g_log_enabled THEN
19788       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_48';
19789 END IF;
19790 --
19791 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19792 
19793       trace
19794          (p_msg      => 'BEGIN of AcctLineType_48'
19795          ,p_level    => C_LEVEL_PROCEDURE
19796          ,p_module   => l_log_module);
19797 
19798 END IF;
19799 --
19800 l_component_type             := 'AMB_JLT';
19801 l_component_code             := 'INV_ROUND';
19802 l_component_type_code        := 'S';
19803 l_component_appl_id          :=  222;
19804 l_amb_context_code           := 'DEFAULT';
19805 l_entity_code                := 'TRANSACTIONS';
19806 l_event_class_code           := 'INVOICE';
19807 l_event_type_code            := 'INVOICE_ALL';
19808 l_line_definition_owner_code := 'S';
19809 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
19810 --
19811 l_balance_type_code          := 'A';
19812 l_segment                     := NULL;
19813 l_ccid                        := NULL;
19814 l_adr_transaction_coa_id      := NULL;
19815 l_adr_accounting_coa_id       := NULL;
19816 l_adr_flexfield_segment_code  := NULL;
19817 l_adr_flex_value_set_id       := NULL;
19818 l_adr_value_type_code         := NULL;
19819 l_adr_value_combination_id    := NULL;
19820 l_adr_value_segment_code      := NULL;
19821 
19822 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
19823 l_bflow_class_code           := '';    -- 4219869 Business Flow
19824 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
19825 l_budgetary_control_flag     := 'N';
19826 
19827 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
19828 l_bflow_applied_to_amt       := NULL; -- 5132302
19829 l_entered_amt_idx            := NULL;          -- 4262811
19830 l_accted_amt_idx             := NULL;          -- 4262811
19831 l_acc_rev_flag               := NULL;          -- 4262811
19832 l_accrual_line_num           := NULL;          -- 4262811
19833 l_tmp_amt                    := NULL;          -- 4262811
19834 --
19835  
19836 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
19837     l_balance_type_code <> 'B' THEN
19838 IF NVL(p_source_26,'
19839 ') =  'ROUND'
19840  THEN 
19841 
19842    --
19843    XLA_AE_LINES_PKG.SetNewLine;
19844 
19845    p_balance_type_code          := l_balance_type_code;
19846    -- set the flag so later we will know whether the gain loss line needs to be created
19847    
19848    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
19849      p_actual_flag :='A';
19850    END IF;
19851 
19852    --
19853    -- bulk performance
19854    --
19855    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
19856                                       p_header_num   => 0); -- 4262811
19857    --
19858    -- set accounting line options
19859    --
19860    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
19861            p_natural_side_code          => 'C'
19862          , p_gain_or_loss_flag          => 'N'
19863          , p_gl_transfer_mode_code      => 'S'
19864          , p_acct_entry_type_code       => 'A'
19865          , p_switch_side_flag           => 'Y'
19866          , p_merge_duplicate_code       => 'A'
19867          );
19868    --
19869    l_acc_rev_natural_side_code := 'D';  -- 4262811
19870    -- 
19871    --
19872    -- set accounting line type info
19873    --
19874    xla_ae_lines_pkg.SetAcctLineType
19875       (p_component_type             => l_component_type
19876       ,p_event_type_code            => l_event_type_code
19877       ,p_line_definition_owner_code => l_line_definition_owner_code
19878       ,p_line_definition_code       => l_line_definition_code
19879       ,p_accounting_line_code       => l_component_code
19880       ,p_accounting_line_type_code  => l_component_type_code
19881       ,p_accounting_line_appl_id    => l_component_appl_id
19882       ,p_amb_context_code           => l_amb_context_code
19883       ,p_entity_code                => l_entity_code
19884       ,p_event_class_code           => l_event_class_code);
19885    --
19886    -- set accounting class
19887    --
19888    xla_ae_lines_pkg.SetAcctClass(
19889            p_accounting_class_code  => 'ROUNDING'
19890          , p_ae_header_id           => l_ae_header_id
19891          );
19892 
19893    --
19894    -- set rounding class
19895    --
19896    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
19897                       'RECEIVABLE';
19898 
19899    --
19900    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
19901    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
19902    --
19903    -- bulk performance
19904    --
19905    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
19906 
19907    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
19908       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
19909 
19910    -- 4955764
19911    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
19912       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
19913 
19914    -- 4458381 Public Sector Enh
19915    
19916    --
19917    -- set accounting attributes for the line type
19918    --
19919    l_entered_amt_idx := 3;
19920    l_accted_amt_idx  := 8;
19921    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
19922    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
19923    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
19924    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
19925    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
19926    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
19927    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
19928    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
19929    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
19930    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
19931    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
19932    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
19933    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
19934    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
19935    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
19936    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
19937    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
19938    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
19939    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
19940    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
19941    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
19942    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
19943    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
19944    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
19945    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
19946 
19947    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
19948    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
19949 
19950    ---------------------------------------------------------------------------------------------------------------
19951    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
19952    ---------------------------------------------------------------------------------------------------------------
19953    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
19954 
19955    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
19956    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
19957 
19958    IF xla_accounting_cache_pkg.GetValueChar
19959          (p_source_code         => 'LEDGER_CATEGORY_CODE'
19960          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
19961    AND l_bflow_method_code = 'PRIOR_ENTRY'
19962 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
19963    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
19964          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
19965        )
19966    THEN
19967          xla_ae_lines_pkg.BflowUpgEntry
19968            (p_business_method_code    => l_bflow_method_code
19969            ,p_business_class_code     => l_bflow_class_code
19970            ,p_balance_type            => l_balance_type_code);
19971    ELSE
19972       NULL;
19973 -- No business flow processing for business flow method of NONE.
19974    END IF;
19975 
19976    --
19977    -- call analytical criteria
19978    --
19979    
19980    --
19981    -- call description
19982    --
19983    -- No description or it is inherited.
19984    --
19985    -- call ADRs
19986    -- Bug 4922099
19987    --
19988    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
19989         (NVL(l_actual_upg_option, 'N') = 'O') OR
19990         (NVL(l_enc_upg_option, 'N') = 'O')
19991       )
19992    THEN
19993    NULL;
19994    --
19995    --
19996    
19997   l_ccid := AcctDerRule_16(
19998            p_application_id           => p_application_id
19999          , p_ae_header_id             => l_ae_header_id 
20000 , p_source_4 => p_source_4
20001          , x_transaction_coa_id       => l_adr_transaction_coa_id
20002          , x_accounting_coa_id        => l_adr_accounting_coa_id
20003          , x_value_type_code          => l_adr_value_type_code
20004          , p_side                     => 'NA'
20005    );
20006 
20007    xla_ae_lines_pkg.set_ccid(
20008     p_code_combination_id          => l_ccid
20009   , p_value_type_code              => l_adr_value_type_code
20010   , p_transaction_coa_id           => l_adr_transaction_coa_id
20011   , p_accounting_coa_id            => l_adr_accounting_coa_id
20012   , p_adr_code                     => 'TRX_DIST_CCID'
20013   , p_adr_type_code                => 'S'
20014   , p_component_type               => l_component_type
20015   , p_component_code               => l_component_code
20016   , p_component_type_code          => l_component_type_code
20017   , p_component_appl_id            => l_component_appl_id
20021 
20018   , p_amb_context_code             => l_amb_context_code
20019   , p_side                         => 'NA'
20020   );
20022 
20023    --
20024    --
20025    END IF;
20026    --
20027    -- Bug 4922099
20028    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
20029           (NVL(l_enc_upg_option, 'N') = 'O')
20030         ) AND
20031         (l_bflow_method_code = 'PRIOR_ENTRY')
20032       )
20033    THEN
20034       IF
20035       --
20036       1 = 2
20037       --
20038       THEN
20039       xla_accounting_err_pkg.build_message
20040                                     (p_appli_s_name            => 'XLA'
20041                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
20042                                     ,p_token_1                 => 'LINE_NUMBER'
20043                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
20044                                     ,p_token_2                 => 'LINE_TYPE_NAME'
20045                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
20046                                                                              l_component_type
20047                                                                             ,l_component_code
20048                                                                             ,l_component_type_code
20049                                                                             ,l_component_appl_id
20050                                                                             ,l_amb_context_code
20051                                                                             ,l_entity_code
20052                                                                             ,l_event_class_code
20053                                                                            )
20054                                     ,p_token_3                 => 'OWNER'
20055                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
20056                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
20057                                                                           ,p_lookup_code    => l_component_type_code
20058                                                                          )
20059                                     ,p_token_4                 => 'PRODUCT_NAME'
20060                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
20061                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
20062                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
20063                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
20064                                     ,p_ae_header_id            =>  NULL
20065                                        );
20066 
20067         IF (C_LEVEL_ERROR>= g_log_level) THEN
20068                  trace
20069                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
20070                       ,p_level    => C_LEVEL_ERROR
20071                       ,p_module   => l_log_module);
20072         END IF;
20073       END IF;
20074    END IF;
20075    --
20076    --
20077    ------------------------------------------------------------------------------------------------
20078    -- 4219869 Business Flow
20079    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
20080    -- Prior Entry.  Currently, the following code is always generated.
20081    ------------------------------------------------------------------------------------------------
20082    XLA_AE_LINES_PKG.ValidateCurrentLine;
20083 
20084    ------------------------------------------------------------------------------------
20085    -- 4219869 Business Flow
20086    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
20087    ------------------------------------------------------------------------------------
20088    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
20089 
20090    ----------------------------------------------------------------------------------
20091    -- 4219869 Business Flow
20092    -- Update journal entry status -- Need to generate this within IF <condition>
20093    ----------------------------------------------------------------------------------
20094    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
20095          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
20096          ,p_balance_type_code => l_balance_type_code
20097          );
20098 
20099    -------------------------------------------------------------------------------------------
20100    -- 4262811 - Generate the Accrual Reversal lines
20101    -------------------------------------------------------------------------------------------
20102    BEGIN
20103       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
20104                               (g_array_event(p_event_id).array_value_num('header_index'));
20105       IF l_acc_rev_flag IS NULL THEN
20106          l_acc_rev_flag := 'N';
20107       END IF;
20108    EXCEPTION
20109       WHEN OTHERS THEN
20110          l_acc_rev_flag := 'N';
20111    END;
20112    --
20113    IF (l_acc_rev_flag = 'Y') THEN
20114 
20115        -- 4645092  ------------------------------------------------------------------------------
20116        -- To allow MPA report to determine if it should generate report process
20117        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
20118        ------------------------------------------------------------------------------------------
20119 
20120        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
20121        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
20122    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
20123    -- call ADRs
20124    -- Bug 4922099
20125    --
20126    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
20127         (NVL(l_actual_upg_option, 'N') = 'O') OR
20128         (NVL(l_enc_upg_option, 'N') = 'O')
20129       )
20130    THEN
20131    NULL;
20132    --
20133    --
20134    
20135   l_ccid := AcctDerRule_16(
20136            p_application_id           => p_application_id
20137          , p_ae_header_id             => l_ae_header_id 
20138 , p_source_4 => p_source_4
20139          , x_transaction_coa_id       => l_adr_transaction_coa_id
20140          , x_accounting_coa_id        => l_adr_accounting_coa_id
20141          , x_value_type_code          => l_adr_value_type_code
20142          , p_side                     => 'NA'
20143    );
20144 
20145    xla_ae_lines_pkg.set_ccid(
20146     p_code_combination_id          => l_ccid
20147   , p_value_type_code              => l_adr_value_type_code
20148   , p_transaction_coa_id           => l_adr_transaction_coa_id
20149   , p_accounting_coa_id            => l_adr_accounting_coa_id
20150   , p_adr_code                     => 'TRX_DIST_CCID'
20151   , p_adr_type_code                => 'S'
20152   , p_component_type               => l_component_type
20153   , p_component_code               => l_component_code
20154   , p_component_type_code          => l_component_type_code
20155   , p_component_appl_id            => l_component_appl_id
20156   , p_amb_context_code             => l_amb_context_code
20157   , p_side                         => 'NA'
20158   );
20159 
20160 
20161    --
20162    --
20163    END IF;
20164 
20165        --
20166        -- Update the line information that should be overwritten
20167        --
20168        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
20169                                          p_header_num   => 1);
20170        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
20171 
20172        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
20173 
20174        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
20175           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
20176        END IF;
20177 
20178       --
20179       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
20180       --
20181       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
20182           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
20183       ELSE
20184           ---------------------------------------------------------------------------------------------------
20185           -- 4262811a Switch Sign
20186           ---------------------------------------------------------------------------------------------------
20187           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
20188           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
20189                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20190           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
20191                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20192           -- 5132302
20193           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
20194                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20195 
20196       END IF;
20197 
20198       -- 4955764
20199       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
20200       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
20201 
20202 
20203       XLA_AE_LINES_PKG.ValidateCurrentLine;
20204       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
20205 
20206       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
20207                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
20208                ,p_balance_type_code => l_balance_type_code);
20209 
20210    END IF;
20211 
20212    -----------------------------------------------------------------------------------------
20213    -- 4262811 Multiperiod Accounting
20214    -----------------------------------------------------------------------------------------
20215      -- No MPA option is assigned.
20216 
20217 
20218 END IF;
20219 END IF;
20220 --
20221 
20222 --
20223 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
20224    trace
20225       (p_msg      => 'END of AcctLineType_48'
20226       ,p_level    => C_LEVEL_PROCEDURE
20227       ,p_module   => l_log_module);
20228 END IF;
20229 --
20230 EXCEPTION
20231   WHEN xla_exceptions_pkg.application_exception THEN
20232       RAISE;
20233   WHEN OTHERS THEN
20234        xla_exceptions_pkg.raise_message
20235            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_48');
20236 END AcctLineType_48;
20237 --
20238 
20239 ---------------------------------------
20240 --
20241 -- PRIVATE FUNCTION
20242 --         AcctLineType_49
20243 --
20244 ---------------------------------------
20245 PROCEDURE AcctLineType_49 (
20246   p_application_id        IN NUMBER
20247  ,p_event_id              IN NUMBER
20248  ,p_calculate_acctd_flag  IN VARCHAR2
20249  ,p_calculate_g_l_flag    IN VARCHAR2
20250  ,p_actual_flag           IN OUT VARCHAR2
20251  ,p_balance_type_code     OUT VARCHAR2
20252  ,p_gain_or_loss_ref      OUT VARCHAR2
20253  
20254 --Transaction Distribution GL Account
20255  , p_source_4            IN NUMBER
20256 --Bill To Customer Account Identifier
20257  , p_source_23            IN NUMBER
20258 --Bill To Customer Site Use Identifier
20259  , p_source_24            IN NUMBER
20260 --SLA Party Type
20261  , p_source_25            IN VARCHAR2
20262 --Transaction Distribution Account Class
20263  , p_source_26            IN VARCHAR2
20264 --Transaction Distribution Identifier
20265  , p_source_27            IN NUMBER
20266 --Transaction Distribution Type
20267  , p_source_28            IN VARCHAR2
20268 --Transaction Distribution Entered Amount
20269  , p_source_29            IN NUMBER
20270 --Transaction Currency Code
20271  , p_source_30            IN VARCHAR2
20272 --Transaction Exchange Date
20273  , p_source_31            IN DATE
20274 --Transaction Exchange Rate
20275  , p_source_32            IN NUMBER
20276 --Transaction Exchange Rate Type
20277  , p_source_33            IN VARCHAR2
20278 --Transaction Accounting Amount
20279  , p_source_34            IN NUMBER
20280 --Transaction Tax Line Identifier
20281  , p_source_48            IN NUMBER
20282 )
20283 IS
20284 
20285 l_component_type              VARCHAR2(80);
20286 l_component_code              VARCHAR2(30);
20287 l_component_type_code         VARCHAR2(1);
20288 l_component_appl_id           INTEGER;
20289 l_amb_context_code            VARCHAR2(30);
20290 l_entity_code                 VARCHAR2(30);
20291 l_event_class_code            VARCHAR2(30);
20292 l_ae_header_id                NUMBER;
20293 l_event_type_code             VARCHAR2(30);
20294 l_line_definition_code        VARCHAR2(30);
20295 l_line_definition_owner_code  VARCHAR2(1);
20296 --
20297 -- adr variables
20298 l_segment                     VARCHAR2(30);
20299 l_ccid                        NUMBER;
20300 l_adr_transaction_coa_id      NUMBER;
20301 l_adr_accounting_coa_id       NUMBER;
20302 l_adr_flexfield_segment_code  VARCHAR2(30);
20303 l_adr_flex_value_set_id       NUMBER;
20304 l_adr_value_type_code         VARCHAR2(30);
20305 l_adr_value_combination_id    NUMBER;
20306 l_adr_value_segment_code      VARCHAR2(30);
20307 
20308 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
20309 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
20310 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
20311 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
20312 
20313 -- 4262811 Variables ------------------------------------------------------------------------------------------
20314 l_entered_amt_idx             NUMBER;
20315 l_accted_amt_idx              NUMBER;
20316 l_acc_rev_flag                VARCHAR2(1);
20317 l_accrual_line_num            NUMBER;
20318 l_tmp_amt                     NUMBER;
20319 l_acc_rev_natural_side_code   VARCHAR2(1);
20320 
20321 l_num_entries                 NUMBER;
20322 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
20323 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
20324 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
20325 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
20326 l_recog_line_1                NUMBER;
20327 l_recog_line_2                NUMBER;
20328 
20329 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
20330 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
20331 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
20332 
20333 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
20334 
20335 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
20336 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
20337 
20338 ---------------------------------------------------------------------------------------------------------------
20339 
20340 
20341 --
20342 -- bulk performance
20343 --
20344 l_balance_type_code           VARCHAR2(1);
20345 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
20346 l_log_module                  VARCHAR2(240);
20347 
20348 --
20349 -- Upgrade strategy
20350 --
20351 l_actual_upg_option           VARCHAR2(1);
20352 l_enc_upg_option           VARCHAR2(1);
20353 
20354 --
20355 BEGIN
20356 --
20357 IF g_log_enabled THEN
20358       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_49';
20359 END IF;
20360 --
20361 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
20362 
20363       trace
20364          (p_msg      => 'BEGIN of AcctLineType_49'
20365          ,p_level    => C_LEVEL_PROCEDURE
20366          ,p_module   => l_log_module);
20367 
20368 END IF;
20369 --
20370 l_component_type             := 'AMB_JLT';
20371 l_component_code             := 'INV_TAX';
20372 l_component_type_code        := 'S';
20373 l_component_appl_id          :=  222;
20374 l_amb_context_code           := 'DEFAULT';
20375 l_entity_code                := 'TRANSACTIONS';
20376 l_event_class_code           := 'INVOICE';
20377 l_event_type_code            := 'INVOICE_ALL';
20378 l_line_definition_owner_code := 'S';
20379 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
20380 --
20381 l_balance_type_code          := 'A';
20382 l_segment                     := NULL;
20383 l_ccid                        := NULL;
20384 l_adr_transaction_coa_id      := NULL;
20385 l_adr_accounting_coa_id       := NULL;
20386 l_adr_flexfield_segment_code  := NULL;
20387 l_adr_flex_value_set_id       := NULL;
20388 l_adr_value_type_code         := NULL;
20389 l_adr_value_combination_id    := NULL;
20390 l_adr_value_segment_code      := NULL;
20391 
20392 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
20393 l_bflow_class_code           := 'TAX';    -- 4219869 Business Flow
20394 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
20395 l_budgetary_control_flag     := 'N';
20396 
20397 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
20398 l_bflow_applied_to_amt       := NULL; -- 5132302
20399 l_entered_amt_idx            := NULL;          -- 4262811
20400 l_accted_amt_idx             := NULL;          -- 4262811
20401 l_acc_rev_flag               := NULL;          -- 4262811
20402 l_accrual_line_num           := NULL;          -- 4262811
20403 l_tmp_amt                    := NULL;          -- 4262811
20404 --
20405  
20406 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
20407     l_balance_type_code <> 'B' THEN
20408 IF NVL(p_source_26,'
20409 ') =  'TAX'
20410  THEN 
20411 
20412    --
20413    XLA_AE_LINES_PKG.SetNewLine;
20414 
20415    p_balance_type_code          := l_balance_type_code;
20416    -- set the flag so later we will know whether the gain loss line needs to be created
20417    
20418    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
20419      p_actual_flag :='A';
20420    END IF;
20421 
20422    --
20423    -- bulk performance
20424    --
20425    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
20426                                       p_header_num   => 0); -- 4262811
20427    --
20428    -- set accounting line options
20429    --
20430    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
20431            p_natural_side_code          => 'C'
20432          , p_gain_or_loss_flag          => 'N'
20433          , p_gl_transfer_mode_code      => 'S'
20434          , p_acct_entry_type_code       => 'A'
20435          , p_switch_side_flag           => 'Y'
20436          , p_merge_duplicate_code       => 'A'
20437          );
20438    --
20439    l_acc_rev_natural_side_code := 'D';  -- 4262811
20440    -- 
20441    --
20442    -- set accounting line type info
20443    --
20444    xla_ae_lines_pkg.SetAcctLineType
20445       (p_component_type             => l_component_type
20446       ,p_event_type_code            => l_event_type_code
20447       ,p_line_definition_owner_code => l_line_definition_owner_code
20448       ,p_line_definition_code       => l_line_definition_code
20449       ,p_accounting_line_code       => l_component_code
20450       ,p_accounting_line_type_code  => l_component_type_code
20451       ,p_accounting_line_appl_id    => l_component_appl_id
20452       ,p_amb_context_code           => l_amb_context_code
20453       ,p_entity_code                => l_entity_code
20454       ,p_event_class_code           => l_event_class_code);
20455    --
20456    -- set accounting class
20457    --
20458    xla_ae_lines_pkg.SetAcctClass(
20459            p_accounting_class_code  => 'TAX'
20460          , p_ae_header_id           => l_ae_header_id
20461          );
20462 
20463    --
20464    -- set rounding class
20465    --
20466    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
20467                       'RECEIVABLE';
20468 
20469    --
20470    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
20471    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
20472    --
20473    -- bulk performance
20474    --
20475    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
20476 
20477    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
20478       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
20479 
20480    -- 4955764
20481    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
20482       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
20483 
20484    -- 4458381 Public Sector Enh
20485    
20486    --
20487    -- set accounting attributes for the line type
20488    --
20489    l_entered_amt_idx := 3;
20490    l_accted_amt_idx  := 8;
20491    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
20492    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
20493    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
20494    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
20495    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
20496    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
20497    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
20498    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
20499    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
20500    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
20501    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
20502    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
20503    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
20504    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
20505    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
20506    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
20507    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
20508    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
20509    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
20510    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
20511    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
20512    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
20513    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
20514    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
20515    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
20516 
20517    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
20518    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
20519 
20520    ---------------------------------------------------------------------------------------------------------------
20521    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
20522    ---------------------------------------------------------------------------------------------------------------
20523    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
20524 
20525    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
20526    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
20527 
20528    IF xla_accounting_cache_pkg.GetValueChar
20529          (p_source_code         => 'LEDGER_CATEGORY_CODE'
20530          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
20531    AND l_bflow_method_code = 'PRIOR_ENTRY'
20532 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
20533    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
20534          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
20535        )
20536    THEN
20537          xla_ae_lines_pkg.BflowUpgEntry
20538            (p_business_method_code    => l_bflow_method_code
20539            ,p_business_class_code     => l_bflow_class_code
20540            ,p_balance_type            => l_balance_type_code);
20541    ELSE
20542       NULL;
20543 -- No business flow processing for business flow method of NONE.
20544    END IF;
20545 
20546    --
20547    -- call analytical criteria
20548    --
20549    
20550    --
20551    -- call description
20552    --
20553    -- No description or it is inherited.
20554    --
20555    -- call ADRs
20556    -- Bug 4922099
20557    --
20558    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
20559         (NVL(l_actual_upg_option, 'N') = 'O') OR
20560         (NVL(l_enc_upg_option, 'N') = 'O')
20561       )
20562    THEN
20563    NULL;
20564    --
20565    --
20566    
20567   l_ccid := AcctDerRule_16(
20568            p_application_id           => p_application_id
20569          , p_ae_header_id             => l_ae_header_id 
20570 , p_source_4 => p_source_4
20571          , x_transaction_coa_id       => l_adr_transaction_coa_id
20572          , x_accounting_coa_id        => l_adr_accounting_coa_id
20573          , x_value_type_code          => l_adr_value_type_code
20574          , p_side                     => 'NA'
20575    );
20576 
20577    xla_ae_lines_pkg.set_ccid(
20578     p_code_combination_id          => l_ccid
20579   , p_value_type_code              => l_adr_value_type_code
20580   , p_transaction_coa_id           => l_adr_transaction_coa_id
20581   , p_accounting_coa_id            => l_adr_accounting_coa_id
20582   , p_adr_code                     => 'TRX_DIST_CCID'
20583   , p_adr_type_code                => 'S'
20584   , p_component_type               => l_component_type
20585   , p_component_code               => l_component_code
20586   , p_component_type_code          => l_component_type_code
20587   , p_component_appl_id            => l_component_appl_id
20588   , p_amb_context_code             => l_amb_context_code
20589   , p_side                         => 'NA'
20590   );
20591 
20592 
20593    --
20594    --
20595    END IF;
20596    --
20597    -- Bug 4922099
20598    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
20599           (NVL(l_enc_upg_option, 'N') = 'O')
20600         ) AND
20601         (l_bflow_method_code = 'PRIOR_ENTRY')
20602       )
20603    THEN
20604       IF
20605       --
20606       1 = 2
20607       --
20608       THEN
20609       xla_accounting_err_pkg.build_message
20610                                     (p_appli_s_name            => 'XLA'
20611                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
20612                                     ,p_token_1                 => 'LINE_NUMBER'
20613                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
20614                                     ,p_token_2                 => 'LINE_TYPE_NAME'
20615                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
20616                                                                              l_component_type
20617                                                                             ,l_component_code
20618                                                                             ,l_component_type_code
20619                                                                             ,l_component_appl_id
20620                                                                             ,l_amb_context_code
20621                                                                             ,l_entity_code
20622                                                                             ,l_event_class_code
20623                                                                            )
20624                                     ,p_token_3                 => 'OWNER'
20625                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
20626                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
20627                                                                           ,p_lookup_code    => l_component_type_code
20628                                                                          )
20629                                     ,p_token_4                 => 'PRODUCT_NAME'
20630                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
20631                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
20632                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
20633                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
20634                                     ,p_ae_header_id            =>  NULL
20635                                        );
20636 
20637         IF (C_LEVEL_ERROR>= g_log_level) THEN
20638                  trace
20639                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
20640                       ,p_level    => C_LEVEL_ERROR
20641                       ,p_module   => l_log_module);
20642         END IF;
20643       END IF;
20644    END IF;
20645    --
20646    --
20647    ------------------------------------------------------------------------------------------------
20648    -- 4219869 Business Flow
20649    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
20650    -- Prior Entry.  Currently, the following code is always generated.
20651    ------------------------------------------------------------------------------------------------
20652    XLA_AE_LINES_PKG.ValidateCurrentLine;
20653 
20654    ------------------------------------------------------------------------------------
20655    -- 4219869 Business Flow
20656    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
20657    ------------------------------------------------------------------------------------
20658    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
20659 
20660    ----------------------------------------------------------------------------------
20661    -- 4219869 Business Flow
20662    -- Update journal entry status -- Need to generate this within IF <condition>
20663    ----------------------------------------------------------------------------------
20664    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
20665          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
20666          ,p_balance_type_code => l_balance_type_code
20667          );
20668 
20669    -------------------------------------------------------------------------------------------
20670    -- 4262811 - Generate the Accrual Reversal lines
20671    -------------------------------------------------------------------------------------------
20672    BEGIN
20673       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
20674                               (g_array_event(p_event_id).array_value_num('header_index'));
20675       IF l_acc_rev_flag IS NULL THEN
20676          l_acc_rev_flag := 'N';
20677       END IF;
20678    EXCEPTION
20679       WHEN OTHERS THEN
20680          l_acc_rev_flag := 'N';
20681    END;
20682    --
20683    IF (l_acc_rev_flag = 'Y') THEN
20684 
20685        -- 4645092  ------------------------------------------------------------------------------
20686        -- To allow MPA report to determine if it should generate report process
20687        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
20688        ------------------------------------------------------------------------------------------
20689 
20690        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
20691        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
20692    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
20693    -- call ADRs
20694    -- Bug 4922099
20695    --
20696    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
20697         (NVL(l_actual_upg_option, 'N') = 'O') OR
20698         (NVL(l_enc_upg_option, 'N') = 'O')
20699       )
20700    THEN
20701    NULL;
20702    --
20703    --
20704    
20705   l_ccid := AcctDerRule_16(
20706            p_application_id           => p_application_id
20707          , p_ae_header_id             => l_ae_header_id 
20708 , p_source_4 => p_source_4
20709          , x_transaction_coa_id       => l_adr_transaction_coa_id
20710          , x_accounting_coa_id        => l_adr_accounting_coa_id
20711          , x_value_type_code          => l_adr_value_type_code
20712          , p_side                     => 'NA'
20713    );
20714 
20715    xla_ae_lines_pkg.set_ccid(
20716     p_code_combination_id          => l_ccid
20717   , p_value_type_code              => l_adr_value_type_code
20718   , p_transaction_coa_id           => l_adr_transaction_coa_id
20719   , p_accounting_coa_id            => l_adr_accounting_coa_id
20720   , p_adr_code                     => 'TRX_DIST_CCID'
20721   , p_adr_type_code                => 'S'
20722   , p_component_type               => l_component_type
20723   , p_component_code               => l_component_code
20724   , p_component_type_code          => l_component_type_code
20725   , p_component_appl_id            => l_component_appl_id
20726   , p_amb_context_code             => l_amb_context_code
20727   , p_side                         => 'NA'
20728   );
20729 
20730 
20731    --
20732    --
20733    END IF;
20734 
20735        --
20736        -- Update the line information that should be overwritten
20737        --
20738        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
20739                                          p_header_num   => 1);
20740        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
20741 
20742        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
20743 
20744        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
20745           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
20746        END IF;
20747 
20748       --
20749       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
20750       --
20751       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
20752           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
20753       ELSE
20754           ---------------------------------------------------------------------------------------------------
20755           -- 4262811a Switch Sign
20756           ---------------------------------------------------------------------------------------------------
20757           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
20758           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
20759                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20760           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
20761                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20762           -- 5132302
20763           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
20764                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20765 
20766       END IF;
20767 
20768       -- 4955764
20769       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
20770       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
20771 
20772 
20773       XLA_AE_LINES_PKG.ValidateCurrentLine;
20774       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
20775 
20776       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
20777                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
20778                ,p_balance_type_code => l_balance_type_code);
20779 
20780    END IF;
20781 
20782    -----------------------------------------------------------------------------------------
20783    -- 4262811 Multiperiod Accounting
20784    -----------------------------------------------------------------------------------------
20785      -- No MPA option is assigned.
20786 
20787 
20788 END IF;
20792 --
20789 END IF;
20790 --
20791 
20793 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
20794    trace
20795       (p_msg      => 'END of AcctLineType_49'
20796       ,p_level    => C_LEVEL_PROCEDURE
20797       ,p_module   => l_log_module);
20798 END IF;
20799 --
20800 EXCEPTION
20801   WHEN xla_exceptions_pkg.application_exception THEN
20802       RAISE;
20803   WHEN OTHERS THEN
20804        xla_exceptions_pkg.raise_message
20805            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_49');
20806 END AcctLineType_49;
20807 --
20808 
20809 ---------------------------------------
20810 --
20811 -- PRIVATE FUNCTION
20812 --         AcctLineType_50
20813 --
20814 ---------------------------------------
20815 PROCEDURE AcctLineType_50 (
20816   p_application_id        IN NUMBER
20817  ,p_event_id              IN NUMBER
20818  ,p_calculate_acctd_flag  IN VARCHAR2
20819  ,p_calculate_g_l_flag    IN VARCHAR2
20820  ,p_actual_flag           IN OUT VARCHAR2
20821  ,p_balance_type_code     OUT VARCHAR2
20822  ,p_gain_or_loss_ref      OUT VARCHAR2
20823  
20824 --Transaction Distribution GL Account
20825  , p_source_4            IN NUMBER
20826 --Bill To Customer Account Identifier
20827  , p_source_23            IN NUMBER
20828 --Bill To Customer Site Use Identifier
20829  , p_source_24            IN NUMBER
20830 --SLA Party Type
20831  , p_source_25            IN VARCHAR2
20832 --Transaction Distribution Account Class
20833  , p_source_26            IN VARCHAR2
20834 --Transaction Distribution Identifier
20835  , p_source_27            IN NUMBER
20836 --Transaction Distribution Type
20837  , p_source_28            IN VARCHAR2
20838 --Transaction Distribution Entered Amount
20839  , p_source_29            IN NUMBER
20840 --Transaction Currency Code
20841  , p_source_30            IN VARCHAR2
20842 --Transaction Exchange Date
20843  , p_source_31            IN DATE
20844 --Transaction Exchange Rate
20845  , p_source_32            IN NUMBER
20846 --Transaction Exchange Rate Type
20847  , p_source_33            IN VARCHAR2
20848 --Transaction Accounting Amount
20849  , p_source_34            IN NUMBER
20850 --Transaction Tax Line Identifier
20851  , p_source_48            IN NUMBER
20852 --Rounding Correction Flag
20853  , p_source_49            IN VARCHAR2
20854 )
20855 IS
20856 
20857 l_component_type              VARCHAR2(80);
20858 l_component_code              VARCHAR2(30);
20859 l_component_type_code         VARCHAR2(1);
20860 l_component_appl_id           INTEGER;
20861 l_amb_context_code            VARCHAR2(30);
20862 l_entity_code                 VARCHAR2(30);
20863 l_event_class_code            VARCHAR2(30);
20864 l_ae_header_id                NUMBER;
20865 l_event_type_code             VARCHAR2(30);
20866 l_line_definition_code        VARCHAR2(30);
20867 l_line_definition_owner_code  VARCHAR2(1);
20868 --
20869 -- adr variables
20870 l_segment                     VARCHAR2(30);
20871 l_ccid                        NUMBER;
20872 l_adr_transaction_coa_id      NUMBER;
20873 l_adr_accounting_coa_id       NUMBER;
20874 l_adr_flexfield_segment_code  VARCHAR2(30);
20875 l_adr_flex_value_set_id       NUMBER;
20876 l_adr_value_type_code         VARCHAR2(30);
20877 l_adr_value_combination_id    NUMBER;
20878 l_adr_value_segment_code      VARCHAR2(30);
20879 
20880 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
20881 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
20882 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
20883 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
20884 
20885 -- 4262811 Variables ------------------------------------------------------------------------------------------
20886 l_entered_amt_idx             NUMBER;
20887 l_accted_amt_idx              NUMBER;
20888 l_acc_rev_flag                VARCHAR2(1);
20889 l_accrual_line_num            NUMBER;
20890 l_tmp_amt                     NUMBER;
20891 l_acc_rev_natural_side_code   VARCHAR2(1);
20892 
20893 l_num_entries                 NUMBER;
20894 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
20895 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
20896 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
20897 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
20898 l_recog_line_1                NUMBER;
20899 l_recog_line_2                NUMBER;
20900 
20901 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
20902 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
20903 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
20904 
20905 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
20906 
20907 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
20908 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
20909 
20910 ---------------------------------------------------------------------------------------------------------------
20911 
20912 
20913 --
20914 -- bulk performance
20915 --
20916 l_balance_type_code           VARCHAR2(1);
20917 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
20918 l_log_module                  VARCHAR2(240);
20919 
20920 --
20921 -- Upgrade strategy
20922 --
20923 l_actual_upg_option           VARCHAR2(1);
20924 l_enc_upg_option           VARCHAR2(1);
20925 
20926 --
20927 BEGIN
20928 --
20929 IF g_log_enabled THEN
20930       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_50';
20931 END IF;
20932 --
20933 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
20934 
20935       trace
20936          (p_msg      => 'BEGIN of AcctLineType_50'
20937          ,p_level    => C_LEVEL_PROCEDURE
20938          ,p_module   => l_log_module);
20939 
20940 END IF;
20941 --
20942 l_component_type             := 'AMB_JLT';
20943 l_component_code             := 'INV_UNBILL';
20944 l_component_type_code        := 'S';
20945 l_component_appl_id          :=  222;
20946 l_amb_context_code           := 'DEFAULT';
20947 l_entity_code                := 'TRANSACTIONS';
20948 l_event_class_code           := 'INVOICE';
20949 l_event_type_code            := 'INVOICE_ALL';
20950 l_line_definition_owner_code := 'S';
20951 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
20952 --
20953 l_balance_type_code          := 'A';
20954 l_segment                     := NULL;
20955 l_ccid                        := NULL;
20956 l_adr_transaction_coa_id      := NULL;
20957 l_adr_accounting_coa_id       := NULL;
20958 l_adr_flexfield_segment_code  := NULL;
20959 l_adr_flex_value_set_id       := NULL;
20960 l_adr_value_type_code         := NULL;
20961 l_adr_value_combination_id    := NULL;
20962 l_adr_value_segment_code      := NULL;
20963 
20964 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
20965 l_bflow_class_code           := '';    -- 4219869 Business Flow
20966 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
20967 l_budgetary_control_flag     := 'N';
20968 
20969 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
20970 l_bflow_applied_to_amt       := NULL; -- 5132302
20971 l_entered_amt_idx            := NULL;          -- 4262811
20972 l_accted_amt_idx             := NULL;          -- 4262811
20973 l_acc_rev_flag               := NULL;          -- 4262811
20974 l_accrual_line_num           := NULL;          -- 4262811
20975 l_tmp_amt                    := NULL;          -- 4262811
20976 --
20977  
20978 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
20979     l_balance_type_code <> 'B' THEN
20980 IF NVL(p_source_26,'
20981 ') =  'UNBILL' AND 
20982 p_source_49 IS NULL 
20983  THEN 
20984 
20985    --
20986    XLA_AE_LINES_PKG.SetNewLine;
20987 
20988    p_balance_type_code          := l_balance_type_code;
20989    -- set the flag so later we will know whether the gain loss line needs to be created
20990    
20991    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
20992      p_actual_flag :='A';
20993    END IF;
20994 
20995    --
20996    -- bulk performance
20997    --
20998    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
20999                                       p_header_num   => 0); -- 4262811
21000    --
21001    -- set accounting line options
21002    --
21003    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
21004            p_natural_side_code          => 'C'
21005          , p_gain_or_loss_flag          => 'N'
21006          , p_gl_transfer_mode_code      => 'S'
21007          , p_acct_entry_type_code       => 'A'
21008          , p_switch_side_flag           => 'Y'
21009          , p_merge_duplicate_code       => 'A'
21010          );
21011    --
21012    l_acc_rev_natural_side_code := 'D';  -- 4262811
21013    -- 
21014    --
21015    -- set accounting line type info
21016    --
21017    xla_ae_lines_pkg.SetAcctLineType
21018       (p_component_type             => l_component_type
21019       ,p_event_type_code            => l_event_type_code
21020       ,p_line_definition_owner_code => l_line_definition_owner_code
21021       ,p_line_definition_code       => l_line_definition_code
21022       ,p_accounting_line_code       => l_component_code
21023       ,p_accounting_line_type_code  => l_component_type_code
21024       ,p_accounting_line_appl_id    => l_component_appl_id
21025       ,p_amb_context_code           => l_amb_context_code
21026       ,p_entity_code                => l_entity_code
21027       ,p_event_class_code           => l_event_class_code);
21028    --
21029    -- set accounting class
21030    --
21031    xla_ae_lines_pkg.SetAcctClass(
21032            p_accounting_class_code  => 'UNBILL'
21033          , p_ae_header_id           => l_ae_header_id
21034          );
21035 
21036    --
21037    -- set rounding class
21038    --
21039    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
21040                       'UNBILL';
21041 
21042    --
21043    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
21044    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
21045    --
21046    -- bulk performance
21047    --
21048    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
21049 
21050    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
21051       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
21052 
21053    -- 4955764
21054    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
21055       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
21056 
21057    -- 4458381 Public Sector Enh
21058    
21059    --
21060    -- set accounting attributes for the line type
21061    --
21062    l_entered_amt_idx := 3;
21063    l_accted_amt_idx  := 8;
21064    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
21065    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
21066    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
21067    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
21068    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
21069    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
21070    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
21071    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
21072    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
21073    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
21074    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
21075    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
21076    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
21077    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
21078    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
21079    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
21080    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
21081    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
21082    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
21083    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
21084    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
21085    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
21086    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
21087    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
21088    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
21089 
21090    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
21091    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
21092 
21093    ---------------------------------------------------------------------------------------------------------------
21094    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
21095    ---------------------------------------------------------------------------------------------------------------
21096    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
21097 
21098    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
21099    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
21100 
21101    IF xla_accounting_cache_pkg.GetValueChar
21102          (p_source_code         => 'LEDGER_CATEGORY_CODE'
21103          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
21104    AND l_bflow_method_code = 'PRIOR_ENTRY'
21105 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
21106    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
21107          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
21108        )
21109    THEN
21110          xla_ae_lines_pkg.BflowUpgEntry
21111            (p_business_method_code    => l_bflow_method_code
21112            ,p_business_class_code     => l_bflow_class_code
21113            ,p_balance_type            => l_balance_type_code);
21114    ELSE
21115       NULL;
21116 -- No business flow processing for business flow method of NONE.
21117    END IF;
21118 
21119    --
21120    -- call analytical criteria
21121    --
21122    
21123    --
21124    -- call description
21125    --
21126    -- No description or it is inherited.
21127    --
21128    -- call ADRs
21129    -- Bug 4922099
21130    --
21134       )
21131    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
21132         (NVL(l_actual_upg_option, 'N') = 'O') OR
21133         (NVL(l_enc_upg_option, 'N') = 'O')
21135    THEN
21136    NULL;
21137    --
21138    --
21139    
21140   l_ccid := AcctDerRule_16(
21141            p_application_id           => p_application_id
21142          , p_ae_header_id             => l_ae_header_id 
21143 , p_source_4 => p_source_4
21144          , x_transaction_coa_id       => l_adr_transaction_coa_id
21145          , x_accounting_coa_id        => l_adr_accounting_coa_id
21146          , x_value_type_code          => l_adr_value_type_code
21147          , p_side                     => 'NA'
21148    );
21149 
21150    xla_ae_lines_pkg.set_ccid(
21151     p_code_combination_id          => l_ccid
21152   , p_value_type_code              => l_adr_value_type_code
21153   , p_transaction_coa_id           => l_adr_transaction_coa_id
21154   , p_accounting_coa_id            => l_adr_accounting_coa_id
21155   , p_adr_code                     => 'TRX_DIST_CCID'
21156   , p_adr_type_code                => 'S'
21157   , p_component_type               => l_component_type
21158   , p_component_code               => l_component_code
21159   , p_component_type_code          => l_component_type_code
21160   , p_component_appl_id            => l_component_appl_id
21161   , p_amb_context_code             => l_amb_context_code
21162   , p_side                         => 'NA'
21163   );
21164 
21165 
21166    --
21167    --
21168    END IF;
21169    --
21170    -- Bug 4922099
21171    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
21172           (NVL(l_enc_upg_option, 'N') = 'O')
21173         ) AND
21174         (l_bflow_method_code = 'PRIOR_ENTRY')
21175       )
21176    THEN
21177       IF
21178       --
21179       1 = 2
21180       --
21181       THEN
21182       xla_accounting_err_pkg.build_message
21183                                     (p_appli_s_name            => 'XLA'
21184                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
21185                                     ,p_token_1                 => 'LINE_NUMBER'
21186                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
21187                                     ,p_token_2                 => 'LINE_TYPE_NAME'
21188                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
21189                                                                              l_component_type
21190                                                                             ,l_component_code
21191                                                                             ,l_component_type_code
21192                                                                             ,l_component_appl_id
21193                                                                             ,l_amb_context_code
21194                                                                             ,l_entity_code
21195                                                                             ,l_event_class_code
21196                                                                            )
21197                                     ,p_token_3                 => 'OWNER'
21198                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
21199                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
21200                                                                           ,p_lookup_code    => l_component_type_code
21201                                                                          )
21202                                     ,p_token_4                 => 'PRODUCT_NAME'
21203                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
21204                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
21205                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
21206                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
21207                                     ,p_ae_header_id            =>  NULL
21208                                        );
21209 
21210         IF (C_LEVEL_ERROR>= g_log_level) THEN
21211                  trace
21212                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
21213                       ,p_level    => C_LEVEL_ERROR
21214                       ,p_module   => l_log_module);
21215         END IF;
21216       END IF;
21217    END IF;
21218    --
21219    --
21220    ------------------------------------------------------------------------------------------------
21221    -- 4219869 Business Flow
21222    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
21223    -- Prior Entry.  Currently, the following code is always generated.
21224    ------------------------------------------------------------------------------------------------
21225    XLA_AE_LINES_PKG.ValidateCurrentLine;
21226 
21227    ------------------------------------------------------------------------------------
21228    -- 4219869 Business Flow
21229    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
21230    ------------------------------------------------------------------------------------
21231    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
21232 
21233    ----------------------------------------------------------------------------------
21234    -- 4219869 Business Flow
21235    -- Update journal entry status -- Need to generate this within IF <condition>
21239          ,p_balance_type_code => l_balance_type_code
21236    ----------------------------------------------------------------------------------
21237    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
21238          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
21240          );
21241 
21242    -------------------------------------------------------------------------------------------
21243    -- 4262811 - Generate the Accrual Reversal lines
21244    -------------------------------------------------------------------------------------------
21245    BEGIN
21246       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
21247                               (g_array_event(p_event_id).array_value_num('header_index'));
21248       IF l_acc_rev_flag IS NULL THEN
21249          l_acc_rev_flag := 'N';
21250       END IF;
21251    EXCEPTION
21252       WHEN OTHERS THEN
21253          l_acc_rev_flag := 'N';
21254    END;
21255    --
21256    IF (l_acc_rev_flag = 'Y') THEN
21257 
21258        -- 4645092  ------------------------------------------------------------------------------
21259        -- To allow MPA report to determine if it should generate report process
21260        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
21261        ------------------------------------------------------------------------------------------
21262 
21263        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
21264        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
21265    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
21266    -- call ADRs
21267    -- Bug 4922099
21268    --
21269    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
21270         (NVL(l_actual_upg_option, 'N') = 'O') OR
21271         (NVL(l_enc_upg_option, 'N') = 'O')
21272       )
21273    THEN
21274    NULL;
21275    --
21276    --
21277    
21278   l_ccid := AcctDerRule_16(
21279            p_application_id           => p_application_id
21280          , p_ae_header_id             => l_ae_header_id 
21281 , p_source_4 => p_source_4
21282          , x_transaction_coa_id       => l_adr_transaction_coa_id
21283          , x_accounting_coa_id        => l_adr_accounting_coa_id
21284          , x_value_type_code          => l_adr_value_type_code
21285          , p_side                     => 'NA'
21286    );
21287 
21288    xla_ae_lines_pkg.set_ccid(
21289     p_code_combination_id          => l_ccid
21290   , p_value_type_code              => l_adr_value_type_code
21291   , p_transaction_coa_id           => l_adr_transaction_coa_id
21292   , p_accounting_coa_id            => l_adr_accounting_coa_id
21293   , p_adr_code                     => 'TRX_DIST_CCID'
21294   , p_adr_type_code                => 'S'
21295   , p_component_type               => l_component_type
21296   , p_component_code               => l_component_code
21297   , p_component_type_code          => l_component_type_code
21298   , p_component_appl_id            => l_component_appl_id
21299   , p_amb_context_code             => l_amb_context_code
21300   , p_side                         => 'NA'
21301   );
21302 
21303 
21304    --
21305    --
21306    END IF;
21307 
21308        --
21309        -- Update the line information that should be overwritten
21310        --
21311        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
21312                                          p_header_num   => 1);
21313        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
21314 
21315        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
21316 
21317        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
21318           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
21319        END IF;
21320 
21321       --
21322       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
21323       --
21324       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
21325           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
21326       ELSE
21327           ---------------------------------------------------------------------------------------------------
21328           -- 4262811a Switch Sign
21329           ---------------------------------------------------------------------------------------------------
21330           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
21331           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
21332                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
21333           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
21334                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
21335           -- 5132302
21336           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
21337                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
21338 
21339       END IF;
21340 
21341       -- 4955764
21342       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
21343       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
21344 
21345 
21346       XLA_AE_LINES_PKG.ValidateCurrentLine;
21347       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
21348 
21349       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
21350                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
21351                ,p_balance_type_code => l_balance_type_code);
21352 
21353    END IF;
21354 
21355    -----------------------------------------------------------------------------------------
21356    -- 4262811 Multiperiod Accounting
21357    -----------------------------------------------------------------------------------------
21358      -- No MPA option is assigned.
21359 
21360 
21361 END IF;
21362 END IF;
21363 --
21364 
21365 --
21366 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
21367    trace
21368       (p_msg      => 'END of AcctLineType_50'
21369       ,p_level    => C_LEVEL_PROCEDURE
21370       ,p_module   => l_log_module);
21371 END IF;
21372 --
21373 EXCEPTION
21374   WHEN xla_exceptions_pkg.application_exception THEN
21375       RAISE;
21376   WHEN OTHERS THEN
21377        xla_exceptions_pkg.raise_message
21378            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_50');
21379 END AcctLineType_50;
21380 --
21381 
21382 ---------------------------------------
21383 --
21384 -- PRIVATE FUNCTION
21385 --         AcctLineType_51
21386 --
21387 ---------------------------------------
21388 PROCEDURE AcctLineType_51 (
21389   p_application_id        IN NUMBER
21390  ,p_event_id              IN NUMBER
21391  ,p_calculate_acctd_flag  IN VARCHAR2
21392  ,p_calculate_g_l_flag    IN VARCHAR2
21393  ,p_actual_flag           IN OUT VARCHAR2
21394  ,p_balance_type_code     OUT VARCHAR2
21395  ,p_gain_or_loss_ref      OUT VARCHAR2
21396  
21397 --Transaction Distribution GL Account
21398  , p_source_4            IN NUMBER
21399 --Bill To Customer Account Identifier
21400  , p_source_23            IN NUMBER
21401 --Bill To Customer Site Use Identifier
21402  , p_source_24            IN NUMBER
21403 --SLA Party Type
21404  , p_source_25            IN VARCHAR2
21405 --Transaction Distribution Account Class
21406  , p_source_26            IN VARCHAR2
21407 --Transaction Distribution Identifier
21408  , p_source_27            IN NUMBER
21409 --Transaction Distribution Type
21410  , p_source_28            IN VARCHAR2
21411 --Transaction Distribution Entered Amount
21412  , p_source_29            IN NUMBER
21413 --Transaction Currency Code
21414  , p_source_30            IN VARCHAR2
21415 --Transaction Exchange Date
21416  , p_source_31            IN DATE
21417 --Transaction Exchange Rate
21418  , p_source_32            IN NUMBER
21419 --Transaction Exchange Rate Type
21420  , p_source_33            IN VARCHAR2
21421 --Transaction Accounting Amount
21422  , p_source_34            IN NUMBER
21423 --Transaction Tax Line Identifier
21424  , p_source_48            IN NUMBER
21425 --Rounding Correction Flag
21426  , p_source_49            IN VARCHAR2
21427 )
21428 IS
21429 
21430 l_component_type              VARCHAR2(80);
21431 l_component_code              VARCHAR2(30);
21432 l_component_type_code         VARCHAR2(1);
21433 l_component_appl_id           INTEGER;
21434 l_amb_context_code            VARCHAR2(30);
21435 l_entity_code                 VARCHAR2(30);
21436 l_event_class_code            VARCHAR2(30);
21437 l_ae_header_id                NUMBER;
21438 l_event_type_code             VARCHAR2(30);
21439 l_line_definition_code        VARCHAR2(30);
21440 l_line_definition_owner_code  VARCHAR2(1);
21441 --
21442 -- adr variables
21443 l_segment                     VARCHAR2(30);
21444 l_ccid                        NUMBER;
21445 l_adr_transaction_coa_id      NUMBER;
21446 l_adr_accounting_coa_id       NUMBER;
21447 l_adr_flexfield_segment_code  VARCHAR2(30);
21448 l_adr_flex_value_set_id       NUMBER;
21449 l_adr_value_type_code         VARCHAR2(30);
21450 l_adr_value_combination_id    NUMBER;
21451 l_adr_value_segment_code      VARCHAR2(30);
21452 
21453 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
21454 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
21455 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
21456 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
21457 
21458 -- 4262811 Variables ------------------------------------------------------------------------------------------
21459 l_entered_amt_idx             NUMBER;
21460 l_accted_amt_idx              NUMBER;
21461 l_acc_rev_flag                VARCHAR2(1);
21462 l_accrual_line_num            NUMBER;
21463 l_tmp_amt                     NUMBER;
21464 l_acc_rev_natural_side_code   VARCHAR2(1);
21465 
21466 l_num_entries                 NUMBER;
21467 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
21468 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
21469 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
21470 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
21471 l_recog_line_1                NUMBER;
21472 l_recog_line_2                NUMBER;
21473 
21474 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
21475 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
21476 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
21477 
21478 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
21479 
21480 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
21481 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
21482 
21483 ---------------------------------------------------------------------------------------------------------------
21484 
21485 
21486 --
21487 -- bulk performance
21488 --
21489 l_balance_type_code           VARCHAR2(1);
21490 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
21491 l_log_module                  VARCHAR2(240);
21492 
21493 --
21494 -- Upgrade strategy
21495 --
21496 l_actual_upg_option           VARCHAR2(1);
21497 l_enc_upg_option           VARCHAR2(1);
21498 
21499 --
21500 BEGIN
21501 --
21502 IF g_log_enabled THEN
21503       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_51';
21504 END IF;
21505 --
21506 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
21507 
21508       trace
21509          (p_msg      => 'BEGIN of AcctLineType_51'
21510          ,p_level    => C_LEVEL_PROCEDURE
21511          ,p_module   => l_log_module);
21512 
21513 END IF;
21514 --
21515 l_component_type             := 'AMB_JLT';
21516 l_component_code             := 'INV_UNEARN';
21517 l_component_type_code        := 'S';
21518 l_component_appl_id          :=  222;
21519 l_amb_context_code           := 'DEFAULT';
21520 l_entity_code                := 'TRANSACTIONS';
21521 l_event_class_code           := 'INVOICE';
21522 l_event_type_code            := 'INVOICE_ALL';
21523 l_line_definition_owner_code := 'S';
21524 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
21525 --
21526 l_balance_type_code          := 'A';
21527 l_segment                     := NULL;
21528 l_ccid                        := NULL;
21529 l_adr_transaction_coa_id      := NULL;
21530 l_adr_accounting_coa_id       := NULL;
21531 l_adr_flexfield_segment_code  := NULL;
21532 l_adr_flex_value_set_id       := NULL;
21533 l_adr_value_type_code         := NULL;
21534 l_adr_value_combination_id    := NULL;
21535 l_adr_value_segment_code      := NULL;
21536 
21537 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
21538 l_bflow_class_code           := '';    -- 4219869 Business Flow
21539 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
21540 l_budgetary_control_flag     := 'N';
21541 
21542 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
21543 l_bflow_applied_to_amt       := NULL; -- 5132302
21544 l_entered_amt_idx            := NULL;          -- 4262811
21545 l_accted_amt_idx             := NULL;          -- 4262811
21546 l_acc_rev_flag               := NULL;          -- 4262811
21547 l_accrual_line_num           := NULL;          -- 4262811
21548 l_tmp_amt                    := NULL;          -- 4262811
21549 --
21550  
21551 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
21552     l_balance_type_code <> 'B' THEN
21553 IF NVL(p_source_26,'
21554 ') =  'UNEARN' AND 
21555 p_source_49 IS NULL 
21556  THEN 
21557 
21558    --
21559    XLA_AE_LINES_PKG.SetNewLine;
21560 
21561    p_balance_type_code          := l_balance_type_code;
21562    -- set the flag so later we will know whether the gain loss line needs to be created
21563    
21564    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
21565      p_actual_flag :='A';
21566    END IF;
21567 
21568    --
21569    -- bulk performance
21570    --
21571    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
21572                                       p_header_num   => 0); -- 4262811
21573    --
21574    -- set accounting line options
21575    --
21576    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
21577            p_natural_side_code          => 'C'
21578          , p_gain_or_loss_flag          => 'N'
21579          , p_gl_transfer_mode_code      => 'S'
21580          , p_acct_entry_type_code       => 'A'
21581          , p_switch_side_flag           => 'Y'
21582          , p_merge_duplicate_code       => 'A'
21583          );
21584    --
21585    l_acc_rev_natural_side_code := 'D';  -- 4262811
21586    -- 
21587    --
21588    -- set accounting line type info
21589    --
21590    xla_ae_lines_pkg.SetAcctLineType
21591       (p_component_type             => l_component_type
21592       ,p_event_type_code            => l_event_type_code
21593       ,p_line_definition_owner_code => l_line_definition_owner_code
21594       ,p_line_definition_code       => l_line_definition_code
21595       ,p_accounting_line_code       => l_component_code
21596       ,p_accounting_line_type_code  => l_component_type_code
21597       ,p_accounting_line_appl_id    => l_component_appl_id
21598       ,p_amb_context_code           => l_amb_context_code
21599       ,p_entity_code                => l_entity_code
21600       ,p_event_class_code           => l_event_class_code);
21601    --
21602    -- set accounting class
21603    --
21604    xla_ae_lines_pkg.SetAcctClass(
21605            p_accounting_class_code  => 'UNEARNED_REVENUE'
21606          , p_ae_header_id           => l_ae_header_id
21607          );
21608 
21609    --
21610    -- set rounding class
21611    --
21612    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
21613                       'RECEIVABLE';
21614 
21615    --
21616    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
21617    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
21618    --
21619    -- bulk performance
21620    --
21621    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
21622 
21623    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
21624       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
21625 
21626    -- 4955764
21627    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
21628       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
21629 
21630    -- 4458381 Public Sector Enh
21631    
21632    --
21633    -- set accounting attributes for the line type
21634    --
21635    l_entered_amt_idx := 3;
21636    l_accted_amt_idx  := 8;
21637    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
21638    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
21639    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
21640    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
21641    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
21642    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
21643    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
21644    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
21645    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
21646    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
21647    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
21648    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
21649    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
21650    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
21651    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
21652    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
21653    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
21654    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
21655    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
21656    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
21657    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
21658    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
21659    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
21660    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
21661    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
21662 
21663    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
21664    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
21665 
21666    ---------------------------------------------------------------------------------------------------------------
21667    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
21668    ---------------------------------------------------------------------------------------------------------------
21669    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
21670 
21671    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
21672    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
21673 
21674    IF xla_accounting_cache_pkg.GetValueChar
21675          (p_source_code         => 'LEDGER_CATEGORY_CODE'
21676          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
21677    AND l_bflow_method_code = 'PRIOR_ENTRY'
21678 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
21679    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
21680          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
21681        )
21682    THEN
21683          xla_ae_lines_pkg.BflowUpgEntry
21684            (p_business_method_code    => l_bflow_method_code
21685            ,p_business_class_code     => l_bflow_class_code
21686            ,p_balance_type            => l_balance_type_code);
21687    ELSE
21688       NULL;
21689 -- No business flow processing for business flow method of NONE.
21690    END IF;
21691 
21692    --
21693    -- call analytical criteria
21694    --
21695    
21696    --
21697    -- call description
21698    --
21699    -- No description or it is inherited.
21700    --
21701    -- call ADRs
21702    -- Bug 4922099
21703    --
21704    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
21705         (NVL(l_actual_upg_option, 'N') = 'O') OR
21706         (NVL(l_enc_upg_option, 'N') = 'O')
21707       )
21708    THEN
21709    NULL;
21710    --
21711    --
21712    
21713   l_ccid := AcctDerRule_16(
21714            p_application_id           => p_application_id
21715          , p_ae_header_id             => l_ae_header_id 
21716 , p_source_4 => p_source_4
21717          , x_transaction_coa_id       => l_adr_transaction_coa_id
21718          , x_accounting_coa_id        => l_adr_accounting_coa_id
21719          , x_value_type_code          => l_adr_value_type_code
21720          , p_side                     => 'NA'
21721    );
21722 
21723    xla_ae_lines_pkg.set_ccid(
21724     p_code_combination_id          => l_ccid
21725   , p_value_type_code              => l_adr_value_type_code
21726   , p_transaction_coa_id           => l_adr_transaction_coa_id
21727   , p_accounting_coa_id            => l_adr_accounting_coa_id
21728   , p_adr_code                     => 'TRX_DIST_CCID'
21729   , p_adr_type_code                => 'S'
21730   , p_component_type               => l_component_type
21731   , p_component_code               => l_component_code
21732   , p_component_type_code          => l_component_type_code
21733   , p_component_appl_id            => l_component_appl_id
21734   , p_amb_context_code             => l_amb_context_code
21735   , p_side                         => 'NA'
21736   );
21737 
21738 
21739    --
21740    --
21741    END IF;
21742    --
21743    -- Bug 4922099
21744    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
21745           (NVL(l_enc_upg_option, 'N') = 'O')
21746         ) AND
21747         (l_bflow_method_code = 'PRIOR_ENTRY')
21748       )
21749    THEN
21750       IF
21751       --
21752       1 = 2
21753       --
21754       THEN
21755       xla_accounting_err_pkg.build_message
21756                                     (p_appli_s_name            => 'XLA'
21757                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
21758                                     ,p_token_1                 => 'LINE_NUMBER'
21759                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
21760                                     ,p_token_2                 => 'LINE_TYPE_NAME'
21761                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
21762                                                                              l_component_type
21763                                                                             ,l_component_code
21764                                                                             ,l_component_type_code
21765                                                                             ,l_component_appl_id
21766                                                                             ,l_amb_context_code
21767                                                                             ,l_entity_code
21768                                                                             ,l_event_class_code
21769                                                                            )
21770                                     ,p_token_3                 => 'OWNER'
21771                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
21772                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
21773                                                                           ,p_lookup_code    => l_component_type_code
21774                                                                          )
21775                                     ,p_token_4                 => 'PRODUCT_NAME'
21776                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
21777                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
21778                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
21779                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
21780                                     ,p_ae_header_id            =>  NULL
21781                                        );
21782 
21783         IF (C_LEVEL_ERROR>= g_log_level) THEN
21784                  trace
21785                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
21786                       ,p_level    => C_LEVEL_ERROR
21787                       ,p_module   => l_log_module);
21788         END IF;
21789       END IF;
21790    END IF;
21791    --
21792    --
21793    ------------------------------------------------------------------------------------------------
21794    -- 4219869 Business Flow
21795    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
21796    -- Prior Entry.  Currently, the following code is always generated.
21797    ------------------------------------------------------------------------------------------------
21798    XLA_AE_LINES_PKG.ValidateCurrentLine;
21799 
21800    ------------------------------------------------------------------------------------
21801    -- 4219869 Business Flow
21802    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
21803    ------------------------------------------------------------------------------------
21804    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
21805 
21806    ----------------------------------------------------------------------------------
21807    -- 4219869 Business Flow
21808    -- Update journal entry status -- Need to generate this within IF <condition>
21809    ----------------------------------------------------------------------------------
21810    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
21811          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
21812          ,p_balance_type_code => l_balance_type_code
21813          );
21814 
21815    -------------------------------------------------------------------------------------------
21816    -- 4262811 - Generate the Accrual Reversal lines
21817    -------------------------------------------------------------------------------------------
21818    BEGIN
21819       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
21820                               (g_array_event(p_event_id).array_value_num('header_index'));
21821       IF l_acc_rev_flag IS NULL THEN
21822          l_acc_rev_flag := 'N';
21823       END IF;
21824    EXCEPTION
21825       WHEN OTHERS THEN
21826          l_acc_rev_flag := 'N';
21827    END;
21828    --
21829    IF (l_acc_rev_flag = 'Y') THEN
21830 
21831        -- 4645092  ------------------------------------------------------------------------------
21832        -- To allow MPA report to determine if it should generate report process
21833        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
21834        ------------------------------------------------------------------------------------------
21835 
21836        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
21837        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
21838    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
21839    -- call ADRs
21840    -- Bug 4922099
21841    --
21842    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
21843         (NVL(l_actual_upg_option, 'N') = 'O') OR
21844         (NVL(l_enc_upg_option, 'N') = 'O')
21845       )
21846    THEN
21847    NULL;
21848    --
21849    --
21850    
21851   l_ccid := AcctDerRule_16(
21852            p_application_id           => p_application_id
21853          , p_ae_header_id             => l_ae_header_id 
21854 , p_source_4 => p_source_4
21855          , x_transaction_coa_id       => l_adr_transaction_coa_id
21856          , x_accounting_coa_id        => l_adr_accounting_coa_id
21857          , x_value_type_code          => l_adr_value_type_code
21858          , p_side                     => 'NA'
21859    );
21860 
21861    xla_ae_lines_pkg.set_ccid(
21862     p_code_combination_id          => l_ccid
21863   , p_value_type_code              => l_adr_value_type_code
21864   , p_transaction_coa_id           => l_adr_transaction_coa_id
21865   , p_accounting_coa_id            => l_adr_accounting_coa_id
21866   , p_adr_code                     => 'TRX_DIST_CCID'
21867   , p_adr_type_code                => 'S'
21868   , p_component_type               => l_component_type
21869   , p_component_code               => l_component_code
21870   , p_component_type_code          => l_component_type_code
21871   , p_component_appl_id            => l_component_appl_id
21872   , p_amb_context_code             => l_amb_context_code
21873   , p_side                         => 'NA'
21874   );
21875 
21876 
21877    --
21878    --
21879    END IF;
21880 
21881        --
21882        -- Update the line information that should be overwritten
21883        --
21884        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
21885                                          p_header_num   => 1);
21886        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
21887 
21888        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
21889 
21890        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
21891           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
21892        END IF;
21893 
21894       --
21895       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
21896       --
21897       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
21898           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
21899       ELSE
21900           ---------------------------------------------------------------------------------------------------
21901           -- 4262811a Switch Sign
21902           ---------------------------------------------------------------------------------------------------
21903           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
21904           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
21905                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
21906           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
21907                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
21908           -- 5132302
21909           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
21910                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
21911 
21912       END IF;
21913 
21914       -- 4955764
21915       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
21916       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
21917 
21918 
21919       XLA_AE_LINES_PKG.ValidateCurrentLine;
21920       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
21921 
21922       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
21923                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
21924                ,p_balance_type_code => l_balance_type_code);
21925 
21926    END IF;
21927 
21928    -----------------------------------------------------------------------------------------
21932 
21929    -- 4262811 Multiperiod Accounting
21930    -----------------------------------------------------------------------------------------
21931      -- No MPA option is assigned.
21933 
21934 END IF;
21935 END IF;
21936 --
21937 
21938 --
21939 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
21940    trace
21941       (p_msg      => 'END of AcctLineType_51'
21942       ,p_level    => C_LEVEL_PROCEDURE
21943       ,p_module   => l_log_module);
21944 END IF;
21945 --
21946 EXCEPTION
21947   WHEN xla_exceptions_pkg.application_exception THEN
21948       RAISE;
21949   WHEN OTHERS THEN
21950        xla_exceptions_pkg.raise_message
21951            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_51');
21952 END AcctLineType_51;
21953 --
21954 
21955 ---------------------------------------
21956 --
21957 -- PRIVATE FUNCTION
21958 --         AcctLineType_52
21959 --
21960 ---------------------------------------
21961 PROCEDURE AcctLineType_52 (
21962   p_application_id        IN NUMBER
21963  ,p_event_id              IN NUMBER
21964  ,p_calculate_acctd_flag  IN VARCHAR2
21965  ,p_calculate_g_l_flag    IN VARCHAR2
21966  ,p_actual_flag           IN OUT VARCHAR2
21967  ,p_balance_type_code     OUT VARCHAR2
21968  ,p_gain_or_loss_ref      OUT VARCHAR2
21969  
21970 --Distribution GL Account
21971  , p_source_3            IN NUMBER
21972 --Transaction Default Receivable Account
21973  , p_source_9            IN NUMBER
21974 --Distribution Source Type
21975  , p_source_13            IN VARCHAR2
21976 --Receivable Activity Type
21977  , p_source_14            IN VARCHAR2
21978 --Distribution Line Identifier
21979  , p_source_15            IN NUMBER
21980 --Distribution Type
21981  , p_source_16            IN VARCHAR2
21982 --Entered Amount
21983  , p_source_17            IN NUMBER
21984 --Currency Code
21985  , p_source_18            IN VARCHAR2
21986 --Exchange Date
21987  , p_source_19            IN DATE
21988 --Exchange Rate
21989  , p_source_20            IN NUMBER
21990 --Exchange Rate Type
21991  , p_source_21            IN VARCHAR2
21992 --Applied To Document Accounting Amount
21993  , p_source_22            IN NUMBER
21994 --Bill To Customer Account Identifier
21995  , p_source_23            IN NUMBER
21996 --Bill To Customer Site Use Identifier
21997  , p_source_24            IN NUMBER
21998 --SLA Party Type
21999  , p_source_25            IN VARCHAR2
22000 )
22001 IS
22002 
22003 l_component_type              VARCHAR2(80);
22004 l_component_code              VARCHAR2(30);
22005 l_component_type_code         VARCHAR2(1);
22006 l_component_appl_id           INTEGER;
22007 l_amb_context_code            VARCHAR2(30);
22008 l_entity_code                 VARCHAR2(30);
22009 l_event_class_code            VARCHAR2(30);
22010 l_ae_header_id                NUMBER;
22011 l_event_type_code             VARCHAR2(30);
22012 l_line_definition_code        VARCHAR2(30);
22013 l_line_definition_owner_code  VARCHAR2(1);
22014 --
22015 -- adr variables
22016 l_segment                     VARCHAR2(30);
22017 l_ccid                        NUMBER;
22018 l_adr_transaction_coa_id      NUMBER;
22019 l_adr_accounting_coa_id       NUMBER;
22020 l_adr_flexfield_segment_code  VARCHAR2(30);
22021 l_adr_flex_value_set_id       NUMBER;
22022 l_adr_value_type_code         VARCHAR2(30);
22023 l_adr_value_combination_id    NUMBER;
22024 l_adr_value_segment_code      VARCHAR2(30);
22025 
22026 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
22027 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
22028 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
22029 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
22030 
22031 -- 4262811 Variables ------------------------------------------------------------------------------------------
22032 l_entered_amt_idx             NUMBER;
22033 l_accted_amt_idx              NUMBER;
22034 l_acc_rev_flag                VARCHAR2(1);
22035 l_accrual_line_num            NUMBER;
22036 l_tmp_amt                     NUMBER;
22037 l_acc_rev_natural_side_code   VARCHAR2(1);
22038 
22039 l_num_entries                 NUMBER;
22040 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
22041 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
22042 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
22043 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
22044 l_recog_line_1                NUMBER;
22045 l_recog_line_2                NUMBER;
22046 
22047 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
22048 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
22049 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
22050 
22051 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
22052 
22053 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
22054 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
22055 
22056 ---------------------------------------------------------------------------------------------------------------
22057 
22058 
22059 --
22060 -- bulk performance
22061 --
22062 l_balance_type_code           VARCHAR2(1);
22063 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
22064 l_log_module                  VARCHAR2(240);
22065 
22066 --
22067 -- Upgrade strategy
22068 --
22069 l_actual_upg_option           VARCHAR2(1);
22070 l_enc_upg_option           VARCHAR2(1);
22071 
22072 --
22073 BEGIN
22074 --
22075 IF g_log_enabled THEN
22076       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_52';
22077 END IF;
22078 --
22079 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
22080 
22081       trace
22082          (p_msg      => 'BEGIN of AcctLineType_52'
22083          ,p_level    => C_LEVEL_PROCEDURE
22084          ,p_module   => l_log_module);
22085 
22086 END IF;
22087 --
22088 l_component_type             := 'AMB_JLT';
22089 l_component_code             := 'MFAR_ADJ_REC';
22090 l_component_type_code        := 'S';
22091 l_component_appl_id          :=  222;
22092 l_amb_context_code           := 'DEFAULT';
22093 l_entity_code                := 'ADJUSTMENTS';
22094 l_event_class_code           := 'ADJUSTMENT';
22095 l_event_type_code            := 'ADJUSTMENT_ALL';
22096 l_line_definition_owner_code := 'S';
22097 l_line_definition_code       := 'MFAR_ADJ_ACCRUAL_BALANCING';
22098 --
22099 l_balance_type_code          := 'A';
22100 l_segment                     := NULL;
22101 l_ccid                        := NULL;
22102 l_adr_transaction_coa_id      := NULL;
22103 l_adr_accounting_coa_id       := NULL;
22104 l_adr_flexfield_segment_code  := NULL;
22105 l_adr_flex_value_set_id       := NULL;
22106 l_adr_value_type_code         := NULL;
22107 l_adr_value_combination_id    := NULL;
22108 l_adr_value_segment_code      := NULL;
22109 
22110 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
22111 l_bflow_class_code           := 'RECEIVABLE';    -- 4219869 Business Flow
22112 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
22113 l_budgetary_control_flag     := 'N';
22114 
22115 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
22116 l_bflow_applied_to_amt       := NULL; -- 5132302
22117 l_entered_amt_idx            := NULL;          -- 4262811
22118 l_accted_amt_idx             := NULL;          -- 4262811
22119 l_acc_rev_flag               := NULL;          -- 4262811
22120 l_accrual_line_num           := NULL;          -- 4262811
22121 l_tmp_amt                    := NULL;          -- 4262811
22122 --
22123  
22124 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
22125     l_balance_type_code <> 'B' THEN
22126 IF NVL(p_source_13,'
22127 ') =  'TAX' OR 
22128 NVL(p_source_13,'
22129 ') =  'DEFERRED_TAX' OR 
22130 NVL(p_source_13,'
22131 ') =  'FINCHRG' OR 
22132 (NVL(p_source_13,'
22133 ') =  'ADJ' AND 
22134 NVL(p_source_14,'
22135 ') =  'ENDORSEMENT') OR 
22136 (NVL(p_source_13,'
22137 ') =  'ADJ' AND 
22138 NVL(p_source_14,'
22139 ') <>  'ENDORSEMENT')
22140  THEN 
22141 
22142    --
22143    XLA_AE_LINES_PKG.SetNewLine;
22144 
22145    p_balance_type_code          := l_balance_type_code;
22146    -- set the flag so later we will know whether the gain loss line needs to be created
22147    
22148    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
22149      p_actual_flag :='A';
22150    END IF;
22151 
22152    --
22153    -- bulk performance
22154    --
22155    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
22156                                       p_header_num   => 0); -- 4262811
22157    --
22158    -- set accounting line options
22159    --
22160    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
22161            p_natural_side_code          => 'D'
22162          , p_gain_or_loss_flag          => 'N'
22163          , p_gl_transfer_mode_code      => 'S'
22164          , p_acct_entry_type_code       => 'A'
22165          , p_switch_side_flag           => 'Y'
22166          , p_merge_duplicate_code       => 'A'
22167          );
22168    --
22169    l_acc_rev_natural_side_code := 'C';  -- 4262811
22170    -- 
22171    --
22172    -- set accounting line type info
22173    --
22174    xla_ae_lines_pkg.SetAcctLineType
22175       (p_component_type             => l_component_type
22176       ,p_event_type_code            => l_event_type_code
22177       ,p_line_definition_owner_code => l_line_definition_owner_code
22178       ,p_line_definition_code       => l_line_definition_code
22179       ,p_accounting_line_code       => l_component_code
22180       ,p_accounting_line_type_code  => l_component_type_code
22181       ,p_accounting_line_appl_id    => l_component_appl_id
22182       ,p_amb_context_code           => l_amb_context_code
22183       ,p_entity_code                => l_entity_code
22184       ,p_event_class_code           => l_event_class_code);
22185    --
22186    -- set accounting class
22187    --
22188    xla_ae_lines_pkg.SetAcctClass(
22189            p_accounting_class_code  => 'RECEIVABLE'
22190          , p_ae_header_id           => l_ae_header_id
22191          );
22192 
22193    --
22194    -- set rounding class
22195    --
22196    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
22197                       'RECEIVABLE';
22198 
22199    --
22200    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
22201    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
22202    --
22203    -- bulk performance
22204    --
22205    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
22206 
22207    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
22208       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
22209 
22210    -- 4955764
22211    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
22212       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
22213 
22214    -- 4458381 Public Sector Enh
22215    
22216    --
22217    -- set accounting attributes for the line type
22218    --
22219    l_entered_amt_idx := 3;
22220    l_accted_amt_idx  := 8;
22221    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
22222    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
22223    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
22224    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
22225    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
22226    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
22227    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
22228    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
22229    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
22230    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
22231    l_rec_acct_attrs.array_date_value(5)  := p_source_19;
22232    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
22233    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
22234    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
22235    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
22236    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
22237    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
22238    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
22239    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
22240    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
22241    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
22242    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
22243    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
22244 
22245    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
22246    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
22247 
22248    ---------------------------------------------------------------------------------------------------------------
22249    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
22250    ---------------------------------------------------------------------------------------------------------------
22251    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
22252 
22253    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
22257          (p_source_code         => 'LEDGER_CATEGORY_CODE'
22254    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
22255 
22256    IF xla_accounting_cache_pkg.GetValueChar
22258          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
22259    AND l_bflow_method_code = 'PRIOR_ENTRY'
22260 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
22261    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
22262          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
22263        )
22264    THEN
22265          xla_ae_lines_pkg.BflowUpgEntry
22266            (p_business_method_code    => l_bflow_method_code
22267            ,p_business_class_code     => l_bflow_class_code
22268            ,p_balance_type            => l_balance_type_code);
22269    ELSE
22270       NULL;
22271 -- No business flow processing for business flow method of NONE.
22272    END IF;
22273 
22274    --
22275    -- call analytical criteria
22276    --
22277    
22278    --
22279    -- call description
22280    --
22281    
22282 xla_ae_lines_pkg.SetLineDescription(
22283    p_ae_header_id => l_ae_header_id
22284   ,p_description  => Description_1 (
22285      p_application_id         => p_application_id
22286    , p_ae_header_id           => l_ae_header_id 
22287    )
22288 );
22289 
22290 
22291    --
22292    -- call ADRs
22293    -- Bug 4922099
22294    --
22295    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
22296         (NVL(l_actual_upg_option, 'N') = 'O') OR
22297         (NVL(l_enc_upg_option, 'N') = 'O')
22298       )
22299    THEN
22300    NULL;
22301    --
22302    --
22303    
22304   l_ccid := AcctDerRule_12(
22305            p_application_id           => p_application_id
22306          , p_ae_header_id             => l_ae_header_id 
22307 , p_source_9 => p_source_9
22308          , x_transaction_coa_id       => l_adr_transaction_coa_id
22309          , x_accounting_coa_id        => l_adr_accounting_coa_id
22310          , x_value_type_code          => l_adr_value_type_code
22311          , p_side                     => 'NA'
22312    );
22313 
22314    xla_ae_lines_pkg.set_ccid(
22315     p_code_combination_id          => l_ccid
22316   , p_value_type_code              => l_adr_value_type_code
22317   , p_transaction_coa_id           => l_adr_transaction_coa_id
22318   , p_accounting_coa_id            => l_adr_accounting_coa_id
22319   , p_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
22320   , p_adr_type_code                => 'S'
22321   , p_component_type               => l_component_type
22322   , p_component_code               => l_component_code
22323   , p_component_type_code          => l_component_type_code
22324   , p_component_appl_id            => l_component_appl_id
22325   , p_amb_context_code             => l_amb_context_code
22326   , p_side                         => 'NA'
22327   );
22328 
22329 
22330    l_segment := AcctDerRule_4(
22331            p_application_id           => p_application_id
22332          , p_ae_header_id             => l_ae_header_id 
22333 , p_source_3 => p_source_3
22334          , x_transaction_coa_id       => l_adr_transaction_coa_id
22335          , x_accounting_coa_id        => l_adr_accounting_coa_id
22336          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
22337          , x_flex_value_set_id        => l_adr_flex_value_set_id
22338          , x_value_type_code          => l_adr_value_type_code
22339          , x_value_combination_id     => l_adr_value_combination_id
22340          , x_value_segment_code       => l_adr_value_segment_code
22341          , p_side                     => 'NA'
22342          , p_override_seg_flag        => 'Y'
22343    );
22344 
22345    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
22346 
22347       xla_ae_lines_pkg.set_segment(
22348           p_to_segment_code         => 'GL_BALANCING'
22349         , p_segment_value           => l_segment
22350         , p_from_segment_code       => l_adr_value_segment_code
22351         , p_from_combination_id     => l_adr_value_combination_id
22352         , p_value_type_code         => l_adr_value_type_code
22353         , p_transaction_coa_id      => l_adr_transaction_coa_id
22354         , p_accounting_coa_id       => l_adr_accounting_coa_id
22355         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
22356         , p_flex_value_set_id       => l_adr_flex_value_set_id
22357         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
22358         , p_adr_type_code           => 'S'
22359         , p_component_type          => l_component_type
22360         , p_component_code          => l_component_code
22361         , p_component_type_code     => l_component_type_code
22362         , p_component_appl_id       => l_component_appl_id
22363         , p_amb_context_code        => l_amb_context_code
22364         , p_entity_code             => 'ADJUSTMENTS'
22365         , p_event_class_code        => 'ADJUSTMENT'
22366         , p_side                    => 'NA'
22367         );
22368 
22369   END IF;
22370 
22371    --
22372    --
22373    END IF;
22374    --
22375    -- Bug 4922099
22376    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
22377           (NVL(l_enc_upg_option, 'N') = 'O')
22378         ) AND
22379         (l_bflow_method_code = 'PRIOR_ENTRY')
22380       )
22381    THEN
22382       IF
22383       --
22384       1 = 2
22385       --
22386       THEN
22387       xla_accounting_err_pkg.build_message
22388                                     (p_appli_s_name            => 'XLA'
22392                                     ,p_token_2                 => 'LINE_TYPE_NAME'
22389                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
22390                                     ,p_token_1                 => 'LINE_NUMBER'
22391                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
22393                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
22394                                                                              l_component_type
22395                                                                             ,l_component_code
22396                                                                             ,l_component_type_code
22397                                                                             ,l_component_appl_id
22398                                                                             ,l_amb_context_code
22399                                                                             ,l_entity_code
22400                                                                             ,l_event_class_code
22401                                                                            )
22402                                     ,p_token_3                 => 'OWNER'
22403                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
22404                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
22405                                                                           ,p_lookup_code    => l_component_type_code
22406                                                                          )
22407                                     ,p_token_4                 => 'PRODUCT_NAME'
22408                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
22409                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
22410                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
22411                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
22412                                     ,p_ae_header_id            =>  NULL
22413                                        );
22414 
22415         IF (C_LEVEL_ERROR>= g_log_level) THEN
22416                  trace
22417                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
22418                       ,p_level    => C_LEVEL_ERROR
22419                       ,p_module   => l_log_module);
22420         END IF;
22421       END IF;
22422    END IF;
22423    --
22424    --
22425    ------------------------------------------------------------------------------------------------
22426    -- 4219869 Business Flow
22427    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
22428    -- Prior Entry.  Currently, the following code is always generated.
22429    ------------------------------------------------------------------------------------------------
22430    XLA_AE_LINES_PKG.ValidateCurrentLine;
22431 
22432    ------------------------------------------------------------------------------------
22433    -- 4219869 Business Flow
22434    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
22435    ------------------------------------------------------------------------------------
22436    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
22437 
22438    ----------------------------------------------------------------------------------
22439    -- 4219869 Business Flow
22440    -- Update journal entry status -- Need to generate this within IF <condition>
22441    ----------------------------------------------------------------------------------
22442    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
22443          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
22444          ,p_balance_type_code => l_balance_type_code
22445          );
22446 
22447    -------------------------------------------------------------------------------------------
22448    -- 4262811 - Generate the Accrual Reversal lines
22449    -------------------------------------------------------------------------------------------
22450    BEGIN
22451       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
22452                               (g_array_event(p_event_id).array_value_num('header_index'));
22453       IF l_acc_rev_flag IS NULL THEN
22454          l_acc_rev_flag := 'N';
22455       END IF;
22456    EXCEPTION
22457       WHEN OTHERS THEN
22458          l_acc_rev_flag := 'N';
22459    END;
22460    --
22461    IF (l_acc_rev_flag = 'Y') THEN
22462 
22463        -- 4645092  ------------------------------------------------------------------------------
22464        -- To allow MPA report to determine if it should generate report process
22465        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
22466        ------------------------------------------------------------------------------------------
22467 
22468        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
22469        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
22470    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
22471    -- call ADRs
22472    -- Bug 4922099
22473    --
22474    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
22475         (NVL(l_actual_upg_option, 'N') = 'O') OR
22476         (NVL(l_enc_upg_option, 'N') = 'O')
22477       )
22478    THEN
22479    NULL;
22480    --
22481    --
22482    
22483   l_ccid := AcctDerRule_12(
22484            p_application_id           => p_application_id
22485          , p_ae_header_id             => l_ae_header_id 
22486 , p_source_9 => p_source_9
22487          , x_transaction_coa_id       => l_adr_transaction_coa_id
22488          , x_accounting_coa_id        => l_adr_accounting_coa_id
22489          , x_value_type_code          => l_adr_value_type_code
22490          , p_side                     => 'NA'
22491    );
22492 
22493    xla_ae_lines_pkg.set_ccid(
22494     p_code_combination_id          => l_ccid
22495   , p_value_type_code              => l_adr_value_type_code
22496   , p_transaction_coa_id           => l_adr_transaction_coa_id
22497   , p_accounting_coa_id            => l_adr_accounting_coa_id
22498   , p_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
22499   , p_adr_type_code                => 'S'
22500   , p_component_type               => l_component_type
22501   , p_component_code               => l_component_code
22502   , p_component_type_code          => l_component_type_code
22503   , p_component_appl_id            => l_component_appl_id
22504   , p_amb_context_code             => l_amb_context_code
22505   , p_side                         => 'NA'
22506   );
22507 
22508 
22509    l_segment := AcctDerRule_4(
22510            p_application_id           => p_application_id
22511          , p_ae_header_id             => l_ae_header_id 
22512 , p_source_3 => p_source_3
22513          , x_transaction_coa_id       => l_adr_transaction_coa_id
22514          , x_accounting_coa_id        => l_adr_accounting_coa_id
22515          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
22516          , x_flex_value_set_id        => l_adr_flex_value_set_id
22517          , x_value_type_code          => l_adr_value_type_code
22518          , x_value_combination_id     => l_adr_value_combination_id
22519          , x_value_segment_code       => l_adr_value_segment_code
22520          , p_side                     => 'NA'
22521          , p_override_seg_flag        => 'Y'
22522    );
22523 
22524    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
22525 
22526       xla_ae_lines_pkg.set_segment(
22527           p_to_segment_code         => 'GL_BALANCING'
22528         , p_segment_value           => l_segment
22529         , p_from_segment_code       => l_adr_value_segment_code
22530         , p_from_combination_id     => l_adr_value_combination_id
22531         , p_value_type_code         => l_adr_value_type_code
22532         , p_transaction_coa_id      => l_adr_transaction_coa_id
22533         , p_accounting_coa_id       => l_adr_accounting_coa_id
22534         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
22535         , p_flex_value_set_id       => l_adr_flex_value_set_id
22536         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
22537         , p_adr_type_code           => 'S'
22538         , p_component_type          => l_component_type
22539         , p_component_code          => l_component_code
22540         , p_component_type_code     => l_component_type_code
22541         , p_component_appl_id       => l_component_appl_id
22542         , p_amb_context_code        => l_amb_context_code
22543         , p_entity_code             => 'ADJUSTMENTS'
22544         , p_event_class_code        => 'ADJUSTMENT'
22545         , p_side                    => 'NA'
22546         );
22547 
22548   END IF;
22549 
22550    --
22551    --
22552    END IF;
22553 
22554        --
22555        -- Update the line information that should be overwritten
22556        --
22557        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
22558                                          p_header_num   => 1);
22559        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
22560 
22561        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
22562 
22563        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
22564           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
22565        END IF;
22566 
22567       --
22568       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
22569       --
22570       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
22571           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
22572       ELSE
22573           ---------------------------------------------------------------------------------------------------
22574           -- 4262811a Switch Sign
22575           ---------------------------------------------------------------------------------------------------
22576           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
22577           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
22581           -- 5132302
22578                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
22579           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
22580                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
22582           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
22583                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
22584 
22585       END IF;
22586 
22587       -- 4955764
22588       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
22589       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
22590 
22591 
22592       XLA_AE_LINES_PKG.ValidateCurrentLine;
22593       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
22594 
22595       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
22596                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
22597                ,p_balance_type_code => l_balance_type_code);
22598 
22599    END IF;
22600 
22601    -----------------------------------------------------------------------------------------
22602    -- 4262811 Multiperiod Accounting
22603    -----------------------------------------------------------------------------------------
22604      -- No MPA option is assigned.
22605 
22606 
22607 END IF;
22608 END IF;
22609 --
22610 
22611 --
22612 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
22613    trace
22614       (p_msg      => 'END of AcctLineType_52'
22615       ,p_level    => C_LEVEL_PROCEDURE
22616       ,p_module   => l_log_module);
22617 END IF;
22618 --
22619 EXCEPTION
22620   WHEN xla_exceptions_pkg.application_exception THEN
22621       RAISE;
22622   WHEN OTHERS THEN
22623        xla_exceptions_pkg.raise_message
22624            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_52');
22625 END AcctLineType_52;
22626 --
22627 
22628 ---------------------------------------
22629 --
22630 -- PRIVATE FUNCTION
22631 --         AcctLineType_53
22632 --
22633 ---------------------------------------
22634 PROCEDURE AcctLineType_53 (
22635   p_application_id        IN NUMBER
22636  ,p_event_id              IN NUMBER
22637  ,p_calculate_acctd_flag  IN VARCHAR2
22638  ,p_calculate_g_l_flag    IN VARCHAR2
22639  ,p_actual_flag           IN OUT VARCHAR2
22640  ,p_balance_type_code     OUT VARCHAR2
22641  ,p_gain_or_loss_ref      OUT VARCHAR2
22642  
22643 --Credit Memo Distribution GL Account
22644  , p_source_2            IN NUMBER
22645 --Credit Memo Default Receivable Account
22646  , p_source_5            IN NUMBER
22647 --SLA Party Type
22648  , p_source_25            IN VARCHAR2
22649 --Credit Memo Distribution Identifier
22650  , p_source_35            IN NUMBER
22651 --Credit memo distributions type
22652  , p_source_36            IN VARCHAR2
22653 --Credit Memo Currency Code
22654  , p_source_37            IN VARCHAR2
22655 --Credit Memo Exchange Date
22656  , p_source_38            IN DATE
22657 --Credit Memo Exchange Rate
22658  , p_source_39            IN NUMBER
22659 --Credit Memo Exchange Rate Type
22660  , p_source_40            IN VARCHAR2
22661 --Gain Loss Reference
22662  , p_source_41            IN VARCHAR2
22663 --Credit Memo Accounting Amount
22664  , p_source_42            IN NUMBER
22665 --Credit Memo Bill To Customer Account Identifier
22666  , p_source_43            IN NUMBER
22667 --Credit Memo Bill To Customer Site Use Identifier
22668  , p_source_44            IN NUMBER
22669 --Credit Memo Tax Line Identifier
22670  , p_source_45            IN NUMBER
22671 --Credit Memo Distribution Account Class
22672  , p_source_46            IN VARCHAR2
22673 --Credit Memo Distribution Entered Amount
22674  , p_source_47            IN NUMBER
22675 --Credit Memo Invoicing Rule
22676  , p_source_50            IN NUMBER
22677 )
22678 IS
22679 
22680 l_component_type              VARCHAR2(80);
22681 l_component_code              VARCHAR2(30);
22682 l_component_type_code         VARCHAR2(1);
22683 l_component_appl_id           INTEGER;
22684 l_amb_context_code            VARCHAR2(30);
22685 l_entity_code                 VARCHAR2(30);
22686 l_event_class_code            VARCHAR2(30);
22687 l_ae_header_id                NUMBER;
22688 l_event_type_code             VARCHAR2(30);
22689 l_line_definition_code        VARCHAR2(30);
22690 l_line_definition_owner_code  VARCHAR2(1);
22691 --
22692 -- adr variables
22693 l_segment                     VARCHAR2(30);
22694 l_ccid                        NUMBER;
22695 l_adr_transaction_coa_id      NUMBER;
22696 l_adr_accounting_coa_id       NUMBER;
22697 l_adr_flexfield_segment_code  VARCHAR2(30);
22698 l_adr_flex_value_set_id       NUMBER;
22699 l_adr_value_type_code         VARCHAR2(30);
22700 l_adr_value_combination_id    NUMBER;
22701 l_adr_value_segment_code      VARCHAR2(30);
22702 
22703 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
22704 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
22705 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
22706 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
22707 
22708 -- 4262811 Variables ------------------------------------------------------------------------------------------
22709 l_entered_amt_idx             NUMBER;
22710 l_accted_amt_idx              NUMBER;
22711 l_acc_rev_flag                VARCHAR2(1);
22712 l_accrual_line_num            NUMBER;
22713 l_tmp_amt                     NUMBER;
22714 l_acc_rev_natural_side_code   VARCHAR2(1);
22715 
22716 l_num_entries                 NUMBER;
22717 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
22718 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
22719 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
22720 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
22721 l_recog_line_1                NUMBER;
22722 l_recog_line_2                NUMBER;
22723 
22724 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
22725 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
22726 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
22727 
22728 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
22729 
22730 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
22731 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
22732 
22733 ---------------------------------------------------------------------------------------------------------------
22734 
22735 
22736 --
22737 -- bulk performance
22738 --
22739 l_balance_type_code           VARCHAR2(1);
22740 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
22741 l_log_module                  VARCHAR2(240);
22742 
22743 --
22744 -- Upgrade strategy
22745 --
22746 l_actual_upg_option           VARCHAR2(1);
22747 l_enc_upg_option           VARCHAR2(1);
22748 
22749 --
22750 BEGIN
22751 --
22752 IF g_log_enabled THEN
22753       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_53';
22754 END IF;
22755 --
22756 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
22757 
22758       trace
22759          (p_msg      => 'BEGIN of AcctLineType_53'
22760          ,p_level    => C_LEVEL_PROCEDURE
22761          ,p_module   => l_log_module);
22762 
22763 END IF;
22764 --
22765 l_component_type             := 'AMB_JLT';
22766 l_component_code             := 'MFAR_CM_REC';
22767 l_component_type_code        := 'S';
22768 l_component_appl_id          :=  222;
22769 l_amb_context_code           := 'DEFAULT';
22770 l_entity_code                := 'TRANSACTIONS';
22771 l_event_class_code           := 'CREDIT_MEMO';
22772 l_event_type_code            := 'CREDIT_MEMO_ALL';
22773 l_line_definition_owner_code := 'S';
22774 l_line_definition_code       := 'MFAR_CM_ACCRUAL_BALANCING';
22775 --
22776 l_balance_type_code          := 'A';
22777 l_segment                     := NULL;
22778 l_ccid                        := NULL;
22779 l_adr_transaction_coa_id      := NULL;
22780 l_adr_accounting_coa_id       := NULL;
22781 l_adr_flexfield_segment_code  := NULL;
22782 l_adr_flex_value_set_id       := NULL;
22783 l_adr_value_type_code         := NULL;
22784 l_adr_value_combination_id    := NULL;
22785 l_adr_value_segment_code      := NULL;
22786 
22787 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
22788 l_bflow_class_code           := 'RECEIVABLE';    -- 4219869 Business Flow
22789 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
22790 l_budgetary_control_flag     := 'N';
22791 
22792 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
22793 l_bflow_applied_to_amt       := NULL; -- 5132302
22794 l_entered_amt_idx            := NULL;          -- 4262811
22795 l_accted_amt_idx             := NULL;          -- 4262811
22796 l_acc_rev_flag               := NULL;          -- 4262811
22797 l_accrual_line_num           := NULL;          -- 4262811
22798 l_tmp_amt                    := NULL;          -- 4262811
22799 --
22800  
22804 (NVL(p_source_46,'
22801 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
22802     l_balance_type_code <> 'B' THEN
22803 IF (p_source_50 IS NULL ) AND 
22805 ') =  'REV' OR 
22806 NVL(p_source_46,'
22807 ') =  'TAX' OR 
22808 NVL(p_source_46,'
22809 ') =  'FREIGHT' OR 
22810 NVL(p_source_46,'
22811 ') =  'ROUND' OR 
22812 NVL(p_source_46,'
22813 ') =  'CHARGES')
22814  THEN 
22815 
22816    --
22817    XLA_AE_LINES_PKG.SetNewLine;
22818 
22819    p_balance_type_code          := l_balance_type_code;
22820    -- set the flag so later we will know whether the gain loss line needs to be created
22821    
22822    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
22823      p_actual_flag :='A';
22824    END IF;
22825 
22826    --
22827    -- bulk performance
22828    --
22829    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
22830                                       p_header_num   => 0); -- 4262811
22831    --
22832    -- set accounting line options
22833    --
22834    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
22835            p_natural_side_code          => 'D'
22836          , p_gain_or_loss_flag          => 'N'
22837          , p_gl_transfer_mode_code      => 'S'
22838          , p_acct_entry_type_code       => 'A'
22839          , p_switch_side_flag           => 'Y'
22840          , p_merge_duplicate_code       => 'A'
22841          );
22842    --
22843    l_acc_rev_natural_side_code := 'C';  -- 4262811
22844    -- 
22845    --
22846    -- set accounting line type info
22847    --
22848    xla_ae_lines_pkg.SetAcctLineType
22849       (p_component_type             => l_component_type
22850       ,p_event_type_code            => l_event_type_code
22851       ,p_line_definition_owner_code => l_line_definition_owner_code
22852       ,p_line_definition_code       => l_line_definition_code
22853       ,p_accounting_line_code       => l_component_code
22854       ,p_accounting_line_type_code  => l_component_type_code
22855       ,p_accounting_line_appl_id    => l_component_appl_id
22856       ,p_amb_context_code           => l_amb_context_code
22857       ,p_entity_code                => l_entity_code
22858       ,p_event_class_code           => l_event_class_code);
22859    --
22860    -- set accounting class
22861    --
22862    xla_ae_lines_pkg.SetAcctClass(
22863            p_accounting_class_code  => 'RECEIVABLE'
22864          , p_ae_header_id           => l_ae_header_id
22865          );
22866 
22867    --
22868    -- set rounding class
22869    --
22870    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
22871                       'RECEIVABLE';
22872 
22873    --
22874    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
22875    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
22876    --
22877    -- bulk performance
22878    --
22879    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
22880 
22881    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
22882       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
22883 
22884    -- 4955764
22885    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
22886       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
22887 
22888    -- 4458381 Public Sector Enh
22889    
22890    --
22891    -- set accounting attributes for the line type
22892    --
22893    l_entered_amt_idx := 3;
22894    l_accted_amt_idx  := 9;
22895    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
22896    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
22897    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_35);
22898    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
22899    l_rec_acct_attrs.array_char_value(2)  := p_source_36;
22900    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
22901    l_rec_acct_attrs.array_num_value(3)  := p_source_47;
22902    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
22903    l_rec_acct_attrs.array_char_value(4)  := p_source_37;
22904    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
22905    l_rec_acct_attrs.array_date_value(5)  := p_source_38;
22906    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
22907    l_rec_acct_attrs.array_num_value(6)  := p_source_39;
22908    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
22909    l_rec_acct_attrs.array_char_value(7)  := p_source_40;
22910    l_rec_acct_attrs.array_acct_attr_code(8) := 'GAIN_LOSS_REFERENCE';
22911    l_rec_acct_attrs.array_char_value(8)  := p_source_41;
22912    l_rec_acct_attrs.array_acct_attr_code(9) := 'LEDGER_AMOUNT';
22913    l_rec_acct_attrs.array_num_value(9)  := p_source_42;
22914    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_ID';
22915    l_rec_acct_attrs.array_num_value(10)  := p_source_43;
22916    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_SITE_ID';
22917    l_rec_acct_attrs.array_num_value(11)  := p_source_44;
22918    l_rec_acct_attrs.array_acct_attr_code(12) := 'PARTY_TYPE';
22919    l_rec_acct_attrs.array_char_value(12)  := p_source_25;
22920    l_rec_acct_attrs.array_acct_attr_code(13) := 'TAX_LINE_REF_ID';
22921    l_rec_acct_attrs.array_num_value(13)  := p_source_45;
22922 
22923    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
22924    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
22925 
22926    ---------------------------------------------------------------------------------------------------------------
22927    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
22928    ---------------------------------------------------------------------------------------------------------------
22929    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
22930 
22931    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
22932    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
22933 
22934    IF xla_accounting_cache_pkg.GetValueChar
22935          (p_source_code         => 'LEDGER_CATEGORY_CODE'
22936          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
22937    AND l_bflow_method_code = 'PRIOR_ENTRY'
22938 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
22939    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
22940          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
22941        )
22942    THEN
22943          xla_ae_lines_pkg.BflowUpgEntry
22944            (p_business_method_code    => l_bflow_method_code
22945            ,p_business_class_code     => l_bflow_class_code
22946            ,p_balance_type            => l_balance_type_code);
22947    ELSE
22948       NULL;
22949 -- No business flow processing for business flow method of NONE.
22950    END IF;
22951 
22952    --
22953    -- call analytical criteria
22954    --
22955    
22956    --
22957    -- call description
22958    --
22959    
22960 xla_ae_lines_pkg.SetLineDescription(
22961    p_ae_header_id => l_ae_header_id
22962   ,p_description  => Description_1 (
22963      p_application_id         => p_application_id
22964    , p_ae_header_id           => l_ae_header_id 
22965    )
22966 );
22967 
22968 
22969    --
22970    -- call ADRs
22971    -- Bug 4922099
22972    --
22973    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
22974         (NVL(l_actual_upg_option, 'N') = 'O') OR
22975         (NVL(l_enc_upg_option, 'N') = 'O')
22976       )
22977    THEN
22978    NULL;
22979    --
22980    --
22981    
22982   l_ccid := AcctDerRule_8(
22983            p_application_id           => p_application_id
22984          , p_ae_header_id             => l_ae_header_id 
22985 , p_source_5 => p_source_5
22986          , x_transaction_coa_id       => l_adr_transaction_coa_id
22987          , x_accounting_coa_id        => l_adr_accounting_coa_id
22988          , x_value_type_code          => l_adr_value_type_code
22989          , p_side                     => 'NA'
22990    );
22991 
22992    xla_ae_lines_pkg.set_ccid(
22993     p_code_combination_id          => l_ccid
22994   , p_value_type_code              => l_adr_value_type_code
22995   , p_transaction_coa_id           => l_adr_transaction_coa_id
22996   , p_accounting_coa_id            => l_adr_accounting_coa_id
22997   , p_adr_code                     => 'MFAR_CM_DEF_REC_CCID'
22998   , p_adr_type_code                => 'S'
22999   , p_component_type               => l_component_type
23000   , p_component_code               => l_component_code
23001   , p_component_type_code          => l_component_type_code
23002   , p_component_appl_id            => l_component_appl_id
23003   , p_amb_context_code             => l_amb_context_code
23004   , p_side                         => 'NA'
23005   );
23006 
23007 
23008    l_segment := AcctDerRule_3(
23009            p_application_id           => p_application_id
23010          , p_ae_header_id             => l_ae_header_id 
23011 , p_source_2 => p_source_2
23012          , x_transaction_coa_id       => l_adr_transaction_coa_id
23013          , x_accounting_coa_id        => l_adr_accounting_coa_id
23014          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
23015          , x_flex_value_set_id        => l_adr_flex_value_set_id
23016          , x_value_type_code          => l_adr_value_type_code
23017          , x_value_combination_id     => l_adr_value_combination_id
23018          , x_value_segment_code       => l_adr_value_segment_code
23019          , p_side                     => 'NA'
23020          , p_override_seg_flag        => 'Y'
23021    );
23022 
23023    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
23024 
23025       xla_ae_lines_pkg.set_segment(
23026           p_to_segment_code         => 'GL_BALANCING'
23027         , p_segment_value           => l_segment
23028         , p_from_segment_code       => l_adr_value_segment_code
23029         , p_from_combination_id     => l_adr_value_combination_id
23030         , p_value_type_code         => l_adr_value_type_code
23031         , p_transaction_coa_id      => l_adr_transaction_coa_id
23032         , p_accounting_coa_id       => l_adr_accounting_coa_id
23033         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
23034         , p_flex_value_set_id       => l_adr_flex_value_set_id
23035         , p_adr_code                => 'MFAR_CM_BALANCING_SEGMENT'
23036         , p_adr_type_code           => 'S'
23037         , p_component_type          => l_component_type
23038         , p_component_code          => l_component_code
23039         , p_component_type_code     => l_component_type_code
23040         , p_component_appl_id       => l_component_appl_id
23041         , p_amb_context_code        => l_amb_context_code
23042         , p_entity_code             => 'TRANSACTIONS'
23043         , p_event_class_code        => 'CREDIT_MEMO'
23044         , p_side                    => 'NA'
23045         );
23046 
23047   END IF;
23048 
23049    --
23050    --
23051    END IF;
23052    --
23053    -- Bug 4922099
23054    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
23055           (NVL(l_enc_upg_option, 'N') = 'O')
23056         ) AND
23057         (l_bflow_method_code = 'PRIOR_ENTRY')
23058       )
23059    THEN
23060       IF
23061       --
23062       1 = 2
23063       --
23064       THEN
23065       xla_accounting_err_pkg.build_message
23066                                     (p_appli_s_name            => 'XLA'
23067                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
23068                                     ,p_token_1                 => 'LINE_NUMBER'
23069                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
23070                                     ,p_token_2                 => 'LINE_TYPE_NAME'
23071                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
23072                                                                              l_component_type
23073                                                                             ,l_component_code
23074                                                                             ,l_component_type_code
23075                                                                             ,l_component_appl_id
23076                                                                             ,l_amb_context_code
23077                                                                             ,l_entity_code
23078                                                                             ,l_event_class_code
23079                                                                            )
23080                                     ,p_token_3                 => 'OWNER'
23081                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
23082                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
23083                                                                           ,p_lookup_code    => l_component_type_code
23084                                                                          )
23085                                     ,p_token_4                 => 'PRODUCT_NAME'
23086                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
23087                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
23088                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
23089                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
23090                                     ,p_ae_header_id            =>  NULL
23091                                        );
23092 
23093         IF (C_LEVEL_ERROR>= g_log_level) THEN
23094                  trace
23095                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
23096                       ,p_level    => C_LEVEL_ERROR
23097                       ,p_module   => l_log_module);
23098         END IF;
23099       END IF;
23100    END IF;
23101    --
23102    --
23103    ------------------------------------------------------------------------------------------------
23104    -- 4219869 Business Flow
23105    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
23106    -- Prior Entry.  Currently, the following code is always generated.
23107    ------------------------------------------------------------------------------------------------
23108    XLA_AE_LINES_PKG.ValidateCurrentLine;
23109 
23110    ------------------------------------------------------------------------------------
23111    -- 4219869 Business Flow
23112    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
23113    ------------------------------------------------------------------------------------
23114    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
23115 
23116    ----------------------------------------------------------------------------------
23117    -- 4219869 Business Flow
23118    -- Update journal entry status -- Need to generate this within IF <condition>
23119    ----------------------------------------------------------------------------------
23120    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
23121          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
23122          ,p_balance_type_code => l_balance_type_code
23123          );
23124 
23125    -------------------------------------------------------------------------------------------
23126    -- 4262811 - Generate the Accrual Reversal lines
23127    -------------------------------------------------------------------------------------------
23128    BEGIN
23129       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
23130                               (g_array_event(p_event_id).array_value_num('header_index'));
23131       IF l_acc_rev_flag IS NULL THEN
23132          l_acc_rev_flag := 'N';
23133       END IF;
23134    EXCEPTION
23135       WHEN OTHERS THEN
23136          l_acc_rev_flag := 'N';
23137    END;
23138    --
23139    IF (l_acc_rev_flag = 'Y') THEN
23140 
23141        -- 4645092  ------------------------------------------------------------------------------
23142        -- To allow MPA report to determine if it should generate report process
23143        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
23144        ------------------------------------------------------------------------------------------
23145 
23146        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
23147        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
23148    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
23149    -- call ADRs
23150    -- Bug 4922099
23151    --
23152    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
23153         (NVL(l_actual_upg_option, 'N') = 'O') OR
23154         (NVL(l_enc_upg_option, 'N') = 'O')
23155       )
23156    THEN
23157    NULL;
23158    --
23159    --
23160    
23161   l_ccid := AcctDerRule_8(
23162            p_application_id           => p_application_id
23163          , p_ae_header_id             => l_ae_header_id 
23164 , p_source_5 => p_source_5
23165          , x_transaction_coa_id       => l_adr_transaction_coa_id
23166          , x_accounting_coa_id        => l_adr_accounting_coa_id
23167          , x_value_type_code          => l_adr_value_type_code
23168          , p_side                     => 'NA'
23169    );
23170 
23171    xla_ae_lines_pkg.set_ccid(
23172     p_code_combination_id          => l_ccid
23173   , p_value_type_code              => l_adr_value_type_code
23174   , p_transaction_coa_id           => l_adr_transaction_coa_id
23175   , p_accounting_coa_id            => l_adr_accounting_coa_id
23176   , p_adr_code                     => 'MFAR_CM_DEF_REC_CCID'
23177   , p_adr_type_code                => 'S'
23178   , p_component_type               => l_component_type
23179   , p_component_code               => l_component_code
23180   , p_component_type_code          => l_component_type_code
23181   , p_component_appl_id            => l_component_appl_id
23182   , p_amb_context_code             => l_amb_context_code
23183   , p_side                         => 'NA'
23184   );
23185 
23186 
23187    l_segment := AcctDerRule_3(
23188            p_application_id           => p_application_id
23189          , p_ae_header_id             => l_ae_header_id 
23190 , p_source_2 => p_source_2
23191          , x_transaction_coa_id       => l_adr_transaction_coa_id
23192          , x_accounting_coa_id        => l_adr_accounting_coa_id
23193          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
23194          , x_flex_value_set_id        => l_adr_flex_value_set_id
23195          , x_value_type_code          => l_adr_value_type_code
23196          , x_value_combination_id     => l_adr_value_combination_id
23197          , x_value_segment_code       => l_adr_value_segment_code
23198          , p_side                     => 'NA'
23199          , p_override_seg_flag        => 'Y'
23200    );
23201 
23202    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
23203 
23204       xla_ae_lines_pkg.set_segment(
23205           p_to_segment_code         => 'GL_BALANCING'
23206         , p_segment_value           => l_segment
23207         , p_from_segment_code       => l_adr_value_segment_code
23208         , p_from_combination_id     => l_adr_value_combination_id
23209         , p_value_type_code         => l_adr_value_type_code
23210         , p_transaction_coa_id      => l_adr_transaction_coa_id
23211         , p_accounting_coa_id       => l_adr_accounting_coa_id
23212         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
23213         , p_flex_value_set_id       => l_adr_flex_value_set_id
23214         , p_adr_code                => 'MFAR_CM_BALANCING_SEGMENT'
23215         , p_adr_type_code           => 'S'
23216         , p_component_type          => l_component_type
23217         , p_component_code          => l_component_code
23218         , p_component_type_code     => l_component_type_code
23219         , p_component_appl_id       => l_component_appl_id
23220         , p_amb_context_code        => l_amb_context_code
23221         , p_entity_code             => 'TRANSACTIONS'
23222         , p_event_class_code        => 'CREDIT_MEMO'
23223         , p_side                    => 'NA'
23224         );
23225 
23226   END IF;
23227 
23228    --
23229    --
23230    END IF;
23231 
23232        --
23233        -- Update the line information that should be overwritten
23234        --
23235        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
23236                                          p_header_num   => 1);
23237        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
23238 
23239        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
23240 
23241        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
23242           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
23243        END IF;
23244 
23245       --
23246       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
23247       --
23248       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
23249           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
23250       ELSE
23251           ---------------------------------------------------------------------------------------------------
23252           -- 4262811a Switch Sign
23253           ---------------------------------------------------------------------------------------------------
23254           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
23255           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
23256                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
23257           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
23258                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
23259           -- 5132302
23260           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
23261                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
23262 
23263       END IF;
23264 
23265       -- 4955764
23266       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
23267       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
23268 
23269 
23270       XLA_AE_LINES_PKG.ValidateCurrentLine;
23271       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
23272 
23273       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
23274                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
23275                ,p_balance_type_code => l_balance_type_code);
23276 
23277    END IF;
23278 
23279    -----------------------------------------------------------------------------------------
23280    -- 4262811 Multiperiod Accounting
23281    -----------------------------------------------------------------------------------------
23282      -- No MPA option is assigned.
23283 
23284 
23285 END IF;
23286 END IF;
23287 --
23288 
23289 --
23290 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
23291    trace
23292       (p_msg      => 'END of AcctLineType_53'
23293       ,p_level    => C_LEVEL_PROCEDURE
23294       ,p_module   => l_log_module);
23295 END IF;
23296 --
23297 EXCEPTION
23298   WHEN xla_exceptions_pkg.application_exception THEN
23299       RAISE;
23300   WHEN OTHERS THEN
23301        xla_exceptions_pkg.raise_message
23302            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_53');
23303 END AcctLineType_53;
23304 --
23305 
23306 ---------------------------------------
23307 --
23308 -- PRIVATE FUNCTION
23309 --         AcctLineType_54
23310 --
23311 ---------------------------------------
23312 PROCEDURE AcctLineType_54 (
23313   p_application_id        IN NUMBER
23314  ,p_event_id              IN NUMBER
23315  ,p_calculate_acctd_flag  IN VARCHAR2
23316  ,p_calculate_g_l_flag    IN VARCHAR2
23317  ,p_actual_flag           IN OUT VARCHAR2
23318  ,p_balance_type_code     OUT VARCHAR2
23319  ,p_gain_or_loss_ref      OUT VARCHAR2
23320  
23321 --Transaction Distribution GL Account
23322  , p_source_4            IN NUMBER
23323 --Transaction Default Receivable Account
23324  , p_source_9            IN NUMBER
23325 --Bill To Customer Account Identifier
23326  , p_source_23            IN NUMBER
23327 --Bill To Customer Site Use Identifier
23328  , p_source_24            IN NUMBER
23329 --SLA Party Type
23330  , p_source_25            IN VARCHAR2
23331 --Transaction Distribution Account Class
23332  , p_source_26            IN VARCHAR2
23333 --Transaction Distribution Identifier
23334  , p_source_27            IN NUMBER
23335 --Transaction Distribution Type
23336  , p_source_28            IN VARCHAR2
23337 --Transaction Distribution Entered Amount
23338  , p_source_29            IN NUMBER
23339 --Transaction Currency Code
23340  , p_source_30            IN VARCHAR2
23341 --Transaction Exchange Date
23342  , p_source_31            IN DATE
23343 --Transaction Exchange Rate
23344  , p_source_32            IN NUMBER
23345 --Transaction Exchange Rate Type
23346  , p_source_33            IN VARCHAR2
23347 --Transaction Accounting Amount
23348  , p_source_34            IN NUMBER
23349 --Transaction Tax Line Identifier
23350  , p_source_48            IN NUMBER
23351 --Transaction Invoicing Rule
23352  , p_source_51            IN NUMBER
23353 )
23354 IS
23355 
23356 l_component_type              VARCHAR2(80);
23357 l_component_code              VARCHAR2(30);
23358 l_component_type_code         VARCHAR2(1);
23359 l_component_appl_id           INTEGER;
23360 l_amb_context_code            VARCHAR2(30);
23361 l_entity_code                 VARCHAR2(30);
23362 l_event_class_code            VARCHAR2(30);
23363 l_ae_header_id                NUMBER;
23364 l_event_type_code             VARCHAR2(30);
23365 l_line_definition_code        VARCHAR2(30);
23366 l_line_definition_owner_code  VARCHAR2(1);
23367 --
23368 -- adr variables
23369 l_segment                     VARCHAR2(30);
23370 l_ccid                        NUMBER;
23371 l_adr_transaction_coa_id      NUMBER;
23372 l_adr_accounting_coa_id       NUMBER;
23373 l_adr_flexfield_segment_code  VARCHAR2(30);
23374 l_adr_flex_value_set_id       NUMBER;
23375 l_adr_value_type_code         VARCHAR2(30);
23376 l_adr_value_combination_id    NUMBER;
23377 l_adr_value_segment_code      VARCHAR2(30);
23378 
23379 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
23380 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
23381 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
23382 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
23383 
23384 -- 4262811 Variables ------------------------------------------------------------------------------------------
23385 l_entered_amt_idx             NUMBER;
23386 l_accted_amt_idx              NUMBER;
23387 l_acc_rev_flag                VARCHAR2(1);
23388 l_accrual_line_num            NUMBER;
23389 l_tmp_amt                     NUMBER;
23390 l_acc_rev_natural_side_code   VARCHAR2(1);
23391 
23392 l_num_entries                 NUMBER;
23393 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
23394 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
23395 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
23396 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
23397 l_recog_line_1                NUMBER;
23398 l_recog_line_2                NUMBER;
23399 
23400 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
23404 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
23401 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
23402 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
23403 
23405 
23406 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
23407 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
23408 
23409 ---------------------------------------------------------------------------------------------------------------
23410 
23411 
23412 --
23413 -- bulk performance
23414 --
23415 l_balance_type_code           VARCHAR2(1);
23416 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
23417 l_log_module                  VARCHAR2(240);
23418 
23419 --
23420 -- Upgrade strategy
23421 --
23422 l_actual_upg_option           VARCHAR2(1);
23423 l_enc_upg_option           VARCHAR2(1);
23424 
23425 --
23426 BEGIN
23427 --
23428 IF g_log_enabled THEN
23429       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_54';
23430 END IF;
23431 --
23432 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
23433 
23434       trace
23435          (p_msg      => 'BEGIN of AcctLineType_54'
23436          ,p_level    => C_LEVEL_PROCEDURE
23437          ,p_module   => l_log_module);
23438 
23439 END IF;
23440 --
23441 l_component_type             := 'AMB_JLT';
23442 l_component_code             := 'MFAR_DM_REC';
23443 l_component_type_code        := 'S';
23444 l_component_appl_id          :=  222;
23445 l_amb_context_code           := 'DEFAULT';
23446 l_entity_code                := 'TRANSACTIONS';
23447 l_event_class_code           := 'DEBIT_MEMO';
23448 l_event_type_code            := 'DEBIT_MEMO_ALL';
23449 l_line_definition_owner_code := 'S';
23450 l_line_definition_code       := 'MFAR_DM_ACCRUAL_BALANCING';
23451 --
23452 l_balance_type_code          := 'A';
23453 l_segment                     := NULL;
23454 l_ccid                        := NULL;
23455 l_adr_transaction_coa_id      := NULL;
23456 l_adr_accounting_coa_id       := NULL;
23457 l_adr_flexfield_segment_code  := NULL;
23458 l_adr_flex_value_set_id       := NULL;
23459 l_adr_value_type_code         := NULL;
23460 l_adr_value_combination_id    := NULL;
23461 l_adr_value_segment_code      := NULL;
23462 
23463 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
23464 l_bflow_class_code           := 'RECEIVABLE';    -- 4219869 Business Flow
23465 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
23466 l_budgetary_control_flag     := 'N';
23467 
23468 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
23469 l_bflow_applied_to_amt       := NULL; -- 5132302
23470 l_entered_amt_idx            := NULL;          -- 4262811
23471 l_accted_amt_idx             := NULL;          -- 4262811
23472 l_acc_rev_flag               := NULL;          -- 4262811
23473 l_accrual_line_num           := NULL;          -- 4262811
23474 l_tmp_amt                    := NULL;          -- 4262811
23475 --
23476  
23477 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
23478     l_balance_type_code <> 'B' THEN
23479 IF (p_source_51 IS NULL ) AND 
23480 (NVL(p_source_26,'
23481 ') =  'REV' OR 
23482 NVL(p_source_26,'
23483 ') =  'TAX' OR 
23484 NVL(p_source_26,'
23485 ') =  'FREIGHT' OR 
23486 NVL(p_source_26,'
23487 ') =  'ROUND' OR 
23488 NVL(p_source_26,'
23489 ') =  'CHARGES')
23490  THEN 
23491 
23492    --
23493    XLA_AE_LINES_PKG.SetNewLine;
23494 
23495    p_balance_type_code          := l_balance_type_code;
23496    -- set the flag so later we will know whether the gain loss line needs to be created
23497    
23498    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
23499      p_actual_flag :='A';
23500    END IF;
23501 
23502    --
23503    -- bulk performance
23504    --
23505    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
23506                                       p_header_num   => 0); -- 4262811
23507    --
23508    -- set accounting line options
23509    --
23510    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
23511            p_natural_side_code          => 'D'
23512          , p_gain_or_loss_flag          => 'N'
23513          , p_gl_transfer_mode_code      => 'S'
23514          , p_acct_entry_type_code       => 'A'
23515          , p_switch_side_flag           => 'Y'
23516          , p_merge_duplicate_code       => 'A'
23517          );
23518    --
23519    l_acc_rev_natural_side_code := 'C';  -- 4262811
23520    -- 
23521    --
23522    -- set accounting line type info
23523    --
23524    xla_ae_lines_pkg.SetAcctLineType
23525       (p_component_type             => l_component_type
23526       ,p_event_type_code            => l_event_type_code
23527       ,p_line_definition_owner_code => l_line_definition_owner_code
23528       ,p_line_definition_code       => l_line_definition_code
23529       ,p_accounting_line_code       => l_component_code
23530       ,p_accounting_line_type_code  => l_component_type_code
23531       ,p_accounting_line_appl_id    => l_component_appl_id
23532       ,p_amb_context_code           => l_amb_context_code
23533       ,p_entity_code                => l_entity_code
23534       ,p_event_class_code           => l_event_class_code);
23535    --
23536    -- set accounting class
23537    --
23538    xla_ae_lines_pkg.SetAcctClass(
23539            p_accounting_class_code  => 'RECEIVABLE'
23540          , p_ae_header_id           => l_ae_header_id
23541          );
23542 
23543    --
23544    -- set rounding class
23545    --
23546    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
23547                       'RECEIVABLE';
23548 
23549    --
23550    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
23551    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
23552    --
23553    -- bulk performance
23554    --
23555    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
23556 
23557    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
23558       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
23559 
23560    -- 4955764
23561    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
23562       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
23563 
23564    -- 4458381 Public Sector Enh
23565    
23566    --
23567    -- set accounting attributes for the line type
23568    --
23569    l_entered_amt_idx := 3;
23570    l_accted_amt_idx  := 8;
23571    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
23572    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
23573    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
23574    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
23575    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
23576    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
23577    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
23578    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
23579    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
23580    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
23581    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
23582    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
23583    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
23584    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
23585    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
23586    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
23587    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
23588    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
23589    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
23590    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
23591    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
23592    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
23593    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
23594    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
23595    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
23596 
23597    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
23598    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
23599 
23600    ---------------------------------------------------------------------------------------------------------------
23601    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
23602    ---------------------------------------------------------------------------------------------------------------
23603    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
23604 
23605    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
23606    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
23607 
23608    IF xla_accounting_cache_pkg.GetValueChar
23609          (p_source_code         => 'LEDGER_CATEGORY_CODE'
23610          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
23611    AND l_bflow_method_code = 'PRIOR_ENTRY'
23612 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
23613    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
23614          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
23615        )
23616    THEN
23617          xla_ae_lines_pkg.BflowUpgEntry
23618            (p_business_method_code    => l_bflow_method_code
23619            ,p_business_class_code     => l_bflow_class_code
23620            ,p_balance_type            => l_balance_type_code);
23621    ELSE
23622       NULL;
23623 -- No business flow processing for business flow method of NONE.
23624    END IF;
23625 
23626    --
23627    -- call analytical criteria
23628    --
23629    
23630    --
23631    -- call description
23632    --
23633    
23634 xla_ae_lines_pkg.SetLineDescription(
23635    p_ae_header_id => l_ae_header_id
23636   ,p_description  => Description_1 (
23637      p_application_id         => p_application_id
23638    , p_ae_header_id           => l_ae_header_id 
23639    )
23640 );
23641 
23642 
23643    --
23644    -- call ADRs
23645    -- Bug 4922099
23646    --
23647    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
23648         (NVL(l_actual_upg_option, 'N') = 'O') OR
23649         (NVL(l_enc_upg_option, 'N') = 'O')
23650       )
23651    THEN
23652    NULL;
23653    --
23654    --
23655    
23656   l_ccid := AcctDerRule_12(
23657            p_application_id           => p_application_id
23658          , p_ae_header_id             => l_ae_header_id 
23659 , p_source_9 => p_source_9
23660          , x_transaction_coa_id       => l_adr_transaction_coa_id
23661          , x_accounting_coa_id        => l_adr_accounting_coa_id
23662          , x_value_type_code          => l_adr_value_type_code
23663          , p_side                     => 'NA'
23664    );
23665 
23666    xla_ae_lines_pkg.set_ccid(
23667     p_code_combination_id          => l_ccid
23668   , p_value_type_code              => l_adr_value_type_code
23669   , p_transaction_coa_id           => l_adr_transaction_coa_id
23670   , p_accounting_coa_id            => l_adr_accounting_coa_id
23671   , p_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
23672   , p_adr_type_code                => 'S'
23673   , p_component_type               => l_component_type
23674   , p_component_code               => l_component_code
23675   , p_component_type_code          => l_component_type_code
23676   , p_component_appl_id            => l_component_appl_id
23677   , p_amb_context_code             => l_amb_context_code
23678   , p_side                         => 'NA'
23679   );
23680 
23681 
23682    l_segment := AcctDerRule_5(
23683            p_application_id           => p_application_id
23684          , p_ae_header_id             => l_ae_header_id 
23685 , p_source_4 => p_source_4
23686          , x_transaction_coa_id       => l_adr_transaction_coa_id
23687          , x_accounting_coa_id        => l_adr_accounting_coa_id
23688          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
23689          , x_flex_value_set_id        => l_adr_flex_value_set_id
23690          , x_value_type_code          => l_adr_value_type_code
23691          , x_value_combination_id     => l_adr_value_combination_id
23692          , x_value_segment_code       => l_adr_value_segment_code
23693          , p_side                     => 'NA'
23694          , p_override_seg_flag        => 'Y'
23695    );
23696 
23697    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
23698 
23699       xla_ae_lines_pkg.set_segment(
23700           p_to_segment_code         => 'GL_BALANCING'
23701         , p_segment_value           => l_segment
23702         , p_from_segment_code       => l_adr_value_segment_code
23703         , p_from_combination_id     => l_adr_value_combination_id
23704         , p_value_type_code         => l_adr_value_type_code
23705         , p_transaction_coa_id      => l_adr_transaction_coa_id
23706         , p_accounting_coa_id       => l_adr_accounting_coa_id
23707         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
23708         , p_flex_value_set_id       => l_adr_flex_value_set_id
23709         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
23710         , p_adr_type_code           => 'S'
23711         , p_component_type          => l_component_type
23712         , p_component_code          => l_component_code
23713         , p_component_type_code     => l_component_type_code
23714         , p_component_appl_id       => l_component_appl_id
23715         , p_amb_context_code        => l_amb_context_code
23716         , p_entity_code             => 'TRANSACTIONS'
23717         , p_event_class_code        => 'DEBIT_MEMO'
23718         , p_side                    => 'NA'
23719         );
23720 
23721   END IF;
23722 
23723    --
23724    --
23725    END IF;
23726    --
23727    -- Bug 4922099
23728    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
23729           (NVL(l_enc_upg_option, 'N') = 'O')
23730         ) AND
23731         (l_bflow_method_code = 'PRIOR_ENTRY')
23732       )
23733    THEN
23734       IF
23735       --
23736       1 = 2
23737       --
23738       THEN
23739       xla_accounting_err_pkg.build_message
23740                                     (p_appli_s_name            => 'XLA'
23741                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
23742                                     ,p_token_1                 => 'LINE_NUMBER'
23743                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
23744                                     ,p_token_2                 => 'LINE_TYPE_NAME'
23745                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
23746                                                                              l_component_type
23747                                                                             ,l_component_code
23748                                                                             ,l_component_type_code
23749                                                                             ,l_component_appl_id
23750                                                                             ,l_amb_context_code
23751                                                                             ,l_entity_code
23752                                                                             ,l_event_class_code
23753                                                                            )
23754                                     ,p_token_3                 => 'OWNER'
23755                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
23756                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
23757                                                                           ,p_lookup_code    => l_component_type_code
23758                                                                          )
23759                                     ,p_token_4                 => 'PRODUCT_NAME'
23760                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
23761                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
23762                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
23763                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
23764                                     ,p_ae_header_id            =>  NULL
23765                                        );
23766 
23767         IF (C_LEVEL_ERROR>= g_log_level) THEN
23768                  trace
23769                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
23770                       ,p_level    => C_LEVEL_ERROR
23771                       ,p_module   => l_log_module);
23772         END IF;
23773       END IF;
23774    END IF;
23775    --
23776    --
23777    ------------------------------------------------------------------------------------------------
23778    -- 4219869 Business Flow
23779    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
23780    -- Prior Entry.  Currently, the following code is always generated.
23781    ------------------------------------------------------------------------------------------------
23782    XLA_AE_LINES_PKG.ValidateCurrentLine;
23783 
23784    ------------------------------------------------------------------------------------
23785    -- 4219869 Business Flow
23786    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
23787    ------------------------------------------------------------------------------------
23788    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
23789 
23790    ----------------------------------------------------------------------------------
23791    -- 4219869 Business Flow
23792    -- Update journal entry status -- Need to generate this within IF <condition>
23793    ----------------------------------------------------------------------------------
23794    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
23795          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
23796          ,p_balance_type_code => l_balance_type_code
23797          );
23798 
23799    -------------------------------------------------------------------------------------------
23800    -- 4262811 - Generate the Accrual Reversal lines
23801    -------------------------------------------------------------------------------------------
23802    BEGIN
23803       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
23804                               (g_array_event(p_event_id).array_value_num('header_index'));
23805       IF l_acc_rev_flag IS NULL THEN
23806          l_acc_rev_flag := 'N';
23807       END IF;
23808    EXCEPTION
23809       WHEN OTHERS THEN
23810          l_acc_rev_flag := 'N';
23811    END;
23812    --
23813    IF (l_acc_rev_flag = 'Y') THEN
23814 
23815        -- 4645092  ------------------------------------------------------------------------------
23816        -- To allow MPA report to determine if it should generate report process
23817        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
23818        ------------------------------------------------------------------------------------------
23819 
23820        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
23821        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
23822    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
23823    -- call ADRs
23824    -- Bug 4922099
23825    --
23826    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
23827         (NVL(l_actual_upg_option, 'N') = 'O') OR
23828         (NVL(l_enc_upg_option, 'N') = 'O')
23829       )
23830    THEN
23831    NULL;
23832    --
23833    --
23834    
23835   l_ccid := AcctDerRule_12(
23836            p_application_id           => p_application_id
23837          , p_ae_header_id             => l_ae_header_id 
23838 , p_source_9 => p_source_9
23839          , x_transaction_coa_id       => l_adr_transaction_coa_id
23840          , x_accounting_coa_id        => l_adr_accounting_coa_id
23841          , x_value_type_code          => l_adr_value_type_code
23842          , p_side                     => 'NA'
23843    );
23844 
23845    xla_ae_lines_pkg.set_ccid(
23846     p_code_combination_id          => l_ccid
23847   , p_value_type_code              => l_adr_value_type_code
23848   , p_transaction_coa_id           => l_adr_transaction_coa_id
23849   , p_accounting_coa_id            => l_adr_accounting_coa_id
23850   , p_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
23851   , p_adr_type_code                => 'S'
23852   , p_component_type               => l_component_type
23853   , p_component_code               => l_component_code
23854   , p_component_type_code          => l_component_type_code
23855   , p_component_appl_id            => l_component_appl_id
23856   , p_amb_context_code             => l_amb_context_code
23857   , p_side                         => 'NA'
23858   );
23859 
23860 
23861    l_segment := AcctDerRule_5(
23862            p_application_id           => p_application_id
23863          , p_ae_header_id             => l_ae_header_id 
23864 , p_source_4 => p_source_4
23865          , x_transaction_coa_id       => l_adr_transaction_coa_id
23866          , x_accounting_coa_id        => l_adr_accounting_coa_id
23867          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
23868          , x_flex_value_set_id        => l_adr_flex_value_set_id
23869          , x_value_type_code          => l_adr_value_type_code
23870          , x_value_combination_id     => l_adr_value_combination_id
23871          , x_value_segment_code       => l_adr_value_segment_code
23872          , p_side                     => 'NA'
23873          , p_override_seg_flag        => 'Y'
23874    );
23875 
23876    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
23877 
23878       xla_ae_lines_pkg.set_segment(
23879           p_to_segment_code         => 'GL_BALANCING'
23880         , p_segment_value           => l_segment
23881         , p_from_segment_code       => l_adr_value_segment_code
23882         , p_from_combination_id     => l_adr_value_combination_id
23883         , p_value_type_code         => l_adr_value_type_code
23884         , p_transaction_coa_id      => l_adr_transaction_coa_id
23885         , p_accounting_coa_id       => l_adr_accounting_coa_id
23886         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
23887         , p_flex_value_set_id       => l_adr_flex_value_set_id
23888         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
23889         , p_adr_type_code           => 'S'
23890         , p_component_type          => l_component_type
23891         , p_component_code          => l_component_code
23892         , p_component_type_code     => l_component_type_code
23893         , p_component_appl_id       => l_component_appl_id
23894         , p_amb_context_code        => l_amb_context_code
23895         , p_entity_code             => 'TRANSACTIONS'
23896         , p_event_class_code        => 'DEBIT_MEMO'
23897         , p_side                    => 'NA'
23898         );
23899 
23900   END IF;
23901 
23902    --
23903    --
23904    END IF;
23905 
23906        --
23907        -- Update the line information that should be overwritten
23908        --
23909        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
23910                                          p_header_num   => 1);
23911        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
23912 
23913        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
23914 
23915        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
23916           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
23917        END IF;
23918 
23919       --
23920       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
23921       --
23922       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
23923           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
23924       ELSE
23925           ---------------------------------------------------------------------------------------------------
23926           -- 4262811a Switch Sign
23927           ---------------------------------------------------------------------------------------------------
23928           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
23929           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
23933           -- 5132302
23930                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
23931           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
23932                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
23934           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
23935                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
23936 
23937       END IF;
23938 
23939       -- 4955764
23940       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
23941       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
23942 
23943 
23944       XLA_AE_LINES_PKG.ValidateCurrentLine;
23945       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
23946 
23947       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
23948                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
23949                ,p_balance_type_code => l_balance_type_code);
23950 
23951    END IF;
23952 
23953    -----------------------------------------------------------------------------------------
23954    -- 4262811 Multiperiod Accounting
23955    -----------------------------------------------------------------------------------------
23956      -- No MPA option is assigned.
23957 
23958 
23959 END IF;
23960 END IF;
23961 --
23962 
23963 --
23964 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
23965    trace
23966       (p_msg      => 'END of AcctLineType_54'
23967       ,p_level    => C_LEVEL_PROCEDURE
23968       ,p_module   => l_log_module);
23969 END IF;
23970 --
23971 EXCEPTION
23972   WHEN xla_exceptions_pkg.application_exception THEN
23973       RAISE;
23974   WHEN OTHERS THEN
23975        xla_exceptions_pkg.raise_message
23976            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_54');
23977 END AcctLineType_54;
23978 --
23979 
23980 ---------------------------------------
23981 --
23982 -- PRIVATE FUNCTION
23983 --         AcctLineType_55
23984 --
23985 ---------------------------------------
23986 PROCEDURE AcctLineType_55 (
23987   p_application_id        IN NUMBER
23988  ,p_event_id              IN NUMBER
23989  ,p_calculate_acctd_flag  IN VARCHAR2
23990  ,p_calculate_g_l_flag    IN VARCHAR2
23991  ,p_actual_flag           IN OUT VARCHAR2
23992  ,p_balance_type_code     OUT VARCHAR2
23993  ,p_gain_or_loss_ref      OUT VARCHAR2
23994  
23995 --Transaction Distribution GL Account
23996  , p_source_4            IN NUMBER
23997 --Transaction Default Receivable Account
23998  , p_source_9            IN NUMBER
23999 --Bill To Customer Account Identifier
24000  , p_source_23            IN NUMBER
24001 --Bill To Customer Site Use Identifier
24002  , p_source_24            IN NUMBER
24003 --SLA Party Type
24004  , p_source_25            IN VARCHAR2
24005 --Transaction Distribution Account Class
24006  , p_source_26            IN VARCHAR2
24007 --Transaction Distribution Identifier
24008  , p_source_27            IN NUMBER
24009 --Transaction Distribution Type
24010  , p_source_28            IN VARCHAR2
24011 --Transaction Distribution Entered Amount
24012  , p_source_29            IN NUMBER
24013 --Transaction Currency Code
24014  , p_source_30            IN VARCHAR2
24015 --Transaction Exchange Date
24016  , p_source_31            IN DATE
24017 --Transaction Exchange Rate
24018  , p_source_32            IN NUMBER
24019 --Transaction Exchange Rate Type
24020  , p_source_33            IN VARCHAR2
24021 --Transaction Accounting Amount
24022  , p_source_34            IN NUMBER
24023 --Transaction Tax Line Identifier
24024  , p_source_48            IN NUMBER
24025 --Transaction Invoicing Rule
24026  , p_source_51            IN NUMBER
24027 )
24028 IS
24029 
24030 l_component_type              VARCHAR2(80);
24031 l_component_code              VARCHAR2(30);
24032 l_component_type_code         VARCHAR2(1);
24033 l_component_appl_id           INTEGER;
24034 l_amb_context_code            VARCHAR2(30);
24035 l_entity_code                 VARCHAR2(30);
24036 l_event_class_code            VARCHAR2(30);
24037 l_ae_header_id                NUMBER;
24038 l_event_type_code             VARCHAR2(30);
24039 l_line_definition_code        VARCHAR2(30);
24040 l_line_definition_owner_code  VARCHAR2(1);
24041 --
24042 -- adr variables
24043 l_segment                     VARCHAR2(30);
24044 l_ccid                        NUMBER;
24045 l_adr_transaction_coa_id      NUMBER;
24046 l_adr_accounting_coa_id       NUMBER;
24047 l_adr_flexfield_segment_code  VARCHAR2(30);
24048 l_adr_flex_value_set_id       NUMBER;
24049 l_adr_value_type_code         VARCHAR2(30);
24050 l_adr_value_combination_id    NUMBER;
24051 l_adr_value_segment_code      VARCHAR2(30);
24052 
24053 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
24054 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
24055 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
24056 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
24057 
24058 -- 4262811 Variables ------------------------------------------------------------------------------------------
24059 l_entered_amt_idx             NUMBER;
24060 l_accted_amt_idx              NUMBER;
24061 l_acc_rev_flag                VARCHAR2(1);
24062 l_accrual_line_num            NUMBER;
24063 l_tmp_amt                     NUMBER;
24064 l_acc_rev_natural_side_code   VARCHAR2(1);
24065 
24066 l_num_entries                 NUMBER;
24067 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
24068 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
24069 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
24070 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
24071 l_recog_line_1                NUMBER;
24072 l_recog_line_2                NUMBER;
24073 
24074 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
24075 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
24076 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
24077 
24078 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
24079 
24080 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
24081 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
24082 
24083 ---------------------------------------------------------------------------------------------------------------
24084 
24085 
24086 --
24087 -- bulk performance
24088 --
24089 l_balance_type_code           VARCHAR2(1);
24090 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
24091 l_log_module                  VARCHAR2(240);
24092 
24093 --
24094 -- Upgrade strategy
24095 --
24096 l_actual_upg_option           VARCHAR2(1);
24097 l_enc_upg_option           VARCHAR2(1);
24098 
24099 --
24100 BEGIN
24101 --
24102 IF g_log_enabled THEN
24103       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_55';
24104 END IF;
24105 --
24106 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24107 
24108       trace
24109          (p_msg      => 'BEGIN of AcctLineType_55'
24110          ,p_level    => C_LEVEL_PROCEDURE
24111          ,p_module   => l_log_module);
24112 
24113 END IF;
24114 --
24115 l_component_type             := 'AMB_JLT';
24116 l_component_code             := 'MFAR_INV_REC';
24117 l_component_type_code        := 'S';
24118 l_component_appl_id          :=  222;
24119 l_amb_context_code           := 'DEFAULT';
24120 l_entity_code                := 'TRANSACTIONS';
24121 l_event_class_code           := 'INVOICE';
24122 l_event_type_code            := 'INVOICE_ALL';
24123 l_line_definition_owner_code := 'S';
24124 l_line_definition_code       := 'MFAR_INV_ACCRUAL_BALANCING';
24125 --
24126 l_balance_type_code          := 'A';
24127 l_segment                     := NULL;
24128 l_ccid                        := NULL;
24129 l_adr_transaction_coa_id      := NULL;
24130 l_adr_accounting_coa_id       := NULL;
24131 l_adr_flexfield_segment_code  := NULL;
24132 l_adr_flex_value_set_id       := NULL;
24133 l_adr_value_type_code         := NULL;
24134 l_adr_value_combination_id    := NULL;
24135 l_adr_value_segment_code      := NULL;
24136 
24137 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
24138 l_bflow_class_code           := 'RECEIVABLE';    -- 4219869 Business Flow
24139 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
24140 l_budgetary_control_flag     := 'N';
24141 
24142 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
24143 l_bflow_applied_to_amt       := NULL; -- 5132302
24144 l_entered_amt_idx            := NULL;          -- 4262811
24145 l_accted_amt_idx             := NULL;          -- 4262811
24146 l_acc_rev_flag               := NULL;          -- 4262811
24147 l_accrual_line_num           := NULL;          -- 4262811
24148 l_tmp_amt                    := NULL;          -- 4262811
24149 --
24150  
24151 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
24152     l_balance_type_code <> 'B' THEN
24153 IF (p_source_51 IS NULL ) AND 
24154 (NVL(p_source_26,'
24155 ') =  'REV' OR 
24156 NVL(p_source_26,'
24157 ') =  'TAX' OR 
24158 NVL(p_source_26,'
24159 ') =  'FREIGHT' OR 
24160 NVL(p_source_26,'
24161 ') =  'ROUND' OR 
24162 NVL(p_source_26,'
24163 ') =  'CHARGES')
24164  THEN 
24165 
24166    --
24167    XLA_AE_LINES_PKG.SetNewLine;
24168 
24169    p_balance_type_code          := l_balance_type_code;
24170    -- set the flag so later we will know whether the gain loss line needs to be created
24171    
24172    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
24173      p_actual_flag :='A';
24174    END IF;
24175 
24176    --
24177    -- bulk performance
24178    --
24179    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
24180                                       p_header_num   => 0); -- 4262811
24181    --
24182    -- set accounting line options
24183    --
24184    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
24185            p_natural_side_code          => 'D'
24186          , p_gain_or_loss_flag          => 'N'
24187          , p_gl_transfer_mode_code      => 'S'
24188          , p_acct_entry_type_code       => 'A'
24189          , p_switch_side_flag           => 'Y'
24190          , p_merge_duplicate_code       => 'A'
24191          );
24192    --
24193    l_acc_rev_natural_side_code := 'C';  -- 4262811
24194    -- 
24195    --
24196    -- set accounting line type info
24197    --
24198    xla_ae_lines_pkg.SetAcctLineType
24199       (p_component_type             => l_component_type
24200       ,p_event_type_code            => l_event_type_code
24201       ,p_line_definition_owner_code => l_line_definition_owner_code
24202       ,p_line_definition_code       => l_line_definition_code
24203       ,p_accounting_line_code       => l_component_code
24204       ,p_accounting_line_type_code  => l_component_type_code
24205       ,p_accounting_line_appl_id    => l_component_appl_id
24206       ,p_amb_context_code           => l_amb_context_code
24207       ,p_entity_code                => l_entity_code
24208       ,p_event_class_code           => l_event_class_code);
24209    --
24210    -- set accounting class
24211    --
24212    xla_ae_lines_pkg.SetAcctClass(
24213            p_accounting_class_code  => 'RECEIVABLE'
24214          , p_ae_header_id           => l_ae_header_id
24215          );
24216 
24217    --
24218    -- set rounding class
24219    --
24220    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
24221                       'RECEIVABLE';
24222 
24223    --
24224    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
24225    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
24226    --
24227    -- bulk performance
24228    --
24229    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
24230 
24231    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
24232       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
24233 
24234    -- 4955764
24235    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
24236       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
24237 
24238    -- 4458381 Public Sector Enh
24239    
24240    --
24241    -- set accounting attributes for the line type
24242    --
24243    l_entered_amt_idx := 3;
24244    l_accted_amt_idx  := 8;
24245    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
24246    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
24247    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_27);
24248    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
24249    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
24250    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
24251    l_rec_acct_attrs.array_num_value(3)  := p_source_29;
24252    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
24253    l_rec_acct_attrs.array_char_value(4)  := p_source_30;
24254    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
24255    l_rec_acct_attrs.array_date_value(5)  := p_source_31;
24256    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
24257    l_rec_acct_attrs.array_num_value(6)  := p_source_32;
24258    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
24259    l_rec_acct_attrs.array_char_value(7)  := p_source_33;
24260    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
24261    l_rec_acct_attrs.array_num_value(8)  := p_source_34;
24262    l_rec_acct_attrs.array_acct_attr_code(9) := 'PARTY_ID';
24263    l_rec_acct_attrs.array_num_value(9)  := p_source_23;
24264    l_rec_acct_attrs.array_acct_attr_code(10) := 'PARTY_SITE_ID';
24265    l_rec_acct_attrs.array_num_value(10)  := p_source_24;
24266    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
24267    l_rec_acct_attrs.array_char_value(11)  := p_source_25;
24268    l_rec_acct_attrs.array_acct_attr_code(12) := 'TAX_LINE_REF_ID';
24269    l_rec_acct_attrs.array_num_value(12)  := p_source_48;
24270 
24271    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
24272    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
24273 
24274    ---------------------------------------------------------------------------------------------------------------
24275    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
24276    ---------------------------------------------------------------------------------------------------------------
24277    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
24278 
24279    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
24280    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
24281 
24282    IF xla_accounting_cache_pkg.GetValueChar
24283          (p_source_code         => 'LEDGER_CATEGORY_CODE'
24284          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
24285    AND l_bflow_method_code = 'PRIOR_ENTRY'
24286 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
24287    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
24288          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
24289        )
24290    THEN
24291          xla_ae_lines_pkg.BflowUpgEntry
24292            (p_business_method_code    => l_bflow_method_code
24293            ,p_business_class_code     => l_bflow_class_code
24294            ,p_balance_type            => l_balance_type_code);
24295    ELSE
24296       NULL;
24297 -- No business flow processing for business flow method of NONE.
24298    END IF;
24299 
24300    --
24301    -- call analytical criteria
24302    --
24303    
24304    --
24305    -- call description
24306    --
24307    
24308 xla_ae_lines_pkg.SetLineDescription(
24309    p_ae_header_id => l_ae_header_id
24310   ,p_description  => Description_1 (
24311      p_application_id         => p_application_id
24312    , p_ae_header_id           => l_ae_header_id 
24313    )
24314 );
24315 
24316 
24317    --
24318    -- call ADRs
24319    -- Bug 4922099
24320    --
24321    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
24322         (NVL(l_actual_upg_option, 'N') = 'O') OR
24323         (NVL(l_enc_upg_option, 'N') = 'O')
24324       )
24325    THEN
24326    NULL;
24327    --
24328    --
24329    
24330   l_ccid := AcctDerRule_12(
24331            p_application_id           => p_application_id
24332          , p_ae_header_id             => l_ae_header_id 
24333 , p_source_9 => p_source_9
24334          , x_transaction_coa_id       => l_adr_transaction_coa_id
24335          , x_accounting_coa_id        => l_adr_accounting_coa_id
24336          , x_value_type_code          => l_adr_value_type_code
24337          , p_side                     => 'NA'
24338    );
24339 
24340    xla_ae_lines_pkg.set_ccid(
24341     p_code_combination_id          => l_ccid
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_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
24346   , p_adr_type_code                => 'S'
24347   , p_component_type               => l_component_type
24348   , p_component_code               => l_component_code
24349   , p_component_type_code          => l_component_type_code
24350   , p_component_appl_id            => l_component_appl_id
24351   , p_amb_context_code             => l_amb_context_code
24352   , p_side                         => 'NA'
24353   );
24354 
24355 
24356    l_segment := AcctDerRule_5(
24357            p_application_id           => p_application_id
24358          , p_ae_header_id             => l_ae_header_id 
24359 , p_source_4 => p_source_4
24360          , x_transaction_coa_id       => l_adr_transaction_coa_id
24361          , x_accounting_coa_id        => l_adr_accounting_coa_id
24362          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
24363          , x_flex_value_set_id        => l_adr_flex_value_set_id
24364          , x_value_type_code          => l_adr_value_type_code
24365          , x_value_combination_id     => l_adr_value_combination_id
24366          , x_value_segment_code       => l_adr_value_segment_code
24367          , p_side                     => 'NA'
24368          , p_override_seg_flag        => 'Y'
24369    );
24370 
24371    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
24372 
24373       xla_ae_lines_pkg.set_segment(
24374           p_to_segment_code         => 'GL_BALANCING'
24375         , p_segment_value           => l_segment
24376         , p_from_segment_code       => l_adr_value_segment_code
24377         , p_from_combination_id     => l_adr_value_combination_id
24378         , p_value_type_code         => l_adr_value_type_code
24379         , p_transaction_coa_id      => l_adr_transaction_coa_id
24380         , p_accounting_coa_id       => l_adr_accounting_coa_id
24381         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
24382         , p_flex_value_set_id       => l_adr_flex_value_set_id
24383         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
24384         , p_adr_type_code           => 'S'
24385         , p_component_type          => l_component_type
24386         , p_component_code          => l_component_code
24387         , p_component_type_code     => l_component_type_code
24388         , p_component_appl_id       => l_component_appl_id
24389         , p_amb_context_code        => l_amb_context_code
24390         , p_entity_code             => 'TRANSACTIONS'
24391         , p_event_class_code        => 'INVOICE'
24392         , p_side                    => 'NA'
24393         );
24394 
24395   END IF;
24396 
24397    --
24398    --
24399    END IF;
24400    --
24401    -- Bug 4922099
24402    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
24403           (NVL(l_enc_upg_option, 'N') = 'O')
24404         ) AND
24405         (l_bflow_method_code = 'PRIOR_ENTRY')
24406       )
24407    THEN
24408       IF
24409       --
24410       1 = 2
24411       --
24412       THEN
24413       xla_accounting_err_pkg.build_message
24414                                     (p_appli_s_name            => 'XLA'
24415                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
24416                                     ,p_token_1                 => 'LINE_NUMBER'
24417                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
24418                                     ,p_token_2                 => 'LINE_TYPE_NAME'
24419                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
24420                                                                              l_component_type
24421                                                                             ,l_component_code
24422                                                                             ,l_component_type_code
24423                                                                             ,l_component_appl_id
24424                                                                             ,l_amb_context_code
24425                                                                             ,l_entity_code
24426                                                                             ,l_event_class_code
24427                                                                            )
24428                                     ,p_token_3                 => 'OWNER'
24429                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
24430                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
24431                                                                           ,p_lookup_code    => l_component_type_code
24432                                                                          )
24433                                     ,p_token_4                 => 'PRODUCT_NAME'
24434                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
24435                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
24436                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
24437                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
24438                                     ,p_ae_header_id            =>  NULL
24439                                        );
24440 
24441         IF (C_LEVEL_ERROR>= g_log_level) THEN
24442                  trace
24443                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
24444                       ,p_level    => C_LEVEL_ERROR
24445                       ,p_module   => l_log_module);
24446         END IF;
24447       END IF;
24448    END IF;
24449    --
24450    --
24451    ------------------------------------------------------------------------------------------------
24452    -- 4219869 Business Flow
24453    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
24454    -- Prior Entry.  Currently, the following code is always generated.
24455    ------------------------------------------------------------------------------------------------
24456    XLA_AE_LINES_PKG.ValidateCurrentLine;
24457 
24458    ------------------------------------------------------------------------------------
24459    -- 4219869 Business Flow
24460    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
24461    ------------------------------------------------------------------------------------
24462    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
24463 
24464    ----------------------------------------------------------------------------------
24465    -- 4219869 Business Flow
24466    -- Update journal entry status -- Need to generate this within IF <condition>
24467    ----------------------------------------------------------------------------------
24468    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
24469          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
24470          ,p_balance_type_code => l_balance_type_code
24471          );
24472 
24473    -------------------------------------------------------------------------------------------
24474    -- 4262811 - Generate the Accrual Reversal lines
24475    -------------------------------------------------------------------------------------------
24476    BEGIN
24477       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
24478                               (g_array_event(p_event_id).array_value_num('header_index'));
24479       IF l_acc_rev_flag IS NULL THEN
24480          l_acc_rev_flag := 'N';
24481       END IF;
24482    EXCEPTION
24483       WHEN OTHERS THEN
24484          l_acc_rev_flag := 'N';
24485    END;
24486    --
24487    IF (l_acc_rev_flag = 'Y') THEN
24488 
24489        -- 4645092  ------------------------------------------------------------------------------
24490        -- To allow MPA report to determine if it should generate report process
24491        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
24492        ------------------------------------------------------------------------------------------
24493 
24494        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
24495        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
24496    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
24497    -- call ADRs
24498    -- Bug 4922099
24499    --
24500    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
24501         (NVL(l_actual_upg_option, 'N') = 'O') OR
24502         (NVL(l_enc_upg_option, 'N') = 'O')
24503       )
24504    THEN
24505    NULL;
24506    --
24507    --
24508    
24509   l_ccid := AcctDerRule_12(
24510            p_application_id           => p_application_id
24511          , p_ae_header_id             => l_ae_header_id 
24512 , p_source_9 => p_source_9
24513          , x_transaction_coa_id       => l_adr_transaction_coa_id
24514          , x_accounting_coa_id        => l_adr_accounting_coa_id
24515          , x_value_type_code          => l_adr_value_type_code
24516          , p_side                     => 'NA'
24517    );
24518 
24519    xla_ae_lines_pkg.set_ccid(
24520     p_code_combination_id          => l_ccid
24521   , p_value_type_code              => l_adr_value_type_code
24522   , p_transaction_coa_id           => l_adr_transaction_coa_id
24523   , p_accounting_coa_id            => l_adr_accounting_coa_id
24524   , p_adr_code                     => 'MFAR_TRX_DEF_REC_CCID'
24525   , p_adr_type_code                => 'S'
24526   , p_component_type               => l_component_type
24527   , p_component_code               => l_component_code
24528   , p_component_type_code          => l_component_type_code
24529   , p_component_appl_id            => l_component_appl_id
24530   , p_amb_context_code             => l_amb_context_code
24531   , p_side                         => 'NA'
24532   );
24533 
24534 
24535    l_segment := AcctDerRule_5(
24536            p_application_id           => p_application_id
24537          , p_ae_header_id             => l_ae_header_id 
24538 , p_source_4 => p_source_4
24539          , x_transaction_coa_id       => l_adr_transaction_coa_id
24540          , x_accounting_coa_id        => l_adr_accounting_coa_id
24541          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
24542          , x_flex_value_set_id        => l_adr_flex_value_set_id
24543          , x_value_type_code          => l_adr_value_type_code
24544          , x_value_combination_id     => l_adr_value_combination_id
24545          , x_value_segment_code       => l_adr_value_segment_code
24546          , p_side                     => 'NA'
24547          , p_override_seg_flag        => 'Y'
24548    );
24549 
24550    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
24551 
24552       xla_ae_lines_pkg.set_segment(
24553           p_to_segment_code         => 'GL_BALANCING'
24554         , p_segment_value           => l_segment
24555         , p_from_segment_code       => l_adr_value_segment_code
24556         , p_from_combination_id     => l_adr_value_combination_id
24557         , p_value_type_code         => l_adr_value_type_code
24558         , p_transaction_coa_id      => l_adr_transaction_coa_id
24559         , p_accounting_coa_id       => l_adr_accounting_coa_id
24560         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
24561         , p_flex_value_set_id       => l_adr_flex_value_set_id
24562         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
24563         , p_adr_type_code           => 'S'
24564         , p_component_type          => l_component_type
24565         , p_component_code          => l_component_code
24566         , p_component_type_code     => l_component_type_code
24567         , p_component_appl_id       => l_component_appl_id
24568         , p_amb_context_code        => l_amb_context_code
24569         , p_entity_code             => 'TRANSACTIONS'
24570         , p_event_class_code        => 'INVOICE'
24571         , p_side                    => 'NA'
24572         );
24573 
24574   END IF;
24575 
24576    --
24577    --
24578    END IF;
24579 
24580        --
24581        -- Update the line information that should be overwritten
24582        --
24583        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
24584                                          p_header_num   => 1);
24585        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
24586 
24587        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
24588 
24589        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
24590           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
24591        END IF;
24592 
24593       --
24594       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
24595       --
24596       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
24597           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
24598       ELSE
24599           ---------------------------------------------------------------------------------------------------
24600           -- 4262811a Switch Sign
24601           ---------------------------------------------------------------------------------------------------
24602           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
24603           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
24604                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
24605           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
24606                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
24607           -- 5132302
24608           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
24609                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
24610 
24611       END IF;
24612 
24613       -- 4955764
24614       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
24615       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
24616 
24617 
24618       XLA_AE_LINES_PKG.ValidateCurrentLine;
24619       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
24620 
24621       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
24622                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
24623                ,p_balance_type_code => l_balance_type_code);
24624 
24625    END IF;
24626 
24627    -----------------------------------------------------------------------------------------
24628    -- 4262811 Multiperiod Accounting
24629    -----------------------------------------------------------------------------------------
24630      -- No MPA option is assigned.
24631 
24632 
24633 END IF;
24634 END IF;
24635 --
24636 
24637 --
24638 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24639    trace
24640       (p_msg      => 'END of AcctLineType_55'
24641       ,p_level    => C_LEVEL_PROCEDURE
24642       ,p_module   => l_log_module);
24643 END IF;
24644 --
24645 EXCEPTION
24646   WHEN xla_exceptions_pkg.application_exception THEN
24647       RAISE;
24648   WHEN OTHERS THEN
24649        xla_exceptions_pkg.raise_message
24650            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_55');
24651 END AcctLineType_55;
24652 --
24653 
24654 ---------------------------------------
24655 --
24656 -- PRIVATE FUNCTION
24657 --         AcctLineType_56
24658 --
24659 ---------------------------------------
24660 PROCEDURE AcctLineType_56 (
24661   p_application_id        IN NUMBER
24662  ,p_event_id              IN NUMBER
24663  ,p_calculate_acctd_flag  IN VARCHAR2
24664  ,p_calculate_g_l_flag    IN VARCHAR2
24665  ,p_actual_flag           IN OUT VARCHAR2
24666  ,p_balance_type_code     OUT VARCHAR2
24667  ,p_gain_or_loss_ref      OUT VARCHAR2
24668  
24669 --Remittance Bank Account Bank Charges Acount
24670  , p_source_1            IN NUMBER
24671 --Remittance Bank Account Cash Account
24672  , p_source_6            IN NUMBER
24673 --Distribution Source Type
24674  , p_source_13            IN VARCHAR2
24675 --Distribution Line Identifier
24676  , p_source_15            IN NUMBER
24677 --Distribution Type
24678  , p_source_16            IN VARCHAR2
24679 --Entered Amount
24680  , p_source_17            IN NUMBER
24681 --Currency Code
24682  , p_source_18            IN VARCHAR2
24683 --Exchange Rate
24684  , p_source_20            IN NUMBER
24685 --Exchange Rate Type
24686  , p_source_21            IN VARCHAR2
24687 --Applied To Document Accounting Amount
24688  , p_source_22            IN NUMBER
24689 --Distribution Multi Fund Additional Entry
24690  , p_source_52            IN VARCHAR2
24691 --Applied To Document Exchange Date
24692  , p_source_53            IN DATE
24693 )
24694 IS
24695 
24696 l_component_type              VARCHAR2(80);
24697 l_component_code              VARCHAR2(30);
24698 l_component_type_code         VARCHAR2(1);
24699 l_component_appl_id           INTEGER;
24700 l_amb_context_code            VARCHAR2(30);
24701 l_entity_code                 VARCHAR2(30);
24702 l_event_class_code            VARCHAR2(30);
24703 l_ae_header_id                NUMBER;
24704 l_event_type_code             VARCHAR2(30);
24705 l_line_definition_code        VARCHAR2(30);
24706 l_line_definition_owner_code  VARCHAR2(1);
24707 --
24708 -- adr variables
24709 l_segment                     VARCHAR2(30);
24710 l_ccid                        NUMBER;
24711 l_adr_transaction_coa_id      NUMBER;
24712 l_adr_accounting_coa_id       NUMBER;
24713 l_adr_flexfield_segment_code  VARCHAR2(30);
24714 l_adr_flex_value_set_id       NUMBER;
24715 l_adr_value_type_code         VARCHAR2(30);
24716 l_adr_value_combination_id    NUMBER;
24717 l_adr_value_segment_code      VARCHAR2(30);
24718 
24719 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
24720 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
24721 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
24722 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
24723 
24724 -- 4262811 Variables ------------------------------------------------------------------------------------------
24725 l_entered_amt_idx             NUMBER;
24726 l_accted_amt_idx              NUMBER;
24727 l_acc_rev_flag                VARCHAR2(1);
24728 l_accrual_line_num            NUMBER;
24729 l_tmp_amt                     NUMBER;
24730 l_acc_rev_natural_side_code   VARCHAR2(1);
24731 
24732 l_num_entries                 NUMBER;
24733 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
24734 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
24735 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
24736 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
24737 l_recog_line_1                NUMBER;
24738 l_recog_line_2                NUMBER;
24739 
24740 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
24741 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
24742 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
24743 
24744 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
24745 
24746 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
24747 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
24748 
24749 ---------------------------------------------------------------------------------------------------------------
24750 
24751 
24752 --
24753 -- bulk performance
24754 --
24755 l_balance_type_code           VARCHAR2(1);
24756 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
24757 l_log_module                  VARCHAR2(240);
24758 
24759 --
24760 -- Upgrade strategy
24761 --
24762 l_actual_upg_option           VARCHAR2(1);
24763 l_enc_upg_option           VARCHAR2(1);
24764 
24765 --
24766 BEGIN
24767 --
24768 IF g_log_enabled THEN
24769       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_56';
24770 END IF;
24771 --
24772 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24773 
24774       trace
24775          (p_msg      => 'BEGIN of AcctLineType_56'
24776          ,p_level    => C_LEVEL_PROCEDURE
24777          ,p_module   => l_log_module);
24778 
24779 END IF;
24780 --
24781 l_component_type             := 'AMB_JLT';
24782 l_component_code             := 'MFAR_MISC_RCT_BNK_CHG_CASH';
24783 l_component_type_code        := 'S';
24784 l_component_appl_id          :=  222;
24785 l_amb_context_code           := 'DEFAULT';
24786 l_entity_code                := 'RECEIPTS';
24787 l_event_class_code           := 'MISC_RECEIPT';
24788 l_event_type_code            := 'MISC_RECEIPT_ALL';
24789 l_line_definition_owner_code := 'S';
24790 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
24791 --
24792 l_balance_type_code          := 'A';
24793 l_segment                     := NULL;
24794 l_ccid                        := NULL;
24795 l_adr_transaction_coa_id      := NULL;
24796 l_adr_accounting_coa_id       := NULL;
24797 l_adr_flexfield_segment_code  := NULL;
24798 l_adr_flex_value_set_id       := NULL;
24799 l_adr_value_type_code         := NULL;
24800 l_adr_value_combination_id    := NULL;
24801 l_adr_value_segment_code      := NULL;
24802 
24803 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
24804 l_bflow_class_code           := '';    -- 4219869 Business Flow
24805 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
24806 l_budgetary_control_flag     := 'N';
24807 
24808 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
24809 l_bflow_applied_to_amt       := NULL; -- 5132302
24810 l_entered_amt_idx            := NULL;          -- 4262811
24811 l_accted_amt_idx             := NULL;          -- 4262811
24812 l_acc_rev_flag               := NULL;          -- 4262811
24816  
24813 l_accrual_line_num           := NULL;          -- 4262811
24814 l_tmp_amt                    := NULL;          -- 4262811
24815 --
24817 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
24818     l_balance_type_code <> 'B' THEN
24819 IF NVL(p_source_13,'
24820 ') =  'BANK_CHARGES' AND 
24821 NVL(p_source_52,'
24822 ') =  'N'
24823  THEN 
24824 
24825    --
24826    XLA_AE_LINES_PKG.SetNewLine;
24827 
24828    p_balance_type_code          := l_balance_type_code;
24829    -- set the flag so later we will know whether the gain loss line needs to be created
24830    
24831    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
24832      p_actual_flag :='A';
24833    END IF;
24834 
24835    --
24836    -- bulk performance
24837    --
24838    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
24839                                       p_header_num   => 0); -- 4262811
24840    --
24841    -- set accounting line options
24842    --
24843    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
24844            p_natural_side_code          => 'D'
24845          , p_gain_or_loss_flag          => 'N'
24846          , p_gl_transfer_mode_code      => 'S'
24847          , p_acct_entry_type_code       => 'A'
24848          , p_switch_side_flag           => 'Y'
24849          , p_merge_duplicate_code       => 'A'
24850          );
24851    --
24852    l_acc_rev_natural_side_code := 'C';  -- 4262811
24853    -- 
24854    --
24855    -- set accounting line type info
24856    --
24857    xla_ae_lines_pkg.SetAcctLineType
24858       (p_component_type             => l_component_type
24859       ,p_event_type_code            => l_event_type_code
24860       ,p_line_definition_owner_code => l_line_definition_owner_code
24861       ,p_line_definition_code       => l_line_definition_code
24862       ,p_accounting_line_code       => l_component_code
24863       ,p_accounting_line_type_code  => l_component_type_code
24864       ,p_accounting_line_appl_id    => l_component_appl_id
24865       ,p_amb_context_code           => l_amb_context_code
24866       ,p_entity_code                => l_entity_code
24867       ,p_event_class_code           => l_event_class_code);
24868    --
24869    -- set accounting class
24870    --
24871    xla_ae_lines_pkg.SetAcctClass(
24872            p_accounting_class_code  => 'BANK_CHG'
24873          , p_ae_header_id           => l_ae_header_id
24874          );
24875 
24876    --
24877    -- set rounding class
24878    --
24879    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
24880                       'RECEIVABLE';
24881 
24882    --
24883    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
24884    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
24885    --
24886    -- bulk performance
24887    --
24888    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
24889 
24890    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
24891       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
24892 
24893    -- 4955764
24894    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
24895       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
24896 
24897    -- 4458381 Public Sector Enh
24898    
24899    --
24900    -- set accounting attributes for the line type
24901    --
24902    l_entered_amt_idx := 3;
24903    l_accted_amt_idx  := 8;
24904    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
24905    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
24906    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
24907    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
24908    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
24909    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
24910    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
24911    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
24912    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
24913    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
24914    l_rec_acct_attrs.array_date_value(5)  := p_source_53;
24915    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
24916    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
24917    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
24918    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
24919    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
24920    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
24921 
24922    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
24923    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
24924 
24925    ---------------------------------------------------------------------------------------------------------------
24926    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
24927    ---------------------------------------------------------------------------------------------------------------
24928    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
24929 
24930    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
24931    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
24932 
24933    IF xla_accounting_cache_pkg.GetValueChar
24934          (p_source_code         => 'LEDGER_CATEGORY_CODE'
24935          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
24936    AND l_bflow_method_code = 'PRIOR_ENTRY'
24937 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
24938    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
24939          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
24940        )
24941    THEN
24942          xla_ae_lines_pkg.BflowUpgEntry
24943            (p_business_method_code    => l_bflow_method_code
24944            ,p_business_class_code     => l_bflow_class_code
24945            ,p_balance_type            => l_balance_type_code);
24946    ELSE
24947       NULL;
24948 -- No business flow processing for business flow method of NONE.
24949    END IF;
24950 
24951    --
24952    -- call analytical criteria
24953    --
24954    
24955    --
24956    -- call description
24957    --
24958    
24959 xla_ae_lines_pkg.SetLineDescription(
24960    p_ae_header_id => l_ae_header_id
24961   ,p_description  => Description_1 (
24962      p_application_id         => p_application_id
24963    , p_ae_header_id           => l_ae_header_id 
24964    )
24965 );
24966 
24967 
24968    --
24969    -- call ADRs
24970    -- Bug 4922099
24971    --
24972    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
24973         (NVL(l_actual_upg_option, 'N') = 'O') OR
24974         (NVL(l_enc_upg_option, 'N') = 'O')
24975       )
24976    THEN
24977    NULL;
24978    --
24979    --
24980    
24981   l_ccid := AcctDerRule_9(
24982            p_application_id           => p_application_id
24983          , p_ae_header_id             => l_ae_header_id 
24984 , p_source_6 => p_source_6
24985          , x_transaction_coa_id       => l_adr_transaction_coa_id
24986          , x_accounting_coa_id        => l_adr_accounting_coa_id
24987          , x_value_type_code          => l_adr_value_type_code
24988          , p_side                     => 'NA'
24989    );
24990 
24991    xla_ae_lines_pkg.set_ccid(
24992     p_code_combination_id          => l_ccid
24993   , p_value_type_code              => l_adr_value_type_code
24994   , p_transaction_coa_id           => l_adr_transaction_coa_id
24995   , p_accounting_coa_id            => l_adr_accounting_coa_id
24996   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
24997   , p_adr_type_code                => 'S'
24998   , p_component_type               => l_component_type
24999   , p_component_code               => l_component_code
25000   , p_component_type_code          => l_component_type_code
25001   , p_component_appl_id            => l_component_appl_id
25002   , p_amb_context_code             => l_amb_context_code
25003   , p_side                         => 'NA'
25004   );
25005 
25006 
25007    l_segment := AcctDerRule_2(
25008            p_application_id           => p_application_id
25009          , p_ae_header_id             => l_ae_header_id 
25010 , p_source_1 => p_source_1
25011          , x_transaction_coa_id       => l_adr_transaction_coa_id
25012          , x_accounting_coa_id        => l_adr_accounting_coa_id
25013          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
25014          , x_flex_value_set_id        => l_adr_flex_value_set_id
25015          , x_value_type_code          => l_adr_value_type_code
25016          , x_value_combination_id     => l_adr_value_combination_id
25017          , x_value_segment_code       => l_adr_value_segment_code
25018          , p_side                     => 'NA'
25019          , p_override_seg_flag        => 'Y'
25020    );
25021 
25022    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
25023 
25024       xla_ae_lines_pkg.set_segment(
25025           p_to_segment_code         => 'GL_BALANCING'
25029         , p_value_type_code         => l_adr_value_type_code
25026         , p_segment_value           => l_segment
25027         , p_from_segment_code       => l_adr_value_segment_code
25028         , p_from_combination_id     => l_adr_value_combination_id
25030         , p_transaction_coa_id      => l_adr_transaction_coa_id
25031         , p_accounting_coa_id       => l_adr_accounting_coa_id
25032         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
25033         , p_flex_value_set_id       => l_adr_flex_value_set_id
25034         , p_adr_code                => 'MFAR_BNK_CHARGES_BALANCING_SEG'
25035         , p_adr_type_code           => 'S'
25036         , p_component_type          => l_component_type
25037         , p_component_code          => l_component_code
25038         , p_component_type_code     => l_component_type_code
25039         , p_component_appl_id       => l_component_appl_id
25040         , p_amb_context_code        => l_amb_context_code
25041         , p_entity_code             => 'RECEIPTS'
25042         , p_event_class_code        => 'MISC_RECEIPT'
25043         , p_side                    => 'NA'
25044         );
25045 
25046   END IF;
25047 
25048    --
25049    --
25050    END IF;
25051    --
25052    -- Bug 4922099
25053    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
25054           (NVL(l_enc_upg_option, 'N') = 'O')
25055         ) AND
25056         (l_bflow_method_code = 'PRIOR_ENTRY')
25057       )
25058    THEN
25059       IF
25060       --
25061       1 = 2
25062       --
25063       THEN
25064       xla_accounting_err_pkg.build_message
25065                                     (p_appli_s_name            => 'XLA'
25066                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
25067                                     ,p_token_1                 => 'LINE_NUMBER'
25068                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
25069                                     ,p_token_2                 => 'LINE_TYPE_NAME'
25070                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
25071                                                                              l_component_type
25072                                                                             ,l_component_code
25073                                                                             ,l_component_type_code
25074                                                                             ,l_component_appl_id
25075                                                                             ,l_amb_context_code
25076                                                                             ,l_entity_code
25077                                                                             ,l_event_class_code
25078                                                                            )
25079                                     ,p_token_3                 => 'OWNER'
25080                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
25081                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
25082                                                                           ,p_lookup_code    => l_component_type_code
25083                                                                          )
25084                                     ,p_token_4                 => 'PRODUCT_NAME'
25085                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
25086                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
25087                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
25088                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
25089                                     ,p_ae_header_id            =>  NULL
25090                                        );
25091 
25092         IF (C_LEVEL_ERROR>= g_log_level) THEN
25093                  trace
25094                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
25095                       ,p_level    => C_LEVEL_ERROR
25096                       ,p_module   => l_log_module);
25097         END IF;
25098       END IF;
25099    END IF;
25100    --
25101    --
25102    ------------------------------------------------------------------------------------------------
25103    -- 4219869 Business Flow
25104    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
25105    -- Prior Entry.  Currently, the following code is always generated.
25106    ------------------------------------------------------------------------------------------------
25107    XLA_AE_LINES_PKG.ValidateCurrentLine;
25108 
25109    ------------------------------------------------------------------------------------
25110    -- 4219869 Business Flow
25111    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
25112    ------------------------------------------------------------------------------------
25113    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
25114 
25115    ----------------------------------------------------------------------------------
25116    -- 4219869 Business Flow
25117    -- Update journal entry status -- Need to generate this within IF <condition>
25118    ----------------------------------------------------------------------------------
25119    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
25120          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
25121          ,p_balance_type_code => l_balance_type_code
25122          );
25123 
25124    -------------------------------------------------------------------------------------------
25125    -- 4262811 - Generate the Accrual Reversal lines
25129                               (g_array_event(p_event_id).array_value_num('header_index'));
25126    -------------------------------------------------------------------------------------------
25127    BEGIN
25128       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
25130       IF l_acc_rev_flag IS NULL THEN
25131          l_acc_rev_flag := 'N';
25132       END IF;
25133    EXCEPTION
25134       WHEN OTHERS THEN
25135          l_acc_rev_flag := 'N';
25136    END;
25137    --
25138    IF (l_acc_rev_flag = 'Y') THEN
25139 
25140        -- 4645092  ------------------------------------------------------------------------------
25141        -- To allow MPA report to determine if it should generate report process
25142        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
25143        ------------------------------------------------------------------------------------------
25144 
25145        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
25146        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
25147    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
25148    -- call ADRs
25149    -- Bug 4922099
25150    --
25151    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
25152         (NVL(l_actual_upg_option, 'N') = 'O') OR
25153         (NVL(l_enc_upg_option, 'N') = 'O')
25154       )
25155    THEN
25156    NULL;
25157    --
25158    --
25159    
25160   l_ccid := AcctDerRule_9(
25161            p_application_id           => p_application_id
25162          , p_ae_header_id             => l_ae_header_id 
25163 , p_source_6 => p_source_6
25164          , x_transaction_coa_id       => l_adr_transaction_coa_id
25165          , x_accounting_coa_id        => l_adr_accounting_coa_id
25166          , x_value_type_code          => l_adr_value_type_code
25167          , p_side                     => 'NA'
25168    );
25169 
25170    xla_ae_lines_pkg.set_ccid(
25171     p_code_combination_id          => l_ccid
25172   , p_value_type_code              => l_adr_value_type_code
25173   , p_transaction_coa_id           => l_adr_transaction_coa_id
25174   , p_accounting_coa_id            => l_adr_accounting_coa_id
25175   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
25176   , p_adr_type_code                => 'S'
25177   , p_component_type               => l_component_type
25178   , p_component_code               => l_component_code
25179   , p_component_type_code          => l_component_type_code
25180   , p_component_appl_id            => l_component_appl_id
25181   , p_amb_context_code             => l_amb_context_code
25182   , p_side                         => 'NA'
25183   );
25184 
25185 
25186    l_segment := AcctDerRule_2(
25187            p_application_id           => p_application_id
25188          , p_ae_header_id             => l_ae_header_id 
25189 , p_source_1 => p_source_1
25190          , x_transaction_coa_id       => l_adr_transaction_coa_id
25191          , x_accounting_coa_id        => l_adr_accounting_coa_id
25192          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
25193          , x_flex_value_set_id        => l_adr_flex_value_set_id
25194          , x_value_type_code          => l_adr_value_type_code
25195          , x_value_combination_id     => l_adr_value_combination_id
25196          , x_value_segment_code       => l_adr_value_segment_code
25197          , p_side                     => 'NA'
25198          , p_override_seg_flag        => 'Y'
25199    );
25200 
25201    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
25202 
25203       xla_ae_lines_pkg.set_segment(
25204           p_to_segment_code         => 'GL_BALANCING'
25205         , p_segment_value           => l_segment
25206         , p_from_segment_code       => l_adr_value_segment_code
25207         , p_from_combination_id     => l_adr_value_combination_id
25208         , p_value_type_code         => l_adr_value_type_code
25209         , p_transaction_coa_id      => l_adr_transaction_coa_id
25210         , p_accounting_coa_id       => l_adr_accounting_coa_id
25211         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
25212         , p_flex_value_set_id       => l_adr_flex_value_set_id
25213         , p_adr_code                => 'MFAR_BNK_CHARGES_BALANCING_SEG'
25214         , p_adr_type_code           => 'S'
25215         , p_component_type          => l_component_type
25216         , p_component_code          => l_component_code
25217         , p_component_type_code     => l_component_type_code
25218         , p_component_appl_id       => l_component_appl_id
25219         , p_amb_context_code        => l_amb_context_code
25220         , p_entity_code             => 'RECEIPTS'
25221         , p_event_class_code        => 'MISC_RECEIPT'
25222         , p_side                    => 'NA'
25223         );
25224 
25225   END IF;
25226 
25227    --
25228    --
25229    END IF;
25230 
25231        --
25232        -- Update the line information that should be overwritten
25233        --
25234        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
25235                                          p_header_num   => 1);
25236        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
25237 
25238        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
25239 
25240        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
25241           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
25242        END IF;
25243 
25244       --
25245       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
25246       --
25250           ---------------------------------------------------------------------------------------------------
25247       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
25248           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
25249       ELSE
25251           -- 4262811a Switch Sign
25252           ---------------------------------------------------------------------------------------------------
25253           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
25254           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
25255                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
25256           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
25257                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
25258           -- 5132302
25259           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
25260                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
25261 
25262       END IF;
25263 
25264       -- 4955764
25265       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
25266       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
25267 
25268 
25269       XLA_AE_LINES_PKG.ValidateCurrentLine;
25270       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
25271 
25272       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
25273                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
25274                ,p_balance_type_code => l_balance_type_code);
25275 
25276    END IF;
25277 
25278    -----------------------------------------------------------------------------------------
25279    -- 4262811 Multiperiod Accounting
25280    -----------------------------------------------------------------------------------------
25281      -- No MPA option is assigned.
25282 
25283 
25284 END IF;
25285 END IF;
25286 --
25287 
25288 --
25289 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
25290    trace
25291       (p_msg      => 'END of AcctLineType_56'
25292       ,p_level    => C_LEVEL_PROCEDURE
25293       ,p_module   => l_log_module);
25294 END IF;
25295 --
25296 EXCEPTION
25297   WHEN xla_exceptions_pkg.application_exception THEN
25298       RAISE;
25299   WHEN OTHERS THEN
25300        xla_exceptions_pkg.raise_message
25301            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_56');
25302 END AcctLineType_56;
25303 --
25304 
25305 ---------------------------------------
25306 --
25307 -- PRIVATE FUNCTION
25308 --         AcctLineType_57
25309 --
25310 ---------------------------------------
25311 PROCEDURE AcctLineType_57 (
25312   p_application_id        IN NUMBER
25313  ,p_event_id              IN NUMBER
25314  ,p_calculate_acctd_flag  IN VARCHAR2
25315  ,p_calculate_g_l_flag    IN VARCHAR2
25316  ,p_actual_flag           IN OUT VARCHAR2
25317  ,p_balance_type_code     OUT VARCHAR2
25318  ,p_gain_or_loss_ref      OUT VARCHAR2
25319  
25320 --Distribution GL Account
25321  , p_source_3            IN NUMBER
25322 --Remittance Bank Account Cash Account
25323  , p_source_6            IN NUMBER
25324 --Distribution Source Type
25325  , p_source_13            IN VARCHAR2
25326 --Distribution Line Identifier
25327  , p_source_15            IN NUMBER
25328 --Distribution Type
25329  , p_source_16            IN VARCHAR2
25330 --Entered Amount
25331  , p_source_17            IN NUMBER
25332 --Currency Code
25333  , p_source_18            IN VARCHAR2
25334 --Exchange Rate
25335  , p_source_20            IN NUMBER
25336 --Exchange Rate Type
25337  , p_source_21            IN VARCHAR2
25338 --Applied To Document Accounting Amount
25339  , p_source_22            IN NUMBER
25340 --Distribution Multi Fund Additional Entry
25341  , p_source_52            IN VARCHAR2
25342 --Applied To Document Exchange Date
25343  , p_source_53            IN DATE
25344 --Receipt Class Require Remittance Flag
25345  , p_source_54            IN VARCHAR2
25346 --Receipt Class Confirm Flag
25347  , p_source_55            IN VARCHAR2
25348 )
25349 IS
25350 
25351 l_component_type              VARCHAR2(80);
25352 l_component_code              VARCHAR2(30);
25353 l_component_type_code         VARCHAR2(1);
25354 l_component_appl_id           INTEGER;
25355 l_amb_context_code            VARCHAR2(30);
25356 l_entity_code                 VARCHAR2(30);
25357 l_event_class_code            VARCHAR2(30);
25358 l_ae_header_id                NUMBER;
25359 l_event_type_code             VARCHAR2(30);
25360 l_line_definition_code        VARCHAR2(30);
25361 l_line_definition_owner_code  VARCHAR2(1);
25362 --
25363 -- adr variables
25364 l_segment                     VARCHAR2(30);
25365 l_ccid                        NUMBER;
25366 l_adr_transaction_coa_id      NUMBER;
25367 l_adr_accounting_coa_id       NUMBER;
25368 l_adr_flexfield_segment_code  VARCHAR2(30);
25369 l_adr_flex_value_set_id       NUMBER;
25370 l_adr_value_type_code         VARCHAR2(30);
25371 l_adr_value_combination_id    NUMBER;
25372 l_adr_value_segment_code      VARCHAR2(30);
25373 
25374 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
25375 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
25376 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
25377 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
25378 
25379 -- 4262811 Variables ------------------------------------------------------------------------------------------
25380 l_entered_amt_idx             NUMBER;
25381 l_accted_amt_idx              NUMBER;
25382 l_acc_rev_flag                VARCHAR2(1);
25383 l_accrual_line_num            NUMBER;
25384 l_tmp_amt                     NUMBER;
25385 l_acc_rev_natural_side_code   VARCHAR2(1);
25386 
25387 l_num_entries                 NUMBER;
25388 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
25389 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
25390 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
25391 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
25392 l_recog_line_1                NUMBER;
25393 l_recog_line_2                NUMBER;
25394 
25395 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
25396 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
25397 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
25398 
25399 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
25400 
25401 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
25402 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
25403 
25404 ---------------------------------------------------------------------------------------------------------------
25405 
25406 
25407 --
25408 -- bulk performance
25409 --
25410 l_balance_type_code           VARCHAR2(1);
25411 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
25412 l_log_module                  VARCHAR2(240);
25413 
25414 --
25415 -- Upgrade strategy
25416 --
25417 l_actual_upg_option           VARCHAR2(1);
25418 l_enc_upg_option           VARCHAR2(1);
25419 
25420 --
25421 BEGIN
25422 --
25423 IF g_log_enabled THEN
25424       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_57';
25425 END IF;
25426 --
25427 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
25428 
25429       trace
25430          (p_msg      => 'BEGIN of AcctLineType_57'
25431          ,p_level    => C_LEVEL_PROCEDURE
25432          ,p_module   => l_log_module);
25433 
25434 END IF;
25435 --
25436 l_component_type             := 'AMB_JLT';
25437 l_component_code             := 'MFAR_MISC_RCT_CASH';
25438 l_component_type_code        := 'S';
25439 l_component_appl_id          :=  222;
25440 l_amb_context_code           := 'DEFAULT';
25441 l_entity_code                := 'RECEIPTS';
25442 l_event_class_code           := 'MISC_RECEIPT';
25443 l_event_type_code            := 'MISC_RECEIPT_ALL';
25444 l_line_definition_owner_code := 'S';
25445 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
25446 --
25447 l_balance_type_code          := 'A';
25448 l_segment                     := NULL;
25449 l_ccid                        := NULL;
25450 l_adr_transaction_coa_id      := NULL;
25451 l_adr_accounting_coa_id       := NULL;
25452 l_adr_flexfield_segment_code  := NULL;
25453 l_adr_flex_value_set_id       := NULL;
25454 l_adr_value_type_code         := NULL;
25455 l_adr_value_combination_id    := NULL;
25456 l_adr_value_segment_code      := NULL;
25457 
25458 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
25459 l_bflow_class_code           := '';    -- 4219869 Business Flow
25460 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
25461 l_budgetary_control_flag     := 'N';
25462 
25463 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
25464 l_bflow_applied_to_amt       := NULL; -- 5132302
25465 l_entered_amt_idx            := NULL;          -- 4262811
25466 l_accted_amt_idx             := NULL;          -- 4262811
25467 l_acc_rev_flag               := NULL;          -- 4262811
25468 l_accrual_line_num           := NULL;          -- 4262811
25469 l_tmp_amt                    := NULL;          -- 4262811
25470 --
25471  
25472 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
25473     l_balance_type_code <> 'B' THEN
25474 IF (NVL(p_source_13,'
25475 ') =  'CASH' OR 
25476 NVL(p_source_13,'
25477 ') =  'TAX') AND 
25478 NVL(p_source_52,'
25479 ') =  'N' AND 
25480 NVL(p_source_54,'
25481 ') =  'N' AND 
25482 NVL(p_source_55,'
25483 ') =  'N'
25484  THEN 
25485 
25486    --
25487    XLA_AE_LINES_PKG.SetNewLine;
25488 
25489    p_balance_type_code          := l_balance_type_code;
25490    -- set the flag so later we will know whether the gain loss line needs to be created
25491    
25492    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
25493      p_actual_flag :='A';
25494    END IF;
25495 
25496    --
25497    -- bulk performance
25498    --
25499    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
25500                                       p_header_num   => 0); -- 4262811
25501    --
25502    -- set accounting line options
25503    --
25504    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
25505            p_natural_side_code          => 'C'
25506          , p_gain_or_loss_flag          => 'N'
25507          , p_gl_transfer_mode_code      => 'S'
25508          , p_acct_entry_type_code       => 'A'
25509          , p_switch_side_flag           => 'Y'
25510          , p_merge_duplicate_code       => 'A'
25511          );
25512    --
25513    l_acc_rev_natural_side_code := 'D';  -- 4262811
25514    -- 
25515    --
25516    -- set accounting line type info
25517    --
25518    xla_ae_lines_pkg.SetAcctLineType
25519       (p_component_type             => l_component_type
25520       ,p_event_type_code            => l_event_type_code
25521       ,p_line_definition_owner_code => l_line_definition_owner_code
25522       ,p_line_definition_code       => l_line_definition_code
25523       ,p_accounting_line_code       => l_component_code
25524       ,p_accounting_line_type_code  => l_component_type_code
25525       ,p_accounting_line_appl_id    => l_component_appl_id
25526       ,p_amb_context_code           => l_amb_context_code
25527       ,p_entity_code                => l_entity_code
25528       ,p_event_class_code           => l_event_class_code);
25529    --
25530    -- set accounting class
25531    --
25532    xla_ae_lines_pkg.SetAcctClass(
25533            p_accounting_class_code  => 'CASH'
25534          , p_ae_header_id           => l_ae_header_id
25535          );
25536 
25537    --
25538    -- set rounding class
25539    --
25540    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
25541                       'RECEIVABLE';
25542 
25543    --
25544    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
25545    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
25546    --
25547    -- bulk performance
25548    --
25549    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
25550 
25551    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
25552       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
25553 
25554    -- 4955764
25555    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
25556       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
25557 
25558    -- 4458381 Public Sector Enh
25559    
25560    --
25561    -- set accounting attributes for the line type
25565    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
25562    --
25563    l_entered_amt_idx := 3;
25564    l_accted_amt_idx  := 8;
25566    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
25567    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
25568    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
25569    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
25570    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
25571    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
25572    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
25573    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
25574    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
25575    l_rec_acct_attrs.array_date_value(5)  := p_source_53;
25576    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
25577    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
25578    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
25579    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
25580    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
25581    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
25582 
25583    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
25584    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
25585 
25586    ---------------------------------------------------------------------------------------------------------------
25587    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
25588    ---------------------------------------------------------------------------------------------------------------
25589    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
25590 
25591    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
25592    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
25593 
25594    IF xla_accounting_cache_pkg.GetValueChar
25595          (p_source_code         => 'LEDGER_CATEGORY_CODE'
25596          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
25597    AND l_bflow_method_code = 'PRIOR_ENTRY'
25598 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
25599    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
25600          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
25601        )
25602    THEN
25603          xla_ae_lines_pkg.BflowUpgEntry
25604            (p_business_method_code    => l_bflow_method_code
25605            ,p_business_class_code     => l_bflow_class_code
25606            ,p_balance_type            => l_balance_type_code);
25607    ELSE
25608       NULL;
25609 -- No business flow processing for business flow method of NONE.
25610    END IF;
25611 
25612    --
25613    -- call analytical criteria
25614    --
25615    
25616    --
25617    -- call description
25618    --
25619    
25620 xla_ae_lines_pkg.SetLineDescription(
25621    p_ae_header_id => l_ae_header_id
25622   ,p_description  => Description_1 (
25623      p_application_id         => p_application_id
25624    , p_ae_header_id           => l_ae_header_id 
25625    )
25626 );
25627 
25628 
25629    --
25630    -- call ADRs
25631    -- Bug 4922099
25632    --
25633    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
25634         (NVL(l_actual_upg_option, 'N') = 'O') OR
25635         (NVL(l_enc_upg_option, 'N') = 'O')
25636       )
25637    THEN
25638    NULL;
25639    --
25640    --
25641    
25642   l_ccid := AcctDerRule_9(
25643            p_application_id           => p_application_id
25644          , p_ae_header_id             => l_ae_header_id 
25645 , p_source_6 => p_source_6
25646          , x_transaction_coa_id       => l_adr_transaction_coa_id
25647          , x_accounting_coa_id        => l_adr_accounting_coa_id
25648          , x_value_type_code          => l_adr_value_type_code
25649          , p_side                     => 'NA'
25650    );
25651 
25652    xla_ae_lines_pkg.set_ccid(
25653     p_code_combination_id          => l_ccid
25654   , p_value_type_code              => l_adr_value_type_code
25655   , p_transaction_coa_id           => l_adr_transaction_coa_id
25656   , p_accounting_coa_id            => l_adr_accounting_coa_id
25657   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
25658   , p_adr_type_code                => 'S'
25659   , p_component_type               => l_component_type
25660   , p_component_code               => l_component_code
25661   , p_component_type_code          => l_component_type_code
25662   , p_component_appl_id            => l_component_appl_id
25663   , p_amb_context_code             => l_amb_context_code
25664   , p_side                         => 'NA'
25665   );
25666 
25667 
25668    l_segment := AcctDerRule_4(
25669            p_application_id           => p_application_id
25670          , p_ae_header_id             => l_ae_header_id 
25671 , p_source_3 => p_source_3
25672          , x_transaction_coa_id       => l_adr_transaction_coa_id
25673          , x_accounting_coa_id        => l_adr_accounting_coa_id
25674          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
25675          , x_flex_value_set_id        => l_adr_flex_value_set_id
25676          , x_value_type_code          => l_adr_value_type_code
25677          , x_value_combination_id     => l_adr_value_combination_id
25678          , x_value_segment_code       => l_adr_value_segment_code
25679          , p_side                     => 'NA'
25680          , p_override_seg_flag        => 'Y'
25681    );
25682 
25683    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
25687         , p_segment_value           => l_segment
25684 
25685       xla_ae_lines_pkg.set_segment(
25686           p_to_segment_code         => 'GL_BALANCING'
25688         , p_from_segment_code       => l_adr_value_segment_code
25689         , p_from_combination_id     => l_adr_value_combination_id
25690         , p_value_type_code         => l_adr_value_type_code
25691         , p_transaction_coa_id      => l_adr_transaction_coa_id
25692         , p_accounting_coa_id       => l_adr_accounting_coa_id
25693         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
25694         , p_flex_value_set_id       => l_adr_flex_value_set_id
25695         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
25696         , p_adr_type_code           => 'S'
25697         , p_component_type          => l_component_type
25698         , p_component_code          => l_component_code
25699         , p_component_type_code     => l_component_type_code
25700         , p_component_appl_id       => l_component_appl_id
25701         , p_amb_context_code        => l_amb_context_code
25702         , p_entity_code             => 'RECEIPTS'
25703         , p_event_class_code        => 'MISC_RECEIPT'
25704         , p_side                    => 'NA'
25705         );
25706 
25707   END IF;
25708 
25709    --
25710    --
25711    END IF;
25712    --
25713    -- Bug 4922099
25714    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
25715           (NVL(l_enc_upg_option, 'N') = 'O')
25716         ) AND
25717         (l_bflow_method_code = 'PRIOR_ENTRY')
25718       )
25719    THEN
25720       IF
25721       --
25722       1 = 2
25723       --
25724       THEN
25725       xla_accounting_err_pkg.build_message
25726                                     (p_appli_s_name            => 'XLA'
25727                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
25728                                     ,p_token_1                 => 'LINE_NUMBER'
25729                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
25730                                     ,p_token_2                 => 'LINE_TYPE_NAME'
25731                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
25732                                                                              l_component_type
25733                                                                             ,l_component_code
25734                                                                             ,l_component_type_code
25735                                                                             ,l_component_appl_id
25736                                                                             ,l_amb_context_code
25737                                                                             ,l_entity_code
25738                                                                             ,l_event_class_code
25739                                                                            )
25740                                     ,p_token_3                 => 'OWNER'
25741                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
25742                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
25743                                                                           ,p_lookup_code    => l_component_type_code
25744                                                                          )
25745                                     ,p_token_4                 => 'PRODUCT_NAME'
25746                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
25747                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
25748                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
25749                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
25750                                     ,p_ae_header_id            =>  NULL
25751                                        );
25752 
25753         IF (C_LEVEL_ERROR>= g_log_level) THEN
25754                  trace
25755                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
25756                       ,p_level    => C_LEVEL_ERROR
25757                       ,p_module   => l_log_module);
25758         END IF;
25759       END IF;
25760    END IF;
25761    --
25762    --
25763    ------------------------------------------------------------------------------------------------
25764    -- 4219869 Business Flow
25765    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
25766    -- Prior Entry.  Currently, the following code is always generated.
25767    ------------------------------------------------------------------------------------------------
25768    XLA_AE_LINES_PKG.ValidateCurrentLine;
25769 
25770    ------------------------------------------------------------------------------------
25771    -- 4219869 Business Flow
25772    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
25773    ------------------------------------------------------------------------------------
25774    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
25775 
25776    ----------------------------------------------------------------------------------
25777    -- 4219869 Business Flow
25778    -- Update journal entry status -- Need to generate this within IF <condition>
25779    ----------------------------------------------------------------------------------
25780    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
25781          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
25782          ,p_balance_type_code => l_balance_type_code
25783          );
25784 
25785    -------------------------------------------------------------------------------------------
25786    -- 4262811 - Generate the Accrual Reversal lines
25787    -------------------------------------------------------------------------------------------
25788    BEGIN
25789       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
25790                               (g_array_event(p_event_id).array_value_num('header_index'));
25791       IF l_acc_rev_flag IS NULL THEN
25792          l_acc_rev_flag := 'N';
25793       END IF;
25794    EXCEPTION
25795       WHEN OTHERS THEN
25796          l_acc_rev_flag := 'N';
25797    END;
25798    --
25799    IF (l_acc_rev_flag = 'Y') THEN
25800 
25801        -- 4645092  ------------------------------------------------------------------------------
25802        -- To allow MPA report to determine if it should generate report process
25803        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
25804        ------------------------------------------------------------------------------------------
25808    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
25805 
25806        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
25807        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
25809    -- call ADRs
25810    -- Bug 4922099
25811    --
25812    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
25813         (NVL(l_actual_upg_option, 'N') = 'O') OR
25814         (NVL(l_enc_upg_option, 'N') = 'O')
25815       )
25816    THEN
25817    NULL;
25818    --
25819    --
25820    
25821   l_ccid := AcctDerRule_9(
25822            p_application_id           => p_application_id
25823          , p_ae_header_id             => l_ae_header_id 
25824 , p_source_6 => p_source_6
25825          , x_transaction_coa_id       => l_adr_transaction_coa_id
25826          , x_accounting_coa_id        => l_adr_accounting_coa_id
25827          , x_value_type_code          => l_adr_value_type_code
25828          , p_side                     => 'NA'
25829    );
25830 
25831    xla_ae_lines_pkg.set_ccid(
25832     p_code_combination_id          => l_ccid
25833   , p_value_type_code              => l_adr_value_type_code
25834   , p_transaction_coa_id           => l_adr_transaction_coa_id
25835   , p_accounting_coa_id            => l_adr_accounting_coa_id
25836   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
25837   , p_adr_type_code                => 'S'
25838   , p_component_type               => l_component_type
25839   , p_component_code               => l_component_code
25840   , p_component_type_code          => l_component_type_code
25841   , p_component_appl_id            => l_component_appl_id
25842   , p_amb_context_code             => l_amb_context_code
25843   , p_side                         => 'NA'
25844   );
25845 
25846 
25847    l_segment := AcctDerRule_4(
25848            p_application_id           => p_application_id
25849          , p_ae_header_id             => l_ae_header_id 
25850 , p_source_3 => p_source_3
25851          , x_transaction_coa_id       => l_adr_transaction_coa_id
25852          , x_accounting_coa_id        => l_adr_accounting_coa_id
25853          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
25854          , x_flex_value_set_id        => l_adr_flex_value_set_id
25855          , x_value_type_code          => l_adr_value_type_code
25856          , x_value_combination_id     => l_adr_value_combination_id
25857          , x_value_segment_code       => l_adr_value_segment_code
25858          , p_side                     => 'NA'
25859          , p_override_seg_flag        => 'Y'
25860    );
25861 
25862    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
25863 
25864       xla_ae_lines_pkg.set_segment(
25865           p_to_segment_code         => 'GL_BALANCING'
25866         , p_segment_value           => l_segment
25867         , p_from_segment_code       => l_adr_value_segment_code
25868         , p_from_combination_id     => l_adr_value_combination_id
25869         , p_value_type_code         => l_adr_value_type_code
25870         , p_transaction_coa_id      => l_adr_transaction_coa_id
25871         , p_accounting_coa_id       => l_adr_accounting_coa_id
25872         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
25873         , p_flex_value_set_id       => l_adr_flex_value_set_id
25874         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
25875         , p_adr_type_code           => 'S'
25876         , p_component_type          => l_component_type
25877         , p_component_code          => l_component_code
25878         , p_component_type_code     => l_component_type_code
25879         , p_component_appl_id       => l_component_appl_id
25880         , p_amb_context_code        => l_amb_context_code
25881         , p_entity_code             => 'RECEIPTS'
25882         , p_event_class_code        => 'MISC_RECEIPT'
25883         , p_side                    => 'NA'
25884         );
25885 
25886   END IF;
25887 
25888    --
25889    --
25890    END IF;
25891 
25892        --
25893        -- Update the line information that should be overwritten
25894        --
25895        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
25896                                          p_header_num   => 1);
25897        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
25898 
25899        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
25900 
25901        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
25902           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
25903        END IF;
25904 
25905       --
25906       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
25907       --
25908       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
25909           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
25910       ELSE
25911           ---------------------------------------------------------------------------------------------------
25912           -- 4262811a Switch Sign
25913           ---------------------------------------------------------------------------------------------------
25914           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
25915           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
25919           -- 5132302
25916                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
25917           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
25918                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
25920           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
25921                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
25922 
25923       END IF;
25924 
25925       -- 4955764
25926       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
25927       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
25928 
25929 
25930       XLA_AE_LINES_PKG.ValidateCurrentLine;
25931       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
25932 
25933       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
25934                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
25935                ,p_balance_type_code => l_balance_type_code);
25936 
25937    END IF;
25938 
25939    -----------------------------------------------------------------------------------------
25940    -- 4262811 Multiperiod Accounting
25941    -----------------------------------------------------------------------------------------
25942      -- No MPA option is assigned.
25943 
25944 
25945 END IF;
25946 END IF;
25947 --
25948 
25949 --
25950 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
25951    trace
25952       (p_msg      => 'END of AcctLineType_57'
25953       ,p_level    => C_LEVEL_PROCEDURE
25954       ,p_module   => l_log_module);
25955 END IF;
25956 --
25957 EXCEPTION
25958   WHEN xla_exceptions_pkg.application_exception THEN
25959       RAISE;
25960   WHEN OTHERS THEN
25961        xla_exceptions_pkg.raise_message
25962            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_57');
25963 END AcctLineType_57;
25964 --
25965 
25966 ---------------------------------------
25967 --
25968 -- PRIVATE FUNCTION
25969 --         AcctLineType_58
25970 --
25971 ---------------------------------------
25972 PROCEDURE AcctLineType_58 (
25973   p_application_id        IN NUMBER
25974  ,p_event_id              IN NUMBER
25975  ,p_calculate_acctd_flag  IN VARCHAR2
25976  ,p_calculate_g_l_flag    IN VARCHAR2
25977  ,p_actual_flag           IN OUT VARCHAR2
25978  ,p_balance_type_code     OUT VARCHAR2
25979  ,p_gain_or_loss_ref      OUT VARCHAR2
25980  
25981 --Distribution GL Account
25982  , p_source_3            IN NUMBER
25983 --Remittance Bank Account Cash Account
25984  , p_source_6            IN NUMBER
25985 --Distribution Source Type
25986  , p_source_13            IN VARCHAR2
25987 --Distribution Line Identifier
25988  , p_source_15            IN NUMBER
25989 --Distribution Type
25990  , p_source_16            IN VARCHAR2
25991 --Entered Amount
25992  , p_source_17            IN NUMBER
25993 --Currency Code
25994  , p_source_18            IN VARCHAR2
25995 --Exchange Rate
25996  , p_source_20            IN NUMBER
25997 --Exchange Rate Type
25998  , p_source_21            IN VARCHAR2
25999 --Applied To Document Accounting Amount
26000  , p_source_22            IN NUMBER
26001 --Distribution Multi Fund Additional Entry
26002  , p_source_52            IN VARCHAR2
26003 --Applied To Document Exchange Date
26004  , p_source_53            IN DATE
26005 --Receipt Class Require Remittance Flag
26006  , p_source_54            IN VARCHAR2
26007 )
26008 IS
26009 
26010 l_component_type              VARCHAR2(80);
26011 l_component_code              VARCHAR2(30);
26012 l_component_type_code         VARCHAR2(1);
26013 l_component_appl_id           INTEGER;
26014 l_amb_context_code            VARCHAR2(30);
26015 l_entity_code                 VARCHAR2(30);
26016 l_event_class_code            VARCHAR2(30);
26017 l_ae_header_id                NUMBER;
26018 l_event_type_code             VARCHAR2(30);
26019 l_line_definition_code        VARCHAR2(30);
26020 l_line_definition_owner_code  VARCHAR2(1);
26021 --
26022 -- adr variables
26023 l_segment                     VARCHAR2(30);
26024 l_ccid                        NUMBER;
26025 l_adr_transaction_coa_id      NUMBER;
26026 l_adr_accounting_coa_id       NUMBER;
26027 l_adr_flexfield_segment_code  VARCHAR2(30);
26028 l_adr_flex_value_set_id       NUMBER;
26029 l_adr_value_type_code         VARCHAR2(30);
26030 l_adr_value_combination_id    NUMBER;
26031 l_adr_value_segment_code      VARCHAR2(30);
26032 
26033 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
26034 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
26035 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
26036 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
26037 
26038 -- 4262811 Variables ------------------------------------------------------------------------------------------
26039 l_entered_amt_idx             NUMBER;
26040 l_accted_amt_idx              NUMBER;
26041 l_acc_rev_flag                VARCHAR2(1);
26042 l_accrual_line_num            NUMBER;
26043 l_tmp_amt                     NUMBER;
26044 l_acc_rev_natural_side_code   VARCHAR2(1);
26045 
26046 l_num_entries                 NUMBER;
26047 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
26048 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
26049 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
26050 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
26051 l_recog_line_1                NUMBER;
26055 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
26052 l_recog_line_2                NUMBER;
26053 
26054 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
26056 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
26057 
26058 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
26059 
26060 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
26061 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
26062 
26063 ---------------------------------------------------------------------------------------------------------------
26064 
26065 
26066 --
26067 -- bulk performance
26068 --
26069 l_balance_type_code           VARCHAR2(1);
26070 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
26071 l_log_module                  VARCHAR2(240);
26072 
26073 --
26074 -- Upgrade strategy
26075 --
26076 l_actual_upg_option           VARCHAR2(1);
26077 l_enc_upg_option           VARCHAR2(1);
26078 
26079 --
26080 BEGIN
26081 --
26082 IF g_log_enabled THEN
26083       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_58';
26084 END IF;
26085 --
26086 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
26087 
26088       trace
26089          (p_msg      => 'BEGIN of AcctLineType_58'
26090          ,p_level    => C_LEVEL_PROCEDURE
26091          ,p_module   => l_log_module);
26092 
26093 END IF;
26094 --
26095 l_component_type             := 'AMB_JLT';
26096 l_component_code             := 'MFAR_MISC_RCT_CM_CASH';
26097 l_component_type_code        := 'S';
26098 l_component_appl_id          :=  222;
26099 l_amb_context_code           := 'DEFAULT';
26100 l_entity_code                := 'RECEIPTS';
26101 l_event_class_code           := 'MISC_RECEIPT';
26102 l_event_type_code            := 'MISC_RECEIPT_ALL';
26103 l_line_definition_owner_code := 'S';
26104 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
26105 --
26106 l_balance_type_code          := 'A';
26107 l_segment                     := NULL;
26108 l_ccid                        := NULL;
26109 l_adr_transaction_coa_id      := NULL;
26110 l_adr_accounting_coa_id       := NULL;
26111 l_adr_flexfield_segment_code  := NULL;
26112 l_adr_flex_value_set_id       := NULL;
26113 l_adr_value_type_code         := NULL;
26114 l_adr_value_combination_id    := NULL;
26115 l_adr_value_segment_code      := NULL;
26116 
26117 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
26118 l_bflow_class_code           := '';    -- 4219869 Business Flow
26119 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
26120 l_budgetary_control_flag     := 'N';
26121 
26122 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
26123 l_bflow_applied_to_amt       := NULL; -- 5132302
26124 l_entered_amt_idx            := NULL;          -- 4262811
26125 l_accted_amt_idx             := NULL;          -- 4262811
26126 l_acc_rev_flag               := NULL;          -- 4262811
26127 l_accrual_line_num           := NULL;          -- 4262811
26128 l_tmp_amt                    := NULL;          -- 4262811
26129 --
26130  
26131 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
26132     l_balance_type_code <> 'B' THEN
26133 IF NVL(p_source_13,'
26134 ') =  'MISCCASH' AND 
26135 NVL(p_source_52,'
26136 ') =  'Y' AND 
26137 NVL(p_source_54,'
26138 ') =  'Y'
26139  THEN 
26140 
26141    --
26142    XLA_AE_LINES_PKG.SetNewLine;
26143 
26144    p_balance_type_code          := l_balance_type_code;
26145    -- set the flag so later we will know whether the gain loss line needs to be created
26146    
26147    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
26148      p_actual_flag :='A';
26149    END IF;
26150 
26151    --
26152    -- bulk performance
26153    --
26154    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
26155                                       p_header_num   => 0); -- 4262811
26156    --
26157    -- set accounting line options
26158    --
26159    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
26160            p_natural_side_code          => 'C'
26161          , p_gain_or_loss_flag          => 'N'
26162          , p_gl_transfer_mode_code      => 'S'
26163          , p_acct_entry_type_code       => 'A'
26164          , p_switch_side_flag           => 'Y'
26165          , p_merge_duplicate_code       => 'A'
26166          );
26167    --
26168    l_acc_rev_natural_side_code := 'D';  -- 4262811
26169    -- 
26170    --
26171    -- set accounting line type info
26172    --
26173    xla_ae_lines_pkg.SetAcctLineType
26174       (p_component_type             => l_component_type
26175       ,p_event_type_code            => l_event_type_code
26176       ,p_line_definition_owner_code => l_line_definition_owner_code
26177       ,p_line_definition_code       => l_line_definition_code
26178       ,p_accounting_line_code       => l_component_code
26179       ,p_accounting_line_type_code  => l_component_type_code
26180       ,p_accounting_line_appl_id    => l_component_appl_id
26181       ,p_amb_context_code           => l_amb_context_code
26182       ,p_entity_code                => l_entity_code
26183       ,p_event_class_code           => l_event_class_code);
26184    --
26185    -- set accounting class
26186    --
26187    xla_ae_lines_pkg.SetAcctClass(
26188            p_accounting_class_code  => 'CASH'
26189          , p_ae_header_id           => l_ae_header_id
26190          );
26191 
26192    --
26193    -- set rounding class
26194    --
26198    --
26195    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
26196                       'RECEIVABLE';
26197 
26199    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
26200    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
26201    --
26202    -- bulk performance
26203    --
26204    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
26205 
26206    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
26207       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
26208 
26209    -- 4955764
26210    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
26211       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
26212 
26213    -- 4458381 Public Sector Enh
26214    
26215    --
26216    -- set accounting attributes for the line type
26217    --
26218    l_entered_amt_idx := 3;
26219    l_accted_amt_idx  := 8;
26220    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
26221    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
26222    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
26223    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
26224    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
26225    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
26226    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
26227    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
26228    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
26229    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
26230    l_rec_acct_attrs.array_date_value(5)  := p_source_53;
26231    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
26232    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
26233    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
26234    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
26235    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
26236    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
26237 
26238    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
26239    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
26240 
26241    ---------------------------------------------------------------------------------------------------------------
26242    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
26243    ---------------------------------------------------------------------------------------------------------------
26244    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
26245 
26246    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
26247    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
26248 
26249    IF xla_accounting_cache_pkg.GetValueChar
26250          (p_source_code         => 'LEDGER_CATEGORY_CODE'
26251          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
26252    AND l_bflow_method_code = 'PRIOR_ENTRY'
26253 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
26254    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
26255          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
26256        )
26257    THEN
26258          xla_ae_lines_pkg.BflowUpgEntry
26259            (p_business_method_code    => l_bflow_method_code
26260            ,p_business_class_code     => l_bflow_class_code
26261            ,p_balance_type            => l_balance_type_code);
26262    ELSE
26263       NULL;
26264 -- No business flow processing for business flow method of NONE.
26265    END IF;
26266 
26267    --
26268    -- call analytical criteria
26269    --
26270    
26271    --
26272    -- call description
26273    --
26274    
26275 xla_ae_lines_pkg.SetLineDescription(
26276    p_ae_header_id => l_ae_header_id
26277   ,p_description  => Description_1 (
26278      p_application_id         => p_application_id
26279    , p_ae_header_id           => l_ae_header_id 
26280    )
26281 );
26282 
26283 
26284    --
26285    -- call ADRs
26286    -- Bug 4922099
26287    --
26288    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
26289         (NVL(l_actual_upg_option, 'N') = 'O') OR
26290         (NVL(l_enc_upg_option, 'N') = 'O')
26291       )
26292    THEN
26293    NULL;
26294    --
26295    --
26296    
26297   l_ccid := AcctDerRule_9(
26298            p_application_id           => p_application_id
26299          , p_ae_header_id             => l_ae_header_id 
26300 , p_source_6 => p_source_6
26301          , x_transaction_coa_id       => l_adr_transaction_coa_id
26302          , x_accounting_coa_id        => l_adr_accounting_coa_id
26303          , x_value_type_code          => l_adr_value_type_code
26304          , p_side                     => 'NA'
26305    );
26306 
26307    xla_ae_lines_pkg.set_ccid(
26308     p_code_combination_id          => l_ccid
26309   , p_value_type_code              => l_adr_value_type_code
26310   , p_transaction_coa_id           => l_adr_transaction_coa_id
26311   , p_accounting_coa_id            => l_adr_accounting_coa_id
26312   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
26313   , p_adr_type_code                => 'S'
26314   , p_component_type               => l_component_type
26315   , p_component_code               => l_component_code
26316   , p_component_type_code          => l_component_type_code
26320   );
26317   , p_component_appl_id            => l_component_appl_id
26318   , p_amb_context_code             => l_amb_context_code
26319   , p_side                         => 'NA'
26321 
26322 
26323    l_segment := AcctDerRule_4(
26324            p_application_id           => p_application_id
26325          , p_ae_header_id             => l_ae_header_id 
26326 , p_source_3 => p_source_3
26327          , x_transaction_coa_id       => l_adr_transaction_coa_id
26328          , x_accounting_coa_id        => l_adr_accounting_coa_id
26329          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
26330          , x_flex_value_set_id        => l_adr_flex_value_set_id
26331          , x_value_type_code          => l_adr_value_type_code
26332          , x_value_combination_id     => l_adr_value_combination_id
26333          , x_value_segment_code       => l_adr_value_segment_code
26334          , p_side                     => 'NA'
26335          , p_override_seg_flag        => 'Y'
26336    );
26337 
26338    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
26339 
26340       xla_ae_lines_pkg.set_segment(
26341           p_to_segment_code         => 'GL_BALANCING'
26342         , p_segment_value           => l_segment
26343         , p_from_segment_code       => l_adr_value_segment_code
26344         , p_from_combination_id     => l_adr_value_combination_id
26345         , p_value_type_code         => l_adr_value_type_code
26346         , p_transaction_coa_id      => l_adr_transaction_coa_id
26347         , p_accounting_coa_id       => l_adr_accounting_coa_id
26348         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
26349         , p_flex_value_set_id       => l_adr_flex_value_set_id
26350         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
26351         , p_adr_type_code           => 'S'
26352         , p_component_type          => l_component_type
26353         , p_component_code          => l_component_code
26354         , p_component_type_code     => l_component_type_code
26355         , p_component_appl_id       => l_component_appl_id
26356         , p_amb_context_code        => l_amb_context_code
26357         , p_entity_code             => 'RECEIPTS'
26358         , p_event_class_code        => 'MISC_RECEIPT'
26359         , p_side                    => 'NA'
26360         );
26361 
26362   END IF;
26363 
26364    --
26365    --
26366    END IF;
26367    --
26368    -- Bug 4922099
26369    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
26370           (NVL(l_enc_upg_option, 'N') = 'O')
26371         ) AND
26372         (l_bflow_method_code = 'PRIOR_ENTRY')
26373       )
26374    THEN
26375       IF
26376       --
26377       1 = 2
26378       --
26379       THEN
26380       xla_accounting_err_pkg.build_message
26381                                     (p_appli_s_name            => 'XLA'
26382                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
26383                                     ,p_token_1                 => 'LINE_NUMBER'
26384                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
26385                                     ,p_token_2                 => 'LINE_TYPE_NAME'
26386                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
26387                                                                              l_component_type
26388                                                                             ,l_component_code
26389                                                                             ,l_component_type_code
26390                                                                             ,l_component_appl_id
26391                                                                             ,l_amb_context_code
26392                                                                             ,l_entity_code
26393                                                                             ,l_event_class_code
26394                                                                            )
26395                                     ,p_token_3                 => 'OWNER'
26396                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
26397                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
26398                                                                           ,p_lookup_code    => l_component_type_code
26399                                                                          )
26400                                     ,p_token_4                 => 'PRODUCT_NAME'
26401                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
26402                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
26403                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
26404                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
26405                                     ,p_ae_header_id            =>  NULL
26406                                        );
26407 
26408         IF (C_LEVEL_ERROR>= g_log_level) THEN
26409                  trace
26410                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
26411                       ,p_level    => C_LEVEL_ERROR
26412                       ,p_module   => l_log_module);
26413         END IF;
26414       END IF;
26415    END IF;
26416    --
26417    --
26418    ------------------------------------------------------------------------------------------------
26419    -- 4219869 Business Flow
26420    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
26421    -- Prior Entry.  Currently, the following code is always generated.
26425    ------------------------------------------------------------------------------------
26422    ------------------------------------------------------------------------------------------------
26423    XLA_AE_LINES_PKG.ValidateCurrentLine;
26424 
26426    -- 4219869 Business Flow
26427    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
26428    ------------------------------------------------------------------------------------
26429    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
26430 
26431    ----------------------------------------------------------------------------------
26432    -- 4219869 Business Flow
26433    -- Update journal entry status -- Need to generate this within IF <condition>
26434    ----------------------------------------------------------------------------------
26435    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
26436          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
26437          ,p_balance_type_code => l_balance_type_code
26438          );
26439 
26440    -------------------------------------------------------------------------------------------
26441    -- 4262811 - Generate the Accrual Reversal lines
26442    -------------------------------------------------------------------------------------------
26443    BEGIN
26444       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
26445                               (g_array_event(p_event_id).array_value_num('header_index'));
26446       IF l_acc_rev_flag IS NULL THEN
26447          l_acc_rev_flag := 'N';
26448       END IF;
26449    EXCEPTION
26450       WHEN OTHERS THEN
26451          l_acc_rev_flag := 'N';
26452    END;
26453    --
26454    IF (l_acc_rev_flag = 'Y') THEN
26455 
26456        -- 4645092  ------------------------------------------------------------------------------
26457        -- To allow MPA report to determine if it should generate report process
26458        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
26459        ------------------------------------------------------------------------------------------
26460 
26461        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
26462        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
26463    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
26464    -- call ADRs
26465    -- Bug 4922099
26466    --
26467    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
26468         (NVL(l_actual_upg_option, 'N') = 'O') OR
26469         (NVL(l_enc_upg_option, 'N') = 'O')
26470       )
26471    THEN
26472    NULL;
26473    --
26474    --
26475    
26476   l_ccid := AcctDerRule_9(
26477            p_application_id           => p_application_id
26478          , p_ae_header_id             => l_ae_header_id 
26479 , p_source_6 => p_source_6
26480          , x_transaction_coa_id       => l_adr_transaction_coa_id
26481          , x_accounting_coa_id        => l_adr_accounting_coa_id
26482          , x_value_type_code          => l_adr_value_type_code
26483          , p_side                     => 'NA'
26484    );
26485 
26486    xla_ae_lines_pkg.set_ccid(
26487     p_code_combination_id          => l_ccid
26488   , p_value_type_code              => l_adr_value_type_code
26489   , p_transaction_coa_id           => l_adr_transaction_coa_id
26490   , p_accounting_coa_id            => l_adr_accounting_coa_id
26491   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
26492   , p_adr_type_code                => 'S'
26493   , p_component_type               => l_component_type
26494   , p_component_code               => l_component_code
26495   , p_component_type_code          => l_component_type_code
26496   , p_component_appl_id            => l_component_appl_id
26497   , p_amb_context_code             => l_amb_context_code
26498   , p_side                         => 'NA'
26499   );
26500 
26501 
26502    l_segment := AcctDerRule_4(
26503            p_application_id           => p_application_id
26504          , p_ae_header_id             => l_ae_header_id 
26505 , p_source_3 => p_source_3
26506          , x_transaction_coa_id       => l_adr_transaction_coa_id
26507          , x_accounting_coa_id        => l_adr_accounting_coa_id
26508          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
26509          , x_flex_value_set_id        => l_adr_flex_value_set_id
26510          , x_value_type_code          => l_adr_value_type_code
26511          , x_value_combination_id     => l_adr_value_combination_id
26512          , x_value_segment_code       => l_adr_value_segment_code
26513          , p_side                     => 'NA'
26514          , p_override_seg_flag        => 'Y'
26515    );
26516 
26517    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
26518 
26519       xla_ae_lines_pkg.set_segment(
26520           p_to_segment_code         => 'GL_BALANCING'
26521         , p_segment_value           => l_segment
26522         , p_from_segment_code       => l_adr_value_segment_code
26523         , p_from_combination_id     => l_adr_value_combination_id
26524         , p_value_type_code         => l_adr_value_type_code
26525         , p_transaction_coa_id      => l_adr_transaction_coa_id
26526         , p_accounting_coa_id       => l_adr_accounting_coa_id
26527         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
26528         , p_flex_value_set_id       => l_adr_flex_value_set_id
26529         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
26530         , p_adr_type_code           => 'S'
26531         , p_component_type          => l_component_type
26532         , p_component_code          => l_component_code
26533         , p_component_type_code     => l_component_type_code
26534         , p_component_appl_id       => l_component_appl_id
26535         , p_amb_context_code        => l_amb_context_code
26536         , p_entity_code             => 'RECEIPTS'
26540 
26537         , p_event_class_code        => 'MISC_RECEIPT'
26538         , p_side                    => 'NA'
26539         );
26541   END IF;
26542 
26543    --
26544    --
26545    END IF;
26546 
26547        --
26548        -- Update the line information that should be overwritten
26549        --
26550        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
26551                                          p_header_num   => 1);
26552        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
26553 
26554        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
26555 
26556        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
26557           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
26558        END IF;
26559 
26560       --
26561       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
26562       --
26563       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
26564           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
26565       ELSE
26566           ---------------------------------------------------------------------------------------------------
26567           -- 4262811a Switch Sign
26568           ---------------------------------------------------------------------------------------------------
26569           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
26570           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
26571                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
26572           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
26573                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
26574           -- 5132302
26575           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
26576                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
26577 
26578       END IF;
26579 
26580       -- 4955764
26581       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
26582       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
26583 
26584 
26585       XLA_AE_LINES_PKG.ValidateCurrentLine;
26586       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
26587 
26588       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
26589                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
26590                ,p_balance_type_code => l_balance_type_code);
26591 
26592    END IF;
26593 
26594    -----------------------------------------------------------------------------------------
26595    -- 4262811 Multiperiod Accounting
26596    -----------------------------------------------------------------------------------------
26597      -- No MPA option is assigned.
26598 
26599 
26600 END IF;
26601 END IF;
26602 --
26603 
26604 --
26605 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
26606    trace
26607       (p_msg      => 'END of AcctLineType_58'
26608       ,p_level    => C_LEVEL_PROCEDURE
26609       ,p_module   => l_log_module);
26610 END IF;
26611 --
26612 EXCEPTION
26613   WHEN xla_exceptions_pkg.application_exception THEN
26614       RAISE;
26615   WHEN OTHERS THEN
26616        xla_exceptions_pkg.raise_message
26617            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_58');
26618 END AcctLineType_58;
26619 --
26620 
26621 ---------------------------------------
26622 --
26623 -- PRIVATE FUNCTION
26624 --         AcctLineType_59
26625 --
26626 ---------------------------------------
26627 PROCEDURE AcctLineType_59 (
26628   p_application_id        IN NUMBER
26629  ,p_event_id              IN NUMBER
26630  ,p_calculate_acctd_flag  IN VARCHAR2
26631  ,p_calculate_g_l_flag    IN VARCHAR2
26632  ,p_actual_flag           IN OUT VARCHAR2
26633  ,p_balance_type_code     OUT VARCHAR2
26634  ,p_gain_or_loss_ref      OUT VARCHAR2
26635  
26636 --Distribution GL Account
26637  , p_source_3            IN NUMBER
26638 --Remittance Bank Account Confirmation Account
26639  , p_source_7            IN NUMBER
26640 --Distribution Source Type
26641  , p_source_13            IN VARCHAR2
26642 --Distribution Line Identifier
26643  , p_source_15            IN NUMBER
26644 --Distribution Type
26645  , p_source_16            IN VARCHAR2
26646 --Entered Amount
26647  , p_source_17            IN NUMBER
26648 --Currency Code
26649  , p_source_18            IN VARCHAR2
26650 --Exchange Rate
26651  , p_source_20            IN NUMBER
26652 --Exchange Rate Type
26653  , p_source_21            IN VARCHAR2
26654 --Applied To Document Accounting Amount
26655  , p_source_22            IN NUMBER
26656 --Distribution Multi Fund Additional Entry
26657  , p_source_52            IN VARCHAR2
26658 --Applied To Document Exchange Date
26659  , p_source_53            IN DATE
26660 )
26661 IS
26662 
26663 l_component_type              VARCHAR2(80);
26664 l_component_code              VARCHAR2(30);
26665 l_component_type_code         VARCHAR2(1);
26666 l_component_appl_id           INTEGER;
26667 l_amb_context_code            VARCHAR2(30);
26668 l_entity_code                 VARCHAR2(30);
26669 l_event_class_code            VARCHAR2(30);
26670 l_ae_header_id                NUMBER;
26671 l_event_type_code             VARCHAR2(30);
26672 l_line_definition_code        VARCHAR2(30);
26673 l_line_definition_owner_code  VARCHAR2(1);
26674 --
26675 -- adr variables
26676 l_segment                     VARCHAR2(30);
26677 l_ccid                        NUMBER;
26678 l_adr_transaction_coa_id      NUMBER;
26679 l_adr_accounting_coa_id       NUMBER;
26680 l_adr_flexfield_segment_code  VARCHAR2(30);
26681 l_adr_flex_value_set_id       NUMBER;
26682 l_adr_value_type_code         VARCHAR2(30);
26683 l_adr_value_combination_id    NUMBER;
26684 l_adr_value_segment_code      VARCHAR2(30);
26685 
26686 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
26687 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
26688 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
26689 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
26690 
26691 -- 4262811 Variables ------------------------------------------------------------------------------------------
26692 l_entered_amt_idx             NUMBER;
26693 l_accted_amt_idx              NUMBER;
26694 l_acc_rev_flag                VARCHAR2(1);
26695 l_accrual_line_num            NUMBER;
26696 l_tmp_amt                     NUMBER;
26697 l_acc_rev_natural_side_code   VARCHAR2(1);
26698 
26699 l_num_entries                 NUMBER;
26700 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
26701 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
26702 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
26703 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
26704 l_recog_line_1                NUMBER;
26705 l_recog_line_2                NUMBER;
26706 
26707 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
26708 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
26709 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
26710 
26711 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
26712 
26713 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
26714 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
26715 
26716 ---------------------------------------------------------------------------------------------------------------
26717 
26718 
26719 --
26720 -- bulk performance
26721 --
26722 l_balance_type_code           VARCHAR2(1);
26723 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
26724 l_log_module                  VARCHAR2(240);
26725 
26726 --
26727 -- Upgrade strategy
26728 --
26729 l_actual_upg_option           VARCHAR2(1);
26730 l_enc_upg_option           VARCHAR2(1);
26731 
26732 --
26733 BEGIN
26734 --
26735 IF g_log_enabled THEN
26736       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_59';
26737 END IF;
26738 --
26739 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
26740 
26741       trace
26742          (p_msg      => 'BEGIN of AcctLineType_59'
26743          ,p_level    => C_LEVEL_PROCEDURE
26744          ,p_module   => l_log_module);
26745 
26746 END IF;
26747 --
26748 l_component_type             := 'AMB_JLT';
26749 l_component_code             := 'MFAR_MISC_RCT_CONFIRMATION';
26750 l_component_type_code        := 'S';
26751 l_component_appl_id          :=  222;
26752 l_amb_context_code           := 'DEFAULT';
26753 l_entity_code                := 'RECEIPTS';
26754 l_event_class_code           := 'MISC_RECEIPT';
26755 l_event_type_code            := 'MISC_RECEIPT_ALL';
26756 l_line_definition_owner_code := 'S';
26757 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
26758 --
26759 l_balance_type_code          := 'A';
26760 l_segment                     := NULL;
26761 l_ccid                        := NULL;
26762 l_adr_transaction_coa_id      := NULL;
26763 l_adr_accounting_coa_id       := NULL;
26764 l_adr_flexfield_segment_code  := NULL;
26765 l_adr_flex_value_set_id       := NULL;
26766 l_adr_value_type_code         := NULL;
26767 l_adr_value_combination_id    := NULL;
26768 l_adr_value_segment_code      := NULL;
26769 
26770 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
26771 l_bflow_class_code           := '';    -- 4219869 Business Flow
26772 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
26773 l_budgetary_control_flag     := 'N';
26774 
26775 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
26776 l_bflow_applied_to_amt       := NULL; -- 5132302
26777 l_entered_amt_idx            := NULL;          -- 4262811
26778 l_accted_amt_idx             := NULL;          -- 4262811
26779 l_acc_rev_flag               := NULL;          -- 4262811
26780 l_accrual_line_num           := NULL;          -- 4262811
26781 l_tmp_amt                    := NULL;          -- 4262811
26782 --
26783  
26784 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
26785     l_balance_type_code <> 'B' THEN
26786 IF NVL(p_source_13,'
26787 ') =  'CONFIRMATION' AND 
26788 NVL(p_source_52,'
26789 ') =  'Y'
26790  THEN 
26791 
26792    --
26793    XLA_AE_LINES_PKG.SetNewLine;
26794 
26795    p_balance_type_code          := l_balance_type_code;
26796    -- set the flag so later we will know whether the gain loss line needs to be created
26797    
26798    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
26799      p_actual_flag :='A';
26800    END IF;
26801 
26802    --
26803    -- bulk performance
26804    --
26805    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
26806                                       p_header_num   => 0); -- 4262811
26810    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
26807    --
26808    -- set accounting line options
26809    --
26811            p_natural_side_code          => 'C'
26812          , p_gain_or_loss_flag          => 'N'
26813          , p_gl_transfer_mode_code      => 'S'
26814          , p_acct_entry_type_code       => 'A'
26815          , p_switch_side_flag           => 'Y'
26816          , p_merge_duplicate_code       => 'A'
26817          );
26818    --
26819    l_acc_rev_natural_side_code := 'D';  -- 4262811
26820    -- 
26821    --
26822    -- set accounting line type info
26823    --
26824    xla_ae_lines_pkg.SetAcctLineType
26825       (p_component_type             => l_component_type
26826       ,p_event_type_code            => l_event_type_code
26827       ,p_line_definition_owner_code => l_line_definition_owner_code
26828       ,p_line_definition_code       => l_line_definition_code
26829       ,p_accounting_line_code       => l_component_code
26830       ,p_accounting_line_type_code  => l_component_type_code
26831       ,p_accounting_line_appl_id    => l_component_appl_id
26832       ,p_amb_context_code           => l_amb_context_code
26833       ,p_entity_code                => l_entity_code
26834       ,p_event_class_code           => l_event_class_code);
26835    --
26836    -- set accounting class
26837    --
26838    xla_ae_lines_pkg.SetAcctClass(
26839            p_accounting_class_code  => 'CONFIRMATION'
26840          , p_ae_header_id           => l_ae_header_id
26841          );
26842 
26843    --
26844    -- set rounding class
26845    --
26846    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
26847                       'RECEIVABLE';
26848 
26849    --
26850    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
26851    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
26852    --
26853    -- bulk performance
26854    --
26855    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
26856 
26857    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
26858       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
26859 
26860    -- 4955764
26861    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
26862       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
26863 
26864    -- 4458381 Public Sector Enh
26865    
26866    --
26867    -- set accounting attributes for the line type
26868    --
26869    l_entered_amt_idx := 3;
26870    l_accted_amt_idx  := 8;
26871    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
26872    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
26873    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
26874    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
26875    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
26876    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
26877    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
26878    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
26879    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
26880    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
26881    l_rec_acct_attrs.array_date_value(5)  := p_source_53;
26882    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
26883    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
26884    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
26885    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
26886    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
26887    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
26888 
26889    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
26890    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
26891 
26892    ---------------------------------------------------------------------------------------------------------------
26893    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
26894    ---------------------------------------------------------------------------------------------------------------
26895    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
26896 
26897    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
26898    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
26899 
26900    IF xla_accounting_cache_pkg.GetValueChar
26901          (p_source_code         => 'LEDGER_CATEGORY_CODE'
26902          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
26903    AND l_bflow_method_code = 'PRIOR_ENTRY'
26904 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
26905    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
26906          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
26907        )
26908    THEN
26909          xla_ae_lines_pkg.BflowUpgEntry
26910            (p_business_method_code    => l_bflow_method_code
26911            ,p_business_class_code     => l_bflow_class_code
26912            ,p_balance_type            => l_balance_type_code);
26913    ELSE
26914       NULL;
26915 -- No business flow processing for business flow method of NONE.
26916    END IF;
26917 
26918    --
26919    -- call analytical criteria
26920    --
26921    
26922    --
26923    -- call description
26924    --
26925    
26926 xla_ae_lines_pkg.SetLineDescription(
26930    , p_ae_header_id           => l_ae_header_id 
26927    p_ae_header_id => l_ae_header_id
26928   ,p_description  => Description_1 (
26929      p_application_id         => p_application_id
26931    )
26932 );
26933 
26934 
26935    --
26936    -- call ADRs
26937    -- Bug 4922099
26938    --
26939    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
26940         (NVL(l_actual_upg_option, 'N') = 'O') OR
26941         (NVL(l_enc_upg_option, 'N') = 'O')
26942       )
26943    THEN
26944    NULL;
26945    --
26946    --
26947    
26948   l_ccid := AcctDerRule_10(
26949            p_application_id           => p_application_id
26950          , p_ae_header_id             => l_ae_header_id 
26951 , p_source_7 => p_source_7
26952          , x_transaction_coa_id       => l_adr_transaction_coa_id
26953          , x_accounting_coa_id        => l_adr_accounting_coa_id
26954          , x_value_type_code          => l_adr_value_type_code
26955          , p_side                     => 'NA'
26956    );
26957 
26958    xla_ae_lines_pkg.set_ccid(
26959     p_code_combination_id          => l_ccid
26960   , p_value_type_code              => l_adr_value_type_code
26961   , p_transaction_coa_id           => l_adr_transaction_coa_id
26962   , p_accounting_coa_id            => l_adr_accounting_coa_id
26963   , p_adr_code                     => 'MFAR_RCT_DEF_CONFIRMATION_CCID'
26964   , p_adr_type_code                => 'S'
26965   , p_component_type               => l_component_type
26966   , p_component_code               => l_component_code
26967   , p_component_type_code          => l_component_type_code
26968   , p_component_appl_id            => l_component_appl_id
26969   , p_amb_context_code             => l_amb_context_code
26970   , p_side                         => 'NA'
26971   );
26972 
26973 
26974    l_segment := AcctDerRule_4(
26975            p_application_id           => p_application_id
26976          , p_ae_header_id             => l_ae_header_id 
26977 , p_source_3 => p_source_3
26978          , x_transaction_coa_id       => l_adr_transaction_coa_id
26979          , x_accounting_coa_id        => l_adr_accounting_coa_id
26980          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
26981          , x_flex_value_set_id        => l_adr_flex_value_set_id
26982          , x_value_type_code          => l_adr_value_type_code
26983          , x_value_combination_id     => l_adr_value_combination_id
26984          , x_value_segment_code       => l_adr_value_segment_code
26985          , p_side                     => 'NA'
26986          , p_override_seg_flag        => 'Y'
26987    );
26988 
26989    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
26990 
26991       xla_ae_lines_pkg.set_segment(
26992           p_to_segment_code         => 'GL_BALANCING'
26993         , p_segment_value           => l_segment
26994         , p_from_segment_code       => l_adr_value_segment_code
26995         , p_from_combination_id     => l_adr_value_combination_id
26996         , p_value_type_code         => l_adr_value_type_code
26997         , p_transaction_coa_id      => l_adr_transaction_coa_id
26998         , p_accounting_coa_id       => l_adr_accounting_coa_id
26999         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
27000         , p_flex_value_set_id       => l_adr_flex_value_set_id
27001         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
27002         , p_adr_type_code           => 'S'
27003         , p_component_type          => l_component_type
27004         , p_component_code          => l_component_code
27005         , p_component_type_code     => l_component_type_code
27006         , p_component_appl_id       => l_component_appl_id
27007         , p_amb_context_code        => l_amb_context_code
27008         , p_entity_code             => 'RECEIPTS'
27009         , p_event_class_code        => 'MISC_RECEIPT'
27010         , p_side                    => 'NA'
27011         );
27012 
27013   END IF;
27014 
27015    --
27016    --
27017    END IF;
27018    --
27019    -- Bug 4922099
27020    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
27021           (NVL(l_enc_upg_option, 'N') = 'O')
27022         ) AND
27023         (l_bflow_method_code = 'PRIOR_ENTRY')
27024       )
27025    THEN
27026       IF
27027       --
27028       1 = 2
27029       --
27030       THEN
27031       xla_accounting_err_pkg.build_message
27032                                     (p_appli_s_name            => 'XLA'
27033                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
27034                                     ,p_token_1                 => 'LINE_NUMBER'
27035                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
27036                                     ,p_token_2                 => 'LINE_TYPE_NAME'
27037                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
27038                                                                              l_component_type
27039                                                                             ,l_component_code
27040                                                                             ,l_component_type_code
27041                                                                             ,l_component_appl_id
27042                                                                             ,l_amb_context_code
27043                                                                             ,l_entity_code
27044                                                                             ,l_event_class_code
27045                                                                            )
27049                                                                           ,p_lookup_code    => l_component_type_code
27046                                     ,p_token_3                 => 'OWNER'
27047                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
27048                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
27050                                                                          )
27051                                     ,p_token_4                 => 'PRODUCT_NAME'
27052                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
27053                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
27054                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
27055                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
27056                                     ,p_ae_header_id            =>  NULL
27057                                        );
27058 
27059         IF (C_LEVEL_ERROR>= g_log_level) THEN
27060                  trace
27061                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
27062                       ,p_level    => C_LEVEL_ERROR
27063                       ,p_module   => l_log_module);
27064         END IF;
27065       END IF;
27066    END IF;
27067    --
27068    --
27069    ------------------------------------------------------------------------------------------------
27070    -- 4219869 Business Flow
27071    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
27072    -- Prior Entry.  Currently, the following code is always generated.
27073    ------------------------------------------------------------------------------------------------
27074    XLA_AE_LINES_PKG.ValidateCurrentLine;
27075 
27076    ------------------------------------------------------------------------------------
27077    -- 4219869 Business Flow
27078    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
27079    ------------------------------------------------------------------------------------
27080    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
27081 
27082    ----------------------------------------------------------------------------------
27083    -- 4219869 Business Flow
27084    -- Update journal entry status -- Need to generate this within IF <condition>
27085    ----------------------------------------------------------------------------------
27086    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
27087          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
27088          ,p_balance_type_code => l_balance_type_code
27089          );
27090 
27091    -------------------------------------------------------------------------------------------
27092    -- 4262811 - Generate the Accrual Reversal lines
27093    -------------------------------------------------------------------------------------------
27094    BEGIN
27095       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
27096                               (g_array_event(p_event_id).array_value_num('header_index'));
27097       IF l_acc_rev_flag IS NULL THEN
27098          l_acc_rev_flag := 'N';
27099       END IF;
27100    EXCEPTION
27101       WHEN OTHERS THEN
27102          l_acc_rev_flag := 'N';
27103    END;
27104    --
27105    IF (l_acc_rev_flag = 'Y') THEN
27106 
27107        -- 4645092  ------------------------------------------------------------------------------
27108        -- To allow MPA report to determine if it should generate report process
27109        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
27110        ------------------------------------------------------------------------------------------
27111 
27112        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
27113        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
27114    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
27115    -- call ADRs
27116    -- Bug 4922099
27117    --
27118    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
27119         (NVL(l_actual_upg_option, 'N') = 'O') OR
27120         (NVL(l_enc_upg_option, 'N') = 'O')
27121       )
27122    THEN
27123    NULL;
27124    --
27125    --
27126    
27127   l_ccid := AcctDerRule_10(
27128            p_application_id           => p_application_id
27129          , p_ae_header_id             => l_ae_header_id 
27130 , p_source_7 => p_source_7
27131          , x_transaction_coa_id       => l_adr_transaction_coa_id
27132          , x_accounting_coa_id        => l_adr_accounting_coa_id
27133          , x_value_type_code          => l_adr_value_type_code
27134          , p_side                     => 'NA'
27135    );
27136 
27137    xla_ae_lines_pkg.set_ccid(
27138     p_code_combination_id          => l_ccid
27139   , p_value_type_code              => l_adr_value_type_code
27140   , p_transaction_coa_id           => l_adr_transaction_coa_id
27141   , p_accounting_coa_id            => l_adr_accounting_coa_id
27142   , p_adr_code                     => 'MFAR_RCT_DEF_CONFIRMATION_CCID'
27143   , p_adr_type_code                => 'S'
27144   , p_component_type               => l_component_type
27145   , p_component_code               => l_component_code
27146   , p_component_type_code          => l_component_type_code
27147   , p_component_appl_id            => l_component_appl_id
27148   , p_amb_context_code             => l_amb_context_code
27149   , p_side                         => 'NA'
27150   );
27151 
27152 
27153    l_segment := AcctDerRule_4(
27154            p_application_id           => p_application_id
27155          , p_ae_header_id             => l_ae_header_id 
27156 , p_source_3 => p_source_3
27157          , x_transaction_coa_id       => l_adr_transaction_coa_id
27158          , x_accounting_coa_id        => l_adr_accounting_coa_id
27159          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
27160          , x_flex_value_set_id        => l_adr_flex_value_set_id
27161          , x_value_type_code          => l_adr_value_type_code
27162          , x_value_combination_id     => l_adr_value_combination_id
27163          , x_value_segment_code       => l_adr_value_segment_code
27164          , p_side                     => 'NA'
27165          , p_override_seg_flag        => 'Y'
27166    );
27167 
27168    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
27169 
27170       xla_ae_lines_pkg.set_segment(
27171           p_to_segment_code         => 'GL_BALANCING'
27172         , p_segment_value           => l_segment
27173         , p_from_segment_code       => l_adr_value_segment_code
27174         , p_from_combination_id     => l_adr_value_combination_id
27175         , p_value_type_code         => l_adr_value_type_code
27176         , p_transaction_coa_id      => l_adr_transaction_coa_id
27177         , p_accounting_coa_id       => l_adr_accounting_coa_id
27178         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
27179         , p_flex_value_set_id       => l_adr_flex_value_set_id
27180         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
27181         , p_adr_type_code           => 'S'
27182         , p_component_type          => l_component_type
27183         , p_component_code          => l_component_code
27184         , p_component_type_code     => l_component_type_code
27185         , p_component_appl_id       => l_component_appl_id
27186         , p_amb_context_code        => l_amb_context_code
27187         , p_entity_code             => 'RECEIPTS'
27188         , p_event_class_code        => 'MISC_RECEIPT'
27189         , p_side                    => 'NA'
27190         );
27191 
27192   END IF;
27193 
27194    --
27195    --
27196    END IF;
27197 
27198        --
27199        -- Update the line information that should be overwritten
27200        --
27201        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
27202                                          p_header_num   => 1);
27203        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
27204 
27205        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
27206 
27207        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
27208           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
27209        END IF;
27210 
27211       --
27212       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
27213       --
27214       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
27215           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
27216       ELSE
27217           ---------------------------------------------------------------------------------------------------
27218           -- 4262811a Switch Sign
27219           ---------------------------------------------------------------------------------------------------
27220           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
27221           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
27222                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
27223           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
27224                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
27225           -- 5132302
27226           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
27227                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
27228 
27229       END IF;
27230 
27231       -- 4955764
27232       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
27233       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
27234 
27235 
27236       XLA_AE_LINES_PKG.ValidateCurrentLine;
27237       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
27238 
27239       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
27240                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
27241                ,p_balance_type_code => l_balance_type_code);
27242 
27243    END IF;
27244 
27245    -----------------------------------------------------------------------------------------
27246    -- 4262811 Multiperiod Accounting
27247    -----------------------------------------------------------------------------------------
27248      -- No MPA option is assigned.
27249 
27250 
27251 END IF;
27252 END IF;
27253 --
27254 
27255 --
27256 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
27257    trace
27258       (p_msg      => 'END of AcctLineType_59'
27259       ,p_level    => C_LEVEL_PROCEDURE
27260       ,p_module   => l_log_module);
27261 END IF;
27262 --
27263 EXCEPTION
27264   WHEN xla_exceptions_pkg.application_exception THEN
27265       RAISE;
27266   WHEN OTHERS THEN
27267        xla_exceptions_pkg.raise_message
27268            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_59');
27269 END AcctLineType_59;
27270 --
27271 
27272 ---------------------------------------
27273 --
27274 -- PRIVATE FUNCTION
27275 --         AcctLineType_60
27276 --
27277 ---------------------------------------
27278 PROCEDURE AcctLineType_60 (
27279   p_application_id        IN NUMBER
27280  ,p_event_id              IN NUMBER
27281  ,p_calculate_acctd_flag  IN VARCHAR2
27282  ,p_calculate_g_l_flag    IN VARCHAR2
27283  ,p_actual_flag           IN OUT VARCHAR2
27284  ,p_balance_type_code     OUT VARCHAR2
27285  ,p_gain_or_loss_ref      OUT VARCHAR2
27286  
27287 --Distribution GL Account
27288  , p_source_3            IN NUMBER
27289 --Remittance Bank Account Remittance Account
27290  , p_source_8            IN NUMBER
27291 --Distribution Source Type
27292  , p_source_13            IN VARCHAR2
27293 --Distribution Line Identifier
27294  , p_source_15            IN NUMBER
27295 --Distribution Type
27296  , p_source_16            IN VARCHAR2
27297 --Entered Amount
27298  , p_source_17            IN NUMBER
27299 --Currency Code
27300  , p_source_18            IN VARCHAR2
27301 --Exchange Rate
27302  , p_source_20            IN NUMBER
27303 --Exchange Rate Type
27304  , p_source_21            IN VARCHAR2
27305 --Applied To Document Accounting Amount
27306  , p_source_22            IN NUMBER
27307 --Distribution Multi Fund Additional Entry
27308  , p_source_52            IN VARCHAR2
27309 --Applied To Document Exchange Date
27310  , p_source_53            IN DATE
27311 )
27312 IS
27313 
27314 l_component_type              VARCHAR2(80);
27315 l_component_code              VARCHAR2(30);
27316 l_component_type_code         VARCHAR2(1);
27317 l_component_appl_id           INTEGER;
27318 l_amb_context_code            VARCHAR2(30);
27319 l_entity_code                 VARCHAR2(30);
27320 l_event_class_code            VARCHAR2(30);
27321 l_ae_header_id                NUMBER;
27322 l_event_type_code             VARCHAR2(30);
27323 l_line_definition_code        VARCHAR2(30);
27324 l_line_definition_owner_code  VARCHAR2(1);
27325 --
27326 -- adr variables
27327 l_segment                     VARCHAR2(30);
27328 l_ccid                        NUMBER;
27329 l_adr_transaction_coa_id      NUMBER;
27330 l_adr_accounting_coa_id       NUMBER;
27331 l_adr_flexfield_segment_code  VARCHAR2(30);
27332 l_adr_flex_value_set_id       NUMBER;
27333 l_adr_value_type_code         VARCHAR2(30);
27334 l_adr_value_combination_id    NUMBER;
27335 l_adr_value_segment_code      VARCHAR2(30);
27336 
27337 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
27338 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
27339 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
27340 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
27341 
27342 -- 4262811 Variables ------------------------------------------------------------------------------------------
27343 l_entered_amt_idx             NUMBER;
27344 l_accted_amt_idx              NUMBER;
27345 l_acc_rev_flag                VARCHAR2(1);
27346 l_accrual_line_num            NUMBER;
27347 l_tmp_amt                     NUMBER;
27348 l_acc_rev_natural_side_code   VARCHAR2(1);
27349 
27350 l_num_entries                 NUMBER;
27351 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
27352 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
27353 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
27354 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
27355 l_recog_line_1                NUMBER;
27356 l_recog_line_2                NUMBER;
27357 
27358 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
27359 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
27360 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
27361 
27362 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
27363 
27364 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
27365 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
27366 
27367 ---------------------------------------------------------------------------------------------------------------
27368 
27369 
27370 --
27371 -- bulk performance
27372 --
27373 l_balance_type_code           VARCHAR2(1);
27374 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
27375 l_log_module                  VARCHAR2(240);
27376 
27377 --
27378 -- Upgrade strategy
27379 --
27380 l_actual_upg_option           VARCHAR2(1);
27381 l_enc_upg_option           VARCHAR2(1);
27382 
27383 --
27384 BEGIN
27385 --
27386 IF g_log_enabled THEN
27387       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_60';
27388 END IF;
27389 --
27390 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
27391 
27392       trace
27393          (p_msg      => 'BEGIN of AcctLineType_60'
27394          ,p_level    => C_LEVEL_PROCEDURE
27395          ,p_module   => l_log_module);
27396 
27397 END IF;
27398 --
27399 l_component_type             := 'AMB_JLT';
27400 l_component_code             := 'MFAR_MISC_RCT_REMITTANCE';
27401 l_component_type_code        := 'S';
27402 l_component_appl_id          :=  222;
27403 l_amb_context_code           := 'DEFAULT';
27404 l_entity_code                := 'RECEIPTS';
27405 l_event_class_code           := 'MISC_RECEIPT';
27406 l_event_type_code            := 'MISC_RECEIPT_ALL';
27407 l_line_definition_owner_code := 'S';
27408 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
27409 --
27410 l_balance_type_code          := 'A';
27411 l_segment                     := NULL;
27412 l_ccid                        := NULL;
27413 l_adr_transaction_coa_id      := NULL;
27414 l_adr_accounting_coa_id       := NULL;
27415 l_adr_flexfield_segment_code  := NULL;
27416 l_adr_flex_value_set_id       := NULL;
27420 
27417 l_adr_value_type_code         := NULL;
27418 l_adr_value_combination_id    := NULL;
27419 l_adr_value_segment_code      := NULL;
27421 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
27422 l_bflow_class_code           := '';    -- 4219869 Business Flow
27423 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
27424 l_budgetary_control_flag     := 'N';
27425 
27426 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
27427 l_bflow_applied_to_amt       := NULL; -- 5132302
27428 l_entered_amt_idx            := NULL;          -- 4262811
27429 l_accted_amt_idx             := NULL;          -- 4262811
27430 l_acc_rev_flag               := NULL;          -- 4262811
27431 l_accrual_line_num           := NULL;          -- 4262811
27432 l_tmp_amt                    := NULL;          -- 4262811
27433 --
27434  
27435 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
27436     l_balance_type_code <> 'B' THEN
27437 IF NVL(p_source_13,'
27438 ') =  'REMITTANCE' AND 
27439 NVL(p_source_52,'
27440 ') =  'Y'
27441  THEN 
27442 
27443    --
27444    XLA_AE_LINES_PKG.SetNewLine;
27445 
27446    p_balance_type_code          := l_balance_type_code;
27447    -- set the flag so later we will know whether the gain loss line needs to be created
27448    
27449    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
27450      p_actual_flag :='A';
27451    END IF;
27452 
27453    --
27454    -- bulk performance
27455    --
27456    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
27457                                       p_header_num   => 0); -- 4262811
27458    --
27459    -- set accounting line options
27460    --
27461    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
27462            p_natural_side_code          => 'C'
27463          , p_gain_or_loss_flag          => 'N'
27464          , p_gl_transfer_mode_code      => 'S'
27465          , p_acct_entry_type_code       => 'A'
27466          , p_switch_side_flag           => 'Y'
27467          , p_merge_duplicate_code       => 'A'
27468          );
27469    --
27470    l_acc_rev_natural_side_code := 'D';  -- 4262811
27471    -- 
27472    --
27473    -- set accounting line type info
27474    --
27475    xla_ae_lines_pkg.SetAcctLineType
27476       (p_component_type             => l_component_type
27477       ,p_event_type_code            => l_event_type_code
27478       ,p_line_definition_owner_code => l_line_definition_owner_code
27479       ,p_line_definition_code       => l_line_definition_code
27480       ,p_accounting_line_code       => l_component_code
27481       ,p_accounting_line_type_code  => l_component_type_code
27482       ,p_accounting_line_appl_id    => l_component_appl_id
27483       ,p_amb_context_code           => l_amb_context_code
27484       ,p_entity_code                => l_entity_code
27485       ,p_event_class_code           => l_event_class_code);
27486    --
27487    -- set accounting class
27488    --
27489    xla_ae_lines_pkg.SetAcctClass(
27490            p_accounting_class_code  => 'REMITTANCE'
27491          , p_ae_header_id           => l_ae_header_id
27492          );
27493 
27494    --
27495    -- set rounding class
27496    --
27497    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
27498                       'RECEIVABLE';
27499 
27500    --
27501    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
27502    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
27503    --
27504    -- bulk performance
27505    --
27506    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
27507 
27508    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
27509       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
27510 
27511    -- 4955764
27512    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
27513       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
27514 
27515    -- 4458381 Public Sector Enh
27516    
27517    --
27518    -- set accounting attributes for the line type
27519    --
27520    l_entered_amt_idx := 3;
27521    l_accted_amt_idx  := 8;
27522    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
27523    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
27524    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
27525    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
27526    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
27527    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
27528    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
27529    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
27530    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
27531    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
27532    l_rec_acct_attrs.array_date_value(5)  := p_source_53;
27533    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
27534    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
27535    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
27536    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
27537    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
27538    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
27539 
27540    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
27544    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
27541    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
27542 
27543    ---------------------------------------------------------------------------------------------------------------
27545    ---------------------------------------------------------------------------------------------------------------
27546    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
27547 
27548    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
27549    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
27550 
27551    IF xla_accounting_cache_pkg.GetValueChar
27552          (p_source_code         => 'LEDGER_CATEGORY_CODE'
27553          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
27554    AND l_bflow_method_code = 'PRIOR_ENTRY'
27555 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
27556    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
27557          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
27558        )
27559    THEN
27560          xla_ae_lines_pkg.BflowUpgEntry
27561            (p_business_method_code    => l_bflow_method_code
27562            ,p_business_class_code     => l_bflow_class_code
27563            ,p_balance_type            => l_balance_type_code);
27564    ELSE
27565       NULL;
27566 -- No business flow processing for business flow method of NONE.
27567    END IF;
27568 
27569    --
27570    -- call analytical criteria
27571    --
27572    
27573    --
27574    -- call description
27575    --
27576    
27577 xla_ae_lines_pkg.SetLineDescription(
27578    p_ae_header_id => l_ae_header_id
27579   ,p_description  => Description_1 (
27580      p_application_id         => p_application_id
27581    , p_ae_header_id           => l_ae_header_id 
27582    )
27583 );
27584 
27585 
27586    --
27587    -- call ADRs
27588    -- Bug 4922099
27589    --
27590    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
27591         (NVL(l_actual_upg_option, 'N') = 'O') OR
27592         (NVL(l_enc_upg_option, 'N') = 'O')
27593       )
27594    THEN
27595    NULL;
27596    --
27597    --
27598    
27599   l_ccid := AcctDerRule_11(
27600            p_application_id           => p_application_id
27601          , p_ae_header_id             => l_ae_header_id 
27602 , p_source_8 => p_source_8
27603          , x_transaction_coa_id       => l_adr_transaction_coa_id
27604          , x_accounting_coa_id        => l_adr_accounting_coa_id
27605          , x_value_type_code          => l_adr_value_type_code
27606          , p_side                     => 'NA'
27607    );
27608 
27609    xla_ae_lines_pkg.set_ccid(
27610     p_code_combination_id          => l_ccid
27611   , p_value_type_code              => l_adr_value_type_code
27612   , p_transaction_coa_id           => l_adr_transaction_coa_id
27613   , p_accounting_coa_id            => l_adr_accounting_coa_id
27614   , p_adr_code                     => 'MFAR_RCT_DEF_REMITTANCE_CCID'
27615   , p_adr_type_code                => 'S'
27616   , p_component_type               => l_component_type
27617   , p_component_code               => l_component_code
27618   , p_component_type_code          => l_component_type_code
27619   , p_component_appl_id            => l_component_appl_id
27620   , p_amb_context_code             => l_amb_context_code
27621   , p_side                         => 'NA'
27622   );
27623 
27624 
27625    l_segment := AcctDerRule_4(
27626            p_application_id           => p_application_id
27627          , p_ae_header_id             => l_ae_header_id 
27628 , p_source_3 => p_source_3
27629          , x_transaction_coa_id       => l_adr_transaction_coa_id
27630          , x_accounting_coa_id        => l_adr_accounting_coa_id
27631          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
27632          , x_flex_value_set_id        => l_adr_flex_value_set_id
27633          , x_value_type_code          => l_adr_value_type_code
27634          , x_value_combination_id     => l_adr_value_combination_id
27635          , x_value_segment_code       => l_adr_value_segment_code
27636          , p_side                     => 'NA'
27637          , p_override_seg_flag        => 'Y'
27638    );
27639 
27640    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
27641 
27642       xla_ae_lines_pkg.set_segment(
27643           p_to_segment_code         => 'GL_BALANCING'
27644         , p_segment_value           => l_segment
27645         , p_from_segment_code       => l_adr_value_segment_code
27646         , p_from_combination_id     => l_adr_value_combination_id
27647         , p_value_type_code         => l_adr_value_type_code
27648         , p_transaction_coa_id      => l_adr_transaction_coa_id
27649         , p_accounting_coa_id       => l_adr_accounting_coa_id
27650         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
27651         , p_flex_value_set_id       => l_adr_flex_value_set_id
27652         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
27653         , p_adr_type_code           => 'S'
27654         , p_component_type          => l_component_type
27655         , p_component_code          => l_component_code
27656         , p_component_type_code     => l_component_type_code
27657         , p_component_appl_id       => l_component_appl_id
27658         , p_amb_context_code        => l_amb_context_code
27659         , p_entity_code             => 'RECEIPTS'
27660         , p_event_class_code        => 'MISC_RECEIPT'
27661         , p_side                    => 'NA'
27662         );
27663 
27667    --
27664   END IF;
27665 
27666    --
27668    END IF;
27669    --
27670    -- Bug 4922099
27671    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
27672           (NVL(l_enc_upg_option, 'N') = 'O')
27673         ) AND
27674         (l_bflow_method_code = 'PRIOR_ENTRY')
27675       )
27676    THEN
27677       IF
27678       --
27679       1 = 2
27680       --
27681       THEN
27682       xla_accounting_err_pkg.build_message
27683                                     (p_appli_s_name            => 'XLA'
27684                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
27685                                     ,p_token_1                 => 'LINE_NUMBER'
27686                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
27687                                     ,p_token_2                 => 'LINE_TYPE_NAME'
27688                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
27689                                                                              l_component_type
27690                                                                             ,l_component_code
27691                                                                             ,l_component_type_code
27692                                                                             ,l_component_appl_id
27693                                                                             ,l_amb_context_code
27694                                                                             ,l_entity_code
27695                                                                             ,l_event_class_code
27696                                                                            )
27697                                     ,p_token_3                 => 'OWNER'
27698                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
27699                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
27700                                                                           ,p_lookup_code    => l_component_type_code
27701                                                                          )
27702                                     ,p_token_4                 => 'PRODUCT_NAME'
27703                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
27704                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
27705                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
27706                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
27707                                     ,p_ae_header_id            =>  NULL
27708                                        );
27709 
27710         IF (C_LEVEL_ERROR>= g_log_level) THEN
27711                  trace
27712                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
27713                       ,p_level    => C_LEVEL_ERROR
27714                       ,p_module   => l_log_module);
27715         END IF;
27716       END IF;
27717    END IF;
27718    --
27719    --
27720    ------------------------------------------------------------------------------------------------
27721    -- 4219869 Business Flow
27722    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
27723    -- Prior Entry.  Currently, the following code is always generated.
27724    ------------------------------------------------------------------------------------------------
27725    XLA_AE_LINES_PKG.ValidateCurrentLine;
27726 
27727    ------------------------------------------------------------------------------------
27728    -- 4219869 Business Flow
27729    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
27730    ------------------------------------------------------------------------------------
27731    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
27732 
27733    ----------------------------------------------------------------------------------
27734    -- 4219869 Business Flow
27735    -- Update journal entry status -- Need to generate this within IF <condition>
27736    ----------------------------------------------------------------------------------
27737    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
27738          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
27739          ,p_balance_type_code => l_balance_type_code
27740          );
27741 
27742    -------------------------------------------------------------------------------------------
27743    -- 4262811 - Generate the Accrual Reversal lines
27744    -------------------------------------------------------------------------------------------
27745    BEGIN
27746       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
27747                               (g_array_event(p_event_id).array_value_num('header_index'));
27748       IF l_acc_rev_flag IS NULL THEN
27749          l_acc_rev_flag := 'N';
27750       END IF;
27751    EXCEPTION
27752       WHEN OTHERS THEN
27753          l_acc_rev_flag := 'N';
27754    END;
27755    --
27756    IF (l_acc_rev_flag = 'Y') THEN
27757 
27758        -- 4645092  ------------------------------------------------------------------------------
27759        -- To allow MPA report to determine if it should generate report process
27760        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
27761        ------------------------------------------------------------------------------------------
27762 
27763        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
27764        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
27768    --
27765    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
27766    -- call ADRs
27767    -- Bug 4922099
27769    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
27770         (NVL(l_actual_upg_option, 'N') = 'O') OR
27771         (NVL(l_enc_upg_option, 'N') = 'O')
27772       )
27773    THEN
27774    NULL;
27775    --
27776    --
27777    
27778   l_ccid := AcctDerRule_11(
27779            p_application_id           => p_application_id
27780          , p_ae_header_id             => l_ae_header_id 
27781 , p_source_8 => p_source_8
27782          , x_transaction_coa_id       => l_adr_transaction_coa_id
27783          , x_accounting_coa_id        => l_adr_accounting_coa_id
27784          , x_value_type_code          => l_adr_value_type_code
27785          , p_side                     => 'NA'
27786    );
27787 
27788    xla_ae_lines_pkg.set_ccid(
27789     p_code_combination_id          => l_ccid
27790   , p_value_type_code              => l_adr_value_type_code
27791   , p_transaction_coa_id           => l_adr_transaction_coa_id
27792   , p_accounting_coa_id            => l_adr_accounting_coa_id
27793   , p_adr_code                     => 'MFAR_RCT_DEF_REMITTANCE_CCID'
27794   , p_adr_type_code                => 'S'
27795   , p_component_type               => l_component_type
27796   , p_component_code               => l_component_code
27797   , p_component_type_code          => l_component_type_code
27798   , p_component_appl_id            => l_component_appl_id
27799   , p_amb_context_code             => l_amb_context_code
27800   , p_side                         => 'NA'
27801   );
27802 
27803 
27804    l_segment := AcctDerRule_4(
27805            p_application_id           => p_application_id
27806          , p_ae_header_id             => l_ae_header_id 
27807 , p_source_3 => p_source_3
27808          , x_transaction_coa_id       => l_adr_transaction_coa_id
27809          , x_accounting_coa_id        => l_adr_accounting_coa_id
27810          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
27811          , x_flex_value_set_id        => l_adr_flex_value_set_id
27812          , x_value_type_code          => l_adr_value_type_code
27813          , x_value_combination_id     => l_adr_value_combination_id
27814          , x_value_segment_code       => l_adr_value_segment_code
27815          , p_side                     => 'NA'
27816          , p_override_seg_flag        => 'Y'
27817    );
27818 
27819    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
27820 
27821       xla_ae_lines_pkg.set_segment(
27822           p_to_segment_code         => 'GL_BALANCING'
27823         , p_segment_value           => l_segment
27824         , p_from_segment_code       => l_adr_value_segment_code
27825         , p_from_combination_id     => l_adr_value_combination_id
27826         , p_value_type_code         => l_adr_value_type_code
27827         , p_transaction_coa_id      => l_adr_transaction_coa_id
27828         , p_accounting_coa_id       => l_adr_accounting_coa_id
27829         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
27830         , p_flex_value_set_id       => l_adr_flex_value_set_id
27831         , p_adr_code                => 'MFAR_DIST_BALANCING_SEGMENT'
27832         , p_adr_type_code           => 'S'
27833         , p_component_type          => l_component_type
27834         , p_component_code          => l_component_code
27835         , p_component_type_code     => l_component_type_code
27836         , p_component_appl_id       => l_component_appl_id
27837         , p_amb_context_code        => l_amb_context_code
27838         , p_entity_code             => 'RECEIPTS'
27839         , p_event_class_code        => 'MISC_RECEIPT'
27840         , p_side                    => 'NA'
27841         );
27842 
27843   END IF;
27844 
27845    --
27846    --
27847    END IF;
27848 
27849        --
27850        -- Update the line information that should be overwritten
27851        --
27852        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
27853                                          p_header_num   => 1);
27854        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
27855 
27856        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
27857 
27858        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
27859           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
27860        END IF;
27861 
27862       --
27863       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
27864       --
27865       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
27866           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
27867       ELSE
27868           ---------------------------------------------------------------------------------------------------
27869           -- 4262811a Switch Sign
27870           ---------------------------------------------------------------------------------------------------
27871           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
27872           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
27873                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
27874           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
27875                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
27876           -- 5132302
27877           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
27881 
27878                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
27879 
27880       END IF;
27882       -- 4955764
27883       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
27884       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
27885 
27886 
27887       XLA_AE_LINES_PKG.ValidateCurrentLine;
27888       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
27889 
27890       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
27891                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
27892                ,p_balance_type_code => l_balance_type_code);
27893 
27894    END IF;
27895 
27896    -----------------------------------------------------------------------------------------
27897    -- 4262811 Multiperiod Accounting
27898    -----------------------------------------------------------------------------------------
27899      -- No MPA option is assigned.
27900 
27901 
27902 END IF;
27903 END IF;
27904 --
27905 
27906 --
27907 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
27908    trace
27909       (p_msg      => 'END of AcctLineType_60'
27910       ,p_level    => C_LEVEL_PROCEDURE
27911       ,p_module   => l_log_module);
27912 END IF;
27913 --
27914 EXCEPTION
27915   WHEN xla_exceptions_pkg.application_exception THEN
27916       RAISE;
27917   WHEN OTHERS THEN
27918        xla_exceptions_pkg.raise_message
27919            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_60');
27920 END AcctLineType_60;
27921 --
27922 
27923 ---------------------------------------
27924 --
27925 -- PRIVATE FUNCTION
27926 --         AcctLineType_61
27927 --
27928 ---------------------------------------
27929 PROCEDURE AcctLineType_61 (
27930   p_application_id        IN NUMBER
27931  ,p_event_id              IN NUMBER
27932  ,p_calculate_acctd_flag  IN VARCHAR2
27933  ,p_calculate_g_l_flag    IN VARCHAR2
27934  ,p_actual_flag           IN OUT VARCHAR2
27935  ,p_balance_type_code     OUT VARCHAR2
27936  ,p_gain_or_loss_ref      OUT VARCHAR2
27937  
27938 --Remittance Bank Account Bank Charges Acount
27939  , p_source_1            IN NUMBER
27940 --Remittance Bank Account Cash Account
27941  , p_source_6            IN NUMBER
27942 --Distribution Source Type
27943  , p_source_13            IN VARCHAR2
27944 --Distribution Line Identifier
27945  , p_source_15            IN NUMBER
27946 --Distribution Type
27947  , p_source_16            IN VARCHAR2
27948 --Exchange Date
27949  , p_source_19            IN DATE
27950 --Exchange Rate
27951  , p_source_20            IN NUMBER
27952 --Exchange Rate Type
27953  , p_source_21            IN VARCHAR2
27954 --Transaction Distribution Identifier
27955  , p_source_27            IN NUMBER
27956 --Transaction Distribution Type
27957  , p_source_28            IN VARCHAR2
27958 --Distribution Multi Fund Additional Entry
27959  , p_source_52            IN VARCHAR2
27960 --Receipt Applied To Application Identifier
27961  , p_source_56            IN NUMBER
27962 --Transaction Entity Code
27963  , p_source_57            IN VARCHAR2
27964 --Transaction Identifier
27965  , p_source_58            IN NUMBER
27966 --DIST_ENT_AMT_FROM
27967  , p_source_59            IN NUMBER
27968 --Applying Document Currency Code
27969  , p_source_60            IN VARCHAR2
27970 --Accounting Amount
27971  , p_source_61            IN NUMBER
27972 --Distribution Party Identifier
27973  , p_source_62            IN NUMBER
27974 --Distribution Party Site Id
27975  , p_source_63            IN NUMBER
27976 --Distribution Party Type
27977  , p_source_64            IN VARCHAR2
27978 )
27979 IS
27980 
27981 l_component_type              VARCHAR2(80);
27982 l_component_code              VARCHAR2(30);
27983 l_component_type_code         VARCHAR2(1);
27984 l_component_appl_id           INTEGER;
27985 l_amb_context_code            VARCHAR2(30);
27986 l_entity_code                 VARCHAR2(30);
27987 l_event_class_code            VARCHAR2(30);
27988 l_ae_header_id                NUMBER;
27989 l_event_type_code             VARCHAR2(30);
27990 l_line_definition_code        VARCHAR2(30);
27991 l_line_definition_owner_code  VARCHAR2(1);
27992 --
27993 -- adr variables
27994 l_segment                     VARCHAR2(30);
27995 l_ccid                        NUMBER;
27996 l_adr_transaction_coa_id      NUMBER;
27997 l_adr_accounting_coa_id       NUMBER;
27998 l_adr_flexfield_segment_code  VARCHAR2(30);
27999 l_adr_flex_value_set_id       NUMBER;
28000 l_adr_value_type_code         VARCHAR2(30);
28004 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
28001 l_adr_value_combination_id    NUMBER;
28002 l_adr_value_segment_code      VARCHAR2(30);
28003 
28005 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
28006 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
28007 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
28008 
28009 -- 4262811 Variables ------------------------------------------------------------------------------------------
28010 l_entered_amt_idx             NUMBER;
28011 l_accted_amt_idx              NUMBER;
28012 l_acc_rev_flag                VARCHAR2(1);
28013 l_accrual_line_num            NUMBER;
28014 l_tmp_amt                     NUMBER;
28015 l_acc_rev_natural_side_code   VARCHAR2(1);
28016 
28017 l_num_entries                 NUMBER;
28018 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
28019 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
28020 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
28021 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
28022 l_recog_line_1                NUMBER;
28023 l_recog_line_2                NUMBER;
28024 
28025 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
28026 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
28027 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
28028 
28029 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
28030 
28031 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
28032 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
28033 
28034 ---------------------------------------------------------------------------------------------------------------
28035 
28036 
28037 --
28038 -- bulk performance
28039 --
28040 l_balance_type_code           VARCHAR2(1);
28041 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
28042 l_log_module                  VARCHAR2(240);
28043 
28044 --
28045 -- Upgrade strategy
28046 --
28047 l_actual_upg_option           VARCHAR2(1);
28048 l_enc_upg_option           VARCHAR2(1);
28049 
28050 --
28051 BEGIN
28052 --
28053 IF g_log_enabled THEN
28054       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_61';
28055 END IF;
28056 --
28057 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
28058 
28059       trace
28060          (p_msg      => 'BEGIN of AcctLineType_61'
28061          ,p_level    => C_LEVEL_PROCEDURE
28062          ,p_module   => l_log_module);
28063 
28064 END IF;
28065 --
28066 l_component_type             := 'AMB_JLT';
28067 l_component_code             := 'MFAR_RCT_BNK_CHG_CASH';
28068 l_component_type_code        := 'S';
28069 l_component_appl_id          :=  222;
28070 l_amb_context_code           := 'DEFAULT';
28071 l_entity_code                := 'RECEIPTS';
28072 l_event_class_code           := 'RECEIPT';
28073 l_event_type_code            := 'RECEIPT_ALL';
28074 l_line_definition_owner_code := 'S';
28075 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
28076 --
28077 l_balance_type_code          := 'A';
28078 l_segment                     := NULL;
28079 l_ccid                        := NULL;
28080 l_adr_transaction_coa_id      := NULL;
28081 l_adr_accounting_coa_id       := NULL;
28082 l_adr_flexfield_segment_code  := NULL;
28083 l_adr_flex_value_set_id       := NULL;
28084 l_adr_value_type_code         := NULL;
28085 l_adr_value_combination_id    := NULL;
28086 l_adr_value_segment_code      := NULL;
28087 
28088 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
28089 l_bflow_class_code           := '';    -- 4219869 Business Flow
28090 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
28091 l_budgetary_control_flag     := 'N';
28092 
28093 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
28094 l_bflow_applied_to_amt       := NULL; -- 5132302
28095 l_entered_amt_idx            := NULL;          -- 4262811
28096 l_accted_amt_idx             := NULL;          -- 4262811
28097 l_acc_rev_flag               := NULL;          -- 4262811
28098 l_accrual_line_num           := NULL;          -- 4262811
28099 l_tmp_amt                    := NULL;          -- 4262811
28100 --
28101  
28102 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
28103     l_balance_type_code <> 'B' THEN
28104 IF NVL(p_source_13,'
28105 ') =  'BANK_CHARGES' AND 
28106 NVL(p_source_52,'
28107 ') =  'N'
28108  THEN 
28109 
28110    --
28111    XLA_AE_LINES_PKG.SetNewLine;
28112 
28113    p_balance_type_code          := l_balance_type_code;
28114    -- set the flag so later we will know whether the gain loss line needs to be created
28115    
28116    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
28117      p_actual_flag :='A';
28118    END IF;
28119 
28120    --
28121    -- bulk performance
28122    --
28123    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
28124                                       p_header_num   => 0); -- 4262811
28125    --
28126    -- set accounting line options
28127    --
28128    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
28129            p_natural_side_code          => 'D'
28130          , p_gain_or_loss_flag          => 'N'
28131          , p_gl_transfer_mode_code      => 'S'
28135          );
28132          , p_acct_entry_type_code       => 'A'
28133          , p_switch_side_flag           => 'Y'
28134          , p_merge_duplicate_code       => 'A'
28136    --
28137    l_acc_rev_natural_side_code := 'C';  -- 4262811
28138    -- 
28139    --
28140    -- set accounting line type info
28141    --
28142    xla_ae_lines_pkg.SetAcctLineType
28143       (p_component_type             => l_component_type
28144       ,p_event_type_code            => l_event_type_code
28145       ,p_line_definition_owner_code => l_line_definition_owner_code
28146       ,p_line_definition_code       => l_line_definition_code
28147       ,p_accounting_line_code       => l_component_code
28148       ,p_accounting_line_type_code  => l_component_type_code
28149       ,p_accounting_line_appl_id    => l_component_appl_id
28150       ,p_amb_context_code           => l_amb_context_code
28151       ,p_entity_code                => l_entity_code
28152       ,p_event_class_code           => l_event_class_code);
28153    --
28154    -- set accounting class
28155    --
28156    xla_ae_lines_pkg.SetAcctClass(
28157            p_accounting_class_code  => 'CASH'
28158          , p_ae_header_id           => l_ae_header_id
28159          );
28160 
28161    --
28162    -- set rounding class
28163    --
28164    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
28165                       'RECEIVABLE';
28166 
28167    --
28168    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
28169    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
28170    --
28171    -- bulk performance
28172    --
28173    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
28174 
28175    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
28176       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
28177 
28178    -- 4955764
28179    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
28180       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
28181 
28182    -- 4458381 Public Sector Enh
28183    
28184    --
28185    -- set accounting attributes for the line type
28186    --
28187    l_entered_amt_idx := 8;
28188    l_accted_amt_idx  := 13;
28189    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
28190    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
28191    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
28192    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
28193    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
28194    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
28195    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
28196    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
28197    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
28198    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
28199    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
28200    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
28201    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
28202    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
28203    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
28204    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
28205    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
28206    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
28207    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
28208    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
28209    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
28210    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
28211    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
28212    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
28213    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
28214    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
28215    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
28216    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
28217    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
28218    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
28219    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
28220    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
28221    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
28222 
28223    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
28224    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
28225 
28226    ---------------------------------------------------------------------------------------------------------------
28227    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
28228    ---------------------------------------------------------------------------------------------------------------
28229    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
28230 
28231    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
28232    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
28233 
28234    IF xla_accounting_cache_pkg.GetValueChar
28235          (p_source_code         => 'LEDGER_CATEGORY_CODE'
28236          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
28237    AND l_bflow_method_code = 'PRIOR_ENTRY'
28238 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
28242    THEN
28239    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
28240          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
28241        )
28243          xla_ae_lines_pkg.BflowUpgEntry
28244            (p_business_method_code    => l_bflow_method_code
28245            ,p_business_class_code     => l_bflow_class_code
28246            ,p_balance_type            => l_balance_type_code);
28247    ELSE
28248       NULL;
28249 -- No business flow processing for business flow method of NONE.
28250    END IF;
28251 
28252    --
28253    -- call analytical criteria
28254    --
28255    
28256    --
28257    -- call description
28258    --
28259    
28260 xla_ae_lines_pkg.SetLineDescription(
28261    p_ae_header_id => l_ae_header_id
28262   ,p_description  => Description_1 (
28263      p_application_id         => p_application_id
28264    , p_ae_header_id           => l_ae_header_id 
28265    )
28266 );
28267 
28268 
28269    --
28270    -- call ADRs
28271    -- Bug 4922099
28272    --
28273    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
28274         (NVL(l_actual_upg_option, 'N') = 'O') OR
28275         (NVL(l_enc_upg_option, 'N') = 'O')
28276       )
28277    THEN
28278    NULL;
28279    --
28280    --
28281    
28282   l_ccid := AcctDerRule_9(
28283            p_application_id           => p_application_id
28284          , p_ae_header_id             => l_ae_header_id 
28285 , p_source_6 => p_source_6
28286          , x_transaction_coa_id       => l_adr_transaction_coa_id
28287          , x_accounting_coa_id        => l_adr_accounting_coa_id
28288          , x_value_type_code          => l_adr_value_type_code
28289          , p_side                     => 'NA'
28290    );
28291 
28292    xla_ae_lines_pkg.set_ccid(
28293     p_code_combination_id          => l_ccid
28294   , p_value_type_code              => l_adr_value_type_code
28295   , p_transaction_coa_id           => l_adr_transaction_coa_id
28296   , p_accounting_coa_id            => l_adr_accounting_coa_id
28297   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
28298   , p_adr_type_code                => 'S'
28299   , p_component_type               => l_component_type
28300   , p_component_code               => l_component_code
28301   , p_component_type_code          => l_component_type_code
28302   , p_component_appl_id            => l_component_appl_id
28303   , p_amb_context_code             => l_amb_context_code
28304   , p_side                         => 'NA'
28305   );
28306 
28307 
28308    l_segment := AcctDerRule_2(
28309            p_application_id           => p_application_id
28310          , p_ae_header_id             => l_ae_header_id 
28311 , p_source_1 => p_source_1
28312          , x_transaction_coa_id       => l_adr_transaction_coa_id
28313          , x_accounting_coa_id        => l_adr_accounting_coa_id
28314          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
28315          , x_flex_value_set_id        => l_adr_flex_value_set_id
28316          , x_value_type_code          => l_adr_value_type_code
28317          , x_value_combination_id     => l_adr_value_combination_id
28318          , x_value_segment_code       => l_adr_value_segment_code
28319          , p_side                     => 'NA'
28320          , p_override_seg_flag        => 'Y'
28321    );
28322 
28323    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
28324 
28325       xla_ae_lines_pkg.set_segment(
28326           p_to_segment_code         => 'GL_BALANCING'
28327         , p_segment_value           => l_segment
28328         , p_from_segment_code       => l_adr_value_segment_code
28329         , p_from_combination_id     => l_adr_value_combination_id
28330         , p_value_type_code         => l_adr_value_type_code
28331         , p_transaction_coa_id      => l_adr_transaction_coa_id
28332         , p_accounting_coa_id       => l_adr_accounting_coa_id
28333         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
28334         , p_flex_value_set_id       => l_adr_flex_value_set_id
28335         , p_adr_code                => 'MFAR_BNK_CHARGES_BALANCING_SEG'
28336         , p_adr_type_code           => 'S'
28337         , p_component_type          => l_component_type
28338         , p_component_code          => l_component_code
28339         , p_component_type_code     => l_component_type_code
28340         , p_component_appl_id       => l_component_appl_id
28341         , p_amb_context_code        => l_amb_context_code
28342         , p_entity_code             => 'RECEIPTS'
28343         , p_event_class_code        => 'RECEIPT'
28344         , p_side                    => 'NA'
28345         );
28346 
28347   END IF;
28348 
28349    --
28350    --
28351    END IF;
28352    --
28353    -- Bug 4922099
28354    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
28355           (NVL(l_enc_upg_option, 'N') = 'O')
28356         ) AND
28357         (l_bflow_method_code = 'PRIOR_ENTRY')
28358       )
28359    THEN
28360       IF
28361       --
28362       1 = 2
28363       --
28364       THEN
28365       xla_accounting_err_pkg.build_message
28366                                     (p_appli_s_name            => 'XLA'
28367                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
28368                                     ,p_token_1                 => 'LINE_NUMBER'
28369                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
28370                                     ,p_token_2                 => 'LINE_TYPE_NAME'
28371                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
28372                                                                              l_component_type
28376                                                                             ,l_amb_context_code
28373                                                                             ,l_component_code
28374                                                                             ,l_component_type_code
28375                                                                             ,l_component_appl_id
28377                                                                             ,l_entity_code
28378                                                                             ,l_event_class_code
28379                                                                            )
28380                                     ,p_token_3                 => 'OWNER'
28381                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
28382                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
28383                                                                           ,p_lookup_code    => l_component_type_code
28384                                                                          )
28385                                     ,p_token_4                 => 'PRODUCT_NAME'
28386                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
28387                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
28388                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
28389                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
28390                                     ,p_ae_header_id            =>  NULL
28391                                        );
28392 
28393         IF (C_LEVEL_ERROR>= g_log_level) THEN
28394                  trace
28395                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
28396                       ,p_level    => C_LEVEL_ERROR
28397                       ,p_module   => l_log_module);
28398         END IF;
28399       END IF;
28400    END IF;
28401    --
28402    --
28403    ------------------------------------------------------------------------------------------------
28404    -- 4219869 Business Flow
28405    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
28406    -- Prior Entry.  Currently, the following code is always generated.
28407    ------------------------------------------------------------------------------------------------
28408    XLA_AE_LINES_PKG.ValidateCurrentLine;
28409 
28410    ------------------------------------------------------------------------------------
28411    -- 4219869 Business Flow
28412    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
28413    ------------------------------------------------------------------------------------
28414    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
28415 
28416    ----------------------------------------------------------------------------------
28417    -- 4219869 Business Flow
28418    -- Update journal entry status -- Need to generate this within IF <condition>
28419    ----------------------------------------------------------------------------------
28420    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
28421          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
28422          ,p_balance_type_code => l_balance_type_code
28423          );
28424 
28425    -------------------------------------------------------------------------------------------
28426    -- 4262811 - Generate the Accrual Reversal lines
28427    -------------------------------------------------------------------------------------------
28428    BEGIN
28429       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
28430                               (g_array_event(p_event_id).array_value_num('header_index'));
28431       IF l_acc_rev_flag IS NULL THEN
28432          l_acc_rev_flag := 'N';
28433       END IF;
28434    EXCEPTION
28435       WHEN OTHERS THEN
28436          l_acc_rev_flag := 'N';
28437    END;
28438    --
28439    IF (l_acc_rev_flag = 'Y') THEN
28440 
28441        -- 4645092  ------------------------------------------------------------------------------
28442        -- To allow MPA report to determine if it should generate report process
28443        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
28444        ------------------------------------------------------------------------------------------
28445 
28446        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
28447        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
28448    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
28449    -- call ADRs
28450    -- Bug 4922099
28451    --
28452    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
28453         (NVL(l_actual_upg_option, 'N') = 'O') OR
28454         (NVL(l_enc_upg_option, 'N') = 'O')
28455       )
28456    THEN
28457    NULL;
28458    --
28459    --
28460    
28461   l_ccid := AcctDerRule_9(
28465          , x_transaction_coa_id       => l_adr_transaction_coa_id
28462            p_application_id           => p_application_id
28463          , p_ae_header_id             => l_ae_header_id 
28464 , p_source_6 => p_source_6
28466          , x_accounting_coa_id        => l_adr_accounting_coa_id
28467          , x_value_type_code          => l_adr_value_type_code
28468          , p_side                     => 'NA'
28469    );
28470 
28471    xla_ae_lines_pkg.set_ccid(
28472     p_code_combination_id          => l_ccid
28473   , p_value_type_code              => l_adr_value_type_code
28474   , p_transaction_coa_id           => l_adr_transaction_coa_id
28475   , p_accounting_coa_id            => l_adr_accounting_coa_id
28476   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
28477   , p_adr_type_code                => 'S'
28478   , p_component_type               => l_component_type
28479   , p_component_code               => l_component_code
28480   , p_component_type_code          => l_component_type_code
28481   , p_component_appl_id            => l_component_appl_id
28482   , p_amb_context_code             => l_amb_context_code
28483   , p_side                         => 'NA'
28484   );
28485 
28486 
28487    l_segment := AcctDerRule_2(
28488            p_application_id           => p_application_id
28489          , p_ae_header_id             => l_ae_header_id 
28490 , p_source_1 => p_source_1
28491          , x_transaction_coa_id       => l_adr_transaction_coa_id
28492          , x_accounting_coa_id        => l_adr_accounting_coa_id
28493          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
28494          , x_flex_value_set_id        => l_adr_flex_value_set_id
28495          , x_value_type_code          => l_adr_value_type_code
28496          , x_value_combination_id     => l_adr_value_combination_id
28497          , x_value_segment_code       => l_adr_value_segment_code
28498          , p_side                     => 'NA'
28499          , p_override_seg_flag        => 'Y'
28500    );
28501 
28502    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
28503 
28504       xla_ae_lines_pkg.set_segment(
28505           p_to_segment_code         => 'GL_BALANCING'
28506         , p_segment_value           => l_segment
28507         , p_from_segment_code       => l_adr_value_segment_code
28508         , p_from_combination_id     => l_adr_value_combination_id
28509         , p_value_type_code         => l_adr_value_type_code
28510         , p_transaction_coa_id      => l_adr_transaction_coa_id
28511         , p_accounting_coa_id       => l_adr_accounting_coa_id
28512         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
28513         , p_flex_value_set_id       => l_adr_flex_value_set_id
28514         , p_adr_code                => 'MFAR_BNK_CHARGES_BALANCING_SEG'
28515         , p_adr_type_code           => 'S'
28516         , p_component_type          => l_component_type
28517         , p_component_code          => l_component_code
28518         , p_component_type_code     => l_component_type_code
28519         , p_component_appl_id       => l_component_appl_id
28520         , p_amb_context_code        => l_amb_context_code
28521         , p_entity_code             => 'RECEIPTS'
28522         , p_event_class_code        => 'RECEIPT'
28523         , p_side                    => 'NA'
28524         );
28525 
28526   END IF;
28527 
28528    --
28529    --
28530    END IF;
28531 
28532        --
28533        -- Update the line information that should be overwritten
28534        --
28535        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
28536                                          p_header_num   => 1);
28537        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
28538 
28539        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
28540 
28541        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
28542           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
28543        END IF;
28544 
28545       --
28546       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
28547       --
28548       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
28549           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
28550       ELSE
28551           ---------------------------------------------------------------------------------------------------
28552           -- 4262811a Switch Sign
28553           ---------------------------------------------------------------------------------------------------
28554           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
28555           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
28556                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
28557           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
28558                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
28559           -- 5132302
28560           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
28561                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
28562 
28563       END IF;
28564 
28565       -- 4955764
28566       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
28570       XLA_AE_LINES_PKG.ValidateCurrentLine;
28567       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
28568 
28569 
28571       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
28572 
28573       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
28574                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
28575                ,p_balance_type_code => l_balance_type_code);
28576 
28577    END IF;
28578 
28579    -----------------------------------------------------------------------------------------
28580    -- 4262811 Multiperiod Accounting
28581    -----------------------------------------------------------------------------------------
28582      -- No MPA option is assigned.
28583 
28584 
28585 END IF;
28586 END IF;
28587 --
28588 
28589 --
28590 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
28591    trace
28592       (p_msg      => 'END of AcctLineType_61'
28593       ,p_level    => C_LEVEL_PROCEDURE
28594       ,p_module   => l_log_module);
28595 END IF;
28596 --
28597 EXCEPTION
28598   WHEN xla_exceptions_pkg.application_exception THEN
28599       RAISE;
28600   WHEN OTHERS THEN
28601        xla_exceptions_pkg.raise_message
28602            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_61');
28603 END AcctLineType_61;
28604 --
28605 
28606 ---------------------------------------
28607 --
28608 -- PRIVATE FUNCTION
28609 --         AcctLineType_62
28610 --
28611 ---------------------------------------
28612 PROCEDURE AcctLineType_62 (
28613   p_application_id        IN NUMBER
28614  ,p_event_id              IN NUMBER
28615  ,p_calculate_acctd_flag  IN VARCHAR2
28616  ,p_calculate_g_l_flag    IN VARCHAR2
28617  ,p_actual_flag           IN OUT VARCHAR2
28618  ,p_balance_type_code     OUT VARCHAR2
28619  ,p_gain_or_loss_ref      OUT VARCHAR2
28620  
28621 --Remittance Bank Account Cash Account
28622  , p_source_6            IN NUMBER
28623 --Distribution Source Type
28624  , p_source_13            IN VARCHAR2
28625 --Distribution Line Identifier
28626  , p_source_15            IN NUMBER
28627 --Distribution Type
28628  , p_source_16            IN VARCHAR2
28629 --Exchange Date
28630  , p_source_19            IN DATE
28631 --Exchange Rate
28632  , p_source_20            IN NUMBER
28633 --Exchange Rate Type
28634  , p_source_21            IN VARCHAR2
28635 --Transaction Distribution Account Class
28636  , p_source_26            IN VARCHAR2
28637 --Transaction Distribution Identifier
28638  , p_source_27            IN NUMBER
28639 --Transaction Distribution Type
28640  , p_source_28            IN VARCHAR2
28641 --Distribution Multi Fund Additional Entry
28642  , p_source_52            IN VARCHAR2
28643 --Receipt Class Require Remittance Flag
28644  , p_source_54            IN VARCHAR2
28645 --Receipt Class Confirm Flag
28646  , p_source_55            IN VARCHAR2
28647 --Receipt Applied To Application Identifier
28648  , p_source_56            IN NUMBER
28649 --Transaction Entity Code
28650  , p_source_57            IN VARCHAR2
28651 --Transaction Identifier
28652  , p_source_58            IN NUMBER
28653 --DIST_ENT_AMT_FROM
28654  , p_source_59            IN NUMBER
28655 --Applying Document Currency Code
28656  , p_source_60            IN VARCHAR2
28657 --Accounting Amount
28658  , p_source_61            IN NUMBER
28659 --Distribution Party Identifier
28660  , p_source_62            IN NUMBER
28661 --Distribution Party Site Id
28662  , p_source_63            IN NUMBER
28663 --Distribution Party Type
28664  , p_source_64            IN VARCHAR2
28665 )
28666 IS
28667 
28668 l_component_type              VARCHAR2(80);
28669 l_component_code              VARCHAR2(30);
28670 l_component_type_code         VARCHAR2(1);
28671 l_component_appl_id           INTEGER;
28672 l_amb_context_code            VARCHAR2(30);
28673 l_entity_code                 VARCHAR2(30);
28674 l_event_class_code            VARCHAR2(30);
28675 l_ae_header_id                NUMBER;
28676 l_event_type_code             VARCHAR2(30);
28677 l_line_definition_code        VARCHAR2(30);
28678 l_line_definition_owner_code  VARCHAR2(1);
28679 --
28680 -- adr variables
28681 l_segment                     VARCHAR2(30);
28682 l_ccid                        NUMBER;
28683 l_adr_transaction_coa_id      NUMBER;
28684 l_adr_accounting_coa_id       NUMBER;
28685 l_adr_flexfield_segment_code  VARCHAR2(30);
28686 l_adr_flex_value_set_id       NUMBER;
28687 l_adr_value_type_code         VARCHAR2(30);
28688 l_adr_value_combination_id    NUMBER;
28689 l_adr_value_segment_code      VARCHAR2(30);
28690 
28691 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
28692 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
28693 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
28694 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
28695 
28696 -- 4262811 Variables ------------------------------------------------------------------------------------------
28697 l_entered_amt_idx             NUMBER;
28698 l_accted_amt_idx              NUMBER;
28699 l_acc_rev_flag                VARCHAR2(1);
28700 l_accrual_line_num            NUMBER;
28701 l_tmp_amt                     NUMBER;
28702 l_acc_rev_natural_side_code   VARCHAR2(1);
28703 
28704 l_num_entries                 NUMBER;
28708 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
28705 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
28706 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
28707 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
28709 l_recog_line_1                NUMBER;
28710 l_recog_line_2                NUMBER;
28711 
28712 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
28713 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
28714 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
28715 
28716 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
28717 
28718 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
28719 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
28720 
28721 ---------------------------------------------------------------------------------------------------------------
28722 
28723 
28724 --
28725 -- bulk performance
28726 --
28727 l_balance_type_code           VARCHAR2(1);
28728 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
28729 l_log_module                  VARCHAR2(240);
28730 
28731 --
28732 -- Upgrade strategy
28733 --
28734 l_actual_upg_option           VARCHAR2(1);
28735 l_enc_upg_option           VARCHAR2(1);
28736 
28737 --
28738 BEGIN
28739 --
28740 IF g_log_enabled THEN
28741       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_62';
28742 END IF;
28743 --
28744 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
28745 
28746       trace
28747          (p_msg      => 'BEGIN of AcctLineType_62'
28748          ,p_level    => C_LEVEL_PROCEDURE
28749          ,p_module   => l_log_module);
28750 
28751 END IF;
28752 --
28753 l_component_type             := 'AMB_JLT';
28754 l_component_code             := 'MFAR_RCT_CASH_REVERSE';
28755 l_component_type_code        := 'S';
28756 l_component_appl_id          :=  222;
28757 l_amb_context_code           := 'DEFAULT';
28758 l_entity_code                := 'RECEIPTS';
28759 l_event_class_code           := 'RECEIPT';
28760 l_event_type_code            := 'RECEIPT_ALL';
28761 l_line_definition_owner_code := 'S';
28762 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
28763 --
28764 l_balance_type_code          := 'A';
28765 l_segment                     := NULL;
28766 l_ccid                        := NULL;
28767 l_adr_transaction_coa_id      := NULL;
28768 l_adr_accounting_coa_id       := NULL;
28769 l_adr_flexfield_segment_code  := NULL;
28770 l_adr_flex_value_set_id       := NULL;
28771 l_adr_value_type_code         := NULL;
28772 l_adr_value_combination_id    := NULL;
28773 l_adr_value_segment_code      := NULL;
28774 
28775 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
28776 l_bflow_class_code           := '';    -- 4219869 Business Flow
28777 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
28778 l_budgetary_control_flag     := 'N';
28779 
28780 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
28781 l_bflow_applied_to_amt       := NULL; -- 5132302
28782 l_entered_amt_idx            := NULL;          -- 4262811
28783 l_accted_amt_idx             := NULL;          -- 4262811
28784 l_acc_rev_flag               := NULL;          -- 4262811
28785 l_accrual_line_num           := NULL;          -- 4262811
28786 l_tmp_amt                    := NULL;          -- 4262811
28787 --
28788  
28789 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
28790     l_balance_type_code <> 'B' THEN
28791 IF (NVL(p_source_26,'
28792 ') =  'REV' OR 
28793 NVL(p_source_26,'
28794 ') =  'TAX' OR 
28795 NVL(p_source_26,'
28796 ') =  'FREIGHT' OR 
28797 NVL(p_source_26,'
28798 ') =  'CHARGES' OR 
28799 NVL(p_source_26,'
28800 ') =  'ROUND') AND 
28801 NVL(p_source_13,'
28802 ') =  'REC' AND 
28803 NVL(p_source_52,'
28804 ') =  'N' AND 
28805 NVL(p_source_54,'
28806 ') =  'N' AND 
28807 NVL(p_source_55,'
28808 ') =  'N'
28809  THEN 
28810 
28811    --
28812    XLA_AE_LINES_PKG.SetNewLine;
28813 
28814    p_balance_type_code          := l_balance_type_code;
28815    -- set the flag so later we will know whether the gain loss line needs to be created
28816    
28817    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
28818      p_actual_flag :='A';
28819    END IF;
28820 
28821    --
28822    -- bulk performance
28823    --
28824    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
28825                                       p_header_num   => 0); -- 4262811
28826    --
28827    -- set accounting line options
28828    --
28829    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
28830            p_natural_side_code          => 'C'
28831          , p_gain_or_loss_flag          => 'N'
28832          , p_gl_transfer_mode_code      => 'S'
28833          , p_acct_entry_type_code       => 'A'
28834          , p_switch_side_flag           => 'Y'
28835          , p_merge_duplicate_code       => 'A'
28836          );
28837    --
28838    l_acc_rev_natural_side_code := 'D';  -- 4262811
28839    -- 
28840    --
28841    -- set accounting line type info
28842    --
28843    xla_ae_lines_pkg.SetAcctLineType
28847       ,p_line_definition_code       => l_line_definition_code
28844       (p_component_type             => l_component_type
28845       ,p_event_type_code            => l_event_type_code
28846       ,p_line_definition_owner_code => l_line_definition_owner_code
28848       ,p_accounting_line_code       => l_component_code
28849       ,p_accounting_line_type_code  => l_component_type_code
28850       ,p_accounting_line_appl_id    => l_component_appl_id
28851       ,p_amb_context_code           => l_amb_context_code
28852       ,p_entity_code                => l_entity_code
28853       ,p_event_class_code           => l_event_class_code);
28854    --
28855    -- set accounting class
28856    --
28857    xla_ae_lines_pkg.SetAcctClass(
28858            p_accounting_class_code  => 'CASH'
28859          , p_ae_header_id           => l_ae_header_id
28860          );
28861 
28862    --
28863    -- set rounding class
28864    --
28865    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
28866                       'RECEIVABLE';
28867 
28868    --
28869    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
28870    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
28871    --
28872    -- bulk performance
28873    --
28874    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
28875 
28876    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
28877       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
28878 
28879    -- 4955764
28880    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
28881       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
28882 
28883    -- 4458381 Public Sector Enh
28884    
28885    --
28886    -- set accounting attributes for the line type
28887    --
28888    l_entered_amt_idx := 8;
28889    l_accted_amt_idx  := 13;
28890    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
28891    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
28892    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
28893    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
28894    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
28895    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
28896    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
28897    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
28898    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
28899    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
28900    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
28901    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
28902    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
28903    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
28904    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
28905    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
28906    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
28907    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
28908    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
28909    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
28910    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
28911    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
28912    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
28913    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
28914    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
28915    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
28916    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
28917    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
28918    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
28919    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
28920    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
28921    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
28925    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
28922    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
28923 
28924    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
28926 
28927    ---------------------------------------------------------------------------------------------------------------
28928    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
28929    ---------------------------------------------------------------------------------------------------------------
28930    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
28931 
28932    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
28933    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
28934 
28935    IF xla_accounting_cache_pkg.GetValueChar
28936          (p_source_code         => 'LEDGER_CATEGORY_CODE'
28937          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
28938    AND l_bflow_method_code = 'PRIOR_ENTRY'
28939 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
28940    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
28941          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
28942        )
28943    THEN
28944          xla_ae_lines_pkg.BflowUpgEntry
28945            (p_business_method_code    => l_bflow_method_code
28946            ,p_business_class_code     => l_bflow_class_code
28947            ,p_balance_type            => l_balance_type_code);
28948    ELSE
28949       NULL;
28950 -- No business flow processing for business flow method of NONE.
28951    END IF;
28952 
28953    --
28954    -- call analytical criteria
28955    --
28956    
28957    --
28958    -- call description
28959    --
28960    
28961 xla_ae_lines_pkg.SetLineDescription(
28962    p_ae_header_id => l_ae_header_id
28963   ,p_description  => Description_1 (
28964      p_application_id         => p_application_id
28965    , p_ae_header_id           => l_ae_header_id 
28966    )
28967 );
28968 
28969 
28970    --
28971    -- call ADRs
28972    -- Bug 4922099
28973    --
28974    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
28975         (NVL(l_actual_upg_option, 'N') = 'O') OR
28976         (NVL(l_enc_upg_option, 'N') = 'O')
28977       )
28978    THEN
28979    NULL;
28980    --
28981    --
28982    
28983   l_ccid := AcctDerRule_9(
28984            p_application_id           => p_application_id
28985          , p_ae_header_id             => l_ae_header_id 
28986 , p_source_6 => p_source_6
28987          , x_transaction_coa_id       => l_adr_transaction_coa_id
28988          , x_accounting_coa_id        => l_adr_accounting_coa_id
28989          , x_value_type_code          => l_adr_value_type_code
28990          , p_side                     => 'NA'
28991    );
28992 
28993    xla_ae_lines_pkg.set_ccid(
28994     p_code_combination_id          => l_ccid
28995   , p_value_type_code              => l_adr_value_type_code
28996   , p_transaction_coa_id           => l_adr_transaction_coa_id
28997   , p_accounting_coa_id            => l_adr_accounting_coa_id
28998   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
28999   , p_adr_type_code                => 'S'
29000   , p_component_type               => l_component_type
29001   , p_component_code               => l_component_code
29002   , p_component_type_code          => l_component_type_code
29003   , p_component_appl_id            => l_component_appl_id
29004   , p_amb_context_code             => l_amb_context_code
29005   , p_side                         => 'NA'
29006   );
29007 
29008 
29009    --
29010    --
29011    END IF;
29012    --
29013    -- Bug 4922099
29014    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
29015           (NVL(l_enc_upg_option, 'N') = 'O')
29016         ) AND
29017         (l_bflow_method_code = 'PRIOR_ENTRY')
29018       )
29019    THEN
29020       IF
29021       --
29022       1 = 2
29023       --
29024       THEN
29025       xla_accounting_err_pkg.build_message
29026                                     (p_appli_s_name            => 'XLA'
29027                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
29028                                     ,p_token_1                 => 'LINE_NUMBER'
29029                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
29030                                     ,p_token_2                 => 'LINE_TYPE_NAME'
29031                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
29032                                                                              l_component_type
29036                                                                             ,l_amb_context_code
29033                                                                             ,l_component_code
29034                                                                             ,l_component_type_code
29035                                                                             ,l_component_appl_id
29037                                                                             ,l_entity_code
29038                                                                             ,l_event_class_code
29039                                                                            )
29040                                     ,p_token_3                 => 'OWNER'
29041                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
29042                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
29043                                                                           ,p_lookup_code    => l_component_type_code
29044                                                                          )
29045                                     ,p_token_4                 => 'PRODUCT_NAME'
29046                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
29047                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
29048                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
29049                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
29050                                     ,p_ae_header_id            =>  NULL
29051                                        );
29052 
29053         IF (C_LEVEL_ERROR>= g_log_level) THEN
29054                  trace
29055                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
29056                       ,p_level    => C_LEVEL_ERROR
29057                       ,p_module   => l_log_module);
29058         END IF;
29059       END IF;
29060    END IF;
29061    --
29062    --
29063    ------------------------------------------------------------------------------------------------
29064    -- 4219869 Business Flow
29065    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
29066    -- Prior Entry.  Currently, the following code is always generated.
29067    ------------------------------------------------------------------------------------------------
29068    XLA_AE_LINES_PKG.ValidateCurrentLine;
29069 
29070    ------------------------------------------------------------------------------------
29071    -- 4219869 Business Flow
29072    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
29073    ------------------------------------------------------------------------------------
29074    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
29075 
29076    ----------------------------------------------------------------------------------
29077    -- 4219869 Business Flow
29078    -- Update journal entry status -- Need to generate this within IF <condition>
29079    ----------------------------------------------------------------------------------
29080    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
29081          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
29082          ,p_balance_type_code => l_balance_type_code
29083          );
29084 
29085    -------------------------------------------------------------------------------------------
29086    -- 4262811 - Generate the Accrual Reversal lines
29087    -------------------------------------------------------------------------------------------
29088    BEGIN
29089       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
29090                               (g_array_event(p_event_id).array_value_num('header_index'));
29091       IF l_acc_rev_flag IS NULL THEN
29092          l_acc_rev_flag := 'N';
29093       END IF;
29094    EXCEPTION
29095       WHEN OTHERS THEN
29096          l_acc_rev_flag := 'N';
29097    END;
29098    --
29099    IF (l_acc_rev_flag = 'Y') THEN
29100 
29101        -- 4645092  ------------------------------------------------------------------------------
29102        -- To allow MPA report to determine if it should generate report process
29103        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
29104        ------------------------------------------------------------------------------------------
29105 
29106        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
29107        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
29108    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
29109    -- call ADRs
29110    -- Bug 4922099
29111    --
29112    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
29113         (NVL(l_actual_upg_option, 'N') = 'O') OR
29114         (NVL(l_enc_upg_option, 'N') = 'O')
29115       )
29116    THEN
29117    NULL;
29118    --
29119    --
29120    
29121   l_ccid := AcctDerRule_9(
29122            p_application_id           => p_application_id
29123          , p_ae_header_id             => l_ae_header_id 
29124 , p_source_6 => p_source_6
29125          , x_transaction_coa_id       => l_adr_transaction_coa_id
29126          , x_accounting_coa_id        => l_adr_accounting_coa_id
29127          , x_value_type_code          => l_adr_value_type_code
29128          , p_side                     => 'NA'
29129    );
29130 
29131    xla_ae_lines_pkg.set_ccid(
29132     p_code_combination_id          => l_ccid
29133   , p_value_type_code              => l_adr_value_type_code
29134   , p_transaction_coa_id           => l_adr_transaction_coa_id
29135   , p_accounting_coa_id            => l_adr_accounting_coa_id
29136   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
29140   , p_component_type_code          => l_component_type_code
29137   , p_adr_type_code                => 'S'
29138   , p_component_type               => l_component_type
29139   , p_component_code               => l_component_code
29141   , p_component_appl_id            => l_component_appl_id
29142   , p_amb_context_code             => l_amb_context_code
29143   , p_side                         => 'NA'
29144   );
29145 
29146 
29147    --
29148    --
29149    END IF;
29150 
29151        --
29152        -- Update the line information that should be overwritten
29153        --
29154        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
29155                                          p_header_num   => 1);
29156        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
29157 
29158        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
29159 
29160        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
29161           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
29162        END IF;
29163 
29164       --
29165       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
29166       --
29167       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
29168           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
29169       ELSE
29170           ---------------------------------------------------------------------------------------------------
29171           -- 4262811a Switch Sign
29172           ---------------------------------------------------------------------------------------------------
29173           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
29174           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
29175                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
29176           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
29177                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
29178           -- 5132302
29179           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
29180                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
29181 
29182       END IF;
29183 
29184       -- 4955764
29185       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
29186       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
29187 
29188 
29189       XLA_AE_LINES_PKG.ValidateCurrentLine;
29190       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
29191 
29192       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
29193                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
29194                ,p_balance_type_code => l_balance_type_code);
29195 
29196    END IF;
29197 
29198    -----------------------------------------------------------------------------------------
29199    -- 4262811 Multiperiod Accounting
29203 
29200    -----------------------------------------------------------------------------------------
29201      -- No MPA option is assigned.
29202 
29204 END IF;
29205 END IF;
29206 --
29207 
29208 --
29209 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
29210    trace
29211       (p_msg      => 'END of AcctLineType_62'
29212       ,p_level    => C_LEVEL_PROCEDURE
29213       ,p_module   => l_log_module);
29214 END IF;
29215 --
29216 EXCEPTION
29217   WHEN xla_exceptions_pkg.application_exception THEN
29218       RAISE;
29219   WHEN OTHERS THEN
29220        xla_exceptions_pkg.raise_message
29221            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_62');
29222 END AcctLineType_62;
29223 --
29224 
29225 ---------------------------------------
29226 --
29227 -- PRIVATE FUNCTION
29228 --         AcctLineType_63
29229 --
29230 ---------------------------------------
29231 PROCEDURE AcctLineType_63 (
29232   p_application_id        IN NUMBER
29233  ,p_event_id              IN NUMBER
29234  ,p_calculate_acctd_flag  IN VARCHAR2
29235  ,p_calculate_g_l_flag    IN VARCHAR2
29236  ,p_actual_flag           IN OUT VARCHAR2
29237  ,p_balance_type_code     OUT VARCHAR2
29238  ,p_gain_or_loss_ref      OUT VARCHAR2
29239  
29240 --Remittance Bank Account Cash Account
29241  , p_source_6            IN NUMBER
29242 --Distribution Source Type
29243  , p_source_13            IN VARCHAR2
29244 --Distribution Line Identifier
29245  , p_source_15            IN NUMBER
29246 --Distribution Type
29247  , p_source_16            IN VARCHAR2
29248 --Exchange Date
29249  , p_source_19            IN DATE
29250 --Exchange Rate
29251  , p_source_20            IN NUMBER
29252 --Exchange Rate Type
29253  , p_source_21            IN VARCHAR2
29254 --Transaction Distribution Identifier
29255  , p_source_27            IN NUMBER
29256 --Transaction Distribution Type
29257  , p_source_28            IN VARCHAR2
29258 --Distribution Multi Fund Additional Entry
29259  , p_source_52            IN VARCHAR2
29260 --Receipt Class Require Remittance Flag
29261  , p_source_54            IN VARCHAR2
29262 --Receipt Applied To Application Identifier
29263  , p_source_56            IN NUMBER
29264 --Transaction Entity Code
29265  , p_source_57            IN VARCHAR2
29266 --Transaction Identifier
29267  , p_source_58            IN NUMBER
29268 --DIST_ENT_AMT_FROM
29269  , p_source_59            IN NUMBER
29270 --Applying Document Currency Code
29271  , p_source_60            IN VARCHAR2
29272 --Accounting Amount
29273  , p_source_61            IN NUMBER
29274 --Distribution Party Identifier
29275  , p_source_62            IN NUMBER
29276 --Distribution Party Site Id
29277  , p_source_63            IN NUMBER
29278 --Distribution Party Type
29279  , p_source_64            IN VARCHAR2
29280 )
29281 IS
29282 
29283 l_component_type              VARCHAR2(80);
29284 l_component_code              VARCHAR2(30);
29285 l_component_type_code         VARCHAR2(1);
29286 l_component_appl_id           INTEGER;
29287 l_amb_context_code            VARCHAR2(30);
29288 l_entity_code                 VARCHAR2(30);
29289 l_event_class_code            VARCHAR2(30);
29290 l_ae_header_id                NUMBER;
29291 l_event_type_code             VARCHAR2(30);
29292 l_line_definition_code        VARCHAR2(30);
29293 l_line_definition_owner_code  VARCHAR2(1);
29294 --
29295 -- adr variables
29296 l_segment                     VARCHAR2(30);
29297 l_ccid                        NUMBER;
29298 l_adr_transaction_coa_id      NUMBER;
29299 l_adr_accounting_coa_id       NUMBER;
29300 l_adr_flexfield_segment_code  VARCHAR2(30);
29301 l_adr_flex_value_set_id       NUMBER;
29302 l_adr_value_type_code         VARCHAR2(30);
29303 l_adr_value_combination_id    NUMBER;
29304 l_adr_value_segment_code      VARCHAR2(30);
29305 
29306 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
29307 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
29308 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
29309 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
29310 
29311 -- 4262811 Variables ------------------------------------------------------------------------------------------
29312 l_entered_amt_idx             NUMBER;
29313 l_accted_amt_idx              NUMBER;
29314 l_acc_rev_flag                VARCHAR2(1);
29315 l_accrual_line_num            NUMBER;
29316 l_tmp_amt                     NUMBER;
29317 l_acc_rev_natural_side_code   VARCHAR2(1);
29318 
29319 l_num_entries                 NUMBER;
29320 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
29321 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
29322 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
29323 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
29324 l_recog_line_1                NUMBER;
29325 l_recog_line_2                NUMBER;
29326 
29327 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
29328 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
29329 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
29330 
29331 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
29332 
29333 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
29334 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
29335 
29339 --
29336 ---------------------------------------------------------------------------------------------------------------
29337 
29338 
29340 -- bulk performance
29341 --
29342 l_balance_type_code           VARCHAR2(1);
29343 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
29344 l_log_module                  VARCHAR2(240);
29345 
29346 --
29347 -- Upgrade strategy
29348 --
29349 l_actual_upg_option           VARCHAR2(1);
29350 l_enc_upg_option           VARCHAR2(1);
29351 
29352 --
29353 BEGIN
29354 --
29355 IF g_log_enabled THEN
29356       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_63';
29357 END IF;
29358 --
29359 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
29360 
29361       trace
29362          (p_msg      => 'BEGIN of AcctLineType_63'
29363          ,p_level    => C_LEVEL_PROCEDURE
29364          ,p_module   => l_log_module);
29365 
29366 END IF;
29367 --
29368 l_component_type             := 'AMB_JLT';
29369 l_component_code             := 'MFAR_RCT_CM_CASH_REVERSAL';
29370 l_component_type_code        := 'S';
29371 l_component_appl_id          :=  222;
29372 l_amb_context_code           := 'DEFAULT';
29373 l_entity_code                := 'RECEIPTS';
29374 l_event_class_code           := 'RECEIPT';
29375 l_event_type_code            := 'RECEIPT_ALL';
29376 l_line_definition_owner_code := 'S';
29377 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
29378 --
29379 l_balance_type_code          := 'A';
29380 l_segment                     := NULL;
29381 l_ccid                        := NULL;
29382 l_adr_transaction_coa_id      := NULL;
29383 l_adr_accounting_coa_id       := NULL;
29384 l_adr_flexfield_segment_code  := NULL;
29385 l_adr_flex_value_set_id       := NULL;
29386 l_adr_value_type_code         := NULL;
29387 l_adr_value_combination_id    := NULL;
29388 l_adr_value_segment_code      := NULL;
29389 
29390 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
29391 l_bflow_class_code           := '';    -- 4219869 Business Flow
29392 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
29393 l_budgetary_control_flag     := 'N';
29394 
29395 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
29396 l_bflow_applied_to_amt       := NULL; -- 5132302
29397 l_entered_amt_idx            := NULL;          -- 4262811
29398 l_accted_amt_idx             := NULL;          -- 4262811
29399 l_acc_rev_flag               := NULL;          -- 4262811
29400 l_accrual_line_num           := NULL;          -- 4262811
29401 l_tmp_amt                    := NULL;          -- 4262811
29402 --
29403  
29404 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
29405     l_balance_type_code <> 'B' THEN
29406 IF NVL(p_source_13,'
29407 ') =  'CASH' AND 
29408 NVL(p_source_52,'
29409 ') =  'Y' AND 
29410 NVL(p_source_54,'
29411 ') =  'Y'
29412  THEN 
29413 
29414    --
29415    XLA_AE_LINES_PKG.SetNewLine;
29416 
29417    p_balance_type_code          := l_balance_type_code;
29418    -- set the flag so later we will know whether the gain loss line needs to be created
29419    
29420    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
29421      p_actual_flag :='A';
29422    END IF;
29423 
29424    --
29425    -- bulk performance
29426    --
29427    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
29428                                       p_header_num   => 0); -- 4262811
29429    --
29430    -- set accounting line options
29431    --
29432    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
29433            p_natural_side_code          => 'D'
29434          , p_gain_or_loss_flag          => 'N'
29435          , p_gl_transfer_mode_code      => 'S'
29436          , p_acct_entry_type_code       => 'A'
29437          , p_switch_side_flag           => 'Y'
29438          , p_merge_duplicate_code       => 'A'
29439          );
29440    --
29441    l_acc_rev_natural_side_code := 'C';  -- 4262811
29442    -- 
29443    --
29444    -- set accounting line type info
29445    --
29446    xla_ae_lines_pkg.SetAcctLineType
29447       (p_component_type             => l_component_type
29448       ,p_event_type_code            => l_event_type_code
29449       ,p_line_definition_owner_code => l_line_definition_owner_code
29450       ,p_line_definition_code       => l_line_definition_code
29451       ,p_accounting_line_code       => l_component_code
29452       ,p_accounting_line_type_code  => l_component_type_code
29453       ,p_accounting_line_appl_id    => l_component_appl_id
29454       ,p_amb_context_code           => l_amb_context_code
29455       ,p_entity_code                => l_entity_code
29456       ,p_event_class_code           => l_event_class_code);
29457    --
29458    -- set accounting class
29459    --
29460    xla_ae_lines_pkg.SetAcctClass(
29461            p_accounting_class_code  => 'CASH'
29462          , p_ae_header_id           => l_ae_header_id
29463          );
29464 
29465    --
29466    -- set rounding class
29467    --
29468    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
29469                       'RECEIVABLE';
29470 
29471    --
29472    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
29473    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
29474    --
29475    -- bulk performance
29476    --
29477    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
29478 
29482    -- 4955764
29479    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
29480       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
29481 
29483    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
29484       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
29485 
29486    -- 4458381 Public Sector Enh
29487    
29488    --
29489    -- set accounting attributes for the line type
29490    --
29491    l_entered_amt_idx := 8;
29492    l_accted_amt_idx  := 13;
29493    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
29494    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
29495    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
29496    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
29497    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
29498    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
29499    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
29500    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
29501    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
29502    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
29503    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
29504    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
29505    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
29506    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
29507    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
29508    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
29509    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
29510    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
29511    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
29512    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
29513    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
29514    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
29515    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
29516    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
29517    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
29518    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
29519    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
29520    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
29521    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
29522    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
29523    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
29524    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
29525    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
29526 
29527    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
29528    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
29529 
29530    ---------------------------------------------------------------------------------------------------------------
29531    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
29532    ---------------------------------------------------------------------------------------------------------------
29533    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
29534 
29535    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
29536    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
29537 
29538    IF xla_accounting_cache_pkg.GetValueChar
29539          (p_source_code         => 'LEDGER_CATEGORY_CODE'
29540          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
29541    AND l_bflow_method_code = 'PRIOR_ENTRY'
29542 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
29543    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
29544          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
29545        )
29546    THEN
29547          xla_ae_lines_pkg.BflowUpgEntry
29548            (p_business_method_code    => l_bflow_method_code
29549            ,p_business_class_code     => l_bflow_class_code
29550            ,p_balance_type            => l_balance_type_code);
29551    ELSE
29552       NULL;
29553 -- No business flow processing for business flow method of NONE.
29554    END IF;
29555 
29556    --
29557    -- call analytical criteria
29558    --
29559    
29560    --
29561    -- call description
29562    --
29563    
29564 xla_ae_lines_pkg.SetLineDescription(
29565    p_ae_header_id => l_ae_header_id
29566   ,p_description  => Description_1 (
29567      p_application_id         => p_application_id
29568    , p_ae_header_id           => l_ae_header_id 
29569    )
29570 );
29571 
29572 
29573    --
29574    -- call ADRs
29575    -- Bug 4922099
29576    --
29577    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
29578         (NVL(l_actual_upg_option, 'N') = 'O') OR
29579         (NVL(l_enc_upg_option, 'N') = 'O')
29580       )
29581    THEN
29582    NULL;
29583    --
29584    --
29585    
29586   l_ccid := AcctDerRule_9(
29587            p_application_id           => p_application_id
29588          , p_ae_header_id             => l_ae_header_id 
29589 , p_source_6 => p_source_6
29590          , x_transaction_coa_id       => l_adr_transaction_coa_id
29591          , x_accounting_coa_id        => l_adr_accounting_coa_id
29592          , x_value_type_code          => l_adr_value_type_code
29593          , p_side                     => 'NA'
29594    );
29595 
29596    xla_ae_lines_pkg.set_ccid(
29597     p_code_combination_id          => l_ccid
29598   , p_value_type_code              => l_adr_value_type_code
29599   , p_transaction_coa_id           => l_adr_transaction_coa_id
29600   , p_accounting_coa_id            => l_adr_accounting_coa_id
29601   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
29602   , p_adr_type_code                => 'S'
29603   , p_component_type               => l_component_type
29604   , p_component_code               => l_component_code
29605   , p_component_type_code          => l_component_type_code
29606   , p_component_appl_id            => l_component_appl_id
29607   , p_amb_context_code             => l_amb_context_code
29608   , p_side                         => 'NA'
29609   );
29610 
29611 
29612    --
29613    --
29614    END IF;
29615    --
29616    -- Bug 4922099
29617    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
29618           (NVL(l_enc_upg_option, 'N') = 'O')
29619         ) AND
29620         (l_bflow_method_code = 'PRIOR_ENTRY')
29621       )
29622    THEN
29623       IF
29624       --
29625       1 = 2
29626       --
29627       THEN
29628       xla_accounting_err_pkg.build_message
29629                                     (p_appli_s_name            => 'XLA'
29630                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
29631                                     ,p_token_1                 => 'LINE_NUMBER'
29632                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
29633                                     ,p_token_2                 => 'LINE_TYPE_NAME'
29634                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
29635                                                                              l_component_type
29636                                                                             ,l_component_code
29637                                                                             ,l_component_type_code
29638                                                                             ,l_component_appl_id
29639                                                                             ,l_amb_context_code
29640                                                                             ,l_entity_code
29641                                                                             ,l_event_class_code
29642                                                                            )
29643                                     ,p_token_3                 => 'OWNER'
29644                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
29645                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
29646                                                                           ,p_lookup_code    => l_component_type_code
29647                                                                          )
29648                                     ,p_token_4                 => 'PRODUCT_NAME'
29649                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
29650                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
29651                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
29652                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
29653                                     ,p_ae_header_id            =>  NULL
29654                                        );
29655 
29656         IF (C_LEVEL_ERROR>= g_log_level) THEN
29657                  trace
29658                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
29659                       ,p_level    => C_LEVEL_ERROR
29660                       ,p_module   => l_log_module);
29661         END IF;
29662       END IF;
29663    END IF;
29664    --
29665    --
29666    ------------------------------------------------------------------------------------------------
29667    -- 4219869 Business Flow
29668    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
29669    -- Prior Entry.  Currently, the following code is always generated.
29670    ------------------------------------------------------------------------------------------------
29671    XLA_AE_LINES_PKG.ValidateCurrentLine;
29672 
29673    ------------------------------------------------------------------------------------
29674    -- 4219869 Business Flow
29675    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
29676    ------------------------------------------------------------------------------------
29677    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
29678 
29679    ----------------------------------------------------------------------------------
29680    -- 4219869 Business Flow
29681    -- Update journal entry status -- Need to generate this within IF <condition>
29682    ----------------------------------------------------------------------------------
29683    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
29684          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
29685          ,p_balance_type_code => l_balance_type_code
29686          );
29687 
29688    -------------------------------------------------------------------------------------------
29689    -- 4262811 - Generate the Accrual Reversal lines
29690    -------------------------------------------------------------------------------------------
29691    BEGIN
29692       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
29693                               (g_array_event(p_event_id).array_value_num('header_index'));
29694       IF l_acc_rev_flag IS NULL THEN
29695          l_acc_rev_flag := 'N';
29696       END IF;
29697    EXCEPTION
29698       WHEN OTHERS THEN
29699          l_acc_rev_flag := 'N';
29700    END;
29701    --
29702    IF (l_acc_rev_flag = 'Y') THEN
29703 
29704        -- 4645092  ------------------------------------------------------------------------------
29705        -- To allow MPA report to determine if it should generate report process
29706        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
29707        ------------------------------------------------------------------------------------------
29708 
29709        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
29710        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
29711    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
29712    -- call ADRs
29713    -- Bug 4922099
29714    --
29715    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
29716         (NVL(l_actual_upg_option, 'N') = 'O') OR
29717         (NVL(l_enc_upg_option, 'N') = 'O')
29718       )
29719    THEN
29720    NULL;
29721    --
29722    --
29723    
29724   l_ccid := AcctDerRule_9(
29725            p_application_id           => p_application_id
29726          , p_ae_header_id             => l_ae_header_id 
29727 , p_source_6 => p_source_6
29728          , x_transaction_coa_id       => l_adr_transaction_coa_id
29729          , x_accounting_coa_id        => l_adr_accounting_coa_id
29730          , x_value_type_code          => l_adr_value_type_code
29731          , p_side                     => 'NA'
29732    );
29733 
29734    xla_ae_lines_pkg.set_ccid(
29735     p_code_combination_id          => l_ccid
29736   , p_value_type_code              => l_adr_value_type_code
29737   , p_transaction_coa_id           => l_adr_transaction_coa_id
29738   , p_accounting_coa_id            => l_adr_accounting_coa_id
29739   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
29740   , p_adr_type_code                => 'S'
29741   , p_component_type               => l_component_type
29742   , p_component_code               => l_component_code
29743   , p_component_type_code          => l_component_type_code
29744   , p_component_appl_id            => l_component_appl_id
29745   , p_amb_context_code             => l_amb_context_code
29746   , p_side                         => 'NA'
29747   );
29748 
29749 
29750    --
29751    --
29752    END IF;
29753 
29754        --
29755        -- Update the line information that should be overwritten
29756        --
29757        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
29758                                          p_header_num   => 1);
29759        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
29760 
29761        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
29762 
29763        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
29764           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
29765        END IF;
29766 
29767       --
29768       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
29769       --
29770       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
29771           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
29772       ELSE
29773           ---------------------------------------------------------------------------------------------------
29774           -- 4262811a Switch Sign
29775           ---------------------------------------------------------------------------------------------------
29776           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
29777           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
29778                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
29779           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
29780                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
29781           -- 5132302
29782           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
29783                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
29784 
29785       END IF;
29786 
29787       -- 4955764
29788       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
29789       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
29790 
29791 
29792       XLA_AE_LINES_PKG.ValidateCurrentLine;
29793       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
29794 
29795       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
29796                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
29797                ,p_balance_type_code => l_balance_type_code);
29798 
29799    END IF;
29800 
29801    -----------------------------------------------------------------------------------------
29802    -- 4262811 Multiperiod Accounting
29803    -----------------------------------------------------------------------------------------
29804      -- No MPA option is assigned.
29805 
29806 
29807 END IF;
29808 END IF;
29809 --
29810 
29811 --
29812 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
29813    trace
29814       (p_msg      => 'END of AcctLineType_63'
29815       ,p_level    => C_LEVEL_PROCEDURE
29816       ,p_module   => l_log_module);
29817 END IF;
29818 --
29819 EXCEPTION
29820   WHEN xla_exceptions_pkg.application_exception THEN
29821       RAISE;
29822   WHEN OTHERS THEN
29823        xla_exceptions_pkg.raise_message
29824            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_63');
29825 END AcctLineType_63;
29826 --
29827 
29828 ---------------------------------------
29829 --
29830 -- PRIVATE FUNCTION
29831 --         AcctLineType_64
29832 --
29833 ---------------------------------------
29834 PROCEDURE AcctLineType_64 (
29835   p_application_id        IN NUMBER
29836  ,p_event_id              IN NUMBER
29837  ,p_calculate_acctd_flag  IN VARCHAR2
29838  ,p_calculate_g_l_flag    IN VARCHAR2
29839  ,p_actual_flag           IN OUT VARCHAR2
29840  ,p_balance_type_code     OUT VARCHAR2
29841  ,p_gain_or_loss_ref      OUT VARCHAR2
29842  
29843 --Remittance Bank Account Confirmation Account
29844  , p_source_7            IN NUMBER
29845 --Distribution Source Type
29846  , p_source_13            IN VARCHAR2
29847 --Distribution Line Identifier
29848  , p_source_15            IN NUMBER
29849 --Distribution Type
29850  , p_source_16            IN VARCHAR2
29851 --Exchange Date
29852  , p_source_19            IN DATE
29853 --Exchange Rate
29854  , p_source_20            IN NUMBER
29855 --Exchange Rate Type
29856  , p_source_21            IN VARCHAR2
29857 --Transaction Distribution Identifier
29858  , p_source_27            IN NUMBER
29859 --Transaction Distribution Type
29860  , p_source_28            IN VARCHAR2
29861 --Distribution Multi Fund Additional Entry
29862  , p_source_52            IN VARCHAR2
29863 --Receipt Applied To Application Identifier
29864  , p_source_56            IN NUMBER
29865 --Transaction Entity Code
29866  , p_source_57            IN VARCHAR2
29867 --Transaction Identifier
29868  , p_source_58            IN NUMBER
29869 --DIST_ENT_AMT_FROM
29870  , p_source_59            IN NUMBER
29871 --Applying Document Currency Code
29872  , p_source_60            IN VARCHAR2
29873 --Accounting Amount
29874  , p_source_61            IN NUMBER
29875 --Distribution Party Identifier
29876  , p_source_62            IN NUMBER
29877 --Distribution Party Site Id
29878  , p_source_63            IN NUMBER
29879 --Distribution Party Type
29880  , p_source_64            IN VARCHAR2
29881 )
29882 IS
29883 
29884 l_component_type              VARCHAR2(80);
29885 l_component_code              VARCHAR2(30);
29886 l_component_type_code         VARCHAR2(1);
29887 l_component_appl_id           INTEGER;
29888 l_amb_context_code            VARCHAR2(30);
29889 l_entity_code                 VARCHAR2(30);
29890 l_event_class_code            VARCHAR2(30);
29891 l_ae_header_id                NUMBER;
29892 l_event_type_code             VARCHAR2(30);
29893 l_line_definition_code        VARCHAR2(30);
29894 l_line_definition_owner_code  VARCHAR2(1);
29895 --
29896 -- adr variables
29897 l_segment                     VARCHAR2(30);
29898 l_ccid                        NUMBER;
29899 l_adr_transaction_coa_id      NUMBER;
29900 l_adr_accounting_coa_id       NUMBER;
29901 l_adr_flexfield_segment_code  VARCHAR2(30);
29902 l_adr_flex_value_set_id       NUMBER;
29903 l_adr_value_type_code         VARCHAR2(30);
29904 l_adr_value_combination_id    NUMBER;
29905 l_adr_value_segment_code      VARCHAR2(30);
29906 
29910 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
29907 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
29908 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
29909 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
29911 
29912 -- 4262811 Variables ------------------------------------------------------------------------------------------
29913 l_entered_amt_idx             NUMBER;
29914 l_accted_amt_idx              NUMBER;
29915 l_acc_rev_flag                VARCHAR2(1);
29916 l_accrual_line_num            NUMBER;
29917 l_tmp_amt                     NUMBER;
29918 l_acc_rev_natural_side_code   VARCHAR2(1);
29919 
29920 l_num_entries                 NUMBER;
29921 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
29922 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
29923 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
29924 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
29925 l_recog_line_1                NUMBER;
29926 l_recog_line_2                NUMBER;
29927 
29928 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
29929 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
29930 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
29931 
29932 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
29933 
29934 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
29935 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
29936 
29937 ---------------------------------------------------------------------------------------------------------------
29938 
29939 
29940 --
29941 -- bulk performance
29942 --
29943 l_balance_type_code           VARCHAR2(1);
29944 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
29945 l_log_module                  VARCHAR2(240);
29946 
29947 --
29948 -- Upgrade strategy
29949 --
29950 l_actual_upg_option           VARCHAR2(1);
29951 l_enc_upg_option           VARCHAR2(1);
29952 
29953 --
29954 BEGIN
29955 --
29956 IF g_log_enabled THEN
29957       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_64';
29958 END IF;
29959 --
29960 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
29961 
29962       trace
29963          (p_msg      => 'BEGIN of AcctLineType_64'
29964          ,p_level    => C_LEVEL_PROCEDURE
29965          ,p_module   => l_log_module);
29966 
29967 END IF;
29968 --
29969 l_component_type             := 'AMB_JLT';
29970 l_component_code             := 'MFAR_RCT_CONFIRM_REVERSAL';
29971 l_component_type_code        := 'S';
29972 l_component_appl_id          :=  222;
29973 l_amb_context_code           := 'DEFAULT';
29974 l_entity_code                := 'RECEIPTS';
29975 l_event_class_code           := 'RECEIPT';
29976 l_event_type_code            := 'RECEIPT_ALL';
29977 l_line_definition_owner_code := 'S';
29978 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
29979 --
29980 l_balance_type_code          := 'A';
29981 l_segment                     := NULL;
29982 l_ccid                        := NULL;
29983 l_adr_transaction_coa_id      := NULL;
29984 l_adr_accounting_coa_id       := NULL;
29985 l_adr_flexfield_segment_code  := NULL;
29986 l_adr_flex_value_set_id       := NULL;
29987 l_adr_value_type_code         := NULL;
29988 l_adr_value_combination_id    := NULL;
29989 l_adr_value_segment_code      := NULL;
29990 
29991 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
29992 l_bflow_class_code           := '';    -- 4219869 Business Flow
29993 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
29994 l_budgetary_control_flag     := 'N';
29995 
29996 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
29997 l_bflow_applied_to_amt       := NULL; -- 5132302
29998 l_entered_amt_idx            := NULL;          -- 4262811
29999 l_accted_amt_idx             := NULL;          -- 4262811
30000 l_acc_rev_flag               := NULL;          -- 4262811
30001 l_accrual_line_num           := NULL;          -- 4262811
30002 l_tmp_amt                    := NULL;          -- 4262811
30003 --
30004  
30005 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
30006     l_balance_type_code <> 'B' THEN
30007 IF NVL(p_source_13,'
30008 ') =  'CONFIRMATION' AND 
30009 NVL(p_source_52,'
30010 ') =  'Y'
30011  THEN 
30012 
30013    --
30014    XLA_AE_LINES_PKG.SetNewLine;
30015 
30016    p_balance_type_code          := l_balance_type_code;
30017    -- set the flag so later we will know whether the gain loss line needs to be created
30018    
30019    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
30020      p_actual_flag :='A';
30021    END IF;
30022 
30023    --
30024    -- bulk performance
30025    --
30026    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
30027                                       p_header_num   => 0); -- 4262811
30028    --
30029    -- set accounting line options
30030    --
30031    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
30032            p_natural_side_code          => 'D'
30033          , p_gain_or_loss_flag          => 'N'
30034          , p_gl_transfer_mode_code      => 'S'
30035          , p_acct_entry_type_code       => 'A'
30036          , p_switch_side_flag           => 'Y'
30037          , p_merge_duplicate_code       => 'A'
30038          );
30039    --
30043    -- set accounting line type info
30040    l_acc_rev_natural_side_code := 'C';  -- 4262811
30041    -- 
30042    --
30044    --
30045    xla_ae_lines_pkg.SetAcctLineType
30046       (p_component_type             => l_component_type
30047       ,p_event_type_code            => l_event_type_code
30048       ,p_line_definition_owner_code => l_line_definition_owner_code
30049       ,p_line_definition_code       => l_line_definition_code
30050       ,p_accounting_line_code       => l_component_code
30051       ,p_accounting_line_type_code  => l_component_type_code
30052       ,p_accounting_line_appl_id    => l_component_appl_id
30053       ,p_amb_context_code           => l_amb_context_code
30054       ,p_entity_code                => l_entity_code
30055       ,p_event_class_code           => l_event_class_code);
30056    --
30057    -- set accounting class
30058    --
30059    xla_ae_lines_pkg.SetAcctClass(
30060            p_accounting_class_code  => 'CONFIRMATION'
30061          , p_ae_header_id           => l_ae_header_id
30062          );
30063 
30064    --
30065    -- set rounding class
30066    --
30067    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
30068                       'RECEIVABLE';
30069 
30070    --
30071    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
30072    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
30073    --
30074    -- bulk performance
30075    --
30076    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
30077 
30078    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
30079       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
30080 
30081    -- 4955764
30082    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
30083       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
30084 
30085    -- 4458381 Public Sector Enh
30086    
30087    --
30088    -- set accounting attributes for the line type
30089    --
30090    l_entered_amt_idx := 8;
30091    l_accted_amt_idx  := 13;
30092    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
30093    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
30094    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
30095    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
30096    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
30097    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
30098    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
30099    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
30100    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
30101    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
30102    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
30103    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
30104    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
30105    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
30106    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
30107    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
30108    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
30109    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
30110    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
30111    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
30112    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
30113    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
30114    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
30115    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
30116    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
30117    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
30118    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
30119    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
30120    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
30121    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
30122    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
30123    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
30124    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
30125 
30126    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
30127    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
30128 
30129    ---------------------------------------------------------------------------------------------------------------
30130    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
30131    ---------------------------------------------------------------------------------------------------------------
30132    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
30133 
30134    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
30135    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
30136 
30137    IF xla_accounting_cache_pkg.GetValueChar
30138          (p_source_code         => 'LEDGER_CATEGORY_CODE'
30139          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
30140    AND l_bflow_method_code = 'PRIOR_ENTRY'
30141 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
30142    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
30143          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
30144        )
30145    THEN
30146          xla_ae_lines_pkg.BflowUpgEntry
30147            (p_business_method_code    => l_bflow_method_code
30148            ,p_business_class_code     => l_bflow_class_code
30149            ,p_balance_type            => l_balance_type_code);
30150    ELSE
30151       NULL;
30152 -- No business flow processing for business flow method of NONE.
30153    END IF;
30154 
30155    --
30156    -- call analytical criteria
30157    --
30158    
30159    --
30160    -- call description
30161    --
30162    
30163 xla_ae_lines_pkg.SetLineDescription(
30164    p_ae_header_id => l_ae_header_id
30165   ,p_description  => Description_1 (
30166      p_application_id         => p_application_id
30167    , p_ae_header_id           => l_ae_header_id 
30168    )
30169 );
30170 
30171 
30172    --
30173    -- call ADRs
30174    -- Bug 4922099
30175    --
30176    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
30177         (NVL(l_actual_upg_option, 'N') = 'O') OR
30178         (NVL(l_enc_upg_option, 'N') = 'O')
30179       )
30180    THEN
30181    NULL;
30182    --
30183    --
30184    
30185   l_ccid := AcctDerRule_10(
30186            p_application_id           => p_application_id
30187          , p_ae_header_id             => l_ae_header_id 
30188 , p_source_7 => p_source_7
30189          , x_transaction_coa_id       => l_adr_transaction_coa_id
30190          , x_accounting_coa_id        => l_adr_accounting_coa_id
30191          , x_value_type_code          => l_adr_value_type_code
30192          , p_side                     => 'NA'
30193    );
30194 
30195    xla_ae_lines_pkg.set_ccid(
30196     p_code_combination_id          => l_ccid
30197   , p_value_type_code              => l_adr_value_type_code
30198   , p_transaction_coa_id           => l_adr_transaction_coa_id
30199   , p_accounting_coa_id            => l_adr_accounting_coa_id
30200   , p_adr_code                     => 'MFAR_RCT_DEF_CONFIRMATION_CCID'
30201   , p_adr_type_code                => 'S'
30202   , p_component_type               => l_component_type
30203   , p_component_code               => l_component_code
30204   , p_component_type_code          => l_component_type_code
30205   , p_component_appl_id            => l_component_appl_id
30206   , p_amb_context_code             => l_amb_context_code
30207   , p_side                         => 'NA'
30208   );
30209 
30210 
30211    --
30212    --
30213    END IF;
30214    --
30215    -- Bug 4922099
30216    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
30217           (NVL(l_enc_upg_option, 'N') = 'O')
30218         ) AND
30219         (l_bflow_method_code = 'PRIOR_ENTRY')
30220       )
30221    THEN
30222       IF
30223       --
30224       1 = 2
30225       --
30226       THEN
30227       xla_accounting_err_pkg.build_message
30228                                     (p_appli_s_name            => 'XLA'
30229                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
30230                                     ,p_token_1                 => 'LINE_NUMBER'
30231                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
30232                                     ,p_token_2                 => 'LINE_TYPE_NAME'
30233                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
30234                                                                              l_component_type
30235                                                                             ,l_component_code
30236                                                                             ,l_component_type_code
30237                                                                             ,l_component_appl_id
30238                                                                             ,l_amb_context_code
30239                                                                             ,l_entity_code
30240                                                                             ,l_event_class_code
30241                                                                            )
30242                                     ,p_token_3                 => 'OWNER'
30243                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
30244                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
30245                                                                           ,p_lookup_code    => l_component_type_code
30246                                                                          )
30247                                     ,p_token_4                 => 'PRODUCT_NAME'
30248                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
30249                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
30250                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
30251                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
30252                                     ,p_ae_header_id            =>  NULL
30253                                        );
30254 
30255         IF (C_LEVEL_ERROR>= g_log_level) THEN
30259                       ,p_module   => l_log_module);
30256                  trace
30257                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
30258                       ,p_level    => C_LEVEL_ERROR
30260         END IF;
30261       END IF;
30262    END IF;
30263    --
30264    --
30265    ------------------------------------------------------------------------------------------------
30266    -- 4219869 Business Flow
30267    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
30268    -- Prior Entry.  Currently, the following code is always generated.
30269    ------------------------------------------------------------------------------------------------
30270    XLA_AE_LINES_PKG.ValidateCurrentLine;
30271 
30272    ------------------------------------------------------------------------------------
30273    -- 4219869 Business Flow
30274    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
30275    ------------------------------------------------------------------------------------
30276    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
30277 
30278    ----------------------------------------------------------------------------------
30279    -- 4219869 Business Flow
30280    -- Update journal entry status -- Need to generate this within IF <condition>
30281    ----------------------------------------------------------------------------------
30282    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
30283          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
30284          ,p_balance_type_code => l_balance_type_code
30285          );
30286 
30287    -------------------------------------------------------------------------------------------
30288    -- 4262811 - Generate the Accrual Reversal lines
30289    -------------------------------------------------------------------------------------------
30290    BEGIN
30291       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
30292                               (g_array_event(p_event_id).array_value_num('header_index'));
30293       IF l_acc_rev_flag IS NULL THEN
30294          l_acc_rev_flag := 'N';
30295       END IF;
30296    EXCEPTION
30297       WHEN OTHERS THEN
30298          l_acc_rev_flag := 'N';
30299    END;
30300    --
30301    IF (l_acc_rev_flag = 'Y') THEN
30302 
30303        -- 4645092  ------------------------------------------------------------------------------
30304        -- To allow MPA report to determine if it should generate report process
30305        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
30306        ------------------------------------------------------------------------------------------
30307 
30308        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
30309        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
30310    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
30311    -- call ADRs
30312    -- Bug 4922099
30313    --
30314    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
30315         (NVL(l_actual_upg_option, 'N') = 'O') OR
30316         (NVL(l_enc_upg_option, 'N') = 'O')
30317       )
30318    THEN
30319    NULL;
30320    --
30321    --
30322    
30323   l_ccid := AcctDerRule_10(
30324            p_application_id           => p_application_id
30325          , p_ae_header_id             => l_ae_header_id 
30326 , p_source_7 => p_source_7
30327          , x_transaction_coa_id       => l_adr_transaction_coa_id
30328          , x_accounting_coa_id        => l_adr_accounting_coa_id
30329          , x_value_type_code          => l_adr_value_type_code
30330          , p_side                     => 'NA'
30331    );
30332 
30333    xla_ae_lines_pkg.set_ccid(
30334     p_code_combination_id          => l_ccid
30335   , p_value_type_code              => l_adr_value_type_code
30336   , p_transaction_coa_id           => l_adr_transaction_coa_id
30337   , p_accounting_coa_id            => l_adr_accounting_coa_id
30338   , p_adr_code                     => 'MFAR_RCT_DEF_CONFIRMATION_CCID'
30339   , p_adr_type_code                => 'S'
30340   , p_component_type               => l_component_type
30341   , p_component_code               => l_component_code
30342   , p_component_type_code          => l_component_type_code
30343   , p_component_appl_id            => l_component_appl_id
30344   , p_amb_context_code             => l_amb_context_code
30345   , p_side                         => 'NA'
30346   );
30347 
30348 
30349    --
30350    --
30351    END IF;
30352 
30353        --
30354        -- Update the line information that should be overwritten
30355        --
30356        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
30357                                          p_header_num   => 1);
30358        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
30359 
30360        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
30361 
30362        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
30363           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
30364        END IF;
30365 
30366       --
30367       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
30368       --
30369       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
30370           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
30371       ELSE
30372           ---------------------------------------------------------------------------------------------------
30373           -- 4262811a Switch Sign
30377                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
30374           ---------------------------------------------------------------------------------------------------
30375           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
30376           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
30378           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
30379                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
30380           -- 5132302
30381           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
30382                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
30383 
30384       END IF;
30385 
30386       -- 4955764
30387       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
30388       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
30389 
30390 
30391       XLA_AE_LINES_PKG.ValidateCurrentLine;
30392       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
30393 
30394       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
30395                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
30396                ,p_balance_type_code => l_balance_type_code);
30397 
30398    END IF;
30399 
30400    -----------------------------------------------------------------------------------------
30401    -- 4262811 Multiperiod Accounting
30402    -----------------------------------------------------------------------------------------
30403      -- No MPA option is assigned.
30404 
30405 
30406 END IF;
30407 END IF;
30408 --
30409 
30410 --
30411 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
30412    trace
30413       (p_msg      => 'END of AcctLineType_64'
30414       ,p_level    => C_LEVEL_PROCEDURE
30415       ,p_module   => l_log_module);
30416 END IF;
30417 --
30418 EXCEPTION
30419   WHEN xla_exceptions_pkg.application_exception THEN
30420       RAISE;
30421   WHEN OTHERS THEN
30422        xla_exceptions_pkg.raise_message
30423            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_64');
30424 END AcctLineType_64;
30425 --
30426 
30427 ---------------------------------------
30428 --
30429 -- PRIVATE FUNCTION
30430 --         AcctLineType_65
30431 --
30432 ---------------------------------------
30433 PROCEDURE AcctLineType_65 (
30434   p_application_id        IN NUMBER
30435  ,p_event_id              IN NUMBER
30436  ,p_calculate_acctd_flag  IN VARCHAR2
30437  ,p_calculate_g_l_flag    IN VARCHAR2
30438  ,p_actual_flag           IN OUT VARCHAR2
30439  ,p_balance_type_code     OUT VARCHAR2
30440  ,p_gain_or_loss_ref      OUT VARCHAR2
30441  
30442 --Distribution Source Type
30443  , p_source_13            IN VARCHAR2
30444 --Distribution Line Identifier
30445  , p_source_15            IN NUMBER
30446 --Distribution Type
30447  , p_source_16            IN VARCHAR2
30448 --Entered Amount
30449  , p_source_17            IN NUMBER
30450 --Currency Code
30451  , p_source_18            IN VARCHAR2
30452 --Applied To Document Accounting Amount
30453  , p_source_22            IN NUMBER
30454 --Transaction Distribution Identifier
30455  , p_source_27            IN NUMBER
30456 --Transaction Distribution Type
30457  , p_source_28            IN VARCHAR2
30458 --Distribution Multi Fund Additional Entry
30459  , p_source_52            IN VARCHAR2
30460 --Receipt Applied To Application Identifier
30461  , p_source_56            IN NUMBER
30462 --Transaction Entity Code
30463  , p_source_57            IN VARCHAR2
30464 --Transaction Identifier
30465  , p_source_58            IN NUMBER
30466 --Distribution Party Type
30467  , p_source_64            IN VARCHAR2
30468 )
30469 IS
30470 
30471 l_component_type              VARCHAR2(80);
30472 l_component_code              VARCHAR2(30);
30473 l_component_type_code         VARCHAR2(1);
30474 l_component_appl_id           INTEGER;
30475 l_amb_context_code            VARCHAR2(30);
30476 l_entity_code                 VARCHAR2(30);
30477 l_event_class_code            VARCHAR2(30);
30478 l_ae_header_id                NUMBER;
30479 l_event_type_code             VARCHAR2(30);
30480 l_line_definition_code        VARCHAR2(30);
30481 l_line_definition_owner_code  VARCHAR2(1);
30482 --
30483 -- adr variables
30484 l_segment                     VARCHAR2(30);
30485 l_ccid                        NUMBER;
30486 l_adr_transaction_coa_id      NUMBER;
30487 l_adr_accounting_coa_id       NUMBER;
30488 l_adr_flexfield_segment_code  VARCHAR2(30);
30489 l_adr_flex_value_set_id       NUMBER;
30490 l_adr_value_type_code         VARCHAR2(30);
30491 l_adr_value_combination_id    NUMBER;
30492 l_adr_value_segment_code      VARCHAR2(30);
30493 
30494 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
30495 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
30496 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
30497 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
30498 
30499 -- 4262811 Variables ------------------------------------------------------------------------------------------
30500 l_entered_amt_idx             NUMBER;
30501 l_accted_amt_idx              NUMBER;
30502 l_acc_rev_flag                VARCHAR2(1);
30503 l_accrual_line_num            NUMBER;
30504 l_tmp_amt                     NUMBER;
30508 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
30505 l_acc_rev_natural_side_code   VARCHAR2(1);
30506 
30507 l_num_entries                 NUMBER;
30509 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
30510 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
30511 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
30512 l_recog_line_1                NUMBER;
30513 l_recog_line_2                NUMBER;
30514 
30515 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
30516 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
30517 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
30518 
30519 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
30520 
30521 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
30522 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
30523 
30524 ---------------------------------------------------------------------------------------------------------------
30525 
30526 
30527 --
30528 -- bulk performance
30529 --
30530 l_balance_type_code           VARCHAR2(1);
30531 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
30532 l_log_module                  VARCHAR2(240);
30533 
30534 --
30535 -- Upgrade strategy
30536 --
30537 l_actual_upg_option           VARCHAR2(1);
30538 l_enc_upg_option           VARCHAR2(1);
30539 
30540 --
30541 BEGIN
30542 --
30543 IF g_log_enabled THEN
30544       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_65';
30545 END IF;
30546 --
30547 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
30548 
30549       trace
30550          (p_msg      => 'BEGIN of AcctLineType_65'
30551          ,p_level    => C_LEVEL_PROCEDURE
30552          ,p_module   => l_log_module);
30553 
30554 END IF;
30555 --
30556 l_component_type             := 'AMB_JLT';
30557 l_component_code             := 'MFAR_RCT_EDISC_REC';
30558 l_component_type_code        := 'S';
30559 l_component_appl_id          :=  222;
30560 l_amb_context_code           := 'DEFAULT';
30561 l_entity_code                := 'RECEIPTS';
30562 l_event_class_code           := 'RECEIPT';
30563 l_event_type_code            := 'RECEIPT_ALL';
30564 l_line_definition_owner_code := 'S';
30565 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
30566 --
30567 l_balance_type_code          := 'A';
30568 l_segment                     := NULL;
30569 l_ccid                        := NULL;
30570 l_adr_transaction_coa_id      := NULL;
30571 l_adr_accounting_coa_id       := NULL;
30572 l_adr_flexfield_segment_code  := NULL;
30573 l_adr_flex_value_set_id       := NULL;
30574 l_adr_value_type_code         := NULL;
30575 l_adr_value_combination_id    := NULL;
30576 l_adr_value_segment_code      := NULL;
30577 
30578 l_bflow_method_code          := 'PRIOR_ENTRY';   -- 4219869 Business Flow
30579 l_bflow_class_code           := 'RECEIVABLE';    -- 4219869 Business Flow
30580 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
30581 l_budgetary_control_flag     := 'N';
30582 
30583 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
30584 l_bflow_applied_to_amt       := NULL; -- 5132302
30585 l_entered_amt_idx            := NULL;          -- 4262811
30586 l_accted_amt_idx             := NULL;          -- 4262811
30587 l_acc_rev_flag               := NULL;          -- 4262811
30588 l_accrual_line_num           := NULL;          -- 4262811
30589 l_tmp_amt                    := NULL;          -- 4262811
30590 --
30591  
30592 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
30593     l_balance_type_code <> 'B' THEN
30594 IF NVL(p_source_13,'
30595 ') =  'EDISC' AND 
30596 NVL(p_source_52,'
30597 ') =  'N'
30598  THEN 
30599 
30600    --
30601    XLA_AE_LINES_PKG.SetNewLine;
30602 
30603    p_balance_type_code          := l_balance_type_code;
30604    -- set the flag so later we will know whether the gain loss line needs to be created
30605    
30606    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
30607      p_actual_flag :='A';
30608    END IF;
30609 
30610    --
30611    -- bulk performance
30612    --
30613    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
30614                                       p_header_num   => 0); -- 4262811
30615    --
30616    -- set accounting line options
30617    --
30618    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
30619            p_natural_side_code          => 'D'
30620          , p_gain_or_loss_flag          => 'N'
30621          , p_gl_transfer_mode_code      => 'S'
30622          , p_acct_entry_type_code       => 'A'
30623          , p_switch_side_flag           => 'Y'
30624          , p_merge_duplicate_code       => 'A'
30625          );
30626    --
30627    l_acc_rev_natural_side_code := 'C';  -- 4262811
30628    -- 
30629    --
30630    -- set accounting line type info
30631    --
30632    xla_ae_lines_pkg.SetAcctLineType
30633       (p_component_type             => l_component_type
30634       ,p_event_type_code            => l_event_type_code
30635       ,p_line_definition_owner_code => l_line_definition_owner_code
30636       ,p_line_definition_code       => l_line_definition_code
30637       ,p_accounting_line_code       => l_component_code
30638       ,p_accounting_line_type_code  => l_component_type_code
30639       ,p_accounting_line_appl_id    => l_component_appl_id
30643    --
30640       ,p_amb_context_code           => l_amb_context_code
30641       ,p_entity_code                => l_entity_code
30642       ,p_event_class_code           => l_event_class_code);
30644    -- set accounting class
30645    --
30646    xla_ae_lines_pkg.SetAcctClass(
30647            p_accounting_class_code  => 'RECEIVABLE'
30648          , p_ae_header_id           => l_ae_header_id
30649          );
30650 
30651    --
30652    -- set rounding class
30653    --
30654    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
30655                       'RECEIVABLE';
30656 
30657    --
30658    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
30659    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
30660    --
30661    -- bulk performance
30662    --
30663    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
30664 
30665    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
30666       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
30667 
30668    -- 4955764
30669    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
30670       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
30671 
30672    -- 4458381 Public Sector Enh
30673    
30674    --
30675    -- set accounting attributes for the line type
30676    --
30677    l_entered_amt_idx := 8;
30678    l_accted_amt_idx  := 10;
30679    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
30680    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
30681    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
30682    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
30683    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
30684    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
30685    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
30686    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
30687    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
30688    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
30689    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
30690    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
30691    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
30692    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
30693    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
30694    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
30695    l_rec_acct_attrs.array_num_value(8)  := p_source_17;
30696    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
30697    l_rec_acct_attrs.array_char_value(9)  := p_source_18;
30698    l_rec_acct_attrs.array_acct_attr_code(10) := 'LEDGER_AMOUNT';
30699    l_rec_acct_attrs.array_num_value(10)  := p_source_22;
30700    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
30701    l_rec_acct_attrs.array_char_value(11)  := p_source_64;
30702 
30703    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
30704    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
30705 
30706    ---------------------------------------------------------------------------------------------------------------
30707    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
30708    ---------------------------------------------------------------------------------------------------------------
30709    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
30710 
30711    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
30712    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
30713 
30714    IF xla_accounting_cache_pkg.GetValueChar
30715          (p_source_code         => 'LEDGER_CATEGORY_CODE'
30716          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
30717    AND l_bflow_method_code = 'PRIOR_ENTRY'
30718 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
30719    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
30720          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
30721        )
30722    THEN
30723          xla_ae_lines_pkg.BflowUpgEntry
30724            (p_business_method_code    => l_bflow_method_code
30725            ,p_business_class_code     => l_bflow_class_code
30726            ,p_balance_type            => l_balance_type_code);
30727    ELSE
30728       NULL;
30729 XLA_AE_LINES_PKG.business_flow_validation(
30730                                 p_business_method_code     => l_bflow_method_code
30731                                ,p_business_class_code      => l_bflow_class_code
30732                                ,p_inherit_description_flag => l_inherit_desc_flag);
30733    END IF;
30734 
30735    --
30736    -- call analytical criteria
30737    --
30738    -- Inherited Analytical Criteria for business flow method of Prior Entry.
30739    --
30740    -- call description
30741    --
30742    
30743 xla_ae_lines_pkg.SetLineDescription(
30744    p_ae_header_id => l_ae_header_id
30745   ,p_description  => Description_1 (
30746      p_application_id         => p_application_id
30747    , p_ae_header_id           => l_ae_header_id 
30748    )
30749 );
30750 
30751 
30752    --
30756    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
30753    -- call ADRs
30754    -- Bug 4922099
30755    --
30757         (NVL(l_actual_upg_option, 'N') = 'O') OR
30758         (NVL(l_enc_upg_option, 'N') = 'O')
30759       )
30760    THEN
30761    NULL;
30762    --
30763    --
30764    
30765    --
30766    --
30767    END IF;
30768    --
30769    -- Bug 4922099
30770    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
30771           (NVL(l_enc_upg_option, 'N') = 'O')
30772         ) AND
30773         (l_bflow_method_code = 'PRIOR_ENTRY')
30774       )
30775    THEN
30776       IF
30777       --
30778       1 = 1
30779       --
30780       THEN
30781       xla_accounting_err_pkg.build_message
30782                                     (p_appli_s_name            => 'XLA'
30783                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
30784                                     ,p_token_1                 => 'LINE_NUMBER'
30785                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
30786                                     ,p_token_2                 => 'LINE_TYPE_NAME'
30787                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
30788                                                                              l_component_type
30789                                                                             ,l_component_code
30790                                                                             ,l_component_type_code
30791                                                                             ,l_component_appl_id
30792                                                                             ,l_amb_context_code
30793                                                                             ,l_entity_code
30794                                                                             ,l_event_class_code
30795                                                                            )
30796                                     ,p_token_3                 => 'OWNER'
30797                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
30798                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
30799                                                                           ,p_lookup_code    => l_component_type_code
30800                                                                          )
30801                                     ,p_token_4                 => 'PRODUCT_NAME'
30802                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
30803                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
30804                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
30805                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
30806                                     ,p_ae_header_id            =>  NULL
30807                                        );
30808 
30809         IF (C_LEVEL_ERROR>= g_log_level) THEN
30810                  trace
30811                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
30812                       ,p_level    => C_LEVEL_ERROR
30813                       ,p_module   => l_log_module);
30814         END IF;
30815       END IF;
30816    END IF;
30817    --
30818    --
30819    ------------------------------------------------------------------------------------------------
30820    -- 4219869 Business Flow
30821    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
30822    -- Prior Entry.  Currently, the following code is always generated.
30823    ------------------------------------------------------------------------------------------------
30824    -- No ValidateCurrentLine for business flow method of Prior Entry
30825 
30826    ------------------------------------------------------------------------------------
30827    -- 4219869 Business Flow
30828    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
30829    ------------------------------------------------------------------------------------
30830    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
30831 
30832    ----------------------------------------------------------------------------------
30833    -- 4219869 Business Flow
30834    -- Update journal entry status -- Need to generate this within IF <condition>
30835    ----------------------------------------------------------------------------------
30836    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
30837          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
30838          ,p_balance_type_code => l_balance_type_code
30839          );
30840 
30841    -------------------------------------------------------------------------------------------
30842    -- 4262811 - Generate the Accrual Reversal lines
30843    -------------------------------------------------------------------------------------------
30844    BEGIN
30845       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
30846                               (g_array_event(p_event_id).array_value_num('header_index'));
30847       IF l_acc_rev_flag IS NULL THEN
30848          l_acc_rev_flag := 'N';
30849       END IF;
30850    EXCEPTION
30851       WHEN OTHERS THEN
30852          l_acc_rev_flag := 'N';
30853    END;
30854    --
30855    IF (l_acc_rev_flag = 'Y') THEN
30856 
30857        -- 4645092  ------------------------------------------------------------------------------
30858        -- To allow MPA report to determine if it should generate report process
30859        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
30863        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
30860        ------------------------------------------------------------------------------------------
30861 
30862        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
30864    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
30865    -- call ADRs
30866    -- Bug 4922099
30867    --
30868    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
30869         (NVL(l_actual_upg_option, 'N') = 'O') OR
30870         (NVL(l_enc_upg_option, 'N') = 'O')
30871       )
30872    THEN
30873    NULL;
30874    --
30875    --
30876    
30877    --
30878    --
30879    END IF;
30880 
30881        --
30882        -- Update the line information that should be overwritten
30883        --
30884        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
30885                                          p_header_num   => 1);
30886        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
30887 
30888        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
30889 
30890        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
30891           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
30892        END IF;
30893 
30894       --
30895       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
30896       --
30897       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
30898           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
30899       ELSE
30900           ---------------------------------------------------------------------------------------------------
30901           -- 4262811a Switch Sign
30902           ---------------------------------------------------------------------------------------------------
30903           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
30904           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
30905                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
30906           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
30907                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
30908           -- 5132302
30909           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
30910                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
30911 
30912       END IF;
30913 
30914       -- 4955764
30915       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
30916       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
30917 
30918 
30919       XLA_AE_LINES_PKG.ValidateCurrentLine;
30920       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
30921 
30922       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
30923                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
30924                ,p_balance_type_code => l_balance_type_code);
30925 
30926    END IF;
30927 
30928    -----------------------------------------------------------------------------------------
30929    -- 4262811 Multiperiod Accounting
30930    -----------------------------------------------------------------------------------------
30931      -- No MPA option is assigned.
30932 
30933 
30934 END IF;
30935 END IF;
30936 --
30937 
30938 --
30939 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
30940    trace
30941       (p_msg      => 'END of AcctLineType_65'
30942       ,p_level    => C_LEVEL_PROCEDURE
30943       ,p_module   => l_log_module);
30944 END IF;
30945 --
30946 EXCEPTION
30947   WHEN xla_exceptions_pkg.application_exception THEN
30948       RAISE;
30949   WHEN OTHERS THEN
30950        xla_exceptions_pkg.raise_message
30951            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_65');
30952 END AcctLineType_65;
30953 --
30954 
30955 ---------------------------------------
30956 --
30957 -- PRIVATE FUNCTION
30958 --         AcctLineType_66
30959 --
30960 ---------------------------------------
30961 PROCEDURE AcctLineType_66 (
30962   p_application_id        IN NUMBER
30963  ,p_event_id              IN NUMBER
30964  ,p_calculate_acctd_flag  IN VARCHAR2
30965  ,p_calculate_g_l_flag    IN VARCHAR2
30966  ,p_actual_flag           IN OUT VARCHAR2
30967  ,p_balance_type_code     OUT VARCHAR2
30968  ,p_gain_or_loss_ref      OUT VARCHAR2
30969  
30970 --Remittance Bank Account Remittance Account
30971  , p_source_8            IN NUMBER
30972 --Distribution Source Type
30973  , p_source_13            IN VARCHAR2
30974 --Distribution Line Identifier
30975  , p_source_15            IN NUMBER
30976 --Distribution Type
30977  , p_source_16            IN VARCHAR2
30978 --Exchange Date
30979  , p_source_19            IN DATE
30980 --Exchange Rate
30981  , p_source_20            IN NUMBER
30982 --Exchange Rate Type
30983  , p_source_21            IN VARCHAR2
30984 --Transaction Distribution Identifier
30985  , p_source_27            IN NUMBER
30986 --Transaction Distribution Type
30987  , p_source_28            IN VARCHAR2
30988 --Distribution Multi Fund Additional Entry
30989  , p_source_52            IN VARCHAR2
30990 --Receipt Applied To Application Identifier
30994 --Transaction Identifier
30991  , p_source_56            IN NUMBER
30992 --Transaction Entity Code
30993  , p_source_57            IN VARCHAR2
30995  , p_source_58            IN NUMBER
30996 --DIST_ENT_AMT_FROM
30997  , p_source_59            IN NUMBER
30998 --Applying Document Currency Code
30999  , p_source_60            IN VARCHAR2
31000 --Accounting Amount
31001  , p_source_61            IN NUMBER
31002 --Distribution Party Identifier
31003  , p_source_62            IN NUMBER
31004 --Distribution Party Site Id
31005  , p_source_63            IN NUMBER
31006 --Distribution Party Type
31007  , p_source_64            IN VARCHAR2
31008 )
31009 IS
31010 
31011 l_component_type              VARCHAR2(80);
31012 l_component_code              VARCHAR2(30);
31013 l_component_type_code         VARCHAR2(1);
31014 l_component_appl_id           INTEGER;
31015 l_amb_context_code            VARCHAR2(30);
31016 l_entity_code                 VARCHAR2(30);
31017 l_event_class_code            VARCHAR2(30);
31018 l_ae_header_id                NUMBER;
31019 l_event_type_code             VARCHAR2(30);
31020 l_line_definition_code        VARCHAR2(30);
31021 l_line_definition_owner_code  VARCHAR2(1);
31022 --
31023 -- adr variables
31024 l_segment                     VARCHAR2(30);
31025 l_ccid                        NUMBER;
31026 l_adr_transaction_coa_id      NUMBER;
31027 l_adr_accounting_coa_id       NUMBER;
31028 l_adr_flexfield_segment_code  VARCHAR2(30);
31029 l_adr_flex_value_set_id       NUMBER;
31030 l_adr_value_type_code         VARCHAR2(30);
31031 l_adr_value_combination_id    NUMBER;
31032 l_adr_value_segment_code      VARCHAR2(30);
31033 
31034 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
31035 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
31036 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
31037 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
31038 
31039 -- 4262811 Variables ------------------------------------------------------------------------------------------
31040 l_entered_amt_idx             NUMBER;
31041 l_accted_amt_idx              NUMBER;
31042 l_acc_rev_flag                VARCHAR2(1);
31043 l_accrual_line_num            NUMBER;
31044 l_tmp_amt                     NUMBER;
31045 l_acc_rev_natural_side_code   VARCHAR2(1);
31046 
31047 l_num_entries                 NUMBER;
31048 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
31049 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
31050 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
31051 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
31052 l_recog_line_1                NUMBER;
31053 l_recog_line_2                NUMBER;
31054 
31055 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
31056 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
31057 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
31058 
31059 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
31060 
31061 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
31062 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
31063 
31064 ---------------------------------------------------------------------------------------------------------------
31065 
31066 
31067 --
31068 -- bulk performance
31069 --
31070 l_balance_type_code           VARCHAR2(1);
31071 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
31072 l_log_module                  VARCHAR2(240);
31073 
31074 --
31075 -- Upgrade strategy
31076 --
31077 l_actual_upg_option           VARCHAR2(1);
31078 l_enc_upg_option           VARCHAR2(1);
31079 
31080 --
31081 BEGIN
31082 --
31083 IF g_log_enabled THEN
31084       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_66';
31085 END IF;
31086 --
31087 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
31088 
31089       trace
31090          (p_msg      => 'BEGIN of AcctLineType_66'
31091          ,p_level    => C_LEVEL_PROCEDURE
31092          ,p_module   => l_log_module);
31093 
31094 END IF;
31095 --
31096 l_component_type             := 'AMB_JLT';
31097 l_component_code             := 'MFAR_RCT_REMIT_REVERSAL';
31098 l_component_type_code        := 'S';
31099 l_component_appl_id          :=  222;
31100 l_amb_context_code           := 'DEFAULT';
31101 l_entity_code                := 'RECEIPTS';
31102 l_event_class_code           := 'RECEIPT';
31103 l_event_type_code            := 'RECEIPT_ALL';
31104 l_line_definition_owner_code := 'S';
31105 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
31106 --
31107 l_balance_type_code          := 'A';
31108 l_segment                     := NULL;
31109 l_ccid                        := NULL;
31110 l_adr_transaction_coa_id      := NULL;
31111 l_adr_accounting_coa_id       := NULL;
31112 l_adr_flexfield_segment_code  := NULL;
31113 l_adr_flex_value_set_id       := NULL;
31114 l_adr_value_type_code         := NULL;
31115 l_adr_value_combination_id    := NULL;
31116 l_adr_value_segment_code      := NULL;
31117 
31118 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
31119 l_bflow_class_code           := '';    -- 4219869 Business Flow
31120 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
31121 l_budgetary_control_flag     := 'N';
31122 
31123 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
31124 l_bflow_applied_to_amt       := NULL; -- 5132302
31125 l_entered_amt_idx            := NULL;          -- 4262811
31126 l_accted_amt_idx             := NULL;          -- 4262811
31127 l_acc_rev_flag               := NULL;          -- 4262811
31128 l_accrual_line_num           := NULL;          -- 4262811
31129 l_tmp_amt                    := NULL;          -- 4262811
31130 --
31131  
31132 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
31133     l_balance_type_code <> 'B' THEN
31134 IF NVL(p_source_13,'
31135 ') =  'REMITTANCE' AND 
31136 NVL(p_source_52,'
31137 ') =  'Y'
31138  THEN 
31139 
31140    --
31141    XLA_AE_LINES_PKG.SetNewLine;
31142 
31143    p_balance_type_code          := l_balance_type_code;
31144    -- set the flag so later we will know whether the gain loss line needs to be created
31145    
31146    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
31147      p_actual_flag :='A';
31148    END IF;
31149 
31150    --
31151    -- bulk performance
31152    --
31153    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
31154                                       p_header_num   => 0); -- 4262811
31155    --
31156    -- set accounting line options
31157    --
31158    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
31159            p_natural_side_code          => 'D'
31160          , p_gain_or_loss_flag          => 'N'
31161          , p_gl_transfer_mode_code      => 'S'
31162          , p_acct_entry_type_code       => 'A'
31163          , p_switch_side_flag           => 'Y'
31164          , p_merge_duplicate_code       => 'A'
31165          );
31166    --
31167    l_acc_rev_natural_side_code := 'C';  -- 4262811
31168    -- 
31169    --
31170    -- set accounting line type info
31171    --
31172    xla_ae_lines_pkg.SetAcctLineType
31173       (p_component_type             => l_component_type
31174       ,p_event_type_code            => l_event_type_code
31175       ,p_line_definition_owner_code => l_line_definition_owner_code
31176       ,p_line_definition_code       => l_line_definition_code
31177       ,p_accounting_line_code       => l_component_code
31178       ,p_accounting_line_type_code  => l_component_type_code
31179       ,p_accounting_line_appl_id    => l_component_appl_id
31180       ,p_amb_context_code           => l_amb_context_code
31181       ,p_entity_code                => l_entity_code
31182       ,p_event_class_code           => l_event_class_code);
31183    --
31184    -- set accounting class
31185    --
31186    xla_ae_lines_pkg.SetAcctClass(
31187            p_accounting_class_code  => 'REMITTANCE'
31188          , p_ae_header_id           => l_ae_header_id
31189          );
31190 
31191    --
31192    -- set rounding class
31193    --
31194    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
31198    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
31195                       'RECEIVABLE';
31196 
31197    --
31199    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
31200    --
31201    -- bulk performance
31202    --
31203    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
31204 
31205    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
31206       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
31207 
31208    -- 4955764
31209    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
31210       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
31211 
31212    -- 4458381 Public Sector Enh
31213    
31214    --
31215    -- set accounting attributes for the line type
31216    --
31217    l_entered_amt_idx := 8;
31218    l_accted_amt_idx  := 13;
31219    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
31220    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
31221    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
31222    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
31223    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
31224    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
31225    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
31226    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
31227    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
31228    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
31229    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
31230    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
31231    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
31232    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
31233    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
31234    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
31235    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
31236    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
31237    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
31238    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
31239    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
31240    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
31241    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
31242    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
31243    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
31244    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
31245    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
31246    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
31247    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
31248    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
31249    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
31250    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
31251    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
31252 
31253    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
31254    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
31255 
31256    ---------------------------------------------------------------------------------------------------------------
31257    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
31258    ---------------------------------------------------------------------------------------------------------------
31259    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
31260 
31261    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
31262    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
31263 
31264    IF xla_accounting_cache_pkg.GetValueChar
31265          (p_source_code         => 'LEDGER_CATEGORY_CODE'
31266          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
31267    AND l_bflow_method_code = 'PRIOR_ENTRY'
31268 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
31269    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
31270          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
31271        )
31272    THEN
31273          xla_ae_lines_pkg.BflowUpgEntry
31274            (p_business_method_code    => l_bflow_method_code
31275            ,p_business_class_code     => l_bflow_class_code
31276            ,p_balance_type            => l_balance_type_code);
31277    ELSE
31278       NULL;
31279 -- No business flow processing for business flow method of NONE.
31280    END IF;
31281 
31282    --
31283    -- call analytical criteria
31284    --
31285    
31286    --
31287    -- call description
31288    --
31289    
31290 xla_ae_lines_pkg.SetLineDescription(
31291    p_ae_header_id => l_ae_header_id
31292   ,p_description  => Description_1 (
31293      p_application_id         => p_application_id
31294    , p_ae_header_id           => l_ae_header_id 
31295    )
31296 );
31297 
31298 
31299    --
31300    -- call ADRs
31301    -- Bug 4922099
31302    --
31303    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
31304         (NVL(l_actual_upg_option, 'N') = 'O') OR
31305         (NVL(l_enc_upg_option, 'N') = 'O')
31309    --
31306       )
31307    THEN
31308    NULL;
31310    --
31311    
31312   l_ccid := AcctDerRule_11(
31313            p_application_id           => p_application_id
31314          , p_ae_header_id             => l_ae_header_id 
31315 , p_source_8 => p_source_8
31316          , x_transaction_coa_id       => l_adr_transaction_coa_id
31317          , x_accounting_coa_id        => l_adr_accounting_coa_id
31318          , x_value_type_code          => l_adr_value_type_code
31319          , p_side                     => 'NA'
31320    );
31321 
31322    xla_ae_lines_pkg.set_ccid(
31323     p_code_combination_id          => l_ccid
31324   , p_value_type_code              => l_adr_value_type_code
31325   , p_transaction_coa_id           => l_adr_transaction_coa_id
31326   , p_accounting_coa_id            => l_adr_accounting_coa_id
31327   , p_adr_code                     => 'MFAR_RCT_DEF_REMITTANCE_CCID'
31328   , p_adr_type_code                => 'S'
31329   , p_component_type               => l_component_type
31330   , p_component_code               => l_component_code
31331   , p_component_type_code          => l_component_type_code
31332   , p_component_appl_id            => l_component_appl_id
31333   , p_amb_context_code             => l_amb_context_code
31334   , p_side                         => 'NA'
31335   );
31336 
31337 
31338    --
31339    --
31340    END IF;
31341    --
31342    -- Bug 4922099
31343    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
31344           (NVL(l_enc_upg_option, 'N') = 'O')
31345         ) AND
31346         (l_bflow_method_code = 'PRIOR_ENTRY')
31347       )
31348    THEN
31349       IF
31350       --
31351       1 = 2
31352       --
31353       THEN
31354       xla_accounting_err_pkg.build_message
31355                                     (p_appli_s_name            => 'XLA'
31356                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
31357                                     ,p_token_1                 => 'LINE_NUMBER'
31358                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
31359                                     ,p_token_2                 => 'LINE_TYPE_NAME'
31360                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
31361                                                                              l_component_type
31362                                                                             ,l_component_code
31363                                                                             ,l_component_type_code
31364                                                                             ,l_component_appl_id
31365                                                                             ,l_amb_context_code
31366                                                                             ,l_entity_code
31367                                                                             ,l_event_class_code
31368                                                                            )
31369                                     ,p_token_3                 => 'OWNER'
31370                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
31371                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
31372                                                                           ,p_lookup_code    => l_component_type_code
31373                                                                          )
31374                                     ,p_token_4                 => 'PRODUCT_NAME'
31375                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
31376                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
31377                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
31378                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
31379                                     ,p_ae_header_id            =>  NULL
31380                                        );
31381 
31382         IF (C_LEVEL_ERROR>= g_log_level) THEN
31383                  trace
31384                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
31385                       ,p_level    => C_LEVEL_ERROR
31386                       ,p_module   => l_log_module);
31387         END IF;
31388       END IF;
31389    END IF;
31390    --
31391    --
31392    ------------------------------------------------------------------------------------------------
31393    -- 4219869 Business Flow
31394    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
31395    -- Prior Entry.  Currently, the following code is always generated.
31396    ------------------------------------------------------------------------------------------------
31397    XLA_AE_LINES_PKG.ValidateCurrentLine;
31398 
31399    ------------------------------------------------------------------------------------
31400    -- 4219869 Business Flow
31401    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
31402    ------------------------------------------------------------------------------------
31403    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
31404 
31405    ----------------------------------------------------------------------------------
31406    -- 4219869 Business Flow
31407    -- Update journal entry status -- Need to generate this within IF <condition>
31411          ,p_balance_type_code => l_balance_type_code
31408    ----------------------------------------------------------------------------------
31409    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
31410          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
31412          );
31413 
31414    -------------------------------------------------------------------------------------------
31415    -- 4262811 - Generate the Accrual Reversal lines
31416    -------------------------------------------------------------------------------------------
31417    BEGIN
31418       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
31419                               (g_array_event(p_event_id).array_value_num('header_index'));
31420       IF l_acc_rev_flag IS NULL THEN
31421          l_acc_rev_flag := 'N';
31422       END IF;
31423    EXCEPTION
31424       WHEN OTHERS THEN
31425          l_acc_rev_flag := 'N';
31426    END;
31427    --
31428    IF (l_acc_rev_flag = 'Y') THEN
31429 
31430        -- 4645092  ------------------------------------------------------------------------------
31431        -- To allow MPA report to determine if it should generate report process
31432        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
31433        ------------------------------------------------------------------------------------------
31434 
31435        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
31436        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
31437    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
31438    -- call ADRs
31439    -- Bug 4922099
31440    --
31441    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
31442         (NVL(l_actual_upg_option, 'N') = 'O') OR
31443         (NVL(l_enc_upg_option, 'N') = 'O')
31444       )
31445    THEN
31446    NULL;
31447    --
31448    --
31449    
31450   l_ccid := AcctDerRule_11(
31451            p_application_id           => p_application_id
31452          , p_ae_header_id             => l_ae_header_id 
31453 , p_source_8 => p_source_8
31454          , x_transaction_coa_id       => l_adr_transaction_coa_id
31455          , x_accounting_coa_id        => l_adr_accounting_coa_id
31456          , x_value_type_code          => l_adr_value_type_code
31457          , p_side                     => 'NA'
31458    );
31459 
31460    xla_ae_lines_pkg.set_ccid(
31461     p_code_combination_id          => l_ccid
31462   , p_value_type_code              => l_adr_value_type_code
31463   , p_transaction_coa_id           => l_adr_transaction_coa_id
31464   , p_accounting_coa_id            => l_adr_accounting_coa_id
31465   , p_adr_code                     => 'MFAR_RCT_DEF_REMITTANCE_CCID'
31466   , p_adr_type_code                => 'S'
31467   , p_component_type               => l_component_type
31468   , p_component_code               => l_component_code
31469   , p_component_type_code          => l_component_type_code
31470   , p_component_appl_id            => l_component_appl_id
31471   , p_amb_context_code             => l_amb_context_code
31472   , p_side                         => 'NA'
31473   );
31474 
31475 
31476    --
31477    --
31478    END IF;
31479 
31480        --
31481        -- Update the line information that should be overwritten
31482        --
31483        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
31484                                          p_header_num   => 1);
31485        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
31486 
31487        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
31488 
31489        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
31490           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
31491        END IF;
31492 
31493       --
31494       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
31495       --
31496       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
31497           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
31498       ELSE
31499           ---------------------------------------------------------------------------------------------------
31500           -- 4262811a Switch Sign
31501           ---------------------------------------------------------------------------------------------------
31502           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
31503           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
31504                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
31505           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
31506                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
31507           -- 5132302
31508           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
31509                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
31510 
31511       END IF;
31512 
31513       -- 4955764
31514       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
31515       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
31516 
31517 
31518       XLA_AE_LINES_PKG.ValidateCurrentLine;
31519       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
31520 
31521       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
31522                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
31523                ,p_balance_type_code => l_balance_type_code);
31524 
31525    END IF;
31526 
31527    -----------------------------------------------------------------------------------------
31528    -- 4262811 Multiperiod Accounting
31529    -----------------------------------------------------------------------------------------
31530      -- No MPA option is assigned.
31531 
31532 
31533 END IF;
31534 END IF;
31535 --
31536 
31537 --
31538 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
31539    trace
31540       (p_msg      => 'END of AcctLineType_66'
31541       ,p_level    => C_LEVEL_PROCEDURE
31542       ,p_module   => l_log_module);
31543 END IF;
31544 --
31545 EXCEPTION
31546   WHEN xla_exceptions_pkg.application_exception THEN
31547       RAISE;
31548   WHEN OTHERS THEN
31549        xla_exceptions_pkg.raise_message
31550            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_66');
31551 END AcctLineType_66;
31552 --
31553 
31557 --         AcctLineType_67
31554 ---------------------------------------
31555 --
31556 -- PRIVATE FUNCTION
31558 --
31559 ---------------------------------------
31560 PROCEDURE AcctLineType_67 (
31561   p_application_id        IN NUMBER
31562  ,p_event_id              IN NUMBER
31563  ,p_calculate_acctd_flag  IN VARCHAR2
31564  ,p_calculate_g_l_flag    IN VARCHAR2
31565  ,p_actual_flag           IN OUT VARCHAR2
31566  ,p_balance_type_code     OUT VARCHAR2
31567  ,p_gain_or_loss_ref      OUT VARCHAR2
31568  
31569 --Distribution Source Type
31570  , p_source_13            IN VARCHAR2
31571 --Distribution Line Identifier
31572  , p_source_15            IN NUMBER
31573 --Distribution Type
31574  , p_source_16            IN VARCHAR2
31575 --Entered Amount
31576  , p_source_17            IN NUMBER
31577 --Currency Code
31578  , p_source_18            IN VARCHAR2
31579 --Applied To Document Accounting Amount
31580  , p_source_22            IN NUMBER
31581 --Transaction Distribution Identifier
31582  , p_source_27            IN NUMBER
31583 --Transaction Distribution Type
31584  , p_source_28            IN VARCHAR2
31585 --Distribution Multi Fund Additional Entry
31586  , p_source_52            IN VARCHAR2
31587 --Receipt Applied To Application Identifier
31588  , p_source_56            IN NUMBER
31589 --Transaction Entity Code
31590  , p_source_57            IN VARCHAR2
31591 --Transaction Identifier
31592  , p_source_58            IN NUMBER
31593 --Distribution Party Type
31594  , p_source_64            IN VARCHAR2
31595 )
31596 IS
31597 
31598 l_component_type              VARCHAR2(80);
31599 l_component_code              VARCHAR2(30);
31600 l_component_type_code         VARCHAR2(1);
31601 l_component_appl_id           INTEGER;
31602 l_amb_context_code            VARCHAR2(30);
31603 l_entity_code                 VARCHAR2(30);
31604 l_event_class_code            VARCHAR2(30);
31605 l_ae_header_id                NUMBER;
31606 l_event_type_code             VARCHAR2(30);
31607 l_line_definition_code        VARCHAR2(30);
31608 l_line_definition_owner_code  VARCHAR2(1);
31609 --
31610 -- adr variables
31611 l_segment                     VARCHAR2(30);
31612 l_ccid                        NUMBER;
31613 l_adr_transaction_coa_id      NUMBER;
31614 l_adr_accounting_coa_id       NUMBER;
31615 l_adr_flexfield_segment_code  VARCHAR2(30);
31616 l_adr_flex_value_set_id       NUMBER;
31617 l_adr_value_type_code         VARCHAR2(30);
31618 l_adr_value_combination_id    NUMBER;
31619 l_adr_value_segment_code      VARCHAR2(30);
31620 
31621 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
31622 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
31623 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
31624 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
31625 
31626 -- 4262811 Variables ------------------------------------------------------------------------------------------
31627 l_entered_amt_idx             NUMBER;
31628 l_accted_amt_idx              NUMBER;
31629 l_acc_rev_flag                VARCHAR2(1);
31630 l_accrual_line_num            NUMBER;
31631 l_tmp_amt                     NUMBER;
31632 l_acc_rev_natural_side_code   VARCHAR2(1);
31633 
31634 l_num_entries                 NUMBER;
31635 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
31636 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
31637 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
31638 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
31639 l_recog_line_1                NUMBER;
31640 l_recog_line_2                NUMBER;
31641 
31642 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
31643 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
31644 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
31645 
31646 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
31647 
31648 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
31649 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
31650 
31651 ---------------------------------------------------------------------------------------------------------------
31652 
31653 
31654 --
31655 -- bulk performance
31656 --
31657 l_balance_type_code           VARCHAR2(1);
31658 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
31659 l_log_module                  VARCHAR2(240);
31660 
31661 --
31662 -- Upgrade strategy
31663 --
31664 l_actual_upg_option           VARCHAR2(1);
31665 l_enc_upg_option           VARCHAR2(1);
31666 
31667 --
31668 BEGIN
31669 --
31670 IF g_log_enabled THEN
31671       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_67';
31672 END IF;
31673 --
31674 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
31675 
31676       trace
31677          (p_msg      => 'BEGIN of AcctLineType_67'
31678          ,p_level    => C_LEVEL_PROCEDURE
31679          ,p_module   => l_log_module);
31680 
31681 END IF;
31682 --
31683 l_component_type             := 'AMB_JLT';
31684 l_component_code             := 'MFAR_RCT_UNDISC_REC';
31685 l_component_type_code        := 'S';
31686 l_component_appl_id          :=  222;
31687 l_amb_context_code           := 'DEFAULT';
31688 l_entity_code                := 'RECEIPTS';
31689 l_event_class_code           := 'RECEIPT';
31690 l_event_type_code            := 'RECEIPT_ALL';
31691 l_line_definition_owner_code := 'S';
31692 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
31693 --
31694 l_balance_type_code          := 'A';
31695 l_segment                     := NULL;
31696 l_ccid                        := NULL;
31697 l_adr_transaction_coa_id      := NULL;
31698 l_adr_accounting_coa_id       := NULL;
31699 l_adr_flexfield_segment_code  := NULL;
31700 l_adr_flex_value_set_id       := NULL;
31701 l_adr_value_type_code         := NULL;
31702 l_adr_value_combination_id    := NULL;
31703 l_adr_value_segment_code      := NULL;
31704 
31705 l_bflow_method_code          := 'PRIOR_ENTRY';   -- 4219869 Business Flow
31706 l_bflow_class_code           := 'RECEIVABLE';    -- 4219869 Business Flow
31707 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
31708 l_budgetary_control_flag     := 'N';
31709 
31710 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
31711 l_bflow_applied_to_amt       := NULL; -- 5132302
31712 l_entered_amt_idx            := NULL;          -- 4262811
31713 l_accted_amt_idx             := NULL;          -- 4262811
31714 l_acc_rev_flag               := NULL;          -- 4262811
31715 l_accrual_line_num           := NULL;          -- 4262811
31716 l_tmp_amt                    := NULL;          -- 4262811
31717 --
31718  
31719 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
31720     l_balance_type_code <> 'B' THEN
31721 IF NVL(p_source_13,'
31722 ') =  'UNEDISC' AND 
31723 NVL(p_source_52,'
31724 ') =  'N'
31725  THEN 
31726 
31727    --
31728    XLA_AE_LINES_PKG.SetNewLine;
31729 
31730    p_balance_type_code          := l_balance_type_code;
31731    -- set the flag so later we will know whether the gain loss line needs to be created
31732    
31733    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
31734      p_actual_flag :='A';
31735    END IF;
31736 
31737    --
31738    -- bulk performance
31739    --
31740    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
31741                                       p_header_num   => 0); -- 4262811
31742    --
31743    -- set accounting line options
31744    --
31745    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
31746            p_natural_side_code          => 'D'
31747          , p_gain_or_loss_flag          => 'N'
31748          , p_gl_transfer_mode_code      => 'S'
31749          , p_acct_entry_type_code       => 'A'
31750          , p_switch_side_flag           => 'Y'
31751          , p_merge_duplicate_code       => 'A'
31752          );
31753    --
31754    l_acc_rev_natural_side_code := 'C';  -- 4262811
31755    -- 
31756    --
31757    -- set accounting line type info
31758    --
31759    xla_ae_lines_pkg.SetAcctLineType
31760       (p_component_type             => l_component_type
31761       ,p_event_type_code            => l_event_type_code
31762       ,p_line_definition_owner_code => l_line_definition_owner_code
31763       ,p_line_definition_code       => l_line_definition_code
31764       ,p_accounting_line_code       => l_component_code
31765       ,p_accounting_line_type_code  => l_component_type_code
31766       ,p_accounting_line_appl_id    => l_component_appl_id
31767       ,p_amb_context_code           => l_amb_context_code
31768       ,p_entity_code                => l_entity_code
31769       ,p_event_class_code           => l_event_class_code);
31770    --
31771    -- set accounting class
31772    --
31773    xla_ae_lines_pkg.SetAcctClass(
31774            p_accounting_class_code  => 'RECEIVABLE'
31775          , p_ae_header_id           => l_ae_header_id
31776          );
31777 
31778    --
31779    -- set rounding class
31780    --
31781    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
31782                       'RECEIVABLE';
31783 
31784    --
31785    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
31786    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
31787    --
31788    -- bulk performance
31789    --
31790    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
31791 
31792    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
31793       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
31794 
31795    -- 4955764
31796    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
31797       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
31798 
31799    -- 4458381 Public Sector Enh
31800    
31801    --
31802    -- set accounting attributes for the line type
31803    --
31804    l_entered_amt_idx := 8;
31805    l_accted_amt_idx  := 10;
31806    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
31807    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
31808    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
31809    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
31810    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
31811    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
31812    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
31813    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
31814    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
31815    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
31816    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
31817    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
31818    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
31819    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
31820    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
31821    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
31822    l_rec_acct_attrs.array_num_value(8)  := p_source_17;
31823    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
31824    l_rec_acct_attrs.array_char_value(9)  := p_source_18;
31825    l_rec_acct_attrs.array_acct_attr_code(10) := 'LEDGER_AMOUNT';
31826    l_rec_acct_attrs.array_num_value(10)  := p_source_22;
31827    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
31828    l_rec_acct_attrs.array_char_value(11)  := p_source_64;
31829 
31830    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
31831    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
31832 
31833    ---------------------------------------------------------------------------------------------------------------
31834    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
31835    ---------------------------------------------------------------------------------------------------------------
31836    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
31837 
31838    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
31839    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
31840 
31841    IF xla_accounting_cache_pkg.GetValueChar
31842          (p_source_code         => 'LEDGER_CATEGORY_CODE'
31843          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
31844    AND l_bflow_method_code = 'PRIOR_ENTRY'
31845 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
31846    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
31847          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
31848        )
31849    THEN
31850          xla_ae_lines_pkg.BflowUpgEntry
31851            (p_business_method_code    => l_bflow_method_code
31852            ,p_business_class_code     => l_bflow_class_code
31853            ,p_balance_type            => l_balance_type_code);
31854    ELSE
31855       NULL;
31856 XLA_AE_LINES_PKG.business_flow_validation(
31857                                 p_business_method_code     => l_bflow_method_code
31858                                ,p_business_class_code      => l_bflow_class_code
31859                                ,p_inherit_description_flag => l_inherit_desc_flag);
31860    END IF;
31861 
31862    --
31863    -- call analytical criteria
31864    --
31865    -- Inherited Analytical Criteria for business flow method of Prior Entry.
31866    --
31867    -- call description
31868    --
31869    
31870 xla_ae_lines_pkg.SetLineDescription(
31871    p_ae_header_id => l_ae_header_id
31872   ,p_description  => Description_1 (
31873      p_application_id         => p_application_id
31874    , p_ae_header_id           => l_ae_header_id 
31875    )
31876 );
31877 
31878 
31879    --
31880    -- call ADRs
31881    -- Bug 4922099
31882    --
31883    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
31884         (NVL(l_actual_upg_option, 'N') = 'O') OR
31885         (NVL(l_enc_upg_option, 'N') = 'O')
31886       )
31887    THEN
31888    NULL;
31889    --
31890    --
31891    
31892    --
31893    --
31894    END IF;
31895    --
31896    -- Bug 4922099
31897    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
31898           (NVL(l_enc_upg_option, 'N') = 'O')
31899         ) AND
31900         (l_bflow_method_code = 'PRIOR_ENTRY')
31901       )
31902    THEN
31903       IF
31904       --
31905       1 = 1
31906       --
31907       THEN
31908       xla_accounting_err_pkg.build_message
31909                                     (p_appli_s_name            => 'XLA'
31910                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
31911                                     ,p_token_1                 => 'LINE_NUMBER'
31912                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
31913                                     ,p_token_2                 => 'LINE_TYPE_NAME'
31914                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
31915                                                                              l_component_type
31916                                                                             ,l_component_code
31917                                                                             ,l_component_type_code
31918                                                                             ,l_component_appl_id
31919                                                                             ,l_amb_context_code
31920                                                                             ,l_entity_code
31921                                                                             ,l_event_class_code
31922                                                                            )
31923                                     ,p_token_3                 => 'OWNER'
31924                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
31925                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
31926                                                                           ,p_lookup_code    => l_component_type_code
31927                                                                          )
31928                                     ,p_token_4                 => 'PRODUCT_NAME'
31929                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
31930                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
31931                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
31932                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
31933                                     ,p_ae_header_id            =>  NULL
31934                                        );
31935 
31936         IF (C_LEVEL_ERROR>= g_log_level) THEN
31937                  trace
31938                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
31939                       ,p_level    => C_LEVEL_ERROR
31940                       ,p_module   => l_log_module);
31941         END IF;
31942       END IF;
31943    END IF;
31944    --
31945    --
31946    ------------------------------------------------------------------------------------------------
31947    -- 4219869 Business Flow
31948    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
31949    -- Prior Entry.  Currently, the following code is always generated.
31950    ------------------------------------------------------------------------------------------------
31951    -- No ValidateCurrentLine for business flow method of Prior Entry
31952 
31953    ------------------------------------------------------------------------------------
31954    -- 4219869 Business Flow
31955    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
31956    ------------------------------------------------------------------------------------
31957    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
31958 
31959    ----------------------------------------------------------------------------------
31960    -- 4219869 Business Flow
31961    -- Update journal entry status -- Need to generate this within IF <condition>
31962    ----------------------------------------------------------------------------------
31963    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
31964          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
31965          ,p_balance_type_code => l_balance_type_code
31966          );
31967 
31968    -------------------------------------------------------------------------------------------
31969    -- 4262811 - Generate the Accrual Reversal lines
31970    -------------------------------------------------------------------------------------------
31971    BEGIN
31972       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
31973                               (g_array_event(p_event_id).array_value_num('header_index'));
31974       IF l_acc_rev_flag IS NULL THEN
31975          l_acc_rev_flag := 'N';
31976       END IF;
31977    EXCEPTION
31978       WHEN OTHERS THEN
31979          l_acc_rev_flag := 'N';
31980    END;
31981    --
31982    IF (l_acc_rev_flag = 'Y') THEN
31983 
31984        -- 4645092  ------------------------------------------------------------------------------
31985        -- To allow MPA report to determine if it should generate report process
31986        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
31987        ------------------------------------------------------------------------------------------
31988 
31989        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
31990        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
31991    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
31992    -- call ADRs
31993    -- Bug 4922099
31994    --
31995    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
31996         (NVL(l_actual_upg_option, 'N') = 'O') OR
31997         (NVL(l_enc_upg_option, 'N') = 'O')
31998       )
31999    THEN
32000    NULL;
32001    --
32002    --
32003    
32004    --
32005    --
32006    END IF;
32007 
32008        --
32009        -- Update the line information that should be overwritten
32010        --
32011        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
32012                                          p_header_num   => 1);
32013        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
32014 
32015        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
32016 
32017        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
32018           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
32019        END IF;
32020 
32021       --
32022       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
32023       --
32024       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
32025           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
32026       ELSE
32027           ---------------------------------------------------------------------------------------------------
32028           -- 4262811a Switch Sign
32029           ---------------------------------------------------------------------------------------------------
32030           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
32031           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
32032                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
32033           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
32034                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
32035           -- 5132302
32036           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
32037                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
32038 
32039       END IF;
32040 
32041       -- 4955764
32042       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
32043       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
32044 
32045 
32046       XLA_AE_LINES_PKG.ValidateCurrentLine;
32047       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
32048 
32049       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
32050                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
32051                ,p_balance_type_code => l_balance_type_code);
32052 
32053    END IF;
32054 
32055    -----------------------------------------------------------------------------------------
32056    -- 4262811 Multiperiod Accounting
32057    -----------------------------------------------------------------------------------------
32058      -- No MPA option is assigned.
32059 
32060 
32061 END IF;
32062 END IF;
32063 --
32064 
32065 --
32066 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
32067    trace
32068       (p_msg      => 'END of AcctLineType_67'
32069       ,p_level    => C_LEVEL_PROCEDURE
32070       ,p_module   => l_log_module);
32071 END IF;
32072 --
32073 EXCEPTION
32074   WHEN xla_exceptions_pkg.application_exception THEN
32075       RAISE;
32076   WHEN OTHERS THEN
32077        xla_exceptions_pkg.raise_message
32078            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_67');
32079 END AcctLineType_67;
32080 --
32081 
32082 ---------------------------------------
32083 --
32084 -- PRIVATE FUNCTION
32085 --         AcctLineType_68
32086 --
32087 ---------------------------------------
32088 PROCEDURE AcctLineType_68 (
32089   p_application_id        IN NUMBER
32090  ,p_event_id              IN NUMBER
32091  ,p_calculate_acctd_flag  IN VARCHAR2
32092  ,p_calculate_g_l_flag    IN VARCHAR2
32093  ,p_actual_flag           IN OUT VARCHAR2
32094  ,p_balance_type_code     OUT VARCHAR2
32095  ,p_gain_or_loss_ref      OUT VARCHAR2
32096  
32097 --Distribution GL Account
32098  , p_source_3            IN NUMBER
32099 --Distribution Source Type
32100  , p_source_13            IN VARCHAR2
32101 --Distribution Line Identifier
32102  , p_source_15            IN NUMBER
32103 --Distribution Type
32104  , p_source_16            IN VARCHAR2
32105 --Entered Amount
32106  , p_source_17            IN NUMBER
32107 --Currency Code
32108  , p_source_18            IN VARCHAR2
32109 --Exchange Rate
32110  , p_source_20            IN NUMBER
32111 --Exchange Rate Type
32112  , p_source_21            IN VARCHAR2
32113 --Applied To Document Accounting Amount
32114  , p_source_22            IN NUMBER
32115 --Distribution Multi Fund Additional Entry
32116  , p_source_52            IN VARCHAR2
32117 --Applied To Document Exchange Date
32118  , p_source_53            IN DATE
32119 )
32120 IS
32121 
32122 l_component_type              VARCHAR2(80);
32123 l_component_code              VARCHAR2(30);
32124 l_component_type_code         VARCHAR2(1);
32125 l_component_appl_id           INTEGER;
32126 l_amb_context_code            VARCHAR2(30);
32127 l_entity_code                 VARCHAR2(30);
32128 l_event_class_code            VARCHAR2(30);
32129 l_ae_header_id                NUMBER;
32130 l_event_type_code             VARCHAR2(30);
32131 l_line_definition_code        VARCHAR2(30);
32132 l_line_definition_owner_code  VARCHAR2(1);
32133 --
32134 -- adr variables
32135 l_segment                     VARCHAR2(30);
32136 l_ccid                        NUMBER;
32137 l_adr_transaction_coa_id      NUMBER;
32138 l_adr_accounting_coa_id       NUMBER;
32139 l_adr_flexfield_segment_code  VARCHAR2(30);
32140 l_adr_flex_value_set_id       NUMBER;
32141 l_adr_value_type_code         VARCHAR2(30);
32142 l_adr_value_combination_id    NUMBER;
32143 l_adr_value_segment_code      VARCHAR2(30);
32144 
32145 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
32146 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
32147 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
32148 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
32149 
32150 -- 4262811 Variables ------------------------------------------------------------------------------------------
32151 l_entered_amt_idx             NUMBER;
32152 l_accted_amt_idx              NUMBER;
32153 l_acc_rev_flag                VARCHAR2(1);
32154 l_accrual_line_num            NUMBER;
32155 l_tmp_amt                     NUMBER;
32156 l_acc_rev_natural_side_code   VARCHAR2(1);
32157 
32158 l_num_entries                 NUMBER;
32159 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
32160 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
32161 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
32162 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
32163 l_recog_line_1                NUMBER;
32164 l_recog_line_2                NUMBER;
32165 
32166 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
32167 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
32168 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
32169 
32170 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
32171 
32172 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
32173 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
32174 
32175 ---------------------------------------------------------------------------------------------------------------
32176 
32177 
32178 --
32179 -- bulk performance
32180 --
32181 l_balance_type_code           VARCHAR2(1);
32182 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
32183 l_log_module                  VARCHAR2(240);
32184 
32185 --
32186 -- Upgrade strategy
32187 --
32188 l_actual_upg_option           VARCHAR2(1);
32189 l_enc_upg_option           VARCHAR2(1);
32190 
32191 --
32192 BEGIN
32193 --
32194 IF g_log_enabled THEN
32195       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_68';
32196 END IF;
32197 --
32198 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
32199 
32200       trace
32201          (p_msg      => 'BEGIN of AcctLineType_68'
32202          ,p_level    => C_LEVEL_PROCEDURE
32203          ,p_module   => l_log_module);
32204 
32205 END IF;
32206 --
32207 l_component_type             := 'AMB_JLT';
32208 l_component_code             := 'MISC_RCT_BNK_CHG';
32209 l_component_type_code        := 'S';
32213 l_event_class_code           := 'MISC_RECEIPT';
32210 l_component_appl_id          :=  222;
32211 l_amb_context_code           := 'DEFAULT';
32212 l_entity_code                := 'RECEIPTS';
32214 l_event_type_code            := 'MISC_RECEIPT_ALL';
32215 l_line_definition_owner_code := 'S';
32216 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
32217 --
32218 l_balance_type_code          := 'A';
32219 l_segment                     := NULL;
32220 l_ccid                        := NULL;
32221 l_adr_transaction_coa_id      := NULL;
32222 l_adr_accounting_coa_id       := NULL;
32223 l_adr_flexfield_segment_code  := NULL;
32224 l_adr_flex_value_set_id       := NULL;
32225 l_adr_value_type_code         := NULL;
32226 l_adr_value_combination_id    := NULL;
32227 l_adr_value_segment_code      := NULL;
32228 
32229 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
32230 l_bflow_class_code           := '';    -- 4219869 Business Flow
32231 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
32232 l_budgetary_control_flag     := 'N';
32233 
32234 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
32235 l_bflow_applied_to_amt       := NULL; -- 5132302
32236 l_entered_amt_idx            := NULL;          -- 4262811
32237 l_accted_amt_idx             := NULL;          -- 4262811
32238 l_acc_rev_flag               := NULL;          -- 4262811
32239 l_accrual_line_num           := NULL;          -- 4262811
32240 l_tmp_amt                    := NULL;          -- 4262811
32241 --
32242  
32243 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
32244     l_balance_type_code <> 'B' THEN
32245 IF NVL(p_source_13,'
32246 ') =  'BANK_CHARGES' AND 
32247 NVL(p_source_52,'
32248 ') =  'N'
32249  THEN 
32250 
32251    --
32252    XLA_AE_LINES_PKG.SetNewLine;
32253 
32254    p_balance_type_code          := l_balance_type_code;
32255    -- set the flag so later we will know whether the gain loss line needs to be created
32256    
32257    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
32258      p_actual_flag :='A';
32259    END IF;
32260 
32261    --
32262    -- bulk performance
32263    --
32264    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
32265                                       p_header_num   => 0); -- 4262811
32266    --
32267    -- set accounting line options
32268    --
32269    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
32270            p_natural_side_code          => 'C'
32271          , p_gain_or_loss_flag          => 'N'
32272          , p_gl_transfer_mode_code      => 'S'
32273          , p_acct_entry_type_code       => 'A'
32274          , p_switch_side_flag           => 'Y'
32275          , p_merge_duplicate_code       => 'A'
32276          );
32277    --
32278    l_acc_rev_natural_side_code := 'D';  -- 4262811
32279    -- 
32280    --
32281    -- set accounting line type info
32282    --
32283    xla_ae_lines_pkg.SetAcctLineType
32284       (p_component_type             => l_component_type
32285       ,p_event_type_code            => l_event_type_code
32286       ,p_line_definition_owner_code => l_line_definition_owner_code
32287       ,p_line_definition_code       => l_line_definition_code
32288       ,p_accounting_line_code       => l_component_code
32289       ,p_accounting_line_type_code  => l_component_type_code
32290       ,p_accounting_line_appl_id    => l_component_appl_id
32291       ,p_amb_context_code           => l_amb_context_code
32292       ,p_entity_code                => l_entity_code
32293       ,p_event_class_code           => l_event_class_code);
32294    --
32295    -- set accounting class
32296    --
32297    xla_ae_lines_pkg.SetAcctClass(
32298            p_accounting_class_code  => 'BANK_CHG'
32299          , p_ae_header_id           => l_ae_header_id
32300          );
32301 
32302    --
32303    -- set rounding class
32304    --
32305    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
32306                       'RECEIVABLE';
32307 
32308    --
32309    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
32310    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
32311    --
32312    -- bulk performance
32313    --
32314    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
32315 
32316    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
32317       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
32318 
32319    -- 4955764
32320    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
32321       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
32322 
32323    -- 4458381 Public Sector Enh
32324    
32325    --
32326    -- set accounting attributes for the line type
32327    --
32328    l_entered_amt_idx := 3;
32329    l_accted_amt_idx  := 8;
32330    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
32331    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
32332    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
32333    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
32334    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
32335    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
32339    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
32336    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
32337    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
32338    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
32340    l_rec_acct_attrs.array_date_value(5)  := p_source_53;
32341    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
32342    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
32343    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
32344    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
32345    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
32346    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
32347 
32348    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
32349    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
32350 
32351    ---------------------------------------------------------------------------------------------------------------
32352    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
32353    ---------------------------------------------------------------------------------------------------------------
32354    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
32355 
32356    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
32357    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
32358 
32359    IF xla_accounting_cache_pkg.GetValueChar
32360          (p_source_code         => 'LEDGER_CATEGORY_CODE'
32361          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
32362    AND l_bflow_method_code = 'PRIOR_ENTRY'
32363 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
32364    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
32365          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
32366        )
32367    THEN
32368          xla_ae_lines_pkg.BflowUpgEntry
32369            (p_business_method_code    => l_bflow_method_code
32370            ,p_business_class_code     => l_bflow_class_code
32371            ,p_balance_type            => l_balance_type_code);
32372    ELSE
32373       NULL;
32374 -- No business flow processing for business flow method of NONE.
32375    END IF;
32376 
32377    --
32378    -- call analytical criteria
32379    --
32380    
32381    --
32382    -- call description
32383    --
32384    -- No description or it is inherited.
32385    --
32386    -- call ADRs
32387    -- Bug 4922099
32388    --
32389    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
32390         (NVL(l_actual_upg_option, 'N') = 'O') OR
32391         (NVL(l_enc_upg_option, 'N') = 'O')
32392       )
32393    THEN
32394    NULL;
32395    --
32396    --
32397    
32398   l_ccid := AcctDerRule_7(
32399            p_application_id           => p_application_id
32400          , p_ae_header_id             => l_ae_header_id 
32401 , p_source_3 => p_source_3
32402          , x_transaction_coa_id       => l_adr_transaction_coa_id
32403          , x_accounting_coa_id        => l_adr_accounting_coa_id
32404          , x_value_type_code          => l_adr_value_type_code
32405          , p_side                     => 'NA'
32406    );
32407 
32408    xla_ae_lines_pkg.set_ccid(
32409     p_code_combination_id          => l_ccid
32410   , p_value_type_code              => l_adr_value_type_code
32411   , p_transaction_coa_id           => l_adr_transaction_coa_id
32412   , p_accounting_coa_id            => l_adr_accounting_coa_id
32413   , p_adr_code                     => 'DIST_CCID'
32414   , p_adr_type_code                => 'S'
32415   , p_component_type               => l_component_type
32416   , p_component_code               => l_component_code
32417   , p_component_type_code          => l_component_type_code
32418   , p_component_appl_id            => l_component_appl_id
32419   , p_amb_context_code             => l_amb_context_code
32420   , p_side                         => 'NA'
32421   );
32422 
32423 
32424    --
32425    --
32426    END IF;
32427    --
32428    -- Bug 4922099
32429    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
32430           (NVL(l_enc_upg_option, 'N') = 'O')
32431         ) AND
32432         (l_bflow_method_code = 'PRIOR_ENTRY')
32433       )
32434    THEN
32435       IF
32439       THEN
32436       --
32437       1 = 2
32438       --
32440       xla_accounting_err_pkg.build_message
32441                                     (p_appli_s_name            => 'XLA'
32442                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
32443                                     ,p_token_1                 => 'LINE_NUMBER'
32444                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
32445                                     ,p_token_2                 => 'LINE_TYPE_NAME'
32446                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
32447                                                                              l_component_type
32448                                                                             ,l_component_code
32449                                                                             ,l_component_type_code
32450                                                                             ,l_component_appl_id
32451                                                                             ,l_amb_context_code
32452                                                                             ,l_entity_code
32453                                                                             ,l_event_class_code
32454                                                                            )
32455                                     ,p_token_3                 => 'OWNER'
32456                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
32457                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
32458                                                                           ,p_lookup_code    => l_component_type_code
32459                                                                          )
32460                                     ,p_token_4                 => 'PRODUCT_NAME'
32461                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
32462                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
32463                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
32464                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
32465                                     ,p_ae_header_id            =>  NULL
32466                                        );
32467 
32468         IF (C_LEVEL_ERROR>= g_log_level) THEN
32469                  trace
32470                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
32471                       ,p_level    => C_LEVEL_ERROR
32472                       ,p_module   => l_log_module);
32473         END IF;
32474       END IF;
32475    END IF;
32476    --
32477    --
32478    ------------------------------------------------------------------------------------------------
32479    -- 4219869 Business Flow
32480    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
32481    -- Prior Entry.  Currently, the following code is always generated.
32482    ------------------------------------------------------------------------------------------------
32483    XLA_AE_LINES_PKG.ValidateCurrentLine;
32484 
32485    ------------------------------------------------------------------------------------
32486    -- 4219869 Business Flow
32487    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
32488    ------------------------------------------------------------------------------------
32489    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
32490 
32491    ----------------------------------------------------------------------------------
32492    -- 4219869 Business Flow
32493    -- Update journal entry status -- Need to generate this within IF <condition>
32494    ----------------------------------------------------------------------------------
32495    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
32496          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
32497          ,p_balance_type_code => l_balance_type_code
32498          );
32499 
32500    -------------------------------------------------------------------------------------------
32501    -- 4262811 - Generate the Accrual Reversal lines
32502    -------------------------------------------------------------------------------------------
32503    BEGIN
32504       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
32505                               (g_array_event(p_event_id).array_value_num('header_index'));
32506       IF l_acc_rev_flag IS NULL THEN
32507          l_acc_rev_flag := 'N';
32508       END IF;
32509    EXCEPTION
32510       WHEN OTHERS THEN
32511          l_acc_rev_flag := 'N';
32512    END;
32513    --
32514    IF (l_acc_rev_flag = 'Y') THEN
32515 
32516        -- 4645092  ------------------------------------------------------------------------------
32517        -- To allow MPA report to determine if it should generate report process
32518        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
32519        ------------------------------------------------------------------------------------------
32520 
32521        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
32522        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
32523    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
32524    -- call ADRs
32525    -- Bug 4922099
32526    --
32527    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
32528         (NVL(l_actual_upg_option, 'N') = 'O') OR
32529         (NVL(l_enc_upg_option, 'N') = 'O')
32530       )
32531    THEN
32532    NULL;
32533    --
32534    --
32535    
32539 , p_source_3 => p_source_3
32536   l_ccid := AcctDerRule_7(
32537            p_application_id           => p_application_id
32538          , p_ae_header_id             => l_ae_header_id 
32540          , x_transaction_coa_id       => l_adr_transaction_coa_id
32541          , x_accounting_coa_id        => l_adr_accounting_coa_id
32542          , x_value_type_code          => l_adr_value_type_code
32543          , p_side                     => 'NA'
32544    );
32545 
32546    xla_ae_lines_pkg.set_ccid(
32547     p_code_combination_id          => l_ccid
32548   , p_value_type_code              => l_adr_value_type_code
32549   , p_transaction_coa_id           => l_adr_transaction_coa_id
32550   , p_accounting_coa_id            => l_adr_accounting_coa_id
32551   , p_adr_code                     => 'DIST_CCID'
32552   , p_adr_type_code                => 'S'
32553   , p_component_type               => l_component_type
32554   , p_component_code               => l_component_code
32555   , p_component_type_code          => l_component_type_code
32556   , p_component_appl_id            => l_component_appl_id
32557   , p_amb_context_code             => l_amb_context_code
32558   , p_side                         => 'NA'
32559   );
32560 
32561 
32562    --
32563    --
32564    END IF;
32565 
32566        --
32567        -- Update the line information that should be overwritten
32568        --
32569        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
32570                                          p_header_num   => 1);
32571        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
32572 
32573        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
32574 
32575        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
32576           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
32577        END IF;
32578 
32579       --
32580       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
32581       --
32582       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
32583           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
32584       ELSE
32585           ---------------------------------------------------------------------------------------------------
32586           -- 4262811a Switch Sign
32587           ---------------------------------------------------------------------------------------------------
32588           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
32589           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
32590                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
32591           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
32592                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
32593           -- 5132302
32594           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
32595                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
32596 
32597       END IF;
32598 
32599       -- 4955764
32600       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
32601       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
32602 
32603 
32604       XLA_AE_LINES_PKG.ValidateCurrentLine;
32605       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
32606 
32607       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
32608                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
32609                ,p_balance_type_code => l_balance_type_code);
32610 
32611    END IF;
32612 
32613    -----------------------------------------------------------------------------------------
32614    -- 4262811 Multiperiod Accounting
32615    -----------------------------------------------------------------------------------------
32616      -- No MPA option is assigned.
32617 
32618 
32619 END IF;
32620 END IF;
32621 --
32622 
32623 --
32624 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
32625    trace
32626       (p_msg      => 'END of AcctLineType_68'
32627       ,p_level    => C_LEVEL_PROCEDURE
32628       ,p_module   => l_log_module);
32629 END IF;
32630 --
32631 EXCEPTION
32632   WHEN xla_exceptions_pkg.application_exception THEN
32633       RAISE;
32634   WHEN OTHERS THEN
32635        xla_exceptions_pkg.raise_message
32636            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_68');
32637 END AcctLineType_68;
32638 --
32639 
32640 ---------------------------------------
32641 --
32642 -- PRIVATE FUNCTION
32643 --         AcctLineType_69
32644 --
32645 ---------------------------------------
32646 PROCEDURE AcctLineType_69 (
32647   p_application_id        IN NUMBER
32648  ,p_event_id              IN NUMBER
32649  ,p_calculate_acctd_flag  IN VARCHAR2
32650  ,p_calculate_g_l_flag    IN VARCHAR2
32651  ,p_actual_flag           IN OUT VARCHAR2
32652  ,p_balance_type_code     OUT VARCHAR2
32653  ,p_gain_or_loss_ref      OUT VARCHAR2
32654  
32655 --Distribution GL Account
32656  , p_source_3            IN NUMBER
32657 --Distribution Source Type
32658  , p_source_13            IN VARCHAR2
32659 --Distribution Line Identifier
32660  , p_source_15            IN NUMBER
32661 --Distribution Type
32662  , p_source_16            IN VARCHAR2
32663 --Entered Amount
32667 --Exchange Rate
32664  , p_source_17            IN NUMBER
32665 --Currency Code
32666  , p_source_18            IN VARCHAR2
32668  , p_source_20            IN NUMBER
32669 --Exchange Rate Type
32670  , p_source_21            IN VARCHAR2
32671 --Applied To Document Accounting Amount
32672  , p_source_22            IN NUMBER
32673 --Distribution Multi Fund Additional Entry
32674  , p_source_52            IN VARCHAR2
32675 --Applied To Document Exchange Date
32676  , p_source_53            IN DATE
32677 )
32678 IS
32679 
32680 l_component_type              VARCHAR2(80);
32681 l_component_code              VARCHAR2(30);
32682 l_component_type_code         VARCHAR2(1);
32683 l_component_appl_id           INTEGER;
32684 l_amb_context_code            VARCHAR2(30);
32685 l_entity_code                 VARCHAR2(30);
32686 l_event_class_code            VARCHAR2(30);
32687 l_ae_header_id                NUMBER;
32688 l_event_type_code             VARCHAR2(30);
32689 l_line_definition_code        VARCHAR2(30);
32690 l_line_definition_owner_code  VARCHAR2(1);
32691 --
32692 -- adr variables
32693 l_segment                     VARCHAR2(30);
32694 l_ccid                        NUMBER;
32695 l_adr_transaction_coa_id      NUMBER;
32696 l_adr_accounting_coa_id       NUMBER;
32697 l_adr_flexfield_segment_code  VARCHAR2(30);
32698 l_adr_flex_value_set_id       NUMBER;
32699 l_adr_value_type_code         VARCHAR2(30);
32700 l_adr_value_combination_id    NUMBER;
32701 l_adr_value_segment_code      VARCHAR2(30);
32702 
32703 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
32704 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
32705 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
32706 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
32707 
32708 -- 4262811 Variables ------------------------------------------------------------------------------------------
32709 l_entered_amt_idx             NUMBER;
32710 l_accted_amt_idx              NUMBER;
32711 l_acc_rev_flag                VARCHAR2(1);
32712 l_accrual_line_num            NUMBER;
32713 l_tmp_amt                     NUMBER;
32714 l_acc_rev_natural_side_code   VARCHAR2(1);
32715 
32716 l_num_entries                 NUMBER;
32717 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
32718 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
32719 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
32720 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
32721 l_recog_line_1                NUMBER;
32722 l_recog_line_2                NUMBER;
32723 
32724 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
32725 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
32726 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
32727 
32728 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
32729 
32730 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
32731 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
32732 
32733 ---------------------------------------------------------------------------------------------------------------
32734 
32735 
32736 --
32737 -- bulk performance
32738 --
32739 l_balance_type_code           VARCHAR2(1);
32740 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
32741 l_log_module                  VARCHAR2(240);
32742 
32743 --
32744 -- Upgrade strategy
32745 --
32746 l_actual_upg_option           VARCHAR2(1);
32747 l_enc_upg_option           VARCHAR2(1);
32748 
32749 --
32750 BEGIN
32751 --
32752 IF g_log_enabled THEN
32753       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_69';
32754 END IF;
32755 --
32756 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
32757 
32758       trace
32759          (p_msg      => 'BEGIN of AcctLineType_69'
32760          ,p_level    => C_LEVEL_PROCEDURE
32761          ,p_module   => l_log_module);
32762 
32763 END IF;
32764 --
32765 l_component_type             := 'AMB_JLT';
32766 l_component_code             := 'MISC_RCT_DEBT';
32767 l_component_type_code        := 'S';
32768 l_component_appl_id          :=  222;
32769 l_amb_context_code           := 'DEFAULT';
32770 l_entity_code                := 'RECEIPTS';
32771 l_event_class_code           := 'MISC_RECEIPT';
32772 l_event_type_code            := 'MISC_RECEIPT_ALL';
32773 l_line_definition_owner_code := 'S';
32774 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
32775 --
32776 l_balance_type_code          := 'A';
32777 l_segment                     := NULL;
32778 l_ccid                        := NULL;
32779 l_adr_transaction_coa_id      := NULL;
32780 l_adr_accounting_coa_id       := NULL;
32784 l_adr_value_combination_id    := NULL;
32781 l_adr_flexfield_segment_code  := NULL;
32782 l_adr_flex_value_set_id       := NULL;
32783 l_adr_value_type_code         := NULL;
32785 l_adr_value_segment_code      := NULL;
32786 
32787 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
32788 l_bflow_class_code           := '';    -- 4219869 Business Flow
32789 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
32790 l_budgetary_control_flag     := 'N';
32791 
32792 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
32793 l_bflow_applied_to_amt       := NULL; -- 5132302
32794 l_entered_amt_idx            := NULL;          -- 4262811
32795 l_accted_amt_idx             := NULL;          -- 4262811
32796 l_acc_rev_flag               := NULL;          -- 4262811
32797 l_accrual_line_num           := NULL;          -- 4262811
32798 l_tmp_amt                    := NULL;          -- 4262811
32799 --
32800  
32801 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
32802     l_balance_type_code <> 'B' THEN
32803 IF NVL(p_source_13,'
32804 ') =  'SHORT_TERM_DEBT' AND 
32805 NVL(p_source_52,'
32806 ') =  'N'
32807  THEN 
32808 
32809    --
32810    XLA_AE_LINES_PKG.SetNewLine;
32811 
32812    p_balance_type_code          := l_balance_type_code;
32813    -- set the flag so later we will know whether the gain loss line needs to be created
32814    
32815    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
32816      p_actual_flag :='A';
32817    END IF;
32818 
32819    --
32820    -- bulk performance
32821    --
32822    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
32823                                       p_header_num   => 0); -- 4262811
32824    --
32825    -- set accounting line options
32826    --
32827    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
32828            p_natural_side_code          => 'C'
32829          , p_gain_or_loss_flag          => 'N'
32830          , p_gl_transfer_mode_code      => 'S'
32831          , p_acct_entry_type_code       => 'A'
32832          , p_switch_side_flag           => 'Y'
32833          , p_merge_duplicate_code       => 'A'
32834          );
32835    --
32836    l_acc_rev_natural_side_code := 'D';  -- 4262811
32837    -- 
32838    --
32839    -- set accounting line type info
32840    --
32841    xla_ae_lines_pkg.SetAcctLineType
32842       (p_component_type             => l_component_type
32843       ,p_event_type_code            => l_event_type_code
32844       ,p_line_definition_owner_code => l_line_definition_owner_code
32845       ,p_line_definition_code       => l_line_definition_code
32846       ,p_accounting_line_code       => l_component_code
32847       ,p_accounting_line_type_code  => l_component_type_code
32848       ,p_accounting_line_appl_id    => l_component_appl_id
32849       ,p_amb_context_code           => l_amb_context_code
32850       ,p_entity_code                => l_entity_code
32851       ,p_event_class_code           => l_event_class_code);
32852    --
32853    -- set accounting class
32854    --
32855    xla_ae_lines_pkg.SetAcctClass(
32856            p_accounting_class_code  => 'SHORT_TERM_DEBT'
32857          , p_ae_header_id           => l_ae_header_id
32858          );
32859 
32860    --
32861    -- set rounding class
32862    --
32866    --
32863    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
32864                       'RECEIVABLE';
32865 
32867    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
32868    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
32869    --
32870    -- bulk performance
32871    --
32872    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
32873 
32874    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
32875       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
32876 
32877    -- 4955764
32878    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
32879       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
32880 
32881    -- 4458381 Public Sector Enh
32882    
32883    --
32884    -- set accounting attributes for the line type
32885    --
32886    l_entered_amt_idx := 3;
32887    l_accted_amt_idx  := 8;
32888    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
32889    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
32890    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
32891    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
32892    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
32893    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
32894    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
32895    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
32896    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
32897    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
32898    l_rec_acct_attrs.array_date_value(5)  := p_source_53;
32899    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
32900    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
32901    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
32902    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
32903    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
32904    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
32905 
32906    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
32907    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
32908 
32909    ---------------------------------------------------------------------------------------------------------------
32910    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
32911    ---------------------------------------------------------------------------------------------------------------
32912    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
32913 
32914    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
32915    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
32916 
32917    IF xla_accounting_cache_pkg.GetValueChar
32918          (p_source_code         => 'LEDGER_CATEGORY_CODE'
32919          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
32920    AND l_bflow_method_code = 'PRIOR_ENTRY'
32921 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
32922    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
32923          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
32924        )
32925    THEN
32926          xla_ae_lines_pkg.BflowUpgEntry
32927            (p_business_method_code    => l_bflow_method_code
32928            ,p_business_class_code     => l_bflow_class_code
32929            ,p_balance_type            => l_balance_type_code);
32930    ELSE
32931       NULL;
32932 -- No business flow processing for business flow method of NONE.
32933    END IF;
32934 
32935    --
32936    -- call analytical criteria
32937    --
32938    
32939    --
32940    -- call description
32941    --
32942    -- No description or it is inherited.
32943    --
32944    -- call ADRs
32945    -- Bug 4922099
32946    --
32947    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
32948         (NVL(l_actual_upg_option, 'N') = 'O') OR
32949         (NVL(l_enc_upg_option, 'N') = 'O')
32950       )
32951    THEN
32952    NULL;
32953    --
32954    --
32955    
32956   l_ccid := AcctDerRule_7(
32957            p_application_id           => p_application_id
32958          , p_ae_header_id             => l_ae_header_id 
32959 , p_source_3 => p_source_3
32960          , x_transaction_coa_id       => l_adr_transaction_coa_id
32961          , x_accounting_coa_id        => l_adr_accounting_coa_id
32962          , x_value_type_code          => l_adr_value_type_code
32963          , p_side                     => 'NA'
32964    );
32965 
32966    xla_ae_lines_pkg.set_ccid(
32967     p_code_combination_id          => l_ccid
32968   , p_value_type_code              => l_adr_value_type_code
32969   , p_transaction_coa_id           => l_adr_transaction_coa_id
32970   , p_accounting_coa_id            => l_adr_accounting_coa_id
32971   , p_adr_code                     => 'DIST_CCID'
32972   , p_adr_type_code                => 'S'
32973   , p_component_type               => l_component_type
32974   , p_component_code               => l_component_code
32975   , p_component_type_code          => l_component_type_code
32976   , p_component_appl_id            => l_component_appl_id
32977   , p_amb_context_code             => l_amb_context_code
32978   , p_side                         => 'NA'
32979   );
32980 
32981 
32982    --
32986    -- Bug 4922099
32983    --
32984    END IF;
32985    --
32987    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
32988           (NVL(l_enc_upg_option, 'N') = 'O')
32989         ) AND
32990         (l_bflow_method_code = 'PRIOR_ENTRY')
32991       )
32992    THEN
32993       IF
32994       --
32995       1 = 2
32996       --
32997       THEN
32998       xla_accounting_err_pkg.build_message
32999                                     (p_appli_s_name            => 'XLA'
33000                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
33001                                     ,p_token_1                 => 'LINE_NUMBER'
33002                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
33003                                     ,p_token_2                 => 'LINE_TYPE_NAME'
33004                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
33005                                                                              l_component_type
33006                                                                             ,l_component_code
33007                                                                             ,l_component_type_code
33008                                                                             ,l_component_appl_id
33009                                                                             ,l_amb_context_code
33010                                                                             ,l_entity_code
33011                                                                             ,l_event_class_code
33012                                                                            )
33013                                     ,p_token_3                 => 'OWNER'
33014                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
33015                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
33016                                                                           ,p_lookup_code    => l_component_type_code
33017                                                                          )
33018                                     ,p_token_4                 => 'PRODUCT_NAME'
33019                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
33020                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
33021                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
33022                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
33023                                     ,p_ae_header_id            =>  NULL
33024                                        );
33025 
33026         IF (C_LEVEL_ERROR>= g_log_level) THEN
33027                  trace
33028                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
33029                       ,p_level    => C_LEVEL_ERROR
33030                       ,p_module   => l_log_module);
33031         END IF;
33032       END IF;
33033    END IF;
33034    --
33035    --
33036    ------------------------------------------------------------------------------------------------
33037    -- 4219869 Business Flow
33038    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
33039    -- Prior Entry.  Currently, the following code is always generated.
33040    ------------------------------------------------------------------------------------------------
33041    XLA_AE_LINES_PKG.ValidateCurrentLine;
33042 
33043    ------------------------------------------------------------------------------------
33044    -- 4219869 Business Flow
33045    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
33046    ------------------------------------------------------------------------------------
33047    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
33048 
33049    ----------------------------------------------------------------------------------
33050    -- 4219869 Business Flow
33051    -- Update journal entry status -- Need to generate this within IF <condition>
33052    ----------------------------------------------------------------------------------
33053    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
33054          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
33055          ,p_balance_type_code => l_balance_type_code
33056          );
33057 
33058    -------------------------------------------------------------------------------------------
33059    -- 4262811 - Generate the Accrual Reversal lines
33060    -------------------------------------------------------------------------------------------
33061    BEGIN
33062       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
33063                               (g_array_event(p_event_id).array_value_num('header_index'));
33064       IF l_acc_rev_flag IS NULL THEN
33065          l_acc_rev_flag := 'N';
33066       END IF;
33067    EXCEPTION
33068       WHEN OTHERS THEN
33069          l_acc_rev_flag := 'N';
33070    END;
33071    --
33072    IF (l_acc_rev_flag = 'Y') THEN
33073 
33074        -- 4645092  ------------------------------------------------------------------------------
33075        -- To allow MPA report to determine if it should generate report process
33076        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
33077        ------------------------------------------------------------------------------------------
33078 
33079        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
33080        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
33081    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
33082    -- call ADRs
33083    -- Bug 4922099
33084    --
33088       )
33085    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
33086         (NVL(l_actual_upg_option, 'N') = 'O') OR
33087         (NVL(l_enc_upg_option, 'N') = 'O')
33089    THEN
33090    NULL;
33091    --
33092    --
33093    
33094   l_ccid := AcctDerRule_7(
33095            p_application_id           => p_application_id
33096          , p_ae_header_id             => l_ae_header_id 
33097 , p_source_3 => p_source_3
33098          , x_transaction_coa_id       => l_adr_transaction_coa_id
33099          , x_accounting_coa_id        => l_adr_accounting_coa_id
33100          , x_value_type_code          => l_adr_value_type_code
33101          , p_side                     => 'NA'
33102    );
33103 
33104    xla_ae_lines_pkg.set_ccid(
33105     p_code_combination_id          => l_ccid
33106   , p_value_type_code              => l_adr_value_type_code
33107   , p_transaction_coa_id           => l_adr_transaction_coa_id
33108   , p_accounting_coa_id            => l_adr_accounting_coa_id
33109   , p_adr_code                     => 'DIST_CCID'
33110   , p_adr_type_code                => 'S'
33111   , p_component_type               => l_component_type
33112   , p_component_code               => l_component_code
33113   , p_component_type_code          => l_component_type_code
33114   , p_component_appl_id            => l_component_appl_id
33115   , p_amb_context_code             => l_amb_context_code
33116   , p_side                         => 'NA'
33117   );
33118 
33119 
33120    --
33121    --
33122    END IF;
33123 
33124        --
33125        -- Update the line information that should be overwritten
33126        --
33127        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
33128                                          p_header_num   => 1);
33129        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
33130 
33131        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
33132 
33133        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
33134           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
33135        END IF;
33136 
33137       --
33138       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
33139       --
33140       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
33141           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
33142       ELSE
33143           ---------------------------------------------------------------------------------------------------
33144           -- 4262811a Switch Sign
33145           ---------------------------------------------------------------------------------------------------
33146           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
33147           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
33148                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
33149           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
33150                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
33151           -- 5132302
33152           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
33153                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
33154 
33155       END IF;
33156 
33157       -- 4955764
33158       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
33159       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
33160 
33161 
33162       XLA_AE_LINES_PKG.ValidateCurrentLine;
33163       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
33164 
33165       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
33166                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
33167                ,p_balance_type_code => l_balance_type_code);
33168 
33169    END IF;
33170 
33171    -----------------------------------------------------------------------------------------
33172    -- 4262811 Multiperiod Accounting
33173    -----------------------------------------------------------------------------------------
33174      -- No MPA option is assigned.
33175 
33176 
33177 END IF;
33178 END IF;
33179 --
33180 
33181 --
33182 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
33183    trace
33184       (p_msg      => 'END of AcctLineType_69'
33185       ,p_level    => C_LEVEL_PROCEDURE
33186       ,p_module   => l_log_module);
33187 END IF;
33188 --
33189 EXCEPTION
33190   WHEN xla_exceptions_pkg.application_exception THEN
33191       RAISE;
33192   WHEN OTHERS THEN
33193        xla_exceptions_pkg.raise_message
33194            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_69');
33195 END AcctLineType_69;
33196 --
33197 
33198 ---------------------------------------
33199 --
33200 -- PRIVATE FUNCTION
33201 --         AcctLineType_70
33202 --
33203 ---------------------------------------
33204 PROCEDURE AcctLineType_70 (
33205   p_application_id        IN NUMBER
33206  ,p_event_id              IN NUMBER
33207  ,p_calculate_acctd_flag  IN VARCHAR2
33208  ,p_calculate_g_l_flag    IN VARCHAR2
33209  ,p_actual_flag           IN OUT VARCHAR2
33210  ,p_balance_type_code     OUT VARCHAR2
33211  ,p_gain_or_loss_ref      OUT VARCHAR2
33212  
33213 --Distribution GL Account
33214  , p_source_3            IN NUMBER
33218  , p_source_15            IN NUMBER
33215 --Distribution Source Type
33216  , p_source_13            IN VARCHAR2
33217 --Distribution Line Identifier
33219 --Distribution Type
33220  , p_source_16            IN VARCHAR2
33221 --Entered Amount
33222  , p_source_17            IN NUMBER
33223 --Currency Code
33224  , p_source_18            IN VARCHAR2
33225 --Exchange Rate
33226  , p_source_20            IN NUMBER
33227 --Exchange Rate Type
33228  , p_source_21            IN VARCHAR2
33229 --Applied To Document Accounting Amount
33230  , p_source_22            IN NUMBER
33231 --Distribution Multi Fund Additional Entry
33232  , p_source_52            IN VARCHAR2
33233 --Applied To Document Exchange Date
33234  , p_source_53            IN DATE
33235 )
33236 IS
33237 
33238 l_component_type              VARCHAR2(80);
33239 l_component_code              VARCHAR2(30);
33240 l_component_type_code         VARCHAR2(1);
33241 l_component_appl_id           INTEGER;
33242 l_amb_context_code            VARCHAR2(30);
33243 l_entity_code                 VARCHAR2(30);
33244 l_event_class_code            VARCHAR2(30);
33245 l_ae_header_id                NUMBER;
33246 l_event_type_code             VARCHAR2(30);
33247 l_line_definition_code        VARCHAR2(30);
33248 l_line_definition_owner_code  VARCHAR2(1);
33249 --
33250 -- adr variables
33251 l_segment                     VARCHAR2(30);
33252 l_ccid                        NUMBER;
33253 l_adr_transaction_coa_id      NUMBER;
33254 l_adr_accounting_coa_id       NUMBER;
33255 l_adr_flexfield_segment_code  VARCHAR2(30);
33256 l_adr_flex_value_set_id       NUMBER;
33257 l_adr_value_type_code         VARCHAR2(30);
33258 l_adr_value_combination_id    NUMBER;
33259 l_adr_value_segment_code      VARCHAR2(30);
33260 
33261 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
33262 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
33263 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
33264 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
33265 
33266 -- 4262811 Variables ------------------------------------------------------------------------------------------
33267 l_entered_amt_idx             NUMBER;
33268 l_accted_amt_idx              NUMBER;
33269 l_acc_rev_flag                VARCHAR2(1);
33270 l_accrual_line_num            NUMBER;
33271 l_tmp_amt                     NUMBER;
33272 l_acc_rev_natural_side_code   VARCHAR2(1);
33273 
33274 l_num_entries                 NUMBER;
33275 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
33276 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
33277 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
33278 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
33279 l_recog_line_1                NUMBER;
33280 l_recog_line_2                NUMBER;
33281 
33282 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
33283 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
33284 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
33285 
33286 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
33287 
33288 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
33289 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
33290 
33291 ---------------------------------------------------------------------------------------------------------------
33292 
33293 
33294 --
33295 -- bulk performance
33296 --
33297 l_balance_type_code           VARCHAR2(1);
33298 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
33299 l_log_module                  VARCHAR2(240);
33300 
33301 --
33302 -- Upgrade strategy
33303 --
33304 l_actual_upg_option           VARCHAR2(1);
33305 l_enc_upg_option           VARCHAR2(1);
33306 
33307 --
33308 BEGIN
33309 --
33310 IF g_log_enabled THEN
33311       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_70';
33312 END IF;
33313 --
33314 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
33315 
33316       trace
33317          (p_msg      => 'BEGIN of AcctLineType_70'
33318          ,p_level    => C_LEVEL_PROCEDURE
33319          ,p_module   => l_log_module);
33320 
33321 END IF;
33322 --
33323 l_component_type             := 'AMB_JLT';
33324 l_component_code             := 'MISC_RCT_FACTOR';
33325 l_component_type_code        := 'S';
33326 l_component_appl_id          :=  222;
33327 l_amb_context_code           := 'DEFAULT';
33328 l_entity_code                := 'RECEIPTS';
33329 l_event_class_code           := 'MISC_RECEIPT';
33330 l_event_type_code            := 'MISC_RECEIPT_ALL';
33331 l_line_definition_owner_code := 'S';
33332 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
33333 --
33334 l_balance_type_code          := 'A';
33335 l_segment                     := NULL;
33336 l_ccid                        := NULL;
33337 l_adr_transaction_coa_id      := NULL;
33338 l_adr_accounting_coa_id       := NULL;
33339 l_adr_flexfield_segment_code  := NULL;
33340 l_adr_flex_value_set_id       := NULL;
33341 l_adr_value_type_code         := NULL;
33342 l_adr_value_combination_id    := NULL;
33343 l_adr_value_segment_code      := NULL;
33344 
33345 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
33346 l_bflow_class_code           := '';    -- 4219869 Business Flow
33347 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
33351 l_bflow_applied_to_amt       := NULL; -- 5132302
33348 l_budgetary_control_flag     := 'N';
33349 
33350 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
33352 l_entered_amt_idx            := NULL;          -- 4262811
33353 l_accted_amt_idx             := NULL;          -- 4262811
33354 l_acc_rev_flag               := NULL;          -- 4262811
33355 l_accrual_line_num           := NULL;          -- 4262811
33356 l_tmp_amt                    := NULL;          -- 4262811
33357 --
33358  
33359 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
33360     l_balance_type_code <> 'B' THEN
33361 IF NVL(p_source_13,'
33362 ') =  'FACTOR' AND 
33363 NVL(p_source_52,'
33364 ') =  'N'
33365  THEN 
33366 
33367    --
33368    XLA_AE_LINES_PKG.SetNewLine;
33369 
33370    p_balance_type_code          := l_balance_type_code;
33371    -- set the flag so later we will know whether the gain loss line needs to be created
33372    
33373    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
33374      p_actual_flag :='A';
33375    END IF;
33376 
33377    --
33378    -- bulk performance
33379    --
33380    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
33381                                       p_header_num   => 0); -- 4262811
33382    --
33383    -- set accounting line options
33384    --
33385    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
33386            p_natural_side_code          => 'C'
33387          , p_gain_or_loss_flag          => 'N'
33388          , p_gl_transfer_mode_code      => 'S'
33389          , p_acct_entry_type_code       => 'A'
33390          , p_switch_side_flag           => 'Y'
33391          , p_merge_duplicate_code       => 'A'
33392          );
33393    --
33394    l_acc_rev_natural_side_code := 'D';  -- 4262811
33395    -- 
33396    --
33397    -- set accounting line type info
33398    --
33399    xla_ae_lines_pkg.SetAcctLineType
33400       (p_component_type             => l_component_type
33401       ,p_event_type_code            => l_event_type_code
33402       ,p_line_definition_owner_code => l_line_definition_owner_code
33403       ,p_line_definition_code       => l_line_definition_code
33404       ,p_accounting_line_code       => l_component_code
33405       ,p_accounting_line_type_code  => l_component_type_code
33406       ,p_accounting_line_appl_id    => l_component_appl_id
33407       ,p_amb_context_code           => l_amb_context_code
33408       ,p_entity_code                => l_entity_code
33409       ,p_event_class_code           => l_event_class_code);
33410    --
33411    -- set accounting class
33412    --
33413    xla_ae_lines_pkg.SetAcctClass(
33414            p_accounting_class_code  => 'FACTOR'
33415          , p_ae_header_id           => l_ae_header_id
33416          );
33417 
33418    --
33419    -- set rounding class
33420    --
33421    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
33422                       'RECEIVABLE';
33423 
33424    --
33425    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
33426    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
33427    --
33428    -- bulk performance
33429    --
33430    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
33431 
33432    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
33433       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
33434 
33435    -- 4955764
33436    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
33437       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
33438 
33439    -- 4458381 Public Sector Enh
33440    
33441    --
33442    -- set accounting attributes for the line type
33443    --
33444    l_entered_amt_idx := 3;
33445    l_accted_amt_idx  := 8;
33446    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
33447    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
33448    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
33449    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
33450    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
33451    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
33452    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
33453    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
33454    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
33455    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
33456    l_rec_acct_attrs.array_date_value(5)  := p_source_53;
33457    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
33458    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
33459    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
33460    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
33461    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
33462    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
33463 
33464    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
33465    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
33466 
33467    ---------------------------------------------------------------------------------------------------------------
33468    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
33472    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
33469    ---------------------------------------------------------------------------------------------------------------
33470    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
33471 
33473    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
33474 
33475    IF xla_accounting_cache_pkg.GetValueChar
33476          (p_source_code         => 'LEDGER_CATEGORY_CODE'
33477          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
33478    AND l_bflow_method_code = 'PRIOR_ENTRY'
33479 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
33480    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
33481          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
33482        )
33483    THEN
33484          xla_ae_lines_pkg.BflowUpgEntry
33485            (p_business_method_code    => l_bflow_method_code
33486            ,p_business_class_code     => l_bflow_class_code
33487            ,p_balance_type            => l_balance_type_code);
33488    ELSE
33489       NULL;
33490 -- No business flow processing for business flow method of NONE.
33491    END IF;
33492 
33493    --
33494    -- call analytical criteria
33495    --
33496    
33497    --
33498    -- call description
33499    --
33500    -- No description or it is inherited.
33501    --
33502    -- call ADRs
33503    -- Bug 4922099
33504    --
33505    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
33506         (NVL(l_actual_upg_option, 'N') = 'O') OR
33507         (NVL(l_enc_upg_option, 'N') = 'O')
33508       )
33509    THEN
33510    NULL;
33511    --
33512    --
33513    
33514   l_ccid := AcctDerRule_7(
33515            p_application_id           => p_application_id
33516          , p_ae_header_id             => l_ae_header_id 
33517 , p_source_3 => p_source_3
33518          , x_transaction_coa_id       => l_adr_transaction_coa_id
33519          , x_accounting_coa_id        => l_adr_accounting_coa_id
33520          , x_value_type_code          => l_adr_value_type_code
33521          , p_side                     => 'NA'
33522    );
33523 
33524    xla_ae_lines_pkg.set_ccid(
33525     p_code_combination_id          => l_ccid
33526   , p_value_type_code              => l_adr_value_type_code
33527   , p_transaction_coa_id           => l_adr_transaction_coa_id
33528   , p_accounting_coa_id            => l_adr_accounting_coa_id
33529   , p_adr_code                     => 'DIST_CCID'
33530   , p_adr_type_code                => 'S'
33531   , p_component_type               => l_component_type
33532   , p_component_code               => l_component_code
33533   , p_component_type_code          => l_component_type_code
33534   , p_component_appl_id            => l_component_appl_id
33535   , p_amb_context_code             => l_amb_context_code
33536   , p_side                         => 'NA'
33537   );
33538 
33539 
33540    --
33541    --
33542    END IF;
33543    --
33544    -- Bug 4922099
33545    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
33546           (NVL(l_enc_upg_option, 'N') = 'O')
33547         ) AND
33548         (l_bflow_method_code = 'PRIOR_ENTRY')
33549       )
33550    THEN
33551       IF
33552       --
33553       1 = 2
33554       --
33555       THEN
33556       xla_accounting_err_pkg.build_message
33557                                     (p_appli_s_name            => 'XLA'
33558                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
33559                                     ,p_token_1                 => 'LINE_NUMBER'
33560                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
33561                                     ,p_token_2                 => 'LINE_TYPE_NAME'
33562                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
33563                                                                              l_component_type
33564                                                                             ,l_component_code
33565                                                                             ,l_component_type_code
33566                                                                             ,l_component_appl_id
33567                                                                             ,l_amb_context_code
33568                                                                             ,l_entity_code
33569                                                                             ,l_event_class_code
33570                                                                            )
33571                                     ,p_token_3                 => 'OWNER'
33572                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
33573                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
33574                                                                           ,p_lookup_code    => l_component_type_code
33575                                                                          )
33576                                     ,p_token_4                 => 'PRODUCT_NAME'
33577                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
33581                                     ,p_ae_header_id            =>  NULL
33578                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
33579                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
33580                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
33582                                        );
33583 
33584         IF (C_LEVEL_ERROR>= g_log_level) THEN
33585                  trace
33586                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
33587                       ,p_level    => C_LEVEL_ERROR
33588                       ,p_module   => l_log_module);
33589         END IF;
33590       END IF;
33591    END IF;
33592    --
33593    --
33594    ------------------------------------------------------------------------------------------------
33595    -- 4219869 Business Flow
33596    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
33597    -- Prior Entry.  Currently, the following code is always generated.
33598    ------------------------------------------------------------------------------------------------
33599    XLA_AE_LINES_PKG.ValidateCurrentLine;
33600 
33601    ------------------------------------------------------------------------------------
33602    -- 4219869 Business Flow
33603    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
33604    ------------------------------------------------------------------------------------
33605    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
33606 
33607    ----------------------------------------------------------------------------------
33608    -- 4219869 Business Flow
33609    -- Update journal entry status -- Need to generate this within IF <condition>
33610    ----------------------------------------------------------------------------------
33611    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
33612          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
33613          ,p_balance_type_code => l_balance_type_code
33614          );
33615 
33616    -------------------------------------------------------------------------------------------
33617    -- 4262811 - Generate the Accrual Reversal lines
33618    -------------------------------------------------------------------------------------------
33619    BEGIN
33620       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
33621                               (g_array_event(p_event_id).array_value_num('header_index'));
33622       IF l_acc_rev_flag IS NULL THEN
33623          l_acc_rev_flag := 'N';
33624       END IF;
33625    EXCEPTION
33626       WHEN OTHERS THEN
33627          l_acc_rev_flag := 'N';
33628    END;
33629    --
33630    IF (l_acc_rev_flag = 'Y') THEN
33631 
33632        -- 4645092  ------------------------------------------------------------------------------
33633        -- To allow MPA report to determine if it should generate report process
33634        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
33635        ------------------------------------------------------------------------------------------
33636 
33637        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
33638        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
33639    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
33640    -- call ADRs
33641    -- Bug 4922099
33642    --
33643    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
33644         (NVL(l_actual_upg_option, 'N') = 'O') OR
33645         (NVL(l_enc_upg_option, 'N') = 'O')
33646       )
33647    THEN
33648    NULL;
33649    --
33650    --
33651    
33652   l_ccid := AcctDerRule_7(
33653            p_application_id           => p_application_id
33654          , p_ae_header_id             => l_ae_header_id 
33655 , p_source_3 => p_source_3
33656          , x_transaction_coa_id       => l_adr_transaction_coa_id
33657          , x_accounting_coa_id        => l_adr_accounting_coa_id
33658          , x_value_type_code          => l_adr_value_type_code
33659          , p_side                     => 'NA'
33660    );
33661 
33662    xla_ae_lines_pkg.set_ccid(
33663     p_code_combination_id          => l_ccid
33664   , p_value_type_code              => l_adr_value_type_code
33665   , p_transaction_coa_id           => l_adr_transaction_coa_id
33666   , p_accounting_coa_id            => l_adr_accounting_coa_id
33667   , p_adr_code                     => 'DIST_CCID'
33668   , p_adr_type_code                => 'S'
33669   , p_component_type               => l_component_type
33670   , p_component_code               => l_component_code
33671   , p_component_type_code          => l_component_type_code
33672   , p_component_appl_id            => l_component_appl_id
33673   , p_amb_context_code             => l_amb_context_code
33674   , p_side                         => 'NA'
33675   );
33676 
33677 
33678    --
33679    --
33680    END IF;
33681 
33682        --
33683        -- Update the line information that should be overwritten
33684        --
33685        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
33686                                          p_header_num   => 1);
33687        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
33688 
33689        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
33690 
33691        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
33695       --
33692           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
33693        END IF;
33694 
33696       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
33697       --
33698       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
33699           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
33700       ELSE
33701           ---------------------------------------------------------------------------------------------------
33702           -- 4262811a Switch Sign
33703           ---------------------------------------------------------------------------------------------------
33704           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
33705           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
33706                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
33707           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
33708                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
33709           -- 5132302
33710           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
33711                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
33712 
33713       END IF;
33714 
33715       -- 4955764
33716       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
33717       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
33718 
33719 
33720       XLA_AE_LINES_PKG.ValidateCurrentLine;
33721       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
33722 
33723       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
33724                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
33725                ,p_balance_type_code => l_balance_type_code);
33726 
33727    END IF;
33728 
33729    -----------------------------------------------------------------------------------------
33730    -- 4262811 Multiperiod Accounting
33731    -----------------------------------------------------------------------------------------
33732      -- No MPA option is assigned.
33733 
33734 
33735 END IF;
33736 END IF;
33737 --
33738 
33739 --
33740 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
33741    trace
33742       (p_msg      => 'END of AcctLineType_70'
33743       ,p_level    => C_LEVEL_PROCEDURE
33744       ,p_module   => l_log_module);
33745 END IF;
33746 --
33747 EXCEPTION
33748   WHEN xla_exceptions_pkg.application_exception THEN
33749       RAISE;
33750   WHEN OTHERS THEN
33751        xla_exceptions_pkg.raise_message
33752            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_70');
33753 END AcctLineType_70;
33754 --
33755 
33756 ---------------------------------------
33757 --
33758 -- PRIVATE FUNCTION
33759 --         AcctLineType_71
33760 --
33761 ---------------------------------------
33762 PROCEDURE AcctLineType_71 (
33763   p_application_id        IN NUMBER
33764  ,p_event_id              IN NUMBER
33765  ,p_calculate_acctd_flag  IN VARCHAR2
33766  ,p_calculate_g_l_flag    IN VARCHAR2
33767  ,p_actual_flag           IN OUT VARCHAR2
33768  ,p_balance_type_code     OUT VARCHAR2
33769  ,p_gain_or_loss_ref      OUT VARCHAR2
33770  
33771 --Distribution GL Account
33772  , p_source_3            IN NUMBER
33773 --Distribution Source Type
33774  , p_source_13            IN VARCHAR2
33775 --Distribution Line Identifier
33776  , p_source_15            IN NUMBER
33777 --Distribution Type
33778  , p_source_16            IN VARCHAR2
33779 --Entered Amount
33780  , p_source_17            IN NUMBER
33781 --Currency Code
33782  , p_source_18            IN VARCHAR2
33783 --Exchange Rate
33784  , p_source_20            IN NUMBER
33785 --Exchange Rate Type
33786  , p_source_21            IN VARCHAR2
33787 --Applied To Document Accounting Amount
33788  , p_source_22            IN NUMBER
33789 --Distribution Multi Fund Additional Entry
33790  , p_source_52            IN VARCHAR2
33791 --Applied To Document Exchange Date
33792  , p_source_53            IN DATE
33793 )
33794 IS
33795 
33796 l_component_type              VARCHAR2(80);
33797 l_component_code              VARCHAR2(30);
33798 l_component_type_code         VARCHAR2(1);
33799 l_component_appl_id           INTEGER;
33800 l_amb_context_code            VARCHAR2(30);
33801 l_entity_code                 VARCHAR2(30);
33802 l_event_class_code            VARCHAR2(30);
33803 l_ae_header_id                NUMBER;
33804 l_event_type_code             VARCHAR2(30);
33805 l_line_definition_code        VARCHAR2(30);
33806 l_line_definition_owner_code  VARCHAR2(1);
33807 --
33808 -- adr variables
33809 l_segment                     VARCHAR2(30);
33810 l_ccid                        NUMBER;
33811 l_adr_transaction_coa_id      NUMBER;
33812 l_adr_accounting_coa_id       NUMBER;
33813 l_adr_flexfield_segment_code  VARCHAR2(30);
33814 l_adr_flex_value_set_id       NUMBER;
33815 l_adr_value_type_code         VARCHAR2(30);
33816 l_adr_value_combination_id    NUMBER;
33817 l_adr_value_segment_code      VARCHAR2(30);
33818 
33819 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
33820 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
33821 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
33822 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
33823 
33827 l_acc_rev_flag                VARCHAR2(1);
33824 -- 4262811 Variables ------------------------------------------------------------------------------------------
33825 l_entered_amt_idx             NUMBER;
33826 l_accted_amt_idx              NUMBER;
33828 l_accrual_line_num            NUMBER;
33829 l_tmp_amt                     NUMBER;
33830 l_acc_rev_natural_side_code   VARCHAR2(1);
33831 
33832 l_num_entries                 NUMBER;
33833 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
33834 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
33835 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
33836 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
33837 l_recog_line_1                NUMBER;
33838 l_recog_line_2                NUMBER;
33839 
33840 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
33841 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
33842 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
33843 
33844 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
33845 
33846 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
33847 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
33848 
33849 ---------------------------------------------------------------------------------------------------------------
33850 
33851 
33852 --
33853 -- bulk performance
33854 --
33855 l_balance_type_code           VARCHAR2(1);
33856 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
33857 l_log_module                  VARCHAR2(240);
33858 
33859 --
33860 -- Upgrade strategy
33861 --
33862 l_actual_upg_option           VARCHAR2(1);
33863 l_enc_upg_option           VARCHAR2(1);
33864 
33865 --
33866 BEGIN
33867 --
33868 IF g_log_enabled THEN
33869       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_71';
33870 END IF;
33871 --
33872 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
33873 
33874       trace
33875          (p_msg      => 'BEGIN of AcctLineType_71'
33876          ,p_level    => C_LEVEL_PROCEDURE
33877          ,p_module   => l_log_module);
33878 
33879 END IF;
33880 --
33881 l_component_type             := 'AMB_JLT';
33882 l_component_code             := 'MISC_RCT_MISCCASH';
33883 l_component_type_code        := 'S';
33884 l_component_appl_id          :=  222;
33885 l_amb_context_code           := 'DEFAULT';
33886 l_entity_code                := 'RECEIPTS';
33887 l_event_class_code           := 'MISC_RECEIPT';
33888 l_event_type_code            := 'MISC_RECEIPT_ALL';
33889 l_line_definition_owner_code := 'S';
33890 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
33891 --
33892 l_balance_type_code          := 'A';
33893 l_segment                     := NULL;
33894 l_ccid                        := NULL;
33895 l_adr_transaction_coa_id      := NULL;
33896 l_adr_accounting_coa_id       := NULL;
33897 l_adr_flexfield_segment_code  := NULL;
33898 l_adr_flex_value_set_id       := NULL;
33899 l_adr_value_type_code         := NULL;
33900 l_adr_value_combination_id    := NULL;
33901 l_adr_value_segment_code      := NULL;
33902 
33903 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
33904 l_bflow_class_code           := '';    -- 4219869 Business Flow
33905 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
33906 l_budgetary_control_flag     := 'N';
33907 
33908 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
33909 l_bflow_applied_to_amt       := NULL; -- 5132302
33910 l_entered_amt_idx            := NULL;          -- 4262811
33911 l_accted_amt_idx             := NULL;          -- 4262811
33912 l_acc_rev_flag               := NULL;          -- 4262811
33913 l_accrual_line_num           := NULL;          -- 4262811
33914 l_tmp_amt                    := NULL;          -- 4262811
33915 --
33916  
33917 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
33918     l_balance_type_code <> 'B' THEN
33919 IF NVL(p_source_13,'
33920 ') =  'MISCCASH' AND 
33921 NVL(p_source_52,'
33922 ') =  'N'
33923  THEN 
33924 
33925    --
33926    XLA_AE_LINES_PKG.SetNewLine;
33927 
33928    p_balance_type_code          := l_balance_type_code;
33929    -- set the flag so later we will know whether the gain loss line needs to be created
33930    
33931    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
33932      p_actual_flag :='A';
33933    END IF;
33934 
33935    --
33936    -- bulk performance
33937    --
33938    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
33939                                       p_header_num   => 0); -- 4262811
33940    --
33941    -- set accounting line options
33942    --
33943    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
33944            p_natural_side_code          => 'C'
33945          , p_gain_or_loss_flag          => 'N'
33946          , p_gl_transfer_mode_code      => 'S'
33947          , p_acct_entry_type_code       => 'A'
33948          , p_switch_side_flag           => 'Y'
33949          , p_merge_duplicate_code       => 'A'
33950          );
33951    --
33952    l_acc_rev_natural_side_code := 'D';  -- 4262811
33953    -- 
33954    --
33955    -- set accounting line type info
33956    --
33957    xla_ae_lines_pkg.SetAcctLineType
33958       (p_component_type             => l_component_type
33959       ,p_event_type_code            => l_event_type_code
33960       ,p_line_definition_owner_code => l_line_definition_owner_code
33961       ,p_line_definition_code       => l_line_definition_code
33965       ,p_amb_context_code           => l_amb_context_code
33962       ,p_accounting_line_code       => l_component_code
33963       ,p_accounting_line_type_code  => l_component_type_code
33964       ,p_accounting_line_appl_id    => l_component_appl_id
33966       ,p_entity_code                => l_entity_code
33967       ,p_event_class_code           => l_event_class_code);
33968    --
33969    -- set accounting class
33970    --
33971    xla_ae_lines_pkg.SetAcctClass(
33972            p_accounting_class_code  => 'MISC_CASH'
33973          , p_ae_header_id           => l_ae_header_id
33974          );
33975 
33976    --
33977    -- set rounding class
33978    --
33979    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
33980                       'RECEIVABLE';
33981 
33982    --
33983    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
33984    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
33985    --
33986    -- bulk performance
33987    --
33988    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
33989 
33990    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
33991       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
33992 
33993    -- 4955764
33994    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
33995       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
33996 
33997    -- 4458381 Public Sector Enh
33998    
33999    --
34000    -- set accounting attributes for the line type
34001    --
34002    l_entered_amt_idx := 3;
34003    l_accted_amt_idx  := 8;
34004    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
34005    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
34006    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
34007    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
34008    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
34009    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
34010    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
34011    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
34012    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
34013    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
34014    l_rec_acct_attrs.array_date_value(5)  := p_source_53;
34015    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
34016    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
34017    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
34018    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
34019    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
34020    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
34021 
34022    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
34023    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
34024 
34025    ---------------------------------------------------------------------------------------------------------------
34026    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
34027    ---------------------------------------------------------------------------------------------------------------
34028    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
34029 
34030    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
34031    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
34032 
34033    IF xla_accounting_cache_pkg.GetValueChar
34034          (p_source_code         => 'LEDGER_CATEGORY_CODE'
34035          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
34036    AND l_bflow_method_code = 'PRIOR_ENTRY'
34037 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
34038    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
34039          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
34040        )
34041    THEN
34042          xla_ae_lines_pkg.BflowUpgEntry
34043            (p_business_method_code    => l_bflow_method_code
34044            ,p_business_class_code     => l_bflow_class_code
34045            ,p_balance_type            => l_balance_type_code);
34046    ELSE
34047       NULL;
34048 -- No business flow processing for business flow method of NONE.
34049    END IF;
34050 
34051    --
34052    -- call analytical criteria
34053    --
34054    
34055    --
34056    -- call description
34057    --
34058    -- No description or it is inherited.
34059    --
34060    -- call ADRs
34061    -- Bug 4922099
34062    --
34063    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
34064         (NVL(l_actual_upg_option, 'N') = 'O') OR
34065         (NVL(l_enc_upg_option, 'N') = 'O')
34066       )
34067    THEN
34068    NULL;
34069    --
34070    --
34071    
34072   l_ccid := AcctDerRule_7(
34073            p_application_id           => p_application_id
34074          , p_ae_header_id             => l_ae_header_id 
34075 , p_source_3 => p_source_3
34076          , x_transaction_coa_id       => l_adr_transaction_coa_id
34077          , x_accounting_coa_id        => l_adr_accounting_coa_id
34078          , x_value_type_code          => l_adr_value_type_code
34079          , p_side                     => 'NA'
34080    );
34081 
34082    xla_ae_lines_pkg.set_ccid(
34083     p_code_combination_id          => l_ccid
34084   , p_value_type_code              => l_adr_value_type_code
34085   , p_transaction_coa_id           => l_adr_transaction_coa_id
34086   , p_accounting_coa_id            => l_adr_accounting_coa_id
34087   , p_adr_code                     => 'DIST_CCID'
34088   , p_adr_type_code                => 'S'
34089   , p_component_type               => l_component_type
34090   , p_component_code               => l_component_code
34091   , p_component_type_code          => l_component_type_code
34092   , p_component_appl_id            => l_component_appl_id
34093   , p_amb_context_code             => l_amb_context_code
34094   , p_side                         => 'NA'
34095   );
34096 
34097 
34098    --
34099    --
34100    END IF;
34101    --
34102    -- Bug 4922099
34103    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
34104           (NVL(l_enc_upg_option, 'N') = 'O')
34105         ) AND
34106         (l_bflow_method_code = 'PRIOR_ENTRY')
34107       )
34108    THEN
34109       IF
34110       --
34111       1 = 2
34112       --
34113       THEN
34114       xla_accounting_err_pkg.build_message
34115                                     (p_appli_s_name            => 'XLA'
34116                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
34117                                     ,p_token_1                 => 'LINE_NUMBER'
34118                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
34119                                     ,p_token_2                 => 'LINE_TYPE_NAME'
34120                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
34121                                                                              l_component_type
34122                                                                             ,l_component_code
34123                                                                             ,l_component_type_code
34124                                                                             ,l_component_appl_id
34125                                                                             ,l_amb_context_code
34126                                                                             ,l_entity_code
34127                                                                             ,l_event_class_code
34128                                                                            )
34129                                     ,p_token_3                 => 'OWNER'
34130                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
34131                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
34132                                                                           ,p_lookup_code    => l_component_type_code
34133                                                                          )
34134                                     ,p_token_4                 => 'PRODUCT_NAME'
34135                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
34136                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
34137                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
34138                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
34139                                     ,p_ae_header_id            =>  NULL
34140                                        );
34141 
34142         IF (C_LEVEL_ERROR>= g_log_level) THEN
34143                  trace
34144                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
34145                       ,p_level    => C_LEVEL_ERROR
34146                       ,p_module   => l_log_module);
34147         END IF;
34148       END IF;
34149    END IF;
34150    --
34151    --
34152    ------------------------------------------------------------------------------------------------
34153    -- 4219869 Business Flow
34154    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
34155    -- Prior Entry.  Currently, the following code is always generated.
34156    ------------------------------------------------------------------------------------------------
34157    XLA_AE_LINES_PKG.ValidateCurrentLine;
34158 
34159    ------------------------------------------------------------------------------------
34160    -- 4219869 Business Flow
34161    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
34162    ------------------------------------------------------------------------------------
34163    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
34164 
34165    ----------------------------------------------------------------------------------
34166    -- 4219869 Business Flow
34167    -- Update journal entry status -- Need to generate this within IF <condition>
34168    ----------------------------------------------------------------------------------
34169    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
34170          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
34171          ,p_balance_type_code => l_balance_type_code
34172          );
34173 
34174    -------------------------------------------------------------------------------------------
34175    -- 4262811 - Generate the Accrual Reversal lines
34176    -------------------------------------------------------------------------------------------
34177    BEGIN
34178       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
34179                               (g_array_event(p_event_id).array_value_num('header_index'));
34180       IF l_acc_rev_flag IS NULL THEN
34184       WHEN OTHERS THEN
34181          l_acc_rev_flag := 'N';
34182       END IF;
34183    EXCEPTION
34185          l_acc_rev_flag := 'N';
34186    END;
34187    --
34188    IF (l_acc_rev_flag = 'Y') THEN
34189 
34190        -- 4645092  ------------------------------------------------------------------------------
34191        -- To allow MPA report to determine if it should generate report process
34192        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
34193        ------------------------------------------------------------------------------------------
34194 
34195        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
34196        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
34197    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
34198    -- call ADRs
34199    -- Bug 4922099
34200    --
34201    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
34202         (NVL(l_actual_upg_option, 'N') = 'O') OR
34203         (NVL(l_enc_upg_option, 'N') = 'O')
34204       )
34205    THEN
34206    NULL;
34207    --
34208    --
34209    
34210   l_ccid := AcctDerRule_7(
34211            p_application_id           => p_application_id
34212          , p_ae_header_id             => l_ae_header_id 
34213 , p_source_3 => p_source_3
34214          , x_transaction_coa_id       => l_adr_transaction_coa_id
34215          , x_accounting_coa_id        => l_adr_accounting_coa_id
34216          , x_value_type_code          => l_adr_value_type_code
34217          , p_side                     => 'NA'
34218    );
34219 
34220    xla_ae_lines_pkg.set_ccid(
34221     p_code_combination_id          => l_ccid
34222   , p_value_type_code              => l_adr_value_type_code
34223   , p_transaction_coa_id           => l_adr_transaction_coa_id
34224   , p_accounting_coa_id            => l_adr_accounting_coa_id
34225   , p_adr_code                     => 'DIST_CCID'
34226   , p_adr_type_code                => 'S'
34227   , p_component_type               => l_component_type
34228   , p_component_code               => l_component_code
34229   , p_component_type_code          => l_component_type_code
34230   , p_component_appl_id            => l_component_appl_id
34231   , p_amb_context_code             => l_amb_context_code
34232   , p_side                         => 'NA'
34233   );
34234 
34235 
34236    --
34237    --
34238    END IF;
34239 
34240        --
34241        -- Update the line information that should be overwritten
34242        --
34243        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
34244                                          p_header_num   => 1);
34245        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
34246 
34247        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
34248 
34249        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
34250           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
34251        END IF;
34252 
34253       --
34254       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
34255       --
34256       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
34257           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
34258       ELSE
34259           ---------------------------------------------------------------------------------------------------
34260           -- 4262811a Switch Sign
34261           ---------------------------------------------------------------------------------------------------
34262           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
34263           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
34267           -- 5132302
34264                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
34265           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
34266                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
34268           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
34269                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
34270 
34271       END IF;
34272 
34273       -- 4955764
34274       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
34275       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
34276 
34277 
34278       XLA_AE_LINES_PKG.ValidateCurrentLine;
34279       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
34280 
34281       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
34282                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
34283                ,p_balance_type_code => l_balance_type_code);
34284 
34285    END IF;
34286 
34287    -----------------------------------------------------------------------------------------
34288    -- 4262811 Multiperiod Accounting
34289    -----------------------------------------------------------------------------------------
34290      -- No MPA option is assigned.
34291 
34292 
34293 END IF;
34294 END IF;
34295 --
34296 
34297 --
34298 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
34299    trace
34300       (p_msg      => 'END of AcctLineType_71'
34301       ,p_level    => C_LEVEL_PROCEDURE
34302       ,p_module   => l_log_module);
34303 END IF;
34304 --
34305 EXCEPTION
34306   WHEN xla_exceptions_pkg.application_exception THEN
34307       RAISE;
34308   WHEN OTHERS THEN
34309        xla_exceptions_pkg.raise_message
34310            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_71');
34311 END AcctLineType_71;
34312 --
34313 
34314 ---------------------------------------
34315 --
34316 -- PRIVATE FUNCTION
34317 --         AcctLineType_72
34318 --
34319 ---------------------------------------
34320 PROCEDURE AcctLineType_72 (
34321   p_application_id        IN NUMBER
34322  ,p_event_id              IN NUMBER
34323  ,p_calculate_acctd_flag  IN VARCHAR2
34324  ,p_calculate_g_l_flag    IN VARCHAR2
34325  ,p_actual_flag           IN OUT VARCHAR2
34326  ,p_balance_type_code     OUT VARCHAR2
34327  ,p_gain_or_loss_ref      OUT VARCHAR2
34328  
34329 --Distribution GL Account
34330  , p_source_3            IN NUMBER
34331 --Distribution Source Type
34332  , p_source_13            IN VARCHAR2
34333 --Distribution Line Identifier
34334  , p_source_15            IN NUMBER
34335 --Distribution Type
34336  , p_source_16            IN VARCHAR2
34337 --Entered Amount
34338  , p_source_17            IN NUMBER
34339 --Currency Code
34340  , p_source_18            IN VARCHAR2
34341 --Exchange Rate
34342  , p_source_20            IN NUMBER
34343 --Exchange Rate Type
34344  , p_source_21            IN VARCHAR2
34345 --Applied To Document Accounting Amount
34346  , p_source_22            IN NUMBER
34347 --Distribution Multi Fund Additional Entry
34348  , p_source_52            IN VARCHAR2
34349 --Applied To Document Exchange Date
34350  , p_source_53            IN DATE
34351 )
34352 IS
34353 
34354 l_component_type              VARCHAR2(80);
34355 l_component_code              VARCHAR2(30);
34356 l_component_type_code         VARCHAR2(1);
34357 l_component_appl_id           INTEGER;
34358 l_amb_context_code            VARCHAR2(30);
34359 l_entity_code                 VARCHAR2(30);
34360 l_event_class_code            VARCHAR2(30);
34361 l_ae_header_id                NUMBER;
34362 l_event_type_code             VARCHAR2(30);
34363 l_line_definition_code        VARCHAR2(30);
34364 l_line_definition_owner_code  VARCHAR2(1);
34365 --
34366 -- adr variables
34367 l_segment                     VARCHAR2(30);
34368 l_ccid                        NUMBER;
34369 l_adr_transaction_coa_id      NUMBER;
34370 l_adr_accounting_coa_id       NUMBER;
34371 l_adr_flexfield_segment_code  VARCHAR2(30);
34372 l_adr_flex_value_set_id       NUMBER;
34373 l_adr_value_type_code         VARCHAR2(30);
34374 l_adr_value_combination_id    NUMBER;
34375 l_adr_value_segment_code      VARCHAR2(30);
34376 
34377 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
34378 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
34379 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
34380 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
34381 
34382 -- 4262811 Variables ------------------------------------------------------------------------------------------
34383 l_entered_amt_idx             NUMBER;
34384 l_accted_amt_idx              NUMBER;
34385 l_acc_rev_flag                VARCHAR2(1);
34386 l_accrual_line_num            NUMBER;
34387 l_tmp_amt                     NUMBER;
34388 l_acc_rev_natural_side_code   VARCHAR2(1);
34389 
34390 l_num_entries                 NUMBER;
34391 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
34392 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
34393 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
34394 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
34395 l_recog_line_1                NUMBER;
34396 l_recog_line_2                NUMBER;
34397 
34398 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
34402 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
34399 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
34400 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
34401 
34403 
34404 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
34405 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
34406 
34407 ---------------------------------------------------------------------------------------------------------------
34408 
34409 
34410 --
34411 -- bulk performance
34412 --
34413 l_balance_type_code           VARCHAR2(1);
34414 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
34415 l_log_module                  VARCHAR2(240);
34416 
34417 --
34418 -- Upgrade strategy
34419 --
34420 l_actual_upg_option           VARCHAR2(1);
34421 l_enc_upg_option           VARCHAR2(1);
34422 
34423 --
34424 BEGIN
34425 --
34426 IF g_log_enabled THEN
34427       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_72';
34428 END IF;
34429 --
34430 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
34431 
34432       trace
34433          (p_msg      => 'BEGIN of AcctLineType_72'
34434          ,p_level    => C_LEVEL_PROCEDURE
34435          ,p_module   => l_log_module);
34436 
34437 END IF;
34438 --
34439 l_component_type             := 'AMB_JLT';
34440 l_component_code             := 'MISC_RCT_TAX';
34441 l_component_type_code        := 'S';
34442 l_component_appl_id          :=  222;
34443 l_amb_context_code           := 'DEFAULT';
34444 l_entity_code                := 'RECEIPTS';
34445 l_event_class_code           := 'MISC_RECEIPT';
34446 l_event_type_code            := 'MISC_RECEIPT_ALL';
34447 l_line_definition_owner_code := 'S';
34448 l_line_definition_code       := 'MFAR_MISC_RECEIPTS_BALANCING';
34449 --
34450 l_balance_type_code          := 'A';
34451 l_segment                     := NULL;
34452 l_ccid                        := NULL;
34453 l_adr_transaction_coa_id      := NULL;
34454 l_adr_accounting_coa_id       := NULL;
34455 l_adr_flexfield_segment_code  := NULL;
34456 l_adr_flex_value_set_id       := NULL;
34457 l_adr_value_type_code         := NULL;
34458 l_adr_value_combination_id    := NULL;
34459 l_adr_value_segment_code      := NULL;
34460 
34461 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
34462 l_bflow_class_code           := '';    -- 4219869 Business Flow
34463 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
34464 l_budgetary_control_flag     := 'N';
34465 
34466 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
34467 l_bflow_applied_to_amt       := NULL; -- 5132302
34468 l_entered_amt_idx            := NULL;          -- 4262811
34469 l_accted_amt_idx             := NULL;          -- 4262811
34470 l_acc_rev_flag               := NULL;          -- 4262811
34471 l_accrual_line_num           := NULL;          -- 4262811
34472 l_tmp_amt                    := NULL;          -- 4262811
34473 --
34474  
34475 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
34476     l_balance_type_code <> 'B' THEN
34477 IF NVL(p_source_13,'
34478 ') =  'TAX' AND 
34479 NVL(p_source_52,'
34480 ') =  'N'
34481  THEN 
34482 
34483    --
34484    XLA_AE_LINES_PKG.SetNewLine;
34485 
34486    p_balance_type_code          := l_balance_type_code;
34487    -- set the flag so later we will know whether the gain loss line needs to be created
34488    
34489    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
34490      p_actual_flag :='A';
34491    END IF;
34492 
34493    --
34494    -- bulk performance
34495    --
34496    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
34497                                       p_header_num   => 0); -- 4262811
34498    --
34499    -- set accounting line options
34500    --
34501    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
34502            p_natural_side_code          => 'C'
34503          , p_gain_or_loss_flag          => 'N'
34504          , p_gl_transfer_mode_code      => 'S'
34505          , p_acct_entry_type_code       => 'A'
34506          , p_switch_side_flag           => 'Y'
34507          , p_merge_duplicate_code       => 'A'
34508          );
34509    --
34510    l_acc_rev_natural_side_code := 'D';  -- 4262811
34511    -- 
34512    --
34513    -- set accounting line type info
34514    --
34515    xla_ae_lines_pkg.SetAcctLineType
34516       (p_component_type             => l_component_type
34517       ,p_event_type_code            => l_event_type_code
34518       ,p_line_definition_owner_code => l_line_definition_owner_code
34519       ,p_line_definition_code       => l_line_definition_code
34520       ,p_accounting_line_code       => l_component_code
34521       ,p_accounting_line_type_code  => l_component_type_code
34522       ,p_accounting_line_appl_id    => l_component_appl_id
34523       ,p_amb_context_code           => l_amb_context_code
34524       ,p_entity_code                => l_entity_code
34525       ,p_event_class_code           => l_event_class_code);
34526    --
34527    -- set accounting class
34528    --
34529    xla_ae_lines_pkg.SetAcctClass(
34530            p_accounting_class_code  => 'TAX'
34531          , p_ae_header_id           => l_ae_header_id
34532          );
34533 
34534    --
34535    -- set rounding class
34536    --
34537    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
34538                       'RECEIVABLE';
34539 
34540    --
34541    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
34542    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
34543    --
34544    -- bulk performance
34545    --
34546    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
34547 
34548    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
34549       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
34550 
34551    -- 4955764
34552    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
34553       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
34554 
34555    -- 4458381 Public Sector Enh
34556    
34557    --
34558    -- set accounting attributes for the line type
34559    --
34560    l_entered_amt_idx := 3;
34561    l_accted_amt_idx  := 8;
34562    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
34563    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
34564    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_15);
34565    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
34566    l_rec_acct_attrs.array_char_value(2)  := p_source_16;
34567    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
34568    l_rec_acct_attrs.array_num_value(3)  := p_source_17;
34569    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
34570    l_rec_acct_attrs.array_char_value(4)  := p_source_18;
34571    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
34572    l_rec_acct_attrs.array_date_value(5)  := p_source_53;
34573    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
34574    l_rec_acct_attrs.array_num_value(6)  := p_source_20;
34575    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
34576    l_rec_acct_attrs.array_char_value(7)  := p_source_21;
34577    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
34578    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
34579 
34580    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
34581    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
34582 
34583    ---------------------------------------------------------------------------------------------------------------
34584    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
34585    ---------------------------------------------------------------------------------------------------------------
34586    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
34587 
34588    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
34589    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
34590 
34591    IF xla_accounting_cache_pkg.GetValueChar
34592          (p_source_code         => 'LEDGER_CATEGORY_CODE'
34593          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
34594    AND l_bflow_method_code = 'PRIOR_ENTRY'
34595 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
34596    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
34597          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
34598        )
34599    THEN
34600          xla_ae_lines_pkg.BflowUpgEntry
34601            (p_business_method_code    => l_bflow_method_code
34602            ,p_business_class_code     => l_bflow_class_code
34603            ,p_balance_type            => l_balance_type_code);
34604    ELSE
34605       NULL;
34606 -- No business flow processing for business flow method of NONE.
34607    END IF;
34608 
34609    --
34610    -- call analytical criteria
34611    --
34612    
34613    --
34614    -- call description
34615    --
34616    -- No description or it is inherited.
34617    --
34618    -- call ADRs
34619    -- Bug 4922099
34620    --
34621    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
34622         (NVL(l_actual_upg_option, 'N') = 'O') OR
34623         (NVL(l_enc_upg_option, 'N') = 'O')
34624       )
34625    THEN
34626    NULL;
34627    --
34628    --
34629    
34630   l_ccid := AcctDerRule_7(
34631            p_application_id           => p_application_id
34632          , p_ae_header_id             => l_ae_header_id 
34633 , p_source_3 => p_source_3
34634          , x_transaction_coa_id       => l_adr_transaction_coa_id
34635          , x_accounting_coa_id        => l_adr_accounting_coa_id
34636          , x_value_type_code          => l_adr_value_type_code
34637          , p_side                     => 'NA'
34638    );
34639 
34640    xla_ae_lines_pkg.set_ccid(
34641     p_code_combination_id          => l_ccid
34642   , p_value_type_code              => l_adr_value_type_code
34643   , p_transaction_coa_id           => l_adr_transaction_coa_id
34644   , p_accounting_coa_id            => l_adr_accounting_coa_id
34645   , p_adr_code                     => 'DIST_CCID'
34646   , p_adr_type_code                => 'S'
34647   , p_component_type               => l_component_type
34648   , p_component_code               => l_component_code
34649   , p_component_type_code          => l_component_type_code
34650   , p_component_appl_id            => l_component_appl_id
34651   , p_amb_context_code             => l_amb_context_code
34652   , p_side                         => 'NA'
34653   );
34654 
34655 
34656    --
34657    --
34658    END IF;
34659    --
34660    -- Bug 4922099
34661    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
34662           (NVL(l_enc_upg_option, 'N') = 'O')
34663         ) AND
34664         (l_bflow_method_code = 'PRIOR_ENTRY')
34665       )
34666    THEN
34667       IF
34668       --
34669       1 = 2
34670       --
34671       THEN
34672       xla_accounting_err_pkg.build_message
34673                                     (p_appli_s_name            => 'XLA'
34674                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
34675                                     ,p_token_1                 => 'LINE_NUMBER'
34676                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
34677                                     ,p_token_2                 => 'LINE_TYPE_NAME'
34678                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
34679                                                                              l_component_type
34680                                                                             ,l_component_code
34681                                                                             ,l_component_type_code
34682                                                                             ,l_component_appl_id
34683                                                                             ,l_amb_context_code
34684                                                                             ,l_entity_code
34685                                                                             ,l_event_class_code
34686                                                                            )
34687                                     ,p_token_3                 => 'OWNER'
34688                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
34689                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
34690                                                                           ,p_lookup_code    => l_component_type_code
34691                                                                          )
34692                                     ,p_token_4                 => 'PRODUCT_NAME'
34693                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
34694                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
34695                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
34696                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
34697                                     ,p_ae_header_id            =>  NULL
34698                                        );
34699 
34700         IF (C_LEVEL_ERROR>= g_log_level) THEN
34701                  trace
34702                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
34703                       ,p_level    => C_LEVEL_ERROR
34704                       ,p_module   => l_log_module);
34705         END IF;
34706       END IF;
34707    END IF;
34708    --
34709    --
34710    ------------------------------------------------------------------------------------------------
34714    ------------------------------------------------------------------------------------------------
34711    -- 4219869 Business Flow
34712    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
34713    -- Prior Entry.  Currently, the following code is always generated.
34715    XLA_AE_LINES_PKG.ValidateCurrentLine;
34716 
34717    ------------------------------------------------------------------------------------
34718    -- 4219869 Business Flow
34719    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
34720    ------------------------------------------------------------------------------------
34721    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
34722 
34723    ----------------------------------------------------------------------------------
34724    -- 4219869 Business Flow
34725    -- Update journal entry status -- Need to generate this within IF <condition>
34726    ----------------------------------------------------------------------------------
34727    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
34728          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
34729          ,p_balance_type_code => l_balance_type_code
34730          );
34731 
34732    -------------------------------------------------------------------------------------------
34733    -- 4262811 - Generate the Accrual Reversal lines
34734    -------------------------------------------------------------------------------------------
34735    BEGIN
34736       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
34737                               (g_array_event(p_event_id).array_value_num('header_index'));
34738       IF l_acc_rev_flag IS NULL THEN
34739          l_acc_rev_flag := 'N';
34740       END IF;
34741    EXCEPTION
34742       WHEN OTHERS THEN
34743          l_acc_rev_flag := 'N';
34744    END;
34745    --
34746    IF (l_acc_rev_flag = 'Y') THEN
34747 
34748        -- 4645092  ------------------------------------------------------------------------------
34749        -- To allow MPA report to determine if it should generate report process
34750        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
34751        ------------------------------------------------------------------------------------------
34752 
34753        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
34754        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
34755    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
34756    -- call ADRs
34757    -- Bug 4922099
34758    --
34759    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
34760         (NVL(l_actual_upg_option, 'N') = 'O') OR
34761         (NVL(l_enc_upg_option, 'N') = 'O')
34762       )
34763    THEN
34764    NULL;
34765    --
34766    --
34767    
34768   l_ccid := AcctDerRule_7(
34769            p_application_id           => p_application_id
34770          , p_ae_header_id             => l_ae_header_id 
34771 , p_source_3 => p_source_3
34772          , x_transaction_coa_id       => l_adr_transaction_coa_id
34773          , x_accounting_coa_id        => l_adr_accounting_coa_id
34774          , x_value_type_code          => l_adr_value_type_code
34775          , p_side                     => 'NA'
34776    );
34777 
34778    xla_ae_lines_pkg.set_ccid(
34779     p_code_combination_id          => l_ccid
34780   , p_value_type_code              => l_adr_value_type_code
34781   , p_transaction_coa_id           => l_adr_transaction_coa_id
34782   , p_accounting_coa_id            => l_adr_accounting_coa_id
34783   , p_adr_code                     => 'DIST_CCID'
34784   , p_adr_type_code                => 'S'
34785   , p_component_type               => l_component_type
34786   , p_component_code               => l_component_code
34787   , p_component_type_code          => l_component_type_code
34788   , p_component_appl_id            => l_component_appl_id
34789   , p_amb_context_code             => l_amb_context_code
34790   , p_side                         => 'NA'
34791   );
34792 
34793 
34794    --
34795    --
34796    END IF;
34797 
34798        --
34799        -- Update the line information that should be overwritten
34800        --
34801        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
34802                                          p_header_num   => 1);
34803        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
34804 
34805        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
34806 
34807        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
34808           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
34809        END IF;
34810 
34811       --
34812       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
34813       --
34814       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
34815           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
34816       ELSE
34817           ---------------------------------------------------------------------------------------------------
34818           -- 4262811a Switch Sign
34819           ---------------------------------------------------------------------------------------------------
34820           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
34821           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
34825           -- 5132302
34822                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
34823           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
34824                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
34826           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
34827                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
34828 
34829       END IF;
34830 
34831       -- 4955764
34832       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
34833       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
34834 
34835 
34836       XLA_AE_LINES_PKG.ValidateCurrentLine;
34837       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
34838 
34839       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
34840                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
34841                ,p_balance_type_code => l_balance_type_code);
34842 
34843    END IF;
34844 
34845    -----------------------------------------------------------------------------------------
34846    -- 4262811 Multiperiod Accounting
34847    -----------------------------------------------------------------------------------------
34848      -- No MPA option is assigned.
34849 
34850 
34851 END IF;
34852 END IF;
34853 --
34854 
34855 --
34856 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
34857    trace
34858       (p_msg      => 'END of AcctLineType_72'
34859       ,p_level    => C_LEVEL_PROCEDURE
34860       ,p_module   => l_log_module);
34861 END IF;
34862 --
34863 EXCEPTION
34864   WHEN xla_exceptions_pkg.application_exception THEN
34865       RAISE;
34866   WHEN OTHERS THEN
34867        xla_exceptions_pkg.raise_message
34868            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_72');
34869 END AcctLineType_72;
34870 --
34871 
34872 ---------------------------------------
34873 --
34874 -- PRIVATE FUNCTION
34875 --         AcctLineType_73
34876 --
34877 ---------------------------------------
34878 PROCEDURE AcctLineType_73 (
34879   p_application_id        IN NUMBER
34880  ,p_event_id              IN NUMBER
34881  ,p_calculate_acctd_flag  IN VARCHAR2
34882  ,p_calculate_g_l_flag    IN VARCHAR2
34883  ,p_actual_flag           IN OUT VARCHAR2
34884  ,p_balance_type_code     OUT VARCHAR2
34885  ,p_gain_or_loss_ref      OUT VARCHAR2
34886  
34887 --Distribution GL Account
34888  , p_source_3            IN NUMBER
34889 --Distribution Source Type
34890  , p_source_13            IN VARCHAR2
34891 --Distribution Line Identifier
34892  , p_source_15            IN NUMBER
34893 --Distribution Type
34894  , p_source_16            IN VARCHAR2
34895 --Exchange Date
34896  , p_source_19            IN DATE
34897 --Exchange Rate
34898  , p_source_20            IN NUMBER
34899 --Exchange Rate Type
34900  , p_source_21            IN VARCHAR2
34901 --Transaction Distribution Identifier
34902  , p_source_27            IN NUMBER
34903 --Transaction Distribution Type
34904  , p_source_28            IN VARCHAR2
34905 --Distribution Multi Fund Additional Entry
34906  , p_source_52            IN VARCHAR2
34907 --Receipt Applied To Application Identifier
34908  , p_source_56            IN NUMBER
34909 --Transaction Entity Code
34910  , p_source_57            IN VARCHAR2
34911 --Transaction Identifier
34912  , p_source_58            IN NUMBER
34913 --DIST_ENT_AMT_FROM
34914  , p_source_59            IN NUMBER
34915 --Applying Document Currency Code
34916  , p_source_60            IN VARCHAR2
34917 --Accounting Amount
34918  , p_source_61            IN NUMBER
34919 --Distribution Party Identifier
34920  , p_source_62            IN NUMBER
34921 --Distribution Party Site Id
34922  , p_source_63            IN NUMBER
34923 --Distribution Party Type
34924  , p_source_64            IN VARCHAR2
34925 )
34926 IS
34927 
34928 l_component_type              VARCHAR2(80);
34929 l_component_code              VARCHAR2(30);
34930 l_component_type_code         VARCHAR2(1);
34931 l_component_appl_id           INTEGER;
34932 l_amb_context_code            VARCHAR2(30);
34933 l_entity_code                 VARCHAR2(30);
34934 l_event_class_code            VARCHAR2(30);
34935 l_ae_header_id                NUMBER;
34936 l_event_type_code             VARCHAR2(30);
34937 l_line_definition_code        VARCHAR2(30);
34938 l_line_definition_owner_code  VARCHAR2(1);
34939 --
34940 -- adr variables
34941 l_segment                     VARCHAR2(30);
34942 l_ccid                        NUMBER;
34943 l_adr_transaction_coa_id      NUMBER;
34944 l_adr_accounting_coa_id       NUMBER;
34945 l_adr_flexfield_segment_code  VARCHAR2(30);
34946 l_adr_flex_value_set_id       NUMBER;
34947 l_adr_value_type_code         VARCHAR2(30);
34948 l_adr_value_combination_id    NUMBER;
34949 l_adr_value_segment_code      VARCHAR2(30);
34950 
34951 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
34952 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
34953 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
34954 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
34955 
34956 -- 4262811 Variables ------------------------------------------------------------------------------------------
34957 l_entered_amt_idx             NUMBER;
34958 l_accted_amt_idx              NUMBER;
34959 l_acc_rev_flag                VARCHAR2(1);
34960 l_accrual_line_num            NUMBER;
34964 l_num_entries                 NUMBER;
34961 l_tmp_amt                     NUMBER;
34962 l_acc_rev_natural_side_code   VARCHAR2(1);
34963 
34965 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
34966 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
34967 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
34968 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
34969 l_recog_line_1                NUMBER;
34970 l_recog_line_2                NUMBER;
34971 
34972 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
34973 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
34974 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
34975 
34976 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
34977 
34978 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
34979 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
34980 
34981 ---------------------------------------------------------------------------------------------------------------
34982 
34983 
34984 --
34985 -- bulk performance
34986 --
34987 l_balance_type_code           VARCHAR2(1);
34988 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
34989 l_log_module                  VARCHAR2(240);
34990 
34991 --
34992 -- Upgrade strategy
34993 --
34994 l_actual_upg_option           VARCHAR2(1);
34995 l_enc_upg_option           VARCHAR2(1);
34996 
34997 --
34998 BEGIN
34999 --
35000 IF g_log_enabled THEN
35001       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_73';
35002 END IF;
35003 --
35004 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
35005 
35006       trace
35007          (p_msg      => 'BEGIN of AcctLineType_73'
35008          ,p_level    => C_LEVEL_PROCEDURE
35009          ,p_module   => l_log_module);
35010 
35011 END IF;
35012 --
35013 l_component_type             := 'AMB_JLT';
35014 l_component_code             := 'RCT_ACC';
35015 l_component_type_code        := 'S';
35016 l_component_appl_id          :=  222;
35017 l_amb_context_code           := 'DEFAULT';
35018 l_entity_code                := 'RECEIPTS';
35019 l_event_class_code           := 'RECEIPT';
35020 l_event_type_code            := 'RECEIPT_ALL';
35021 l_line_definition_owner_code := 'S';
35022 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
35023 --
35024 l_balance_type_code          := 'A';
35025 l_segment                     := NULL;
35026 l_ccid                        := NULL;
35027 l_adr_transaction_coa_id      := NULL;
35028 l_adr_accounting_coa_id       := NULL;
35029 l_adr_flexfield_segment_code  := NULL;
35030 l_adr_flex_value_set_id       := NULL;
35031 l_adr_value_type_code         := NULL;
35032 l_adr_value_combination_id    := NULL;
35033 l_adr_value_segment_code      := NULL;
35034 
35035 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
35036 l_bflow_class_code           := '';    -- 4219869 Business Flow
35037 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
35038 l_budgetary_control_flag     := 'N';
35039 
35040 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
35041 l_bflow_applied_to_amt       := NULL; -- 5132302
35042 l_entered_amt_idx            := NULL;          -- 4262811
35043 l_accted_amt_idx             := NULL;          -- 4262811
35044 l_acc_rev_flag               := NULL;          -- 4262811
35045 l_accrual_line_num           := NULL;          -- 4262811
35046 l_tmp_amt                    := NULL;          -- 4262811
35047 --
35048  
35049 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
35050     l_balance_type_code <> 'B' THEN
35051 IF NVL(p_source_13,'
35052 ') =  'ACC' AND 
35053 NVL(p_source_52,'
35054 ') =  'N'
35055  THEN 
35056 
35057    --
35058    XLA_AE_LINES_PKG.SetNewLine;
35059 
35060    p_balance_type_code          := l_balance_type_code;
35061    -- set the flag so later we will know whether the gain loss line needs to be created
35062    
35063    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
35064      p_actual_flag :='A';
35065    END IF;
35066 
35067    --
35068    -- bulk performance
35069    --
35070    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
35071                                       p_header_num   => 0); -- 4262811
35072    --
35073    -- set accounting line options
35074    --
35075    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
35076            p_natural_side_code          => 'C'
35077          , p_gain_or_loss_flag          => 'N'
35078          , p_gl_transfer_mode_code      => 'S'
35079          , p_acct_entry_type_code       => 'A'
35080          , p_switch_side_flag           => 'Y'
35081          , p_merge_duplicate_code       => 'A'
35082          );
35083    --
35084    l_acc_rev_natural_side_code := 'D';  -- 4262811
35085    -- 
35086    --
35087    -- set accounting line type info
35088    --
35089    xla_ae_lines_pkg.SetAcctLineType
35090       (p_component_type             => l_component_type
35091       ,p_event_type_code            => l_event_type_code
35092       ,p_line_definition_owner_code => l_line_definition_owner_code
35093       ,p_line_definition_code       => l_line_definition_code
35094       ,p_accounting_line_code       => l_component_code
35095       ,p_accounting_line_type_code  => l_component_type_code
35096       ,p_accounting_line_appl_id    => l_component_appl_id
35097       ,p_amb_context_code           => l_amb_context_code
35098       ,p_entity_code                => l_entity_code
35099       ,p_event_class_code           => l_event_class_code);
35100    --
35101    -- set accounting class
35102    --
35103    xla_ae_lines_pkg.SetAcctClass(
35104            p_accounting_class_code  => 'ACC'
35105          , p_ae_header_id           => l_ae_header_id
35106          );
35107 
35108    --
35109    -- set rounding class
35110    --
35111    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
35112                       'RECEIVABLE';
35113 
35114    --
35115    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
35116    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
35117    --
35118    -- bulk performance
35119    --
35120    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
35121 
35122    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
35123       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
35124 
35125    -- 4955764
35126    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
35127       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
35128 
35129    -- 4458381 Public Sector Enh
35130    
35131    --
35132    -- set accounting attributes for the line type
35133    --
35134    l_entered_amt_idx := 8;
35135    l_accted_amt_idx  := 13;
35136    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
35137    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
35138    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
35139    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
35140    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
35141    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
35142    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
35143    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
35144    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
35145    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
35146    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
35147    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
35148    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
35149    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
35150    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
35151    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
35152    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
35153    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
35154    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
35155    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
35156    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
35157    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
35158    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
35159    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
35160    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
35161    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
35162    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
35163    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
35164    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
35165    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
35166    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
35167    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
35168    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
35169 
35170    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
35171    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
35172 
35173    ---------------------------------------------------------------------------------------------------------------
35174    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
35175    ---------------------------------------------------------------------------------------------------------------
35176    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
35177 
35178    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
35182          (p_source_code         => 'LEDGER_CATEGORY_CODE'
35179    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
35180 
35181    IF xla_accounting_cache_pkg.GetValueChar
35183          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
35184    AND l_bflow_method_code = 'PRIOR_ENTRY'
35185 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
35186    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
35187          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
35188        )
35189    THEN
35190          xla_ae_lines_pkg.BflowUpgEntry
35191            (p_business_method_code    => l_bflow_method_code
35192            ,p_business_class_code     => l_bflow_class_code
35193            ,p_balance_type            => l_balance_type_code);
35194    ELSE
35195       NULL;
35196 -- No business flow processing for business flow method of NONE.
35197    END IF;
35198 
35199    --
35200    -- call analytical criteria
35201    --
35202    
35203    --
35204    -- call description
35205    --
35206    -- No description or it is inherited.
35207    --
35208    -- call ADRs
35209    -- Bug 4922099
35210    --
35211    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
35212         (NVL(l_actual_upg_option, 'N') = 'O') OR
35213         (NVL(l_enc_upg_option, 'N') = 'O')
35214       )
35215    THEN
35216    NULL;
35217    --
35218    --
35219    
35220   l_ccid := AcctDerRule_7(
35221            p_application_id           => p_application_id
35222          , p_ae_header_id             => l_ae_header_id 
35223 , p_source_3 => p_source_3
35224          , x_transaction_coa_id       => l_adr_transaction_coa_id
35225          , x_accounting_coa_id        => l_adr_accounting_coa_id
35226          , x_value_type_code          => l_adr_value_type_code
35227          , p_side                     => 'NA'
35228    );
35229 
35230    xla_ae_lines_pkg.set_ccid(
35231     p_code_combination_id          => l_ccid
35232   , p_value_type_code              => l_adr_value_type_code
35233   , p_transaction_coa_id           => l_adr_transaction_coa_id
35234   , p_accounting_coa_id            => l_adr_accounting_coa_id
35235   , p_adr_code                     => 'DIST_CCID'
35236   , p_adr_type_code                => 'S'
35237   , p_component_type               => l_component_type
35238   , p_component_code               => l_component_code
35239   , p_component_type_code          => l_component_type_code
35240   , p_component_appl_id            => l_component_appl_id
35241   , p_amb_context_code             => l_amb_context_code
35242   , p_side                         => 'NA'
35243   );
35244 
35245 
35246    --
35247    --
35248    END IF;
35249    --
35250    -- Bug 4922099
35251    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
35252           (NVL(l_enc_upg_option, 'N') = 'O')
35253         ) AND
35254         (l_bflow_method_code = 'PRIOR_ENTRY')
35255       )
35256    THEN
35257       IF
35258       --
35259       1 = 2
35260       --
35261       THEN
35262       xla_accounting_err_pkg.build_message
35263                                     (p_appli_s_name            => 'XLA'
35264                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
35265                                     ,p_token_1                 => 'LINE_NUMBER'
35266                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
35267                                     ,p_token_2                 => 'LINE_TYPE_NAME'
35268                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
35269                                                                              l_component_type
35270                                                                             ,l_component_code
35271                                                                             ,l_component_type_code
35272                                                                             ,l_component_appl_id
35273                                                                             ,l_amb_context_code
35274                                                                             ,l_entity_code
35275                                                                             ,l_event_class_code
35276                                                                            )
35277                                     ,p_token_3                 => 'OWNER'
35278                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
35279                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
35280                                                                           ,p_lookup_code    => l_component_type_code
35281                                                                          )
35282                                     ,p_token_4                 => 'PRODUCT_NAME'
35283                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
35284                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
35285                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
35286                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
35287                                     ,p_ae_header_id            =>  NULL
35288                                        );
35289 
35290         IF (C_LEVEL_ERROR>= g_log_level) THEN
35291                  trace
35292                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
35293                       ,p_level    => C_LEVEL_ERROR
35294                       ,p_module   => l_log_module);
35295         END IF;
35296       END IF;
35297    END IF;
35298    --
35299    --
35300    ------------------------------------------------------------------------------------------------
35301    -- 4219869 Business Flow
35302    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
35303    -- Prior Entry.  Currently, the following code is always generated.
35304    ------------------------------------------------------------------------------------------------
35305    XLA_AE_LINES_PKG.ValidateCurrentLine;
35306 
35307    ------------------------------------------------------------------------------------
35308    -- 4219869 Business Flow
35309    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
35310    ------------------------------------------------------------------------------------
35311    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
35312 
35313    ----------------------------------------------------------------------------------
35314    -- 4219869 Business Flow
35315    -- Update journal entry status -- Need to generate this within IF <condition>
35316    ----------------------------------------------------------------------------------
35317    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
35318          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
35319          ,p_balance_type_code => l_balance_type_code
35320          );
35321 
35322    -------------------------------------------------------------------------------------------
35323    -- 4262811 - Generate the Accrual Reversal lines
35324    -------------------------------------------------------------------------------------------
35325    BEGIN
35326       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
35327                               (g_array_event(p_event_id).array_value_num('header_index'));
35328       IF l_acc_rev_flag IS NULL THEN
35329          l_acc_rev_flag := 'N';
35330       END IF;
35331    EXCEPTION
35332       WHEN OTHERS THEN
35333          l_acc_rev_flag := 'N';
35334    END;
35335    --
35336    IF (l_acc_rev_flag = 'Y') THEN
35337 
35338        -- 4645092  ------------------------------------------------------------------------------
35339        -- To allow MPA report to determine if it should generate report process
35340        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
35341        ------------------------------------------------------------------------------------------
35342 
35343        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
35344        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
35345    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
35346    -- call ADRs
35347    -- Bug 4922099
35348    --
35349    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
35350         (NVL(l_actual_upg_option, 'N') = 'O') OR
35351         (NVL(l_enc_upg_option, 'N') = 'O')
35352       )
35353    THEN
35354    NULL;
35355    --
35356    --
35357    
35358   l_ccid := AcctDerRule_7(
35359            p_application_id           => p_application_id
35360          , p_ae_header_id             => l_ae_header_id 
35361 , p_source_3 => p_source_3
35362          , x_transaction_coa_id       => l_adr_transaction_coa_id
35363          , x_accounting_coa_id        => l_adr_accounting_coa_id
35364          , x_value_type_code          => l_adr_value_type_code
35365          , p_side                     => 'NA'
35366    );
35367 
35368    xla_ae_lines_pkg.set_ccid(
35369     p_code_combination_id          => l_ccid
35370   , p_value_type_code              => l_adr_value_type_code
35371   , p_transaction_coa_id           => l_adr_transaction_coa_id
35372   , p_accounting_coa_id            => l_adr_accounting_coa_id
35373   , p_adr_code                     => 'DIST_CCID'
35374   , p_adr_type_code                => 'S'
35375   , p_component_type               => l_component_type
35376   , p_component_code               => l_component_code
35377   , p_component_type_code          => l_component_type_code
35378   , p_component_appl_id            => l_component_appl_id
35379   , p_amb_context_code             => l_amb_context_code
35380   , p_side                         => 'NA'
35381   );
35382 
35383 
35384    --
35385    --
35386    END IF;
35387 
35388        --
35389        -- Update the line information that should be overwritten
35390        --
35391        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
35392                                          p_header_num   => 1);
35393        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
35394 
35395        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
35396 
35397        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
35398           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
35399        END IF;
35400 
35401       --
35402       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
35403       --
35404       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
35405           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
35406       ELSE
35407           ---------------------------------------------------------------------------------------------------
35408           -- 4262811a Switch Sign
35409           ---------------------------------------------------------------------------------------------------
35410           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
35411           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
35412                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
35413           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
35414                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
35415           -- 5132302
35416           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
35417                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
35418 
35419       END IF;
35420 
35421       -- 4955764
35422       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
35423       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
35424 
35425 
35426       XLA_AE_LINES_PKG.ValidateCurrentLine;
35427       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
35428 
35429       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
35430                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
35431                ,p_balance_type_code => l_balance_type_code);
35432 
35433    END IF;
35434 
35435    -----------------------------------------------------------------------------------------
35436    -- 4262811 Multiperiod Accounting
35437    -----------------------------------------------------------------------------------------
35438      -- No MPA option is assigned.
35439 
35440 
35441 END IF;
35442 END IF;
35443 --
35444 
35445 --
35446 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
35447    trace
35448       (p_msg      => 'END of AcctLineType_73'
35449       ,p_level    => C_LEVEL_PROCEDURE
35450       ,p_module   => l_log_module);
35451 END IF;
35452 --
35453 EXCEPTION
35454   WHEN xla_exceptions_pkg.application_exception THEN
35455       RAISE;
35456   WHEN OTHERS THEN
35457        xla_exceptions_pkg.raise_message
35458            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_73');
35459 END AcctLineType_73;
35460 --
35461 
35462 ---------------------------------------
35463 --
35464 -- PRIVATE FUNCTION
35465 --         AcctLineType_74
35466 --
35467 ---------------------------------------
35468 PROCEDURE AcctLineType_74 (
35469   p_application_id        IN NUMBER
35470  ,p_event_id              IN NUMBER
35471  ,p_calculate_acctd_flag  IN VARCHAR2
35472  ,p_calculate_g_l_flag    IN VARCHAR2
35473  ,p_actual_flag           IN OUT VARCHAR2
35474  ,p_balance_type_code     OUT VARCHAR2
35475  ,p_gain_or_loss_ref      OUT VARCHAR2
35476  
35477 --Transaction Distribution GL Account
35478  , p_source_4            IN NUMBER
35479 --Remittance Bank Account Cash Account
35480  , p_source_6            IN NUMBER
35481 --Distribution Source Type
35482  , p_source_13            IN VARCHAR2
35483 --Distribution Line Identifier
35484  , p_source_15            IN NUMBER
35485 --Distribution Type
35486  , p_source_16            IN VARCHAR2
35487 --Exchange Date
35488  , p_source_19            IN DATE
35489 --Exchange Rate
35490  , p_source_20            IN NUMBER
35491 --Exchange Rate Type
35492  , p_source_21            IN VARCHAR2
35493 --Transaction Distribution Account Class
35494  , p_source_26            IN VARCHAR2
35495 --Transaction Distribution Identifier
35496  , p_source_27            IN NUMBER
35497 --Transaction Distribution Type
35498  , p_source_28            IN VARCHAR2
35499 --Distribution Multi Fund Additional Entry
35500  , p_source_52            IN VARCHAR2
35501 --Receipt Class Require Remittance Flag
35502  , p_source_54            IN VARCHAR2
35503 --Receipt Class Confirm Flag
35504  , p_source_55            IN VARCHAR2
35505 --Receipt Applied To Application Identifier
35506  , p_source_56            IN NUMBER
35507 --Transaction Entity Code
35508  , p_source_57            IN VARCHAR2
35509 --Transaction Identifier
35510  , p_source_58            IN NUMBER
35511 --DIST_ENT_AMT_FROM
35512  , p_source_59            IN NUMBER
35513 --Applying Document Currency Code
35514  , p_source_60            IN VARCHAR2
35515 --Accounting Amount
35516  , p_source_61            IN NUMBER
35517 --Distribution Party Identifier
35518  , p_source_62            IN NUMBER
35519 --Distribution Party Site Id
35520  , p_source_63            IN NUMBER
35521 --Distribution Party Type
35522  , p_source_64            IN VARCHAR2
35523 )
35524 IS
35525 
35526 l_component_type              VARCHAR2(80);
35527 l_component_code              VARCHAR2(30);
35528 l_component_type_code         VARCHAR2(1);
35529 l_component_appl_id           INTEGER;
35530 l_amb_context_code            VARCHAR2(30);
35531 l_entity_code                 VARCHAR2(30);
35532 l_event_class_code            VARCHAR2(30);
35533 l_ae_header_id                NUMBER;
35534 l_event_type_code             VARCHAR2(30);
35535 l_line_definition_code        VARCHAR2(30);
35536 l_line_definition_owner_code  VARCHAR2(1);
35537 --
35538 -- adr variables
35539 l_segment                     VARCHAR2(30);
35540 l_ccid                        NUMBER;
35541 l_adr_transaction_coa_id      NUMBER;
35542 l_adr_accounting_coa_id       NUMBER;
35543 l_adr_flexfield_segment_code  VARCHAR2(30);
35544 l_adr_flex_value_set_id       NUMBER;
35545 l_adr_value_type_code         VARCHAR2(30);
35546 l_adr_value_combination_id    NUMBER;
35547 l_adr_value_segment_code      VARCHAR2(30);
35548 
35549 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
35550 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
35551 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
35552 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
35553 
35554 -- 4262811 Variables ------------------------------------------------------------------------------------------
35555 l_entered_amt_idx             NUMBER;
35556 l_accted_amt_idx              NUMBER;
35557 l_acc_rev_flag                VARCHAR2(1);
35558 l_accrual_line_num            NUMBER;
35559 l_tmp_amt                     NUMBER;
35560 l_acc_rev_natural_side_code   VARCHAR2(1);
35561 
35562 l_num_entries                 NUMBER;
35563 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
35564 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
35565 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
35566 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
35567 l_recog_line_1                NUMBER;
35568 l_recog_line_2                NUMBER;
35569 
35570 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
35571 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
35572 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
35573 
35574 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
35575 
35576 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
35577 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
35578 
35579 ---------------------------------------------------------------------------------------------------------------
35580 
35581 
35582 --
35583 -- bulk performance
35584 --
35585 l_balance_type_code           VARCHAR2(1);
35586 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
35587 l_log_module                  VARCHAR2(240);
35588 
35589 --
35590 -- Upgrade strategy
35591 --
35592 l_actual_upg_option           VARCHAR2(1);
35593 l_enc_upg_option           VARCHAR2(1);
35594 
35595 --
35596 BEGIN
35597 --
35598 IF g_log_enabled THEN
35599       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_74';
35600 END IF;
35601 --
35602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
35603 
35604       trace
35605          (p_msg      => 'BEGIN of AcctLineType_74'
35606          ,p_level    => C_LEVEL_PROCEDURE
35607          ,p_module   => l_log_module);
35608 
35609 END IF;
35610 --
35611 l_component_type             := 'AMB_JLT';
35612 l_component_code             := 'RCT_APP_MFAR_TRX_CASH';
35613 l_component_type_code        := 'S';
35614 l_component_appl_id          :=  222;
35615 l_amb_context_code           := 'DEFAULT';
35616 l_entity_code                := 'RECEIPTS';
35617 l_event_class_code           := 'RECEIPT';
35618 l_event_type_code            := 'RECEIPT_ALL';
35619 l_line_definition_owner_code := 'S';
35620 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
35621 --
35622 l_balance_type_code          := 'A';
35623 l_segment                     := NULL;
35624 l_ccid                        := NULL;
35625 l_adr_transaction_coa_id      := NULL;
35626 l_adr_accounting_coa_id       := NULL;
35627 l_adr_flexfield_segment_code  := NULL;
35628 l_adr_flex_value_set_id       := NULL;
35629 l_adr_value_type_code         := NULL;
35630 l_adr_value_combination_id    := NULL;
35631 l_adr_value_segment_code      := NULL;
35632 
35633 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
35634 l_bflow_class_code           := '';    -- 4219869 Business Flow
35635 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
35636 l_budgetary_control_flag     := 'N';
35637 
35638 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
35639 l_bflow_applied_to_amt       := NULL; -- 5132302
35640 l_entered_amt_idx            := NULL;          -- 4262811
35641 l_accted_amt_idx             := NULL;          -- 4262811
35642 l_acc_rev_flag               := NULL;          -- 4262811
35643 l_accrual_line_num           := NULL;          -- 4262811
35644 l_tmp_amt                    := NULL;          -- 4262811
35645 --
35646  
35647 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
35648     l_balance_type_code <> 'B' THEN
35649 IF (NVL(p_source_26,'
35650 ') =  'REV' OR 
35651 NVL(p_source_26,'
35652 ') =  'TAX' OR 
35653 NVL(p_source_26,'
35654 ') =  'FREIGHT' OR 
35655 NVL(p_source_26,'
35656 ') =  'CHARGES' OR 
35657 NVL(p_source_26,'
35658 ') =  'ROUND') AND 
35659 NVL(p_source_13,'
35660 ') =  'REC' AND 
35661 NVL(p_source_52,'
35662 ') =  'N' AND 
35663 NVL(p_source_54,'
35664 ') =  'N' AND 
35665 NVL(p_source_55,'
35666 ') =  'N'
35667  THEN 
35668 
35669    --
35670    XLA_AE_LINES_PKG.SetNewLine;
35671 
35672    p_balance_type_code          := l_balance_type_code;
35673    -- set the flag so later we will know whether the gain loss line needs to be created
35674    
35675    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
35676      p_actual_flag :='A';
35677    END IF;
35678 
35679    --
35680    -- bulk performance
35681    --
35682    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
35683                                       p_header_num   => 0); -- 4262811
35684    --
35685    -- set accounting line options
35686    --
35687    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
35688            p_natural_side_code          => 'D'
35689          , p_gain_or_loss_flag          => 'N'
35690          , p_gl_transfer_mode_code      => 'S'
35691          , p_acct_entry_type_code       => 'A'
35692          , p_switch_side_flag           => 'Y'
35693          , p_merge_duplicate_code       => 'A'
35694          );
35695    --
35696    l_acc_rev_natural_side_code := 'C';  -- 4262811
35697    -- 
35698    --
35699    -- set accounting line type info
35700    --
35701    xla_ae_lines_pkg.SetAcctLineType
35702       (p_component_type             => l_component_type
35703       ,p_event_type_code            => l_event_type_code
35704       ,p_line_definition_owner_code => l_line_definition_owner_code
35705       ,p_line_definition_code       => l_line_definition_code
35706       ,p_accounting_line_code       => l_component_code
35707       ,p_accounting_line_type_code  => l_component_type_code
35708       ,p_accounting_line_appl_id    => l_component_appl_id
35709       ,p_amb_context_code           => l_amb_context_code
35710       ,p_entity_code                => l_entity_code
35711       ,p_event_class_code           => l_event_class_code);
35712    --
35713    -- set accounting class
35714    --
35715    xla_ae_lines_pkg.SetAcctClass(
35716            p_accounting_class_code  => 'CASH'
35717          , p_ae_header_id           => l_ae_header_id
35718          );
35719 
35720    --
35721    -- set rounding class
35722    --
35723    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
35724                       'RECEIVABLE';
35725 
35726    --
35727    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
35728    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
35729    --
35730    -- bulk performance
35731    --
35732    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
35733 
35734    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
35735       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
35736 
35737    -- 4955764
35738    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
35739       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
35740 
35741    -- 4458381 Public Sector Enh
35742    
35743    --
35744    -- set accounting attributes for the line type
35745    --
35746    l_entered_amt_idx := 8;
35747    l_accted_amt_idx  := 13;
35748    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
35749    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
35750    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
35751    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
35752    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
35753    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
35754    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
35755    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
35756    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
35757    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
35758    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
35759    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
35760    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
35761    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
35762    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
35763    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
35764    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
35765    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
35766    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
35767    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
35768    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
35769    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
35770    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
35771    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
35772    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
35773    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
35774    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
35775    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
35776    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
35777    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
35778    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
35779    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
35780    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
35781 
35782    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
35783    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
35784 
35785    ---------------------------------------------------------------------------------------------------------------
35786    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
35787    ---------------------------------------------------------------------------------------------------------------
35788    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
35789 
35790    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
35791    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
35792 
35793    IF xla_accounting_cache_pkg.GetValueChar
35794          (p_source_code         => 'LEDGER_CATEGORY_CODE'
35795          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
35796    AND l_bflow_method_code = 'PRIOR_ENTRY'
35797 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
35798    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
35799          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
35800        )
35801    THEN
35802          xla_ae_lines_pkg.BflowUpgEntry
35803            (p_business_method_code    => l_bflow_method_code
35804            ,p_business_class_code     => l_bflow_class_code
35805            ,p_balance_type            => l_balance_type_code);
35806    ELSE
35807       NULL;
35808 -- No business flow processing for business flow method of NONE.
35809    END IF;
35810 
35811    --
35812    -- call analytical criteria
35813    --
35814    
35815    --
35816    -- call description
35817    --
35818    
35819 xla_ae_lines_pkg.SetLineDescription(
35820    p_ae_header_id => l_ae_header_id
35821   ,p_description  => Description_1 (
35822      p_application_id         => p_application_id
35823    , p_ae_header_id           => l_ae_header_id 
35824    )
35825 );
35826 
35827 
35828    --
35829    -- call ADRs
35830    -- Bug 4922099
35831    --
35832    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
35833         (NVL(l_actual_upg_option, 'N') = 'O') OR
35834         (NVL(l_enc_upg_option, 'N') = 'O')
35835       )
35836    THEN
35837    NULL;
35838    --
35839    --
35840    
35841   l_ccid := AcctDerRule_9(
35842            p_application_id           => p_application_id
35843          , p_ae_header_id             => l_ae_header_id 
35844 , p_source_6 => p_source_6
35845          , x_transaction_coa_id       => l_adr_transaction_coa_id
35846          , x_accounting_coa_id        => l_adr_accounting_coa_id
35847          , x_value_type_code          => l_adr_value_type_code
35848          , p_side                     => 'NA'
35849    );
35850 
35851    xla_ae_lines_pkg.set_ccid(
35852     p_code_combination_id          => l_ccid
35853   , p_value_type_code              => l_adr_value_type_code
35854   , p_transaction_coa_id           => l_adr_transaction_coa_id
35855   , p_accounting_coa_id            => l_adr_accounting_coa_id
35856   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
35857   , p_adr_type_code                => 'S'
35858   , p_component_type               => l_component_type
35859   , p_component_code               => l_component_code
35860   , p_component_type_code          => l_component_type_code
35861   , p_component_appl_id            => l_component_appl_id
35862   , p_amb_context_code             => l_amb_context_code
35863   , p_side                         => 'NA'
35864   );
35865 
35866 
35867    l_segment := AcctDerRule_5(
35868            p_application_id           => p_application_id
35869          , p_ae_header_id             => l_ae_header_id 
35870 , p_source_4 => p_source_4
35871          , x_transaction_coa_id       => l_adr_transaction_coa_id
35872          , x_accounting_coa_id        => l_adr_accounting_coa_id
35873          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
35874          , x_flex_value_set_id        => l_adr_flex_value_set_id
35875          , x_value_type_code          => l_adr_value_type_code
35876          , x_value_combination_id     => l_adr_value_combination_id
35877          , x_value_segment_code       => l_adr_value_segment_code
35878          , p_side                     => 'NA'
35879          , p_override_seg_flag        => 'Y'
35880    );
35881 
35882    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
35883 
35884       xla_ae_lines_pkg.set_segment(
35885           p_to_segment_code         => 'GL_BALANCING'
35886         , p_segment_value           => l_segment
35887         , p_from_segment_code       => l_adr_value_segment_code
35888         , p_from_combination_id     => l_adr_value_combination_id
35889         , p_value_type_code         => l_adr_value_type_code
35890         , p_transaction_coa_id      => l_adr_transaction_coa_id
35891         , p_accounting_coa_id       => l_adr_accounting_coa_id
35892         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
35893         , p_flex_value_set_id       => l_adr_flex_value_set_id
35894         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
35895         , p_adr_type_code           => 'S'
35896         , p_component_type          => l_component_type
35897         , p_component_code          => l_component_code
35898         , p_component_type_code     => l_component_type_code
35899         , p_component_appl_id       => l_component_appl_id
35900         , p_amb_context_code        => l_amb_context_code
35901         , p_entity_code             => 'RECEIPTS'
35902         , p_event_class_code        => 'RECEIPT'
35903         , p_side                    => 'NA'
35904         );
35905 
35906   END IF;
35907 
35908    --
35909    --
35910    END IF;
35911    --
35912    -- Bug 4922099
35913    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
35914           (NVL(l_enc_upg_option, 'N') = 'O')
35915         ) AND
35916         (l_bflow_method_code = 'PRIOR_ENTRY')
35917       )
35918    THEN
35919       IF
35920       --
35921       1 = 2
35922       --
35923       THEN
35924       xla_accounting_err_pkg.build_message
35925                                     (p_appli_s_name            => 'XLA'
35926                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
35927                                     ,p_token_1                 => 'LINE_NUMBER'
35928                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
35929                                     ,p_token_2                 => 'LINE_TYPE_NAME'
35930                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
35931                                                                              l_component_type
35932                                                                             ,l_component_code
35933                                                                             ,l_component_type_code
35934                                                                             ,l_component_appl_id
35935                                                                             ,l_amb_context_code
35936                                                                             ,l_entity_code
35937                                                                             ,l_event_class_code
35938                                                                            )
35939                                     ,p_token_3                 => 'OWNER'
35940                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
35941                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
35942                                                                           ,p_lookup_code    => l_component_type_code
35943                                                                          )
35944                                     ,p_token_4                 => 'PRODUCT_NAME'
35945                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
35946                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
35947                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
35948                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
35949                                     ,p_ae_header_id            =>  NULL
35950                                        );
35951 
35952         IF (C_LEVEL_ERROR>= g_log_level) THEN
35953                  trace
35954                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
35955                       ,p_level    => C_LEVEL_ERROR
35956                       ,p_module   => l_log_module);
35957         END IF;
35958       END IF;
35959    END IF;
35960    --
35961    --
35962    ------------------------------------------------------------------------------------------------
35963    -- 4219869 Business Flow
35964    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
35965    -- Prior Entry.  Currently, the following code is always generated.
35966    ------------------------------------------------------------------------------------------------
35970    -- 4219869 Business Flow
35967    XLA_AE_LINES_PKG.ValidateCurrentLine;
35968 
35969    ------------------------------------------------------------------------------------
35971    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
35972    ------------------------------------------------------------------------------------
35973    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
35974 
35975    ----------------------------------------------------------------------------------
35976    -- 4219869 Business Flow
35977    -- Update journal entry status -- Need to generate this within IF <condition>
35978    ----------------------------------------------------------------------------------
35979    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
35980          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
35981          ,p_balance_type_code => l_balance_type_code
35982          );
35983 
35984    -------------------------------------------------------------------------------------------
35985    -- 4262811 - Generate the Accrual Reversal lines
35986    -------------------------------------------------------------------------------------------
35987    BEGIN
35988       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
35989                               (g_array_event(p_event_id).array_value_num('header_index'));
35990       IF l_acc_rev_flag IS NULL THEN
35991          l_acc_rev_flag := 'N';
35992       END IF;
35993    EXCEPTION
35994       WHEN OTHERS THEN
35995          l_acc_rev_flag := 'N';
35996    END;
35997    --
35998    IF (l_acc_rev_flag = 'Y') THEN
35999 
36000        -- 4645092  ------------------------------------------------------------------------------
36001        -- To allow MPA report to determine if it should generate report process
36002        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
36003        ------------------------------------------------------------------------------------------
36004 
36005        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
36006        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
36007    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
36008    -- call ADRs
36009    -- Bug 4922099
36010    --
36011    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
36012         (NVL(l_actual_upg_option, 'N') = 'O') OR
36013         (NVL(l_enc_upg_option, 'N') = 'O')
36014       )
36015    THEN
36016    NULL;
36017    --
36018    --
36019    
36020   l_ccid := AcctDerRule_9(
36021            p_application_id           => p_application_id
36022          , p_ae_header_id             => l_ae_header_id 
36023 , p_source_6 => p_source_6
36024          , x_transaction_coa_id       => l_adr_transaction_coa_id
36025          , x_accounting_coa_id        => l_adr_accounting_coa_id
36026          , x_value_type_code          => l_adr_value_type_code
36027          , p_side                     => 'NA'
36028    );
36029 
36030    xla_ae_lines_pkg.set_ccid(
36031     p_code_combination_id          => l_ccid
36032   , p_value_type_code              => l_adr_value_type_code
36033   , p_transaction_coa_id           => l_adr_transaction_coa_id
36034   , p_accounting_coa_id            => l_adr_accounting_coa_id
36035   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
36036   , p_adr_type_code                => 'S'
36037   , p_component_type               => l_component_type
36038   , p_component_code               => l_component_code
36039   , p_component_type_code          => l_component_type_code
36040   , p_component_appl_id            => l_component_appl_id
36041   , p_amb_context_code             => l_amb_context_code
36042   , p_side                         => 'NA'
36043   );
36044 
36045 
36046    l_segment := AcctDerRule_5(
36047            p_application_id           => p_application_id
36048          , p_ae_header_id             => l_ae_header_id 
36049 , p_source_4 => p_source_4
36050          , x_transaction_coa_id       => l_adr_transaction_coa_id
36051          , x_accounting_coa_id        => l_adr_accounting_coa_id
36052          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
36053          , x_flex_value_set_id        => l_adr_flex_value_set_id
36054          , x_value_type_code          => l_adr_value_type_code
36055          , x_value_combination_id     => l_adr_value_combination_id
36056          , x_value_segment_code       => l_adr_value_segment_code
36057          , p_side                     => 'NA'
36058          , p_override_seg_flag        => 'Y'
36059    );
36060 
36061    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
36062 
36063       xla_ae_lines_pkg.set_segment(
36064           p_to_segment_code         => 'GL_BALANCING'
36065         , p_segment_value           => l_segment
36066         , p_from_segment_code       => l_adr_value_segment_code
36067         , p_from_combination_id     => l_adr_value_combination_id
36068         , p_value_type_code         => l_adr_value_type_code
36069         , p_transaction_coa_id      => l_adr_transaction_coa_id
36070         , p_accounting_coa_id       => l_adr_accounting_coa_id
36071         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
36072         , p_flex_value_set_id       => l_adr_flex_value_set_id
36073         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
36074         , p_adr_type_code           => 'S'
36075         , p_component_type          => l_component_type
36076         , p_component_code          => l_component_code
36077         , p_component_type_code     => l_component_type_code
36078         , p_component_appl_id       => l_component_appl_id
36079         , p_amb_context_code        => l_amb_context_code
36080         , p_entity_code             => 'RECEIPTS'
36081         , p_event_class_code        => 'RECEIPT'
36082         , p_side                    => 'NA'
36083         );
36084 
36085   END IF;
36086 
36087    --
36088    --
36089    END IF;
36090 
36091        --
36092        -- Update the line information that should be overwritten
36093        --
36094        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
36095                                          p_header_num   => 1);
36096        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
36097 
36098        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
36099 
36100        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
36101           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
36102        END IF;
36103 
36104       --
36105       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
36106       --
36107       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
36108           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
36109       ELSE
36110           ---------------------------------------------------------------------------------------------------
36111           -- 4262811a Switch Sign
36112           ---------------------------------------------------------------------------------------------------
36113           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
36114           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
36115                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
36116           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
36117                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
36118           -- 5132302
36119           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
36120                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
36121 
36122       END IF;
36123 
36124       -- 4955764
36125       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
36126       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
36127 
36128 
36129       XLA_AE_LINES_PKG.ValidateCurrentLine;
36130       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
36131 
36132       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
36133                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
36134                ,p_balance_type_code => l_balance_type_code);
36135 
36136    END IF;
36137 
36138    -----------------------------------------------------------------------------------------
36139    -- 4262811 Multiperiod Accounting
36140    -----------------------------------------------------------------------------------------
36141      -- No MPA option is assigned.
36142 
36143 
36144 END IF;
36145 END IF;
36146 --
36147 
36148 --
36149 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
36150    trace
36151       (p_msg      => 'END of AcctLineType_74'
36152       ,p_level    => C_LEVEL_PROCEDURE
36153       ,p_module   => l_log_module);
36154 END IF;
36155 --
36156 EXCEPTION
36157   WHEN xla_exceptions_pkg.application_exception THEN
36158       RAISE;
36159   WHEN OTHERS THEN
36160        xla_exceptions_pkg.raise_message
36161            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_74');
36162 END AcctLineType_74;
36163 --
36164 
36165 ---------------------------------------
36166 --
36167 -- PRIVATE FUNCTION
36168 --         AcctLineType_75
36169 --
36170 ---------------------------------------
36171 PROCEDURE AcctLineType_75 (
36172   p_application_id        IN NUMBER
36173  ,p_event_id              IN NUMBER
36174  ,p_calculate_acctd_flag  IN VARCHAR2
36175  ,p_calculate_g_l_flag    IN VARCHAR2
36176  ,p_actual_flag           IN OUT VARCHAR2
36177  ,p_balance_type_code     OUT VARCHAR2
36178  ,p_gain_or_loss_ref      OUT VARCHAR2
36179  
36180 --Transaction Distribution GL Account
36181  , p_source_4            IN NUMBER
36182 --Remittance Bank Account Cash Account
36183  , p_source_6            IN NUMBER
36184 --Distribution Source Type
36185  , p_source_13            IN VARCHAR2
36186 --Distribution Line Identifier
36187  , p_source_15            IN NUMBER
36188 --Distribution Type
36189  , p_source_16            IN VARCHAR2
36190 --Exchange Date
36191  , p_source_19            IN DATE
36192 --Exchange Rate
36193  , p_source_20            IN NUMBER
36194 --Exchange Rate Type
36195  , p_source_21            IN VARCHAR2
36196 --Transaction Distribution Identifier
36197  , p_source_27            IN NUMBER
36198 --Transaction Distribution Type
36199  , p_source_28            IN VARCHAR2
36200 --Distribution Multi Fund Additional Entry
36201  , p_source_52            IN VARCHAR2
36202 --Receipt Class Require Remittance Flag
36203  , p_source_54            IN VARCHAR2
36204 --Receipt Applied To Application Identifier
36205  , p_source_56            IN NUMBER
36206 --Transaction Entity Code
36207  , p_source_57            IN VARCHAR2
36208 --Transaction Identifier
36209  , p_source_58            IN NUMBER
36210 --DIST_ENT_AMT_FROM
36211  , p_source_59            IN NUMBER
36212 --Applying Document Currency Code
36213  , p_source_60            IN VARCHAR2
36214 --Accounting Amount
36215  , p_source_61            IN NUMBER
36216 --Distribution Party Identifier
36217  , p_source_62            IN NUMBER
36218 --Distribution Party Site Id
36219  , p_source_63            IN NUMBER
36220 --Distribution Party Type
36221  , p_source_64            IN VARCHAR2
36222 )
36223 IS
36224 
36225 l_component_type              VARCHAR2(80);
36226 l_component_code              VARCHAR2(30);
36227 l_component_type_code         VARCHAR2(1);
36228 l_component_appl_id           INTEGER;
36229 l_amb_context_code            VARCHAR2(30);
36230 l_entity_code                 VARCHAR2(30);
36231 l_event_class_code            VARCHAR2(30);
36232 l_ae_header_id                NUMBER;
36233 l_event_type_code             VARCHAR2(30);
36234 l_line_definition_code        VARCHAR2(30);
36235 l_line_definition_owner_code  VARCHAR2(1);
36236 --
36237 -- adr variables
36238 l_segment                     VARCHAR2(30);
36239 l_ccid                        NUMBER;
36240 l_adr_transaction_coa_id      NUMBER;
36241 l_adr_accounting_coa_id       NUMBER;
36242 l_adr_flexfield_segment_code  VARCHAR2(30);
36243 l_adr_flex_value_set_id       NUMBER;
36244 l_adr_value_type_code         VARCHAR2(30);
36245 l_adr_value_combination_id    NUMBER;
36246 l_adr_value_segment_code      VARCHAR2(30);
36247 
36248 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
36249 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
36250 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
36251 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
36252 
36253 -- 4262811 Variables ------------------------------------------------------------------------------------------
36254 l_entered_amt_idx             NUMBER;
36255 l_accted_amt_idx              NUMBER;
36256 l_acc_rev_flag                VARCHAR2(1);
36257 l_accrual_line_num            NUMBER;
36258 l_tmp_amt                     NUMBER;
36259 l_acc_rev_natural_side_code   VARCHAR2(1);
36260 
36261 l_num_entries                 NUMBER;
36262 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
36263 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
36264 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
36265 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
36266 l_recog_line_1                NUMBER;
36267 l_recog_line_2                NUMBER;
36268 
36269 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
36270 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
36271 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
36272 
36273 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
36274 
36275 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
36276 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
36277 
36278 ---------------------------------------------------------------------------------------------------------------
36279 
36280 
36281 --
36282 -- bulk performance
36283 --
36284 l_balance_type_code           VARCHAR2(1);
36285 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
36286 l_log_module                  VARCHAR2(240);
36287 
36288 --
36289 -- Upgrade strategy
36290 --
36291 l_actual_upg_option           VARCHAR2(1);
36292 l_enc_upg_option           VARCHAR2(1);
36293 
36294 --
36295 BEGIN
36296 --
36297 IF g_log_enabled THEN
36298       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_75';
36299 END IF;
36300 --
36301 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
36302 
36303       trace
36304          (p_msg      => 'BEGIN of AcctLineType_75'
36305          ,p_level    => C_LEVEL_PROCEDURE
36306          ,p_module   => l_log_module);
36307 
36308 END IF;
36309 --
36310 l_component_type             := 'AMB_JLT';
36311 l_component_code             := 'RCT_APP_MFAR_TRX_CM_CASH';
36312 l_component_type_code        := 'S';
36313 l_component_appl_id          :=  222;
36314 l_amb_context_code           := 'DEFAULT';
36315 l_entity_code                := 'RECEIPTS';
36316 l_event_class_code           := 'RECEIPT';
36317 l_event_type_code            := 'RECEIPT_ALL';
36318 l_line_definition_owner_code := 'S';
36319 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
36320 --
36321 l_balance_type_code          := 'A';
36322 l_segment                     := NULL;
36323 l_ccid                        := NULL;
36324 l_adr_transaction_coa_id      := NULL;
36325 l_adr_accounting_coa_id       := NULL;
36326 l_adr_flexfield_segment_code  := NULL;
36327 l_adr_flex_value_set_id       := NULL;
36328 l_adr_value_type_code         := NULL;
36329 l_adr_value_combination_id    := NULL;
36330 l_adr_value_segment_code      := NULL;
36331 
36332 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
36333 l_bflow_class_code           := '';    -- 4219869 Business Flow
36334 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
36335 l_budgetary_control_flag     := 'N';
36336 
36337 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
36338 l_bflow_applied_to_amt       := NULL; -- 5132302
36339 l_entered_amt_idx            := NULL;          -- 4262811
36340 l_accted_amt_idx             := NULL;          -- 4262811
36341 l_acc_rev_flag               := NULL;          -- 4262811
36342 l_accrual_line_num           := NULL;          -- 4262811
36343 l_tmp_amt                    := NULL;          -- 4262811
36344 --
36345  
36346 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
36347     l_balance_type_code <> 'B' THEN
36348 IF NVL(p_source_13,'
36349 ') =  'CASH' AND 
36350 NVL(p_source_52,'
36351 ') =  'Y' AND 
36352 NVL(p_source_54,'
36353 ') =  'Y'
36354  THEN 
36355 
36356    --
36357    XLA_AE_LINES_PKG.SetNewLine;
36358 
36359    p_balance_type_code          := l_balance_type_code;
36360    -- set the flag so later we will know whether the gain loss line needs to be created
36361    
36362    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
36363      p_actual_flag :='A';
36364    END IF;
36365 
36366    --
36367    -- bulk performance
36368    --
36369    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
36370                                       p_header_num   => 0); -- 4262811
36371    --
36372    -- set accounting line options
36373    --
36374    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
36375            p_natural_side_code          => 'C'
36376          , p_gain_or_loss_flag          => 'N'
36377          , p_gl_transfer_mode_code      => 'S'
36378          , p_acct_entry_type_code       => 'A'
36379          , p_switch_side_flag           => 'Y'
36380          , p_merge_duplicate_code       => 'A'
36381          );
36382    --
36383    l_acc_rev_natural_side_code := 'D';  -- 4262811
36384    -- 
36385    --
36386    -- set accounting line type info
36387    --
36388    xla_ae_lines_pkg.SetAcctLineType
36389       (p_component_type             => l_component_type
36390       ,p_event_type_code            => l_event_type_code
36391       ,p_line_definition_owner_code => l_line_definition_owner_code
36392       ,p_line_definition_code       => l_line_definition_code
36393       ,p_accounting_line_code       => l_component_code
36394       ,p_accounting_line_type_code  => l_component_type_code
36395       ,p_accounting_line_appl_id    => l_component_appl_id
36396       ,p_amb_context_code           => l_amb_context_code
36397       ,p_entity_code                => l_entity_code
36398       ,p_event_class_code           => l_event_class_code);
36399    --
36400    -- set accounting class
36401    --
36402    xla_ae_lines_pkg.SetAcctClass(
36403            p_accounting_class_code  => 'CASH'
36404          , p_ae_header_id           => l_ae_header_id
36405          );
36406 
36407    --
36408    -- set rounding class
36409    --
36410    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
36411                       'RECEIVABLE';
36412 
36413    --
36414    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
36415    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
36416    --
36417    -- bulk performance
36418    --
36419    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
36420 
36421    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
36422       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
36423 
36424    -- 4955764
36425    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
36426       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
36427 
36428    -- 4458381 Public Sector Enh
36429    
36430    --
36431    -- set accounting attributes for the line type
36432    --
36433    l_entered_amt_idx := 8;
36434    l_accted_amt_idx  := 13;
36435    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
36436    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
36437    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
36438    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
36439    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
36440    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
36441    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
36442    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
36443    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
36444    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
36445    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
36446    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
36447    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
36448    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
36449    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
36450    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
36451    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
36452    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
36453    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
36454    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
36455    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
36456    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
36457    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
36458    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
36459    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
36460    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
36461    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
36462    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
36463    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
36464    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
36465    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
36466    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
36467    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
36468 
36469    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
36470    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
36471 
36472    ---------------------------------------------------------------------------------------------------------------
36473    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
36474    ---------------------------------------------------------------------------------------------------------------
36475    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
36476 
36477    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
36478    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
36479 
36480    IF xla_accounting_cache_pkg.GetValueChar
36481          (p_source_code         => 'LEDGER_CATEGORY_CODE'
36482          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
36483    AND l_bflow_method_code = 'PRIOR_ENTRY'
36484 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
36485    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
36486          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
36487        )
36488    THEN
36489          xla_ae_lines_pkg.BflowUpgEntry
36490            (p_business_method_code    => l_bflow_method_code
36491            ,p_business_class_code     => l_bflow_class_code
36492            ,p_balance_type            => l_balance_type_code);
36493    ELSE
36494       NULL;
36495 -- No business flow processing for business flow method of NONE.
36496    END IF;
36497 
36498    --
36499    -- call analytical criteria
36500    --
36501    
36502    --
36503    -- call description
36504    --
36505    
36506 xla_ae_lines_pkg.SetLineDescription(
36507    p_ae_header_id => l_ae_header_id
36508   ,p_description  => Description_1 (
36509      p_application_id         => p_application_id
36510    , p_ae_header_id           => l_ae_header_id 
36511    )
36512 );
36513 
36514 
36515    --
36516    -- call ADRs
36517    -- Bug 4922099
36518    --
36519    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
36520         (NVL(l_actual_upg_option, 'N') = 'O') OR
36521         (NVL(l_enc_upg_option, 'N') = 'O')
36522       )
36523    THEN
36524    NULL;
36525    --
36526    --
36527    
36528   l_ccid := AcctDerRule_9(
36529            p_application_id           => p_application_id
36530          , p_ae_header_id             => l_ae_header_id 
36531 , p_source_6 => p_source_6
36532          , x_transaction_coa_id       => l_adr_transaction_coa_id
36533          , x_accounting_coa_id        => l_adr_accounting_coa_id
36534          , x_value_type_code          => l_adr_value_type_code
36535          , p_side                     => 'NA'
36536    );
36537 
36538    xla_ae_lines_pkg.set_ccid(
36539     p_code_combination_id          => l_ccid
36540   , p_value_type_code              => l_adr_value_type_code
36541   , p_transaction_coa_id           => l_adr_transaction_coa_id
36542   , p_accounting_coa_id            => l_adr_accounting_coa_id
36543   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
36544   , p_adr_type_code                => 'S'
36545   , p_component_type               => l_component_type
36546   , p_component_code               => l_component_code
36547   , p_component_type_code          => l_component_type_code
36548   , p_component_appl_id            => l_component_appl_id
36549   , p_amb_context_code             => l_amb_context_code
36550   , p_side                         => 'NA'
36551   );
36552 
36553 
36554    l_segment := AcctDerRule_5(
36555            p_application_id           => p_application_id
36556          , p_ae_header_id             => l_ae_header_id 
36557 , p_source_4 => p_source_4
36558          , x_transaction_coa_id       => l_adr_transaction_coa_id
36559          , x_accounting_coa_id        => l_adr_accounting_coa_id
36560          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
36561          , x_flex_value_set_id        => l_adr_flex_value_set_id
36565          , p_side                     => 'NA'
36562          , x_value_type_code          => l_adr_value_type_code
36563          , x_value_combination_id     => l_adr_value_combination_id
36564          , x_value_segment_code       => l_adr_value_segment_code
36566          , p_override_seg_flag        => 'Y'
36567    );
36568 
36569    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
36570 
36571       xla_ae_lines_pkg.set_segment(
36572           p_to_segment_code         => 'GL_BALANCING'
36573         , p_segment_value           => l_segment
36574         , p_from_segment_code       => l_adr_value_segment_code
36575         , p_from_combination_id     => l_adr_value_combination_id
36576         , p_value_type_code         => l_adr_value_type_code
36577         , p_transaction_coa_id      => l_adr_transaction_coa_id
36578         , p_accounting_coa_id       => l_adr_accounting_coa_id
36579         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
36580         , p_flex_value_set_id       => l_adr_flex_value_set_id
36581         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
36582         , p_adr_type_code           => 'S'
36583         , p_component_type          => l_component_type
36584         , p_component_code          => l_component_code
36585         , p_component_type_code     => l_component_type_code
36586         , p_component_appl_id       => l_component_appl_id
36587         , p_amb_context_code        => l_amb_context_code
36588         , p_entity_code             => 'RECEIPTS'
36589         , p_event_class_code        => 'RECEIPT'
36590         , p_side                    => 'NA'
36591         );
36592 
36593   END IF;
36594 
36595    --
36596    --
36597    END IF;
36598    --
36599    -- Bug 4922099
36600    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
36601           (NVL(l_enc_upg_option, 'N') = 'O')
36602         ) AND
36603         (l_bflow_method_code = 'PRIOR_ENTRY')
36604       )
36605    THEN
36606       IF
36607       --
36608       1 = 2
36609       --
36610       THEN
36611       xla_accounting_err_pkg.build_message
36612                                     (p_appli_s_name            => 'XLA'
36613                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
36614                                     ,p_token_1                 => 'LINE_NUMBER'
36615                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
36616                                     ,p_token_2                 => 'LINE_TYPE_NAME'
36617                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
36618                                                                              l_component_type
36619                                                                             ,l_component_code
36620                                                                             ,l_component_type_code
36621                                                                             ,l_component_appl_id
36622                                                                             ,l_amb_context_code
36623                                                                             ,l_entity_code
36624                                                                             ,l_event_class_code
36625                                                                            )
36626                                     ,p_token_3                 => 'OWNER'
36627                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
36628                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
36629                                                                           ,p_lookup_code    => l_component_type_code
36630                                                                          )
36631                                     ,p_token_4                 => 'PRODUCT_NAME'
36632                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
36633                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
36634                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
36635                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
36636                                     ,p_ae_header_id            =>  NULL
36637                                        );
36638 
36639         IF (C_LEVEL_ERROR>= g_log_level) THEN
36640                  trace
36641                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
36642                       ,p_level    => C_LEVEL_ERROR
36643                       ,p_module   => l_log_module);
36644         END IF;
36645       END IF;
36646    END IF;
36647    --
36648    --
36649    ------------------------------------------------------------------------------------------------
36650    -- 4219869 Business Flow
36651    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
36652    -- Prior Entry.  Currently, the following code is always generated.
36653    ------------------------------------------------------------------------------------------------
36654    XLA_AE_LINES_PKG.ValidateCurrentLine;
36655 
36656    ------------------------------------------------------------------------------------
36657    -- 4219869 Business Flow
36658    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
36659    ------------------------------------------------------------------------------------
36660    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
36661 
36662    ----------------------------------------------------------------------------------
36663    -- 4219869 Business Flow
36664    -- Update journal entry status -- Need to generate this within IF <condition>
36665    ----------------------------------------------------------------------------------
36666    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
36667          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
36668          ,p_balance_type_code => l_balance_type_code
36669          );
36670 
36671    -------------------------------------------------------------------------------------------
36672    -- 4262811 - Generate the Accrual Reversal lines
36673    -------------------------------------------------------------------------------------------
36674    BEGIN
36675       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
36676                               (g_array_event(p_event_id).array_value_num('header_index'));
36677       IF l_acc_rev_flag IS NULL THEN
36678          l_acc_rev_flag := 'N';
36679       END IF;
36680    EXCEPTION
36681       WHEN OTHERS THEN
36682          l_acc_rev_flag := 'N';
36683    END;
36684    --
36685    IF (l_acc_rev_flag = 'Y') THEN
36686 
36687        -- 4645092  ------------------------------------------------------------------------------
36688        -- To allow MPA report to determine if it should generate report process
36689        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
36690        ------------------------------------------------------------------------------------------
36691 
36692        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
36693        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
36694    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
36695    -- call ADRs
36696    -- Bug 4922099
36697    --
36698    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
36699         (NVL(l_actual_upg_option, 'N') = 'O') OR
36700         (NVL(l_enc_upg_option, 'N') = 'O')
36701       )
36702    THEN
36703    NULL;
36704    --
36705    --
36706    
36707   l_ccid := AcctDerRule_9(
36708            p_application_id           => p_application_id
36709          , p_ae_header_id             => l_ae_header_id 
36710 , p_source_6 => p_source_6
36711          , x_transaction_coa_id       => l_adr_transaction_coa_id
36712          , x_accounting_coa_id        => l_adr_accounting_coa_id
36713          , x_value_type_code          => l_adr_value_type_code
36714          , p_side                     => 'NA'
36715    );
36716 
36717    xla_ae_lines_pkg.set_ccid(
36718     p_code_combination_id          => l_ccid
36719   , p_value_type_code              => l_adr_value_type_code
36720   , p_transaction_coa_id           => l_adr_transaction_coa_id
36721   , p_accounting_coa_id            => l_adr_accounting_coa_id
36722   , p_adr_code                     => 'MFAR_RCT_DEF_CASH_CCID'
36723   , p_adr_type_code                => 'S'
36724   , p_component_type               => l_component_type
36725   , p_component_code               => l_component_code
36726   , p_component_type_code          => l_component_type_code
36727   , p_component_appl_id            => l_component_appl_id
36728   , p_amb_context_code             => l_amb_context_code
36729   , p_side                         => 'NA'
36730   );
36731 
36732 
36733    l_segment := AcctDerRule_5(
36734            p_application_id           => p_application_id
36735          , p_ae_header_id             => l_ae_header_id 
36736 , p_source_4 => p_source_4
36737          , x_transaction_coa_id       => l_adr_transaction_coa_id
36738          , x_accounting_coa_id        => l_adr_accounting_coa_id
36739          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
36740          , x_flex_value_set_id        => l_adr_flex_value_set_id
36741          , x_value_type_code          => l_adr_value_type_code
36742          , x_value_combination_id     => l_adr_value_combination_id
36743          , x_value_segment_code       => l_adr_value_segment_code
36744          , p_side                     => 'NA'
36745          , p_override_seg_flag        => 'Y'
36746    );
36747 
36748    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
36749 
36750       xla_ae_lines_pkg.set_segment(
36751           p_to_segment_code         => 'GL_BALANCING'
36752         , p_segment_value           => l_segment
36753         , p_from_segment_code       => l_adr_value_segment_code
36754         , p_from_combination_id     => l_adr_value_combination_id
36755         , p_value_type_code         => l_adr_value_type_code
36756         , p_transaction_coa_id      => l_adr_transaction_coa_id
36757         , p_accounting_coa_id       => l_adr_accounting_coa_id
36758         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
36759         , p_flex_value_set_id       => l_adr_flex_value_set_id
36760         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
36761         , p_adr_type_code           => 'S'
36762         , p_component_type          => l_component_type
36763         , p_component_code          => l_component_code
36764         , p_component_type_code     => l_component_type_code
36765         , p_component_appl_id       => l_component_appl_id
36766         , p_amb_context_code        => l_amb_context_code
36767         , p_entity_code             => 'RECEIPTS'
36768         , p_event_class_code        => 'RECEIPT'
36769         , p_side                    => 'NA'
36770         );
36771 
36772   END IF;
36773 
36774    --
36775    --
36776    END IF;
36777 
36778        --
36779        -- Update the line information that should be overwritten
36780        --
36781        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
36782                                          p_header_num   => 1);
36783        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
36784 
36785        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
36786 
36787        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
36788           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
36789        END IF;
36790 
36791       --
36792       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
36793       --
36794       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
36795           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
36796       ELSE
36797           ---------------------------------------------------------------------------------------------------
36798           -- 4262811a Switch Sign
36799           ---------------------------------------------------------------------------------------------------
36800           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
36801           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
36802                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
36803           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
36804                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
36805           -- 5132302
36806           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
36807                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
36808 
36809       END IF;
36810 
36811       -- 4955764
36812       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
36813       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
36814 
36815 
36816       XLA_AE_LINES_PKG.ValidateCurrentLine;
36817       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
36818 
36819       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
36820                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
36821                ,p_balance_type_code => l_balance_type_code);
36822 
36823    END IF;
36824 
36825    -----------------------------------------------------------------------------------------
36826    -- 4262811 Multiperiod Accounting
36827    -----------------------------------------------------------------------------------------
36828      -- No MPA option is assigned.
36829 
36830 
36831 END IF;
36832 END IF;
36833 --
36834 
36835 --
36836 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
36837    trace
36838       (p_msg      => 'END of AcctLineType_75'
36839       ,p_level    => C_LEVEL_PROCEDURE
36840       ,p_module   => l_log_module);
36841 END IF;
36842 --
36843 EXCEPTION
36844   WHEN xla_exceptions_pkg.application_exception THEN
36845       RAISE;
36846   WHEN OTHERS THEN
36847        xla_exceptions_pkg.raise_message
36848            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_75');
36849 END AcctLineType_75;
36850 --
36851 
36852 ---------------------------------------
36853 --
36854 -- PRIVATE FUNCTION
36855 --         AcctLineType_76
36856 --
36857 ---------------------------------------
36858 PROCEDURE AcctLineType_76 (
36859   p_application_id        IN NUMBER
36860  ,p_event_id              IN NUMBER
36861  ,p_calculate_acctd_flag  IN VARCHAR2
36862  ,p_calculate_g_l_flag    IN VARCHAR2
36863  ,p_actual_flag           IN OUT VARCHAR2
36864  ,p_balance_type_code     OUT VARCHAR2
36865  ,p_gain_or_loss_ref      OUT VARCHAR2
36866  
36867 --Transaction Distribution GL Account
36868  , p_source_4            IN NUMBER
36869 --Remittance Bank Account Confirmation Account
36870  , p_source_7            IN NUMBER
36871 --Distribution Source Type
36872  , p_source_13            IN VARCHAR2
36873 --Distribution Line Identifier
36874  , p_source_15            IN NUMBER
36875 --Distribution Type
36876  , p_source_16            IN VARCHAR2
36877 --Exchange Date
36878  , p_source_19            IN DATE
36879 --Exchange Rate
36880  , p_source_20            IN NUMBER
36881 --Exchange Rate Type
36882  , p_source_21            IN VARCHAR2
36883 --Transaction Distribution Identifier
36884  , p_source_27            IN NUMBER
36885 --Transaction Distribution Type
36886  , p_source_28            IN VARCHAR2
36887 --Distribution Multi Fund Additional Entry
36888  , p_source_52            IN VARCHAR2
36889 --Receipt Applied To Application Identifier
36890  , p_source_56            IN NUMBER
36891 --Transaction Entity Code
36892  , p_source_57            IN VARCHAR2
36893 --Transaction Identifier
36894  , p_source_58            IN NUMBER
36895 --DIST_ENT_AMT_FROM
36896  , p_source_59            IN NUMBER
36897 --Applying Document Currency Code
36898  , p_source_60            IN VARCHAR2
36899 --Accounting Amount
36900  , p_source_61            IN NUMBER
36901 --Distribution Party Identifier
36902  , p_source_62            IN NUMBER
36903 --Distribution Party Site Id
36904  , p_source_63            IN NUMBER
36905 --Distribution Party Type
36906  , p_source_64            IN VARCHAR2
36907 )
36908 IS
36909 
36910 l_component_type              VARCHAR2(80);
36911 l_component_code              VARCHAR2(30);
36912 l_component_type_code         VARCHAR2(1);
36913 l_component_appl_id           INTEGER;
36914 l_amb_context_code            VARCHAR2(30);
36915 l_entity_code                 VARCHAR2(30);
36916 l_event_class_code            VARCHAR2(30);
36917 l_ae_header_id                NUMBER;
36918 l_event_type_code             VARCHAR2(30);
36919 l_line_definition_code        VARCHAR2(30);
36920 l_line_definition_owner_code  VARCHAR2(1);
36921 --
36922 -- adr variables
36923 l_segment                     VARCHAR2(30);
36924 l_ccid                        NUMBER;
36925 l_adr_transaction_coa_id      NUMBER;
36926 l_adr_accounting_coa_id       NUMBER;
36927 l_adr_flexfield_segment_code  VARCHAR2(30);
36928 l_adr_flex_value_set_id       NUMBER;
36929 l_adr_value_type_code         VARCHAR2(30);
36930 l_adr_value_combination_id    NUMBER;
36931 l_adr_value_segment_code      VARCHAR2(30);
36932 
36933 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
36934 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
36935 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
36936 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
36937 
36938 -- 4262811 Variables ------------------------------------------------------------------------------------------
36939 l_entered_amt_idx             NUMBER;
36940 l_accted_amt_idx              NUMBER;
36941 l_acc_rev_flag                VARCHAR2(1);
36942 l_accrual_line_num            NUMBER;
36943 l_tmp_amt                     NUMBER;
36944 l_acc_rev_natural_side_code   VARCHAR2(1);
36945 
36946 l_num_entries                 NUMBER;
36947 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
36948 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
36949 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
36950 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
36951 l_recog_line_1                NUMBER;
36952 l_recog_line_2                NUMBER;
36953 
36954 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
36955 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
36956 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
36957 
36958 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
36959 
36960 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
36961 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
36962 
36963 ---------------------------------------------------------------------------------------------------------------
36964 
36965 
36966 --
36967 -- bulk performance
36968 --
36969 l_balance_type_code           VARCHAR2(1);
36970 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
36971 l_log_module                  VARCHAR2(240);
36972 
36973 --
36974 -- Upgrade strategy
36975 --
36976 l_actual_upg_option           VARCHAR2(1);
36977 l_enc_upg_option           VARCHAR2(1);
36978 
36979 --
36980 BEGIN
36981 --
36982 IF g_log_enabled THEN
36983       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_76';
36984 END IF;
36985 --
36986 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
36987 
36988       trace
36989          (p_msg      => 'BEGIN of AcctLineType_76'
36990          ,p_level    => C_LEVEL_PROCEDURE
36991          ,p_module   => l_log_module);
36992 
36993 END IF;
36994 --
36995 l_component_type             := 'AMB_JLT';
36996 l_component_code             := 'RCT_APP_MFAR_TRX_CONFIRMATION';
36997 l_component_type_code        := 'S';
36998 l_component_appl_id          :=  222;
36999 l_amb_context_code           := 'DEFAULT';
37000 l_entity_code                := 'RECEIPTS';
37001 l_event_class_code           := 'RECEIPT';
37002 l_event_type_code            := 'RECEIPT_ALL';
37003 l_line_definition_owner_code := 'S';
37004 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
37005 --
37006 l_balance_type_code          := 'A';
37007 l_segment                     := NULL;
37008 l_ccid                        := NULL;
37009 l_adr_transaction_coa_id      := NULL;
37010 l_adr_accounting_coa_id       := NULL;
37011 l_adr_flexfield_segment_code  := NULL;
37012 l_adr_flex_value_set_id       := NULL;
37013 l_adr_value_type_code         := NULL;
37014 l_adr_value_combination_id    := NULL;
37015 l_adr_value_segment_code      := NULL;
37016 
37017 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
37018 l_bflow_class_code           := '';    -- 4219869 Business Flow
37019 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
37020 l_budgetary_control_flag     := 'N';
37021 
37022 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
37023 l_bflow_applied_to_amt       := NULL; -- 5132302
37024 l_entered_amt_idx            := NULL;          -- 4262811
37025 l_accted_amt_idx             := NULL;          -- 4262811
37026 l_acc_rev_flag               := NULL;          -- 4262811
37027 l_accrual_line_num           := NULL;          -- 4262811
37028 l_tmp_amt                    := NULL;          -- 4262811
37029 --
37030  
37031 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
37032     l_balance_type_code <> 'B' THEN
37033 IF NVL(p_source_13,'
37034 ') =  'CONFIRMATION' AND 
37035 NVL(p_source_52,'
37036 ') =  'Y'
37037  THEN 
37038 
37039    --
37040    XLA_AE_LINES_PKG.SetNewLine;
37041 
37042    p_balance_type_code          := l_balance_type_code;
37043    -- set the flag so later we will know whether the gain loss line needs to be created
37044    
37045    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
37046      p_actual_flag :='A';
37047    END IF;
37048 
37049    --
37050    -- bulk performance
37051    --
37052    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
37053                                       p_header_num   => 0); -- 4262811
37054    --
37055    -- set accounting line options
37056    --
37057    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
37058            p_natural_side_code          => 'C'
37059          , p_gain_or_loss_flag          => 'N'
37060          , p_gl_transfer_mode_code      => 'S'
37061          , p_acct_entry_type_code       => 'A'
37062          , p_switch_side_flag           => 'Y'
37063          , p_merge_duplicate_code       => 'A'
37064          );
37065    --
37066    l_acc_rev_natural_side_code := 'D';  -- 4262811
37067    -- 
37068    --
37069    -- set accounting line type info
37070    --
37071    xla_ae_lines_pkg.SetAcctLineType
37072       (p_component_type             => l_component_type
37073       ,p_event_type_code            => l_event_type_code
37074       ,p_line_definition_owner_code => l_line_definition_owner_code
37075       ,p_line_definition_code       => l_line_definition_code
37076       ,p_accounting_line_code       => l_component_code
37077       ,p_accounting_line_type_code  => l_component_type_code
37078       ,p_accounting_line_appl_id    => l_component_appl_id
37079       ,p_amb_context_code           => l_amb_context_code
37080       ,p_entity_code                => l_entity_code
37081       ,p_event_class_code           => l_event_class_code);
37082    --
37083    -- set accounting class
37084    --
37085    xla_ae_lines_pkg.SetAcctClass(
37086            p_accounting_class_code  => 'CONFIRMATION'
37090    --
37087          , p_ae_header_id           => l_ae_header_id
37088          );
37089 
37091    -- set rounding class
37092    --
37093    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
37094                       'RECEIVABLE';
37095 
37096    --
37097    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
37098    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
37099    --
37100    -- bulk performance
37101    --
37102    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
37103 
37104    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
37105       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
37106 
37107    -- 4955764
37108    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
37109       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
37110 
37111    -- 4458381 Public Sector Enh
37112    
37113    --
37114    -- set accounting attributes for the line type
37115    --
37116    l_entered_amt_idx := 8;
37117    l_accted_amt_idx  := 13;
37118    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
37119    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
37120    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
37121    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
37122    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
37123    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
37124    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
37125    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
37126    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
37127    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
37128    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
37129    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
37130    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
37131    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
37132    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
37133    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
37134    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
37135    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
37136    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
37137    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
37138    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
37139    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
37140    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
37141    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
37142    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
37143    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
37144    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
37145    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
37146    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
37147    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
37148    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
37149    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
37150    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
37151 
37152    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
37153    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
37154 
37155    ---------------------------------------------------------------------------------------------------------------
37156    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
37157    ---------------------------------------------------------------------------------------------------------------
37158    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
37159 
37160    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
37161    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
37162 
37163    IF xla_accounting_cache_pkg.GetValueChar
37164          (p_source_code         => 'LEDGER_CATEGORY_CODE'
37165          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
37166    AND l_bflow_method_code = 'PRIOR_ENTRY'
37167 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
37168    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
37169          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
37170        )
37171    THEN
37172          xla_ae_lines_pkg.BflowUpgEntry
37173            (p_business_method_code    => l_bflow_method_code
37174            ,p_business_class_code     => l_bflow_class_code
37175            ,p_balance_type            => l_balance_type_code);
37176    ELSE
37177       NULL;
37178 -- No business flow processing for business flow method of NONE.
37179    END IF;
37180 
37181    --
37182    -- call analytical criteria
37183    --
37184    
37185    --
37186    -- call description
37187    --
37188    
37189 xla_ae_lines_pkg.SetLineDescription(
37190    p_ae_header_id => l_ae_header_id
37191   ,p_description  => Description_1 (
37192      p_application_id         => p_application_id
37193    , p_ae_header_id           => l_ae_header_id 
37194    )
37195 );
37199    -- call ADRs
37196 
37197 
37198    --
37200    -- Bug 4922099
37201    --
37202    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
37203         (NVL(l_actual_upg_option, 'N') = 'O') OR
37204         (NVL(l_enc_upg_option, 'N') = 'O')
37205       )
37206    THEN
37207    NULL;
37208    --
37209    --
37210    
37211   l_ccid := AcctDerRule_10(
37212            p_application_id           => p_application_id
37213          , p_ae_header_id             => l_ae_header_id 
37214 , p_source_7 => p_source_7
37215          , x_transaction_coa_id       => l_adr_transaction_coa_id
37216          , x_accounting_coa_id        => l_adr_accounting_coa_id
37217          , x_value_type_code          => l_adr_value_type_code
37218          , p_side                     => 'NA'
37219    );
37220 
37221    xla_ae_lines_pkg.set_ccid(
37222     p_code_combination_id          => l_ccid
37223   , p_value_type_code              => l_adr_value_type_code
37224   , p_transaction_coa_id           => l_adr_transaction_coa_id
37225   , p_accounting_coa_id            => l_adr_accounting_coa_id
37226   , p_adr_code                     => 'MFAR_RCT_DEF_CONFIRMATION_CCID'
37227   , p_adr_type_code                => 'S'
37228   , p_component_type               => l_component_type
37229   , p_component_code               => l_component_code
37230   , p_component_type_code          => l_component_type_code
37231   , p_component_appl_id            => l_component_appl_id
37232   , p_amb_context_code             => l_amb_context_code
37233   , p_side                         => 'NA'
37234   );
37235 
37236 
37237    l_segment := AcctDerRule_5(
37238            p_application_id           => p_application_id
37239          , p_ae_header_id             => l_ae_header_id 
37240 , p_source_4 => p_source_4
37241          , x_transaction_coa_id       => l_adr_transaction_coa_id
37242          , x_accounting_coa_id        => l_adr_accounting_coa_id
37243          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
37244          , x_flex_value_set_id        => l_adr_flex_value_set_id
37245          , x_value_type_code          => l_adr_value_type_code
37246          , x_value_combination_id     => l_adr_value_combination_id
37247          , x_value_segment_code       => l_adr_value_segment_code
37248          , p_side                     => 'NA'
37249          , p_override_seg_flag        => 'Y'
37250    );
37251 
37252    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
37253 
37254       xla_ae_lines_pkg.set_segment(
37255           p_to_segment_code         => 'GL_BALANCING'
37256         , p_segment_value           => l_segment
37257         , p_from_segment_code       => l_adr_value_segment_code
37258         , p_from_combination_id     => l_adr_value_combination_id
37259         , p_value_type_code         => l_adr_value_type_code
37260         , p_transaction_coa_id      => l_adr_transaction_coa_id
37261         , p_accounting_coa_id       => l_adr_accounting_coa_id
37262         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
37263         , p_flex_value_set_id       => l_adr_flex_value_set_id
37264         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
37265         , p_adr_type_code           => 'S'
37266         , p_component_type          => l_component_type
37267         , p_component_code          => l_component_code
37268         , p_component_type_code     => l_component_type_code
37269         , p_component_appl_id       => l_component_appl_id
37270         , p_amb_context_code        => l_amb_context_code
37271         , p_entity_code             => 'RECEIPTS'
37272         , p_event_class_code        => 'RECEIPT'
37273         , p_side                    => 'NA'
37274         );
37275 
37276   END IF;
37277 
37278    --
37279    --
37280    END IF;
37281    --
37282    -- Bug 4922099
37283    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
37284           (NVL(l_enc_upg_option, 'N') = 'O')
37285         ) AND
37286         (l_bflow_method_code = 'PRIOR_ENTRY')
37287       )
37288    THEN
37289       IF
37290       --
37291       1 = 2
37292       --
37293       THEN
37294       xla_accounting_err_pkg.build_message
37295                                     (p_appli_s_name            => 'XLA'
37296                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
37297                                     ,p_token_1                 => 'LINE_NUMBER'
37298                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
37299                                     ,p_token_2                 => 'LINE_TYPE_NAME'
37300                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
37301                                                                              l_component_type
37302                                                                             ,l_component_code
37303                                                                             ,l_component_type_code
37304                                                                             ,l_component_appl_id
37305                                                                             ,l_amb_context_code
37306                                                                             ,l_entity_code
37307                                                                             ,l_event_class_code
37308                                                                            )
37309                                     ,p_token_3                 => 'OWNER'
37310                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
37314                                     ,p_token_4                 => 'PRODUCT_NAME'
37311                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
37312                                                                           ,p_lookup_code    => l_component_type_code
37313                                                                          )
37315                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
37316                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
37317                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
37318                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
37319                                     ,p_ae_header_id            =>  NULL
37320                                        );
37321 
37322         IF (C_LEVEL_ERROR>= g_log_level) THEN
37323                  trace
37324                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
37325                       ,p_level    => C_LEVEL_ERROR
37326                       ,p_module   => l_log_module);
37327         END IF;
37328       END IF;
37329    END IF;
37330    --
37331    --
37332    ------------------------------------------------------------------------------------------------
37333    -- 4219869 Business Flow
37334    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
37335    -- Prior Entry.  Currently, the following code is always generated.
37336    ------------------------------------------------------------------------------------------------
37337    XLA_AE_LINES_PKG.ValidateCurrentLine;
37338 
37339    ------------------------------------------------------------------------------------
37340    -- 4219869 Business Flow
37341    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
37342    ------------------------------------------------------------------------------------
37343    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
37344 
37345    ----------------------------------------------------------------------------------
37346    -- 4219869 Business Flow
37347    -- Update journal entry status -- Need to generate this within IF <condition>
37348    ----------------------------------------------------------------------------------
37349    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
37350          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
37351          ,p_balance_type_code => l_balance_type_code
37352          );
37353 
37354    -------------------------------------------------------------------------------------------
37355    -- 4262811 - Generate the Accrual Reversal lines
37356    -------------------------------------------------------------------------------------------
37357    BEGIN
37358       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
37359                               (g_array_event(p_event_id).array_value_num('header_index'));
37360       IF l_acc_rev_flag IS NULL THEN
37361          l_acc_rev_flag := 'N';
37362       END IF;
37363    EXCEPTION
37364       WHEN OTHERS THEN
37365          l_acc_rev_flag := 'N';
37366    END;
37367    --
37368    IF (l_acc_rev_flag = 'Y') THEN
37369 
37370        -- 4645092  ------------------------------------------------------------------------------
37371        -- To allow MPA report to determine if it should generate report process
37372        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
37373        ------------------------------------------------------------------------------------------
37374 
37375        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
37376        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
37377    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
37378    -- call ADRs
37379    -- Bug 4922099
37380    --
37381    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
37382         (NVL(l_actual_upg_option, 'N') = 'O') OR
37383         (NVL(l_enc_upg_option, 'N') = 'O')
37384       )
37385    THEN
37386    NULL;
37387    --
37388    --
37389    
37390   l_ccid := AcctDerRule_10(
37391            p_application_id           => p_application_id
37392          , p_ae_header_id             => l_ae_header_id 
37393 , p_source_7 => p_source_7
37394          , x_transaction_coa_id       => l_adr_transaction_coa_id
37395          , x_accounting_coa_id        => l_adr_accounting_coa_id
37396          , x_value_type_code          => l_adr_value_type_code
37397          , p_side                     => 'NA'
37398    );
37399 
37400    xla_ae_lines_pkg.set_ccid(
37401     p_code_combination_id          => l_ccid
37402   , p_value_type_code              => l_adr_value_type_code
37403   , p_transaction_coa_id           => l_adr_transaction_coa_id
37404   , p_accounting_coa_id            => l_adr_accounting_coa_id
37405   , p_adr_code                     => 'MFAR_RCT_DEF_CONFIRMATION_CCID'
37406   , p_adr_type_code                => 'S'
37407   , p_component_type               => l_component_type
37408   , p_component_code               => l_component_code
37409   , p_component_type_code          => l_component_type_code
37410   , p_component_appl_id            => l_component_appl_id
37411   , p_amb_context_code             => l_amb_context_code
37412   , p_side                         => 'NA'
37413   );
37414 
37415 
37416    l_segment := AcctDerRule_5(
37417            p_application_id           => p_application_id
37418          , p_ae_header_id             => l_ae_header_id 
37419 , p_source_4 => p_source_4
37420          , x_transaction_coa_id       => l_adr_transaction_coa_id
37421          , x_accounting_coa_id        => l_adr_accounting_coa_id
37422          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
37423          , x_flex_value_set_id        => l_adr_flex_value_set_id
37424          , x_value_type_code          => l_adr_value_type_code
37425          , x_value_combination_id     => l_adr_value_combination_id
37426          , x_value_segment_code       => l_adr_value_segment_code
37427          , p_side                     => 'NA'
37428          , p_override_seg_flag        => 'Y'
37429    );
37430 
37431    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
37432 
37433       xla_ae_lines_pkg.set_segment(
37434           p_to_segment_code         => 'GL_BALANCING'
37435         , p_segment_value           => l_segment
37436         , p_from_segment_code       => l_adr_value_segment_code
37437         , p_from_combination_id     => l_adr_value_combination_id
37438         , p_value_type_code         => l_adr_value_type_code
37439         , p_transaction_coa_id      => l_adr_transaction_coa_id
37440         , p_accounting_coa_id       => l_adr_accounting_coa_id
37441         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
37442         , p_flex_value_set_id       => l_adr_flex_value_set_id
37443         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
37444         , p_adr_type_code           => 'S'
37445         , p_component_type          => l_component_type
37446         , p_component_code          => l_component_code
37447         , p_component_type_code     => l_component_type_code
37448         , p_component_appl_id       => l_component_appl_id
37449         , p_amb_context_code        => l_amb_context_code
37450         , p_entity_code             => 'RECEIPTS'
37451         , p_event_class_code        => 'RECEIPT'
37452         , p_side                    => 'NA'
37453         );
37454 
37455   END IF;
37456 
37457    --
37458    --
37459    END IF;
37460 
37461        --
37462        -- Update the line information that should be overwritten
37463        --
37464        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
37465                                          p_header_num   => 1);
37466        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
37467 
37468        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
37469 
37470        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
37471           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
37472        END IF;
37473 
37474       --
37475       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
37476       --
37477       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
37478           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
37479       ELSE
37480           ---------------------------------------------------------------------------------------------------
37481           -- 4262811a Switch Sign
37482           ---------------------------------------------------------------------------------------------------
37483           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
37484           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
37485                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
37486           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
37487                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
37488           -- 5132302
37489           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
37490                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
37491 
37492       END IF;
37493 
37494       -- 4955764
37495       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
37496       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
37497 
37498 
37499       XLA_AE_LINES_PKG.ValidateCurrentLine;
37500       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
37501 
37502       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
37503                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
37504                ,p_balance_type_code => l_balance_type_code);
37505 
37506    END IF;
37507 
37508    -----------------------------------------------------------------------------------------
37509    -- 4262811 Multiperiod Accounting
37510    -----------------------------------------------------------------------------------------
37511      -- No MPA option is assigned.
37512 
37513 
37514 END IF;
37515 END IF;
37516 --
37517 
37518 --
37519 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
37520    trace
37521       (p_msg      => 'END of AcctLineType_76'
37522       ,p_level    => C_LEVEL_PROCEDURE
37523       ,p_module   => l_log_module);
37524 END IF;
37525 --
37526 EXCEPTION
37527   WHEN xla_exceptions_pkg.application_exception THEN
37528       RAISE;
37529   WHEN OTHERS THEN
37530        xla_exceptions_pkg.raise_message
37531            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_76');
37532 END AcctLineType_76;
37533 --
37534 
37535 ---------------------------------------
37536 --
37537 -- PRIVATE FUNCTION
37538 --         AcctLineType_77
37539 --
37540 ---------------------------------------
37541 PROCEDURE AcctLineType_77 (
37542   p_application_id        IN NUMBER
37543  ,p_event_id              IN NUMBER
37544  ,p_calculate_acctd_flag  IN VARCHAR2
37545  ,p_calculate_g_l_flag    IN VARCHAR2
37546  ,p_actual_flag           IN OUT VARCHAR2
37547  ,p_balance_type_code     OUT VARCHAR2
37548  ,p_gain_or_loss_ref      OUT VARCHAR2
37549  
37550 --Distribution Source Type
37551  , p_source_13            IN VARCHAR2
37552 --Distribution Line Identifier
37553  , p_source_15            IN NUMBER
37554 --Distribution Type
37555  , p_source_16            IN VARCHAR2
37556 --Entered Amount
37557  , p_source_17            IN NUMBER
37558 --Currency Code
37559  , p_source_18            IN VARCHAR2
37560 --Applied To Document Accounting Amount
37561  , p_source_22            IN NUMBER
37562 --Transaction Distribution Account Class
37563  , p_source_26            IN VARCHAR2
37564 --Transaction Distribution Identifier
37565  , p_source_27            IN NUMBER
37566 --Transaction Distribution Type
37567  , p_source_28            IN VARCHAR2
37568 --Distribution Multi Fund Additional Entry
37569  , p_source_52            IN VARCHAR2
37570 --Receipt Applied To Application Identifier
37571  , p_source_56            IN NUMBER
37572 --Transaction Entity Code
37573  , p_source_57            IN VARCHAR2
37574 --Transaction Identifier
37575  , p_source_58            IN NUMBER
37576 --Distribution Party Type
37577  , p_source_64            IN VARCHAR2
37578 )
37579 IS
37580 
37581 l_component_type              VARCHAR2(80);
37582 l_component_code              VARCHAR2(30);
37583 l_component_type_code         VARCHAR2(1);
37584 l_component_appl_id           INTEGER;
37585 l_amb_context_code            VARCHAR2(30);
37586 l_entity_code                 VARCHAR2(30);
37587 l_event_class_code            VARCHAR2(30);
37588 l_ae_header_id                NUMBER;
37589 l_event_type_code             VARCHAR2(30);
37590 l_line_definition_code        VARCHAR2(30);
37591 l_line_definition_owner_code  VARCHAR2(1);
37592 --
37593 -- adr variables
37594 l_segment                     VARCHAR2(30);
37595 l_ccid                        NUMBER;
37596 l_adr_transaction_coa_id      NUMBER;
37597 l_adr_accounting_coa_id       NUMBER;
37598 l_adr_flexfield_segment_code  VARCHAR2(30);
37599 l_adr_flex_value_set_id       NUMBER;
37600 l_adr_value_type_code         VARCHAR2(30);
37601 l_adr_value_combination_id    NUMBER;
37602 l_adr_value_segment_code      VARCHAR2(30);
37603 
37604 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
37605 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
37606 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
37607 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
37608 
37609 -- 4262811 Variables ------------------------------------------------------------------------------------------
37610 l_entered_amt_idx             NUMBER;
37611 l_accted_amt_idx              NUMBER;
37612 l_acc_rev_flag                VARCHAR2(1);
37613 l_accrual_line_num            NUMBER;
37617 l_num_entries                 NUMBER;
37614 l_tmp_amt                     NUMBER;
37615 l_acc_rev_natural_side_code   VARCHAR2(1);
37616 
37618 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
37619 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
37620 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
37621 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
37622 l_recog_line_1                NUMBER;
37623 l_recog_line_2                NUMBER;
37624 
37625 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
37626 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
37627 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
37628 
37629 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
37630 
37631 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
37632 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
37633 
37634 ---------------------------------------------------------------------------------------------------------------
37635 
37636 
37637 --
37638 -- bulk performance
37639 --
37640 l_balance_type_code           VARCHAR2(1);
37641 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
37642 l_log_module                  VARCHAR2(240);
37643 
37644 --
37645 -- Upgrade strategy
37646 --
37647 l_actual_upg_option           VARCHAR2(1);
37648 l_enc_upg_option           VARCHAR2(1);
37649 
37650 --
37651 BEGIN
37652 --
37653 IF g_log_enabled THEN
37654       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_77';
37655 END IF;
37656 --
37657 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
37658 
37659       trace
37660          (p_msg      => 'BEGIN of AcctLineType_77'
37661          ,p_level    => C_LEVEL_PROCEDURE
37662          ,p_module   => l_log_module);
37663 
37664 END IF;
37665 --
37666 l_component_type             := 'AMB_JLT';
37667 l_component_code             := 'RCT_APP_MFAR_TRX_REC';
37668 l_component_type_code        := 'S';
37669 l_component_appl_id          :=  222;
37670 l_amb_context_code           := 'DEFAULT';
37671 l_entity_code                := 'RECEIPTS';
37672 l_event_class_code           := 'RECEIPT';
37673 l_event_type_code            := 'RECEIPT_ALL';
37674 l_line_definition_owner_code := 'S';
37675 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
37676 --
37677 l_balance_type_code          := 'A';
37678 l_segment                     := NULL;
37679 l_ccid                        := NULL;
37680 l_adr_transaction_coa_id      := NULL;
37681 l_adr_accounting_coa_id       := NULL;
37682 l_adr_flexfield_segment_code  := NULL;
37683 l_adr_flex_value_set_id       := NULL;
37684 l_adr_value_type_code         := NULL;
37685 l_adr_value_combination_id    := NULL;
37686 l_adr_value_segment_code      := NULL;
37687 
37688 l_bflow_method_code          := 'PRIOR_ENTRY';   -- 4219869 Business Flow
37689 l_bflow_class_code           := 'RECEIVABLE';    -- 4219869 Business Flow
37690 l_inherit_desc_flag          := 'Y';   -- 4219869 Business Flow
37691 l_budgetary_control_flag     := 'N';
37692 
37693 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
37694 l_bflow_applied_to_amt       := NULL; -- 5132302
37695 l_entered_amt_idx            := NULL;          -- 4262811
37696 l_accted_amt_idx             := NULL;          -- 4262811
37697 l_acc_rev_flag               := NULL;          -- 4262811
37698 l_accrual_line_num           := NULL;          -- 4262811
37699 l_tmp_amt                    := NULL;          -- 4262811
37700 --
37701  
37702 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
37703     l_balance_type_code <> 'B' THEN
37704 IF (NVL(p_source_26,'
37705 ') =  'REV' OR 
37706 NVL(p_source_26,'
37707 ') =  'TAX' OR 
37708 NVL(p_source_26,'
37709 ') =  'FREIGHT' OR 
37710 NVL(p_source_26,'
37711 ') =  'ROUND' OR 
37712 NVL(p_source_26,'
37713 ') =  'CHARGES') AND 
37714 NVL(p_source_13,'
37715 ') =  'REC' AND 
37716 NVL(p_source_52,'
37717 ') =  'N'
37718  THEN 
37719 
37720    --
37721    XLA_AE_LINES_PKG.SetNewLine;
37722 
37723    p_balance_type_code          := l_balance_type_code;
37724    -- set the flag so later we will know whether the gain loss line needs to be created
37725    
37726    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
37727      p_actual_flag :='A';
37728    END IF;
37729 
37730    --
37731    -- bulk performance
37732    --
37733    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
37734                                       p_header_num   => 0); -- 4262811
37735    --
37736    -- set accounting line options
37737    --
37738    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
37739            p_natural_side_code          => 'C'
37740          , p_gain_or_loss_flag          => 'N'
37741          , p_gl_transfer_mode_code      => 'S'
37742          , p_acct_entry_type_code       => 'A'
37743          , p_switch_side_flag           => 'Y'
37744          , p_merge_duplicate_code       => 'A'
37745          );
37746    --
37747    l_acc_rev_natural_side_code := 'D';  -- 4262811
37748    -- 
37749    --
37750    -- set accounting line type info
37751    --
37752    xla_ae_lines_pkg.SetAcctLineType
37753       (p_component_type             => l_component_type
37754       ,p_event_type_code            => l_event_type_code
37755       ,p_line_definition_owner_code => l_line_definition_owner_code
37756       ,p_line_definition_code       => l_line_definition_code
37757       ,p_accounting_line_code       => l_component_code
37758       ,p_accounting_line_type_code  => l_component_type_code
37759       ,p_accounting_line_appl_id    => l_component_appl_id
37760       ,p_amb_context_code           => l_amb_context_code
37761       ,p_entity_code                => l_entity_code
37762       ,p_event_class_code           => l_event_class_code);
37763    --
37764    -- set accounting class
37765    --
37766    xla_ae_lines_pkg.SetAcctClass(
37767            p_accounting_class_code  => 'RECEIVABLE'
37768          , p_ae_header_id           => l_ae_header_id
37769          );
37770 
37771    --
37772    -- set rounding class
37773    --
37774    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
37775                       'RECEIVABLE';
37776 
37777    --
37778    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
37779    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
37780    --
37781    -- bulk performance
37782    --
37783    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
37784 
37785    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
37786       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
37787 
37788    -- 4955764
37789    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
37790       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
37791 
37792    -- 4458381 Public Sector Enh
37793    
37794    --
37795    -- set accounting attributes for the line type
37796    --
37797    l_entered_amt_idx := 8;
37798    l_accted_amt_idx  := 10;
37799    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
37800    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
37801    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
37802    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
37803    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
37804    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
37805    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
37806    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
37807    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
37808    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
37809    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
37810    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
37811    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
37812    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
37813    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
37814    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
37815    l_rec_acct_attrs.array_num_value(8)  := p_source_17;
37816    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
37817    l_rec_acct_attrs.array_char_value(9)  := p_source_18;
37818    l_rec_acct_attrs.array_acct_attr_code(10) := 'LEDGER_AMOUNT';
37819    l_rec_acct_attrs.array_num_value(10)  := p_source_22;
37820    l_rec_acct_attrs.array_acct_attr_code(11) := 'PARTY_TYPE';
37821    l_rec_acct_attrs.array_char_value(11)  := p_source_64;
37822 
37823    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
37824    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
37825 
37826    ---------------------------------------------------------------------------------------------------------------
37827    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
37828    ---------------------------------------------------------------------------------------------------------------
37829    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
37830 
37831    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
37832    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
37833 
37834    IF xla_accounting_cache_pkg.GetValueChar
37835          (p_source_code         => 'LEDGER_CATEGORY_CODE'
37836          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
37837    AND l_bflow_method_code = 'PRIOR_ENTRY'
37838 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
37839    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
37840          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
37841        )
37842    THEN
37843          xla_ae_lines_pkg.BflowUpgEntry
37844            (p_business_method_code    => l_bflow_method_code
37845            ,p_business_class_code     => l_bflow_class_code
37846            ,p_balance_type            => l_balance_type_code);
37847    ELSE
37848       NULL;
37849 XLA_AE_LINES_PKG.business_flow_validation(
37850                                 p_business_method_code     => l_bflow_method_code
37851                                ,p_business_class_code      => l_bflow_class_code
37852                                ,p_inherit_description_flag => l_inherit_desc_flag);
37853    END IF;
37854 
37855    --
37856    -- call analytical criteria
37857    --
37858    -- Inherited Analytical Criteria for business flow method of Prior Entry.
37859    --
37860    -- call description
37861    --
37862    -- No description or it is inherited.
37863    --
37864    -- call ADRs
37865    -- Bug 4922099
37866    --
37867    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
37868         (NVL(l_actual_upg_option, 'N') = 'O') OR
37869         (NVL(l_enc_upg_option, 'N') = 'O')
37870       )
37871    THEN
37872    NULL;
37873    --
37874    --
37875    
37876    --
37877    --
37878    END IF;
37879    --
37880    -- Bug 4922099
37881    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
37882           (NVL(l_enc_upg_option, 'N') = 'O')
37883         ) AND
37884         (l_bflow_method_code = 'PRIOR_ENTRY')
37885       )
37886    THEN
37887       IF
37888       --
37889       1 = 1
37890       --
37891       THEN
37892       xla_accounting_err_pkg.build_message
37893                                     (p_appli_s_name            => 'XLA'
37894                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
37895                                     ,p_token_1                 => 'LINE_NUMBER'
37896                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
37897                                     ,p_token_2                 => 'LINE_TYPE_NAME'
37898                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
37899                                                                              l_component_type
37900                                                                             ,l_component_code
37901                                                                             ,l_component_type_code
37902                                                                             ,l_component_appl_id
37903                                                                             ,l_amb_context_code
37904                                                                             ,l_entity_code
37905                                                                             ,l_event_class_code
37906                                                                            )
37907                                     ,p_token_3                 => 'OWNER'
37908                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
37909                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
37910                                                                           ,p_lookup_code    => l_component_type_code
37911                                                                          )
37912                                     ,p_token_4                 => 'PRODUCT_NAME'
37913                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
37914                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
37915                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
37916                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
37917                                     ,p_ae_header_id            =>  NULL
37918                                        );
37919 
37920         IF (C_LEVEL_ERROR>= g_log_level) THEN
37921                  trace
37922                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
37923                       ,p_level    => C_LEVEL_ERROR
37924                       ,p_module   => l_log_module);
37925         END IF;
37926       END IF;
37927    END IF;
37928    --
37929    --
37930    ------------------------------------------------------------------------------------------------
37931    -- 4219869 Business Flow
37932    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
37933    -- Prior Entry.  Currently, the following code is always generated.
37934    ------------------------------------------------------------------------------------------------
37935    -- No ValidateCurrentLine for business flow method of Prior Entry
37936 
37937    ------------------------------------------------------------------------------------
37938    -- 4219869 Business Flow
37939    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
37940    ------------------------------------------------------------------------------------
37941    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
37942 
37943    ----------------------------------------------------------------------------------
37944    -- 4219869 Business Flow
37945    -- Update journal entry status -- Need to generate this within IF <condition>
37946    ----------------------------------------------------------------------------------
37947    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
37948          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
37949          ,p_balance_type_code => l_balance_type_code
37950          );
37951 
37952    -------------------------------------------------------------------------------------------
37953    -- 4262811 - Generate the Accrual Reversal lines
37954    -------------------------------------------------------------------------------------------
37955    BEGIN
37956       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
37957                               (g_array_event(p_event_id).array_value_num('header_index'));
37958       IF l_acc_rev_flag IS NULL THEN
37959          l_acc_rev_flag := 'N';
37960       END IF;
37961    EXCEPTION
37962       WHEN OTHERS THEN
37963          l_acc_rev_flag := 'N';
37964    END;
37965    --
37966    IF (l_acc_rev_flag = 'Y') THEN
37967 
37968        -- 4645092  ------------------------------------------------------------------------------
37969        -- To allow MPA report to determine if it should generate report process
37970        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
37971        ------------------------------------------------------------------------------------------
37972 
37973        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
37974        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
37975    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
37976    -- call ADRs
37977    -- Bug 4922099
37978    --
37979    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
37980         (NVL(l_actual_upg_option, 'N') = 'O') OR
37981         (NVL(l_enc_upg_option, 'N') = 'O')
37982       )
37983    THEN
37984    NULL;
37985    --
37986    --
37987    
37988    --
37989    --
37990    END IF;
37991 
37992        --
37993        -- Update the line information that should be overwritten
37994        --
37995        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
37996                                          p_header_num   => 1);
37997        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
37998 
37999        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
38000 
38001        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
38002           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
38003        END IF;
38004 
38005       --
38006       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
38007       --
38008       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
38009           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
38010       ELSE
38011           ---------------------------------------------------------------------------------------------------
38012           -- 4262811a Switch Sign
38013           ---------------------------------------------------------------------------------------------------
38014           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
38015           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
38016                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
38017           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
38018                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
38019           -- 5132302
38020           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
38021                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
38022 
38023       END IF;
38024 
38025       -- 4955764
38026       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
38027       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
38028 
38029 
38030       XLA_AE_LINES_PKG.ValidateCurrentLine;
38031       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
38032 
38033       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
38034                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
38035                ,p_balance_type_code => l_balance_type_code);
38036 
38037    END IF;
38038 
38039    -----------------------------------------------------------------------------------------
38040    -- 4262811 Multiperiod Accounting
38041    -----------------------------------------------------------------------------------------
38042      -- No MPA option is assigned.
38043 
38044 
38045 END IF;
38046 END IF;
38047 --
38048 
38049 --
38050 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
38051    trace
38052       (p_msg      => 'END of AcctLineType_77'
38053       ,p_level    => C_LEVEL_PROCEDURE
38054       ,p_module   => l_log_module);
38055 END IF;
38056 --
38057 EXCEPTION
38058   WHEN xla_exceptions_pkg.application_exception THEN
38059       RAISE;
38060   WHEN OTHERS THEN
38061        xla_exceptions_pkg.raise_message
38062            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_77');
38063 END AcctLineType_77;
38064 --
38065 
38066 ---------------------------------------
38067 --
38068 -- PRIVATE FUNCTION
38069 --         AcctLineType_78
38070 --
38071 ---------------------------------------
38072 PROCEDURE AcctLineType_78 (
38073   p_application_id        IN NUMBER
38074  ,p_event_id              IN NUMBER
38075  ,p_calculate_acctd_flag  IN VARCHAR2
38076  ,p_calculate_g_l_flag    IN VARCHAR2
38077  ,p_actual_flag           IN OUT VARCHAR2
38078  ,p_balance_type_code     OUT VARCHAR2
38079  ,p_gain_or_loss_ref      OUT VARCHAR2
38080  
38081 --Transaction Distribution GL Account
38082  , p_source_4            IN NUMBER
38083 --Remittance Bank Account Remittance Account
38084  , p_source_8            IN NUMBER
38085 --Distribution Source Type
38086  , p_source_13            IN VARCHAR2
38087 --Distribution Line Identifier
38088  , p_source_15            IN NUMBER
38089 --Distribution Type
38090  , p_source_16            IN VARCHAR2
38091 --Exchange Date
38092  , p_source_19            IN DATE
38093 --Exchange Rate
38094  , p_source_20            IN NUMBER
38095 --Exchange Rate Type
38096  , p_source_21            IN VARCHAR2
38097 --Transaction Distribution Identifier
38098  , p_source_27            IN NUMBER
38099 --Transaction Distribution Type
38100  , p_source_28            IN VARCHAR2
38101 --Distribution Multi Fund Additional Entry
38102  , p_source_52            IN VARCHAR2
38103 --Receipt Applied To Application Identifier
38104  , p_source_56            IN NUMBER
38105 --Transaction Entity Code
38106  , p_source_57            IN VARCHAR2
38107 --Transaction Identifier
38108  , p_source_58            IN NUMBER
38109 --DIST_ENT_AMT_FROM
38110  , p_source_59            IN NUMBER
38111 --Applying Document Currency Code
38112  , p_source_60            IN VARCHAR2
38113 --Accounting Amount
38114  , p_source_61            IN NUMBER
38115 --Distribution Party Identifier
38116  , p_source_62            IN NUMBER
38117 --Distribution Party Site Id
38118  , p_source_63            IN NUMBER
38119 --Distribution Party Type
38120  , p_source_64            IN VARCHAR2
38121 )
38122 IS
38123 
38124 l_component_type              VARCHAR2(80);
38125 l_component_code              VARCHAR2(30);
38126 l_component_type_code         VARCHAR2(1);
38127 l_component_appl_id           INTEGER;
38128 l_amb_context_code            VARCHAR2(30);
38129 l_entity_code                 VARCHAR2(30);
38130 l_event_class_code            VARCHAR2(30);
38131 l_ae_header_id                NUMBER;
38132 l_event_type_code             VARCHAR2(30);
38133 l_line_definition_code        VARCHAR2(30);
38134 l_line_definition_owner_code  VARCHAR2(1);
38135 --
38136 -- adr variables
38137 l_segment                     VARCHAR2(30);
38138 l_ccid                        NUMBER;
38142 l_adr_flex_value_set_id       NUMBER;
38139 l_adr_transaction_coa_id      NUMBER;
38140 l_adr_accounting_coa_id       NUMBER;
38141 l_adr_flexfield_segment_code  VARCHAR2(30);
38143 l_adr_value_type_code         VARCHAR2(30);
38144 l_adr_value_combination_id    NUMBER;
38145 l_adr_value_segment_code      VARCHAR2(30);
38146 
38147 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
38148 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
38149 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
38150 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
38151 
38152 -- 4262811 Variables ------------------------------------------------------------------------------------------
38153 l_entered_amt_idx             NUMBER;
38154 l_accted_amt_idx              NUMBER;
38155 l_acc_rev_flag                VARCHAR2(1);
38156 l_accrual_line_num            NUMBER;
38157 l_tmp_amt                     NUMBER;
38158 l_acc_rev_natural_side_code   VARCHAR2(1);
38159 
38160 l_num_entries                 NUMBER;
38161 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
38162 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
38163 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
38164 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
38165 l_recog_line_1                NUMBER;
38166 l_recog_line_2                NUMBER;
38167 
38168 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
38169 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
38170 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
38171 
38172 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
38173 
38174 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
38175 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
38176 
38177 ---------------------------------------------------------------------------------------------------------------
38178 
38179 
38180 --
38181 -- bulk performance
38182 --
38183 l_balance_type_code           VARCHAR2(1);
38184 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
38185 l_log_module                  VARCHAR2(240);
38186 
38187 --
38188 -- Upgrade strategy
38189 --
38190 l_actual_upg_option           VARCHAR2(1);
38191 l_enc_upg_option           VARCHAR2(1);
38192 
38193 --
38194 BEGIN
38195 --
38196 IF g_log_enabled THEN
38197       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_78';
38198 END IF;
38199 --
38200 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
38201 
38202       trace
38203          (p_msg      => 'BEGIN of AcctLineType_78'
38204          ,p_level    => C_LEVEL_PROCEDURE
38205          ,p_module   => l_log_module);
38206 
38207 END IF;
38208 --
38209 l_component_type             := 'AMB_JLT';
38210 l_component_code             := 'RCT_APP_MFAR_TRX_REMITTANCE';
38211 l_component_type_code        := 'S';
38212 l_component_appl_id          :=  222;
38213 l_amb_context_code           := 'DEFAULT';
38214 l_entity_code                := 'RECEIPTS';
38215 l_event_class_code           := 'RECEIPT';
38216 l_event_type_code            := 'RECEIPT_ALL';
38217 l_line_definition_owner_code := 'S';
38218 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
38219 --
38220 l_balance_type_code          := 'A';
38221 l_segment                     := NULL;
38222 l_ccid                        := NULL;
38223 l_adr_transaction_coa_id      := NULL;
38224 l_adr_accounting_coa_id       := NULL;
38225 l_adr_flexfield_segment_code  := NULL;
38226 l_adr_flex_value_set_id       := NULL;
38227 l_adr_value_type_code         := NULL;
38228 l_adr_value_combination_id    := NULL;
38229 l_adr_value_segment_code      := NULL;
38230 
38231 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
38232 l_bflow_class_code           := '';    -- 4219869 Business Flow
38233 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
38234 l_budgetary_control_flag     := 'N';
38235 
38236 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
38237 l_bflow_applied_to_amt       := NULL; -- 5132302
38238 l_entered_amt_idx            := NULL;          -- 4262811
38239 l_accted_amt_idx             := NULL;          -- 4262811
38240 l_acc_rev_flag               := NULL;          -- 4262811
38241 l_accrual_line_num           := NULL;          -- 4262811
38242 l_tmp_amt                    := NULL;          -- 4262811
38243 --
38244  
38245 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
38246     l_balance_type_code <> 'B' THEN
38247 IF NVL(p_source_13,'
38248 ') =  'REMITTANCE' AND 
38249 NVL(p_source_52,'
38250 ') =  'Y'
38251  THEN 
38252 
38253    --
38254    XLA_AE_LINES_PKG.SetNewLine;
38255 
38256    p_balance_type_code          := l_balance_type_code;
38257    -- set the flag so later we will know whether the gain loss line needs to be created
38258    
38259    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
38260      p_actual_flag :='A';
38261    END IF;
38262 
38263    --
38264    -- bulk performance
38265    --
38266    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
38267                                       p_header_num   => 0); -- 4262811
38268    --
38269    -- set accounting line options
38270    --
38271    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
38272            p_natural_side_code          => 'C'
38273          , p_gain_or_loss_flag          => 'N'
38274          , p_gl_transfer_mode_code      => 'S'
38275          , p_acct_entry_type_code       => 'A'
38276          , p_switch_side_flag           => 'Y'
38277          , p_merge_duplicate_code       => 'A'
38278          );
38279    --
38280    l_acc_rev_natural_side_code := 'D';  -- 4262811
38281    -- 
38282    --
38283    -- set accounting line type info
38284    --
38285    xla_ae_lines_pkg.SetAcctLineType
38286       (p_component_type             => l_component_type
38287       ,p_event_type_code            => l_event_type_code
38288       ,p_line_definition_owner_code => l_line_definition_owner_code
38289       ,p_line_definition_code       => l_line_definition_code
38290       ,p_accounting_line_code       => l_component_code
38291       ,p_accounting_line_type_code  => l_component_type_code
38292       ,p_accounting_line_appl_id    => l_component_appl_id
38293       ,p_amb_context_code           => l_amb_context_code
38294       ,p_entity_code                => l_entity_code
38295       ,p_event_class_code           => l_event_class_code);
38296    --
38297    -- set accounting class
38298    --
38299    xla_ae_lines_pkg.SetAcctClass(
38300            p_accounting_class_code  => 'REMITTANCE'
38301          , p_ae_header_id           => l_ae_header_id
38302          );
38303 
38304    --
38305    -- set rounding class
38306    --
38307    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
38308                       'RECEIVABLE';
38309 
38310    --
38311    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
38312    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
38313    --
38314    -- bulk performance
38315    --
38316    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
38317 
38318    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
38319       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
38320 
38321    -- 4955764
38322    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
38323       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
38324 
38325    -- 4458381 Public Sector Enh
38326    
38327    --
38328    -- set accounting attributes for the line type
38329    --
38330    l_entered_amt_idx := 8;
38331    l_accted_amt_idx  := 13;
38332    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
38333    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
38334    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
38335    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
38336    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
38337    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
38338    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
38339    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
38340    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
38341    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
38342    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
38343    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
38344    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
38345    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
38346    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
38347    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
38348    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
38349    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
38350    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
38351    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
38352    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
38353    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
38354    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
38355    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
38356    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
38357    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
38358    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
38359    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
38360    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
38361    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
38362    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
38363    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
38364    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
38365 
38366    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
38367    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
38368 
38369    ---------------------------------------------------------------------------------------------------------------
38370    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
38371    ---------------------------------------------------------------------------------------------------------------
38372    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
38373 
38374    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
38375    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
38376 
38377    IF xla_accounting_cache_pkg.GetValueChar
38378          (p_source_code         => 'LEDGER_CATEGORY_CODE'
38379          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
38380    AND l_bflow_method_code = 'PRIOR_ENTRY'
38384        )
38381 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
38382    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
38383          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
38385    THEN
38386          xla_ae_lines_pkg.BflowUpgEntry
38387            (p_business_method_code    => l_bflow_method_code
38388            ,p_business_class_code     => l_bflow_class_code
38389            ,p_balance_type            => l_balance_type_code);
38390    ELSE
38391       NULL;
38392 -- No business flow processing for business flow method of NONE.
38393    END IF;
38394 
38395    --
38396    -- call analytical criteria
38397    --
38398    
38399    --
38400    -- call description
38401    --
38402    
38403 xla_ae_lines_pkg.SetLineDescription(
38404    p_ae_header_id => l_ae_header_id
38405   ,p_description  => Description_1 (
38406      p_application_id         => p_application_id
38407    , p_ae_header_id           => l_ae_header_id 
38408    )
38409 );
38410 
38411 
38412    --
38413    -- call ADRs
38414    -- Bug 4922099
38415    --
38416    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
38417         (NVL(l_actual_upg_option, 'N') = 'O') OR
38418         (NVL(l_enc_upg_option, 'N') = 'O')
38419       )
38420    THEN
38421    NULL;
38422    --
38423    --
38424    
38425   l_ccid := AcctDerRule_11(
38426            p_application_id           => p_application_id
38427          , p_ae_header_id             => l_ae_header_id 
38428 , p_source_8 => p_source_8
38429          , x_transaction_coa_id       => l_adr_transaction_coa_id
38430          , x_accounting_coa_id        => l_adr_accounting_coa_id
38431          , x_value_type_code          => l_adr_value_type_code
38432          , p_side                     => 'NA'
38433    );
38434 
38435    xla_ae_lines_pkg.set_ccid(
38436     p_code_combination_id          => l_ccid
38437   , p_value_type_code              => l_adr_value_type_code
38438   , p_transaction_coa_id           => l_adr_transaction_coa_id
38439   , p_accounting_coa_id            => l_adr_accounting_coa_id
38440   , p_adr_code                     => 'MFAR_RCT_DEF_REMITTANCE_CCID'
38441   , p_adr_type_code                => 'S'
38442   , p_component_type               => l_component_type
38443   , p_component_code               => l_component_code
38444   , p_component_type_code          => l_component_type_code
38445   , p_component_appl_id            => l_component_appl_id
38446   , p_amb_context_code             => l_amb_context_code
38447   , p_side                         => 'NA'
38448   );
38449 
38450 
38451    l_segment := AcctDerRule_5(
38452            p_application_id           => p_application_id
38453          , p_ae_header_id             => l_ae_header_id 
38454 , p_source_4 => p_source_4
38455          , x_transaction_coa_id       => l_adr_transaction_coa_id
38456          , x_accounting_coa_id        => l_adr_accounting_coa_id
38457          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
38458          , x_flex_value_set_id        => l_adr_flex_value_set_id
38459          , x_value_type_code          => l_adr_value_type_code
38460          , x_value_combination_id     => l_adr_value_combination_id
38461          , x_value_segment_code       => l_adr_value_segment_code
38462          , p_side                     => 'NA'
38463          , p_override_seg_flag        => 'Y'
38464    );
38465 
38466    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
38467 
38468       xla_ae_lines_pkg.set_segment(
38469           p_to_segment_code         => 'GL_BALANCING'
38470         , p_segment_value           => l_segment
38471         , p_from_segment_code       => l_adr_value_segment_code
38472         , p_from_combination_id     => l_adr_value_combination_id
38473         , p_value_type_code         => l_adr_value_type_code
38474         , p_transaction_coa_id      => l_adr_transaction_coa_id
38475         , p_accounting_coa_id       => l_adr_accounting_coa_id
38476         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
38477         , p_flex_value_set_id       => l_adr_flex_value_set_id
38478         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
38479         , p_adr_type_code           => 'S'
38480         , p_component_type          => l_component_type
38481         , p_component_code          => l_component_code
38482         , p_component_type_code     => l_component_type_code
38483         , p_component_appl_id       => l_component_appl_id
38484         , p_amb_context_code        => l_amb_context_code
38485         , p_entity_code             => 'RECEIPTS'
38486         , p_event_class_code        => 'RECEIPT'
38487         , p_side                    => 'NA'
38488         );
38489 
38490   END IF;
38491 
38492    --
38493    --
38494    END IF;
38495    --
38496    -- Bug 4922099
38497    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
38498           (NVL(l_enc_upg_option, 'N') = 'O')
38499         ) AND
38500         (l_bflow_method_code = 'PRIOR_ENTRY')
38501       )
38502    THEN
38503       IF
38504       --
38505       1 = 2
38506       --
38507       THEN
38508       xla_accounting_err_pkg.build_message
38509                                     (p_appli_s_name            => 'XLA'
38510                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
38511                                     ,p_token_1                 => 'LINE_NUMBER'
38512                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
38513                                     ,p_token_2                 => 'LINE_TYPE_NAME'
38514                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
38518                                                                             ,l_component_appl_id
38515                                                                              l_component_type
38516                                                                             ,l_component_code
38517                                                                             ,l_component_type_code
38519                                                                             ,l_amb_context_code
38520                                                                             ,l_entity_code
38521                                                                             ,l_event_class_code
38522                                                                            )
38523                                     ,p_token_3                 => 'OWNER'
38524                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
38525                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
38526                                                                           ,p_lookup_code    => l_component_type_code
38527                                                                          )
38528                                     ,p_token_4                 => 'PRODUCT_NAME'
38529                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
38530                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
38531                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
38532                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
38533                                     ,p_ae_header_id            =>  NULL
38534                                        );
38535 
38536         IF (C_LEVEL_ERROR>= g_log_level) THEN
38537                  trace
38538                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
38539                       ,p_level    => C_LEVEL_ERROR
38540                       ,p_module   => l_log_module);
38541         END IF;
38542       END IF;
38543    END IF;
38544    --
38545    --
38546    ------------------------------------------------------------------------------------------------
38547    -- 4219869 Business Flow
38548    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
38549    -- Prior Entry.  Currently, the following code is always generated.
38550    ------------------------------------------------------------------------------------------------
38551    XLA_AE_LINES_PKG.ValidateCurrentLine;
38552 
38553    ------------------------------------------------------------------------------------
38554    -- 4219869 Business Flow
38555    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
38556    ------------------------------------------------------------------------------------
38557    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
38558 
38559    ----------------------------------------------------------------------------------
38560    -- 4219869 Business Flow
38561    -- Update journal entry status -- Need to generate this within IF <condition>
38562    ----------------------------------------------------------------------------------
38563    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
38564          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
38565          ,p_balance_type_code => l_balance_type_code
38566          );
38567 
38568    -------------------------------------------------------------------------------------------
38569    -- 4262811 - Generate the Accrual Reversal lines
38570    -------------------------------------------------------------------------------------------
38571    BEGIN
38572       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
38573                               (g_array_event(p_event_id).array_value_num('header_index'));
38574       IF l_acc_rev_flag IS NULL THEN
38575          l_acc_rev_flag := 'N';
38576       END IF;
38577    EXCEPTION
38578       WHEN OTHERS THEN
38579          l_acc_rev_flag := 'N';
38580    END;
38581    --
38582    IF (l_acc_rev_flag = 'Y') THEN
38583 
38584        -- 4645092  ------------------------------------------------------------------------------
38585        -- To allow MPA report to determine if it should generate report process
38589        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
38586        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
38587        ------------------------------------------------------------------------------------------
38588 
38590        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
38591    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
38592    -- call ADRs
38593    -- Bug 4922099
38594    --
38595    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
38596         (NVL(l_actual_upg_option, 'N') = 'O') OR
38597         (NVL(l_enc_upg_option, 'N') = 'O')
38598       )
38599    THEN
38600    NULL;
38601    --
38602    --
38603    
38604   l_ccid := AcctDerRule_11(
38605            p_application_id           => p_application_id
38606          , p_ae_header_id             => l_ae_header_id 
38607 , p_source_8 => p_source_8
38608          , x_transaction_coa_id       => l_adr_transaction_coa_id
38609          , x_accounting_coa_id        => l_adr_accounting_coa_id
38610          , x_value_type_code          => l_adr_value_type_code
38611          , p_side                     => 'NA'
38612    );
38613 
38614    xla_ae_lines_pkg.set_ccid(
38615     p_code_combination_id          => l_ccid
38616   , p_value_type_code              => l_adr_value_type_code
38617   , p_transaction_coa_id           => l_adr_transaction_coa_id
38618   , p_accounting_coa_id            => l_adr_accounting_coa_id
38619   , p_adr_code                     => 'MFAR_RCT_DEF_REMITTANCE_CCID'
38620   , p_adr_type_code                => 'S'
38621   , p_component_type               => l_component_type
38622   , p_component_code               => l_component_code
38623   , p_component_type_code          => l_component_type_code
38624   , p_component_appl_id            => l_component_appl_id
38625   , p_amb_context_code             => l_amb_context_code
38626   , p_side                         => 'NA'
38627   );
38628 
38629 
38630    l_segment := AcctDerRule_5(
38631            p_application_id           => p_application_id
38632          , p_ae_header_id             => l_ae_header_id 
38633 , p_source_4 => p_source_4
38634          , x_transaction_coa_id       => l_adr_transaction_coa_id
38635          , x_accounting_coa_id        => l_adr_accounting_coa_id
38636          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
38637          , x_flex_value_set_id        => l_adr_flex_value_set_id
38638          , x_value_type_code          => l_adr_value_type_code
38639          , x_value_combination_id     => l_adr_value_combination_id
38640          , x_value_segment_code       => l_adr_value_segment_code
38641          , p_side                     => 'NA'
38642          , p_override_seg_flag        => 'Y'
38643    );
38644 
38645    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
38646 
38647       xla_ae_lines_pkg.set_segment(
38648           p_to_segment_code         => 'GL_BALANCING'
38649         , p_segment_value           => l_segment
38650         , p_from_segment_code       => l_adr_value_segment_code
38651         , p_from_combination_id     => l_adr_value_combination_id
38652         , p_value_type_code         => l_adr_value_type_code
38653         , p_transaction_coa_id      => l_adr_transaction_coa_id
38654         , p_accounting_coa_id       => l_adr_accounting_coa_id
38655         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
38656         , p_flex_value_set_id       => l_adr_flex_value_set_id
38657         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
38658         , p_adr_type_code           => 'S'
38659         , p_component_type          => l_component_type
38660         , p_component_code          => l_component_code
38661         , p_component_type_code     => l_component_type_code
38662         , p_component_appl_id       => l_component_appl_id
38663         , p_amb_context_code        => l_amb_context_code
38664         , p_entity_code             => 'RECEIPTS'
38665         , p_event_class_code        => 'RECEIPT'
38666         , p_side                    => 'NA'
38667         );
38668 
38669   END IF;
38670 
38671    --
38672    --
38673    END IF;
38674 
38675        --
38676        -- Update the line information that should be overwritten
38677        --
38678        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
38679                                          p_header_num   => 1);
38680        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
38681 
38682        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
38683 
38684        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
38685           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
38686        END IF;
38687 
38688       --
38689       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
38690       --
38691       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
38692           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
38693       ELSE
38694           ---------------------------------------------------------------------------------------------------
38695           -- 4262811a Switch Sign
38696           ---------------------------------------------------------------------------------------------------
38697           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
38698           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
38699                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
38700           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
38701                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
38702           -- 5132302
38703           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
38704                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
38705 
38706       END IF;
38707 
38708       -- 4955764
38709       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
38710       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
38711 
38712 
38713       XLA_AE_LINES_PKG.ValidateCurrentLine;
38714       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
38715 
38716       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
38717                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
38718                ,p_balance_type_code => l_balance_type_code);
38719 
38720    END IF;
38721 
38722    -----------------------------------------------------------------------------------------
38723    -- 4262811 Multiperiod Accounting
38724    -----------------------------------------------------------------------------------------
38725      -- No MPA option is assigned.
38726 
38727 
38728 END IF;
38729 END IF;
38730 --
38731 
38732 --
38733 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
38734    trace
38735       (p_msg      => 'END of AcctLineType_78'
38736       ,p_level    => C_LEVEL_PROCEDURE
38737       ,p_module   => l_log_module);
38738 END IF;
38739 --
38740 EXCEPTION
38741   WHEN xla_exceptions_pkg.application_exception THEN
38742       RAISE;
38743   WHEN OTHERS THEN
38744        xla_exceptions_pkg.raise_message
38745            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_78');
38746 END AcctLineType_78;
38747 --
38748 
38749 ---------------------------------------
38750 --
38751 -- PRIVATE FUNCTION
38752 --         AcctLineType_79
38753 --
38754 ---------------------------------------
38755 PROCEDURE AcctLineType_79 (
38756   p_application_id        IN NUMBER
38757  ,p_event_id              IN NUMBER
38758  ,p_calculate_acctd_flag  IN VARCHAR2
38759  ,p_calculate_g_l_flag    IN VARCHAR2
38760  ,p_actual_flag           IN OUT VARCHAR2
38761  ,p_balance_type_code     OUT VARCHAR2
38762  ,p_gain_or_loss_ref      OUT VARCHAR2
38763  
38764 --Distribution GL Account
38765  , p_source_3            IN NUMBER
38766 --Distribution Source Type
38767  , p_source_13            IN VARCHAR2
38768 --Distribution Line Identifier
38769  , p_source_15            IN NUMBER
38770 --Distribution Type
38771  , p_source_16            IN VARCHAR2
38772 --Exchange Date
38773  , p_source_19            IN DATE
38774 --Exchange Rate
38775  , p_source_20            IN NUMBER
38776 --Exchange Rate Type
38777  , p_source_21            IN VARCHAR2
38778 --Transaction Distribution Identifier
38779  , p_source_27            IN NUMBER
38780 --Transaction Distribution Type
38781  , p_source_28            IN VARCHAR2
38782 --Distribution Multi Fund Additional Entry
38783  , p_source_52            IN VARCHAR2
38784 --Receipt Applied To Application Identifier
38785  , p_source_56            IN NUMBER
38786 --Transaction Entity Code
38787  , p_source_57            IN VARCHAR2
38788 --Transaction Identifier
38789  , p_source_58            IN NUMBER
38790 --DIST_ENT_AMT_FROM
38791  , p_source_59            IN NUMBER
38792 --Applying Document Currency Code
38793  , p_source_60            IN VARCHAR2
38794 --Accounting Amount
38795  , p_source_61            IN NUMBER
38796 --Distribution Party Identifier
38797  , p_source_62            IN NUMBER
38798 --Distribution Party Site Id
38799  , p_source_63            IN NUMBER
38800 --Distribution Party Type
38801  , p_source_64            IN VARCHAR2
38802 )
38803 IS
38804 
38805 l_component_type              VARCHAR2(80);
38806 l_component_code              VARCHAR2(30);
38807 l_component_type_code         VARCHAR2(1);
38808 l_component_appl_id           INTEGER;
38809 l_amb_context_code            VARCHAR2(30);
38810 l_entity_code                 VARCHAR2(30);
38811 l_event_class_code            VARCHAR2(30);
38812 l_ae_header_id                NUMBER;
38813 l_event_type_code             VARCHAR2(30);
38814 l_line_definition_code        VARCHAR2(30);
38815 l_line_definition_owner_code  VARCHAR2(1);
38816 --
38817 -- adr variables
38818 l_segment                     VARCHAR2(30);
38819 l_ccid                        NUMBER;
38820 l_adr_transaction_coa_id      NUMBER;
38821 l_adr_accounting_coa_id       NUMBER;
38822 l_adr_flexfield_segment_code  VARCHAR2(30);
38823 l_adr_flex_value_set_id       NUMBER;
38824 l_adr_value_type_code         VARCHAR2(30);
38825 l_adr_value_combination_id    NUMBER;
38826 l_adr_value_segment_code      VARCHAR2(30);
38827 
38828 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
38829 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
38830 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
38831 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
38832 
38833 -- 4262811 Variables ------------------------------------------------------------------------------------------
38834 l_entered_amt_idx             NUMBER;
38835 l_accted_amt_idx              NUMBER;
38836 l_acc_rev_flag                VARCHAR2(1);
38837 l_accrual_line_num            NUMBER;
38838 l_tmp_amt                     NUMBER;
38839 l_acc_rev_natural_side_code   VARCHAR2(1);
38840 
38841 l_num_entries                 NUMBER;
38842 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
38843 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
38844 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
38845 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
38846 l_recog_line_1                NUMBER;
38847 l_recog_line_2                NUMBER;
38848 
38849 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
38850 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
38851 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
38852 
38853 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
38854 
38855 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
38856 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
38857 
38858 ---------------------------------------------------------------------------------------------------------------
38859 
38860 
38861 --
38862 -- bulk performance
38863 --
38864 l_balance_type_code           VARCHAR2(1);
38865 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
38866 l_log_module                  VARCHAR2(240);
38867 
38868 --
38869 -- Upgrade strategy
38870 --
38871 l_actual_upg_option           VARCHAR2(1);
38872 l_enc_upg_option           VARCHAR2(1);
38873 
38874 --
38875 BEGIN
38876 --
38877 IF g_log_enabled THEN
38878       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_79';
38879 END IF;
38880 --
38881 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
38882 
38883       trace
38884          (p_msg      => 'BEGIN of AcctLineType_79'
38885          ,p_level    => C_LEVEL_PROCEDURE
38886          ,p_module   => l_log_module);
38887 
38888 END IF;
38889 --
38890 l_component_type             := 'AMB_JLT';
38891 l_component_code             := 'RCT_BNK_CHG';
38892 l_component_type_code        := 'S';
38893 l_component_appl_id          :=  222;
38894 l_amb_context_code           := 'DEFAULT';
38895 l_entity_code                := 'RECEIPTS';
38896 l_event_class_code           := 'RECEIPT';
38897 l_event_type_code            := 'RECEIPT_ALL';
38898 l_line_definition_owner_code := 'S';
38899 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
38900 --
38901 l_balance_type_code          := 'A';
38902 l_segment                     := NULL;
38903 l_ccid                        := NULL;
38904 l_adr_transaction_coa_id      := NULL;
38905 l_adr_accounting_coa_id       := NULL;
38906 l_adr_flexfield_segment_code  := NULL;
38907 l_adr_flex_value_set_id       := NULL;
38908 l_adr_value_type_code         := NULL;
38909 l_adr_value_combination_id    := NULL;
38910 l_adr_value_segment_code      := NULL;
38911 
38912 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
38913 l_bflow_class_code           := '';    -- 4219869 Business Flow
38914 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
38915 l_budgetary_control_flag     := 'N';
38916 
38917 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
38918 l_bflow_applied_to_amt       := NULL; -- 5132302
38919 l_entered_amt_idx            := NULL;          -- 4262811
38920 l_accted_amt_idx             := NULL;          -- 4262811
38921 l_acc_rev_flag               := NULL;          -- 4262811
38922 l_accrual_line_num           := NULL;          -- 4262811
38923 l_tmp_amt                    := NULL;          -- 4262811
38924 --
38925  
38926 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
38927     l_balance_type_code <> 'B' THEN
38928 IF NVL(p_source_13,'
38929 ') =  'BANK_CHARGES' AND 
38930 NVL(p_source_52,'
38931 ') =  'N'
38932  THEN 
38933 
38934    --
38935    XLA_AE_LINES_PKG.SetNewLine;
38936 
38937    p_balance_type_code          := l_balance_type_code;
38938    -- set the flag so later we will know whether the gain loss line needs to be created
38939    
38940    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
38941      p_actual_flag :='A';
38942    END IF;
38943 
38944    --
38945    -- bulk performance
38946    --
38947    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
38948                                       p_header_num   => 0); -- 4262811
38949    --
38950    -- set accounting line options
38951    --
38952    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
38953            p_natural_side_code          => 'C'
38954          , p_gain_or_loss_flag          => 'N'
38955          , p_gl_transfer_mode_code      => 'S'
38956          , p_acct_entry_type_code       => 'A'
38957          , p_switch_side_flag           => 'Y'
38958          , p_merge_duplicate_code       => 'A'
38959          );
38960    --
38961    l_acc_rev_natural_side_code := 'D';  -- 4262811
38962    -- 
38963    --
38964    -- set accounting line type info
38965    --
38966    xla_ae_lines_pkg.SetAcctLineType
38967       (p_component_type             => l_component_type
38968       ,p_event_type_code            => l_event_type_code
38969       ,p_line_definition_owner_code => l_line_definition_owner_code
38970       ,p_line_definition_code       => l_line_definition_code
38971       ,p_accounting_line_code       => l_component_code
38972       ,p_accounting_line_type_code  => l_component_type_code
38973       ,p_accounting_line_appl_id    => l_component_appl_id
38974       ,p_amb_context_code           => l_amb_context_code
38975       ,p_entity_code                => l_entity_code
38976       ,p_event_class_code           => l_event_class_code);
38977    --
38978    -- set accounting class
38979    --
38980    xla_ae_lines_pkg.SetAcctClass(
38981            p_accounting_class_code  => 'BANK_CHG'
38982          , p_ae_header_id           => l_ae_header_id
38983          );
38984 
38985    --
38986    -- set rounding class
38987    --
38988    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
38989                       'RECEIVABLE';
38990 
38991    --
38992    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
38993    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
38994    --
38995    -- bulk performance
38996    --
38997    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
38998 
38999    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
39000       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
39001 
39002    -- 4955764
39003    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
39004       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
39005 
39006    -- 4458381 Public Sector Enh
39007    
39008    --
39009    -- set accounting attributes for the line type
39010    --
39011    l_entered_amt_idx := 8;
39012    l_accted_amt_idx  := 13;
39013    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
39014    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
39015    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
39016    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
39017    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
39018    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
39019    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
39020    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
39021    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
39022    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
39023    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
39024    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
39025    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
39026    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
39027    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
39028    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
39029    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
39030    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
39031    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
39032    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
39033    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
39034    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
39035    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
39036    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
39037    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
39038    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
39039    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
39040    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
39041    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
39042    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
39043    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
39044    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
39045    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
39046 
39047    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
39048    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
39049 
39050    ---------------------------------------------------------------------------------------------------------------
39051    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
39052    ---------------------------------------------------------------------------------------------------------------
39056    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
39053    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
39054 
39055    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
39057 
39058    IF xla_accounting_cache_pkg.GetValueChar
39059          (p_source_code         => 'LEDGER_CATEGORY_CODE'
39060          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
39061    AND l_bflow_method_code = 'PRIOR_ENTRY'
39062 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
39063    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
39064          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
39065        )
39066    THEN
39067          xla_ae_lines_pkg.BflowUpgEntry
39068            (p_business_method_code    => l_bflow_method_code
39069            ,p_business_class_code     => l_bflow_class_code
39070            ,p_balance_type            => l_balance_type_code);
39071    ELSE
39072       NULL;
39073 -- No business flow processing for business flow method of NONE.
39074    END IF;
39075 
39076    --
39077    -- call analytical criteria
39078    --
39079    
39080    --
39081    -- call description
39082    --
39083    -- No description or it is inherited.
39084    --
39085    -- call ADRs
39086    -- Bug 4922099
39087    --
39088    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
39089         (NVL(l_actual_upg_option, 'N') = 'O') OR
39090         (NVL(l_enc_upg_option, 'N') = 'O')
39091       )
39092    THEN
39093    NULL;
39094    --
39095    --
39096    
39097   l_ccid := AcctDerRule_7(
39098            p_application_id           => p_application_id
39099          , p_ae_header_id             => l_ae_header_id 
39100 , p_source_3 => p_source_3
39101          , x_transaction_coa_id       => l_adr_transaction_coa_id
39102          , x_accounting_coa_id        => l_adr_accounting_coa_id
39103          , x_value_type_code          => l_adr_value_type_code
39104          , p_side                     => 'NA'
39105    );
39106 
39107    xla_ae_lines_pkg.set_ccid(
39108     p_code_combination_id          => l_ccid
39109   , p_value_type_code              => l_adr_value_type_code
39110   , p_transaction_coa_id           => l_adr_transaction_coa_id
39111   , p_accounting_coa_id            => l_adr_accounting_coa_id
39112   , p_adr_code                     => 'DIST_CCID'
39113   , p_adr_type_code                => 'S'
39114   , p_component_type               => l_component_type
39115   , p_component_code               => l_component_code
39116   , p_component_type_code          => l_component_type_code
39117   , p_component_appl_id            => l_component_appl_id
39118   , p_amb_context_code             => l_amb_context_code
39119   , p_side                         => 'NA'
39120   );
39121 
39122 
39123    --
39124    --
39125    END IF;
39126    --
39127    -- Bug 4922099
39128    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
39129           (NVL(l_enc_upg_option, 'N') = 'O')
39130         ) AND
39131         (l_bflow_method_code = 'PRIOR_ENTRY')
39132       )
39133    THEN
39134       IF
39135       --
39136       1 = 2
39137       --
39138       THEN
39139       xla_accounting_err_pkg.build_message
39140                                     (p_appli_s_name            => 'XLA'
39141                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
39142                                     ,p_token_1                 => 'LINE_NUMBER'
39143                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
39144                                     ,p_token_2                 => 'LINE_TYPE_NAME'
39145                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
39146                                                                              l_component_type
39147                                                                             ,l_component_code
39148                                                                             ,l_component_type_code
39149                                                                             ,l_component_appl_id
39150                                                                             ,l_amb_context_code
39151                                                                             ,l_entity_code
39152                                                                             ,l_event_class_code
39153                                                                            )
39154                                     ,p_token_3                 => 'OWNER'
39155                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
39156                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
39157                                                                           ,p_lookup_code    => l_component_type_code
39158                                                                          )
39159                                     ,p_token_4                 => 'PRODUCT_NAME'
39160                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
39161                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
39162                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
39166 
39163                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
39164                                     ,p_ae_header_id            =>  NULL
39165                                        );
39167         IF (C_LEVEL_ERROR>= g_log_level) THEN
39168                  trace
39169                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
39170                       ,p_level    => C_LEVEL_ERROR
39171                       ,p_module   => l_log_module);
39172         END IF;
39173       END IF;
39174    END IF;
39175    --
39176    --
39177    ------------------------------------------------------------------------------------------------
39178    -- 4219869 Business Flow
39179    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
39180    -- Prior Entry.  Currently, the following code is always generated.
39181    ------------------------------------------------------------------------------------------------
39182    XLA_AE_LINES_PKG.ValidateCurrentLine;
39183 
39184    ------------------------------------------------------------------------------------
39185    -- 4219869 Business Flow
39186    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
39187    ------------------------------------------------------------------------------------
39188    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
39189 
39190    ----------------------------------------------------------------------------------
39191    -- 4219869 Business Flow
39192    -- Update journal entry status -- Need to generate this within IF <condition>
39193    ----------------------------------------------------------------------------------
39194    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
39195          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
39196          ,p_balance_type_code => l_balance_type_code
39197          );
39198 
39199    -------------------------------------------------------------------------------------------
39200    -- 4262811 - Generate the Accrual Reversal lines
39201    -------------------------------------------------------------------------------------------
39202    BEGIN
39203       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
39204                               (g_array_event(p_event_id).array_value_num('header_index'));
39205       IF l_acc_rev_flag IS NULL THEN
39206          l_acc_rev_flag := 'N';
39207       END IF;
39208    EXCEPTION
39209       WHEN OTHERS THEN
39210          l_acc_rev_flag := 'N';
39211    END;
39212    --
39213    IF (l_acc_rev_flag = 'Y') THEN
39214 
39215        -- 4645092  ------------------------------------------------------------------------------
39216        -- To allow MPA report to determine if it should generate report process
39217        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
39218        ------------------------------------------------------------------------------------------
39219 
39220        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
39221        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
39222    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
39223    -- call ADRs
39224    -- Bug 4922099
39225    --
39226    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
39227         (NVL(l_actual_upg_option, 'N') = 'O') OR
39228         (NVL(l_enc_upg_option, 'N') = 'O')
39229       )
39230    THEN
39231    NULL;
39232    --
39233    --
39234    
39235   l_ccid := AcctDerRule_7(
39236            p_application_id           => p_application_id
39237          , p_ae_header_id             => l_ae_header_id 
39238 , p_source_3 => p_source_3
39239          , x_transaction_coa_id       => l_adr_transaction_coa_id
39240          , x_accounting_coa_id        => l_adr_accounting_coa_id
39241          , x_value_type_code          => l_adr_value_type_code
39242          , p_side                     => 'NA'
39243    );
39244 
39245    xla_ae_lines_pkg.set_ccid(
39246     p_code_combination_id          => l_ccid
39247   , p_value_type_code              => l_adr_value_type_code
39248   , p_transaction_coa_id           => l_adr_transaction_coa_id
39249   , p_accounting_coa_id            => l_adr_accounting_coa_id
39250   , p_adr_code                     => 'DIST_CCID'
39251   , p_adr_type_code                => 'S'
39252   , p_component_type               => l_component_type
39253   , p_component_code               => l_component_code
39254   , p_component_type_code          => l_component_type_code
39255   , p_component_appl_id            => l_component_appl_id
39256   , p_amb_context_code             => l_amb_context_code
39257   , p_side                         => 'NA'
39258   );
39259 
39260 
39261    --
39262    --
39263    END IF;
39264 
39265        --
39266        -- Update the line information that should be overwritten
39267        --
39268        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
39269                                          p_header_num   => 1);
39270        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
39271 
39272        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
39273 
39274        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
39275           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
39276        END IF;
39277 
39281       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
39278       --
39279       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
39280       --
39282           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
39283       ELSE
39284           ---------------------------------------------------------------------------------------------------
39285           -- 4262811a Switch Sign
39286           ---------------------------------------------------------------------------------------------------
39287           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
39288           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
39289                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
39290           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
39291                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
39292           -- 5132302
39293           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
39294                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
39295 
39296       END IF;
39297 
39298       -- 4955764
39299       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
39300       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
39301 
39302 
39303       XLA_AE_LINES_PKG.ValidateCurrentLine;
39304       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
39305 
39306       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
39307                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
39308                ,p_balance_type_code => l_balance_type_code);
39309 
39310    END IF;
39311 
39312    -----------------------------------------------------------------------------------------
39313    -- 4262811 Multiperiod Accounting
39314    -----------------------------------------------------------------------------------------
39315      -- No MPA option is assigned.
39316 
39317 
39318 END IF;
39319 END IF;
39320 --
39321 
39322 --
39323 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
39324    trace
39325       (p_msg      => 'END of AcctLineType_79'
39326       ,p_level    => C_LEVEL_PROCEDURE
39327       ,p_module   => l_log_module);
39328 END IF;
39329 --
39330 EXCEPTION
39331   WHEN xla_exceptions_pkg.application_exception THEN
39332       RAISE;
39333   WHEN OTHERS THEN
39334        xla_exceptions_pkg.raise_message
39335            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_79');
39336 END AcctLineType_79;
39337 --
39338 
39339 ---------------------------------------
39340 --
39341 -- PRIVATE FUNCTION
39342 --         AcctLineType_80
39343 --
39344 ---------------------------------------
39345 PROCEDURE AcctLineType_80 (
39346   p_application_id        IN NUMBER
39347  ,p_event_id              IN NUMBER
39348  ,p_calculate_acctd_flag  IN VARCHAR2
39349  ,p_calculate_g_l_flag    IN VARCHAR2
39350  ,p_actual_flag           IN OUT VARCHAR2
39351  ,p_balance_type_code     OUT VARCHAR2
39352  ,p_gain_or_loss_ref      OUT VARCHAR2
39353  
39354 --Distribution GL Account
39355  , p_source_3            IN NUMBER
39356 --Distribution Source Type
39357  , p_source_13            IN VARCHAR2
39358 --Distribution Line Identifier
39359  , p_source_15            IN NUMBER
39360 --Distribution Type
39361  , p_source_16            IN VARCHAR2
39362 --Exchange Date
39363  , p_source_19            IN DATE
39364 --Exchange Rate
39365  , p_source_20            IN NUMBER
39366 --Exchange Rate Type
39367  , p_source_21            IN VARCHAR2
39368 --Transaction Distribution Identifier
39369  , p_source_27            IN NUMBER
39370 --Transaction Distribution Type
39371  , p_source_28            IN VARCHAR2
39372 --Distribution Multi Fund Additional Entry
39373  , p_source_52            IN VARCHAR2
39374 --Receipt Applied To Application Identifier
39375  , p_source_56            IN NUMBER
39376 --Transaction Entity Code
39377  , p_source_57            IN VARCHAR2
39378 --Transaction Identifier
39379  , p_source_58            IN NUMBER
39380 --DIST_ENT_AMT_FROM
39381  , p_source_59            IN NUMBER
39382 --Applying Document Currency Code
39383  , p_source_60            IN VARCHAR2
39384 --Accounting Amount
39385  , p_source_61            IN NUMBER
39386 --Distribution Party Identifier
39387  , p_source_62            IN NUMBER
39388 --Distribution Party Site Id
39389  , p_source_63            IN NUMBER
39390 --Distribution Party Type
39391  , p_source_64            IN VARCHAR2
39392 )
39393 IS
39394 
39395 l_component_type              VARCHAR2(80);
39396 l_component_code              VARCHAR2(30);
39397 l_component_type_code         VARCHAR2(1);
39398 l_component_appl_id           INTEGER;
39399 l_amb_context_code            VARCHAR2(30);
39400 l_entity_code                 VARCHAR2(30);
39401 l_event_class_code            VARCHAR2(30);
39402 l_ae_header_id                NUMBER;
39403 l_event_type_code             VARCHAR2(30);
39404 l_line_definition_code        VARCHAR2(30);
39405 l_line_definition_owner_code  VARCHAR2(1);
39406 --
39407 -- adr variables
39408 l_segment                     VARCHAR2(30);
39409 l_ccid                        NUMBER;
39410 l_adr_transaction_coa_id      NUMBER;
39411 l_adr_accounting_coa_id       NUMBER;
39415 l_adr_value_combination_id    NUMBER;
39412 l_adr_flexfield_segment_code  VARCHAR2(30);
39413 l_adr_flex_value_set_id       NUMBER;
39414 l_adr_value_type_code         VARCHAR2(30);
39416 l_adr_value_segment_code      VARCHAR2(30);
39417 
39418 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
39419 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
39420 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
39421 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
39422 
39423 -- 4262811 Variables ------------------------------------------------------------------------------------------
39424 l_entered_amt_idx             NUMBER;
39425 l_accted_amt_idx              NUMBER;
39426 l_acc_rev_flag                VARCHAR2(1);
39427 l_accrual_line_num            NUMBER;
39428 l_tmp_amt                     NUMBER;
39429 l_acc_rev_natural_side_code   VARCHAR2(1);
39430 
39431 l_num_entries                 NUMBER;
39432 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
39433 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
39434 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
39435 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
39436 l_recog_line_1                NUMBER;
39437 l_recog_line_2                NUMBER;
39438 
39439 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
39440 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
39441 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
39442 
39443 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
39444 
39445 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
39446 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
39447 
39448 ---------------------------------------------------------------------------------------------------------------
39449 
39450 
39451 --
39452 -- bulk performance
39453 --
39454 l_balance_type_code           VARCHAR2(1);
39455 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
39456 l_log_module                  VARCHAR2(240);
39457 
39458 --
39459 -- Upgrade strategy
39460 --
39461 l_actual_upg_option           VARCHAR2(1);
39462 l_enc_upg_option           VARCHAR2(1);
39463 
39464 --
39465 BEGIN
39466 --
39467 IF g_log_enabled THEN
39468       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_80';
39469 END IF;
39470 --
39471 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
39472 
39473       trace
39474          (p_msg      => 'BEGIN of AcctLineType_80'
39475          ,p_level    => C_LEVEL_PROCEDURE
39476          ,p_module   => l_log_module);
39477 
39478 END IF;
39479 --
39480 l_component_type             := 'AMB_JLT';
39481 l_component_code             := 'RCT_CASH';
39482 l_component_type_code        := 'S';
39483 l_component_appl_id          :=  222;
39484 l_amb_context_code           := 'DEFAULT';
39485 l_entity_code                := 'RECEIPTS';
39486 l_event_class_code           := 'RECEIPT';
39487 l_event_type_code            := 'RECEIPT_ALL';
39488 l_line_definition_owner_code := 'S';
39489 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
39490 --
39491 l_balance_type_code          := 'A';
39492 l_segment                     := NULL;
39493 l_ccid                        := NULL;
39494 l_adr_transaction_coa_id      := NULL;
39495 l_adr_accounting_coa_id       := NULL;
39496 l_adr_flexfield_segment_code  := NULL;
39497 l_adr_flex_value_set_id       := NULL;
39498 l_adr_value_type_code         := NULL;
39499 l_adr_value_combination_id    := NULL;
39500 l_adr_value_segment_code      := NULL;
39501 
39502 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
39503 l_bflow_class_code           := '';    -- 4219869 Business Flow
39504 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
39505 l_budgetary_control_flag     := 'N';
39506 
39507 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
39508 l_bflow_applied_to_amt       := NULL; -- 5132302
39509 l_entered_amt_idx            := NULL;          -- 4262811
39510 l_accted_amt_idx             := NULL;          -- 4262811
39511 l_acc_rev_flag               := NULL;          -- 4262811
39512 l_accrual_line_num           := NULL;          -- 4262811
39513 l_tmp_amt                    := NULL;          -- 4262811
39514 --
39515  
39516 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
39517     l_balance_type_code <> 'B' THEN
39518 IF NVL(p_source_13,'
39519 ') =  'CASH' AND 
39520 NVL(p_source_52,'
39521 ') =  'N'
39522  THEN 
39523 
39524    --
39525    XLA_AE_LINES_PKG.SetNewLine;
39526 
39527    p_balance_type_code          := l_balance_type_code;
39531      p_actual_flag :='A';
39528    -- set the flag so later we will know whether the gain loss line needs to be created
39529    
39530    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
39532    END IF;
39533 
39534    --
39535    -- bulk performance
39536    --
39537    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
39538                                       p_header_num   => 0); -- 4262811
39539    --
39540    -- set accounting line options
39541    --
39542    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
39543            p_natural_side_code          => 'C'
39544          , p_gain_or_loss_flag          => 'N'
39545          , p_gl_transfer_mode_code      => 'S'
39546          , p_acct_entry_type_code       => 'A'
39547          , p_switch_side_flag           => 'Y'
39548          , p_merge_duplicate_code       => 'A'
39549          );
39550    --
39551    l_acc_rev_natural_side_code := 'D';  -- 4262811
39552    -- 
39553    --
39554    -- set accounting line type info
39555    --
39556    xla_ae_lines_pkg.SetAcctLineType
39557       (p_component_type             => l_component_type
39558       ,p_event_type_code            => l_event_type_code
39559       ,p_line_definition_owner_code => l_line_definition_owner_code
39560       ,p_line_definition_code       => l_line_definition_code
39561       ,p_accounting_line_code       => l_component_code
39562       ,p_accounting_line_type_code  => l_component_type_code
39563       ,p_accounting_line_appl_id    => l_component_appl_id
39564       ,p_amb_context_code           => l_amb_context_code
39565       ,p_entity_code                => l_entity_code
39566       ,p_event_class_code           => l_event_class_code);
39567    --
39568    -- set accounting class
39569    --
39570    xla_ae_lines_pkg.SetAcctClass(
39571            p_accounting_class_code  => 'CASH'
39572          , p_ae_header_id           => l_ae_header_id
39573          );
39574 
39575    --
39576    -- set rounding class
39577    --
39578    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
39579                       'RECEIVABLE';
39580 
39581    --
39582    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
39583    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
39584    --
39585    -- bulk performance
39586    --
39587    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
39588 
39589    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
39590       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
39591 
39592    -- 4955764
39593    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
39594       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
39595 
39596    -- 4458381 Public Sector Enh
39597    
39598    --
39599    -- set accounting attributes for the line type
39600    --
39601    l_entered_amt_idx := 8;
39602    l_accted_amt_idx  := 13;
39603    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
39604    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
39605    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
39606    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
39607    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
39608    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
39609    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
39610    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
39611    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
39612    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
39613    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
39614    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
39615    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
39616    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
39617    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
39618    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
39619    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
39620    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
39621    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
39622    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
39623    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
39624    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
39625    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
39626    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
39627    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
39628    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
39629    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
39630    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
39631    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
39632    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
39633    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
39634    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
39635    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
39636 
39637    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
39638    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
39639 
39643    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
39640    ---------------------------------------------------------------------------------------------------------------
39641    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
39642    ---------------------------------------------------------------------------------------------------------------
39644 
39645    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
39646    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
39647 
39648    IF xla_accounting_cache_pkg.GetValueChar
39649          (p_source_code         => 'LEDGER_CATEGORY_CODE'
39650          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
39651    AND l_bflow_method_code = 'PRIOR_ENTRY'
39652 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
39653    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
39654          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
39655        )
39656    THEN
39657          xla_ae_lines_pkg.BflowUpgEntry
39658            (p_business_method_code    => l_bflow_method_code
39659            ,p_business_class_code     => l_bflow_class_code
39660            ,p_balance_type            => l_balance_type_code);
39661    ELSE
39662       NULL;
39663 -- No business flow processing for business flow method of NONE.
39664    END IF;
39665 
39666    --
39667    -- call analytical criteria
39668    --
39669    
39670    --
39671    -- call description
39672    --
39673    -- No description or it is inherited.
39674    --
39675    -- call ADRs
39676    -- Bug 4922099
39677    --
39678    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
39679         (NVL(l_actual_upg_option, 'N') = 'O') OR
39680         (NVL(l_enc_upg_option, 'N') = 'O')
39681       )
39682    THEN
39683    NULL;
39684    --
39685    --
39686    
39687   l_ccid := AcctDerRule_7(
39688            p_application_id           => p_application_id
39689          , p_ae_header_id             => l_ae_header_id 
39690 , p_source_3 => p_source_3
39691          , x_transaction_coa_id       => l_adr_transaction_coa_id
39692          , x_accounting_coa_id        => l_adr_accounting_coa_id
39693          , x_value_type_code          => l_adr_value_type_code
39694          , p_side                     => 'NA'
39695    );
39696 
39697    xla_ae_lines_pkg.set_ccid(
39698     p_code_combination_id          => l_ccid
39699   , p_value_type_code              => l_adr_value_type_code
39700   , p_transaction_coa_id           => l_adr_transaction_coa_id
39701   , p_accounting_coa_id            => l_adr_accounting_coa_id
39702   , p_adr_code                     => 'DIST_CCID'
39703   , p_adr_type_code                => 'S'
39704   , p_component_type               => l_component_type
39705   , p_component_code               => l_component_code
39706   , p_component_type_code          => l_component_type_code
39707   , p_component_appl_id            => l_component_appl_id
39708   , p_amb_context_code             => l_amb_context_code
39709   , p_side                         => 'NA'
39710   );
39711 
39712 
39713    --
39714    --
39715    END IF;
39716    --
39717    -- Bug 4922099
39718    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
39719           (NVL(l_enc_upg_option, 'N') = 'O')
39720         ) AND
39721         (l_bflow_method_code = 'PRIOR_ENTRY')
39722       )
39723    THEN
39724       IF
39725       --
39726       1 = 2
39727       --
39728       THEN
39729       xla_accounting_err_pkg.build_message
39730                                     (p_appli_s_name            => 'XLA'
39731                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
39732                                     ,p_token_1                 => 'LINE_NUMBER'
39736                                                                              l_component_type
39733                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
39734                                     ,p_token_2                 => 'LINE_TYPE_NAME'
39735                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
39737                                                                             ,l_component_code
39738                                                                             ,l_component_type_code
39739                                                                             ,l_component_appl_id
39740                                                                             ,l_amb_context_code
39741                                                                             ,l_entity_code
39742                                                                             ,l_event_class_code
39743                                                                            )
39744                                     ,p_token_3                 => 'OWNER'
39745                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
39746                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
39747                                                                           ,p_lookup_code    => l_component_type_code
39748                                                                          )
39749                                     ,p_token_4                 => 'PRODUCT_NAME'
39750                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
39751                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
39752                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
39753                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
39754                                     ,p_ae_header_id            =>  NULL
39755                                        );
39756 
39757         IF (C_LEVEL_ERROR>= g_log_level) THEN
39758                  trace
39759                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
39760                       ,p_level    => C_LEVEL_ERROR
39761                       ,p_module   => l_log_module);
39762         END IF;
39763       END IF;
39764    END IF;
39765    --
39766    --
39767    ------------------------------------------------------------------------------------------------
39768    -- 4219869 Business Flow
39769    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
39770    -- Prior Entry.  Currently, the following code is always generated.
39771    ------------------------------------------------------------------------------------------------
39772    XLA_AE_LINES_PKG.ValidateCurrentLine;
39773 
39774    ------------------------------------------------------------------------------------
39775    -- 4219869 Business Flow
39776    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
39777    ------------------------------------------------------------------------------------
39778    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
39779 
39780    ----------------------------------------------------------------------------------
39781    -- 4219869 Business Flow
39782    -- Update journal entry status -- Need to generate this within IF <condition>
39783    ----------------------------------------------------------------------------------
39784    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
39785          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
39786          ,p_balance_type_code => l_balance_type_code
39787          );
39788 
39789    -------------------------------------------------------------------------------------------
39790    -- 4262811 - Generate the Accrual Reversal lines
39791    -------------------------------------------------------------------------------------------
39792    BEGIN
39793       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
39794                               (g_array_event(p_event_id).array_value_num('header_index'));
39795       IF l_acc_rev_flag IS NULL THEN
39796          l_acc_rev_flag := 'N';
39797       END IF;
39798    EXCEPTION
39799       WHEN OTHERS THEN
39800          l_acc_rev_flag := 'N';
39801    END;
39802    --
39803    IF (l_acc_rev_flag = 'Y') THEN
39804 
39805        -- 4645092  ------------------------------------------------------------------------------
39806        -- To allow MPA report to determine if it should generate report process
39807        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
39808        ------------------------------------------------------------------------------------------
39809 
39810        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
39811        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
39812    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
39813    -- call ADRs
39814    -- Bug 4922099
39818         (NVL(l_enc_upg_option, 'N') = 'O')
39815    --
39816    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
39817         (NVL(l_actual_upg_option, 'N') = 'O') OR
39819       )
39820    THEN
39821    NULL;
39822    --
39823    --
39824    
39825   l_ccid := AcctDerRule_7(
39826            p_application_id           => p_application_id
39827          , p_ae_header_id             => l_ae_header_id 
39828 , p_source_3 => p_source_3
39829          , x_transaction_coa_id       => l_adr_transaction_coa_id
39830          , x_accounting_coa_id        => l_adr_accounting_coa_id
39831          , x_value_type_code          => l_adr_value_type_code
39832          , p_side                     => 'NA'
39833    );
39834 
39835    xla_ae_lines_pkg.set_ccid(
39836     p_code_combination_id          => l_ccid
39837   , p_value_type_code              => l_adr_value_type_code
39838   , p_transaction_coa_id           => l_adr_transaction_coa_id
39839   , p_accounting_coa_id            => l_adr_accounting_coa_id
39840   , p_adr_code                     => 'DIST_CCID'
39841   , p_adr_type_code                => 'S'
39842   , p_component_type               => l_component_type
39843   , p_component_code               => l_component_code
39844   , p_component_type_code          => l_component_type_code
39845   , p_component_appl_id            => l_component_appl_id
39846   , p_amb_context_code             => l_amb_context_code
39847   , p_side                         => 'NA'
39848   );
39849 
39850 
39851    --
39852    --
39853    END IF;
39854 
39855        --
39856        -- Update the line information that should be overwritten
39857        --
39858        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
39859                                          p_header_num   => 1);
39860        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
39861 
39862        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
39863 
39864        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
39865           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
39866        END IF;
39867 
39868       --
39869       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
39870       --
39871       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
39872           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
39873       ELSE
39874           ---------------------------------------------------------------------------------------------------
39875           -- 4262811a Switch Sign
39876           ---------------------------------------------------------------------------------------------------
39877           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
39878           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
39879                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
39880           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
39881                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
39882           -- 5132302
39883           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
39884                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
39885 
39886       END IF;
39887 
39888       -- 4955764
39889       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
39890       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
39891 
39892 
39893       XLA_AE_LINES_PKG.ValidateCurrentLine;
39894       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
39895 
39896       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
39897                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
39898                ,p_balance_type_code => l_balance_type_code);
39899 
39900    END IF;
39901 
39902    -----------------------------------------------------------------------------------------
39903    -- 4262811 Multiperiod Accounting
39904    -----------------------------------------------------------------------------------------
39905      -- No MPA option is assigned.
39906 
39907 
39908 END IF;
39909 END IF;
39910 --
39911 
39912 --
39913 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
39914    trace
39915       (p_msg      => 'END of AcctLineType_80'
39916       ,p_level    => C_LEVEL_PROCEDURE
39917       ,p_module   => l_log_module);
39918 END IF;
39919 --
39920 EXCEPTION
39921   WHEN xla_exceptions_pkg.application_exception THEN
39922       RAISE;
39923   WHEN OTHERS THEN
39924        xla_exceptions_pkg.raise_message
39925            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_80');
39926 END AcctLineType_80;
39927 --
39928 
39929 ---------------------------------------
39930 --
39931 -- PRIVATE FUNCTION
39932 --         AcctLineType_81
39933 --
39934 ---------------------------------------
39935 PROCEDURE AcctLineType_81 (
39936   p_application_id        IN NUMBER
39937  ,p_event_id              IN NUMBER
39938  ,p_calculate_acctd_flag  IN VARCHAR2
39939  ,p_calculate_g_l_flag    IN VARCHAR2
39940  ,p_actual_flag           IN OUT VARCHAR2
39941  ,p_balance_type_code     OUT VARCHAR2
39945  , p_source_3            IN NUMBER
39942  ,p_gain_or_loss_ref      OUT VARCHAR2
39943  
39944 --Distribution GL Account
39946 --Distribution Source Type
39947  , p_source_13            IN VARCHAR2
39948 --Receivable Activity Type
39949  , p_source_14            IN VARCHAR2
39950 --Distribution Line Identifier
39951  , p_source_15            IN NUMBER
39952 --Distribution Type
39953  , p_source_16            IN VARCHAR2
39954 --Exchange Date
39955  , p_source_19            IN DATE
39956 --Exchange Rate
39957  , p_source_20            IN NUMBER
39958 --Transaction Distribution Identifier
39959  , p_source_27            IN NUMBER
39960 --Transaction Distribution Type
39961  , p_source_28            IN VARCHAR2
39962 --Distribution Multi Fund Additional Entry
39963  , p_source_52            IN VARCHAR2
39964 --Receipt Applied To Application Identifier
39965  , p_source_56            IN NUMBER
39966 --Transaction Entity Code
39967  , p_source_57            IN VARCHAR2
39968 --Transaction Identifier
39969  , p_source_58            IN NUMBER
39970 --DIST_ENT_AMT_FROM
39971  , p_source_59            IN NUMBER
39972 --Applying Document Currency Code
39973  , p_source_60            IN VARCHAR2
39974 --Accounting Amount
39975  , p_source_61            IN NUMBER
39976 --Distribution Party Identifier
39977  , p_source_62            IN NUMBER
39978 --Distribution Party Site Id
39979  , p_source_63            IN NUMBER
39980 --Distribution Party Type
39981  , p_source_64            IN VARCHAR2
39982 --Applied To Document Exchange Rate Type
39983  , p_source_65            IN VARCHAR2
39984 )
39985 IS
39986 
39987 l_component_type              VARCHAR2(80);
39988 l_component_code              VARCHAR2(30);
39989 l_component_type_code         VARCHAR2(1);
39990 l_component_appl_id           INTEGER;
39991 l_amb_context_code            VARCHAR2(30);
39992 l_entity_code                 VARCHAR2(30);
39993 l_event_class_code            VARCHAR2(30);
39994 l_ae_header_id                NUMBER;
39995 l_event_type_code             VARCHAR2(30);
39996 l_line_definition_code        VARCHAR2(30);
39997 l_line_definition_owner_code  VARCHAR2(1);
39998 --
39999 -- adr variables
40000 l_segment                     VARCHAR2(30);
40001 l_ccid                        NUMBER;
40002 l_adr_transaction_coa_id      NUMBER;
40003 l_adr_accounting_coa_id       NUMBER;
40004 l_adr_flexfield_segment_code  VARCHAR2(30);
40005 l_adr_flex_value_set_id       NUMBER;
40006 l_adr_value_type_code         VARCHAR2(30);
40007 l_adr_value_combination_id    NUMBER;
40008 l_adr_value_segment_code      VARCHAR2(30);
40009 
40010 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
40011 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
40012 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
40013 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
40014 
40015 -- 4262811 Variables ------------------------------------------------------------------------------------------
40016 l_entered_amt_idx             NUMBER;
40017 l_accted_amt_idx              NUMBER;
40018 l_acc_rev_flag                VARCHAR2(1);
40019 l_accrual_line_num            NUMBER;
40020 l_tmp_amt                     NUMBER;
40021 l_acc_rev_natural_side_code   VARCHAR2(1);
40022 
40023 l_num_entries                 NUMBER;
40024 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
40025 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
40026 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
40027 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
40028 l_recog_line_1                NUMBER;
40029 l_recog_line_2                NUMBER;
40030 
40031 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
40032 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
40033 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
40034 
40035 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
40036 
40037 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
40038 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
40039 
40040 ---------------------------------------------------------------------------------------------------------------
40041 
40042 
40043 --
40044 -- bulk performance
40045 --
40046 l_balance_type_code           VARCHAR2(1);
40047 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
40048 l_log_module                  VARCHAR2(240);
40049 
40050 --
40051 -- Upgrade strategy
40052 --
40053 l_actual_upg_option           VARCHAR2(1);
40054 l_enc_upg_option           VARCHAR2(1);
40055 
40056 --
40057 BEGIN
40058 --
40059 IF g_log_enabled THEN
40060       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_81';
40061 END IF;
40062 --
40063 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
40064 
40065       trace
40066          (p_msg      => 'BEGIN of AcctLineType_81'
40067          ,p_level    => C_LEVEL_PROCEDURE
40068          ,p_module   => l_log_module);
40069 
40070 END IF;
40071 --
40072 l_component_type             := 'AMB_JLT';
40073 l_component_code             := 'RCT_CLAIM';
40074 l_component_type_code        := 'S';
40075 l_component_appl_id          :=  222;
40076 l_amb_context_code           := 'DEFAULT';
40077 l_entity_code                := 'RECEIPTS';
40078 l_event_class_code           := 'RECEIPT';
40079 l_event_type_code            := 'RECEIPT_ALL';
40080 l_line_definition_owner_code := 'S';
40084 l_segment                     := NULL;
40081 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
40082 --
40083 l_balance_type_code          := 'A';
40085 l_ccid                        := NULL;
40086 l_adr_transaction_coa_id      := NULL;
40087 l_adr_accounting_coa_id       := NULL;
40088 l_adr_flexfield_segment_code  := NULL;
40089 l_adr_flex_value_set_id       := NULL;
40090 l_adr_value_type_code         := NULL;
40091 l_adr_value_combination_id    := NULL;
40092 l_adr_value_segment_code      := NULL;
40093 
40094 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
40095 l_bflow_class_code           := '';    -- 4219869 Business Flow
40096 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
40097 l_budgetary_control_flag     := 'N';
40098 
40099 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
40100 l_bflow_applied_to_amt       := NULL; -- 5132302
40101 l_entered_amt_idx            := NULL;          -- 4262811
40102 l_accted_amt_idx             := NULL;          -- 4262811
40103 l_acc_rev_flag               := NULL;          -- 4262811
40104 l_accrual_line_num           := NULL;          -- 4262811
40105 l_tmp_amt                    := NULL;          -- 4262811
40106 --
40107  
40108 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
40109     l_balance_type_code <> 'B' THEN
40110 IF NVL(p_source_13,'
40111 ') =  'OTHER ACC' AND 
40112 NVL(p_source_14,'
40113 ') =  'CLAIM_INVESTIGATION' AND 
40114 NVL(p_source_52,'
40115 ') =  'N'
40116  THEN 
40117 
40118    --
40119    XLA_AE_LINES_PKG.SetNewLine;
40120 
40121    p_balance_type_code          := l_balance_type_code;
40122    -- set the flag so later we will know whether the gain loss line needs to be created
40123    
40124    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
40125      p_actual_flag :='A';
40126    END IF;
40127 
40128    --
40129    -- bulk performance
40130    --
40131    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
40132                                       p_header_num   => 0); -- 4262811
40133    --
40134    -- set accounting line options
40135    --
40136    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
40137            p_natural_side_code          => 'C'
40138          , p_gain_or_loss_flag          => 'N'
40139          , p_gl_transfer_mode_code      => 'S'
40140          , p_acct_entry_type_code       => 'A'
40141          , p_switch_side_flag           => 'Y'
40142          , p_merge_duplicate_code       => 'A'
40143          );
40144    --
40145    l_acc_rev_natural_side_code := 'D';  -- 4262811
40146    -- 
40147    --
40148    -- set accounting line type info
40149    --
40150    xla_ae_lines_pkg.SetAcctLineType
40151       (p_component_type             => l_component_type
40152       ,p_event_type_code            => l_event_type_code
40153       ,p_line_definition_owner_code => l_line_definition_owner_code
40154       ,p_line_definition_code       => l_line_definition_code
40155       ,p_accounting_line_code       => l_component_code
40156       ,p_accounting_line_type_code  => l_component_type_code
40157       ,p_accounting_line_appl_id    => l_component_appl_id
40158       ,p_amb_context_code           => l_amb_context_code
40159       ,p_entity_code                => l_entity_code
40160       ,p_event_class_code           => l_event_class_code);
40161    --
40162    -- set accounting class
40163    --
40164    xla_ae_lines_pkg.SetAcctClass(
40165            p_accounting_class_code  => 'CLAIM'
40166          , p_ae_header_id           => l_ae_header_id
40167          );
40168 
40169    --
40170    -- set rounding class
40171    --
40172    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
40173                       'RECEIVABLE';
40174 
40175    --
40176    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
40177    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
40178    --
40179    -- bulk performance
40180    --
40181    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
40182 
40183    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
40184       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
40185 
40186    -- 4955764
40187    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
40188       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
40189 
40190    -- 4458381 Public Sector Enh
40191    
40192    --
40193    -- set accounting attributes for the line type
40194    --
40195    l_entered_amt_idx := 8;
40196    l_accted_amt_idx  := 13;
40197    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
40198    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
40199    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
40200    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
40201    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
40202    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
40203    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
40204    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
40205    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
40206    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
40207    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
40208    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
40209    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
40213    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
40210    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
40211    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
40212    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
40214    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
40215    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
40216    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
40217    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
40218    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
40219    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
40220    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
40221    l_rec_acct_attrs.array_char_value(12)  := p_source_65;
40222    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
40223    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
40224    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
40225    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
40226    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
40227    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
40228    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
40229    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
40230 
40231    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
40232    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
40233 
40234    ---------------------------------------------------------------------------------------------------------------
40235    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
40236    ---------------------------------------------------------------------------------------------------------------
40237    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
40238 
40239    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
40240    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
40241 
40242    IF xla_accounting_cache_pkg.GetValueChar
40243          (p_source_code         => 'LEDGER_CATEGORY_CODE'
40244          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
40245    AND l_bflow_method_code = 'PRIOR_ENTRY'
40246 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
40247    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
40248          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
40249        )
40250    THEN
40251          xla_ae_lines_pkg.BflowUpgEntry
40252            (p_business_method_code    => l_bflow_method_code
40253            ,p_business_class_code     => l_bflow_class_code
40254            ,p_balance_type            => l_balance_type_code);
40255    ELSE
40256       NULL;
40257 -- No business flow processing for business flow method of NONE.
40258    END IF;
40259 
40260    --
40261    -- call analytical criteria
40262    --
40263    
40264    --
40265    -- call description
40266    --
40267    -- No description or it is inherited.
40268    --
40269    -- call ADRs
40270    -- Bug 4922099
40271    --
40272    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
40273         (NVL(l_actual_upg_option, 'N') = 'O') OR
40274         (NVL(l_enc_upg_option, 'N') = 'O')
40275       )
40276    THEN
40277    NULL;
40278    --
40279    --
40280    
40281   l_ccid := AcctDerRule_7(
40282            p_application_id           => p_application_id
40283          , p_ae_header_id             => l_ae_header_id 
40284 , p_source_3 => p_source_3
40285          , x_transaction_coa_id       => l_adr_transaction_coa_id
40286          , x_accounting_coa_id        => l_adr_accounting_coa_id
40287          , x_value_type_code          => l_adr_value_type_code
40288          , p_side                     => 'NA'
40289    );
40290 
40291    xla_ae_lines_pkg.set_ccid(
40292     p_code_combination_id          => l_ccid
40293   , p_value_type_code              => l_adr_value_type_code
40294   , p_transaction_coa_id           => l_adr_transaction_coa_id
40295   , p_accounting_coa_id            => l_adr_accounting_coa_id
40296   , p_adr_code                     => 'DIST_CCID'
40297   , p_adr_type_code                => 'S'
40298   , p_component_type               => l_component_type
40299   , p_component_code               => l_component_code
40300   , p_component_type_code          => l_component_type_code
40301   , p_component_appl_id            => l_component_appl_id
40302   , p_amb_context_code             => l_amb_context_code
40303   , p_side                         => 'NA'
40304   );
40305 
40306 
40307    --
40308    --
40309    END IF;
40310    --
40311    -- Bug 4922099
40312    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
40313           (NVL(l_enc_upg_option, 'N') = 'O')
40314         ) AND
40315         (l_bflow_method_code = 'PRIOR_ENTRY')
40316       )
40317    THEN
40318       IF
40319       --
40320       1 = 2
40321       --
40322       THEN
40323       xla_accounting_err_pkg.build_message
40324                                     (p_appli_s_name            => 'XLA'
40325                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
40326                                     ,p_token_1                 => 'LINE_NUMBER'
40327                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
40328                                     ,p_token_2                 => 'LINE_TYPE_NAME'
40329                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
40333                                                                             ,l_component_appl_id
40330                                                                              l_component_type
40331                                                                             ,l_component_code
40332                                                                             ,l_component_type_code
40334                                                                             ,l_amb_context_code
40335                                                                             ,l_entity_code
40336                                                                             ,l_event_class_code
40337                                                                            )
40338                                     ,p_token_3                 => 'OWNER'
40339                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
40340                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
40341                                                                           ,p_lookup_code    => l_component_type_code
40342                                                                          )
40343                                     ,p_token_4                 => 'PRODUCT_NAME'
40344                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
40345                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
40346                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
40347                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
40348                                     ,p_ae_header_id            =>  NULL
40349                                        );
40350 
40351         IF (C_LEVEL_ERROR>= g_log_level) THEN
40352                  trace
40353                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
40354                       ,p_level    => C_LEVEL_ERROR
40355                       ,p_module   => l_log_module);
40356         END IF;
40357       END IF;
40358    END IF;
40359    --
40360    --
40361    ------------------------------------------------------------------------------------------------
40362    -- 4219869 Business Flow
40363    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
40364    -- Prior Entry.  Currently, the following code is always generated.
40365    ------------------------------------------------------------------------------------------------
40366    XLA_AE_LINES_PKG.ValidateCurrentLine;
40367 
40368    ------------------------------------------------------------------------------------
40369    -- 4219869 Business Flow
40370    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
40371    ------------------------------------------------------------------------------------
40372    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
40373 
40374    ----------------------------------------------------------------------------------
40375    -- 4219869 Business Flow
40376    -- Update journal entry status -- Need to generate this within IF <condition>
40377    ----------------------------------------------------------------------------------
40378    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
40379          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
40380          ,p_balance_type_code => l_balance_type_code
40381          );
40382 
40383    -------------------------------------------------------------------------------------------
40384    -- 4262811 - Generate the Accrual Reversal lines
40385    -------------------------------------------------------------------------------------------
40386    BEGIN
40387       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
40388                               (g_array_event(p_event_id).array_value_num('header_index'));
40389       IF l_acc_rev_flag IS NULL THEN
40390          l_acc_rev_flag := 'N';
40391       END IF;
40392    EXCEPTION
40393       WHEN OTHERS THEN
40394          l_acc_rev_flag := 'N';
40395    END;
40396    --
40397    IF (l_acc_rev_flag = 'Y') THEN
40398 
40399        -- 4645092  ------------------------------------------------------------------------------
40400        -- To allow MPA report to determine if it should generate report process
40401        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
40402        ------------------------------------------------------------------------------------------
40403 
40404        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
40405        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
40406    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
40407    -- call ADRs
40408    -- Bug 4922099
40409    --
40410    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
40411         (NVL(l_actual_upg_option, 'N') = 'O') OR
40412         (NVL(l_enc_upg_option, 'N') = 'O')
40413       )
40414    THEN
40415    NULL;
40416    --
40417    --
40418    
40419   l_ccid := AcctDerRule_7(
40420            p_application_id           => p_application_id
40421          , p_ae_header_id             => l_ae_header_id 
40422 , p_source_3 => p_source_3
40423          , x_transaction_coa_id       => l_adr_transaction_coa_id
40424          , x_accounting_coa_id        => l_adr_accounting_coa_id
40425          , x_value_type_code          => l_adr_value_type_code
40426          , p_side                     => 'NA'
40427    );
40428 
40429    xla_ae_lines_pkg.set_ccid(
40430     p_code_combination_id          => l_ccid
40431   , p_value_type_code              => l_adr_value_type_code
40432   , p_transaction_coa_id           => l_adr_transaction_coa_id
40436   , p_component_type               => l_component_type
40433   , p_accounting_coa_id            => l_adr_accounting_coa_id
40434   , p_adr_code                     => 'DIST_CCID'
40435   , p_adr_type_code                => 'S'
40437   , p_component_code               => l_component_code
40438   , p_component_type_code          => l_component_type_code
40439   , p_component_appl_id            => l_component_appl_id
40440   , p_amb_context_code             => l_amb_context_code
40441   , p_side                         => 'NA'
40442   );
40443 
40444 
40445    --
40446    --
40447    END IF;
40448 
40449        --
40450        -- Update the line information that should be overwritten
40451        --
40452        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
40453                                          p_header_num   => 1);
40454        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
40455 
40456        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
40457 
40458        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
40459           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
40460        END IF;
40461 
40462       --
40463       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
40464       --
40465       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
40466           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
40467       ELSE
40468           ---------------------------------------------------------------------------------------------------
40469           -- 4262811a Switch Sign
40470           ---------------------------------------------------------------------------------------------------
40471           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
40472           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
40473                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
40474           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
40475                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
40476           -- 5132302
40477           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
40481 
40478                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
40479 
40480       END IF;
40482       -- 4955764
40483       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
40484       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
40485 
40486 
40487       XLA_AE_LINES_PKG.ValidateCurrentLine;
40488       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
40489 
40490       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
40491                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
40492                ,p_balance_type_code => l_balance_type_code);
40493 
40494    END IF;
40495 
40496    -----------------------------------------------------------------------------------------
40497    -- 4262811 Multiperiod Accounting
40498    -----------------------------------------------------------------------------------------
40499      -- No MPA option is assigned.
40500 
40501 
40502 END IF;
40503 END IF;
40504 --
40505 
40506 --
40507 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
40508    trace
40509       (p_msg      => 'END of AcctLineType_81'
40510       ,p_level    => C_LEVEL_PROCEDURE
40511       ,p_module   => l_log_module);
40512 END IF;
40513 --
40514 EXCEPTION
40515   WHEN xla_exceptions_pkg.application_exception THEN
40516       RAISE;
40517   WHEN OTHERS THEN
40518        xla_exceptions_pkg.raise_message
40519            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_81');
40520 END AcctLineType_81;
40521 --
40522 
40523 ---------------------------------------
40524 --
40525 -- PRIVATE FUNCTION
40526 --         AcctLineType_82
40527 --
40528 ---------------------------------------
40529 PROCEDURE AcctLineType_82 (
40530   p_application_id        IN NUMBER
40531  ,p_event_id              IN NUMBER
40532  ,p_calculate_acctd_flag  IN VARCHAR2
40533  ,p_calculate_g_l_flag    IN VARCHAR2
40534  ,p_actual_flag           IN OUT VARCHAR2
40535  ,p_balance_type_code     OUT VARCHAR2
40536  ,p_gain_or_loss_ref      OUT VARCHAR2
40537  
40538 --Distribution GL Account
40539  , p_source_3            IN NUMBER
40540 --Distribution Source Type
40541  , p_source_13            IN VARCHAR2
40542 --Distribution Line Identifier
40543  , p_source_15            IN NUMBER
40544 --Distribution Type
40545  , p_source_16            IN VARCHAR2
40546 --Exchange Date
40547  , p_source_19            IN DATE
40548 --Exchange Rate
40549  , p_source_20            IN NUMBER
40550 --Exchange Rate Type
40551  , p_source_21            IN VARCHAR2
40552 --Transaction Distribution Identifier
40553  , p_source_27            IN NUMBER
40554 --Transaction Distribution Type
40555  , p_source_28            IN VARCHAR2
40556 --Distribution Multi Fund Additional Entry
40560 --Transaction Entity Code
40557  , p_source_52            IN VARCHAR2
40558 --Receipt Applied To Application Identifier
40559  , p_source_56            IN NUMBER
40561  , p_source_57            IN VARCHAR2
40562 --Transaction Identifier
40563  , p_source_58            IN NUMBER
40564 --DIST_ENT_AMT_FROM
40565  , p_source_59            IN NUMBER
40566 --Applying Document Currency Code
40567  , p_source_60            IN VARCHAR2
40568 --Accounting Amount
40569  , p_source_61            IN NUMBER
40570 --Distribution Party Identifier
40571  , p_source_62            IN NUMBER
40572 --Distribution Party Site Id
40573  , p_source_63            IN NUMBER
40574 --Distribution Party Type
40575  , p_source_64            IN VARCHAR2
40576 )
40577 IS
40578 
40579 l_component_type              VARCHAR2(80);
40580 l_component_code              VARCHAR2(30);
40581 l_component_type_code         VARCHAR2(1);
40582 l_component_appl_id           INTEGER;
40583 l_amb_context_code            VARCHAR2(30);
40584 l_entity_code                 VARCHAR2(30);
40585 l_event_class_code            VARCHAR2(30);
40586 l_ae_header_id                NUMBER;
40587 l_event_type_code             VARCHAR2(30);
40588 l_line_definition_code        VARCHAR2(30);
40589 l_line_definition_owner_code  VARCHAR2(1);
40590 --
40591 -- adr variables
40592 l_segment                     VARCHAR2(30);
40593 l_ccid                        NUMBER;
40594 l_adr_transaction_coa_id      NUMBER;
40595 l_adr_accounting_coa_id       NUMBER;
40596 l_adr_flexfield_segment_code  VARCHAR2(30);
40597 l_adr_flex_value_set_id       NUMBER;
40598 l_adr_value_type_code         VARCHAR2(30);
40599 l_adr_value_combination_id    NUMBER;
40600 l_adr_value_segment_code      VARCHAR2(30);
40601 
40602 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
40603 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
40604 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
40605 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
40606 
40607 -- 4262811 Variables ------------------------------------------------------------------------------------------
40608 l_entered_amt_idx             NUMBER;
40609 l_accted_amt_idx              NUMBER;
40610 l_acc_rev_flag                VARCHAR2(1);
40611 l_accrual_line_num            NUMBER;
40612 l_tmp_amt                     NUMBER;
40613 l_acc_rev_natural_side_code   VARCHAR2(1);
40614 
40615 l_num_entries                 NUMBER;
40616 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
40617 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
40618 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
40619 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
40620 l_recog_line_1                NUMBER;
40621 l_recog_line_2                NUMBER;
40622 
40623 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
40624 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
40625 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
40626 
40627 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
40628 
40629 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
40630 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
40631 
40632 ---------------------------------------------------------------------------------------------------------------
40633 
40634 
40635 --
40636 -- bulk performance
40637 --
40638 l_balance_type_code           VARCHAR2(1);
40639 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
40640 l_log_module                  VARCHAR2(240);
40641 
40642 --
40643 -- Upgrade strategy
40644 --
40645 l_actual_upg_option           VARCHAR2(1);
40646 l_enc_upg_option           VARCHAR2(1);
40647 
40648 --
40649 BEGIN
40650 --
40651 IF g_log_enabled THEN
40652       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_82';
40653 END IF;
40654 --
40655 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
40656 
40657       trace
40658          (p_msg      => 'BEGIN of AcctLineType_82'
40659          ,p_level    => C_LEVEL_PROCEDURE
40660          ,p_module   => l_log_module);
40661 
40662 END IF;
40663 --
40664 l_component_type             := 'AMB_JLT';
40665 l_component_code             := 'RCT_CONFIRM';
40666 l_component_type_code        := 'S';
40667 l_component_appl_id          :=  222;
40668 l_amb_context_code           := 'DEFAULT';
40669 l_entity_code                := 'RECEIPTS';
40670 l_event_class_code           := 'RECEIPT';
40671 l_event_type_code            := 'RECEIPT_ALL';
40672 l_line_definition_owner_code := 'S';
40673 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
40674 --
40675 l_balance_type_code          := 'A';
40676 l_segment                     := NULL;
40677 l_ccid                        := NULL;
40678 l_adr_transaction_coa_id      := NULL;
40679 l_adr_accounting_coa_id       := NULL;
40680 l_adr_flexfield_segment_code  := NULL;
40681 l_adr_flex_value_set_id       := NULL;
40682 l_adr_value_type_code         := NULL;
40683 l_adr_value_combination_id    := NULL;
40684 l_adr_value_segment_code      := NULL;
40685 
40686 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
40687 l_bflow_class_code           := '';    -- 4219869 Business Flow
40688 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
40689 l_budgetary_control_flag     := 'N';
40690 
40691 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
40692 l_bflow_applied_to_amt       := NULL; -- 5132302
40696 l_accrual_line_num           := NULL;          -- 4262811
40693 l_entered_amt_idx            := NULL;          -- 4262811
40694 l_accted_amt_idx             := NULL;          -- 4262811
40695 l_acc_rev_flag               := NULL;          -- 4262811
40697 l_tmp_amt                    := NULL;          -- 4262811
40698 --
40699  
40700 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
40701     l_balance_type_code <> 'B' THEN
40702 IF NVL(p_source_13,'
40703 ') =  'CONFIRMATION' AND 
40704 NVL(p_source_52,'
40705 ') =  'N'
40706  THEN 
40707 
40708    --
40709    XLA_AE_LINES_PKG.SetNewLine;
40710 
40711    p_balance_type_code          := l_balance_type_code;
40712    -- set the flag so later we will know whether the gain loss line needs to be created
40713    
40714    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
40715      p_actual_flag :='A';
40716    END IF;
40717 
40718    --
40719    -- bulk performance
40720    --
40721    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
40722                                       p_header_num   => 0); -- 4262811
40723    --
40724    -- set accounting line options
40725    --
40726    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
40727            p_natural_side_code          => 'C'
40728          , p_gain_or_loss_flag          => 'N'
40729          , p_gl_transfer_mode_code      => 'S'
40730          , p_acct_entry_type_code       => 'A'
40731          , p_switch_side_flag           => 'Y'
40732          , p_merge_duplicate_code       => 'A'
40733          );
40734    --
40735    l_acc_rev_natural_side_code := 'D';  -- 4262811
40736    -- 
40737    --
40738    -- set accounting line type info
40739    --
40740    xla_ae_lines_pkg.SetAcctLineType
40741       (p_component_type             => l_component_type
40742       ,p_event_type_code            => l_event_type_code
40743       ,p_line_definition_owner_code => l_line_definition_owner_code
40744       ,p_line_definition_code       => l_line_definition_code
40745       ,p_accounting_line_code       => l_component_code
40746       ,p_accounting_line_type_code  => l_component_type_code
40747       ,p_accounting_line_appl_id    => l_component_appl_id
40748       ,p_amb_context_code           => l_amb_context_code
40749       ,p_entity_code                => l_entity_code
40750       ,p_event_class_code           => l_event_class_code);
40751    --
40752    -- set accounting class
40753    --
40754    xla_ae_lines_pkg.SetAcctClass(
40755            p_accounting_class_code  => 'CONFIRMATION'
40756          , p_ae_header_id           => l_ae_header_id
40757          );
40758 
40759    --
40760    -- set rounding class
40761    --
40762    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
40763                       'RECEIVABLE';
40764 
40765    --
40766    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
40767    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
40768    --
40769    -- bulk performance
40770    --
40771    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
40772 
40773    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
40774       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
40775 
40776    -- 4955764
40777    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
40778       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
40779 
40780    -- 4458381 Public Sector Enh
40781    
40782    --
40783    -- set accounting attributes for the line type
40784    --
40785    l_entered_amt_idx := 8;
40786    l_accted_amt_idx  := 13;
40787    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
40788    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
40789    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
40790    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
40791    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
40792    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
40793    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
40794    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
40795    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
40796    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
40797    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
40798    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
40799    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
40800    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
40801    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
40802    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
40803    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
40804    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
40805    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
40806    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
40807    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
40808    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
40809    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
40810    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
40811    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
40812    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
40813    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
40814    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
40815    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
40816    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
40817    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
40818    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
40819    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
40820 
40821    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
40822    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
40823 
40824    ---------------------------------------------------------------------------------------------------------------
40825    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
40826    ---------------------------------------------------------------------------------------------------------------
40827    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
40828 
40829    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
40830    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
40831 
40832    IF xla_accounting_cache_pkg.GetValueChar
40833          (p_source_code         => 'LEDGER_CATEGORY_CODE'
40834          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
40835    AND l_bflow_method_code = 'PRIOR_ENTRY'
40836 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
40837    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
40838          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
40839        )
40840    THEN
40841          xla_ae_lines_pkg.BflowUpgEntry
40842            (p_business_method_code    => l_bflow_method_code
40843            ,p_business_class_code     => l_bflow_class_code
40844            ,p_balance_type            => l_balance_type_code);
40845    ELSE
40846       NULL;
40847 -- No business flow processing for business flow method of NONE.
40848    END IF;
40849 
40850    --
40851    -- call analytical criteria
40852    --
40853    
40854    --
40855    -- call description
40856    --
40857    -- No description or it is inherited.
40858    --
40859    -- call ADRs
40860    -- Bug 4922099
40861    --
40862    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
40863         (NVL(l_actual_upg_option, 'N') = 'O') OR
40864         (NVL(l_enc_upg_option, 'N') = 'O')
40865       )
40866    THEN
40867    NULL;
40868    --
40869    --
40870    
40871   l_ccid := AcctDerRule_7(
40872            p_application_id           => p_application_id
40873          , p_ae_header_id             => l_ae_header_id 
40874 , p_source_3 => p_source_3
40875          , x_transaction_coa_id       => l_adr_transaction_coa_id
40876          , x_accounting_coa_id        => l_adr_accounting_coa_id
40877          , x_value_type_code          => l_adr_value_type_code
40878          , p_side                     => 'NA'
40879    );
40880 
40881    xla_ae_lines_pkg.set_ccid(
40882     p_code_combination_id          => l_ccid
40883   , p_value_type_code              => l_adr_value_type_code
40884   , p_transaction_coa_id           => l_adr_transaction_coa_id
40885   , p_accounting_coa_id            => l_adr_accounting_coa_id
40886   , p_adr_code                     => 'DIST_CCID'
40887   , p_adr_type_code                => 'S'
40888   , p_component_type               => l_component_type
40889   , p_component_code               => l_component_code
40890   , p_component_type_code          => l_component_type_code
40891   , p_component_appl_id            => l_component_appl_id
40892   , p_amb_context_code             => l_amb_context_code
40893   , p_side                         => 'NA'
40894   );
40895 
40896 
40897    --
40898    --
40899    END IF;
40900    --
40901    -- Bug 4922099
40902    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
40903           (NVL(l_enc_upg_option, 'N') = 'O')
40904         ) AND
40905         (l_bflow_method_code = 'PRIOR_ENTRY')
40906       )
40907    THEN
40908       IF
40909       --
40910       1 = 2
40911       --
40912       THEN
40913       xla_accounting_err_pkg.build_message
40914                                     (p_appli_s_name            => 'XLA'
40915                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
40916                                     ,p_token_1                 => 'LINE_NUMBER'
40920                                                                              l_component_type
40917                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
40918                                     ,p_token_2                 => 'LINE_TYPE_NAME'
40919                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
40921                                                                             ,l_component_code
40922                                                                             ,l_component_type_code
40923                                                                             ,l_component_appl_id
40924                                                                             ,l_amb_context_code
40925                                                                             ,l_entity_code
40926                                                                             ,l_event_class_code
40927                                                                            )
40928                                     ,p_token_3                 => 'OWNER'
40929                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
40930                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
40931                                                                           ,p_lookup_code    => l_component_type_code
40932                                                                          )
40933                                     ,p_token_4                 => 'PRODUCT_NAME'
40934                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
40935                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
40936                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
40937                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
40938                                     ,p_ae_header_id            =>  NULL
40939                                        );
40940 
40941         IF (C_LEVEL_ERROR>= g_log_level) THEN
40942                  trace
40943                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
40944                       ,p_level    => C_LEVEL_ERROR
40945                       ,p_module   => l_log_module);
40946         END IF;
40947       END IF;
40948    END IF;
40949    --
40950    --
40951    ------------------------------------------------------------------------------------------------
40952    -- 4219869 Business Flow
40953    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
40954    -- Prior Entry.  Currently, the following code is always generated.
40955    ------------------------------------------------------------------------------------------------
40956    XLA_AE_LINES_PKG.ValidateCurrentLine;
40957 
40958    ------------------------------------------------------------------------------------
40959    -- 4219869 Business Flow
40960    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
40961    ------------------------------------------------------------------------------------
40962    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
40963 
40964    ----------------------------------------------------------------------------------
40965    -- 4219869 Business Flow
40966    -- Update journal entry status -- Need to generate this within IF <condition>
40967    ----------------------------------------------------------------------------------
40968    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
40969          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
40970          ,p_balance_type_code => l_balance_type_code
40971          );
40972 
40973    -------------------------------------------------------------------------------------------
40974    -- 4262811 - Generate the Accrual Reversal lines
40975    -------------------------------------------------------------------------------------------
40976    BEGIN
40977       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
40978                               (g_array_event(p_event_id).array_value_num('header_index'));
40979       IF l_acc_rev_flag IS NULL THEN
40980          l_acc_rev_flag := 'N';
40981       END IF;
40982    EXCEPTION
40983       WHEN OTHERS THEN
40984          l_acc_rev_flag := 'N';
40985    END;
40986    --
40987    IF (l_acc_rev_flag = 'Y') THEN
40988 
40989        -- 4645092  ------------------------------------------------------------------------------
40990        -- To allow MPA report to determine if it should generate report process
40991        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
40992        ------------------------------------------------------------------------------------------
40993 
40994        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
40995        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
40996    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
40997    -- call ADRs
40998    -- Bug 4922099
40999    --
41000    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
41001         (NVL(l_actual_upg_option, 'N') = 'O') OR
41002         (NVL(l_enc_upg_option, 'N') = 'O')
41003       )
41004    THEN
41005    NULL;
41006    --
41007    --
41008    
41009   l_ccid := AcctDerRule_7(
41010            p_application_id           => p_application_id
41011          , p_ae_header_id             => l_ae_header_id 
41012 , p_source_3 => p_source_3
41013          , x_transaction_coa_id       => l_adr_transaction_coa_id
41014          , x_accounting_coa_id        => l_adr_accounting_coa_id
41015          , x_value_type_code          => l_adr_value_type_code
41016          , p_side                     => 'NA'
41017    );
41018 
41019    xla_ae_lines_pkg.set_ccid(
41020     p_code_combination_id          => l_ccid
41021   , p_value_type_code              => l_adr_value_type_code
41022   , p_transaction_coa_id           => l_adr_transaction_coa_id
41023   , p_accounting_coa_id            => l_adr_accounting_coa_id
41024   , p_adr_code                     => 'DIST_CCID'
41025   , p_adr_type_code                => 'S'
41026   , p_component_type               => l_component_type
41027   , p_component_code               => l_component_code
41028   , p_component_type_code          => l_component_type_code
41029   , p_component_appl_id            => l_component_appl_id
41030   , p_amb_context_code             => l_amb_context_code
41031   , p_side                         => 'NA'
41032   );
41033 
41034 
41035    --
41036    --
41037    END IF;
41038 
41039        --
41040        -- Update the line information that should be overwritten
41041        --
41042        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
41043                                          p_header_num   => 1);
41044        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
41045 
41046        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
41047 
41048        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
41049           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
41050        END IF;
41051 
41052       --
41053       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
41054       --
41055       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
41056           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
41057       ELSE
41058           ---------------------------------------------------------------------------------------------------
41059           -- 4262811a Switch Sign
41060           ---------------------------------------------------------------------------------------------------
41061           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
41062           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
41063                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
41064           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
41065                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
41066           -- 5132302
41067           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
41068                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
41069 
41070       END IF;
41071 
41072       -- 4955764
41073       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
41074       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
41075 
41076 
41077       XLA_AE_LINES_PKG.ValidateCurrentLine;
41078       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
41079 
41080       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
41081                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
41082                ,p_balance_type_code => l_balance_type_code);
41083 
41084    END IF;
41085 
41086    -----------------------------------------------------------------------------------------
41087    -- 4262811 Multiperiod Accounting
41088    -----------------------------------------------------------------------------------------
41089      -- No MPA option is assigned.
41090 
41091 
41092 END IF;
41093 END IF;
41094 --
41095 
41096 --
41097 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
41098    trace
41099       (p_msg      => 'END of AcctLineType_82'
41100       ,p_level    => C_LEVEL_PROCEDURE
41101       ,p_module   => l_log_module);
41102 END IF;
41103 --
41104 EXCEPTION
41105   WHEN xla_exceptions_pkg.application_exception THEN
41106       RAISE;
41107   WHEN OTHERS THEN
41108        xla_exceptions_pkg.raise_message
41109            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_82');
41110 END AcctLineType_82;
41111 --
41112 
41113 ---------------------------------------
41114 --
41115 -- PRIVATE FUNCTION
41116 --         AcctLineType_83
41117 --
41118 ---------------------------------------
41119 PROCEDURE AcctLineType_83 (
41120   p_application_id        IN NUMBER
41121  ,p_event_id              IN NUMBER
41122  ,p_calculate_acctd_flag  IN VARCHAR2
41123  ,p_calculate_g_l_flag    IN VARCHAR2
41124  ,p_actual_flag           IN OUT VARCHAR2
41125  ,p_balance_type_code     OUT VARCHAR2
41126  ,p_gain_or_loss_ref      OUT VARCHAR2
41127  
41128 --Distribution GL Account
41129  , p_source_3            IN NUMBER
41130 --Distribution Source Type
41131  , p_source_13            IN VARCHAR2
41132 --Distribution Line Identifier
41133  , p_source_15            IN NUMBER
41134 --Distribution Type
41135  , p_source_16            IN VARCHAR2
41136 --Exchange Date
41137  , p_source_19            IN DATE
41138 --Exchange Rate
41139  , p_source_20            IN NUMBER
41140 --Exchange Rate Type
41141  , p_source_21            IN VARCHAR2
41142 --Transaction Distribution Identifier
41143  , p_source_27            IN NUMBER
41144 --Transaction Distribution Type
41145  , p_source_28            IN VARCHAR2
41146 --Distribution Multi Fund Additional Entry
41147  , p_source_52            IN VARCHAR2
41148 --Receipt Applied To Application Identifier
41149  , p_source_56            IN NUMBER
41150 --Transaction Entity Code
41151  , p_source_57            IN VARCHAR2
41152 --Transaction Identifier
41153  , p_source_58            IN NUMBER
41154 --DIST_ENT_AMT_FROM
41155  , p_source_59            IN NUMBER
41156 --Applying Document Currency Code
41157  , p_source_60            IN VARCHAR2
41158 --Accounting Amount
41159  , p_source_61            IN NUMBER
41160 --Distribution Party Identifier
41161  , p_source_62            IN NUMBER
41162 --Distribution Party Site Id
41163  , p_source_63            IN NUMBER
41164 --Distribution Party Type
41165  , p_source_64            IN VARCHAR2
41166 )
41167 IS
41168 
41169 l_component_type              VARCHAR2(80);
41170 l_component_code              VARCHAR2(30);
41171 l_component_type_code         VARCHAR2(1);
41172 l_component_appl_id           INTEGER;
41173 l_amb_context_code            VARCHAR2(30);
41174 l_entity_code                 VARCHAR2(30);
41175 l_event_class_code            VARCHAR2(30);
41176 l_ae_header_id                NUMBER;
41177 l_event_type_code             VARCHAR2(30);
41178 l_line_definition_code        VARCHAR2(30);
41179 l_line_definition_owner_code  VARCHAR2(1);
41180 --
41181 -- adr variables
41182 l_segment                     VARCHAR2(30);
41183 l_ccid                        NUMBER;
41184 l_adr_transaction_coa_id      NUMBER;
41185 l_adr_accounting_coa_id       NUMBER;
41186 l_adr_flexfield_segment_code  VARCHAR2(30);
41187 l_adr_flex_value_set_id       NUMBER;
41188 l_adr_value_type_code         VARCHAR2(30);
41189 l_adr_value_combination_id    NUMBER;
41190 l_adr_value_segment_code      VARCHAR2(30);
41191 
41192 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
41193 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
41194 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
41195 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
41196 
41197 -- 4262811 Variables ------------------------------------------------------------------------------------------
41198 l_entered_amt_idx             NUMBER;
41199 l_accted_amt_idx              NUMBER;
41200 l_acc_rev_flag                VARCHAR2(1);
41201 l_accrual_line_num            NUMBER;
41202 l_tmp_amt                     NUMBER;
41203 l_acc_rev_natural_side_code   VARCHAR2(1);
41204 
41205 l_num_entries                 NUMBER;
41206 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
41207 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
41208 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
41209 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
41210 l_recog_line_1                NUMBER;
41211 l_recog_line_2                NUMBER;
41212 
41213 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
41214 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
41215 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
41216 
41217 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
41218 
41219 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
41220 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
41221 
41222 ---------------------------------------------------------------------------------------------------------------
41223 
41224 
41225 --
41226 -- bulk performance
41227 --
41228 l_balance_type_code           VARCHAR2(1);
41229 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
41230 l_log_module                  VARCHAR2(240);
41231 
41232 --
41233 -- Upgrade strategy
41234 --
41235 l_actual_upg_option           VARCHAR2(1);
41236 l_enc_upg_option           VARCHAR2(1);
41237 
41238 --
41239 BEGIN
41240 --
41241 IF g_log_enabled THEN
41242       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_83';
41243 END IF;
41244 --
41245 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
41246 
41247       trace
41248          (p_msg      => 'BEGIN of AcctLineType_83'
41249          ,p_level    => C_LEVEL_PROCEDURE
41250          ,p_module   => l_log_module);
41251 
41252 END IF;
41253 --
41254 l_component_type             := 'AMB_JLT';
41255 l_component_code             := 'RCT_CURR_ROUND';
41256 l_component_type_code        := 'S';
41257 l_component_appl_id          :=  222;
41258 l_amb_context_code           := 'DEFAULT';
41259 l_entity_code                := 'RECEIPTS';
41260 l_event_class_code           := 'RECEIPT';
41261 l_event_type_code            := 'RECEIPT_ALL';
41262 l_line_definition_owner_code := 'S';
41263 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
41264 --
41265 l_balance_type_code          := 'A';
41266 l_segment                     := NULL;
41267 l_ccid                        := NULL;
41268 l_adr_transaction_coa_id      := NULL;
41269 l_adr_accounting_coa_id       := NULL;
41270 l_adr_flexfield_segment_code  := NULL;
41271 l_adr_flex_value_set_id       := NULL;
41272 l_adr_value_type_code         := NULL;
41273 l_adr_value_combination_id    := NULL;
41274 l_adr_value_segment_code      := NULL;
41275 
41276 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
41277 l_bflow_class_code           := '';    -- 4219869 Business Flow
41278 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
41279 l_budgetary_control_flag     := 'N';
41280 
41281 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
41282 l_bflow_applied_to_amt       := NULL; -- 5132302
41283 l_entered_amt_idx            := NULL;          -- 4262811
41284 l_accted_amt_idx             := NULL;          -- 4262811
41285 l_acc_rev_flag               := NULL;          -- 4262811
41286 l_accrual_line_num           := NULL;          -- 4262811
41287 l_tmp_amt                    := NULL;          -- 4262811
41288 --
41289  
41290 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
41291     l_balance_type_code <> 'B' THEN
41292 IF NVL(p_source_13,'
41293 ') =  'CURR_ROUND' AND 
41294 NVL(p_source_52,'
41295 ') =  'N'
41296  THEN 
41297 
41298    --
41299    XLA_AE_LINES_PKG.SetNewLine;
41300 
41301    p_balance_type_code          := l_balance_type_code;
41302    -- set the flag so later we will know whether the gain loss line needs to be created
41303    
41304    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
41305      p_actual_flag :='A';
41306    END IF;
41307 
41308    --
41309    -- bulk performance
41310    --
41311    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
41312                                       p_header_num   => 0); -- 4262811
41313    --
41314    -- set accounting line options
41315    --
41316    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
41317            p_natural_side_code          => 'C'
41318          , p_gain_or_loss_flag          => 'N'
41319          , p_gl_transfer_mode_code      => 'S'
41320          , p_acct_entry_type_code       => 'A'
41321          , p_switch_side_flag           => 'Y'
41322          , p_merge_duplicate_code       => 'A'
41323          );
41324    --
41325    l_acc_rev_natural_side_code := 'D';  -- 4262811
41326    -- 
41327    --
41328    -- set accounting line type info
41329    --
41330    xla_ae_lines_pkg.SetAcctLineType
41331       (p_component_type             => l_component_type
41332       ,p_event_type_code            => l_event_type_code
41333       ,p_line_definition_owner_code => l_line_definition_owner_code
41334       ,p_line_definition_code       => l_line_definition_code
41335       ,p_accounting_line_code       => l_component_code
41336       ,p_accounting_line_type_code  => l_component_type_code
41337       ,p_accounting_line_appl_id    => l_component_appl_id
41338       ,p_amb_context_code           => l_amb_context_code
41339       ,p_entity_code                => l_entity_code
41340       ,p_event_class_code           => l_event_class_code);
41341    --
41342    -- set accounting class
41343    --
41344    xla_ae_lines_pkg.SetAcctClass(
41345            p_accounting_class_code  => 'ROUNDING'
41346          , p_ae_header_id           => l_ae_header_id
41347          );
41348 
41349    --
41350    -- set rounding class
41351    --
41352    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
41353                       'RECEIVABLE';
41354 
41355    --
41356    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
41357    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
41358    --
41359    -- bulk performance
41360    --
41361    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
41362 
41363    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
41364       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
41365 
41366    -- 4955764
41367    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
41368       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
41369 
41370    -- 4458381 Public Sector Enh
41371    
41372    --
41373    -- set accounting attributes for the line type
41374    --
41375    l_entered_amt_idx := 8;
41376    l_accted_amt_idx  := 13;
41377    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
41378    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
41379    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
41380    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
41381    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
41382    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
41383    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
41384    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
41385    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
41386    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
41387    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
41388    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
41389    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
41390    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
41391    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
41392    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
41393    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
41394    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
41395    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
41396    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
41397    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
41398    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
41399    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
41400    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
41401    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
41402    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
41403    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
41404    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
41405    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
41406    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
41407    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
41408    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
41409    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
41410 
41411    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
41412    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
41413 
41414    ---------------------------------------------------------------------------------------------------------------
41415    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
41416    ---------------------------------------------------------------------------------------------------------------
41417    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
41418 
41419    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
41420    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
41421 
41422    IF xla_accounting_cache_pkg.GetValueChar
41423          (p_source_code         => 'LEDGER_CATEGORY_CODE'
41424          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
41425    AND l_bflow_method_code = 'PRIOR_ENTRY'
41426 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
41427    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
41428          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
41429        )
41430    THEN
41431          xla_ae_lines_pkg.BflowUpgEntry
41432            (p_business_method_code    => l_bflow_method_code
41433            ,p_business_class_code     => l_bflow_class_code
41434            ,p_balance_type            => l_balance_type_code);
41435    ELSE
41436       NULL;
41437 -- No business flow processing for business flow method of NONE.
41438    END IF;
41439 
41440    --
41441    -- call analytical criteria
41442    --
41443    
41444    --
41445    -- call description
41446    --
41447    -- No description or it is inherited.
41448    --
41449    -- call ADRs
41450    -- Bug 4922099
41451    --
41452    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
41453         (NVL(l_actual_upg_option, 'N') = 'O') OR
41454         (NVL(l_enc_upg_option, 'N') = 'O')
41455       )
41456    THEN
41457    NULL;
41458    --
41459    --
41460    
41461   l_ccid := AcctDerRule_7(
41462            p_application_id           => p_application_id
41463          , p_ae_header_id             => l_ae_header_id 
41464 , p_source_3 => p_source_3
41465          , x_transaction_coa_id       => l_adr_transaction_coa_id
41466          , x_accounting_coa_id        => l_adr_accounting_coa_id
41467          , x_value_type_code          => l_adr_value_type_code
41468          , p_side                     => 'NA'
41469    );
41470 
41471    xla_ae_lines_pkg.set_ccid(
41472     p_code_combination_id          => l_ccid
41473   , p_value_type_code              => l_adr_value_type_code
41474   , p_transaction_coa_id           => l_adr_transaction_coa_id
41475   , p_accounting_coa_id            => l_adr_accounting_coa_id
41476   , p_adr_code                     => 'DIST_CCID'
41477   , p_adr_type_code                => 'S'
41478   , p_component_type               => l_component_type
41479   , p_component_code               => l_component_code
41480   , p_component_type_code          => l_component_type_code
41481   , p_component_appl_id            => l_component_appl_id
41482   , p_amb_context_code             => l_amb_context_code
41483   , p_side                         => 'NA'
41484   );
41485 
41486 
41487    --
41488    --
41489    END IF;
41490    --
41491    -- Bug 4922099
41492    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
41493           (NVL(l_enc_upg_option, 'N') = 'O')
41494         ) AND
41495         (l_bflow_method_code = 'PRIOR_ENTRY')
41496       )
41497    THEN
41498       IF
41499       --
41500       1 = 2
41501       --
41502       THEN
41503       xla_accounting_err_pkg.build_message
41504                                     (p_appli_s_name            => 'XLA'
41505                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
41506                                     ,p_token_1                 => 'LINE_NUMBER'
41507                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
41508                                     ,p_token_2                 => 'LINE_TYPE_NAME'
41509                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
41510                                                                              l_component_type
41511                                                                             ,l_component_code
41512                                                                             ,l_component_type_code
41513                                                                             ,l_component_appl_id
41514                                                                             ,l_amb_context_code
41515                                                                             ,l_entity_code
41516                                                                             ,l_event_class_code
41517                                                                            )
41518                                     ,p_token_3                 => 'OWNER'
41519                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
41520                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
41521                                                                           ,p_lookup_code    => l_component_type_code
41522                                                                          )
41523                                     ,p_token_4                 => 'PRODUCT_NAME'
41524                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
41525                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
41526                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
41527                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
41528                                     ,p_ae_header_id            =>  NULL
41529                                        );
41530 
41531         IF (C_LEVEL_ERROR>= g_log_level) THEN
41532                  trace
41533                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
41534                       ,p_level    => C_LEVEL_ERROR
41535                       ,p_module   => l_log_module);
41536         END IF;
41537       END IF;
41538    END IF;
41539    --
41540    --
41541    ------------------------------------------------------------------------------------------------
41542    -- 4219869 Business Flow
41543    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
41544    -- Prior Entry.  Currently, the following code is always generated.
41545    ------------------------------------------------------------------------------------------------
41546    XLA_AE_LINES_PKG.ValidateCurrentLine;
41547 
41548    ------------------------------------------------------------------------------------
41549    -- 4219869 Business Flow
41550    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
41551    ------------------------------------------------------------------------------------
41552    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
41553 
41554    ----------------------------------------------------------------------------------
41555    -- 4219869 Business Flow
41556    -- Update journal entry status -- Need to generate this within IF <condition>
41557    ----------------------------------------------------------------------------------
41558    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
41559          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
41560          ,p_balance_type_code => l_balance_type_code
41561          );
41562 
41563    -------------------------------------------------------------------------------------------
41564    -- 4262811 - Generate the Accrual Reversal lines
41565    -------------------------------------------------------------------------------------------
41566    BEGIN
41567       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
41568                               (g_array_event(p_event_id).array_value_num('header_index'));
41569       IF l_acc_rev_flag IS NULL THEN
41570          l_acc_rev_flag := 'N';
41571       END IF;
41572    EXCEPTION
41573       WHEN OTHERS THEN
41574          l_acc_rev_flag := 'N';
41575    END;
41576    --
41577    IF (l_acc_rev_flag = 'Y') THEN
41578 
41579        -- 4645092  ------------------------------------------------------------------------------
41580        -- To allow MPA report to determine if it should generate report process
41581        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
41582        ------------------------------------------------------------------------------------------
41583 
41584        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
41585        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
41586    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
41587    -- call ADRs
41588    -- Bug 4922099
41589    --
41590    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
41591         (NVL(l_actual_upg_option, 'N') = 'O') OR
41592         (NVL(l_enc_upg_option, 'N') = 'O')
41593       )
41594    THEN
41595    NULL;
41596    --
41597    --
41598    
41599   l_ccid := AcctDerRule_7(
41600            p_application_id           => p_application_id
41601          , p_ae_header_id             => l_ae_header_id 
41602 , p_source_3 => p_source_3
41603          , x_transaction_coa_id       => l_adr_transaction_coa_id
41604          , x_accounting_coa_id        => l_adr_accounting_coa_id
41605          , x_value_type_code          => l_adr_value_type_code
41606          , p_side                     => 'NA'
41607    );
41608 
41609    xla_ae_lines_pkg.set_ccid(
41610     p_code_combination_id          => l_ccid
41611   , p_value_type_code              => l_adr_value_type_code
41612   , p_transaction_coa_id           => l_adr_transaction_coa_id
41613   , p_accounting_coa_id            => l_adr_accounting_coa_id
41614   , p_adr_code                     => 'DIST_CCID'
41615   , p_adr_type_code                => 'S'
41616   , p_component_type               => l_component_type
41617   , p_component_code               => l_component_code
41618   , p_component_type_code          => l_component_type_code
41619   , p_component_appl_id            => l_component_appl_id
41620   , p_amb_context_code             => l_amb_context_code
41621   , p_side                         => 'NA'
41622   );
41623 
41624 
41625    --
41626    --
41627    END IF;
41628 
41629        --
41630        -- Update the line information that should be overwritten
41631        --
41632        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
41633                                          p_header_num   => 1);
41634        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
41635 
41636        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
41637 
41638        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
41639           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
41640        END IF;
41641 
41642       --
41643       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
41644       --
41645       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
41646           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
41647       ELSE
41648           ---------------------------------------------------------------------------------------------------
41649           -- 4262811a Switch Sign
41650           ---------------------------------------------------------------------------------------------------
41651           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
41652           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
41653                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
41654           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
41655                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
41656           -- 5132302
41657           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
41658                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
41659 
41660       END IF;
41661 
41662       -- 4955764
41663       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
41664       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
41665 
41666 
41667       XLA_AE_LINES_PKG.ValidateCurrentLine;
41668       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
41669 
41670       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
41671                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
41672                ,p_balance_type_code => l_balance_type_code);
41673 
41674    END IF;
41675 
41676    -----------------------------------------------------------------------------------------
41677    -- 4262811 Multiperiod Accounting
41678    -----------------------------------------------------------------------------------------
41679      -- No MPA option is assigned.
41680 
41681 
41682 END IF;
41683 END IF;
41684 --
41685 
41686 --
41687 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
41688    trace
41689       (p_msg      => 'END of AcctLineType_83'
41690       ,p_level    => C_LEVEL_PROCEDURE
41691       ,p_module   => l_log_module);
41692 END IF;
41693 --
41694 EXCEPTION
41695   WHEN xla_exceptions_pkg.application_exception THEN
41696       RAISE;
41697   WHEN OTHERS THEN
41698        xla_exceptions_pkg.raise_message
41699            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_83');
41700 END AcctLineType_83;
41701 --
41702 
41703 ---------------------------------------
41704 --
41705 -- PRIVATE FUNCTION
41706 --         AcctLineType_84
41707 --
41708 ---------------------------------------
41709 PROCEDURE AcctLineType_84 (
41710   p_application_id        IN NUMBER
41711  ,p_event_id              IN NUMBER
41712  ,p_calculate_acctd_flag  IN VARCHAR2
41713  ,p_calculate_g_l_flag    IN VARCHAR2
41714  ,p_actual_flag           IN OUT VARCHAR2
41715  ,p_balance_type_code     OUT VARCHAR2
41716  ,p_gain_or_loss_ref      OUT VARCHAR2
41717  
41718 --Distribution GL Account
41719  , p_source_3            IN NUMBER
41720 --Distribution Source Type
41721  , p_source_13            IN VARCHAR2
41722 --Distribution Line Identifier
41723  , p_source_15            IN NUMBER
41724 --Distribution Type
41725  , p_source_16            IN VARCHAR2
41726 --Exchange Date
41727  , p_source_19            IN DATE
41728 --Exchange Rate
41729  , p_source_20            IN NUMBER
41730 --Exchange Rate Type
41731  , p_source_21            IN VARCHAR2
41732 --Transaction Distribution Identifier
41733  , p_source_27            IN NUMBER
41734 --Transaction Distribution Type
41735  , p_source_28            IN VARCHAR2
41736 --Distribution Multi Fund Additional Entry
41737  , p_source_52            IN VARCHAR2
41738 --Receipt Applied To Application Identifier
41739  , p_source_56            IN NUMBER
41740 --Transaction Entity Code
41741  , p_source_57            IN VARCHAR2
41742 --Transaction Identifier
41743  , p_source_58            IN NUMBER
41744 --DIST_ENT_AMT_FROM
41745  , p_source_59            IN NUMBER
41746 --Applying Document Currency Code
41747  , p_source_60            IN VARCHAR2
41748 --Accounting Amount
41749  , p_source_61            IN NUMBER
41750 --Distribution Party Identifier
41751  , p_source_62            IN NUMBER
41752 --Distribution Party Site Id
41753  , p_source_63            IN NUMBER
41754 --Distribution Party Type
41755  , p_source_64            IN VARCHAR2
41756 )
41757 IS
41758 
41759 l_component_type              VARCHAR2(80);
41760 l_component_code              VARCHAR2(30);
41761 l_component_type_code         VARCHAR2(1);
41762 l_component_appl_id           INTEGER;
41763 l_amb_context_code            VARCHAR2(30);
41764 l_entity_code                 VARCHAR2(30);
41765 l_event_class_code            VARCHAR2(30);
41766 l_ae_header_id                NUMBER;
41767 l_event_type_code             VARCHAR2(30);
41768 l_line_definition_code        VARCHAR2(30);
41769 l_line_definition_owner_code  VARCHAR2(1);
41770 --
41771 -- adr variables
41772 l_segment                     VARCHAR2(30);
41773 l_ccid                        NUMBER;
41774 l_adr_transaction_coa_id      NUMBER;
41775 l_adr_accounting_coa_id       NUMBER;
41776 l_adr_flexfield_segment_code  VARCHAR2(30);
41777 l_adr_flex_value_set_id       NUMBER;
41778 l_adr_value_type_code         VARCHAR2(30);
41779 l_adr_value_combination_id    NUMBER;
41780 l_adr_value_segment_code      VARCHAR2(30);
41781 
41782 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
41783 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
41784 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
41785 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
41786 
41787 -- 4262811 Variables ------------------------------------------------------------------------------------------
41788 l_entered_amt_idx             NUMBER;
41789 l_accted_amt_idx              NUMBER;
41790 l_acc_rev_flag                VARCHAR2(1);
41791 l_accrual_line_num            NUMBER;
41792 l_tmp_amt                     NUMBER;
41793 l_acc_rev_natural_side_code   VARCHAR2(1);
41794 
41795 l_num_entries                 NUMBER;
41796 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
41797 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
41798 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
41799 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
41800 l_recog_line_1                NUMBER;
41801 l_recog_line_2                NUMBER;
41802 
41806 
41803 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
41804 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
41805 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
41807 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
41808 
41809 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
41810 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
41811 
41812 ---------------------------------------------------------------------------------------------------------------
41813 
41814 
41815 --
41816 -- bulk performance
41817 --
41818 l_balance_type_code           VARCHAR2(1);
41819 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
41820 l_log_module                  VARCHAR2(240);
41821 
41822 --
41823 -- Upgrade strategy
41824 --
41825 l_actual_upg_option           VARCHAR2(1);
41826 l_enc_upg_option           VARCHAR2(1);
41827 
41828 --
41829 BEGIN
41830 --
41831 IF g_log_enabled THEN
41832       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_84';
41833 END IF;
41834 --
41835 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
41836 
41837       trace
41838          (p_msg      => 'BEGIN of AcctLineType_84'
41839          ,p_level    => C_LEVEL_PROCEDURE
41840          ,p_module   => l_log_module);
41841 
41842 END IF;
41843 --
41844 l_component_type             := 'AMB_JLT';
41845 l_component_code             := 'RCT_DEBT';
41846 l_component_type_code        := 'S';
41847 l_component_appl_id          :=  222;
41848 l_amb_context_code           := 'DEFAULT';
41849 l_entity_code                := 'RECEIPTS';
41850 l_event_class_code           := 'RECEIPT';
41851 l_event_type_code            := 'RECEIPT_ALL';
41852 l_line_definition_owner_code := 'S';
41853 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
41854 --
41855 l_balance_type_code          := 'A';
41856 l_segment                     := NULL;
41857 l_ccid                        := NULL;
41858 l_adr_transaction_coa_id      := NULL;
41859 l_adr_accounting_coa_id       := NULL;
41860 l_adr_flexfield_segment_code  := NULL;
41861 l_adr_flex_value_set_id       := NULL;
41862 l_adr_value_type_code         := NULL;
41863 l_adr_value_combination_id    := NULL;
41864 l_adr_value_segment_code      := NULL;
41865 
41866 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
41867 l_bflow_class_code           := '';    -- 4219869 Business Flow
41868 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
41869 l_budgetary_control_flag     := 'N';
41870 
41871 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
41872 l_bflow_applied_to_amt       := NULL; -- 5132302
41873 l_entered_amt_idx            := NULL;          -- 4262811
41874 l_accted_amt_idx             := NULL;          -- 4262811
41875 l_acc_rev_flag               := NULL;          -- 4262811
41876 l_accrual_line_num           := NULL;          -- 4262811
41877 l_tmp_amt                    := NULL;          -- 4262811
41878 --
41879  
41880 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
41881     l_balance_type_code <> 'B' THEN
41882 IF NVL(p_source_13,'
41883 ') =  'SHORT_TERM_DEBT' AND 
41884 NVL(p_source_52,'
41885 ') =  'N'
41886  THEN 
41887 
41888    --
41889    XLA_AE_LINES_PKG.SetNewLine;
41890 
41891    p_balance_type_code          := l_balance_type_code;
41892    -- set the flag so later we will know whether the gain loss line needs to be created
41893    
41894    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
41895      p_actual_flag :='A';
41896    END IF;
41897 
41898    --
41899    -- bulk performance
41900    --
41901    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
41902                                       p_header_num   => 0); -- 4262811
41903    --
41904    -- set accounting line options
41905    --
41906    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
41907            p_natural_side_code          => 'C'
41908          , p_gain_or_loss_flag          => 'N'
41909          , p_gl_transfer_mode_code      => 'S'
41910          , p_acct_entry_type_code       => 'A'
41911          , p_switch_side_flag           => 'Y'
41912          , p_merge_duplicate_code       => 'A'
41913          );
41914    --
41915    l_acc_rev_natural_side_code := 'D';  -- 4262811
41916    -- 
41917    --
41918    -- set accounting line type info
41919    --
41920    xla_ae_lines_pkg.SetAcctLineType
41921       (p_component_type             => l_component_type
41922       ,p_event_type_code            => l_event_type_code
41923       ,p_line_definition_owner_code => l_line_definition_owner_code
41924       ,p_line_definition_code       => l_line_definition_code
41925       ,p_accounting_line_code       => l_component_code
41926       ,p_accounting_line_type_code  => l_component_type_code
41927       ,p_accounting_line_appl_id    => l_component_appl_id
41928       ,p_amb_context_code           => l_amb_context_code
41929       ,p_entity_code                => l_entity_code
41930       ,p_event_class_code           => l_event_class_code);
41931    --
41932    -- set accounting class
41933    --
41934    xla_ae_lines_pkg.SetAcctClass(
41935            p_accounting_class_code  => 'SHORT_TERM_DEBT'
41936          , p_ae_header_id           => l_ae_header_id
41940    -- set rounding class
41937          );
41938 
41939    --
41941    --
41942    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
41943                       'RECEIVABLE';
41944 
41945    --
41946    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
41947    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
41948    --
41949    -- bulk performance
41950    --
41951    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
41952 
41953    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
41954       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
41955 
41956    -- 4955764
41957    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
41958       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
41959 
41960    -- 4458381 Public Sector Enh
41961    
41962    --
41963    -- set accounting attributes for the line type
41964    --
41965    l_entered_amt_idx := 8;
41966    l_accted_amt_idx  := 13;
41967    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
41968    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
41969    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
41970    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
41971    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
41972    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
41973    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
41974    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
41975    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
41976    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
41977    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
41978    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
41979    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
41980    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
41981    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
41982    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
41983    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
41984    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
41985    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
41986    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
41987    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
41988    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
41989    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
41990    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
41991    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
41992    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
41993    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
41994    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
41995    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
41996    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
41997    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
41998    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
41999    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
42000 
42001    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
42002    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
42003 
42004    ---------------------------------------------------------------------------------------------------------------
42005    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
42006    ---------------------------------------------------------------------------------------------------------------
42007    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
42008 
42009    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
42010    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
42011 
42012    IF xla_accounting_cache_pkg.GetValueChar
42013          (p_source_code         => 'LEDGER_CATEGORY_CODE'
42014          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
42015    AND l_bflow_method_code = 'PRIOR_ENTRY'
42016 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
42017    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
42018          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
42019        )
42020    THEN
42021          xla_ae_lines_pkg.BflowUpgEntry
42022            (p_business_method_code    => l_bflow_method_code
42023            ,p_business_class_code     => l_bflow_class_code
42024            ,p_balance_type            => l_balance_type_code);
42025    ELSE
42026       NULL;
42027 -- No business flow processing for business flow method of NONE.
42028    END IF;
42029 
42030    --
42031    -- call analytical criteria
42032    --
42033    
42034    --
42035    -- call description
42036    --
42037    -- No description or it is inherited.
42038    --
42039    -- call ADRs
42040    -- Bug 4922099
42041    --
42042    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
42043         (NVL(l_actual_upg_option, 'N') = 'O') OR
42044         (NVL(l_enc_upg_option, 'N') = 'O')
42045       )
42046    THEN
42047    NULL;
42048    --
42049    --
42050    
42051   l_ccid := AcctDerRule_7(
42052            p_application_id           => p_application_id
42053          , p_ae_header_id             => l_ae_header_id 
42054 , p_source_3 => p_source_3
42055          , x_transaction_coa_id       => l_adr_transaction_coa_id
42056          , x_accounting_coa_id        => l_adr_accounting_coa_id
42057          , x_value_type_code          => l_adr_value_type_code
42058          , p_side                     => 'NA'
42059    );
42060 
42061    xla_ae_lines_pkg.set_ccid(
42062     p_code_combination_id          => l_ccid
42063   , p_value_type_code              => l_adr_value_type_code
42064   , p_transaction_coa_id           => l_adr_transaction_coa_id
42065   , p_accounting_coa_id            => l_adr_accounting_coa_id
42066   , p_adr_code                     => 'DIST_CCID'
42067   , p_adr_type_code                => 'S'
42068   , p_component_type               => l_component_type
42069   , p_component_code               => l_component_code
42070   , p_component_type_code          => l_component_type_code
42071   , p_component_appl_id            => l_component_appl_id
42072   , p_amb_context_code             => l_amb_context_code
42073   , p_side                         => 'NA'
42074   );
42075 
42076 
42077    --
42078    --
42079    END IF;
42080    --
42081    -- Bug 4922099
42082    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
42083           (NVL(l_enc_upg_option, 'N') = 'O')
42084         ) AND
42085         (l_bflow_method_code = 'PRIOR_ENTRY')
42086       )
42087    THEN
42088       IF
42089       --
42090       1 = 2
42091       --
42092       THEN
42093       xla_accounting_err_pkg.build_message
42094                                     (p_appli_s_name            => 'XLA'
42095                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
42096                                     ,p_token_1                 => 'LINE_NUMBER'
42097                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
42098                                     ,p_token_2                 => 'LINE_TYPE_NAME'
42099                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
42100                                                                              l_component_type
42101                                                                             ,l_component_code
42102                                                                             ,l_component_type_code
42103                                                                             ,l_component_appl_id
42104                                                                             ,l_amb_context_code
42105                                                                             ,l_entity_code
42106                                                                             ,l_event_class_code
42107                                                                            )
42108                                     ,p_token_3                 => 'OWNER'
42109                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
42110                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
42111                                                                           ,p_lookup_code    => l_component_type_code
42112                                                                          )
42113                                     ,p_token_4                 => 'PRODUCT_NAME'
42114                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
42115                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
42116                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
42117                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
42118                                     ,p_ae_header_id            =>  NULL
42122                  trace
42119                                        );
42120 
42121         IF (C_LEVEL_ERROR>= g_log_level) THEN
42123                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
42124                       ,p_level    => C_LEVEL_ERROR
42125                       ,p_module   => l_log_module);
42126         END IF;
42127       END IF;
42128    END IF;
42129    --
42130    --
42131    ------------------------------------------------------------------------------------------------
42132    -- 4219869 Business Flow
42133    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
42134    -- Prior Entry.  Currently, the following code is always generated.
42135    ------------------------------------------------------------------------------------------------
42136    XLA_AE_LINES_PKG.ValidateCurrentLine;
42137 
42138    ------------------------------------------------------------------------------------
42139    -- 4219869 Business Flow
42140    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
42141    ------------------------------------------------------------------------------------
42142    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
42143 
42144    ----------------------------------------------------------------------------------
42145    -- 4219869 Business Flow
42146    -- Update journal entry status -- Need to generate this within IF <condition>
42147    ----------------------------------------------------------------------------------
42148    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
42149          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
42150          ,p_balance_type_code => l_balance_type_code
42151          );
42152 
42153    -------------------------------------------------------------------------------------------
42154    -- 4262811 - Generate the Accrual Reversal lines
42155    -------------------------------------------------------------------------------------------
42156    BEGIN
42157       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
42158                               (g_array_event(p_event_id).array_value_num('header_index'));
42159       IF l_acc_rev_flag IS NULL THEN
42160          l_acc_rev_flag := 'N';
42161       END IF;
42162    EXCEPTION
42163       WHEN OTHERS THEN
42164          l_acc_rev_flag := 'N';
42165    END;
42166    --
42167    IF (l_acc_rev_flag = 'Y') THEN
42168 
42169        -- 4645092  ------------------------------------------------------------------------------
42170        -- To allow MPA report to determine if it should generate report process
42171        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
42172        ------------------------------------------------------------------------------------------
42173 
42174        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
42175        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
42176    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
42177    -- call ADRs
42178    -- Bug 4922099
42179    --
42180    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
42181         (NVL(l_actual_upg_option, 'N') = 'O') OR
42182         (NVL(l_enc_upg_option, 'N') = 'O')
42183       )
42184    THEN
42185    NULL;
42186    --
42187    --
42188    
42189   l_ccid := AcctDerRule_7(
42190            p_application_id           => p_application_id
42191          , p_ae_header_id             => l_ae_header_id 
42192 , p_source_3 => p_source_3
42193          , x_transaction_coa_id       => l_adr_transaction_coa_id
42194          , x_accounting_coa_id        => l_adr_accounting_coa_id
42195          , x_value_type_code          => l_adr_value_type_code
42196          , p_side                     => 'NA'
42197    );
42198 
42199    xla_ae_lines_pkg.set_ccid(
42200     p_code_combination_id          => l_ccid
42201   , p_value_type_code              => l_adr_value_type_code
42202   , p_transaction_coa_id           => l_adr_transaction_coa_id
42203   , p_accounting_coa_id            => l_adr_accounting_coa_id
42204   , p_adr_code                     => 'DIST_CCID'
42205   , p_adr_type_code                => 'S'
42206   , p_component_type               => l_component_type
42207   , p_component_code               => l_component_code
42208   , p_component_type_code          => l_component_type_code
42209   , p_component_appl_id            => l_component_appl_id
42210   , p_amb_context_code             => l_amb_context_code
42211   , p_side                         => 'NA'
42212   );
42213 
42214 
42215    --
42216    --
42217    END IF;
42218 
42219        --
42220        -- Update the line information that should be overwritten
42221        --
42222        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
42223                                          p_header_num   => 1);
42224        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
42225 
42226        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
42227 
42228        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
42229           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
42230        END IF;
42231 
42232       --
42233       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
42234       --
42235       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
42236           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
42237       ELSE
42238           ---------------------------------------------------------------------------------------------------
42239           -- 4262811a Switch Sign
42240           ---------------------------------------------------------------------------------------------------
42241           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
42242           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
42243                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
42244           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
42245                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
42246           -- 5132302
42247           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
42248                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
42249 
42250       END IF;
42251 
42252       -- 4955764
42253       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
42254       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
42255 
42256 
42257       XLA_AE_LINES_PKG.ValidateCurrentLine;
42258       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
42259 
42260       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
42261                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
42262                ,p_balance_type_code => l_balance_type_code);
42263 
42264    END IF;
42265 
42266    -----------------------------------------------------------------------------------------
42267    -- 4262811 Multiperiod Accounting
42268    -----------------------------------------------------------------------------------------
42269      -- No MPA option is assigned.
42270 
42271 
42272 END IF;
42273 END IF;
42274 --
42275 
42276 --
42277 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
42278    trace
42279       (p_msg      => 'END of AcctLineType_84'
42280       ,p_level    => C_LEVEL_PROCEDURE
42281       ,p_module   => l_log_module);
42282 END IF;
42283 --
42284 EXCEPTION
42285   WHEN xla_exceptions_pkg.application_exception THEN
42286       RAISE;
42287   WHEN OTHERS THEN
42288        xla_exceptions_pkg.raise_message
42289            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_84');
42290 END AcctLineType_84;
42291 --
42292 
42293 ---------------------------------------
42294 --
42295 -- PRIVATE FUNCTION
42296 --         AcctLineType_85
42297 --
42298 ---------------------------------------
42299 PROCEDURE AcctLineType_85 (
42300   p_application_id        IN NUMBER
42301  ,p_event_id              IN NUMBER
42302  ,p_calculate_acctd_flag  IN VARCHAR2
42303  ,p_calculate_g_l_flag    IN VARCHAR2
42304  ,p_actual_flag           IN OUT VARCHAR2
42305  ,p_balance_type_code     OUT VARCHAR2
42306  ,p_gain_or_loss_ref      OUT VARCHAR2
42307  
42308 --Distribution GL Account
42309  , p_source_3            IN NUMBER
42310 --Distribution Source Type
42311  , p_source_13            IN VARCHAR2
42312 --Distribution Line Identifier
42313  , p_source_15            IN NUMBER
42314 --Distribution Type
42315  , p_source_16            IN VARCHAR2
42316 --Entered Amount
42317  , p_source_17            IN NUMBER
42318 --Currency Code
42319  , p_source_18            IN VARCHAR2
42320 --Applied To Document Accounting Amount
42321  , p_source_22            IN NUMBER
42322 --Transaction Distribution Identifier
42323  , p_source_27            IN NUMBER
42324 --Transaction Distribution Type
42325  , p_source_28            IN VARCHAR2
42326 --Distribution Multi Fund Additional Entry
42327  , p_source_52            IN VARCHAR2
42328 --Applied To Document Exchange Date
42329  , p_source_53            IN DATE
42330 --Receipt Applied To Application Identifier
42331  , p_source_56            IN NUMBER
42332 --Transaction Entity Code
42333  , p_source_57            IN VARCHAR2
42334 --Transaction Identifier
42335  , p_source_58            IN NUMBER
42336 --Distribution Party Identifier
42337  , p_source_62            IN NUMBER
42338 --Distribution Party Site Id
42339  , p_source_63            IN NUMBER
42340 --Distribution Party Type
42344 --Applied To Document Exchange Rate
42341  , p_source_64            IN VARCHAR2
42342 --Applied To Document Exchange Rate Type
42343  , p_source_65            IN VARCHAR2
42345  , p_source_66            IN NUMBER
42346 )
42347 IS
42348 
42349 l_component_type              VARCHAR2(80);
42350 l_component_code              VARCHAR2(30);
42351 l_component_type_code         VARCHAR2(1);
42352 l_component_appl_id           INTEGER;
42353 l_amb_context_code            VARCHAR2(30);
42354 l_entity_code                 VARCHAR2(30);
42355 l_event_class_code            VARCHAR2(30);
42356 l_ae_header_id                NUMBER;
42357 l_event_type_code             VARCHAR2(30);
42358 l_line_definition_code        VARCHAR2(30);
42359 l_line_definition_owner_code  VARCHAR2(1);
42360 --
42361 -- adr variables
42362 l_segment                     VARCHAR2(30);
42363 l_ccid                        NUMBER;
42364 l_adr_transaction_coa_id      NUMBER;
42365 l_adr_accounting_coa_id       NUMBER;
42366 l_adr_flexfield_segment_code  VARCHAR2(30);
42367 l_adr_flex_value_set_id       NUMBER;
42368 l_adr_value_type_code         VARCHAR2(30);
42369 l_adr_value_combination_id    NUMBER;
42370 l_adr_value_segment_code      VARCHAR2(30);
42371 
42372 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
42373 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
42374 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
42375 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
42376 
42377 -- 4262811 Variables ------------------------------------------------------------------------------------------
42378 l_entered_amt_idx             NUMBER;
42379 l_accted_amt_idx              NUMBER;
42380 l_acc_rev_flag                VARCHAR2(1);
42381 l_accrual_line_num            NUMBER;
42382 l_tmp_amt                     NUMBER;
42383 l_acc_rev_natural_side_code   VARCHAR2(1);
42384 
42385 l_num_entries                 NUMBER;
42386 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
42387 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
42388 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
42389 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
42390 l_recog_line_1                NUMBER;
42391 l_recog_line_2                NUMBER;
42392 
42393 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
42394 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
42395 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
42396 
42397 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
42398 
42399 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
42400 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
42401 
42402 ---------------------------------------------------------------------------------------------------------------
42403 
42404 
42405 --
42406 -- bulk performance
42407 --
42408 l_balance_type_code           VARCHAR2(1);
42409 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
42410 l_log_module                  VARCHAR2(240);
42411 
42412 --
42413 -- Upgrade strategy
42414 --
42415 l_actual_upg_option           VARCHAR2(1);
42416 l_enc_upg_option           VARCHAR2(1);
42417 
42418 --
42419 BEGIN
42420 --
42421 IF g_log_enabled THEN
42422       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_85';
42423 END IF;
42424 --
42425 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
42426 
42427       trace
42428          (p_msg      => 'BEGIN of AcctLineType_85'
42429          ,p_level    => C_LEVEL_PROCEDURE
42430          ,p_module   => l_log_module);
42431 
42432 END IF;
42433 --
42434 l_component_type             := 'AMB_JLT';
42435 l_component_code             := 'RCT_DEFERRED_TAX';
42436 l_component_type_code        := 'S';
42437 l_component_appl_id          :=  222;
42438 l_amb_context_code           := 'DEFAULT';
42439 l_entity_code                := 'RECEIPTS';
42440 l_event_class_code           := 'RECEIPT';
42441 l_event_type_code            := 'RECEIPT_ALL';
42442 l_line_definition_owner_code := 'S';
42443 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
42444 --
42445 l_balance_type_code          := 'A';
42446 l_segment                     := NULL;
42447 l_ccid                        := NULL;
42448 l_adr_transaction_coa_id      := NULL;
42449 l_adr_accounting_coa_id       := NULL;
42450 l_adr_flexfield_segment_code  := NULL;
42451 l_adr_flex_value_set_id       := NULL;
42452 l_adr_value_type_code         := NULL;
42453 l_adr_value_combination_id    := NULL;
42454 l_adr_value_segment_code      := NULL;
42455 
42456 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
42457 l_bflow_class_code           := '';    -- 4219869 Business Flow
42458 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
42459 l_budgetary_control_flag     := 'N';
42460 
42461 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
42462 l_bflow_applied_to_amt       := NULL; -- 5132302
42463 l_entered_amt_idx            := NULL;          -- 4262811
42464 l_accted_amt_idx             := NULL;          -- 4262811
42465 l_acc_rev_flag               := NULL;          -- 4262811
42466 l_accrual_line_num           := NULL;          -- 4262811
42467 l_tmp_amt                    := NULL;          -- 4262811
42468 --
42469  
42470 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
42471     l_balance_type_code <> 'B' THEN
42472 IF NVL(p_source_13,'
42473 ') =  'DEFERRED_TAX' AND 
42477 
42474 NVL(p_source_52,'
42475 ') =  'N'
42476  THEN 
42478    --
42479    XLA_AE_LINES_PKG.SetNewLine;
42480 
42481    p_balance_type_code          := l_balance_type_code;
42482    -- set the flag so later we will know whether the gain loss line needs to be created
42483    
42484    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
42485      p_actual_flag :='A';
42486    END IF;
42487 
42488    --
42489    -- bulk performance
42490    --
42491    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
42492                                       p_header_num   => 0); -- 4262811
42493    --
42494    -- set accounting line options
42495    --
42496    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
42497            p_natural_side_code          => 'C'
42498          , p_gain_or_loss_flag          => 'N'
42499          , p_gl_transfer_mode_code      => 'S'
42500          , p_acct_entry_type_code       => 'A'
42501          , p_switch_side_flag           => 'Y'
42502          , p_merge_duplicate_code       => 'A'
42503          );
42504    --
42505    l_acc_rev_natural_side_code := 'D';  -- 4262811
42506    -- 
42507    --
42508    -- set accounting line type info
42509    --
42510    xla_ae_lines_pkg.SetAcctLineType
42511       (p_component_type             => l_component_type
42512       ,p_event_type_code            => l_event_type_code
42513       ,p_line_definition_owner_code => l_line_definition_owner_code
42514       ,p_line_definition_code       => l_line_definition_code
42515       ,p_accounting_line_code       => l_component_code
42516       ,p_accounting_line_type_code  => l_component_type_code
42517       ,p_accounting_line_appl_id    => l_component_appl_id
42518       ,p_amb_context_code           => l_amb_context_code
42519       ,p_entity_code                => l_entity_code
42520       ,p_event_class_code           => l_event_class_code);
42521    --
42522    -- set accounting class
42523    --
42524    xla_ae_lines_pkg.SetAcctClass(
42525            p_accounting_class_code  => 'DEFERRED_TAX'
42526          , p_ae_header_id           => l_ae_header_id
42527          );
42528 
42529    --
42530    -- set rounding class
42531    --
42532    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
42533                       'RECEIVABLE';
42534 
42535    --
42536    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
42537    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
42538    --
42539    -- bulk performance
42540    --
42541    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
42542 
42543    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
42544       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
42545 
42546    -- 4955764
42547    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
42548       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
42549 
42550    -- 4458381 Public Sector Enh
42551    
42552    --
42553    -- set accounting attributes for the line type
42554    --
42555    l_entered_amt_idx := 8;
42556    l_accted_amt_idx  := 13;
42557    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
42558    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
42559    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
42560    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
42561    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
42562    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
42563    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
42564    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
42565    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
42566    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
42567    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
42568    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
42569    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
42570    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
42574    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
42571    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
42572    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
42573    l_rec_acct_attrs.array_num_value(8)  := p_source_17;
42575    l_rec_acct_attrs.array_char_value(9)  := p_source_18;
42576    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
42577    l_rec_acct_attrs.array_date_value(10)  := p_source_53;
42578    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
42579    l_rec_acct_attrs.array_num_value(11)  := p_source_66;
42580    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
42581    l_rec_acct_attrs.array_char_value(12)  := p_source_65;
42582    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
42583    l_rec_acct_attrs.array_num_value(13)  := p_source_22;
42584    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
42585    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
42586    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
42587    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
42588    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
42589    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
42590 
42591    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
42592    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
42593 
42594    ---------------------------------------------------------------------------------------------------------------
42595    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
42596    ---------------------------------------------------------------------------------------------------------------
42597    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
42598 
42599    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
42600    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
42601 
42602    IF xla_accounting_cache_pkg.GetValueChar
42603          (p_source_code         => 'LEDGER_CATEGORY_CODE'
42604          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
42605    AND l_bflow_method_code = 'PRIOR_ENTRY'
42606 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
42607    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
42608          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
42609        )
42610    THEN
42611          xla_ae_lines_pkg.BflowUpgEntry
42612            (p_business_method_code    => l_bflow_method_code
42613            ,p_business_class_code     => l_bflow_class_code
42614            ,p_balance_type            => l_balance_type_code);
42615    ELSE
42616       NULL;
42617 -- No business flow processing for business flow method of NONE.
42618    END IF;
42619 
42620    --
42621    -- call analytical criteria
42622    --
42623    
42624    --
42625    -- call description
42626    --
42627    -- No description or it is inherited.
42628    --
42629    -- call ADRs
42630    -- Bug 4922099
42631    --
42632    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
42633         (NVL(l_actual_upg_option, 'N') = 'O') OR
42634         (NVL(l_enc_upg_option, 'N') = 'O')
42635       )
42636    THEN
42637    NULL;
42638    --
42639    --
42640    
42641   l_ccid := AcctDerRule_7(
42642            p_application_id           => p_application_id
42643          , p_ae_header_id             => l_ae_header_id 
42644 , p_source_3 => p_source_3
42645          , x_transaction_coa_id       => l_adr_transaction_coa_id
42646          , x_accounting_coa_id        => l_adr_accounting_coa_id
42647          , x_value_type_code          => l_adr_value_type_code
42648          , p_side                     => 'NA'
42649    );
42650 
42651    xla_ae_lines_pkg.set_ccid(
42652     p_code_combination_id          => l_ccid
42653   , p_value_type_code              => l_adr_value_type_code
42654   , p_transaction_coa_id           => l_adr_transaction_coa_id
42655   , p_accounting_coa_id            => l_adr_accounting_coa_id
42656   , p_adr_code                     => 'DIST_CCID'
42657   , p_adr_type_code                => 'S'
42658   , p_component_type               => l_component_type
42659   , p_component_code               => l_component_code
42660   , p_component_type_code          => l_component_type_code
42661   , p_component_appl_id            => l_component_appl_id
42662   , p_amb_context_code             => l_amb_context_code
42663   , p_side                         => 'NA'
42664   );
42665 
42666 
42667    --
42668    --
42669    END IF;
42670    --
42671    -- Bug 4922099
42672    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
42673           (NVL(l_enc_upg_option, 'N') = 'O')
42674         ) AND
42675         (l_bflow_method_code = 'PRIOR_ENTRY')
42676       )
42677    THEN
42678       IF
42679       --
42680       1 = 2
42681       --
42682       THEN
42683       xla_accounting_err_pkg.build_message
42684                                     (p_appli_s_name            => 'XLA'
42685                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
42686                                     ,p_token_1                 => 'LINE_NUMBER'
42687                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
42688                                     ,p_token_2                 => 'LINE_TYPE_NAME'
42689                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
42693                                                                             ,l_component_appl_id
42690                                                                              l_component_type
42691                                                                             ,l_component_code
42692                                                                             ,l_component_type_code
42694                                                                             ,l_amb_context_code
42695                                                                             ,l_entity_code
42696                                                                             ,l_event_class_code
42697                                                                            )
42698                                     ,p_token_3                 => 'OWNER'
42699                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
42700                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
42701                                                                           ,p_lookup_code    => l_component_type_code
42702                                                                          )
42703                                     ,p_token_4                 => 'PRODUCT_NAME'
42704                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
42705                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
42706                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
42707                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
42708                                     ,p_ae_header_id            =>  NULL
42709                                        );
42710 
42711         IF (C_LEVEL_ERROR>= g_log_level) THEN
42712                  trace
42713                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
42714                       ,p_level    => C_LEVEL_ERROR
42715                       ,p_module   => l_log_module);
42716         END IF;
42717       END IF;
42718    END IF;
42719    --
42720    --
42721    ------------------------------------------------------------------------------------------------
42722    -- 4219869 Business Flow
42723    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
42724    -- Prior Entry.  Currently, the following code is always generated.
42725    ------------------------------------------------------------------------------------------------
42726    XLA_AE_LINES_PKG.ValidateCurrentLine;
42727 
42728    ------------------------------------------------------------------------------------
42729    -- 4219869 Business Flow
42730    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
42731    ------------------------------------------------------------------------------------
42732    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
42733 
42734    ----------------------------------------------------------------------------------
42735    -- 4219869 Business Flow
42736    -- Update journal entry status -- Need to generate this within IF <condition>
42737    ----------------------------------------------------------------------------------
42738    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
42739          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
42740          ,p_balance_type_code => l_balance_type_code
42741          );
42742 
42743    -------------------------------------------------------------------------------------------
42744    -- 4262811 - Generate the Accrual Reversal lines
42745    -------------------------------------------------------------------------------------------
42746    BEGIN
42747       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
42748                               (g_array_event(p_event_id).array_value_num('header_index'));
42749       IF l_acc_rev_flag IS NULL THEN
42750          l_acc_rev_flag := 'N';
42751       END IF;
42752    EXCEPTION
42753       WHEN OTHERS THEN
42754          l_acc_rev_flag := 'N';
42755    END;
42756    --
42757    IF (l_acc_rev_flag = 'Y') THEN
42758 
42759        -- 4645092  ------------------------------------------------------------------------------
42760        -- To allow MPA report to determine if it should generate report process
42761        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
42762        ------------------------------------------------------------------------------------------
42763 
42764        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
42765        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
42766    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
42767    -- call ADRs
42768    -- Bug 4922099
42769    --
42770    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
42771         (NVL(l_actual_upg_option, 'N') = 'O') OR
42772         (NVL(l_enc_upg_option, 'N') = 'O')
42773       )
42774    THEN
42775    NULL;
42776    --
42777    --
42778    
42779   l_ccid := AcctDerRule_7(
42780            p_application_id           => p_application_id
42781          , p_ae_header_id             => l_ae_header_id 
42782 , p_source_3 => p_source_3
42783          , x_transaction_coa_id       => l_adr_transaction_coa_id
42784          , x_accounting_coa_id        => l_adr_accounting_coa_id
42785          , x_value_type_code          => l_adr_value_type_code
42786          , p_side                     => 'NA'
42787    );
42788 
42789    xla_ae_lines_pkg.set_ccid(
42790     p_code_combination_id          => l_ccid
42791   , p_value_type_code              => l_adr_value_type_code
42792   , p_transaction_coa_id           => l_adr_transaction_coa_id
42796   , p_component_type               => l_component_type
42793   , p_accounting_coa_id            => l_adr_accounting_coa_id
42794   , p_adr_code                     => 'DIST_CCID'
42795   , p_adr_type_code                => 'S'
42797   , p_component_code               => l_component_code
42798   , p_component_type_code          => l_component_type_code
42799   , p_component_appl_id            => l_component_appl_id
42800   , p_amb_context_code             => l_amb_context_code
42801   , p_side                         => 'NA'
42802   );
42803 
42804 
42805    --
42806    --
42807    END IF;
42808 
42809        --
42810        -- Update the line information that should be overwritten
42811        --
42812        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
42813                                          p_header_num   => 1);
42814        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
42815 
42816        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
42817 
42818        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
42819           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
42820        END IF;
42821 
42822       --
42823       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
42824       --
42825       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
42826           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
42827       ELSE
42828           ---------------------------------------------------------------------------------------------------
42829           -- 4262811a Switch Sign
42830           ---------------------------------------------------------------------------------------------------
42831           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
42832           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
42833                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
42834           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
42835                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
42836           -- 5132302
42837           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
42838                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
42839 
42840       END IF;
42841 
42842       -- 4955764
42843       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
42844       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
42845 
42846 
42847       XLA_AE_LINES_PKG.ValidateCurrentLine;
42848       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
42849 
42850       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
42851                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
42852                ,p_balance_type_code => l_balance_type_code);
42853 
42854    END IF;
42855 
42856    -----------------------------------------------------------------------------------------
42857    -- 4262811 Multiperiod Accounting
42858    -----------------------------------------------------------------------------------------
42859      -- No MPA option is assigned.
42860 
42861 
42862 END IF;
42863 END IF;
42864 --
42865 
42866 --
42867 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
42868    trace
42869       (p_msg      => 'END of AcctLineType_85'
42870       ,p_level    => C_LEVEL_PROCEDURE
42871       ,p_module   => l_log_module);
42872 END IF;
42873 --
42877   WHEN OTHERS THEN
42874 EXCEPTION
42875   WHEN xla_exceptions_pkg.application_exception THEN
42876       RAISE;
42878        xla_exceptions_pkg.raise_message
42879            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_85');
42880 END AcctLineType_85;
42881 --
42882 
42883 ---------------------------------------
42884 --
42885 -- PRIVATE FUNCTION
42886 --         AcctLineType_86
42887 --
42888 ---------------------------------------
42889 PROCEDURE AcctLineType_86 (
42890   p_application_id        IN NUMBER
42891  ,p_event_id              IN NUMBER
42892  ,p_calculate_acctd_flag  IN VARCHAR2
42893  ,p_calculate_g_l_flag    IN VARCHAR2
42894  ,p_actual_flag           IN OUT VARCHAR2
42895  ,p_balance_type_code     OUT VARCHAR2
42896  ,p_gain_or_loss_ref      OUT VARCHAR2
42897  
42898 --Distribution GL Account
42899  , p_source_3            IN NUMBER
42900 --Transaction Distribution GL Account
42901  , p_source_4            IN NUMBER
42902 --Distribution Source Type
42903  , p_source_13            IN VARCHAR2
42904 --Distribution Line Identifier
42905  , p_source_15            IN NUMBER
42906 --Distribution Type
42907  , p_source_16            IN VARCHAR2
42908 --Entered Amount
42909  , p_source_17            IN NUMBER
42910 --Currency Code
42911  , p_source_18            IN VARCHAR2
42912 --Applied To Document Accounting Amount
42913  , p_source_22            IN NUMBER
42914 --Transaction Distribution Identifier
42915  , p_source_27            IN NUMBER
42916 --Transaction Distribution Type
42917  , p_source_28            IN VARCHAR2
42918 --Distribution Multi Fund Additional Entry
42919  , p_source_52            IN VARCHAR2
42920 --Applied To Document Exchange Date
42921  , p_source_53            IN DATE
42922 --Receipt Applied To Application Identifier
42923  , p_source_56            IN NUMBER
42924 --Transaction Entity Code
42925  , p_source_57            IN VARCHAR2
42926 --Transaction Identifier
42927  , p_source_58            IN NUMBER
42928 --Distribution Party Identifier
42929  , p_source_62            IN NUMBER
42930 --Distribution Party Site Id
42931  , p_source_63            IN NUMBER
42932 --Distribution Party Type
42933  , p_source_64            IN VARCHAR2
42934 --Applied To Document Exchange Rate Type
42935  , p_source_65            IN VARCHAR2
42936 --Applied To Document Exchange Rate
42937  , p_source_66            IN NUMBER
42938 )
42939 IS
42940 
42941 l_component_type              VARCHAR2(80);
42942 l_component_code              VARCHAR2(30);
42943 l_component_type_code         VARCHAR2(1);
42944 l_component_appl_id           INTEGER;
42945 l_amb_context_code            VARCHAR2(30);
42946 l_entity_code                 VARCHAR2(30);
42947 l_event_class_code            VARCHAR2(30);
42948 l_ae_header_id                NUMBER;
42949 l_event_type_code             VARCHAR2(30);
42950 l_line_definition_code        VARCHAR2(30);
42951 l_line_definition_owner_code  VARCHAR2(1);
42952 --
42953 -- adr variables
42954 l_segment                     VARCHAR2(30);
42955 l_ccid                        NUMBER;
42956 l_adr_transaction_coa_id      NUMBER;
42957 l_adr_accounting_coa_id       NUMBER;
42958 l_adr_flexfield_segment_code  VARCHAR2(30);
42959 l_adr_flex_value_set_id       NUMBER;
42960 l_adr_value_type_code         VARCHAR2(30);
42961 l_adr_value_combination_id    NUMBER;
42962 l_adr_value_segment_code      VARCHAR2(30);
42963 
42964 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
42965 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
42966 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
42967 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
42968 
42969 -- 4262811 Variables ------------------------------------------------------------------------------------------
42970 l_entered_amt_idx             NUMBER;
42971 l_accted_amt_idx              NUMBER;
42972 l_acc_rev_flag                VARCHAR2(1);
42973 l_accrual_line_num            NUMBER;
42974 l_tmp_amt                     NUMBER;
42975 l_acc_rev_natural_side_code   VARCHAR2(1);
42976 
42977 l_num_entries                 NUMBER;
42978 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
42979 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
42980 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
42981 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
42982 l_recog_line_1                NUMBER;
42983 l_recog_line_2                NUMBER;
42984 
42985 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
42986 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
42987 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
42988 
42989 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
42990 
42991 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
42992 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
42993 
42994 ---------------------------------------------------------------------------------------------------------------
42995 
42996 
42997 --
42998 -- bulk performance
42999 --
43000 l_balance_type_code           VARCHAR2(1);
43001 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
43002 l_log_module                  VARCHAR2(240);
43003 
43004 --
43005 -- Upgrade strategy
43006 --
43007 l_actual_upg_option           VARCHAR2(1);
43008 l_enc_upg_option           VARCHAR2(1);
43009 
43010 --
43011 BEGIN
43012 --
43013 IF g_log_enabled THEN
43017 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
43014       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_86';
43015 END IF;
43016 --
43018 
43019       trace
43020          (p_msg      => 'BEGIN of AcctLineType_86'
43021          ,p_level    => C_LEVEL_PROCEDURE
43022          ,p_module   => l_log_module);
43023 
43024 END IF;
43025 --
43026 l_component_type             := 'AMB_JLT';
43027 l_component_code             := 'RCT_EDISC';
43028 l_component_type_code        := 'S';
43029 l_component_appl_id          :=  222;
43030 l_amb_context_code           := 'DEFAULT';
43031 l_entity_code                := 'RECEIPTS';
43032 l_event_class_code           := 'RECEIPT';
43033 l_event_type_code            := 'RECEIPT_ALL';
43034 l_line_definition_owner_code := 'S';
43035 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
43036 --
43037 l_balance_type_code          := 'A';
43038 l_segment                     := NULL;
43039 l_ccid                        := NULL;
43040 l_adr_transaction_coa_id      := NULL;
43041 l_adr_accounting_coa_id       := NULL;
43042 l_adr_flexfield_segment_code  := NULL;
43043 l_adr_flex_value_set_id       := NULL;
43044 l_adr_value_type_code         := NULL;
43045 l_adr_value_combination_id    := NULL;
43046 l_adr_value_segment_code      := NULL;
43047 
43048 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
43049 l_bflow_class_code           := '';    -- 4219869 Business Flow
43050 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
43051 l_budgetary_control_flag     := 'N';
43052 
43053 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
43054 l_bflow_applied_to_amt       := NULL; -- 5132302
43055 l_entered_amt_idx            := NULL;          -- 4262811
43056 l_accted_amt_idx             := NULL;          -- 4262811
43057 l_acc_rev_flag               := NULL;          -- 4262811
43058 l_accrual_line_num           := NULL;          -- 4262811
43059 l_tmp_amt                    := NULL;          -- 4262811
43060 --
43061  
43062 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
43063     l_balance_type_code <> 'B' THEN
43064 IF NVL(p_source_13,'
43065 ') =  'EDISC' AND 
43066 NVL(p_source_52,'
43067 ') =  'N'
43068  THEN 
43069 
43070    --
43071    XLA_AE_LINES_PKG.SetNewLine;
43072 
43073    p_balance_type_code          := l_balance_type_code;
43074    -- set the flag so later we will know whether the gain loss line needs to be created
43075    
43076    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
43077      p_actual_flag :='A';
43078    END IF;
43079 
43080    --
43081    -- bulk performance
43082    --
43083    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
43084                                       p_header_num   => 0); -- 4262811
43085    --
43086    -- set accounting line options
43087    --
43088    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
43089            p_natural_side_code          => 'C'
43090          , p_gain_or_loss_flag          => 'N'
43091          , p_gl_transfer_mode_code      => 'S'
43092          , p_acct_entry_type_code       => 'A'
43093          , p_switch_side_flag           => 'Y'
43094          , p_merge_duplicate_code       => 'A'
43095          );
43096    --
43097    l_acc_rev_natural_side_code := 'D';  -- 4262811
43098    -- 
43099    --
43100    -- set accounting line type info
43101    --
43102    xla_ae_lines_pkg.SetAcctLineType
43103       (p_component_type             => l_component_type
43104       ,p_event_type_code            => l_event_type_code
43105       ,p_line_definition_owner_code => l_line_definition_owner_code
43106       ,p_line_definition_code       => l_line_definition_code
43107       ,p_accounting_line_code       => l_component_code
43108       ,p_accounting_line_type_code  => l_component_type_code
43109       ,p_accounting_line_appl_id    => l_component_appl_id
43110       ,p_amb_context_code           => l_amb_context_code
43111       ,p_entity_code                => l_entity_code
43112       ,p_event_class_code           => l_event_class_code);
43113    --
43114    -- set accounting class
43115    --
43116    xla_ae_lines_pkg.SetAcctClass(
43117            p_accounting_class_code  => 'EDISC'
43118          , p_ae_header_id           => l_ae_header_id
43119          );
43120 
43121    --
43122    -- set rounding class
43123    --
43124    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
43125                       'RECEIVABLE';
43126 
43127    --
43128    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
43129    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
43130    --
43131    -- bulk performance
43132    --
43133    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
43134 
43135    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
43136       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
43137 
43138    -- 4955764
43139    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
43140       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
43141 
43142    -- 4458381 Public Sector Enh
43143    
43144    --
43145    -- set accounting attributes for the line type
43146    --
43147    l_entered_amt_idx := 8;
43148    l_accted_amt_idx  := 13;
43149    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
43153    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
43150    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
43151    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
43152    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
43154    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
43155    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
43156    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
43157    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
43158    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
43159    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
43160    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
43161    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
43162    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
43163    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
43164    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
43165    l_rec_acct_attrs.array_num_value(8)  := p_source_17;
43166    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
43167    l_rec_acct_attrs.array_char_value(9)  := p_source_18;
43168    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
43169    l_rec_acct_attrs.array_date_value(10)  := p_source_53;
43170    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
43171    l_rec_acct_attrs.array_num_value(11)  := p_source_66;
43172    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
43173    l_rec_acct_attrs.array_char_value(12)  := p_source_65;
43174    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
43175    l_rec_acct_attrs.array_num_value(13)  := p_source_22;
43176    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
43177    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
43178    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
43179    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
43180    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
43181    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
43182 
43183    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
43184    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
43185 
43186    ---------------------------------------------------------------------------------------------------------------
43187    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
43188    ---------------------------------------------------------------------------------------------------------------
43189    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
43190 
43191    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
43192    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
43193 
43194    IF xla_accounting_cache_pkg.GetValueChar
43195          (p_source_code         => 'LEDGER_CATEGORY_CODE'
43196          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
43197    AND l_bflow_method_code = 'PRIOR_ENTRY'
43198 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
43199    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
43200          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
43201        )
43202    THEN
43203          xla_ae_lines_pkg.BflowUpgEntry
43204            (p_business_method_code    => l_bflow_method_code
43205            ,p_business_class_code     => l_bflow_class_code
43206            ,p_balance_type            => l_balance_type_code);
43207    ELSE
43208       NULL;
43209 -- No business flow processing for business flow method of NONE.
43210    END IF;
43211 
43212    --
43213    -- call analytical criteria
43214    --
43215    
43216    --
43217    -- call description
43218    --
43219    
43220 xla_ae_lines_pkg.SetLineDescription(
43221    p_ae_header_id => l_ae_header_id
43222   ,p_description  => Description_1 (
43223      p_application_id         => p_application_id
43224    , p_ae_header_id           => l_ae_header_id 
43225    )
43226 );
43227 
43228 
43229    --
43230    -- call ADRs
43231    -- Bug 4922099
43232    --
43233    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
43234         (NVL(l_actual_upg_option, 'N') = 'O') OR
43235         (NVL(l_enc_upg_option, 'N') = 'O')
43236       )
43237    THEN
43238    NULL;
43239    --
43240    --
43241    
43242   l_ccid := AcctDerRule_7(
43243            p_application_id           => p_application_id
43244          , p_ae_header_id             => l_ae_header_id 
43245 , p_source_3 => p_source_3
43246          , x_transaction_coa_id       => l_adr_transaction_coa_id
43247          , x_accounting_coa_id        => l_adr_accounting_coa_id
43248          , x_value_type_code          => l_adr_value_type_code
43249          , p_side                     => 'NA'
43250    );
43251 
43252    xla_ae_lines_pkg.set_ccid(
43253     p_code_combination_id          => l_ccid
43254   , p_value_type_code              => l_adr_value_type_code
43255   , p_transaction_coa_id           => l_adr_transaction_coa_id
43256   , p_accounting_coa_id            => l_adr_accounting_coa_id
43257   , p_adr_code                     => 'DIST_CCID'
43258   , p_adr_type_code                => 'S'
43259   , p_component_type               => l_component_type
43260   , p_component_code               => l_component_code
43261   , p_component_type_code          => l_component_type_code
43262   , p_component_appl_id            => l_component_appl_id
43263   , p_amb_context_code             => l_amb_context_code
43264   , p_side                         => 'NA'
43265   );
43269            p_application_id           => p_application_id
43266 
43267 
43268    l_segment := AcctDerRule_5(
43270          , p_ae_header_id             => l_ae_header_id 
43271 , p_source_4 => p_source_4
43272          , x_transaction_coa_id       => l_adr_transaction_coa_id
43273          , x_accounting_coa_id        => l_adr_accounting_coa_id
43274          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
43275          , x_flex_value_set_id        => l_adr_flex_value_set_id
43276          , x_value_type_code          => l_adr_value_type_code
43277          , x_value_combination_id     => l_adr_value_combination_id
43278          , x_value_segment_code       => l_adr_value_segment_code
43279          , p_side                     => 'NA'
43280          , p_override_seg_flag        => 'Y'
43281    );
43282 
43283    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
43284 
43285       xla_ae_lines_pkg.set_segment(
43286           p_to_segment_code         => 'GL_BALANCING'
43287         , p_segment_value           => l_segment
43288         , p_from_segment_code       => l_adr_value_segment_code
43289         , p_from_combination_id     => l_adr_value_combination_id
43290         , p_value_type_code         => l_adr_value_type_code
43291         , p_transaction_coa_id      => l_adr_transaction_coa_id
43292         , p_accounting_coa_id       => l_adr_accounting_coa_id
43293         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
43294         , p_flex_value_set_id       => l_adr_flex_value_set_id
43295         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
43296         , p_adr_type_code           => 'S'
43297         , p_component_type          => l_component_type
43298         , p_component_code          => l_component_code
43299         , p_component_type_code     => l_component_type_code
43300         , p_component_appl_id       => l_component_appl_id
43301         , p_amb_context_code        => l_amb_context_code
43302         , p_entity_code             => 'RECEIPTS'
43303         , p_event_class_code        => 'RECEIPT'
43304         , p_side                    => 'NA'
43305         );
43306 
43307   END IF;
43308 
43309    --
43310    --
43311    END IF;
43312    --
43313    -- Bug 4922099
43314    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
43315           (NVL(l_enc_upg_option, 'N') = 'O')
43316         ) AND
43317         (l_bflow_method_code = 'PRIOR_ENTRY')
43318       )
43319    THEN
43320       IF
43321       --
43322       1 = 2
43323       --
43324       THEN
43325       xla_accounting_err_pkg.build_message
43326                                     (p_appli_s_name            => 'XLA'
43327                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
43328                                     ,p_token_1                 => 'LINE_NUMBER'
43329                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
43330                                     ,p_token_2                 => 'LINE_TYPE_NAME'
43331                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
43332                                                                              l_component_type
43333                                                                             ,l_component_code
43334                                                                             ,l_component_type_code
43335                                                                             ,l_component_appl_id
43336                                                                             ,l_amb_context_code
43337                                                                             ,l_entity_code
43338                                                                             ,l_event_class_code
43339                                                                            )
43340                                     ,p_token_3                 => 'OWNER'
43341                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
43342                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
43343                                                                           ,p_lookup_code    => l_component_type_code
43344                                                                          )
43345                                     ,p_token_4                 => 'PRODUCT_NAME'
43346                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
43347                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
43348                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
43349                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
43350                                     ,p_ae_header_id            =>  NULL
43351                                        );
43352 
43353         IF (C_LEVEL_ERROR>= g_log_level) THEN
43354                  trace
43355                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
43356                       ,p_level    => C_LEVEL_ERROR
43357                       ,p_module   => l_log_module);
43358         END IF;
43359       END IF;
43360    END IF;
43361    --
43362    --
43363    ------------------------------------------------------------------------------------------------
43364    -- 4219869 Business Flow
43365    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
43366    -- Prior Entry.  Currently, the following code is always generated.
43367    ------------------------------------------------------------------------------------------------
43368    XLA_AE_LINES_PKG.ValidateCurrentLine;
43369 
43373    ------------------------------------------------------------------------------------
43370    ------------------------------------------------------------------------------------
43371    -- 4219869 Business Flow
43372    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
43374    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
43375 
43376    ----------------------------------------------------------------------------------
43377    -- 4219869 Business Flow
43378    -- Update journal entry status -- Need to generate this within IF <condition>
43379    ----------------------------------------------------------------------------------
43380    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
43381          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
43382          ,p_balance_type_code => l_balance_type_code
43383          );
43384 
43385    -------------------------------------------------------------------------------------------
43386    -- 4262811 - Generate the Accrual Reversal lines
43387    -------------------------------------------------------------------------------------------
43388    BEGIN
43389       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
43390                               (g_array_event(p_event_id).array_value_num('header_index'));
43391       IF l_acc_rev_flag IS NULL THEN
43392          l_acc_rev_flag := 'N';
43393       END IF;
43394    EXCEPTION
43395       WHEN OTHERS THEN
43396          l_acc_rev_flag := 'N';
43397    END;
43398    --
43399    IF (l_acc_rev_flag = 'Y') THEN
43400 
43401        -- 4645092  ------------------------------------------------------------------------------
43402        -- To allow MPA report to determine if it should generate report process
43403        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
43404        ------------------------------------------------------------------------------------------
43405 
43406        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
43407        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
43408    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
43409    -- call ADRs
43410    -- Bug 4922099
43411    --
43412    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
43413         (NVL(l_actual_upg_option, 'N') = 'O') OR
43414         (NVL(l_enc_upg_option, 'N') = 'O')
43415       )
43416    THEN
43417    NULL;
43418    --
43419    --
43420    
43421   l_ccid := AcctDerRule_7(
43422            p_application_id           => p_application_id
43423          , p_ae_header_id             => l_ae_header_id 
43424 , p_source_3 => p_source_3
43425          , x_transaction_coa_id       => l_adr_transaction_coa_id
43426          , x_accounting_coa_id        => l_adr_accounting_coa_id
43427          , x_value_type_code          => l_adr_value_type_code
43428          , p_side                     => 'NA'
43429    );
43430 
43431    xla_ae_lines_pkg.set_ccid(
43432     p_code_combination_id          => l_ccid
43433   , p_value_type_code              => l_adr_value_type_code
43434   , p_transaction_coa_id           => l_adr_transaction_coa_id
43435   , p_accounting_coa_id            => l_adr_accounting_coa_id
43436   , p_adr_code                     => 'DIST_CCID'
43437   , p_adr_type_code                => 'S'
43438   , p_component_type               => l_component_type
43439   , p_component_code               => l_component_code
43440   , p_component_type_code          => l_component_type_code
43441   , p_component_appl_id            => l_component_appl_id
43442   , p_amb_context_code             => l_amb_context_code
43443   , p_side                         => 'NA'
43444   );
43445 
43446 
43447    l_segment := AcctDerRule_5(
43448            p_application_id           => p_application_id
43449          , p_ae_header_id             => l_ae_header_id 
43450 , p_source_4 => p_source_4
43451          , x_transaction_coa_id       => l_adr_transaction_coa_id
43452          , x_accounting_coa_id        => l_adr_accounting_coa_id
43453          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
43454          , x_flex_value_set_id        => l_adr_flex_value_set_id
43455          , x_value_type_code          => l_adr_value_type_code
43456          , x_value_combination_id     => l_adr_value_combination_id
43457          , x_value_segment_code       => l_adr_value_segment_code
43458          , p_side                     => 'NA'
43459          , p_override_seg_flag        => 'Y'
43460    );
43461 
43462    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
43463 
43464       xla_ae_lines_pkg.set_segment(
43465           p_to_segment_code         => 'GL_BALANCING'
43466         , p_segment_value           => l_segment
43467         , p_from_segment_code       => l_adr_value_segment_code
43468         , p_from_combination_id     => l_adr_value_combination_id
43469         , p_value_type_code         => l_adr_value_type_code
43470         , p_transaction_coa_id      => l_adr_transaction_coa_id
43471         , p_accounting_coa_id       => l_adr_accounting_coa_id
43472         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
43473         , p_flex_value_set_id       => l_adr_flex_value_set_id
43474         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
43475         , p_adr_type_code           => 'S'
43476         , p_component_type          => l_component_type
43477         , p_component_code          => l_component_code
43478         , p_component_type_code     => l_component_type_code
43479         , p_component_appl_id       => l_component_appl_id
43483         , p_side                    => 'NA'
43480         , p_amb_context_code        => l_amb_context_code
43481         , p_entity_code             => 'RECEIPTS'
43482         , p_event_class_code        => 'RECEIPT'
43484         );
43485 
43486   END IF;
43487 
43488    --
43489    --
43490    END IF;
43491 
43492        --
43493        -- Update the line information that should be overwritten
43494        --
43495        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
43496                                          p_header_num   => 1);
43497        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
43498 
43499        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
43500 
43501        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
43502           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
43503        END IF;
43504 
43505       --
43506       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
43507       --
43508       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
43509           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
43510       ELSE
43511           ---------------------------------------------------------------------------------------------------
43512           -- 4262811a Switch Sign
43513           ---------------------------------------------------------------------------------------------------
43514           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
43515           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
43516                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
43517           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
43518                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
43519           -- 5132302
43520           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
43521                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
43522 
43523       END IF;
43524 
43525       -- 4955764
43526       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
43527       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
43528 
43529 
43530       XLA_AE_LINES_PKG.ValidateCurrentLine;
43531       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
43532 
43533       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
43534                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
43535                ,p_balance_type_code => l_balance_type_code);
43536 
43537    END IF;
43538 
43539    -----------------------------------------------------------------------------------------
43540    -- 4262811 Multiperiod Accounting
43541    -----------------------------------------------------------------------------------------
43542      -- No MPA option is assigned.
43543 
43544 
43545 END IF;
43546 END IF;
43547 --
43548 
43549 --
43550 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
43551    trace
43552       (p_msg      => 'END of AcctLineType_86'
43553       ,p_level    => C_LEVEL_PROCEDURE
43554       ,p_module   => l_log_module);
43555 END IF;
43556 --
43557 EXCEPTION
43558   WHEN xla_exceptions_pkg.application_exception THEN
43559       RAISE;
43560   WHEN OTHERS THEN
43561        xla_exceptions_pkg.raise_message
43562            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_86');
43563 END AcctLineType_86;
43564 --
43565 
43566 ---------------------------------------
43567 --
43568 -- PRIVATE FUNCTION
43569 --         AcctLineType_87
43570 --
43571 ---------------------------------------
43572 PROCEDURE AcctLineType_87 (
43573   p_application_id        IN NUMBER
43574  ,p_event_id              IN NUMBER
43575  ,p_calculate_acctd_flag  IN VARCHAR2
43576  ,p_calculate_g_l_flag    IN VARCHAR2
43577  ,p_actual_flag           IN OUT VARCHAR2
43578  ,p_balance_type_code     OUT VARCHAR2
43579  ,p_gain_or_loss_ref      OUT VARCHAR2
43580  
43581 --Distribution GL Account
43582  , p_source_3            IN NUMBER
43583 --Distribution Source Type
43584  , p_source_13            IN VARCHAR2
43585 --Distribution Line Identifier
43586  , p_source_15            IN NUMBER
43587 --Distribution Type
43588  , p_source_16            IN VARCHAR2
43589 --Entered Amount
43590  , p_source_17            IN NUMBER
43591 --Exchange Date
43592  , p_source_19            IN DATE
43593 --Exchange Rate
43594  , p_source_20            IN NUMBER
43595 --Exchange Rate Type
43596  , p_source_21            IN VARCHAR2
43597 --Applied To Document Accounting Amount
43598  , p_source_22            IN NUMBER
43599 --Transaction Distribution Identifier
43600  , p_source_27            IN NUMBER
43601 --Transaction Distribution Type
43602  , p_source_28            IN VARCHAR2
43603 --Receipt Applied To Application Identifier
43604  , p_source_56            IN NUMBER
43605 --Transaction Entity Code
43606  , p_source_57            IN VARCHAR2
43607 --Transaction Identifier
43611 --Distribution Party Identifier
43608  , p_source_58            IN NUMBER
43609 --Applying Document Currency Code
43610  , p_source_60            IN VARCHAR2
43612  , p_source_62            IN NUMBER
43613 --Distribution Party Site Id
43614  , p_source_63            IN NUMBER
43615 --Distribution Party Type
43616  , p_source_64            IN VARCHAR2
43617 )
43618 IS
43619 
43620 l_component_type              VARCHAR2(80);
43621 l_component_code              VARCHAR2(30);
43622 l_component_type_code         VARCHAR2(1);
43623 l_component_appl_id           INTEGER;
43624 l_amb_context_code            VARCHAR2(30);
43625 l_entity_code                 VARCHAR2(30);
43626 l_event_class_code            VARCHAR2(30);
43627 l_ae_header_id                NUMBER;
43628 l_event_type_code             VARCHAR2(30);
43629 l_line_definition_code        VARCHAR2(30);
43630 l_line_definition_owner_code  VARCHAR2(1);
43631 --
43632 -- adr variables
43633 l_segment                     VARCHAR2(30);
43634 l_ccid                        NUMBER;
43635 l_adr_transaction_coa_id      NUMBER;
43636 l_adr_accounting_coa_id       NUMBER;
43637 l_adr_flexfield_segment_code  VARCHAR2(30);
43638 l_adr_flex_value_set_id       NUMBER;
43639 l_adr_value_type_code         VARCHAR2(30);
43640 l_adr_value_combination_id    NUMBER;
43641 l_adr_value_segment_code      VARCHAR2(30);
43642 
43643 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
43644 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
43645 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
43646 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
43647 
43648 -- 4262811 Variables ------------------------------------------------------------------------------------------
43649 l_entered_amt_idx             NUMBER;
43650 l_accted_amt_idx              NUMBER;
43651 l_acc_rev_flag                VARCHAR2(1);
43652 l_accrual_line_num            NUMBER;
43653 l_tmp_amt                     NUMBER;
43654 l_acc_rev_natural_side_code   VARCHAR2(1);
43655 
43656 l_num_entries                 NUMBER;
43657 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
43658 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
43659 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
43660 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
43661 l_recog_line_1                NUMBER;
43662 l_recog_line_2                NUMBER;
43663 
43664 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
43665 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
43666 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
43667 
43668 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
43669 
43670 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
43671 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
43672 
43673 ---------------------------------------------------------------------------------------------------------------
43674 
43675 
43676 --
43677 -- bulk performance
43678 --
43679 l_balance_type_code           VARCHAR2(1);
43680 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
43681 l_log_module                  VARCHAR2(240);
43682 
43683 --
43684 -- Upgrade strategy
43685 --
43686 l_actual_upg_option           VARCHAR2(1);
43687 l_enc_upg_option           VARCHAR2(1);
43688 
43689 --
43690 BEGIN
43691 --
43692 IF g_log_enabled THEN
43693       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_87';
43694 END IF;
43695 --
43696 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
43697 
43698       trace
43699          (p_msg      => 'BEGIN of AcctLineType_87'
43700          ,p_level    => C_LEVEL_PROCEDURE
43701          ,p_module   => l_log_module);
43702 
43703 END IF;
43704 --
43705 l_component_type             := 'AMB_JLT';
43706 l_component_code             := 'RCT_EXCH_GAIN';
43707 l_component_type_code        := 'S';
43708 l_component_appl_id          :=  222;
43709 l_amb_context_code           := 'DEFAULT';
43710 l_entity_code                := 'RECEIPTS';
43711 l_event_class_code           := 'RECEIPT';
43712 l_event_type_code            := 'RECEIPT_ALL';
43713 l_line_definition_owner_code := 'S';
43714 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
43715 --
43716 l_balance_type_code          := 'A';
43717 l_segment                     := NULL;
43718 l_ccid                        := NULL;
43719 l_adr_transaction_coa_id      := NULL;
43720 l_adr_accounting_coa_id       := NULL;
43721 l_adr_flexfield_segment_code  := NULL;
43722 l_adr_flex_value_set_id       := NULL;
43723 l_adr_value_type_code         := NULL;
43724 l_adr_value_combination_id    := NULL;
43725 l_adr_value_segment_code      := NULL;
43726 
43727 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
43728 l_bflow_class_code           := '';    -- 4219869 Business Flow
43729 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
43730 l_budgetary_control_flag     := 'N';
43731 
43732 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
43733 l_bflow_applied_to_amt       := NULL; -- 5132302
43734 l_entered_amt_idx            := NULL;          -- 4262811
43735 l_accted_amt_idx             := NULL;          -- 4262811
43736 l_acc_rev_flag               := NULL;          -- 4262811
43737 l_accrual_line_num           := NULL;          -- 4262811
43738 l_tmp_amt                    := NULL;          -- 4262811
43739 --
43740 IF ((p_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
43741             (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
43742                return;
43743   END IF;
43744   
43745 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
43746     l_balance_type_code <> 'B' THEN
43747 IF NVL(p_source_13,'
43748 ') =  'EXCH_GAIN'
43749  THEN 
43750 
43751    --
43752    XLA_AE_LINES_PKG.SetNewLine;
43753 
43754    p_balance_type_code          := l_balance_type_code;
43755    -- set the flag so later we will know whether the gain loss line needs to be created
43756    
43757    IF(l_balance_type_code = 'A' ) THEN
43758      p_actual_flag :='G';
43759    END IF;
43760 
43761    --
43762    -- bulk performance
43763    --
43764    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
43765                                       p_header_num   => 0); -- 4262811
43766    --
43767    -- set accounting line options
43768    --
43769    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
43770            p_natural_side_code          => 'C'
43771          , p_gain_or_loss_flag          => 'Y'
43772          , p_gl_transfer_mode_code      => 'S'
43773          , p_acct_entry_type_code       => 'A'
43774          , p_switch_side_flag           => 'Y'
43775          , p_merge_duplicate_code       => 'A'
43776          );
43777    --
43778    l_acc_rev_natural_side_code := 'D';  -- 4262811
43779    -- 
43780    --
43781    -- set accounting line type info
43782    --
43783    xla_ae_lines_pkg.SetAcctLineType
43784       (p_component_type             => l_component_type
43785       ,p_event_type_code            => l_event_type_code
43786       ,p_line_definition_owner_code => l_line_definition_owner_code
43787       ,p_line_definition_code       => l_line_definition_code
43788       ,p_accounting_line_code       => l_component_code
43789       ,p_accounting_line_type_code  => l_component_type_code
43790       ,p_accounting_line_appl_id    => l_component_appl_id
43791       ,p_amb_context_code           => l_amb_context_code
43792       ,p_entity_code                => l_entity_code
43793       ,p_event_class_code           => l_event_class_code);
43794    --
43795    -- set accounting class
43796    --
43797    xla_ae_lines_pkg.SetAcctClass(
43798            p_accounting_class_code  => 'GAIN'
43799          , p_ae_header_id           => l_ae_header_id
43800          );
43801 
43802    --
43803    -- set rounding class
43804    --
43805    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
43806                       'RECEIVABLE';
43807 
43808    --
43809    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
43810    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
43811    --
43812    -- bulk performance
43813    --
43814    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
43815 
43816    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
43820    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
43817       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
43818 
43819    -- 4955764
43821       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
43822 
43823    -- 4458381 Public Sector Enh
43824    
43825    --
43826    -- set accounting attributes for the line type
43827    --
43828    l_entered_amt_idx := 8;
43829    l_accted_amt_idx  := 13;
43830    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
43831    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
43832    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
43833    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
43834    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
43835    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
43836    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
43837    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
43838    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
43839    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
43840    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
43841    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
43842    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
43843    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
43844    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
43845    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
43846    l_rec_acct_attrs.array_num_value(8)  := p_source_17;
43847    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
43848    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
43849    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
43850    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
43851    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
43852    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
43853    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
43854    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
43855    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
43856    l_rec_acct_attrs.array_num_value(13)  := p_source_22;
43857    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
43858    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
43859    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
43860    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
43861    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
43862    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
43863 
43864    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
43865    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
43866 
43867    ---------------------------------------------------------------------------------------------------------------
43868    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
43869    ---------------------------------------------------------------------------------------------------------------
43870    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
43871 
43872    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
43873    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
43874 
43875    IF xla_accounting_cache_pkg.GetValueChar
43876          (p_source_code         => 'LEDGER_CATEGORY_CODE'
43877          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
43878    AND l_bflow_method_code = 'PRIOR_ENTRY'
43879 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
43880    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
43881          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
43882        )
43883    THEN
43884          xla_ae_lines_pkg.BflowUpgEntry
43885            (p_business_method_code    => l_bflow_method_code
43886            ,p_business_class_code     => l_bflow_class_code
43887            ,p_balance_type            => l_balance_type_code);
43888    ELSE
43889       NULL;
43890 -- No business flow processing for business flow method of NONE.
43891    END IF;
43892 
43893    --
43894    -- call analytical criteria
43895    --
43896    
43897    --
43898    -- call description
43899    --
43900    -- No description or it is inherited.
43901    --
43902    -- call ADRs
43903    -- Bug 4922099
43904    --
43905    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
43906         (NVL(l_actual_upg_option, 'N') = 'O') OR
43907         (NVL(l_enc_upg_option, 'N') = 'O')
43908       )
43909    THEN
43910    NULL;
43911    --
43912    --
43913    
43914   l_ccid := AcctDerRule_7(
43915            p_application_id           => p_application_id
43916          , p_ae_header_id             => l_ae_header_id 
43917 , p_source_3 => p_source_3
43918          , x_transaction_coa_id       => l_adr_transaction_coa_id
43919          , x_accounting_coa_id        => l_adr_accounting_coa_id
43920          , x_value_type_code          => l_adr_value_type_code
43921          , p_side                     => 'NA'
43922    );
43923 
43924    xla_ae_lines_pkg.set_ccid(
43925     p_code_combination_id          => l_ccid
43926   , p_value_type_code              => l_adr_value_type_code
43927   , p_transaction_coa_id           => l_adr_transaction_coa_id
43928   , p_accounting_coa_id            => l_adr_accounting_coa_id
43929   , p_adr_code                     => 'DIST_CCID'
43930   , p_adr_type_code                => 'S'
43931   , p_component_type               => l_component_type
43932   , p_component_code               => l_component_code
43933   , p_component_type_code          => l_component_type_code
43934   , p_component_appl_id            => l_component_appl_id
43935   , p_amb_context_code             => l_amb_context_code
43936   , p_side                         => 'NA'
43937   );
43938 
43939 
43940    --
43941    --
43942    END IF;
43943    --
43944    -- Bug 4922099
43945    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
43946           (NVL(l_enc_upg_option, 'N') = 'O')
43947         ) AND
43948         (l_bflow_method_code = 'PRIOR_ENTRY')
43949       )
43950    THEN
43951       IF
43952       --
43953       1 = 2
43954       --
43955       THEN
43956       xla_accounting_err_pkg.build_message
43957                                     (p_appli_s_name            => 'XLA'
43958                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
43959                                     ,p_token_1                 => 'LINE_NUMBER'
43960                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
43961                                     ,p_token_2                 => 'LINE_TYPE_NAME'
43962                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
43963                                                                              l_component_type
43964                                                                             ,l_component_code
43965                                                                             ,l_component_type_code
43966                                                                             ,l_component_appl_id
43967                                                                             ,l_amb_context_code
43968                                                                             ,l_entity_code
43969                                                                             ,l_event_class_code
43970                                                                            )
43971                                     ,p_token_3                 => 'OWNER'
43972                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
43973                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
43974                                                                           ,p_lookup_code    => l_component_type_code
43975                                                                          )
43976                                     ,p_token_4                 => 'PRODUCT_NAME'
43977                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
43978                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
43979                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
43980                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
43981                                     ,p_ae_header_id            =>  NULL
43982                                        );
43983 
43984         IF (C_LEVEL_ERROR>= g_log_level) THEN
43985                  trace
43986                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
43987                       ,p_level    => C_LEVEL_ERROR
43988                       ,p_module   => l_log_module);
43989         END IF;
43990       END IF;
43991    END IF;
43992    --
43993    --
43994    ------------------------------------------------------------------------------------------------
43995    -- 4219869 Business Flow
43996    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
43997    -- Prior Entry.  Currently, the following code is always generated.
43998    ------------------------------------------------------------------------------------------------
43999    XLA_AE_LINES_PKG.ValidateCurrentLine;
44000 
44001    ------------------------------------------------------------------------------------
44002    -- 4219869 Business Flow
44003    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
44004    ------------------------------------------------------------------------------------
44005    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
44006 
44007    ----------------------------------------------------------------------------------
44008    -- 4219869 Business Flow
44009    -- Update journal entry status -- Need to generate this within IF <condition>
44010    ----------------------------------------------------------------------------------
44011    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
44012          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
44013          ,p_balance_type_code => l_balance_type_code
44014          );
44015 
44016    -------------------------------------------------------------------------------------------
44017    -- 4262811 - Generate the Accrual Reversal lines
44018    -------------------------------------------------------------------------------------------
44019    BEGIN
44020       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
44021                               (g_array_event(p_event_id).array_value_num('header_index'));
44022       IF l_acc_rev_flag IS NULL THEN
44023          l_acc_rev_flag := 'N';
44024       END IF;
44025    EXCEPTION
44026       WHEN OTHERS THEN
44027          l_acc_rev_flag := 'N';
44028    END;
44029    --
44030    IF (l_acc_rev_flag = 'Y') THEN
44031 
44032        -- 4645092  ------------------------------------------------------------------------------
44033        -- To allow MPA report to determine if it should generate report process
44034        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
44035        ------------------------------------------------------------------------------------------
44036 
44037        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
44038        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
44039    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
44040    -- call ADRs
44041    -- Bug 4922099
44042    --
44043    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
44044         (NVL(l_actual_upg_option, 'N') = 'O') OR
44045         (NVL(l_enc_upg_option, 'N') = 'O')
44046       )
44047    THEN
44048    NULL;
44049    --
44050    --
44051    
44052   l_ccid := AcctDerRule_7(
44053            p_application_id           => p_application_id
44054          , p_ae_header_id             => l_ae_header_id 
44055 , p_source_3 => p_source_3
44056          , x_transaction_coa_id       => l_adr_transaction_coa_id
44057          , x_accounting_coa_id        => l_adr_accounting_coa_id
44058          , x_value_type_code          => l_adr_value_type_code
44059          , p_side                     => 'NA'
44060    );
44061 
44062    xla_ae_lines_pkg.set_ccid(
44063     p_code_combination_id          => l_ccid
44064   , p_value_type_code              => l_adr_value_type_code
44065   , p_transaction_coa_id           => l_adr_transaction_coa_id
44066   , p_accounting_coa_id            => l_adr_accounting_coa_id
44067   , p_adr_code                     => 'DIST_CCID'
44068   , p_adr_type_code                => 'S'
44069   , p_component_type               => l_component_type
44070   , p_component_code               => l_component_code
44071   , p_component_type_code          => l_component_type_code
44072   , p_component_appl_id            => l_component_appl_id
44073   , p_amb_context_code             => l_amb_context_code
44074   , p_side                         => 'NA'
44075   );
44076 
44077 
44078    --
44079    --
44080    END IF;
44081 
44082        --
44083        -- Update the line information that should be overwritten
44084        --
44085        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
44086                                          p_header_num   => 1);
44087        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
44088 
44089        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
44090 
44091        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
44092           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
44093        END IF;
44094 
44095       --
44096       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
44097       --
44098       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
44099           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
44100       ELSE
44101           ---------------------------------------------------------------------------------------------------
44102           -- 4262811a Switch Sign
44103           ---------------------------------------------------------------------------------------------------
44104           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
44105           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
44106                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
44107           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
44108                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
44109           -- 5132302
44110           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
44111                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
44112 
44113       END IF;
44114 
44115       -- 4955764
44116       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
44117       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
44118 
44119 
44120       XLA_AE_LINES_PKG.ValidateCurrentLine;
44121       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
44122 
44123       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
44124                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
44125                ,p_balance_type_code => l_balance_type_code);
44126 
44127    END IF;
44128 
44129    -----------------------------------------------------------------------------------------
44130    -- 4262811 Multiperiod Accounting
44131    -----------------------------------------------------------------------------------------
44132      -- No MPA option is assigned.
44133 
44134 
44135 END IF;
44136 END IF;
44137 --
44138 
44139 --
44140 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
44141    trace
44142       (p_msg      => 'END of AcctLineType_87'
44143       ,p_level    => C_LEVEL_PROCEDURE
44144       ,p_module   => l_log_module);
44145 END IF;
44146 --
44147 EXCEPTION
44148   WHEN xla_exceptions_pkg.application_exception THEN
44149       RAISE;
44150   WHEN OTHERS THEN
44151        xla_exceptions_pkg.raise_message
44152            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_87');
44153 END AcctLineType_87;
44154 --
44155 
44156 ---------------------------------------
44157 --
44158 -- PRIVATE FUNCTION
44159 --         AcctLineType_88
44160 --
44161 ---------------------------------------
44162 PROCEDURE AcctLineType_88 (
44163   p_application_id        IN NUMBER
44164  ,p_event_id              IN NUMBER
44165  ,p_calculate_acctd_flag  IN VARCHAR2
44166  ,p_calculate_g_l_flag    IN VARCHAR2
44167  ,p_actual_flag           IN OUT VARCHAR2
44168  ,p_balance_type_code     OUT VARCHAR2
44169  ,p_gain_or_loss_ref      OUT VARCHAR2
44170  
44171 --Distribution GL Account
44172  , p_source_3            IN NUMBER
44173 --Distribution Source Type
44174  , p_source_13            IN VARCHAR2
44175 --Distribution Line Identifier
44176  , p_source_15            IN NUMBER
44177 --Distribution Type
44178  , p_source_16            IN VARCHAR2
44179 --Entered Amount
44180  , p_source_17            IN NUMBER
44181 --Exchange Date
44182  , p_source_19            IN DATE
44183 --Exchange Rate
44184  , p_source_20            IN NUMBER
44185 --Exchange Rate Type
44186  , p_source_21            IN VARCHAR2
44187 --Applied To Document Accounting Amount
44188  , p_source_22            IN NUMBER
44189 --Transaction Distribution Identifier
44190  , p_source_27            IN NUMBER
44191 --Transaction Distribution Type
44192  , p_source_28            IN VARCHAR2
44193 --Receipt Applied To Application Identifier
44194  , p_source_56            IN NUMBER
44195 --Transaction Entity Code
44196  , p_source_57            IN VARCHAR2
44197 --Transaction Identifier
44198  , p_source_58            IN NUMBER
44199 --Applying Document Currency Code
44200  , p_source_60            IN VARCHAR2
44201 --Distribution Party Identifier
44202  , p_source_62            IN NUMBER
44203 --Distribution Party Site Id
44204  , p_source_63            IN NUMBER
44205 --Distribution Party Type
44206  , p_source_64            IN VARCHAR2
44207 )
44208 IS
44209 
44210 l_component_type              VARCHAR2(80);
44211 l_component_code              VARCHAR2(30);
44212 l_component_type_code         VARCHAR2(1);
44213 l_component_appl_id           INTEGER;
44214 l_amb_context_code            VARCHAR2(30);
44215 l_entity_code                 VARCHAR2(30);
44216 l_event_class_code            VARCHAR2(30);
44217 l_ae_header_id                NUMBER;
44218 l_event_type_code             VARCHAR2(30);
44219 l_line_definition_code        VARCHAR2(30);
44220 l_line_definition_owner_code  VARCHAR2(1);
44221 --
44222 -- adr variables
44223 l_segment                     VARCHAR2(30);
44224 l_ccid                        NUMBER;
44225 l_adr_transaction_coa_id      NUMBER;
44226 l_adr_accounting_coa_id       NUMBER;
44227 l_adr_flexfield_segment_code  VARCHAR2(30);
44228 l_adr_flex_value_set_id       NUMBER;
44229 l_adr_value_type_code         VARCHAR2(30);
44230 l_adr_value_combination_id    NUMBER;
44231 l_adr_value_segment_code      VARCHAR2(30);
44232 
44233 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
44234 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
44235 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
44236 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
44237 
44238 -- 4262811 Variables ------------------------------------------------------------------------------------------
44239 l_entered_amt_idx             NUMBER;
44240 l_accted_amt_idx              NUMBER;
44241 l_acc_rev_flag                VARCHAR2(1);
44242 l_accrual_line_num            NUMBER;
44243 l_tmp_amt                     NUMBER;
44244 l_acc_rev_natural_side_code   VARCHAR2(1);
44245 
44246 l_num_entries                 NUMBER;
44247 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
44248 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
44249 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
44250 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
44251 l_recog_line_1                NUMBER;
44252 l_recog_line_2                NUMBER;
44253 
44254 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
44255 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
44256 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
44257 
44258 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
44259 
44260 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
44261 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
44262 
44263 ---------------------------------------------------------------------------------------------------------------
44264 
44265 
44266 --
44267 -- bulk performance
44268 --
44269 l_balance_type_code           VARCHAR2(1);
44270 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
44271 l_log_module                  VARCHAR2(240);
44272 
44273 --
44274 -- Upgrade strategy
44275 --
44276 l_actual_upg_option           VARCHAR2(1);
44277 l_enc_upg_option           VARCHAR2(1);
44278 
44279 --
44280 BEGIN
44281 --
44282 IF g_log_enabled THEN
44283       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_88';
44284 END IF;
44285 --
44286 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
44287 
44288       trace
44289          (p_msg      => 'BEGIN of AcctLineType_88'
44290          ,p_level    => C_LEVEL_PROCEDURE
44291          ,p_module   => l_log_module);
44292 
44293 END IF;
44294 --
44295 l_component_type             := 'AMB_JLT';
44296 l_component_code             := 'RCT_EXCH_LOSS';
44297 l_component_type_code        := 'S';
44298 l_component_appl_id          :=  222;
44299 l_amb_context_code           := 'DEFAULT';
44300 l_entity_code                := 'RECEIPTS';
44301 l_event_class_code           := 'RECEIPT';
44302 l_event_type_code            := 'RECEIPT_ALL';
44303 l_line_definition_owner_code := 'S';
44304 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
44305 --
44306 l_balance_type_code          := 'A';
44307 l_segment                     := NULL;
44308 l_ccid                        := NULL;
44309 l_adr_transaction_coa_id      := NULL;
44310 l_adr_accounting_coa_id       := NULL;
44311 l_adr_flexfield_segment_code  := NULL;
44312 l_adr_flex_value_set_id       := NULL;
44313 l_adr_value_type_code         := NULL;
44314 l_adr_value_combination_id    := NULL;
44315 l_adr_value_segment_code      := NULL;
44316 
44317 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
44318 l_bflow_class_code           := '';    -- 4219869 Business Flow
44319 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
44320 l_budgetary_control_flag     := 'N';
44321 
44322 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
44323 l_bflow_applied_to_amt       := NULL; -- 5132302
44324 l_entered_amt_idx            := NULL;          -- 4262811
44325 l_accted_amt_idx             := NULL;          -- 4262811
44326 l_acc_rev_flag               := NULL;          -- 4262811
44327 l_accrual_line_num           := NULL;          -- 4262811
44328 l_tmp_amt                    := NULL;          -- 4262811
44329 --
44330 IF ((p_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
44331             (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
44332                return;
44333   END IF;
44334   
44335 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
44336     l_balance_type_code <> 'B' THEN
44337 IF NVL(p_source_13,'
44338 ') =  'EXCH_LOSS'
44339  THEN 
44340 
44341    --
44342    XLA_AE_LINES_PKG.SetNewLine;
44343 
44344    p_balance_type_code          := l_balance_type_code;
44345    -- set the flag so later we will know whether the gain loss line needs to be created
44346    
44347    IF(l_balance_type_code = 'A' ) THEN
44348      p_actual_flag :='G';
44349    END IF;
44350 
44351    --
44352    -- bulk performance
44353    --
44354    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
44355                                       p_header_num   => 0); -- 4262811
44356    --
44357    -- set accounting line options
44358    --
44359    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
44360            p_natural_side_code          => 'C'
44361          , p_gain_or_loss_flag          => 'Y'
44362          , p_gl_transfer_mode_code      => 'S'
44363          , p_acct_entry_type_code       => 'A'
44364          , p_switch_side_flag           => 'Y'
44365          , p_merge_duplicate_code       => 'A'
44366          );
44367    --
44368    l_acc_rev_natural_side_code := 'D';  -- 4262811
44369    -- 
44370    --
44371    -- set accounting line type info
44372    --
44373    xla_ae_lines_pkg.SetAcctLineType
44374       (p_component_type             => l_component_type
44375       ,p_event_type_code            => l_event_type_code
44376       ,p_line_definition_owner_code => l_line_definition_owner_code
44377       ,p_line_definition_code       => l_line_definition_code
44378       ,p_accounting_line_code       => l_component_code
44379       ,p_accounting_line_type_code  => l_component_type_code
44380       ,p_accounting_line_appl_id    => l_component_appl_id
44381       ,p_amb_context_code           => l_amb_context_code
44382       ,p_entity_code                => l_entity_code
44383       ,p_event_class_code           => l_event_class_code);
44384    --
44385    -- set accounting class
44386    --
44387    xla_ae_lines_pkg.SetAcctClass(
44388            p_accounting_class_code  => 'LOSS'
44389          , p_ae_header_id           => l_ae_header_id
44390          );
44391 
44392    --
44393    -- set rounding class
44394    --
44395    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
44396                       'RECEIVABLE';
44397 
44398    --
44399    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
44400    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
44401    --
44402    -- bulk performance
44403    --
44404    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
44405 
44406    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
44407       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
44408 
44409    -- 4955764
44410    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
44411       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
44412 
44413    -- 4458381 Public Sector Enh
44414    
44415    --
44416    -- set accounting attributes for the line type
44417    --
44418    l_entered_amt_idx := 8;
44419    l_accted_amt_idx  := 13;
44420    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
44421    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
44422    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
44423    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
44424    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
44425    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
44426    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
44427    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
44428    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
44429    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
44430    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
44431    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
44432    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
44433    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
44434    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
44435    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
44436    l_rec_acct_attrs.array_num_value(8)  := p_source_17;
44437    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
44438    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
44439    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
44440    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
44441    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
44442    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
44443    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
44444    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
44445    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
44446    l_rec_acct_attrs.array_num_value(13)  := p_source_22;
44447    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
44448    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
44449    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
44450    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
44451    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
44452    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
44453 
44454    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
44455    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
44456 
44457    ---------------------------------------------------------------------------------------------------------------
44458    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
44459    ---------------------------------------------------------------------------------------------------------------
44460    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
44461 
44462    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
44463    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
44464 
44465    IF xla_accounting_cache_pkg.GetValueChar
44466          (p_source_code         => 'LEDGER_CATEGORY_CODE'
44467          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
44468    AND l_bflow_method_code = 'PRIOR_ENTRY'
44469 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
44470    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
44471          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
44472        )
44473    THEN
44474          xla_ae_lines_pkg.BflowUpgEntry
44475            (p_business_method_code    => l_bflow_method_code
44476            ,p_business_class_code     => l_bflow_class_code
44477            ,p_balance_type            => l_balance_type_code);
44478    ELSE
44479       NULL;
44480 -- No business flow processing for business flow method of NONE.
44481    END IF;
44482 
44483    --
44484    -- call analytical criteria
44485    --
44486    
44487    --
44488    -- call description
44489    --
44490    -- No description or it is inherited.
44491    --
44492    -- call ADRs
44493    -- Bug 4922099
44494    --
44495    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
44496         (NVL(l_actual_upg_option, 'N') = 'O') OR
44497         (NVL(l_enc_upg_option, 'N') = 'O')
44498       )
44499    THEN
44500    NULL;
44501    --
44502    --
44503    
44504   l_ccid := AcctDerRule_7(
44505            p_application_id           => p_application_id
44506          , p_ae_header_id             => l_ae_header_id 
44507 , p_source_3 => p_source_3
44508          , x_transaction_coa_id       => l_adr_transaction_coa_id
44509          , x_accounting_coa_id        => l_adr_accounting_coa_id
44510          , x_value_type_code          => l_adr_value_type_code
44511          , p_side                     => 'NA'
44512    );
44513 
44514    xla_ae_lines_pkg.set_ccid(
44515     p_code_combination_id          => l_ccid
44516   , p_value_type_code              => l_adr_value_type_code
44517   , p_transaction_coa_id           => l_adr_transaction_coa_id
44518   , p_accounting_coa_id            => l_adr_accounting_coa_id
44519   , p_adr_code                     => 'DIST_CCID'
44520   , p_adr_type_code                => 'S'
44521   , p_component_type               => l_component_type
44522   , p_component_code               => l_component_code
44523   , p_component_type_code          => l_component_type_code
44524   , p_component_appl_id            => l_component_appl_id
44525   , p_amb_context_code             => l_amb_context_code
44526   , p_side                         => 'NA'
44527   );
44528 
44529 
44530    --
44531    --
44532    END IF;
44533    --
44534    -- Bug 4922099
44535    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
44536           (NVL(l_enc_upg_option, 'N') = 'O')
44537         ) AND
44538         (l_bflow_method_code = 'PRIOR_ENTRY')
44539       )
44540    THEN
44541       IF
44542       --
44543       1 = 2
44544       --
44545       THEN
44546       xla_accounting_err_pkg.build_message
44547                                     (p_appli_s_name            => 'XLA'
44548                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
44549                                     ,p_token_1                 => 'LINE_NUMBER'
44550                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
44551                                     ,p_token_2                 => 'LINE_TYPE_NAME'
44552                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
44553                                                                              l_component_type
44554                                                                             ,l_component_code
44555                                                                             ,l_component_type_code
44556                                                                             ,l_component_appl_id
44557                                                                             ,l_amb_context_code
44558                                                                             ,l_entity_code
44559                                                                             ,l_event_class_code
44560                                                                            )
44561                                     ,p_token_3                 => 'OWNER'
44562                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
44563                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
44564                                                                           ,p_lookup_code    => l_component_type_code
44565                                                                          )
44566                                     ,p_token_4                 => 'PRODUCT_NAME'
44567                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
44568                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
44569                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
44570                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
44571                                     ,p_ae_header_id            =>  NULL
44572                                        );
44573 
44574         IF (C_LEVEL_ERROR>= g_log_level) THEN
44575                  trace
44576                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
44577                       ,p_level    => C_LEVEL_ERROR
44578                       ,p_module   => l_log_module);
44579         END IF;
44580       END IF;
44581    END IF;
44582    --
44583    --
44584    ------------------------------------------------------------------------------------------------
44585    -- 4219869 Business Flow
44586    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
44587    -- Prior Entry.  Currently, the following code is always generated.
44588    ------------------------------------------------------------------------------------------------
44589    XLA_AE_LINES_PKG.ValidateCurrentLine;
44590 
44591    ------------------------------------------------------------------------------------
44592    -- 4219869 Business Flow
44593    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
44594    ------------------------------------------------------------------------------------
44595    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
44596 
44597    ----------------------------------------------------------------------------------
44598    -- 4219869 Business Flow
44599    -- Update journal entry status -- Need to generate this within IF <condition>
44600    ----------------------------------------------------------------------------------
44601    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
44602          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
44603          ,p_balance_type_code => l_balance_type_code
44604          );
44605 
44606    -------------------------------------------------------------------------------------------
44607    -- 4262811 - Generate the Accrual Reversal lines
44608    -------------------------------------------------------------------------------------------
44609    BEGIN
44610       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
44611                               (g_array_event(p_event_id).array_value_num('header_index'));
44612       IF l_acc_rev_flag IS NULL THEN
44613          l_acc_rev_flag := 'N';
44614       END IF;
44615    EXCEPTION
44616       WHEN OTHERS THEN
44617          l_acc_rev_flag := 'N';
44618    END;
44619    --
44620    IF (l_acc_rev_flag = 'Y') THEN
44621 
44622        -- 4645092  ------------------------------------------------------------------------------
44623        -- To allow MPA report to determine if it should generate report process
44624        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
44625        ------------------------------------------------------------------------------------------
44626 
44627        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
44628        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
44629    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
44630    -- call ADRs
44631    -- Bug 4922099
44632    --
44633    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
44634         (NVL(l_actual_upg_option, 'N') = 'O') OR
44635         (NVL(l_enc_upg_option, 'N') = 'O')
44636       )
44637    THEN
44638    NULL;
44639    --
44640    --
44641    
44642   l_ccid := AcctDerRule_7(
44643            p_application_id           => p_application_id
44644          , p_ae_header_id             => l_ae_header_id 
44645 , p_source_3 => p_source_3
44646          , x_transaction_coa_id       => l_adr_transaction_coa_id
44647          , x_accounting_coa_id        => l_adr_accounting_coa_id
44648          , x_value_type_code          => l_adr_value_type_code
44649          , p_side                     => 'NA'
44650    );
44651 
44652    xla_ae_lines_pkg.set_ccid(
44653     p_code_combination_id          => l_ccid
44654   , p_value_type_code              => l_adr_value_type_code
44655   , p_transaction_coa_id           => l_adr_transaction_coa_id
44656   , p_accounting_coa_id            => l_adr_accounting_coa_id
44657   , p_adr_code                     => 'DIST_CCID'
44658   , p_adr_type_code                => 'S'
44659   , p_component_type               => l_component_type
44660   , p_component_code               => l_component_code
44661   , p_component_type_code          => l_component_type_code
44662   , p_component_appl_id            => l_component_appl_id
44663   , p_amb_context_code             => l_amb_context_code
44664   , p_side                         => 'NA'
44665   );
44666 
44667 
44668    --
44669    --
44670    END IF;
44671 
44672        --
44673        -- Update the line information that should be overwritten
44674        --
44675        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
44676                                          p_header_num   => 1);
44677        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
44678 
44679        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
44680 
44681        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
44682           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
44683        END IF;
44684 
44685       --
44686       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
44687       --
44688       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
44689           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
44690       ELSE
44691           ---------------------------------------------------------------------------------------------------
44692           -- 4262811a Switch Sign
44693           ---------------------------------------------------------------------------------------------------
44694           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
44695           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
44696                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
44697           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
44698                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
44699           -- 5132302
44700           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
44701                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
44702 
44703       END IF;
44704 
44705       -- 4955764
44706       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
44707       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
44708 
44709 
44710       XLA_AE_LINES_PKG.ValidateCurrentLine;
44711       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
44712 
44713       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
44714                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
44715                ,p_balance_type_code => l_balance_type_code);
44716 
44717    END IF;
44718 
44719    -----------------------------------------------------------------------------------------
44720    -- 4262811 Multiperiod Accounting
44721    -----------------------------------------------------------------------------------------
44722      -- No MPA option is assigned.
44723 
44724 
44725 END IF;
44726 END IF;
44727 --
44728 
44729 --
44730 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
44731    trace
44732       (p_msg      => 'END of AcctLineType_88'
44733       ,p_level    => C_LEVEL_PROCEDURE
44734       ,p_module   => l_log_module);
44735 END IF;
44736 --
44737 EXCEPTION
44738   WHEN xla_exceptions_pkg.application_exception THEN
44739       RAISE;
44740   WHEN OTHERS THEN
44741        xla_exceptions_pkg.raise_message
44742            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_88');
44743 END AcctLineType_88;
44744 --
44745 
44746 ---------------------------------------
44747 --
44748 -- PRIVATE FUNCTION
44749 --         AcctLineType_89
44750 --
44751 ---------------------------------------
44752 PROCEDURE AcctLineType_89 (
44753   p_application_id        IN NUMBER
44754  ,p_event_id              IN NUMBER
44755  ,p_calculate_acctd_flag  IN VARCHAR2
44756  ,p_calculate_g_l_flag    IN VARCHAR2
44757  ,p_actual_flag           IN OUT VARCHAR2
44758  ,p_balance_type_code     OUT VARCHAR2
44759  ,p_gain_or_loss_ref      OUT VARCHAR2
44760  
44761 --Distribution GL Account
44762  , p_source_3            IN NUMBER
44763 --Distribution Source Type
44764  , p_source_13            IN VARCHAR2
44765 --Distribution Line Identifier
44766  , p_source_15            IN NUMBER
44767 --Distribution Type
44768  , p_source_16            IN VARCHAR2
44769 --Exchange Date
44770  , p_source_19            IN DATE
44771 --Exchange Rate
44772  , p_source_20            IN NUMBER
44773 --Exchange Rate Type
44774  , p_source_21            IN VARCHAR2
44775 --Transaction Distribution Identifier
44776  , p_source_27            IN NUMBER
44777 --Transaction Distribution Type
44778  , p_source_28            IN VARCHAR2
44779 --Distribution Multi Fund Additional Entry
44780  , p_source_52            IN VARCHAR2
44781 --Receipt Applied To Application Identifier
44782  , p_source_56            IN NUMBER
44783 --Transaction Entity Code
44784  , p_source_57            IN VARCHAR2
44785 --Transaction Identifier
44786  , p_source_58            IN NUMBER
44787 --DIST_ENT_AMT_FROM
44788  , p_source_59            IN NUMBER
44789 --Applying Document Currency Code
44790  , p_source_60            IN VARCHAR2
44791 --Accounting Amount
44792  , p_source_61            IN NUMBER
44793 --Distribution Party Identifier
44794  , p_source_62            IN NUMBER
44795 --Distribution Party Site Id
44796  , p_source_63            IN NUMBER
44797 --Distribution Party Type
44798  , p_source_64            IN VARCHAR2
44799 --Distribution Source Table
44800  , p_source_67            IN VARCHAR2
44801 )
44802 IS
44803 
44804 l_component_type              VARCHAR2(80);
44805 l_component_code              VARCHAR2(30);
44806 l_component_type_code         VARCHAR2(1);
44807 l_component_appl_id           INTEGER;
44808 l_amb_context_code            VARCHAR2(30);
44809 l_entity_code                 VARCHAR2(30);
44810 l_event_class_code            VARCHAR2(30);
44811 l_ae_header_id                NUMBER;
44812 l_event_type_code             VARCHAR2(30);
44813 l_line_definition_code        VARCHAR2(30);
44814 l_line_definition_owner_code  VARCHAR2(1);
44815 --
44816 -- adr variables
44817 l_segment                     VARCHAR2(30);
44818 l_ccid                        NUMBER;
44819 l_adr_transaction_coa_id      NUMBER;
44820 l_adr_accounting_coa_id       NUMBER;
44821 l_adr_flexfield_segment_code  VARCHAR2(30);
44822 l_adr_flex_value_set_id       NUMBER;
44823 l_adr_value_type_code         VARCHAR2(30);
44824 l_adr_value_combination_id    NUMBER;
44825 l_adr_value_segment_code      VARCHAR2(30);
44826 
44827 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
44828 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
44829 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
44830 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
44831 
44832 -- 4262811 Variables ------------------------------------------------------------------------------------------
44833 l_entered_amt_idx             NUMBER;
44834 l_accted_amt_idx              NUMBER;
44838 l_acc_rev_natural_side_code   VARCHAR2(1);
44835 l_acc_rev_flag                VARCHAR2(1);
44836 l_accrual_line_num            NUMBER;
44837 l_tmp_amt                     NUMBER;
44839 
44840 l_num_entries                 NUMBER;
44841 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
44842 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
44843 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
44844 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
44845 l_recog_line_1                NUMBER;
44846 l_recog_line_2                NUMBER;
44847 
44848 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
44849 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
44850 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
44851 
44852 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
44853 
44854 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
44855 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
44856 
44857 ---------------------------------------------------------------------------------------------------------------
44858 
44859 
44860 --
44861 -- bulk performance
44862 --
44863 l_balance_type_code           VARCHAR2(1);
44864 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
44865 l_log_module                  VARCHAR2(240);
44866 
44867 --
44868 -- Upgrade strategy
44869 --
44870 l_actual_upg_option           VARCHAR2(1);
44871 l_enc_upg_option           VARCHAR2(1);
44872 
44873 --
44874 BEGIN
44875 --
44876 IF g_log_enabled THEN
44877       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_89';
44878 END IF;
44879 --
44880 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
44881 
44882       trace
44883          (p_msg      => 'BEGIN of AcctLineType_89'
44884          ,p_level    => C_LEVEL_PROCEDURE
44885          ,p_module   => l_log_module);
44886 
44887 END IF;
44888 --
44889 l_component_type             := 'AMB_JLT';
44890 l_component_code             := 'RCT_FACTOR';
44891 l_component_type_code        := 'S';
44892 l_component_appl_id          :=  222;
44893 l_amb_context_code           := 'DEFAULT';
44894 l_entity_code                := 'RECEIPTS';
44895 l_event_class_code           := 'RECEIPT';
44896 l_event_type_code            := 'RECEIPT_ALL';
44897 l_line_definition_owner_code := 'S';
44898 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
44899 --
44900 l_balance_type_code          := 'A';
44901 l_segment                     := NULL;
44902 l_ccid                        := NULL;
44903 l_adr_transaction_coa_id      := NULL;
44904 l_adr_accounting_coa_id       := NULL;
44905 l_adr_flexfield_segment_code  := NULL;
44906 l_adr_flex_value_set_id       := NULL;
44907 l_adr_value_type_code         := NULL;
44908 l_adr_value_combination_id    := NULL;
44909 l_adr_value_segment_code      := NULL;
44910 
44911 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
44912 l_bflow_class_code           := '';    -- 4219869 Business Flow
44913 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
44914 l_budgetary_control_flag     := 'N';
44915 
44916 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
44917 l_bflow_applied_to_amt       := NULL; -- 5132302
44918 l_entered_amt_idx            := NULL;          -- 4262811
44919 l_accted_amt_idx             := NULL;          -- 4262811
44920 l_acc_rev_flag               := NULL;          -- 4262811
44921 l_accrual_line_num           := NULL;          -- 4262811
44922 l_tmp_amt                    := NULL;          -- 4262811
44923 --
44924  
44925 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
44926     l_balance_type_code <> 'B' THEN
44927 IF NVL(p_source_13,'
44928 ') =  'FACTOR' AND 
44929 NVL(p_source_67,'
44930 ') =  'CRH' AND 
44931 NVL(p_source_52,'
44932 ') =  'N'
44933  THEN 
44934 
44935    --
44936    XLA_AE_LINES_PKG.SetNewLine;
44937 
44938    p_balance_type_code          := l_balance_type_code;
44939    -- set the flag so later we will know whether the gain loss line needs to be created
44940    
44941    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
44942      p_actual_flag :='A';
44943    END IF;
44944 
44945    --
44946    -- bulk performance
44947    --
44948    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
44949                                       p_header_num   => 0); -- 4262811
44950    --
44951    -- set accounting line options
44952    --
44953    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
44954            p_natural_side_code          => 'C'
44955          , p_gain_or_loss_flag          => 'N'
44956          , p_gl_transfer_mode_code      => 'S'
44957          , p_acct_entry_type_code       => 'A'
44958          , p_switch_side_flag           => 'Y'
44959          , p_merge_duplicate_code       => 'A'
44960          );
44961    --
44962    l_acc_rev_natural_side_code := 'D';  -- 4262811
44963    -- 
44964    --
44965    -- set accounting line type info
44966    --
44967    xla_ae_lines_pkg.SetAcctLineType
44968       (p_component_type             => l_component_type
44969       ,p_event_type_code            => l_event_type_code
44970       ,p_line_definition_owner_code => l_line_definition_owner_code
44971       ,p_line_definition_code       => l_line_definition_code
44972       ,p_accounting_line_code       => l_component_code
44973       ,p_accounting_line_type_code  => l_component_type_code
44974       ,p_accounting_line_appl_id    => l_component_appl_id
44975       ,p_amb_context_code           => l_amb_context_code
44976       ,p_entity_code                => l_entity_code
44977       ,p_event_class_code           => l_event_class_code);
44978    --
44979    -- set accounting class
44980    --
44981    xla_ae_lines_pkg.SetAcctClass(
44982            p_accounting_class_code  => 'FACTOR'
44983          , p_ae_header_id           => l_ae_header_id
44984          );
44985 
44986    --
44987    -- set rounding class
44988    --
44989    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
44990                       'RECEIVABLE';
44991 
44992    --
44993    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
44994    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
44995    --
44996    -- bulk performance
44997    --
44998    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
44999 
45000    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
45001       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
45002 
45003    -- 4955764
45004    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
45005       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
45006 
45007    -- 4458381 Public Sector Enh
45008    
45009    --
45010    -- set accounting attributes for the line type
45011    --
45012    l_entered_amt_idx := 8;
45013    l_accted_amt_idx  := 13;
45014    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
45015    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
45016    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
45017    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
45018    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
45019    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
45020    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
45021    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
45022    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
45023    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
45024    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
45025    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
45026    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
45027    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
45028    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
45029    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
45030    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
45031    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
45032    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
45033    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
45034    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
45035    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
45036    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
45037    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
45038    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
45039    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
45040    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
45041    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
45042    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
45043    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
45044    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
45045    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
45046    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
45047 
45048    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
45049    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
45050 
45051    ---------------------------------------------------------------------------------------------------------------
45052    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
45053    ---------------------------------------------------------------------------------------------------------------
45054    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
45055 
45056    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
45057    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
45058 
45059    IF xla_accounting_cache_pkg.GetValueChar
45060          (p_source_code         => 'LEDGER_CATEGORY_CODE'
45061          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
45062    AND l_bflow_method_code = 'PRIOR_ENTRY'
45063 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
45064    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
45065          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
45066        )
45067    THEN
45068          xla_ae_lines_pkg.BflowUpgEntry
45069            (p_business_method_code    => l_bflow_method_code
45070            ,p_business_class_code     => l_bflow_class_code
45071            ,p_balance_type            => l_balance_type_code);
45072    ELSE
45073       NULL;
45074 -- No business flow processing for business flow method of NONE.
45075    END IF;
45076 
45077    --
45078    -- call analytical criteria
45079    --
45080    
45081    --
45082    -- call description
45083    --
45084    -- No description or it is inherited.
45085    --
45086    -- call ADRs
45087    -- Bug 4922099
45088    --
45089    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
45090         (NVL(l_actual_upg_option, 'N') = 'O') OR
45091         (NVL(l_enc_upg_option, 'N') = 'O')
45092       )
45093    THEN
45094    NULL;
45095    --
45096    --
45097    
45098   l_ccid := AcctDerRule_7(
45099            p_application_id           => p_application_id
45100          , p_ae_header_id             => l_ae_header_id 
45101 , p_source_3 => p_source_3
45102          , x_transaction_coa_id       => l_adr_transaction_coa_id
45103          , x_accounting_coa_id        => l_adr_accounting_coa_id
45104          , x_value_type_code          => l_adr_value_type_code
45105          , p_side                     => 'NA'
45106    );
45107 
45108    xla_ae_lines_pkg.set_ccid(
45109     p_code_combination_id          => l_ccid
45110   , p_value_type_code              => l_adr_value_type_code
45111   , p_transaction_coa_id           => l_adr_transaction_coa_id
45112   , p_accounting_coa_id            => l_adr_accounting_coa_id
45113   , p_adr_code                     => 'DIST_CCID'
45114   , p_adr_type_code                => 'S'
45115   , p_component_type               => l_component_type
45116   , p_component_code               => l_component_code
45117   , p_component_type_code          => l_component_type_code
45118   , p_component_appl_id            => l_component_appl_id
45119   , p_amb_context_code             => l_amb_context_code
45120   , p_side                         => 'NA'
45121   );
45122 
45123 
45124    --
45125    --
45126    END IF;
45127    --
45128    -- Bug 4922099
45129    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
45130           (NVL(l_enc_upg_option, 'N') = 'O')
45131         ) AND
45132         (l_bflow_method_code = 'PRIOR_ENTRY')
45133       )
45134    THEN
45135       IF
45136       --
45137       1 = 2
45138       --
45139       THEN
45140       xla_accounting_err_pkg.build_message
45141                                     (p_appli_s_name            => 'XLA'
45142                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
45143                                     ,p_token_1                 => 'LINE_NUMBER'
45144                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
45145                                     ,p_token_2                 => 'LINE_TYPE_NAME'
45146                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
45147                                                                              l_component_type
45148                                                                             ,l_component_code
45149                                                                             ,l_component_type_code
45150                                                                             ,l_component_appl_id
45151                                                                             ,l_amb_context_code
45152                                                                             ,l_entity_code
45153                                                                             ,l_event_class_code
45154                                                                            )
45155                                     ,p_token_3                 => 'OWNER'
45156                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
45157                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
45158                                                                           ,p_lookup_code    => l_component_type_code
45159                                                                          )
45160                                     ,p_token_4                 => 'PRODUCT_NAME'
45161                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
45162                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
45163                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
45164                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
45165                                     ,p_ae_header_id            =>  NULL
45166                                        );
45167 
45168         IF (C_LEVEL_ERROR>= g_log_level) THEN
45169                  trace
45170                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
45171                       ,p_level    => C_LEVEL_ERROR
45172                       ,p_module   => l_log_module);
45173         END IF;
45174       END IF;
45175    END IF;
45176    --
45177    --
45178    ------------------------------------------------------------------------------------------------
45179    -- 4219869 Business Flow
45180    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
45181    -- Prior Entry.  Currently, the following code is always generated.
45182    ------------------------------------------------------------------------------------------------
45183    XLA_AE_LINES_PKG.ValidateCurrentLine;
45184 
45185    ------------------------------------------------------------------------------------
45186    -- 4219869 Business Flow
45187    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
45188    ------------------------------------------------------------------------------------
45189    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
45190 
45191    ----------------------------------------------------------------------------------
45192    -- 4219869 Business Flow
45193    -- Update journal entry status -- Need to generate this within IF <condition>
45194    ----------------------------------------------------------------------------------
45195    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
45196          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
45197          ,p_balance_type_code => l_balance_type_code
45198          );
45199 
45200    -------------------------------------------------------------------------------------------
45201    -- 4262811 - Generate the Accrual Reversal lines
45202    -------------------------------------------------------------------------------------------
45203    BEGIN
45204       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
45205                               (g_array_event(p_event_id).array_value_num('header_index'));
45206       IF l_acc_rev_flag IS NULL THEN
45207          l_acc_rev_flag := 'N';
45208       END IF;
45209    EXCEPTION
45210       WHEN OTHERS THEN
45211          l_acc_rev_flag := 'N';
45212    END;
45213    --
45214    IF (l_acc_rev_flag = 'Y') THEN
45215 
45216        -- 4645092  ------------------------------------------------------------------------------
45217        -- To allow MPA report to determine if it should generate report process
45218        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
45219        ------------------------------------------------------------------------------------------
45220 
45221        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
45222        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
45223    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
45224    -- call ADRs
45225    -- Bug 4922099
45226    --
45227    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
45228         (NVL(l_actual_upg_option, 'N') = 'O') OR
45229         (NVL(l_enc_upg_option, 'N') = 'O')
45230       )
45231    THEN
45232    NULL;
45233    --
45234    --
45235    
45236   l_ccid := AcctDerRule_7(
45237            p_application_id           => p_application_id
45238          , p_ae_header_id             => l_ae_header_id 
45239 , p_source_3 => p_source_3
45240          , x_transaction_coa_id       => l_adr_transaction_coa_id
45241          , x_accounting_coa_id        => l_adr_accounting_coa_id
45242          , x_value_type_code          => l_adr_value_type_code
45243          , p_side                     => 'NA'
45244    );
45245 
45246    xla_ae_lines_pkg.set_ccid(
45247     p_code_combination_id          => l_ccid
45248   , p_value_type_code              => l_adr_value_type_code
45249   , p_transaction_coa_id           => l_adr_transaction_coa_id
45250   , p_accounting_coa_id            => l_adr_accounting_coa_id
45251   , p_adr_code                     => 'DIST_CCID'
45252   , p_adr_type_code                => 'S'
45253   , p_component_type               => l_component_type
45254   , p_component_code               => l_component_code
45255   , p_component_type_code          => l_component_type_code
45256   , p_component_appl_id            => l_component_appl_id
45257   , p_amb_context_code             => l_amb_context_code
45258   , p_side                         => 'NA'
45259   );
45260 
45261 
45262    --
45263    --
45264    END IF;
45265 
45266        --
45267        -- Update the line information that should be overwritten
45268        --
45269        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
45270                                          p_header_num   => 1);
45271        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
45272 
45273        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
45274 
45275        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
45276           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
45277        END IF;
45278 
45279       --
45280       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
45281       --
45282       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
45283           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
45284       ELSE
45285           ---------------------------------------------------------------------------------------------------
45286           -- 4262811a Switch Sign
45287           ---------------------------------------------------------------------------------------------------
45288           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
45289           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
45290                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45291           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
45292                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45293           -- 5132302
45294           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
45295                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45296 
45297       END IF;
45298 
45299       -- 4955764
45300       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
45301       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
45302 
45303 
45304       XLA_AE_LINES_PKG.ValidateCurrentLine;
45305       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
45306 
45307       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
45308                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
45309                ,p_balance_type_code => l_balance_type_code);
45310 
45311    END IF;
45312 
45313    -----------------------------------------------------------------------------------------
45314    -- 4262811 Multiperiod Accounting
45315    -----------------------------------------------------------------------------------------
45316      -- No MPA option is assigned.
45317 
45318 
45319 END IF;
45320 END IF;
45321 --
45322 
45323 --
45324 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
45325    trace
45326       (p_msg      => 'END of AcctLineType_89'
45327       ,p_level    => C_LEVEL_PROCEDURE
45328       ,p_module   => l_log_module);
45329 END IF;
45330 --
45331 EXCEPTION
45332   WHEN xla_exceptions_pkg.application_exception THEN
45333       RAISE;
45334   WHEN OTHERS THEN
45335        xla_exceptions_pkg.raise_message
45336            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_89');
45337 END AcctLineType_89;
45338 --
45339 
45340 ---------------------------------------
45341 --
45342 -- PRIVATE FUNCTION
45343 --         AcctLineType_90
45344 --
45345 ---------------------------------------
45349  ,p_calculate_acctd_flag  IN VARCHAR2
45346 PROCEDURE AcctLineType_90 (
45347   p_application_id        IN NUMBER
45348  ,p_event_id              IN NUMBER
45350  ,p_calculate_g_l_flag    IN VARCHAR2
45351  ,p_actual_flag           IN OUT VARCHAR2
45352  ,p_balance_type_code     OUT VARCHAR2
45353  ,p_gain_or_loss_ref      OUT VARCHAR2
45354  
45355 --Distribution GL Account
45356  , p_source_3            IN NUMBER
45357 --Distribution Source Type
45358  , p_source_13            IN VARCHAR2
45359 --Distribution Line Identifier
45360  , p_source_15            IN NUMBER
45361 --Distribution Type
45362  , p_source_16            IN VARCHAR2
45363 --Exchange Date
45364  , p_source_19            IN DATE
45365 --Exchange Rate
45366  , p_source_20            IN NUMBER
45367 --Exchange Rate Type
45368  , p_source_21            IN VARCHAR2
45369 --Transaction Distribution Identifier
45370  , p_source_27            IN NUMBER
45371 --Transaction Distribution Type
45372  , p_source_28            IN VARCHAR2
45373 --Distribution Multi Fund Additional Entry
45374  , p_source_52            IN VARCHAR2
45375 --Receipt Applied To Application Identifier
45376  , p_source_56            IN NUMBER
45377 --Transaction Entity Code
45378  , p_source_57            IN VARCHAR2
45379 --Transaction Identifier
45380  , p_source_58            IN NUMBER
45381 --DIST_ENT_AMT_FROM
45382  , p_source_59            IN NUMBER
45383 --Applying Document Currency Code
45384  , p_source_60            IN VARCHAR2
45385 --Accounting Amount
45386  , p_source_61            IN NUMBER
45387 --Distribution Party Identifier
45388  , p_source_62            IN NUMBER
45389 --Distribution Party Site Id
45390  , p_source_63            IN NUMBER
45391 --Distribution Party Type
45392  , p_source_64            IN VARCHAR2
45393 --Distribution Source Table
45394  , p_source_67            IN VARCHAR2
45395 )
45396 IS
45397 
45398 l_component_type              VARCHAR2(80);
45399 l_component_code              VARCHAR2(30);
45400 l_component_type_code         VARCHAR2(1);
45401 l_component_appl_id           INTEGER;
45402 l_amb_context_code            VARCHAR2(30);
45403 l_entity_code                 VARCHAR2(30);
45404 l_event_class_code            VARCHAR2(30);
45405 l_ae_header_id                NUMBER;
45406 l_event_type_code             VARCHAR2(30);
45407 l_line_definition_code        VARCHAR2(30);
45408 l_line_definition_owner_code  VARCHAR2(1);
45409 --
45410 -- adr variables
45411 l_segment                     VARCHAR2(30);
45412 l_ccid                        NUMBER;
45413 l_adr_transaction_coa_id      NUMBER;
45414 l_adr_accounting_coa_id       NUMBER;
45415 l_adr_flexfield_segment_code  VARCHAR2(30);
45416 l_adr_flex_value_set_id       NUMBER;
45417 l_adr_value_type_code         VARCHAR2(30);
45418 l_adr_value_combination_id    NUMBER;
45419 l_adr_value_segment_code      VARCHAR2(30);
45420 
45421 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
45422 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
45423 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
45424 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
45425 
45426 -- 4262811 Variables ------------------------------------------------------------------------------------------
45427 l_entered_amt_idx             NUMBER;
45428 l_accted_amt_idx              NUMBER;
45429 l_acc_rev_flag                VARCHAR2(1);
45430 l_accrual_line_num            NUMBER;
45431 l_tmp_amt                     NUMBER;
45432 l_acc_rev_natural_side_code   VARCHAR2(1);
45433 
45434 l_num_entries                 NUMBER;
45435 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
45436 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
45437 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
45438 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
45439 l_recog_line_1                NUMBER;
45440 l_recog_line_2                NUMBER;
45441 
45442 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
45443 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
45444 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
45445 
45446 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
45447 
45448 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
45449 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
45450 
45451 ---------------------------------------------------------------------------------------------------------------
45452 
45453 
45454 --
45455 -- bulk performance
45456 --
45457 l_balance_type_code           VARCHAR2(1);
45458 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
45459 l_log_module                  VARCHAR2(240);
45460 
45461 --
45462 -- Upgrade strategy
45463 --
45464 l_actual_upg_option           VARCHAR2(1);
45465 l_enc_upg_option           VARCHAR2(1);
45466 
45467 --
45468 BEGIN
45469 --
45470 IF g_log_enabled THEN
45471       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_90';
45472 END IF;
45473 --
45474 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
45475 
45476       trace
45477          (p_msg      => 'BEGIN of AcctLineType_90'
45478          ,p_level    => C_LEVEL_PROCEDURE
45479          ,p_module   => l_log_module);
45480 
45484 l_component_code             := 'RCT_FACTOR_BR';
45481 END IF;
45482 --
45483 l_component_type             := 'AMB_JLT';
45485 l_component_type_code        := 'S';
45486 l_component_appl_id          :=  222;
45487 l_amb_context_code           := 'DEFAULT';
45488 l_entity_code                := 'RECEIPTS';
45489 l_event_class_code           := 'RECEIPT';
45490 l_event_type_code            := 'RECEIPT_ALL';
45491 l_line_definition_owner_code := 'S';
45492 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
45493 --
45494 l_balance_type_code          := 'A';
45495 l_segment                     := NULL;
45496 l_ccid                        := NULL;
45497 l_adr_transaction_coa_id      := NULL;
45498 l_adr_accounting_coa_id       := NULL;
45499 l_adr_flexfield_segment_code  := NULL;
45500 l_adr_flex_value_set_id       := NULL;
45501 l_adr_value_type_code         := NULL;
45502 l_adr_value_combination_id    := NULL;
45503 l_adr_value_segment_code      := NULL;
45504 
45505 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
45506 l_bflow_class_code           := '';    -- 4219869 Business Flow
45507 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
45508 l_budgetary_control_flag     := 'N';
45509 
45510 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
45511 l_bflow_applied_to_amt       := NULL; -- 5132302
45512 l_entered_amt_idx            := NULL;          -- 4262811
45513 l_accted_amt_idx             := NULL;          -- 4262811
45514 l_acc_rev_flag               := NULL;          -- 4262811
45515 l_accrual_line_num           := NULL;          -- 4262811
45516 l_tmp_amt                    := NULL;          -- 4262811
45517 --
45518  
45519 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
45520     l_balance_type_code <> 'B' THEN
45521 IF NVL(p_source_13,'
45522 ') =  'FACTOR' AND 
45523 NVL(p_source_67,'
45524 ') =  'RA' AND 
45525 NVL(p_source_52,'
45526 ') =  'N'
45527  THEN 
45528 
45529    --
45530    XLA_AE_LINES_PKG.SetNewLine;
45531 
45532    p_balance_type_code          := l_balance_type_code;
45533    -- set the flag so later we will know whether the gain loss line needs to be created
45534    
45535    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
45536      p_actual_flag :='A';
45537    END IF;
45538 
45539    --
45540    -- bulk performance
45541    --
45542    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
45543                                       p_header_num   => 0); -- 4262811
45544    --
45545    -- set accounting line options
45546    --
45547    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
45548            p_natural_side_code          => 'C'
45549          , p_gain_or_loss_flag          => 'N'
45550          , p_gl_transfer_mode_code      => 'S'
45551          , p_acct_entry_type_code       => 'A'
45552          , p_switch_side_flag           => 'Y'
45553          , p_merge_duplicate_code       => 'A'
45554          );
45555    --
45556    l_acc_rev_natural_side_code := 'D';  -- 4262811
45557    -- 
45558    --
45559    -- set accounting line type info
45560    --
45561    xla_ae_lines_pkg.SetAcctLineType
45562       (p_component_type             => l_component_type
45563       ,p_event_type_code            => l_event_type_code
45564       ,p_line_definition_owner_code => l_line_definition_owner_code
45565       ,p_line_definition_code       => l_line_definition_code
45566       ,p_accounting_line_code       => l_component_code
45567       ,p_accounting_line_type_code  => l_component_type_code
45568       ,p_accounting_line_appl_id    => l_component_appl_id
45569       ,p_amb_context_code           => l_amb_context_code
45570       ,p_entity_code                => l_entity_code
45571       ,p_event_class_code           => l_event_class_code);
45572    --
45573    -- set accounting class
45574    --
45575    xla_ae_lines_pkg.SetAcctClass(
45576            p_accounting_class_code  => 'FAC_BR'
45577          , p_ae_header_id           => l_ae_header_id
45578          );
45579 
45580    --
45581    -- set rounding class
45582    --
45583    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
45584                       'RECEIVABLE';
45585 
45586    --
45587    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
45588    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
45589    --
45590    -- bulk performance
45591    --
45592    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
45593 
45594    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
45595       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
45596 
45597    -- 4955764
45598    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
45599       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
45600 
45601    -- 4458381 Public Sector Enh
45602    
45603    --
45604    -- set accounting attributes for the line type
45605    --
45606    l_entered_amt_idx := 8;
45607    l_accted_amt_idx  := 13;
45608    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
45609    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
45610    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
45611    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
45612    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
45613    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
45614    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
45615    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
45616    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
45617    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
45618    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
45619    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
45620    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
45621    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
45622    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
45623    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
45624    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
45625    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
45626    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
45627    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
45628    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
45629    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
45630    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
45631    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
45632    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
45633    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
45634    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
45635    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
45636    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
45637    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
45638    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
45639    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
45640    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
45641 
45642    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
45643    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
45644 
45645    ---------------------------------------------------------------------------------------------------------------
45646    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
45647    ---------------------------------------------------------------------------------------------------------------
45648    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
45649 
45650    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
45651    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
45652 
45653    IF xla_accounting_cache_pkg.GetValueChar
45654          (p_source_code         => 'LEDGER_CATEGORY_CODE'
45655          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
45656    AND l_bflow_method_code = 'PRIOR_ENTRY'
45657 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
45658    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
45659          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
45660        )
45661    THEN
45662          xla_ae_lines_pkg.BflowUpgEntry
45663            (p_business_method_code    => l_bflow_method_code
45664            ,p_business_class_code     => l_bflow_class_code
45665            ,p_balance_type            => l_balance_type_code);
45666    ELSE
45667       NULL;
45668 -- No business flow processing for business flow method of NONE.
45669    END IF;
45670 
45671    --
45672    -- call analytical criteria
45673    --
45674    
45675    --
45676    -- call description
45677    --
45678    -- No description or it is inherited.
45679    --
45680    -- call ADRs
45681    -- Bug 4922099
45682    --
45683    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
45684         (NVL(l_actual_upg_option, 'N') = 'O') OR
45685         (NVL(l_enc_upg_option, 'N') = 'O')
45686       )
45687    THEN
45688    NULL;
45689    --
45690    --
45691    
45692   l_ccid := AcctDerRule_7(
45693            p_application_id           => p_application_id
45694          , p_ae_header_id             => l_ae_header_id 
45695 , p_source_3 => p_source_3
45696          , x_transaction_coa_id       => l_adr_transaction_coa_id
45697          , x_accounting_coa_id        => l_adr_accounting_coa_id
45698          , x_value_type_code          => l_adr_value_type_code
45699          , p_side                     => 'NA'
45700    );
45701 
45702    xla_ae_lines_pkg.set_ccid(
45703     p_code_combination_id          => l_ccid
45704   , p_value_type_code              => l_adr_value_type_code
45705   , p_transaction_coa_id           => l_adr_transaction_coa_id
45706   , p_accounting_coa_id            => l_adr_accounting_coa_id
45707   , p_adr_code                     => 'DIST_CCID'
45708   , p_adr_type_code                => 'S'
45709   , p_component_type               => l_component_type
45710   , p_component_code               => l_component_code
45711   , p_component_type_code          => l_component_type_code
45712   , p_component_appl_id            => l_component_appl_id
45713   , p_amb_context_code             => l_amb_context_code
45714   , p_side                         => 'NA'
45715   );
45716 
45717 
45718    --
45719    --
45720    END IF;
45721    --
45722    -- Bug 4922099
45723    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
45724           (NVL(l_enc_upg_option, 'N') = 'O')
45725         ) AND
45726         (l_bflow_method_code = 'PRIOR_ENTRY')
45727       )
45728    THEN
45729       IF
45730       --
45731       1 = 2
45732       --
45733       THEN
45734       xla_accounting_err_pkg.build_message
45735                                     (p_appli_s_name            => 'XLA'
45736                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
45737                                     ,p_token_1                 => 'LINE_NUMBER'
45738                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
45739                                     ,p_token_2                 => 'LINE_TYPE_NAME'
45740                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
45741                                                                              l_component_type
45742                                                                             ,l_component_code
45743                                                                             ,l_component_type_code
45744                                                                             ,l_component_appl_id
45745                                                                             ,l_amb_context_code
45746                                                                             ,l_entity_code
45747                                                                             ,l_event_class_code
45748                                                                            )
45749                                     ,p_token_3                 => 'OWNER'
45750                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
45751                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
45752                                                                           ,p_lookup_code    => l_component_type_code
45753                                                                          )
45754                                     ,p_token_4                 => 'PRODUCT_NAME'
45755                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
45756                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
45757                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
45758                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
45759                                     ,p_ae_header_id            =>  NULL
45760                                        );
45761 
45762         IF (C_LEVEL_ERROR>= g_log_level) THEN
45763                  trace
45764                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
45765                       ,p_level    => C_LEVEL_ERROR
45766                       ,p_module   => l_log_module);
45767         END IF;
45768       END IF;
45769    END IF;
45770    --
45771    --
45772    ------------------------------------------------------------------------------------------------
45773    -- 4219869 Business Flow
45774    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
45775    -- Prior Entry.  Currently, the following code is always generated.
45776    ------------------------------------------------------------------------------------------------
45777    XLA_AE_LINES_PKG.ValidateCurrentLine;
45778 
45779    ------------------------------------------------------------------------------------
45780    -- 4219869 Business Flow
45781    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
45782    ------------------------------------------------------------------------------------
45783    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
45784 
45785    ----------------------------------------------------------------------------------
45786    -- 4219869 Business Flow
45787    -- Update journal entry status -- Need to generate this within IF <condition>
45788    ----------------------------------------------------------------------------------
45789    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
45790          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
45791          ,p_balance_type_code => l_balance_type_code
45792          );
45793 
45794    -------------------------------------------------------------------------------------------
45795    -- 4262811 - Generate the Accrual Reversal lines
45796    -------------------------------------------------------------------------------------------
45797    BEGIN
45798       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
45799                               (g_array_event(p_event_id).array_value_num('header_index'));
45800       IF l_acc_rev_flag IS NULL THEN
45801          l_acc_rev_flag := 'N';
45802       END IF;
45803    EXCEPTION
45804       WHEN OTHERS THEN
45805          l_acc_rev_flag := 'N';
45806    END;
45807    --
45808    IF (l_acc_rev_flag = 'Y') THEN
45809 
45810        -- 4645092  ------------------------------------------------------------------------------
45811        -- To allow MPA report to determine if it should generate report process
45812        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
45813        ------------------------------------------------------------------------------------------
45814 
45815        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
45816        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
45817    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
45818    -- call ADRs
45819    -- Bug 4922099
45820    --
45821    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
45822         (NVL(l_actual_upg_option, 'N') = 'O') OR
45823         (NVL(l_enc_upg_option, 'N') = 'O')
45824       )
45825    THEN
45826    NULL;
45827    --
45828    --
45829    
45830   l_ccid := AcctDerRule_7(
45831            p_application_id           => p_application_id
45832          , p_ae_header_id             => l_ae_header_id 
45833 , p_source_3 => p_source_3
45834          , x_transaction_coa_id       => l_adr_transaction_coa_id
45835          , x_accounting_coa_id        => l_adr_accounting_coa_id
45836          , x_value_type_code          => l_adr_value_type_code
45837          , p_side                     => 'NA'
45838    );
45839 
45840    xla_ae_lines_pkg.set_ccid(
45841     p_code_combination_id          => l_ccid
45842   , p_value_type_code              => l_adr_value_type_code
45843   , p_transaction_coa_id           => l_adr_transaction_coa_id
45844   , p_accounting_coa_id            => l_adr_accounting_coa_id
45845   , p_adr_code                     => 'DIST_CCID'
45846   , p_adr_type_code                => 'S'
45847   , p_component_type               => l_component_type
45848   , p_component_code               => l_component_code
45849   , p_component_type_code          => l_component_type_code
45850   , p_component_appl_id            => l_component_appl_id
45851   , p_amb_context_code             => l_amb_context_code
45852   , p_side                         => 'NA'
45853   );
45854 
45855 
45856    --
45857    --
45858    END IF;
45859 
45860        --
45861        -- Update the line information that should be overwritten
45862        --
45863        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
45864                                          p_header_num   => 1);
45865        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
45866 
45867        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
45868 
45869        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
45870           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
45871        END IF;
45872 
45873       --
45874       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
45875       --
45876       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
45877           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
45878       ELSE
45879           ---------------------------------------------------------------------------------------------------
45880           -- 4262811a Switch Sign
45881           ---------------------------------------------------------------------------------------------------
45882           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
45883           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
45884                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45885           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
45886                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45887           -- 5132302
45888           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
45889                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
45890 
45891       END IF;
45892 
45893       -- 4955764
45894       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
45895       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
45896 
45897 
45898       XLA_AE_LINES_PKG.ValidateCurrentLine;
45899       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
45900 
45901       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
45902                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
45903                ,p_balance_type_code => l_balance_type_code);
45904 
45905    END IF;
45906 
45907    -----------------------------------------------------------------------------------------
45911 
45908    -- 4262811 Multiperiod Accounting
45909    -----------------------------------------------------------------------------------------
45910      -- No MPA option is assigned.
45912 
45913 END IF;
45914 END IF;
45915 --
45916 
45917 --
45918 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
45919    trace
45920       (p_msg      => 'END of AcctLineType_90'
45921       ,p_level    => C_LEVEL_PROCEDURE
45922       ,p_module   => l_log_module);
45923 END IF;
45924 --
45925 EXCEPTION
45926   WHEN xla_exceptions_pkg.application_exception THEN
45927       RAISE;
45928   WHEN OTHERS THEN
45929        xla_exceptions_pkg.raise_message
45930            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_90');
45931 END AcctLineType_90;
45932 --
45933 
45934 ---------------------------------------
45935 --
45936 -- PRIVATE FUNCTION
45937 --         AcctLineType_91
45938 --
45939 ---------------------------------------
45940 PROCEDURE AcctLineType_91 (
45941   p_application_id        IN NUMBER
45942  ,p_event_id              IN NUMBER
45943  ,p_calculate_acctd_flag  IN VARCHAR2
45944  ,p_calculate_g_l_flag    IN VARCHAR2
45945  ,p_actual_flag           IN OUT VARCHAR2
45946  ,p_balance_type_code     OUT VARCHAR2
45947  ,p_gain_or_loss_ref      OUT VARCHAR2
45948  
45949 --Distribution GL Account
45950  , p_source_3            IN NUMBER
45951 --Distribution Source Type
45952  , p_source_13            IN VARCHAR2
45953 --Receivable Activity Type
45954  , p_source_14            IN VARCHAR2
45955 --Distribution Line Identifier
45956  , p_source_15            IN NUMBER
45957 --Distribution Type
45958  , p_source_16            IN VARCHAR2
45959 --Exchange Date
45960  , p_source_19            IN DATE
45961 --Exchange Rate
45962  , p_source_20            IN NUMBER
45963 --Exchange Rate Type
45964  , p_source_21            IN VARCHAR2
45965 --Applied To Document Accounting Amount
45966  , p_source_22            IN NUMBER
45967 --Transaction Distribution Identifier
45968  , p_source_27            IN NUMBER
45969 --Transaction Distribution Type
45970  , p_source_28            IN VARCHAR2
45971 --Distribution Multi Fund Additional Entry
45972  , p_source_52            IN VARCHAR2
45973 --Receipt Applied To Application Identifier
45974  , p_source_56            IN NUMBER
45975 --Transaction Entity Code
45976  , p_source_57            IN VARCHAR2
45977 --Transaction Identifier
45978  , p_source_58            IN NUMBER
45979 --DIST_ENT_AMT_FROM
45980  , p_source_59            IN NUMBER
45981 --Applying Document Currency Code
45982  , p_source_60            IN VARCHAR2
45983 --Distribution Party Identifier
45984  , p_source_62            IN NUMBER
45985 --Distribution Party Site Id
45986  , p_source_63            IN NUMBER
45987 --Distribution Party Type
45988  , p_source_64            IN VARCHAR2
45989 )
45990 IS
45991 
45992 l_component_type              VARCHAR2(80);
45993 l_component_code              VARCHAR2(30);
45994 l_component_type_code         VARCHAR2(1);
45995 l_component_appl_id           INTEGER;
45996 l_amb_context_code            VARCHAR2(30);
45997 l_entity_code                 VARCHAR2(30);
45998 l_event_class_code            VARCHAR2(30);
45999 l_ae_header_id                NUMBER;
46000 l_event_type_code             VARCHAR2(30);
46001 l_line_definition_code        VARCHAR2(30);
46002 l_line_definition_owner_code  VARCHAR2(1);
46003 --
46004 -- adr variables
46005 l_segment                     VARCHAR2(30);
46006 l_ccid                        NUMBER;
46007 l_adr_transaction_coa_id      NUMBER;
46008 l_adr_accounting_coa_id       NUMBER;
46009 l_adr_flexfield_segment_code  VARCHAR2(30);
46010 l_adr_flex_value_set_id       NUMBER;
46011 l_adr_value_type_code         VARCHAR2(30);
46012 l_adr_value_combination_id    NUMBER;
46013 l_adr_value_segment_code      VARCHAR2(30);
46014 
46015 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
46016 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
46017 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
46018 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
46019 
46020 -- 4262811 Variables ------------------------------------------------------------------------------------------
46021 l_entered_amt_idx             NUMBER;
46022 l_accted_amt_idx              NUMBER;
46023 l_acc_rev_flag                VARCHAR2(1);
46024 l_accrual_line_num            NUMBER;
46025 l_tmp_amt                     NUMBER;
46026 l_acc_rev_natural_side_code   VARCHAR2(1);
46027 
46028 l_num_entries                 NUMBER;
46029 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
46030 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
46031 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
46032 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
46033 l_recog_line_1                NUMBER;
46034 l_recog_line_2                NUMBER;
46035 
46036 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
46037 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
46038 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
46039 
46040 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
46041 
46042 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
46043 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
46044 
46045 ---------------------------------------------------------------------------------------------------------------
46046 
46047 
46048 --
46049 -- bulk performance
46050 --
46051 l_balance_type_code           VARCHAR2(1);
46052 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
46053 l_log_module                  VARCHAR2(240);
46054 
46055 --
46056 -- Upgrade strategy
46057 --
46058 l_actual_upg_option           VARCHAR2(1);
46059 l_enc_upg_option           VARCHAR2(1);
46060 
46061 --
46062 BEGIN
46063 --
46064 IF g_log_enabled THEN
46065       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_91';
46066 END IF;
46067 --
46068 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
46069 
46070       trace
46071          (p_msg      => 'BEGIN of AcctLineType_91'
46072          ,p_level    => C_LEVEL_PROCEDURE
46073          ,p_module   => l_log_module);
46074 
46075 END IF;
46076 --
46077 l_component_type             := 'AMB_JLT';
46078 l_component_code             := 'RCT_PMT_NET';
46079 l_component_type_code        := 'S';
46080 l_component_appl_id          :=  222;
46081 l_amb_context_code           := 'DEFAULT';
46082 l_entity_code                := 'RECEIPTS';
46083 l_event_class_code           := 'RECEIPT';
46084 l_event_type_code            := 'RECEIPT_ALL';
46085 l_line_definition_owner_code := 'S';
46086 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
46087 --
46088 l_balance_type_code          := 'A';
46089 l_segment                     := NULL;
46090 l_ccid                        := NULL;
46091 l_adr_transaction_coa_id      := NULL;
46092 l_adr_accounting_coa_id       := NULL;
46093 l_adr_flexfield_segment_code  := NULL;
46094 l_adr_flex_value_set_id       := NULL;
46095 l_adr_value_type_code         := NULL;
46096 l_adr_value_combination_id    := NULL;
46097 l_adr_value_segment_code      := NULL;
46098 
46099 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
46100 l_bflow_class_code           := '';    -- 4219869 Business Flow
46101 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
46102 l_budgetary_control_flag     := 'N';
46103 
46104 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
46105 l_bflow_applied_to_amt       := NULL; -- 5132302
46106 l_entered_amt_idx            := NULL;          -- 4262811
46107 l_accted_amt_idx             := NULL;          -- 4262811
46108 l_acc_rev_flag               := NULL;          -- 4262811
46109 l_accrual_line_num           := NULL;          -- 4262811
46110 l_tmp_amt                    := NULL;          -- 4262811
46111 --
46112  
46113 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
46114     l_balance_type_code <> 'B' THEN
46115 IF (NVL(p_source_13,'
46116 ') =  'OTHER_ACC' OR 
46117 NVL(p_source_13,'
46118 ') =  'ACTIVITY') AND 
46119 NVL(p_source_14,'
46120 ') =  'NETTING' AND 
46121 NVL(p_source_52,'
46122 ') =  'N'
46123  THEN 
46124 
46125    --
46126    XLA_AE_LINES_PKG.SetNewLine;
46127 
46128    p_balance_type_code          := l_balance_type_code;
46129    -- set the flag so later we will know whether the gain loss line needs to be created
46130    
46131    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
46132      p_actual_flag :='A';
46133    END IF;
46134 
46135    --
46136    -- bulk performance
46137    --
46138    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
46139                                       p_header_num   => 0); -- 4262811
46140    --
46141    -- set accounting line options
46142    --
46143    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
46144            p_natural_side_code          => 'C'
46145          , p_gain_or_loss_flag          => 'N'
46146          , p_gl_transfer_mode_code      => 'S'
46147          , p_acct_entry_type_code       => 'A'
46148          , p_switch_side_flag           => 'Y'
46149          , p_merge_duplicate_code       => 'A'
46150          );
46151    --
46152    l_acc_rev_natural_side_code := 'D';  -- 4262811
46153    -- 
46154    --
46155    -- set accounting line type info
46156    --
46157    xla_ae_lines_pkg.SetAcctLineType
46158       (p_component_type             => l_component_type
46159       ,p_event_type_code            => l_event_type_code
46160       ,p_line_definition_owner_code => l_line_definition_owner_code
46161       ,p_line_definition_code       => l_line_definition_code
46162       ,p_accounting_line_code       => l_component_code
46163       ,p_accounting_line_type_code  => l_component_type_code
46164       ,p_accounting_line_appl_id    => l_component_appl_id
46165       ,p_amb_context_code           => l_amb_context_code
46166       ,p_entity_code                => l_entity_code
46167       ,p_event_class_code           => l_event_class_code);
46168    --
46169    -- set accounting class
46170    --
46171    xla_ae_lines_pkg.SetAcctClass(
46172            p_accounting_class_code  => 'PMT_NET'
46173          , p_ae_header_id           => l_ae_header_id
46174          );
46175 
46176    --
46177    -- set rounding class
46178    --
46179    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
46180                       'RECEIVABLE';
46181 
46182    --
46183    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
46184    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
46185    --
46186    -- bulk performance
46187    --
46188    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
46189 
46190    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
46191       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
46192 
46193    -- 4955764
46194    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
46195       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
46196 
46197    -- 4458381 Public Sector Enh
46198    
46199    --
46200    -- set accounting attributes for the line type
46201    --
46202    l_entered_amt_idx := 8;
46203    l_accted_amt_idx  := 13;
46204    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
46205    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
46206    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
46207    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
46208    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
46209    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
46210    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
46211    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
46212    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
46213    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
46214    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
46215    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
46216    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
46217    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
46218    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
46219    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
46220    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
46221    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
46222    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
46223    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
46224    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
46225    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
46226    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
46227    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
46228    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
46229    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
46230    l_rec_acct_attrs.array_num_value(13)  := p_source_22;
46231    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
46232    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
46233    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
46234    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
46235    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
46236    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
46237 
46238    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
46239    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
46240 
46241    ---------------------------------------------------------------------------------------------------------------
46242    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
46243    ---------------------------------------------------------------------------------------------------------------
46244    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
46245 
46246    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
46247    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
46248 
46249    IF xla_accounting_cache_pkg.GetValueChar
46250          (p_source_code         => 'LEDGER_CATEGORY_CODE'
46251          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
46252    AND l_bflow_method_code = 'PRIOR_ENTRY'
46253 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
46254    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
46255          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
46256        )
46257    THEN
46258          xla_ae_lines_pkg.BflowUpgEntry
46259            (p_business_method_code    => l_bflow_method_code
46260            ,p_business_class_code     => l_bflow_class_code
46261            ,p_balance_type            => l_balance_type_code);
46262    ELSE
46263       NULL;
46264 -- No business flow processing for business flow method of NONE.
46265    END IF;
46266 
46267    --
46268    -- call analytical criteria
46269    --
46270    
46271    --
46272    -- call description
46273    --
46274    -- No description or it is inherited.
46275    --
46276    -- call ADRs
46277    -- Bug 4922099
46278    --
46279    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
46280         (NVL(l_actual_upg_option, 'N') = 'O') OR
46281         (NVL(l_enc_upg_option, 'N') = 'O')
46282       )
46283    THEN
46284    NULL;
46285    --
46286    --
46287    
46288   l_ccid := AcctDerRule_7(
46289            p_application_id           => p_application_id
46290          , p_ae_header_id             => l_ae_header_id 
46291 , p_source_3 => p_source_3
46292          , x_transaction_coa_id       => l_adr_transaction_coa_id
46293          , x_accounting_coa_id        => l_adr_accounting_coa_id
46294          , x_value_type_code          => l_adr_value_type_code
46295          , p_side                     => 'NA'
46296    );
46300   , p_value_type_code              => l_adr_value_type_code
46297 
46298    xla_ae_lines_pkg.set_ccid(
46299     p_code_combination_id          => l_ccid
46301   , p_transaction_coa_id           => l_adr_transaction_coa_id
46302   , p_accounting_coa_id            => l_adr_accounting_coa_id
46303   , p_adr_code                     => 'DIST_CCID'
46304   , p_adr_type_code                => 'S'
46305   , p_component_type               => l_component_type
46306   , p_component_code               => l_component_code
46307   , p_component_type_code          => l_component_type_code
46308   , p_component_appl_id            => l_component_appl_id
46309   , p_amb_context_code             => l_amb_context_code
46310   , p_side                         => 'NA'
46311   );
46312 
46313 
46314    --
46315    --
46316    END IF;
46317    --
46318    -- Bug 4922099
46319    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
46320           (NVL(l_enc_upg_option, 'N') = 'O')
46321         ) AND
46322         (l_bflow_method_code = 'PRIOR_ENTRY')
46323       )
46324    THEN
46325       IF
46326       --
46327       1 = 2
46328       --
46329       THEN
46330       xla_accounting_err_pkg.build_message
46331                                     (p_appli_s_name            => 'XLA'
46332                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
46333                                     ,p_token_1                 => 'LINE_NUMBER'
46334                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
46335                                     ,p_token_2                 => 'LINE_TYPE_NAME'
46336                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
46337                                                                              l_component_type
46338                                                                             ,l_component_code
46339                                                                             ,l_component_type_code
46340                                                                             ,l_component_appl_id
46341                                                                             ,l_amb_context_code
46342                                                                             ,l_entity_code
46343                                                                             ,l_event_class_code
46344                                                                            )
46345                                     ,p_token_3                 => 'OWNER'
46346                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
46347                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
46348                                                                           ,p_lookup_code    => l_component_type_code
46349                                                                          )
46350                                     ,p_token_4                 => 'PRODUCT_NAME'
46351                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
46352                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
46353                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
46354                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
46355                                     ,p_ae_header_id            =>  NULL
46356                                        );
46357 
46358         IF (C_LEVEL_ERROR>= g_log_level) THEN
46359                  trace
46360                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
46361                       ,p_level    => C_LEVEL_ERROR
46362                       ,p_module   => l_log_module);
46363         END IF;
46364       END IF;
46365    END IF;
46366    --
46367    --
46368    ------------------------------------------------------------------------------------------------
46369    -- 4219869 Business Flow
46370    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
46371    -- Prior Entry.  Currently, the following code is always generated.
46372    ------------------------------------------------------------------------------------------------
46373    XLA_AE_LINES_PKG.ValidateCurrentLine;
46374 
46375    ------------------------------------------------------------------------------------
46376    -- 4219869 Business Flow
46377    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
46378    ------------------------------------------------------------------------------------
46379    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
46380 
46381    ----------------------------------------------------------------------------------
46382    -- 4219869 Business Flow
46383    -- Update journal entry status -- Need to generate this within IF <condition>
46384    ----------------------------------------------------------------------------------
46385    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
46386          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
46387          ,p_balance_type_code => l_balance_type_code
46388          );
46389 
46390    -------------------------------------------------------------------------------------------
46391    -- 4262811 - Generate the Accrual Reversal lines
46392    -------------------------------------------------------------------------------------------
46393    BEGIN
46394       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
46398       END IF;
46395                               (g_array_event(p_event_id).array_value_num('header_index'));
46396       IF l_acc_rev_flag IS NULL THEN
46397          l_acc_rev_flag := 'N';
46399    EXCEPTION
46400       WHEN OTHERS THEN
46401          l_acc_rev_flag := 'N';
46402    END;
46403    --
46404    IF (l_acc_rev_flag = 'Y') THEN
46405 
46406        -- 4645092  ------------------------------------------------------------------------------
46407        -- To allow MPA report to determine if it should generate report process
46408        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
46409        ------------------------------------------------------------------------------------------
46410 
46411        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
46412        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
46413    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
46414    -- call ADRs
46415    -- Bug 4922099
46416    --
46417    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
46418         (NVL(l_actual_upg_option, 'N') = 'O') OR
46419         (NVL(l_enc_upg_option, 'N') = 'O')
46420       )
46421    THEN
46422    NULL;
46423    --
46424    --
46425    
46426   l_ccid := AcctDerRule_7(
46427            p_application_id           => p_application_id
46428          , p_ae_header_id             => l_ae_header_id 
46429 , p_source_3 => p_source_3
46430          , x_transaction_coa_id       => l_adr_transaction_coa_id
46431          , x_accounting_coa_id        => l_adr_accounting_coa_id
46432          , x_value_type_code          => l_adr_value_type_code
46433          , p_side                     => 'NA'
46434    );
46435 
46436    xla_ae_lines_pkg.set_ccid(
46437     p_code_combination_id          => l_ccid
46438   , p_value_type_code              => l_adr_value_type_code
46439   , p_transaction_coa_id           => l_adr_transaction_coa_id
46440   , p_accounting_coa_id            => l_adr_accounting_coa_id
46441   , p_adr_code                     => 'DIST_CCID'
46442   , p_adr_type_code                => 'S'
46443   , p_component_type               => l_component_type
46444   , p_component_code               => l_component_code
46445   , p_component_type_code          => l_component_type_code
46446   , p_component_appl_id            => l_component_appl_id
46447   , p_amb_context_code             => l_amb_context_code
46448   , p_side                         => 'NA'
46449   );
46450 
46451 
46452    --
46453    --
46454    END IF;
46455 
46456        --
46457        -- Update the line information that should be overwritten
46458        --
46459        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
46460                                          p_header_num   => 1);
46461        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
46462 
46463        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
46464 
46465        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
46466           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
46467        END IF;
46468 
46469       --
46470       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
46471       --
46472       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
46473           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
46474       ELSE
46475           ---------------------------------------------------------------------------------------------------
46476           -- 4262811a Switch Sign
46477           ---------------------------------------------------------------------------------------------------
46478           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
46479           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
46480                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
46481           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
46482                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
46483           -- 5132302
46484           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
46485                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
46486 
46487       END IF;
46488 
46489       -- 4955764
46490       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
46491       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
46492 
46493 
46494       XLA_AE_LINES_PKG.ValidateCurrentLine;
46495       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
46496 
46497       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
46498                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
46499                ,p_balance_type_code => l_balance_type_code);
46500 
46501    END IF;
46502 
46503    -----------------------------------------------------------------------------------------
46504    -- 4262811 Multiperiod Accounting
46505    -----------------------------------------------------------------------------------------
46506      -- No MPA option is assigned.
46507 
46508 
46509 END IF;
46510 END IF;
46511 --
46512 
46513 --
46514 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
46515    trace
46516       (p_msg      => 'END of AcctLineType_91'
46517       ,p_level    => C_LEVEL_PROCEDURE
46518       ,p_module   => l_log_module);
46519 END IF;
46520 --
46521 EXCEPTION
46522   WHEN xla_exceptions_pkg.application_exception THEN
46523       RAISE;
46524   WHEN OTHERS THEN
46525        xla_exceptions_pkg.raise_message
46526            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_91');
46527 END AcctLineType_91;
46528 --
46529 
46530 ---------------------------------------
46531 --
46532 -- PRIVATE FUNCTION
46533 --         AcctLineType_92
46534 --
46535 ---------------------------------------
46536 PROCEDURE AcctLineType_92 (
46537   p_application_id        IN NUMBER
46538  ,p_event_id              IN NUMBER
46539  ,p_calculate_acctd_flag  IN VARCHAR2
46540  ,p_calculate_g_l_flag    IN VARCHAR2
46541  ,p_actual_flag           IN OUT VARCHAR2
46542  ,p_balance_type_code     OUT VARCHAR2
46543  ,p_gain_or_loss_ref      OUT VARCHAR2
46544  
46545 --Distribution GL Account
46546  , p_source_3            IN NUMBER
46547 --Distribution Source Type
46548  , p_source_13            IN VARCHAR2
46549 --Receivable Activity Type
46550  , p_source_14            IN VARCHAR2
46551 --Distribution Line Identifier
46552  , p_source_15            IN NUMBER
46553 --Distribution Type
46554  , p_source_16            IN VARCHAR2
46555 --Exchange Date
46556  , p_source_19            IN DATE
46557 --Exchange Rate
46558  , p_source_20            IN NUMBER
46559 --Exchange Rate Type
46560  , p_source_21            IN VARCHAR2
46561 --Transaction Distribution Identifier
46562  , p_source_27            IN NUMBER
46563 --Transaction Distribution Type
46564  , p_source_28            IN VARCHAR2
46565 --Distribution Multi Fund Additional Entry
46566  , p_source_52            IN VARCHAR2
46567 --Receipt Applied To Application Identifier
46568  , p_source_56            IN NUMBER
46569 --Transaction Entity Code
46570  , p_source_57            IN VARCHAR2
46571 --Transaction Identifier
46572  , p_source_58            IN NUMBER
46573 --DIST_ENT_AMT_FROM
46574  , p_source_59            IN NUMBER
46575 --Applying Document Currency Code
46576  , p_source_60            IN VARCHAR2
46577 --Accounting Amount
46578  , p_source_61            IN NUMBER
46579 --Distribution Party Identifier
46580  , p_source_62            IN NUMBER
46581 --Distribution Party Site Id
46582  , p_source_63            IN NUMBER
46583 --Distribution Party Type
46584  , p_source_64            IN VARCHAR2
46585 )
46586 IS
46587 
46588 l_component_type              VARCHAR2(80);
46589 l_component_code              VARCHAR2(30);
46590 l_component_type_code         VARCHAR2(1);
46591 l_component_appl_id           INTEGER;
46592 l_amb_context_code            VARCHAR2(30);
46593 l_entity_code                 VARCHAR2(30);
46594 l_event_class_code            VARCHAR2(30);
46595 l_ae_header_id                NUMBER;
46596 l_event_type_code             VARCHAR2(30);
46597 l_line_definition_code        VARCHAR2(30);
46598 l_line_definition_owner_code  VARCHAR2(1);
46599 --
46600 -- adr variables
46601 l_segment                     VARCHAR2(30);
46602 l_ccid                        NUMBER;
46603 l_adr_transaction_coa_id      NUMBER;
46604 l_adr_accounting_coa_id       NUMBER;
46605 l_adr_flexfield_segment_code  VARCHAR2(30);
46606 l_adr_flex_value_set_id       NUMBER;
46607 l_adr_value_type_code         VARCHAR2(30);
46608 l_adr_value_combination_id    NUMBER;
46609 l_adr_value_segment_code      VARCHAR2(30);
46610 
46611 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
46612 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
46613 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
46614 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
46615 
46619 l_acc_rev_flag                VARCHAR2(1);
46616 -- 4262811 Variables ------------------------------------------------------------------------------------------
46617 l_entered_amt_idx             NUMBER;
46618 l_accted_amt_idx              NUMBER;
46620 l_accrual_line_num            NUMBER;
46621 l_tmp_amt                     NUMBER;
46622 l_acc_rev_natural_side_code   VARCHAR2(1);
46623 
46624 l_num_entries                 NUMBER;
46625 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
46626 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
46627 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
46628 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
46629 l_recog_line_1                NUMBER;
46630 l_recog_line_2                NUMBER;
46631 
46632 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
46633 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
46634 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
46635 
46636 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
46637 
46638 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
46639 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
46640 
46641 ---------------------------------------------------------------------------------------------------------------
46642 
46643 
46644 --
46645 -- bulk performance
46646 --
46647 l_balance_type_code           VARCHAR2(1);
46648 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
46649 l_log_module                  VARCHAR2(240);
46650 
46651 --
46652 -- Upgrade strategy
46653 --
46654 l_actual_upg_option           VARCHAR2(1);
46655 l_enc_upg_option           VARCHAR2(1);
46656 
46657 --
46658 BEGIN
46659 --
46660 IF g_log_enabled THEN
46661       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_92';
46662 END IF;
46663 --
46664 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
46665 
46666       trace
46667          (p_msg      => 'BEGIN of AcctLineType_92'
46668          ,p_level    => C_LEVEL_PROCEDURE
46669          ,p_module   => l_log_module);
46670 
46671 END IF;
46672 --
46673 l_component_type             := 'AMB_JLT';
46674 l_component_code             := 'RCT_PREPAYMENT';
46675 l_component_type_code        := 'S';
46676 l_component_appl_id          :=  222;
46677 l_amb_context_code           := 'DEFAULT';
46678 l_entity_code                := 'RECEIPTS';
46679 l_event_class_code           := 'RECEIPT';
46680 l_event_type_code            := 'RECEIPT_ALL';
46681 l_line_definition_owner_code := 'S';
46682 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
46683 --
46684 l_balance_type_code          := 'A';
46685 l_segment                     := NULL;
46686 l_ccid                        := NULL;
46687 l_adr_transaction_coa_id      := NULL;
46688 l_adr_accounting_coa_id       := NULL;
46689 l_adr_flexfield_segment_code  := NULL;
46690 l_adr_flex_value_set_id       := NULL;
46691 l_adr_value_type_code         := NULL;
46692 l_adr_value_combination_id    := NULL;
46693 l_adr_value_segment_code      := NULL;
46694 
46695 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
46696 l_bflow_class_code           := '';    -- 4219869 Business Flow
46697 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
46698 l_budgetary_control_flag     := 'N';
46699 
46700 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
46701 l_bflow_applied_to_amt       := NULL; -- 5132302
46702 l_entered_amt_idx            := NULL;          -- 4262811
46703 l_accted_amt_idx             := NULL;          -- 4262811
46704 l_acc_rev_flag               := NULL;          -- 4262811
46705 l_accrual_line_num           := NULL;          -- 4262811
46706 l_tmp_amt                    := NULL;          -- 4262811
46707 --
46708  
46709 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
46710     l_balance_type_code <> 'B' THEN
46711 IF NVL(p_source_13,'
46712 ') =  'OTHER ACC' AND 
46713 NVL(p_source_14,'
46714 ') =  'PREPAYMENT' AND 
46715 NVL(p_source_52,'
46716 ') =  'N'
46717  THEN 
46718 
46719    --
46720    XLA_AE_LINES_PKG.SetNewLine;
46721 
46722    p_balance_type_code          := l_balance_type_code;
46723    -- set the flag so later we will know whether the gain loss line needs to be created
46724    
46725    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
46726      p_actual_flag :='A';
46727    END IF;
46728 
46729    --
46730    -- bulk performance
46731    --
46732    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
46733                                       p_header_num   => 0); -- 4262811
46734    --
46735    -- set accounting line options
46736    --
46737    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
46738            p_natural_side_code          => 'C'
46739          , p_gain_or_loss_flag          => 'N'
46740          , p_gl_transfer_mode_code      => 'S'
46741          , p_acct_entry_type_code       => 'A'
46742          , p_switch_side_flag           => 'Y'
46743          , p_merge_duplicate_code       => 'A'
46744          );
46745    --
46746    l_acc_rev_natural_side_code := 'D';  -- 4262811
46747    -- 
46748    --
46749    -- set accounting line type info
46750    --
46751    xla_ae_lines_pkg.SetAcctLineType
46752       (p_component_type             => l_component_type
46753       ,p_event_type_code            => l_event_type_code
46757       ,p_accounting_line_type_code  => l_component_type_code
46754       ,p_line_definition_owner_code => l_line_definition_owner_code
46755       ,p_line_definition_code       => l_line_definition_code
46756       ,p_accounting_line_code       => l_component_code
46758       ,p_accounting_line_appl_id    => l_component_appl_id
46759       ,p_amb_context_code           => l_amb_context_code
46760       ,p_entity_code                => l_entity_code
46761       ,p_event_class_code           => l_event_class_code);
46762    --
46763    -- set accounting class
46764    --
46765    xla_ae_lines_pkg.SetAcctClass(
46766            p_accounting_class_code  => 'PREPAY'
46767          , p_ae_header_id           => l_ae_header_id
46768          );
46769 
46770    --
46771    -- set rounding class
46772    --
46773    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
46774                       'RECEIVABLE';
46775 
46776    --
46777    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
46778    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
46779    --
46780    -- bulk performance
46781    --
46782    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
46783 
46784    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
46785       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
46786 
46787    -- 4955764
46788    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
46789       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
46790 
46791    -- 4458381 Public Sector Enh
46792    
46793    --
46794    -- set accounting attributes for the line type
46795    --
46796    l_entered_amt_idx := 8;
46797    l_accted_amt_idx  := 13;
46798    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
46799    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
46800    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
46801    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
46802    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
46803    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
46804    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
46805    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
46806    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
46807    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
46808    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
46809    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
46810    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
46811    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
46812    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
46813    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
46814    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
46815    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
46816    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
46817    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
46818    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
46819    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
46820    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
46821    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
46822    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
46823    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
46824    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
46825    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
46826    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
46827    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
46828    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
46829    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
46830    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
46831 
46832    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
46833    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
46834 
46835    ---------------------------------------------------------------------------------------------------------------
46836    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
46837    ---------------------------------------------------------------------------------------------------------------
46838    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
46839 
46840    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
46841    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
46842 
46843    IF xla_accounting_cache_pkg.GetValueChar
46844          (p_source_code         => 'LEDGER_CATEGORY_CODE'
46845          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
46846    AND l_bflow_method_code = 'PRIOR_ENTRY'
46847 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
46848    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
46849          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
46850        )
46851    THEN
46852          xla_ae_lines_pkg.BflowUpgEntry
46853            (p_business_method_code    => l_bflow_method_code
46854            ,p_business_class_code     => l_bflow_class_code
46855            ,p_balance_type            => l_balance_type_code);
46856    ELSE
46857       NULL;
46858 -- No business flow processing for business flow method of NONE.
46862    -- call analytical criteria
46859    END IF;
46860 
46861    --
46863    --
46864    
46865    --
46866    -- call description
46867    --
46868    -- No description or it is inherited.
46869    --
46870    -- call ADRs
46871    -- Bug 4922099
46872    --
46873    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
46874         (NVL(l_actual_upg_option, 'N') = 'O') OR
46875         (NVL(l_enc_upg_option, 'N') = 'O')
46876       )
46877    THEN
46878    NULL;
46879    --
46880    --
46881    
46882   l_ccid := AcctDerRule_7(
46883            p_application_id           => p_application_id
46884          , p_ae_header_id             => l_ae_header_id 
46885 , p_source_3 => p_source_3
46886          , x_transaction_coa_id       => l_adr_transaction_coa_id
46887          , x_accounting_coa_id        => l_adr_accounting_coa_id
46888          , x_value_type_code          => l_adr_value_type_code
46889          , p_side                     => 'NA'
46890    );
46891 
46892    xla_ae_lines_pkg.set_ccid(
46893     p_code_combination_id          => l_ccid
46894   , p_value_type_code              => l_adr_value_type_code
46895   , p_transaction_coa_id           => l_adr_transaction_coa_id
46896   , p_accounting_coa_id            => l_adr_accounting_coa_id
46897   , p_adr_code                     => 'DIST_CCID'
46898   , p_adr_type_code                => 'S'
46899   , p_component_type               => l_component_type
46900   , p_component_code               => l_component_code
46901   , p_component_type_code          => l_component_type_code
46902   , p_component_appl_id            => l_component_appl_id
46903   , p_amb_context_code             => l_amb_context_code
46904   , p_side                         => 'NA'
46905   );
46906 
46907 
46908    --
46909    --
46910    END IF;
46911    --
46912    -- Bug 4922099
46913    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
46914           (NVL(l_enc_upg_option, 'N') = 'O')
46915         ) AND
46916         (l_bflow_method_code = 'PRIOR_ENTRY')
46917       )
46918    THEN
46919       IF
46920       --
46921       1 = 2
46922       --
46923       THEN
46924       xla_accounting_err_pkg.build_message
46925                                     (p_appli_s_name            => 'XLA'
46926                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
46927                                     ,p_token_1                 => 'LINE_NUMBER'
46928                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
46929                                     ,p_token_2                 => 'LINE_TYPE_NAME'
46930                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
46931                                                                              l_component_type
46932                                                                             ,l_component_code
46933                                                                             ,l_component_type_code
46934                                                                             ,l_component_appl_id
46935                                                                             ,l_amb_context_code
46936                                                                             ,l_entity_code
46937                                                                             ,l_event_class_code
46938                                                                            )
46939                                     ,p_token_3                 => 'OWNER'
46940                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
46941                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
46942                                                                           ,p_lookup_code    => l_component_type_code
46943                                                                          )
46944                                     ,p_token_4                 => 'PRODUCT_NAME'
46945                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
46946                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
46947                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
46948                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
46949                                     ,p_ae_header_id            =>  NULL
46950                                        );
46951 
46952         IF (C_LEVEL_ERROR>= g_log_level) THEN
46953                  trace
46954                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
46955                       ,p_level    => C_LEVEL_ERROR
46956                       ,p_module   => l_log_module);
46957         END IF;
46958       END IF;
46959    END IF;
46960    --
46961    --
46962    ------------------------------------------------------------------------------------------------
46963    -- 4219869 Business Flow
46964    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
46965    -- Prior Entry.  Currently, the following code is always generated.
46966    ------------------------------------------------------------------------------------------------
46967    XLA_AE_LINES_PKG.ValidateCurrentLine;
46968 
46969    ------------------------------------------------------------------------------------
46970    -- 4219869 Business Flow
46971    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
46972    ------------------------------------------------------------------------------------
46976    -- 4219869 Business Flow
46973    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
46974 
46975    ----------------------------------------------------------------------------------
46977    -- Update journal entry status -- Need to generate this within IF <condition>
46978    ----------------------------------------------------------------------------------
46979    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
46980          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
46981          ,p_balance_type_code => l_balance_type_code
46982          );
46983 
46984    -------------------------------------------------------------------------------------------
46985    -- 4262811 - Generate the Accrual Reversal lines
46986    -------------------------------------------------------------------------------------------
46987    BEGIN
46988       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
46989                               (g_array_event(p_event_id).array_value_num('header_index'));
46990       IF l_acc_rev_flag IS NULL THEN
46991          l_acc_rev_flag := 'N';
46992       END IF;
46993    EXCEPTION
46994       WHEN OTHERS THEN
46995          l_acc_rev_flag := 'N';
46996    END;
46997    --
46998    IF (l_acc_rev_flag = 'Y') THEN
46999 
47000        -- 4645092  ------------------------------------------------------------------------------
47001        -- To allow MPA report to determine if it should generate report process
47002        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
47003        ------------------------------------------------------------------------------------------
47004 
47005        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
47006        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
47007    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
47008    -- call ADRs
47009    -- Bug 4922099
47010    --
47011    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
47012         (NVL(l_actual_upg_option, 'N') = 'O') OR
47013         (NVL(l_enc_upg_option, 'N') = 'O')
47014       )
47015    THEN
47016    NULL;
47017    --
47018    --
47019    
47020   l_ccid := AcctDerRule_7(
47021            p_application_id           => p_application_id
47022          , p_ae_header_id             => l_ae_header_id 
47023 , p_source_3 => p_source_3
47024          , x_transaction_coa_id       => l_adr_transaction_coa_id
47025          , x_accounting_coa_id        => l_adr_accounting_coa_id
47026          , x_value_type_code          => l_adr_value_type_code
47027          , p_side                     => 'NA'
47028    );
47029 
47030    xla_ae_lines_pkg.set_ccid(
47031     p_code_combination_id          => l_ccid
47032   , p_value_type_code              => l_adr_value_type_code
47033   , p_transaction_coa_id           => l_adr_transaction_coa_id
47034   , p_accounting_coa_id            => l_adr_accounting_coa_id
47035   , p_adr_code                     => 'DIST_CCID'
47036   , p_adr_type_code                => 'S'
47037   , p_component_type               => l_component_type
47038   , p_component_code               => l_component_code
47039   , p_component_type_code          => l_component_type_code
47040   , p_component_appl_id            => l_component_appl_id
47041   , p_amb_context_code             => l_amb_context_code
47042   , p_side                         => 'NA'
47043   );
47044 
47045 
47046    --
47047    --
47048    END IF;
47049 
47050        --
47051        -- Update the line information that should be overwritten
47052        --
47053        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
47054                                          p_header_num   => 1);
47058 
47055        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
47056 
47057        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
47059        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
47060           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
47061        END IF;
47062 
47063       --
47064       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
47065       --
47066       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
47067           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
47068       ELSE
47069           ---------------------------------------------------------------------------------------------------
47070           -- 4262811a Switch Sign
47071           ---------------------------------------------------------------------------------------------------
47072           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
47073           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
47074                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
47075           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
47076                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
47077           -- 5132302
47078           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
47079                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
47080 
47081       END IF;
47082 
47083       -- 4955764
47084       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
47085       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
47086 
47087 
47088       XLA_AE_LINES_PKG.ValidateCurrentLine;
47089       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
47090 
47091       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
47092                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
47093                ,p_balance_type_code => l_balance_type_code);
47094 
47095    END IF;
47096 
47097    -----------------------------------------------------------------------------------------
47098    -- 4262811 Multiperiod Accounting
47099    -----------------------------------------------------------------------------------------
47100      -- No MPA option is assigned.
47101 
47102 
47103 END IF;
47104 END IF;
47105 --
47106 
47107 --
47108 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
47109    trace
47110       (p_msg      => 'END of AcctLineType_92'
47111       ,p_level    => C_LEVEL_PROCEDURE
47112       ,p_module   => l_log_module);
47113 END IF;
47114 --
47115 EXCEPTION
47116   WHEN xla_exceptions_pkg.application_exception THEN
47117       RAISE;
47118   WHEN OTHERS THEN
47119        xla_exceptions_pkg.raise_message
47120            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_92');
47121 END AcctLineType_92;
47122 --
47123 
47124 ---------------------------------------
47125 --
47126 -- PRIVATE FUNCTION
47127 --         AcctLineType_93
47128 --
47129 ---------------------------------------
47130 PROCEDURE AcctLineType_93 (
47131   p_application_id        IN NUMBER
47132  ,p_event_id              IN NUMBER
47133  ,p_calculate_acctd_flag  IN VARCHAR2
47134  ,p_calculate_g_l_flag    IN VARCHAR2
47135  ,p_actual_flag           IN OUT VARCHAR2
47136  ,p_balance_type_code     OUT VARCHAR2
47137  ,p_gain_or_loss_ref      OUT VARCHAR2
47138  
47139 --Distribution GL Account
47140  , p_source_3            IN NUMBER
47141 --Distribution Source Type
47142  , p_source_13            IN VARCHAR2
47143 --Receivable Activity Type
47144  , p_source_14            IN VARCHAR2
47145 --Distribution Line Identifier
47146  , p_source_15            IN NUMBER
47147 --Distribution Type
47148  , p_source_16            IN VARCHAR2
47149 --Exchange Date
47150  , p_source_19            IN DATE
47151 --Exchange Rate
47152  , p_source_20            IN NUMBER
47153 --Exchange Rate Type
47154  , p_source_21            IN VARCHAR2
47155 --Transaction Distribution Identifier
47156  , p_source_27            IN NUMBER
47157 --Transaction Distribution Type
47158  , p_source_28            IN VARCHAR2
47159 --Distribution Multi Fund Additional Entry
47160  , p_source_52            IN VARCHAR2
47161 --Receipt Applied To Application Identifier
47162  , p_source_56            IN NUMBER
47163 --Transaction Entity Code
47164  , p_source_57            IN VARCHAR2
47165 --Transaction Identifier
47166  , p_source_58            IN NUMBER
47167 --DIST_ENT_AMT_FROM
47168  , p_source_59            IN NUMBER
47169 --Applying Document Currency Code
47170  , p_source_60            IN VARCHAR2
47171 --Accounting Amount
47172  , p_source_61            IN NUMBER
47173 --Distribution Party Identifier
47174  , p_source_62            IN NUMBER
47175 --Distribution Party Site Id
47176  , p_source_63            IN NUMBER
47177 --Distribution Party Type
47178  , p_source_64            IN VARCHAR2
47179 )
47180 IS
47181 
47182 l_component_type              VARCHAR2(80);
47183 l_component_code              VARCHAR2(30);
47184 l_component_type_code         VARCHAR2(1);
47185 l_component_appl_id           INTEGER;
47186 l_amb_context_code            VARCHAR2(30);
47187 l_entity_code                 VARCHAR2(30);
47191 l_line_definition_code        VARCHAR2(30);
47188 l_event_class_code            VARCHAR2(30);
47189 l_ae_header_id                NUMBER;
47190 l_event_type_code             VARCHAR2(30);
47192 l_line_definition_owner_code  VARCHAR2(1);
47193 --
47194 -- adr variables
47195 l_segment                     VARCHAR2(30);
47196 l_ccid                        NUMBER;
47197 l_adr_transaction_coa_id      NUMBER;
47198 l_adr_accounting_coa_id       NUMBER;
47199 l_adr_flexfield_segment_code  VARCHAR2(30);
47200 l_adr_flex_value_set_id       NUMBER;
47201 l_adr_value_type_code         VARCHAR2(30);
47202 l_adr_value_combination_id    NUMBER;
47203 l_adr_value_segment_code      VARCHAR2(30);
47204 
47205 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
47206 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
47207 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
47208 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
47209 
47210 -- 4262811 Variables ------------------------------------------------------------------------------------------
47211 l_entered_amt_idx             NUMBER;
47212 l_accted_amt_idx              NUMBER;
47213 l_acc_rev_flag                VARCHAR2(1);
47214 l_accrual_line_num            NUMBER;
47215 l_tmp_amt                     NUMBER;
47216 l_acc_rev_natural_side_code   VARCHAR2(1);
47217 
47218 l_num_entries                 NUMBER;
47219 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
47220 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
47221 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
47222 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
47223 l_recog_line_1                NUMBER;
47224 l_recog_line_2                NUMBER;
47225 
47226 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
47227 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
47228 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
47229 
47230 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
47231 
47232 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
47233 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
47234 
47235 ---------------------------------------------------------------------------------------------------------------
47236 
47237 
47238 --
47239 -- bulk performance
47240 --
47241 l_balance_type_code           VARCHAR2(1);
47242 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
47243 l_log_module                  VARCHAR2(240);
47244 
47245 --
47246 -- Upgrade strategy
47247 --
47248 l_actual_upg_option           VARCHAR2(1);
47249 l_enc_upg_option           VARCHAR2(1);
47250 
47251 --
47252 BEGIN
47253 --
47254 IF g_log_enabled THEN
47255       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_93';
47256 END IF;
47257 --
47258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
47259 
47260       trace
47261          (p_msg      => 'BEGIN of AcctLineType_93'
47262          ,p_level    => C_LEVEL_PROCEDURE
47263          ,p_module   => l_log_module);
47264 
47265 END IF;
47266 --
47267 l_component_type             := 'AMB_JLT';
47268 l_component_code             := 'RCT_REFUND';
47269 l_component_type_code        := 'S';
47270 l_component_appl_id          :=  222;
47271 l_amb_context_code           := 'DEFAULT';
47272 l_entity_code                := 'RECEIPTS';
47273 l_event_class_code           := 'RECEIPT';
47274 l_event_type_code            := 'RECEIPT_ALL';
47275 l_line_definition_owner_code := 'S';
47276 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
47277 --
47278 l_balance_type_code          := 'A';
47279 l_segment                     := NULL;
47280 l_ccid                        := NULL;
47281 l_adr_transaction_coa_id      := NULL;
47282 l_adr_accounting_coa_id       := NULL;
47283 l_adr_flexfield_segment_code  := NULL;
47284 l_adr_flex_value_set_id       := NULL;
47285 l_adr_value_type_code         := NULL;
47286 l_adr_value_combination_id    := NULL;
47287 l_adr_value_segment_code      := NULL;
47288 
47289 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
47290 l_bflow_class_code           := '';    -- 4219869 Business Flow
47291 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
47292 l_budgetary_control_flag     := 'N';
47293 
47294 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
47295 l_bflow_applied_to_amt       := NULL; -- 5132302
47296 l_entered_amt_idx            := NULL;          -- 4262811
47297 l_accted_amt_idx             := NULL;          -- 4262811
47298 l_acc_rev_flag               := NULL;          -- 4262811
47299 l_accrual_line_num           := NULL;          -- 4262811
47300 l_tmp_amt                    := NULL;          -- 4262811
47301 --
47302  
47303 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
47304     l_balance_type_code <> 'B' THEN
47305 IF (NVL(p_source_13,'
47306 ') =  'ACTIVITY' AND 
47307 NVL(p_source_14,'
47308 ') =  'CCREFUND' AND 
47309 NVL(p_source_52,'
47310 ') =  'N') OR 
47311 (NVL(p_source_13,'
47312 ') =  'ACTIVITY' AND 
47313 NVL(p_source_14,'
47314 ') =  'CM_REFUND' AND 
47315 NVL(p_source_52,'
47316 ') =  'N')
47317  THEN 
47318 
47319    --
47320    XLA_AE_LINES_PKG.SetNewLine;
47321 
47322    p_balance_type_code          := l_balance_type_code;
47323    -- set the flag so later we will know whether the gain loss line needs to be created
47324    
47325    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
47329    --
47326      p_actual_flag :='A';
47327    END IF;
47328 
47330    -- bulk performance
47331    --
47332    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
47333                                       p_header_num   => 0); -- 4262811
47334    --
47335    -- set accounting line options
47336    --
47337    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
47338            p_natural_side_code          => 'C'
47339          , p_gain_or_loss_flag          => 'N'
47340          , p_gl_transfer_mode_code      => 'S'
47341          , p_acct_entry_type_code       => 'A'
47342          , p_switch_side_flag           => 'Y'
47343          , p_merge_duplicate_code       => 'A'
47344          );
47345    --
47346    l_acc_rev_natural_side_code := 'D';  -- 4262811
47347    -- 
47348    --
47349    -- set accounting line type info
47350    --
47351    xla_ae_lines_pkg.SetAcctLineType
47352       (p_component_type             => l_component_type
47353       ,p_event_type_code            => l_event_type_code
47354       ,p_line_definition_owner_code => l_line_definition_owner_code
47355       ,p_line_definition_code       => l_line_definition_code
47356       ,p_accounting_line_code       => l_component_code
47357       ,p_accounting_line_type_code  => l_component_type_code
47358       ,p_accounting_line_appl_id    => l_component_appl_id
47359       ,p_amb_context_code           => l_amb_context_code
47360       ,p_entity_code                => l_entity_code
47361       ,p_event_class_code           => l_event_class_code);
47362    --
47363    -- set accounting class
47364    --
47365    xla_ae_lines_pkg.SetAcctClass(
47366            p_accounting_class_code  => 'REFUND'
47367          , p_ae_header_id           => l_ae_header_id
47368          );
47369 
47370    --
47371    -- set rounding class
47372    --
47373    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
47374                       'RECEIVABLE';
47375 
47376    --
47377    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
47378    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
47379    --
47380    -- bulk performance
47381    --
47382    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
47383 
47384    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
47385       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
47386 
47387    -- 4955764
47388    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
47389       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
47390 
47391    -- 4458381 Public Sector Enh
47392    
47393    --
47394    -- set accounting attributes for the line type
47395    --
47396    l_entered_amt_idx := 8;
47397    l_accted_amt_idx  := 13;
47398    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
47399    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
47400    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
47401    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
47402    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
47403    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
47404    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
47405    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
47406    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
47407    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
47408    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
47409    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
47410    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
47411    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
47412    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
47413    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
47414    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
47415    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
47416    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
47417    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
47418    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
47419    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
47420    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
47421    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
47422    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
47423    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
47424    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
47425    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
47426    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
47427    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
47428    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
47429    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
47430    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
47431 
47432    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
47433    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
47434 
47435    ---------------------------------------------------------------------------------------------------------------
47436    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
47437    ---------------------------------------------------------------------------------------------------------------
47438    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
47439 
47443    IF xla_accounting_cache_pkg.GetValueChar
47440    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
47441    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
47442 
47444          (p_source_code         => 'LEDGER_CATEGORY_CODE'
47445          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
47446    AND l_bflow_method_code = 'PRIOR_ENTRY'
47447 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
47448    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
47449          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
47450        )
47451    THEN
47452          xla_ae_lines_pkg.BflowUpgEntry
47453            (p_business_method_code    => l_bflow_method_code
47454            ,p_business_class_code     => l_bflow_class_code
47455            ,p_balance_type            => l_balance_type_code);
47456    ELSE
47457       NULL;
47458 -- No business flow processing for business flow method of NONE.
47459    END IF;
47460 
47461    --
47462    -- call analytical criteria
47463    --
47464    
47465    --
47466    -- call description
47467    --
47468    -- No description or it is inherited.
47469    --
47470    -- call ADRs
47471    -- Bug 4922099
47472    --
47473    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
47474         (NVL(l_actual_upg_option, 'N') = 'O') OR
47475         (NVL(l_enc_upg_option, 'N') = 'O')
47476       )
47477    THEN
47478    NULL;
47479    --
47480    --
47481    
47482   l_ccid := AcctDerRule_7(
47483            p_application_id           => p_application_id
47484          , p_ae_header_id             => l_ae_header_id 
47485 , p_source_3 => p_source_3
47486          , x_transaction_coa_id       => l_adr_transaction_coa_id
47487          , x_accounting_coa_id        => l_adr_accounting_coa_id
47488          , x_value_type_code          => l_adr_value_type_code
47489          , p_side                     => 'NA'
47490    );
47491 
47492    xla_ae_lines_pkg.set_ccid(
47493     p_code_combination_id          => l_ccid
47494   , p_value_type_code              => l_adr_value_type_code
47495   , p_transaction_coa_id           => l_adr_transaction_coa_id
47496   , p_accounting_coa_id            => l_adr_accounting_coa_id
47497   , p_adr_code                     => 'DIST_CCID'
47498   , p_adr_type_code                => 'S'
47499   , p_component_type               => l_component_type
47500   , p_component_code               => l_component_code
47501   , p_component_type_code          => l_component_type_code
47502   , p_component_appl_id            => l_component_appl_id
47503   , p_amb_context_code             => l_amb_context_code
47504   , p_side                         => 'NA'
47505   );
47506 
47507 
47508    --
47509    --
47510    END IF;
47511    --
47512    -- Bug 4922099
47513    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
47514           (NVL(l_enc_upg_option, 'N') = 'O')
47515         ) AND
47516         (l_bflow_method_code = 'PRIOR_ENTRY')
47517       )
47518    THEN
47519       IF
47520       --
47521       1 = 2
47522       --
47523       THEN
47524       xla_accounting_err_pkg.build_message
47525                                     (p_appli_s_name            => 'XLA'
47526                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
47527                                     ,p_token_1                 => 'LINE_NUMBER'
47528                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
47529                                     ,p_token_2                 => 'LINE_TYPE_NAME'
47530                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
47531                                                                              l_component_type
47532                                                                             ,l_component_code
47533                                                                             ,l_component_type_code
47534                                                                             ,l_component_appl_id
47535                                                                             ,l_amb_context_code
47536                                                                             ,l_entity_code
47537                                                                             ,l_event_class_code
47538                                                                            )
47539                                     ,p_token_3                 => 'OWNER'
47540                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
47541                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
47542                                                                           ,p_lookup_code    => l_component_type_code
47543                                                                          )
47544                                     ,p_token_4                 => 'PRODUCT_NAME'
47545                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
47546                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
47547                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
47548                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
47549                                     ,p_ae_header_id            =>  NULL
47550                                        );
47551 
47552         IF (C_LEVEL_ERROR>= g_log_level) THEN
47553                  trace
47557         END IF;
47554                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
47555                       ,p_level    => C_LEVEL_ERROR
47556                       ,p_module   => l_log_module);
47558       END IF;
47559    END IF;
47560    --
47561    --
47562    ------------------------------------------------------------------------------------------------
47563    -- 4219869 Business Flow
47564    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
47565    -- Prior Entry.  Currently, the following code is always generated.
47566    ------------------------------------------------------------------------------------------------
47567    XLA_AE_LINES_PKG.ValidateCurrentLine;
47568 
47569    ------------------------------------------------------------------------------------
47570    -- 4219869 Business Flow
47571    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
47572    ------------------------------------------------------------------------------------
47573    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
47574 
47575    ----------------------------------------------------------------------------------
47576    -- 4219869 Business Flow
47577    -- Update journal entry status -- Need to generate this within IF <condition>
47578    ----------------------------------------------------------------------------------
47579    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
47580          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
47581          ,p_balance_type_code => l_balance_type_code
47582          );
47583 
47584    -------------------------------------------------------------------------------------------
47585    -- 4262811 - Generate the Accrual Reversal lines
47586    -------------------------------------------------------------------------------------------
47587    BEGIN
47588       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
47589                               (g_array_event(p_event_id).array_value_num('header_index'));
47590       IF l_acc_rev_flag IS NULL THEN
47591          l_acc_rev_flag := 'N';
47592       END IF;
47593    EXCEPTION
47594       WHEN OTHERS THEN
47595          l_acc_rev_flag := 'N';
47596    END;
47597    --
47598    IF (l_acc_rev_flag = 'Y') THEN
47599 
47600        -- 4645092  ------------------------------------------------------------------------------
47601        -- To allow MPA report to determine if it should generate report process
47602        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
47603        ------------------------------------------------------------------------------------------
47604 
47605        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
47606        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
47607    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
47608    -- call ADRs
47609    -- Bug 4922099
47610    --
47611    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
47612         (NVL(l_actual_upg_option, 'N') = 'O') OR
47613         (NVL(l_enc_upg_option, 'N') = 'O')
47614       )
47615    THEN
47616    NULL;
47617    --
47618    --
47619    
47620   l_ccid := AcctDerRule_7(
47621            p_application_id           => p_application_id
47622          , p_ae_header_id             => l_ae_header_id 
47623 , p_source_3 => p_source_3
47624          , x_transaction_coa_id       => l_adr_transaction_coa_id
47625          , x_accounting_coa_id        => l_adr_accounting_coa_id
47626          , x_value_type_code          => l_adr_value_type_code
47627          , p_side                     => 'NA'
47628    );
47629 
47630    xla_ae_lines_pkg.set_ccid(
47631     p_code_combination_id          => l_ccid
47632   , p_value_type_code              => l_adr_value_type_code
47633   , p_transaction_coa_id           => l_adr_transaction_coa_id
47634   , p_accounting_coa_id            => l_adr_accounting_coa_id
47635   , p_adr_code                     => 'DIST_CCID'
47636   , p_adr_type_code                => 'S'
47637   , p_component_type               => l_component_type
47638   , p_component_code               => l_component_code
47639   , p_component_type_code          => l_component_type_code
47640   , p_component_appl_id            => l_component_appl_id
47641   , p_amb_context_code             => l_amb_context_code
47642   , p_side                         => 'NA'
47643   );
47644 
47645 
47646    --
47647    --
47648    END IF;
47649 
47650        --
47651        -- Update the line information that should be overwritten
47652        --
47653        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
47654                                          p_header_num   => 1);
47655        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
47656 
47657        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
47658 
47659        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
47660           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
47661        END IF;
47662 
47663       --
47664       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
47665       --
47666       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
47667           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
47668       ELSE
47669           ---------------------------------------------------------------------------------------------------
47670           -- 4262811a Switch Sign
47671           ---------------------------------------------------------------------------------------------------
47675           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
47672           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
47673           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
47674                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
47676                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
47677           -- 5132302
47678           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
47679                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
47680 
47681       END IF;
47682 
47683       -- 4955764
47684       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
47685       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
47686 
47687 
47688       XLA_AE_LINES_PKG.ValidateCurrentLine;
47689       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
47690 
47691       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
47692                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
47693                ,p_balance_type_code => l_balance_type_code);
47694 
47695    END IF;
47696 
47697    -----------------------------------------------------------------------------------------
47698    -- 4262811 Multiperiod Accounting
47699    -----------------------------------------------------------------------------------------
47700      -- No MPA option is assigned.
47701 
47702 
47703 END IF;
47704 END IF;
47705 --
47706 
47707 --
47708 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
47709    trace
47710       (p_msg      => 'END of AcctLineType_93'
47711       ,p_level    => C_LEVEL_PROCEDURE
47712       ,p_module   => l_log_module);
47713 END IF;
47714 --
47715 EXCEPTION
47716   WHEN xla_exceptions_pkg.application_exception THEN
47717       RAISE;
47718   WHEN OTHERS THEN
47719        xla_exceptions_pkg.raise_message
47720            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_93');
47721 END AcctLineType_93;
47722 --
47723 
47724 ---------------------------------------
47725 --
47726 -- PRIVATE FUNCTION
47727 --         AcctLineType_94
47728 --
47729 ---------------------------------------
47730 PROCEDURE AcctLineType_94 (
47731   p_application_id        IN NUMBER
47732  ,p_event_id              IN NUMBER
47733  ,p_calculate_acctd_flag  IN VARCHAR2
47734  ,p_calculate_g_l_flag    IN VARCHAR2
47735  ,p_actual_flag           IN OUT VARCHAR2
47736  ,p_balance_type_code     OUT VARCHAR2
47737  ,p_gain_or_loss_ref      OUT VARCHAR2
47738  
47739 --Distribution GL Account
47740  , p_source_3            IN NUMBER
47741 --Distribution Source Type
47742  , p_source_13            IN VARCHAR2
47743 --Distribution Line Identifier
47744  , p_source_15            IN NUMBER
47745 --Distribution Type
47746  , p_source_16            IN VARCHAR2
47747 --Exchange Date
47748  , p_source_19            IN DATE
47749 --Exchange Rate
47750  , p_source_20            IN NUMBER
47751 --Exchange Rate Type
47752  , p_source_21            IN VARCHAR2
47753 --Transaction Distribution Identifier
47754  , p_source_27            IN NUMBER
47755 --Transaction Distribution Type
47756  , p_source_28            IN VARCHAR2
47757 --Distribution Multi Fund Additional Entry
47758  , p_source_52            IN VARCHAR2
47759 --Receipt Applied To Application Identifier
47760  , p_source_56            IN NUMBER
47761 --Transaction Entity Code
47762  , p_source_57            IN VARCHAR2
47763 --Transaction Identifier
47764  , p_source_58            IN NUMBER
47765 --DIST_ENT_AMT_FROM
47766  , p_source_59            IN NUMBER
47767 --Applying Document Currency Code
47768  , p_source_60            IN VARCHAR2
47769 --Accounting Amount
47770  , p_source_61            IN NUMBER
47771 --Distribution Party Identifier
47772  , p_source_62            IN NUMBER
47773 --Distribution Party Site Id
47774  , p_source_63            IN NUMBER
47775 --Distribution Party Type
47776  , p_source_64            IN VARCHAR2
47777 --Distribution Source Table
47778  , p_source_67            IN VARCHAR2
47779 )
47780 IS
47781 
47782 l_component_type              VARCHAR2(80);
47783 l_component_code              VARCHAR2(30);
47784 l_component_type_code         VARCHAR2(1);
47785 l_component_appl_id           INTEGER;
47786 l_amb_context_code            VARCHAR2(30);
47787 l_entity_code                 VARCHAR2(30);
47788 l_event_class_code            VARCHAR2(30);
47789 l_ae_header_id                NUMBER;
47790 l_event_type_code             VARCHAR2(30);
47791 l_line_definition_code        VARCHAR2(30);
47792 l_line_definition_owner_code  VARCHAR2(1);
47793 --
47794 -- adr variables
47795 l_segment                     VARCHAR2(30);
47796 l_ccid                        NUMBER;
47797 l_adr_transaction_coa_id      NUMBER;
47798 l_adr_accounting_coa_id       NUMBER;
47799 l_adr_flexfield_segment_code  VARCHAR2(30);
47800 l_adr_flex_value_set_id       NUMBER;
47801 l_adr_value_type_code         VARCHAR2(30);
47802 l_adr_value_combination_id    NUMBER;
47803 l_adr_value_segment_code      VARCHAR2(30);
47804 
47805 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
47809 
47806 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
47807 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
47808 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
47810 -- 4262811 Variables ------------------------------------------------------------------------------------------
47811 l_entered_amt_idx             NUMBER;
47812 l_accted_amt_idx              NUMBER;
47813 l_acc_rev_flag                VARCHAR2(1);
47814 l_accrual_line_num            NUMBER;
47815 l_tmp_amt                     NUMBER;
47816 l_acc_rev_natural_side_code   VARCHAR2(1);
47817 
47818 l_num_entries                 NUMBER;
47819 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
47820 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
47821 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
47822 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
47823 l_recog_line_1                NUMBER;
47824 l_recog_line_2                NUMBER;
47825 
47826 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
47827 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
47828 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
47829 
47830 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
47831 
47832 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
47833 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
47834 
47835 ---------------------------------------------------------------------------------------------------------------
47836 
47837 
47838 --
47839 -- bulk performance
47840 --
47841 l_balance_type_code           VARCHAR2(1);
47842 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
47843 l_log_module                  VARCHAR2(240);
47844 
47845 --
47846 -- Upgrade strategy
47847 --
47848 l_actual_upg_option           VARCHAR2(1);
47849 l_enc_upg_option           VARCHAR2(1);
47850 
47851 --
47852 BEGIN
47853 --
47854 IF g_log_enabled THEN
47855       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_94';
47856 END IF;
47857 --
47858 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
47859 
47860       trace
47861          (p_msg      => 'BEGIN of AcctLineType_94'
47862          ,p_level    => C_LEVEL_PROCEDURE
47863          ,p_module   => l_log_module);
47864 
47865 END IF;
47866 --
47867 l_component_type             := 'AMB_JLT';
47868 l_component_code             := 'RCT_REMIT';
47869 l_component_type_code        := 'S';
47870 l_component_appl_id          :=  222;
47871 l_amb_context_code           := 'DEFAULT';
47872 l_entity_code                := 'RECEIPTS';
47873 l_event_class_code           := 'RECEIPT';
47874 l_event_type_code            := 'RECEIPT_ALL';
47875 l_line_definition_owner_code := 'S';
47876 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
47877 --
47878 l_balance_type_code          := 'A';
47879 l_segment                     := NULL;
47880 l_ccid                        := NULL;
47881 l_adr_transaction_coa_id      := NULL;
47882 l_adr_accounting_coa_id       := NULL;
47883 l_adr_flexfield_segment_code  := NULL;
47884 l_adr_flex_value_set_id       := NULL;
47885 l_adr_value_type_code         := NULL;
47886 l_adr_value_combination_id    := NULL;
47887 l_adr_value_segment_code      := NULL;
47888 
47889 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
47890 l_bflow_class_code           := '';    -- 4219869 Business Flow
47891 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
47892 l_budgetary_control_flag     := 'N';
47893 
47894 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
47895 l_bflow_applied_to_amt       := NULL; -- 5132302
47896 l_entered_amt_idx            := NULL;          -- 4262811
47897 l_accted_amt_idx             := NULL;          -- 4262811
47898 l_acc_rev_flag               := NULL;          -- 4262811
47899 l_accrual_line_num           := NULL;          -- 4262811
47900 l_tmp_amt                    := NULL;          -- 4262811
47901 --
47902  
47903 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
47904     l_balance_type_code <> 'B' THEN
47905 IF NVL(p_source_13,'
47906 ') =  'REMITTANCE' AND 
47907 NVL(p_source_67,'
47908 ') =  'CRH' AND 
47909 NVL(p_source_52,'
47910 ') =  'N'
47911  THEN 
47912 
47913    --
47914    XLA_AE_LINES_PKG.SetNewLine;
47915 
47916    p_balance_type_code          := l_balance_type_code;
47917    -- set the flag so later we will know whether the gain loss line needs to be created
47918    
47919    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
47920      p_actual_flag :='A';
47921    END IF;
47922 
47923    --
47924    -- bulk performance
47925    --
47926    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
47927                                       p_header_num   => 0); -- 4262811
47928    --
47929    -- set accounting line options
47930    --
47931    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
47932            p_natural_side_code          => 'C'
47933          , p_gain_or_loss_flag          => 'N'
47934          , p_gl_transfer_mode_code      => 'S'
47935          , p_acct_entry_type_code       => 'A'
47939    --
47936          , p_switch_side_flag           => 'Y'
47937          , p_merge_duplicate_code       => 'A'
47938          );
47940    l_acc_rev_natural_side_code := 'D';  -- 4262811
47941    -- 
47942    --
47943    -- set accounting line type info
47944    --
47945    xla_ae_lines_pkg.SetAcctLineType
47946       (p_component_type             => l_component_type
47947       ,p_event_type_code            => l_event_type_code
47948       ,p_line_definition_owner_code => l_line_definition_owner_code
47949       ,p_line_definition_code       => l_line_definition_code
47950       ,p_accounting_line_code       => l_component_code
47951       ,p_accounting_line_type_code  => l_component_type_code
47952       ,p_accounting_line_appl_id    => l_component_appl_id
47953       ,p_amb_context_code           => l_amb_context_code
47954       ,p_entity_code                => l_entity_code
47955       ,p_event_class_code           => l_event_class_code);
47956    --
47957    -- set accounting class
47958    --
47959    xla_ae_lines_pkg.SetAcctClass(
47960            p_accounting_class_code  => 'REMITTANCE'
47961          , p_ae_header_id           => l_ae_header_id
47962          );
47963 
47964    --
47965    -- set rounding class
47966    --
47967    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
47968                       'RECEIVABLE';
47969 
47970    --
47971    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
47972    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
47973    --
47974    -- bulk performance
47975    --
47976    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
47977 
47978    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
47979       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
47980 
47981    -- 4955764
47982    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
47983       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
47984 
47985    -- 4458381 Public Sector Enh
47986    
47987    --
47988    -- set accounting attributes for the line type
47989    --
47990    l_entered_amt_idx := 8;
47991    l_accted_amt_idx  := 13;
47992    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
47993    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
47994    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
47995    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
47996    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
47997    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
47998    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
47999    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
48000    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
48001    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
48002    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
48003    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
48004    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
48005    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
48006    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
48007    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
48008    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
48009    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
48010    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
48011    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
48012    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
48013    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
48014    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
48015    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
48016    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
48017    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
48018    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
48019    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
48020    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
48021    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
48022    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
48023    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
48024    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
48025 
48026    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
48027    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
48028 
48029    ---------------------------------------------------------------------------------------------------------------
48030    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
48031    ---------------------------------------------------------------------------------------------------------------
48032    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
48033 
48034    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
48035    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
48036 
48037    IF xla_accounting_cache_pkg.GetValueChar
48038          (p_source_code         => 'LEDGER_CATEGORY_CODE'
48039          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
48040    AND l_bflow_method_code = 'PRIOR_ENTRY'
48044        )
48041 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
48042    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
48043          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
48045    THEN
48046          xla_ae_lines_pkg.BflowUpgEntry
48047            (p_business_method_code    => l_bflow_method_code
48048            ,p_business_class_code     => l_bflow_class_code
48049            ,p_balance_type            => l_balance_type_code);
48050    ELSE
48051       NULL;
48052 -- No business flow processing for business flow method of NONE.
48053    END IF;
48054 
48055    --
48056    -- call analytical criteria
48057    --
48058    
48059    --
48060    -- call description
48061    --
48062    -- No description or it is inherited.
48063    --
48064    -- call ADRs
48065    -- Bug 4922099
48066    --
48067    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
48068         (NVL(l_actual_upg_option, 'N') = 'O') OR
48069         (NVL(l_enc_upg_option, 'N') = 'O')
48070       )
48071    THEN
48072    NULL;
48073    --
48074    --
48075    
48076   l_ccid := AcctDerRule_7(
48077            p_application_id           => p_application_id
48078          , p_ae_header_id             => l_ae_header_id 
48079 , p_source_3 => p_source_3
48080          , x_transaction_coa_id       => l_adr_transaction_coa_id
48081          , x_accounting_coa_id        => l_adr_accounting_coa_id
48082          , x_value_type_code          => l_adr_value_type_code
48083          , p_side                     => 'NA'
48084    );
48085 
48086    xla_ae_lines_pkg.set_ccid(
48087     p_code_combination_id          => l_ccid
48088   , p_value_type_code              => l_adr_value_type_code
48089   , p_transaction_coa_id           => l_adr_transaction_coa_id
48090   , p_accounting_coa_id            => l_adr_accounting_coa_id
48091   , p_adr_code                     => 'DIST_CCID'
48092   , p_adr_type_code                => 'S'
48093   , p_component_type               => l_component_type
48094   , p_component_code               => l_component_code
48095   , p_component_type_code          => l_component_type_code
48096   , p_component_appl_id            => l_component_appl_id
48097   , p_amb_context_code             => l_amb_context_code
48098   , p_side                         => 'NA'
48099   );
48100 
48101 
48102    --
48103    --
48104    END IF;
48105    --
48106    -- Bug 4922099
48107    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
48108           (NVL(l_enc_upg_option, 'N') = 'O')
48109         ) AND
48110         (l_bflow_method_code = 'PRIOR_ENTRY')
48111       )
48112    THEN
48113       IF
48114       --
48115       1 = 2
48116       --
48117       THEN
48118       xla_accounting_err_pkg.build_message
48119                                     (p_appli_s_name            => 'XLA'
48120                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
48121                                     ,p_token_1                 => 'LINE_NUMBER'
48122                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
48123                                     ,p_token_2                 => 'LINE_TYPE_NAME'
48124                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
48125                                                                              l_component_type
48126                                                                             ,l_component_code
48127                                                                             ,l_component_type_code
48128                                                                             ,l_component_appl_id
48129                                                                             ,l_amb_context_code
48130                                                                             ,l_entity_code
48131                                                                             ,l_event_class_code
48132                                                                            )
48133                                     ,p_token_3                 => 'OWNER'
48134                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
48135                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
48136                                                                           ,p_lookup_code    => l_component_type_code
48137                                                                          )
48138                                     ,p_token_4                 => 'PRODUCT_NAME'
48139                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
48140                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
48141                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
48142                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
48143                                     ,p_ae_header_id            =>  NULL
48144                                        );
48145 
48146         IF (C_LEVEL_ERROR>= g_log_level) THEN
48147                  trace
48148                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
48149                       ,p_level    => C_LEVEL_ERROR
48150                       ,p_module   => l_log_module);
48151         END IF;
48152       END IF;
48153    END IF;
48154    --
48155    --
48156    ------------------------------------------------------------------------------------------------
48157    -- 4219869 Business Flow
48158    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
48162 
48159    -- Prior Entry.  Currently, the following code is always generated.
48160    ------------------------------------------------------------------------------------------------
48161    XLA_AE_LINES_PKG.ValidateCurrentLine;
48163    ------------------------------------------------------------------------------------
48164    -- 4219869 Business Flow
48165    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
48166    ------------------------------------------------------------------------------------
48167    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
48168 
48169    ----------------------------------------------------------------------------------
48170    -- 4219869 Business Flow
48171    -- Update journal entry status -- Need to generate this within IF <condition>
48172    ----------------------------------------------------------------------------------
48173    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
48174          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
48175          ,p_balance_type_code => l_balance_type_code
48176          );
48177 
48178    -------------------------------------------------------------------------------------------
48179    -- 4262811 - Generate the Accrual Reversal lines
48180    -------------------------------------------------------------------------------------------
48181    BEGIN
48182       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
48183                               (g_array_event(p_event_id).array_value_num('header_index'));
48184       IF l_acc_rev_flag IS NULL THEN
48185          l_acc_rev_flag := 'N';
48186       END IF;
48187    EXCEPTION
48188       WHEN OTHERS THEN
48189          l_acc_rev_flag := 'N';
48190    END;
48191    --
48192    IF (l_acc_rev_flag = 'Y') THEN
48193 
48194        -- 4645092  ------------------------------------------------------------------------------
48195        -- To allow MPA report to determine if it should generate report process
48196        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
48197        ------------------------------------------------------------------------------------------
48198 
48199        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
48200        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
48201    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
48202    -- call ADRs
48203    -- Bug 4922099
48204    --
48205    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
48206         (NVL(l_actual_upg_option, 'N') = 'O') OR
48207         (NVL(l_enc_upg_option, 'N') = 'O')
48208       )
48209    THEN
48210    NULL;
48211    --
48212    --
48213    
48214   l_ccid := AcctDerRule_7(
48215            p_application_id           => p_application_id
48216          , p_ae_header_id             => l_ae_header_id 
48217 , p_source_3 => p_source_3
48218          , x_transaction_coa_id       => l_adr_transaction_coa_id
48219          , x_accounting_coa_id        => l_adr_accounting_coa_id
48220          , x_value_type_code          => l_adr_value_type_code
48221          , p_side                     => 'NA'
48222    );
48223 
48224    xla_ae_lines_pkg.set_ccid(
48225     p_code_combination_id          => l_ccid
48226   , p_value_type_code              => l_adr_value_type_code
48227   , p_transaction_coa_id           => l_adr_transaction_coa_id
48228   , p_accounting_coa_id            => l_adr_accounting_coa_id
48229   , p_adr_code                     => 'DIST_CCID'
48230   , p_adr_type_code                => 'S'
48231   , p_component_type               => l_component_type
48232   , p_component_code               => l_component_code
48233   , p_component_type_code          => l_component_type_code
48234   , p_component_appl_id            => l_component_appl_id
48235   , p_amb_context_code             => l_amb_context_code
48236   , p_side                         => 'NA'
48237   );
48238 
48239 
48240    --
48241    --
48242    END IF;
48243 
48244        --
48245        -- Update the line information that should be overwritten
48246        --
48247        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
48248                                          p_header_num   => 1);
48249        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
48250 
48251        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
48252 
48253        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
48254           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
48255        END IF;
48256 
48257       --
48258       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
48259       --
48260       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
48261           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
48262       ELSE
48263           ---------------------------------------------------------------------------------------------------
48264           -- 4262811a Switch Sign
48265           ---------------------------------------------------------------------------------------------------
48266           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
48267           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
48268                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48269           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
48270                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48271           -- 5132302
48272           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
48273                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48274 
48275       END IF;
48276 
48277       -- 4955764
48278       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
48279       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
48280 
48281 
48282       XLA_AE_LINES_PKG.ValidateCurrentLine;
48283       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
48284 
48285       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
48286                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
48287                ,p_balance_type_code => l_balance_type_code);
48288 
48289    END IF;
48290 
48291    -----------------------------------------------------------------------------------------
48292    -- 4262811 Multiperiod Accounting
48293    -----------------------------------------------------------------------------------------
48294      -- No MPA option is assigned.
48295 
48296 
48297 END IF;
48298 END IF;
48299 --
48300 
48301 --
48302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
48303    trace
48304       (p_msg      => 'END of AcctLineType_94'
48305       ,p_level    => C_LEVEL_PROCEDURE
48306       ,p_module   => l_log_module);
48307 END IF;
48308 --
48309 EXCEPTION
48310   WHEN xla_exceptions_pkg.application_exception THEN
48311       RAISE;
48312   WHEN OTHERS THEN
48313        xla_exceptions_pkg.raise_message
48314            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_94');
48315 END AcctLineType_94;
48316 --
48317 
48318 ---------------------------------------
48319 --
48320 -- PRIVATE FUNCTION
48321 --         AcctLineType_95
48322 --
48323 ---------------------------------------
48324 PROCEDURE AcctLineType_95 (
48325   p_application_id        IN NUMBER
48326  ,p_event_id              IN NUMBER
48327  ,p_calculate_acctd_flag  IN VARCHAR2
48328  ,p_calculate_g_l_flag    IN VARCHAR2
48329  ,p_actual_flag           IN OUT VARCHAR2
48330  ,p_balance_type_code     OUT VARCHAR2
48331  ,p_gain_or_loss_ref      OUT VARCHAR2
48332  
48333 --Distribution GL Account
48334  , p_source_3            IN NUMBER
48335 --Distribution Source Type
48336  , p_source_13            IN VARCHAR2
48337 --Distribution Line Identifier
48338  , p_source_15            IN NUMBER
48339 --Distribution Type
48340  , p_source_16            IN VARCHAR2
48341 --Exchange Date
48342  , p_source_19            IN DATE
48343 --Exchange Rate
48344  , p_source_20            IN NUMBER
48345 --Exchange Rate Type
48346  , p_source_21            IN VARCHAR2
48347 --Transaction Distribution Identifier
48348  , p_source_27            IN NUMBER
48349 --Transaction Distribution Type
48350  , p_source_28            IN VARCHAR2
48351 --Distribution Multi Fund Additional Entry
48352  , p_source_52            IN VARCHAR2
48353 --Receipt Applied To Application Identifier
48354  , p_source_56            IN NUMBER
48355 --Transaction Entity Code
48356  , p_source_57            IN VARCHAR2
48357 --Transaction Identifier
48358  , p_source_58            IN NUMBER
48359 --DIST_ENT_AMT_FROM
48360  , p_source_59            IN NUMBER
48361 --Applying Document Currency Code
48362  , p_source_60            IN VARCHAR2
48363 --Accounting Amount
48364  , p_source_61            IN NUMBER
48365 --Distribution Party Identifier
48366  , p_source_62            IN NUMBER
48367 --Distribution Party Site Id
48368  , p_source_63            IN NUMBER
48369 --Distribution Party Type
48370  , p_source_64            IN VARCHAR2
48371 --Distribution Source Table
48372  , p_source_67            IN VARCHAR2
48373 )
48374 IS
48375 
48376 l_component_type              VARCHAR2(80);
48377 l_component_code              VARCHAR2(30);
48378 l_component_type_code         VARCHAR2(1);
48379 l_component_appl_id           INTEGER;
48380 l_amb_context_code            VARCHAR2(30);
48381 l_entity_code                 VARCHAR2(30);
48382 l_event_class_code            VARCHAR2(30);
48383 l_ae_header_id                NUMBER;
48384 l_event_type_code             VARCHAR2(30);
48385 l_line_definition_code        VARCHAR2(30);
48386 l_line_definition_owner_code  VARCHAR2(1);
48387 --
48388 -- adr variables
48389 l_segment                     VARCHAR2(30);
48390 l_ccid                        NUMBER;
48391 l_adr_transaction_coa_id      NUMBER;
48392 l_adr_accounting_coa_id       NUMBER;
48393 l_adr_flexfield_segment_code  VARCHAR2(30);
48394 l_adr_flex_value_set_id       NUMBER;
48395 l_adr_value_type_code         VARCHAR2(30);
48396 l_adr_value_combination_id    NUMBER;
48397 l_adr_value_segment_code      VARCHAR2(30);
48398 
48399 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
48400 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
48401 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
48402 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
48403 
48404 -- 4262811 Variables ------------------------------------------------------------------------------------------
48405 l_entered_amt_idx             NUMBER;
48406 l_accted_amt_idx              NUMBER;
48407 l_acc_rev_flag                VARCHAR2(1);
48408 l_accrual_line_num            NUMBER;
48409 l_tmp_amt                     NUMBER;
48410 l_acc_rev_natural_side_code   VARCHAR2(1);
48411 
48412 l_num_entries                 NUMBER;
48413 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
48414 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
48415 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
48416 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
48417 l_recog_line_1                NUMBER;
48418 l_recog_line_2                NUMBER;
48419 
48420 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
48421 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
48422 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
48423 
48424 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
48425 
48426 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
48427 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
48428 
48429 ---------------------------------------------------------------------------------------------------------------
48430 
48431 
48432 --
48433 -- bulk performance
48434 --
48435 l_balance_type_code           VARCHAR2(1);
48436 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
48437 l_log_module                  VARCHAR2(240);
48438 
48439 --
48440 -- Upgrade strategy
48441 --
48442 l_actual_upg_option           VARCHAR2(1);
48443 l_enc_upg_option           VARCHAR2(1);
48444 
48445 --
48446 BEGIN
48447 --
48448 IF g_log_enabled THEN
48449       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_95';
48450 END IF;
48451 --
48452 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
48453 
48454       trace
48455          (p_msg      => 'BEGIN of AcctLineType_95'
48456          ,p_level    => C_LEVEL_PROCEDURE
48457          ,p_module   => l_log_module);
48458 
48459 END IF;
48460 --
48461 l_component_type             := 'AMB_JLT';
48462 l_component_code             := 'RCT_REMIT_BR';
48463 l_component_type_code        := 'S';
48464 l_component_appl_id          :=  222;
48465 l_amb_context_code           := 'DEFAULT';
48466 l_entity_code                := 'RECEIPTS';
48467 l_event_class_code           := 'RECEIPT';
48468 l_event_type_code            := 'RECEIPT_ALL';
48469 l_line_definition_owner_code := 'S';
48470 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
48471 --
48472 l_balance_type_code          := 'A';
48473 l_segment                     := NULL;
48477 l_adr_flexfield_segment_code  := NULL;
48474 l_ccid                        := NULL;
48475 l_adr_transaction_coa_id      := NULL;
48476 l_adr_accounting_coa_id       := NULL;
48478 l_adr_flex_value_set_id       := NULL;
48479 l_adr_value_type_code         := NULL;
48480 l_adr_value_combination_id    := NULL;
48481 l_adr_value_segment_code      := NULL;
48482 
48483 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
48484 l_bflow_class_code           := '';    -- 4219869 Business Flow
48485 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
48486 l_budgetary_control_flag     := 'N';
48487 
48488 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
48489 l_bflow_applied_to_amt       := NULL; -- 5132302
48490 l_entered_amt_idx            := NULL;          -- 4262811
48491 l_accted_amt_idx             := NULL;          -- 4262811
48492 l_acc_rev_flag               := NULL;          -- 4262811
48493 l_accrual_line_num           := NULL;          -- 4262811
48494 l_tmp_amt                    := NULL;          -- 4262811
48495 --
48496  
48497 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
48498     l_balance_type_code <> 'B' THEN
48499 IF NVL(p_source_13,'
48500 ') =  'REMITTANCE' AND 
48501 NVL(p_source_67,'
48502 ') =  'RA' AND 
48503 NVL(p_source_52,'
48504 ') =  'N'
48505  THEN 
48506 
48507    --
48508    XLA_AE_LINES_PKG.SetNewLine;
48509 
48510    p_balance_type_code          := l_balance_type_code;
48511    -- set the flag so later we will know whether the gain loss line needs to be created
48512    
48513    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
48514      p_actual_flag :='A';
48515    END IF;
48516 
48517    --
48518    -- bulk performance
48519    --
48520    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
48521                                       p_header_num   => 0); -- 4262811
48522    --
48523    -- set accounting line options
48524    --
48525    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
48526            p_natural_side_code          => 'C'
48527          , p_gain_or_loss_flag          => 'N'
48528          , p_gl_transfer_mode_code      => 'S'
48529          , p_acct_entry_type_code       => 'A'
48530          , p_switch_side_flag           => 'Y'
48531          , p_merge_duplicate_code       => 'A'
48532          );
48533    --
48534    l_acc_rev_natural_side_code := 'D';  -- 4262811
48535    -- 
48536    --
48537    -- set accounting line type info
48538    --
48539    xla_ae_lines_pkg.SetAcctLineType
48540       (p_component_type             => l_component_type
48541       ,p_event_type_code            => l_event_type_code
48542       ,p_line_definition_owner_code => l_line_definition_owner_code
48543       ,p_line_definition_code       => l_line_definition_code
48544       ,p_accounting_line_code       => l_component_code
48545       ,p_accounting_line_type_code  => l_component_type_code
48546       ,p_accounting_line_appl_id    => l_component_appl_id
48547       ,p_amb_context_code           => l_amb_context_code
48548       ,p_entity_code                => l_entity_code
48549       ,p_event_class_code           => l_event_class_code);
48550    --
48551    -- set accounting class
48552    --
48553    xla_ae_lines_pkg.SetAcctClass(
48554            p_accounting_class_code  => 'REM_BR'
48555          , p_ae_header_id           => l_ae_header_id
48556          );
48557 
48558    --
48559    -- set rounding class
48560    --
48561    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
48562                       'RECEIVABLE';
48563 
48564    --
48565    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
48566    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
48567    --
48568    -- bulk performance
48569    --
48570    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
48571 
48572    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
48573       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
48574 
48575    -- 4955764
48576    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
48577       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
48578 
48579    -- 4458381 Public Sector Enh
48580    
48581    --
48582    -- set accounting attributes for the line type
48583    --
48584    l_entered_amt_idx := 8;
48585    l_accted_amt_idx  := 13;
48586    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
48587    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
48588    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
48589    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
48590    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
48591    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
48592    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
48593    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
48594    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
48595    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
48596    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
48597    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
48598    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
48599    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
48603    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
48600    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
48601    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
48602    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
48604    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
48605    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
48606    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
48607    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
48608    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
48609    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
48610    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
48611    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
48612    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
48613    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
48614    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
48615    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
48616    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
48617    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
48618    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
48619 
48620    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
48621    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
48622 
48623    ---------------------------------------------------------------------------------------------------------------
48624    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
48625    ---------------------------------------------------------------------------------------------------------------
48626    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
48627 
48628    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
48629    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
48630 
48631    IF xla_accounting_cache_pkg.GetValueChar
48632          (p_source_code         => 'LEDGER_CATEGORY_CODE'
48633          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
48634    AND l_bflow_method_code = 'PRIOR_ENTRY'
48635 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
48636    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
48637          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
48638        )
48639    THEN
48640          xla_ae_lines_pkg.BflowUpgEntry
48641            (p_business_method_code    => l_bflow_method_code
48642            ,p_business_class_code     => l_bflow_class_code
48643            ,p_balance_type            => l_balance_type_code);
48644    ELSE
48645       NULL;
48646 -- No business flow processing for business flow method of NONE.
48647    END IF;
48648 
48649    --
48650    -- call analytical criteria
48651    --
48652    
48653    --
48654    -- call description
48655    --
48656    -- No description or it is inherited.
48657    --
48658    -- call ADRs
48659    -- Bug 4922099
48660    --
48661    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
48662         (NVL(l_actual_upg_option, 'N') = 'O') OR
48663         (NVL(l_enc_upg_option, 'N') = 'O')
48664       )
48665    THEN
48666    NULL;
48667    --
48668    --
48669    
48670   l_ccid := AcctDerRule_7(
48671            p_application_id           => p_application_id
48672          , p_ae_header_id             => l_ae_header_id 
48673 , p_source_3 => p_source_3
48674          , x_transaction_coa_id       => l_adr_transaction_coa_id
48675          , x_accounting_coa_id        => l_adr_accounting_coa_id
48676          , x_value_type_code          => l_adr_value_type_code
48677          , p_side                     => 'NA'
48678    );
48679 
48680    xla_ae_lines_pkg.set_ccid(
48681     p_code_combination_id          => l_ccid
48682   , p_value_type_code              => l_adr_value_type_code
48683   , p_transaction_coa_id           => l_adr_transaction_coa_id
48684   , p_accounting_coa_id            => l_adr_accounting_coa_id
48685   , p_adr_code                     => 'DIST_CCID'
48686   , p_adr_type_code                => 'S'
48687   , p_component_type               => l_component_type
48688   , p_component_code               => l_component_code
48689   , p_component_type_code          => l_component_type_code
48690   , p_component_appl_id            => l_component_appl_id
48691   , p_amb_context_code             => l_amb_context_code
48692   , p_side                         => 'NA'
48693   );
48694 
48695 
48696    --
48697    --
48698    END IF;
48699    --
48700    -- Bug 4922099
48701    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
48702           (NVL(l_enc_upg_option, 'N') = 'O')
48703         ) AND
48704         (l_bflow_method_code = 'PRIOR_ENTRY')
48705       )
48706    THEN
48707       IF
48708       --
48709       1 = 2
48710       --
48711       THEN
48712       xla_accounting_err_pkg.build_message
48713                                     (p_appli_s_name            => 'XLA'
48714                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
48715                                     ,p_token_1                 => 'LINE_NUMBER'
48716                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
48717                                     ,p_token_2                 => 'LINE_TYPE_NAME'
48718                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
48719                                                                              l_component_type
48720                                                                             ,l_component_code
48721                                                                             ,l_component_type_code
48722                                                                             ,l_component_appl_id
48723                                                                             ,l_amb_context_code
48724                                                                             ,l_entity_code
48725                                                                             ,l_event_class_code
48726                                                                            )
48727                                     ,p_token_3                 => 'OWNER'
48728                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
48729                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
48730                                                                           ,p_lookup_code    => l_component_type_code
48731                                                                          )
48732                                     ,p_token_4                 => 'PRODUCT_NAME'
48733                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
48734                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
48735                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
48736                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
48737                                     ,p_ae_header_id            =>  NULL
48738                                        );
48739 
48740         IF (C_LEVEL_ERROR>= g_log_level) THEN
48741                  trace
48742                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
48743                       ,p_level    => C_LEVEL_ERROR
48744                       ,p_module   => l_log_module);
48745         END IF;
48746       END IF;
48747    END IF;
48748    --
48749    --
48750    ------------------------------------------------------------------------------------------------
48751    -- 4219869 Business Flow
48752    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
48753    -- Prior Entry.  Currently, the following code is always generated.
48754    ------------------------------------------------------------------------------------------------
48755    XLA_AE_LINES_PKG.ValidateCurrentLine;
48756 
48757    ------------------------------------------------------------------------------------
48758    -- 4219869 Business Flow
48759    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
48760    ------------------------------------------------------------------------------------
48761    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
48762 
48763    ----------------------------------------------------------------------------------
48764    -- 4219869 Business Flow
48765    -- Update journal entry status -- Need to generate this within IF <condition>
48766    ----------------------------------------------------------------------------------
48767    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
48768          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
48769          ,p_balance_type_code => l_balance_type_code
48770          );
48771 
48772    -------------------------------------------------------------------------------------------
48773    -- 4262811 - Generate the Accrual Reversal lines
48774    -------------------------------------------------------------------------------------------
48775    BEGIN
48776       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
48777                               (g_array_event(p_event_id).array_value_num('header_index'));
48778       IF l_acc_rev_flag IS NULL THEN
48779          l_acc_rev_flag := 'N';
48780       END IF;
48781    EXCEPTION
48782       WHEN OTHERS THEN
48783          l_acc_rev_flag := 'N';
48784    END;
48785    --
48786    IF (l_acc_rev_flag = 'Y') THEN
48787 
48788        -- 4645092  ------------------------------------------------------------------------------
48789        -- To allow MPA report to determine if it should generate report process
48790        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
48791        ------------------------------------------------------------------------------------------
48792 
48793        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
48794        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
48795    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
48796    -- call ADRs
48797    -- Bug 4922099
48798    --
48799    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
48800         (NVL(l_actual_upg_option, 'N') = 'O') OR
48801         (NVL(l_enc_upg_option, 'N') = 'O')
48802       )
48803    THEN
48804    NULL;
48805    --
48806    --
48807    
48808   l_ccid := AcctDerRule_7(
48809            p_application_id           => p_application_id
48810          , p_ae_header_id             => l_ae_header_id 
48811 , p_source_3 => p_source_3
48812          , x_transaction_coa_id       => l_adr_transaction_coa_id
48813          , x_accounting_coa_id        => l_adr_accounting_coa_id
48814          , x_value_type_code          => l_adr_value_type_code
48815          , p_side                     => 'NA'
48816    );
48817 
48818    xla_ae_lines_pkg.set_ccid(
48819     p_code_combination_id          => l_ccid
48820   , p_value_type_code              => l_adr_value_type_code
48821   , p_transaction_coa_id           => l_adr_transaction_coa_id
48822   , p_accounting_coa_id            => l_adr_accounting_coa_id
48823   , p_adr_code                     => 'DIST_CCID'
48824   , p_adr_type_code                => 'S'
48825   , p_component_type               => l_component_type
48826   , p_component_code               => l_component_code
48827   , p_component_type_code          => l_component_type_code
48828   , p_component_appl_id            => l_component_appl_id
48829   , p_amb_context_code             => l_amb_context_code
48830   , p_side                         => 'NA'
48831   );
48832 
48833 
48834    --
48835    --
48836    END IF;
48837 
48838        --
48839        -- Update the line information that should be overwritten
48840        --
48841        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
48842                                          p_header_num   => 1);
48843        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
48844 
48845        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
48846 
48847        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
48848           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
48849        END IF;
48850 
48851       --
48852       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
48853       --
48854       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
48855           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
48856       ELSE
48857           ---------------------------------------------------------------------------------------------------
48858           -- 4262811a Switch Sign
48859           ---------------------------------------------------------------------------------------------------
48860           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
48861           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
48862                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48863           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
48864                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48865           -- 5132302
48866           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
48867                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
48868 
48869       END IF;
48870 
48871       -- 4955764
48872       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
48873       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
48874 
48875 
48876       XLA_AE_LINES_PKG.ValidateCurrentLine;
48877       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
48878 
48879       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
48880                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
48881                ,p_balance_type_code => l_balance_type_code);
48882 
48883    END IF;
48884 
48885    -----------------------------------------------------------------------------------------
48886    -- 4262811 Multiperiod Accounting
48887    -----------------------------------------------------------------------------------------
48888      -- No MPA option is assigned.
48889 
48890 
48891 END IF;
48892 END IF;
48893 --
48894 
48895 --
48896 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
48897    trace
48898       (p_msg      => 'END of AcctLineType_95'
48899       ,p_level    => C_LEVEL_PROCEDURE
48900       ,p_module   => l_log_module);
48901 END IF;
48902 --
48903 EXCEPTION
48904   WHEN xla_exceptions_pkg.application_exception THEN
48905       RAISE;
48906   WHEN OTHERS THEN
48907        xla_exceptions_pkg.raise_message
48908            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_95');
48909 END AcctLineType_95;
48910 --
48911 
48912 ---------------------------------------
48913 --
48914 -- PRIVATE FUNCTION
48915 --         AcctLineType_96
48916 --
48917 ---------------------------------------
48918 PROCEDURE AcctLineType_96 (
48919   p_application_id        IN NUMBER
48920  ,p_event_id              IN NUMBER
48921  ,p_calculate_acctd_flag  IN VARCHAR2
48922  ,p_calculate_g_l_flag    IN VARCHAR2
48923  ,p_actual_flag           IN OUT VARCHAR2
48924  ,p_balance_type_code     OUT VARCHAR2
48925  ,p_gain_or_loss_ref      OUT VARCHAR2
48926  
48927 --Distribution GL Account
48928  , p_source_3            IN NUMBER
48929 --Distribution Source Type
48930  , p_source_13            IN VARCHAR2
48931 --Distribution Line Identifier
48932  , p_source_15            IN NUMBER
48933 --Distribution Type
48934  , p_source_16            IN VARCHAR2
48935 --Entered Amount
48936  , p_source_17            IN NUMBER
48937 --Currency Code
48938  , p_source_18            IN VARCHAR2
48939 --Applied To Document Accounting Amount
48940  , p_source_22            IN NUMBER
48941 --Transaction Distribution Identifier
48942  , p_source_27            IN NUMBER
48943 --Transaction Distribution Type
48944  , p_source_28            IN VARCHAR2
48945 --Distribution Multi Fund Additional Entry
48946  , p_source_52            IN VARCHAR2
48947 --Applied To Document Exchange Date
48948  , p_source_53            IN DATE
48949 --Receipt Applied To Application Identifier
48950  , p_source_56            IN NUMBER
48951 --Transaction Entity Code
48955 --Distribution Party Identifier
48952  , p_source_57            IN VARCHAR2
48953 --Transaction Identifier
48954  , p_source_58            IN NUMBER
48956  , p_source_62            IN NUMBER
48957 --Distribution Party Site Id
48958  , p_source_63            IN NUMBER
48959 --Distribution Party Type
48960  , p_source_64            IN VARCHAR2
48961 --Applied To Document Exchange Rate Type
48962  , p_source_65            IN VARCHAR2
48963 --Applied To Document Exchange Rate
48964  , p_source_66            IN NUMBER
48965 )
48966 IS
48967 
48968 l_component_type              VARCHAR2(80);
48969 l_component_code              VARCHAR2(30);
48970 l_component_type_code         VARCHAR2(1);
48971 l_component_appl_id           INTEGER;
48972 l_amb_context_code            VARCHAR2(30);
48973 l_entity_code                 VARCHAR2(30);
48974 l_event_class_code            VARCHAR2(30);
48975 l_ae_header_id                NUMBER;
48976 l_event_type_code             VARCHAR2(30);
48977 l_line_definition_code        VARCHAR2(30);
48978 l_line_definition_owner_code  VARCHAR2(1);
48979 --
48980 -- adr variables
48981 l_segment                     VARCHAR2(30);
48982 l_ccid                        NUMBER;
48983 l_adr_transaction_coa_id      NUMBER;
48984 l_adr_accounting_coa_id       NUMBER;
48985 l_adr_flexfield_segment_code  VARCHAR2(30);
48986 l_adr_flex_value_set_id       NUMBER;
48987 l_adr_value_type_code         VARCHAR2(30);
48988 l_adr_value_combination_id    NUMBER;
48989 l_adr_value_segment_code      VARCHAR2(30);
48990 
48991 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
48992 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
48993 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
48994 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
48995 
48996 -- 4262811 Variables ------------------------------------------------------------------------------------------
48997 l_entered_amt_idx             NUMBER;
48998 l_accted_amt_idx              NUMBER;
48999 l_acc_rev_flag                VARCHAR2(1);
49000 l_accrual_line_num            NUMBER;
49001 l_tmp_amt                     NUMBER;
49002 l_acc_rev_natural_side_code   VARCHAR2(1);
49003 
49004 l_num_entries                 NUMBER;
49005 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
49006 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
49007 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
49008 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
49009 l_recog_line_1                NUMBER;
49010 l_recog_line_2                NUMBER;
49011 
49012 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
49013 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
49014 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
49015 
49016 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
49017 
49018 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
49019 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
49020 
49021 ---------------------------------------------------------------------------------------------------------------
49022 
49023 
49024 --
49025 -- bulk performance
49026 --
49027 l_balance_type_code           VARCHAR2(1);
49028 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
49029 l_log_module                  VARCHAR2(240);
49030 
49031 --
49032 -- Upgrade strategy
49036 
49033 --
49034 l_actual_upg_option           VARCHAR2(1);
49035 l_enc_upg_option           VARCHAR2(1);
49037 --
49038 BEGIN
49039 --
49040 IF g_log_enabled THEN
49041       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_96';
49042 END IF;
49043 --
49044 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
49045 
49046       trace
49047          (p_msg      => 'BEGIN of AcctLineType_96'
49048          ,p_level    => C_LEVEL_PROCEDURE
49049          ,p_module   => l_log_module);
49050 
49051 END IF;
49052 --
49053 l_component_type             := 'AMB_JLT';
49054 l_component_code             := 'RCT_TAX';
49055 l_component_type_code        := 'S';
49056 l_component_appl_id          :=  222;
49057 l_amb_context_code           := 'DEFAULT';
49058 l_entity_code                := 'RECEIPTS';
49059 l_event_class_code           := 'RECEIPT';
49060 l_event_type_code            := 'RECEIPT_ALL';
49061 l_line_definition_owner_code := 'S';
49062 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
49063 --
49064 l_balance_type_code          := 'A';
49065 l_segment                     := NULL;
49066 l_ccid                        := NULL;
49067 l_adr_transaction_coa_id      := NULL;
49068 l_adr_accounting_coa_id       := NULL;
49069 l_adr_flexfield_segment_code  := NULL;
49070 l_adr_flex_value_set_id       := NULL;
49071 l_adr_value_type_code         := NULL;
49072 l_adr_value_combination_id    := NULL;
49073 l_adr_value_segment_code      := NULL;
49074 
49075 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
49076 l_bflow_class_code           := '';    -- 4219869 Business Flow
49077 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
49078 l_budgetary_control_flag     := 'N';
49079 
49080 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
49081 l_bflow_applied_to_amt       := NULL; -- 5132302
49082 l_entered_amt_idx            := NULL;          -- 4262811
49083 l_accted_amt_idx             := NULL;          -- 4262811
49084 l_acc_rev_flag               := NULL;          -- 4262811
49085 l_accrual_line_num           := NULL;          -- 4262811
49086 l_tmp_amt                    := NULL;          -- 4262811
49087 --
49088  
49089 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
49090     l_balance_type_code <> 'B' THEN
49091 IF NVL(p_source_13,'
49092 ') =  'TAX' AND 
49093 NVL(p_source_52,'
49094 ') =  'N'
49095  THEN 
49096 
49097    --
49098    XLA_AE_LINES_PKG.SetNewLine;
49099 
49100    p_balance_type_code          := l_balance_type_code;
49101    -- set the flag so later we will know whether the gain loss line needs to be created
49102    
49103    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
49104      p_actual_flag :='A';
49105    END IF;
49106 
49107    --
49108    -- bulk performance
49109    --
49110    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
49111                                       p_header_num   => 0); -- 4262811
49112    --
49113    -- set accounting line options
49114    --
49115    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
49116            p_natural_side_code          => 'C'
49117          , p_gain_or_loss_flag          => 'N'
49118          , p_gl_transfer_mode_code      => 'S'
49119          , p_acct_entry_type_code       => 'A'
49120          , p_switch_side_flag           => 'Y'
49121          , p_merge_duplicate_code       => 'A'
49122          );
49123    --
49124    l_acc_rev_natural_side_code := 'D';  -- 4262811
49125    -- 
49126    --
49127    -- set accounting line type info
49128    --
49129    xla_ae_lines_pkg.SetAcctLineType
49130       (p_component_type             => l_component_type
49131       ,p_event_type_code            => l_event_type_code
49132       ,p_line_definition_owner_code => l_line_definition_owner_code
49133       ,p_line_definition_code       => l_line_definition_code
49134       ,p_accounting_line_code       => l_component_code
49135       ,p_accounting_line_type_code  => l_component_type_code
49136       ,p_accounting_line_appl_id    => l_component_appl_id
49140    --
49137       ,p_amb_context_code           => l_amb_context_code
49138       ,p_entity_code                => l_entity_code
49139       ,p_event_class_code           => l_event_class_code);
49141    -- set accounting class
49142    --
49143    xla_ae_lines_pkg.SetAcctClass(
49144            p_accounting_class_code  => 'TAX'
49145          , p_ae_header_id           => l_ae_header_id
49146          );
49147 
49148    --
49149    -- set rounding class
49150    --
49151    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
49152                       'RECEIVABLE';
49153 
49154    --
49155    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
49156    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
49157    --
49158    -- bulk performance
49159    --
49160    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
49161 
49162    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
49163       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
49164 
49165    -- 4955764
49166    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
49167       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
49168 
49169    -- 4458381 Public Sector Enh
49170    
49171    --
49172    -- set accounting attributes for the line type
49173    --
49174    l_entered_amt_idx := 8;
49175    l_accted_amt_idx  := 13;
49176    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
49177    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
49178    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
49179    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
49180    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
49181    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
49182    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
49183    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
49184    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
49185    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
49186    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
49187    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
49188    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
49189    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
49190    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
49191    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
49192    l_rec_acct_attrs.array_num_value(8)  := p_source_17;
49193    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
49194    l_rec_acct_attrs.array_char_value(9)  := p_source_18;
49195    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
49196    l_rec_acct_attrs.array_date_value(10)  := p_source_53;
49197    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
49198    l_rec_acct_attrs.array_num_value(11)  := p_source_66;
49199    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
49200    l_rec_acct_attrs.array_char_value(12)  := p_source_65;
49201    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
49202    l_rec_acct_attrs.array_num_value(13)  := p_source_22;
49203    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
49204    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
49205    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
49206    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
49207    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
49208    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
49209 
49210    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
49211    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
49212 
49213    ---------------------------------------------------------------------------------------------------------------
49214    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
49215    ---------------------------------------------------------------------------------------------------------------
49216    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
49217 
49218    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
49219    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
49220 
49221    IF xla_accounting_cache_pkg.GetValueChar
49222          (p_source_code         => 'LEDGER_CATEGORY_CODE'
49223          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
49224    AND l_bflow_method_code = 'PRIOR_ENTRY'
49225 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
49226    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
49227          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
49228        )
49229    THEN
49230          xla_ae_lines_pkg.BflowUpgEntry
49231            (p_business_method_code    => l_bflow_method_code
49232            ,p_business_class_code     => l_bflow_class_code
49233            ,p_balance_type            => l_balance_type_code);
49234    ELSE
49235       NULL;
49236 -- No business flow processing for business flow method of NONE.
49237    END IF;
49238 
49239    --
49240    -- call analytical criteria
49241    --
49242    
49243    --
49244    -- call description
49245    --
49246    -- No description or it is inherited.
49247    --
49248    -- call ADRs
49249    -- Bug 4922099
49250    --
49254       )
49251    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
49252         (NVL(l_actual_upg_option, 'N') = 'O') OR
49253         (NVL(l_enc_upg_option, 'N') = 'O')
49255    THEN
49256    NULL;
49257    --
49258    --
49259    
49260   l_ccid := AcctDerRule_7(
49261            p_application_id           => p_application_id
49262          , p_ae_header_id             => l_ae_header_id 
49263 , p_source_3 => p_source_3
49264          , x_transaction_coa_id       => l_adr_transaction_coa_id
49265          , x_accounting_coa_id        => l_adr_accounting_coa_id
49266          , x_value_type_code          => l_adr_value_type_code
49267          , p_side                     => 'NA'
49268    );
49269 
49270    xla_ae_lines_pkg.set_ccid(
49271     p_code_combination_id          => l_ccid
49272   , p_value_type_code              => l_adr_value_type_code
49273   , p_transaction_coa_id           => l_adr_transaction_coa_id
49274   , p_accounting_coa_id            => l_adr_accounting_coa_id
49275   , p_adr_code                     => 'DIST_CCID'
49276   , p_adr_type_code                => 'S'
49277   , p_component_type               => l_component_type
49278   , p_component_code               => l_component_code
49279   , p_component_type_code          => l_component_type_code
49280   , p_component_appl_id            => l_component_appl_id
49281   , p_amb_context_code             => l_amb_context_code
49282   , p_side                         => 'NA'
49283   );
49284 
49285 
49286    --
49287    --
49288    END IF;
49289    --
49290    -- Bug 4922099
49291    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
49292           (NVL(l_enc_upg_option, 'N') = 'O')
49293         ) AND
49294         (l_bflow_method_code = 'PRIOR_ENTRY')
49295       )
49296    THEN
49297       IF
49298       --
49299       1 = 2
49300       --
49301       THEN
49302       xla_accounting_err_pkg.build_message
49303                                     (p_appli_s_name            => 'XLA'
49304                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
49305                                     ,p_token_1                 => 'LINE_NUMBER'
49306                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
49307                                     ,p_token_2                 => 'LINE_TYPE_NAME'
49308                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
49309                                                                              l_component_type
49310                                                                             ,l_component_code
49311                                                                             ,l_component_type_code
49312                                                                             ,l_component_appl_id
49313                                                                             ,l_amb_context_code
49314                                                                             ,l_entity_code
49315                                                                             ,l_event_class_code
49316                                                                            )
49317                                     ,p_token_3                 => 'OWNER'
49318                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
49319                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
49320                                                                           ,p_lookup_code    => l_component_type_code
49321                                                                          )
49322                                     ,p_token_4                 => 'PRODUCT_NAME'
49323                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
49324                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
49325                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
49326                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
49327                                     ,p_ae_header_id            =>  NULL
49328                                        );
49329 
49330         IF (C_LEVEL_ERROR>= g_log_level) THEN
49331                  trace
49332                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
49333                       ,p_level    => C_LEVEL_ERROR
49334                       ,p_module   => l_log_module);
49335         END IF;
49336       END IF;
49337    END IF;
49338    --
49339    --
49340    ------------------------------------------------------------------------------------------------
49341    -- 4219869 Business Flow
49342    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
49343    -- Prior Entry.  Currently, the following code is always generated.
49344    ------------------------------------------------------------------------------------------------
49345    XLA_AE_LINES_PKG.ValidateCurrentLine;
49346 
49347    ------------------------------------------------------------------------------------
49348    -- 4219869 Business Flow
49349    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
49350    ------------------------------------------------------------------------------------
49351    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
49352 
49353    ----------------------------------------------------------------------------------
49354    -- 4219869 Business Flow
49358          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
49355    -- Update journal entry status -- Need to generate this within IF <condition>
49356    ----------------------------------------------------------------------------------
49357    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
49359          ,p_balance_type_code => l_balance_type_code
49360          );
49361 
49362    -------------------------------------------------------------------------------------------
49363    -- 4262811 - Generate the Accrual Reversal lines
49364    -------------------------------------------------------------------------------------------
49365    BEGIN
49366       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
49367                               (g_array_event(p_event_id).array_value_num('header_index'));
49368       IF l_acc_rev_flag IS NULL THEN
49369          l_acc_rev_flag := 'N';
49370       END IF;
49371    EXCEPTION
49372       WHEN OTHERS THEN
49373          l_acc_rev_flag := 'N';
49374    END;
49375    --
49376    IF (l_acc_rev_flag = 'Y') THEN
49377 
49378        -- 4645092  ------------------------------------------------------------------------------
49379        -- To allow MPA report to determine if it should generate report process
49380        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
49381        ------------------------------------------------------------------------------------------
49382 
49383        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
49384        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
49385    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
49386    -- call ADRs
49387    -- Bug 4922099
49388    --
49389    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
49390         (NVL(l_actual_upg_option, 'N') = 'O') OR
49391         (NVL(l_enc_upg_option, 'N') = 'O')
49392       )
49393    THEN
49394    NULL;
49395    --
49396    --
49397    
49398   l_ccid := AcctDerRule_7(
49399            p_application_id           => p_application_id
49400          , p_ae_header_id             => l_ae_header_id 
49401 , p_source_3 => p_source_3
49402          , x_transaction_coa_id       => l_adr_transaction_coa_id
49403          , x_accounting_coa_id        => l_adr_accounting_coa_id
49404          , x_value_type_code          => l_adr_value_type_code
49405          , p_side                     => 'NA'
49406    );
49407 
49408    xla_ae_lines_pkg.set_ccid(
49409     p_code_combination_id          => l_ccid
49410   , p_value_type_code              => l_adr_value_type_code
49411   , p_transaction_coa_id           => l_adr_transaction_coa_id
49412   , p_accounting_coa_id            => l_adr_accounting_coa_id
49413   , p_adr_code                     => 'DIST_CCID'
49414   , p_adr_type_code                => 'S'
49415   , p_component_type               => l_component_type
49416   , p_component_code               => l_component_code
49417   , p_component_type_code          => l_component_type_code
49418   , p_component_appl_id            => l_component_appl_id
49419   , p_amb_context_code             => l_amb_context_code
49420   , p_side                         => 'NA'
49421   );
49422 
49423 
49424    --
49425    --
49426    END IF;
49427 
49428        --
49429        -- Update the line information that should be overwritten
49430        --
49431        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
49432                                          p_header_num   => 1);
49433        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
49434 
49435        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
49436 
49437        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
49438           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
49439        END IF;
49440 
49441       --
49442       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
49443       --
49444       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
49445           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
49446       ELSE
49447           ---------------------------------------------------------------------------------------------------
49448           -- 4262811a Switch Sign
49449           ---------------------------------------------------------------------------------------------------
49450           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
49451           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
49452                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
49453           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
49454                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
49455           -- 5132302
49456           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
49457                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
49458 
49459       END IF;
49460 
49461       -- 4955764
49462       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
49463       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
49464 
49465 
49466       XLA_AE_LINES_PKG.ValidateCurrentLine;
49467       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
49468 
49469       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
49473    END IF;
49470                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
49471                ,p_balance_type_code => l_balance_type_code);
49472 
49474 
49475    -----------------------------------------------------------------------------------------
49476    -- 4262811 Multiperiod Accounting
49477    -----------------------------------------------------------------------------------------
49478      -- No MPA option is assigned.
49479 
49480 
49481 END IF;
49482 END IF;
49483 --
49484 
49485 --
49486 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
49487    trace
49488       (p_msg      => 'END of AcctLineType_96'
49489       ,p_level    => C_LEVEL_PROCEDURE
49490       ,p_module   => l_log_module);
49491 END IF;
49492 --
49493 EXCEPTION
49494   WHEN xla_exceptions_pkg.application_exception THEN
49495       RAISE;
49496   WHEN OTHERS THEN
49497        xla_exceptions_pkg.raise_message
49498            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_96');
49499 END AcctLineType_96;
49500 --
49501 
49502 ---------------------------------------
49503 --
49504 -- PRIVATE FUNCTION
49505 --         AcctLineType_97
49506 --
49507 ---------------------------------------
49508 PROCEDURE AcctLineType_97 (
49509   p_application_id        IN NUMBER
49510  ,p_event_id              IN NUMBER
49511  ,p_calculate_acctd_flag  IN VARCHAR2
49512  ,p_calculate_g_l_flag    IN VARCHAR2
49513  ,p_actual_flag           IN OUT VARCHAR2
49514  ,p_balance_type_code     OUT VARCHAR2
49515  ,p_gain_or_loss_ref      OUT VARCHAR2
49516  
49517 --Remittance Bank Account Unapplied Account
49518  , p_source_10            IN NUMBER
49519 --Distribution Source Type
49520  , p_source_13            IN VARCHAR2
49521 --Receivable Activity Type
49522  , p_source_14            IN VARCHAR2
49523 --Distribution Line Identifier
49524  , p_source_15            IN NUMBER
49525 --Distribution Type
49526  , p_source_16            IN VARCHAR2
49527 --Exchange Date
49528  , p_source_19            IN DATE
49529 --Exchange Rate
49530  , p_source_20            IN NUMBER
49531 --Exchange Rate Type
49532  , p_source_21            IN VARCHAR2
49533 --Transaction Distribution Identifier
49534  , p_source_27            IN NUMBER
49535 --Transaction Distribution Type
49536  , p_source_28            IN VARCHAR2
49537 --Distribution Multi Fund Additional Entry
49538  , p_source_52            IN VARCHAR2
49539 --Receipt Applied To Application Identifier
49540  , p_source_56            IN NUMBER
49541 --Transaction Entity Code
49542  , p_source_57            IN VARCHAR2
49543 --Transaction Identifier
49544  , p_source_58            IN NUMBER
49545 --DIST_ENT_AMT_FROM
49546  , p_source_59            IN NUMBER
49547 --Applying Document Currency Code
49548  , p_source_60            IN VARCHAR2
49549 --Accounting Amount
49550  , p_source_61            IN NUMBER
49551 --Distribution Party Type
49552  , p_source_64            IN VARCHAR2
49553 --Distribution Source Table
49554  , p_source_67            IN VARCHAR2
49555 --Receipt Pay From Customer
49556  , p_source_68            IN NUMBER
49557 --Receipt Customer Site Use Identifier
49558  , p_source_69            IN NUMBER
49559 )
49560 IS
49561 
49562 l_component_type              VARCHAR2(80);
49563 l_component_code              VARCHAR2(30);
49564 l_component_type_code         VARCHAR2(1);
49565 l_component_appl_id           INTEGER;
49566 l_amb_context_code            VARCHAR2(30);
49567 l_entity_code                 VARCHAR2(30);
49568 l_event_class_code            VARCHAR2(30);
49569 l_ae_header_id                NUMBER;
49570 l_event_type_code             VARCHAR2(30);
49571 l_line_definition_code        VARCHAR2(30);
49572 l_line_definition_owner_code  VARCHAR2(1);
49573 --
49574 -- adr variables
49575 l_segment                     VARCHAR2(30);
49576 l_ccid                        NUMBER;
49577 l_adr_transaction_coa_id      NUMBER;
49578 l_adr_accounting_coa_id       NUMBER;
49579 l_adr_flexfield_segment_code  VARCHAR2(30);
49580 l_adr_flex_value_set_id       NUMBER;
49581 l_adr_value_type_code         VARCHAR2(30);
49582 l_adr_value_combination_id    NUMBER;
49583 l_adr_value_segment_code      VARCHAR2(30);
49584 
49585 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
49586 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
49587 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
49588 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
49589 
49590 -- 4262811 Variables ------------------------------------------------------------------------------------------
49591 l_entered_amt_idx             NUMBER;
49592 l_accted_amt_idx              NUMBER;
49593 l_acc_rev_flag                VARCHAR2(1);
49594 l_accrual_line_num            NUMBER;
49595 l_tmp_amt                     NUMBER;
49596 l_acc_rev_natural_side_code   VARCHAR2(1);
49597 
49598 l_num_entries                 NUMBER;
49599 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
49600 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
49601 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
49602 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
49603 l_recog_line_1                NUMBER;
49604 l_recog_line_2                NUMBER;
49605 
49606 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
49607 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
49608 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
49609 
49613 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
49610 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
49611 
49612 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
49614 
49615 ---------------------------------------------------------------------------------------------------------------
49616 
49617 
49618 --
49619 -- bulk performance
49620 --
49621 l_balance_type_code           VARCHAR2(1);
49622 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
49623 l_log_module                  VARCHAR2(240);
49624 
49625 --
49626 -- Upgrade strategy
49627 --
49628 l_actual_upg_option           VARCHAR2(1);
49629 l_enc_upg_option           VARCHAR2(1);
49630 
49631 --
49632 BEGIN
49633 --
49634 IF g_log_enabled THEN
49635       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_97';
49636 END IF;
49637 --
49638 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
49639 
49640       trace
49641          (p_msg      => 'BEGIN of AcctLineType_97'
49642          ,p_level    => C_LEVEL_PROCEDURE
49643          ,p_module   => l_log_module);
49644 
49645 END IF;
49646 --
49647 l_component_type             := 'AMB_JLT';
49648 l_component_code             := 'RCT_UNAPP';
49649 l_component_type_code        := 'S';
49650 l_component_appl_id          :=  222;
49651 l_amb_context_code           := 'DEFAULT';
49652 l_entity_code                := 'RECEIPTS';
49653 l_event_class_code           := 'RECEIPT';
49654 l_event_type_code            := 'RECEIPT_ALL';
49655 l_line_definition_owner_code := 'S';
49656 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
49657 --
49658 l_balance_type_code          := 'A';
49659 l_segment                     := NULL;
49660 l_ccid                        := NULL;
49661 l_adr_transaction_coa_id      := NULL;
49662 l_adr_accounting_coa_id       := NULL;
49663 l_adr_flexfield_segment_code  := NULL;
49664 l_adr_flex_value_set_id       := NULL;
49665 l_adr_value_type_code         := NULL;
49666 l_adr_value_combination_id    := NULL;
49667 l_adr_value_segment_code      := NULL;
49668 
49669 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
49670 l_bflow_class_code           := '';    -- 4219869 Business Flow
49671 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
49672 l_budgetary_control_flag     := 'N';
49673 
49674 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
49675 l_bflow_applied_to_amt       := NULL; -- 5132302
49676 l_entered_amt_idx            := NULL;          -- 4262811
49677 l_accted_amt_idx             := NULL;          -- 4262811
49678 l_acc_rev_flag               := NULL;          -- 4262811
49679 l_accrual_line_num           := NULL;          -- 4262811
49680 l_tmp_amt                    := NULL;          -- 4262811
49681 --
49682  
49683 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
49684     l_balance_type_code <> 'B' THEN
49685 IF (NVL(p_source_13,'
49686 ') =  'OTHER ACC' AND 
49687 NVL(p_source_14,'
49688 ') =  'CLAIM_INVESTIGATION' AND 
49689 NVL(p_source_52,'
49690 ') =  'N') OR 
49691 (NVL(p_source_13,'
49692 ') =  'FACTOR' AND 
49693 NVL(p_source_67,'
49694 ') =  'RA' AND 
49695 NVL(p_source_52,'
49696 ') =  'N') OR 
49697 (NVL(p_source_13,'
49698 ') =  'OTHER ACC' AND 
49699 NVL(p_source_52,'
49700 ') =  'N' AND 
49701 NVL(p_source_14,'
49702 ') =  'NETTING') OR 
49703 (NVL(p_source_13,'
49704 ') =  'OTHER ACC' AND 
49705 NVL(p_source_52,'
49706 ') =  'N' AND 
49707 NVL(p_source_14,'
49708 ') =  'PREPAYMENT') OR 
49709 (NVL(p_source_13,'
49710 ') =  'ACTIVITY' AND 
49711 NVL(p_source_52,'
49712 ') =  'N' AND 
49713 NVL(p_source_14,'
49714 ') =  'CCREFUND') OR 
49715 (NVL(p_source_13,'
49716 ') =  'REMITTANCE' AND 
49717 NVL(p_source_52,'
49718 ') =  'N' AND 
49719 NVL(p_source_67,'
49720 ') =  'RA') OR 
49721 (NVL(p_source_13,'
49722 ') =  'ACTIVITY' AND 
49723 NVL(p_source_52,'
49724 ') =  'N' AND 
49725 NVL(p_source_14,'
49726 ') =  'WRITEOFF') OR 
49727 (NVL(p_source_13,'
49728 ') =  'ACTIVITY' AND 
49729 NVL(p_source_52,'
49730 ') =  'N' AND 
49731 NVL(p_source_14,'
49732 ') =  'CM_REFUND') OR 
49733 (NVL(p_source_13,'
49734 ') =  'ACTIVITY' AND 
49735 NVL(p_source_14,'
49736 ') =  'ADJUST' AND 
49737 NVL(p_source_52,'
49738 ') =  'N') OR 
49739 (NVL(p_source_13,'
49740 ') =  'ACTIVITY' AND 
49741 NVL(p_source_52,'
49742 ') =  'N' AND 
49743 NVL(p_source_14,'
49744 ') =  'CC_CHARGEBACK') OR 
49745 (NVL(p_source_13,'
49746 ') =  'ACTIVITY' AND 
49747 NVL(p_source_52,'
49748 ') =  'N' AND 
49749 NVL(p_source_14,'
49750 ') =  'NETTING')
49751  THEN 
49752 
49753    --
49754    XLA_AE_LINES_PKG.SetNewLine;
49755 
49756    p_balance_type_code          := l_balance_type_code;
49757    -- set the flag so later we will know whether the gain loss line needs to be created
49758    
49759    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
49760      p_actual_flag :='A';
49761    END IF;
49762 
49763    --
49764    -- bulk performance
49765    --
49766    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
49767                                       p_header_num   => 0); -- 4262811
49768    --
49769    -- set accounting line options
49770    --
49771    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
49772            p_natural_side_code          => 'D'
49776          , p_switch_side_flag           => 'Y'
49773          , p_gain_or_loss_flag          => 'N'
49774          , p_gl_transfer_mode_code      => 'S'
49775          , p_acct_entry_type_code       => 'A'
49777          , p_merge_duplicate_code       => 'A'
49778          );
49779    --
49780    l_acc_rev_natural_side_code := 'C';  -- 4262811
49781    -- 
49782    --
49783    -- set accounting line type info
49784    --
49785    xla_ae_lines_pkg.SetAcctLineType
49786       (p_component_type             => l_component_type
49787       ,p_event_type_code            => l_event_type_code
49788       ,p_line_definition_owner_code => l_line_definition_owner_code
49789       ,p_line_definition_code       => l_line_definition_code
49790       ,p_accounting_line_code       => l_component_code
49791       ,p_accounting_line_type_code  => l_component_type_code
49792       ,p_accounting_line_appl_id    => l_component_appl_id
49793       ,p_amb_context_code           => l_amb_context_code
49794       ,p_entity_code                => l_entity_code
49795       ,p_event_class_code           => l_event_class_code);
49796    --
49797    -- set accounting class
49798    --
49799    xla_ae_lines_pkg.SetAcctClass(
49800            p_accounting_class_code  => 'UNAPP'
49801          , p_ae_header_id           => l_ae_header_id
49802          );
49803 
49804    --
49805    -- set rounding class
49806    --
49807    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
49808                       'RECEIVABLE';
49809 
49810    --
49811    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
49812    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
49813    --
49814    -- bulk performance
49815    --
49816    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
49817 
49818    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
49819       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
49820 
49821    -- 4955764
49822    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
49823       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
49824 
49825    -- 4458381 Public Sector Enh
49826    
49827    --
49828    -- set accounting attributes for the line type
49829    --
49830    l_entered_amt_idx := 8;
49831    l_accted_amt_idx  := 13;
49832    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
49833    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
49834    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
49835    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
49836    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
49837    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
49838    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
49839    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
49840    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
49841    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
49842    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
49843    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
49844    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
49845    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
49846    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
49847    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
49848    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
49849    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
49850    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
49854    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
49851    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
49852    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
49853    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
49855    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
49856    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
49857    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
49858    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
49859    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
49860    l_rec_acct_attrs.array_num_value(14)  := p_source_68;
49861    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
49862    l_rec_acct_attrs.array_num_value(15)  := p_source_69;
49863    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
49864    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
49865 
49866    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
49867    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
49868 
49869    ---------------------------------------------------------------------------------------------------------------
49870    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
49871    ---------------------------------------------------------------------------------------------------------------
49872    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
49873 
49874    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
49875    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
49876 
49877    IF xla_accounting_cache_pkg.GetValueChar
49878          (p_source_code         => 'LEDGER_CATEGORY_CODE'
49879          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
49880    AND l_bflow_method_code = 'PRIOR_ENTRY'
49881 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
49882    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
49883          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
49884        )
49885    THEN
49886          xla_ae_lines_pkg.BflowUpgEntry
49887            (p_business_method_code    => l_bflow_method_code
49888            ,p_business_class_code     => l_bflow_class_code
49889            ,p_balance_type            => l_balance_type_code);
49890    ELSE
49891       NULL;
49892 -- No business flow processing for business flow method of NONE.
49893    END IF;
49894 
49895    --
49896    -- call analytical criteria
49897    --
49898    
49899    --
49900    -- call description
49901    --
49902    -- No description or it is inherited.
49903    --
49904    -- call ADRs
49905    -- Bug 4922099
49906    --
49907    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
49908         (NVL(l_actual_upg_option, 'N') = 'O') OR
49909         (NVL(l_enc_upg_option, 'N') = 'O')
49910       )
49911    THEN
49912    NULL;
49913    --
49914    --
49915    
49916   l_ccid := AcctDerRule_13(
49917            p_application_id           => p_application_id
49918          , p_ae_header_id             => l_ae_header_id 
49919 , p_source_10 => p_source_10
49920          , x_transaction_coa_id       => l_adr_transaction_coa_id
49921          , x_accounting_coa_id        => l_adr_accounting_coa_id
49922          , x_value_type_code          => l_adr_value_type_code
49923          , p_side                     => 'NA'
49924    );
49925 
49926    xla_ae_lines_pkg.set_ccid(
49927     p_code_combination_id          => l_ccid
49928   , p_value_type_code              => l_adr_value_type_code
49929   , p_transaction_coa_id           => l_adr_transaction_coa_id
49930   , p_accounting_coa_id            => l_adr_accounting_coa_id
49931   , p_adr_code                     => 'RMT_BNK_UNAPP_CCID'
49932   , p_adr_type_code                => 'S'
49933   , p_component_type               => l_component_type
49934   , p_component_code               => l_component_code
49935   , p_component_type_code          => l_component_type_code
49936   , p_component_appl_id            => l_component_appl_id
49937   , p_amb_context_code             => l_amb_context_code
49938   , p_side                         => 'NA'
49939   );
49940 
49941 
49942    --
49943    --
49944    END IF;
49945    --
49946    -- Bug 4922099
49947    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
49948           (NVL(l_enc_upg_option, 'N') = 'O')
49949         ) AND
49950         (l_bflow_method_code = 'PRIOR_ENTRY')
49951       )
49952    THEN
49953       IF
49954       --
49955       1 = 2
49956       --
49957       THEN
49958       xla_accounting_err_pkg.build_message
49959                                     (p_appli_s_name            => 'XLA'
49960                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
49961                                     ,p_token_1                 => 'LINE_NUMBER'
49962                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
49963                                     ,p_token_2                 => 'LINE_TYPE_NAME'
49964                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
49965                                                                              l_component_type
49966                                                                             ,l_component_code
49967                                                                             ,l_component_type_code
49968                                                                             ,l_component_appl_id
49972                                                                            )
49969                                                                             ,l_amb_context_code
49970                                                                             ,l_entity_code
49971                                                                             ,l_event_class_code
49973                                     ,p_token_3                 => 'OWNER'
49974                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
49975                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
49976                                                                           ,p_lookup_code    => l_component_type_code
49977                                                                          )
49978                                     ,p_token_4                 => 'PRODUCT_NAME'
49979                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
49980                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
49981                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
49982                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
49983                                     ,p_ae_header_id            =>  NULL
49984                                        );
49985 
49986         IF (C_LEVEL_ERROR>= g_log_level) THEN
49987                  trace
49988                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
49989                       ,p_level    => C_LEVEL_ERROR
49990                       ,p_module   => l_log_module);
49991         END IF;
49992       END IF;
49993    END IF;
49994    --
49995    --
49996    ------------------------------------------------------------------------------------------------
49997    -- 4219869 Business Flow
49998    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
49999    -- Prior Entry.  Currently, the following code is always generated.
50000    ------------------------------------------------------------------------------------------------
50001    XLA_AE_LINES_PKG.ValidateCurrentLine;
50002 
50003    ------------------------------------------------------------------------------------
50004    -- 4219869 Business Flow
50005    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
50006    ------------------------------------------------------------------------------------
50007    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
50008 
50009    ----------------------------------------------------------------------------------
50010    -- 4219869 Business Flow
50011    -- Update journal entry status -- Need to generate this within IF <condition>
50012    ----------------------------------------------------------------------------------
50013    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
50014          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
50015          ,p_balance_type_code => l_balance_type_code
50016          );
50017 
50018    -------------------------------------------------------------------------------------------
50019    -- 4262811 - Generate the Accrual Reversal lines
50020    -------------------------------------------------------------------------------------------
50021    BEGIN
50022       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
50023                               (g_array_event(p_event_id).array_value_num('header_index'));
50024       IF l_acc_rev_flag IS NULL THEN
50025          l_acc_rev_flag := 'N';
50026       END IF;
50027    EXCEPTION
50028       WHEN OTHERS THEN
50029          l_acc_rev_flag := 'N';
50030    END;
50031    --
50032    IF (l_acc_rev_flag = 'Y') THEN
50033 
50034        -- 4645092  ------------------------------------------------------------------------------
50035        -- To allow MPA report to determine if it should generate report process
50036        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
50037        ------------------------------------------------------------------------------------------
50038 
50039        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
50040        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
50041    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
50042    -- call ADRs
50043    -- Bug 4922099
50044    --
50045    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
50046         (NVL(l_actual_upg_option, 'N') = 'O') OR
50047         (NVL(l_enc_upg_option, 'N') = 'O')
50048       )
50049    THEN
50050    NULL;
50051    --
50052    --
50053    
50054   l_ccid := AcctDerRule_13(
50055            p_application_id           => p_application_id
50056          , p_ae_header_id             => l_ae_header_id 
50057 , p_source_10 => p_source_10
50058          , x_transaction_coa_id       => l_adr_transaction_coa_id
50059          , x_accounting_coa_id        => l_adr_accounting_coa_id
50060          , x_value_type_code          => l_adr_value_type_code
50061          , p_side                     => 'NA'
50062    );
50063 
50064    xla_ae_lines_pkg.set_ccid(
50065     p_code_combination_id          => l_ccid
50066   , p_value_type_code              => l_adr_value_type_code
50067   , p_transaction_coa_id           => l_adr_transaction_coa_id
50068   , p_accounting_coa_id            => l_adr_accounting_coa_id
50069   , p_adr_code                     => 'RMT_BNK_UNAPP_CCID'
50070   , p_adr_type_code                => 'S'
50071   , p_component_type               => l_component_type
50072   , p_component_code               => l_component_code
50073   , p_component_type_code          => l_component_type_code
50077   );
50074   , p_component_appl_id            => l_component_appl_id
50075   , p_amb_context_code             => l_amb_context_code
50076   , p_side                         => 'NA'
50078 
50079 
50080    --
50081    --
50082    END IF;
50083 
50084        --
50085        -- Update the line information that should be overwritten
50086        --
50087        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
50088                                          p_header_num   => 1);
50089        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
50090 
50091        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
50092 
50093        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
50094           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
50095        END IF;
50096 
50097       --
50098       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
50099       --
50100       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
50101           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
50102       ELSE
50103           ---------------------------------------------------------------------------------------------------
50104           -- 4262811a Switch Sign
50105           ---------------------------------------------------------------------------------------------------
50106           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
50107           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
50108                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
50109           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
50110                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
50111           -- 5132302
50112           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
50113                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
50114 
50115       END IF;
50116 
50117       -- 4955764
50118       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
50119       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
50120 
50121 
50122       XLA_AE_LINES_PKG.ValidateCurrentLine;
50123       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
50124 
50125       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
50126                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
50127                ,p_balance_type_code => l_balance_type_code);
50128 
50129    END IF;
50130 
50131    -----------------------------------------------------------------------------------------
50132    -- 4262811 Multiperiod Accounting
50133    -----------------------------------------------------------------------------------------
50134      -- No MPA option is assigned.
50135 
50136 
50137 END IF;
50138 END IF;
50139 --
50140 
50141 --
50142 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
50143    trace
50144       (p_msg      => 'END of AcctLineType_97'
50145       ,p_level    => C_LEVEL_PROCEDURE
50146       ,p_module   => l_log_module);
50147 END IF;
50148 --
50149 EXCEPTION
50150   WHEN xla_exceptions_pkg.application_exception THEN
50151       RAISE;
50152   WHEN OTHERS THEN
50153        xla_exceptions_pkg.raise_message
50154            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_97');
50155 END AcctLineType_97;
50156 --
50157 
50158 ---------------------------------------
50159 --
50160 -- PRIVATE FUNCTION
50161 --         AcctLineType_98
50162 --
50163 ---------------------------------------
50164 PROCEDURE AcctLineType_98 (
50165   p_application_id        IN NUMBER
50166  ,p_event_id              IN NUMBER
50167  ,p_calculate_acctd_flag  IN VARCHAR2
50168  ,p_calculate_g_l_flag    IN VARCHAR2
50169  ,p_actual_flag           IN OUT VARCHAR2
50170  ,p_balance_type_code     OUT VARCHAR2
50171  ,p_gain_or_loss_ref      OUT VARCHAR2
50172  
50173 --Remittance Bank Account Unapplied Account
50174  , p_source_10            IN NUMBER
50175 --Distribution Source Type
50176  , p_source_13            IN VARCHAR2
50177 --Distribution Line Identifier
50178  , p_source_15            IN NUMBER
50179 --Distribution Type
50180  , p_source_16            IN VARCHAR2
50181 --Exchange Date
50182  , p_source_19            IN DATE
50183 --Exchange Rate
50184  , p_source_20            IN NUMBER
50185 --Exchange Rate Type
50186  , p_source_21            IN VARCHAR2
50187 --Transaction Distribution Identifier
50188  , p_source_27            IN NUMBER
50189 --Transaction Distribution Type
50190  , p_source_28            IN VARCHAR2
50191 --Distribution Multi Fund Additional Entry
50192  , p_source_52            IN VARCHAR2
50193 --Receipt Applied To Application Identifier
50194  , p_source_56            IN NUMBER
50195 --Transaction Entity Code
50196  , p_source_57            IN VARCHAR2
50197 --Transaction Identifier
50198  , p_source_58            IN NUMBER
50199 --DIST_ENT_AMT_FROM
50200  , p_source_59            IN NUMBER
50201 --Applying Document Currency Code
50202  , p_source_60            IN VARCHAR2
50203 --Accounting Amount
50204  , p_source_61            IN NUMBER
50205 --Distribution Party Type
50206  , p_source_64            IN VARCHAR2
50210  , p_source_68            IN NUMBER
50207 --Distribution Source Table
50208  , p_source_67            IN VARCHAR2
50209 --Receipt Pay From Customer
50211 --Receipt Customer Site Use Identifier
50212  , p_source_69            IN NUMBER
50213 --Receipt Application Status
50214  , p_source_70            IN VARCHAR2
50215 )
50216 IS
50217 
50218 l_component_type              VARCHAR2(80);
50219 l_component_code              VARCHAR2(30);
50220 l_component_type_code         VARCHAR2(1);
50221 l_component_appl_id           INTEGER;
50222 l_amb_context_code            VARCHAR2(30);
50223 l_entity_code                 VARCHAR2(30);
50224 l_event_class_code            VARCHAR2(30);
50225 l_ae_header_id                NUMBER;
50226 l_event_type_code             VARCHAR2(30);
50227 l_line_definition_code        VARCHAR2(30);
50228 l_line_definition_owner_code  VARCHAR2(1);
50229 --
50230 -- adr variables
50231 l_segment                     VARCHAR2(30);
50232 l_ccid                        NUMBER;
50233 l_adr_transaction_coa_id      NUMBER;
50234 l_adr_accounting_coa_id       NUMBER;
50235 l_adr_flexfield_segment_code  VARCHAR2(30);
50236 l_adr_flex_value_set_id       NUMBER;
50237 l_adr_value_type_code         VARCHAR2(30);
50238 l_adr_value_combination_id    NUMBER;
50239 l_adr_value_segment_code      VARCHAR2(30);
50240 
50241 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
50242 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
50243 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
50244 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
50245 
50246 -- 4262811 Variables ------------------------------------------------------------------------------------------
50247 l_entered_amt_idx             NUMBER;
50248 l_accted_amt_idx              NUMBER;
50249 l_acc_rev_flag                VARCHAR2(1);
50250 l_accrual_line_num            NUMBER;
50251 l_tmp_amt                     NUMBER;
50252 l_acc_rev_natural_side_code   VARCHAR2(1);
50253 
50254 l_num_entries                 NUMBER;
50255 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
50256 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
50257 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
50258 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
50259 l_recog_line_1                NUMBER;
50260 l_recog_line_2                NUMBER;
50261 
50262 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
50263 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
50264 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
50265 
50266 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
50267 
50268 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
50269 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
50270 
50271 ---------------------------------------------------------------------------------------------------------------
50272 
50273 
50274 --
50275 -- bulk performance
50276 --
50277 l_balance_type_code           VARCHAR2(1);
50278 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
50279 l_log_module                  VARCHAR2(240);
50280 
50281 --
50282 -- Upgrade strategy
50283 --
50284 l_actual_upg_option           VARCHAR2(1);
50285 l_enc_upg_option           VARCHAR2(1);
50286 
50287 --
50288 BEGIN
50289 --
50290 IF g_log_enabled THEN
50291       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_98';
50292 END IF;
50293 --
50294 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
50295 
50296       trace
50297          (p_msg      => 'BEGIN of AcctLineType_98'
50298          ,p_level    => C_LEVEL_PROCEDURE
50299          ,p_module   => l_log_module);
50300 
50301 END IF;
50302 --
50303 l_component_type             := 'AMB_JLT';
50304 l_component_code             := 'RCT_UNAPP_DEBIT';
50305 l_component_type_code        := 'S';
50306 l_component_appl_id          :=  222;
50307 l_amb_context_code           := 'DEFAULT';
50308 l_entity_code                := 'RECEIPTS';
50309 l_event_class_code           := 'RECEIPT';
50310 l_event_type_code            := 'RECEIPT_ALL';
50311 l_line_definition_owner_code := 'S';
50312 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
50313 --
50314 l_balance_type_code          := 'A';
50315 l_segment                     := NULL;
50316 l_ccid                        := NULL;
50317 l_adr_transaction_coa_id      := NULL;
50318 l_adr_accounting_coa_id       := NULL;
50319 l_adr_flexfield_segment_code  := NULL;
50320 l_adr_flex_value_set_id       := NULL;
50321 l_adr_value_type_code         := NULL;
50322 l_adr_value_combination_id    := NULL;
50323 l_adr_value_segment_code      := NULL;
50324 
50325 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
50326 l_bflow_class_code           := '';    -- 4219869 Business Flow
50327 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
50328 l_budgetary_control_flag     := 'N';
50329 
50330 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
50331 l_bflow_applied_to_amt       := NULL; -- 5132302
50332 l_entered_amt_idx            := NULL;          -- 4262811
50333 l_accted_amt_idx             := NULL;          -- 4262811
50334 l_acc_rev_flag               := NULL;          -- 4262811
50335 l_accrual_line_num           := NULL;          -- 4262811
50336 l_tmp_amt                    := NULL;          -- 4262811
50337 --
50338  
50339 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
50343 NVL(p_source_52,'
50340     l_balance_type_code <> 'B' THEN
50341 IF ((NVL(p_source_13,'
50342 ') =  'REC' AND 
50344 ') =  'N') OR 
50345 (NVL(p_source_52,'
50346 ') =  'N' AND 
50347 NVL(p_source_13,'
50348 ') =  'CASH') OR 
50349 (NVL(p_source_52,'
50350 ') =  'N' AND 
50351 NVL(p_source_13,'
50352 ') =  'CONFIRMATION') OR 
50353 (NVL(p_source_52,'
50354 ') =  'N' AND 
50355 NVL(p_source_13,'
50356 ') =  'CURR_ROUND') OR 
50357 (NVL(p_source_52,'
50358 ') =  'N' AND 
50359 NVL(p_source_13,'
50360 ') =  'DEFERRED_TAX') OR 
50361 (NVL(p_source_52,'
50362 ') =  'N' AND 
50363 NVL(p_source_67,'
50364 ') =  'CRH' AND 
50365 NVL(p_source_13,'
50366 ') =  'FACTOR') OR 
50367 (NVL(p_source_52,'
50368 ') =  'N' AND 
50369 NVL(p_source_13,'
50370 ') =  'ACC') OR 
50371 (NVL(p_source_52,'
50372 ') =  'N' AND 
50373 NVL(p_source_13,'
50374 ') =  'REMITTANCE' AND 
50375 NVL(p_source_67,'
50376 ') =  'CRH') OR 
50377 (NVL(p_source_52,'
50378 ') =  'N' AND 
50379 NVL(p_source_13,'
50380 ') =  'SHORT_TERM_DEBT') OR 
50381 (NVL(p_source_52,'
50382 ') =  'N' AND 
50383 NVL(p_source_13,'
50384 ') =  'TAX') OR 
50385 (NVL(p_source_52,'
50386 ') =  'N' AND 
50387 NVL(p_source_13,'
50388 ') =  'UNID') OR 
50389 (NVL(p_source_52,'
50390 ') =  'N' AND 
50391 NVL(p_source_13,'
50392 ') =  'BANK_CHARGES') OR 
50393 (NVL(p_source_52,'
50394 ') =  'N' AND 
50395 NVL(p_source_13,'
50396 ') =  'EDISC') OR 
50397 (NVL(p_source_52,'
50398 ') =  'N' AND 
50399 NVL(p_source_13,'
50400 ') =  'UNEDISC')
50401 ) AND NVL(p_source_70,'
50402 ') <>  'UNID'
50403  THEN 
50404 
50405    --
50406    XLA_AE_LINES_PKG.SetNewLine;
50407 
50408    p_balance_type_code          := l_balance_type_code;
50409    -- set the flag so later we will know whether the gain loss line needs to be created
50410    
50411    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
50412      p_actual_flag :='A';
50413    END IF;
50414 
50415    --
50416    -- bulk performance
50417    --
50418    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
50419                                       p_header_num   => 0); -- 4262811
50420    --
50421    -- set accounting line options
50422    --
50423    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
50424            p_natural_side_code          => 'D'
50425          , p_gain_or_loss_flag          => 'N'
50426          , p_gl_transfer_mode_code      => 'S'
50427          , p_acct_entry_type_code       => 'A'
50428          , p_switch_side_flag           => 'Y'
50429          , p_merge_duplicate_code       => 'A'
50430          );
50431    --
50432    l_acc_rev_natural_side_code := 'C';  -- 4262811
50433    -- 
50434    --
50435    -- set accounting line type info
50436    --
50437    xla_ae_lines_pkg.SetAcctLineType
50438       (p_component_type             => l_component_type
50439       ,p_event_type_code            => l_event_type_code
50440       ,p_line_definition_owner_code => l_line_definition_owner_code
50441       ,p_line_definition_code       => l_line_definition_code
50442       ,p_accounting_line_code       => l_component_code
50443       ,p_accounting_line_type_code  => l_component_type_code
50444       ,p_accounting_line_appl_id    => l_component_appl_id
50445       ,p_amb_context_code           => l_amb_context_code
50446       ,p_entity_code                => l_entity_code
50447       ,p_event_class_code           => l_event_class_code);
50448    --
50449    -- set accounting class
50450    --
50451    xla_ae_lines_pkg.SetAcctClass(
50452            p_accounting_class_code  => 'UNAPP'
50453          , p_ae_header_id           => l_ae_header_id
50454          );
50455 
50456    --
50457    -- set rounding class
50458    --
50459    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
50460                       'RECEIVABLE';
50461 
50462    --
50463    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
50464    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
50465    --
50466    -- bulk performance
50467    --
50468    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
50469 
50470    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
50471       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
50472 
50473    -- 4955764
50474    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
50475       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
50476 
50477    -- 4458381 Public Sector Enh
50478    
50479    --
50480    -- set accounting attributes for the line type
50481    --
50482    l_entered_amt_idx := 8;
50483    l_accted_amt_idx  := 13;
50484    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
50485    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
50486    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
50487    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
50488    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
50489    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
50490    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
50491    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
50492    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
50496    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
50493    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
50494    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
50495    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
50497    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
50498    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
50499    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
50500    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
50501    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
50502    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
50503    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
50504    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
50505    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
50506    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
50507    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
50508    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
50509    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
50510    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
50511    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
50512    l_rec_acct_attrs.array_num_value(14)  := p_source_68;
50513    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
50514    l_rec_acct_attrs.array_num_value(15)  := p_source_69;
50515    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
50516    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
50517 
50518    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
50519    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
50520 
50521    ---------------------------------------------------------------------------------------------------------------
50522    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
50523    ---------------------------------------------------------------------------------------------------------------
50524    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
50525 
50526    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
50527    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
50528 
50529    IF xla_accounting_cache_pkg.GetValueChar
50530          (p_source_code         => 'LEDGER_CATEGORY_CODE'
50531          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
50532    AND l_bflow_method_code = 'PRIOR_ENTRY'
50533 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
50534    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
50535          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
50536        )
50537    THEN
50538          xla_ae_lines_pkg.BflowUpgEntry
50539            (p_business_method_code    => l_bflow_method_code
50540            ,p_business_class_code     => l_bflow_class_code
50541            ,p_balance_type            => l_balance_type_code);
50542    ELSE
50543       NULL;
50544 -- No business flow processing for business flow method of NONE.
50545    END IF;
50546 
50547    --
50548    -- call analytical criteria
50549    --
50550    
50551    --
50552    -- call description
50553    --
50554    -- No description or it is inherited.
50555    --
50556    -- call ADRs
50557    -- Bug 4922099
50558    --
50559    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
50560         (NVL(l_actual_upg_option, 'N') = 'O') OR
50561         (NVL(l_enc_upg_option, 'N') = 'O')
50562       )
50563    THEN
50564    NULL;
50565    --
50566    --
50567    
50568   l_ccid := AcctDerRule_13(
50569            p_application_id           => p_application_id
50570          , p_ae_header_id             => l_ae_header_id 
50571 , p_source_10 => p_source_10
50572          , x_transaction_coa_id       => l_adr_transaction_coa_id
50573          , x_accounting_coa_id        => l_adr_accounting_coa_id
50574          , x_value_type_code          => l_adr_value_type_code
50575          , p_side                     => 'NA'
50576    );
50577 
50578    xla_ae_lines_pkg.set_ccid(
50579     p_code_combination_id          => l_ccid
50580   , p_value_type_code              => l_adr_value_type_code
50581   , p_transaction_coa_id           => l_adr_transaction_coa_id
50582   , p_accounting_coa_id            => l_adr_accounting_coa_id
50583   , p_adr_code                     => 'RMT_BNK_UNAPP_CCID'
50584   , p_adr_type_code                => 'S'
50585   , p_component_type               => l_component_type
50586   , p_component_code               => l_component_code
50587   , p_component_type_code          => l_component_type_code
50588   , p_component_appl_id            => l_component_appl_id
50589   , p_amb_context_code             => l_amb_context_code
50590   , p_side                         => 'NA'
50591   );
50592 
50593 
50594    --
50595    --
50596    END IF;
50597    --
50601         ) AND
50598    -- Bug 4922099
50599    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
50600           (NVL(l_enc_upg_option, 'N') = 'O')
50602         (l_bflow_method_code = 'PRIOR_ENTRY')
50603       )
50604    THEN
50605       IF
50606       --
50607       1 = 2
50608       --
50609       THEN
50610       xla_accounting_err_pkg.build_message
50611                                     (p_appli_s_name            => 'XLA'
50612                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
50613                                     ,p_token_1                 => 'LINE_NUMBER'
50614                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
50615                                     ,p_token_2                 => 'LINE_TYPE_NAME'
50616                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
50617                                                                              l_component_type
50618                                                                             ,l_component_code
50619                                                                             ,l_component_type_code
50620                                                                             ,l_component_appl_id
50621                                                                             ,l_amb_context_code
50622                                                                             ,l_entity_code
50623                                                                             ,l_event_class_code
50624                                                                            )
50625                                     ,p_token_3                 => 'OWNER'
50626                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
50627                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
50628                                                                           ,p_lookup_code    => l_component_type_code
50629                                                                          )
50630                                     ,p_token_4                 => 'PRODUCT_NAME'
50631                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
50632                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
50633                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
50634                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
50635                                     ,p_ae_header_id            =>  NULL
50636                                        );
50637 
50638         IF (C_LEVEL_ERROR>= g_log_level) THEN
50639                  trace
50640                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
50641                       ,p_level    => C_LEVEL_ERROR
50642                       ,p_module   => l_log_module);
50643         END IF;
50644       END IF;
50645    END IF;
50646    --
50647    --
50648    ------------------------------------------------------------------------------------------------
50649    -- 4219869 Business Flow
50650    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
50651    -- Prior Entry.  Currently, the following code is always generated.
50652    ------------------------------------------------------------------------------------------------
50653    XLA_AE_LINES_PKG.ValidateCurrentLine;
50654 
50655    ------------------------------------------------------------------------------------
50656    -- 4219869 Business Flow
50657    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
50658    ------------------------------------------------------------------------------------
50659    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
50660 
50661    ----------------------------------------------------------------------------------
50662    -- 4219869 Business Flow
50663    -- Update journal entry status -- Need to generate this within IF <condition>
50664    ----------------------------------------------------------------------------------
50665    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
50666          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
50667          ,p_balance_type_code => l_balance_type_code
50668          );
50669 
50670    -------------------------------------------------------------------------------------------
50671    -- 4262811 - Generate the Accrual Reversal lines
50672    -------------------------------------------------------------------------------------------
50673    BEGIN
50674       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
50675                               (g_array_event(p_event_id).array_value_num('header_index'));
50676       IF l_acc_rev_flag IS NULL THEN
50677          l_acc_rev_flag := 'N';
50678       END IF;
50679    EXCEPTION
50680       WHEN OTHERS THEN
50681          l_acc_rev_flag := 'N';
50682    END;
50683    --
50684    IF (l_acc_rev_flag = 'Y') THEN
50685 
50686        -- 4645092  ------------------------------------------------------------------------------
50687        -- To allow MPA report to determine if it should generate report process
50688        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
50689        ------------------------------------------------------------------------------------------
50690 
50691        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
50695    -- Bug 4922099
50692        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
50693    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
50694    -- call ADRs
50696    --
50697    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
50698         (NVL(l_actual_upg_option, 'N') = 'O') OR
50699         (NVL(l_enc_upg_option, 'N') = 'O')
50700       )
50701    THEN
50702    NULL;
50703    --
50704    --
50705    
50706   l_ccid := AcctDerRule_13(
50707            p_application_id           => p_application_id
50708          , p_ae_header_id             => l_ae_header_id 
50709 , p_source_10 => p_source_10
50710          , x_transaction_coa_id       => l_adr_transaction_coa_id
50711          , x_accounting_coa_id        => l_adr_accounting_coa_id
50712          , x_value_type_code          => l_adr_value_type_code
50713          , p_side                     => 'NA'
50714    );
50715 
50716    xla_ae_lines_pkg.set_ccid(
50717     p_code_combination_id          => l_ccid
50718   , p_value_type_code              => l_adr_value_type_code
50719   , p_transaction_coa_id           => l_adr_transaction_coa_id
50720   , p_accounting_coa_id            => l_adr_accounting_coa_id
50721   , p_adr_code                     => 'RMT_BNK_UNAPP_CCID'
50722   , p_adr_type_code                => 'S'
50723   , p_component_type               => l_component_type
50724   , p_component_code               => l_component_code
50725   , p_component_type_code          => l_component_type_code
50726   , p_component_appl_id            => l_component_appl_id
50727   , p_amb_context_code             => l_amb_context_code
50728   , p_side                         => 'NA'
50729   );
50730 
50731 
50732    --
50733    --
50734    END IF;
50735 
50736        --
50737        -- Update the line information that should be overwritten
50738        --
50739        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
50740                                          p_header_num   => 1);
50741        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
50742 
50743        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
50744 
50745        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
50746           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
50747        END IF;
50748 
50749       --
50750       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
50751       --
50752       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
50753           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
50754       ELSE
50755           ---------------------------------------------------------------------------------------------------
50756           -- 4262811a Switch Sign
50757           ---------------------------------------------------------------------------------------------------
50758           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
50759           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
50760                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
50761           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
50762                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
50763           -- 5132302
50764           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
50765                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
50766 
50767       END IF;
50768 
50769       -- 4955764
50770       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
50771       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
50772 
50773 
50774       XLA_AE_LINES_PKG.ValidateCurrentLine;
50775       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
50776 
50777       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
50778                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
50779                ,p_balance_type_code => l_balance_type_code);
50780 
50781    END IF;
50782 
50783    -----------------------------------------------------------------------------------------
50784    -- 4262811 Multiperiod Accounting
50785    -----------------------------------------------------------------------------------------
50786      -- No MPA option is assigned.
50787 
50788 
50789 END IF;
50790 END IF;
50791 --
50792 
50793 --
50794 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
50795    trace
50796       (p_msg      => 'END of AcctLineType_98'
50797       ,p_level    => C_LEVEL_PROCEDURE
50798       ,p_module   => l_log_module);
50799 END IF;
50800 --
50801 EXCEPTION
50802   WHEN xla_exceptions_pkg.application_exception THEN
50803       RAISE;
50804   WHEN OTHERS THEN
50805        xla_exceptions_pkg.raise_message
50806            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_98');
50807 END AcctLineType_98;
50808 --
50809 
50810 ---------------------------------------
50811 --
50812 -- PRIVATE FUNCTION
50813 --         AcctLineType_99
50814 --
50815 ---------------------------------------
50816 PROCEDURE AcctLineType_99 (
50817   p_application_id        IN NUMBER
50818  ,p_event_id              IN NUMBER
50819  ,p_calculate_acctd_flag  IN VARCHAR2
50820  ,p_calculate_g_l_flag    IN VARCHAR2
50821  ,p_actual_flag           IN OUT VARCHAR2
50822  ,p_balance_type_code     OUT VARCHAR2
50823  ,p_gain_or_loss_ref      OUT VARCHAR2
50824  
50825 --Distribution GL Account
50826  , p_source_3            IN NUMBER
50827 --Transaction Distribution GL Account
50828  , p_source_4            IN NUMBER
50829 --Distribution Source Type
50830  , p_source_13            IN VARCHAR2
50831 --Distribution Line Identifier
50832  , p_source_15            IN NUMBER
50833 --Distribution Type
50834  , p_source_16            IN VARCHAR2
50835 --Entered Amount
50836  , p_source_17            IN NUMBER
50837 --Currency Code
50838  , p_source_18            IN VARCHAR2
50839 --Applied To Document Accounting Amount
50840  , p_source_22            IN NUMBER
50841 --Transaction Distribution Identifier
50842  , p_source_27            IN NUMBER
50843 --Transaction Distribution Type
50844  , p_source_28            IN VARCHAR2
50845 --Distribution Multi Fund Additional Entry
50846  , p_source_52            IN VARCHAR2
50847 --Applied To Document Exchange Date
50848  , p_source_53            IN DATE
50849 --Receipt Applied To Application Identifier
50850  , p_source_56            IN NUMBER
50851 --Transaction Entity Code
50852  , p_source_57            IN VARCHAR2
50853 --Transaction Identifier
50854  , p_source_58            IN NUMBER
50855 --Distribution Party Identifier
50856  , p_source_62            IN NUMBER
50857 --Distribution Party Site Id
50858  , p_source_63            IN NUMBER
50859 --Distribution Party Type
50860  , p_source_64            IN VARCHAR2
50861 --Applied To Document Exchange Rate Type
50862  , p_source_65            IN VARCHAR2
50863 --Applied To Document Exchange Rate
50864  , p_source_66            IN NUMBER
50865 )
50866 IS
50867 
50868 l_component_type              VARCHAR2(80);
50869 l_component_code              VARCHAR2(30);
50870 l_component_type_code         VARCHAR2(1);
50871 l_component_appl_id           INTEGER;
50872 l_amb_context_code            VARCHAR2(30);
50873 l_entity_code                 VARCHAR2(30);
50874 l_event_class_code            VARCHAR2(30);
50875 l_ae_header_id                NUMBER;
50876 l_event_type_code             VARCHAR2(30);
50877 l_line_definition_code        VARCHAR2(30);
50878 l_line_definition_owner_code  VARCHAR2(1);
50879 --
50880 -- adr variables
50881 l_segment                     VARCHAR2(30);
50882 l_ccid                        NUMBER;
50883 l_adr_transaction_coa_id      NUMBER;
50884 l_adr_accounting_coa_id       NUMBER;
50885 l_adr_flexfield_segment_code  VARCHAR2(30);
50886 l_adr_flex_value_set_id       NUMBER;
50887 l_adr_value_type_code         VARCHAR2(30);
50888 l_adr_value_combination_id    NUMBER;
50889 l_adr_value_segment_code      VARCHAR2(30);
50890 
50891 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
50892 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
50893 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
50894 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
50895 
50896 -- 4262811 Variables ------------------------------------------------------------------------------------------
50897 l_entered_amt_idx             NUMBER;
50898 l_accted_amt_idx              NUMBER;
50899 l_acc_rev_flag                VARCHAR2(1);
50900 l_accrual_line_num            NUMBER;
50901 l_tmp_amt                     NUMBER;
50902 l_acc_rev_natural_side_code   VARCHAR2(1);
50903 
50904 l_num_entries                 NUMBER;
50905 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
50906 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
50907 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
50908 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
50909 l_recog_line_1                NUMBER;
50910 l_recog_line_2                NUMBER;
50911 
50912 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
50913 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
50914 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
50915 
50916 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
50917 
50918 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
50919 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
50920 
50921 ---------------------------------------------------------------------------------------------------------------
50922 
50923 
50924 --
50925 -- bulk performance
50926 --
50927 l_balance_type_code           VARCHAR2(1);
50928 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
50929 l_log_module                  VARCHAR2(240);
50930 
50931 --
50932 -- Upgrade strategy
50933 --
50934 l_actual_upg_option           VARCHAR2(1);
50935 l_enc_upg_option           VARCHAR2(1);
50936 
50937 --
50938 BEGIN
50939 --
50940 IF g_log_enabled THEN
50941       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_99';
50942 END IF;
50943 --
50944 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
50945 
50946       trace
50947          (p_msg      => 'BEGIN of AcctLineType_99'
50948          ,p_level    => C_LEVEL_PROCEDURE
50949          ,p_module   => l_log_module);
50950 
50951 END IF;
50952 --
50953 l_component_type             := 'AMB_JLT';
50954 l_component_code             := 'RCT_UNEDISC';
50955 l_component_type_code        := 'S';
50956 l_component_appl_id          :=  222;
50957 l_amb_context_code           := 'DEFAULT';
50958 l_entity_code                := 'RECEIPTS';
50959 l_event_class_code           := 'RECEIPT';
50960 l_event_type_code            := 'RECEIPT_ALL';
50961 l_line_definition_owner_code := 'S';
50962 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
50963 --
50964 l_balance_type_code          := 'A';
50965 l_segment                     := NULL;
50966 l_ccid                        := NULL;
50967 l_adr_transaction_coa_id      := NULL;
50968 l_adr_accounting_coa_id       := NULL;
50969 l_adr_flexfield_segment_code  := NULL;
50970 l_adr_flex_value_set_id       := NULL;
50971 l_adr_value_type_code         := NULL;
50972 l_adr_value_combination_id    := NULL;
50973 l_adr_value_segment_code      := NULL;
50974 
50975 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
50976 l_bflow_class_code           := '';    -- 4219869 Business Flow
50977 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
50978 l_budgetary_control_flag     := 'N';
50979 
50980 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
50981 l_bflow_applied_to_amt       := NULL; -- 5132302
50982 l_entered_amt_idx            := NULL;          -- 4262811
50983 l_accted_amt_idx             := NULL;          -- 4262811
50984 l_acc_rev_flag               := NULL;          -- 4262811
50985 l_accrual_line_num           := NULL;          -- 4262811
50986 l_tmp_amt                    := NULL;          -- 4262811
50987 --
50988  
50989 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
50990     l_balance_type_code <> 'B' THEN
50991 IF NVL(p_source_13,'
50992 ') =  'UNEDISC' AND 
50993 NVL(p_source_52,'
50994 ') =  'N'
50995  THEN 
50996 
50997    --
50998    XLA_AE_LINES_PKG.SetNewLine;
50999 
51000    p_balance_type_code          := l_balance_type_code;
51001    -- set the flag so later we will know whether the gain loss line needs to be created
51002    
51003    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
51004      p_actual_flag :='A';
51005    END IF;
51006 
51007    --
51008    -- bulk performance
51009    --
51010    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
51011                                       p_header_num   => 0); -- 4262811
51012    --
51013    -- set accounting line options
51014    --
51015    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
51016            p_natural_side_code          => 'C'
51017          , p_gain_or_loss_flag          => 'N'
51018          , p_gl_transfer_mode_code      => 'S'
51019          , p_acct_entry_type_code       => 'A'
51020          , p_switch_side_flag           => 'Y'
51021          , p_merge_duplicate_code       => 'A'
51022          );
51023    --
51024    l_acc_rev_natural_side_code := 'D';  -- 4262811
51025    -- 
51026    --
51027    -- set accounting line type info
51028    --
51029    xla_ae_lines_pkg.SetAcctLineType
51030       (p_component_type             => l_component_type
51031       ,p_event_type_code            => l_event_type_code
51032       ,p_line_definition_owner_code => l_line_definition_owner_code
51033       ,p_line_definition_code       => l_line_definition_code
51034       ,p_accounting_line_code       => l_component_code
51035       ,p_accounting_line_type_code  => l_component_type_code
51036       ,p_accounting_line_appl_id    => l_component_appl_id
51037       ,p_amb_context_code           => l_amb_context_code
51038       ,p_entity_code                => l_entity_code
51039       ,p_event_class_code           => l_event_class_code);
51040    --
51041    -- set accounting class
51042    --
51043    xla_ae_lines_pkg.SetAcctClass(
51044            p_accounting_class_code  => 'UNEDISC'
51045          , p_ae_header_id           => l_ae_header_id
51046          );
51047 
51048    --
51049    -- set rounding class
51050    --
51051    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
51052                       'RECEIVABLE';
51053 
51054    --
51055    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
51056    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
51057    --
51058    -- bulk performance
51059    --
51060    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
51061 
51062    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
51063       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
51064 
51065    -- 4955764
51066    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
51067       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
51068 
51069    -- 4458381 Public Sector Enh
51070    
51071    --
51072    -- set accounting attributes for the line type
51073    --
51074    l_entered_amt_idx := 8;
51075    l_accted_amt_idx  := 13;
51076    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
51077    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
51078    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
51079    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
51080    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
51081    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
51082    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
51083    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
51084    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
51085    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
51086    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
51087    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
51091    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
51088    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
51089    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
51090    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
51092    l_rec_acct_attrs.array_num_value(8)  := p_source_17;
51093    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
51094    l_rec_acct_attrs.array_char_value(9)  := p_source_18;
51095    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
51096    l_rec_acct_attrs.array_date_value(10)  := p_source_53;
51097    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
51098    l_rec_acct_attrs.array_num_value(11)  := p_source_66;
51099    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
51100    l_rec_acct_attrs.array_char_value(12)  := p_source_65;
51101    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
51102    l_rec_acct_attrs.array_num_value(13)  := p_source_22;
51103    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
51104    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
51105    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
51106    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
51107    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
51108    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
51109 
51110    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
51111    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
51112 
51113    ---------------------------------------------------------------------------------------------------------------
51114    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
51115    ---------------------------------------------------------------------------------------------------------------
51116    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
51117 
51118    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
51119    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
51120 
51121    IF xla_accounting_cache_pkg.GetValueChar
51122          (p_source_code         => 'LEDGER_CATEGORY_CODE'
51123          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
51124    AND l_bflow_method_code = 'PRIOR_ENTRY'
51125 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
51126    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
51127          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
51128        )
51129    THEN
51130          xla_ae_lines_pkg.BflowUpgEntry
51131            (p_business_method_code    => l_bflow_method_code
51132            ,p_business_class_code     => l_bflow_class_code
51133            ,p_balance_type            => l_balance_type_code);
51134    ELSE
51135       NULL;
51136 -- No business flow processing for business flow method of NONE.
51137    END IF;
51138 
51139    --
51140    -- call analytical criteria
51141    --
51142    
51143    --
51144    -- call description
51145    --
51146    
51147 xla_ae_lines_pkg.SetLineDescription(
51148    p_ae_header_id => l_ae_header_id
51149   ,p_description  => Description_1 (
51150      p_application_id         => p_application_id
51151    , p_ae_header_id           => l_ae_header_id 
51152    )
51153 );
51154 
51155 
51156    --
51157    -- call ADRs
51158    -- Bug 4922099
51159    --
51160    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
51161         (NVL(l_actual_upg_option, 'N') = 'O') OR
51162         (NVL(l_enc_upg_option, 'N') = 'O')
51163       )
51164    THEN
51165    NULL;
51166    --
51167    --
51168    
51169   l_ccid := AcctDerRule_7(
51170            p_application_id           => p_application_id
51171          , p_ae_header_id             => l_ae_header_id 
51172 , p_source_3 => p_source_3
51173          , x_transaction_coa_id       => l_adr_transaction_coa_id
51174          , x_accounting_coa_id        => l_adr_accounting_coa_id
51175          , x_value_type_code          => l_adr_value_type_code
51176          , p_side                     => 'NA'
51177    );
51178 
51179    xla_ae_lines_pkg.set_ccid(
51180     p_code_combination_id          => l_ccid
51181   , p_value_type_code              => l_adr_value_type_code
51182   , p_transaction_coa_id           => l_adr_transaction_coa_id
51183   , p_accounting_coa_id            => l_adr_accounting_coa_id
51184   , p_adr_code                     => 'DIST_CCID'
51185   , p_adr_type_code                => 'S'
51186   , p_component_type               => l_component_type
51187   , p_component_code               => l_component_code
51188   , p_component_type_code          => l_component_type_code
51189   , p_component_appl_id            => l_component_appl_id
51190   , p_amb_context_code             => l_amb_context_code
51191   , p_side                         => 'NA'
51192   );
51193 
51194 
51195    l_segment := AcctDerRule_5(
51196            p_application_id           => p_application_id
51197          , p_ae_header_id             => l_ae_header_id 
51198 , p_source_4 => p_source_4
51199          , x_transaction_coa_id       => l_adr_transaction_coa_id
51200          , x_accounting_coa_id        => l_adr_accounting_coa_id
51201          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
51202          , x_flex_value_set_id        => l_adr_flex_value_set_id
51203          , x_value_type_code          => l_adr_value_type_code
51204          , x_value_combination_id     => l_adr_value_combination_id
51205          , x_value_segment_code       => l_adr_value_segment_code
51206          , p_side                     => 'NA'
51210    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
51207          , p_override_seg_flag        => 'Y'
51208    );
51209 
51211 
51212       xla_ae_lines_pkg.set_segment(
51213           p_to_segment_code         => 'GL_BALANCING'
51214         , p_segment_value           => l_segment
51215         , p_from_segment_code       => l_adr_value_segment_code
51216         , p_from_combination_id     => l_adr_value_combination_id
51217         , p_value_type_code         => l_adr_value_type_code
51218         , p_transaction_coa_id      => l_adr_transaction_coa_id
51219         , p_accounting_coa_id       => l_adr_accounting_coa_id
51220         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
51221         , p_flex_value_set_id       => l_adr_flex_value_set_id
51222         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
51223         , p_adr_type_code           => 'S'
51224         , p_component_type          => l_component_type
51225         , p_component_code          => l_component_code
51226         , p_component_type_code     => l_component_type_code
51227         , p_component_appl_id       => l_component_appl_id
51228         , p_amb_context_code        => l_amb_context_code
51229         , p_entity_code             => 'RECEIPTS'
51230         , p_event_class_code        => 'RECEIPT'
51231         , p_side                    => 'NA'
51232         );
51233 
51234   END IF;
51235 
51236    --
51237    --
51238    END IF;
51239    --
51240    -- Bug 4922099
51241    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
51242           (NVL(l_enc_upg_option, 'N') = 'O')
51243         ) AND
51244         (l_bflow_method_code = 'PRIOR_ENTRY')
51245       )
51246    THEN
51247       IF
51248       --
51249       1 = 2
51250       --
51251       THEN
51252       xla_accounting_err_pkg.build_message
51253                                     (p_appli_s_name            => 'XLA'
51254                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
51255                                     ,p_token_1                 => 'LINE_NUMBER'
51256                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
51257                                     ,p_token_2                 => 'LINE_TYPE_NAME'
51258                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
51259                                                                              l_component_type
51260                                                                             ,l_component_code
51261                                                                             ,l_component_type_code
51262                                                                             ,l_component_appl_id
51263                                                                             ,l_amb_context_code
51264                                                                             ,l_entity_code
51265                                                                             ,l_event_class_code
51266                                                                            )
51267                                     ,p_token_3                 => 'OWNER'
51268                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
51269                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
51270                                                                           ,p_lookup_code    => l_component_type_code
51271                                                                          )
51272                                     ,p_token_4                 => 'PRODUCT_NAME'
51273                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
51274                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
51275                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
51276                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
51277                                     ,p_ae_header_id            =>  NULL
51278                                        );
51279 
51280         IF (C_LEVEL_ERROR>= g_log_level) THEN
51281                  trace
51282                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
51283                       ,p_level    => C_LEVEL_ERROR
51284                       ,p_module   => l_log_module);
51285         END IF;
51286       END IF;
51287    END IF;
51288    --
51289    --
51290    ------------------------------------------------------------------------------------------------
51291    -- 4219869 Business Flow
51292    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
51293    -- Prior Entry.  Currently, the following code is always generated.
51294    ------------------------------------------------------------------------------------------------
51295    XLA_AE_LINES_PKG.ValidateCurrentLine;
51296 
51297    ------------------------------------------------------------------------------------
51298    -- 4219869 Business Flow
51299    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
51300    ------------------------------------------------------------------------------------
51301    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
51302 
51303    ----------------------------------------------------------------------------------
51304    -- 4219869 Business Flow
51305    -- Update journal entry status -- Need to generate this within IF <condition>
51306    ----------------------------------------------------------------------------------
51307    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
51308          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
51309          ,p_balance_type_code => l_balance_type_code
51310          );
51311 
51312    -------------------------------------------------------------------------------------------
51313    -- 4262811 - Generate the Accrual Reversal lines
51314    -------------------------------------------------------------------------------------------
51315    BEGIN
51316       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
51317                               (g_array_event(p_event_id).array_value_num('header_index'));
51318       IF l_acc_rev_flag IS NULL THEN
51319          l_acc_rev_flag := 'N';
51320       END IF;
51321    EXCEPTION
51322       WHEN OTHERS THEN
51323          l_acc_rev_flag := 'N';
51324    END;
51325    --
51326    IF (l_acc_rev_flag = 'Y') THEN
51327 
51328        -- 4645092  ------------------------------------------------------------------------------
51329        -- To allow MPA report to determine if it should generate report process
51330        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
51331        ------------------------------------------------------------------------------------------
51332 
51333        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
51334        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
51335    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
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    l_segment := AcctDerRule_5(
51375            p_application_id           => p_application_id
51376          , p_ae_header_id             => l_ae_header_id 
51377 , p_source_4 => p_source_4
51378          , x_transaction_coa_id       => l_adr_transaction_coa_id
51379          , x_accounting_coa_id        => l_adr_accounting_coa_id
51380          , x_flexfield_segment_code   => l_adr_flexfield_segment_code
51381          , x_flex_value_set_id        => l_adr_flex_value_set_id
51382          , x_value_type_code          => l_adr_value_type_code
51383          , x_value_combination_id     => l_adr_value_combination_id
51384          , x_value_segment_code       => l_adr_value_segment_code
51385          , p_side                     => 'NA'
51386          , p_override_seg_flag        => 'Y'
51387    );
51388 
51389    IF NVL(l_segment,'NULL') <> '#$NO_OVERRIDE#$' THEN  -- 4465612
51390 
51391       xla_ae_lines_pkg.set_segment(
51392           p_to_segment_code         => 'GL_BALANCING'
51393         , p_segment_value           => l_segment
51394         , p_from_segment_code       => l_adr_value_segment_code
51395         , p_from_combination_id     => l_adr_value_combination_id
51396         , p_value_type_code         => l_adr_value_type_code
51397         , p_transaction_coa_id      => l_adr_transaction_coa_id
51398         , p_accounting_coa_id       => l_adr_accounting_coa_id
51399         , p_flexfield_segment_code  => l_adr_flexfield_segment_code
51400         , p_flex_value_set_id       => l_adr_flex_value_set_id
51401         , p_adr_code                => 'MFAR_TRX_BALANCING_SEGMENT'
51402         , p_adr_type_code           => 'S'
51403         , p_component_type          => l_component_type
51404         , p_component_code          => l_component_code
51405         , p_component_type_code     => l_component_type_code
51406         , p_component_appl_id       => l_component_appl_id
51407         , p_amb_context_code        => l_amb_context_code
51408         , p_entity_code             => 'RECEIPTS'
51409         , p_event_class_code        => 'RECEIPT'
51410         , p_side                    => 'NA'
51411         );
51412 
51413   END IF;
51414 
51415    --
51416    --
51417    END IF;
51418 
51419        --
51420        -- Update the line information that should be overwritten
51421        --
51422        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
51423                                          p_header_num   => 1);
51424        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
51425 
51426        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
51427 
51428        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
51429           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
51430        END IF;
51431 
51432       --
51433       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
51434       --
51435       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
51436           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
51437       ELSE
51438           ---------------------------------------------------------------------------------------------------
51439           -- 4262811a Switch Sign
51440           ---------------------------------------------------------------------------------------------------
51441           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
51442           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
51443                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
51444           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
51445                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
51446           -- 5132302
51447           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
51448                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
51449 
51450       END IF;
51451 
51452       -- 4955764
51453       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
51454       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
51455 
51456 
51457       XLA_AE_LINES_PKG.ValidateCurrentLine;
51458       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
51459 
51460       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
51461                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
51462                ,p_balance_type_code => l_balance_type_code);
51463 
51464    END IF;
51465 
51466    -----------------------------------------------------------------------------------------
51467    -- 4262811 Multiperiod Accounting
51468    -----------------------------------------------------------------------------------------
51469      -- No MPA option is assigned.
51470 
51471 
51472 END IF;
51473 END IF;
51474 --
51475 
51476 --
51477 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
51478    trace
51479       (p_msg      => 'END of AcctLineType_99'
51480       ,p_level    => C_LEVEL_PROCEDURE
51481       ,p_module   => l_log_module);
51482 END IF;
51483 --
51484 EXCEPTION
51485   WHEN xla_exceptions_pkg.application_exception THEN
51486       RAISE;
51487   WHEN OTHERS THEN
51488        xla_exceptions_pkg.raise_message
51489            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_99');
51490 END AcctLineType_99;
51491 --
51492 
51493 ---------------------------------------
51494 --
51495 -- PRIVATE FUNCTION
51496 --         AcctLineType_100
51497 --
51498 ---------------------------------------
51499 PROCEDURE AcctLineType_100 (
51500   p_application_id        IN NUMBER
51501  ,p_event_id              IN NUMBER
51502  ,p_calculate_acctd_flag  IN VARCHAR2
51503  ,p_calculate_g_l_flag    IN VARCHAR2
51504  ,p_actual_flag           IN OUT VARCHAR2
51505  ,p_balance_type_code     OUT VARCHAR2
51506  ,p_gain_or_loss_ref      OUT VARCHAR2
51507  
51508 --Distribution GL Account
51509  , p_source_3            IN NUMBER
51510 --Distribution Source Type
51511  , p_source_13            IN VARCHAR2
51512 --Distribution Line Identifier
51513  , p_source_15            IN NUMBER
51514 --Distribution Type
51515  , p_source_16            IN VARCHAR2
51516 --Exchange Date
51517  , p_source_19            IN DATE
51518 --Exchange Rate
51519  , p_source_20            IN NUMBER
51520 --Exchange Rate Type
51521  , p_source_21            IN VARCHAR2
51522 --Transaction Distribution Identifier
51523  , p_source_27            IN NUMBER
51524 --Transaction Distribution Type
51525  , p_source_28            IN VARCHAR2
51529  , p_source_56            IN NUMBER
51526 --Distribution Multi Fund Additional Entry
51527  , p_source_52            IN VARCHAR2
51528 --Receipt Applied To Application Identifier
51530 --Transaction Entity Code
51531  , p_source_57            IN VARCHAR2
51532 --Transaction Identifier
51533  , p_source_58            IN NUMBER
51534 --DIST_ENT_AMT_FROM
51535  , p_source_59            IN NUMBER
51536 --Applying Document Currency Code
51537  , p_source_60            IN VARCHAR2
51538 --Accounting Amount
51539  , p_source_61            IN NUMBER
51540 --Distribution Party Identifier
51541  , p_source_62            IN NUMBER
51542 --Distribution Party Site Id
51543  , p_source_63            IN NUMBER
51544 --Distribution Party Type
51545  , p_source_64            IN VARCHAR2
51546 )
51547 IS
51548 
51549 l_component_type              VARCHAR2(80);
51550 l_component_code              VARCHAR2(30);
51551 l_component_type_code         VARCHAR2(1);
51552 l_component_appl_id           INTEGER;
51553 l_amb_context_code            VARCHAR2(30);
51554 l_entity_code                 VARCHAR2(30);
51555 l_event_class_code            VARCHAR2(30);
51556 l_ae_header_id                NUMBER;
51557 l_event_type_code             VARCHAR2(30);
51558 l_line_definition_code        VARCHAR2(30);
51559 l_line_definition_owner_code  VARCHAR2(1);
51560 --
51561 -- adr variables
51562 l_segment                     VARCHAR2(30);
51563 l_ccid                        NUMBER;
51564 l_adr_transaction_coa_id      NUMBER;
51565 l_adr_accounting_coa_id       NUMBER;
51566 l_adr_flexfield_segment_code  VARCHAR2(30);
51567 l_adr_flex_value_set_id       NUMBER;
51568 l_adr_value_type_code         VARCHAR2(30);
51569 l_adr_value_combination_id    NUMBER;
51570 l_adr_value_segment_code      VARCHAR2(30);
51571 
51572 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
51573 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
51574 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
51575 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
51576 
51577 -- 4262811 Variables ------------------------------------------------------------------------------------------
51578 l_entered_amt_idx             NUMBER;
51579 l_accted_amt_idx              NUMBER;
51580 l_acc_rev_flag                VARCHAR2(1);
51581 l_accrual_line_num            NUMBER;
51582 l_tmp_amt                     NUMBER;
51583 l_acc_rev_natural_side_code   VARCHAR2(1);
51584 
51585 l_num_entries                 NUMBER;
51586 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
51587 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
51588 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
51589 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
51590 l_recog_line_1                NUMBER;
51591 l_recog_line_2                NUMBER;
51592 
51593 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
51594 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
51595 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
51596 
51597 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
51598 
51602 ---------------------------------------------------------------------------------------------------------------
51599 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
51600 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
51601 
51603 
51604 
51605 --
51606 -- bulk performance
51607 --
51608 l_balance_type_code           VARCHAR2(1);
51609 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
51610 l_log_module                  VARCHAR2(240);
51611 
51612 --
51613 -- Upgrade strategy
51614 --
51615 l_actual_upg_option           VARCHAR2(1);
51616 l_enc_upg_option           VARCHAR2(1);
51617 
51618 --
51619 BEGIN
51620 --
51621 IF g_log_enabled THEN
51622       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_100';
51623 END IF;
51624 --
51625 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
51626 
51627       trace
51628          (p_msg      => 'BEGIN of AcctLineType_100'
51629          ,p_level    => C_LEVEL_PROCEDURE
51630          ,p_module   => l_log_module);
51631 
51632 END IF;
51633 --
51634 l_component_type             := 'AMB_JLT';
51635 l_component_code             := 'RCT_UNID';
51636 l_component_type_code        := 'S';
51637 l_component_appl_id          :=  222;
51638 l_amb_context_code           := 'DEFAULT';
51639 l_entity_code                := 'RECEIPTS';
51640 l_event_class_code           := 'RECEIPT';
51641 l_event_type_code            := 'RECEIPT_ALL';
51642 l_line_definition_owner_code := 'S';
51643 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
51644 --
51645 l_balance_type_code          := 'A';
51646 l_segment                     := NULL;
51647 l_ccid                        := NULL;
51648 l_adr_transaction_coa_id      := NULL;
51649 l_adr_accounting_coa_id       := NULL;
51650 l_adr_flexfield_segment_code  := NULL;
51651 l_adr_flex_value_set_id       := NULL;
51652 l_adr_value_type_code         := NULL;
51653 l_adr_value_combination_id    := NULL;
51654 l_adr_value_segment_code      := NULL;
51655 
51656 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
51657 l_bflow_class_code           := '';    -- 4219869 Business Flow
51658 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
51659 l_budgetary_control_flag     := 'N';
51660 
51661 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
51662 l_bflow_applied_to_amt       := NULL; -- 5132302
51663 l_entered_amt_idx            := NULL;          -- 4262811
51664 l_accted_amt_idx             := NULL;          -- 4262811
51665 l_acc_rev_flag               := NULL;          -- 4262811
51666 l_accrual_line_num           := NULL;          -- 4262811
51667 l_tmp_amt                    := NULL;          -- 4262811
51668 --
51669  
51670 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
51671     l_balance_type_code <> 'B' THEN
51672 IF NVL(p_source_13,'
51673 ') =  'UNID' AND 
51674 NVL(p_source_52,'
51675 ') =  'N'
51676  THEN 
51677 
51678    --
51679    XLA_AE_LINES_PKG.SetNewLine;
51680 
51681    p_balance_type_code          := l_balance_type_code;
51682    -- set the flag so later we will know whether the gain loss line needs to be created
51683    
51684    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
51685      p_actual_flag :='A';
51686    END IF;
51687 
51688    --
51689    -- bulk performance
51690    --
51691    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
51692                                       p_header_num   => 0); -- 4262811
51693    --
51694    -- set accounting line options
51695    --
51696    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
51697            p_natural_side_code          => 'C'
51698          , p_gain_or_loss_flag          => 'N'
51699          , p_gl_transfer_mode_code      => 'S'
51700          , p_acct_entry_type_code       => 'A'
51701          , p_switch_side_flag           => 'Y'
51702          , p_merge_duplicate_code       => 'A'
51703          );
51704    --
51705    l_acc_rev_natural_side_code := 'D';  -- 4262811
51706    -- 
51707    --
51708    -- set accounting line type info
51709    --
51710    xla_ae_lines_pkg.SetAcctLineType
51711       (p_component_type             => l_component_type
51712       ,p_event_type_code            => l_event_type_code
51713       ,p_line_definition_owner_code => l_line_definition_owner_code
51714       ,p_line_definition_code       => l_line_definition_code
51715       ,p_accounting_line_code       => l_component_code
51716       ,p_accounting_line_type_code  => l_component_type_code
51717       ,p_accounting_line_appl_id    => l_component_appl_id
51718       ,p_amb_context_code           => l_amb_context_code
51719       ,p_entity_code                => l_entity_code
51720       ,p_event_class_code           => l_event_class_code);
51721    --
51722    -- set accounting class
51723    --
51724    xla_ae_lines_pkg.SetAcctClass(
51725            p_accounting_class_code  => 'UNID'
51726          , p_ae_header_id           => l_ae_header_id
51727          );
51728 
51729    --
51730    -- set rounding class
51731    --
51732    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
51733                       'RECEIVABLE';
51734 
51735    --
51736    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
51737    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
51738    --
51739    -- bulk performance
51740    --
51744       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
51741    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
51742 
51743    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
51745 
51746    -- 4955764
51747    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
51748       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
51749 
51750    -- 4458381 Public Sector Enh
51751    
51752    --
51753    -- set accounting attributes for the line type
51754    --
51755    l_entered_amt_idx := 8;
51756    l_accted_amt_idx  := 13;
51757    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
51758    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
51759    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
51760    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
51761    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
51762    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
51763    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
51764    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
51765    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
51766    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
51767    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
51768    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
51769    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
51770    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
51771    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
51772    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
51773    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
51774    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
51775    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
51776    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
51777    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
51778    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
51779    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
51780    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
51781    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
51782    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
51783    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
51784    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
51785    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
51786    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
51787    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
51788    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
51789    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
51790 
51791    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
51792    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
51793 
51794    ---------------------------------------------------------------------------------------------------------------
51795    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
51796    ---------------------------------------------------------------------------------------------------------------
51797    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
51798 
51799    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
51800    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
51801 
51802    IF xla_accounting_cache_pkg.GetValueChar
51803          (p_source_code         => 'LEDGER_CATEGORY_CODE'
51804          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
51805    AND l_bflow_method_code = 'PRIOR_ENTRY'
51806 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
51807    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
51808          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
51809        )
51810    THEN
51811          xla_ae_lines_pkg.BflowUpgEntry
51812            (p_business_method_code    => l_bflow_method_code
51813            ,p_business_class_code     => l_bflow_class_code
51814            ,p_balance_type            => l_balance_type_code);
51815    ELSE
51816       NULL;
51817 -- No business flow processing for business flow method of NONE.
51818    END IF;
51819 
51820    --
51821    -- call analytical criteria
51822    --
51823    
51824    --
51825    -- call description
51826    --
51827    -- No description or it is inherited.
51828    --
51829    -- call ADRs
51830    -- Bug 4922099
51831    --
51832    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
51833         (NVL(l_actual_upg_option, 'N') = 'O') OR
51834         (NVL(l_enc_upg_option, 'N') = 'O')
51835       )
51836    THEN
51837    NULL;
51838    --
51839    --
51840    
51841   l_ccid := AcctDerRule_7(
51842            p_application_id           => p_application_id
51843          , p_ae_header_id             => l_ae_header_id 
51844 , p_source_3 => p_source_3
51845          , x_transaction_coa_id       => l_adr_transaction_coa_id
51846          , x_accounting_coa_id        => l_adr_accounting_coa_id
51847          , x_value_type_code          => l_adr_value_type_code
51848          , p_side                     => 'NA'
51849    );
51850 
51851    xla_ae_lines_pkg.set_ccid(
51852     p_code_combination_id          => l_ccid
51853   , p_value_type_code              => l_adr_value_type_code
51854   , p_transaction_coa_id           => l_adr_transaction_coa_id
51858   , p_component_type               => l_component_type
51855   , p_accounting_coa_id            => l_adr_accounting_coa_id
51856   , p_adr_code                     => 'DIST_CCID'
51857   , p_adr_type_code                => 'S'
51859   , p_component_code               => l_component_code
51860   , p_component_type_code          => l_component_type_code
51861   , p_component_appl_id            => l_component_appl_id
51862   , p_amb_context_code             => l_amb_context_code
51863   , p_side                         => 'NA'
51864   );
51865 
51866 
51867    --
51868    --
51869    END IF;
51870    --
51871    -- Bug 4922099
51872    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
51873           (NVL(l_enc_upg_option, 'N') = 'O')
51874         ) AND
51875         (l_bflow_method_code = 'PRIOR_ENTRY')
51876       )
51877    THEN
51878       IF
51879       --
51880       1 = 2
51881       --
51882       THEN
51883       xla_accounting_err_pkg.build_message
51884                                     (p_appli_s_name            => 'XLA'
51885                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
51886                                     ,p_token_1                 => 'LINE_NUMBER'
51887                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
51888                                     ,p_token_2                 => 'LINE_TYPE_NAME'
51889                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
51890                                                                              l_component_type
51891                                                                             ,l_component_code
51892                                                                             ,l_component_type_code
51893                                                                             ,l_component_appl_id
51894                                                                             ,l_amb_context_code
51895                                                                             ,l_entity_code
51896                                                                             ,l_event_class_code
51897                                                                            )
51898                                     ,p_token_3                 => 'OWNER'
51899                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
51900                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
51901                                                                           ,p_lookup_code    => l_component_type_code
51902                                                                          )
51903                                     ,p_token_4                 => 'PRODUCT_NAME'
51904                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
51905                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
51906                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
51907                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
51908                                     ,p_ae_header_id            =>  NULL
51909                                        );
51910 
51911         IF (C_LEVEL_ERROR>= g_log_level) THEN
51912                  trace
51913                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
51914                       ,p_level    => C_LEVEL_ERROR
51915                       ,p_module   => l_log_module);
51916         END IF;
51917       END IF;
51918    END IF;
51919    --
51920    --
51921    ------------------------------------------------------------------------------------------------
51922    -- 4219869 Business Flow
51923    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
51924    -- Prior Entry.  Currently, the following code is always generated.
51925    ------------------------------------------------------------------------------------------------
51926    XLA_AE_LINES_PKG.ValidateCurrentLine;
51927 
51928    ------------------------------------------------------------------------------------
51929    -- 4219869 Business Flow
51930    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
51931    ------------------------------------------------------------------------------------
51932    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
51933 
51934    ----------------------------------------------------------------------------------
51935    -- 4219869 Business Flow
51936    -- Update journal entry status -- Need to generate this within IF <condition>
51937    ----------------------------------------------------------------------------------
51938    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
51939          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
51940          ,p_balance_type_code => l_balance_type_code
51941          );
51942 
51943    -------------------------------------------------------------------------------------------
51944    -- 4262811 - Generate the Accrual Reversal lines
51945    -------------------------------------------------------------------------------------------
51946    BEGIN
51947       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
51948                               (g_array_event(p_event_id).array_value_num('header_index'));
51949       IF l_acc_rev_flag IS NULL THEN
51950          l_acc_rev_flag := 'N';
51951       END IF;
51952    EXCEPTION
51953       WHEN OTHERS THEN
51954          l_acc_rev_flag := 'N';
51958 
51955    END;
51956    --
51957    IF (l_acc_rev_flag = 'Y') THEN
51959        -- 4645092  ------------------------------------------------------------------------------
51960        -- To allow MPA report to determine if it should generate report process
51961        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
51962        ------------------------------------------------------------------------------------------
51963 
51964        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
51965        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
51966    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
51967    -- call ADRs
51968    -- Bug 4922099
51969    --
51970    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
51971         (NVL(l_actual_upg_option, 'N') = 'O') OR
51972         (NVL(l_enc_upg_option, 'N') = 'O')
51973       )
51974    THEN
51975    NULL;
51976    --
51977    --
51978    
51979   l_ccid := AcctDerRule_7(
51980            p_application_id           => p_application_id
51981          , p_ae_header_id             => l_ae_header_id 
51982 , p_source_3 => p_source_3
51983          , x_transaction_coa_id       => l_adr_transaction_coa_id
51984          , x_accounting_coa_id        => l_adr_accounting_coa_id
51985          , x_value_type_code          => l_adr_value_type_code
51986          , p_side                     => 'NA'
51987    );
51988 
51989    xla_ae_lines_pkg.set_ccid(
51990     p_code_combination_id          => l_ccid
51991   , p_value_type_code              => l_adr_value_type_code
51992   , p_transaction_coa_id           => l_adr_transaction_coa_id
51993   , p_accounting_coa_id            => l_adr_accounting_coa_id
51994   , p_adr_code                     => 'DIST_CCID'
51995   , p_adr_type_code                => 'S'
51996   , p_component_type               => l_component_type
51997   , p_component_code               => l_component_code
51998   , p_component_type_code          => l_component_type_code
51999   , p_component_appl_id            => l_component_appl_id
52000   , p_amb_context_code             => l_amb_context_code
52001   , p_side                         => 'NA'
52002   );
52003 
52004 
52005    --
52006    --
52007    END IF;
52008 
52009        --
52010        -- Update the line information that should be overwritten
52011        --
52012        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
52013                                          p_header_num   => 1);
52014        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
52015 
52016        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
52017 
52018        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
52019           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
52020        END IF;
52021 
52022       --
52023       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
52024       --
52025       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
52026           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
52027       ELSE
52028           ---------------------------------------------------------------------------------------------------
52029           -- 4262811a Switch Sign
52030           ---------------------------------------------------------------------------------------------------
52031           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
52032           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
52033                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
52034           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
52035                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
52036           -- 5132302
52037           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
52038                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
52039 
52040       END IF;
52041 
52042       -- 4955764
52043       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
52044       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
52045 
52046 
52047       XLA_AE_LINES_PKG.ValidateCurrentLine;
52048       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
52049 
52050       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
52051                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
52052                ,p_balance_type_code => l_balance_type_code);
52053 
52054    END IF;
52055 
52056    -----------------------------------------------------------------------------------------
52057    -- 4262811 Multiperiod Accounting
52058    -----------------------------------------------------------------------------------------
52059      -- No MPA option is assigned.
52060 
52061 
52062 END IF;
52063 END IF;
52064 --
52065 
52066 --
52067 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
52068    trace
52069       (p_msg      => 'END of AcctLineType_100'
52070       ,p_level    => C_LEVEL_PROCEDURE
52071       ,p_module   => l_log_module);
52072 END IF;
52073 --
52074 EXCEPTION
52075   WHEN xla_exceptions_pkg.application_exception THEN
52076       RAISE;
52077   WHEN OTHERS THEN
52078        xla_exceptions_pkg.raise_message
52082 
52079            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_100');
52080 END AcctLineType_100;
52081 --
52083 ---------------------------------------
52084 --
52085 -- PRIVATE FUNCTION
52086 --         AcctLineType_101
52087 --
52088 ---------------------------------------
52089 PROCEDURE AcctLineType_101 (
52090   p_application_id        IN NUMBER
52091  ,p_event_id              IN NUMBER
52092  ,p_calculate_acctd_flag  IN VARCHAR2
52093  ,p_calculate_g_l_flag    IN VARCHAR2
52094  ,p_actual_flag           IN OUT VARCHAR2
52095  ,p_balance_type_code     OUT VARCHAR2
52096  ,p_gain_or_loss_ref      OUT VARCHAR2
52097  
52098 --Distribution GL Account
52099  , p_source_3            IN NUMBER
52100 --Distribution Source Type
52101  , p_source_13            IN VARCHAR2
52102 --Receivable Activity Type
52103  , p_source_14            IN VARCHAR2
52104 --Distribution Line Identifier
52105  , p_source_15            IN NUMBER
52106 --Distribution Type
52107  , p_source_16            IN VARCHAR2
52108 --Exchange Date
52109  , p_source_19            IN DATE
52110 --Exchange Rate
52111  , p_source_20            IN NUMBER
52112 --Exchange Rate Type
52113  , p_source_21            IN VARCHAR2
52114 --Transaction Distribution Identifier
52115  , p_source_27            IN NUMBER
52116 --Transaction Distribution Type
52117  , p_source_28            IN VARCHAR2
52118 --Distribution Multi Fund Additional Entry
52119  , p_source_52            IN VARCHAR2
52120 --Receipt Applied To Application Identifier
52121  , p_source_56            IN NUMBER
52122 --Transaction Entity Code
52123  , p_source_57            IN VARCHAR2
52124 --Transaction Identifier
52125  , p_source_58            IN NUMBER
52126 --DIST_ENT_AMT_FROM
52127  , p_source_59            IN NUMBER
52128 --Applying Document Currency Code
52129  , p_source_60            IN VARCHAR2
52130 --Accounting Amount
52131  , p_source_61            IN NUMBER
52132 --Distribution Party Identifier
52133  , p_source_62            IN NUMBER
52134 --Distribution Party Site Id
52135  , p_source_63            IN NUMBER
52136 --Distribution Party Type
52137  , p_source_64            IN VARCHAR2
52138 )
52139 IS
52140 
52141 l_component_type              VARCHAR2(80);
52142 l_component_code              VARCHAR2(30);
52143 l_component_type_code         VARCHAR2(1);
52144 l_component_appl_id           INTEGER;
52145 l_amb_context_code            VARCHAR2(30);
52146 l_entity_code                 VARCHAR2(30);
52147 l_event_class_code            VARCHAR2(30);
52148 l_ae_header_id                NUMBER;
52149 l_event_type_code             VARCHAR2(30);
52150 l_line_definition_code        VARCHAR2(30);
52151 l_line_definition_owner_code  VARCHAR2(1);
52152 --
52153 -- adr variables
52154 l_segment                     VARCHAR2(30);
52155 l_ccid                        NUMBER;
52156 l_adr_transaction_coa_id      NUMBER;
52157 l_adr_accounting_coa_id       NUMBER;
52158 l_adr_flexfield_segment_code  VARCHAR2(30);
52159 l_adr_flex_value_set_id       NUMBER;
52160 l_adr_value_type_code         VARCHAR2(30);
52161 l_adr_value_combination_id    NUMBER;
52162 l_adr_value_segment_code      VARCHAR2(30);
52163 
52164 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
52165 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
52166 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
52167 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
52168 
52169 -- 4262811 Variables ------------------------------------------------------------------------------------------
52170 l_entered_amt_idx             NUMBER;
52171 l_accted_amt_idx              NUMBER;
52172 l_acc_rev_flag                VARCHAR2(1);
52173 l_accrual_line_num            NUMBER;
52174 l_tmp_amt                     NUMBER;
52175 l_acc_rev_natural_side_code   VARCHAR2(1);
52176 
52177 l_num_entries                 NUMBER;
52178 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
52179 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
52180 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
52181 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
52182 l_recog_line_1                NUMBER;
52183 l_recog_line_2                NUMBER;
52184 
52185 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
52186 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
52187 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
52188 
52189 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
52190 
52191 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
52192 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
52193 
52194 ---------------------------------------------------------------------------------------------------------------
52195 
52196 
52197 --
52198 -- bulk performance
52199 --
52200 l_balance_type_code           VARCHAR2(1);
52201 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
52202 l_log_module                  VARCHAR2(240);
52203 
52204 --
52205 -- Upgrade strategy
52206 --
52207 l_actual_upg_option           VARCHAR2(1);
52208 l_enc_upg_option           VARCHAR2(1);
52209 
52210 --
52211 BEGIN
52212 --
52213 IF g_log_enabled THEN
52214       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_101';
52215 END IF;
52216 --
52217 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
52218 
52219       trace
52223 
52220          (p_msg      => 'BEGIN of AcctLineType_101'
52221          ,p_level    => C_LEVEL_PROCEDURE
52222          ,p_module   => l_log_module);
52224 END IF;
52225 --
52226 l_component_type             := 'AMB_JLT';
52227 l_component_code             := 'RCT_WRITEOFF';
52228 l_component_type_code        := 'S';
52229 l_component_appl_id          :=  222;
52230 l_amb_context_code           := 'DEFAULT';
52231 l_entity_code                := 'RECEIPTS';
52232 l_event_class_code           := 'RECEIPT';
52233 l_event_type_code            := 'RECEIPT_ALL';
52234 l_line_definition_owner_code := 'S';
52235 l_line_definition_code       := 'MFAR_RCT_ACCRUAL_BALANCING';
52236 --
52237 l_balance_type_code          := 'A';
52238 l_segment                     := NULL;
52239 l_ccid                        := NULL;
52240 l_adr_transaction_coa_id      := NULL;
52241 l_adr_accounting_coa_id       := NULL;
52242 l_adr_flexfield_segment_code  := NULL;
52243 l_adr_flex_value_set_id       := NULL;
52244 l_adr_value_type_code         := NULL;
52245 l_adr_value_combination_id    := NULL;
52246 l_adr_value_segment_code      := NULL;
52247 
52248 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
52249 l_bflow_class_code           := '';    -- 4219869 Business Flow
52250 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
52251 l_budgetary_control_flag     := 'N';
52252 
52253 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
52254 l_bflow_applied_to_amt       := NULL; -- 5132302
52255 l_entered_amt_idx            := NULL;          -- 4262811
52256 l_accted_amt_idx             := NULL;          -- 4262811
52257 l_acc_rev_flag               := NULL;          -- 4262811
52258 l_accrual_line_num           := NULL;          -- 4262811
52259 l_tmp_amt                    := NULL;          -- 4262811
52260 --
52261  
52262 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
52263     l_balance_type_code <> 'B' THEN
52264 IF NVL(p_source_13,'
52265 ') =  'ACTIVITY' AND 
52266 NVL(p_source_14,'
52267 ') =  'WRITEOFF' AND 
52268 NVL(p_source_52,'
52269 ') =  'N'
52270  THEN 
52271 
52272    --
52273    XLA_AE_LINES_PKG.SetNewLine;
52274 
52275    p_balance_type_code          := l_balance_type_code;
52276    -- set the flag so later we will know whether the gain loss line needs to be created
52277    
52278    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
52279      p_actual_flag :='A';
52280    END IF;
52281 
52282    --
52283    -- bulk performance
52284    --
52285    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
52286                                       p_header_num   => 0); -- 4262811
52287    --
52288    -- set accounting line options
52289    --
52290    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
52291            p_natural_side_code          => 'C'
52292          , p_gain_or_loss_flag          => 'N'
52293          , p_gl_transfer_mode_code      => 'S'
52294          , p_acct_entry_type_code       => 'A'
52295          , p_switch_side_flag           => 'Y'
52296          , p_merge_duplicate_code       => 'A'
52297          );
52298    --
52299    l_acc_rev_natural_side_code := 'D';  -- 4262811
52300    -- 
52301    --
52302    -- set accounting line type info
52303    --
52304    xla_ae_lines_pkg.SetAcctLineType
52305       (p_component_type             => l_component_type
52306       ,p_event_type_code            => l_event_type_code
52307       ,p_line_definition_owner_code => l_line_definition_owner_code
52308       ,p_line_definition_code       => l_line_definition_code
52312       ,p_amb_context_code           => l_amb_context_code
52309       ,p_accounting_line_code       => l_component_code
52310       ,p_accounting_line_type_code  => l_component_type_code
52311       ,p_accounting_line_appl_id    => l_component_appl_id
52313       ,p_entity_code                => l_entity_code
52314       ,p_event_class_code           => l_event_class_code);
52315    --
52316    -- set accounting class
52317    --
52318    xla_ae_lines_pkg.SetAcctClass(
52319            p_accounting_class_code  => 'WRITE_OFF'
52320          , p_ae_header_id           => l_ae_header_id
52321          );
52322 
52323    --
52324    -- set rounding class
52325    --
52326    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
52327                       'RECEIVABLE';
52328 
52329    --
52330    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
52331    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
52332    --
52333    -- bulk performance
52334    --
52335    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
52336 
52337    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
52338       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
52339 
52340    -- 4955764
52341    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
52342       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
52343 
52344    -- 4458381 Public Sector Enh
52345    
52346    --
52347    -- set accounting attributes for the line type
52348    --
52349    l_entered_amt_idx := 8;
52350    l_accted_amt_idx  := 13;
52351    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
52352    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
52353    l_rec_acct_attrs.array_num_value(1)  := p_source_56;
52354    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
52355    l_rec_acct_attrs.array_char_value(2)  := p_source_28;
52356    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
52357    l_rec_acct_attrs.array_char_value(3)  := p_source_57;
52358    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
52359    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_27);
52360    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
52361    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_58);
52362    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
52363    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_15);
52364    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
52365    l_rec_acct_attrs.array_char_value(7)  := p_source_16;
52366    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
52367    l_rec_acct_attrs.array_num_value(8)  := p_source_59;
52368    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
52369    l_rec_acct_attrs.array_char_value(9)  := p_source_60;
52370    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
52371    l_rec_acct_attrs.array_date_value(10)  := p_source_19;
52372    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
52373    l_rec_acct_attrs.array_num_value(11)  := p_source_20;
52374    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
52375    l_rec_acct_attrs.array_char_value(12)  := p_source_21;
52376    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
52377    l_rec_acct_attrs.array_num_value(13)  := p_source_61;
52378    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
52379    l_rec_acct_attrs.array_num_value(14)  := p_source_62;
52380    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
52381    l_rec_acct_attrs.array_num_value(15)  := p_source_63;
52382    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
52383    l_rec_acct_attrs.array_char_value(16)  := p_source_64;
52384 
52385    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
52386    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
52387 
52388    ---------------------------------------------------------------------------------------------------------------
52389    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
52390    ---------------------------------------------------------------------------------------------------------------
52391    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
52392 
52393    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
52394    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
52395 
52396    IF xla_accounting_cache_pkg.GetValueChar
52397          (p_source_code         => 'LEDGER_CATEGORY_CODE'
52398          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
52399    AND l_bflow_method_code = 'PRIOR_ENTRY'
52400 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
52401    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
52402          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
52403        )
52404    THEN
52405          xla_ae_lines_pkg.BflowUpgEntry
52406            (p_business_method_code    => l_bflow_method_code
52407            ,p_business_class_code     => l_bflow_class_code
52411 -- No business flow processing for business flow method of NONE.
52408            ,p_balance_type            => l_balance_type_code);
52409    ELSE
52410       NULL;
52412    END IF;
52413 
52414    --
52415    -- call analytical criteria
52416    --
52417    
52418    --
52419    -- call description
52420    --
52421    -- No description or it is inherited.
52422    --
52423    -- call ADRs
52424    -- Bug 4922099
52425    --
52426    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
52427         (NVL(l_actual_upg_option, 'N') = 'O') OR
52428         (NVL(l_enc_upg_option, 'N') = 'O')
52429       )
52430    THEN
52431    NULL;
52432    --
52433    --
52434    
52435   l_ccid := AcctDerRule_7(
52436            p_application_id           => p_application_id
52437          , p_ae_header_id             => l_ae_header_id 
52438 , p_source_3 => p_source_3
52439          , x_transaction_coa_id       => l_adr_transaction_coa_id
52440          , x_accounting_coa_id        => l_adr_accounting_coa_id
52441          , x_value_type_code          => l_adr_value_type_code
52442          , p_side                     => 'NA'
52443    );
52444 
52445    xla_ae_lines_pkg.set_ccid(
52446     p_code_combination_id          => l_ccid
52447   , p_value_type_code              => l_adr_value_type_code
52448   , p_transaction_coa_id           => l_adr_transaction_coa_id
52449   , p_accounting_coa_id            => l_adr_accounting_coa_id
52450   , p_adr_code                     => 'DIST_CCID'
52451   , p_adr_type_code                => 'S'
52452   , p_component_type               => l_component_type
52453   , p_component_code               => l_component_code
52454   , p_component_type_code          => l_component_type_code
52455   , p_component_appl_id            => l_component_appl_id
52456   , p_amb_context_code             => l_amb_context_code
52457   , p_side                         => 'NA'
52458   );
52459 
52460 
52461    --
52462    --
52463    END IF;
52464    --
52465    -- Bug 4922099
52466    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
52467           (NVL(l_enc_upg_option, 'N') = 'O')
52468         ) AND
52469         (l_bflow_method_code = 'PRIOR_ENTRY')
52470       )
52471    THEN
52472       IF
52473       --
52474       1 = 2
52475       --
52476       THEN
52477       xla_accounting_err_pkg.build_message
52478                                     (p_appli_s_name            => 'XLA'
52479                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
52480                                     ,p_token_1                 => 'LINE_NUMBER'
52481                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
52482                                     ,p_token_2                 => 'LINE_TYPE_NAME'
52483                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
52484                                                                              l_component_type
52485                                                                             ,l_component_code
52486                                                                             ,l_component_type_code
52487                                                                             ,l_component_appl_id
52488                                                                             ,l_amb_context_code
52489                                                                             ,l_entity_code
52490                                                                             ,l_event_class_code
52491                                                                            )
52492                                     ,p_token_3                 => 'OWNER'
52493                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
52494                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
52495                                                                           ,p_lookup_code    => l_component_type_code
52496                                                                          )
52497                                     ,p_token_4                 => 'PRODUCT_NAME'
52498                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
52499                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
52500                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
52501                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
52502                                     ,p_ae_header_id            =>  NULL
52503                                        );
52504 
52505         IF (C_LEVEL_ERROR>= g_log_level) THEN
52506                  trace
52507                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
52508                       ,p_level    => C_LEVEL_ERROR
52509                       ,p_module   => l_log_module);
52510         END IF;
52511       END IF;
52512    END IF;
52513    --
52514    --
52515    ------------------------------------------------------------------------------------------------
52516    -- 4219869 Business Flow
52517    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
52518    -- Prior Entry.  Currently, the following code is always generated.
52519    ------------------------------------------------------------------------------------------------
52520    XLA_AE_LINES_PKG.ValidateCurrentLine;
52521 
52522    ------------------------------------------------------------------------------------
52523    -- 4219869 Business Flow
52524    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
52528    ----------------------------------------------------------------------------------
52525    ------------------------------------------------------------------------------------
52526    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
52527 
52529    -- 4219869 Business Flow
52530    -- Update journal entry status -- Need to generate this within IF <condition>
52531    ----------------------------------------------------------------------------------
52532    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
52533          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
52534          ,p_balance_type_code => l_balance_type_code
52535          );
52536 
52537    -------------------------------------------------------------------------------------------
52538    -- 4262811 - Generate the Accrual Reversal lines
52539    -------------------------------------------------------------------------------------------
52540    BEGIN
52541       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
52542                               (g_array_event(p_event_id).array_value_num('header_index'));
52543       IF l_acc_rev_flag IS NULL THEN
52544          l_acc_rev_flag := 'N';
52545       END IF;
52546    EXCEPTION
52547       WHEN OTHERS THEN
52548          l_acc_rev_flag := 'N';
52549    END;
52550    --
52551    IF (l_acc_rev_flag = 'Y') THEN
52552 
52553        -- 4645092  ------------------------------------------------------------------------------
52554        -- To allow MPA report to determine if it should generate report process
52555        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
52556        ------------------------------------------------------------------------------------------
52557 
52558        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
52559        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
52560    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
52561    -- call ADRs
52562    -- Bug 4922099
52563    --
52564    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
52565         (NVL(l_actual_upg_option, 'N') = 'O') OR
52566         (NVL(l_enc_upg_option, 'N') = 'O')
52567       )
52568    THEN
52569    NULL;
52570    --
52571    --
52572    
52573   l_ccid := AcctDerRule_7(
52574            p_application_id           => p_application_id
52575          , p_ae_header_id             => l_ae_header_id 
52576 , p_source_3 => p_source_3
52577          , x_transaction_coa_id       => l_adr_transaction_coa_id
52578          , x_accounting_coa_id        => l_adr_accounting_coa_id
52579          , x_value_type_code          => l_adr_value_type_code
52580          , p_side                     => 'NA'
52581    );
52582 
52583    xla_ae_lines_pkg.set_ccid(
52584     p_code_combination_id          => l_ccid
52585   , p_value_type_code              => l_adr_value_type_code
52586   , p_transaction_coa_id           => l_adr_transaction_coa_id
52587   , p_accounting_coa_id            => l_adr_accounting_coa_id
52588   , p_adr_code                     => 'DIST_CCID'
52589   , p_adr_type_code                => 'S'
52590   , p_component_type               => l_component_type
52591   , p_component_code               => l_component_code
52592   , p_component_type_code          => l_component_type_code
52593   , p_component_appl_id            => l_component_appl_id
52594   , p_amb_context_code             => l_amb_context_code
52595   , p_side                         => 'NA'
52596   );
52597 
52598 
52599    --
52600    --
52601    END IF;
52602 
52603        --
52604        -- Update the line information that should be overwritten
52605        --
52606        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
52607                                          p_header_num   => 1);
52608        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
52609 
52610        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
52611 
52612        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
52613           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
52614        END IF;
52615 
52616       --
52617       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
52618       --
52619       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
52623           -- 4262811a Switch Sign
52620           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
52621       ELSE
52622           ---------------------------------------------------------------------------------------------------
52624           ---------------------------------------------------------------------------------------------------
52625           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
52626           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
52627                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
52628           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
52629                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
52630           -- 5132302
52631           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
52632                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
52633 
52634       END IF;
52635 
52636       -- 4955764
52637       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
52638       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
52639 
52640 
52641       XLA_AE_LINES_PKG.ValidateCurrentLine;
52642       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
52643 
52644       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
52645                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
52646                ,p_balance_type_code => l_balance_type_code);
52647 
52648    END IF;
52649 
52650    -----------------------------------------------------------------------------------------
52651    -- 4262811 Multiperiod Accounting
52652    -----------------------------------------------------------------------------------------
52653      -- No MPA option is assigned.
52654 
52655 
52656 END IF;
52657 END IF;
52658 --
52659 
52660 --
52661 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
52662    trace
52663       (p_msg      => 'END of AcctLineType_101'
52664       ,p_level    => C_LEVEL_PROCEDURE
52665       ,p_module   => l_log_module);
52666 END IF;
52667 --
52668 EXCEPTION
52669   WHEN xla_exceptions_pkg.application_exception THEN
52670       RAISE;
52671   WHEN OTHERS THEN
52672        xla_exceptions_pkg.raise_message
52673            (p_location => 'XLA_00222_AAD_S_000008_PKG.AcctLineType_101');
52674 END AcctLineType_101;
52675 --
52676 
52677 ---------------------------------------
52678 --
52679 -- PRIVATE PROCEDURE
52680 --         insert_sources_102
52681 --
52682 ----------------------------------------
52683 --
52684 PROCEDURE insert_sources_102(
52685                                 p_target_ledger_id       IN NUMBER
52686                               , p_language               IN VARCHAR2
52687                               , p_sla_ledger_id          IN NUMBER
52688                               , p_pad_start_date         IN DATE
52689                               , p_pad_end_date           IN DATE
52690                          )
52691 IS
52692 
52693 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'ADJUSTMENT_ALL';
52694 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'ADJUSTMENT';
52695 p_apps_owner                   VARCHAR2(30);
52696 l_log_module                   VARCHAR2(240);
52697 BEGIN
52698 IF g_log_enabled THEN
52699       l_log_module := C_DEFAULT_MODULE||'.insert_sources_102';
52700 END IF;
52701 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
52702 
52703       trace
52704          (p_msg      => 'BEGIN of insert_sources_102'
52705          ,p_level    => C_LEVEL_PROCEDURE
52706          ,p_module   => l_log_module);
52707 
52708 END IF;
52709 
52710 -- select APPS owner
52711 SELECT oracle_username
52712   INTO p_apps_owner
52713   FROM fnd_oracle_userid
52714  WHERE read_only_flag = 'U'
52715 ;
52716 
52717 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
52718       trace
52719          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
52720                         ' - p_language = '||p_language||
52721                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
52722                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
52723                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
52724                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
52725          ,p_level    => C_LEVEL_STATEMENT
52726          ,p_module   => l_log_module);
52727 END IF;
52728 
52729 
52730 --
52731 INSERT INTO xla_diag_sources --hdr2
52732 (
52733         event_id
52734       , ledger_id
52735       , sla_ledger_id
52736       , description_language
52737       , object_name
52738       , object_type_code
52739       , line_number
52740       , source_application_id
52741       , source_type_code
52742       , source_code
52743       , source_value
52744       , source_meaning
52745       , created_by
52746       , creation_date
52747       , last_update_date
52748       , last_updated_by
52749       , last_update_login
52750       , program_update_date
52751       , program_application_id
52752       , program_id
52753       , request_id
52754 )
52755 SELECT
52759       , p_language
52756         event_id
52757       , p_target_ledger_id
52758       , p_sla_ledger_id
52760       , object_name
52761       , object_type_code
52762       , line_number
52763       , source_application_id
52764       , source_type_code
52765       , source_code
52766       , SUBSTR(source_value ,1,1996)
52767       , SUBSTR(source_meaning ,1,200)
52768       , xla_environment_pkg.g_Usr_Id
52769       , TRUNC(SYSDATE)
52770       , TRUNC(SYSDATE)
52771       , xla_environment_pkg.g_Usr_Id
52772       , xla_environment_pkg.g_Login_Id
52773       , TRUNC(SYSDATE)
52774       , xla_environment_pkg.g_Prog_Appl_Id
52775       , xla_environment_pkg.g_Prog_Id
52776       , xla_environment_pkg.g_Req_Id
52777   FROM (
52778        SELECT xet.event_id                  event_id
52779             , 0                          line_number
52780             , CASE r
52781                WHEN 1 THEN 'AR_TRANSACTIONS_S_V' 
52782                 WHEN 2 THEN 'AR_RECEIVABLES_TRX_ACT_S_V' 
52783                 WHEN 3 THEN 'AR_BILL_TO_CUSTOMERS_S_V' 
52784                 WHEN 4 THEN 'AR_BILL_TO_SITE_USES_S_V' 
52785                 WHEN 5 THEN 'AR_TRANSACTIONS_S_V' 
52786                 WHEN 6 THEN 'AR_ADJUSTMENTS_H_V' 
52787                 WHEN 7 THEN 'AR_ADJUSTMENTS_H_V' 
52788                 WHEN 8 THEN 'AR_ADJUSTMENTS_H_V' 
52789                 
52790                ELSE null
52791               END                           object_name
52792             , CASE r
52793                 WHEN 1 THEN 'HEADER' 
52794                 WHEN 2 THEN 'HEADER' 
52795                 WHEN 3 THEN 'HEADER' 
52796                 WHEN 4 THEN 'HEADER' 
52797                 WHEN 5 THEN 'HEADER' 
52798                 WHEN 6 THEN 'HEADER' 
52799                 WHEN 7 THEN 'HEADER' 
52800                 WHEN 8 THEN 'HEADER' 
52801                 
52802                 ELSE null
52803               END                           object_type_code
52804             , CASE r
52805                 WHEN 1 THEN '222' 
52806                 WHEN 2 THEN '222' 
52807                 WHEN 3 THEN '222' 
52808                 WHEN 4 THEN '222' 
52809                 WHEN 5 THEN '222' 
52810                 WHEN 6 THEN '222' 
52811                 WHEN 7 THEN '222' 
52812                 WHEN 8 THEN '222' 
52813                 
52814                 ELSE null
52815               END                           source_application_id
52816             , 'S'             source_type_code
52817             , CASE r
52818                 WHEN 1 THEN 'TRX_RECEIVABLE_CCID' 
52819                 WHEN 2 THEN 'REC_ACT_TYPE' 
52820                 WHEN 3 THEN 'BILL_CUST_ACCOUNT_ID' 
52821                 WHEN 4 THEN 'BILL_USES_SITE_USE_ID' 
52822                 WHEN 5 THEN 'XLA_PARTY_TYPE' 
52823                 WHEN 6 THEN 'ADJ_DOC_SEQUENCE_CATEGORY' 
52824                 WHEN 7 THEN 'ADJ_DOC_SEQUENCE_ID' 
52825                 WHEN 8 THEN 'ADJ_DOC_SEQUENCE_VALUE' 
52826                 
52827                 ELSE null
52828               END                           source_code
52829             , CASE r
52830                 WHEN 1 THEN TO_CHAR(h7.TRX_RECEIVABLE_CCID)
52831                 WHEN 2 THEN TO_CHAR(h6.REC_ACT_TYPE)
52832                 WHEN 3 THEN TO_CHAR(h2.BILL_CUST_ACCOUNT_ID)
52833                 WHEN 4 THEN TO_CHAR(h3.BILL_USES_SITE_USE_ID)
52834                 WHEN 5 THEN TO_CHAR(h7.XLA_PARTY_TYPE)
52835                 WHEN 6 THEN TO_CHAR(h1.ADJ_DOC_SEQUENCE_CATEGORY)
52836                 WHEN 7 THEN TO_CHAR(h1.ADJ_DOC_SEQUENCE_ID)
52837                 WHEN 8 THEN TO_CHAR(h1.ADJ_DOC_SEQUENCE_VALUE)
52838                 
52839                 ELSE null
52840               END                           source_value
52841             , null              source_meaning
52842          FROM xla_events_gt     xet  
52843       , AR_ADJUSTMENTS_H_V  h1
52844       , AR_BILL_TO_CUSTOMERS_S_V  h2
52845       , AR_BILL_TO_SITE_USES_S_V  h3
52846       , AR_RECEIVABLES_TRX_ACT_S_V  h6
52847       , AR_TRANSACTIONS_S_V  h7
52848              ,(select rownum r from all_objects where rownum <= 8 and owner = p_apps_owner)
52849          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
52850            AND xet.event_class_code = C_EVENT_CLASS_CODE
52851               AND h1.event_id = xet.event_id
52855   AND h7.event_id  = h1.event_id
52852   AND h2.event_id  = h1.event_id
52853   AND h3.event_id  = h1.event_id
52854   AND h6.event_id (+) = h1.event_id
52856 
52857 )
52858 ;
52859 --
52860 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
52861 
52862       trace
52863          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
52864          ,p_level    => C_LEVEL_STATEMENT
52865          ,p_module   => l_log_module);
52866 
52867 END IF;
52868 --
52869 
52870 
52871 
52872 --
52873 INSERT INTO xla_diag_sources  --line2
52874 (
52875         event_id
52876       , ledger_id
52877       , sla_ledger_id
52878       , description_language
52879       , object_name
52880       , object_type_code
52881       , line_number
52882       , source_application_id
52883       , source_type_code
52884       , source_code
52885       , source_value
52886       , source_meaning
52887       , created_by
52888       , creation_date
52889       , last_update_date
52890       , last_updated_by
52891       , last_update_login
52892       , program_update_date
52893       , program_application_id
52894       , program_id
52895       , request_id
52896 )
52897 SELECT  event_id
52898       , p_target_ledger_id
52899       , p_sla_ledger_id
52900       , p_language
52901       , object_name
52902       , object_type_code
52903       , line_number
52904       , source_application_id
52905       , source_type_code
52906       , source_code
52907       , SUBSTR(source_value,1,1996)
52908       , SUBSTR(source_meaning ,1,200)
52909       , xla_environment_pkg.g_Usr_Id
52910       , TRUNC(SYSDATE)
52911       , TRUNC(SYSDATE)
52912       , xla_environment_pkg.g_Usr_Id
52913       , xla_environment_pkg.g_Login_Id
52914       , TRUNC(SYSDATE)
52915       , xla_environment_pkg.g_Prog_Appl_Id
52916       , xla_environment_pkg.g_Prog_Id
52917       , xla_environment_pkg.g_Req_Id
52918   FROM (
52919        SELECT xet.event_id                  event_id
52920             , l5.line_number                 line_number
52921             , CASE r
52922                WHEN 1 THEN 'AR_DISTRIBUTIONS_L_V' 
52923                 WHEN 2 THEN 'AR_DISTRIBUTIONS_L_V' 
52924                 WHEN 3 THEN 'AR_DISTRIBUTIONS_L_V' 
52925                 WHEN 4 THEN 'AR_DISTRIBUTIONS_L_V' 
52926                 WHEN 5 THEN 'AR_DISTRIBUTIONS_L_V' 
52927                 WHEN 6 THEN 'AR_DISTRIBUTIONS_L_V' 
52928                 WHEN 7 THEN 'AR_DISTRIBUTIONS_BASE_V' 
52929                 WHEN 8 THEN 'AR_DISTRIBUTIONS_BASE_V' 
52930                 WHEN 9 THEN 'AR_DISTRIBUTIONS_BASE_V' 
52931                 WHEN 10 THEN 'AR_DISTRIBUTIONS_BASE_V' 
52932                 
52933                ELSE null
52934               END                           object_name
52935             , CASE r
52936                 WHEN 1 THEN 'LINE' 
52937                 WHEN 2 THEN 'LINE' 
52938                 WHEN 3 THEN 'LINE' 
52939                 WHEN 4 THEN 'LINE' 
52940                 WHEN 5 THEN 'LINE' 
52941                 WHEN 6 THEN 'LINE' 
52942                 WHEN 7 THEN 'LINE' 
52943                 WHEN 8 THEN 'LINE' 
52944                 WHEN 9 THEN 'LINE' 
52945                 WHEN 10 THEN 'LINE' 
52946                 
52947                 ELSE null
52948               END                           object_type_code
52949             , CASE r
52950                 WHEN 1 THEN '222' 
52951                 WHEN 2 THEN '222' 
52952                 WHEN 3 THEN '222' 
52953                 WHEN 4 THEN '222' 
52954                 WHEN 5 THEN '222' 
52955                 WHEN 6 THEN '222' 
52956                 WHEN 7 THEN '222' 
52957                 WHEN 8 THEN '222' 
52958                 WHEN 9 THEN '222' 
52959                 WHEN 10 THEN '222' 
52960                 
52961                 ELSE null
52962               END                           source_application_id
52963             , 'S'             source_type_code
52964             , CASE r
52965                 WHEN 1 THEN 'DIST_CODE_COMBINATION_ID' 
52966                 WHEN 2 THEN 'DIST_SOURCE_TYPE' 
52967                 WHEN 3 THEN 'DIST_LINE_ID' 
52968                 WHEN 4 THEN 'DISTRIBUTION_TYPE' 
52969                 WHEN 5 THEN 'DIST_ENT_AMT' 
52970                 WHEN 6 THEN 'DIST_CURRENCY_CODE' 
52971                 WHEN 7 THEN 'DIST_CUR_CONVERSION_DATE' 
52972                 WHEN 8 THEN 'DIST_CUR_CONVERSION_RATE' 
52973                 WHEN 9 THEN 'DIST_CUR_CONVERSION_TYPE' 
52974                 WHEN 10 THEN 'DIST_TO_ACCTD_AMT' 
52975                 
52976                 ELSE null
52977               END                           source_code
52978             , CASE r
52979                 WHEN 1 THEN TO_CHAR(l5.DIST_CODE_COMBINATION_ID)
52980                 WHEN 2 THEN TO_CHAR(l5.DIST_SOURCE_TYPE)
52981                 WHEN 3 THEN TO_CHAR(l5.DIST_LINE_ID)
52982                 WHEN 4 THEN TO_CHAR(l5.DISTRIBUTION_TYPE)
52983                 WHEN 5 THEN TO_CHAR(l5.DIST_ENT_AMT)
52984                 WHEN 6 THEN TO_CHAR(l5.DIST_CURRENCY_CODE)
52985                 WHEN 7 THEN TO_CHAR(l4.DIST_CUR_CONVERSION_DATE)
52986                 WHEN 8 THEN TO_CHAR(l4.DIST_CUR_CONVERSION_RATE)
52987                 WHEN 9 THEN TO_CHAR(l4.DIST_CUR_CONVERSION_TYPE)
52988                 WHEN 10 THEN TO_CHAR(l4.DIST_TO_ACCTD_AMT)
52989                 
52990                 ELSE null
52991               END                           source_value
52995         , AR_DISTRIBUTIONS_L_V  l5
52992             , null              source_meaning
52993          FROM  xla_events_gt     xet  
52994         , AR_DISTRIBUTIONS_BASE_V  l4
52996             , (select rownum r from all_objects where rownum <= 10 and owner = p_apps_owner)
52997         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
52998           AND xet.event_class_code = C_EVENT_CLASS_CODE
52999             AND l4.event_id          = xet.event_id
53000   AND l5.event_id    = l4.event_id
53001   AND l5.line_number = l4.line_number
53002 
53003 )
53004 ;
53005 --
53006 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
53007 
53008       trace
53009          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
53010          ,p_level    => C_LEVEL_STATEMENT
53011          ,p_module   => l_log_module);
53012 
53013 END IF;
53014 
53015 
53016 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
53017       trace
53018          (p_msg      => 'END of insert_sources_102'
53019          ,p_level    => C_LEVEL_PROCEDURE
53020          ,p_module   => l_log_module);
53021 END IF;
53022 EXCEPTION
53023   WHEN xla_exceptions_pkg.application_exception THEN
53024       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
53025             trace
53026                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
53027                ,p_level    => C_LEVEL_EXCEPTION
53028                ,p_module   => l_log_module);
53029       END IF;
53030       RAISE;
53031   WHEN OTHERS THEN
53032       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
53033             trace
53034                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
53035                ,p_level    => C_LEVEL_EXCEPTION
53036                ,p_module   => l_log_module);
53037        END IF;
53038        xla_exceptions_pkg.raise_message
53039            (p_location => 'XLA_00222_AAD_S_000008_PKG.insert_sources_102');
53040 END insert_sources_102;
53041 --
53042 
53043 ---------------------------------------
53044 --
53045 -- PRIVATE FUNCTION
53046 --         EventClass_102
53047 --
53048 ----------------------------------------
53049 --
53050 FUNCTION EventClass_102
53051        (p_application_id         IN NUMBER
53052        ,p_base_ledger_id         IN NUMBER
53053        ,p_target_ledger_id       IN NUMBER
53054        ,p_language               IN VARCHAR2
53055        ,p_currency_code          IN VARCHAR2
53056        ,p_sla_ledger_id          IN NUMBER
53057        ,p_pad_start_date         IN DATE
53058        ,p_pad_end_date           IN DATE
53059        ,p_primary_ledger_id      IN NUMBER)
53060 RETURN BOOLEAN IS
53061 --
53062 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'ADJUSTMENT_ALL';
53063 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'ADJUSTMENT';
53064 
53065 l_calculate_acctd_flag   VARCHAR2(1) :='N';
53066 l_calculate_g_l_flag     VARCHAR2(1) :='Y';
53067 --
53068 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
53069 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
53070 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
53071 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
53072 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
53073 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
53074 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
53075 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
53076 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
53077 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
53078 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
53079 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
53080 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
53081 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
53082 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
53083 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
53084 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
53088 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
53085 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
53086 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
53087 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
53089 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
53090 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
53091 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
53092 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
53093 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
53094 
53095 l_event_id                             NUMBER;
53096 l_previous_event_id                    NUMBER;
53097 l_first_event_id                       NUMBER;
53098 l_last_event_id                        NUMBER;
53099 
53100 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
53101 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
53102 --
53103 --
53104 l_result                    BOOLEAN := TRUE;
53105 l_rows                      NUMBER  := 1000;
53106 l_event_type_name           VARCHAR2(80) := 'All';
53107 l_event_class_name          VARCHAR2(80) := 'Adjustment';
53108 l_description               VARCHAR2(4000);
53109 l_transaction_reversal      NUMBER;
53110 l_ae_header_id              NUMBER;
53111 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
53112 l_log_module                VARCHAR2(240);
53113 --
53114 l_acct_reversal_source      VARCHAR2(30);
53115 l_trx_reversal_source       VARCHAR2(30);
53116 
53117 l_continue_with_lines       BOOLEAN := TRUE;
53118 --
53119 l_acc_rev_gl_date_source    DATE;                      -- 4262811
53120 --
53121 type t_array_event_id is table of number index by binary_integer;
53122 
53123 l_rec_array_event                    t_rec_array_event;
53124 l_null_rec_array_event               t_rec_array_event;
53125 l_array_ae_header_id                 xla_number_array_type;
53126 l_actual_flag                        VARCHAR2(1) := NULL;
53127 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
53128 l_balance_type_code                  VARCHAR2(1) :=NULL;
53129 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
53130 
53131 --
53132 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
53133 --
53134 
53135 TYPE t_array_source_9 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_RECEIVABLE_CCID%TYPE INDEX BY BINARY_INTEGER;
53136 TYPE t_array_source_14 IS TABLE OF AR_RECEIVABLES_TRX_ACT_S_V.REC_ACT_TYPE%TYPE INDEX BY BINARY_INTEGER;
53137 TYPE t_array_source_23 IS TABLE OF AR_BILL_TO_CUSTOMERS_S_V.BILL_CUST_ACCOUNT_ID%TYPE INDEX BY BINARY_INTEGER;
53138 TYPE t_array_source_24 IS TABLE OF AR_BILL_TO_SITE_USES_S_V.BILL_USES_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
53139 TYPE t_array_source_25 IS TABLE OF AR_TRANSACTIONS_S_V.XLA_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
53140 TYPE t_array_source_71 IS TABLE OF AR_ADJUSTMENTS_H_V.ADJ_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
53141 TYPE t_array_source_72 IS TABLE OF AR_ADJUSTMENTS_H_V.ADJ_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
53142 TYPE t_array_source_73 IS TABLE OF AR_ADJUSTMENTS_H_V.ADJ_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
53143 
53144 TYPE t_array_source_3 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CODE_COMBINATION_ID%TYPE INDEX BY BINARY_INTEGER;
53145 TYPE t_array_source_13 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_SOURCE_TYPE%TYPE INDEX BY BINARY_INTEGER;
53149 TYPE t_array_source_18 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
53146 TYPE t_array_source_15 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
53147 TYPE t_array_source_16 IS TABLE OF AR_DISTRIBUTIONS_L_V.DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
53148 TYPE t_array_source_17 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_ENT_AMT%TYPE INDEX BY BINARY_INTEGER;
53150 TYPE t_array_source_19 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
53151 TYPE t_array_source_20 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
53152 TYPE t_array_source_21 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
53153 TYPE t_array_source_22 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
53154 
53155 l_array_source_9              t_array_source_9;
53156 l_array_source_14              t_array_source_14;
53157 l_array_source_23              t_array_source_23;
53158 l_array_source_24              t_array_source_24;
53159 l_array_source_25              t_array_source_25;
53160 l_array_source_71              t_array_source_71;
53161 l_array_source_72              t_array_source_72;
53162 l_array_source_73              t_array_source_73;
53163 
53164 l_array_source_3      t_array_source_3;
53165 l_array_source_13      t_array_source_13;
53166 l_array_source_15      t_array_source_15;
53167 l_array_source_16      t_array_source_16;
53168 l_array_source_17      t_array_source_17;
53169 l_array_source_18      t_array_source_18;
53170 l_array_source_19      t_array_source_19;
53171 l_array_source_20      t_array_source_20;
53172 l_array_source_21      t_array_source_21;
53173 l_array_source_22      t_array_source_22;
53174 
53175 --
53176 CURSOR header_cur
53177 IS
53178 SELECT /*+ leading(xet) cardinality(xet,1) */
53179 -- Event Class Code: ADJUSTMENT
53180     xet.entity_id
53181    ,xet.legal_entity_id
53182    ,xet.entity_code
53183    ,xet.transaction_number
53184    ,xet.event_id
53185    ,xet.event_class_code
53186    ,xet.event_type_code
53187    ,xet.event_number
53188    ,xet.event_date
53189    ,xet.transaction_date
53190    ,xet.reference_num_1
53191    ,xet.reference_num_2
53192    ,xet.reference_num_3
53193    ,xet.reference_num_4
53194    ,xet.reference_char_1
53195    ,xet.reference_char_2
53196    ,xet.reference_char_3
53197    ,xet.reference_char_4
53198    ,xet.reference_date_1
53199    ,xet.reference_date_2
53200    ,xet.reference_date_3
53201    ,xet.reference_date_4
53202    ,xet.event_created_by
53203    ,xet.budgetary_control_flag 
53204   , h7.TRX_RECEIVABLE_CCID    source_9
53205   , h6.REC_ACT_TYPE    source_14
53206   , h2.BILL_CUST_ACCOUNT_ID    source_23
53207   , h3.BILL_USES_SITE_USE_ID    source_24
53208   , h7.XLA_PARTY_TYPE    source_25
53209   , h1.ADJ_DOC_SEQUENCE_CATEGORY    source_71
53210   , h1.ADJ_DOC_SEQUENCE_ID    source_72
53211   , h1.ADJ_DOC_SEQUENCE_VALUE    source_73
53212   FROM xla_events_gt     xet 
53213   , AR_ADJUSTMENTS_H_V  h1
53214   , AR_BILL_TO_CUSTOMERS_S_V  h2
53215   , AR_BILL_TO_SITE_USES_S_V  h3
53216   , AR_RECEIVABLES_TRX_ACT_S_V  h6
53217   , AR_TRANSACTIONS_S_V  h7
53218  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
53219    and xet.event_class_code = C_EVENT_CLASS_CODE
53220    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
53221   AND h2.event_id  = h1.event_id
53222   AND h3.event_id  = h1.event_id
53223   AND h6.event_id (+) = h1.event_id
53224   AND h7.event_id  = h1.event_id
53225 
53226  ORDER BY event_id
53227 ;
53228 
53229 
53230 --
53231 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
53232 IS
53233 SELECT  /*+ leading(xet) cardinality(xet,1) */
53234 -- Event Class Code: ADJUSTMENT
53235     xet.entity_id
53236    ,xet.legal_entity_id
53237    ,xet.entity_code
53238    ,xet.transaction_number
53239    ,xet.event_id
53240    ,xet.event_class_code
53241    ,xet.event_type_code
53242    ,xet.event_number
53243    ,xet.event_date
53244    ,xet.transaction_date
53245    ,xet.reference_num_1
53246    ,xet.reference_num_2
53247    ,xet.reference_num_3
53248    ,xet.reference_num_4
53249    ,xet.reference_char_1
53250    ,xet.reference_char_2
53251    ,xet.reference_char_3
53252    ,xet.reference_char_4
53253    ,xet.reference_date_1
53254    ,xet.reference_date_2
53255    ,xet.reference_date_3
53256    ,xet.reference_date_4
53257    ,xet.event_created_by
53258    ,xet.budgetary_control_flag
53259  , l4.LINE_NUMBER  
53260   , l5.DIST_CODE_COMBINATION_ID    source_3
53261   , l5.DIST_SOURCE_TYPE    source_13
53262   , l5.DIST_LINE_ID    source_15
53263   , l5.DISTRIBUTION_TYPE    source_16
53264   , l5.DIST_ENT_AMT    source_17
53265   , l5.DIST_CURRENCY_CODE    source_18
53266   , l4.DIST_CUR_CONVERSION_DATE    source_19
53267   , l4.DIST_CUR_CONVERSION_RATE    source_20
53268   , l4.DIST_CUR_CONVERSION_TYPE    source_21
53269   , l4.DIST_TO_ACCTD_AMT    source_22
53270   FROM xla_events_gt     xet 
53271   , AR_DISTRIBUTIONS_BASE_V  l4
53272   , AR_DISTRIBUTIONS_L_V  l5
53273  WHERE xet.event_id between x_first_event_id and x_last_event_id
53274    and xet.event_date between p_pad_start_date and p_pad_end_date
53275    and xet.event_class_code = C_EVENT_CLASS_CODE
53276    and xet.event_status_code <> 'N'   AND l4.event_id      = xet.event_id
53277   AND l5.event_id    = l4.event_id
53278   AND l5.line_number = l4.line_number
53279 ;
53280 
53281 --
53282 BEGIN
53283 IF g_log_enabled THEN
53284    l_log_module := C_DEFAULT_MODULE||'.EventClass_102';
53285 END IF;
53286 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
53287    trace
53288       (p_msg      => 'BEGIN of EventClass_102'
53289       ,p_level    => C_LEVEL_PROCEDURE
53290       ,p_module   => l_log_module);
53291 END IF;
53292 
53293 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
53294    trace
53295       (p_msg      => 'p_application_id = '||p_application_id||
53296                      ' - p_base_ledger_id = '||p_base_ledger_id||
53297                      ' - p_target_ledger_id  = '||p_target_ledger_id||
53298                      ' - p_language = '||p_language||
53299                      ' - p_currency_code = '||p_currency_code||
53300                      ' - p_sla_ledger_id = '||p_sla_ledger_id
53301       ,p_level    => C_LEVEL_STATEMENT
53302       ,p_module   => l_log_module);
53303 END IF;
53304 --
53305 -- initialze arrays
53306 --
53307 g_array_event.DELETE;
53308 l_rec_array_event := l_null_rec_array_event;
53309 --
53310 --------------------------------------
53311 -- 4262811 Initialze MPA Line Number
53312 --------------------------------------
53313 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
53314 
53315 --
53316 
53317 --
53318 OPEN header_cur;
53319 --
53320 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
53321    trace
53322    (p_msg      => 'SQL - FETCH header_cur'
53323    ,p_level    => C_LEVEL_STATEMENT
53324    ,p_module   => l_log_module);
53325 END IF;
53326 --
53327 LOOP
53328 FETCH header_cur BULK COLLECT INTO
53329         l_array_entity_id
53330       , l_array_legal_entity_id
53331       , l_array_entity_code
53332       , l_array_transaction_num
53333       , l_array_event_id
53334       , l_array_class_code
53335       , l_array_event_type
53336       , l_array_event_number
53337       , l_array_event_date
53338       , l_array_transaction_date
53339       , l_array_reference_num_1
53340       , l_array_reference_num_2
53341       , l_array_reference_num_3
53342       , l_array_reference_num_4
53343       , l_array_reference_char_1
53344       , l_array_reference_char_2
53345       , l_array_reference_char_3
53346       , l_array_reference_char_4
53347       , l_array_reference_date_1
53348       , l_array_reference_date_2
53349       , l_array_reference_date_3
53350       , l_array_reference_date_4
53351       , l_array_event_created_by
53352       , l_array_budgetary_control_flag 
53353       , l_array_source_9
53354       , l_array_source_14
53355       , l_array_source_23
53356       , l_array_source_24
53357       , l_array_source_25
53358       , l_array_source_71
53359       , l_array_source_72
53360       , l_array_source_73
53361       LIMIT l_rows;
53362 --
53363 IF (C_LEVEL_EVENT >= g_log_level) THEN
53364    trace
53365    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
53366    ,p_level    => C_LEVEL_EVENT
53367    ,p_module   => l_log_module);
53368 END IF;
53369 --
53370 EXIT WHEN l_array_entity_id.COUNT = 0;
53371 
53372 -- initialize arrays
53373 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
53374 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
53375 
53376 --
53377 -- Bug 4458708
53378 --
53379 XLA_AE_LINES_PKG.g_LineNumber := 0;
53380 
53381 
53382 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
53383 g_last_hdr_idx := l_array_event_id.LAST;
53384 --
53385 -- loop for the headers. Each iteration is for each header extract row
53386 -- fetched in header cursor
53387 --
53388 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
53389 
53390 --
53391 -- set event info as cache for other routines to refer event attributes
53392 --
53393 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
53394    (p_application_id           => p_application_id
53395    ,p_primary_ledger_id        => p_primary_ledger_id
53396    ,p_base_ledger_id           => p_base_ledger_id
53397    ,p_target_ledger_id         => p_target_ledger_id
53398    ,p_entity_id                => l_array_entity_id(hdr_idx)
53399    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
53400    ,p_entity_code              => l_array_entity_code(hdr_idx)
53401    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
53402    ,p_event_id                 => l_array_event_id(hdr_idx)
53403    ,p_event_class_code         => l_array_class_code(hdr_idx)
53404    ,p_event_type_code          => l_array_event_type(hdr_idx)
53405    ,p_event_number             => l_array_event_number(hdr_idx)
53406    ,p_event_date               => l_array_event_date(hdr_idx)
53407    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
53408    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
53409    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
53410    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
53411    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
53412    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
53413    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
53414    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
53415    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
53416    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
53417    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
53418    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
53419    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
53420    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
53421    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
53422 
53423 --
53424 -- set the status of entry to C_VALID (0)
53425 --
53426 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
53427 
53428 --
53429 -- initialize a row for ae header
53430 --
53431 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
53432 
53433 l_event_id := l_array_event_id(hdr_idx);
53434 
53435 --
53436 -- storing the hdr_idx for event. May be used by line cursor.
53437 --
53438 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
53439 
53440 --
53441 -- store sources from header extract. This can be improved to
53442 -- store only those sources from header extract that may be used in lines
53443 --
53444 
53445 g_array_event(l_event_id).array_value_num('source_9') := l_array_source_9(hdr_idx);
53446 g_array_event(l_event_id).array_value_char('source_14') := l_array_source_14(hdr_idx);
53447 g_array_event(l_event_id).array_value_num('source_23') := l_array_source_23(hdr_idx);
53448 g_array_event(l_event_id).array_value_num('source_24') := l_array_source_24(hdr_idx);
53449 g_array_event(l_event_id).array_value_char('source_25') := l_array_source_25(hdr_idx);
53450 g_array_event(l_event_id).array_value_char('source_71') := l_array_source_71(hdr_idx);
53451 g_array_event(l_event_id).array_value_num('source_72') := l_array_source_72(hdr_idx);
53452 g_array_event(l_event_id).array_value_num('source_73') := l_array_source_73(hdr_idx);
53453 
53454 --
53455 -- initilaize the status of ae headers for diffrent balance types
53456 -- the status is initialised to C_NOT_CREATED (2)
53457 --
53458 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
53459 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
53460 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
53461 
53462 --
53463 -- call api to validate and store accounting attributes for header
53464 --
53465 
53466 ------------------------------------------------------------
53467 -- Accrual Reversal : to get date for Standard Source (NONE)
53468 ------------------------------------------------------------
53469 l_acc_rev_gl_date_source := NULL;
53470 
53471      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
53472       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_71');
53473      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
53474       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_72');
53475      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
53476       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_73');
53477      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
53478       l_rec_acct_attrs.array_date_value(4) := 
53479 xla_ae_sources_pkg.GetSystemSourceDate(
53480    p_source_code           => 'XLA_EVENT_DATE'
53481  , p_source_type_code      => 'Y'
53482  , p_source_application_id =>  602
53483 );
53484 
53488 XLA_AE_HEADER_PKG.SetJeCategoryName;
53485 
53486 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
53487 
53489 
53490 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
53491 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
53492 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
53493 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
53494 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
53495 
53496 
53497 -- No header level analytical criteria
53498 
53499 --
53500 --accounting attribute enhancement, bug 3612931
53501 --
53502 l_trx_reversal_source := SUBSTR(NULL, 1,30);
53503 
53504 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
53505    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
53506 
53507    xla_accounting_err_pkg.build_message
53508       (p_appli_s_name            => 'XLA'
53509       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
53510       ,p_token_1                 => 'ACCT_ATTR_NAME'
53511       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
53512       ,p_token_2                 => 'PRODUCT_NAME'
53513       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
53514       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
53515       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
53516       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
53517 
53518 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
53519    --
53520    -- following sets the accounting attributes needed to reverse
53521    -- accounting for a distributeion
53522    --
53523    xla_ae_lines_pkg.SetTrxReversalAttrs
53524       (p_event_id              => l_event_id
53525       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
53526       ,p_trx_reversal_source   => l_trx_reversal_source);
53527 
53528 END IF;
53529 
53530 
53531 ----------------------------------------------------------------
53532 -- 4262811 -  update the header statuses to invalid in need be
53533 ----------------------------------------------------------------
53534 --
53535 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
53536 
53537 
53538   -----------------------------------------------
53539   -- No accrual reversal for the event class/type
53540   -----------------------------------------------
53541 ----------------------------------------------------------------
53542 
53543 --
53544 -- this ends the header loop iteration for one bulk fetch
53545 --
53546 END LOOP;
53547 
53548 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
53549 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
53550 
53551 --
53552 -- insert dummy rows into lines gt table that were created due to
53553 -- transaction reversals
53554 --
53555 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
53556    l_result := XLA_AE_LINES_PKG.InsertLines;
53557 END IF;
53558 
53559 --
53560 -- reset the temp_line_num for each set of events fetched from header
53561 -- cursor rather than doing it for each new event in line cursor
53562 -- Bug 3939231
53563 --
53564 xla_ae_lines_pkg.g_temp_line_num := 0;
53565 
53566 
53567 
53568 --
53569 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
53570 --
53571 --
53572 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
53573 
53574       trace
53575          (p_msg      => 'SQL - FETCH line_cur'
53576          ,p_level    => C_LEVEL_STATEMENT
53577          ,p_module   => l_log_module);
53578 
53579 END IF;
53580 --
53581 --
53582 LOOP
53583   --
53584   FETCH line_cur BULK COLLECT INTO
53585         l_array_entity_id
53586       , l_array_legal_entity_id
53587       , l_array_entity_code
53588       , l_array_transaction_num
53589       , l_array_event_id
53590       , l_array_class_code
53591       , l_array_event_type
53592       , l_array_event_number
53593       , l_array_event_date
53594       , l_array_transaction_date
53595       , l_array_reference_num_1
53596       , l_array_reference_num_2
53600       , l_array_reference_char_2
53597       , l_array_reference_num_3
53598       , l_array_reference_num_4
53599       , l_array_reference_char_1
53601       , l_array_reference_char_3
53602       , l_array_reference_char_4
53603       , l_array_reference_date_1
53604       , l_array_reference_date_2
53605       , l_array_reference_date_3
53606       , l_array_reference_date_4
53607       , l_array_event_created_by
53608       , l_array_budgetary_control_flag
53609       , l_array_extract_line_num 
53610       , l_array_source_3
53611       , l_array_source_13
53612       , l_array_source_15
53613       , l_array_source_16
53614       , l_array_source_17
53615       , l_array_source_18
53616       , l_array_source_19
53617       , l_array_source_20
53618       , l_array_source_21
53619       , l_array_source_22
53620       LIMIT l_rows;
53621 
53622   --
53623   IF (C_LEVEL_EVENT >= g_log_level) THEN
53624             trace
53625                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
53626                ,p_level    => C_LEVEL_EVENT
53627                ,p_module   => l_log_module);
53628   END IF;
53629   --
53630   EXIT WHEN l_array_entity_id.count = 0;
53631 
53632   XLA_AE_LINES_PKG.g_rec_lines := null;
53633 
53634 --
53635 -- Bug 4458708
53636 --
53637 XLA_AE_LINES_PKG.g_LineNumber := 0;
53638 --
53639 --
53640 
53641 FOR Idx IN 1..l_array_event_id.count LOOP
53642    --
53643    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
53644    --
53645    l_event_id := l_array_event_id(idx);  -- 5648433
53646 
53647    --
53648    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
53649    --
53650 
53651    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
53652              (g_array_event(l_event_id).array_value_num('header_index'))
53653          ,'N'
53654          ) <> 'Y'
53655    THEN
53656       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
53657          trace
53658             (p_msg      => 'Trancaction revesal option is not Y '
53659             ,p_level    => C_LEVEL_STATEMENT
53660             ,p_module   => l_log_module);
53661       END IF;
53662 
53663 --
53664 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
53665 --
53666 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
53667 --
53668 -- set event info as cache for other routines to refer event attributes
53669 --
53670 
53671 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
53672    l_previous_event_id := l_event_id;
53673 
53674    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
53675       (p_application_id           => p_application_id
53676       ,p_primary_ledger_id        => p_primary_ledger_id
53677       ,p_base_ledger_id           => p_base_ledger_id
53678       ,p_target_ledger_id         => p_target_ledger_id
53679       ,p_entity_id                => l_array_entity_id(Idx)
53680       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
53681       ,p_entity_code              => l_array_entity_code(Idx)
53682       ,p_transaction_num          => l_array_transaction_num(Idx)
53683       ,p_event_id                 => l_array_event_id(Idx)
53684       ,p_event_class_code         => l_array_class_code(Idx)
53688       ,p_transaction_date         => l_array_transaction_date(Idx)
53685       ,p_event_type_code          => l_array_event_type(Idx)
53686       ,p_event_number             => l_array_event_number(Idx)
53687       ,p_event_date               => l_array_event_date(Idx)
53689       ,p_reference_num_1          => l_array_reference_num_1(Idx)
53690       ,p_reference_num_2          => l_array_reference_num_2(Idx)
53691       ,p_reference_num_3          => l_array_reference_num_3(Idx)
53692       ,p_reference_num_4          => l_array_reference_num_4(Idx)
53693       ,p_reference_char_1         => l_array_reference_char_1(Idx)
53694       ,p_reference_char_2         => l_array_reference_char_2(Idx)
53695       ,p_reference_char_3         => l_array_reference_char_3(Idx)
53696       ,p_reference_char_4         => l_array_reference_char_4(Idx)
53697       ,p_reference_date_1         => l_array_reference_date_1(Idx)
53698       ,p_reference_date_2         => l_array_reference_date_2(Idx)
53699       ,p_reference_date_3         => l_array_reference_date_3(Idx)
53700       ,p_reference_date_4         => l_array_reference_date_4(Idx)
53701       ,p_event_created_by         => l_array_event_created_by(Idx)
53702       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
53703        --
53704 END IF;
53705 
53706 
53707 
53708 --
53709 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
53710 
53711 l_acct_reversal_source := SUBSTR(NULL, 1,30);
53712 
53713 IF l_continue_with_lines THEN
53714    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
53715       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
53716 
53717       xla_accounting_err_pkg.build_message
53718          (p_appli_s_name            => 'XLA'
53719          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
53720          ,p_token_1                 => 'LINE_NUMBER'
53721          ,p_value_1                 => l_array_extract_line_num(Idx)
53722          ,p_token_2                 => 'PRODUCT_NAME'
53723          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
53724          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
53725          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
53726          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
53727 
53728    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
53729       --
53730       -- following sets the accounting attributes needed to reverse
53731       -- accounting for a distributeion
53732       --
53733 
53734       --
53735       -- 5217187
53736       --
53737       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
53738       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
53739                                        g_array_event(l_event_id).array_value_num('header_index'));
53740       --
53741       --
53742 
53743       -- No reversal code generated
53744 
53745       xla_ae_lines_pkg.SetAcctReversalAttrs
53746          (p_event_id             => l_event_id
53747          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
53748          ,p_calculate_acctd_flag => l_calculate_acctd_flag
53749          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
53750    END IF;
53751 
53752    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
53753        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
53754 
53755 --
53756 AcctLineType_17 (
53757  p_application_id  => p_application_id
53758  ,p_event_id     => l_event_id
53759  ,p_calculate_acctd_flag => l_calculate_acctd_flag
53760  ,p_calculate_g_l_flag => l_calculate_g_l_flag
53761  ,p_actual_flag => l_actual_flag
53762  ,p_balance_type_code => l_balance_type_code
53763  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
53764  
53765  , p_source_3 => l_array_source_3(Idx)
53766  , p_source_13 => l_array_source_13(Idx)
53767  , p_source_14 => g_array_event(l_event_id).array_value_char('source_14')
53768  , p_source_15 => l_array_source_15(Idx)
53769  , p_source_16 => l_array_source_16(Idx)
53770  , p_source_17 => l_array_source_17(Idx)
53771  , p_source_18 => l_array_source_18(Idx)
53772  , p_source_19 => l_array_source_19(Idx)
53773  , p_source_20 => l_array_source_20(Idx)
53774  , p_source_21 => l_array_source_21(Idx)
53775  , p_source_22 => l_array_source_22(Idx)
53776  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
53777  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
53778  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
53779  );
53780 If(l_balance_type_code = 'A') THEN
53781   l_actual_gain_loss_ref := l_gain_or_loss_ref;
53782 END IF;
53783 
53784 --
53785 
53786 
53787 --
53788 AcctLineType_18 (
53789  p_application_id  => p_application_id
53790  ,p_event_id     => l_event_id
53791  ,p_calculate_acctd_flag => l_calculate_acctd_flag
53792  ,p_calculate_g_l_flag => l_calculate_g_l_flag
53793  ,p_actual_flag => l_actual_flag
53794  ,p_balance_type_code => l_balance_type_code
53795  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
53796  
53797  , p_source_3 => l_array_source_3(Idx)
53798  , p_source_13 => l_array_source_13(Idx)
53799  , p_source_14 => g_array_event(l_event_id).array_value_char('source_14')
53800  , p_source_15 => l_array_source_15(Idx)
53801  , p_source_16 => l_array_source_16(Idx)
53802  , p_source_17 => l_array_source_17(Idx)
53803  , p_source_18 => l_array_source_18(Idx)
53804  , p_source_19 => l_array_source_19(Idx)
53805  , p_source_20 => l_array_source_20(Idx)
53806  , p_source_21 => l_array_source_21(Idx)
53807  , p_source_22 => l_array_source_22(Idx)
53808  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
53809  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
53810  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
53811  );
53812 If(l_balance_type_code = 'A') THEN
53813   l_actual_gain_loss_ref := l_gain_or_loss_ref;
53814 END IF;
53815 
53816 --
53817 
53818 
53819 --
53820 AcctLineType_19 (
53821  p_application_id  => p_application_id
53822  ,p_event_id     => l_event_id
53823  ,p_calculate_acctd_flag => l_calculate_acctd_flag
53824  ,p_calculate_g_l_flag => l_calculate_g_l_flag
53825  ,p_actual_flag => l_actual_flag
53826  ,p_balance_type_code => l_balance_type_code
53827  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
53828  
53829  , p_source_3 => l_array_source_3(Idx)
53830  , p_source_13 => l_array_source_13(Idx)
53831  , p_source_15 => l_array_source_15(Idx)
53832  , p_source_16 => l_array_source_16(Idx)
53833  , p_source_17 => l_array_source_17(Idx)
53834  , p_source_18 => l_array_source_18(Idx)
53835  , p_source_19 => l_array_source_19(Idx)
53836  , p_source_20 => l_array_source_20(Idx)
53837  , p_source_21 => l_array_source_21(Idx)
53838  , p_source_22 => l_array_source_22(Idx)
53839  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
53840  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
53841  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
53842  );
53843 If(l_balance_type_code = 'A') THEN
53844   l_actual_gain_loss_ref := l_gain_or_loss_ref;
53845 END IF;
53846 
53847 --
53848 
53849 
53850 --
53851 AcctLineType_20 (
53852  p_application_id  => p_application_id
53853  ,p_event_id     => l_event_id
53854  ,p_calculate_acctd_flag => l_calculate_acctd_flag
53855  ,p_calculate_g_l_flag => l_calculate_g_l_flag
53856  ,p_actual_flag => l_actual_flag
53857  ,p_balance_type_code => l_balance_type_code
53858  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
53859  
53860  , p_source_3 => l_array_source_3(Idx)
53861  , p_source_13 => l_array_source_13(Idx)
53862  , p_source_15 => l_array_source_15(Idx)
53863  , p_source_16 => l_array_source_16(Idx)
53864  , p_source_17 => l_array_source_17(Idx)
53865  , p_source_18 => l_array_source_18(Idx)
53866  , p_source_19 => l_array_source_19(Idx)
53867  , p_source_20 => l_array_source_20(Idx)
53868  , p_source_21 => l_array_source_21(Idx)
53869  , p_source_22 => l_array_source_22(Idx)
53870  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
53871  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
53872  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
53873  );
53874 If(l_balance_type_code = 'A') THEN
53875   l_actual_gain_loss_ref := l_gain_or_loss_ref;
53876 END IF;
53877 
53878 --
53879 
53880 
53881 --
53882 AcctLineType_21 (
53883  p_application_id  => p_application_id
53884  ,p_event_id     => l_event_id
53885  ,p_calculate_acctd_flag => l_calculate_acctd_flag
53886  ,p_calculate_g_l_flag => l_calculate_g_l_flag
53887  ,p_actual_flag => l_actual_flag
53888  ,p_balance_type_code => l_balance_type_code
53889  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
53890  
53891  , p_source_3 => l_array_source_3(Idx)
53892  , p_source_13 => l_array_source_13(Idx)
53893  , p_source_15 => l_array_source_15(Idx)
53894  , p_source_16 => l_array_source_16(Idx)
53895  , p_source_17 => l_array_source_17(Idx)
53896  , p_source_18 => l_array_source_18(Idx)
53897  , p_source_19 => l_array_source_19(Idx)
53901  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
53898  , p_source_20 => l_array_source_20(Idx)
53899  , p_source_21 => l_array_source_21(Idx)
53900  , p_source_22 => l_array_source_22(Idx)
53902  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
53903  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
53904  );
53905 If(l_balance_type_code = 'A') THEN
53906   l_actual_gain_loss_ref := l_gain_or_loss_ref;
53907 END IF;
53908 
53909 --
53910 
53911 
53912 --
53913 AcctLineType_52 (
53914  p_application_id  => p_application_id
53915  ,p_event_id     => l_event_id
53916  ,p_calculate_acctd_flag => l_calculate_acctd_flag
53917  ,p_calculate_g_l_flag => l_calculate_g_l_flag
53918  ,p_actual_flag => l_actual_flag
53919  ,p_balance_type_code => l_balance_type_code
53920  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
53921  
53922  , p_source_3 => l_array_source_3(Idx)
53923  , p_source_9 => g_array_event(l_event_id).array_value_num('source_9')
53924  , p_source_13 => l_array_source_13(Idx)
53925  , p_source_14 => g_array_event(l_event_id).array_value_char('source_14')
53926  , p_source_15 => l_array_source_15(Idx)
53927  , p_source_16 => l_array_source_16(Idx)
53928  , p_source_17 => l_array_source_17(Idx)
53929  , p_source_18 => l_array_source_18(Idx)
53930  , p_source_19 => l_array_source_19(Idx)
53931  , p_source_20 => l_array_source_20(Idx)
53932  , p_source_21 => l_array_source_21(Idx)
53933  , p_source_22 => l_array_source_22(Idx)
53934  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
53935  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
53936  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
53937  );
53938 If(l_balance_type_code = 'A') THEN
53939   l_actual_gain_loss_ref := l_gain_or_loss_ref;
53940 END IF;
53941 
53942 --
53943 
53944       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
53945       -- or secondary ledger that has different currency with primary
53946       -- or alc that is calculated by sla
53947       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
53948             (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'))
53949 
53950 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
53951 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
53952           AND (l_actual_flag = 'A')) THEN
53953         XLA_AE_LINES_PKG.CreateGainOrLossLines(
53954           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
53955          ,p_application_id   => p_application_id
53956          ,p_amb_context_code => 'DEFAULT'
53957          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
53958          ,p_event_class_code => C_EVENT_CLASS_CODE
53959          ,p_event_type_code  => C_EVENT_TYPE_CODE
53960          
53961          ,p_gain_ccid        => -1
53962          ,p_loss_ccid        => -1
53963 
53964          ,p_actual_flag      => l_actual_flag
53965          ,p_enc_flag         => null
53966          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
53967          ,p_enc_g_l_ref      => null
53968          );
53969       END IF;
53970    END IF;
53971 END IF;
53972 
53973    ELSE
53974       --
53975       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
53976       --
53977       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
53978          trace
53979             (p_msg      => 'Trancaction revesal option is Y'
53980             ,p_level    => C_LEVEL_STATEMENT
53981             ,p_module   => l_log_module);
53982       END IF;
53983    END IF;
53984 
53985 END LOOP;
53986 l_result := XLA_AE_LINES_PKG.InsertLines ;
53987 end loop;
53988 close line_cur;
53989 
53990 
53991 --
53992 -- insert headers into xla_ae_headers_gt table
53993 --
53994 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
53995 
53996 -- insert into errors table here.
53997 
53998 END LOOP;
53999 
54000 --
54001 -- 4865292
54002 --
54003 -- Compare g_hdr_extract_count with event count in
54004 -- CreateHeadersAndLines.
54005 --
54006 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
54007 
54008 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
54009    trace (p_msg     => '# rows extracted from header extract objects '
54010                     || ' (running total): '
54011                     || g_hdr_extract_count
54012          ,p_level   => C_LEVEL_STATEMENT
54013          ,p_module  => l_log_module);
54014 END IF;
54015 
54016 CLOSE header_cur;
54017 --
54018 
54019 --
54020 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
54021    trace
54022       (p_msg      => 'END of EventClass_102'
54023       ,p_level    => C_LEVEL_PROCEDURE
54024       ,p_module   => l_log_module);
54025 END IF;
54026 --
54027 RETURN l_result;
54028 EXCEPTION
54029 WHEN xla_exceptions_pkg.application_exception THEN
54030    
54031 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
54032 
54033    
54034 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
54035 
54036    RAISE;
54037 
54038 WHEN NO_DATA_FOUND THEN
54039 
54043 FOR header_record IN header_cur
54040 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
54041 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
54042 
54044 LOOP
54045     l_array_header_events(header_record.event_id) := header_record.event_id;
54046 END LOOP;
54047 
54048 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
54049 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
54050 
54051 fnd_file.put_line(fnd_file.LOG, '                    ');
54052 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
54053 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
54054 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
54055 
54056 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
54057 LOOP
54058 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
54059 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
54060         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
54061 	END IF;
54062 END LOOP;
54063 
54064 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
54065 fnd_file.put_line(fnd_file.LOG, '                    ');
54066 
54067 
54068 xla_exceptions_pkg.raise_message
54069       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_102');
54070 
54071 
54072 WHEN OTHERS THEN
54073    xla_exceptions_pkg.raise_message
54074       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_102');
54075 END EventClass_102;
54076 --
54077 
54078 ---------------------------------------
54079 --
54080 -- PRIVATE PROCEDURE
54081 --         insert_sources_103
54082 --
54083 ----------------------------------------
54084 --
54085 PROCEDURE insert_sources_103(
54086                                 p_target_ledger_id       IN NUMBER
54087                               , p_language               IN VARCHAR2
54088                               , p_sla_ledger_id          IN NUMBER
54089                               , p_pad_start_date         IN DATE
54090                               , p_pad_end_date           IN DATE
54091                          )
54092 IS
54093 
54094 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CHARGEBACK_ALL';
54095 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CHARGEBACK';
54096 p_apps_owner                   VARCHAR2(30);
54097 l_log_module                   VARCHAR2(240);
54098 BEGIN
54099 IF g_log_enabled THEN
54100       l_log_module := C_DEFAULT_MODULE||'.insert_sources_103';
54101 END IF;
54102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
54103 
54104       trace
54105          (p_msg      => 'BEGIN of insert_sources_103'
54106          ,p_level    => C_LEVEL_PROCEDURE
54107          ,p_module   => l_log_module);
54108 
54109 END IF;
54110 
54111 -- select APPS owner
54112 SELECT oracle_username
54113   INTO p_apps_owner
54114   FROM fnd_oracle_userid
54115  WHERE read_only_flag = 'U'
54116 ;
54117 
54118 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
54119       trace
54120          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
54121                         ' - p_language = '||p_language||
54122                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
54123                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
54124                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
54125                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
54126          ,p_level    => C_LEVEL_STATEMENT
54127          ,p_module   => l_log_module);
54128 END IF;
54129 
54130 
54131 --
54132 INSERT INTO xla_diag_sources --hdr2
54133 (
54134         event_id
54135       , ledger_id
54136       , sla_ledger_id
54137       , description_language
54138       , object_name
54139       , object_type_code
54140       , line_number
54141       , source_application_id
54142       , source_type_code
54143       , source_code
54144       , source_value
54145       , source_meaning
54146       , created_by
54147       , creation_date
54148       , last_update_date
54149       , last_updated_by
54150       , last_update_login
54151       , program_update_date
54152       , program_application_id
54153       , program_id
54154       , request_id
54155 )
54156 SELECT
54157         event_id
54158       , p_target_ledger_id
54159       , p_sla_ledger_id
54160       , p_language
54161       , object_name
54162       , object_type_code
54163       , line_number
54164       , source_application_id
54165       , source_type_code
54166       , source_code
54167       , SUBSTR(source_value ,1,1996)
54168       , SUBSTR(source_meaning ,1,200)
54169       , xla_environment_pkg.g_Usr_Id
54170       , TRUNC(SYSDATE)
54171       , TRUNC(SYSDATE)
54172       , xla_environment_pkg.g_Usr_Id
54173       , xla_environment_pkg.g_Login_Id
54174       , TRUNC(SYSDATE)
54175       , xla_environment_pkg.g_Prog_Appl_Id
54176       , xla_environment_pkg.g_Prog_Id
54177       , xla_environment_pkg.g_Req_Id
54178   FROM (
54179        SELECT xet.event_id                  event_id
54180             , 0                          line_number
54181             , CASE r
54182                WHEN 1 THEN 'AR_BILL_TO_CUSTOMERS_S_V' 
54183                 WHEN 2 THEN 'AR_BILL_TO_SITE_USES_S_V' 
54184                 WHEN 3 THEN 'AR_TRANSACTIONS_S_V' 
54185                 WHEN 4 THEN 'AR_TRANSACTIONS_S_V' 
54189                 
54186                 WHEN 5 THEN 'AR_TRANSACTIONS_S_V' 
54187                 WHEN 6 THEN 'AR_TRANSACTIONS_S_V' 
54188                 WHEN 7 THEN 'AR_TRANSACTIONS_S_V' 
54190                ELSE null
54191               END                           object_name
54192             , CASE r
54193                 WHEN 1 THEN 'HEADER' 
54194                 WHEN 2 THEN 'HEADER' 
54195                 WHEN 3 THEN 'HEADER' 
54196                 WHEN 4 THEN 'HEADER' 
54197                 WHEN 5 THEN 'HEADER' 
54198                 WHEN 6 THEN 'HEADER' 
54199                 WHEN 7 THEN 'HEADER' 
54200                 
54201                 ELSE null
54202               END                           object_type_code
54203             , CASE r
54204                 WHEN 1 THEN '222' 
54205                 WHEN 2 THEN '222' 
54206                 WHEN 3 THEN '222' 
54207                 WHEN 4 THEN '222' 
54208                 WHEN 5 THEN '222' 
54209                 WHEN 6 THEN '222' 
54210                 WHEN 7 THEN '222' 
54211                 
54212                 ELSE null
54213               END                           source_application_id
54214             , 'S'             source_type_code
54215             , CASE r
54216                 WHEN 1 THEN 'BILL_CUST_ACCOUNT_ID' 
54217                 WHEN 2 THEN 'BILL_USES_SITE_USE_ID' 
54218                 WHEN 3 THEN 'XLA_PARTY_TYPE' 
54219                 WHEN 4 THEN 'TRX_INVOICE_CURRENCY_CODE' 
54220                 WHEN 5 THEN 'TRX_DOC_SEQUENCE_CATEGORY' 
54221                 WHEN 6 THEN 'TRX_DOC_SEQUENCE_ID' 
54222                 WHEN 7 THEN 'TRX_DOC_SEQUENCE_VALUE' 
54223                 
54224                 ELSE null
54225               END                           source_code
54226             , CASE r
54227                 WHEN 1 THEN TO_CHAR(h1.BILL_CUST_ACCOUNT_ID)
54228                 WHEN 2 THEN TO_CHAR(h2.BILL_USES_SITE_USE_ID)
54229                 WHEN 3 THEN TO_CHAR(h5.XLA_PARTY_TYPE)
54230                 WHEN 4 THEN TO_CHAR(h5.TRX_INVOICE_CURRENCY_CODE)
54231                 WHEN 5 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_CATEGORY)
54232                 WHEN 6 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_ID)
54233                 WHEN 7 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_VALUE)
54234                 
54235                 ELSE null
54236               END                           source_value
54237             , null              source_meaning
54238          FROM xla_events_gt     xet  
54239       , AR_BILL_TO_CUSTOMERS_S_V  h1
54240       , AR_BILL_TO_SITE_USES_S_V  h2
54241       , AR_TRANSACTIONS_S_V  h5
54242              ,(select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
54243          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
54244            AND xet.event_class_code = C_EVENT_CLASS_CODE
54245               AND h1.event_id = xet.event_id
54246   AND h2.event_id  = h1.event_id
54247   AND h5.event_id  = h1.event_id
54248 
54249 )
54250 ;
54251 --
54252 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
54253 
54254       trace
54255          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
54256          ,p_level    => C_LEVEL_STATEMENT
54257          ,p_module   => l_log_module);
54258 
54259 END IF;
54260 --
54261 
54262 
54263 
54264 --
54265 INSERT INTO xla_diag_sources  --line2
54266 (
54267         event_id
54268       , ledger_id
54269       , sla_ledger_id
54270       , description_language
54271       , object_name
54272       , object_type_code
54273       , line_number
54274       , source_application_id
54275       , source_type_code
54276       , source_code
54277       , source_value
54278       , source_meaning
54279       , created_by
54280       , creation_date
54281       , last_update_date
54282       , last_updated_by
54283       , last_update_login
54284       , program_update_date
54285       , program_application_id
54286       , program_id
54287       , request_id
54288 )
54289 SELECT  event_id
54290       , p_target_ledger_id
54291       , p_sla_ledger_id
54292       , p_language
54293       , object_name
54294       , object_type_code
54295       , line_number
54296       , source_application_id
54297       , source_type_code
54298       , source_code
54299       , SUBSTR(source_value,1,1996)
54300       , SUBSTR(source_meaning ,1,200)
54301       , xla_environment_pkg.g_Usr_Id
54302       , TRUNC(SYSDATE)
54303       , TRUNC(SYSDATE)
54304       , xla_environment_pkg.g_Usr_Id
54305       , xla_environment_pkg.g_Login_Id
54306       , TRUNC(SYSDATE)
54307       , xla_environment_pkg.g_Prog_Appl_Id
54308       , xla_environment_pkg.g_Prog_Id
54309       , xla_environment_pkg.g_Req_Id
54310   FROM (
54311        SELECT xet.event_id                  event_id
54312             , l4.line_number                 line_number
54313             , CASE r
54314                WHEN 1 THEN 'AR_CUST_TRX_LINES_L_V' 
54315                 WHEN 2 THEN 'AR_CUST_TRX_LINES_L_V' 
54316                 WHEN 3 THEN 'AR_CUST_TRX_LINES_L_V' 
54317                 WHEN 4 THEN 'AR_CUST_TRX_LINES_L_V' 
54318                 WHEN 5 THEN 'AR_CUST_TRX_LINES_L_V' 
54319                 WHEN 6 THEN 'AR_CUST_TRX_LINES_BASE_V' 
54320                 WHEN 7 THEN 'AR_CUST_TRX_LINES_BASE_V' 
54321                 WHEN 8 THEN 'AR_CUST_TRX_LINES_BASE_V' 
54322                 WHEN 9 THEN 'AR_CUST_TRX_LINES_BASE_V' 
54323                 
54324                ELSE null
54325               END                           object_name
54326             , CASE r
54327                 WHEN 1 THEN 'LINE' 
54328                 WHEN 2 THEN 'LINE' 
54332                 WHEN 6 THEN 'LINE' 
54329                 WHEN 3 THEN 'LINE' 
54330                 WHEN 4 THEN 'LINE' 
54331                 WHEN 5 THEN 'LINE' 
54333                 WHEN 7 THEN 'LINE' 
54334                 WHEN 8 THEN 'LINE' 
54335                 WHEN 9 THEN 'LINE' 
54336                 
54337                 ELSE null
54338               END                           object_type_code
54339             , CASE r
54340                 WHEN 1 THEN '222' 
54341                 WHEN 2 THEN '222' 
54342                 WHEN 3 THEN '222' 
54343                 WHEN 4 THEN '222' 
54344                 WHEN 5 THEN '222' 
54345                 WHEN 6 THEN '222' 
54346                 WHEN 7 THEN '222' 
54347                 WHEN 8 THEN '222' 
54348                 WHEN 9 THEN '222' 
54349                 
54350                 ELSE null
54351               END                           source_application_id
54352             , 'S'             source_type_code
54353             , CASE r
54354                 WHEN 1 THEN 'TRX_LINE_DIST_CCID' 
54355                 WHEN 2 THEN 'TRX_LINE_DIST_ACCOUNT_CLASS' 
54356                 WHEN 3 THEN 'TRX_LINE_DIST_ID' 
54357                 WHEN 4 THEN 'TRX_DISTRIBUTION_TYPE' 
54358                 WHEN 5 THEN 'TRX_LINE_DIST_AMT' 
54359                 WHEN 6 THEN 'TRX_LINE_CUR_CONVERSION_DATE' 
54360                 WHEN 7 THEN 'TRX_LINE_CUR_CONVERSION_RATE' 
54361                 WHEN 8 THEN 'TRX_LINE_CUR_CONVERSION_TYPE' 
54362                 WHEN 9 THEN 'TRX_LINE_ACCTD_AMT' 
54363                 
54364                 ELSE null
54365               END                           source_code
54366             , CASE r
54367                 WHEN 1 THEN TO_CHAR(l4.TRX_LINE_DIST_CCID)
54368                 WHEN 2 THEN TO_CHAR(l4.TRX_LINE_DIST_ACCOUNT_CLASS)
54369                 WHEN 3 THEN TO_CHAR(l4.TRX_LINE_DIST_ID)
54370                 WHEN 4 THEN TO_CHAR(l4.TRX_DISTRIBUTION_TYPE)
54371                 WHEN 5 THEN TO_CHAR(l4.TRX_LINE_DIST_AMT)
54372                 WHEN 6 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_DATE)
54373                 WHEN 7 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_RATE)
54374                 WHEN 8 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_TYPE)
54375                 WHEN 9 THEN TO_CHAR(l3.TRX_LINE_ACCTD_AMT)
54376                 
54377                 ELSE null
54378               END                           source_value
54379             , null              source_meaning
54380          FROM  xla_events_gt     xet  
54381         , AR_CUST_TRX_LINES_BASE_V  l3
54382         , AR_CUST_TRX_LINES_L_V  l4
54383             , (select rownum r from all_objects where rownum <= 9 and owner = p_apps_owner)
54384         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
54385           AND xet.event_class_code = C_EVENT_CLASS_CODE
54386             AND l3.event_id          = xet.event_id
54387   AND l4.event_id    = l3.event_id
54388   AND l4.line_number = l3.line_number
54389 
54390 )
54391 ;
54392 --
54393 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
54394 
54395       trace
54396          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
54397          ,p_level    => C_LEVEL_STATEMENT
54398          ,p_module   => l_log_module);
54399 
54400 END IF;
54401 
54402 
54403 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
54404       trace
54405          (p_msg      => 'END of insert_sources_103'
54406          ,p_level    => C_LEVEL_PROCEDURE
54407          ,p_module   => l_log_module);
54408 END IF;
54409 EXCEPTION
54410   WHEN xla_exceptions_pkg.application_exception THEN
54411       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
54412             trace
54413                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
54414                ,p_level    => C_LEVEL_EXCEPTION
54415                ,p_module   => l_log_module);
54416       END IF;
54417       RAISE;
54418   WHEN OTHERS THEN
54419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
54420             trace
54421                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
54422                ,p_level    => C_LEVEL_EXCEPTION
54423                ,p_module   => l_log_module);
54424        END IF;
54425        xla_exceptions_pkg.raise_message
54426            (p_location => 'XLA_00222_AAD_S_000008_PKG.insert_sources_103');
54427 END insert_sources_103;
54428 --
54429 
54430 ---------------------------------------
54431 --
54432 -- PRIVATE FUNCTION
54433 --         EventClass_103
54434 --
54435 ----------------------------------------
54436 --
54437 FUNCTION EventClass_103
54438        (p_application_id         IN NUMBER
54439        ,p_base_ledger_id         IN NUMBER
54440        ,p_target_ledger_id       IN NUMBER
54441        ,p_language               IN VARCHAR2
54442        ,p_currency_code          IN VARCHAR2
54443        ,p_sla_ledger_id          IN NUMBER
54444        ,p_pad_start_date         IN DATE
54445        ,p_pad_end_date           IN DATE
54446        ,p_primary_ledger_id      IN NUMBER)
54447 RETURN BOOLEAN IS
54448 --
54449 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CHARGEBACK_ALL';
54450 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CHARGEBACK';
54451 
54452 l_calculate_acctd_flag   VARCHAR2(1) :='N';
54453 l_calculate_g_l_flag     VARCHAR2(1) :='N';
54454 --
54455 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
54456 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
54457 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
54458 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
54459 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
54463 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
54460 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
54461 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
54462 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
54464 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
54465 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
54466 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
54467 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
54468 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
54469 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
54470 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
54471 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
54472 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
54473 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
54474 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
54475 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
54476 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
54477 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
54478 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
54479 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
54480 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
54481 
54482 l_event_id                             NUMBER;
54483 l_previous_event_id                    NUMBER;
54484 l_first_event_id                       NUMBER;
54485 l_last_event_id                        NUMBER;
54486 
54487 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
54488 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
54489 --
54490 --
54491 l_result                    BOOLEAN := TRUE;
54492 l_rows                      NUMBER  := 1000;
54493 l_event_type_name           VARCHAR2(80) := 'All';
54494 l_event_class_name          VARCHAR2(80) := 'Chargeback';
54495 l_description               VARCHAR2(4000);
54496 l_transaction_reversal      NUMBER;
54497 l_ae_header_id              NUMBER;
54498 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
54499 l_log_module                VARCHAR2(240);
54500 --
54501 l_acct_reversal_source      VARCHAR2(30);
54502 l_trx_reversal_source       VARCHAR2(30);
54503 
54504 l_continue_with_lines       BOOLEAN := TRUE;
54505 --
54506 l_acc_rev_gl_date_source    DATE;                      -- 4262811
54507 --
54508 type t_array_event_id is table of number index by binary_integer;
54509 
54510 l_rec_array_event                    t_rec_array_event;
54511 l_null_rec_array_event               t_rec_array_event;
54512 l_array_ae_header_id                 xla_number_array_type;
54513 l_actual_flag                        VARCHAR2(1) := NULL;
54514 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
54515 l_balance_type_code                  VARCHAR2(1) :=NULL;
54516 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
54517 
54518 --
54519 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
54520 --
54521 
54522 TYPE t_array_source_23 IS TABLE OF AR_BILL_TO_CUSTOMERS_S_V.BILL_CUST_ACCOUNT_ID%TYPE INDEX BY BINARY_INTEGER;
54523 TYPE t_array_source_24 IS TABLE OF AR_BILL_TO_SITE_USES_S_V.BILL_USES_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
54524 TYPE t_array_source_25 IS TABLE OF AR_TRANSACTIONS_S_V.XLA_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
54525 TYPE t_array_source_30 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_INVOICE_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
54526 TYPE t_array_source_75 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
54527 TYPE t_array_source_76 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
54528 TYPE t_array_source_77 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
54529 
54530 TYPE t_array_source_4 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
54531 TYPE t_array_source_26 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ACCOUNT_CLASS%TYPE INDEX BY BINARY_INTEGER;
54532 TYPE t_array_source_27 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ID%TYPE INDEX BY BINARY_INTEGER;
54533 TYPE t_array_source_28 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
54534 TYPE t_array_source_29 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_AMT%TYPE INDEX BY BINARY_INTEGER;
54535 TYPE t_array_source_31 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
54536 TYPE t_array_source_32 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
54537 TYPE t_array_source_33 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
54538 TYPE t_array_source_34 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
54539 
54540 l_array_source_23              t_array_source_23;
54541 l_array_source_24              t_array_source_24;
54542 l_array_source_25              t_array_source_25;
54543 l_array_source_30              t_array_source_30;
54544 l_array_source_75              t_array_source_75;
54545 l_array_source_76              t_array_source_76;
54546 l_array_source_77              t_array_source_77;
54547 
54548 l_array_source_4      t_array_source_4;
54549 l_array_source_26      t_array_source_26;
54553 l_array_source_31      t_array_source_31;
54550 l_array_source_27      t_array_source_27;
54551 l_array_source_28      t_array_source_28;
54552 l_array_source_29      t_array_source_29;
54554 l_array_source_32      t_array_source_32;
54555 l_array_source_33      t_array_source_33;
54556 l_array_source_34      t_array_source_34;
54557 
54558 --
54559 CURSOR header_cur
54560 IS
54561 SELECT /*+ leading(xet) cardinality(xet,1) */
54562 -- Event Class Code: CHARGEBACK
54563     xet.entity_id
54564    ,xet.legal_entity_id
54565    ,xet.entity_code
54566    ,xet.transaction_number
54567    ,xet.event_id
54568    ,xet.event_class_code
54569    ,xet.event_type_code
54570    ,xet.event_number
54571    ,xet.event_date
54572    ,xet.transaction_date
54573    ,xet.reference_num_1
54574    ,xet.reference_num_2
54575    ,xet.reference_num_3
54576    ,xet.reference_num_4
54577    ,xet.reference_char_1
54578    ,xet.reference_char_2
54579    ,xet.reference_char_3
54580    ,xet.reference_char_4
54581    ,xet.reference_date_1
54582    ,xet.reference_date_2
54583    ,xet.reference_date_3
54584    ,xet.reference_date_4
54585    ,xet.event_created_by
54586    ,xet.budgetary_control_flag 
54587   , h1.BILL_CUST_ACCOUNT_ID    source_23
54588   , h2.BILL_USES_SITE_USE_ID    source_24
54589   , h5.XLA_PARTY_TYPE    source_25
54590   , h5.TRX_INVOICE_CURRENCY_CODE    source_30
54591   , h5.TRX_DOC_SEQUENCE_CATEGORY    source_75
54592   , h5.TRX_DOC_SEQUENCE_ID    source_76
54593   , h5.TRX_DOC_SEQUENCE_VALUE    source_77
54594   FROM xla_events_gt     xet 
54595   , AR_BILL_TO_CUSTOMERS_S_V  h1
54596   , AR_BILL_TO_SITE_USES_S_V  h2
54597   , AR_TRANSACTIONS_S_V  h5
54598  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
54599    and xet.event_class_code = C_EVENT_CLASS_CODE
54600    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
54601   AND h2.event_id  = h1.event_id
54602   AND h5.event_id  = h1.event_id
54603 
54604  ORDER BY event_id
54605 ;
54606 
54607 
54608 --
54609 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
54610 IS
54611 SELECT  /*+ leading(xet) cardinality(xet,1) */
54612 -- Event Class Code: CHARGEBACK
54613     xet.entity_id
54614    ,xet.legal_entity_id
54615    ,xet.entity_code
54616    ,xet.transaction_number
54617    ,xet.event_id
54618    ,xet.event_class_code
54619    ,xet.event_type_code
54620    ,xet.event_number
54621    ,xet.event_date
54622    ,xet.transaction_date
54623    ,xet.reference_num_1
54624    ,xet.reference_num_2
54625    ,xet.reference_num_3
54626    ,xet.reference_num_4
54627    ,xet.reference_char_1
54628    ,xet.reference_char_2
54629    ,xet.reference_char_3
54630    ,xet.reference_char_4
54631    ,xet.reference_date_1
54632    ,xet.reference_date_2
54633    ,xet.reference_date_3
54634    ,xet.reference_date_4
54635    ,xet.event_created_by
54636    ,xet.budgetary_control_flag
54637  , l3.LINE_NUMBER  
54638   , l4.TRX_LINE_DIST_CCID    source_4
54639   , l4.TRX_LINE_DIST_ACCOUNT_CLASS    source_26
54640   , l4.TRX_LINE_DIST_ID    source_27
54641   , l4.TRX_DISTRIBUTION_TYPE    source_28
54642   , l4.TRX_LINE_DIST_AMT    source_29
54643   , l3.TRX_LINE_CUR_CONVERSION_DATE    source_31
54644   , l3.TRX_LINE_CUR_CONVERSION_RATE    source_32
54645   , l3.TRX_LINE_CUR_CONVERSION_TYPE    source_33
54646   , l3.TRX_LINE_ACCTD_AMT    source_34
54647   FROM xla_events_gt     xet 
54648   , AR_CUST_TRX_LINES_BASE_V  l3
54649   , AR_CUST_TRX_LINES_L_V  l4
54650  WHERE xet.event_id between x_first_event_id and x_last_event_id
54651    and xet.event_date between p_pad_start_date and p_pad_end_date
54652    and xet.event_class_code = C_EVENT_CLASS_CODE
54653    and xet.event_status_code <> 'N'   AND l3.event_id      = xet.event_id
54654   AND l4.event_id    = l3.event_id
54655   AND l4.line_number = l3.line_number
54656 ;
54657 
54658 --
54659 BEGIN
54660 IF g_log_enabled THEN
54661    l_log_module := C_DEFAULT_MODULE||'.EventClass_103';
54662 END IF;
54663 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
54664    trace
54665       (p_msg      => 'BEGIN of EventClass_103'
54666       ,p_level    => C_LEVEL_PROCEDURE
54667       ,p_module   => l_log_module);
54668 END IF;
54669 
54670 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
54671    trace
54672       (p_msg      => 'p_application_id = '||p_application_id||
54676                      ' - p_currency_code = '||p_currency_code||
54673                      ' - p_base_ledger_id = '||p_base_ledger_id||
54674                      ' - p_target_ledger_id  = '||p_target_ledger_id||
54675                      ' - p_language = '||p_language||
54677                      ' - p_sla_ledger_id = '||p_sla_ledger_id
54678       ,p_level    => C_LEVEL_STATEMENT
54679       ,p_module   => l_log_module);
54680 END IF;
54681 --
54682 -- initialze arrays
54683 --
54684 g_array_event.DELETE;
54685 l_rec_array_event := l_null_rec_array_event;
54686 --
54687 --------------------------------------
54688 -- 4262811 Initialze MPA Line Number
54689 --------------------------------------
54690 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
54691 
54692 --
54693 
54694 --
54695 OPEN header_cur;
54696 --
54697 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
54698    trace
54699    (p_msg      => 'SQL - FETCH header_cur'
54700    ,p_level    => C_LEVEL_STATEMENT
54701    ,p_module   => l_log_module);
54702 END IF;
54703 --
54704 LOOP
54705 FETCH header_cur BULK COLLECT INTO
54706         l_array_entity_id
54707       , l_array_legal_entity_id
54708       , l_array_entity_code
54709       , l_array_transaction_num
54710       , l_array_event_id
54711       , l_array_class_code
54712       , l_array_event_type
54713       , l_array_event_number
54714       , l_array_event_date
54715       , l_array_transaction_date
54716       , l_array_reference_num_1
54717       , l_array_reference_num_2
54718       , l_array_reference_num_3
54719       , l_array_reference_num_4
54720       , l_array_reference_char_1
54721       , l_array_reference_char_2
54722       , l_array_reference_char_3
54723       , l_array_reference_char_4
54724       , l_array_reference_date_1
54725       , l_array_reference_date_2
54726       , l_array_reference_date_3
54727       , l_array_reference_date_4
54728       , l_array_event_created_by
54729       , l_array_budgetary_control_flag 
54730       , l_array_source_23
54731       , l_array_source_24
54732       , l_array_source_25
54733       , l_array_source_30
54734       , l_array_source_75
54735       , l_array_source_76
54736       , l_array_source_77
54737       LIMIT l_rows;
54738 --
54739 IF (C_LEVEL_EVENT >= g_log_level) THEN
54740    trace
54741    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
54742    ,p_level    => C_LEVEL_EVENT
54743    ,p_module   => l_log_module);
54744 END IF;
54745 --
54746 EXIT WHEN l_array_entity_id.COUNT = 0;
54747 
54748 -- initialize arrays
54749 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
54750 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
54751 
54752 --
54753 -- Bug 4458708
54754 --
54755 XLA_AE_LINES_PKG.g_LineNumber := 0;
54756 
54757 
54758 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
54759 g_last_hdr_idx := l_array_event_id.LAST;
54760 --
54761 -- loop for the headers. Each iteration is for each header extract row
54762 -- fetched in header cursor
54763 --
54764 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
54765 
54766 --
54767 -- set event info as cache for other routines to refer event attributes
54768 --
54769 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
54770    (p_application_id           => p_application_id
54771    ,p_primary_ledger_id        => p_primary_ledger_id
54772    ,p_base_ledger_id           => p_base_ledger_id
54773    ,p_target_ledger_id         => p_target_ledger_id
54774    ,p_entity_id                => l_array_entity_id(hdr_idx)
54775    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
54776    ,p_entity_code              => l_array_entity_code(hdr_idx)
54777    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
54778    ,p_event_id                 => l_array_event_id(hdr_idx)
54779    ,p_event_class_code         => l_array_class_code(hdr_idx)
54780    ,p_event_type_code          => l_array_event_type(hdr_idx)
54781    ,p_event_number             => l_array_event_number(hdr_idx)
54782    ,p_event_date               => l_array_event_date(hdr_idx)
54783    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
54784    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
54785    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
54786    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
54787    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
54788    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
54789    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
54790    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
54791    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
54792    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
54793    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
54794    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
54795    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
54796    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
54797    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
54798 
54799 --
54800 -- set the status of entry to C_VALID (0)
54801 --
54802 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
54803 
54804 --
54805 -- initialize a row for ae header
54806 --
54810 
54807 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
54808 
54809 l_event_id := l_array_event_id(hdr_idx);
54811 --
54812 -- storing the hdr_idx for event. May be used by line cursor.
54813 --
54814 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
54815 
54816 --
54817 -- store sources from header extract. This can be improved to
54818 -- store only those sources from header extract that may be used in lines
54819 --
54820 
54821 g_array_event(l_event_id).array_value_num('source_23') := l_array_source_23(hdr_idx);
54822 g_array_event(l_event_id).array_value_num('source_24') := l_array_source_24(hdr_idx);
54823 g_array_event(l_event_id).array_value_char('source_25') := l_array_source_25(hdr_idx);
54824 g_array_event(l_event_id).array_value_char('source_30') := l_array_source_30(hdr_idx);
54825 g_array_event(l_event_id).array_value_char('source_75') := l_array_source_75(hdr_idx);
54826 g_array_event(l_event_id).array_value_num('source_76') := l_array_source_76(hdr_idx);
54827 g_array_event(l_event_id).array_value_num('source_77') := l_array_source_77(hdr_idx);
54828 
54829 --
54830 -- initilaize the status of ae headers for diffrent balance types
54831 -- the status is initialised to C_NOT_CREATED (2)
54832 --
54833 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
54834 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
54835 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
54836 
54837 --
54838 -- call api to validate and store accounting attributes for header
54839 --
54840 
54841 ------------------------------------------------------------
54842 -- Accrual Reversal : to get date for Standard Source (NONE)
54843 ------------------------------------------------------------
54844 l_acc_rev_gl_date_source := NULL;
54845 
54846      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
54847       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_75');
54848      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
54849       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_76');
54850      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
54851       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_77');
54852      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
54853       l_rec_acct_attrs.array_date_value(4) := 
54854 xla_ae_sources_pkg.GetSystemSourceDate(
54855    p_source_code           => 'XLA_EVENT_DATE'
54856  , p_source_type_code      => 'Y'
54857  , p_source_application_id =>  602
54858 );
54859 
54860 
54861 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
54862 
54863 XLA_AE_HEADER_PKG.SetJeCategoryName;
54864 
54865 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
54866 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
54867 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
54868 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
54869 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
54870 
54871 
54872 -- No header level analytical criteria
54873 
54874 --
54875 --accounting attribute enhancement, bug 3612931
54876 --
54877 l_trx_reversal_source := SUBSTR(NULL, 1,30);
54878 
54879 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
54880    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
54881 
54882    xla_accounting_err_pkg.build_message
54883       (p_appli_s_name            => 'XLA'
54884       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
54885       ,p_token_1                 => 'ACCT_ATTR_NAME'
54886       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
54887       ,p_token_2                 => 'PRODUCT_NAME'
54888       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
54889       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
54890       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
54891       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
54892 
54893 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
54894    --
54895    -- following sets the accounting attributes needed to reverse
54896    -- accounting for a distributeion
54897    --
54898    xla_ae_lines_pkg.SetTrxReversalAttrs
54899       (p_event_id              => l_event_id
54900       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
54901       ,p_trx_reversal_source   => l_trx_reversal_source);
54902 
54903 END IF;
54904 
54905 
54906 ----------------------------------------------------------------
54907 -- 4262811 -  update the header statuses to invalid in need be
54908 ----------------------------------------------------------------
54909 --
54910 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
54911 
54912 
54913   -----------------------------------------------
54914   -- No accrual reversal for the event class/type
54915   -----------------------------------------------
54916 ----------------------------------------------------------------
54917 
54918 --
54919 -- this ends the header loop iteration for one bulk fetch
54920 --
54921 END LOOP;
54922 
54926 --
54923 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
54924 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
54925 
54927 -- insert dummy rows into lines gt table that were created due to
54928 -- transaction reversals
54929 --
54930 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
54931    l_result := XLA_AE_LINES_PKG.InsertLines;
54932 END IF;
54933 
54934 --
54935 -- reset the temp_line_num for each set of events fetched from header
54936 -- cursor rather than doing it for each new event in line cursor
54937 -- Bug 3939231
54938 --
54939 xla_ae_lines_pkg.g_temp_line_num := 0;
54940 
54941 
54942 
54943 --
54944 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
54945 --
54946 --
54947 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
54948 
54949       trace
54950          (p_msg      => 'SQL - FETCH line_cur'
54951          ,p_level    => C_LEVEL_STATEMENT
54952          ,p_module   => l_log_module);
54953 
54954 END IF;
54955 --
54956 --
54957 LOOP
54958   --
54959   FETCH line_cur BULK COLLECT INTO
54960         l_array_entity_id
54961       , l_array_legal_entity_id
54962       , l_array_entity_code
54963       , l_array_transaction_num
54964       , l_array_event_id
54965       , l_array_class_code
54966       , l_array_event_type
54967       , l_array_event_number
54968       , l_array_event_date
54969       , l_array_transaction_date
54970       , l_array_reference_num_1
54971       , l_array_reference_num_2
54972       , l_array_reference_num_3
54973       , l_array_reference_num_4
54974       , l_array_reference_char_1
54975       , l_array_reference_char_2
54976       , l_array_reference_char_3
54977       , l_array_reference_char_4
54978       , l_array_reference_date_1
54979       , l_array_reference_date_2
54980       , l_array_reference_date_3
54981       , l_array_reference_date_4
54982       , l_array_event_created_by
54983       , l_array_budgetary_control_flag
54984       , l_array_extract_line_num 
54985       , l_array_source_4
54986       , l_array_source_26
54987       , l_array_source_27
54988       , l_array_source_28
54989       , l_array_source_29
54990       , l_array_source_31
54991       , l_array_source_32
54992       , l_array_source_33
54993       , l_array_source_34
54994       LIMIT l_rows;
54995 
54996   --
54997   IF (C_LEVEL_EVENT >= g_log_level) THEN
54998             trace
54999                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
55000                ,p_level    => C_LEVEL_EVENT
55001                ,p_module   => l_log_module);
55002   END IF;
55003   --
55004   EXIT WHEN l_array_entity_id.count = 0;
55005 
55006   XLA_AE_LINES_PKG.g_rec_lines := null;
55007 
55008 --
55009 -- Bug 4458708
55010 --
55011 XLA_AE_LINES_PKG.g_LineNumber := 0;
55012 --
55013 --
55014 
55015 FOR Idx IN 1..l_array_event_id.count LOOP
55016    --
55017    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
55018    --
55019    l_event_id := l_array_event_id(idx);  -- 5648433
55020 
55021    --
55022    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
55023    --
55024 
55025    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
55026              (g_array_event(l_event_id).array_value_num('header_index'))
55027          ,'N'
55028          ) <> 'Y'
55029    THEN
55030       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
55031          trace
55032             (p_msg      => 'Trancaction revesal option is not Y '
55033             ,p_level    => C_LEVEL_STATEMENT
55034             ,p_module   => l_log_module);
55035       END IF;
55036 
55037 --
55038 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
55039 --
55040 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
55041 --
55042 -- set event info as cache for other routines to refer event attributes
55043 --
55044 
55045 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
55046    l_previous_event_id := l_event_id;
55047 
55048    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
55049       (p_application_id           => p_application_id
55050       ,p_primary_ledger_id        => p_primary_ledger_id
55051       ,p_base_ledger_id           => p_base_ledger_id
55052       ,p_target_ledger_id         => p_target_ledger_id
55053       ,p_entity_id                => l_array_entity_id(Idx)
55054       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
55055       ,p_entity_code              => l_array_entity_code(Idx)
55056       ,p_transaction_num          => l_array_transaction_num(Idx)
55057       ,p_event_id                 => l_array_event_id(Idx)
55058       ,p_event_class_code         => l_array_class_code(Idx)
55059       ,p_event_type_code          => l_array_event_type(Idx)
55060       ,p_event_number             => l_array_event_number(Idx)
55061       ,p_event_date               => l_array_event_date(Idx)
55062       ,p_transaction_date         => l_array_transaction_date(Idx)
55063       ,p_reference_num_1          => l_array_reference_num_1(Idx)
55064       ,p_reference_num_2          => l_array_reference_num_2(Idx)
55065       ,p_reference_num_3          => l_array_reference_num_3(Idx)
55066       ,p_reference_num_4          => l_array_reference_num_4(Idx)
55067       ,p_reference_char_1         => l_array_reference_char_1(Idx)
55068       ,p_reference_char_2         => l_array_reference_char_2(Idx)
55072       ,p_reference_date_2         => l_array_reference_date_2(Idx)
55069       ,p_reference_char_3         => l_array_reference_char_3(Idx)
55070       ,p_reference_char_4         => l_array_reference_char_4(Idx)
55071       ,p_reference_date_1         => l_array_reference_date_1(Idx)
55073       ,p_reference_date_3         => l_array_reference_date_3(Idx)
55074       ,p_reference_date_4         => l_array_reference_date_4(Idx)
55075       ,p_event_created_by         => l_array_event_created_by(Idx)
55076       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
55077        --
55078 END IF;
55079 
55080 
55081 
55082 --
55083 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
55084 
55085 l_acct_reversal_source := SUBSTR(NULL, 1,30);
55086 
55087 IF l_continue_with_lines THEN
55088    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
55089       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
55090 
55091       xla_accounting_err_pkg.build_message
55092          (p_appli_s_name            => 'XLA'
55093          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
55094          ,p_token_1                 => 'LINE_NUMBER'
55095          ,p_value_1                 => l_array_extract_line_num(Idx)
55096          ,p_token_2                 => 'PRODUCT_NAME'
55097          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
55098          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
55099          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
55100          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
55101 
55102    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
55103       --
55104       -- following sets the accounting attributes needed to reverse
55105       -- accounting for a distributeion
55106       --
55107 
55108       --
55109       -- 5217187
55110       --
55111       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
55112       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
55113                                        g_array_event(l_event_id).array_value_num('header_index'));
55114       --
55115       --
55116 
55117       -- No reversal code generated
55118 
55119       xla_ae_lines_pkg.SetAcctReversalAttrs
55120          (p_event_id             => l_event_id
55121          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
55122          ,p_calculate_acctd_flag => l_calculate_acctd_flag
55123          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
55124    END IF;
55125 
55126    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
55127        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
55128 
55129 --
55130 AcctLineType_22 (
55131  p_application_id  => p_application_id
55132  ,p_event_id     => l_event_id
55133  ,p_calculate_acctd_flag => l_calculate_acctd_flag
55134  ,p_calculate_g_l_flag => l_calculate_g_l_flag
55135  ,p_actual_flag => l_actual_flag
55136  ,p_balance_type_code => l_balance_type_code
55137  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
55138  
55139  , p_source_4 => l_array_source_4(Idx)
55140  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
55141  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
55142  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
55143  , p_source_26 => l_array_source_26(Idx)
55144  , p_source_27 => l_array_source_27(Idx)
55145  , p_source_28 => l_array_source_28(Idx)
55146  , p_source_29 => l_array_source_29(Idx)
55147  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
55148  , p_source_31 => l_array_source_31(Idx)
55149  , p_source_32 => l_array_source_32(Idx)
55150  , p_source_33 => l_array_source_33(Idx)
55151  , p_source_34 => l_array_source_34(Idx)
55152  );
55153 If(l_balance_type_code = 'A') THEN
55154   l_actual_gain_loss_ref := l_gain_or_loss_ref;
55155 END IF;
55156 
55157 --
55158 
55159 
55160 --
55161 AcctLineType_23 (
55162  p_application_id  => p_application_id
55163  ,p_event_id     => l_event_id
55164  ,p_calculate_acctd_flag => l_calculate_acctd_flag
55165  ,p_calculate_g_l_flag => l_calculate_g_l_flag
55166  ,p_actual_flag => l_actual_flag
55167  ,p_balance_type_code => l_balance_type_code
55171  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
55168  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
55169  
55170  , p_source_4 => l_array_source_4(Idx)
55172  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
55173  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
55174  , p_source_26 => l_array_source_26(Idx)
55175  , p_source_27 => l_array_source_27(Idx)
55176  , p_source_28 => l_array_source_28(Idx)
55177  , p_source_29 => l_array_source_29(Idx)
55178  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
55179  , p_source_31 => l_array_source_31(Idx)
55180  , p_source_32 => l_array_source_32(Idx)
55181  , p_source_33 => l_array_source_33(Idx)
55182  , p_source_34 => l_array_source_34(Idx)
55183  );
55184 If(l_balance_type_code = 'A') THEN
55185   l_actual_gain_loss_ref := l_gain_or_loss_ref;
55186 END IF;
55187 
55188 --
55189 
55190       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
55191       -- or secondary ledger that has different currency with primary
55192       -- or alc that is calculated by sla
55193       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
55194             (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'))
55195 
55196 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
55197 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
55198           AND (l_actual_flag = 'A')) THEN
55199         XLA_AE_LINES_PKG.CreateGainOrLossLines(
55200           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
55201          ,p_application_id   => p_application_id
55202          ,p_amb_context_code => 'DEFAULT'
55203          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
55204          ,p_event_class_code => C_EVENT_CLASS_CODE
55205          ,p_event_type_code  => C_EVENT_TYPE_CODE
55206          
55207          ,p_gain_ccid        => -1
55208          ,p_loss_ccid        => -1
55209 
55210          ,p_actual_flag      => l_actual_flag
55211          ,p_enc_flag         => null
55212          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
55213          ,p_enc_g_l_ref      => null
55214          );
55215       END IF;
55216    END IF;
55217 END IF;
55218 
55219    ELSE
55220       --
55221       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
55222       --
55223       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
55224          trace
55225             (p_msg      => 'Trancaction revesal option is Y'
55226             ,p_level    => C_LEVEL_STATEMENT
55227             ,p_module   => l_log_module);
55228       END IF;
55229    END IF;
55230 
55231 END LOOP;
55232 l_result := XLA_AE_LINES_PKG.InsertLines ;
55233 end loop;
55234 close line_cur;
55235 
55236 
55237 --
55238 -- insert headers into xla_ae_headers_gt table
55239 --
55240 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
55241 
55242 -- insert into errors table here.
55243 
55244 END LOOP;
55245 
55246 --
55247 -- 4865292
55248 --
55249 -- Compare g_hdr_extract_count with event count in
55250 -- CreateHeadersAndLines.
55251 --
55252 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
55253 
55254 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
55255    trace (p_msg     => '# rows extracted from header extract objects '
55256                     || ' (running total): '
55257                     || g_hdr_extract_count
55258          ,p_level   => C_LEVEL_STATEMENT
55259          ,p_module  => l_log_module);
55260 END IF;
55261 
55262 CLOSE header_cur;
55263 --
55264 
55265 --
55266 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
55267    trace
55268       (p_msg      => 'END of EventClass_103'
55269       ,p_level    => C_LEVEL_PROCEDURE
55270       ,p_module   => l_log_module);
55271 END IF;
55272 --
55273 RETURN l_result;
55274 EXCEPTION
55275 WHEN xla_exceptions_pkg.application_exception THEN
55276    
55277 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
55278 
55279    
55280 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
55281 
55282    RAISE;
55283 
55284 WHEN NO_DATA_FOUND THEN
55285 
55286 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
55287 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
55288 
55289 FOR header_record IN header_cur
55290 LOOP
55291     l_array_header_events(header_record.event_id) := header_record.event_id;
55292 END LOOP;
55293 
55294 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
55295 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
55296 
55297 fnd_file.put_line(fnd_file.LOG, '                    ');
55298 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
55299 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
55300 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
55301 
55302 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
55306         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
55303 LOOP
55304 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
55305 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
55307 	END IF;
55308 END LOOP;
55309 
55310 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
55311 fnd_file.put_line(fnd_file.LOG, '                    ');
55312 
55313 
55314 xla_exceptions_pkg.raise_message
55315       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_103');
55316 
55317 
55318 WHEN OTHERS THEN
55319    xla_exceptions_pkg.raise_message
55320       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_103');
55321 END EventClass_103;
55322 --
55323 
55324 ---------------------------------------
55325 --
55326 -- PRIVATE PROCEDURE
55327 --         insert_sources_104
55328 --
55329 ----------------------------------------
55330 --
55331 PROCEDURE insert_sources_104(
55332                                 p_target_ledger_id       IN NUMBER
55333                               , p_language               IN VARCHAR2
55334                               , p_sla_ledger_id          IN NUMBER
55335                               , p_pad_start_date         IN DATE
55336                               , p_pad_end_date           IN DATE
55337                          )
55338 IS
55339 
55340 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CREDIT_MEMO_ALL';
55341 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CREDIT_MEMO';
55342 p_apps_owner                   VARCHAR2(30);
55343 l_log_module                   VARCHAR2(240);
55344 BEGIN
55345 IF g_log_enabled THEN
55346       l_log_module := C_DEFAULT_MODULE||'.insert_sources_104';
55347 END IF;
55348 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
55349 
55350       trace
55351          (p_msg      => 'BEGIN of insert_sources_104'
55352          ,p_level    => C_LEVEL_PROCEDURE
55353          ,p_module   => l_log_module);
55354 
55355 END IF;
55356 
55357 -- select APPS owner
55358 SELECT oracle_username
55359   INTO p_apps_owner
55360   FROM fnd_oracle_userid
55361  WHERE read_only_flag = 'U'
55362 ;
55363 
55364 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
55365       trace
55366          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
55367                         ' - p_language = '||p_language||
55368                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
55369                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
55370                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
55371                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
55372          ,p_level    => C_LEVEL_STATEMENT
55373          ,p_module   => l_log_module);
55374 END IF;
55375 
55376 
55377 --
55378 INSERT INTO xla_diag_sources --hdr2
55379 (
55380         event_id
55381       , ledger_id
55382       , sla_ledger_id
55383       , description_language
55384       , object_name
55385       , object_type_code
55386       , line_number
55387       , source_application_id
55388       , source_type_code
55389       , source_code
55390       , source_value
55391       , source_meaning
55392       , created_by
55393       , creation_date
55394       , last_update_date
55395       , last_updated_by
55396       , last_update_login
55397       , program_update_date
55398       , program_application_id
55399       , program_id
55400       , request_id
55401 )
55402 SELECT
55403         event_id
55404       , p_target_ledger_id
55405       , p_sla_ledger_id
55406       , p_language
55407       , object_name
55408       , object_type_code
55409       , line_number
55410       , source_application_id
55411       , source_type_code
55412       , source_code
55413       , SUBSTR(source_value ,1,1996)
55414       , SUBSTR(source_meaning ,1,200)
55415       , xla_environment_pkg.g_Usr_Id
55416       , TRUNC(SYSDATE)
55417       , TRUNC(SYSDATE)
55418       , xla_environment_pkg.g_Usr_Id
55419       , xla_environment_pkg.g_Login_Id
55420       , TRUNC(SYSDATE)
55421       , xla_environment_pkg.g_Prog_Appl_Id
55422       , xla_environment_pkg.g_Prog_Id
55423       , xla_environment_pkg.g_Req_Id
55424   FROM (
55425        SELECT xet.event_id                  event_id
55426             , 0                          line_number
55427             , CASE r
55428                WHEN 1 THEN 'AR_CREDIT_MEMO_H_V' 
55432                 WHEN 5 THEN 'AR_CREDIT_MEMO_H_V' 
55429                 WHEN 2 THEN 'AR_SYSTEM_PARAM_H_V' 
55430                 WHEN 3 THEN 'AR_SYSTEM_PARAM_H_V' 
55431                 WHEN 4 THEN 'AR_CREDIT_MEMO_H_V' 
55433                 WHEN 6 THEN 'AR_CM_BILL_TO_CUST_H_V' 
55434                 WHEN 7 THEN 'AR_CM_BILL_SITE_USES_H_V' 
55435                 WHEN 8 THEN 'AR_CREDIT_MEMO_H_V' 
55436                 
55437                ELSE null
55438               END                           object_name
55439             , CASE r
55440                 WHEN 1 THEN 'HEADER' 
55441                 WHEN 2 THEN 'HEADER' 
55442                 WHEN 3 THEN 'HEADER' 
55443                 WHEN 4 THEN 'HEADER' 
55444                 WHEN 5 THEN 'HEADER' 
55445                 WHEN 6 THEN 'HEADER' 
55446                 WHEN 7 THEN 'HEADER' 
55447                 WHEN 8 THEN 'HEADER' 
55448                 
55449                 ELSE null
55450               END                           object_type_code
55451             , CASE r
55452                 WHEN 1 THEN '222' 
55453                 WHEN 2 THEN '222' 
55454                 WHEN 3 THEN '222' 
55455                 WHEN 4 THEN '222' 
55456                 WHEN 5 THEN '222' 
55457                 WHEN 6 THEN '222' 
55458                 WHEN 7 THEN '222' 
55459                 WHEN 8 THEN '222' 
55460                 
55461                 ELSE null
55462               END                           source_application_id
55463             , 'S'             source_type_code
55464             , CASE r
55465                 WHEN 1 THEN 'CM_RECEIVABLE_CCID' 
55466                 WHEN 2 THEN 'CODE_COMBINATION_ID_GAIN' 
55467                 WHEN 3 THEN 'CODE_COMBINATION_ID_LOSS' 
55468                 WHEN 4 THEN 'XLA_PARTY_TYPE' 
55469                 WHEN 5 THEN 'CM_INVOICE_CURRENCY_CODE' 
55470                 WHEN 6 THEN 'CM_BILL_CUST_ACCOUNT_ID' 
55471                 WHEN 7 THEN 'CM_BILL_USES_SITE_USE_ID' 
55472                 WHEN 8 THEN 'CM_INVOICING_RULE_ID' 
55473                 
55474                 ELSE null
55475               END                           source_code
55476             , CASE r
55477                 WHEN 1 THEN TO_CHAR(h5.CM_RECEIVABLE_CCID)
55478                 WHEN 2 THEN TO_CHAR(h8.CODE_COMBINATION_ID_GAIN)
55479                 WHEN 3 THEN TO_CHAR(h8.CODE_COMBINATION_ID_LOSS)
55480                 WHEN 4 THEN TO_CHAR(h5.XLA_PARTY_TYPE)
55481                 WHEN 5 THEN TO_CHAR(h5.CM_INVOICE_CURRENCY_CODE)
55482                 WHEN 6 THEN TO_CHAR(h2.CM_BILL_CUST_ACCOUNT_ID)
55483                 WHEN 7 THEN TO_CHAR(h1.CM_BILL_USES_SITE_USE_ID)
55484                 WHEN 8 THEN TO_CHAR(h5.CM_INVOICING_RULE_ID)
55485                 
55486                 ELSE null
55487               END                           source_value
55488             , null              source_meaning
55489          FROM xla_events_gt     xet  
55490       , AR_CM_BILL_SITE_USES_H_V  h1
55491       , AR_CM_BILL_TO_CUST_H_V  h2
55492       , AR_CREDIT_MEMO_H_V  h5
55493       , AR_SYSTEM_PARAM_H_V  h8
55494              ,(select rownum r from all_objects where rownum <= 8 and owner = p_apps_owner)
55495          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
55496            AND xet.event_class_code = C_EVENT_CLASS_CODE
55497               AND h1.event_id = xet.event_id
55498   AND h2.event_id  = h1.event_id
55499   AND h5.event_id  = h1.event_id
55500   AND h8.event_id (+) = h1.event_id
55501 
55502 )
55503 ;
55504 --
55505 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
55506 
55507       trace
55508          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
55509          ,p_level    => C_LEVEL_STATEMENT
55510          ,p_module   => l_log_module);
55511 
55512 END IF;
55513 --
55514 
55515 
55516 
55517 --
55518 INSERT INTO xla_diag_sources  --line2
55519 (
55520         event_id
55521       , ledger_id
55522       , sla_ledger_id
55523       , description_language
55524       , object_name
55525       , object_type_code
55526       , line_number
55527       , source_application_id
55528       , source_type_code
55529       , source_code
55530       , source_value
55531       , source_meaning
55532       , created_by
55533       , creation_date
55534       , last_update_date
55535       , last_updated_by
55536       , last_update_login
55537       , program_update_date
55538       , program_application_id
55539       , program_id
55540       , request_id
55541 )
55542 SELECT  event_id
55543       , p_target_ledger_id
55544       , p_sla_ledger_id
55545       , p_language
55546       , object_name
55547       , object_type_code
55548       , line_number
55549       , source_application_id
55550       , source_type_code
55551       , source_code
55552       , SUBSTR(source_value,1,1996)
55553       , SUBSTR(source_meaning ,1,200)
55554       , xla_environment_pkg.g_Usr_Id
55555       , TRUNC(SYSDATE)
55556       , TRUNC(SYSDATE)
55557       , xla_environment_pkg.g_Usr_Id
55558       , xla_environment_pkg.g_Login_Id
55559       , TRUNC(SYSDATE)
55560       , xla_environment_pkg.g_Prog_Appl_Id
55561       , xla_environment_pkg.g_Prog_Id
55562       , xla_environment_pkg.g_Req_Id
55563   FROM (
55564        SELECT xet.event_id                  event_id
55565             , l3.line_number                 line_number
55566             , CASE r
55567                WHEN 1 THEN 'AR_CM_LINES_L_V' 
55568                 WHEN 2 THEN 'AR_DISTRIBUTIONS_L_V' 
55569                 WHEN 3 THEN 'AR_DISTRIBUTIONS_L_V' 
55570                 WHEN 4 THEN 'AR_RECEIVABLES_TRX_ACT_S_V' 
55574                 WHEN 8 THEN 'AR_CM_LINES_BASE_V' 
55571                 WHEN 5 THEN 'AR_DISTRIBUTIONS_L_V' 
55572                 WHEN 6 THEN 'AR_CM_LINES_BASE_V' 
55573                 WHEN 7 THEN 'AR_CM_LINES_BASE_V' 
55575                 WHEN 9 THEN 'AR_CM_LINES_BASE_V' 
55576                 WHEN 10 THEN 'AR_CM_LINES_BASE_V' 
55577                 WHEN 11 THEN 'AR_CM_LINES_BASE_V' 
55578                 WHEN 12 THEN 'AR_CM_LINES_BASE_V' 
55579                 WHEN 13 THEN 'AR_CM_LINES_L_V' 
55580                 WHEN 14 THEN 'AR_CM_LINES_L_V' 
55581                 WHEN 15 THEN 'AR_CM_LINES_L_V' 
55582                 
55583                ELSE null
55584               END                           object_name
55585             , CASE r
55586                 WHEN 1 THEN 'LINE' 
55587                 WHEN 2 THEN 'LINE' 
55588                 WHEN 3 THEN 'LINE' 
55589                 WHEN 4 THEN 'LINE' 
55590                 WHEN 5 THEN 'LINE' 
55591                 WHEN 6 THEN 'LINE' 
55592                 WHEN 7 THEN 'LINE' 
55593                 WHEN 8 THEN 'LINE' 
55594                 WHEN 9 THEN 'LINE' 
55595                 WHEN 10 THEN 'LINE' 
55596                 WHEN 11 THEN 'LINE' 
55597                 WHEN 12 THEN 'LINE' 
55598                 WHEN 13 THEN 'LINE' 
55599                 WHEN 14 THEN 'LINE' 
55600                 WHEN 15 THEN 'LINE' 
55601                 
55602                 ELSE null
55603               END                           object_type_code
55604             , CASE r
55605                 WHEN 1 THEN '222' 
55606                 WHEN 2 THEN '222' 
55607                 WHEN 3 THEN '222' 
55608                 WHEN 4 THEN '222' 
55609                 WHEN 5 THEN '222' 
55610                 WHEN 6 THEN '222' 
55611                 WHEN 7 THEN '222' 
55612                 WHEN 8 THEN '222' 
55613                 WHEN 9 THEN '222' 
55614                 WHEN 10 THEN '222' 
55615                 WHEN 11 THEN '222' 
55616                 WHEN 12 THEN '222' 
55617                 WHEN 13 THEN '222' 
55618                 WHEN 14 THEN '222' 
55619                 WHEN 15 THEN '222' 
55620                 
55621                 ELSE null
55622               END                           source_application_id
55623             , 'S'             source_type_code
55624             , CASE r
55625                 WHEN 1 THEN 'CM_LINE_DIST_CCID' 
55626                 WHEN 2 THEN 'DIST_CODE_COMBINATION_ID' 
55627                 WHEN 3 THEN 'DIST_SOURCE_TYPE' 
55628                 WHEN 4 THEN 'REC_ACT_TYPE' 
55629                 WHEN 5 THEN 'DIST_ENT_AMT' 
55630                 WHEN 6 THEN 'CM_DIST_IDENTIFER' 
55631                 WHEN 7 THEN 'CM_DIST_TYPE' 
55632                 WHEN 8 THEN 'CM_LINE_CUR_CONVERSION_DATE' 
55633                 WHEN 9 THEN 'CM_LINE_CUR_CONVERSION_RATE' 
55634                 WHEN 10 THEN 'CM_LINE_CUR_CONVERSION_TYPE' 
55635                 WHEN 11 THEN 'GAIN_LOSS_REF' 
55636                 WHEN 12 THEN 'CM_LINE_ACCTD_AMT' 
55637                 WHEN 13 THEN 'CM_TAX_LINE_ID' 
55638                 WHEN 14 THEN 'CM_LINE_DIST_ACCOUNT_CLASS' 
55639                 WHEN 15 THEN 'CM_LINE_DIST_AMT' 
55643             , CASE r
55640                 
55641                 ELSE null
55642               END                           source_code
55644                 WHEN 1 THEN TO_CHAR(l4.CM_LINE_DIST_CCID)
55645                 WHEN 2 THEN TO_CHAR(l6.DIST_CODE_COMBINATION_ID)
55646                 WHEN 3 THEN TO_CHAR(l6.DIST_SOURCE_TYPE)
55647                 WHEN 4 THEN TO_CHAR(l7.REC_ACT_TYPE)
55648                 WHEN 5 THEN TO_CHAR(l6.DIST_ENT_AMT)
55649                 WHEN 6 THEN TO_CHAR(l3.CM_DIST_IDENTIFER)
55650                 WHEN 7 THEN TO_CHAR(l3.CM_DIST_TYPE)
55651                 WHEN 8 THEN TO_CHAR(l3.CM_LINE_CUR_CONVERSION_DATE)
55652                 WHEN 9 THEN TO_CHAR(l3.CM_LINE_CUR_CONVERSION_RATE)
55653                 WHEN 10 THEN TO_CHAR(l3.CM_LINE_CUR_CONVERSION_TYPE)
55654                 WHEN 11 THEN TO_CHAR(l3.GAIN_LOSS_REF)
55655                 WHEN 12 THEN TO_CHAR(l3.CM_LINE_ACCTD_AMT)
55656                 WHEN 13 THEN TO_CHAR(l4.CM_TAX_LINE_ID)
55657                 WHEN 14 THEN TO_CHAR(l4.CM_LINE_DIST_ACCOUNT_CLASS)
55658                 WHEN 15 THEN TO_CHAR(l4.CM_LINE_DIST_AMT)
55659                 
55660                 ELSE null
55661               END                           source_value
55662             , null              source_meaning
55663          FROM  xla_events_gt     xet  
55664         , AR_CM_LINES_BASE_V  l3
55665         , AR_CM_LINES_L_V  l4
55666         , AR_DISTRIBUTIONS_L_V  l6
55667         , AR_RECEIVABLES_TRX_ACT_S_V  l7
55668             , (select rownum r from all_objects where rownum <= 15 and owner = p_apps_owner)
55669         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
55670           AND xet.event_class_code = C_EVENT_CLASS_CODE
55671             AND l3.event_id          = xet.event_id
55672   AND l4.event_id (+)    = l3.event_id
55673   AND l4.line_number (+) = l3.line_number
55674   AND l6.event_id (+)    = l3.event_id
55675   AND l6.line_number (+) = l3.line_number
55676   AND l7.event_id (+)    = l3.event_id
55677   AND l7.line_number (+) = l3.line_number
55678 
55679 )
55680 ;
55681 --
55682 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
55683 
55684       trace
55685          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
55686          ,p_level    => C_LEVEL_STATEMENT
55687          ,p_module   => l_log_module);
55688 
55689 END IF;
55690 
55691 
55692 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
55693       trace
55694          (p_msg      => 'END of insert_sources_104'
55695          ,p_level    => C_LEVEL_PROCEDURE
55696          ,p_module   => l_log_module);
55697 END IF;
55698 EXCEPTION
55699   WHEN xla_exceptions_pkg.application_exception THEN
55700       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
55701             trace
55702                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
55703                ,p_level    => C_LEVEL_EXCEPTION
55704                ,p_module   => l_log_module);
55705       END IF;
55706       RAISE;
55707   WHEN OTHERS THEN
55708       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
55709             trace
55710                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
55711                ,p_level    => C_LEVEL_EXCEPTION
55712                ,p_module   => l_log_module);
55713        END IF;
55714        xla_exceptions_pkg.raise_message
55715            (p_location => 'XLA_00222_AAD_S_000008_PKG.insert_sources_104');
55716 END insert_sources_104;
55717 --
55718 
55719 ---------------------------------------
55720 --
55721 -- PRIVATE FUNCTION
55722 --         EventClass_104
55723 --
55724 ----------------------------------------
55725 --
55726 FUNCTION EventClass_104
55727        (p_application_id         IN NUMBER
55728        ,p_base_ledger_id         IN NUMBER
55729        ,p_target_ledger_id       IN NUMBER
55730        ,p_language               IN VARCHAR2
55731        ,p_currency_code          IN VARCHAR2
55732        ,p_sla_ledger_id          IN NUMBER
55733        ,p_pad_start_date         IN DATE
55734        ,p_pad_end_date           IN DATE
55735        ,p_primary_ledger_id      IN NUMBER)
55736 RETURN BOOLEAN IS
55737 --
55738 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CREDIT_MEMO_ALL';
55739 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CREDIT_MEMO';
55740 
55741 l_calculate_acctd_flag   VARCHAR2(1) :='N';
55742 l_calculate_g_l_flag     VARCHAR2(1) :='Y';
55743 --
55744 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
55745 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
55746 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
55747 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
55748 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
55749 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
55750 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
55751 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
55752 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
55753 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
55754 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
55755 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
55756 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
55757 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
55758 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
55759 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
55760 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
55761 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
55765 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
55762 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
55763 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
55764 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
55766 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
55767 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
55768 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
55769 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
55770 
55771 l_event_id                             NUMBER;
55772 l_previous_event_id                    NUMBER;
55773 l_first_event_id                       NUMBER;
55774 l_last_event_id                        NUMBER;
55775 
55776 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
55777 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
55778 --
55779 --
55780 l_result                    BOOLEAN := TRUE;
55781 l_rows                      NUMBER  := 1000;
55782 l_event_type_name           VARCHAR2(80) := 'All';
55783 l_event_class_name          VARCHAR2(80) := 'Credit Memo';
55784 l_description               VARCHAR2(4000);
55785 l_transaction_reversal      NUMBER;
55786 l_ae_header_id              NUMBER;
55787 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
55788 l_log_module                VARCHAR2(240);
55789 --
55790 l_acct_reversal_source      VARCHAR2(30);
55791 l_trx_reversal_source       VARCHAR2(30);
55792 
55793 l_continue_with_lines       BOOLEAN := TRUE;
55794 --
55795 l_acc_rev_gl_date_source    DATE;                      -- 4262811
55796 --
55797 type t_array_event_id is table of number index by binary_integer;
55798 
55799 l_rec_array_event                    t_rec_array_event;
55800 l_null_rec_array_event               t_rec_array_event;
55801 l_array_ae_header_id                 xla_number_array_type;
55802 l_actual_flag                        VARCHAR2(1) := NULL;
55803 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
55804 l_balance_type_code                  VARCHAR2(1) :=NULL;
55805 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
55806 
55807 --
55808 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
55809 --
55810 
55811 TYPE t_array_source_5 IS TABLE OF AR_CREDIT_MEMO_H_V.CM_RECEIVABLE_CCID%TYPE INDEX BY BINARY_INTEGER;
55812 TYPE t_array_source_11 IS TABLE OF AR_SYSTEM_PARAM_H_V.CODE_COMBINATION_ID_GAIN%TYPE INDEX BY BINARY_INTEGER;
55813 TYPE t_array_source_12 IS TABLE OF AR_SYSTEM_PARAM_H_V.CODE_COMBINATION_ID_LOSS%TYPE INDEX BY BINARY_INTEGER;
55814 TYPE t_array_source_25 IS TABLE OF AR_CREDIT_MEMO_H_V.XLA_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
55815 TYPE t_array_source_37 IS TABLE OF AR_CREDIT_MEMO_H_V.CM_INVOICE_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
55816 TYPE t_array_source_43 IS TABLE OF AR_CM_BILL_TO_CUST_H_V.CM_BILL_CUST_ACCOUNT_ID%TYPE INDEX BY BINARY_INTEGER;
55817 TYPE t_array_source_44 IS TABLE OF AR_CM_BILL_SITE_USES_H_V.CM_BILL_USES_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
55818 TYPE t_array_source_50 IS TABLE OF AR_CREDIT_MEMO_H_V.CM_INVOICING_RULE_ID%TYPE INDEX BY BINARY_INTEGER;
55819 
55820 TYPE t_array_source_2 IS TABLE OF AR_CM_LINES_L_V.CM_LINE_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
55821 TYPE t_array_source_3 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CODE_COMBINATION_ID%TYPE INDEX BY BINARY_INTEGER;
55822 TYPE t_array_source_13 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_SOURCE_TYPE%TYPE INDEX BY BINARY_INTEGER;
55823 TYPE t_array_source_14 IS TABLE OF AR_RECEIVABLES_TRX_ACT_S_V.REC_ACT_TYPE%TYPE INDEX BY BINARY_INTEGER;
55824 TYPE t_array_source_17 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_ENT_AMT%TYPE INDEX BY BINARY_INTEGER;
55825 TYPE t_array_source_35 IS TABLE OF AR_CM_LINES_BASE_V.CM_DIST_IDENTIFER%TYPE INDEX BY BINARY_INTEGER;
55826 TYPE t_array_source_36 IS TABLE OF AR_CM_LINES_BASE_V.CM_DIST_TYPE%TYPE INDEX BY BINARY_INTEGER;
55827 TYPE t_array_source_38 IS TABLE OF AR_CM_LINES_BASE_V.CM_LINE_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
55828 TYPE t_array_source_39 IS TABLE OF AR_CM_LINES_BASE_V.CM_LINE_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
55829 TYPE t_array_source_40 IS TABLE OF AR_CM_LINES_BASE_V.CM_LINE_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
55830 TYPE t_array_source_41 IS TABLE OF AR_CM_LINES_BASE_V.GAIN_LOSS_REF%TYPE INDEX BY BINARY_INTEGER;
55831 TYPE t_array_source_42 IS TABLE OF AR_CM_LINES_BASE_V.CM_LINE_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
55832 TYPE t_array_source_45 IS TABLE OF AR_CM_LINES_L_V.CM_TAX_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
55833 TYPE t_array_source_46 IS TABLE OF AR_CM_LINES_L_V.CM_LINE_DIST_ACCOUNT_CLASS%TYPE INDEX BY BINARY_INTEGER;
55834 TYPE t_array_source_47 IS TABLE OF AR_CM_LINES_L_V.CM_LINE_DIST_AMT%TYPE INDEX BY BINARY_INTEGER;
55835 
55836 l_array_source_5              t_array_source_5;
55837 l_array_source_11              t_array_source_11;
55838 l_array_source_12              t_array_source_12;
55839 l_array_source_25              t_array_source_25;
55840 l_array_source_37              t_array_source_37;
55841 l_array_source_43              t_array_source_43;
55842 l_array_source_44              t_array_source_44;
55843 l_array_source_50              t_array_source_50;
55844 
55845 l_array_source_2      t_array_source_2;
55846 l_array_source_3      t_array_source_3;
55847 l_array_source_13      t_array_source_13;
55848 l_array_source_14      t_array_source_14;
55849 l_array_source_17      t_array_source_17;
55850 l_array_source_35      t_array_source_35;
55851 l_array_source_36      t_array_source_36;
55852 l_array_source_38      t_array_source_38;
55853 l_array_source_39      t_array_source_39;
55854 l_array_source_40      t_array_source_40;
55855 l_array_source_41      t_array_source_41;
55856 l_array_source_42      t_array_source_42;
55857 l_array_source_45      t_array_source_45;
55858 l_array_source_46      t_array_source_46;
55859 l_array_source_47      t_array_source_47;
55860 
55861 --
55862 CURSOR header_cur
55863 IS
55864 SELECT /*+ leading(xet) cardinality(xet,1) */
55865 -- Event Class Code: CREDIT_MEMO
55866     xet.entity_id
55867    ,xet.legal_entity_id
55868    ,xet.entity_code
55869    ,xet.transaction_number
55870    ,xet.event_id
55871    ,xet.event_class_code
55872    ,xet.event_type_code
55873    ,xet.event_number
55874    ,xet.event_date
55875    ,xet.transaction_date
55876    ,xet.reference_num_1
55877    ,xet.reference_num_2
55878    ,xet.reference_num_3
55879    ,xet.reference_num_4
55880    ,xet.reference_char_1
55881    ,xet.reference_char_2
55882    ,xet.reference_char_3
55883    ,xet.reference_char_4
55884    ,xet.reference_date_1
55885    ,xet.reference_date_2
55886    ,xet.reference_date_3
55887    ,xet.reference_date_4
55888    ,xet.event_created_by
55889    ,xet.budgetary_control_flag 
55890   , h5.CM_RECEIVABLE_CCID    source_5
55891   , h8.CODE_COMBINATION_ID_GAIN    source_11
55892   , h8.CODE_COMBINATION_ID_LOSS    source_12
55893   , h5.XLA_PARTY_TYPE    source_25
55894   , h5.CM_INVOICE_CURRENCY_CODE    source_37
55895   , h2.CM_BILL_CUST_ACCOUNT_ID    source_43
55896   , h1.CM_BILL_USES_SITE_USE_ID    source_44
55897   , h5.CM_INVOICING_RULE_ID    source_50
55898   FROM xla_events_gt     xet 
55899   , AR_CM_BILL_SITE_USES_H_V  h1
55900   , AR_CM_BILL_TO_CUST_H_V  h2
55901   , AR_CREDIT_MEMO_H_V  h5
55902   , AR_SYSTEM_PARAM_H_V  h8
55903  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
55904    and xet.event_class_code = C_EVENT_CLASS_CODE
55905    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
55906   AND h2.event_id  = h1.event_id
55907   AND h5.event_id  = h1.event_id
55908   AND h8.event_id (+) = h1.event_id
55909 
55910  ORDER BY event_id
55911 ;
55912 
55913 
55914 --
55915 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
55916 IS
55917 SELECT  /*+ leading(xet) cardinality(xet,1) */
55918 -- Event Class Code: CREDIT_MEMO
55919     xet.entity_id
55920    ,xet.legal_entity_id
55921    ,xet.entity_code
55922    ,xet.transaction_number
55923    ,xet.event_id
55924    ,xet.event_class_code
55925    ,xet.event_type_code
55926    ,xet.event_number
55927    ,xet.event_date
55928    ,xet.transaction_date
55929    ,xet.reference_num_1
55930    ,xet.reference_num_2
55931    ,xet.reference_num_3
55932    ,xet.reference_num_4
55933    ,xet.reference_char_1
55934    ,xet.reference_char_2
55935    ,xet.reference_char_3
55936    ,xet.reference_char_4
55937    ,xet.reference_date_1
55938    ,xet.reference_date_2
55939    ,xet.reference_date_3
55940    ,xet.reference_date_4
55941    ,xet.event_created_by
55942    ,xet.budgetary_control_flag
55943  , l3.LINE_NUMBER  
55944   , l4.CM_LINE_DIST_CCID    source_2
55945   , l6.DIST_CODE_COMBINATION_ID    source_3
55946   , l6.DIST_SOURCE_TYPE    source_13
55947   , l7.REC_ACT_TYPE    source_14
55948   , l6.DIST_ENT_AMT    source_17
55949   , l3.CM_DIST_IDENTIFER    source_35
55950   , l3.CM_DIST_TYPE    source_36
55951   , l3.CM_LINE_CUR_CONVERSION_DATE    source_38
55952   , l3.CM_LINE_CUR_CONVERSION_RATE    source_39
55953   , l3.CM_LINE_CUR_CONVERSION_TYPE    source_40
55954   , l3.GAIN_LOSS_REF    source_41
55955   , l3.CM_LINE_ACCTD_AMT    source_42
55956   , l4.CM_TAX_LINE_ID    source_45
55957   , l4.CM_LINE_DIST_ACCOUNT_CLASS    source_46
55958   , l4.CM_LINE_DIST_AMT    source_47
55959   FROM xla_events_gt     xet 
55960   , AR_CM_LINES_BASE_V  l3
55961   , AR_CM_LINES_L_V  l4
55962   , AR_DISTRIBUTIONS_L_V  l6
55963   , AR_RECEIVABLES_TRX_ACT_S_V  l7
55964  WHERE xet.event_id between x_first_event_id and x_last_event_id
55965    and xet.event_date between p_pad_start_date and p_pad_end_date
55966    and xet.event_class_code = C_EVENT_CLASS_CODE
55967    and xet.event_status_code <> 'N'   AND l3.event_id      = xet.event_id
55968   AND l4.event_id (+)    = l3.event_id
55969   AND l4.line_number (+) = l3.line_number
55970   AND l6.event_id (+)    = l3.event_id
55971   AND l6.line_number (+) = l3.line_number
55972   AND l7.event_id (+)    = l3.event_id
55973   AND l7.line_number (+) = l3.line_number
55974 ;
55975 
55976 --
55977 BEGIN
55978 IF g_log_enabled THEN
55979    l_log_module := C_DEFAULT_MODULE||'.EventClass_104';
55980 END IF;
55981 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
55982    trace
55983       (p_msg      => 'BEGIN of EventClass_104'
55984       ,p_level    => C_LEVEL_PROCEDURE
55985       ,p_module   => l_log_module);
55986 END IF;
55987 
55988 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
55989    trace
55990       (p_msg      => 'p_application_id = '||p_application_id||
55991                      ' - p_base_ledger_id = '||p_base_ledger_id||
55992                      ' - p_target_ledger_id  = '||p_target_ledger_id||
55993                      ' - p_language = '||p_language||
55994                      ' - p_currency_code = '||p_currency_code||
55995                      ' - p_sla_ledger_id = '||p_sla_ledger_id
55996       ,p_level    => C_LEVEL_STATEMENT
55997       ,p_module   => l_log_module);
55998 END IF;
55999 --
56000 -- initialze arrays
56001 --
56002 g_array_event.DELETE;
56003 l_rec_array_event := l_null_rec_array_event;
56004 --
56005 --------------------------------------
56006 -- 4262811 Initialze MPA Line Number
56007 --------------------------------------
56008 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
56009 
56010 --
56011 
56012 --
56013 OPEN header_cur;
56014 --
56015 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
56016    trace
56017    (p_msg      => 'SQL - FETCH header_cur'
56018    ,p_level    => C_LEVEL_STATEMENT
56019    ,p_module   => l_log_module);
56020 END IF;
56021 --
56022 LOOP
56023 FETCH header_cur BULK COLLECT INTO
56024         l_array_entity_id
56025       , l_array_legal_entity_id
56026       , l_array_entity_code
56027       , l_array_transaction_num
56028       , l_array_event_id
56029       , l_array_class_code
56030       , l_array_event_type
56031       , l_array_event_number
56032       , l_array_event_date
56033       , l_array_transaction_date
56034       , l_array_reference_num_1
56035       , l_array_reference_num_2
56036       , l_array_reference_num_3
56037       , l_array_reference_num_4
56038       , l_array_reference_char_1
56039       , l_array_reference_char_2
56040       , l_array_reference_char_3
56041       , l_array_reference_char_4
56042       , l_array_reference_date_1
56043       , l_array_reference_date_2
56044       , l_array_reference_date_3
56045       , l_array_reference_date_4
56046       , l_array_event_created_by
56047       , l_array_budgetary_control_flag 
56048       , l_array_source_5
56049       , l_array_source_11
56050       , l_array_source_12
56051       , l_array_source_25
56052       , l_array_source_37
56053       , l_array_source_43
56054       , l_array_source_44
56055       , l_array_source_50
56056       LIMIT l_rows;
56057 --
56058 IF (C_LEVEL_EVENT >= g_log_level) THEN
56059    trace
56060    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
56061    ,p_level    => C_LEVEL_EVENT
56062    ,p_module   => l_log_module);
56063 END IF;
56064 --
56065 EXIT WHEN l_array_entity_id.COUNT = 0;
56066 
56067 -- initialize arrays
56068 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
56069 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
56070 
56071 --
56072 -- Bug 4458708
56073 --
56074 XLA_AE_LINES_PKG.g_LineNumber := 0;
56075 
56076 
56077 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
56078 g_last_hdr_idx := l_array_event_id.LAST;
56079 --
56080 -- loop for the headers. Each iteration is for each header extract row
56081 -- fetched in header cursor
56082 --
56083 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
56084 
56085 --
56086 -- set event info as cache for other routines to refer event attributes
56087 --
56088 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
56089    (p_application_id           => p_application_id
56090    ,p_primary_ledger_id        => p_primary_ledger_id
56091    ,p_base_ledger_id           => p_base_ledger_id
56092    ,p_target_ledger_id         => p_target_ledger_id
56093    ,p_entity_id                => l_array_entity_id(hdr_idx)
56094    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
56095    ,p_entity_code              => l_array_entity_code(hdr_idx)
56096    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
56097    ,p_event_id                 => l_array_event_id(hdr_idx)
56098    ,p_event_class_code         => l_array_class_code(hdr_idx)
56099    ,p_event_type_code          => l_array_event_type(hdr_idx)
56100    ,p_event_number             => l_array_event_number(hdr_idx)
56101    ,p_event_date               => l_array_event_date(hdr_idx)
56102    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
56103    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
56104    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
56105    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
56106    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
56107    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
56108    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
56109    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
56110    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
56111    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
56112    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
56113    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
56114    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
56115    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
56116    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
56117 
56118 --
56119 -- set the status of entry to C_VALID (0)
56120 --
56121 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
56122 
56123 --
56124 -- initialize a row for ae header
56125 --
56126 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
56127 
56128 l_event_id := l_array_event_id(hdr_idx);
56129 
56130 --
56131 -- storing the hdr_idx for event. May be used by line cursor.
56132 --
56133 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
56134 
56135 --
56136 -- store sources from header extract. This can be improved to
56140 g_array_event(l_event_id).array_value_num('source_5') := l_array_source_5(hdr_idx);
56137 -- store only those sources from header extract that may be used in lines
56138 --
56139 
56141 g_array_event(l_event_id).array_value_num('source_11') := l_array_source_11(hdr_idx);
56142 g_array_event(l_event_id).array_value_num('source_12') := l_array_source_12(hdr_idx);
56143 g_array_event(l_event_id).array_value_char('source_25') := l_array_source_25(hdr_idx);
56144 g_array_event(l_event_id).array_value_char('source_37') := l_array_source_37(hdr_idx);
56145 g_array_event(l_event_id).array_value_num('source_43') := l_array_source_43(hdr_idx);
56146 g_array_event(l_event_id).array_value_num('source_44') := l_array_source_44(hdr_idx);
56147 g_array_event(l_event_id).array_value_num('source_50') := l_array_source_50(hdr_idx);
56148 
56149 --
56150 -- initilaize the status of ae headers for diffrent balance types
56151 -- the status is initialised to C_NOT_CREATED (2)
56152 --
56153 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
56154 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
56155 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
56156 
56157 --
56158 -- call api to validate and store accounting attributes for header
56159 --
56160 
56161 ------------------------------------------------------------
56162 -- Accrual Reversal : to get date for Standard Source (NONE)
56163 ------------------------------------------------------------
56164 l_acc_rev_gl_date_source := NULL;
56165 
56166      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
56167       l_rec_acct_attrs.array_date_value(1) := 
56168 xla_ae_sources_pkg.GetSystemSourceDate(
56169    p_source_code           => 'XLA_EVENT_DATE'
56170  , p_source_type_code      => 'Y'
56171  , p_source_application_id =>  602
56172 );
56173 
56174 
56175 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
56176 
56177 XLA_AE_HEADER_PKG.SetJeCategoryName;
56178 
56179 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
56180 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
56181 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
56182 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
56183 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
56184 
56185 
56186 -- No header level analytical criteria
56187 
56188 --
56189 --accounting attribute enhancement, bug 3612931
56190 --
56191 l_trx_reversal_source := SUBSTR(NULL, 1,30);
56192 
56193 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
56194    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
56195 
56196    xla_accounting_err_pkg.build_message
56197       (p_appli_s_name            => 'XLA'
56198       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
56199       ,p_token_1                 => 'ACCT_ATTR_NAME'
56200       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
56201       ,p_token_2                 => 'PRODUCT_NAME'
56202       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
56203       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
56204       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
56205       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
56206 
56207 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
56208    --
56209    -- following sets the accounting attributes needed to reverse
56210    -- accounting for a distributeion
56211    --
56212    xla_ae_lines_pkg.SetTrxReversalAttrs
56213       (p_event_id              => l_event_id
56214       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
56215       ,p_trx_reversal_source   => l_trx_reversal_source);
56216 
56217 END IF;
56218 
56219 
56220 ----------------------------------------------------------------
56221 -- 4262811 -  update the header statuses to invalid in need be
56222 ----------------------------------------------------------------
56223 --
56224 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
56225 
56226 
56227   -----------------------------------------------
56228   -- No accrual reversal for the event class/type
56229   -----------------------------------------------
56230 ----------------------------------------------------------------
56231 
56232 --
56233 -- this ends the header loop iteration for one bulk fetch
56234 --
56235 END LOOP;
56236 
56237 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
56238 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
56239 
56240 --
56241 -- insert dummy rows into lines gt table that were created due to
56242 -- transaction reversals
56243 --
56244 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
56245    l_result := XLA_AE_LINES_PKG.InsertLines;
56246 END IF;
56247 
56248 --
56249 -- reset the temp_line_num for each set of events fetched from header
56250 -- cursor rather than doing it for each new event in line cursor
56251 -- Bug 3939231
56252 --
56253 xla_ae_lines_pkg.g_temp_line_num := 0;
56254 
56255 
56256 
56257 --
56258 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
56259 --
56260 --
56261 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
56262 
56263       trace
56264          (p_msg      => 'SQL - FETCH line_cur'
56268 END IF;
56265          ,p_level    => C_LEVEL_STATEMENT
56266          ,p_module   => l_log_module);
56267 
56269 --
56270 --
56271 LOOP
56272   --
56273   FETCH line_cur BULK COLLECT INTO
56274         l_array_entity_id
56275       , l_array_legal_entity_id
56276       , l_array_entity_code
56277       , l_array_transaction_num
56278       , l_array_event_id
56279       , l_array_class_code
56280       , l_array_event_type
56281       , l_array_event_number
56282       , l_array_event_date
56283       , l_array_transaction_date
56284       , l_array_reference_num_1
56285       , l_array_reference_num_2
56286       , l_array_reference_num_3
56287       , l_array_reference_num_4
56288       , l_array_reference_char_1
56289       , l_array_reference_char_2
56290       , l_array_reference_char_3
56291       , l_array_reference_char_4
56292       , l_array_reference_date_1
56293       , l_array_reference_date_2
56294       , l_array_reference_date_3
56295       , l_array_reference_date_4
56296       , l_array_event_created_by
56297       , l_array_budgetary_control_flag
56298       , l_array_extract_line_num 
56299       , l_array_source_2
56300       , l_array_source_3
56301       , l_array_source_13
56302       , l_array_source_14
56303       , l_array_source_17
56304       , l_array_source_35
56305       , l_array_source_36
56306       , l_array_source_38
56307       , l_array_source_39
56308       , l_array_source_40
56309       , l_array_source_41
56310       , l_array_source_42
56311       , l_array_source_45
56312       , l_array_source_46
56313       , l_array_source_47
56314       LIMIT l_rows;
56315 
56316   --
56317   IF (C_LEVEL_EVENT >= g_log_level) THEN
56318             trace
56319                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
56320                ,p_level    => C_LEVEL_EVENT
56321                ,p_module   => l_log_module);
56322   END IF;
56323   --
56324   EXIT WHEN l_array_entity_id.count = 0;
56325 
56326   XLA_AE_LINES_PKG.g_rec_lines := null;
56327 
56328 --
56329 -- Bug 4458708
56330 --
56331 XLA_AE_LINES_PKG.g_LineNumber := 0;
56332 --
56333 --
56334 
56335 FOR Idx IN 1..l_array_event_id.count LOOP
56336    --
56337    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
56338    --
56339    l_event_id := l_array_event_id(idx);  -- 5648433
56340 
56341    --
56342    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
56343    --
56344 
56345    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
56346              (g_array_event(l_event_id).array_value_num('header_index'))
56347          ,'N'
56348          ) <> 'Y'
56349    THEN
56350       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
56351          trace
56352             (p_msg      => 'Trancaction revesal option is not Y '
56353             ,p_level    => C_LEVEL_STATEMENT
56354             ,p_module   => l_log_module);
56355       END IF;
56356 
56357 --
56358 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
56359 --
56360 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
56361 --
56362 -- set event info as cache for other routines to refer event attributes
56363 --
56364 
56365 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
56366    l_previous_event_id := l_event_id;
56367 
56368    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
56369       (p_application_id           => p_application_id
56370       ,p_primary_ledger_id        => p_primary_ledger_id
56371       ,p_base_ledger_id           => p_base_ledger_id
56372       ,p_target_ledger_id         => p_target_ledger_id
56373       ,p_entity_id                => l_array_entity_id(Idx)
56374       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
56375       ,p_entity_code              => l_array_entity_code(Idx)
56376       ,p_transaction_num          => l_array_transaction_num(Idx)
56377       ,p_event_id                 => l_array_event_id(Idx)
56378       ,p_event_class_code         => l_array_class_code(Idx)
56379       ,p_event_type_code          => l_array_event_type(Idx)
56380       ,p_event_number             => l_array_event_number(Idx)
56381       ,p_event_date               => l_array_event_date(Idx)
56382       ,p_transaction_date         => l_array_transaction_date(Idx)
56383       ,p_reference_num_1          => l_array_reference_num_1(Idx)
56384       ,p_reference_num_2          => l_array_reference_num_2(Idx)
56385       ,p_reference_num_3          => l_array_reference_num_3(Idx)
56386       ,p_reference_num_4          => l_array_reference_num_4(Idx)
56387       ,p_reference_char_1         => l_array_reference_char_1(Idx)
56388       ,p_reference_char_2         => l_array_reference_char_2(Idx)
56389       ,p_reference_char_3         => l_array_reference_char_3(Idx)
56390       ,p_reference_char_4         => l_array_reference_char_4(Idx)
56391       ,p_reference_date_1         => l_array_reference_date_1(Idx)
56392       ,p_reference_date_2         => l_array_reference_date_2(Idx)
56393       ,p_reference_date_3         => l_array_reference_date_3(Idx)
56394       ,p_reference_date_4         => l_array_reference_date_4(Idx)
56395       ,p_event_created_by         => l_array_event_created_by(Idx)
56396       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
56397        --
56398 END IF;
56399 
56400 
56401 
56402 --
56403 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
56404 
56405 l_acct_reversal_source := SUBSTR(NULL, 1,30);
56406 
56407 IF l_continue_with_lines THEN
56408    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
56409       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
56410 
56411       xla_accounting_err_pkg.build_message
56412          (p_appli_s_name            => 'XLA'
56413          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
56414          ,p_token_1                 => 'LINE_NUMBER'
56415          ,p_value_1                 => l_array_extract_line_num(Idx)
56416          ,p_token_2                 => 'PRODUCT_NAME'
56417          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
56418          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
56419          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
56420          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
56421 
56422    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
56423       --
56424       -- following sets the accounting attributes needed to reverse
56425       -- accounting for a distributeion
56426       --
56427 
56428       --
56429       -- 5217187
56430       --
56431       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
56432       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
56433                                        g_array_event(l_event_id).array_value_num('header_index'));
56434       --
56435       --
56436 
56437       -- No reversal code generated
56438 
56439       xla_ae_lines_pkg.SetAcctReversalAttrs
56440          (p_event_id             => l_event_id
56441          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
56442          ,p_calculate_acctd_flag => l_calculate_acctd_flag
56443          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
56444    END IF;
56445 
56446    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
56447        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
56448 
56449 --
56450 AcctLineType_24 (
56451  p_application_id  => p_application_id
56452  ,p_event_id     => l_event_id
56453  ,p_calculate_acctd_flag => l_calculate_acctd_flag
56454  ,p_calculate_g_l_flag => l_calculate_g_l_flag
56455  ,p_actual_flag => l_actual_flag
56456  ,p_balance_type_code => l_balance_type_code
56457  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
56458  
56459  , p_source_3 => l_array_source_3(Idx)
56460  , p_source_13 => l_array_source_13(Idx)
56461  , p_source_17 => l_array_source_17(Idx)
56462  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
56463  , p_source_35 => l_array_source_35(Idx)
56464  , p_source_36 => l_array_source_36(Idx)
56465  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
56466  , p_source_38 => l_array_source_38(Idx)
56467  , p_source_39 => l_array_source_39(Idx)
56468  , p_source_40 => l_array_source_40(Idx)
56469  , p_source_41 => l_array_source_41(Idx)
56470  , p_source_42 => l_array_source_42(Idx)
56471  , p_source_43 => g_array_event(l_event_id).array_value_num('source_43')
56472  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
56473  , p_source_45 => l_array_source_45(Idx)
56474  );
56475 If(l_balance_type_code = 'A') THEN
56476   l_actual_gain_loss_ref := l_gain_or_loss_ref;
56477 END IF;
56478 
56479 --
56480 
56481 
56482 --
56483 AcctLineType_25 (
56484  p_application_id  => p_application_id
56485  ,p_event_id     => l_event_id
56486  ,p_calculate_acctd_flag => l_calculate_acctd_flag
56487  ,p_calculate_g_l_flag => l_calculate_g_l_flag
56488  ,p_actual_flag => l_actual_flag
56489  ,p_balance_type_code => l_balance_type_code
56490  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
56491  
56492  , p_source_3 => l_array_source_3(Idx)
56493  , p_source_13 => l_array_source_13(Idx)
56494  , p_source_14 => l_array_source_14(Idx)
56495  , p_source_17 => l_array_source_17(Idx)
56496  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
56497  , p_source_35 => l_array_source_35(Idx)
56498  , p_source_36 => l_array_source_36(Idx)
56499  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
56500  , p_source_38 => l_array_source_38(Idx)
56501  , p_source_39 => l_array_source_39(Idx)
56502  , p_source_40 => l_array_source_40(Idx)
56503  , p_source_41 => l_array_source_41(Idx)
56504  , p_source_42 => l_array_source_42(Idx)
56505  , p_source_43 => g_array_event(l_event_id).array_value_num('source_43')
56506  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
56507  , p_source_45 => l_array_source_45(Idx)
56508  );
56509 If(l_balance_type_code = 'A') THEN
56510   l_actual_gain_loss_ref := l_gain_or_loss_ref;
56511 END IF;
56512 
56513 --
56514 
56515 
56516 --
56517 AcctLineType_26 (
56518  p_application_id  => p_application_id
56519  ,p_event_id     => l_event_id
56520  ,p_calculate_acctd_flag => l_calculate_acctd_flag
56521  ,p_calculate_g_l_flag => l_calculate_g_l_flag
56522  ,p_actual_flag => l_actual_flag
56523  ,p_balance_type_code => l_balance_type_code
56524  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
56525  
56526  , p_source_2 => l_array_source_2(Idx)
56527  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
56528  , p_source_35 => l_array_source_35(Idx)
56529  , p_source_36 => l_array_source_36(Idx)
56530  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
56531  , p_source_38 => l_array_source_38(Idx)
56532  , p_source_39 => l_array_source_39(Idx)
56533  , p_source_40 => l_array_source_40(Idx)
56534  , p_source_41 => l_array_source_41(Idx)
56535  , p_source_42 => l_array_source_42(Idx)
56536  , p_source_43 => g_array_event(l_event_id).array_value_num('source_43')
56537  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
56538  , p_source_45 => l_array_source_45(Idx)
56539  , p_source_46 => l_array_source_46(Idx)
56540  , p_source_47 => l_array_source_47(Idx)
56541  );
56542 If(l_balance_type_code = 'A') THEN
56543   l_actual_gain_loss_ref := l_gain_or_loss_ref;
56544 END IF;
56545 
56546 --
56547 
56548 
56549 --
56550 AcctLineType_27 (
56551  p_application_id  => p_application_id
56552  ,p_event_id     => l_event_id
56553  ,p_calculate_acctd_flag => l_calculate_acctd_flag
56554  ,p_calculate_g_l_flag => l_calculate_g_l_flag
56555  ,p_actual_flag => l_actual_flag
56556  ,p_balance_type_code => l_balance_type_code
56557  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
56558  
56559  , p_source_2 => l_array_source_2(Idx)
56560  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
56561  , p_source_35 => l_array_source_35(Idx)
56562  , p_source_36 => l_array_source_36(Idx)
56563  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
56564  , p_source_38 => l_array_source_38(Idx)
56565  , p_source_39 => l_array_source_39(Idx)
56566  , p_source_40 => l_array_source_40(Idx)
56567  , p_source_41 => l_array_source_41(Idx)
56568  , p_source_42 => l_array_source_42(Idx)
56569  , p_source_43 => g_array_event(l_event_id).array_value_num('source_43')
56570  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
56571  , p_source_45 => l_array_source_45(Idx)
56572  , p_source_46 => l_array_source_46(Idx)
56573  , p_source_47 => l_array_source_47(Idx)
56574  );
56575 If(l_balance_type_code = 'A') THEN
56576   l_actual_gain_loss_ref := l_gain_or_loss_ref;
56577 END IF;
56578 
56579 --
56580 
56581 
56582 --
56583 AcctLineType_28 (
56584  p_application_id  => p_application_id
56585  ,p_event_id     => l_event_id
56586  ,p_calculate_acctd_flag => l_calculate_acctd_flag
56587  ,p_calculate_g_l_flag => l_calculate_g_l_flag
56588  ,p_actual_flag => l_actual_flag
56589  ,p_balance_type_code => l_balance_type_code
56590  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
56591  
56592  , p_source_2 => l_array_source_2(Idx)
56593  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
56594  , p_source_35 => l_array_source_35(Idx)
56595  , p_source_36 => l_array_source_36(Idx)
56596  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
56597  , p_source_38 => l_array_source_38(Idx)
56598  , p_source_39 => l_array_source_39(Idx)
56599  , p_source_40 => l_array_source_40(Idx)
56600  , p_source_41 => l_array_source_41(Idx)
56601  , p_source_42 => l_array_source_42(Idx)
56602  , p_source_43 => g_array_event(l_event_id).array_value_num('source_43')
56603  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
56604  , p_source_45 => l_array_source_45(Idx)
56605  , p_source_46 => l_array_source_46(Idx)
56606  , p_source_47 => l_array_source_47(Idx)
56607  );
56608 If(l_balance_type_code = 'A') THEN
56609   l_actual_gain_loss_ref := l_gain_or_loss_ref;
56610 END IF;
56611 
56612 --
56613 
56614 
56615 --
56616 AcctLineType_29 (
56617  p_application_id  => p_application_id
56618  ,p_event_id     => l_event_id
56619  ,p_calculate_acctd_flag => l_calculate_acctd_flag
56620  ,p_calculate_g_l_flag => l_calculate_g_l_flag
56621  ,p_actual_flag => l_actual_flag
56622  ,p_balance_type_code => l_balance_type_code
56623  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
56624  
56625  , p_source_2 => l_array_source_2(Idx)
56626  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
56627  , p_source_35 => l_array_source_35(Idx)
56628  , p_source_36 => l_array_source_36(Idx)
56629  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
56630  , p_source_38 => l_array_source_38(Idx)
56631  , p_source_39 => l_array_source_39(Idx)
56632  , p_source_40 => l_array_source_40(Idx)
56633  , p_source_41 => l_array_source_41(Idx)
56634  , p_source_42 => l_array_source_42(Idx)
56635  , p_source_43 => g_array_event(l_event_id).array_value_num('source_43')
56636  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
56637  , p_source_45 => l_array_source_45(Idx)
56638  , p_source_46 => l_array_source_46(Idx)
56639  , p_source_47 => l_array_source_47(Idx)
56640  );
56641 If(l_balance_type_code = 'A') THEN
56642   l_actual_gain_loss_ref := l_gain_or_loss_ref;
56643 END IF;
56644 
56645 --
56646 
56647 
56648 --
56649 AcctLineType_30 (
56650  p_application_id  => p_application_id
56651  ,p_event_id     => l_event_id
56652  ,p_calculate_acctd_flag => l_calculate_acctd_flag
56653  ,p_calculate_g_l_flag => l_calculate_g_l_flag
56654  ,p_actual_flag => l_actual_flag
56655  ,p_balance_type_code => l_balance_type_code
56656  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
56657  
56658  , p_source_11 => g_array_event(l_event_id).array_value_num('source_11')
56659  , p_source_12 => g_array_event(l_event_id).array_value_num('source_12')
56660  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
56661  , p_source_35 => l_array_source_35(Idx)
56662  , p_source_36 => l_array_source_36(Idx)
56663  , p_source_41 => l_array_source_41(Idx)
56664  , p_source_42 => l_array_source_42(Idx)
56665  , p_source_43 => g_array_event(l_event_id).array_value_num('source_43')
56666  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
56667  , p_source_45 => l_array_source_45(Idx)
56668  );
56669 If(l_balance_type_code = 'A') THEN
56670   l_actual_gain_loss_ref := l_gain_or_loss_ref;
56671 END IF;
56672 
56673 --
56674 
56675 
56676 --
56677 AcctLineType_31 (
56678  p_application_id  => p_application_id
56682  ,p_actual_flag => l_actual_flag
56679  ,p_event_id     => l_event_id
56680  ,p_calculate_acctd_flag => l_calculate_acctd_flag
56681  ,p_calculate_g_l_flag => l_calculate_g_l_flag
56683  ,p_balance_type_code => l_balance_type_code
56684  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
56685  
56686  , p_source_2 => l_array_source_2(Idx)
56687  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
56688  , p_source_35 => l_array_source_35(Idx)
56689  , p_source_36 => l_array_source_36(Idx)
56690  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
56691  , p_source_38 => l_array_source_38(Idx)
56692  , p_source_39 => l_array_source_39(Idx)
56693  , p_source_40 => l_array_source_40(Idx)
56694  , p_source_41 => l_array_source_41(Idx)
56695  , p_source_42 => l_array_source_42(Idx)
56696  , p_source_43 => g_array_event(l_event_id).array_value_num('source_43')
56697  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
56698  , p_source_45 => l_array_source_45(Idx)
56699  , p_source_46 => l_array_source_46(Idx)
56700  , p_source_47 => l_array_source_47(Idx)
56701  );
56702 If(l_balance_type_code = 'A') THEN
56703   l_actual_gain_loss_ref := l_gain_or_loss_ref;
56704 END IF;
56705 
56706 --
56707 
56708 
56709 --
56710 AcctLineType_32 (
56711  p_application_id  => p_application_id
56712  ,p_event_id     => l_event_id
56713  ,p_calculate_acctd_flag => l_calculate_acctd_flag
56714  ,p_calculate_g_l_flag => l_calculate_g_l_flag
56715  ,p_actual_flag => l_actual_flag
56716  ,p_balance_type_code => l_balance_type_code
56717  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
56718  
56719  , p_source_2 => l_array_source_2(Idx)
56720  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
56721  , p_source_35 => l_array_source_35(Idx)
56722  , p_source_36 => l_array_source_36(Idx)
56723  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
56724  , p_source_38 => l_array_source_38(Idx)
56725  , p_source_39 => l_array_source_39(Idx)
56726  , p_source_40 => l_array_source_40(Idx)
56727  , p_source_41 => l_array_source_41(Idx)
56728  , p_source_42 => l_array_source_42(Idx)
56729  , p_source_43 => g_array_event(l_event_id).array_value_num('source_43')
56730  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
56731  , p_source_45 => l_array_source_45(Idx)
56732  , p_source_46 => l_array_source_46(Idx)
56733  , p_source_47 => l_array_source_47(Idx)
56734  );
56735 If(l_balance_type_code = 'A') THEN
56736   l_actual_gain_loss_ref := l_gain_or_loss_ref;
56737 END IF;
56738 
56739 --
56740 
56741 
56742 --
56743 AcctLineType_33 (
56744  p_application_id  => p_application_id
56745  ,p_event_id     => l_event_id
56746  ,p_calculate_acctd_flag => l_calculate_acctd_flag
56747  ,p_calculate_g_l_flag => l_calculate_g_l_flag
56748  ,p_actual_flag => l_actual_flag
56749  ,p_balance_type_code => l_balance_type_code
56750  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
56751  
56752  , p_source_2 => l_array_source_2(Idx)
56753  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
56754  , p_source_35 => l_array_source_35(Idx)
56755  , p_source_36 => l_array_source_36(Idx)
56756  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
56757  , p_source_38 => l_array_source_38(Idx)
56758  , p_source_39 => l_array_source_39(Idx)
56759  , p_source_40 => l_array_source_40(Idx)
56760  , p_source_41 => l_array_source_41(Idx)
56761  , p_source_42 => l_array_source_42(Idx)
56762  , p_source_43 => g_array_event(l_event_id).array_value_num('source_43')
56763  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
56764  , p_source_45 => l_array_source_45(Idx)
56765  , p_source_46 => l_array_source_46(Idx)
56766  , p_source_47 => l_array_source_47(Idx)
56767  );
56768 If(l_balance_type_code = 'A') THEN
56769   l_actual_gain_loss_ref := l_gain_or_loss_ref;
56770 END IF;
56771 
56772 --
56773 
56774 
56775 --
56776 AcctLineType_53 (
56777  p_application_id  => p_application_id
56778  ,p_event_id     => l_event_id
56779  ,p_calculate_acctd_flag => l_calculate_acctd_flag
56780  ,p_calculate_g_l_flag => l_calculate_g_l_flag
56781  ,p_actual_flag => l_actual_flag
56782  ,p_balance_type_code => l_balance_type_code
56783  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
56784  
56785  , p_source_2 => l_array_source_2(Idx)
56786  , p_source_5 => g_array_event(l_event_id).array_value_num('source_5')
56787  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
56788  , p_source_35 => l_array_source_35(Idx)
56789  , p_source_36 => l_array_source_36(Idx)
56790  , p_source_37 => g_array_event(l_event_id).array_value_char('source_37')
56791  , p_source_38 => l_array_source_38(Idx)
56792  , p_source_39 => l_array_source_39(Idx)
56793  , p_source_40 => l_array_source_40(Idx)
56794  , p_source_41 => l_array_source_41(Idx)
56795  , p_source_42 => l_array_source_42(Idx)
56796  , p_source_43 => g_array_event(l_event_id).array_value_num('source_43')
56797  , p_source_44 => g_array_event(l_event_id).array_value_num('source_44')
56798  , p_source_45 => l_array_source_45(Idx)
56799  , p_source_46 => l_array_source_46(Idx)
56800  , p_source_47 => l_array_source_47(Idx)
56801  , p_source_50 => g_array_event(l_event_id).array_value_num('source_50')
56802  );
56803 If(l_balance_type_code = 'A') THEN
56804   l_actual_gain_loss_ref := l_gain_or_loss_ref;
56805 END IF;
56806 
56807 --
56808 
56809       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
56810       -- or secondary ledger that has different currency with primary
56811       -- or alc that is calculated by sla
56812       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
56813             (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'))
56814 
56815 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
56816 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
56817           AND (l_actual_flag = 'A')) THEN
56818         XLA_AE_LINES_PKG.CreateGainOrLossLines(
56819           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
56820          ,p_application_id   => p_application_id
56821          ,p_amb_context_code => 'DEFAULT'
56822          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
56823          ,p_event_class_code => C_EVENT_CLASS_CODE
56824          ,p_event_type_code  => C_EVENT_TYPE_CODE
56825          
56826          ,p_gain_ccid        => -1
56827          ,p_loss_ccid        => -1
56828 
56829          ,p_actual_flag      => l_actual_flag
56830          ,p_enc_flag         => null
56831          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
56832          ,p_enc_g_l_ref      => null
56833          );
56834       END IF;
56835    END IF;
56836 END IF;
56837 
56838    ELSE
56839       --
56840       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
56841       --
56842       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
56843          trace
56844             (p_msg      => 'Trancaction revesal option is Y'
56845             ,p_level    => C_LEVEL_STATEMENT
56846             ,p_module   => l_log_module);
56847       END IF;
56848    END IF;
56849 
56850 END LOOP;
56851 l_result := XLA_AE_LINES_PKG.InsertLines ;
56852 end loop;
56853 close line_cur;
56854 
56855 
56856 --
56857 -- insert headers into xla_ae_headers_gt table
56858 --
56859 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
56860 
56861 -- insert into errors table here.
56862 
56863 END LOOP;
56864 
56865 --
56866 -- 4865292
56867 --
56868 -- Compare g_hdr_extract_count with event count in
56869 -- CreateHeadersAndLines.
56870 --
56871 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
56872 
56873 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
56874    trace (p_msg     => '# rows extracted from header extract objects '
56875                     || ' (running total): '
56876                     || g_hdr_extract_count
56877          ,p_level   => C_LEVEL_STATEMENT
56878          ,p_module  => l_log_module);
56879 END IF;
56880 
56881 CLOSE header_cur;
56882 --
56883 
56884 --
56885 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
56886    trace
56887       (p_msg      => 'END of EventClass_104'
56888       ,p_level    => C_LEVEL_PROCEDURE
56889       ,p_module   => l_log_module);
56890 END IF;
56891 --
56892 RETURN l_result;
56893 EXCEPTION
56894 WHEN xla_exceptions_pkg.application_exception THEN
56895    
56896 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
56897 
56898    
56899 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
56900 
56901    RAISE;
56902 
56903 WHEN NO_DATA_FOUND THEN
56904 
56905 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
56906 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
56907 
56911 END LOOP;
56908 FOR header_record IN header_cur
56909 LOOP
56910     l_array_header_events(header_record.event_id) := header_record.event_id;
56912 
56913 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
56914 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
56915 
56916 fnd_file.put_line(fnd_file.LOG, '                    ');
56917 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
56918 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
56919 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
56920 
56921 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
56922 LOOP
56923 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
56924 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
56925         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
56926 	END IF;
56927 END LOOP;
56928 
56929 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
56930 fnd_file.put_line(fnd_file.LOG, '                    ');
56931 
56932 
56933 xla_exceptions_pkg.raise_message
56934       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_104');
56935 
56936 
56937 WHEN OTHERS THEN
56938    xla_exceptions_pkg.raise_message
56939       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_104');
56940 END EventClass_104;
56941 --
56942 
56943 ---------------------------------------
56944 --
56945 -- PRIVATE PROCEDURE
56946 --         insert_sources_105
56947 --
56948 ----------------------------------------
56949 --
56950 PROCEDURE insert_sources_105(
56951                                 p_target_ledger_id       IN NUMBER
56952                               , p_language               IN VARCHAR2
56953                               , p_sla_ledger_id          IN NUMBER
56954                               , p_pad_start_date         IN DATE
56955                               , p_pad_end_date           IN DATE
56956                          )
56957 IS
56958 
56959 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'DEBIT_MEMO_ALL';
56960 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'DEBIT_MEMO';
56961 p_apps_owner                   VARCHAR2(30);
56962 l_log_module                   VARCHAR2(240);
56963 BEGIN
56964 IF g_log_enabled THEN
56965       l_log_module := C_DEFAULT_MODULE||'.insert_sources_105';
56966 END IF;
56967 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
56968 
56969       trace
56970          (p_msg      => 'BEGIN of insert_sources_105'
56971          ,p_level    => C_LEVEL_PROCEDURE
56972          ,p_module   => l_log_module);
56973 
56974 END IF;
56975 
56976 -- select APPS owner
56977 SELECT oracle_username
56978   INTO p_apps_owner
56979   FROM fnd_oracle_userid
56980  WHERE read_only_flag = 'U'
56981 ;
56982 
56983 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
56984       trace
56985          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
56986                         ' - p_language = '||p_language||
56987                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
56988                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
56989                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
56990                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
56991          ,p_level    => C_LEVEL_STATEMENT
56992          ,p_module   => l_log_module);
56993 END IF;
56994 
56995 
56996 --
56997 INSERT INTO xla_diag_sources --hdr2
56998 (
56999         event_id
57000       , ledger_id
57001       , sla_ledger_id
57002       , description_language
57003       , object_name
57004       , object_type_code
57005       , line_number
57006       , source_application_id
57007       , source_type_code
57008       , source_code
57009       , source_value
57010       , source_meaning
57011       , created_by
57012       , creation_date
57013       , last_update_date
57014       , last_updated_by
57015       , last_update_login
57016       , program_update_date
57017       , program_application_id
57018       , program_id
57019       , request_id
57020 )
57021 SELECT
57022         event_id
57023       , p_target_ledger_id
57024       , p_sla_ledger_id
57025       , p_language
57026       , object_name
57027       , object_type_code
57028       , line_number
57029       , source_application_id
57030       , source_type_code
57031       , source_code
57032       , SUBSTR(source_value ,1,1996)
57033       , SUBSTR(source_meaning ,1,200)
57034       , xla_environment_pkg.g_Usr_Id
57035       , TRUNC(SYSDATE)
57036       , TRUNC(SYSDATE)
57037       , xla_environment_pkg.g_Usr_Id
57038       , xla_environment_pkg.g_Login_Id
57039       , TRUNC(SYSDATE)
57040       , xla_environment_pkg.g_Prog_Appl_Id
57041       , xla_environment_pkg.g_Prog_Id
57042       , xla_environment_pkg.g_Req_Id
57043   FROM (
57044        SELECT xet.event_id                  event_id
57045             , 0                          line_number
57046             , CASE r
57047                WHEN 1 THEN 'AR_TRANSACTIONS_S_V' 
57048                 WHEN 2 THEN 'AR_BILL_TO_CUSTOMERS_S_V' 
57049                 WHEN 3 THEN 'AR_BILL_TO_SITE_USES_S_V' 
57050                 WHEN 4 THEN 'AR_TRANSACTIONS_S_V' 
57051                 WHEN 5 THEN 'AR_TRANSACTIONS_S_V' 
57052                 WHEN 6 THEN 'AR_TRANSACTIONS_S_V' 
57056                 
57053                 WHEN 7 THEN 'AR_TRANSACTIONS_S_V' 
57054                 WHEN 8 THEN 'AR_TRANSACTIONS_S_V' 
57055                 WHEN 9 THEN 'AR_TRANSACTIONS_S_V' 
57057                ELSE null
57058               END                           object_name
57059             , CASE r
57060                 WHEN 1 THEN 'HEADER' 
57061                 WHEN 2 THEN 'HEADER' 
57062                 WHEN 3 THEN 'HEADER' 
57063                 WHEN 4 THEN 'HEADER' 
57064                 WHEN 5 THEN 'HEADER' 
57065                 WHEN 6 THEN 'HEADER' 
57066                 WHEN 7 THEN 'HEADER' 
57067                 WHEN 8 THEN 'HEADER' 
57068                 WHEN 9 THEN 'HEADER' 
57069                 
57070                 ELSE null
57071               END                           object_type_code
57072             , CASE r
57073                 WHEN 1 THEN '222' 
57074                 WHEN 2 THEN '222' 
57075                 WHEN 3 THEN '222' 
57076                 WHEN 4 THEN '222' 
57077                 WHEN 5 THEN '222' 
57078                 WHEN 6 THEN '222' 
57079                 WHEN 7 THEN '222' 
57080                 WHEN 8 THEN '222' 
57081                 WHEN 9 THEN '222' 
57082                 
57083                 ELSE null
57084               END                           source_application_id
57085             , 'S'             source_type_code
57086             , CASE r
57087                 WHEN 1 THEN 'TRX_RECEIVABLE_CCID' 
57088                 WHEN 2 THEN 'BILL_CUST_ACCOUNT_ID' 
57089                 WHEN 3 THEN 'BILL_USES_SITE_USE_ID' 
57090                 WHEN 4 THEN 'XLA_PARTY_TYPE' 
57091                 WHEN 5 THEN 'TRX_INVOICE_CURRENCY_CODE' 
57092                 WHEN 6 THEN 'TRX_INVOICING_RULE_ID' 
57093                 WHEN 7 THEN 'TRX_DOC_SEQUENCE_CATEGORY' 
57094                 WHEN 8 THEN 'TRX_DOC_SEQUENCE_ID' 
57095                 WHEN 9 THEN 'TRX_DOC_SEQUENCE_VALUE' 
57096                 
57097                 ELSE null
57098               END                           source_code
57099             , CASE r
57100                 WHEN 1 THEN TO_CHAR(h5.TRX_RECEIVABLE_CCID)
57101                 WHEN 2 THEN TO_CHAR(h1.BILL_CUST_ACCOUNT_ID)
57102                 WHEN 3 THEN TO_CHAR(h2.BILL_USES_SITE_USE_ID)
57103                 WHEN 4 THEN TO_CHAR(h5.XLA_PARTY_TYPE)
57104                 WHEN 5 THEN TO_CHAR(h5.TRX_INVOICE_CURRENCY_CODE)
57105                 WHEN 6 THEN TO_CHAR(h5.TRX_INVOICING_RULE_ID)
57106                 WHEN 7 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_CATEGORY)
57107                 WHEN 8 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_ID)
57108                 WHEN 9 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_VALUE)
57109                 
57110                 ELSE null
57111               END                           source_value
57112             , null              source_meaning
57113          FROM xla_events_gt     xet  
57114       , AR_BILL_TO_CUSTOMERS_S_V  h1
57115       , AR_BILL_TO_SITE_USES_S_V  h2
57116       , AR_TRANSACTIONS_S_V  h5
57117              ,(select rownum r from all_objects where rownum <= 9 and owner = p_apps_owner)
57118          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
57119            AND xet.event_class_code = C_EVENT_CLASS_CODE
57120               AND h1.event_id = xet.event_id
57121   AND h2.event_id  = h1.event_id
57122   AND h5.event_id  = h1.event_id
57123 
57124 )
57125 ;
57126 --
57127 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
57128 
57129       trace
57130          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
57131          ,p_level    => C_LEVEL_STATEMENT
57132          ,p_module   => l_log_module);
57133 
57134 END IF;
57135 --
57136 
57137 
57138 
57139 --
57140 INSERT INTO xla_diag_sources  --line2
57141 (
57142         event_id
57143       , ledger_id
57144       , sla_ledger_id
57145       , description_language
57146       , object_name
57147       , object_type_code
57148       , line_number
57149       , source_application_id
57150       , source_type_code
57151       , source_code
57152       , source_value
57153       , source_meaning
57154       , created_by
57155       , creation_date
57156       , last_update_date
57157       , last_updated_by
57158       , last_update_login
57159       , program_update_date
57160       , program_application_id
57161       , program_id
57162       , request_id
57163 )
57164 SELECT  event_id
57165       , p_target_ledger_id
57166       , p_sla_ledger_id
57167       , p_language
57168       , object_name
57169       , object_type_code
57170       , line_number
57171       , source_application_id
57172       , source_type_code
57173       , source_code
57174       , SUBSTR(source_value,1,1996)
57175       , SUBSTR(source_meaning ,1,200)
57176       , xla_environment_pkg.g_Usr_Id
57177       , TRUNC(SYSDATE)
57178       , TRUNC(SYSDATE)
57179       , xla_environment_pkg.g_Usr_Id
57180       , xla_environment_pkg.g_Login_Id
57181       , TRUNC(SYSDATE)
57182       , xla_environment_pkg.g_Prog_Appl_Id
57183       , xla_environment_pkg.g_Prog_Id
57184       , xla_environment_pkg.g_Req_Id
57185   FROM (
57186        SELECT xet.event_id                  event_id
57187             , l4.line_number                 line_number
57188             , CASE r
57189                WHEN 1 THEN 'AR_CUST_TRX_LINES_L_V' 
57190                 WHEN 2 THEN 'AR_CUST_TRX_LINES_L_V' 
57194                 WHEN 6 THEN 'AR_CUST_TRX_LINES_BASE_V' 
57191                 WHEN 3 THEN 'AR_CUST_TRX_LINES_L_V' 
57192                 WHEN 4 THEN 'AR_CUST_TRX_LINES_L_V' 
57193                 WHEN 5 THEN 'AR_CUST_TRX_LINES_L_V' 
57195                 WHEN 7 THEN 'AR_CUST_TRX_LINES_BASE_V' 
57196                 WHEN 8 THEN 'AR_CUST_TRX_LINES_BASE_V' 
57197                 WHEN 9 THEN 'AR_CUST_TRX_LINES_BASE_V' 
57198                 WHEN 10 THEN 'AR_CUST_TRX_LINES_L_V' 
57199                 
57200                ELSE null
57201               END                           object_name
57202             , CASE r
57203                 WHEN 1 THEN 'LINE' 
57204                 WHEN 2 THEN 'LINE' 
57205                 WHEN 3 THEN 'LINE' 
57206                 WHEN 4 THEN 'LINE' 
57207                 WHEN 5 THEN 'LINE' 
57208                 WHEN 6 THEN 'LINE' 
57209                 WHEN 7 THEN 'LINE' 
57210                 WHEN 8 THEN 'LINE' 
57211                 WHEN 9 THEN 'LINE' 
57212                 WHEN 10 THEN 'LINE' 
57213                 
57214                 ELSE null
57215               END                           object_type_code
57216             , CASE r
57217                 WHEN 1 THEN '222' 
57218                 WHEN 2 THEN '222' 
57219                 WHEN 3 THEN '222' 
57220                 WHEN 4 THEN '222' 
57221                 WHEN 5 THEN '222' 
57222                 WHEN 6 THEN '222' 
57223                 WHEN 7 THEN '222' 
57224                 WHEN 8 THEN '222' 
57225                 WHEN 9 THEN '222' 
57226                 WHEN 10 THEN '222' 
57227                 
57228                 ELSE null
57229               END                           source_application_id
57230             , 'S'             source_type_code
57231             , CASE r
57232                 WHEN 1 THEN 'TRX_LINE_DIST_CCID' 
57233                 WHEN 2 THEN 'TRX_LINE_DIST_ACCOUNT_CLASS' 
57234                 WHEN 3 THEN 'TRX_LINE_DIST_ID' 
57235                 WHEN 4 THEN 'TRX_DISTRIBUTION_TYPE' 
57236                 WHEN 5 THEN 'TRX_LINE_DIST_AMT' 
57237                 WHEN 6 THEN 'TRX_LINE_CUR_CONVERSION_DATE' 
57238                 WHEN 7 THEN 'TRX_LINE_CUR_CONVERSION_RATE' 
57239                 WHEN 8 THEN 'TRX_LINE_CUR_CONVERSION_TYPE' 
57240                 WHEN 9 THEN 'TRX_LINE_ACCTD_AMT' 
57241                 WHEN 10 THEN 'TRX_TAX_LINE_ID' 
57242                 
57243                 ELSE null
57244               END                           source_code
57245             , CASE r
57246                 WHEN 1 THEN TO_CHAR(l4.TRX_LINE_DIST_CCID)
57247                 WHEN 2 THEN TO_CHAR(l4.TRX_LINE_DIST_ACCOUNT_CLASS)
57248                 WHEN 3 THEN TO_CHAR(l4.TRX_LINE_DIST_ID)
57249                 WHEN 4 THEN TO_CHAR(l4.TRX_DISTRIBUTION_TYPE)
57250                 WHEN 5 THEN TO_CHAR(l4.TRX_LINE_DIST_AMT)
57251                 WHEN 6 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_DATE)
57252                 WHEN 7 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_RATE)
57253                 WHEN 8 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_TYPE)
57254                 WHEN 9 THEN TO_CHAR(l3.TRX_LINE_ACCTD_AMT)
57255                 WHEN 10 THEN TO_CHAR(l4.TRX_TAX_LINE_ID)
57256                 
57257                 ELSE null
57258               END                           source_value
57259             , null              source_meaning
57260          FROM  xla_events_gt     xet  
57261         , AR_CUST_TRX_LINES_BASE_V  l3
57262         , AR_CUST_TRX_LINES_L_V  l4
57263             , (select rownum r from all_objects where rownum <= 10 and owner = p_apps_owner)
57264         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
57265           AND xet.event_class_code = C_EVENT_CLASS_CODE
57266             AND l3.event_id          = xet.event_id
57270 )
57267   AND l4.event_id    = l3.event_id
57268   AND l4.line_number = l3.line_number
57269 
57271 ;
57272 --
57273 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
57274 
57275       trace
57276          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
57277          ,p_level    => C_LEVEL_STATEMENT
57278          ,p_module   => l_log_module);
57279 
57280 END IF;
57281 
57282 
57283 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
57284       trace
57285          (p_msg      => 'END of insert_sources_105'
57286          ,p_level    => C_LEVEL_PROCEDURE
57287          ,p_module   => l_log_module);
57288 END IF;
57289 EXCEPTION
57290   WHEN xla_exceptions_pkg.application_exception THEN
57291       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
57292             trace
57293                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
57294                ,p_level    => C_LEVEL_EXCEPTION
57295                ,p_module   => l_log_module);
57296       END IF;
57297       RAISE;
57298   WHEN OTHERS THEN
57299       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
57300             trace
57301                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
57302                ,p_level    => C_LEVEL_EXCEPTION
57303                ,p_module   => l_log_module);
57304        END IF;
57305        xla_exceptions_pkg.raise_message
57306            (p_location => 'XLA_00222_AAD_S_000008_PKG.insert_sources_105');
57307 END insert_sources_105;
57308 --
57309 
57310 ---------------------------------------
57311 --
57312 -- PRIVATE FUNCTION
57313 --         EventClass_105
57314 --
57315 ----------------------------------------
57316 --
57317 FUNCTION EventClass_105
57318        (p_application_id         IN NUMBER
57319        ,p_base_ledger_id         IN NUMBER
57320        ,p_target_ledger_id       IN NUMBER
57321        ,p_language               IN VARCHAR2
57322        ,p_currency_code          IN VARCHAR2
57323        ,p_sla_ledger_id          IN NUMBER
57324        ,p_pad_start_date         IN DATE
57325        ,p_pad_end_date           IN DATE
57326        ,p_primary_ledger_id      IN NUMBER)
57327 RETURN BOOLEAN IS
57328 --
57329 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'DEBIT_MEMO_ALL';
57330 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'DEBIT_MEMO';
57331 
57332 l_calculate_acctd_flag   VARCHAR2(1) :='N';
57333 l_calculate_g_l_flag     VARCHAR2(1) :='N';
57334 --
57335 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
57336 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
57337 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
57338 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
57339 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
57340 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
57341 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
57342 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
57343 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
57344 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
57345 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
57346 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
57347 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
57348 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
57349 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
57350 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
57351 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
57352 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
57353 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
57354 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
57355 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
57356 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
57357 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
57358 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
57359 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
57360 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
57361 
57362 l_event_id                             NUMBER;
57363 l_previous_event_id                    NUMBER;
57364 l_first_event_id                       NUMBER;
57365 l_last_event_id                        NUMBER;
57366 
57367 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
57371 l_result                    BOOLEAN := TRUE;
57368 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
57369 --
57370 --
57372 l_rows                      NUMBER  := 1000;
57373 l_event_type_name           VARCHAR2(80) := 'All';
57374 l_event_class_name          VARCHAR2(80) := 'Debit Memo';
57375 l_description               VARCHAR2(4000);
57376 l_transaction_reversal      NUMBER;
57377 l_ae_header_id              NUMBER;
57378 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
57379 l_log_module                VARCHAR2(240);
57380 --
57381 l_acct_reversal_source      VARCHAR2(30);
57382 l_trx_reversal_source       VARCHAR2(30);
57383 
57384 l_continue_with_lines       BOOLEAN := TRUE;
57385 --
57386 l_acc_rev_gl_date_source    DATE;                      -- 4262811
57387 --
57388 type t_array_event_id is table of number index by binary_integer;
57389 
57390 l_rec_array_event                    t_rec_array_event;
57391 l_null_rec_array_event               t_rec_array_event;
57392 l_array_ae_header_id                 xla_number_array_type;
57393 l_actual_flag                        VARCHAR2(1) := NULL;
57394 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
57395 l_balance_type_code                  VARCHAR2(1) :=NULL;
57396 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
57397 
57398 --
57399 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
57400 --
57401 
57402 TYPE t_array_source_9 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_RECEIVABLE_CCID%TYPE INDEX BY BINARY_INTEGER;
57403 TYPE t_array_source_23 IS TABLE OF AR_BILL_TO_CUSTOMERS_S_V.BILL_CUST_ACCOUNT_ID%TYPE INDEX BY BINARY_INTEGER;
57404 TYPE t_array_source_24 IS TABLE OF AR_BILL_TO_SITE_USES_S_V.BILL_USES_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
57405 TYPE t_array_source_25 IS TABLE OF AR_TRANSACTIONS_S_V.XLA_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
57406 TYPE t_array_source_30 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_INVOICE_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
57407 TYPE t_array_source_51 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_INVOICING_RULE_ID%TYPE INDEX BY BINARY_INTEGER;
57408 TYPE t_array_source_75 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
57409 TYPE t_array_source_76 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
57410 TYPE t_array_source_77 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
57411 
57412 TYPE t_array_source_4 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
57413 TYPE t_array_source_26 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ACCOUNT_CLASS%TYPE INDEX BY BINARY_INTEGER;
57414 TYPE t_array_source_27 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ID%TYPE INDEX BY BINARY_INTEGER;
57415 TYPE t_array_source_28 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
57416 TYPE t_array_source_29 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_AMT%TYPE INDEX BY BINARY_INTEGER;
57417 TYPE t_array_source_31 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
57418 TYPE t_array_source_32 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
57419 TYPE t_array_source_33 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
57420 TYPE t_array_source_34 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
57421 TYPE t_array_source_48 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_TAX_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
57422 
57423 l_array_source_9              t_array_source_9;
57424 l_array_source_23              t_array_source_23;
57425 l_array_source_24              t_array_source_24;
57426 l_array_source_25              t_array_source_25;
57427 l_array_source_30              t_array_source_30;
57428 l_array_source_51              t_array_source_51;
57429 l_array_source_75              t_array_source_75;
57430 l_array_source_76              t_array_source_76;
57431 l_array_source_77              t_array_source_77;
57432 
57433 l_array_source_4      t_array_source_4;
57434 l_array_source_26      t_array_source_26;
57435 l_array_source_27      t_array_source_27;
57436 l_array_source_28      t_array_source_28;
57437 l_array_source_29      t_array_source_29;
57438 l_array_source_31      t_array_source_31;
57439 l_array_source_32      t_array_source_32;
57440 l_array_source_33      t_array_source_33;
57441 l_array_source_34      t_array_source_34;
57442 l_array_source_48      t_array_source_48;
57443 
57444 --
57445 CURSOR header_cur
57446 IS
57447 SELECT /*+ leading(xet) cardinality(xet,1) */
57448 -- Event Class Code: DEBIT_MEMO
57449     xet.entity_id
57450    ,xet.legal_entity_id
57451    ,xet.entity_code
57452    ,xet.transaction_number
57453    ,xet.event_id
57454    ,xet.event_class_code
57455    ,xet.event_type_code
57456    ,xet.event_number
57457    ,xet.event_date
57458    ,xet.transaction_date
57459    ,xet.reference_num_1
57460    ,xet.reference_num_2
57461    ,xet.reference_num_3
57462    ,xet.reference_num_4
57463    ,xet.reference_char_1
57464    ,xet.reference_char_2
57465    ,xet.reference_char_3
57466    ,xet.reference_char_4
57467    ,xet.reference_date_1
57468    ,xet.reference_date_2
57469    ,xet.reference_date_3
57470    ,xet.reference_date_4
57471    ,xet.event_created_by
57472    ,xet.budgetary_control_flag 
57473   , h5.TRX_RECEIVABLE_CCID    source_9
57474   , h1.BILL_CUST_ACCOUNT_ID    source_23
57475   , h2.BILL_USES_SITE_USE_ID    source_24
57476   , h5.XLA_PARTY_TYPE    source_25
57477   , h5.TRX_INVOICE_CURRENCY_CODE    source_30
57478   , h5.TRX_INVOICING_RULE_ID    source_51
57479   , h5.TRX_DOC_SEQUENCE_CATEGORY    source_75
57480   , h5.TRX_DOC_SEQUENCE_ID    source_76
57481   , h5.TRX_DOC_SEQUENCE_VALUE    source_77
57482   FROM xla_events_gt     xet 
57486  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
57483   , AR_BILL_TO_CUSTOMERS_S_V  h1
57484   , AR_BILL_TO_SITE_USES_S_V  h2
57485   , AR_TRANSACTIONS_S_V  h5
57487    and xet.event_class_code = C_EVENT_CLASS_CODE
57488    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
57489   AND h2.event_id  = h1.event_id
57490   AND h5.event_id  = h1.event_id
57491 
57492  ORDER BY event_id
57493 ;
57494 
57495 
57496 --
57497 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
57498 IS
57499 SELECT  /*+ leading(xet) cardinality(xet,1) */
57500 -- Event Class Code: DEBIT_MEMO
57501     xet.entity_id
57502    ,xet.legal_entity_id
57503    ,xet.entity_code
57504    ,xet.transaction_number
57505    ,xet.event_id
57506    ,xet.event_class_code
57507    ,xet.event_type_code
57508    ,xet.event_number
57509    ,xet.event_date
57510    ,xet.transaction_date
57511    ,xet.reference_num_1
57512    ,xet.reference_num_2
57513    ,xet.reference_num_3
57514    ,xet.reference_num_4
57515    ,xet.reference_char_1
57516    ,xet.reference_char_2
57517    ,xet.reference_char_3
57518    ,xet.reference_char_4
57519    ,xet.reference_date_1
57520    ,xet.reference_date_2
57521    ,xet.reference_date_3
57522    ,xet.reference_date_4
57523    ,xet.event_created_by
57524    ,xet.budgetary_control_flag
57525  , l3.LINE_NUMBER  
57526   , l4.TRX_LINE_DIST_CCID    source_4
57527   , l4.TRX_LINE_DIST_ACCOUNT_CLASS    source_26
57528   , l4.TRX_LINE_DIST_ID    source_27
57529   , l4.TRX_DISTRIBUTION_TYPE    source_28
57530   , l4.TRX_LINE_DIST_AMT    source_29
57531   , l3.TRX_LINE_CUR_CONVERSION_DATE    source_31
57532   , l3.TRX_LINE_CUR_CONVERSION_RATE    source_32
57533   , l3.TRX_LINE_CUR_CONVERSION_TYPE    source_33
57534   , l3.TRX_LINE_ACCTD_AMT    source_34
57535   , l4.TRX_TAX_LINE_ID    source_48
57536   FROM xla_events_gt     xet 
57537   , AR_CUST_TRX_LINES_BASE_V  l3
57538   , AR_CUST_TRX_LINES_L_V  l4
57539  WHERE xet.event_id between x_first_event_id and x_last_event_id
57540    and xet.event_date between p_pad_start_date and p_pad_end_date
57541    and xet.event_class_code = C_EVENT_CLASS_CODE
57542    and xet.event_status_code <> 'N'   AND l3.event_id      = xet.event_id
57543   AND l4.event_id    = l3.event_id
57544   AND l4.line_number = l3.line_number
57545 ;
57546 
57547 --
57548 BEGIN
57549 IF g_log_enabled THEN
57550    l_log_module := C_DEFAULT_MODULE||'.EventClass_105';
57551 END IF;
57552 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
57553    trace
57554       (p_msg      => 'BEGIN of EventClass_105'
57555       ,p_level    => C_LEVEL_PROCEDURE
57556       ,p_module   => l_log_module);
57557 END IF;
57558 
57559 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
57560    trace
57561       (p_msg      => 'p_application_id = '||p_application_id||
57562                      ' - p_base_ledger_id = '||p_base_ledger_id||
57563                      ' - p_target_ledger_id  = '||p_target_ledger_id||
57564                      ' - p_language = '||p_language||
57565                      ' - p_currency_code = '||p_currency_code||
57566                      ' - p_sla_ledger_id = '||p_sla_ledger_id
57567       ,p_level    => C_LEVEL_STATEMENT
57568       ,p_module   => l_log_module);
57569 END IF;
57570 --
57571 -- initialze arrays
57572 --
57573 g_array_event.DELETE;
57574 l_rec_array_event := l_null_rec_array_event;
57575 --
57579 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
57576 --------------------------------------
57577 -- 4262811 Initialze MPA Line Number
57578 --------------------------------------
57580 
57581 --
57582 
57583 --
57584 OPEN header_cur;
57585 --
57586 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
57587    trace
57588    (p_msg      => 'SQL - FETCH header_cur'
57589    ,p_level    => C_LEVEL_STATEMENT
57590    ,p_module   => l_log_module);
57591 END IF;
57592 --
57593 LOOP
57594 FETCH header_cur BULK COLLECT INTO
57595         l_array_entity_id
57596       , l_array_legal_entity_id
57597       , l_array_entity_code
57598       , l_array_transaction_num
57599       , l_array_event_id
57600       , l_array_class_code
57601       , l_array_event_type
57602       , l_array_event_number
57603       , l_array_event_date
57604       , l_array_transaction_date
57605       , l_array_reference_num_1
57606       , l_array_reference_num_2
57607       , l_array_reference_num_3
57608       , l_array_reference_num_4
57609       , l_array_reference_char_1
57610       , l_array_reference_char_2
57611       , l_array_reference_char_3
57612       , l_array_reference_char_4
57613       , l_array_reference_date_1
57614       , l_array_reference_date_2
57615       , l_array_reference_date_3
57616       , l_array_reference_date_4
57617       , l_array_event_created_by
57618       , l_array_budgetary_control_flag 
57619       , l_array_source_9
57620       , l_array_source_23
57621       , l_array_source_24
57622       , l_array_source_25
57623       , l_array_source_30
57624       , l_array_source_51
57625       , l_array_source_75
57626       , l_array_source_76
57627       , l_array_source_77
57628       LIMIT l_rows;
57629 --
57630 IF (C_LEVEL_EVENT >= g_log_level) THEN
57631    trace
57632    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
57633    ,p_level    => C_LEVEL_EVENT
57634    ,p_module   => l_log_module);
57635 END IF;
57636 --
57637 EXIT WHEN l_array_entity_id.COUNT = 0;
57638 
57639 -- initialize arrays
57640 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
57641 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
57642 
57643 --
57644 -- Bug 4458708
57645 --
57646 XLA_AE_LINES_PKG.g_LineNumber := 0;
57647 
57648 
57649 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
57650 g_last_hdr_idx := l_array_event_id.LAST;
57651 --
57652 -- loop for the headers. Each iteration is for each header extract row
57653 -- fetched in header cursor
57654 --
57655 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
57656 
57657 --
57658 -- set event info as cache for other routines to refer event attributes
57659 --
57660 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
57661    (p_application_id           => p_application_id
57662    ,p_primary_ledger_id        => p_primary_ledger_id
57663    ,p_base_ledger_id           => p_base_ledger_id
57664    ,p_target_ledger_id         => p_target_ledger_id
57665    ,p_entity_id                => l_array_entity_id(hdr_idx)
57666    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
57667    ,p_entity_code              => l_array_entity_code(hdr_idx)
57668    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
57669    ,p_event_id                 => l_array_event_id(hdr_idx)
57670    ,p_event_class_code         => l_array_class_code(hdr_idx)
57671    ,p_event_type_code          => l_array_event_type(hdr_idx)
57672    ,p_event_number             => l_array_event_number(hdr_idx)
57673    ,p_event_date               => l_array_event_date(hdr_idx)
57674    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
57675    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
57676    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
57677    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
57678    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
57679    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
57680    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
57681    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
57682    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
57683    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
57684    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
57685    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
57686    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
57687    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
57688    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
57689 
57690 --
57691 -- set the status of entry to C_VALID (0)
57692 --
57693 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
57694 
57695 --
57696 -- initialize a row for ae header
57697 --
57698 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
57699 
57700 l_event_id := l_array_event_id(hdr_idx);
57701 
57702 --
57703 -- storing the hdr_idx for event. May be used by line cursor.
57704 --
57705 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
57706 
57707 --
57708 -- store sources from header extract. This can be improved to
57709 -- store only those sources from header extract that may be used in lines
57710 --
57711 
57712 g_array_event(l_event_id).array_value_num('source_9') := l_array_source_9(hdr_idx);
57713 g_array_event(l_event_id).array_value_num('source_23') := l_array_source_23(hdr_idx);
57714 g_array_event(l_event_id).array_value_num('source_24') := l_array_source_24(hdr_idx);
57718 g_array_event(l_event_id).array_value_char('source_75') := l_array_source_75(hdr_idx);
57715 g_array_event(l_event_id).array_value_char('source_25') := l_array_source_25(hdr_idx);
57716 g_array_event(l_event_id).array_value_char('source_30') := l_array_source_30(hdr_idx);
57717 g_array_event(l_event_id).array_value_num('source_51') := l_array_source_51(hdr_idx);
57719 g_array_event(l_event_id).array_value_num('source_76') := l_array_source_76(hdr_idx);
57720 g_array_event(l_event_id).array_value_num('source_77') := l_array_source_77(hdr_idx);
57721 
57722 --
57723 -- initilaize the status of ae headers for diffrent balance types
57724 -- the status is initialised to C_NOT_CREATED (2)
57725 --
57726 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
57727 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
57728 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
57729 
57730 --
57731 -- call api to validate and store accounting attributes for header
57732 --
57733 
57734 ------------------------------------------------------------
57735 -- Accrual Reversal : to get date for Standard Source (NONE)
57736 ------------------------------------------------------------
57737 l_acc_rev_gl_date_source := NULL;
57738 
57739      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
57740       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_75');
57741      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
57742       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_76');
57743      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
57744       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_77');
57745      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
57746       l_rec_acct_attrs.array_date_value(4) := 
57747 xla_ae_sources_pkg.GetSystemSourceDate(
57748    p_source_code           => 'XLA_EVENT_DATE'
57749  , p_source_type_code      => 'Y'
57750  , p_source_application_id =>  602
57751 );
57752 
57753 
57754 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
57755 
57756 XLA_AE_HEADER_PKG.SetJeCategoryName;
57757 
57758 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
57759 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
57760 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
57761 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
57762 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
57763 
57764 
57765 -- No header level analytical criteria
57766 
57767 --
57768 --accounting attribute enhancement, bug 3612931
57769 --
57770 l_trx_reversal_source := SUBSTR(NULL, 1,30);
57771 
57772 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
57773    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
57774 
57775    xla_accounting_err_pkg.build_message
57776       (p_appli_s_name            => 'XLA'
57777       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
57778       ,p_token_1                 => 'ACCT_ATTR_NAME'
57779       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
57780       ,p_token_2                 => 'PRODUCT_NAME'
57781       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
57782       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
57783       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
57784       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
57785 
57786 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
57787    --
57788    -- following sets the accounting attributes needed to reverse
57789    -- accounting for a distributeion
57790    --
57791    xla_ae_lines_pkg.SetTrxReversalAttrs
57792       (p_event_id              => l_event_id
57793       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
57797 
57794       ,p_trx_reversal_source   => l_trx_reversal_source);
57795 
57796 END IF;
57798 
57799 ----------------------------------------------------------------
57800 -- 4262811 -  update the header statuses to invalid in need be
57801 ----------------------------------------------------------------
57802 --
57803 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
57804 
57805 
57806   -----------------------------------------------
57807   -- No accrual reversal for the event class/type
57808   -----------------------------------------------
57809 ----------------------------------------------------------------
57810 
57811 --
57812 -- this ends the header loop iteration for one bulk fetch
57813 --
57814 END LOOP;
57815 
57816 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
57817 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
57818 
57819 --
57820 -- insert dummy rows into lines gt table that were created due to
57821 -- transaction reversals
57822 --
57823 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
57824    l_result := XLA_AE_LINES_PKG.InsertLines;
57825 END IF;
57826 
57827 --
57828 -- reset the temp_line_num for each set of events fetched from header
57829 -- cursor rather than doing it for each new event in line cursor
57830 -- Bug 3939231
57831 --
57832 xla_ae_lines_pkg.g_temp_line_num := 0;
57833 
57834 
57835 
57836 --
57837 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
57838 --
57839 --
57840 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
57841 
57842       trace
57843          (p_msg      => 'SQL - FETCH line_cur'
57844          ,p_level    => C_LEVEL_STATEMENT
57845          ,p_module   => l_log_module);
57846 
57847 END IF;
57848 --
57849 --
57850 LOOP
57851   --
57852   FETCH line_cur BULK COLLECT INTO
57853         l_array_entity_id
57854       , l_array_legal_entity_id
57855       , l_array_entity_code
57856       , l_array_transaction_num
57857       , l_array_event_id
57858       , l_array_class_code
57859       , l_array_event_type
57860       , l_array_event_number
57861       , l_array_event_date
57862       , l_array_transaction_date
57863       , l_array_reference_num_1
57864       , l_array_reference_num_2
57865       , l_array_reference_num_3
57866       , l_array_reference_num_4
57867       , l_array_reference_char_1
57868       , l_array_reference_char_2
57869       , l_array_reference_char_3
57870       , l_array_reference_char_4
57871       , l_array_reference_date_1
57872       , l_array_reference_date_2
57873       , l_array_reference_date_3
57874       , l_array_reference_date_4
57875       , l_array_event_created_by
57876       , l_array_budgetary_control_flag
57877       , l_array_extract_line_num 
57878       , l_array_source_4
57879       , l_array_source_26
57880       , l_array_source_27
57881       , l_array_source_28
57882       , l_array_source_29
57883       , l_array_source_31
57884       , l_array_source_32
57885       , l_array_source_33
57886       , l_array_source_34
57887       , l_array_source_48
57888       LIMIT l_rows;
57889 
57890   --
57891   IF (C_LEVEL_EVENT >= g_log_level) THEN
57892             trace
57893                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
57894                ,p_level    => C_LEVEL_EVENT
57895                ,p_module   => l_log_module);
57896   END IF;
57897   --
57898   EXIT WHEN l_array_entity_id.count = 0;
57899 
57900   XLA_AE_LINES_PKG.g_rec_lines := null;
57901 
57902 --
57903 -- Bug 4458708
57904 --
57905 XLA_AE_LINES_PKG.g_LineNumber := 0;
57906 --
57907 --
57911    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
57908 
57909 FOR Idx IN 1..l_array_event_id.count LOOP
57910    --
57912    --
57913    l_event_id := l_array_event_id(idx);  -- 5648433
57914 
57915    --
57916    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
57917    --
57918 
57919    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
57920              (g_array_event(l_event_id).array_value_num('header_index'))
57921          ,'N'
57922          ) <> 'Y'
57923    THEN
57924       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
57925          trace
57926             (p_msg      => 'Trancaction revesal option is not Y '
57927             ,p_level    => C_LEVEL_STATEMENT
57928             ,p_module   => l_log_module);
57929       END IF;
57930 
57931 --
57932 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
57933 --
57934 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
57935 --
57936 -- set event info as cache for other routines to refer event attributes
57937 --
57938 
57939 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
57940    l_previous_event_id := l_event_id;
57941 
57942    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
57943       (p_application_id           => p_application_id
57944       ,p_primary_ledger_id        => p_primary_ledger_id
57945       ,p_base_ledger_id           => p_base_ledger_id
57946       ,p_target_ledger_id         => p_target_ledger_id
57947       ,p_entity_id                => l_array_entity_id(Idx)
57948       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
57949       ,p_entity_code              => l_array_entity_code(Idx)
57950       ,p_transaction_num          => l_array_transaction_num(Idx)
57951       ,p_event_id                 => l_array_event_id(Idx)
57952       ,p_event_class_code         => l_array_class_code(Idx)
57953       ,p_event_type_code          => l_array_event_type(Idx)
57954       ,p_event_number             => l_array_event_number(Idx)
57955       ,p_event_date               => l_array_event_date(Idx)
57956       ,p_transaction_date         => l_array_transaction_date(Idx)
57957       ,p_reference_num_1          => l_array_reference_num_1(Idx)
57958       ,p_reference_num_2          => l_array_reference_num_2(Idx)
57959       ,p_reference_num_3          => l_array_reference_num_3(Idx)
57960       ,p_reference_num_4          => l_array_reference_num_4(Idx)
57961       ,p_reference_char_1         => l_array_reference_char_1(Idx)
57962       ,p_reference_char_2         => l_array_reference_char_2(Idx)
57963       ,p_reference_char_3         => l_array_reference_char_3(Idx)
57964       ,p_reference_char_4         => l_array_reference_char_4(Idx)
57965       ,p_reference_date_1         => l_array_reference_date_1(Idx)
57966       ,p_reference_date_2         => l_array_reference_date_2(Idx)
57967       ,p_reference_date_3         => l_array_reference_date_3(Idx)
57968       ,p_reference_date_4         => l_array_reference_date_4(Idx)
57969       ,p_event_created_by         => l_array_event_created_by(Idx)
57970       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
57971        --
57972 END IF;
57973 
57974 
57975 
57976 --
57977 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
57978 
57979 l_acct_reversal_source := SUBSTR(NULL, 1,30);
57980 
57981 IF l_continue_with_lines THEN
57982    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
57983       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
57984 
57985       xla_accounting_err_pkg.build_message
57986          (p_appli_s_name            => 'XLA'
57987          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
57988          ,p_token_1                 => 'LINE_NUMBER'
57989          ,p_value_1                 => l_array_extract_line_num(Idx)
57990          ,p_token_2                 => 'PRODUCT_NAME'
57991          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
57992          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
57993          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
57994          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
57995 
57996    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
57997       --
57998       -- following sets the accounting attributes needed to reverse
57999       -- accounting for a distributeion
58000       --
58001 
58002       --
58003       -- 5217187
58004       --
58005       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
58006       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
58007                                        g_array_event(l_event_id).array_value_num('header_index'));
58008       --
58009       --
58010 
58011       -- No reversal code generated
58012 
58013       xla_ae_lines_pkg.SetAcctReversalAttrs
58014          (p_event_id             => l_event_id
58018    END IF;
58015          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
58016          ,p_calculate_acctd_flag => l_calculate_acctd_flag
58017          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
58019 
58020    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
58021        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
58022 
58023 --
58024 AcctLineType_36 (
58025  p_application_id  => p_application_id
58026  ,p_event_id     => l_event_id
58027  ,p_calculate_acctd_flag => l_calculate_acctd_flag
58028  ,p_calculate_g_l_flag => l_calculate_g_l_flag
58029  ,p_actual_flag => l_actual_flag
58030  ,p_balance_type_code => l_balance_type_code
58031  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
58032  
58033  , p_source_4 => l_array_source_4(Idx)
58034  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
58035  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
58036  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
58037  , p_source_26 => l_array_source_26(Idx)
58038  , p_source_27 => l_array_source_27(Idx)
58039  , p_source_28 => l_array_source_28(Idx)
58040  , p_source_29 => l_array_source_29(Idx)
58041  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
58042  , p_source_31 => l_array_source_31(Idx)
58043  , p_source_32 => l_array_source_32(Idx)
58044  , p_source_33 => l_array_source_33(Idx)
58045  , p_source_34 => l_array_source_34(Idx)
58046  , p_source_48 => l_array_source_48(Idx)
58047  );
58048 If(l_balance_type_code = 'A') THEN
58049   l_actual_gain_loss_ref := l_gain_or_loss_ref;
58050 END IF;
58051 
58052 --
58053 
58054 
58055 --
58056 AcctLineType_37 (
58057  p_application_id  => p_application_id
58058  ,p_event_id     => l_event_id
58059  ,p_calculate_acctd_flag => l_calculate_acctd_flag
58060  ,p_calculate_g_l_flag => l_calculate_g_l_flag
58061  ,p_actual_flag => l_actual_flag
58062  ,p_balance_type_code => l_balance_type_code
58063  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
58064  
58065  , p_source_4 => l_array_source_4(Idx)
58066  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
58067  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
58068  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
58069  , p_source_26 => l_array_source_26(Idx)
58070  , p_source_27 => l_array_source_27(Idx)
58071  , p_source_28 => l_array_source_28(Idx)
58072  , p_source_29 => l_array_source_29(Idx)
58073  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
58074  , p_source_31 => l_array_source_31(Idx)
58075  , p_source_32 => l_array_source_32(Idx)
58076  , p_source_33 => l_array_source_33(Idx)
58077  , p_source_34 => l_array_source_34(Idx)
58078  , p_source_48 => l_array_source_48(Idx)
58079  );
58080 If(l_balance_type_code = 'A') THEN
58081   l_actual_gain_loss_ref := l_gain_or_loss_ref;
58082 END IF;
58083 
58084 --
58085 
58086 
58087 --
58088 AcctLineType_38 (
58089  p_application_id  => p_application_id
58090  ,p_event_id     => l_event_id
58091  ,p_calculate_acctd_flag => l_calculate_acctd_flag
58092  ,p_calculate_g_l_flag => l_calculate_g_l_flag
58093  ,p_actual_flag => l_actual_flag
58094  ,p_balance_type_code => l_balance_type_code
58095  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
58096  
58097  , p_source_4 => l_array_source_4(Idx)
58098  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
58099  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
58100  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
58101  , p_source_26 => l_array_source_26(Idx)
58102  , p_source_27 => l_array_source_27(Idx)
58103  , p_source_28 => l_array_source_28(Idx)
58104  , p_source_29 => l_array_source_29(Idx)
58105  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
58106  , p_source_31 => l_array_source_31(Idx)
58107  , p_source_32 => l_array_source_32(Idx)
58108  , p_source_33 => l_array_source_33(Idx)
58109  , p_source_34 => l_array_source_34(Idx)
58110  , p_source_48 => l_array_source_48(Idx)
58111  );
58112 If(l_balance_type_code = 'A') THEN
58113   l_actual_gain_loss_ref := l_gain_or_loss_ref;
58114 END IF;
58115 
58116 --
58117 
58118 
58119 --
58120 AcctLineType_39 (
58121  p_application_id  => p_application_id
58122  ,p_event_id     => l_event_id
58123  ,p_calculate_acctd_flag => l_calculate_acctd_flag
58124  ,p_calculate_g_l_flag => l_calculate_g_l_flag
58125  ,p_actual_flag => l_actual_flag
58126  ,p_balance_type_code => l_balance_type_code
58127  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
58128  
58129  , p_source_4 => l_array_source_4(Idx)
58130  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
58131  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
58132  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
58133  , p_source_26 => l_array_source_26(Idx)
58134  , p_source_27 => l_array_source_27(Idx)
58135  , p_source_28 => l_array_source_28(Idx)
58136  , p_source_29 => l_array_source_29(Idx)
58137  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
58138  , p_source_31 => l_array_source_31(Idx)
58139  , p_source_32 => l_array_source_32(Idx)
58140  , p_source_33 => l_array_source_33(Idx)
58141  , p_source_34 => l_array_source_34(Idx)
58142  , p_source_48 => l_array_source_48(Idx)
58143  );
58144 If(l_balance_type_code = 'A') THEN
58145   l_actual_gain_loss_ref := l_gain_or_loss_ref;
58146 END IF;
58147 
58148 --
58149 
58150 
58151 --
58152 AcctLineType_40 (
58153  p_application_id  => p_application_id
58157  ,p_actual_flag => l_actual_flag
58154  ,p_event_id     => l_event_id
58155  ,p_calculate_acctd_flag => l_calculate_acctd_flag
58156  ,p_calculate_g_l_flag => l_calculate_g_l_flag
58158  ,p_balance_type_code => l_balance_type_code
58159  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
58160  
58161  , p_source_4 => l_array_source_4(Idx)
58162  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
58163  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
58164  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
58165  , p_source_26 => l_array_source_26(Idx)
58166  , p_source_27 => l_array_source_27(Idx)
58167  , p_source_28 => l_array_source_28(Idx)
58168  , p_source_29 => l_array_source_29(Idx)
58169  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
58170  , p_source_31 => l_array_source_31(Idx)
58171  , p_source_32 => l_array_source_32(Idx)
58172  , p_source_33 => l_array_source_33(Idx)
58173  , p_source_34 => l_array_source_34(Idx)
58174  , p_source_48 => l_array_source_48(Idx)
58175  );
58176 If(l_balance_type_code = 'A') THEN
58177   l_actual_gain_loss_ref := l_gain_or_loss_ref;
58178 END IF;
58179 
58180 --
58181 
58182 
58183 --
58184 AcctLineType_41 (
58185  p_application_id  => p_application_id
58186  ,p_event_id     => l_event_id
58187  ,p_calculate_acctd_flag => l_calculate_acctd_flag
58188  ,p_calculate_g_l_flag => l_calculate_g_l_flag
58189  ,p_actual_flag => l_actual_flag
58190  ,p_balance_type_code => l_balance_type_code
58191  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
58192  
58193  , p_source_4 => l_array_source_4(Idx)
58194  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
58195  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
58196  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
58197  , p_source_26 => l_array_source_26(Idx)
58198  , p_source_27 => l_array_source_27(Idx)
58199  , p_source_28 => l_array_source_28(Idx)
58200  , p_source_29 => l_array_source_29(Idx)
58201  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
58202  , p_source_31 => l_array_source_31(Idx)
58203  , p_source_32 => l_array_source_32(Idx)
58204  , p_source_33 => l_array_source_33(Idx)
58205  , p_source_34 => l_array_source_34(Idx)
58206  , p_source_48 => l_array_source_48(Idx)
58207  );
58208 If(l_balance_type_code = 'A') THEN
58209   l_actual_gain_loss_ref := l_gain_or_loss_ref;
58210 END IF;
58211 
58212 --
58213 
58214 
58215 --
58216 AcctLineType_42 (
58217  p_application_id  => p_application_id
58218  ,p_event_id     => l_event_id
58219  ,p_calculate_acctd_flag => l_calculate_acctd_flag
58220  ,p_calculate_g_l_flag => l_calculate_g_l_flag
58221  ,p_actual_flag => l_actual_flag
58222  ,p_balance_type_code => l_balance_type_code
58223  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
58224  
58225  , p_source_4 => l_array_source_4(Idx)
58226  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
58227  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
58228  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
58229  , p_source_26 => l_array_source_26(Idx)
58230  , p_source_27 => l_array_source_27(Idx)
58231  , p_source_28 => l_array_source_28(Idx)
58232  , p_source_29 => l_array_source_29(Idx)
58233  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
58234  , p_source_31 => l_array_source_31(Idx)
58235  , p_source_32 => l_array_source_32(Idx)
58236  , p_source_33 => l_array_source_33(Idx)
58237  , p_source_34 => l_array_source_34(Idx)
58238  , p_source_48 => l_array_source_48(Idx)
58239  );
58240 If(l_balance_type_code = 'A') THEN
58241   l_actual_gain_loss_ref := l_gain_or_loss_ref;
58242 END IF;
58243 
58244 --
58245 
58246 
58247 --
58248 AcctLineType_54 (
58249  p_application_id  => p_application_id
58250  ,p_event_id     => l_event_id
58251  ,p_calculate_acctd_flag => l_calculate_acctd_flag
58252  ,p_calculate_g_l_flag => l_calculate_g_l_flag
58253  ,p_actual_flag => l_actual_flag
58254  ,p_balance_type_code => l_balance_type_code
58255  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
58256  
58257  , p_source_4 => l_array_source_4(Idx)
58258  , p_source_9 => g_array_event(l_event_id).array_value_num('source_9')
58259  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
58260  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
58261  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
58262  , p_source_26 => l_array_source_26(Idx)
58263  , p_source_27 => l_array_source_27(Idx)
58264  , p_source_28 => l_array_source_28(Idx)
58265  , p_source_29 => l_array_source_29(Idx)
58266  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
58267  , p_source_31 => l_array_source_31(Idx)
58268  , p_source_32 => l_array_source_32(Idx)
58269  , p_source_33 => l_array_source_33(Idx)
58270  , p_source_34 => l_array_source_34(Idx)
58271  , p_source_48 => l_array_source_48(Idx)
58272  , p_source_51 => g_array_event(l_event_id).array_value_num('source_51')
58273  );
58274 If(l_balance_type_code = 'A') THEN
58275   l_actual_gain_loss_ref := l_gain_or_loss_ref;
58276 END IF;
58277 
58278 --
58279 
58280       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
58281       -- or secondary ledger that has different currency with primary
58282       -- or alc that is calculated by sla
58283       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
58287 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
58284             (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'))
58285 
58286 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
58288           AND (l_actual_flag = 'A')) THEN
58289         XLA_AE_LINES_PKG.CreateGainOrLossLines(
58290           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
58291          ,p_application_id   => p_application_id
58292          ,p_amb_context_code => 'DEFAULT'
58293          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
58294          ,p_event_class_code => C_EVENT_CLASS_CODE
58295          ,p_event_type_code  => C_EVENT_TYPE_CODE
58296          
58297          ,p_gain_ccid        => -1
58298          ,p_loss_ccid        => -1
58299 
58300          ,p_actual_flag      => l_actual_flag
58301          ,p_enc_flag         => null
58302          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
58303          ,p_enc_g_l_ref      => null
58304          );
58305       END IF;
58306    END IF;
58307 END IF;
58308 
58309    ELSE
58310       --
58311       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
58312       --
58313       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
58314          trace
58315             (p_msg      => 'Trancaction revesal option is Y'
58316             ,p_level    => C_LEVEL_STATEMENT
58317             ,p_module   => l_log_module);
58318       END IF;
58319    END IF;
58320 
58321 END LOOP;
58322 l_result := XLA_AE_LINES_PKG.InsertLines ;
58323 end loop;
58324 close line_cur;
58325 
58326 
58327 --
58328 -- insert headers into xla_ae_headers_gt table
58329 --
58330 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
58331 
58332 -- insert into errors table here.
58333 
58334 END LOOP;
58335 
58336 --
58337 -- 4865292
58338 --
58339 -- Compare g_hdr_extract_count with event count in
58340 -- CreateHeadersAndLines.
58341 --
58342 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
58343 
58344 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
58345    trace (p_msg     => '# rows extracted from header extract objects '
58346                     || ' (running total): '
58347                     || g_hdr_extract_count
58348          ,p_level   => C_LEVEL_STATEMENT
58349          ,p_module  => l_log_module);
58350 END IF;
58351 
58352 CLOSE header_cur;
58353 --
58354 
58355 --
58356 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
58357    trace
58358       (p_msg      => 'END of EventClass_105'
58359       ,p_level    => C_LEVEL_PROCEDURE
58360       ,p_module   => l_log_module);
58361 END IF;
58362 --
58363 RETURN l_result;
58364 EXCEPTION
58365 WHEN xla_exceptions_pkg.application_exception THEN
58366    
58367 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
58368 
58369    
58370 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
58371 
58372    RAISE;
58373 
58374 WHEN NO_DATA_FOUND THEN
58375 
58376 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
58377 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
58378 
58379 FOR header_record IN header_cur
58380 LOOP
58381     l_array_header_events(header_record.event_id) := header_record.event_id;
58382 END LOOP;
58383 
58384 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
58385 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
58386 
58387 fnd_file.put_line(fnd_file.LOG, '                    ');
58388 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
58389 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
58390 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
58391 
58392 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
58393 LOOP
58394 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
58395 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
58396         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
58397 	END IF;
58398 END LOOP;
58399 
58400 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
58401 fnd_file.put_line(fnd_file.LOG, '                    ');
58402 
58403 
58404 xla_exceptions_pkg.raise_message
58405       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_105');
58406 
58407 
58408 WHEN OTHERS THEN
58409    xla_exceptions_pkg.raise_message
58410       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_105');
58411 END EventClass_105;
58412 --
58413 
58414 ---------------------------------------
58415 --
58416 -- PRIVATE PROCEDURE
58417 --         insert_sources_106
58418 --
58419 ----------------------------------------
58420 --
58421 PROCEDURE insert_sources_106(
58422                                 p_target_ledger_id       IN NUMBER
58423                               , p_language               IN VARCHAR2
58424                               , p_sla_ledger_id          IN NUMBER
58425                               , p_pad_start_date         IN DATE
58426                               , p_pad_end_date           IN DATE
58430 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'DEPOSIT_ALL';
58427                          )
58428 IS
58429 
58431 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'DEPOSIT';
58432 p_apps_owner                   VARCHAR2(30);
58433 l_log_module                   VARCHAR2(240);
58434 BEGIN
58435 IF g_log_enabled THEN
58436       l_log_module := C_DEFAULT_MODULE||'.insert_sources_106';
58437 END IF;
58438 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
58439 
58440       trace
58441          (p_msg      => 'BEGIN of insert_sources_106'
58442          ,p_level    => C_LEVEL_PROCEDURE
58443          ,p_module   => l_log_module);
58444 
58445 END IF;
58446 
58447 -- select APPS owner
58448 SELECT oracle_username
58449   INTO p_apps_owner
58450   FROM fnd_oracle_userid
58451  WHERE read_only_flag = 'U'
58452 ;
58453 
58454 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
58455       trace
58456          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
58457                         ' - p_language = '||p_language||
58458                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
58459                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
58460                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
58461                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
58462          ,p_level    => C_LEVEL_STATEMENT
58463          ,p_module   => l_log_module);
58464 END IF;
58465 
58466 
58467 --
58468 INSERT INTO xla_diag_sources --hdr2
58469 (
58470         event_id
58471       , ledger_id
58472       , sla_ledger_id
58473       , description_language
58474       , object_name
58475       , object_type_code
58476       , line_number
58477       , source_application_id
58478       , source_type_code
58479       , source_code
58480       , source_value
58481       , source_meaning
58482       , created_by
58483       , creation_date
58484       , last_update_date
58485       , last_updated_by
58486       , last_update_login
58487       , program_update_date
58488       , program_application_id
58489       , program_id
58490       , request_id
58491 )
58492 SELECT
58493         event_id
58494       , p_target_ledger_id
58495       , p_sla_ledger_id
58496       , p_language
58497       , object_name
58498       , object_type_code
58499       , line_number
58500       , source_application_id
58501       , source_type_code
58502       , source_code
58503       , SUBSTR(source_value ,1,1996)
58504       , SUBSTR(source_meaning ,1,200)
58505       , xla_environment_pkg.g_Usr_Id
58506       , TRUNC(SYSDATE)
58507       , TRUNC(SYSDATE)
58508       , xla_environment_pkg.g_Usr_Id
58509       , xla_environment_pkg.g_Login_Id
58510       , TRUNC(SYSDATE)
58511       , xla_environment_pkg.g_Prog_Appl_Id
58512       , xla_environment_pkg.g_Prog_Id
58513       , xla_environment_pkg.g_Req_Id
58514   FROM (
58515        SELECT xet.event_id                  event_id
58516             , 0                          line_number
58517             , CASE r
58518                WHEN 1 THEN 'AR_BILL_TO_CUSTOMERS_S_V' 
58519                 WHEN 2 THEN 'AR_BILL_TO_SITE_USES_S_V' 
58520                 WHEN 3 THEN 'AR_TRANSACTIONS_S_V' 
58521                 WHEN 4 THEN 'AR_TRANSACTIONS_S_V' 
58522                 WHEN 5 THEN 'AR_TRANSACTIONS_S_V' 
58523                 WHEN 6 THEN 'AR_TRANSACTIONS_S_V' 
58524                 WHEN 7 THEN 'AR_TRANSACTIONS_S_V' 
58525                 
58526                ELSE null
58527               END                           object_name
58528             , CASE r
58529                 WHEN 1 THEN 'HEADER' 
58530                 WHEN 2 THEN 'HEADER' 
58531                 WHEN 3 THEN 'HEADER' 
58532                 WHEN 4 THEN 'HEADER' 
58533                 WHEN 5 THEN 'HEADER' 
58534                 WHEN 6 THEN 'HEADER' 
58535                 WHEN 7 THEN 'HEADER' 
58536                 
58537                 ELSE null
58538               END                           object_type_code
58539             , CASE r
58540                 WHEN 1 THEN '222' 
58541                 WHEN 2 THEN '222' 
58542                 WHEN 3 THEN '222' 
58543                 WHEN 4 THEN '222' 
58544                 WHEN 5 THEN '222' 
58545                 WHEN 6 THEN '222' 
58546                 WHEN 7 THEN '222' 
58547                 
58548                 ELSE null
58549               END                           source_application_id
58550             , 'S'             source_type_code
58551             , CASE r
58552                 WHEN 1 THEN 'BILL_CUST_ACCOUNT_ID' 
58553                 WHEN 2 THEN 'BILL_USES_SITE_USE_ID' 
58554                 WHEN 3 THEN 'XLA_PARTY_TYPE' 
58555                 WHEN 4 THEN 'TRX_INVOICE_CURRENCY_CODE' 
58556                 WHEN 5 THEN 'TRX_DOC_SEQUENCE_CATEGORY' 
58557                 WHEN 6 THEN 'TRX_DOC_SEQUENCE_ID' 
58558                 WHEN 7 THEN 'TRX_DOC_SEQUENCE_VALUE' 
58559                 
58560                 ELSE null
58561               END                           source_code
58562             , CASE r
58563                 WHEN 1 THEN TO_CHAR(h1.BILL_CUST_ACCOUNT_ID)
58564                 WHEN 2 THEN TO_CHAR(h2.BILL_USES_SITE_USE_ID)
58565                 WHEN 3 THEN TO_CHAR(h5.XLA_PARTY_TYPE)
58566                 WHEN 4 THEN TO_CHAR(h5.TRX_INVOICE_CURRENCY_CODE)
58567                 WHEN 5 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_CATEGORY)
58568                 WHEN 6 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_ID)
58569                 WHEN 7 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_VALUE)
58570                 
58571                 ELSE null
58572               END                           source_value
58573             , null              source_meaning
58574          FROM xla_events_gt     xet  
58575       , AR_BILL_TO_CUSTOMERS_S_V  h1
58576       , AR_BILL_TO_SITE_USES_S_V  h2
58577       , AR_TRANSACTIONS_S_V  h5
58578              ,(select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
58579          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
58580            AND xet.event_class_code = C_EVENT_CLASS_CODE
58581               AND h1.event_id = xet.event_id
58582   AND h2.event_id  = h1.event_id
58583   AND h5.event_id  = h1.event_id
58584 
58585 )
58586 ;
58587 --
58588 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
58589 
58590       trace
58591          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
58592          ,p_level    => C_LEVEL_STATEMENT
58593          ,p_module   => l_log_module);
58594 
58595 END IF;
58596 --
58597 
58598 
58599 
58600 --
58601 INSERT INTO xla_diag_sources  --line2
58602 (
58603         event_id
58604       , ledger_id
58605       , sla_ledger_id
58606       , description_language
58607       , object_name
58608       , object_type_code
58609       , line_number
58610       , source_application_id
58611       , source_type_code
58612       , source_code
58613       , source_value
58614       , source_meaning
58615       , created_by
58616       , creation_date
58617       , last_update_date
58618       , last_updated_by
58619       , last_update_login
58620       , program_update_date
58621       , program_application_id
58622       , program_id
58623       , request_id
58624 )
58625 SELECT  event_id
58626       , p_target_ledger_id
58627       , p_sla_ledger_id
58628       , p_language
58629       , object_name
58630       , object_type_code
58631       , line_number
58632       , source_application_id
58633       , source_type_code
58634       , source_code
58635       , SUBSTR(source_value,1,1996)
58636       , SUBSTR(source_meaning ,1,200)
58637       , xla_environment_pkg.g_Usr_Id
58638       , TRUNC(SYSDATE)
58639       , TRUNC(SYSDATE)
58640       , xla_environment_pkg.g_Usr_Id
58641       , xla_environment_pkg.g_Login_Id
58642       , TRUNC(SYSDATE)
58643       , xla_environment_pkg.g_Prog_Appl_Id
58644       , xla_environment_pkg.g_Prog_Id
58645       , xla_environment_pkg.g_Req_Id
58646   FROM (
58647        SELECT xet.event_id                  event_id
58648             , l4.line_number                 line_number
58649             , CASE r
58650                WHEN 1 THEN 'AR_CUST_TRX_LINES_L_V' 
58651                 WHEN 2 THEN 'AR_CUST_TRX_LINES_L_V' 
58652                 WHEN 3 THEN 'AR_CUST_TRX_LINES_L_V' 
58653                 WHEN 4 THEN 'AR_CUST_TRX_LINES_L_V' 
58654                 WHEN 5 THEN 'AR_CUST_TRX_LINES_L_V' 
58655                 WHEN 6 THEN 'AR_CUST_TRX_LINES_BASE_V' 
58656                 WHEN 7 THEN 'AR_CUST_TRX_LINES_BASE_V' 
58657                 WHEN 8 THEN 'AR_CUST_TRX_LINES_BASE_V' 
58658                 WHEN 9 THEN 'AR_CUST_TRX_LINES_BASE_V' 
58659                 
58660                ELSE null
58661               END                           object_name
58662             , CASE r
58663                 WHEN 1 THEN 'LINE' 
58664                 WHEN 2 THEN 'LINE' 
58665                 WHEN 3 THEN 'LINE' 
58666                 WHEN 4 THEN 'LINE' 
58667                 WHEN 5 THEN 'LINE' 
58668                 WHEN 6 THEN 'LINE' 
58669                 WHEN 7 THEN 'LINE' 
58670                 WHEN 8 THEN 'LINE' 
58671                 WHEN 9 THEN 'LINE' 
58672                 
58673                 ELSE null
58674               END                           object_type_code
58675             , CASE r
58676                 WHEN 1 THEN '222' 
58677                 WHEN 2 THEN '222' 
58678                 WHEN 3 THEN '222' 
58679                 WHEN 4 THEN '222' 
58680                 WHEN 5 THEN '222' 
58681                 WHEN 6 THEN '222' 
58682                 WHEN 7 THEN '222' 
58683                 WHEN 8 THEN '222' 
58684                 WHEN 9 THEN '222' 
58685                 
58686                 ELSE null
58687               END                           source_application_id
58688             , 'S'             source_type_code
58689             , CASE r
58690                 WHEN 1 THEN 'TRX_LINE_DIST_CCID' 
58691                 WHEN 2 THEN 'TRX_LINE_DIST_ACCOUNT_CLASS' 
58692                 WHEN 3 THEN 'TRX_LINE_DIST_ID' 
58693                 WHEN 4 THEN 'TRX_DISTRIBUTION_TYPE' 
58694                 WHEN 5 THEN 'TRX_LINE_DIST_AMT' 
58695                 WHEN 6 THEN 'TRX_LINE_CUR_CONVERSION_DATE' 
58696                 WHEN 7 THEN 'TRX_LINE_CUR_CONVERSION_RATE' 
58697                 WHEN 8 THEN 'TRX_LINE_CUR_CONVERSION_TYPE' 
58698                 WHEN 9 THEN 'TRX_LINE_ACCTD_AMT' 
58699                 
58700                 ELSE null
58701               END                           source_code
58702             , CASE r
58703                 WHEN 1 THEN TO_CHAR(l4.TRX_LINE_DIST_CCID)
58704                 WHEN 2 THEN TO_CHAR(l4.TRX_LINE_DIST_ACCOUNT_CLASS)
58705                 WHEN 3 THEN TO_CHAR(l4.TRX_LINE_DIST_ID)
58706                 WHEN 4 THEN TO_CHAR(l4.TRX_DISTRIBUTION_TYPE)
58707                 WHEN 5 THEN TO_CHAR(l4.TRX_LINE_DIST_AMT)
58708                 WHEN 6 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_DATE)
58709                 WHEN 7 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_RATE)
58710                 WHEN 8 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_TYPE)
58711                 WHEN 9 THEN TO_CHAR(l3.TRX_LINE_ACCTD_AMT)
58712                 
58713                 ELSE null
58714               END                           source_value
58715             , null              source_meaning
58719             , (select rownum r from all_objects where rownum <= 9 and owner = p_apps_owner)
58716          FROM  xla_events_gt     xet  
58717         , AR_CUST_TRX_LINES_BASE_V  l3
58718         , AR_CUST_TRX_LINES_L_V  l4
58720         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
58721           AND xet.event_class_code = C_EVENT_CLASS_CODE
58722             AND l3.event_id          = xet.event_id
58723   AND l4.event_id    = l3.event_id
58724   AND l4.line_number = l3.line_number
58725 
58726 )
58727 ;
58728 --
58729 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
58730 
58731       trace
58732          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
58733          ,p_level    => C_LEVEL_STATEMENT
58734          ,p_module   => l_log_module);
58735 
58736 END IF;
58737 
58738 
58739 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
58740       trace
58741          (p_msg      => 'END of insert_sources_106'
58742          ,p_level    => C_LEVEL_PROCEDURE
58743          ,p_module   => l_log_module);
58744 END IF;
58745 EXCEPTION
58746   WHEN xla_exceptions_pkg.application_exception THEN
58747       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
58748             trace
58749                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
58750                ,p_level    => C_LEVEL_EXCEPTION
58751                ,p_module   => l_log_module);
58752       END IF;
58753       RAISE;
58754   WHEN OTHERS THEN
58755       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
58756             trace
58757                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
58758                ,p_level    => C_LEVEL_EXCEPTION
58759                ,p_module   => l_log_module);
58760        END IF;
58761        xla_exceptions_pkg.raise_message
58762            (p_location => 'XLA_00222_AAD_S_000008_PKG.insert_sources_106');
58763 END insert_sources_106;
58764 --
58765 
58766 ---------------------------------------
58767 --
58768 -- PRIVATE FUNCTION
58769 --         EventClass_106
58770 --
58771 ----------------------------------------
58772 --
58773 FUNCTION EventClass_106
58774        (p_application_id         IN NUMBER
58775        ,p_base_ledger_id         IN NUMBER
58776        ,p_target_ledger_id       IN NUMBER
58777        ,p_language               IN VARCHAR2
58778        ,p_currency_code          IN VARCHAR2
58779        ,p_sla_ledger_id          IN NUMBER
58780        ,p_pad_start_date         IN DATE
58781        ,p_pad_end_date           IN DATE
58782        ,p_primary_ledger_id      IN NUMBER)
58783 RETURN BOOLEAN IS
58784 --
58785 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'DEPOSIT_ALL';
58786 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'DEPOSIT';
58787 
58788 l_calculate_acctd_flag   VARCHAR2(1) :='N';
58789 l_calculate_g_l_flag     VARCHAR2(1) :='N';
58790 --
58791 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
58792 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
58793 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
58794 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
58795 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
58796 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
58797 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
58798 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
58799 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
58800 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
58801 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
58802 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
58803 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
58804 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
58805 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
58806 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
58807 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
58808 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
58809 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
58810 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
58811 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
58812 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
58813 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
58814 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
58815 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
58816 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
58817 
58818 l_event_id                             NUMBER;
58819 l_previous_event_id                    NUMBER;
58820 l_first_event_id                       NUMBER;
58821 l_last_event_id                        NUMBER;
58822 
58823 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
58824 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
58825 --
58826 --
58830 l_event_class_name          VARCHAR2(80) := 'Deposit';
58827 l_result                    BOOLEAN := TRUE;
58828 l_rows                      NUMBER  := 1000;
58829 l_event_type_name           VARCHAR2(80) := 'All';
58831 l_description               VARCHAR2(4000);
58832 l_transaction_reversal      NUMBER;
58833 l_ae_header_id              NUMBER;
58834 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
58835 l_log_module                VARCHAR2(240);
58836 --
58837 l_acct_reversal_source      VARCHAR2(30);
58838 l_trx_reversal_source       VARCHAR2(30);
58839 
58840 l_continue_with_lines       BOOLEAN := TRUE;
58841 --
58842 l_acc_rev_gl_date_source    DATE;                      -- 4262811
58843 --
58844 type t_array_event_id is table of number index by binary_integer;
58845 
58846 l_rec_array_event                    t_rec_array_event;
58847 l_null_rec_array_event               t_rec_array_event;
58848 l_array_ae_header_id                 xla_number_array_type;
58849 l_actual_flag                        VARCHAR2(1) := NULL;
58850 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
58851 l_balance_type_code                  VARCHAR2(1) :=NULL;
58852 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
58853 
58854 --
58855 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
58856 --
58857 
58858 TYPE t_array_source_23 IS TABLE OF AR_BILL_TO_CUSTOMERS_S_V.BILL_CUST_ACCOUNT_ID%TYPE INDEX BY BINARY_INTEGER;
58859 TYPE t_array_source_24 IS TABLE OF AR_BILL_TO_SITE_USES_S_V.BILL_USES_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
58860 TYPE t_array_source_25 IS TABLE OF AR_TRANSACTIONS_S_V.XLA_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
58861 TYPE t_array_source_30 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_INVOICE_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
58862 TYPE t_array_source_75 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
58863 TYPE t_array_source_76 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
58864 TYPE t_array_source_77 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
58865 
58866 TYPE t_array_source_4 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
58867 TYPE t_array_source_26 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ACCOUNT_CLASS%TYPE INDEX BY BINARY_INTEGER;
58868 TYPE t_array_source_27 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ID%TYPE INDEX BY BINARY_INTEGER;
58869 TYPE t_array_source_28 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
58870 TYPE t_array_source_29 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_AMT%TYPE INDEX BY BINARY_INTEGER;
58871 TYPE t_array_source_31 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
58872 TYPE t_array_source_32 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
58873 TYPE t_array_source_33 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
58874 TYPE t_array_source_34 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
58875 
58876 l_array_source_23              t_array_source_23;
58877 l_array_source_24              t_array_source_24;
58878 l_array_source_25              t_array_source_25;
58879 l_array_source_30              t_array_source_30;
58880 l_array_source_75              t_array_source_75;
58881 l_array_source_76              t_array_source_76;
58882 l_array_source_77              t_array_source_77;
58883 
58884 l_array_source_4      t_array_source_4;
58885 l_array_source_26      t_array_source_26;
58886 l_array_source_27      t_array_source_27;
58887 l_array_source_28      t_array_source_28;
58888 l_array_source_29      t_array_source_29;
58889 l_array_source_31      t_array_source_31;
58890 l_array_source_32      t_array_source_32;
58891 l_array_source_33      t_array_source_33;
58895 CURSOR header_cur
58892 l_array_source_34      t_array_source_34;
58893 
58894 --
58896 IS
58897 SELECT /*+ leading(xet) cardinality(xet,1) */
58898 -- Event Class Code: DEPOSIT
58899     xet.entity_id
58900    ,xet.legal_entity_id
58901    ,xet.entity_code
58902    ,xet.transaction_number
58903    ,xet.event_id
58904    ,xet.event_class_code
58905    ,xet.event_type_code
58906    ,xet.event_number
58907    ,xet.event_date
58908    ,xet.transaction_date
58909    ,xet.reference_num_1
58910    ,xet.reference_num_2
58911    ,xet.reference_num_3
58912    ,xet.reference_num_4
58913    ,xet.reference_char_1
58914    ,xet.reference_char_2
58915    ,xet.reference_char_3
58916    ,xet.reference_char_4
58917    ,xet.reference_date_1
58918    ,xet.reference_date_2
58919    ,xet.reference_date_3
58920    ,xet.reference_date_4
58921    ,xet.event_created_by
58922    ,xet.budgetary_control_flag 
58923   , h1.BILL_CUST_ACCOUNT_ID    source_23
58924   , h2.BILL_USES_SITE_USE_ID    source_24
58925   , h5.XLA_PARTY_TYPE    source_25
58926   , h5.TRX_INVOICE_CURRENCY_CODE    source_30
58927   , h5.TRX_DOC_SEQUENCE_CATEGORY    source_75
58928   , h5.TRX_DOC_SEQUENCE_ID    source_76
58929   , h5.TRX_DOC_SEQUENCE_VALUE    source_77
58930   FROM xla_events_gt     xet 
58931   , AR_BILL_TO_CUSTOMERS_S_V  h1
58932   , AR_BILL_TO_SITE_USES_S_V  h2
58933   , AR_TRANSACTIONS_S_V  h5
58934  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
58935    and xet.event_class_code = C_EVENT_CLASS_CODE
58936    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
58937   AND h2.event_id  = h1.event_id
58938   AND h5.event_id  = h1.event_id
58939 
58940  ORDER BY event_id
58941 ;
58942 
58943 
58944 --
58945 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
58946 IS
58947 SELECT  /*+ leading(xet) cardinality(xet,1) */
58948 -- Event Class Code: DEPOSIT
58949     xet.entity_id
58950    ,xet.legal_entity_id
58951    ,xet.entity_code
58952    ,xet.transaction_number
58953    ,xet.event_id
58954    ,xet.event_class_code
58955    ,xet.event_type_code
58956    ,xet.event_number
58957    ,xet.event_date
58958    ,xet.transaction_date
58959    ,xet.reference_num_1
58960    ,xet.reference_num_2
58961    ,xet.reference_num_3
58962    ,xet.reference_num_4
58963    ,xet.reference_char_1
58964    ,xet.reference_char_2
58965    ,xet.reference_char_3
58966    ,xet.reference_char_4
58967    ,xet.reference_date_1
58968    ,xet.reference_date_2
58969    ,xet.reference_date_3
58970    ,xet.reference_date_4
58971    ,xet.event_created_by
58972    ,xet.budgetary_control_flag
58973  , l3.LINE_NUMBER  
58974   , l4.TRX_LINE_DIST_CCID    source_4
58975   , l4.TRX_LINE_DIST_ACCOUNT_CLASS    source_26
58976   , l4.TRX_LINE_DIST_ID    source_27
58977   , l4.TRX_DISTRIBUTION_TYPE    source_28
58978   , l4.TRX_LINE_DIST_AMT    source_29
58979   , l3.TRX_LINE_CUR_CONVERSION_DATE    source_31
58980   , l3.TRX_LINE_CUR_CONVERSION_RATE    source_32
58981   , l3.TRX_LINE_CUR_CONVERSION_TYPE    source_33
58982   , l3.TRX_LINE_ACCTD_AMT    source_34
58983   FROM xla_events_gt     xet 
58984   , AR_CUST_TRX_LINES_BASE_V  l3
58985   , AR_CUST_TRX_LINES_L_V  l4
58986  WHERE xet.event_id between x_first_event_id and x_last_event_id
58987    and xet.event_date between p_pad_start_date and p_pad_end_date
58988    and xet.event_class_code = C_EVENT_CLASS_CODE
58989    and xet.event_status_code <> 'N'   AND l3.event_id      = xet.event_id
58990   AND l4.event_id    = l3.event_id
58991   AND l4.line_number = l3.line_number
58992 ;
58993 
58994 --
58995 BEGIN
58996 IF g_log_enabled THEN
58997    l_log_module := C_DEFAULT_MODULE||'.EventClass_106';
58998 END IF;
58999 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
59000    trace
59001       (p_msg      => 'BEGIN of EventClass_106'
59002       ,p_level    => C_LEVEL_PROCEDURE
59003       ,p_module   => l_log_module);
59004 END IF;
59005 
59006 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
59007    trace
59008       (p_msg      => 'p_application_id = '||p_application_id||
59009                      ' - p_base_ledger_id = '||p_base_ledger_id||
59010                      ' - p_target_ledger_id  = '||p_target_ledger_id||
59011                      ' - p_language = '||p_language||
59012                      ' - p_currency_code = '||p_currency_code||
59013                      ' - p_sla_ledger_id = '||p_sla_ledger_id
59014       ,p_level    => C_LEVEL_STATEMENT
59015       ,p_module   => l_log_module);
59016 END IF;
59017 --
59018 -- initialze arrays
59019 --
59020 g_array_event.DELETE;
59021 l_rec_array_event := l_null_rec_array_event;
59022 --
59023 --------------------------------------
59024 -- 4262811 Initialze MPA Line Number
59025 --------------------------------------
59026 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
59027 
59028 --
59029 
59030 --
59031 OPEN header_cur;
59032 --
59033 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
59034    trace
59035    (p_msg      => 'SQL - FETCH header_cur'
59036    ,p_level    => C_LEVEL_STATEMENT
59037    ,p_module   => l_log_module);
59038 END IF;
59039 --
59040 LOOP
59041 FETCH header_cur BULK COLLECT INTO
59042         l_array_entity_id
59043       , l_array_legal_entity_id
59044       , l_array_entity_code
59045       , l_array_transaction_num
59046       , l_array_event_id
59047       , l_array_class_code
59048       , l_array_event_type
59049       , l_array_event_number
59050       , l_array_event_date
59051       , l_array_transaction_date
59052       , l_array_reference_num_1
59053       , l_array_reference_num_2
59054       , l_array_reference_num_3
59055       , l_array_reference_num_4
59056       , l_array_reference_char_1
59057       , l_array_reference_char_2
59058       , l_array_reference_char_3
59059       , l_array_reference_char_4
59060       , l_array_reference_date_1
59061       , l_array_reference_date_2
59062       , l_array_reference_date_3
59063       , l_array_reference_date_4
59064       , l_array_event_created_by
59065       , l_array_budgetary_control_flag 
59066       , l_array_source_23
59067       , l_array_source_24
59068       , l_array_source_25
59069       , l_array_source_30
59070       , l_array_source_75
59071       , l_array_source_76
59072       , l_array_source_77
59073       LIMIT l_rows;
59074 --
59075 IF (C_LEVEL_EVENT >= g_log_level) THEN
59076    trace
59077    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
59078    ,p_level    => C_LEVEL_EVENT
59079    ,p_module   => l_log_module);
59080 END IF;
59081 --
59082 EXIT WHEN l_array_entity_id.COUNT = 0;
59083 
59084 -- initialize arrays
59085 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
59086 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
59087 
59088 --
59089 -- Bug 4458708
59090 --
59091 XLA_AE_LINES_PKG.g_LineNumber := 0;
59092 
59093 
59094 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
59095 g_last_hdr_idx := l_array_event_id.LAST;
59096 --
59097 -- loop for the headers. Each iteration is for each header extract row
59098 -- fetched in header cursor
59099 --
59100 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
59101 
59102 --
59103 -- set event info as cache for other routines to refer event attributes
59104 --
59105 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
59106    (p_application_id           => p_application_id
59107    ,p_primary_ledger_id        => p_primary_ledger_id
59108    ,p_base_ledger_id           => p_base_ledger_id
59109    ,p_target_ledger_id         => p_target_ledger_id
59110    ,p_entity_id                => l_array_entity_id(hdr_idx)
59111    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
59112    ,p_entity_code              => l_array_entity_code(hdr_idx)
59113    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
59114    ,p_event_id                 => l_array_event_id(hdr_idx)
59115    ,p_event_class_code         => l_array_class_code(hdr_idx)
59116    ,p_event_type_code          => l_array_event_type(hdr_idx)
59117    ,p_event_number             => l_array_event_number(hdr_idx)
59118    ,p_event_date               => l_array_event_date(hdr_idx)
59119    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
59120    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
59121    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
59122    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
59123    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
59124    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
59125    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
59126    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
59127    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
59128    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
59129    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
59130    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
59131    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
59132    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
59133    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
59134 
59135 --
59136 -- set the status of entry to C_VALID (0)
59137 --
59138 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
59139 
59140 --
59141 -- initialize a row for ae header
59142 --
59143 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
59144 
59145 l_event_id := l_array_event_id(hdr_idx);
59146 
59147 --
59148 -- storing the hdr_idx for event. May be used by line cursor.
59149 --
59150 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
59151 
59152 --
59153 -- store sources from header extract. This can be improved to
59154 -- store only those sources from header extract that may be used in lines
59155 --
59156 
59157 g_array_event(l_event_id).array_value_num('source_23') := l_array_source_23(hdr_idx);
59158 g_array_event(l_event_id).array_value_num('source_24') := l_array_source_24(hdr_idx);
59159 g_array_event(l_event_id).array_value_char('source_25') := l_array_source_25(hdr_idx);
59160 g_array_event(l_event_id).array_value_char('source_30') := l_array_source_30(hdr_idx);
59161 g_array_event(l_event_id).array_value_char('source_75') := l_array_source_75(hdr_idx);
59162 g_array_event(l_event_id).array_value_num('source_76') := l_array_source_76(hdr_idx);
59163 g_array_event(l_event_id).array_value_num('source_77') := l_array_source_77(hdr_idx);
59164 
59165 --
59166 -- initilaize the status of ae headers for diffrent balance types
59167 -- the status is initialised to C_NOT_CREATED (2)
59168 --
59169 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
59170 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
59171 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
59172 
59173 --
59177 ------------------------------------------------------------
59174 -- call api to validate and store accounting attributes for header
59175 --
59176 
59178 -- Accrual Reversal : to get date for Standard Source (NONE)
59179 ------------------------------------------------------------
59180 l_acc_rev_gl_date_source := NULL;
59181 
59182      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
59183       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_75');
59184      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
59185       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_76');
59186      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
59187       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_77');
59188      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
59189       l_rec_acct_attrs.array_date_value(4) := 
59190 xla_ae_sources_pkg.GetSystemSourceDate(
59191    p_source_code           => 'XLA_EVENT_DATE'
59192  , p_source_type_code      => 'Y'
59193  , p_source_application_id =>  602
59194 );
59195 
59196 
59197 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
59198 
59199 XLA_AE_HEADER_PKG.SetJeCategoryName;
59200 
59201 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
59202 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
59203 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
59204 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
59205 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
59206 
59207 
59208 -- No header level analytical criteria
59209 
59210 --
59211 --accounting attribute enhancement, bug 3612931
59212 --
59213 l_trx_reversal_source := SUBSTR(NULL, 1,30);
59214 
59215 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
59216    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
59217 
59218    xla_accounting_err_pkg.build_message
59219       (p_appli_s_name            => 'XLA'
59220       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
59221       ,p_token_1                 => 'ACCT_ATTR_NAME'
59222       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
59223       ,p_token_2                 => 'PRODUCT_NAME'
59224       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
59225       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
59226       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
59227       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
59228 
59229 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
59230    --
59231    -- following sets the accounting attributes needed to reverse
59232    -- accounting for a distributeion
59233    --
59234    xla_ae_lines_pkg.SetTrxReversalAttrs
59235       (p_event_id              => l_event_id
59236       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
59237       ,p_trx_reversal_source   => l_trx_reversal_source);
59238 
59239 END IF;
59240 
59241 
59242 ----------------------------------------------------------------
59243 -- 4262811 -  update the header statuses to invalid in need be
59244 ----------------------------------------------------------------
59245 --
59246 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
59247 
59248 
59249   -----------------------------------------------
59250   -- No accrual reversal for the event class/type
59251   -----------------------------------------------
59252 ----------------------------------------------------------------
59253 
59254 --
59255 -- this ends the header loop iteration for one bulk fetch
59256 --
59257 END LOOP;
59258 
59259 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
59260 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
59261 
59262 --
59263 -- insert dummy rows into lines gt table that were created due to
59264 -- transaction reversals
59265 --
59266 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
59267    l_result := XLA_AE_LINES_PKG.InsertLines;
59268 END IF;
59269 
59270 --
59271 -- reset the temp_line_num for each set of events fetched from header
59272 -- cursor rather than doing it for each new event in line cursor
59273 -- Bug 3939231
59274 --
59275 xla_ae_lines_pkg.g_temp_line_num := 0;
59276 
59277 
59278 
59279 --
59280 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
59281 --
59282 --
59283 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
59284 
59285       trace
59286          (p_msg      => 'SQL - FETCH line_cur'
59287          ,p_level    => C_LEVEL_STATEMENT
59288          ,p_module   => l_log_module);
59289 
59290 END IF;
59291 --
59292 --
59293 LOOP
59294   --
59295   FETCH line_cur BULK COLLECT INTO
59296         l_array_entity_id
59297       , l_array_legal_entity_id
59298       , l_array_entity_code
59299       , l_array_transaction_num
59300       , l_array_event_id
59301       , l_array_class_code
59302       , l_array_event_type
59303       , l_array_event_number
59304       , l_array_event_date
59305       , l_array_transaction_date
59306       , l_array_reference_num_1
59307       , l_array_reference_num_2
59308       , l_array_reference_num_3
59309       , l_array_reference_num_4
59310       , l_array_reference_char_1
59311       , l_array_reference_char_2
59312       , l_array_reference_char_3
59313       , l_array_reference_char_4
59314       , l_array_reference_date_1
59315       , l_array_reference_date_2
59316       , l_array_reference_date_3
59317       , l_array_reference_date_4
59318       , l_array_event_created_by
59319       , l_array_budgetary_control_flag
59320       , l_array_extract_line_num 
59321       , l_array_source_4
59322       , l_array_source_26
59323       , l_array_source_27
59324       , l_array_source_28
59325       , l_array_source_29
59326       , l_array_source_31
59327       , l_array_source_32
59328       , l_array_source_33
59329       , l_array_source_34
59330       LIMIT l_rows;
59331 
59332   --
59333   IF (C_LEVEL_EVENT >= g_log_level) THEN
59334             trace
59335                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
59336                ,p_level    => C_LEVEL_EVENT
59337                ,p_module   => l_log_module);
59338   END IF;
59339   --
59340   EXIT WHEN l_array_entity_id.count = 0;
59341 
59342   XLA_AE_LINES_PKG.g_rec_lines := null;
59343 
59344 --
59345 -- Bug 4458708
59346 --
59347 XLA_AE_LINES_PKG.g_LineNumber := 0;
59348 --
59349 --
59350 
59351 FOR Idx IN 1..l_array_event_id.count LOOP
59352    --
59353    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
59354    --
59355    l_event_id := l_array_event_id(idx);  -- 5648433
59356 
59357    --
59358    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
59359    --
59360 
59361    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
59362              (g_array_event(l_event_id).array_value_num('header_index'))
59363          ,'N'
59364          ) <> 'Y'
59365    THEN
59366       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
59367          trace
59368             (p_msg      => 'Trancaction revesal option is not Y '
59369             ,p_level    => C_LEVEL_STATEMENT
59370             ,p_module   => l_log_module);
59371       END IF;
59372 
59373 --
59374 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
59375 --
59376 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
59377 --
59378 -- set event info as cache for other routines to refer event attributes
59379 --
59380 
59381 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
59382    l_previous_event_id := l_event_id;
59383 
59384    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
59385       (p_application_id           => p_application_id
59386       ,p_primary_ledger_id        => p_primary_ledger_id
59387       ,p_base_ledger_id           => p_base_ledger_id
59388       ,p_target_ledger_id         => p_target_ledger_id
59389       ,p_entity_id                => l_array_entity_id(Idx)
59390       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
59391       ,p_entity_code              => l_array_entity_code(Idx)
59392       ,p_transaction_num          => l_array_transaction_num(Idx)
59393       ,p_event_id                 => l_array_event_id(Idx)
59394       ,p_event_class_code         => l_array_class_code(Idx)
59395       ,p_event_type_code          => l_array_event_type(Idx)
59396       ,p_event_number             => l_array_event_number(Idx)
59397       ,p_event_date               => l_array_event_date(Idx)
59398       ,p_transaction_date         => l_array_transaction_date(Idx)
59399       ,p_reference_num_1          => l_array_reference_num_1(Idx)
59400       ,p_reference_num_2          => l_array_reference_num_2(Idx)
59401       ,p_reference_num_3          => l_array_reference_num_3(Idx)
59402       ,p_reference_num_4          => l_array_reference_num_4(Idx)
59403       ,p_reference_char_1         => l_array_reference_char_1(Idx)
59404       ,p_reference_char_2         => l_array_reference_char_2(Idx)
59405       ,p_reference_char_3         => l_array_reference_char_3(Idx)
59406       ,p_reference_char_4         => l_array_reference_char_4(Idx)
59407       ,p_reference_date_1         => l_array_reference_date_1(Idx)
59408       ,p_reference_date_2         => l_array_reference_date_2(Idx)
59409       ,p_reference_date_3         => l_array_reference_date_3(Idx)
59410       ,p_reference_date_4         => l_array_reference_date_4(Idx)
59411       ,p_event_created_by         => l_array_event_created_by(Idx)
59412       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
59413        --
59414 END IF;
59415 
59416 
59417 
59418 --
59419 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
59420 
59421 l_acct_reversal_source := SUBSTR(NULL, 1,30);
59422 
59423 IF l_continue_with_lines THEN
59424    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
59425       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
59426 
59427       xla_accounting_err_pkg.build_message
59428          (p_appli_s_name            => 'XLA'
59429          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
59430          ,p_token_1                 => 'LINE_NUMBER'
59431          ,p_value_1                 => l_array_extract_line_num(Idx)
59432          ,p_token_2                 => 'PRODUCT_NAME'
59433          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
59434          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
59435          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
59436          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
59437 
59438    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
59439       --
59440       -- following sets the accounting attributes needed to reverse
59444       --
59441       -- accounting for a distributeion
59442       --
59443 
59445       -- 5217187
59446       --
59447       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
59448       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
59449                                        g_array_event(l_event_id).array_value_num('header_index'));
59450       --
59451       --
59452 
59453       -- No reversal code generated
59454 
59455       xla_ae_lines_pkg.SetAcctReversalAttrs
59456          (p_event_id             => l_event_id
59457          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
59458          ,p_calculate_acctd_flag => l_calculate_acctd_flag
59459          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
59460    END IF;
59461 
59462    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
59463        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
59464 
59465 --
59466 AcctLineType_34 (
59467  p_application_id  => p_application_id
59468  ,p_event_id     => l_event_id
59469  ,p_calculate_acctd_flag => l_calculate_acctd_flag
59470  ,p_calculate_g_l_flag => l_calculate_g_l_flag
59471  ,p_actual_flag => l_actual_flag
59472  ,p_balance_type_code => l_balance_type_code
59473  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
59474  
59475  , p_source_4 => l_array_source_4(Idx)
59476  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
59477  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
59478  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
59479  , p_source_26 => l_array_source_26(Idx)
59480  , p_source_27 => l_array_source_27(Idx)
59481  , p_source_28 => l_array_source_28(Idx)
59482  , p_source_29 => l_array_source_29(Idx)
59483  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
59484  , p_source_31 => l_array_source_31(Idx)
59485  , p_source_32 => l_array_source_32(Idx)
59486  , p_source_33 => l_array_source_33(Idx)
59487  , p_source_34 => l_array_source_34(Idx)
59488  );
59489 If(l_balance_type_code = 'A') THEN
59490   l_actual_gain_loss_ref := l_gain_or_loss_ref;
59491 END IF;
59492 
59493 --
59494 
59495 
59496 --
59497 AcctLineType_35 (
59498  p_application_id  => p_application_id
59499  ,p_event_id     => l_event_id
59500  ,p_calculate_acctd_flag => l_calculate_acctd_flag
59501  ,p_calculate_g_l_flag => l_calculate_g_l_flag
59502  ,p_actual_flag => l_actual_flag
59503  ,p_balance_type_code => l_balance_type_code
59504  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
59505  
59506  , p_source_4 => l_array_source_4(Idx)
59507  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
59508  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
59509  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
59510  , p_source_26 => l_array_source_26(Idx)
59511  , p_source_27 => l_array_source_27(Idx)
59512  , p_source_28 => l_array_source_28(Idx)
59513  , p_source_29 => l_array_source_29(Idx)
59514  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
59515  , p_source_31 => l_array_source_31(Idx)
59516  , p_source_32 => l_array_source_32(Idx)
59517  , p_source_33 => l_array_source_33(Idx)
59518  , p_source_34 => l_array_source_34(Idx)
59519  );
59520 If(l_balance_type_code = 'A') THEN
59521   l_actual_gain_loss_ref := l_gain_or_loss_ref;
59522 END IF;
59523 
59524 --
59525 
59526       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
59527       -- or secondary ledger that has different currency with primary
59528       -- or alc that is calculated by sla
59529       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
59530             (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'))
59531 
59532 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
59533 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
59534           AND (l_actual_flag = 'A')) THEN
59535         XLA_AE_LINES_PKG.CreateGainOrLossLines(
59536           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
59537          ,p_application_id   => p_application_id
59538          ,p_amb_context_code => 'DEFAULT'
59539          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
59540          ,p_event_class_code => C_EVENT_CLASS_CODE
59541          ,p_event_type_code  => C_EVENT_TYPE_CODE
59542          
59543          ,p_gain_ccid        => -1
59544          ,p_loss_ccid        => -1
59545 
59546          ,p_actual_flag      => l_actual_flag
59547          ,p_enc_flag         => null
59548          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
59549          ,p_enc_g_l_ref      => null
59550          );
59551       END IF;
59552    END IF;
59553 END IF;
59554 
59555    ELSE
59556       --
59557       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
59558       --
59559       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
59560          trace
59561             (p_msg      => 'Trancaction revesal option is Y'
59562             ,p_level    => C_LEVEL_STATEMENT
59563             ,p_module   => l_log_module);
59564       END IF;
59565    END IF;
59566 
59567 END LOOP;
59568 l_result := XLA_AE_LINES_PKG.InsertLines ;
59569 end loop;
59570 close line_cur;
59571 
59572 
59573 --
59577 
59574 -- insert headers into xla_ae_headers_gt table
59575 --
59576 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
59578 -- insert into errors table here.
59579 
59580 END LOOP;
59581 
59582 --
59583 -- 4865292
59584 --
59585 -- Compare g_hdr_extract_count with event count in
59586 -- CreateHeadersAndLines.
59587 --
59588 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
59589 
59590 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
59591    trace (p_msg     => '# rows extracted from header extract objects '
59592                     || ' (running total): '
59593                     || g_hdr_extract_count
59594          ,p_level   => C_LEVEL_STATEMENT
59595          ,p_module  => l_log_module);
59596 END IF;
59597 
59598 CLOSE header_cur;
59599 --
59600 
59601 --
59602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
59603    trace
59604       (p_msg      => 'END of EventClass_106'
59605       ,p_level    => C_LEVEL_PROCEDURE
59606       ,p_module   => l_log_module);
59607 END IF;
59608 --
59609 RETURN l_result;
59610 EXCEPTION
59611 WHEN xla_exceptions_pkg.application_exception THEN
59612    
59613 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
59614 
59615    
59616 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
59617 
59618    RAISE;
59619 
59620 WHEN NO_DATA_FOUND THEN
59621 
59622 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
59623 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
59624 
59625 FOR header_record IN header_cur
59626 LOOP
59627     l_array_header_events(header_record.event_id) := header_record.event_id;
59628 END LOOP;
59629 
59630 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
59631 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
59632 
59633 fnd_file.put_line(fnd_file.LOG, '                    ');
59634 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
59635 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
59636 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
59637 
59638 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
59639 LOOP
59640 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
59641 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
59642         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
59643 	END IF;
59644 END LOOP;
59645 
59646 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
59647 fnd_file.put_line(fnd_file.LOG, '                    ');
59648 
59649 
59650 xla_exceptions_pkg.raise_message
59651       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_106');
59652 
59653 
59654 WHEN OTHERS THEN
59655    xla_exceptions_pkg.raise_message
59656       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_106');
59657 END EventClass_106;
59658 --
59659 
59660 ---------------------------------------
59661 --
59662 -- PRIVATE PROCEDURE
59663 --         insert_sources_107
59664 --
59665 ----------------------------------------
59666 --
59667 PROCEDURE insert_sources_107(
59668                                 p_target_ledger_id       IN NUMBER
59669                               , p_language               IN VARCHAR2
59670                               , p_sla_ledger_id          IN NUMBER
59671                               , p_pad_start_date         IN DATE
59672                               , p_pad_end_date           IN DATE
59673                          )
59674 IS
59675 
59676 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'GUARANTEE_ALL';
59677 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'GUARANTEE';
59678 p_apps_owner                   VARCHAR2(30);
59679 l_log_module                   VARCHAR2(240);
59680 BEGIN
59681 IF g_log_enabled THEN
59682       l_log_module := C_DEFAULT_MODULE||'.insert_sources_107';
59683 END IF;
59684 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
59685 
59686       trace
59687          (p_msg      => 'BEGIN of insert_sources_107'
59688          ,p_level    => C_LEVEL_PROCEDURE
59689          ,p_module   => l_log_module);
59690 
59691 END IF;
59692 
59693 -- select APPS owner
59694 SELECT oracle_username
59695   INTO p_apps_owner
59696   FROM fnd_oracle_userid
59697  WHERE read_only_flag = 'U'
59698 ;
59699 
59700 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
59701       trace
59702          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
59703                         ' - p_language = '||p_language||
59704                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
59705                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
59706                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
59707                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
59708          ,p_level    => C_LEVEL_STATEMENT
59709          ,p_module   => l_log_module);
59710 END IF;
59711 
59712 
59713 --
59714 INSERT INTO xla_diag_sources --hdr2
59715 (
59716         event_id
59717       , ledger_id
59718       , sla_ledger_id
59719       , description_language
59720       , object_name
59721       , object_type_code
59722       , line_number
59723       , source_application_id
59724       , source_type_code
59725       , source_code
59726       , source_value
59727       , source_meaning
59728       , created_by
59729       , creation_date
59730       , last_update_date
59731       , last_updated_by
59732       , last_update_login
59733       , program_update_date
59734       , program_application_id
59735       , program_id
59736       , request_id
59737 )
59738 SELECT
59739         event_id
59740       , p_target_ledger_id
59741       , p_sla_ledger_id
59742       , p_language
59743       , object_name
59744       , object_type_code
59745       , line_number
59746       , source_application_id
59747       , source_type_code
59748       , source_code
59749       , SUBSTR(source_value ,1,1996)
59750       , SUBSTR(source_meaning ,1,200)
59751       , xla_environment_pkg.g_Usr_Id
59752       , TRUNC(SYSDATE)
59753       , TRUNC(SYSDATE)
59754       , xla_environment_pkg.g_Usr_Id
59755       , xla_environment_pkg.g_Login_Id
59756       , TRUNC(SYSDATE)
59757       , xla_environment_pkg.g_Prog_Appl_Id
59758       , xla_environment_pkg.g_Prog_Id
59759       , xla_environment_pkg.g_Req_Id
59760   FROM (
59761        SELECT xet.event_id                  event_id
59762             , 0                          line_number
59763             , CASE r
59764                WHEN 1 THEN 'AR_BILL_TO_CUSTOMERS_S_V' 
59765                 WHEN 2 THEN 'AR_BILL_TO_SITE_USES_S_V' 
59766                 WHEN 3 THEN 'AR_TRANSACTIONS_S_V' 
59767                 WHEN 4 THEN 'AR_TRANSACTIONS_S_V' 
59768                 WHEN 5 THEN 'AR_TRANSACTIONS_S_V' 
59769                 WHEN 6 THEN 'AR_TRANSACTIONS_S_V' 
59770                 WHEN 7 THEN 'AR_TRANSACTIONS_S_V' 
59771                 
59772                ELSE null
59773               END                           object_name
59774             , CASE r
59775                 WHEN 1 THEN 'HEADER' 
59776                 WHEN 2 THEN 'HEADER' 
59777                 WHEN 3 THEN 'HEADER' 
59778                 WHEN 4 THEN 'HEADER' 
59779                 WHEN 5 THEN 'HEADER' 
59780                 WHEN 6 THEN 'HEADER' 
59781                 WHEN 7 THEN 'HEADER' 
59782                 
59783                 ELSE null
59784               END                           object_type_code
59785             , CASE r
59786                 WHEN 1 THEN '222' 
59787                 WHEN 2 THEN '222' 
59788                 WHEN 3 THEN '222' 
59789                 WHEN 4 THEN '222' 
59790                 WHEN 5 THEN '222' 
59791                 WHEN 6 THEN '222' 
59792                 WHEN 7 THEN '222' 
59793                 
59794                 ELSE null
59795               END                           source_application_id
59796             , 'S'             source_type_code
59797             , CASE r
59798                 WHEN 1 THEN 'BILL_CUST_ACCOUNT_ID' 
59799                 WHEN 2 THEN 'BILL_USES_SITE_USE_ID' 
59800                 WHEN 3 THEN 'XLA_PARTY_TYPE' 
59801                 WHEN 4 THEN 'TRX_INVOICE_CURRENCY_CODE' 
59802                 WHEN 5 THEN 'TRX_DOC_SEQUENCE_CATEGORY' 
59803                 WHEN 6 THEN 'TRX_DOC_SEQUENCE_ID' 
59804                 WHEN 7 THEN 'TRX_DOC_SEQUENCE_VALUE' 
59805                 
59806                 ELSE null
59807               END                           source_code
59808             , CASE r
59809                 WHEN 1 THEN TO_CHAR(h1.BILL_CUST_ACCOUNT_ID)
59810                 WHEN 2 THEN TO_CHAR(h2.BILL_USES_SITE_USE_ID)
59811                 WHEN 3 THEN TO_CHAR(h5.XLA_PARTY_TYPE)
59812                 WHEN 4 THEN TO_CHAR(h5.TRX_INVOICE_CURRENCY_CODE)
59813                 WHEN 5 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_CATEGORY)
59814                 WHEN 6 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_ID)
59815                 WHEN 7 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_VALUE)
59816                 
59817                 ELSE null
59818               END                           source_value
59819             , null              source_meaning
59820          FROM xla_events_gt     xet  
59821       , AR_BILL_TO_CUSTOMERS_S_V  h1
59822       , AR_BILL_TO_SITE_USES_S_V  h2
59823       , AR_TRANSACTIONS_S_V  h5
59824              ,(select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
59825          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
59826            AND xet.event_class_code = C_EVENT_CLASS_CODE
59827               AND h1.event_id = xet.event_id
59828   AND h2.event_id  = h1.event_id
59829   AND h5.event_id  = h1.event_id
59830 
59831 )
59832 ;
59833 --
59834 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
59835 
59836       trace
59837          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
59838          ,p_level    => C_LEVEL_STATEMENT
59839          ,p_module   => l_log_module);
59840 
59841 END IF;
59842 --
59843 
59844 
59845 
59846 --
59847 INSERT INTO xla_diag_sources  --line2
59851       , sla_ledger_id
59848 (
59849         event_id
59850       , ledger_id
59852       , description_language
59853       , object_name
59854       , object_type_code
59855       , line_number
59856       , source_application_id
59857       , source_type_code
59858       , source_code
59859       , source_value
59860       , source_meaning
59861       , created_by
59862       , creation_date
59863       , last_update_date
59864       , last_updated_by
59865       , last_update_login
59866       , program_update_date
59867       , program_application_id
59868       , program_id
59869       , request_id
59870 )
59871 SELECT  event_id
59872       , p_target_ledger_id
59873       , p_sla_ledger_id
59874       , p_language
59875       , object_name
59876       , object_type_code
59877       , line_number
59878       , source_application_id
59879       , source_type_code
59880       , source_code
59881       , SUBSTR(source_value,1,1996)
59882       , SUBSTR(source_meaning ,1,200)
59883       , xla_environment_pkg.g_Usr_Id
59884       , TRUNC(SYSDATE)
59885       , TRUNC(SYSDATE)
59886       , xla_environment_pkg.g_Usr_Id
59887       , xla_environment_pkg.g_Login_Id
59888       , TRUNC(SYSDATE)
59889       , xla_environment_pkg.g_Prog_Appl_Id
59890       , xla_environment_pkg.g_Prog_Id
59891       , xla_environment_pkg.g_Req_Id
59892   FROM (
59893        SELECT xet.event_id                  event_id
59894             , l4.line_number                 line_number
59895             , CASE r
59896                WHEN 1 THEN 'AR_CUST_TRX_LINES_L_V' 
59897                 WHEN 2 THEN 'AR_CUST_TRX_LINES_L_V' 
59898                 WHEN 3 THEN 'AR_CUST_TRX_LINES_L_V' 
59899                 WHEN 4 THEN 'AR_CUST_TRX_LINES_L_V' 
59900                 WHEN 5 THEN 'AR_CUST_TRX_LINES_L_V' 
59901                 WHEN 6 THEN 'AR_CUST_TRX_LINES_BASE_V' 
59902                 WHEN 7 THEN 'AR_CUST_TRX_LINES_BASE_V' 
59903                 WHEN 8 THEN 'AR_CUST_TRX_LINES_BASE_V' 
59904                 WHEN 9 THEN 'AR_CUST_TRX_LINES_BASE_V' 
59905                 
59906                ELSE null
59907               END                           object_name
59908             , CASE r
59909                 WHEN 1 THEN 'LINE' 
59910                 WHEN 2 THEN 'LINE' 
59911                 WHEN 3 THEN 'LINE' 
59912                 WHEN 4 THEN 'LINE' 
59913                 WHEN 5 THEN 'LINE' 
59914                 WHEN 6 THEN 'LINE' 
59915                 WHEN 7 THEN 'LINE' 
59916                 WHEN 8 THEN 'LINE' 
59917                 WHEN 9 THEN 'LINE' 
59918                 
59919                 ELSE null
59920               END                           object_type_code
59921             , CASE r
59922                 WHEN 1 THEN '222' 
59923                 WHEN 2 THEN '222' 
59924                 WHEN 3 THEN '222' 
59925                 WHEN 4 THEN '222' 
59926                 WHEN 5 THEN '222' 
59927                 WHEN 6 THEN '222' 
59928                 WHEN 7 THEN '222' 
59929                 WHEN 8 THEN '222' 
59930                 WHEN 9 THEN '222' 
59931                 
59932                 ELSE null
59933               END                           source_application_id
59934             , 'S'             source_type_code
59935             , CASE r
59936                 WHEN 1 THEN 'TRX_LINE_DIST_CCID' 
59937                 WHEN 2 THEN 'TRX_LINE_DIST_ACCOUNT_CLASS' 
59938                 WHEN 3 THEN 'TRX_LINE_DIST_ID' 
59939                 WHEN 4 THEN 'TRX_DISTRIBUTION_TYPE' 
59940                 WHEN 5 THEN 'TRX_LINE_DIST_AMT' 
59941                 WHEN 6 THEN 'TRX_LINE_CUR_CONVERSION_DATE' 
59942                 WHEN 7 THEN 'TRX_LINE_CUR_CONVERSION_RATE' 
59943                 WHEN 8 THEN 'TRX_LINE_CUR_CONVERSION_TYPE' 
59944                 WHEN 9 THEN 'TRX_LINE_ACCTD_AMT' 
59945                 
59946                 ELSE null
59947               END                           source_code
59948             , CASE r
59949                 WHEN 1 THEN TO_CHAR(l4.TRX_LINE_DIST_CCID)
59950                 WHEN 2 THEN TO_CHAR(l4.TRX_LINE_DIST_ACCOUNT_CLASS)
59951                 WHEN 3 THEN TO_CHAR(l4.TRX_LINE_DIST_ID)
59952                 WHEN 4 THEN TO_CHAR(l4.TRX_DISTRIBUTION_TYPE)
59953                 WHEN 5 THEN TO_CHAR(l4.TRX_LINE_DIST_AMT)
59954                 WHEN 6 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_DATE)
59955                 WHEN 7 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_RATE)
59956                 WHEN 8 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_TYPE)
59957                 WHEN 9 THEN TO_CHAR(l3.TRX_LINE_ACCTD_AMT)
59958                 
59959                 ELSE null
59960               END                           source_value
59961             , null              source_meaning
59962          FROM  xla_events_gt     xet  
59963         , AR_CUST_TRX_LINES_BASE_V  l3
59964         , AR_CUST_TRX_LINES_L_V  l4
59965             , (select rownum r from all_objects where rownum <= 9 and owner = p_apps_owner)
59966         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
59967           AND xet.event_class_code = C_EVENT_CLASS_CODE
59968             AND l3.event_id          = xet.event_id
59969   AND l4.event_id    = l3.event_id
59970   AND l4.line_number = l3.line_number
59971 
59972 )
59973 ;
59974 --
59975 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
59976 
59977       trace
59978          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
59979          ,p_level    => C_LEVEL_STATEMENT
59983 
59980          ,p_module   => l_log_module);
59981 
59982 END IF;
59984 
59985 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
59986       trace
59987          (p_msg      => 'END of insert_sources_107'
59988          ,p_level    => C_LEVEL_PROCEDURE
59989          ,p_module   => l_log_module);
59990 END IF;
59991 EXCEPTION
59992   WHEN xla_exceptions_pkg.application_exception THEN
59993       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
59994             trace
59995                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
59996                ,p_level    => C_LEVEL_EXCEPTION
59997                ,p_module   => l_log_module);
59998       END IF;
59999       RAISE;
60000   WHEN OTHERS THEN
60001       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
60002             trace
60003                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
60004                ,p_level    => C_LEVEL_EXCEPTION
60005                ,p_module   => l_log_module);
60006        END IF;
60007        xla_exceptions_pkg.raise_message
60008            (p_location => 'XLA_00222_AAD_S_000008_PKG.insert_sources_107');
60009 END insert_sources_107;
60010 --
60011 
60012 ---------------------------------------
60013 --
60014 -- PRIVATE FUNCTION
60015 --         EventClass_107
60016 --
60017 ----------------------------------------
60018 --
60019 FUNCTION EventClass_107
60020        (p_application_id         IN NUMBER
60021        ,p_base_ledger_id         IN NUMBER
60022        ,p_target_ledger_id       IN NUMBER
60023        ,p_language               IN VARCHAR2
60024        ,p_currency_code          IN VARCHAR2
60025        ,p_sla_ledger_id          IN NUMBER
60026        ,p_pad_start_date         IN DATE
60027        ,p_pad_end_date           IN DATE
60028        ,p_primary_ledger_id      IN NUMBER)
60029 RETURN BOOLEAN IS
60030 --
60031 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'GUARANTEE_ALL';
60032 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'GUARANTEE';
60033 
60034 l_calculate_acctd_flag   VARCHAR2(1) :='N';
60035 l_calculate_g_l_flag     VARCHAR2(1) :='N';
60036 --
60037 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
60038 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
60039 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
60040 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
60041 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
60042 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
60043 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
60044 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
60045 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
60046 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
60047 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
60048 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
60049 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
60050 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
60051 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
60052 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
60053 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
60054 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
60055 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
60056 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
60057 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
60058 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
60059 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
60063 
60060 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
60061 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
60062 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
60064 l_event_id                             NUMBER;
60065 l_previous_event_id                    NUMBER;
60066 l_first_event_id                       NUMBER;
60067 l_last_event_id                        NUMBER;
60068 
60069 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
60070 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
60071 --
60072 --
60073 l_result                    BOOLEAN := TRUE;
60074 l_rows                      NUMBER  := 1000;
60075 l_event_type_name           VARCHAR2(80) := 'All';
60076 l_event_class_name          VARCHAR2(80) := 'Guarantee';
60077 l_description               VARCHAR2(4000);
60078 l_transaction_reversal      NUMBER;
60079 l_ae_header_id              NUMBER;
60080 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
60081 l_log_module                VARCHAR2(240);
60082 --
60083 l_acct_reversal_source      VARCHAR2(30);
60084 l_trx_reversal_source       VARCHAR2(30);
60085 
60086 l_continue_with_lines       BOOLEAN := TRUE;
60087 --
60088 l_acc_rev_gl_date_source    DATE;                      -- 4262811
60089 --
60090 type t_array_event_id is table of number index by binary_integer;
60091 
60092 l_rec_array_event                    t_rec_array_event;
60093 l_null_rec_array_event               t_rec_array_event;
60094 l_array_ae_header_id                 xla_number_array_type;
60095 l_actual_flag                        VARCHAR2(1) := NULL;
60096 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
60097 l_balance_type_code                  VARCHAR2(1) :=NULL;
60098 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
60099 
60100 --
60101 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
60102 --
60103 
60104 TYPE t_array_source_23 IS TABLE OF AR_BILL_TO_CUSTOMERS_S_V.BILL_CUST_ACCOUNT_ID%TYPE INDEX BY BINARY_INTEGER;
60105 TYPE t_array_source_24 IS TABLE OF AR_BILL_TO_SITE_USES_S_V.BILL_USES_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
60106 TYPE t_array_source_25 IS TABLE OF AR_TRANSACTIONS_S_V.XLA_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
60107 TYPE t_array_source_30 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_INVOICE_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
60108 TYPE t_array_source_75 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
60109 TYPE t_array_source_76 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
60110 TYPE t_array_source_77 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
60111 
60112 TYPE t_array_source_4 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
60113 TYPE t_array_source_26 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ACCOUNT_CLASS%TYPE INDEX BY BINARY_INTEGER;
60114 TYPE t_array_source_27 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ID%TYPE INDEX BY BINARY_INTEGER;
60115 TYPE t_array_source_28 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
60116 TYPE t_array_source_29 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_AMT%TYPE INDEX BY BINARY_INTEGER;
60117 TYPE t_array_source_31 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
60118 TYPE t_array_source_32 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
60119 TYPE t_array_source_33 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
60120 TYPE t_array_source_34 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
60121 
60122 l_array_source_23              t_array_source_23;
60123 l_array_source_24              t_array_source_24;
60124 l_array_source_25              t_array_source_25;
60125 l_array_source_30              t_array_source_30;
60126 l_array_source_75              t_array_source_75;
60127 l_array_source_76              t_array_source_76;
60128 l_array_source_77              t_array_source_77;
60129 
60130 l_array_source_4      t_array_source_4;
60131 l_array_source_26      t_array_source_26;
60132 l_array_source_27      t_array_source_27;
60133 l_array_source_28      t_array_source_28;
60134 l_array_source_29      t_array_source_29;
60135 l_array_source_31      t_array_source_31;
60136 l_array_source_32      t_array_source_32;
60137 l_array_source_33      t_array_source_33;
60138 l_array_source_34      t_array_source_34;
60139 
60140 --
60141 CURSOR header_cur
60142 IS
60143 SELECT /*+ leading(xet) cardinality(xet,1) */
60144 -- Event Class Code: GUARANTEE
60145     xet.entity_id
60146    ,xet.legal_entity_id
60147    ,xet.entity_code
60148    ,xet.transaction_number
60149    ,xet.event_id
60150    ,xet.event_class_code
60151    ,xet.event_type_code
60152    ,xet.event_number
60153    ,xet.event_date
60154    ,xet.transaction_date
60155    ,xet.reference_num_1
60156    ,xet.reference_num_2
60157    ,xet.reference_num_3
60158    ,xet.reference_num_4
60159    ,xet.reference_char_1
60160    ,xet.reference_char_2
60161    ,xet.reference_char_3
60162    ,xet.reference_char_4
60163    ,xet.reference_date_1
60164    ,xet.reference_date_2
60165    ,xet.reference_date_3
60166    ,xet.reference_date_4
60167    ,xet.event_created_by
60168    ,xet.budgetary_control_flag 
60169   , h1.BILL_CUST_ACCOUNT_ID    source_23
60170   , h2.BILL_USES_SITE_USE_ID    source_24
60171   , h5.XLA_PARTY_TYPE    source_25
60172   , h5.TRX_INVOICE_CURRENCY_CODE    source_30
60173   , h5.TRX_DOC_SEQUENCE_CATEGORY    source_75
60174   , h5.TRX_DOC_SEQUENCE_ID    source_76
60175   , h5.TRX_DOC_SEQUENCE_VALUE    source_77
60176   FROM xla_events_gt     xet 
60177   , AR_BILL_TO_CUSTOMERS_S_V  h1
60178   , AR_BILL_TO_SITE_USES_S_V  h2
60179   , AR_TRANSACTIONS_S_V  h5
60180  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
60181    and xet.event_class_code = C_EVENT_CLASS_CODE
60182    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
60183   AND h2.event_id  = h1.event_id
60184   AND h5.event_id  = h1.event_id
60185 
60186  ORDER BY event_id
60187 ;
60188 
60189 
60190 --
60191 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
60192 IS
60193 SELECT  /*+ leading(xet) cardinality(xet,1) */
60194 -- Event Class Code: GUARANTEE
60195     xet.entity_id
60196    ,xet.legal_entity_id
60197    ,xet.entity_code
60198    ,xet.transaction_number
60199    ,xet.event_id
60200    ,xet.event_class_code
60201    ,xet.event_type_code
60202    ,xet.event_number
60203    ,xet.event_date
60204    ,xet.transaction_date
60205    ,xet.reference_num_1
60206    ,xet.reference_num_2
60207    ,xet.reference_num_3
60208    ,xet.reference_num_4
60209    ,xet.reference_char_1
60210    ,xet.reference_char_2
60211    ,xet.reference_char_3
60212    ,xet.reference_char_4
60213    ,xet.reference_date_1
60214    ,xet.reference_date_2
60215    ,xet.reference_date_3
60216    ,xet.reference_date_4
60217    ,xet.event_created_by
60218    ,xet.budgetary_control_flag
60219  , l3.LINE_NUMBER  
60220   , l4.TRX_LINE_DIST_CCID    source_4
60221   , l4.TRX_LINE_DIST_ACCOUNT_CLASS    source_26
60222   , l4.TRX_LINE_DIST_ID    source_27
60223   , l4.TRX_DISTRIBUTION_TYPE    source_28
60224   , l4.TRX_LINE_DIST_AMT    source_29
60225   , l3.TRX_LINE_CUR_CONVERSION_DATE    source_31
60226   , l3.TRX_LINE_CUR_CONVERSION_RATE    source_32
60227   , l3.TRX_LINE_CUR_CONVERSION_TYPE    source_33
60228   , l3.TRX_LINE_ACCTD_AMT    source_34
60229   FROM xla_events_gt     xet 
60230   , AR_CUST_TRX_LINES_BASE_V  l3
60231   , AR_CUST_TRX_LINES_L_V  l4
60232  WHERE xet.event_id between x_first_event_id and x_last_event_id
60233    and xet.event_date between p_pad_start_date and p_pad_end_date
60234    and xet.event_class_code = C_EVENT_CLASS_CODE
60235    and xet.event_status_code <> 'N'   AND l3.event_id      = xet.event_id
60236   AND l4.event_id    = l3.event_id
60237   AND l4.line_number = l3.line_number
60238 ;
60239 
60240 --
60241 BEGIN
60242 IF g_log_enabled THEN
60243    l_log_module := C_DEFAULT_MODULE||'.EventClass_107';
60244 END IF;
60245 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
60246    trace
60247       (p_msg      => 'BEGIN of EventClass_107'
60248       ,p_level    => C_LEVEL_PROCEDURE
60249       ,p_module   => l_log_module);
60250 END IF;
60251 
60252 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
60253    trace
60254       (p_msg      => 'p_application_id = '||p_application_id||
60255                      ' - p_base_ledger_id = '||p_base_ledger_id||
60256                      ' - p_target_ledger_id  = '||p_target_ledger_id||
60257                      ' - p_language = '||p_language||
60258                      ' - p_currency_code = '||p_currency_code||
60259                      ' - p_sla_ledger_id = '||p_sla_ledger_id
60260       ,p_level    => C_LEVEL_STATEMENT
60261       ,p_module   => l_log_module);
60262 END IF;
60263 --
60264 -- initialze arrays
60265 --
60266 g_array_event.DELETE;
60267 l_rec_array_event := l_null_rec_array_event;
60268 --
60269 --------------------------------------
60270 -- 4262811 Initialze MPA Line Number
60271 --------------------------------------
60272 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
60273 
60274 --
60275 
60276 --
60277 OPEN header_cur;
60278 --
60279 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
60280    trace
60281    (p_msg      => 'SQL - FETCH header_cur'
60285 --
60282    ,p_level    => C_LEVEL_STATEMENT
60283    ,p_module   => l_log_module);
60284 END IF;
60286 LOOP
60287 FETCH header_cur BULK COLLECT INTO
60288         l_array_entity_id
60289       , l_array_legal_entity_id
60290       , l_array_entity_code
60291       , l_array_transaction_num
60292       , l_array_event_id
60293       , l_array_class_code
60294       , l_array_event_type
60295       , l_array_event_number
60296       , l_array_event_date
60297       , l_array_transaction_date
60298       , l_array_reference_num_1
60299       , l_array_reference_num_2
60300       , l_array_reference_num_3
60301       , l_array_reference_num_4
60302       , l_array_reference_char_1
60303       , l_array_reference_char_2
60304       , l_array_reference_char_3
60305       , l_array_reference_char_4
60306       , l_array_reference_date_1
60307       , l_array_reference_date_2
60308       , l_array_reference_date_3
60309       , l_array_reference_date_4
60310       , l_array_event_created_by
60311       , l_array_budgetary_control_flag 
60312       , l_array_source_23
60313       , l_array_source_24
60314       , l_array_source_25
60315       , l_array_source_30
60316       , l_array_source_75
60317       , l_array_source_76
60318       , l_array_source_77
60319       LIMIT l_rows;
60320 --
60321 IF (C_LEVEL_EVENT >= g_log_level) THEN
60322    trace
60323    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
60324    ,p_level    => C_LEVEL_EVENT
60325    ,p_module   => l_log_module);
60326 END IF;
60327 --
60328 EXIT WHEN l_array_entity_id.COUNT = 0;
60329 
60330 -- initialize arrays
60331 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
60332 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
60333 
60334 --
60335 -- Bug 4458708
60336 --
60337 XLA_AE_LINES_PKG.g_LineNumber := 0;
60338 
60339 
60340 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
60341 g_last_hdr_idx := l_array_event_id.LAST;
60342 --
60343 -- loop for the headers. Each iteration is for each header extract row
60344 -- fetched in header cursor
60345 --
60346 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
60347 
60348 --
60349 -- set event info as cache for other routines to refer event attributes
60350 --
60351 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
60352    (p_application_id           => p_application_id
60353    ,p_primary_ledger_id        => p_primary_ledger_id
60354    ,p_base_ledger_id           => p_base_ledger_id
60355    ,p_target_ledger_id         => p_target_ledger_id
60356    ,p_entity_id                => l_array_entity_id(hdr_idx)
60357    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
60358    ,p_entity_code              => l_array_entity_code(hdr_idx)
60359    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
60360    ,p_event_id                 => l_array_event_id(hdr_idx)
60361    ,p_event_class_code         => l_array_class_code(hdr_idx)
60362    ,p_event_type_code          => l_array_event_type(hdr_idx)
60363    ,p_event_number             => l_array_event_number(hdr_idx)
60364    ,p_event_date               => l_array_event_date(hdr_idx)
60365    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
60366    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
60367    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
60368    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
60369    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
60370    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
60371    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
60372    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
60373    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
60374    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
60375    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
60376    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
60377    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
60378    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
60379    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
60380 
60381 --
60382 -- set the status of entry to C_VALID (0)
60383 --
60384 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
60385 
60386 --
60387 -- initialize a row for ae header
60388 --
60389 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
60390 
60391 l_event_id := l_array_event_id(hdr_idx);
60392 
60393 --
60394 -- storing the hdr_idx for event. May be used by line cursor.
60395 --
60396 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
60397 
60398 --
60399 -- store sources from header extract. This can be improved to
60400 -- store only those sources from header extract that may be used in lines
60401 --
60402 
60403 g_array_event(l_event_id).array_value_num('source_23') := l_array_source_23(hdr_idx);
60404 g_array_event(l_event_id).array_value_num('source_24') := l_array_source_24(hdr_idx);
60405 g_array_event(l_event_id).array_value_char('source_25') := l_array_source_25(hdr_idx);
60406 g_array_event(l_event_id).array_value_char('source_30') := l_array_source_30(hdr_idx);
60407 g_array_event(l_event_id).array_value_char('source_75') := l_array_source_75(hdr_idx);
60408 g_array_event(l_event_id).array_value_num('source_76') := l_array_source_76(hdr_idx);
60412 -- initilaize the status of ae headers for diffrent balance types
60409 g_array_event(l_event_id).array_value_num('source_77') := l_array_source_77(hdr_idx);
60410 
60411 --
60413 -- the status is initialised to C_NOT_CREATED (2)
60414 --
60415 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
60416 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
60417 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
60418 
60419 --
60420 -- call api to validate and store accounting attributes for header
60421 --
60422 
60423 ------------------------------------------------------------
60424 -- Accrual Reversal : to get date for Standard Source (NONE)
60425 ------------------------------------------------------------
60426 l_acc_rev_gl_date_source := NULL;
60427 
60428      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
60429       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_75');
60430      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
60431       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_76');
60432      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
60433       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_77');
60434      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
60435       l_rec_acct_attrs.array_date_value(4) := 
60436 xla_ae_sources_pkg.GetSystemSourceDate(
60437    p_source_code           => 'XLA_EVENT_DATE'
60438  , p_source_type_code      => 'Y'
60439  , p_source_application_id =>  602
60440 );
60441 
60442 
60443 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
60444 
60445 XLA_AE_HEADER_PKG.SetJeCategoryName;
60446 
60447 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
60448 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
60449 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
60450 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
60451 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
60452 
60453 
60454 -- No header level analytical criteria
60455 
60456 --
60457 --accounting attribute enhancement, bug 3612931
60458 --
60459 l_trx_reversal_source := SUBSTR(NULL, 1,30);
60460 
60461 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
60462    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
60463 
60464    xla_accounting_err_pkg.build_message
60465       (p_appli_s_name            => 'XLA'
60466       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
60467       ,p_token_1                 => 'ACCT_ATTR_NAME'
60468       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
60469       ,p_token_2                 => 'PRODUCT_NAME'
60470       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
60471       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
60472       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
60473       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
60474 
60475 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
60476    --
60477    -- following sets the accounting attributes needed to reverse
60478    -- accounting for a distributeion
60479    --
60480    xla_ae_lines_pkg.SetTrxReversalAttrs
60481       (p_event_id              => l_event_id
60482       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
60483       ,p_trx_reversal_source   => l_trx_reversal_source);
60484 
60485 END IF;
60486 
60487 
60488 ----------------------------------------------------------------
60489 -- 4262811 -  update the header statuses to invalid in need be
60490 ----------------------------------------------------------------
60491 --
60492 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
60493 
60494 
60495   -----------------------------------------------
60496   -- No accrual reversal for the event class/type
60497   -----------------------------------------------
60498 ----------------------------------------------------------------
60499 
60500 --
60501 -- this ends the header loop iteration for one bulk fetch
60502 --
60503 END LOOP;
60504 
60505 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
60506 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
60507 
60508 --
60509 -- insert dummy rows into lines gt table that were created due to
60510 -- transaction reversals
60511 --
60512 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
60513    l_result := XLA_AE_LINES_PKG.InsertLines;
60514 END IF;
60515 
60516 --
60517 -- reset the temp_line_num for each set of events fetched from header
60518 -- cursor rather than doing it for each new event in line cursor
60519 -- Bug 3939231
60520 --
60521 xla_ae_lines_pkg.g_temp_line_num := 0;
60522 
60523 
60524 
60525 --
60526 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
60527 --
60528 --
60529 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
60530 
60531       trace
60532          (p_msg      => 'SQL - FETCH line_cur'
60533          ,p_level    => C_LEVEL_STATEMENT
60534          ,p_module   => l_log_module);
60535 
60536 END IF;
60537 --
60538 --
60539 LOOP
60540   --
60544       , l_array_entity_code
60541   FETCH line_cur BULK COLLECT INTO
60542         l_array_entity_id
60543       , l_array_legal_entity_id
60545       , l_array_transaction_num
60546       , l_array_event_id
60547       , l_array_class_code
60548       , l_array_event_type
60549       , l_array_event_number
60550       , l_array_event_date
60551       , l_array_transaction_date
60552       , l_array_reference_num_1
60553       , l_array_reference_num_2
60554       , l_array_reference_num_3
60555       , l_array_reference_num_4
60556       , l_array_reference_char_1
60557       , l_array_reference_char_2
60558       , l_array_reference_char_3
60559       , l_array_reference_char_4
60560       , l_array_reference_date_1
60561       , l_array_reference_date_2
60562       , l_array_reference_date_3
60563       , l_array_reference_date_4
60564       , l_array_event_created_by
60565       , l_array_budgetary_control_flag
60566       , l_array_extract_line_num 
60567       , l_array_source_4
60568       , l_array_source_26
60569       , l_array_source_27
60570       , l_array_source_28
60571       , l_array_source_29
60572       , l_array_source_31
60573       , l_array_source_32
60574       , l_array_source_33
60575       , l_array_source_34
60576       LIMIT l_rows;
60577 
60578   --
60579   IF (C_LEVEL_EVENT >= g_log_level) THEN
60580             trace
60581                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
60582                ,p_level    => C_LEVEL_EVENT
60583                ,p_module   => l_log_module);
60584   END IF;
60585   --
60586   EXIT WHEN l_array_entity_id.count = 0;
60587 
60588   XLA_AE_LINES_PKG.g_rec_lines := null;
60589 
60590 --
60591 -- Bug 4458708
60592 --
60593 XLA_AE_LINES_PKG.g_LineNumber := 0;
60594 --
60595 --
60596 
60597 FOR Idx IN 1..l_array_event_id.count LOOP
60598    --
60599    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
60600    --
60601    l_event_id := l_array_event_id(idx);  -- 5648433
60602 
60603    --
60604    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
60605    --
60606 
60607    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
60608              (g_array_event(l_event_id).array_value_num('header_index'))
60609          ,'N'
60610          ) <> 'Y'
60611    THEN
60612       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
60613          trace
60614             (p_msg      => 'Trancaction revesal option is not Y '
60615             ,p_level    => C_LEVEL_STATEMENT
60616             ,p_module   => l_log_module);
60617       END IF;
60618 
60619 --
60620 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
60621 --
60622 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
60623 --
60624 -- set event info as cache for other routines to refer event attributes
60625 --
60626 
60627 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
60628    l_previous_event_id := l_event_id;
60629 
60630    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
60631       (p_application_id           => p_application_id
60632       ,p_primary_ledger_id        => p_primary_ledger_id
60633       ,p_base_ledger_id           => p_base_ledger_id
60634       ,p_target_ledger_id         => p_target_ledger_id
60635       ,p_entity_id                => l_array_entity_id(Idx)
60636       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
60637       ,p_entity_code              => l_array_entity_code(Idx)
60638       ,p_transaction_num          => l_array_transaction_num(Idx)
60639       ,p_event_id                 => l_array_event_id(Idx)
60640       ,p_event_class_code         => l_array_class_code(Idx)
60641       ,p_event_type_code          => l_array_event_type(Idx)
60642       ,p_event_number             => l_array_event_number(Idx)
60643       ,p_event_date               => l_array_event_date(Idx)
60644       ,p_transaction_date         => l_array_transaction_date(Idx)
60645       ,p_reference_num_1          => l_array_reference_num_1(Idx)
60646       ,p_reference_num_2          => l_array_reference_num_2(Idx)
60647       ,p_reference_num_3          => l_array_reference_num_3(Idx)
60648       ,p_reference_num_4          => l_array_reference_num_4(Idx)
60649       ,p_reference_char_1         => l_array_reference_char_1(Idx)
60650       ,p_reference_char_2         => l_array_reference_char_2(Idx)
60651       ,p_reference_char_3         => l_array_reference_char_3(Idx)
60652       ,p_reference_char_4         => l_array_reference_char_4(Idx)
60653       ,p_reference_date_1         => l_array_reference_date_1(Idx)
60654       ,p_reference_date_2         => l_array_reference_date_2(Idx)
60655       ,p_reference_date_3         => l_array_reference_date_3(Idx)
60656       ,p_reference_date_4         => l_array_reference_date_4(Idx)
60657       ,p_event_created_by         => l_array_event_created_by(Idx)
60658       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
60659        --
60660 END IF;
60661 
60662 
60663 
60664 --
60665 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
60666 
60667 l_acct_reversal_source := SUBSTR(NULL, 1,30);
60668 
60672 
60669 IF l_continue_with_lines THEN
60670    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
60671       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
60673       xla_accounting_err_pkg.build_message
60674          (p_appli_s_name            => 'XLA'
60675          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
60676          ,p_token_1                 => 'LINE_NUMBER'
60677          ,p_value_1                 => l_array_extract_line_num(Idx)
60678          ,p_token_2                 => 'PRODUCT_NAME'
60679          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
60680          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
60681          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
60682          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
60683 
60684    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
60685       --
60686       -- following sets the accounting attributes needed to reverse
60687       -- accounting for a distributeion
60688       --
60689 
60690       --
60691       -- 5217187
60692       --
60693       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
60694       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
60695                                        g_array_event(l_event_id).array_value_num('header_index'));
60696       --
60697       --
60698 
60699       -- No reversal code generated
60700 
60701       xla_ae_lines_pkg.SetAcctReversalAttrs
60702          (p_event_id             => l_event_id
60703          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
60704          ,p_calculate_acctd_flag => l_calculate_acctd_flag
60705          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
60706    END IF;
60707 
60708    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
60709        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
60710 
60711 --
60712 AcctLineType_43 (
60713  p_application_id  => p_application_id
60714  ,p_event_id     => l_event_id
60715  ,p_calculate_acctd_flag => l_calculate_acctd_flag
60716  ,p_calculate_g_l_flag => l_calculate_g_l_flag
60717  ,p_actual_flag => l_actual_flag
60718  ,p_balance_type_code => l_balance_type_code
60719  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
60720  
60721  , p_source_4 => l_array_source_4(Idx)
60722  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
60723  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
60724  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
60725  , p_source_26 => l_array_source_26(Idx)
60726  , p_source_27 => l_array_source_27(Idx)
60727  , p_source_28 => l_array_source_28(Idx)
60728  , p_source_29 => l_array_source_29(Idx)
60729  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
60730  , p_source_31 => l_array_source_31(Idx)
60731  , p_source_32 => l_array_source_32(Idx)
60732  , p_source_33 => l_array_source_33(Idx)
60733  , p_source_34 => l_array_source_34(Idx)
60734  );
60735 If(l_balance_type_code = 'A') THEN
60736   l_actual_gain_loss_ref := l_gain_or_loss_ref;
60737 END IF;
60738 
60739 --
60740 
60741 
60742 --
60743 AcctLineType_44 (
60744  p_application_id  => p_application_id
60745  ,p_event_id     => l_event_id
60746  ,p_calculate_acctd_flag => l_calculate_acctd_flag
60747  ,p_calculate_g_l_flag => l_calculate_g_l_flag
60748  ,p_actual_flag => l_actual_flag
60749  ,p_balance_type_code => l_balance_type_code
60750  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
60751  
60752  , p_source_4 => l_array_source_4(Idx)
60753  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
60754  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
60755  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
60756  , p_source_26 => l_array_source_26(Idx)
60757  , p_source_27 => l_array_source_27(Idx)
60758  , p_source_28 => l_array_source_28(Idx)
60759  , p_source_29 => l_array_source_29(Idx)
60760  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
60761  , p_source_31 => l_array_source_31(Idx)
60762  , p_source_32 => l_array_source_32(Idx)
60763  , p_source_33 => l_array_source_33(Idx)
60767   l_actual_gain_loss_ref := l_gain_or_loss_ref;
60764  , p_source_34 => l_array_source_34(Idx)
60765  );
60766 If(l_balance_type_code = 'A') THEN
60768 END IF;
60769 
60770 --
60771 
60772       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
60773       -- or secondary ledger that has different currency with primary
60774       -- or alc that is calculated by sla
60775       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
60776             (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'))
60777 
60778 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
60779 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
60780           AND (l_actual_flag = 'A')) THEN
60781         XLA_AE_LINES_PKG.CreateGainOrLossLines(
60782           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
60783          ,p_application_id   => p_application_id
60784          ,p_amb_context_code => 'DEFAULT'
60785          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
60786          ,p_event_class_code => C_EVENT_CLASS_CODE
60787          ,p_event_type_code  => C_EVENT_TYPE_CODE
60788          
60789          ,p_gain_ccid        => -1
60790          ,p_loss_ccid        => -1
60791 
60792          ,p_actual_flag      => l_actual_flag
60793          ,p_enc_flag         => null
60794          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
60795          ,p_enc_g_l_ref      => null
60796          );
60797       END IF;
60798    END IF;
60799 END IF;
60800 
60801    ELSE
60802       --
60803       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
60804       --
60805       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
60806          trace
60807             (p_msg      => 'Trancaction revesal option is Y'
60808             ,p_level    => C_LEVEL_STATEMENT
60809             ,p_module   => l_log_module);
60810       END IF;
60811    END IF;
60812 
60813 END LOOP;
60814 l_result := XLA_AE_LINES_PKG.InsertLines ;
60815 end loop;
60816 close line_cur;
60817 
60818 
60819 --
60820 -- insert headers into xla_ae_headers_gt table
60821 --
60822 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
60823 
60824 -- insert into errors table here.
60825 
60826 END LOOP;
60827 
60828 --
60829 -- 4865292
60830 --
60831 -- Compare g_hdr_extract_count with event count in
60832 -- CreateHeadersAndLines.
60833 --
60834 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
60835 
60836 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
60837    trace (p_msg     => '# rows extracted from header extract objects '
60838                     || ' (running total): '
60839                     || g_hdr_extract_count
60840          ,p_level   => C_LEVEL_STATEMENT
60841          ,p_module  => l_log_module);
60842 END IF;
60843 
60844 CLOSE header_cur;
60845 --
60846 
60847 --
60848 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
60849    trace
60850       (p_msg      => 'END of EventClass_107'
60851       ,p_level    => C_LEVEL_PROCEDURE
60852       ,p_module   => l_log_module);
60853 END IF;
60854 --
60855 RETURN l_result;
60856 EXCEPTION
60857 WHEN xla_exceptions_pkg.application_exception THEN
60858    
60859 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
60860 
60861    
60862 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
60863 
60864    RAISE;
60865 
60866 WHEN NO_DATA_FOUND THEN
60867 
60868 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
60869 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
60870 
60871 FOR header_record IN header_cur
60872 LOOP
60873     l_array_header_events(header_record.event_id) := header_record.event_id;
60874 END LOOP;
60875 
60876 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
60877 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
60878 
60879 fnd_file.put_line(fnd_file.LOG, '                    ');
60880 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
60881 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
60882 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
60883 
60884 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
60885 LOOP
60886 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
60887 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
60888         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
60889 	END IF;
60890 END LOOP;
60891 
60892 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
60893 fnd_file.put_line(fnd_file.LOG, '                    ');
60894 
60895 
60896 xla_exceptions_pkg.raise_message
60897       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_107');
60898 
60899 
60900 WHEN OTHERS THEN
60901    xla_exceptions_pkg.raise_message
60902       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_107');
60903 END EventClass_107;
60904 --
60905 
60909 --         insert_sources_108
60906 ---------------------------------------
60907 --
60908 -- PRIVATE PROCEDURE
60910 --
60911 ----------------------------------------
60912 --
60913 PROCEDURE insert_sources_108(
60914                                 p_target_ledger_id       IN NUMBER
60915                               , p_language               IN VARCHAR2
60916                               , p_sla_ledger_id          IN NUMBER
60917                               , p_pad_start_date         IN DATE
60918                               , p_pad_end_date           IN DATE
60919                          )
60920 IS
60921 
60922 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'INVOICE_ALL';
60923 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'INVOICE';
60924 p_apps_owner                   VARCHAR2(30);
60925 l_log_module                   VARCHAR2(240);
60926 BEGIN
60927 IF g_log_enabled THEN
60928       l_log_module := C_DEFAULT_MODULE||'.insert_sources_108';
60929 END IF;
60930 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
60931 
60932       trace
60933          (p_msg      => 'BEGIN of insert_sources_108'
60934          ,p_level    => C_LEVEL_PROCEDURE
60935          ,p_module   => l_log_module);
60936 
60937 END IF;
60938 
60939 -- select APPS owner
60940 SELECT oracle_username
60941   INTO p_apps_owner
60942   FROM fnd_oracle_userid
60943  WHERE read_only_flag = 'U'
60944 ;
60945 
60946 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
60947       trace
60948          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
60949                         ' - p_language = '||p_language||
60950                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
60951                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
60952                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
60953                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
60954          ,p_level    => C_LEVEL_STATEMENT
60955          ,p_module   => l_log_module);
60956 END IF;
60957 
60958 
60959 --
60960 INSERT INTO xla_diag_sources --hdr2
60961 (
60962         event_id
60963       , ledger_id
60964       , sla_ledger_id
60965       , description_language
60966       , object_name
60967       , object_type_code
60968       , line_number
60969       , source_application_id
60970       , source_type_code
60971       , source_code
60972       , source_value
60973       , source_meaning
60974       , created_by
60975       , creation_date
60976       , last_update_date
60977       , last_updated_by
60978       , last_update_login
60979       , program_update_date
60980       , program_application_id
60981       , program_id
60982       , request_id
60983 )
60984 SELECT
60985         event_id
60986       , p_target_ledger_id
60987       , p_sla_ledger_id
60988       , p_language
60989       , object_name
60990       , object_type_code
60991       , line_number
60992       , source_application_id
60993       , source_type_code
60994       , source_code
60995       , SUBSTR(source_value ,1,1996)
60996       , SUBSTR(source_meaning ,1,200)
60997       , xla_environment_pkg.g_Usr_Id
60998       , TRUNC(SYSDATE)
60999       , TRUNC(SYSDATE)
61000       , xla_environment_pkg.g_Usr_Id
61001       , xla_environment_pkg.g_Login_Id
61002       , TRUNC(SYSDATE)
61003       , xla_environment_pkg.g_Prog_Appl_Id
61004       , xla_environment_pkg.g_Prog_Id
61005       , xla_environment_pkg.g_Req_Id
61006   FROM (
61007        SELECT xet.event_id                  event_id
61008             , 0                          line_number
61009             , CASE r
61010                WHEN 1 THEN 'AR_TRANSACTIONS_S_V' 
61011                 WHEN 2 THEN 'AR_BILL_TO_CUSTOMERS_S_V' 
61012                 WHEN 3 THEN 'AR_BILL_TO_SITE_USES_S_V' 
61013                 WHEN 4 THEN 'AR_TRANSACTIONS_S_V' 
61014                 WHEN 5 THEN 'AR_TRANSACTIONS_S_V' 
61015                 WHEN 6 THEN 'AR_TRANSACTIONS_S_V' 
61016                 WHEN 7 THEN 'AR_TRANSACTIONS_S_V' 
61017                 WHEN 8 THEN 'AR_TRANSACTIONS_S_V' 
61018                 WHEN 9 THEN 'AR_TRANSACTIONS_S_V' 
61019                 
61020                ELSE null
61021               END                           object_name
61022             , CASE r
61023                 WHEN 1 THEN 'HEADER' 
61024                 WHEN 2 THEN 'HEADER' 
61025                 WHEN 3 THEN 'HEADER' 
61026                 WHEN 4 THEN 'HEADER' 
61027                 WHEN 5 THEN 'HEADER' 
61028                 WHEN 6 THEN 'HEADER' 
61029                 WHEN 7 THEN 'HEADER' 
61030                 WHEN 8 THEN 'HEADER' 
61031                 WHEN 9 THEN 'HEADER' 
61032                 
61033                 ELSE null
61034               END                           object_type_code
61035             , CASE r
61036                 WHEN 1 THEN '222' 
61037                 WHEN 2 THEN '222' 
61038                 WHEN 3 THEN '222' 
61039                 WHEN 4 THEN '222' 
61040                 WHEN 5 THEN '222' 
61041                 WHEN 6 THEN '222' 
61042                 WHEN 7 THEN '222' 
61043                 WHEN 8 THEN '222' 
61044                 WHEN 9 THEN '222' 
61045                 
61046                 ELSE null
61047               END                           source_application_id
61048             , 'S'             source_type_code
61049             , CASE r
61050                 WHEN 1 THEN 'TRX_RECEIVABLE_CCID' 
61051                 WHEN 2 THEN 'BILL_CUST_ACCOUNT_ID' 
61052                 WHEN 3 THEN 'BILL_USES_SITE_USE_ID' 
61053                 WHEN 4 THEN 'XLA_PARTY_TYPE' 
61057                 WHEN 8 THEN 'TRX_DOC_SEQUENCE_ID' 
61054                 WHEN 5 THEN 'TRX_INVOICE_CURRENCY_CODE' 
61055                 WHEN 6 THEN 'TRX_INVOICING_RULE_ID' 
61056                 WHEN 7 THEN 'TRX_DOC_SEQUENCE_CATEGORY' 
61058                 WHEN 9 THEN 'TRX_DOC_SEQUENCE_VALUE' 
61059                 
61060                 ELSE null
61061               END                           source_code
61062             , CASE r
61063                 WHEN 1 THEN TO_CHAR(h5.TRX_RECEIVABLE_CCID)
61064                 WHEN 2 THEN TO_CHAR(h1.BILL_CUST_ACCOUNT_ID)
61065                 WHEN 3 THEN TO_CHAR(h2.BILL_USES_SITE_USE_ID)
61066                 WHEN 4 THEN TO_CHAR(h5.XLA_PARTY_TYPE)
61067                 WHEN 5 THEN TO_CHAR(h5.TRX_INVOICE_CURRENCY_CODE)
61068                 WHEN 6 THEN TO_CHAR(h5.TRX_INVOICING_RULE_ID)
61069                 WHEN 7 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_CATEGORY)
61070                 WHEN 8 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_ID)
61071                 WHEN 9 THEN TO_CHAR(h5.TRX_DOC_SEQUENCE_VALUE)
61072                 
61073                 ELSE null
61074               END                           source_value
61075             , null              source_meaning
61076          FROM xla_events_gt     xet  
61077       , AR_BILL_TO_CUSTOMERS_S_V  h1
61078       , AR_BILL_TO_SITE_USES_S_V  h2
61079       , AR_TRANSACTIONS_S_V  h5
61080              ,(select rownum r from all_objects where rownum <= 9 and owner = p_apps_owner)
61081          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
61082            AND xet.event_class_code = C_EVENT_CLASS_CODE
61083               AND h1.event_id = xet.event_id
61084   AND h2.event_id  = h1.event_id
61085   AND h5.event_id  = h1.event_id
61086 
61087 )
61088 ;
61089 --
61090 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
61091 
61092       trace
61093          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
61094          ,p_level    => C_LEVEL_STATEMENT
61095          ,p_module   => l_log_module);
61096 
61097 END IF;
61098 --
61099 
61100 
61101 
61102 --
61103 INSERT INTO xla_diag_sources  --line2
61104 (
61105         event_id
61106       , ledger_id
61107       , sla_ledger_id
61108       , description_language
61109       , object_name
61110       , object_type_code
61111       , line_number
61112       , source_application_id
61113       , source_type_code
61114       , source_code
61115       , source_value
61116       , source_meaning
61117       , created_by
61118       , creation_date
61119       , last_update_date
61120       , last_updated_by
61121       , last_update_login
61122       , program_update_date
61123       , program_application_id
61124       , program_id
61125       , request_id
61126 )
61127 SELECT  event_id
61128       , p_target_ledger_id
61129       , p_sla_ledger_id
61130       , p_language
61131       , object_name
61132       , object_type_code
61133       , line_number
61134       , source_application_id
61135       , source_type_code
61136       , source_code
61137       , SUBSTR(source_value,1,1996)
61138       , SUBSTR(source_meaning ,1,200)
61139       , xla_environment_pkg.g_Usr_Id
61140       , TRUNC(SYSDATE)
61141       , TRUNC(SYSDATE)
61142       , xla_environment_pkg.g_Usr_Id
61143       , xla_environment_pkg.g_Login_Id
61144       , TRUNC(SYSDATE)
61145       , xla_environment_pkg.g_Prog_Appl_Id
61146       , xla_environment_pkg.g_Prog_Id
61147       , xla_environment_pkg.g_Req_Id
61148   FROM (
61149        SELECT xet.event_id                  event_id
61150             , l4.line_number                 line_number
61151             , CASE r
61152                WHEN 1 THEN 'AR_CUST_TRX_LINES_L_V' 
61153                 WHEN 2 THEN 'AR_CUST_TRX_LINES_L_V' 
61154                 WHEN 3 THEN 'AR_CUST_TRX_LINES_L_V' 
61155                 WHEN 4 THEN 'AR_CUST_TRX_LINES_L_V' 
61156                 WHEN 5 THEN 'AR_CUST_TRX_LINES_L_V' 
61157                 WHEN 6 THEN 'AR_CUST_TRX_LINES_BASE_V' 
61158                 WHEN 7 THEN 'AR_CUST_TRX_LINES_BASE_V' 
61159                 WHEN 8 THEN 'AR_CUST_TRX_LINES_BASE_V' 
61160                 WHEN 9 THEN 'AR_CUST_TRX_LINES_BASE_V' 
61161                 WHEN 10 THEN 'AR_CUST_TRX_LINES_L_V' 
61162                 WHEN 11 THEN 'AR_CUST_TRX_LINES_BASE_V' 
61163                 
61164                ELSE null
61165               END                           object_name
61166             , CASE r
61167                 WHEN 1 THEN 'LINE' 
61168                 WHEN 2 THEN 'LINE' 
61169                 WHEN 3 THEN 'LINE' 
61170                 WHEN 4 THEN 'LINE' 
61171                 WHEN 5 THEN 'LINE' 
61172                 WHEN 6 THEN 'LINE' 
61173                 WHEN 7 THEN 'LINE' 
61174                 WHEN 8 THEN 'LINE' 
61175                 WHEN 9 THEN 'LINE' 
61176                 WHEN 10 THEN 'LINE' 
61177                 WHEN 11 THEN 'LINE' 
61178                 
61179                 ELSE null
61180               END                           object_type_code
61181             , CASE r
61182                 WHEN 1 THEN '222' 
61183                 WHEN 2 THEN '222' 
61184                 WHEN 3 THEN '222' 
61185                 WHEN 4 THEN '222' 
61186                 WHEN 5 THEN '222' 
61187                 WHEN 6 THEN '222' 
61188                 WHEN 7 THEN '222' 
61189                 WHEN 8 THEN '222' 
61190                 WHEN 9 THEN '222' 
61191                 WHEN 10 THEN '222' 
61192                 WHEN 11 THEN '222' 
61193                 
61194                 ELSE null
61195               END                           source_application_id
61199                 WHEN 2 THEN 'TRX_LINE_DIST_ACCOUNT_CLASS' 
61196             , 'S'             source_type_code
61197             , CASE r
61198                 WHEN 1 THEN 'TRX_LINE_DIST_CCID' 
61200                 WHEN 3 THEN 'TRX_LINE_DIST_ID' 
61201                 WHEN 4 THEN 'TRX_DISTRIBUTION_TYPE' 
61202                 WHEN 5 THEN 'TRX_LINE_DIST_AMT' 
61203                 WHEN 6 THEN 'TRX_LINE_CUR_CONVERSION_DATE' 
61204                 WHEN 7 THEN 'TRX_LINE_CUR_CONVERSION_RATE' 
61205                 WHEN 8 THEN 'TRX_LINE_CUR_CONVERSION_TYPE' 
61206                 WHEN 9 THEN 'TRX_LINE_ACCTD_AMT' 
61207                 WHEN 10 THEN 'TRX_TAX_LINE_ID' 
61208                 WHEN 11 THEN 'ROUNDING_CORRECTION_FLAG' 
61209                 
61210                 ELSE null
61211               END                           source_code
61212             , CASE r
61213                 WHEN 1 THEN TO_CHAR(l4.TRX_LINE_DIST_CCID)
61214                 WHEN 2 THEN TO_CHAR(l4.TRX_LINE_DIST_ACCOUNT_CLASS)
61215                 WHEN 3 THEN TO_CHAR(l4.TRX_LINE_DIST_ID)
61216                 WHEN 4 THEN TO_CHAR(l4.TRX_DISTRIBUTION_TYPE)
61217                 WHEN 5 THEN TO_CHAR(l4.TRX_LINE_DIST_AMT)
61218                 WHEN 6 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_DATE)
61219                 WHEN 7 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_RATE)
61220                 WHEN 8 THEN TO_CHAR(l3.TRX_LINE_CUR_CONVERSION_TYPE)
61221                 WHEN 9 THEN TO_CHAR(l3.TRX_LINE_ACCTD_AMT)
61222                 WHEN 10 THEN TO_CHAR(l4.TRX_TAX_LINE_ID)
61223                 WHEN 11 THEN TO_CHAR(l3.ROUNDING_CORRECTION_FLAG)
61224                 
61225                 ELSE null
61226               END                           source_value
61227             , null              source_meaning
61228          FROM  xla_events_gt     xet  
61229         , AR_CUST_TRX_LINES_BASE_V  l3
61230         , AR_CUST_TRX_LINES_L_V  l4
61231             , (select rownum r from all_objects where rownum <= 11 and owner = p_apps_owner)
61232         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
61233           AND xet.event_class_code = C_EVENT_CLASS_CODE
61234             AND l3.event_id          = xet.event_id
61235   AND l4.event_id    = l3.event_id
61236   AND l4.line_number = l3.line_number
61237 
61238 )
61239 ;
61240 --
61241 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
61242 
61243       trace
61244          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
61245          ,p_level    => C_LEVEL_STATEMENT
61246          ,p_module   => l_log_module);
61247 
61248 END IF;
61249 
61250 
61251 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
61252       trace
61253          (p_msg      => 'END of insert_sources_108'
61254          ,p_level    => C_LEVEL_PROCEDURE
61255          ,p_module   => l_log_module);
61256 END IF;
61257 EXCEPTION
61258   WHEN xla_exceptions_pkg.application_exception THEN
61259       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
61260             trace
61261                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
61262                ,p_level    => C_LEVEL_EXCEPTION
61263                ,p_module   => l_log_module);
61264       END IF;
61265       RAISE;
61266   WHEN OTHERS THEN
61267       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
61268             trace
61269                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
61270                ,p_level    => C_LEVEL_EXCEPTION
61271                ,p_module   => l_log_module);
61272        END IF;
61273        xla_exceptions_pkg.raise_message
61274            (p_location => 'XLA_00222_AAD_S_000008_PKG.insert_sources_108');
61275 END insert_sources_108;
61276 --
61277 
61278 ---------------------------------------
61279 --
61280 -- PRIVATE FUNCTION
61281 --         EventClass_108
61282 --
61283 ----------------------------------------
61284 --
61285 FUNCTION EventClass_108
61286        (p_application_id         IN NUMBER
61287        ,p_base_ledger_id         IN NUMBER
61288        ,p_target_ledger_id       IN NUMBER
61289        ,p_language               IN VARCHAR2
61290        ,p_currency_code          IN VARCHAR2
61291        ,p_sla_ledger_id          IN NUMBER
61292        ,p_pad_start_date         IN DATE
61293        ,p_pad_end_date           IN DATE
61294        ,p_primary_ledger_id      IN NUMBER)
61295 RETURN BOOLEAN IS
61296 --
61297 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'INVOICE_ALL';
61298 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'INVOICE';
61299 
61300 l_calculate_acctd_flag   VARCHAR2(1) :='N';
61301 l_calculate_g_l_flag     VARCHAR2(1) :='N';
61302 --
61303 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
61304 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
61305 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
61306 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
61307 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
61308 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
61309 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
61310 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
61311 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
61312 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
61313 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
61314 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
61315 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
61316 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
61317 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
61318 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
61319 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
61320 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
61321 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
61322 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
61323 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
61324 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
61325 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
61326 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
61327 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
61328 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
61329 
61330 l_event_id                             NUMBER;
61331 l_previous_event_id                    NUMBER;
61332 l_first_event_id                       NUMBER;
61333 l_last_event_id                        NUMBER;
61334 
61335 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
61336 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
61337 --
61338 --
61339 l_result                    BOOLEAN := TRUE;
61340 l_rows                      NUMBER  := 1000;
61341 l_event_type_name           VARCHAR2(80) := 'All';
61342 l_event_class_name          VARCHAR2(80) := 'Invoice';
61343 l_description               VARCHAR2(4000);
61344 l_transaction_reversal      NUMBER;
61345 l_ae_header_id              NUMBER;
61346 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
61347 l_log_module                VARCHAR2(240);
61348 --
61349 l_acct_reversal_source      VARCHAR2(30);
61350 l_trx_reversal_source       VARCHAR2(30);
61351 
61352 l_continue_with_lines       BOOLEAN := TRUE;
61353 --
61354 l_acc_rev_gl_date_source    DATE;                      -- 4262811
61355 --
61356 type t_array_event_id is table of number index by binary_integer;
61357 
61358 l_rec_array_event                    t_rec_array_event;
61359 l_null_rec_array_event               t_rec_array_event;
61360 l_array_ae_header_id                 xla_number_array_type;
61361 l_actual_flag                        VARCHAR2(1) := NULL;
61362 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
61363 l_balance_type_code                  VARCHAR2(1) :=NULL;
61364 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
61365 
61366 --
61367 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
61368 --
61369 
61370 TYPE t_array_source_9 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_RECEIVABLE_CCID%TYPE INDEX BY BINARY_INTEGER;
61371 TYPE t_array_source_23 IS TABLE OF AR_BILL_TO_CUSTOMERS_S_V.BILL_CUST_ACCOUNT_ID%TYPE INDEX BY BINARY_INTEGER;
61372 TYPE t_array_source_24 IS TABLE OF AR_BILL_TO_SITE_USES_S_V.BILL_USES_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
61373 TYPE t_array_source_25 IS TABLE OF AR_TRANSACTIONS_S_V.XLA_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
61374 TYPE t_array_source_30 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_INVOICE_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
61375 TYPE t_array_source_51 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_INVOICING_RULE_ID%TYPE INDEX BY BINARY_INTEGER;
61376 TYPE t_array_source_75 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
61377 TYPE t_array_source_76 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
61378 TYPE t_array_source_77 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
61379 
61380 TYPE t_array_source_4 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
61381 TYPE t_array_source_26 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ACCOUNT_CLASS%TYPE INDEX BY BINARY_INTEGER;
61382 TYPE t_array_source_27 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ID%TYPE INDEX BY BINARY_INTEGER;
61383 TYPE t_array_source_28 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
61384 TYPE t_array_source_29 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_AMT%TYPE INDEX BY BINARY_INTEGER;
61385 TYPE t_array_source_31 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
61386 TYPE t_array_source_32 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
61387 TYPE t_array_source_33 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
61388 TYPE t_array_source_34 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.TRX_LINE_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
61389 TYPE t_array_source_48 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_TAX_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
61390 TYPE t_array_source_49 IS TABLE OF AR_CUST_TRX_LINES_BASE_V.ROUNDING_CORRECTION_FLAG%TYPE INDEX BY BINARY_INTEGER;
61391 
61392 l_array_source_9              t_array_source_9;
61393 l_array_source_23              t_array_source_23;
61394 l_array_source_24              t_array_source_24;
61395 l_array_source_25              t_array_source_25;
61396 l_array_source_30              t_array_source_30;
61397 l_array_source_51              t_array_source_51;
61398 l_array_source_75              t_array_source_75;
61399 l_array_source_76              t_array_source_76;
61400 l_array_source_77              t_array_source_77;
61401 
61402 l_array_source_4      t_array_source_4;
61403 l_array_source_26      t_array_source_26;
61404 l_array_source_27      t_array_source_27;
61405 l_array_source_28      t_array_source_28;
61406 l_array_source_29      t_array_source_29;
61407 l_array_source_31      t_array_source_31;
61408 l_array_source_32      t_array_source_32;
61412 l_array_source_49      t_array_source_49;
61409 l_array_source_33      t_array_source_33;
61410 l_array_source_34      t_array_source_34;
61411 l_array_source_48      t_array_source_48;
61413 
61414 --
61415 CURSOR header_cur
61416 IS
61417 SELECT /*+ leading(xet) cardinality(xet,1) */
61418 -- Event Class Code: INVOICE
61419     xet.entity_id
61420    ,xet.legal_entity_id
61421    ,xet.entity_code
61422    ,xet.transaction_number
61423    ,xet.event_id
61424    ,xet.event_class_code
61425    ,xet.event_type_code
61426    ,xet.event_number
61427    ,xet.event_date
61428    ,xet.transaction_date
61429    ,xet.reference_num_1
61430    ,xet.reference_num_2
61431    ,xet.reference_num_3
61432    ,xet.reference_num_4
61433    ,xet.reference_char_1
61434    ,xet.reference_char_2
61435    ,xet.reference_char_3
61436    ,xet.reference_char_4
61437    ,xet.reference_date_1
61438    ,xet.reference_date_2
61439    ,xet.reference_date_3
61440    ,xet.reference_date_4
61441    ,xet.event_created_by
61442    ,xet.budgetary_control_flag 
61443   , h5.TRX_RECEIVABLE_CCID    source_9
61444   , h1.BILL_CUST_ACCOUNT_ID    source_23
61445   , h2.BILL_USES_SITE_USE_ID    source_24
61446   , h5.XLA_PARTY_TYPE    source_25
61447   , h5.TRX_INVOICE_CURRENCY_CODE    source_30
61448   , h5.TRX_INVOICING_RULE_ID    source_51
61449   , h5.TRX_DOC_SEQUENCE_CATEGORY    source_75
61450   , h5.TRX_DOC_SEQUENCE_ID    source_76
61451   , h5.TRX_DOC_SEQUENCE_VALUE    source_77
61452   FROM xla_events_gt     xet 
61453   , AR_BILL_TO_CUSTOMERS_S_V  h1
61454   , AR_BILL_TO_SITE_USES_S_V  h2
61455   , AR_TRANSACTIONS_S_V  h5
61456  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
61457    and xet.event_class_code = C_EVENT_CLASS_CODE
61458    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
61459   AND h2.event_id  = h1.event_id
61460   AND h5.event_id  = h1.event_id
61461 
61462  ORDER BY event_id
61463 ;
61464 
61465 
61466 --
61467 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
61468 IS
61469 SELECT  /*+ leading(xet) cardinality(xet,1) */
61470 -- Event Class Code: INVOICE
61471     xet.entity_id
61472    ,xet.legal_entity_id
61473    ,xet.entity_code
61474    ,xet.transaction_number
61475    ,xet.event_id
61476    ,xet.event_class_code
61477    ,xet.event_type_code
61478    ,xet.event_number
61479    ,xet.event_date
61480    ,xet.transaction_date
61481    ,xet.reference_num_1
61482    ,xet.reference_num_2
61483    ,xet.reference_num_3
61484    ,xet.reference_num_4
61485    ,xet.reference_char_1
61486    ,xet.reference_char_2
61487    ,xet.reference_char_3
61488    ,xet.reference_char_4
61489    ,xet.reference_date_1
61490    ,xet.reference_date_2
61491    ,xet.reference_date_3
61492    ,xet.reference_date_4
61493    ,xet.event_created_by
61494    ,xet.budgetary_control_flag
61495  , l3.LINE_NUMBER  
61496   , l4.TRX_LINE_DIST_CCID    source_4
61497   , l4.TRX_LINE_DIST_ACCOUNT_CLASS    source_26
61498   , l4.TRX_LINE_DIST_ID    source_27
61499   , l4.TRX_DISTRIBUTION_TYPE    source_28
61500   , l4.TRX_LINE_DIST_AMT    source_29
61501   , l3.TRX_LINE_CUR_CONVERSION_DATE    source_31
61502   , l3.TRX_LINE_CUR_CONVERSION_RATE    source_32
61503   , l3.TRX_LINE_CUR_CONVERSION_TYPE    source_33
61504   , l3.TRX_LINE_ACCTD_AMT    source_34
61505   , l4.TRX_TAX_LINE_ID    source_48
61506   , l3.ROUNDING_CORRECTION_FLAG    source_49
61507   FROM xla_events_gt     xet 
61508   , AR_CUST_TRX_LINES_BASE_V  l3
61509   , AR_CUST_TRX_LINES_L_V  l4
61510  WHERE xet.event_id between x_first_event_id and x_last_event_id
61511    and xet.event_date between p_pad_start_date and p_pad_end_date
61512    and xet.event_class_code = C_EVENT_CLASS_CODE
61513    and xet.event_status_code <> 'N'   AND l3.event_id      = xet.event_id
61514   AND l4.event_id    = l3.event_id
61515   AND l4.line_number = l3.line_number
61516 ;
61517 
61518 --
61519 BEGIN
61520 IF g_log_enabled THEN
61521    l_log_module := C_DEFAULT_MODULE||'.EventClass_108';
61522 END IF;
61523 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
61524    trace
61525       (p_msg      => 'BEGIN of EventClass_108'
61526       ,p_level    => C_LEVEL_PROCEDURE
61527       ,p_module   => l_log_module);
61528 END IF;
61529 
61530 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
61531    trace
61532       (p_msg      => 'p_application_id = '||p_application_id||
61533                      ' - p_base_ledger_id = '||p_base_ledger_id||
61534                      ' - p_target_ledger_id  = '||p_target_ledger_id||
61535                      ' - p_language = '||p_language||
61536                      ' - p_currency_code = '||p_currency_code||
61537                      ' - p_sla_ledger_id = '||p_sla_ledger_id
61538       ,p_level    => C_LEVEL_STATEMENT
61539       ,p_module   => l_log_module);
61540 END IF;
61541 --
61542 -- initialze arrays
61543 --
61544 g_array_event.DELETE;
61545 l_rec_array_event := l_null_rec_array_event;
61546 --
61547 --------------------------------------
61548 -- 4262811 Initialze MPA Line Number
61549 --------------------------------------
61550 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
61551 
61552 --
61553 
61554 --
61555 OPEN header_cur;
61556 --
61557 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
61558    trace
61559    (p_msg      => 'SQL - FETCH header_cur'
61560    ,p_level    => C_LEVEL_STATEMENT
61561    ,p_module   => l_log_module);
61562 END IF;
61566         l_array_entity_id
61563 --
61564 LOOP
61565 FETCH header_cur BULK COLLECT INTO
61567       , l_array_legal_entity_id
61568       , l_array_entity_code
61569       , l_array_transaction_num
61570       , l_array_event_id
61571       , l_array_class_code
61572       , l_array_event_type
61573       , l_array_event_number
61574       , l_array_event_date
61575       , l_array_transaction_date
61576       , l_array_reference_num_1
61577       , l_array_reference_num_2
61578       , l_array_reference_num_3
61579       , l_array_reference_num_4
61580       , l_array_reference_char_1
61581       , l_array_reference_char_2
61582       , l_array_reference_char_3
61583       , l_array_reference_char_4
61584       , l_array_reference_date_1
61585       , l_array_reference_date_2
61586       , l_array_reference_date_3
61587       , l_array_reference_date_4
61588       , l_array_event_created_by
61589       , l_array_budgetary_control_flag 
61590       , l_array_source_9
61591       , l_array_source_23
61592       , l_array_source_24
61593       , l_array_source_25
61594       , l_array_source_30
61595       , l_array_source_51
61596       , l_array_source_75
61597       , l_array_source_76
61598       , l_array_source_77
61599       LIMIT l_rows;
61600 --
61601 IF (C_LEVEL_EVENT >= g_log_level) THEN
61602    trace
61603    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
61604    ,p_level    => C_LEVEL_EVENT
61605    ,p_module   => l_log_module);
61606 END IF;
61607 --
61608 EXIT WHEN l_array_entity_id.COUNT = 0;
61609 
61610 -- initialize arrays
61611 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
61612 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
61613 
61614 --
61615 -- Bug 4458708
61616 --
61617 XLA_AE_LINES_PKG.g_LineNumber := 0;
61618 
61619 
61620 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
61621 g_last_hdr_idx := l_array_event_id.LAST;
61622 --
61623 -- loop for the headers. Each iteration is for each header extract row
61624 -- fetched in header cursor
61625 --
61626 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
61627 
61628 --
61629 -- set event info as cache for other routines to refer event attributes
61630 --
61631 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
61632    (p_application_id           => p_application_id
61633    ,p_primary_ledger_id        => p_primary_ledger_id
61634    ,p_base_ledger_id           => p_base_ledger_id
61635    ,p_target_ledger_id         => p_target_ledger_id
61636    ,p_entity_id                => l_array_entity_id(hdr_idx)
61637    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
61638    ,p_entity_code              => l_array_entity_code(hdr_idx)
61639    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
61640    ,p_event_id                 => l_array_event_id(hdr_idx)
61641    ,p_event_class_code         => l_array_class_code(hdr_idx)
61642    ,p_event_type_code          => l_array_event_type(hdr_idx)
61643    ,p_event_number             => l_array_event_number(hdr_idx)
61644    ,p_event_date               => l_array_event_date(hdr_idx)
61645    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
61646    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
61647    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
61648    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
61649    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
61650    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
61651    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
61652    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
61653    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
61654    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
61655    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
61656    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
61657    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
61658    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
61659    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
61660 
61661 --
61662 -- set the status of entry to C_VALID (0)
61663 --
61664 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
61665 
61666 --
61667 -- initialize a row for ae header
61668 --
61669 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
61670 
61671 l_event_id := l_array_event_id(hdr_idx);
61672 
61673 --
61674 -- storing the hdr_idx for event. May be used by line cursor.
61675 --
61676 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
61677 
61678 --
61679 -- store sources from header extract. This can be improved to
61680 -- store only those sources from header extract that may be used in lines
61681 --
61682 
61683 g_array_event(l_event_id).array_value_num('source_9') := l_array_source_9(hdr_idx);
61684 g_array_event(l_event_id).array_value_num('source_23') := l_array_source_23(hdr_idx);
61685 g_array_event(l_event_id).array_value_num('source_24') := l_array_source_24(hdr_idx);
61686 g_array_event(l_event_id).array_value_char('source_25') := l_array_source_25(hdr_idx);
61687 g_array_event(l_event_id).array_value_char('source_30') := l_array_source_30(hdr_idx);
61688 g_array_event(l_event_id).array_value_num('source_51') := l_array_source_51(hdr_idx);
61689 g_array_event(l_event_id).array_value_char('source_75') := l_array_source_75(hdr_idx);
61690 g_array_event(l_event_id).array_value_num('source_76') := l_array_source_76(hdr_idx);
61691 g_array_event(l_event_id).array_value_num('source_77') := l_array_source_77(hdr_idx);
61692 
61693 --
61694 -- initilaize the status of ae headers for diffrent balance types
61695 -- the status is initialised to C_NOT_CREATED (2)
61696 --
61697 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
61698 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
61699 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
61700 
61701 --
61702 -- call api to validate and store accounting attributes for header
61703 --
61704 
61705 ------------------------------------------------------------
61706 -- Accrual Reversal : to get date for Standard Source (NONE)
61707 ------------------------------------------------------------
61708 l_acc_rev_gl_date_source := NULL;
61709 
61710      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
61711       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_75');
61712      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
61713       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_76');
61714      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
61715       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_77');
61716      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
61717       l_rec_acct_attrs.array_date_value(4) := 
61718 xla_ae_sources_pkg.GetSystemSourceDate(
61719    p_source_code           => 'XLA_EVENT_DATE'
61720  , p_source_type_code      => 'Y'
61721  , p_source_application_id =>  602
61722 );
61723 
61724 
61725 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
61726 
61727 XLA_AE_HEADER_PKG.SetJeCategoryName;
61728 
61729 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
61730 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
61731 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
61732 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
61733 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
61734 
61735 
61736 -- No header level analytical criteria
61737 
61738 --
61739 --accounting attribute enhancement, bug 3612931
61740 --
61741 l_trx_reversal_source := SUBSTR(NULL, 1,30);
61742 
61743 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
61744    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
61745 
61746    xla_accounting_err_pkg.build_message
61747       (p_appli_s_name            => 'XLA'
61748       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
61749       ,p_token_1                 => 'ACCT_ATTR_NAME'
61750       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
61751       ,p_token_2                 => 'PRODUCT_NAME'
61752       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
61753       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
61754       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
61755       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
61756 
61757 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
61758    --
61759    -- following sets the accounting attributes needed to reverse
61760    -- accounting for a distributeion
61761    --
61762    xla_ae_lines_pkg.SetTrxReversalAttrs
61763       (p_event_id              => l_event_id
61764       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
61765       ,p_trx_reversal_source   => l_trx_reversal_source);
61766 
61767 END IF;
61768 
61769 
61770 ----------------------------------------------------------------
61771 -- 4262811 -  update the header statuses to invalid in need be
61772 ----------------------------------------------------------------
61773 --
61774 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
61775 
61776 
61777   -----------------------------------------------
61778   -- No accrual reversal for the event class/type
61779   -----------------------------------------------
61780 ----------------------------------------------------------------
61781 
61782 --
61786 
61783 -- this ends the header loop iteration for one bulk fetch
61784 --
61785 END LOOP;
61787 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
61788 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
61789 
61790 --
61791 -- insert dummy rows into lines gt table that were created due to
61792 -- transaction reversals
61793 --
61794 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
61795    l_result := XLA_AE_LINES_PKG.InsertLines;
61796 END IF;
61797 
61798 --
61799 -- reset the temp_line_num for each set of events fetched from header
61800 -- cursor rather than doing it for each new event in line cursor
61801 -- Bug 3939231
61802 --
61803 xla_ae_lines_pkg.g_temp_line_num := 0;
61804 
61805 
61806 
61807 --
61808 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
61809 --
61810 --
61811 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
61812 
61813       trace
61814          (p_msg      => 'SQL - FETCH line_cur'
61815          ,p_level    => C_LEVEL_STATEMENT
61816          ,p_module   => l_log_module);
61817 
61818 END IF;
61819 --
61820 --
61821 LOOP
61822   --
61823   FETCH line_cur BULK COLLECT INTO
61824         l_array_entity_id
61825       , l_array_legal_entity_id
61826       , l_array_entity_code
61827       , l_array_transaction_num
61828       , l_array_event_id
61829       , l_array_class_code
61830       , l_array_event_type
61831       , l_array_event_number
61832       , l_array_event_date
61833       , l_array_transaction_date
61834       , l_array_reference_num_1
61835       , l_array_reference_num_2
61836       , l_array_reference_num_3
61837       , l_array_reference_num_4
61838       , l_array_reference_char_1
61839       , l_array_reference_char_2
61840       , l_array_reference_char_3
61841       , l_array_reference_char_4
61842       , l_array_reference_date_1
61843       , l_array_reference_date_2
61844       , l_array_reference_date_3
61845       , l_array_reference_date_4
61846       , l_array_event_created_by
61847       , l_array_budgetary_control_flag
61848       , l_array_extract_line_num 
61849       , l_array_source_4
61850       , l_array_source_26
61851       , l_array_source_27
61852       , l_array_source_28
61853       , l_array_source_29
61854       , l_array_source_31
61855       , l_array_source_32
61856       , l_array_source_33
61857       , l_array_source_34
61858       , l_array_source_48
61859       , l_array_source_49
61860       LIMIT l_rows;
61861 
61862   --
61863   IF (C_LEVEL_EVENT >= g_log_level) THEN
61864             trace
61865                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
61866                ,p_level    => C_LEVEL_EVENT
61867                ,p_module   => l_log_module);
61868   END IF;
61869   --
61870   EXIT WHEN l_array_entity_id.count = 0;
61871 
61872   XLA_AE_LINES_PKG.g_rec_lines := null;
61873 
61874 --
61875 -- Bug 4458708
61876 --
61877 XLA_AE_LINES_PKG.g_LineNumber := 0;
61878 --
61879 --
61880 
61881 FOR Idx IN 1..l_array_event_id.count LOOP
61882    --
61883    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
61884    --
61885    l_event_id := l_array_event_id(idx);  -- 5648433
61886 
61887    --
61888    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
61889    --
61890 
61891    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
61892              (g_array_event(l_event_id).array_value_num('header_index'))
61893          ,'N'
61894          ) <> 'Y'
61895    THEN
61896       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
61897          trace
61898             (p_msg      => 'Trancaction revesal option is not Y '
61899             ,p_level    => C_LEVEL_STATEMENT
61900             ,p_module   => l_log_module);
61901       END IF;
61902 
61903 --
61904 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
61905 --
61906 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
61907 --
61908 -- set event info as cache for other routines to refer event attributes
61909 --
61910 
61911 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
61912    l_previous_event_id := l_event_id;
61913 
61914    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
61915       (p_application_id           => p_application_id
61916       ,p_primary_ledger_id        => p_primary_ledger_id
61917       ,p_base_ledger_id           => p_base_ledger_id
61918       ,p_target_ledger_id         => p_target_ledger_id
61919       ,p_entity_id                => l_array_entity_id(Idx)
61920       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
61921       ,p_entity_code              => l_array_entity_code(Idx)
61922       ,p_transaction_num          => l_array_transaction_num(Idx)
61923       ,p_event_id                 => l_array_event_id(Idx)
61924       ,p_event_class_code         => l_array_class_code(Idx)
61925       ,p_event_type_code          => l_array_event_type(Idx)
61926       ,p_event_number             => l_array_event_number(Idx)
61927       ,p_event_date               => l_array_event_date(Idx)
61928       ,p_transaction_date         => l_array_transaction_date(Idx)
61929       ,p_reference_num_1          => l_array_reference_num_1(Idx)
61930       ,p_reference_num_2          => l_array_reference_num_2(Idx)
61934       ,p_reference_char_2         => l_array_reference_char_2(Idx)
61931       ,p_reference_num_3          => l_array_reference_num_3(Idx)
61932       ,p_reference_num_4          => l_array_reference_num_4(Idx)
61933       ,p_reference_char_1         => l_array_reference_char_1(Idx)
61935       ,p_reference_char_3         => l_array_reference_char_3(Idx)
61936       ,p_reference_char_4         => l_array_reference_char_4(Idx)
61937       ,p_reference_date_1         => l_array_reference_date_1(Idx)
61938       ,p_reference_date_2         => l_array_reference_date_2(Idx)
61939       ,p_reference_date_3         => l_array_reference_date_3(Idx)
61940       ,p_reference_date_4         => l_array_reference_date_4(Idx)
61941       ,p_event_created_by         => l_array_event_created_by(Idx)
61942       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
61943        --
61944 END IF;
61945 
61946 
61947 
61948 --
61949 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
61950 
61951 l_acct_reversal_source := SUBSTR(NULL, 1,30);
61952 
61953 IF l_continue_with_lines THEN
61954    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
61955       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
61956 
61957       xla_accounting_err_pkg.build_message
61958          (p_appli_s_name            => 'XLA'
61959          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
61960          ,p_token_1                 => 'LINE_NUMBER'
61961          ,p_value_1                 => l_array_extract_line_num(Idx)
61962          ,p_token_2                 => 'PRODUCT_NAME'
61963          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
61964          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
61965          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
61966          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
61967 
61968    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
61969       --
61970       -- following sets the accounting attributes needed to reverse
61971       -- accounting for a distributeion
61972       --
61973 
61974       --
61975       -- 5217187
61976       --
61977       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
61978       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
61979                                        g_array_event(l_event_id).array_value_num('header_index'));
61980       --
61981       --
61982 
61983       -- No reversal code generated
61984 
61985       xla_ae_lines_pkg.SetAcctReversalAttrs
61986          (p_event_id             => l_event_id
61987          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
61988          ,p_calculate_acctd_flag => l_calculate_acctd_flag
61989          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
61990    END IF;
61991 
61992    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
61993        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
61994 
61995 --
61996 AcctLineType_45 (
61997  p_application_id  => p_application_id
61998  ,p_event_id     => l_event_id
61999  ,p_calculate_acctd_flag => l_calculate_acctd_flag
62000  ,p_calculate_g_l_flag => l_calculate_g_l_flag
62001  ,p_actual_flag => l_actual_flag
62002  ,p_balance_type_code => l_balance_type_code
62003  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
62004  
62005  , p_source_4 => l_array_source_4(Idx)
62006  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
62007  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
62008  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
62009  , p_source_26 => l_array_source_26(Idx)
62010  , p_source_27 => l_array_source_27(Idx)
62011  , p_source_28 => l_array_source_28(Idx)
62012  , p_source_29 => l_array_source_29(Idx)
62013  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
62014  , p_source_31 => l_array_source_31(Idx)
62015  , p_source_32 => l_array_source_32(Idx)
62016  , p_source_33 => l_array_source_33(Idx)
62017  , p_source_34 => l_array_source_34(Idx)
62018  , p_source_48 => l_array_source_48(Idx)
62019  );
62020 If(l_balance_type_code = 'A') THEN
62021   l_actual_gain_loss_ref := l_gain_or_loss_ref;
62022 END IF;
62023 
62024 --
62025 
62026 
62027 --
62028 AcctLineType_46 (
62029  p_application_id  => p_application_id
62030  ,p_event_id     => l_event_id
62031  ,p_calculate_acctd_flag => l_calculate_acctd_flag
62032  ,p_calculate_g_l_flag => l_calculate_g_l_flag
62033  ,p_actual_flag => l_actual_flag
62034  ,p_balance_type_code => l_balance_type_code
62035  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
62036  
62037  , p_source_4 => l_array_source_4(Idx)
62038  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
62039  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
62040  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
62041  , p_source_26 => l_array_source_26(Idx)
62042  , p_source_27 => l_array_source_27(Idx)
62043  , p_source_28 => l_array_source_28(Idx)
62044  , p_source_29 => l_array_source_29(Idx)
62045  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
62046  , p_source_31 => l_array_source_31(Idx)
62047  , p_source_32 => l_array_source_32(Idx)
62048  , p_source_33 => l_array_source_33(Idx)
62049  , p_source_34 => l_array_source_34(Idx)
62050  , p_source_48 => l_array_source_48(Idx)
62051  );
62052 If(l_balance_type_code = 'A') THEN
62053   l_actual_gain_loss_ref := l_gain_or_loss_ref;
62054 END IF;
62055 
62056 --
62057 
62058 
62062  ,p_event_id     => l_event_id
62059 --
62060 AcctLineType_47 (
62061  p_application_id  => p_application_id
62063  ,p_calculate_acctd_flag => l_calculate_acctd_flag
62064  ,p_calculate_g_l_flag => l_calculate_g_l_flag
62065  ,p_actual_flag => l_actual_flag
62066  ,p_balance_type_code => l_balance_type_code
62067  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
62068  
62069  , p_source_4 => l_array_source_4(Idx)
62070  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
62071  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
62072  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
62073  , p_source_26 => l_array_source_26(Idx)
62074  , p_source_27 => l_array_source_27(Idx)
62075  , p_source_28 => l_array_source_28(Idx)
62076  , p_source_29 => l_array_source_29(Idx)
62077  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
62078  , p_source_31 => l_array_source_31(Idx)
62079  , p_source_32 => l_array_source_32(Idx)
62080  , p_source_33 => l_array_source_33(Idx)
62081  , p_source_34 => l_array_source_34(Idx)
62082  , p_source_48 => l_array_source_48(Idx)
62083  , p_source_49 => l_array_source_49(Idx)
62084  );
62085 If(l_balance_type_code = 'A') THEN
62086   l_actual_gain_loss_ref := l_gain_or_loss_ref;
62087 END IF;
62088 
62089 --
62090 
62091 
62092 --
62093 AcctLineType_48 (
62094  p_application_id  => p_application_id
62095  ,p_event_id     => l_event_id
62096  ,p_calculate_acctd_flag => l_calculate_acctd_flag
62097  ,p_calculate_g_l_flag => l_calculate_g_l_flag
62098  ,p_actual_flag => l_actual_flag
62099  ,p_balance_type_code => l_balance_type_code
62100  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
62101  
62102  , p_source_4 => l_array_source_4(Idx)
62103  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
62104  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
62105  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
62106  , p_source_26 => l_array_source_26(Idx)
62107  , p_source_27 => l_array_source_27(Idx)
62108  , p_source_28 => l_array_source_28(Idx)
62109  , p_source_29 => l_array_source_29(Idx)
62110  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
62111  , p_source_31 => l_array_source_31(Idx)
62112  , p_source_32 => l_array_source_32(Idx)
62113  , p_source_33 => l_array_source_33(Idx)
62114  , p_source_34 => l_array_source_34(Idx)
62115  , p_source_48 => l_array_source_48(Idx)
62116  );
62117 If(l_balance_type_code = 'A') THEN
62118   l_actual_gain_loss_ref := l_gain_or_loss_ref;
62119 END IF;
62120 
62121 --
62122 
62123 
62124 --
62125 AcctLineType_49 (
62126  p_application_id  => p_application_id
62127  ,p_event_id     => l_event_id
62128  ,p_calculate_acctd_flag => l_calculate_acctd_flag
62129  ,p_calculate_g_l_flag => l_calculate_g_l_flag
62130  ,p_actual_flag => l_actual_flag
62131  ,p_balance_type_code => l_balance_type_code
62132  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
62133  
62134  , p_source_4 => l_array_source_4(Idx)
62135  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
62136  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
62137  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
62138  , p_source_26 => l_array_source_26(Idx)
62139  , p_source_27 => l_array_source_27(Idx)
62140  , p_source_28 => l_array_source_28(Idx)
62141  , p_source_29 => l_array_source_29(Idx)
62142  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
62143  , p_source_31 => l_array_source_31(Idx)
62144  , p_source_32 => l_array_source_32(Idx)
62145  , p_source_33 => l_array_source_33(Idx)
62146  , p_source_34 => l_array_source_34(Idx)
62147  , p_source_48 => l_array_source_48(Idx)
62148  );
62149 If(l_balance_type_code = 'A') THEN
62150   l_actual_gain_loss_ref := l_gain_or_loss_ref;
62151 END IF;
62152 
62153 --
62154 
62155 
62156 --
62157 AcctLineType_50 (
62158  p_application_id  => p_application_id
62159  ,p_event_id     => l_event_id
62160  ,p_calculate_acctd_flag => l_calculate_acctd_flag
62161  ,p_calculate_g_l_flag => l_calculate_g_l_flag
62162  ,p_actual_flag => l_actual_flag
62163  ,p_balance_type_code => l_balance_type_code
62164  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
62165  
62166  , p_source_4 => l_array_source_4(Idx)
62167  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
62168  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
62169  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
62170  , p_source_26 => l_array_source_26(Idx)
62171  , p_source_27 => l_array_source_27(Idx)
62172  , p_source_28 => l_array_source_28(Idx)
62173  , p_source_29 => l_array_source_29(Idx)
62174  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
62175  , p_source_31 => l_array_source_31(Idx)
62176  , p_source_32 => l_array_source_32(Idx)
62177  , p_source_33 => l_array_source_33(Idx)
62178  , p_source_34 => l_array_source_34(Idx)
62179  , p_source_48 => l_array_source_48(Idx)
62180  , p_source_49 => l_array_source_49(Idx)
62181  );
62182 If(l_balance_type_code = 'A') THEN
62183   l_actual_gain_loss_ref := l_gain_or_loss_ref;
62184 END IF;
62185 
62186 --
62187 
62188 
62189 --
62190 AcctLineType_51 (
62191  p_application_id  => p_application_id
62192  ,p_event_id     => l_event_id
62193  ,p_calculate_acctd_flag => l_calculate_acctd_flag
62194  ,p_calculate_g_l_flag => l_calculate_g_l_flag
62195  ,p_actual_flag => l_actual_flag
62196  ,p_balance_type_code => l_balance_type_code
62197  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
62198  
62202  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
62199  , p_source_4 => l_array_source_4(Idx)
62200  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
62201  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
62203  , p_source_26 => l_array_source_26(Idx)
62204  , p_source_27 => l_array_source_27(Idx)
62205  , p_source_28 => l_array_source_28(Idx)
62206  , p_source_29 => l_array_source_29(Idx)
62207  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
62208  , p_source_31 => l_array_source_31(Idx)
62209  , p_source_32 => l_array_source_32(Idx)
62210  , p_source_33 => l_array_source_33(Idx)
62211  , p_source_34 => l_array_source_34(Idx)
62212  , p_source_48 => l_array_source_48(Idx)
62213  , p_source_49 => l_array_source_49(Idx)
62214  );
62215 If(l_balance_type_code = 'A') THEN
62216   l_actual_gain_loss_ref := l_gain_or_loss_ref;
62217 END IF;
62218 
62219 --
62220 
62221 
62222 --
62223 AcctLineType_55 (
62224  p_application_id  => p_application_id
62225  ,p_event_id     => l_event_id
62226  ,p_calculate_acctd_flag => l_calculate_acctd_flag
62227  ,p_calculate_g_l_flag => l_calculate_g_l_flag
62228  ,p_actual_flag => l_actual_flag
62229  ,p_balance_type_code => l_balance_type_code
62230  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
62231  
62232  , p_source_4 => l_array_source_4(Idx)
62233  , p_source_9 => g_array_event(l_event_id).array_value_num('source_9')
62234  , p_source_23 => g_array_event(l_event_id).array_value_num('source_23')
62235  , p_source_24 => g_array_event(l_event_id).array_value_num('source_24')
62236  , p_source_25 => g_array_event(l_event_id).array_value_char('source_25')
62237  , p_source_26 => l_array_source_26(Idx)
62238  , p_source_27 => l_array_source_27(Idx)
62239  , p_source_28 => l_array_source_28(Idx)
62240  , p_source_29 => l_array_source_29(Idx)
62241  , p_source_30 => g_array_event(l_event_id).array_value_char('source_30')
62242  , p_source_31 => l_array_source_31(Idx)
62243  , p_source_32 => l_array_source_32(Idx)
62244  , p_source_33 => l_array_source_33(Idx)
62245  , p_source_34 => l_array_source_34(Idx)
62246  , p_source_48 => l_array_source_48(Idx)
62247  , p_source_51 => g_array_event(l_event_id).array_value_num('source_51')
62248  );
62249 If(l_balance_type_code = 'A') THEN
62250   l_actual_gain_loss_ref := l_gain_or_loss_ref;
62251 END IF;
62252 
62253 --
62254 
62255       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
62256       -- or secondary ledger that has different currency with primary
62257       -- or alc that is calculated by sla
62258       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
62259             (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'))
62260 
62261 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
62262 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
62263           AND (l_actual_flag = 'A')) THEN
62264         XLA_AE_LINES_PKG.CreateGainOrLossLines(
62265           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
62266          ,p_application_id   => p_application_id
62267          ,p_amb_context_code => 'DEFAULT'
62268          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
62269          ,p_event_class_code => C_EVENT_CLASS_CODE
62270          ,p_event_type_code  => C_EVENT_TYPE_CODE
62271          
62272          ,p_gain_ccid        => -1
62273          ,p_loss_ccid        => -1
62274 
62275          ,p_actual_flag      => l_actual_flag
62276          ,p_enc_flag         => null
62277          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
62278          ,p_enc_g_l_ref      => null
62279          );
62280       END IF;
62281    END IF;
62282 END IF;
62283 
62284    ELSE
62285       --
62286       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
62287       --
62288       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
62289          trace
62290             (p_msg      => 'Trancaction revesal option is Y'
62291             ,p_level    => C_LEVEL_STATEMENT
62292             ,p_module   => l_log_module);
62293       END IF;
62294    END IF;
62295 
62296 END LOOP;
62297 l_result := XLA_AE_LINES_PKG.InsertLines ;
62298 end loop;
62299 close line_cur;
62300 
62301 
62302 --
62303 -- insert headers into xla_ae_headers_gt table
62304 --
62305 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
62306 
62307 -- insert into errors table here.
62308 
62309 END LOOP;
62310 
62311 --
62312 -- 4865292
62313 --
62314 -- Compare g_hdr_extract_count with event count in
62315 -- CreateHeadersAndLines.
62316 --
62317 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
62318 
62322                     || g_hdr_extract_count
62319 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
62320    trace (p_msg     => '# rows extracted from header extract objects '
62321                     || ' (running total): '
62323          ,p_level   => C_LEVEL_STATEMENT
62324          ,p_module  => l_log_module);
62325 END IF;
62326 
62327 CLOSE header_cur;
62328 --
62329 
62330 --
62331 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
62332    trace
62333       (p_msg      => 'END of EventClass_108'
62334       ,p_level    => C_LEVEL_PROCEDURE
62335       ,p_module   => l_log_module);
62336 END IF;
62337 --
62338 RETURN l_result;
62339 EXCEPTION
62340 WHEN xla_exceptions_pkg.application_exception THEN
62341    
62342 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
62343 
62344    
62345 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
62346 
62347    RAISE;
62348 
62349 WHEN NO_DATA_FOUND THEN
62350 
62351 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
62352 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
62353 
62354 FOR header_record IN header_cur
62355 LOOP
62356     l_array_header_events(header_record.event_id) := header_record.event_id;
62357 END LOOP;
62358 
62359 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
62360 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
62361 
62362 fnd_file.put_line(fnd_file.LOG, '                    ');
62363 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
62364 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
62365 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
62366 
62367 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
62368 LOOP
62369 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
62370 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
62371         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
62372 	END IF;
62373 END LOOP;
62374 
62375 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
62376 fnd_file.put_line(fnd_file.LOG, '                    ');
62377 
62378 
62379 xla_exceptions_pkg.raise_message
62380       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_108');
62381 
62382 
62383 WHEN OTHERS THEN
62384    xla_exceptions_pkg.raise_message
62385       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_108');
62386 END EventClass_108;
62387 --
62388 
62389 ---------------------------------------
62390 --
62391 -- PRIVATE PROCEDURE
62392 --         insert_sources_109
62393 --
62394 ----------------------------------------
62395 --
62396 PROCEDURE insert_sources_109(
62397                                 p_target_ledger_id       IN NUMBER
62398                               , p_language               IN VARCHAR2
62402                          )
62399                               , p_sla_ledger_id          IN NUMBER
62400                               , p_pad_start_date         IN DATE
62401                               , p_pad_end_date           IN DATE
62403 IS
62404 
62405 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'MISC_RECEIPT_ALL';
62406 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'MISC_RECEIPT';
62407 p_apps_owner                   VARCHAR2(30);
62408 l_log_module                   VARCHAR2(240);
62409 BEGIN
62410 IF g_log_enabled THEN
62411       l_log_module := C_DEFAULT_MODULE||'.insert_sources_109';
62412 END IF;
62413 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
62414 
62415       trace
62416          (p_msg      => 'BEGIN of insert_sources_109'
62417          ,p_level    => C_LEVEL_PROCEDURE
62418          ,p_module   => l_log_module);
62419 
62420 END IF;
62421 
62422 -- select APPS owner
62423 SELECT oracle_username
62424   INTO p_apps_owner
62425   FROM fnd_oracle_userid
62426  WHERE read_only_flag = 'U'
62427 ;
62428 
62429 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
62430       trace
62431          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
62432                         ' - p_language = '||p_language||
62433                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
62434                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
62435                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
62436                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
62437          ,p_level    => C_LEVEL_STATEMENT
62438          ,p_module   => l_log_module);
62439 END IF;
62440 
62441 
62442 --
62443 INSERT INTO xla_diag_sources --hdr2
62444 (
62445         event_id
62446       , ledger_id
62447       , sla_ledger_id
62448       , description_language
62449       , object_name
62450       , object_type_code
62451       , line_number
62452       , source_application_id
62453       , source_type_code
62454       , source_code
62455       , source_value
62456       , source_meaning
62457       , created_by
62458       , creation_date
62459       , last_update_date
62460       , last_updated_by
62461       , last_update_login
62462       , program_update_date
62463       , program_application_id
62464       , program_id
62465       , request_id
62466 )
62467 SELECT
62468         event_id
62469       , p_target_ledger_id
62470       , p_sla_ledger_id
62471       , p_language
62472       , object_name
62473       , object_type_code
62474       , line_number
62475       , source_application_id
62476       , source_type_code
62477       , source_code
62478       , SUBSTR(source_value ,1,1996)
62479       , SUBSTR(source_meaning ,1,200)
62480       , xla_environment_pkg.g_Usr_Id
62481       , TRUNC(SYSDATE)
62482       , TRUNC(SYSDATE)
62483       , xla_environment_pkg.g_Usr_Id
62484       , xla_environment_pkg.g_Login_Id
62485       , TRUNC(SYSDATE)
62486       , xla_environment_pkg.g_Prog_Appl_Id
62487       , xla_environment_pkg.g_Prog_Id
62488       , xla_environment_pkg.g_Req_Id
62489   FROM (
62490        SELECT xet.event_id                  event_id
62491             , 0                          line_number
62492             , CASE r
62493                WHEN 1 THEN 'AR_REMIT_BANK_ACCT_H_V' 
62494                 WHEN 2 THEN 'AR_REMIT_BANK_ACCT_H_V' 
62495                 WHEN 3 THEN 'AR_REMIT_BANK_ACCT_H_V' 
62496                 WHEN 4 THEN 'AR_REMIT_BANK_ACCT_H_V' 
62500                 WHEN 8 THEN 'AR_CASH_RECEIPTS_H_V' 
62497                 WHEN 5 THEN 'AR_RCT_METHOD_H_V' 
62498                 WHEN 6 THEN 'AR_RCT_METHOD_H_V' 
62499                 WHEN 7 THEN 'AR_CASH_RECEIPTS_H_V' 
62501                 WHEN 9 THEN 'AR_CASH_RECEIPTS_H_V' 
62502                 WHEN 10 THEN 'AR_CASH_RECEIPTS_H_V' 
62503                 
62504                ELSE null
62508                 WHEN 2 THEN 'HEADER' 
62505               END                           object_name
62506             , CASE r
62507                 WHEN 1 THEN 'HEADER' 
62509                 WHEN 3 THEN 'HEADER' 
62510                 WHEN 4 THEN 'HEADER' 
62511                 WHEN 5 THEN 'HEADER' 
62512                 WHEN 6 THEN 'HEADER' 
62513                 WHEN 7 THEN 'HEADER' 
62514                 WHEN 8 THEN 'HEADER' 
62515                 WHEN 9 THEN 'HEADER' 
62516                 WHEN 10 THEN 'HEADER' 
62517                 
62518                 ELSE null
62519               END                           object_type_code
62520             , CASE r
62521                 WHEN 1 THEN '222' 
62522                 WHEN 2 THEN '222' 
62523                 WHEN 3 THEN '222' 
62524                 WHEN 4 THEN '222' 
62525                 WHEN 5 THEN '222' 
62526                 WHEN 6 THEN '222' 
62527                 WHEN 7 THEN '222' 
62528                 WHEN 8 THEN '222' 
62529                 WHEN 9 THEN '222' 
62530                 WHEN 10 THEN '222' 
62531                 
62532                 ELSE null
62533               END                           source_application_id
62534             , 'S'             source_type_code
62535             , CASE r
62536                 WHEN 1 THEN 'RMT_BNK_BANK_CHARGES_CCID' 
62537                 WHEN 2 THEN 'RMT_BNK_CASH_CCID' 
62538                 WHEN 3 THEN 'RMT_BNK_CONFIRMATION_CCID' 
62539                 WHEN 4 THEN 'RMT_BNK_REMITTANCE_CCID' 
62540                 WHEN 5 THEN 'RCT_CLASS_REMIT_FLAG' 
62541                 WHEN 6 THEN 'RCT_CLASS_CONFIRM_FLAG' 
62542                 WHEN 7 THEN 'RCT_DOC_SEQUENCE_CATEGORY' 
62543                 WHEN 8 THEN 'RCT_DOC_SEQUENCE_ID' 
62544                 WHEN 9 THEN 'RCT_DOC_SEQUENCE_VALUE' 
62545                 WHEN 10 THEN 'RCT_TRX_ACCT_REVERSAL' 
62546                 
62547                 ELSE null
62548               END                           source_code
62549             , CASE r
62550                 WHEN 1 THEN TO_CHAR(h5.RMT_BNK_BANK_CHARGES_CCID)
62551                 WHEN 2 THEN TO_CHAR(h5.RMT_BNK_CASH_CCID)
62552                 WHEN 3 THEN TO_CHAR(h5.RMT_BNK_CONFIRMATION_CCID)
62553                 WHEN 4 THEN TO_CHAR(h5.RMT_BNK_REMITTANCE_CCID)
62554                 WHEN 5 THEN TO_CHAR(h4.RCT_CLASS_REMIT_FLAG)
62555                 WHEN 6 THEN TO_CHAR(h4.RCT_CLASS_CONFIRM_FLAG)
62556                 WHEN 7 THEN TO_CHAR(h1.RCT_DOC_SEQUENCE_CATEGORY)
62557                 WHEN 8 THEN TO_CHAR(h1.RCT_DOC_SEQUENCE_ID)
62558                 WHEN 9 THEN TO_CHAR(h1.RCT_DOC_SEQUENCE_VALUE)
62559                 WHEN 10 THEN TO_CHAR(h1.RCT_TRX_ACCT_REVERSAL)
62560                 
62561                 ELSE null
62562               END                           source_value
62563             , null              source_meaning
62564          FROM xla_events_gt     xet  
62565       , AR_CASH_RECEIPTS_H_V  h1
62566       , AR_RCT_METHOD_H_V  h4
62567       , AR_REMIT_BANK_ACCT_H_V  h5
62568              ,(select rownum r from all_objects where rownum <= 10 and owner = p_apps_owner)
62569          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
62570            AND xet.event_class_code = C_EVENT_CLASS_CODE
62571             
62572 )
62573 ;
62574 --
62575 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
62576 
62577       trace
62578          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
62579          ,p_level    => C_LEVEL_STATEMENT
62580          ,p_module   => l_log_module);
62581 
62582 END IF;
62583 --
62584 
62585 
62586 
62587 --
62588 INSERT INTO xla_diag_sources  --line2
62589 (
62590         event_id
62591       , ledger_id
62592       , sla_ledger_id
62593       , description_language
62594       , object_name
62595       , object_type_code
62596       , line_number
62597       , source_application_id
62598       , source_type_code
62599       , source_code
62600       , source_value
62601       , source_meaning
62602       , created_by
62603       , creation_date
62604       , last_update_date
62605       , last_updated_by
62606       , last_update_login
62607       , program_update_date
62608       , program_application_id
62609       , program_id
62610       , request_id
62611 )
62612 SELECT  event_id
62613       , p_target_ledger_id
62614       , p_sla_ledger_id
62615       , p_language
62616       , object_name
62617       , object_type_code
62618       , line_number
62619       , source_application_id
62620       , source_type_code
62621       , source_code
62622       , SUBSTR(source_value,1,1996)
62623       , SUBSTR(source_meaning ,1,200)
62624       , xla_environment_pkg.g_Usr_Id
62625       , TRUNC(SYSDATE)
62626       , TRUNC(SYSDATE)
62627       , xla_environment_pkg.g_Usr_Id
62628       , xla_environment_pkg.g_Login_Id
62629       , TRUNC(SYSDATE)
62630       , xla_environment_pkg.g_Prog_Appl_Id
62631       , xla_environment_pkg.g_Prog_Id
62632       , xla_environment_pkg.g_Req_Id
62633   FROM (
62634        SELECT xet.event_id                  event_id
62635             , l3.line_number                 line_number
62636             , CASE r
62637                WHEN 1 THEN 'AR_DISTRIBUTIONS_L_V' 
62638                 WHEN 2 THEN 'AR_DISTRIBUTIONS_L_V' 
62639                 WHEN 3 THEN 'AR_DISTRIBUTIONS_L_V' 
62640                 WHEN 4 THEN 'AR_DISTRIBUTIONS_L_V' 
62641                 WHEN 5 THEN 'AR_DISTRIBUTIONS_L_V' 
62642                 WHEN 6 THEN 'AR_DISTRIBUTIONS_L_V' 
62643                 WHEN 7 THEN 'AR_DISTRIBUTIONS_BASE_V' 
62644                 WHEN 8 THEN 'AR_DISTRIBUTIONS_BASE_V' 
62648                 
62645                 WHEN 9 THEN 'AR_DISTRIBUTIONS_BASE_V' 
62646                 WHEN 10 THEN 'AR_DISTRIBUTIONS_L_V' 
62647                 WHEN 11 THEN 'AR_DISTRIBUTIONS_BASE_V' 
62649                ELSE null
62650               END                           object_name
62651             , CASE r
62652                 WHEN 1 THEN 'LINE' 
62653                 WHEN 2 THEN 'LINE' 
62654                 WHEN 3 THEN 'LINE' 
62655                 WHEN 4 THEN 'LINE' 
62656                 WHEN 5 THEN 'LINE' 
62657                 WHEN 6 THEN 'LINE' 
62658                 WHEN 7 THEN 'LINE' 
62659                 WHEN 8 THEN 'LINE' 
62660                 WHEN 9 THEN 'LINE' 
62661                 WHEN 10 THEN 'LINE' 
62662                 WHEN 11 THEN 'LINE' 
62663                 
62664                 ELSE null
62665               END                           object_type_code
62666             , CASE r
62667                 WHEN 1 THEN '222' 
62668                 WHEN 2 THEN '222' 
62669                 WHEN 3 THEN '222' 
62670                 WHEN 4 THEN '222' 
62671                 WHEN 5 THEN '222' 
62672                 WHEN 6 THEN '222' 
62673                 WHEN 7 THEN '222' 
62674                 WHEN 8 THEN '222' 
62675                 WHEN 9 THEN '222' 
62676                 WHEN 10 THEN '222' 
62677                 WHEN 11 THEN '222' 
62678                 
62679                 ELSE null
62680               END                           source_application_id
62681             , 'S'             source_type_code
62682             , CASE r
62683                 WHEN 1 THEN 'DIST_CODE_COMBINATION_ID' 
62684                 WHEN 2 THEN 'DIST_SOURCE_TYPE' 
62685                 WHEN 3 THEN 'DIST_LINE_ID' 
62686                 WHEN 4 THEN 'DISTRIBUTION_TYPE' 
62687                 WHEN 5 THEN 'DIST_ENT_AMT' 
62688                 WHEN 6 THEN 'DIST_CURRENCY_CODE' 
62689                 WHEN 7 THEN 'DIST_CUR_CONVERSION_RATE' 
62690                 WHEN 8 THEN 'DIST_CUR_CONVERSION_TYPE' 
62691                 WHEN 9 THEN 'DIST_TO_ACCTD_AMT' 
62692                 WHEN 10 THEN 'DIST_MFAR_ADDITIONAL_ENTRY' 
62693                 WHEN 11 THEN 'DIST_TO_CUR_CONVERSION_DATE' 
62694                 
62695                 ELSE null
62696               END                           source_code
62697             , CASE r
62698                 WHEN 1 THEN TO_CHAR(l3.DIST_CODE_COMBINATION_ID)
62699                 WHEN 2 THEN TO_CHAR(l3.DIST_SOURCE_TYPE)
62700                 WHEN 3 THEN TO_CHAR(l3.DIST_LINE_ID)
62701                 WHEN 4 THEN TO_CHAR(l3.DISTRIBUTION_TYPE)
62702                 WHEN 5 THEN TO_CHAR(l3.DIST_ENT_AMT)
62703                 WHEN 6 THEN TO_CHAR(l3.DIST_CURRENCY_CODE)
62704                 WHEN 7 THEN TO_CHAR(l2.DIST_CUR_CONVERSION_RATE)
62705                 WHEN 8 THEN TO_CHAR(l2.DIST_CUR_CONVERSION_TYPE)
62706                 WHEN 9 THEN TO_CHAR(l2.DIST_TO_ACCTD_AMT)
62707                 WHEN 10 THEN TO_CHAR(l3.DIST_MFAR_ADDITIONAL_ENTRY)
62708                 WHEN 11 THEN TO_CHAR(l2.DIST_TO_CUR_CONVERSION_DATE)
62709                 
62710                 ELSE null
62711               END                           source_value
62712             , null              source_meaning
62713          FROM  xla_events_gt     xet  
62714         , AR_DISTRIBUTIONS_BASE_V  l2
62715         , AR_DISTRIBUTIONS_L_V  l3
62716             , (select rownum r from all_objects where rownum <= 11 and owner = p_apps_owner)
62717         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
62718           AND xet.event_class_code = C_EVENT_CLASS_CODE
62719             AND l2.event_id          = xet.event_id
62720   AND l3.event_id    = l2.event_id
62721   AND l3.line_number = l2.line_number
62722 
62723 )
62724 ;
62725 --
62726 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
62727 
62728       trace
62729          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
62730          ,p_level    => C_LEVEL_STATEMENT
62731          ,p_module   => l_log_module);
62732 
62733 END IF;
62734 
62735 
62736 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
62737       trace
62738          (p_msg      => 'END of insert_sources_109'
62739          ,p_level    => C_LEVEL_PROCEDURE
62740          ,p_module   => l_log_module);
62741 END IF;
62742 EXCEPTION
62743   WHEN xla_exceptions_pkg.application_exception THEN
62744       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
62745             trace
62746                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
62747                ,p_level    => C_LEVEL_EXCEPTION
62748                ,p_module   => l_log_module);
62749       END IF;
62750       RAISE;
62751   WHEN OTHERS THEN
62752       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
62753             trace
62754                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
62755                ,p_level    => C_LEVEL_EXCEPTION
62756                ,p_module   => l_log_module);
62757        END IF;
62758        xla_exceptions_pkg.raise_message
62759            (p_location => 'XLA_00222_AAD_S_000008_PKG.insert_sources_109');
62760 END insert_sources_109;
62761 --
62762 
62763 ---------------------------------------
62764 --
62765 -- PRIVATE FUNCTION
62766 --         EventClass_109
62767 --
62768 ----------------------------------------
62769 --
62770 FUNCTION EventClass_109
62771        (p_application_id         IN NUMBER
62772        ,p_base_ledger_id         IN NUMBER
62773        ,p_target_ledger_id       IN NUMBER
62774        ,p_language               IN VARCHAR2
62775        ,p_currency_code          IN VARCHAR2
62776        ,p_sla_ledger_id          IN NUMBER
62777        ,p_pad_start_date         IN DATE
62778        ,p_pad_end_date           IN DATE
62782 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'MISC_RECEIPT_ALL';
62779        ,p_primary_ledger_id      IN NUMBER)
62780 RETURN BOOLEAN IS
62781 --
62783 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'MISC_RECEIPT';
62784 
62785 l_calculate_acctd_flag   VARCHAR2(1) :='N';
62786 l_calculate_g_l_flag     VARCHAR2(1) :='N';
62787 --
62788 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
62789 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
62790 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
62791 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
62792 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
62793 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
62794 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
62795 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
62796 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
62797 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
62798 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
62799 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
62800 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
62801 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
62802 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
62803 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
62804 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
62805 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
62806 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
62807 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
62808 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
62809 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
62810 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
62811 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
62812 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
62813 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
62814 
62815 l_event_id                             NUMBER;
62816 l_previous_event_id                    NUMBER;
62817 l_first_event_id                       NUMBER;
62818 l_last_event_id                        NUMBER;
62819 
62820 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
62821 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
62822 --
62823 --
62824 l_result                    BOOLEAN := TRUE;
62825 l_rows                      NUMBER  := 1000;
62826 l_event_type_name           VARCHAR2(80) := 'All';
62827 l_event_class_name          VARCHAR2(80) := 'Miscellaneous Receipt';
62828 l_description               VARCHAR2(4000);
62829 l_transaction_reversal      NUMBER;
62830 l_ae_header_id              NUMBER;
62831 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
62832 l_log_module                VARCHAR2(240);
62833 --
62834 l_acct_reversal_source      VARCHAR2(30);
62835 l_trx_reversal_source       VARCHAR2(30);
62836 
62837 l_continue_with_lines       BOOLEAN := TRUE;
62838 --
62839 l_acc_rev_gl_date_source    DATE;                      -- 4262811
62840 --
62841 type t_array_event_id is table of number index by binary_integer;
62842 
62843 l_rec_array_event                    t_rec_array_event;
62844 l_null_rec_array_event               t_rec_array_event;
62845 l_array_ae_header_id                 xla_number_array_type;
62846 l_actual_flag                        VARCHAR2(1) := NULL;
62847 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
62848 l_balance_type_code                  VARCHAR2(1) :=NULL;
62849 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
62850 
62851 --
62852 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
62853 --
62854 
62855 TYPE t_array_source_1 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_BANK_CHARGES_CCID%TYPE INDEX BY BINARY_INTEGER;
62856 TYPE t_array_source_6 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_CASH_CCID%TYPE INDEX BY BINARY_INTEGER;
62857 TYPE t_array_source_7 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_CONFIRMATION_CCID%TYPE INDEX BY BINARY_INTEGER;
62858 TYPE t_array_source_8 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_REMITTANCE_CCID%TYPE INDEX BY BINARY_INTEGER;
62859 TYPE t_array_source_54 IS TABLE OF AR_RCT_METHOD_H_V.RCT_CLASS_REMIT_FLAG%TYPE INDEX BY BINARY_INTEGER;
62860 TYPE t_array_source_55 IS TABLE OF AR_RCT_METHOD_H_V.RCT_CLASS_CONFIRM_FLAG%TYPE INDEX BY BINARY_INTEGER;
62861 TYPE t_array_source_78 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
62862 TYPE t_array_source_79 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
62863 TYPE t_array_source_80 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
62864 TYPE t_array_source_81 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_TRX_ACCT_REVERSAL%TYPE INDEX BY BINARY_INTEGER;
62865 
62866 TYPE t_array_source_3 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CODE_COMBINATION_ID%TYPE INDEX BY BINARY_INTEGER;
62867 TYPE t_array_source_13 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_SOURCE_TYPE%TYPE INDEX BY BINARY_INTEGER;
62868 TYPE t_array_source_15 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
62869 TYPE t_array_source_16 IS TABLE OF AR_DISTRIBUTIONS_L_V.DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
62873 TYPE t_array_source_21 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
62870 TYPE t_array_source_17 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_ENT_AMT%TYPE INDEX BY BINARY_INTEGER;
62871 TYPE t_array_source_18 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
62872 TYPE t_array_source_20 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
62874 TYPE t_array_source_22 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
62875 TYPE t_array_source_52 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_MFAR_ADDITIONAL_ENTRY%TYPE INDEX BY BINARY_INTEGER;
62876 TYPE t_array_source_53 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
62877 
62878 l_array_source_1              t_array_source_1;
62879 l_array_source_6              t_array_source_6;
62880 l_array_source_7              t_array_source_7;
62881 l_array_source_8              t_array_source_8;
62882 l_array_source_54              t_array_source_54;
62883 l_array_source_55              t_array_source_55;
62884 l_array_source_78              t_array_source_78;
62885 l_array_source_79              t_array_source_79;
62886 l_array_source_80              t_array_source_80;
62887 l_array_source_81              t_array_source_81;
62888 
62889 l_array_source_3      t_array_source_3;
62890 l_array_source_13      t_array_source_13;
62891 l_array_source_15      t_array_source_15;
62892 l_array_source_16      t_array_source_16;
62893 l_array_source_17      t_array_source_17;
62894 l_array_source_18      t_array_source_18;
62895 l_array_source_20      t_array_source_20;
62896 l_array_source_21      t_array_source_21;
62897 l_array_source_22      t_array_source_22;
62898 l_array_source_52      t_array_source_52;
62899 l_array_source_53      t_array_source_53;
62900 
62901 --
62902 CURSOR header_cur
62903 IS
62904 SELECT /*+ leading(xet) cardinality(xet,1) */
62905 -- Event Class Code: MISC_RECEIPT
62906     xet.entity_id
62907    ,xet.legal_entity_id
62908    ,xet.entity_code
62909    ,xet.transaction_number
62910    ,xet.event_id
62911    ,xet.event_class_code
62912    ,xet.event_type_code
62913    ,xet.event_number
62914    ,xet.event_date
62915    ,xet.transaction_date
62916    ,xet.reference_num_1
62917    ,xet.reference_num_2
62918    ,xet.reference_num_3
62919    ,xet.reference_num_4
62920    ,xet.reference_char_1
62921    ,xet.reference_char_2
62922    ,xet.reference_char_3
62923    ,xet.reference_char_4
62924    ,xet.reference_date_1
62925    ,xet.reference_date_2
62926    ,xet.reference_date_3
62927    ,xet.reference_date_4
62928    ,xet.event_created_by
62929    ,xet.budgetary_control_flag 
62930   , h5.RMT_BNK_BANK_CHARGES_CCID    source_1
62931   , h5.RMT_BNK_CASH_CCID    source_6
62932   , h5.RMT_BNK_CONFIRMATION_CCID    source_7
62933   , h5.RMT_BNK_REMITTANCE_CCID    source_8
62934   , h4.RCT_CLASS_REMIT_FLAG    source_54
62935   , h4.RCT_CLASS_CONFIRM_FLAG    source_55
62936   , h1.RCT_DOC_SEQUENCE_CATEGORY    source_78
62937   , h1.RCT_DOC_SEQUENCE_ID    source_79
62938   , h1.RCT_DOC_SEQUENCE_VALUE    source_80
62939   , h1.RCT_TRX_ACCT_REVERSAL    source_81
62940   FROM xla_events_gt     xet 
62941   , AR_CASH_RECEIPTS_H_V  h1
62942   , AR_RCT_METHOD_H_V  h4
62943   , AR_REMIT_BANK_ACCT_H_V  h5
62944  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
62945    and xet.event_class_code = C_EVENT_CLASS_CODE
62946    and xet.event_status_code <> 'N'   AND h1.event_id (+) = xet.event_id
62947   AND h4.event_id (+) = xet.event_id
62948   AND h5.event_id (+) = xet.event_id
62949 
62950  ORDER BY event_id
62951 ;
62952 
62953 
62954 --
62955 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
62956 IS
62957 SELECT  /*+ leading(xet) cardinality(xet,1) */
62958 -- Event Class Code: MISC_RECEIPT
62959     xet.entity_id
62960    ,xet.legal_entity_id
62961    ,xet.entity_code
62962    ,xet.transaction_number
62963    ,xet.event_id
62964    ,xet.event_class_code
62965    ,xet.event_type_code
62969    ,xet.reference_num_1
62966    ,xet.event_number
62967    ,xet.event_date
62968    ,xet.transaction_date
62970    ,xet.reference_num_2
62971    ,xet.reference_num_3
62972    ,xet.reference_num_4
62973    ,xet.reference_char_1
62974    ,xet.reference_char_2
62975    ,xet.reference_char_3
62976    ,xet.reference_char_4
62977    ,xet.reference_date_1
62978    ,xet.reference_date_2
62979    ,xet.reference_date_3
62980    ,xet.reference_date_4
62981    ,xet.event_created_by
62982    ,xet.budgetary_control_flag
62983  , l2.LINE_NUMBER  
62984   , l3.DIST_CODE_COMBINATION_ID    source_3
62985   , l3.DIST_SOURCE_TYPE    source_13
62986   , l3.DIST_LINE_ID    source_15
62987   , l3.DISTRIBUTION_TYPE    source_16
62988   , l3.DIST_ENT_AMT    source_17
62989   , l3.DIST_CURRENCY_CODE    source_18
62990   , l2.DIST_CUR_CONVERSION_RATE    source_20
62991   , l2.DIST_CUR_CONVERSION_TYPE    source_21
62992   , l2.DIST_TO_ACCTD_AMT    source_22
62993   , l3.DIST_MFAR_ADDITIONAL_ENTRY    source_52
62994   , l2.DIST_TO_CUR_CONVERSION_DATE    source_53
62995   FROM xla_events_gt     xet 
62996   , AR_DISTRIBUTIONS_BASE_V  l2
62997   , AR_DISTRIBUTIONS_L_V  l3
62998  WHERE xet.event_id between x_first_event_id and x_last_event_id
62999    and xet.event_date between p_pad_start_date and p_pad_end_date
63000    and xet.event_class_code = C_EVENT_CLASS_CODE
63001    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
63002   AND l3.event_id    = l2.event_id
63003   AND l3.line_number = l2.line_number
63004 ;
63005 
63006 --
63007 BEGIN
63008 IF g_log_enabled THEN
63009    l_log_module := C_DEFAULT_MODULE||'.EventClass_109';
63010 END IF;
63011 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
63012    trace
63013       (p_msg      => 'BEGIN of EventClass_109'
63014       ,p_level    => C_LEVEL_PROCEDURE
63015       ,p_module   => l_log_module);
63016 END IF;
63017 
63018 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
63019    trace
63020       (p_msg      => 'p_application_id = '||p_application_id||
63021                      ' - p_base_ledger_id = '||p_base_ledger_id||
63022                      ' - p_target_ledger_id  = '||p_target_ledger_id||
63023                      ' - p_language = '||p_language||
63024                      ' - p_currency_code = '||p_currency_code||
63025                      ' - p_sla_ledger_id = '||p_sla_ledger_id
63026       ,p_level    => C_LEVEL_STATEMENT
63027       ,p_module   => l_log_module);
63028 END IF;
63029 --
63030 -- initialze arrays
63031 --
63032 g_array_event.DELETE;
63033 l_rec_array_event := l_null_rec_array_event;
63034 --
63035 --------------------------------------
63036 -- 4262811 Initialze MPA Line Number
63037 --------------------------------------
63038 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
63039 
63040 --
63041 
63042 --
63043 OPEN header_cur;
63044 --
63045 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
63046    trace
63047    (p_msg      => 'SQL - FETCH header_cur'
63048    ,p_level    => C_LEVEL_STATEMENT
63049    ,p_module   => l_log_module);
63050 END IF;
63051 --
63052 LOOP
63053 FETCH header_cur BULK COLLECT INTO
63054         l_array_entity_id
63055       , l_array_legal_entity_id
63056       , l_array_entity_code
63057       , l_array_transaction_num
63058       , l_array_event_id
63059       , l_array_class_code
63060       , l_array_event_type
63061       , l_array_event_number
63062       , l_array_event_date
63063       , l_array_transaction_date
63064       , l_array_reference_num_1
63065       , l_array_reference_num_2
63066       , l_array_reference_num_3
63067       , l_array_reference_num_4
63068       , l_array_reference_char_1
63069       , l_array_reference_char_2
63070       , l_array_reference_char_3
63071       , l_array_reference_char_4
63072       , l_array_reference_date_1
63073       , l_array_reference_date_2
63074       , l_array_reference_date_3
63075       , l_array_reference_date_4
63076       , l_array_event_created_by
63077       , l_array_budgetary_control_flag 
63078       , l_array_source_1
63079       , l_array_source_6
63080       , l_array_source_7
63081       , l_array_source_8
63082       , l_array_source_54
63083       , l_array_source_55
63084       , l_array_source_78
63085       , l_array_source_79
63086       , l_array_source_80
63087       , l_array_source_81
63088       LIMIT l_rows;
63089 --
63090 IF (C_LEVEL_EVENT >= g_log_level) THEN
63091    trace
63092    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
63093    ,p_level    => C_LEVEL_EVENT
63094    ,p_module   => l_log_module);
63095 END IF;
63096 --
63097 EXIT WHEN l_array_entity_id.COUNT = 0;
63098 
63099 -- initialize arrays
63100 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
63101 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
63102 
63103 --
63104 -- Bug 4458708
63105 --
63106 XLA_AE_LINES_PKG.g_LineNumber := 0;
63107 
63108 
63109 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
63110 g_last_hdr_idx := l_array_event_id.LAST;
63111 --
63112 -- loop for the headers. Each iteration is for each header extract row
63113 -- fetched in header cursor
63114 --
63115 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
63116 
63117 --
63121    (p_application_id           => p_application_id
63118 -- set event info as cache for other routines to refer event attributes
63119 --
63120 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
63122    ,p_primary_ledger_id        => p_primary_ledger_id
63123    ,p_base_ledger_id           => p_base_ledger_id
63124    ,p_target_ledger_id         => p_target_ledger_id
63125    ,p_entity_id                => l_array_entity_id(hdr_idx)
63126    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
63127    ,p_entity_code              => l_array_entity_code(hdr_idx)
63128    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
63129    ,p_event_id                 => l_array_event_id(hdr_idx)
63130    ,p_event_class_code         => l_array_class_code(hdr_idx)
63131    ,p_event_type_code          => l_array_event_type(hdr_idx)
63132    ,p_event_number             => l_array_event_number(hdr_idx)
63133    ,p_event_date               => l_array_event_date(hdr_idx)
63134    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
63135    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
63136    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
63137    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
63138    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
63139    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
63140    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
63141    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
63142    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
63143    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
63144    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
63145    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
63146    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
63147    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
63148    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
63149 
63150 --
63151 -- set the status of entry to C_VALID (0)
63152 --
63153 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
63154 
63155 --
63156 -- initialize a row for ae header
63157 --
63158 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
63159 
63160 l_event_id := l_array_event_id(hdr_idx);
63161 
63162 --
63163 -- storing the hdr_idx for event. May be used by line cursor.
63164 --
63165 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
63166 
63167 --
63168 -- store sources from header extract. This can be improved to
63169 -- store only those sources from header extract that may be used in lines
63170 --
63171 
63172 g_array_event(l_event_id).array_value_num('source_1') := l_array_source_1(hdr_idx);
63173 g_array_event(l_event_id).array_value_num('source_6') := l_array_source_6(hdr_idx);
63174 g_array_event(l_event_id).array_value_num('source_7') := l_array_source_7(hdr_idx);
63175 g_array_event(l_event_id).array_value_num('source_8') := l_array_source_8(hdr_idx);
63176 g_array_event(l_event_id).array_value_char('source_54') := l_array_source_54(hdr_idx);
63177 g_array_event(l_event_id).array_value_char('source_55') := l_array_source_55(hdr_idx);
63178 g_array_event(l_event_id).array_value_char('source_78') := l_array_source_78(hdr_idx);
63179 g_array_event(l_event_id).array_value_num('source_79') := l_array_source_79(hdr_idx);
63180 g_array_event(l_event_id).array_value_num('source_80') := l_array_source_80(hdr_idx);
63181 g_array_event(l_event_id).array_value_char('source_81') := l_array_source_81(hdr_idx);
63182 
63183 --
63184 -- initilaize the status of ae headers for diffrent balance types
63185 -- the status is initialised to C_NOT_CREATED (2)
63186 --
63187 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
63188 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
63189 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
63190 
63191 --
63192 -- call api to validate and store accounting attributes for header
63193 --
63194 
63195 ------------------------------------------------------------
63196 -- Accrual Reversal : to get date for Standard Source (NONE)
63197 ------------------------------------------------------------
63198 l_acc_rev_gl_date_source := NULL;
63199 
63200      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
63201       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_78');
63202      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
63203       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_79');
63204      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
63205       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_80');
63206      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
63207       l_rec_acct_attrs.array_date_value(4) := 
63208 xla_ae_sources_pkg.GetSystemSourceDate(
63209    p_source_code           => 'XLA_EVENT_DATE'
63210  , p_source_type_code      => 'Y'
63211  , p_source_application_id =>  602
63212 );
63213      l_rec_acct_attrs.array_acct_attr_code(5)   := 'TRX_ACCT_REVERSAL_OPTION';
63214       l_rec_acct_attrs.array_char_value(5) := g_array_event(l_event_id).array_value_char('source_81');
63215 
63216 
63217 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
63218 
63219 XLA_AE_HEADER_PKG.SetJeCategoryName;
63220 
63221 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
63225 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
63222 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
63223 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
63224 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
63226 
63227 
63228 -- No header level analytical criteria
63229 
63230 --
63231 --accounting attribute enhancement, bug 3612931
63232 --
63233 l_trx_reversal_source := SUBSTR(g_array_event(l_event_id).array_value_char('source_81'), 1,30);
63234 
63235 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
63236    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
63237 
63238    xla_accounting_err_pkg.build_message
63239       (p_appli_s_name            => 'XLA'
63240       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
63241       ,p_token_1                 => 'ACCT_ATTR_NAME'
63242       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
63243       ,p_token_2                 => 'PRODUCT_NAME'
63244       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
63245       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
63246       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
63247       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
63248 
63249 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
63250    --
63251    -- following sets the accounting attributes needed to reverse
63252    -- accounting for a distributeion
63253    --
63254    xla_ae_lines_pkg.SetTrxReversalAttrs
63255       (p_event_id              => l_event_id
63256       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
63257       ,p_trx_reversal_source   => l_trx_reversal_source);
63258 
63259 END IF;
63260 
63261 
63262 ----------------------------------------------------------------
63263 -- 4262811 -  update the header statuses to invalid in need be
63264 ----------------------------------------------------------------
63265 --
63266 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
63267 
63268 
63269   -----------------------------------------------
63270   -- No accrual reversal for the event class/type
63271   -----------------------------------------------
63272 ----------------------------------------------------------------
63273 
63274 --
63275 -- this ends the header loop iteration for one bulk fetch
63276 --
63277 END LOOP;
63278 
63279 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
63280 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
63281 
63282 --
63283 -- insert dummy rows into lines gt table that were created due to
63284 -- transaction reversals
63285 --
63286 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
63287    l_result := XLA_AE_LINES_PKG.InsertLines;
63288 END IF;
63289 
63290 --
63291 -- reset the temp_line_num for each set of events fetched from header
63292 -- cursor rather than doing it for each new event in line cursor
63293 -- Bug 3939231
63294 --
63295 xla_ae_lines_pkg.g_temp_line_num := 0;
63296 
63297 
63298 
63299 --
63300 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
63301 --
63302 --
63303 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
63304 
63305       trace
63306          (p_msg      => 'SQL - FETCH line_cur'
63307          ,p_level    => C_LEVEL_STATEMENT
63308          ,p_module   => l_log_module);
63309 
63310 END IF;
63311 --
63312 --
63313 LOOP
63314   --
63315   FETCH line_cur BULK COLLECT INTO
63316         l_array_entity_id
63317       , l_array_legal_entity_id
63318       , l_array_entity_code
63319       , l_array_transaction_num
63320       , l_array_event_id
63321       , l_array_class_code
63322       , l_array_event_type
63323       , l_array_event_number
63324       , l_array_event_date
63325       , l_array_transaction_date
63326       , l_array_reference_num_1
63327       , l_array_reference_num_2
63328       , l_array_reference_num_3
63329       , l_array_reference_num_4
63330       , l_array_reference_char_1
63331       , l_array_reference_char_2
63332       , l_array_reference_char_3
63333       , l_array_reference_char_4
63334       , l_array_reference_date_1
63335       , l_array_reference_date_2
63336       , l_array_reference_date_3
63337       , l_array_reference_date_4
63338       , l_array_event_created_by
63339       , l_array_budgetary_control_flag
63340       , l_array_extract_line_num 
63341       , l_array_source_3
63342       , l_array_source_13
63343       , l_array_source_15
63344       , l_array_source_16
63345       , l_array_source_17
63346       , l_array_source_18
63347       , l_array_source_20
63348       , l_array_source_21
63349       , l_array_source_22
63350       , l_array_source_52
63351       , l_array_source_53
63352       LIMIT l_rows;
63353 
63354   --
63355   IF (C_LEVEL_EVENT >= g_log_level) THEN
63356             trace
63357                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
63358                ,p_level    => C_LEVEL_EVENT
63359                ,p_module   => l_log_module);
63360   END IF;
63361   --
63362   EXIT WHEN l_array_entity_id.count = 0;
63363 
63364   XLA_AE_LINES_PKG.g_rec_lines := null;
63365 
63366 --
63367 -- Bug 4458708
63371 --
63368 --
63369 XLA_AE_LINES_PKG.g_LineNumber := 0;
63370 --
63372 
63373 FOR Idx IN 1..l_array_event_id.count LOOP
63374    --
63375    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
63376    --
63377    l_event_id := l_array_event_id(idx);  -- 5648433
63378 
63379    --
63380    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
63381    --
63382 
63383    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
63384              (g_array_event(l_event_id).array_value_num('header_index'))
63385          ,'N'
63386          ) <> 'Y'
63387    THEN
63388       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
63389          trace
63390             (p_msg      => 'Trancaction revesal option is not Y '
63391             ,p_level    => C_LEVEL_STATEMENT
63392             ,p_module   => l_log_module);
63393       END IF;
63394 
63395 --
63396 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
63397 --
63398 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
63399 --
63400 -- set event info as cache for other routines to refer event attributes
63401 --
63402 
63403 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
63404    l_previous_event_id := l_event_id;
63405 
63406    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
63407       (p_application_id           => p_application_id
63408       ,p_primary_ledger_id        => p_primary_ledger_id
63409       ,p_base_ledger_id           => p_base_ledger_id
63410       ,p_target_ledger_id         => p_target_ledger_id
63411       ,p_entity_id                => l_array_entity_id(Idx)
63412       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
63413       ,p_entity_code              => l_array_entity_code(Idx)
63414       ,p_transaction_num          => l_array_transaction_num(Idx)
63415       ,p_event_id                 => l_array_event_id(Idx)
63416       ,p_event_class_code         => l_array_class_code(Idx)
63417       ,p_event_type_code          => l_array_event_type(Idx)
63418       ,p_event_number             => l_array_event_number(Idx)
63419       ,p_event_date               => l_array_event_date(Idx)
63420       ,p_transaction_date         => l_array_transaction_date(Idx)
63421       ,p_reference_num_1          => l_array_reference_num_1(Idx)
63422       ,p_reference_num_2          => l_array_reference_num_2(Idx)
63423       ,p_reference_num_3          => l_array_reference_num_3(Idx)
63424       ,p_reference_num_4          => l_array_reference_num_4(Idx)
63425       ,p_reference_char_1         => l_array_reference_char_1(Idx)
63426       ,p_reference_char_2         => l_array_reference_char_2(Idx)
63427       ,p_reference_char_3         => l_array_reference_char_3(Idx)
63428       ,p_reference_char_4         => l_array_reference_char_4(Idx)
63429       ,p_reference_date_1         => l_array_reference_date_1(Idx)
63430       ,p_reference_date_2         => l_array_reference_date_2(Idx)
63431       ,p_reference_date_3         => l_array_reference_date_3(Idx)
63432       ,p_reference_date_4         => l_array_reference_date_4(Idx)
63433       ,p_event_created_by         => l_array_event_created_by(Idx)
63434       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
63435        --
63436 END IF;
63437 
63438 
63439 
63440 --
63441 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
63442 
63443 l_acct_reversal_source := SUBSTR(NULL, 1,30);
63444 
63445 IF l_continue_with_lines THEN
63446    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
63447       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
63448 
63449       xla_accounting_err_pkg.build_message
63450          (p_appli_s_name            => 'XLA'
63451          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
63452          ,p_token_1                 => 'LINE_NUMBER'
63453          ,p_value_1                 => l_array_extract_line_num(Idx)
63454          ,p_token_2                 => 'PRODUCT_NAME'
63455          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
63456          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
63457          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
63458          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
63459 
63460    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
63461       --
63462       -- following sets the accounting attributes needed to reverse
63463       -- accounting for a distributeion
63464       --
63465 
63466       --
63467       -- 5217187
63468       --
63469       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
63470       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
63471                                        g_array_event(l_event_id).array_value_num('header_index'));
63472       --
63473       --
63474 
63475       -- No reversal code generated
63476 
63477       xla_ae_lines_pkg.SetAcctReversalAttrs
63478          (p_event_id             => l_event_id
63479          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
63480          ,p_calculate_acctd_flag => l_calculate_acctd_flag
63481          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
63482    END IF;
63483 
63484    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
63485        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
63486 
63487 --
63488 AcctLineType_56 (
63489  p_application_id  => p_application_id
63490  ,p_event_id     => l_event_id
63491  ,p_calculate_acctd_flag => l_calculate_acctd_flag
63492  ,p_calculate_g_l_flag => l_calculate_g_l_flag
63493  ,p_actual_flag => l_actual_flag
63497  , p_source_1 => g_array_event(l_event_id).array_value_num('source_1')
63494  ,p_balance_type_code => l_balance_type_code
63495  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
63496  
63498  , p_source_6 => g_array_event(l_event_id).array_value_num('source_6')
63499  , p_source_13 => l_array_source_13(Idx)
63500  , p_source_15 => l_array_source_15(Idx)
63501  , p_source_16 => l_array_source_16(Idx)
63502  , p_source_17 => l_array_source_17(Idx)
63503  , p_source_18 => l_array_source_18(Idx)
63504  , p_source_20 => l_array_source_20(Idx)
63505  , p_source_21 => l_array_source_21(Idx)
63506  , p_source_22 => l_array_source_22(Idx)
63507  , p_source_52 => l_array_source_52(Idx)
63508  , p_source_53 => l_array_source_53(Idx)
63509  );
63510 If(l_balance_type_code = 'A') THEN
63511   l_actual_gain_loss_ref := l_gain_or_loss_ref;
63512 END IF;
63513 
63514 --
63515 
63516 
63517 --
63518 AcctLineType_57 (
63519  p_application_id  => p_application_id
63520  ,p_event_id     => l_event_id
63521  ,p_calculate_acctd_flag => l_calculate_acctd_flag
63522  ,p_calculate_g_l_flag => l_calculate_g_l_flag
63523  ,p_actual_flag => l_actual_flag
63524  ,p_balance_type_code => l_balance_type_code
63525  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
63526  
63527  , p_source_3 => l_array_source_3(Idx)
63528  , p_source_6 => g_array_event(l_event_id).array_value_num('source_6')
63529  , p_source_13 => l_array_source_13(Idx)
63530  , p_source_15 => l_array_source_15(Idx)
63531  , p_source_16 => l_array_source_16(Idx)
63532  , p_source_17 => l_array_source_17(Idx)
63533  , p_source_18 => l_array_source_18(Idx)
63534  , p_source_20 => l_array_source_20(Idx)
63535  , p_source_21 => l_array_source_21(Idx)
63536  , p_source_22 => l_array_source_22(Idx)
63537  , p_source_52 => l_array_source_52(Idx)
63538  , p_source_53 => l_array_source_53(Idx)
63539  , p_source_54 => g_array_event(l_event_id).array_value_char('source_54')
63540  , p_source_55 => g_array_event(l_event_id).array_value_char('source_55')
63541  );
63542 If(l_balance_type_code = 'A') THEN
63543   l_actual_gain_loss_ref := l_gain_or_loss_ref;
63544 END IF;
63545 
63546 --
63547 
63548 
63549 --
63550 AcctLineType_58 (
63551  p_application_id  => p_application_id
63552  ,p_event_id     => l_event_id
63553  ,p_calculate_acctd_flag => l_calculate_acctd_flag
63554  ,p_calculate_g_l_flag => l_calculate_g_l_flag
63555  ,p_actual_flag => l_actual_flag
63556  ,p_balance_type_code => l_balance_type_code
63557  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
63558  
63559  , p_source_3 => l_array_source_3(Idx)
63560  , p_source_6 => g_array_event(l_event_id).array_value_num('source_6')
63561  , p_source_13 => l_array_source_13(Idx)
63562  , p_source_15 => l_array_source_15(Idx)
63563  , p_source_16 => l_array_source_16(Idx)
63564  , p_source_17 => l_array_source_17(Idx)
63565  , p_source_18 => l_array_source_18(Idx)
63566  , p_source_20 => l_array_source_20(Idx)
63567  , p_source_21 => l_array_source_21(Idx)
63568  , p_source_22 => l_array_source_22(Idx)
63569  , p_source_52 => l_array_source_52(Idx)
63570  , p_source_53 => l_array_source_53(Idx)
63571  , p_source_54 => g_array_event(l_event_id).array_value_char('source_54')
63572  );
63573 If(l_balance_type_code = 'A') THEN
63574   l_actual_gain_loss_ref := l_gain_or_loss_ref;
63575 END IF;
63576 
63577 --
63578 
63579 
63580 --
63581 AcctLineType_59 (
63582  p_application_id  => p_application_id
63583  ,p_event_id     => l_event_id
63584  ,p_calculate_acctd_flag => l_calculate_acctd_flag
63585  ,p_calculate_g_l_flag => l_calculate_g_l_flag
63586  ,p_actual_flag => l_actual_flag
63587  ,p_balance_type_code => l_balance_type_code
63588  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
63589  
63590  , p_source_3 => l_array_source_3(Idx)
63591  , p_source_7 => g_array_event(l_event_id).array_value_num('source_7')
63592  , p_source_13 => l_array_source_13(Idx)
63593  , p_source_15 => l_array_source_15(Idx)
63594  , p_source_16 => l_array_source_16(Idx)
63595  , p_source_17 => l_array_source_17(Idx)
63596  , p_source_18 => l_array_source_18(Idx)
63597  , p_source_20 => l_array_source_20(Idx)
63598  , p_source_21 => l_array_source_21(Idx)
63599  , p_source_22 => l_array_source_22(Idx)
63600  , p_source_52 => l_array_source_52(Idx)
63601  , p_source_53 => l_array_source_53(Idx)
63602  );
63603 If(l_balance_type_code = 'A') THEN
63604   l_actual_gain_loss_ref := l_gain_or_loss_ref;
63605 END IF;
63606 
63607 --
63608 
63609 
63610 --
63611 AcctLineType_60 (
63612  p_application_id  => p_application_id
63613  ,p_event_id     => l_event_id
63614  ,p_calculate_acctd_flag => l_calculate_acctd_flag
63615  ,p_calculate_g_l_flag => l_calculate_g_l_flag
63616  ,p_actual_flag => l_actual_flag
63617  ,p_balance_type_code => l_balance_type_code
63618  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
63619  
63620  , p_source_3 => l_array_source_3(Idx)
63621  , p_source_8 => g_array_event(l_event_id).array_value_num('source_8')
63622  , p_source_13 => l_array_source_13(Idx)
63623  , p_source_15 => l_array_source_15(Idx)
63624  , p_source_16 => l_array_source_16(Idx)
63625  , p_source_17 => l_array_source_17(Idx)
63626  , p_source_18 => l_array_source_18(Idx)
63627  , p_source_20 => l_array_source_20(Idx)
63628  , p_source_21 => l_array_source_21(Idx)
63629  , p_source_22 => l_array_source_22(Idx)
63630  , p_source_52 => l_array_source_52(Idx)
63631  , p_source_53 => l_array_source_53(Idx)
63632  );
63633 If(l_balance_type_code = 'A') THEN
63634   l_actual_gain_loss_ref := l_gain_or_loss_ref;
63635 END IF;
63636 
63637 --
63638 
63639 
63640 --
63641 AcctLineType_68 (
63645  ,p_calculate_g_l_flag => l_calculate_g_l_flag
63642  p_application_id  => p_application_id
63643  ,p_event_id     => l_event_id
63644  ,p_calculate_acctd_flag => l_calculate_acctd_flag
63646  ,p_actual_flag => l_actual_flag
63647  ,p_balance_type_code => l_balance_type_code
63648  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
63649  
63650  , p_source_3 => l_array_source_3(Idx)
63651  , p_source_13 => l_array_source_13(Idx)
63652  , p_source_15 => l_array_source_15(Idx)
63653  , p_source_16 => l_array_source_16(Idx)
63654  , p_source_17 => l_array_source_17(Idx)
63655  , p_source_18 => l_array_source_18(Idx)
63656  , p_source_20 => l_array_source_20(Idx)
63657  , p_source_21 => l_array_source_21(Idx)
63658  , p_source_22 => l_array_source_22(Idx)
63659  , p_source_52 => l_array_source_52(Idx)
63660  , p_source_53 => l_array_source_53(Idx)
63661  );
63662 If(l_balance_type_code = 'A') THEN
63663   l_actual_gain_loss_ref := l_gain_or_loss_ref;
63664 END IF;
63665 
63666 --
63667 
63668 
63669 --
63670 AcctLineType_69 (
63671  p_application_id  => p_application_id
63672  ,p_event_id     => l_event_id
63673  ,p_calculate_acctd_flag => l_calculate_acctd_flag
63674  ,p_calculate_g_l_flag => l_calculate_g_l_flag
63675  ,p_actual_flag => l_actual_flag
63676  ,p_balance_type_code => l_balance_type_code
63677  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
63678  
63679  , p_source_3 => l_array_source_3(Idx)
63680  , p_source_13 => l_array_source_13(Idx)
63681  , p_source_15 => l_array_source_15(Idx)
63682  , p_source_16 => l_array_source_16(Idx)
63683  , p_source_17 => l_array_source_17(Idx)
63684  , p_source_18 => l_array_source_18(Idx)
63685  , p_source_20 => l_array_source_20(Idx)
63686  , p_source_21 => l_array_source_21(Idx)
63687  , p_source_22 => l_array_source_22(Idx)
63688  , p_source_52 => l_array_source_52(Idx)
63689  , p_source_53 => l_array_source_53(Idx)
63690  );
63691 If(l_balance_type_code = 'A') THEN
63692   l_actual_gain_loss_ref := l_gain_or_loss_ref;
63693 END IF;
63694 
63695 --
63696 
63697 
63698 --
63699 AcctLineType_70 (
63700  p_application_id  => p_application_id
63701  ,p_event_id     => l_event_id
63702  ,p_calculate_acctd_flag => l_calculate_acctd_flag
63703  ,p_calculate_g_l_flag => l_calculate_g_l_flag
63704  ,p_actual_flag => l_actual_flag
63705  ,p_balance_type_code => l_balance_type_code
63706  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
63707  
63708  , p_source_3 => l_array_source_3(Idx)
63709  , p_source_13 => l_array_source_13(Idx)
63710  , p_source_15 => l_array_source_15(Idx)
63711  , p_source_16 => l_array_source_16(Idx)
63712  , p_source_17 => l_array_source_17(Idx)
63713  , p_source_18 => l_array_source_18(Idx)
63714  , p_source_20 => l_array_source_20(Idx)
63715  , p_source_21 => l_array_source_21(Idx)
63716  , p_source_22 => l_array_source_22(Idx)
63717  , p_source_52 => l_array_source_52(Idx)
63718  , p_source_53 => l_array_source_53(Idx)
63719  );
63720 If(l_balance_type_code = 'A') THEN
63721   l_actual_gain_loss_ref := l_gain_or_loss_ref;
63722 END IF;
63723 
63724 --
63725 
63726 
63727 --
63728 AcctLineType_71 (
63729  p_application_id  => p_application_id
63730  ,p_event_id     => l_event_id
63731  ,p_calculate_acctd_flag => l_calculate_acctd_flag
63732  ,p_calculate_g_l_flag => l_calculate_g_l_flag
63733  ,p_actual_flag => l_actual_flag
63734  ,p_balance_type_code => l_balance_type_code
63735  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
63736  
63737  , p_source_3 => l_array_source_3(Idx)
63738  , p_source_13 => l_array_source_13(Idx)
63739  , p_source_15 => l_array_source_15(Idx)
63740  , p_source_16 => l_array_source_16(Idx)
63741  , p_source_17 => l_array_source_17(Idx)
63742  , p_source_18 => l_array_source_18(Idx)
63743  , p_source_20 => l_array_source_20(Idx)
63744  , p_source_21 => l_array_source_21(Idx)
63745  , p_source_22 => l_array_source_22(Idx)
63746  , p_source_52 => l_array_source_52(Idx)
63747  , p_source_53 => l_array_source_53(Idx)
63748  );
63749 If(l_balance_type_code = 'A') THEN
63750   l_actual_gain_loss_ref := l_gain_or_loss_ref;
63751 END IF;
63752 
63753 --
63754 
63755 
63756 --
63757 AcctLineType_72 (
63758  p_application_id  => p_application_id
63759  ,p_event_id     => l_event_id
63760  ,p_calculate_acctd_flag => l_calculate_acctd_flag
63761  ,p_calculate_g_l_flag => l_calculate_g_l_flag
63762  ,p_actual_flag => l_actual_flag
63763  ,p_balance_type_code => l_balance_type_code
63764  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
63765  
63766  , p_source_3 => l_array_source_3(Idx)
63767  , p_source_13 => l_array_source_13(Idx)
63768  , p_source_15 => l_array_source_15(Idx)
63769  , p_source_16 => l_array_source_16(Idx)
63770  , p_source_17 => l_array_source_17(Idx)
63771  , p_source_18 => l_array_source_18(Idx)
63772  , p_source_20 => l_array_source_20(Idx)
63773  , p_source_21 => l_array_source_21(Idx)
63774  , p_source_22 => l_array_source_22(Idx)
63775  , p_source_52 => l_array_source_52(Idx)
63776  , p_source_53 => l_array_source_53(Idx)
63777  );
63778 If(l_balance_type_code = 'A') THEN
63779   l_actual_gain_loss_ref := l_gain_or_loss_ref;
63780 END IF;
63781 
63782 --
63783 
63784       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
63785       -- or secondary ledger that has different currency with primary
63786       -- or alc that is calculated by sla
63787       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
63791 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
63788             (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'))
63789 
63790 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
63792           AND (l_actual_flag = 'A')) THEN
63793         XLA_AE_LINES_PKG.CreateGainOrLossLines(
63794           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
63795          ,p_application_id   => p_application_id
63796          ,p_amb_context_code => 'DEFAULT'
63797          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
63798          ,p_event_class_code => C_EVENT_CLASS_CODE
63799          ,p_event_type_code  => C_EVENT_TYPE_CODE
63800          
63801          ,p_gain_ccid        => -1
63802          ,p_loss_ccid        => -1
63803 
63804          ,p_actual_flag      => l_actual_flag
63805          ,p_enc_flag         => null
63806          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
63807          ,p_enc_g_l_ref      => null
63808          );
63809       END IF;
63810    END IF;
63811 END IF;
63812 
63813    ELSE
63814       --
63815       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
63816       --
63817       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
63818          trace
63819             (p_msg      => 'Trancaction revesal option is Y'
63820             ,p_level    => C_LEVEL_STATEMENT
63821             ,p_module   => l_log_module);
63822       END IF;
63823    END IF;
63824 
63825 END LOOP;
63826 l_result := XLA_AE_LINES_PKG.InsertLines ;
63827 end loop;
63828 close line_cur;
63829 
63830 
63831 --
63832 -- insert headers into xla_ae_headers_gt table
63833 --
63834 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
63835 
63836 -- insert into errors table here.
63837 
63838 END LOOP;
63839 
63840 --
63841 -- 4865292
63842 --
63843 -- Compare g_hdr_extract_count with event count in
63844 -- CreateHeadersAndLines.
63845 --
63846 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
63847 
63848 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
63849    trace (p_msg     => '# rows extracted from header extract objects '
63850                     || ' (running total): '
63851                     || g_hdr_extract_count
63852          ,p_level   => C_LEVEL_STATEMENT
63853          ,p_module  => l_log_module);
63854 END IF;
63855 
63856 CLOSE header_cur;
63857 --
63858 
63859 --
63860 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
63861    trace
63862       (p_msg      => 'END of EventClass_109'
63863       ,p_level    => C_LEVEL_PROCEDURE
63864       ,p_module   => l_log_module);
63865 END IF;
63866 --
63867 RETURN l_result;
63868 EXCEPTION
63869 WHEN xla_exceptions_pkg.application_exception THEN
63870    
63871 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
63872 
63873    
63874 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
63875 
63876    RAISE;
63877 
63878 WHEN NO_DATA_FOUND THEN
63879 
63880 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
63881 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
63882 
63883 FOR header_record IN header_cur
63884 LOOP
63885     l_array_header_events(header_record.event_id) := header_record.event_id;
63886 END LOOP;
63887 
63888 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
63889 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
63890 
63891 fnd_file.put_line(fnd_file.LOG, '                    ');
63892 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
63893 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
63894 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
63895 
63896 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
63897 LOOP
63898 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
63899 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
63900         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
63901 	END IF;
63902 END LOOP;
63903 
63904 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
63905 fnd_file.put_line(fnd_file.LOG, '                    ');
63906 
63907 
63908 xla_exceptions_pkg.raise_message
63909       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_109');
63910 
63911 
63912 WHEN OTHERS THEN
63913    xla_exceptions_pkg.raise_message
63914       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_109');
63915 END EventClass_109;
63916 --
63917 
63918 ---------------------------------------
63919 --
63920 -- PRIVATE PROCEDURE
63921 --         insert_sources_110
63922 --
63923 ----------------------------------------
63924 --
63925 PROCEDURE insert_sources_110(
63926                                 p_target_ledger_id       IN NUMBER
63927                               , p_language               IN VARCHAR2
63928                               , p_sla_ledger_id          IN NUMBER
63929                               , p_pad_start_date         IN DATE
63930                               , p_pad_end_date           IN DATE
63931                          )
63932 IS
63933 
63934 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'RECEIPT_ALL';
63935 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'RECEIPT';
63939 IF g_log_enabled THEN
63936 p_apps_owner                   VARCHAR2(30);
63937 l_log_module                   VARCHAR2(240);
63938 BEGIN
63940       l_log_module := C_DEFAULT_MODULE||'.insert_sources_110';
63941 END IF;
63942 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
63943 
63944       trace
63945          (p_msg      => 'BEGIN of insert_sources_110'
63946          ,p_level    => C_LEVEL_PROCEDURE
63947          ,p_module   => l_log_module);
63948 
63949 END IF;
63950 
63951 -- select APPS owner
63952 SELECT oracle_username
63953   INTO p_apps_owner
63954   FROM fnd_oracle_userid
63955  WHERE read_only_flag = 'U'
63956 ;
63957 
63958 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
63959       trace
63960          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
63961                         ' - p_language = '||p_language||
63962                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
63963                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
63964                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
63965                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
63966          ,p_level    => C_LEVEL_STATEMENT
63967          ,p_module   => l_log_module);
63968 END IF;
63969 
63970 
63971 --
63972 INSERT INTO xla_diag_sources --hdr2
63973 (
63974         event_id
63975       , ledger_id
63976       , sla_ledger_id
63977       , description_language
63978       , object_name
63979       , object_type_code
63980       , line_number
63981       , source_application_id
63982       , source_type_code
63983       , source_code
63984       , source_value
63985       , source_meaning
63986       , created_by
63987       , creation_date
63988       , last_update_date
63989       , last_updated_by
63990       , last_update_login
63991       , program_update_date
63992       , program_application_id
63993       , program_id
63994       , request_id
63995 )
63996 SELECT
63997         event_id
63998       , p_target_ledger_id
63999       , p_sla_ledger_id
64000       , p_language
64001       , object_name
64002       , object_type_code
64003       , line_number
64004       , source_application_id
64005       , source_type_code
64006       , source_code
64007       , SUBSTR(source_value ,1,1996)
64008       , SUBSTR(source_meaning ,1,200)
64009       , xla_environment_pkg.g_Usr_Id
64010       , TRUNC(SYSDATE)
64011       , TRUNC(SYSDATE)
64012       , xla_environment_pkg.g_Usr_Id
64013       , xla_environment_pkg.g_Login_Id
64014       , TRUNC(SYSDATE)
64015       , xla_environment_pkg.g_Prog_Appl_Id
64016       , xla_environment_pkg.g_Prog_Id
64017       , xla_environment_pkg.g_Req_Id
64018   FROM (
64019        SELECT xet.event_id                  event_id
64020             , 0                          line_number
64021             , CASE r
64022                WHEN 1 THEN 'AR_REMIT_BANK_ACCT_H_V' 
64023                 WHEN 2 THEN 'AR_REMIT_BANK_ACCT_H_V' 
64024                 WHEN 3 THEN 'AR_REMIT_BANK_ACCT_H_V' 
64025                 WHEN 4 THEN 'AR_REMIT_BANK_ACCT_H_V' 
64026                 WHEN 5 THEN 'AR_REMIT_BANK_ACCT_H_V' 
64027                 WHEN 6 THEN 'AR_SYSTEM_PARAM_H_V' 
64028                 WHEN 7 THEN 'AR_SYSTEM_PARAM_H_V' 
64029                 WHEN 8 THEN 'AR_RCT_METHOD_H_V' 
64030                 WHEN 9 THEN 'AR_RCT_METHOD_H_V' 
64031                 WHEN 10 THEN 'AR_CASH_RECEIPTS_H_V' 
64032                 WHEN 11 THEN 'AR_CASH_RECEIPTS_H_V' 
64033                 WHEN 12 THEN 'AR_RCT_SITE_USES_H_V' 
64034                 WHEN 13 THEN 'AR_CASH_RECEIPTS_H_V' 
64035                 WHEN 14 THEN 'AR_CASH_RECEIPTS_H_V' 
64036                 WHEN 15 THEN 'AR_CASH_RECEIPTS_H_V' 
64037                 WHEN 16 THEN 'AR_CASH_RECEIPTS_H_V' 
64038                 WHEN 17 THEN 'AR_CASH_RECEIPTS_H_V' 
64039                 
64040                ELSE null
64041               END                           object_name
64042             , CASE r
64043                 WHEN 1 THEN 'HEADER' 
64044                 WHEN 2 THEN 'HEADER' 
64045                 WHEN 3 THEN 'HEADER' 
64046                 WHEN 4 THEN 'HEADER' 
64047                 WHEN 5 THEN 'HEADER' 
64048                 WHEN 6 THEN 'HEADER' 
64049                 WHEN 7 THEN 'HEADER' 
64050                 WHEN 8 THEN 'HEADER' 
64051                 WHEN 9 THEN 'HEADER' 
64052                 WHEN 10 THEN 'HEADER' 
64053                 WHEN 11 THEN 'HEADER' 
64054                 WHEN 12 THEN 'HEADER' 
64055                 WHEN 13 THEN 'HEADER' 
64056                 WHEN 14 THEN 'HEADER' 
64057                 WHEN 15 THEN 'HEADER' 
64058                 WHEN 16 THEN 'HEADER' 
64059                 WHEN 17 THEN 'HEADER' 
64060                 
64061                 ELSE null
64062               END                           object_type_code
64063             , CASE r
64064                 WHEN 1 THEN '222' 
64065                 WHEN 2 THEN '222' 
64066                 WHEN 3 THEN '222' 
64067                 WHEN 4 THEN '222' 
64068                 WHEN 5 THEN '222' 
64069                 WHEN 6 THEN '222' 
64070                 WHEN 7 THEN '222' 
64071                 WHEN 8 THEN '222' 
64072                 WHEN 9 THEN '222' 
64073                 WHEN 10 THEN '222' 
64074                 WHEN 11 THEN '222' 
64075                 WHEN 12 THEN '222' 
64076                 WHEN 13 THEN '222' 
64077                 WHEN 14 THEN '222' 
64078                 WHEN 15 THEN '222' 
64079                 WHEN 16 THEN '222' 
64080                 WHEN 17 THEN '222' 
64081                 
64082                 ELSE null
64086                 WHEN 1 THEN 'RMT_BNK_BANK_CHARGES_CCID' 
64083               END                           source_application_id
64084             , 'S'             source_type_code
64085             , CASE r
64087                 WHEN 2 THEN 'RMT_BNK_CASH_CCID' 
64088                 WHEN 3 THEN 'RMT_BNK_CONFIRMATION_CCID' 
64089                 WHEN 4 THEN 'RMT_BNK_REMITTANCE_CCID' 
64090                 WHEN 5 THEN 'RMT_BNK_UNAPPLIED_CCID' 
64091                 WHEN 6 THEN 'CODE_COMBINATION_ID_GAIN' 
64092                 WHEN 7 THEN 'CODE_COMBINATION_ID_LOSS' 
64093                 WHEN 8 THEN 'RCT_CLASS_REMIT_FLAG' 
64094                 WHEN 9 THEN 'RCT_CLASS_CONFIRM_FLAG' 
64095                 WHEN 10 THEN 'RCT_XLA_APPLIED_TO_APP_ID' 
64096                 WHEN 11 THEN 'RCT_PAY_FROM_CUSTOMER' 
64097                 WHEN 12 THEN 'RCT_SITE_SITE_USE_ID' 
64098                 WHEN 13 THEN 'RCT_APP_STATUS' 
64099                 WHEN 14 THEN 'RCT_DOC_SEQUENCE_CATEGORY' 
64100                 WHEN 15 THEN 'RCT_DOC_SEQUENCE_ID' 
64101                 WHEN 16 THEN 'RCT_DOC_SEQUENCE_VALUE' 
64102                 WHEN 17 THEN 'RCT_TRX_ACCT_REVERSAL' 
64103                 
64104                 ELSE null
64105               END                           source_code
64106             , CASE r
64107                 WHEN 1 THEN TO_CHAR(h8.RMT_BNK_BANK_CHARGES_CCID)
64108                 WHEN 2 THEN TO_CHAR(h8.RMT_BNK_CASH_CCID)
64109                 WHEN 3 THEN TO_CHAR(h8.RMT_BNK_CONFIRMATION_CCID)
64110                 WHEN 4 THEN TO_CHAR(h8.RMT_BNK_REMITTANCE_CCID)
64111                 WHEN 5 THEN TO_CHAR(h8.RMT_BNK_UNAPPLIED_CCID)
64112                 WHEN 6 THEN TO_CHAR(h9.CODE_COMBINATION_ID_GAIN)
64113                 WHEN 7 THEN TO_CHAR(h9.CODE_COMBINATION_ID_LOSS)
64114                 WHEN 8 THEN TO_CHAR(h5.RCT_CLASS_REMIT_FLAG)
64115                 WHEN 9 THEN TO_CHAR(h5.RCT_CLASS_CONFIRM_FLAG)
64116                 WHEN 10 THEN TO_CHAR(h1.RCT_XLA_APPLIED_TO_APP_ID)
64117                 WHEN 11 THEN TO_CHAR(h1.RCT_PAY_FROM_CUSTOMER)
64118                 WHEN 12 THEN TO_CHAR(h6.RCT_SITE_SITE_USE_ID)
64119                 WHEN 13 THEN TO_CHAR(h1.RCT_APP_STATUS)
64120                 WHEN 14 THEN TO_CHAR(h1.RCT_DOC_SEQUENCE_CATEGORY)
64121                 WHEN 15 THEN TO_CHAR(h1.RCT_DOC_SEQUENCE_ID)
64122                 WHEN 16 THEN TO_CHAR(h1.RCT_DOC_SEQUENCE_VALUE)
64123                 WHEN 17 THEN TO_CHAR(h1.RCT_TRX_ACCT_REVERSAL)
64124                 
64125                 ELSE null
64126               END                           source_value
64127             , null              source_meaning
64128          FROM xla_events_gt     xet  
64129       , AR_CASH_RECEIPTS_H_V  h1
64130       , AR_RCT_METHOD_H_V  h5
64131       , AR_RCT_SITE_USES_H_V  h6
64132       , AR_REMIT_BANK_ACCT_H_V  h8
64133       , AR_SYSTEM_PARAM_H_V  h9
64134              ,(select rownum r from all_objects where rownum <= 17 and owner = p_apps_owner)
64135          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
64136            AND xet.event_class_code = C_EVENT_CLASS_CODE
64137               AND h1.event_id = xet.event_id
64138   AND h5.event_id (+) = h1.event_id
64139   AND h6.event_id (+) = h1.event_id
64140   AND h8.event_id (+) = h1.event_id
64141   AND h9.event_id (+) = h1.event_id
64142 
64143 )
64144 ;
64145 --
64146 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
64147 
64148       trace
64149          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
64150          ,p_level    => C_LEVEL_STATEMENT
64151          ,p_module   => l_log_module);
64152 
64153 END IF;
64154 --
64155 
64156 
64157 
64158 --
64159 INSERT INTO xla_diag_sources  --line2
64160 (
64161         event_id
64162       , ledger_id
64163       , sla_ledger_id
64164       , description_language
64165       , object_name
64166       , object_type_code
64167       , line_number
64168       , source_application_id
64169       , source_type_code
64170       , source_code
64171       , source_value
64172       , source_meaning
64173       , created_by
64174       , creation_date
64175       , last_update_date
64176       , last_updated_by
64177       , last_update_login
64178       , program_update_date
64179       , program_application_id
64180       , program_id
64181       , request_id
64182 )
64183 SELECT  event_id
64184       , p_target_ledger_id
64185       , p_sla_ledger_id
64186       , p_language
64187       , object_name
64188       , object_type_code
64189       , line_number
64190       , source_application_id
64191       , source_type_code
64192       , source_code
64193       , SUBSTR(source_value,1,1996)
64194       , SUBSTR(source_meaning ,1,200)
64195       , xla_environment_pkg.g_Usr_Id
64196       , TRUNC(SYSDATE)
64197       , TRUNC(SYSDATE)
64198       , xla_environment_pkg.g_Usr_Id
64199       , xla_environment_pkg.g_Login_Id
64200       , TRUNC(SYSDATE)
64201       , xla_environment_pkg.g_Prog_Appl_Id
64202       , xla_environment_pkg.g_Prog_Id
64203       , xla_environment_pkg.g_Req_Id
64204   FROM (
64205        SELECT xet.event_id                  event_id
64206             , l4.line_number                 line_number
64207             , CASE r
64208                WHEN 1 THEN 'AR_DISTRIBUTIONS_L_V' 
64209                 WHEN 2 THEN 'AR_CUST_TRX_LINES_L_V' 
64210                 WHEN 3 THEN 'AR_DISTRIBUTIONS_L_V' 
64211                 WHEN 4 THEN 'AR_RECEIVABLES_TRX_ACT_S_V' 
64212                 WHEN 5 THEN 'AR_DISTRIBUTIONS_L_V' 
64213                 WHEN 6 THEN 'AR_DISTRIBUTIONS_L_V' 
64214                 WHEN 7 THEN 'AR_DISTRIBUTIONS_L_V' 
64215                 WHEN 8 THEN 'AR_DISTRIBUTIONS_L_V' 
64216                 WHEN 9 THEN 'AR_DISTRIBUTIONS_BASE_V' 
64220                 WHEN 13 THEN 'AR_CUST_TRX_LINES_L_V' 
64217                 WHEN 10 THEN 'AR_DISTRIBUTIONS_BASE_V' 
64218                 WHEN 11 THEN 'AR_DISTRIBUTIONS_BASE_V' 
64219                 WHEN 12 THEN 'AR_DISTRIBUTIONS_BASE_V' 
64221                 WHEN 14 THEN 'AR_CUST_TRX_LINES_L_V' 
64222                 WHEN 15 THEN 'AR_CUST_TRX_LINES_L_V' 
64223                 WHEN 16 THEN 'AR_DISTRIBUTIONS_L_V' 
64224                 WHEN 17 THEN 'AR_DISTRIBUTIONS_BASE_V' 
64225                 WHEN 18 THEN 'AR_TRANSACTIONS_S_V' 
64226                 WHEN 19 THEN 'AR_TRANSACTIONS_S_V' 
64227                 WHEN 20 THEN 'AR_DISTRIBUTIONS_L_V' 
64228                 WHEN 21 THEN 'AR_DISTRIBUTIONS_L_V' 
64229                 WHEN 22 THEN 'AR_DISTRIBUTIONS_BASE_V' 
64230                 WHEN 23 THEN 'AR_DISTRIBUTIONS_L_V' 
64231                 WHEN 24 THEN 'AR_DISTRIBUTIONS_L_V' 
64232                 WHEN 25 THEN 'AR_DISTRIBUTIONS_L_V' 
64233                 WHEN 26 THEN 'AR_DISTRIBUTIONS_BASE_V' 
64234                 WHEN 27 THEN 'AR_DISTRIBUTIONS_BASE_V' 
64235                 WHEN 28 THEN 'AR_DISTRIBUTIONS_L_V' 
64236                 
64237                ELSE null
64238               END                           object_name
64239             , CASE r
64240                 WHEN 1 THEN 'LINE' 
64241                 WHEN 2 THEN 'LINE' 
64242                 WHEN 3 THEN 'LINE' 
64243                 WHEN 4 THEN 'LINE' 
64244                 WHEN 5 THEN 'LINE' 
64245                 WHEN 6 THEN 'LINE' 
64246                 WHEN 7 THEN 'LINE' 
64247                 WHEN 8 THEN 'LINE' 
64248                 WHEN 9 THEN 'LINE' 
64249                 WHEN 10 THEN 'LINE' 
64250                 WHEN 11 THEN 'LINE' 
64251                 WHEN 12 THEN 'LINE' 
64252                 WHEN 13 THEN 'LINE' 
64253                 WHEN 14 THEN 'LINE' 
64254                 WHEN 15 THEN 'LINE' 
64255                 WHEN 16 THEN 'LINE' 
64256                 WHEN 17 THEN 'LINE' 
64257                 WHEN 18 THEN 'LINE' 
64258                 WHEN 19 THEN 'LINE' 
64259                 WHEN 20 THEN 'LINE' 
64260                 WHEN 21 THEN 'LINE' 
64261                 WHEN 22 THEN 'LINE' 
64262                 WHEN 23 THEN 'LINE' 
64263                 WHEN 24 THEN 'LINE' 
64264                 WHEN 25 THEN 'LINE' 
64265                 WHEN 26 THEN 'LINE' 
64266                 WHEN 27 THEN 'LINE' 
64267                 WHEN 28 THEN 'LINE' 
64268                 
64269                 ELSE null
64270               END                           object_type_code
64271             , CASE r
64272                 WHEN 1 THEN '222' 
64273                 WHEN 2 THEN '222' 
64274                 WHEN 3 THEN '222' 
64275                 WHEN 4 THEN '222' 
64276                 WHEN 5 THEN '222' 
64277                 WHEN 6 THEN '222' 
64278                 WHEN 7 THEN '222' 
64279                 WHEN 8 THEN '222' 
64280                 WHEN 9 THEN '222' 
64281                 WHEN 10 THEN '222' 
64282                 WHEN 11 THEN '222' 
64283                 WHEN 12 THEN '222' 
64284                 WHEN 13 THEN '222' 
64285                 WHEN 14 THEN '222' 
64286                 WHEN 15 THEN '222' 
64287                 WHEN 16 THEN '222' 
64288                 WHEN 17 THEN '222' 
64289                 WHEN 18 THEN '222' 
64290                 WHEN 19 THEN '222' 
64291                 WHEN 20 THEN '222' 
64292                 WHEN 21 THEN '222' 
64293                 WHEN 22 THEN '222' 
64294                 WHEN 23 THEN '222' 
64295                 WHEN 24 THEN '222' 
64296                 WHEN 25 THEN '222' 
64297                 WHEN 26 THEN '222' 
64298                 WHEN 27 THEN '222' 
64299                 WHEN 28 THEN '222' 
64300                 
64301                 ELSE null
64302               END                           source_application_id
64303             , 'S'             source_type_code
64304             , CASE r
64305                 WHEN 1 THEN 'DIST_CODE_COMBINATION_ID' 
64306                 WHEN 2 THEN 'TRX_LINE_DIST_CCID' 
64307                 WHEN 3 THEN 'DIST_SOURCE_TYPE' 
64308                 WHEN 4 THEN 'REC_ACT_TYPE' 
64309                 WHEN 5 THEN 'DIST_LINE_ID' 
64310                 WHEN 6 THEN 'DISTRIBUTION_TYPE' 
64311                 WHEN 7 THEN 'DIST_ENT_AMT' 
64312                 WHEN 8 THEN 'DIST_CURRENCY_CODE' 
64313                 WHEN 9 THEN 'DIST_CUR_CONVERSION_DATE' 
64314                 WHEN 10 THEN 'DIST_CUR_CONVERSION_RATE' 
64315                 WHEN 11 THEN 'DIST_CUR_CONVERSION_TYPE' 
64316                 WHEN 12 THEN 'DIST_TO_ACCTD_AMT' 
64317                 WHEN 13 THEN 'TRX_LINE_DIST_ACCOUNT_CLASS' 
64318                 WHEN 14 THEN 'TRX_LINE_DIST_ID' 
64319                 WHEN 15 THEN 'TRX_DISTRIBUTION_TYPE' 
64320                 WHEN 16 THEN 'DIST_MFAR_ADDITIONAL_ENTRY' 
64321                 WHEN 17 THEN 'DIST_TO_CUR_CONVERSION_DATE' 
64322                 WHEN 18 THEN 'TRX_ENTITY_CODE' 
64323                 WHEN 19 THEN 'TRX_CUSTOMER_TRX_ID' 
64324                 WHEN 20 THEN 'DIST_ENT_AMT_FROM' 
64325                 WHEN 21 THEN 'DIST_CURRENCY_CODE_FROM' 
64326                 WHEN 22 THEN 'DIST_ACCTD_AMT' 
64327                 WHEN 23 THEN 'DIST_PARTY_ID' 
64328                 WHEN 24 THEN 'DIST_PARTY_SITE_ID' 
64329                 WHEN 25 THEN 'DIST_PARTY_TYPE' 
64330                 WHEN 26 THEN 'DIST_TO_CUR_CONVERSION_TYPE' 
64331                 WHEN 27 THEN 'DIST_TO_CUR_CONVERSION_RATE' 
64332                 WHEN 28 THEN 'DIST_SOURCE_TABLE' 
64333                 
64334                 ELSE null
64335               END                           source_code
64336             , CASE r
64337                 WHEN 1 THEN TO_CHAR(l4.DIST_CODE_COMBINATION_ID)
64338                 WHEN 2 THEN TO_CHAR(l2.TRX_LINE_DIST_CCID)
64342                 WHEN 6 THEN TO_CHAR(l4.DISTRIBUTION_TYPE)
64339                 WHEN 3 THEN TO_CHAR(l4.DIST_SOURCE_TYPE)
64340                 WHEN 4 THEN TO_CHAR(l7.REC_ACT_TYPE)
64341                 WHEN 5 THEN TO_CHAR(l4.DIST_LINE_ID)
64343                 WHEN 7 THEN TO_CHAR(l4.DIST_ENT_AMT)
64344                 WHEN 8 THEN TO_CHAR(l4.DIST_CURRENCY_CODE)
64345                 WHEN 9 THEN TO_CHAR(l3.DIST_CUR_CONVERSION_DATE)
64346                 WHEN 10 THEN TO_CHAR(l3.DIST_CUR_CONVERSION_RATE)
64347                 WHEN 11 THEN TO_CHAR(l3.DIST_CUR_CONVERSION_TYPE)
64348                 WHEN 12 THEN TO_CHAR(l3.DIST_TO_ACCTD_AMT)
64349                 WHEN 13 THEN TO_CHAR(l2.TRX_LINE_DIST_ACCOUNT_CLASS)
64350                 WHEN 14 THEN TO_CHAR(l2.TRX_LINE_DIST_ID)
64351                 WHEN 15 THEN TO_CHAR(l2.TRX_DISTRIBUTION_TYPE)
64352                 WHEN 16 THEN TO_CHAR(l4.DIST_MFAR_ADDITIONAL_ENTRY)
64353                 WHEN 17 THEN TO_CHAR(l3.DIST_TO_CUR_CONVERSION_DATE)
64354                 WHEN 18 THEN TO_CHAR(l10.TRX_ENTITY_CODE)
64355                 WHEN 19 THEN TO_CHAR(l10.TRX_CUSTOMER_TRX_ID)
64356                 WHEN 20 THEN TO_CHAR(l4.DIST_ENT_AMT_FROM)
64357                 WHEN 21 THEN TO_CHAR(l4.DIST_CURRENCY_CODE_FROM)
64358                 WHEN 22 THEN TO_CHAR(l3.DIST_ACCTD_AMT)
64359                 WHEN 23 THEN TO_CHAR(l4.DIST_PARTY_ID)
64360                 WHEN 24 THEN TO_CHAR(l4.DIST_PARTY_SITE_ID)
64361                 WHEN 25 THEN TO_CHAR(l4.DIST_PARTY_TYPE)
64362                 WHEN 26 THEN TO_CHAR(l3.DIST_TO_CUR_CONVERSION_TYPE)
64363                 WHEN 27 THEN TO_CHAR(l3.DIST_TO_CUR_CONVERSION_RATE)
64364                 WHEN 28 THEN TO_CHAR(l4.DIST_SOURCE_TABLE)
64365                 
64366                 ELSE null
64367               END                           source_value
64368             , null              source_meaning
64369          FROM  xla_events_gt     xet  
64370         , AR_CUST_TRX_LINES_L_V  l2
64371         , AR_DISTRIBUTIONS_BASE_V  l3
64372         , AR_DISTRIBUTIONS_L_V  l4
64373         , AR_RECEIVABLES_TRX_ACT_S_V  l7
64374         , AR_TRANSACTIONS_S_V  l10
64375             , (select rownum r from all_objects where rownum <= 28 and owner = p_apps_owner)
64376         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
64377           AND xet.event_class_code = C_EVENT_CLASS_CODE
64378             AND l3.event_id          = xet.event_id
64379   AND l2.event_id (+)    = l3.event_id
64380   AND l2.line_number (+) = l3.line_number
64381   AND l4.event_id    = l3.event_id
64382   AND l4.line_number = l3.line_number
64383   AND l7.event_id (+)    = l3.event_id
64384   AND l7.line_number (+) = l3.line_number
64385   AND l10.event_id (+)    = l3.event_id
64386   AND l10.line_number (+) = l3.line_number
64387 
64388 )
64389 ;
64390 --
64391 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
64392 
64393       trace
64394          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
64395          ,p_level    => C_LEVEL_STATEMENT
64396          ,p_module   => l_log_module);
64397 
64398 END IF;
64399 
64400 
64401 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
64402       trace
64403          (p_msg      => 'END of insert_sources_110'
64404          ,p_level    => C_LEVEL_PROCEDURE
64405          ,p_module   => l_log_module);
64406 END IF;
64407 EXCEPTION
64408   WHEN xla_exceptions_pkg.application_exception THEN
64409       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
64410             trace
64411                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
64412                ,p_level    => C_LEVEL_EXCEPTION
64413                ,p_module   => l_log_module);
64414       END IF;
64415       RAISE;
64416   WHEN OTHERS THEN
64417       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
64418             trace
64419                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
64420                ,p_level    => C_LEVEL_EXCEPTION
64421                ,p_module   => l_log_module);
64422        END IF;
64423        xla_exceptions_pkg.raise_message
64424            (p_location => 'XLA_00222_AAD_S_000008_PKG.insert_sources_110');
64425 END insert_sources_110;
64426 --
64427 
64428 ---------------------------------------
64429 --
64430 -- PRIVATE FUNCTION
64431 --         EventClass_110
64432 --
64433 ----------------------------------------
64434 --
64435 FUNCTION EventClass_110
64436        (p_application_id         IN NUMBER
64437        ,p_base_ledger_id         IN NUMBER
64438        ,p_target_ledger_id       IN NUMBER
64439        ,p_language               IN VARCHAR2
64440        ,p_currency_code          IN VARCHAR2
64441        ,p_sla_ledger_id          IN NUMBER
64442        ,p_pad_start_date         IN DATE
64443        ,p_pad_end_date           IN DATE
64444        ,p_primary_ledger_id      IN NUMBER)
64445 RETURN BOOLEAN IS
64446 --
64447 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'RECEIPT_ALL';
64448 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'RECEIPT';
64449 
64450 l_calculate_acctd_flag   VARCHAR2(1) :='N';
64451 l_calculate_g_l_flag     VARCHAR2(1) :='Y';
64452 --
64453 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
64454 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
64455 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
64456 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
64457 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
64458 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
64459 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
64460 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
64464 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
64461 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
64462 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
64463 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
64465 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
64466 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
64467 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
64468 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
64469 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
64470 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
64471 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
64472 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
64473 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
64474 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
64475 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
64476 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
64477 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
64478 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
64479 
64480 l_event_id                             NUMBER;
64481 l_previous_event_id                    NUMBER;
64482 l_first_event_id                       NUMBER;
64483 l_last_event_id                        NUMBER;
64484 
64485 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
64486 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
64487 --
64488 --
64489 l_result                    BOOLEAN := TRUE;
64490 l_rows                      NUMBER  := 1000;
64491 l_event_type_name           VARCHAR2(80) := 'All';
64492 l_event_class_name          VARCHAR2(80) := 'Receipt';
64493 l_description               VARCHAR2(4000);
64494 l_transaction_reversal      NUMBER;
64495 l_ae_header_id              NUMBER;
64496 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
64497 l_log_module                VARCHAR2(240);
64498 --
64499 l_acct_reversal_source      VARCHAR2(30);
64500 l_trx_reversal_source       VARCHAR2(30);
64501 
64502 l_continue_with_lines       BOOLEAN := TRUE;
64503 --
64504 l_acc_rev_gl_date_source    DATE;                      -- 4262811
64505 --
64506 type t_array_event_id is table of number index by binary_integer;
64507 
64508 l_rec_array_event                    t_rec_array_event;
64509 l_null_rec_array_event               t_rec_array_event;
64510 l_array_ae_header_id                 xla_number_array_type;
64511 l_actual_flag                        VARCHAR2(1) := NULL;
64512 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
64513 l_balance_type_code                  VARCHAR2(1) :=NULL;
64514 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
64515 
64516 --
64517 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
64518 --
64519 
64520 TYPE t_array_source_1 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_BANK_CHARGES_CCID%TYPE INDEX BY BINARY_INTEGER;
64521 TYPE t_array_source_6 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_CASH_CCID%TYPE INDEX BY BINARY_INTEGER;
64522 TYPE t_array_source_7 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_CONFIRMATION_CCID%TYPE INDEX BY BINARY_INTEGER;
64523 TYPE t_array_source_8 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_REMITTANCE_CCID%TYPE INDEX BY BINARY_INTEGER;
64524 TYPE t_array_source_10 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_UNAPPLIED_CCID%TYPE INDEX BY BINARY_INTEGER;
64525 TYPE t_array_source_11 IS TABLE OF AR_SYSTEM_PARAM_H_V.CODE_COMBINATION_ID_GAIN%TYPE INDEX BY BINARY_INTEGER;
64526 TYPE t_array_source_12 IS TABLE OF AR_SYSTEM_PARAM_H_V.CODE_COMBINATION_ID_LOSS%TYPE INDEX BY BINARY_INTEGER;
64527 TYPE t_array_source_54 IS TABLE OF AR_RCT_METHOD_H_V.RCT_CLASS_REMIT_FLAG%TYPE INDEX BY BINARY_INTEGER;
64528 TYPE t_array_source_55 IS TABLE OF AR_RCT_METHOD_H_V.RCT_CLASS_CONFIRM_FLAG%TYPE INDEX BY BINARY_INTEGER;
64529 TYPE t_array_source_56 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_XLA_APPLIED_TO_APP_ID%TYPE INDEX BY BINARY_INTEGER;
64530 TYPE t_array_source_68 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_PAY_FROM_CUSTOMER%TYPE INDEX BY BINARY_INTEGER;
64531 TYPE t_array_source_69 IS TABLE OF AR_RCT_SITE_USES_H_V.RCT_SITE_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
64532 TYPE t_array_source_70 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_APP_STATUS%TYPE INDEX BY BINARY_INTEGER;
64533 TYPE t_array_source_78 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
64534 TYPE t_array_source_79 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
64535 TYPE t_array_source_80 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
64536 TYPE t_array_source_81 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_TRX_ACCT_REVERSAL%TYPE INDEX BY BINARY_INTEGER;
64537 
64538 TYPE t_array_source_3 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CODE_COMBINATION_ID%TYPE INDEX BY BINARY_INTEGER;
64539 TYPE t_array_source_4 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
64540 TYPE t_array_source_13 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_SOURCE_TYPE%TYPE INDEX BY BINARY_INTEGER;
64541 TYPE t_array_source_14 IS TABLE OF AR_RECEIVABLES_TRX_ACT_S_V.REC_ACT_TYPE%TYPE INDEX BY BINARY_INTEGER;
64542 TYPE t_array_source_15 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
64546 TYPE t_array_source_19 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
64543 TYPE t_array_source_16 IS TABLE OF AR_DISTRIBUTIONS_L_V.DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
64544 TYPE t_array_source_17 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_ENT_AMT%TYPE INDEX BY BINARY_INTEGER;
64545 TYPE t_array_source_18 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
64547 TYPE t_array_source_20 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
64548 TYPE t_array_source_21 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
64549 TYPE t_array_source_22 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
64550 TYPE t_array_source_26 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ACCOUNT_CLASS%TYPE INDEX BY BINARY_INTEGER;
64551 TYPE t_array_source_27 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ID%TYPE INDEX BY BINARY_INTEGER;
64552 TYPE t_array_source_28 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
64553 TYPE t_array_source_52 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_MFAR_ADDITIONAL_ENTRY%TYPE INDEX BY BINARY_INTEGER;
64554 TYPE t_array_source_53 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
64555 TYPE t_array_source_57 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_ENTITY_CODE%TYPE INDEX BY BINARY_INTEGER;
64556 TYPE t_array_source_58 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_CUSTOMER_TRX_ID%TYPE INDEX BY BINARY_INTEGER;
64557 TYPE t_array_source_59 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_ENT_AMT_FROM%TYPE INDEX BY BINARY_INTEGER;
64558 TYPE t_array_source_60 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CURRENCY_CODE_FROM%TYPE INDEX BY BINARY_INTEGER;
64559 TYPE t_array_source_61 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
64560 TYPE t_array_source_62 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_PARTY_ID%TYPE INDEX BY BINARY_INTEGER;
64561 TYPE t_array_source_63 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_PARTY_SITE_ID%TYPE INDEX BY BINARY_INTEGER;
64562 TYPE t_array_source_64 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
64563 TYPE t_array_source_65 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
64564 TYPE t_array_source_66 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
64565 TYPE t_array_source_67 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_SOURCE_TABLE%TYPE INDEX BY BINARY_INTEGER;
64566 
64567 l_array_source_1              t_array_source_1;
64568 l_array_source_6              t_array_source_6;
64569 l_array_source_7              t_array_source_7;
64570 l_array_source_8              t_array_source_8;
64571 l_array_source_10              t_array_source_10;
64572 l_array_source_11              t_array_source_11;
64573 l_array_source_12              t_array_source_12;
64574 l_array_source_54              t_array_source_54;
64575 l_array_source_55              t_array_source_55;
64576 l_array_source_56              t_array_source_56;
64577 l_array_source_68              t_array_source_68;
64578 l_array_source_69              t_array_source_69;
64579 l_array_source_70              t_array_source_70;
64580 l_array_source_78              t_array_source_78;
64581 l_array_source_79              t_array_source_79;
64582 l_array_source_80              t_array_source_80;
64583 l_array_source_81              t_array_source_81;
64584 
64585 l_array_source_3      t_array_source_3;
64586 l_array_source_4      t_array_source_4;
64587 l_array_source_13      t_array_source_13;
64588 l_array_source_14      t_array_source_14;
64589 l_array_source_15      t_array_source_15;
64590 l_array_source_16      t_array_source_16;
64591 l_array_source_17      t_array_source_17;
64592 l_array_source_18      t_array_source_18;
64593 l_array_source_19      t_array_source_19;
64594 l_array_source_20      t_array_source_20;
64595 l_array_source_21      t_array_source_21;
64596 l_array_source_22      t_array_source_22;
64597 l_array_source_26      t_array_source_26;
64598 l_array_source_27      t_array_source_27;
64599 l_array_source_28      t_array_source_28;
64600 l_array_source_52      t_array_source_52;
64601 l_array_source_53      t_array_source_53;
64602 l_array_source_57      t_array_source_57;
64603 l_array_source_58      t_array_source_58;
64604 l_array_source_59      t_array_source_59;
64605 l_array_source_60      t_array_source_60;
64606 l_array_source_61      t_array_source_61;
64607 l_array_source_62      t_array_source_62;
64608 l_array_source_63      t_array_source_63;
64609 l_array_source_64      t_array_source_64;
64610 l_array_source_65      t_array_source_65;
64611 l_array_source_66      t_array_source_66;
64612 l_array_source_67      t_array_source_67;
64613 
64614 --
64615 CURSOR header_cur
64616 IS
64617 SELECT /*+ leading(xet) cardinality(xet,1) */
64618 -- Event Class Code: RECEIPT
64619     xet.entity_id
64620    ,xet.legal_entity_id
64621    ,xet.entity_code
64622    ,xet.transaction_number
64623    ,xet.event_id
64624    ,xet.event_class_code
64625    ,xet.event_type_code
64626    ,xet.event_number
64627    ,xet.event_date
64628    ,xet.transaction_date
64629    ,xet.reference_num_1
64630    ,xet.reference_num_2
64631    ,xet.reference_num_3
64632    ,xet.reference_num_4
64633    ,xet.reference_char_1
64634    ,xet.reference_char_2
64635    ,xet.reference_char_3
64636    ,xet.reference_char_4
64637    ,xet.reference_date_1
64638    ,xet.reference_date_2
64639    ,xet.reference_date_3
64640    ,xet.reference_date_4
64641    ,xet.event_created_by
64642    ,xet.budgetary_control_flag 
64643   , h8.RMT_BNK_BANK_CHARGES_CCID    source_1
64644   , h8.RMT_BNK_CASH_CCID    source_6
64645   , h8.RMT_BNK_CONFIRMATION_CCID    source_7
64646   , h8.RMT_BNK_REMITTANCE_CCID    source_8
64647   , h8.RMT_BNK_UNAPPLIED_CCID    source_10
64648   , h9.CODE_COMBINATION_ID_GAIN    source_11
64649   , h9.CODE_COMBINATION_ID_LOSS    source_12
64650   , h5.RCT_CLASS_REMIT_FLAG    source_54
64651   , h5.RCT_CLASS_CONFIRM_FLAG    source_55
64652   , h1.RCT_XLA_APPLIED_TO_APP_ID    source_56
64653   , h1.RCT_PAY_FROM_CUSTOMER    source_68
64654   , h6.RCT_SITE_SITE_USE_ID    source_69
64655   , h1.RCT_APP_STATUS    source_70
64656   , h1.RCT_DOC_SEQUENCE_CATEGORY    source_78
64657   , h1.RCT_DOC_SEQUENCE_ID    source_79
64658   , h1.RCT_DOC_SEQUENCE_VALUE    source_80
64659   , h1.RCT_TRX_ACCT_REVERSAL    source_81
64660   FROM xla_events_gt     xet 
64661   , AR_CASH_RECEIPTS_H_V  h1
64662   , AR_RCT_METHOD_H_V  h5
64663   , AR_RCT_SITE_USES_H_V  h6
64664   , AR_REMIT_BANK_ACCT_H_V  h8
64665   , AR_SYSTEM_PARAM_H_V  h9
64666  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
64667    and xet.event_class_code = C_EVENT_CLASS_CODE
64668    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
64669   AND h5.event_id (+) = h1.event_id
64670   AND h6.event_id (+) = h1.event_id
64671   AND h8.event_id (+) = h1.event_id
64672   AND h9.event_id (+) = h1.event_id
64673 
64674  ORDER BY event_id
64675 ;
64676 
64677 
64678 --
64679 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
64680 IS
64681 SELECT  /*+ leading(xet) cardinality(xet,1) */
64682 -- Event Class Code: RECEIPT
64683     xet.entity_id
64684    ,xet.legal_entity_id
64685    ,xet.entity_code
64686    ,xet.transaction_number
64687    ,xet.event_id
64688    ,xet.event_class_code
64689    ,xet.event_type_code
64690    ,xet.event_number
64691    ,xet.event_date
64692    ,xet.transaction_date
64693    ,xet.reference_num_1
64694    ,xet.reference_num_2
64695    ,xet.reference_num_3
64696    ,xet.reference_num_4
64697    ,xet.reference_char_1
64698    ,xet.reference_char_2
64699    ,xet.reference_char_3
64700    ,xet.reference_char_4
64701    ,xet.reference_date_1
64702    ,xet.reference_date_2
64703    ,xet.reference_date_3
64704    ,xet.reference_date_4
64705    ,xet.event_created_by
64706    ,xet.budgetary_control_flag
64707  , l3.LINE_NUMBER  
64708   , l4.DIST_CODE_COMBINATION_ID    source_3
64709   , l2.TRX_LINE_DIST_CCID    source_4
64710   , l4.DIST_SOURCE_TYPE    source_13
64711   , l7.REC_ACT_TYPE    source_14
64712   , l4.DIST_LINE_ID    source_15
64713   , l4.DISTRIBUTION_TYPE    source_16
64714   , l4.DIST_ENT_AMT    source_17
64715   , l4.DIST_CURRENCY_CODE    source_18
64716   , l3.DIST_CUR_CONVERSION_DATE    source_19
64717   , l3.DIST_CUR_CONVERSION_RATE    source_20
64718   , l3.DIST_CUR_CONVERSION_TYPE    source_21
64719   , l3.DIST_TO_ACCTD_AMT    source_22
64720   , l2.TRX_LINE_DIST_ACCOUNT_CLASS    source_26
64721   , l2.TRX_LINE_DIST_ID    source_27
64722   , l2.TRX_DISTRIBUTION_TYPE    source_28
64723   , l4.DIST_MFAR_ADDITIONAL_ENTRY    source_52
64724   , l3.DIST_TO_CUR_CONVERSION_DATE    source_53
64725   , l10.TRX_ENTITY_CODE    source_57
64726   , l10.TRX_CUSTOMER_TRX_ID    source_58
64727   , l4.DIST_ENT_AMT_FROM    source_59
64731   , l4.DIST_PARTY_SITE_ID    source_63
64728   , l4.DIST_CURRENCY_CODE_FROM    source_60
64729   , l3.DIST_ACCTD_AMT    source_61
64730   , l4.DIST_PARTY_ID    source_62
64732   , l4.DIST_PARTY_TYPE    source_64
64733   , l3.DIST_TO_CUR_CONVERSION_TYPE    source_65
64734   , l3.DIST_TO_CUR_CONVERSION_RATE    source_66
64735   , l4.DIST_SOURCE_TABLE    source_67
64736   FROM xla_events_gt     xet 
64737   , AR_CUST_TRX_LINES_L_V  l2
64738   , AR_DISTRIBUTIONS_BASE_V  l3
64739   , AR_DISTRIBUTIONS_L_V  l4
64740   , AR_RECEIVABLES_TRX_ACT_S_V  l7
64741   , AR_TRANSACTIONS_S_V  l10
64742  WHERE xet.event_id between x_first_event_id and x_last_event_id
64743    and xet.event_date between p_pad_start_date and p_pad_end_date
64744    and xet.event_class_code = C_EVENT_CLASS_CODE
64745    and xet.event_status_code <> 'N'   AND l3.event_id      = xet.event_id
64746   AND l2.event_id (+)    = l3.event_id
64747   AND l2.line_number (+) = l3.line_number
64748   AND l4.event_id    = l3.event_id
64749   AND l4.line_number = l3.line_number
64750   AND l7.event_id (+)    = l3.event_id
64751   AND l7.line_number (+) = l3.line_number
64752   AND l10.event_id (+)    = l3.event_id
64753   AND l10.line_number (+) = l3.line_number
64754 ;
64755 
64756 --
64757 BEGIN
64758 IF g_log_enabled THEN
64759    l_log_module := C_DEFAULT_MODULE||'.EventClass_110';
64760 END IF;
64761 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
64762    trace
64763       (p_msg      => 'BEGIN of EventClass_110'
64764       ,p_level    => C_LEVEL_PROCEDURE
64765       ,p_module   => l_log_module);
64766 END IF;
64767 
64768 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
64769    trace
64770       (p_msg      => 'p_application_id = '||p_application_id||
64771                      ' - p_base_ledger_id = '||p_base_ledger_id||
64772                      ' - p_target_ledger_id  = '||p_target_ledger_id||
64773                      ' - p_language = '||p_language||
64774                      ' - p_currency_code = '||p_currency_code||
64775                      ' - p_sla_ledger_id = '||p_sla_ledger_id
64776       ,p_level    => C_LEVEL_STATEMENT
64777       ,p_module   => l_log_module);
64778 END IF;
64779 --
64780 -- initialze arrays
64781 --
64782 g_array_event.DELETE;
64783 l_rec_array_event := l_null_rec_array_event;
64784 --
64785 --------------------------------------
64786 -- 4262811 Initialze MPA Line Number
64787 --------------------------------------
64788 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
64789 
64790 --
64791 
64792 --
64793 OPEN header_cur;
64794 --
64795 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
64796    trace
64797    (p_msg      => 'SQL - FETCH header_cur'
64798    ,p_level    => C_LEVEL_STATEMENT
64799    ,p_module   => l_log_module);
64800 END IF;
64801 --
64802 LOOP
64803 FETCH header_cur BULK COLLECT INTO
64804         l_array_entity_id
64805       , l_array_legal_entity_id
64806       , l_array_entity_code
64807       , l_array_transaction_num
64808       , l_array_event_id
64809       , l_array_class_code
64810       , l_array_event_type
64811       , l_array_event_number
64812       , l_array_event_date
64813       , l_array_transaction_date
64814       , l_array_reference_num_1
64815       , l_array_reference_num_2
64816       , l_array_reference_num_3
64817       , l_array_reference_num_4
64818       , l_array_reference_char_1
64819       , l_array_reference_char_2
64820       , l_array_reference_char_3
64821       , l_array_reference_char_4
64822       , l_array_reference_date_1
64823       , l_array_reference_date_2
64824       , l_array_reference_date_3
64825       , l_array_reference_date_4
64826       , l_array_event_created_by
64827       , l_array_budgetary_control_flag 
64828       , l_array_source_1
64829       , l_array_source_6
64830       , l_array_source_7
64831       , l_array_source_8
64832       , l_array_source_10
64833       , l_array_source_11
64834       , l_array_source_12
64835       , l_array_source_54
64836       , l_array_source_55
64837       , l_array_source_56
64838       , l_array_source_68
64839       , l_array_source_69
64840       , l_array_source_70
64841       , l_array_source_78
64842       , l_array_source_79
64843       , l_array_source_80
64844       , l_array_source_81
64845       LIMIT l_rows;
64846 --
64847 IF (C_LEVEL_EVENT >= g_log_level) THEN
64848    trace
64849    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
64850    ,p_level    => C_LEVEL_EVENT
64851    ,p_module   => l_log_module);
64852 END IF;
64853 --
64854 EXIT WHEN l_array_entity_id.COUNT = 0;
64855 
64856 -- initialize arrays
64857 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
64858 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
64859 
64860 --
64861 -- Bug 4458708
64862 --
64863 XLA_AE_LINES_PKG.g_LineNumber := 0;
64864 
64865 
64866 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
64867 g_last_hdr_idx := l_array_event_id.LAST;
64868 --
64869 -- loop for the headers. Each iteration is for each header extract row
64870 -- fetched in header cursor
64871 --
64872 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
64873 
64874 --
64875 -- set event info as cache for other routines to refer event attributes
64876 --
64877 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
64878    (p_application_id           => p_application_id
64879    ,p_primary_ledger_id        => p_primary_ledger_id
64880    ,p_base_ledger_id           => p_base_ledger_id
64884    ,p_entity_code              => l_array_entity_code(hdr_idx)
64881    ,p_target_ledger_id         => p_target_ledger_id
64882    ,p_entity_id                => l_array_entity_id(hdr_idx)
64883    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
64885    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
64886    ,p_event_id                 => l_array_event_id(hdr_idx)
64887    ,p_event_class_code         => l_array_class_code(hdr_idx)
64888    ,p_event_type_code          => l_array_event_type(hdr_idx)
64889    ,p_event_number             => l_array_event_number(hdr_idx)
64890    ,p_event_date               => l_array_event_date(hdr_idx)
64891    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
64892    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
64893    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
64894    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
64895    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
64896    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
64897    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
64898    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
64899    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
64900    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
64901    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
64902    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
64903    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
64904    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
64905    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
64906 
64907 --
64908 -- set the status of entry to C_VALID (0)
64909 --
64910 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
64911 
64912 --
64913 -- initialize a row for ae header
64914 --
64915 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
64916 
64917 l_event_id := l_array_event_id(hdr_idx);
64918 
64919 --
64920 -- storing the hdr_idx for event. May be used by line cursor.
64921 --
64922 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
64923 
64924 --
64925 -- store sources from header extract. This can be improved to
64926 -- store only those sources from header extract that may be used in lines
64927 --
64928 
64929 g_array_event(l_event_id).array_value_num('source_1') := l_array_source_1(hdr_idx);
64930 g_array_event(l_event_id).array_value_num('source_6') := l_array_source_6(hdr_idx);
64931 g_array_event(l_event_id).array_value_num('source_7') := l_array_source_7(hdr_idx);
64932 g_array_event(l_event_id).array_value_num('source_8') := l_array_source_8(hdr_idx);
64933 g_array_event(l_event_id).array_value_num('source_10') := l_array_source_10(hdr_idx);
64934 g_array_event(l_event_id).array_value_num('source_11') := l_array_source_11(hdr_idx);
64935 g_array_event(l_event_id).array_value_num('source_12') := l_array_source_12(hdr_idx);
64936 g_array_event(l_event_id).array_value_char('source_54') := l_array_source_54(hdr_idx);
64937 g_array_event(l_event_id).array_value_char('source_55') := l_array_source_55(hdr_idx);
64938 g_array_event(l_event_id).array_value_num('source_56') := l_array_source_56(hdr_idx);
64939 g_array_event(l_event_id).array_value_num('source_68') := l_array_source_68(hdr_idx);
64940 g_array_event(l_event_id).array_value_num('source_69') := l_array_source_69(hdr_idx);
64941 g_array_event(l_event_id).array_value_char('source_70') := l_array_source_70(hdr_idx);
64942 g_array_event(l_event_id).array_value_char('source_78') := l_array_source_78(hdr_idx);
64943 g_array_event(l_event_id).array_value_num('source_79') := l_array_source_79(hdr_idx);
64944 g_array_event(l_event_id).array_value_num('source_80') := l_array_source_80(hdr_idx);
64945 g_array_event(l_event_id).array_value_char('source_81') := l_array_source_81(hdr_idx);
64946 
64947 --
64948 -- initilaize the status of ae headers for diffrent balance types
64949 -- the status is initialised to C_NOT_CREATED (2)
64950 --
64951 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
64952 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
64953 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
64954 
64955 --
64956 -- call api to validate and store accounting attributes for header
64957 --
64958 
64959 ------------------------------------------------------------
64960 -- Accrual Reversal : to get date for Standard Source (NONE)
64961 ------------------------------------------------------------
64962 l_acc_rev_gl_date_source := NULL;
64963 
64964      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
64965       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_78');
64966      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
64967       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_79');
64968      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
64969       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_80');
64970      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
64971       l_rec_acct_attrs.array_date_value(4) := 
64972 xla_ae_sources_pkg.GetSystemSourceDate(
64973    p_source_code           => 'XLA_EVENT_DATE'
64974  , p_source_type_code      => 'Y'
64975  , p_source_application_id =>  602
64976 );
64977      l_rec_acct_attrs.array_acct_attr_code(5)   := 'TRX_ACCT_REVERSAL_OPTION';
64978       l_rec_acct_attrs.array_char_value(5) := g_array_event(l_event_id).array_value_char('source_81');
64979 
64980 
64981 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
64982 
64983 XLA_AE_HEADER_PKG.SetJeCategoryName;
64984 
64988 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
64985 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
64986 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
64987 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
64989 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
64990 
64991 
64992 -- No header level analytical criteria
64993 
64994 --
64995 --accounting attribute enhancement, bug 3612931
64996 --
64997 l_trx_reversal_source := SUBSTR(g_array_event(l_event_id).array_value_char('source_81'), 1,30);
64998 
64999 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
65000    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
65001 
65002    xla_accounting_err_pkg.build_message
65003       (p_appli_s_name            => 'XLA'
65004       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
65005       ,p_token_1                 => 'ACCT_ATTR_NAME'
65006       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
65007       ,p_token_2                 => 'PRODUCT_NAME'
65008       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
65009       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
65010       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
65011       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
65012 
65013 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
65014    --
65015    -- following sets the accounting attributes needed to reverse
65016    -- accounting for a distributeion
65017    --
65018    xla_ae_lines_pkg.SetTrxReversalAttrs
65019       (p_event_id              => l_event_id
65020       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
65021       ,p_trx_reversal_source   => l_trx_reversal_source);
65022 
65023 END IF;
65024 
65025 
65026 ----------------------------------------------------------------
65027 -- 4262811 -  update the header statuses to invalid in need be
65028 ----------------------------------------------------------------
65029 --
65030 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
65031 
65032 
65033   -----------------------------------------------
65034   -- No accrual reversal for the event class/type
65035   -----------------------------------------------
65036 ----------------------------------------------------------------
65037 
65038 --
65039 -- this ends the header loop iteration for one bulk fetch
65040 --
65041 END LOOP;
65042 
65043 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
65044 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
65045 
65046 --
65047 -- insert dummy rows into lines gt table that were created due to
65048 -- transaction reversals
65049 --
65050 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
65051    l_result := XLA_AE_LINES_PKG.InsertLines;
65052 END IF;
65053 
65054 --
65055 -- reset the temp_line_num for each set of events fetched from header
65056 -- cursor rather than doing it for each new event in line cursor
65057 -- Bug 3939231
65058 --
65059 xla_ae_lines_pkg.g_temp_line_num := 0;
65060 
65061 
65062 
65063 --
65064 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
65065 --
65066 --
65067 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
65068 
65069       trace
65070          (p_msg      => 'SQL - FETCH line_cur'
65071          ,p_level    => C_LEVEL_STATEMENT
65072          ,p_module   => l_log_module);
65073 
65074 END IF;
65075 --
65076 --
65077 LOOP
65078   --
65079   FETCH line_cur BULK COLLECT INTO
65080         l_array_entity_id
65081       , l_array_legal_entity_id
65082       , l_array_entity_code
65083       , l_array_transaction_num
65084       , l_array_event_id
65085       , l_array_class_code
65086       , l_array_event_type
65087       , l_array_event_number
65088       , l_array_event_date
65089       , l_array_transaction_date
65090       , l_array_reference_num_1
65091       , l_array_reference_num_2
65092       , l_array_reference_num_3
65093       , l_array_reference_num_4
65094       , l_array_reference_char_1
65095       , l_array_reference_char_2
65096       , l_array_reference_char_3
65097       , l_array_reference_char_4
65098       , l_array_reference_date_1
65099       , l_array_reference_date_2
65100       , l_array_reference_date_3
65101       , l_array_reference_date_4
65102       , l_array_event_created_by
65103       , l_array_budgetary_control_flag
65104       , l_array_extract_line_num 
65105       , l_array_source_3
65106       , l_array_source_4
65107       , l_array_source_13
65108       , l_array_source_14
65109       , l_array_source_15
65110       , l_array_source_16
65111       , l_array_source_17
65112       , l_array_source_18
65113       , l_array_source_19
65114       , l_array_source_20
65115       , l_array_source_21
65116       , l_array_source_22
65117       , l_array_source_26
65118       , l_array_source_27
65119       , l_array_source_28
65120       , l_array_source_52
65121       , l_array_source_53
65122       , l_array_source_57
65123       , l_array_source_58
65124       , l_array_source_59
65125       , l_array_source_60
65126       , l_array_source_61
65127       , l_array_source_62
65128       , l_array_source_63
65132       , l_array_source_67
65129       , l_array_source_64
65130       , l_array_source_65
65131       , l_array_source_66
65133       LIMIT l_rows;
65134 
65135   --
65136   IF (C_LEVEL_EVENT >= g_log_level) THEN
65137             trace
65138                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
65139                ,p_level    => C_LEVEL_EVENT
65140                ,p_module   => l_log_module);
65141   END IF;
65142   --
65143   EXIT WHEN l_array_entity_id.count = 0;
65144 
65145   XLA_AE_LINES_PKG.g_rec_lines := null;
65146 
65147 --
65148 -- Bug 4458708
65149 --
65150 XLA_AE_LINES_PKG.g_LineNumber := 0;
65151 --
65152 --
65153 
65154 FOR Idx IN 1..l_array_event_id.count LOOP
65155    --
65156    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
65157    --
65158    l_event_id := l_array_event_id(idx);  -- 5648433
65159 
65160    --
65161    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
65162    --
65163 
65164    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
65165              (g_array_event(l_event_id).array_value_num('header_index'))
65166          ,'N'
65167          ) <> 'Y'
65168    THEN
65169       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
65170          trace
65171             (p_msg      => 'Trancaction revesal option is not Y '
65172             ,p_level    => C_LEVEL_STATEMENT
65173             ,p_module   => l_log_module);
65174       END IF;
65175 
65176 --
65177 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
65178 --
65179 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
65180 --
65181 -- set event info as cache for other routines to refer event attributes
65182 --
65183 
65184 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
65185    l_previous_event_id := l_event_id;
65186 
65187    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
65188       (p_application_id           => p_application_id
65189       ,p_primary_ledger_id        => p_primary_ledger_id
65190       ,p_base_ledger_id           => p_base_ledger_id
65191       ,p_target_ledger_id         => p_target_ledger_id
65192       ,p_entity_id                => l_array_entity_id(Idx)
65193       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
65194       ,p_entity_code              => l_array_entity_code(Idx)
65195       ,p_transaction_num          => l_array_transaction_num(Idx)
65196       ,p_event_id                 => l_array_event_id(Idx)
65197       ,p_event_class_code         => l_array_class_code(Idx)
65198       ,p_event_type_code          => l_array_event_type(Idx)
65199       ,p_event_number             => l_array_event_number(Idx)
65200       ,p_event_date               => l_array_event_date(Idx)
65201       ,p_transaction_date         => l_array_transaction_date(Idx)
65202       ,p_reference_num_1          => l_array_reference_num_1(Idx)
65203       ,p_reference_num_2          => l_array_reference_num_2(Idx)
65204       ,p_reference_num_3          => l_array_reference_num_3(Idx)
65205       ,p_reference_num_4          => l_array_reference_num_4(Idx)
65206       ,p_reference_char_1         => l_array_reference_char_1(Idx)
65207       ,p_reference_char_2         => l_array_reference_char_2(Idx)
65208       ,p_reference_char_3         => l_array_reference_char_3(Idx)
65209       ,p_reference_char_4         => l_array_reference_char_4(Idx)
65210       ,p_reference_date_1         => l_array_reference_date_1(Idx)
65211       ,p_reference_date_2         => l_array_reference_date_2(Idx)
65212       ,p_reference_date_3         => l_array_reference_date_3(Idx)
65213       ,p_reference_date_4         => l_array_reference_date_4(Idx)
65217 END IF;
65214       ,p_event_created_by         => l_array_event_created_by(Idx)
65215       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
65216        --
65218 
65219 
65220 
65221 --
65222 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
65223 
65224 l_acct_reversal_source := SUBSTR(NULL, 1,30);
65225 
65226 IF l_continue_with_lines THEN
65227    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
65228       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
65229 
65230       xla_accounting_err_pkg.build_message
65231          (p_appli_s_name            => 'XLA'
65232          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
65233          ,p_token_1                 => 'LINE_NUMBER'
65234          ,p_value_1                 => l_array_extract_line_num(Idx)
65235          ,p_token_2                 => 'PRODUCT_NAME'
65236          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
65237          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
65238          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
65239          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
65240 
65241    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
65242       --
65243       -- following sets the accounting attributes needed to reverse
65244       -- accounting for a distributeion
65245       --
65246 
65247       --
65248       -- 5217187
65249       --
65250       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
65251       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
65252                                        g_array_event(l_event_id).array_value_num('header_index'));
65253       --
65254       --
65255 
65256       -- No reversal code generated
65257 
65258       xla_ae_lines_pkg.SetAcctReversalAttrs
65259          (p_event_id             => l_event_id
65260          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
65261          ,p_calculate_acctd_flag => l_calculate_acctd_flag
65262          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
65263    END IF;
65264 
65265    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
65266        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
65267 
65268 --
65269 AcctLineType_61 (
65270  p_application_id  => p_application_id
65271  ,p_event_id     => l_event_id
65272  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65273  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65274  ,p_actual_flag => l_actual_flag
65275  ,p_balance_type_code => l_balance_type_code
65276  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65277  
65278  , p_source_1 => g_array_event(l_event_id).array_value_num('source_1')
65279  , p_source_6 => g_array_event(l_event_id).array_value_num('source_6')
65280  , p_source_13 => l_array_source_13(Idx)
65281  , p_source_15 => l_array_source_15(Idx)
65282  , p_source_16 => l_array_source_16(Idx)
65283  , p_source_19 => l_array_source_19(Idx)
65284  , p_source_20 => l_array_source_20(Idx)
65285  , p_source_21 => l_array_source_21(Idx)
65286  , p_source_27 => l_array_source_27(Idx)
65287  , p_source_28 => l_array_source_28(Idx)
65288  , p_source_52 => l_array_source_52(Idx)
65289  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65290  , p_source_57 => l_array_source_57(Idx)
65291  , p_source_58 => l_array_source_58(Idx)
65292  , p_source_59 => l_array_source_59(Idx)
65293  , p_source_60 => l_array_source_60(Idx)
65294  , p_source_61 => l_array_source_61(Idx)
65295  , p_source_62 => l_array_source_62(Idx)
65296  , p_source_63 => l_array_source_63(Idx)
65297  , p_source_64 => l_array_source_64(Idx)
65298  );
65299 If(l_balance_type_code = 'A') THEN
65300   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65301 END IF;
65302 
65303 --
65304 
65305 
65306 --
65307 AcctLineType_62 (
65308  p_application_id  => p_application_id
65309  ,p_event_id     => l_event_id
65310  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65311  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65312  ,p_actual_flag => l_actual_flag
65313  ,p_balance_type_code => l_balance_type_code
65314  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65315  
65316  , p_source_6 => g_array_event(l_event_id).array_value_num('source_6')
65317  , p_source_13 => l_array_source_13(Idx)
65318  , p_source_15 => l_array_source_15(Idx)
65319  , p_source_16 => l_array_source_16(Idx)
65320  , p_source_19 => l_array_source_19(Idx)
65321  , p_source_20 => l_array_source_20(Idx)
65322  , p_source_21 => l_array_source_21(Idx)
65323  , p_source_26 => l_array_source_26(Idx)
65324  , p_source_27 => l_array_source_27(Idx)
65325  , p_source_28 => l_array_source_28(Idx)
65326  , p_source_52 => l_array_source_52(Idx)
65327  , p_source_54 => g_array_event(l_event_id).array_value_char('source_54')
65328  , p_source_55 => g_array_event(l_event_id).array_value_char('source_55')
65329  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65330  , p_source_57 => l_array_source_57(Idx)
65331  , p_source_58 => l_array_source_58(Idx)
65332  , p_source_59 => l_array_source_59(Idx)
65333  , p_source_60 => l_array_source_60(Idx)
65334  , p_source_61 => l_array_source_61(Idx)
65335  , p_source_62 => l_array_source_62(Idx)
65336  , p_source_63 => l_array_source_63(Idx)
65337  , p_source_64 => l_array_source_64(Idx)
65338  );
65339 If(l_balance_type_code = 'A') THEN
65340   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65341 END IF;
65342 
65343 --
65344 
65345 
65346 --
65347 AcctLineType_63 (
65348  p_application_id  => p_application_id
65352  ,p_actual_flag => l_actual_flag
65349  ,p_event_id     => l_event_id
65350  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65351  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65353  ,p_balance_type_code => l_balance_type_code
65354  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65355  
65356  , p_source_6 => g_array_event(l_event_id).array_value_num('source_6')
65357  , p_source_13 => l_array_source_13(Idx)
65358  , p_source_15 => l_array_source_15(Idx)
65359  , p_source_16 => l_array_source_16(Idx)
65360  , p_source_19 => l_array_source_19(Idx)
65361  , p_source_20 => l_array_source_20(Idx)
65362  , p_source_21 => l_array_source_21(Idx)
65363  , p_source_27 => l_array_source_27(Idx)
65364  , p_source_28 => l_array_source_28(Idx)
65365  , p_source_52 => l_array_source_52(Idx)
65366  , p_source_54 => g_array_event(l_event_id).array_value_char('source_54')
65367  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65368  , p_source_57 => l_array_source_57(Idx)
65369  , p_source_58 => l_array_source_58(Idx)
65370  , p_source_59 => l_array_source_59(Idx)
65371  , p_source_60 => l_array_source_60(Idx)
65372  , p_source_61 => l_array_source_61(Idx)
65373  , p_source_62 => l_array_source_62(Idx)
65374  , p_source_63 => l_array_source_63(Idx)
65375  , p_source_64 => l_array_source_64(Idx)
65376  );
65377 If(l_balance_type_code = 'A') THEN
65378   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65379 END IF;
65380 
65381 --
65382 
65383 
65384 --
65385 AcctLineType_64 (
65386  p_application_id  => p_application_id
65387  ,p_event_id     => l_event_id
65388  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65389  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65390  ,p_actual_flag => l_actual_flag
65391  ,p_balance_type_code => l_balance_type_code
65392  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65393  
65394  , p_source_7 => g_array_event(l_event_id).array_value_num('source_7')
65395  , p_source_13 => l_array_source_13(Idx)
65396  , p_source_15 => l_array_source_15(Idx)
65397  , p_source_16 => l_array_source_16(Idx)
65398  , p_source_19 => l_array_source_19(Idx)
65399  , p_source_20 => l_array_source_20(Idx)
65400  , p_source_21 => l_array_source_21(Idx)
65401  , p_source_27 => l_array_source_27(Idx)
65402  , p_source_28 => l_array_source_28(Idx)
65403  , p_source_52 => l_array_source_52(Idx)
65404  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65405  , p_source_57 => l_array_source_57(Idx)
65406  , p_source_58 => l_array_source_58(Idx)
65407  , p_source_59 => l_array_source_59(Idx)
65408  , p_source_60 => l_array_source_60(Idx)
65409  , p_source_61 => l_array_source_61(Idx)
65410  , p_source_62 => l_array_source_62(Idx)
65411  , p_source_63 => l_array_source_63(Idx)
65412  , p_source_64 => l_array_source_64(Idx)
65413  );
65414 If(l_balance_type_code = 'A') THEN
65415   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65416 END IF;
65417 
65418 --
65419 
65420 
65421 --
65422 AcctLineType_65 (
65423  p_application_id  => p_application_id
65424  ,p_event_id     => l_event_id
65425  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65426  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65427  ,p_actual_flag => l_actual_flag
65428  ,p_balance_type_code => l_balance_type_code
65429  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65430  
65431  , p_source_13 => l_array_source_13(Idx)
65432  , p_source_15 => l_array_source_15(Idx)
65433  , p_source_16 => l_array_source_16(Idx)
65434  , p_source_17 => l_array_source_17(Idx)
65435  , p_source_18 => l_array_source_18(Idx)
65436  , p_source_22 => l_array_source_22(Idx)
65437  , p_source_27 => l_array_source_27(Idx)
65438  , p_source_28 => l_array_source_28(Idx)
65439  , p_source_52 => l_array_source_52(Idx)
65440  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65441  , p_source_57 => l_array_source_57(Idx)
65442  , p_source_58 => l_array_source_58(Idx)
65443  , p_source_64 => l_array_source_64(Idx)
65444  );
65445 If(l_balance_type_code = 'A') THEN
65446   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65447 END IF;
65448 
65449 --
65450 
65451 
65452 --
65453 AcctLineType_66 (
65454  p_application_id  => p_application_id
65455  ,p_event_id     => l_event_id
65456  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65457  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65458  ,p_actual_flag => l_actual_flag
65459  ,p_balance_type_code => l_balance_type_code
65460  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65461  
65462  , p_source_8 => g_array_event(l_event_id).array_value_num('source_8')
65463  , p_source_13 => l_array_source_13(Idx)
65464  , p_source_15 => l_array_source_15(Idx)
65465  , p_source_16 => l_array_source_16(Idx)
65466  , p_source_19 => l_array_source_19(Idx)
65467  , p_source_20 => l_array_source_20(Idx)
65468  , p_source_21 => l_array_source_21(Idx)
65469  , p_source_27 => l_array_source_27(Idx)
65470  , p_source_28 => l_array_source_28(Idx)
65471  , p_source_52 => l_array_source_52(Idx)
65472  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65473  , p_source_57 => l_array_source_57(Idx)
65474  , p_source_58 => l_array_source_58(Idx)
65475  , p_source_59 => l_array_source_59(Idx)
65476  , p_source_60 => l_array_source_60(Idx)
65477  , p_source_61 => l_array_source_61(Idx)
65478  , p_source_62 => l_array_source_62(Idx)
65479  , p_source_63 => l_array_source_63(Idx)
65480  , p_source_64 => l_array_source_64(Idx)
65481  );
65482 If(l_balance_type_code = 'A') THEN
65483   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65484 END IF;
65485 
65486 --
65487 
65488 
65489 --
65490 AcctLineType_67 (
65491  p_application_id  => p_application_id
65495  ,p_actual_flag => l_actual_flag
65492  ,p_event_id     => l_event_id
65493  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65494  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65496  ,p_balance_type_code => l_balance_type_code
65497  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65498  
65499  , p_source_13 => l_array_source_13(Idx)
65500  , p_source_15 => l_array_source_15(Idx)
65501  , p_source_16 => l_array_source_16(Idx)
65502  , p_source_17 => l_array_source_17(Idx)
65503  , p_source_18 => l_array_source_18(Idx)
65504  , p_source_22 => l_array_source_22(Idx)
65505  , p_source_27 => l_array_source_27(Idx)
65506  , p_source_28 => l_array_source_28(Idx)
65507  , p_source_52 => l_array_source_52(Idx)
65508  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65509  , p_source_57 => l_array_source_57(Idx)
65510  , p_source_58 => l_array_source_58(Idx)
65511  , p_source_64 => l_array_source_64(Idx)
65512  );
65513 If(l_balance_type_code = 'A') THEN
65514   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65515 END IF;
65516 
65517 --
65518 
65519 
65520 --
65521 AcctLineType_73 (
65522  p_application_id  => p_application_id
65523  ,p_event_id     => l_event_id
65524  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65525  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65526  ,p_actual_flag => l_actual_flag
65527  ,p_balance_type_code => l_balance_type_code
65528  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65529  
65530  , p_source_3 => l_array_source_3(Idx)
65531  , p_source_13 => l_array_source_13(Idx)
65532  , p_source_15 => l_array_source_15(Idx)
65533  , p_source_16 => l_array_source_16(Idx)
65534  , p_source_19 => l_array_source_19(Idx)
65535  , p_source_20 => l_array_source_20(Idx)
65536  , p_source_21 => l_array_source_21(Idx)
65537  , p_source_27 => l_array_source_27(Idx)
65538  , p_source_28 => l_array_source_28(Idx)
65539  , p_source_52 => l_array_source_52(Idx)
65540  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65541  , p_source_57 => l_array_source_57(Idx)
65542  , p_source_58 => l_array_source_58(Idx)
65543  , p_source_59 => l_array_source_59(Idx)
65544  , p_source_60 => l_array_source_60(Idx)
65545  , p_source_61 => l_array_source_61(Idx)
65546  , p_source_62 => l_array_source_62(Idx)
65547  , p_source_63 => l_array_source_63(Idx)
65548  , p_source_64 => l_array_source_64(Idx)
65549  );
65550 If(l_balance_type_code = 'A') THEN
65551   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65552 END IF;
65553 
65554 --
65555 
65556 
65557 --
65558 AcctLineType_74 (
65559  p_application_id  => p_application_id
65560  ,p_event_id     => l_event_id
65561  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65562  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65563  ,p_actual_flag => l_actual_flag
65564  ,p_balance_type_code => l_balance_type_code
65565  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65566  
65567  , p_source_4 => l_array_source_4(Idx)
65568  , p_source_6 => g_array_event(l_event_id).array_value_num('source_6')
65569  , p_source_13 => l_array_source_13(Idx)
65570  , p_source_15 => l_array_source_15(Idx)
65571  , p_source_16 => l_array_source_16(Idx)
65572  , p_source_19 => l_array_source_19(Idx)
65573  , p_source_20 => l_array_source_20(Idx)
65574  , p_source_21 => l_array_source_21(Idx)
65575  , p_source_26 => l_array_source_26(Idx)
65576  , p_source_27 => l_array_source_27(Idx)
65577  , p_source_28 => l_array_source_28(Idx)
65578  , p_source_52 => l_array_source_52(Idx)
65579  , p_source_54 => g_array_event(l_event_id).array_value_char('source_54')
65580  , p_source_55 => g_array_event(l_event_id).array_value_char('source_55')
65581  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65582  , p_source_57 => l_array_source_57(Idx)
65583  , p_source_58 => l_array_source_58(Idx)
65584  , p_source_59 => l_array_source_59(Idx)
65585  , p_source_60 => l_array_source_60(Idx)
65586  , p_source_61 => l_array_source_61(Idx)
65587  , p_source_62 => l_array_source_62(Idx)
65588  , p_source_63 => l_array_source_63(Idx)
65589  , p_source_64 => l_array_source_64(Idx)
65590  );
65591 If(l_balance_type_code = 'A') THEN
65592   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65593 END IF;
65594 
65595 --
65596 
65597 
65598 --
65599 AcctLineType_75 (
65600  p_application_id  => p_application_id
65601  ,p_event_id     => l_event_id
65602  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65603  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65604  ,p_actual_flag => l_actual_flag
65605  ,p_balance_type_code => l_balance_type_code
65606  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65607  
65608  , p_source_4 => l_array_source_4(Idx)
65609  , p_source_6 => g_array_event(l_event_id).array_value_num('source_6')
65610  , p_source_13 => l_array_source_13(Idx)
65611  , p_source_15 => l_array_source_15(Idx)
65612  , p_source_16 => l_array_source_16(Idx)
65613  , p_source_19 => l_array_source_19(Idx)
65614  , p_source_20 => l_array_source_20(Idx)
65615  , p_source_21 => l_array_source_21(Idx)
65616  , p_source_27 => l_array_source_27(Idx)
65617  , p_source_28 => l_array_source_28(Idx)
65618  , p_source_52 => l_array_source_52(Idx)
65619  , p_source_54 => g_array_event(l_event_id).array_value_char('source_54')
65620  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65621  , p_source_57 => l_array_source_57(Idx)
65622  , p_source_58 => l_array_source_58(Idx)
65623  , p_source_59 => l_array_source_59(Idx)
65624  , p_source_60 => l_array_source_60(Idx)
65625  , p_source_61 => l_array_source_61(Idx)
65626  , p_source_62 => l_array_source_62(Idx)
65627  , p_source_63 => l_array_source_63(Idx)
65628  , p_source_64 => l_array_source_64(Idx)
65629  );
65633 
65630 If(l_balance_type_code = 'A') THEN
65631   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65632 END IF;
65634 --
65635 
65636 
65637 --
65638 AcctLineType_76 (
65639  p_application_id  => p_application_id
65640  ,p_event_id     => l_event_id
65641  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65642  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65643  ,p_actual_flag => l_actual_flag
65644  ,p_balance_type_code => l_balance_type_code
65645  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65646  
65647  , p_source_4 => l_array_source_4(Idx)
65648  , p_source_7 => g_array_event(l_event_id).array_value_num('source_7')
65649  , p_source_13 => l_array_source_13(Idx)
65650  , p_source_15 => l_array_source_15(Idx)
65651  , p_source_16 => l_array_source_16(Idx)
65652  , p_source_19 => l_array_source_19(Idx)
65653  , p_source_20 => l_array_source_20(Idx)
65654  , p_source_21 => l_array_source_21(Idx)
65655  , p_source_27 => l_array_source_27(Idx)
65656  , p_source_28 => l_array_source_28(Idx)
65657  , p_source_52 => l_array_source_52(Idx)
65658  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65659  , p_source_57 => l_array_source_57(Idx)
65660  , p_source_58 => l_array_source_58(Idx)
65661  , p_source_59 => l_array_source_59(Idx)
65662  , p_source_60 => l_array_source_60(Idx)
65663  , p_source_61 => l_array_source_61(Idx)
65664  , p_source_62 => l_array_source_62(Idx)
65665  , p_source_63 => l_array_source_63(Idx)
65666  , p_source_64 => l_array_source_64(Idx)
65667  );
65668 If(l_balance_type_code = 'A') THEN
65669   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65670 END IF;
65671 
65672 --
65673 
65674 
65675 --
65676 AcctLineType_77 (
65677  p_application_id  => p_application_id
65678  ,p_event_id     => l_event_id
65679  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65680  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65681  ,p_actual_flag => l_actual_flag
65682  ,p_balance_type_code => l_balance_type_code
65683  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65684  
65685  , p_source_13 => l_array_source_13(Idx)
65686  , p_source_15 => l_array_source_15(Idx)
65687  , p_source_16 => l_array_source_16(Idx)
65688  , p_source_17 => l_array_source_17(Idx)
65689  , p_source_18 => l_array_source_18(Idx)
65690  , p_source_22 => l_array_source_22(Idx)
65691  , p_source_26 => l_array_source_26(Idx)
65692  , p_source_27 => l_array_source_27(Idx)
65693  , p_source_28 => l_array_source_28(Idx)
65694  , p_source_52 => l_array_source_52(Idx)
65695  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65696  , p_source_57 => l_array_source_57(Idx)
65697  , p_source_58 => l_array_source_58(Idx)
65698  , p_source_64 => l_array_source_64(Idx)
65699  );
65700 If(l_balance_type_code = 'A') THEN
65701   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65702 END IF;
65703 
65704 --
65705 
65706 
65707 --
65708 AcctLineType_78 (
65709  p_application_id  => p_application_id
65710  ,p_event_id     => l_event_id
65711  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65712  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65713  ,p_actual_flag => l_actual_flag
65714  ,p_balance_type_code => l_balance_type_code
65715  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65716  
65717  , p_source_4 => l_array_source_4(Idx)
65718  , p_source_8 => g_array_event(l_event_id).array_value_num('source_8')
65719  , p_source_13 => l_array_source_13(Idx)
65720  , p_source_15 => l_array_source_15(Idx)
65721  , p_source_16 => l_array_source_16(Idx)
65722  , p_source_19 => l_array_source_19(Idx)
65723  , p_source_20 => l_array_source_20(Idx)
65724  , p_source_21 => l_array_source_21(Idx)
65725  , p_source_27 => l_array_source_27(Idx)
65726  , p_source_28 => l_array_source_28(Idx)
65727  , p_source_52 => l_array_source_52(Idx)
65728  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65729  , p_source_57 => l_array_source_57(Idx)
65730  , p_source_58 => l_array_source_58(Idx)
65731  , p_source_59 => l_array_source_59(Idx)
65732  , p_source_60 => l_array_source_60(Idx)
65733  , p_source_61 => l_array_source_61(Idx)
65734  , p_source_62 => l_array_source_62(Idx)
65735  , p_source_63 => l_array_source_63(Idx)
65736  , p_source_64 => l_array_source_64(Idx)
65737  );
65738 If(l_balance_type_code = 'A') THEN
65739   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65740 END IF;
65741 
65742 --
65743 
65744 
65745 --
65746 AcctLineType_79 (
65747  p_application_id  => p_application_id
65748  ,p_event_id     => l_event_id
65749  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65750  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65751  ,p_actual_flag => l_actual_flag
65752  ,p_balance_type_code => l_balance_type_code
65753  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65754  
65755  , p_source_3 => l_array_source_3(Idx)
65756  , p_source_13 => l_array_source_13(Idx)
65757  , p_source_15 => l_array_source_15(Idx)
65758  , p_source_16 => l_array_source_16(Idx)
65759  , p_source_19 => l_array_source_19(Idx)
65760  , p_source_20 => l_array_source_20(Idx)
65761  , p_source_21 => l_array_source_21(Idx)
65762  , p_source_27 => l_array_source_27(Idx)
65763  , p_source_28 => l_array_source_28(Idx)
65764  , p_source_52 => l_array_source_52(Idx)
65765  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65766  , p_source_57 => l_array_source_57(Idx)
65767  , p_source_58 => l_array_source_58(Idx)
65768  , p_source_59 => l_array_source_59(Idx)
65769  , p_source_60 => l_array_source_60(Idx)
65770  , p_source_61 => l_array_source_61(Idx)
65771  , p_source_62 => l_array_source_62(Idx)
65772  , p_source_63 => l_array_source_63(Idx)
65773  , p_source_64 => l_array_source_64(Idx)
65777 END IF;
65774  );
65775 If(l_balance_type_code = 'A') THEN
65776   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65778 
65779 --
65780 
65781 
65782 --
65783 AcctLineType_80 (
65784  p_application_id  => p_application_id
65785  ,p_event_id     => l_event_id
65786  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65787  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65788  ,p_actual_flag => l_actual_flag
65789  ,p_balance_type_code => l_balance_type_code
65790  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65791  
65792  , p_source_3 => l_array_source_3(Idx)
65793  , p_source_13 => l_array_source_13(Idx)
65794  , p_source_15 => l_array_source_15(Idx)
65795  , p_source_16 => l_array_source_16(Idx)
65796  , p_source_19 => l_array_source_19(Idx)
65797  , p_source_20 => l_array_source_20(Idx)
65798  , p_source_21 => l_array_source_21(Idx)
65799  , p_source_27 => l_array_source_27(Idx)
65800  , p_source_28 => l_array_source_28(Idx)
65801  , p_source_52 => l_array_source_52(Idx)
65802  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65803  , p_source_57 => l_array_source_57(Idx)
65804  , p_source_58 => l_array_source_58(Idx)
65805  , p_source_59 => l_array_source_59(Idx)
65806  , p_source_60 => l_array_source_60(Idx)
65807  , p_source_61 => l_array_source_61(Idx)
65808  , p_source_62 => l_array_source_62(Idx)
65809  , p_source_63 => l_array_source_63(Idx)
65810  , p_source_64 => l_array_source_64(Idx)
65811  );
65812 If(l_balance_type_code = 'A') THEN
65813   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65814 END IF;
65815 
65816 --
65817 
65818 
65819 --
65820 AcctLineType_81 (
65821  p_application_id  => p_application_id
65822  ,p_event_id     => l_event_id
65823  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65824  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65825  ,p_actual_flag => l_actual_flag
65826  ,p_balance_type_code => l_balance_type_code
65827  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65828  
65829  , p_source_3 => l_array_source_3(Idx)
65830  , p_source_13 => l_array_source_13(Idx)
65831  , p_source_14 => l_array_source_14(Idx)
65832  , p_source_15 => l_array_source_15(Idx)
65833  , p_source_16 => l_array_source_16(Idx)
65834  , p_source_19 => l_array_source_19(Idx)
65835  , p_source_20 => l_array_source_20(Idx)
65836  , p_source_27 => l_array_source_27(Idx)
65837  , p_source_28 => l_array_source_28(Idx)
65838  , p_source_52 => l_array_source_52(Idx)
65839  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65840  , p_source_57 => l_array_source_57(Idx)
65841  , p_source_58 => l_array_source_58(Idx)
65842  , p_source_59 => l_array_source_59(Idx)
65843  , p_source_60 => l_array_source_60(Idx)
65844  , p_source_61 => l_array_source_61(Idx)
65845  , p_source_62 => l_array_source_62(Idx)
65846  , p_source_63 => l_array_source_63(Idx)
65847  , p_source_64 => l_array_source_64(Idx)
65848  , p_source_65 => l_array_source_65(Idx)
65849  );
65850 If(l_balance_type_code = 'A') THEN
65851   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65852 END IF;
65853 
65854 --
65855 
65856 
65857 --
65858 AcctLineType_82 (
65859  p_application_id  => p_application_id
65860  ,p_event_id     => l_event_id
65861  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65862  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65863  ,p_actual_flag => l_actual_flag
65864  ,p_balance_type_code => l_balance_type_code
65865  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65866  
65867  , p_source_3 => l_array_source_3(Idx)
65868  , p_source_13 => l_array_source_13(Idx)
65869  , p_source_15 => l_array_source_15(Idx)
65870  , p_source_16 => l_array_source_16(Idx)
65871  , p_source_19 => l_array_source_19(Idx)
65872  , p_source_20 => l_array_source_20(Idx)
65873  , p_source_21 => l_array_source_21(Idx)
65874  , p_source_27 => l_array_source_27(Idx)
65875  , p_source_28 => l_array_source_28(Idx)
65876  , p_source_52 => l_array_source_52(Idx)
65877  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65878  , p_source_57 => l_array_source_57(Idx)
65879  , p_source_58 => l_array_source_58(Idx)
65880  , p_source_59 => l_array_source_59(Idx)
65881  , p_source_60 => l_array_source_60(Idx)
65882  , p_source_61 => l_array_source_61(Idx)
65883  , p_source_62 => l_array_source_62(Idx)
65884  , p_source_63 => l_array_source_63(Idx)
65885  , p_source_64 => l_array_source_64(Idx)
65886  );
65887 If(l_balance_type_code = 'A') THEN
65888   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65889 END IF;
65890 
65891 --
65892 
65893 
65894 --
65895 AcctLineType_83 (
65896  p_application_id  => p_application_id
65897  ,p_event_id     => l_event_id
65898  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65899  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65900  ,p_actual_flag => l_actual_flag
65901  ,p_balance_type_code => l_balance_type_code
65902  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65903  
65904  , p_source_3 => l_array_source_3(Idx)
65905  , p_source_13 => l_array_source_13(Idx)
65906  , p_source_15 => l_array_source_15(Idx)
65907  , p_source_16 => l_array_source_16(Idx)
65908  , p_source_19 => l_array_source_19(Idx)
65909  , p_source_20 => l_array_source_20(Idx)
65910  , p_source_21 => l_array_source_21(Idx)
65911  , p_source_27 => l_array_source_27(Idx)
65912  , p_source_28 => l_array_source_28(Idx)
65916  , p_source_58 => l_array_source_58(Idx)
65913  , p_source_52 => l_array_source_52(Idx)
65914  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65915  , p_source_57 => l_array_source_57(Idx)
65917  , p_source_59 => l_array_source_59(Idx)
65918  , p_source_60 => l_array_source_60(Idx)
65919  , p_source_61 => l_array_source_61(Idx)
65920  , p_source_62 => l_array_source_62(Idx)
65921  , p_source_63 => l_array_source_63(Idx)
65922  , p_source_64 => l_array_source_64(Idx)
65923  );
65924 If(l_balance_type_code = 'A') THEN
65925   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65926 END IF;
65927 
65928 --
65929 
65930 
65931 --
65932 AcctLineType_84 (
65933  p_application_id  => p_application_id
65934  ,p_event_id     => l_event_id
65935  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65936  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65937  ,p_actual_flag => l_actual_flag
65938  ,p_balance_type_code => l_balance_type_code
65939  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65940  
65941  , p_source_3 => l_array_source_3(Idx)
65942  , p_source_13 => l_array_source_13(Idx)
65943  , p_source_15 => l_array_source_15(Idx)
65944  , p_source_16 => l_array_source_16(Idx)
65945  , p_source_19 => l_array_source_19(Idx)
65946  , p_source_20 => l_array_source_20(Idx)
65947  , p_source_21 => l_array_source_21(Idx)
65948  , p_source_27 => l_array_source_27(Idx)
65949  , p_source_28 => l_array_source_28(Idx)
65950  , p_source_52 => l_array_source_52(Idx)
65951  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65952  , p_source_57 => l_array_source_57(Idx)
65953  , p_source_58 => l_array_source_58(Idx)
65954  , p_source_59 => l_array_source_59(Idx)
65955  , p_source_60 => l_array_source_60(Idx)
65956  , p_source_61 => l_array_source_61(Idx)
65957  , p_source_62 => l_array_source_62(Idx)
65958  , p_source_63 => l_array_source_63(Idx)
65959  , p_source_64 => l_array_source_64(Idx)
65960  );
65961 If(l_balance_type_code = 'A') THEN
65962   l_actual_gain_loss_ref := l_gain_or_loss_ref;
65963 END IF;
65964 
65965 --
65966 
65967 
65968 --
65969 AcctLineType_85 (
65970  p_application_id  => p_application_id
65971  ,p_event_id     => l_event_id
65972  ,p_calculate_acctd_flag => l_calculate_acctd_flag
65973  ,p_calculate_g_l_flag => l_calculate_g_l_flag
65974  ,p_actual_flag => l_actual_flag
65975  ,p_balance_type_code => l_balance_type_code
65976  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
65977  
65978  , p_source_3 => l_array_source_3(Idx)
65979  , p_source_13 => l_array_source_13(Idx)
65980  , p_source_15 => l_array_source_15(Idx)
65981  , p_source_16 => l_array_source_16(Idx)
65982  , p_source_17 => l_array_source_17(Idx)
65983  , p_source_18 => l_array_source_18(Idx)
65984  , p_source_22 => l_array_source_22(Idx)
65985  , p_source_27 => l_array_source_27(Idx)
65986  , p_source_28 => l_array_source_28(Idx)
65987  , p_source_52 => l_array_source_52(Idx)
65988  , p_source_53 => l_array_source_53(Idx)
65989  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
65990  , p_source_57 => l_array_source_57(Idx)
65991  , p_source_58 => l_array_source_58(Idx)
65992  , p_source_62 => l_array_source_62(Idx)
65993  , p_source_63 => l_array_source_63(Idx)
65994  , p_source_64 => l_array_source_64(Idx)
65995  , p_source_65 => l_array_source_65(Idx)
65996  , p_source_66 => l_array_source_66(Idx)
65997  );
65998 If(l_balance_type_code = 'A') THEN
65999   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66000 END IF;
66001 
66002 --
66003 
66004 
66005 --
66006 AcctLineType_86 (
66007  p_application_id  => p_application_id
66008  ,p_event_id     => l_event_id
66009  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66010  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66011  ,p_actual_flag => l_actual_flag
66012  ,p_balance_type_code => l_balance_type_code
66013  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66014  
66015  , p_source_3 => l_array_source_3(Idx)
66016  , p_source_4 => l_array_source_4(Idx)
66017  , p_source_13 => l_array_source_13(Idx)
66018  , p_source_15 => l_array_source_15(Idx)
66019  , p_source_16 => l_array_source_16(Idx)
66020  , p_source_17 => l_array_source_17(Idx)
66021  , p_source_18 => l_array_source_18(Idx)
66022  , p_source_22 => l_array_source_22(Idx)
66023  , p_source_27 => l_array_source_27(Idx)
66024  , p_source_28 => l_array_source_28(Idx)
66025  , p_source_52 => l_array_source_52(Idx)
66026  , p_source_53 => l_array_source_53(Idx)
66027  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66028  , p_source_57 => l_array_source_57(Idx)
66029  , p_source_58 => l_array_source_58(Idx)
66030  , p_source_62 => l_array_source_62(Idx)
66031  , p_source_63 => l_array_source_63(Idx)
66032  , p_source_64 => l_array_source_64(Idx)
66033  , p_source_65 => l_array_source_65(Idx)
66034  , p_source_66 => l_array_source_66(Idx)
66035  );
66036 If(l_balance_type_code = 'A') THEN
66037   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66038 END IF;
66039 
66040 --
66041 
66042 
66043 --
66044 AcctLineType_87 (
66045  p_application_id  => p_application_id
66046  ,p_event_id     => l_event_id
66047  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66048  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66049  ,p_actual_flag => l_actual_flag
66050  ,p_balance_type_code => l_balance_type_code
66051  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66052  
66053  , p_source_3 => l_array_source_3(Idx)
66054  , p_source_13 => l_array_source_13(Idx)
66055  , p_source_15 => l_array_source_15(Idx)
66056  , p_source_16 => l_array_source_16(Idx)
66057  , p_source_17 => l_array_source_17(Idx)
66061  , p_source_22 => l_array_source_22(Idx)
66058  , p_source_19 => l_array_source_19(Idx)
66059  , p_source_20 => l_array_source_20(Idx)
66060  , p_source_21 => l_array_source_21(Idx)
66062  , p_source_27 => l_array_source_27(Idx)
66063  , p_source_28 => l_array_source_28(Idx)
66064  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66065  , p_source_57 => l_array_source_57(Idx)
66066  , p_source_58 => l_array_source_58(Idx)
66067  , p_source_60 => l_array_source_60(Idx)
66068  , p_source_62 => l_array_source_62(Idx)
66069  , p_source_63 => l_array_source_63(Idx)
66070  , p_source_64 => l_array_source_64(Idx)
66071  );
66072 If(l_balance_type_code = 'A') THEN
66073   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66074 END IF;
66075 
66076 --
66077 
66078 
66079 --
66080 AcctLineType_88 (
66081  p_application_id  => p_application_id
66082  ,p_event_id     => l_event_id
66083  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66084  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66085  ,p_actual_flag => l_actual_flag
66086  ,p_balance_type_code => l_balance_type_code
66087  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66088  
66089  , p_source_3 => l_array_source_3(Idx)
66090  , p_source_13 => l_array_source_13(Idx)
66091  , p_source_15 => l_array_source_15(Idx)
66092  , p_source_16 => l_array_source_16(Idx)
66093  , p_source_17 => l_array_source_17(Idx)
66094  , p_source_19 => l_array_source_19(Idx)
66095  , p_source_20 => l_array_source_20(Idx)
66096  , p_source_21 => l_array_source_21(Idx)
66097  , p_source_22 => l_array_source_22(Idx)
66098  , p_source_27 => l_array_source_27(Idx)
66099  , p_source_28 => l_array_source_28(Idx)
66100  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66101  , p_source_57 => l_array_source_57(Idx)
66102  , p_source_58 => l_array_source_58(Idx)
66103  , p_source_60 => l_array_source_60(Idx)
66104  , p_source_62 => l_array_source_62(Idx)
66105  , p_source_63 => l_array_source_63(Idx)
66106  , p_source_64 => l_array_source_64(Idx)
66107  );
66108 If(l_balance_type_code = 'A') THEN
66109   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66110 END IF;
66111 
66112 --
66113 
66114 
66115 --
66116 AcctLineType_89 (
66117  p_application_id  => p_application_id
66118  ,p_event_id     => l_event_id
66119  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66120  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66121  ,p_actual_flag => l_actual_flag
66122  ,p_balance_type_code => l_balance_type_code
66123  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66124  
66125  , p_source_3 => l_array_source_3(Idx)
66126  , p_source_13 => l_array_source_13(Idx)
66127  , p_source_15 => l_array_source_15(Idx)
66128  , p_source_16 => l_array_source_16(Idx)
66129  , p_source_19 => l_array_source_19(Idx)
66130  , p_source_20 => l_array_source_20(Idx)
66131  , p_source_21 => l_array_source_21(Idx)
66132  , p_source_27 => l_array_source_27(Idx)
66133  , p_source_28 => l_array_source_28(Idx)
66134  , p_source_52 => l_array_source_52(Idx)
66135  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66136  , p_source_57 => l_array_source_57(Idx)
66137  , p_source_58 => l_array_source_58(Idx)
66138  , p_source_59 => l_array_source_59(Idx)
66139  , p_source_60 => l_array_source_60(Idx)
66140  , p_source_61 => l_array_source_61(Idx)
66141  , p_source_62 => l_array_source_62(Idx)
66142  , p_source_63 => l_array_source_63(Idx)
66143  , p_source_64 => l_array_source_64(Idx)
66144  , p_source_67 => l_array_source_67(Idx)
66145  );
66146 If(l_balance_type_code = 'A') THEN
66147   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66148 END IF;
66149 
66150 --
66151 
66152 
66153 --
66154 AcctLineType_90 (
66155  p_application_id  => p_application_id
66156  ,p_event_id     => l_event_id
66157  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66158  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66159  ,p_actual_flag => l_actual_flag
66160  ,p_balance_type_code => l_balance_type_code
66161  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66162  
66163  , p_source_3 => l_array_source_3(Idx)
66164  , p_source_13 => l_array_source_13(Idx)
66165  , p_source_15 => l_array_source_15(Idx)
66166  , p_source_16 => l_array_source_16(Idx)
66167  , p_source_19 => l_array_source_19(Idx)
66168  , p_source_20 => l_array_source_20(Idx)
66169  , p_source_21 => l_array_source_21(Idx)
66170  , p_source_27 => l_array_source_27(Idx)
66171  , p_source_28 => l_array_source_28(Idx)
66172  , p_source_52 => l_array_source_52(Idx)
66173  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66174  , p_source_57 => l_array_source_57(Idx)
66175  , p_source_58 => l_array_source_58(Idx)
66176  , p_source_59 => l_array_source_59(Idx)
66177  , p_source_60 => l_array_source_60(Idx)
66178  , p_source_61 => l_array_source_61(Idx)
66179  , p_source_62 => l_array_source_62(Idx)
66180  , p_source_63 => l_array_source_63(Idx)
66181  , p_source_64 => l_array_source_64(Idx)
66182  , p_source_67 => l_array_source_67(Idx)
66183  );
66184 If(l_balance_type_code = 'A') THEN
66185   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66186 END IF;
66187 
66188 --
66189 
66190 
66191 --
66192 AcctLineType_91 (
66193  p_application_id  => p_application_id
66194  ,p_event_id     => l_event_id
66195  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66196  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66197  ,p_actual_flag => l_actual_flag
66198  ,p_balance_type_code => l_balance_type_code
66199  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66200  
66201  , p_source_3 => l_array_source_3(Idx)
66205  , p_source_16 => l_array_source_16(Idx)
66202  , p_source_13 => l_array_source_13(Idx)
66203  , p_source_14 => l_array_source_14(Idx)
66204  , p_source_15 => l_array_source_15(Idx)
66206  , p_source_19 => l_array_source_19(Idx)
66207  , p_source_20 => l_array_source_20(Idx)
66208  , p_source_21 => l_array_source_21(Idx)
66209  , p_source_22 => l_array_source_22(Idx)
66210  , p_source_27 => l_array_source_27(Idx)
66211  , p_source_28 => l_array_source_28(Idx)
66212  , p_source_52 => l_array_source_52(Idx)
66213  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66214  , p_source_57 => l_array_source_57(Idx)
66215  , p_source_58 => l_array_source_58(Idx)
66216  , p_source_59 => l_array_source_59(Idx)
66217  , p_source_60 => l_array_source_60(Idx)
66218  , p_source_62 => l_array_source_62(Idx)
66219  , p_source_63 => l_array_source_63(Idx)
66220  , p_source_64 => l_array_source_64(Idx)
66221  );
66222 If(l_balance_type_code = 'A') THEN
66223   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66224 END IF;
66225 
66226 --
66227 
66228 
66229 --
66230 AcctLineType_92 (
66231  p_application_id  => p_application_id
66232  ,p_event_id     => l_event_id
66233  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66234  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66235  ,p_actual_flag => l_actual_flag
66236  ,p_balance_type_code => l_balance_type_code
66237  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66238  
66239  , p_source_3 => l_array_source_3(Idx)
66240  , p_source_13 => l_array_source_13(Idx)
66241  , p_source_14 => l_array_source_14(Idx)
66242  , p_source_15 => l_array_source_15(Idx)
66243  , p_source_16 => l_array_source_16(Idx)
66244  , p_source_19 => l_array_source_19(Idx)
66245  , p_source_20 => l_array_source_20(Idx)
66246  , p_source_21 => l_array_source_21(Idx)
66247  , p_source_27 => l_array_source_27(Idx)
66248  , p_source_28 => l_array_source_28(Idx)
66249  , p_source_52 => l_array_source_52(Idx)
66250  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66251  , p_source_57 => l_array_source_57(Idx)
66252  , p_source_58 => l_array_source_58(Idx)
66253  , p_source_59 => l_array_source_59(Idx)
66254  , p_source_60 => l_array_source_60(Idx)
66255  , p_source_61 => l_array_source_61(Idx)
66256  , p_source_62 => l_array_source_62(Idx)
66257  , p_source_63 => l_array_source_63(Idx)
66258  , p_source_64 => l_array_source_64(Idx)
66259  );
66260 If(l_balance_type_code = 'A') THEN
66261   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66262 END IF;
66263 
66264 --
66265 
66266 
66267 --
66268 AcctLineType_93 (
66269  p_application_id  => p_application_id
66270  ,p_event_id     => l_event_id
66271  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66272  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66273  ,p_actual_flag => l_actual_flag
66274  ,p_balance_type_code => l_balance_type_code
66275  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66276  
66277  , p_source_3 => l_array_source_3(Idx)
66278  , p_source_13 => l_array_source_13(Idx)
66279  , p_source_14 => l_array_source_14(Idx)
66280  , p_source_15 => l_array_source_15(Idx)
66281  , p_source_16 => l_array_source_16(Idx)
66282  , p_source_19 => l_array_source_19(Idx)
66283  , p_source_20 => l_array_source_20(Idx)
66284  , p_source_21 => l_array_source_21(Idx)
66285  , p_source_27 => l_array_source_27(Idx)
66286  , p_source_28 => l_array_source_28(Idx)
66287  , p_source_52 => l_array_source_52(Idx)
66288  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66289  , p_source_57 => l_array_source_57(Idx)
66290  , p_source_58 => l_array_source_58(Idx)
66291  , p_source_59 => l_array_source_59(Idx)
66292  , p_source_60 => l_array_source_60(Idx)
66293  , p_source_61 => l_array_source_61(Idx)
66294  , p_source_62 => l_array_source_62(Idx)
66295  , p_source_63 => l_array_source_63(Idx)
66296  , p_source_64 => l_array_source_64(Idx)
66297  );
66298 If(l_balance_type_code = 'A') THEN
66299   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66300 END IF;
66301 
66302 --
66303 
66304 
66305 --
66306 AcctLineType_94 (
66307  p_application_id  => p_application_id
66308  ,p_event_id     => l_event_id
66309  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66310  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66311  ,p_actual_flag => l_actual_flag
66312  ,p_balance_type_code => l_balance_type_code
66313  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66314  
66315  , p_source_3 => l_array_source_3(Idx)
66316  , p_source_13 => l_array_source_13(Idx)
66317  , p_source_15 => l_array_source_15(Idx)
66318  , p_source_16 => l_array_source_16(Idx)
66319  , p_source_19 => l_array_source_19(Idx)
66320  , p_source_20 => l_array_source_20(Idx)
66321  , p_source_21 => l_array_source_21(Idx)
66322  , p_source_27 => l_array_source_27(Idx)
66323  , p_source_28 => l_array_source_28(Idx)
66324  , p_source_52 => l_array_source_52(Idx)
66325  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66326  , p_source_57 => l_array_source_57(Idx)
66327  , p_source_58 => l_array_source_58(Idx)
66328  , p_source_59 => l_array_source_59(Idx)
66329  , p_source_60 => l_array_source_60(Idx)
66330  , p_source_61 => l_array_source_61(Idx)
66331  , p_source_62 => l_array_source_62(Idx)
66332  , p_source_63 => l_array_source_63(Idx)
66333  , p_source_64 => l_array_source_64(Idx)
66334  , p_source_67 => l_array_source_67(Idx)
66335  );
66336 If(l_balance_type_code = 'A') THEN
66337   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66338 END IF;
66339 
66340 --
66341 
66342 
66343 --
66344 AcctLineType_95 (
66348  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66345  p_application_id  => p_application_id
66346  ,p_event_id     => l_event_id
66347  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66349  ,p_actual_flag => l_actual_flag
66350  ,p_balance_type_code => l_balance_type_code
66351  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66352  
66353  , p_source_3 => l_array_source_3(Idx)
66354  , p_source_13 => l_array_source_13(Idx)
66355  , p_source_15 => l_array_source_15(Idx)
66356  , p_source_16 => l_array_source_16(Idx)
66357  , p_source_19 => l_array_source_19(Idx)
66358  , p_source_20 => l_array_source_20(Idx)
66359  , p_source_21 => l_array_source_21(Idx)
66360  , p_source_27 => l_array_source_27(Idx)
66361  , p_source_28 => l_array_source_28(Idx)
66362  , p_source_52 => l_array_source_52(Idx)
66363  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66364  , p_source_57 => l_array_source_57(Idx)
66365  , p_source_58 => l_array_source_58(Idx)
66366  , p_source_59 => l_array_source_59(Idx)
66367  , p_source_60 => l_array_source_60(Idx)
66368  , p_source_61 => l_array_source_61(Idx)
66369  , p_source_62 => l_array_source_62(Idx)
66370  , p_source_63 => l_array_source_63(Idx)
66371  , p_source_64 => l_array_source_64(Idx)
66372  , p_source_67 => l_array_source_67(Idx)
66373  );
66374 If(l_balance_type_code = 'A') THEN
66375   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66376 END IF;
66377 
66378 --
66379 
66380 
66381 --
66382 AcctLineType_96 (
66383  p_application_id  => p_application_id
66384  ,p_event_id     => l_event_id
66385  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66386  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66387  ,p_actual_flag => l_actual_flag
66388  ,p_balance_type_code => l_balance_type_code
66389  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66390  
66391  , p_source_3 => l_array_source_3(Idx)
66392  , p_source_13 => l_array_source_13(Idx)
66393  , p_source_15 => l_array_source_15(Idx)
66394  , p_source_16 => l_array_source_16(Idx)
66395  , p_source_17 => l_array_source_17(Idx)
66396  , p_source_18 => l_array_source_18(Idx)
66397  , p_source_22 => l_array_source_22(Idx)
66398  , p_source_27 => l_array_source_27(Idx)
66399  , p_source_28 => l_array_source_28(Idx)
66400  , p_source_52 => l_array_source_52(Idx)
66401  , p_source_53 => l_array_source_53(Idx)
66402  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66403  , p_source_57 => l_array_source_57(Idx)
66404  , p_source_58 => l_array_source_58(Idx)
66405  , p_source_62 => l_array_source_62(Idx)
66406  , p_source_63 => l_array_source_63(Idx)
66407  , p_source_64 => l_array_source_64(Idx)
66408  , p_source_65 => l_array_source_65(Idx)
66409  , p_source_66 => l_array_source_66(Idx)
66410  );
66411 If(l_balance_type_code = 'A') THEN
66412   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66413 END IF;
66414 
66415 --
66416 
66417 
66418 --
66419 AcctLineType_97 (
66420  p_application_id  => p_application_id
66421  ,p_event_id     => l_event_id
66422  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66423  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66424  ,p_actual_flag => l_actual_flag
66425  ,p_balance_type_code => l_balance_type_code
66426  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66427  
66428  , p_source_10 => g_array_event(l_event_id).array_value_num('source_10')
66429  , p_source_13 => l_array_source_13(Idx)
66430  , p_source_14 => l_array_source_14(Idx)
66431  , p_source_15 => l_array_source_15(Idx)
66432  , p_source_16 => l_array_source_16(Idx)
66433  , p_source_19 => l_array_source_19(Idx)
66434  , p_source_20 => l_array_source_20(Idx)
66435  , p_source_21 => l_array_source_21(Idx)
66436  , p_source_27 => l_array_source_27(Idx)
66437  , p_source_28 => l_array_source_28(Idx)
66438  , p_source_52 => l_array_source_52(Idx)
66439  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66440  , p_source_57 => l_array_source_57(Idx)
66441  , p_source_58 => l_array_source_58(Idx)
66442  , p_source_59 => l_array_source_59(Idx)
66443  , p_source_60 => l_array_source_60(Idx)
66444  , p_source_61 => l_array_source_61(Idx)
66445  , p_source_64 => l_array_source_64(Idx)
66446  , p_source_67 => l_array_source_67(Idx)
66447  , p_source_68 => g_array_event(l_event_id).array_value_num('source_68')
66448  , p_source_69 => g_array_event(l_event_id).array_value_num('source_69')
66449  );
66450 If(l_balance_type_code = 'A') THEN
66451   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66452 END IF;
66453 
66454 --
66455 
66456 
66457 --
66458 AcctLineType_98 (
66459  p_application_id  => p_application_id
66460  ,p_event_id     => l_event_id
66461  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66462  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66463  ,p_actual_flag => l_actual_flag
66464  ,p_balance_type_code => l_balance_type_code
66465  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66466  
66467  , p_source_10 => g_array_event(l_event_id).array_value_num('source_10')
66468  , p_source_13 => l_array_source_13(Idx)
66469  , p_source_15 => l_array_source_15(Idx)
66470  , p_source_16 => l_array_source_16(Idx)
66471  , p_source_19 => l_array_source_19(Idx)
66472  , p_source_20 => l_array_source_20(Idx)
66473  , p_source_21 => l_array_source_21(Idx)
66474  , p_source_27 => l_array_source_27(Idx)
66475  , p_source_28 => l_array_source_28(Idx)
66476  , p_source_52 => l_array_source_52(Idx)
66477  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66478  , p_source_57 => l_array_source_57(Idx)
66479  , p_source_58 => l_array_source_58(Idx)
66480  , p_source_59 => l_array_source_59(Idx)
66484  , p_source_67 => l_array_source_67(Idx)
66481  , p_source_60 => l_array_source_60(Idx)
66482  , p_source_61 => l_array_source_61(Idx)
66483  , p_source_64 => l_array_source_64(Idx)
66485  , p_source_68 => g_array_event(l_event_id).array_value_num('source_68')
66486  , p_source_69 => g_array_event(l_event_id).array_value_num('source_69')
66487  , p_source_70 => g_array_event(l_event_id).array_value_char('source_70')
66488  );
66489 If(l_balance_type_code = 'A') THEN
66490   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66491 END IF;
66492 
66493 --
66494 
66495 
66496 --
66497 AcctLineType_99 (
66498  p_application_id  => p_application_id
66499  ,p_event_id     => l_event_id
66500  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66501  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66502  ,p_actual_flag => l_actual_flag
66503  ,p_balance_type_code => l_balance_type_code
66504  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66505  
66506  , p_source_3 => l_array_source_3(Idx)
66507  , p_source_4 => l_array_source_4(Idx)
66508  , p_source_13 => l_array_source_13(Idx)
66509  , p_source_15 => l_array_source_15(Idx)
66510  , p_source_16 => l_array_source_16(Idx)
66511  , p_source_17 => l_array_source_17(Idx)
66512  , p_source_18 => l_array_source_18(Idx)
66513  , p_source_22 => l_array_source_22(Idx)
66514  , p_source_27 => l_array_source_27(Idx)
66515  , p_source_28 => l_array_source_28(Idx)
66516  , p_source_52 => l_array_source_52(Idx)
66517  , p_source_53 => l_array_source_53(Idx)
66518  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66519  , p_source_57 => l_array_source_57(Idx)
66520  , p_source_58 => l_array_source_58(Idx)
66521  , p_source_62 => l_array_source_62(Idx)
66522  , p_source_63 => l_array_source_63(Idx)
66523  , p_source_64 => l_array_source_64(Idx)
66524  , p_source_65 => l_array_source_65(Idx)
66525  , p_source_66 => l_array_source_66(Idx)
66526  );
66527 If(l_balance_type_code = 'A') THEN
66528   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66529 END IF;
66530 
66531 --
66532 
66533 
66534 --
66535 AcctLineType_100 (
66536  p_application_id  => p_application_id
66537  ,p_event_id     => l_event_id
66538  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66539  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66540  ,p_actual_flag => l_actual_flag
66541  ,p_balance_type_code => l_balance_type_code
66542  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66543  
66544  , p_source_3 => l_array_source_3(Idx)
66545  , p_source_13 => l_array_source_13(Idx)
66546  , p_source_15 => l_array_source_15(Idx)
66547  , p_source_16 => l_array_source_16(Idx)
66548  , p_source_19 => l_array_source_19(Idx)
66549  , p_source_20 => l_array_source_20(Idx)
66550  , p_source_21 => l_array_source_21(Idx)
66551  , p_source_27 => l_array_source_27(Idx)
66552  , p_source_28 => l_array_source_28(Idx)
66553  , p_source_52 => l_array_source_52(Idx)
66554  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66555  , p_source_57 => l_array_source_57(Idx)
66556  , p_source_58 => l_array_source_58(Idx)
66557  , p_source_59 => l_array_source_59(Idx)
66558  , p_source_60 => l_array_source_60(Idx)
66559  , p_source_61 => l_array_source_61(Idx)
66560  , p_source_62 => l_array_source_62(Idx)
66561  , p_source_63 => l_array_source_63(Idx)
66562  , p_source_64 => l_array_source_64(Idx)
66563  );
66564 If(l_balance_type_code = 'A') THEN
66565   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66566 END IF;
66567 
66568 --
66569 
66570 
66571 --
66572 AcctLineType_101 (
66573  p_application_id  => p_application_id
66574  ,p_event_id     => l_event_id
66575  ,p_calculate_acctd_flag => l_calculate_acctd_flag
66576  ,p_calculate_g_l_flag => l_calculate_g_l_flag
66577  ,p_actual_flag => l_actual_flag
66578  ,p_balance_type_code => l_balance_type_code
66579  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
66580  
66581  , p_source_3 => l_array_source_3(Idx)
66582  , p_source_13 => l_array_source_13(Idx)
66583  , p_source_14 => l_array_source_14(Idx)
66584  , p_source_15 => l_array_source_15(Idx)
66585  , p_source_16 => l_array_source_16(Idx)
66586  , p_source_19 => l_array_source_19(Idx)
66587  , p_source_20 => l_array_source_20(Idx)
66588  , p_source_21 => l_array_source_21(Idx)
66589  , p_source_27 => l_array_source_27(Idx)
66590  , p_source_28 => l_array_source_28(Idx)
66591  , p_source_52 => l_array_source_52(Idx)
66592  , p_source_56 => g_array_event(l_event_id).array_value_num('source_56')
66593  , p_source_57 => l_array_source_57(Idx)
66594  , p_source_58 => l_array_source_58(Idx)
66595  , p_source_59 => l_array_source_59(Idx)
66596  , p_source_60 => l_array_source_60(Idx)
66597  , p_source_61 => l_array_source_61(Idx)
66598  , p_source_62 => l_array_source_62(Idx)
66599  , p_source_63 => l_array_source_63(Idx)
66600  , p_source_64 => l_array_source_64(Idx)
66601  );
66602 If(l_balance_type_code = 'A') THEN
66603   l_actual_gain_loss_ref := l_gain_or_loss_ref;
66604 END IF;
66605 
66606 --
66607 
66608       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
66609       -- or secondary ledger that has different currency with primary
66610       -- or alc that is calculated by sla
66611       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
66612             (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'))
66613 
66614 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
66615 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
66616           AND (l_actual_flag = 'A')) THEN
66617         XLA_AE_LINES_PKG.CreateGainOrLossLines(
66618           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
66619          ,p_application_id   => p_application_id
66620          ,p_amb_context_code => 'DEFAULT'
66621          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
66622          ,p_event_class_code => C_EVENT_CLASS_CODE
66623          ,p_event_type_code  => C_EVENT_TYPE_CODE
66624          
66625          ,p_gain_ccid        => TO_NUMBER(g_array_event(l_event_id).array_value_num('source_11'))
66626          ,p_loss_ccid        => TO_NUMBER(g_array_event(l_event_id).array_value_num('source_12'))
66627 
66628          ,p_actual_flag      => l_actual_flag
66629          ,p_enc_flag         => null
66630          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
66631          ,p_enc_g_l_ref      => null
66632          );
66633       END IF;
66634    END IF;
66635 END IF;
66636 
66637    ELSE
66638       --
66639       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
66640       --
66641       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
66642          trace
66643             (p_msg      => 'Trancaction revesal option is Y'
66644             ,p_level    => C_LEVEL_STATEMENT
66645             ,p_module   => l_log_module);
66646       END IF;
66647    END IF;
66648 
66649 END LOOP;
66650 l_result := XLA_AE_LINES_PKG.InsertLines ;
66651 end loop;
66652 close line_cur;
66653 
66654 
66655 --
66656 -- insert headers into xla_ae_headers_gt table
66657 --
66658 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
66659 
66660 -- insert into errors table here.
66661 
66662 END LOOP;
66663 
66664 --
66665 -- 4865292
66666 --
66667 -- Compare g_hdr_extract_count with event count in
66668 -- CreateHeadersAndLines.
66669 --
66670 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
66671 
66672 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
66673    trace (p_msg     => '# rows extracted from header extract objects '
66674                     || ' (running total): '
66675                     || g_hdr_extract_count
66676          ,p_level   => C_LEVEL_STATEMENT
66677          ,p_module  => l_log_module);
66678 END IF;
66679 
66680 CLOSE header_cur;
66681 --
66682 
66683 --
66684 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
66685    trace
66686       (p_msg      => 'END of EventClass_110'
66687       ,p_level    => C_LEVEL_PROCEDURE
66688       ,p_module   => l_log_module);
66689 END IF;
66690 --
66691 RETURN l_result;
66692 EXCEPTION
66693 WHEN xla_exceptions_pkg.application_exception THEN
66694    
66695 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
66696 
66697    
66698 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
66699 
66700    RAISE;
66701 
66702 WHEN NO_DATA_FOUND THEN
66703 
66704 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
66705 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
66706 
66707 FOR header_record IN header_cur
66708 LOOP
66709     l_array_header_events(header_record.event_id) := header_record.event_id;
66710 END LOOP;
66711 
66712 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
66713 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
66714 
66715 fnd_file.put_line(fnd_file.LOG, '                    ');
66716 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
66717 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
66718 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
66719 
66720 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
66721 LOOP
66722 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
66723 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
66724         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
66725 	END IF;
66726 END LOOP;
66727 
66728 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
66729 fnd_file.put_line(fnd_file.LOG, '                    ');
66730 
66731 
66732 xla_exceptions_pkg.raise_message
66733       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_110');
66734 
66735 
66736 WHEN OTHERS THEN
66737    xla_exceptions_pkg.raise_message
66738       (p_location => 'XLA_00222_AAD_S_000008_PKG.EventClass_110');
66739 END EventClass_110;
66740 --
66741 
66742 --
66743 --+============================================+
66744 --|                                            |
66745 --|  PRIVATE FUNCTION                          |
66746 --|                                            |
66747 --+============================================+
66748 --
66749 FUNCTION CreateHeadersAndLines
66750        (p_application_id         IN NUMBER
66751        ,p_base_ledger_id         IN NUMBER
66752        ,p_target_ledger_id       IN NUMBER
66753        ,p_pad_start_date         IN DATE
66754        ,p_pad_end_date           IN DATE
66755        ,p_primary_ledger_id      IN NUMBER)
66759 l_event_date                DATE;
66756 RETURN BOOLEAN IS
66757 l_created                   BOOLEAN:=FALSE;
66758 l_event_id                  NUMBER;
66760 l_language                  VARCHAR2(30);
66761 l_currency_code             VARCHAR2(30);
66762 l_sla_ledger_id             NUMBER;
66763 l_log_module                VARCHAR2(240);
66764 
66765 BEGIN
66766 --
66767 IF g_log_enabled THEN
66768    l_log_module := C_DEFAULT_MODULE||'.CreateHeadersAndLines';
66769 END IF;
66770 --
66771 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
66772    trace
66773       (p_msg      => 'BEGIN of CreateHeadersAndLines'
66774       ,p_level    => C_LEVEL_PROCEDURE
66775       ,p_module   => l_log_module);
66776 END IF;
66777 
66778 l_language         := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
66779 l_currency_code    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.currency_code;
66780 l_sla_ledger_id    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.sla_ledger_id;
66781 
66782 --
66783 -- initialize array of lines with NULL
66784 --
66785 xla_ae_lines_pkg.SetNullLine;
66786 
66787 --
66788 -- initialize header extract count -- Bug 4865292
66789 --
66790 g_hdr_extract_count:= 0;
66791 
66792 
66793 l_created := EventClass_102(
66794    p_application_id         => p_application_id
66795  , p_base_ledger_id         => p_base_ledger_id
66796  , p_target_ledger_id       => p_target_ledger_id
66797  , p_language               => l_language
66798  , p_currency_code          => l_currency_code
66799  , p_sla_ledger_id          => l_sla_ledger_id
66800  , p_pad_start_date         => p_pad_start_date
66801  , p_pad_end_date           => p_pad_end_date
66802  , p_primary_ledger_id      => p_primary_ledger_id
66803 );
66804 
66805 
66806 
66807      IF ( g_diagnostics_mode ='Y' ) THEN
66808 
66809          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
66810           trace
66811               (p_msg      => 'CALL Transaction Objects Diagnostics'
66812               ,p_level    => C_LEVEL_STATEMENT
66813               ,p_module   => l_log_module);
66814 
66815          END IF;
66816 
66817          insert_sources_102(
66818                           p_target_ledger_id => p_target_ledger_id
66819                         , p_language         => l_language
66820                         , p_sla_ledger_id    => l_sla_ledger_id
66821                         , p_pad_start_date   => p_pad_start_date
66822                         , p_pad_end_date     => p_pad_end_date
66823                           );
66824 
66825      END IF;
66826 
66827 l_created := EventClass_103(
66828    p_application_id         => p_application_id
66829  , p_base_ledger_id         => p_base_ledger_id
66830  , p_target_ledger_id       => p_target_ledger_id
66831  , p_language               => l_language
66832  , p_currency_code          => l_currency_code
66833  , p_sla_ledger_id          => l_sla_ledger_id
66834  , p_pad_start_date         => p_pad_start_date
66835  , p_pad_end_date           => p_pad_end_date
66836  , p_primary_ledger_id      => p_primary_ledger_id
66837 );
66838 
66839 
66840 
66841      IF ( g_diagnostics_mode ='Y' ) THEN
66842 
66843          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
66844           trace
66845               (p_msg      => 'CALL Transaction Objects Diagnostics'
66846               ,p_level    => C_LEVEL_STATEMENT
66847               ,p_module   => l_log_module);
66848 
66849          END IF;
66850 
66851          insert_sources_103(
66852                           p_target_ledger_id => p_target_ledger_id
66853                         , p_language         => l_language
66854                         , p_sla_ledger_id    => l_sla_ledger_id
66855                         , p_pad_start_date   => p_pad_start_date
66856                         , p_pad_end_date     => p_pad_end_date
66857                           );
66858 
66859      END IF;
66860 
66861 l_created := EventClass_104(
66862    p_application_id         => p_application_id
66863  , p_base_ledger_id         => p_base_ledger_id
66864  , p_target_ledger_id       => p_target_ledger_id
66865  , p_language               => l_language
66866  , p_currency_code          => l_currency_code
66867  , p_sla_ledger_id          => l_sla_ledger_id
66868  , p_pad_start_date         => p_pad_start_date
66869  , p_pad_end_date           => p_pad_end_date
66870  , p_primary_ledger_id      => p_primary_ledger_id
66871 );
66872 
66873 
66874 
66875      IF ( g_diagnostics_mode ='Y' ) THEN
66876 
66877          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
66878           trace
66879               (p_msg      => 'CALL Transaction Objects Diagnostics'
66880               ,p_level    => C_LEVEL_STATEMENT
66881               ,p_module   => l_log_module);
66882 
66883          END IF;
66884 
66885          insert_sources_104(
66886                           p_target_ledger_id => p_target_ledger_id
66887                         , p_language         => l_language
66888                         , p_sla_ledger_id    => l_sla_ledger_id
66889                         , p_pad_start_date   => p_pad_start_date
66890                         , p_pad_end_date     => p_pad_end_date
66891                           );
66892 
66893      END IF;
66894 
66895 l_created := EventClass_105(
66896    p_application_id         => p_application_id
66897  , p_base_ledger_id         => p_base_ledger_id
66898  , p_target_ledger_id       => p_target_ledger_id
66899  , p_language               => l_language
66900  , p_currency_code          => l_currency_code
66901  , p_sla_ledger_id          => l_sla_ledger_id
66902  , p_pad_start_date         => p_pad_start_date
66903  , p_pad_end_date           => p_pad_end_date
66904  , p_primary_ledger_id      => p_primary_ledger_id
66905 );
66906 
66907 
66908 
66909      IF ( g_diagnostics_mode ='Y' ) THEN
66910 
66911          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
66912           trace
66913               (p_msg      => 'CALL Transaction Objects Diagnostics'
66914               ,p_level    => C_LEVEL_STATEMENT
66915               ,p_module   => l_log_module);
66916 
66917          END IF;
66918 
66919          insert_sources_105(
66920                           p_target_ledger_id => p_target_ledger_id
66921                         , p_language         => l_language
66922                         , p_sla_ledger_id    => l_sla_ledger_id
66923                         , p_pad_start_date   => p_pad_start_date
66924                         , p_pad_end_date     => p_pad_end_date
66925                           );
66926 
66927      END IF;
66928 
66929 l_created := EventClass_106(
66930    p_application_id         => p_application_id
66931  , p_base_ledger_id         => p_base_ledger_id
66932  , p_target_ledger_id       => p_target_ledger_id
66933  , p_language               => l_language
66934  , p_currency_code          => l_currency_code
66935  , p_sla_ledger_id          => l_sla_ledger_id
66936  , p_pad_start_date         => p_pad_start_date
66937  , p_pad_end_date           => p_pad_end_date
66938  , p_primary_ledger_id      => p_primary_ledger_id
66939 );
66940 
66941 
66942 
66943      IF ( g_diagnostics_mode ='Y' ) THEN
66944 
66945          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
66946           trace
66947               (p_msg      => 'CALL Transaction Objects Diagnostics'
66948               ,p_level    => C_LEVEL_STATEMENT
66949               ,p_module   => l_log_module);
66950 
66951          END IF;
66952 
66953          insert_sources_106(
66954                           p_target_ledger_id => p_target_ledger_id
66955                         , p_language         => l_language
66956                         , p_sla_ledger_id    => l_sla_ledger_id
66957                         , p_pad_start_date   => p_pad_start_date
66958                         , p_pad_end_date     => p_pad_end_date
66959                           );
66960 
66961      END IF;
66962 
66963 l_created := EventClass_107(
66964    p_application_id         => p_application_id
66965  , p_base_ledger_id         => p_base_ledger_id
66966  , p_target_ledger_id       => p_target_ledger_id
66967  , p_language               => l_language
66968  , p_currency_code          => l_currency_code
66969  , p_sla_ledger_id          => l_sla_ledger_id
66970  , p_pad_start_date         => p_pad_start_date
66971  , p_pad_end_date           => p_pad_end_date
66972  , p_primary_ledger_id      => p_primary_ledger_id
66973 );
66974 
66975 
66976 
66977      IF ( g_diagnostics_mode ='Y' ) THEN
66978 
66979          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
66980           trace
66981               (p_msg      => 'CALL Transaction Objects Diagnostics'
66982               ,p_level    => C_LEVEL_STATEMENT
66983               ,p_module   => l_log_module);
66984 
66985          END IF;
66986 
66987          insert_sources_107(
66988                           p_target_ledger_id => p_target_ledger_id
66989                         , p_language         => l_language
66990                         , p_sla_ledger_id    => l_sla_ledger_id
66991                         , p_pad_start_date   => p_pad_start_date
66992                         , p_pad_end_date     => p_pad_end_date
66993                           );
66994 
66995      END IF;
66996 
66997 l_created := EventClass_108(
66998    p_application_id         => p_application_id
66999  , p_base_ledger_id         => p_base_ledger_id
67000  , p_target_ledger_id       => p_target_ledger_id
67001  , p_language               => l_language
67002  , p_currency_code          => l_currency_code
67003  , p_sla_ledger_id          => l_sla_ledger_id
67004  , p_pad_start_date         => p_pad_start_date
67005  , p_pad_end_date           => p_pad_end_date
67006  , p_primary_ledger_id      => p_primary_ledger_id
67007 );
67008 
67009 
67010 
67011      IF ( g_diagnostics_mode ='Y' ) THEN
67012 
67013          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
67014           trace
67015               (p_msg      => 'CALL Transaction Objects Diagnostics'
67016               ,p_level    => C_LEVEL_STATEMENT
67017               ,p_module   => l_log_module);
67018 
67019          END IF;
67020 
67021          insert_sources_108(
67022                           p_target_ledger_id => p_target_ledger_id
67023                         , p_language         => l_language
67024                         , p_sla_ledger_id    => l_sla_ledger_id
67025                         , p_pad_start_date   => p_pad_start_date
67026                         , p_pad_end_date     => p_pad_end_date
67027                           );
67028 
67029      END IF;
67030 
67031 l_created := EventClass_109(
67032    p_application_id         => p_application_id
67033  , p_base_ledger_id         => p_base_ledger_id
67034  , p_target_ledger_id       => p_target_ledger_id
67035  , p_language               => l_language
67036  , p_currency_code          => l_currency_code
67037  , p_sla_ledger_id          => l_sla_ledger_id
67038  , p_pad_start_date         => p_pad_start_date
67039  , p_pad_end_date           => p_pad_end_date
67040  , p_primary_ledger_id      => p_primary_ledger_id
67041 );
67042 
67043 
67044 
67045      IF ( g_diagnostics_mode ='Y' ) THEN
67046 
67047          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
67048           trace
67049               (p_msg      => 'CALL Transaction Objects Diagnostics'
67050               ,p_level    => C_LEVEL_STATEMENT
67051               ,p_module   => l_log_module);
67052 
67053          END IF;
67054 
67055          insert_sources_109(
67056                           p_target_ledger_id => p_target_ledger_id
67057                         , p_language         => l_language
67058                         , p_sla_ledger_id    => l_sla_ledger_id
67059                         , p_pad_start_date   => p_pad_start_date
67060                         , p_pad_end_date     => p_pad_end_date
67061                           );
67062 
67063      END IF;
67064 
67065 l_created := EventClass_110(
67066    p_application_id         => p_application_id
67067  , p_base_ledger_id         => p_base_ledger_id
67068  , p_target_ledger_id       => p_target_ledger_id
67069  , p_language               => l_language
67070  , p_currency_code          => l_currency_code
67071  , p_sla_ledger_id          => l_sla_ledger_id
67072  , p_pad_start_date         => p_pad_start_date
67073  , p_pad_end_date           => p_pad_end_date
67074  , p_primary_ledger_id      => p_primary_ledger_id
67075 );
67076 
67077 
67078 
67079      IF ( g_diagnostics_mode ='Y' ) THEN
67080 
67081          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
67082           trace
67083               (p_msg      => 'CALL Transaction Objects Diagnostics'
67084               ,p_level    => C_LEVEL_STATEMENT
67085               ,p_module   => l_log_module);
67086 
67087          END IF;
67088 
67089          insert_sources_110(
67090                           p_target_ledger_id => p_target_ledger_id
67091                         , p_language         => l_language
67092                         , p_sla_ledger_id    => l_sla_ledger_id
67093                         , p_pad_start_date   => p_pad_start_date
67094                         , p_pad_end_date     => p_pad_end_date
67095                           );
67096 
67097      END IF;
67098 
67099 
67100  --
67101  -- Bug 4865292
67102  -- When the number of events and that of header extract do not match,
67103  -- set the no header extract flag to indicate there are some issues
67104  -- in header extract.
67105  --
67106  -- Event count context is set in xla_accounting_pkg.unit_processor.
67107  -- Build_Message for this error is called in xla_accounting_pkg.post_accounting
67108  -- to report it as a general error.
67109  --
67110  IF  xla_context_pkg.get_event_count_context <> g_hdr_extract_count
67111  AND xla_context_pkg.get_event_nohdr_context <> 'Y' THEN
67112 
67113      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
67114         trace
67115           (p_msg      => '# of extracted headers and events does not match'
67116           ,p_level    => C_LEVEL_STATEMENT
67117           ,p_module   => l_log_module);
67118 
67119         trace
67120           (p_msg      => '# of extracted headers: '
67121                          ||g_hdr_extract_count
67122           ,p_level    => C_LEVEL_STATEMENT
67123           ,p_module   => l_log_module);
67124 
67125         trace
67126           (p_msg      => '# of events in xla_events_gt: '
67127                          ||xla_context_pkg.get_event_count_context
67128           ,p_level    => C_LEVEL_STATEMENT
67129           ,p_module   => l_log_module);
67130 
67131         trace
67132           (p_msg      => 'Event No Header Extract Context: '
67133                          ||xla_context_pkg.get_event_nohdr_context
67134           ,p_level    => C_LEVEL_STATEMENT
67135           ,p_module   => l_log_module);
67136 
67137      END IF;
67138 
67139 
67140      xla_context_pkg.set_event_nohdr_context
67141        (p_nohdr_extract_flag => 'Y'
67142        ,p_client_id => sys_context('USERENV','CLIENT_IDENTIFIER'));
67143 
67144      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
67145         trace
67146           (p_msg      => 'No Header Extract Flag is set to Y'
67147           ,p_level    => C_LEVEL_STATEMENT
67148           ,p_module   => l_log_module);
67149      END IF;
67150 
67151  END IF;
67152 
67153 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
67154    trace
67155       (p_msg      => 'END of CreateHeadersAndLines'
67156       ,p_level    => C_LEVEL_PROCEDURE
67157       ,p_module   => l_log_module);
67158 END IF;
67159 
67160 RETURN l_created;
67161 EXCEPTION
67162 WHEN xla_exceptions_pkg.application_exception THEN
67163    RAISE;
67164 WHEN OTHERS THEN
67165    xla_exceptions_pkg.raise_message
67166       (p_location => 'XLA_00222_AAD_S_000008_PKG.CreateHeadersAndLines');
67167 END CreateHeadersAndLines;
67168 --
67169 --
67170 
67171 --
67172 --+============================================+
67173 --|                                            |
67174 --|  PUBLIC FUNCTION                           |
67175 --|                                            |
67176 --+============================================+
67177 --
67178 FUNCTION CreateJournalEntries
67179        (p_application_id         IN NUMBER
67180        ,p_base_ledger_id         IN NUMBER
67181        ,p_pad_start_date         IN DATE
67182        ,p_pad_end_date           IN DATE
67183        ,p_primary_ledger_id      IN NUMBER)
67184 RETURN NUMBER IS
67185 l_log_module                   VARCHAR2(240);
67186 l_array_ledgers                xla_accounting_cache_pkg.t_array_ledger_id;
67187 l_temp_result                  BOOLEAN;
67188 l_result                       NUMBER;
67189 BEGIN
67190 --
67191 IF g_log_enabled THEN
67192    l_log_module := C_DEFAULT_MODULE||'.CreateJournalEntries';
67193 END IF;
67194 --
67195 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
67196    trace
67197       (p_msg      => 'BEGIN of CreateJournalEntries'||
67198                      ' - p_base_ledger_id = '||TO_CHAR(p_base_ledger_id)
67199       ,p_level    => C_LEVEL_PROCEDURE
67200       ,p_module   => l_log_module);
67201 
67202 END IF;
67203 
67204 --
67205 g_diagnostics_mode:= xla_accounting_engine_pkg.g_diagnostics_mode;
67206 
67207 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
67208    trace
67209       (p_msg      => 'g_diagnostics_mode = '||g_diagnostics_mode
67210       ,p_level    => C_LEVEL_STATEMENT
67211       ,p_module   => l_log_module);
67212 END IF;
67213 --
67214 xla_ae_journal_entry_pkg.SetProductAcctDefinition
67215    (p_product_rule_code      => 'MFAR_ACCRUAL_BALANCING'
67216    ,p_product_rule_type_code => 'S'
67217    ,p_product_rule_version   => ''
67218    ,p_product_rule_name      => 'Multi-Fund Account Receivables Accrual - Balancing Method'
67219    ,p_amb_context_code       => 'DEFAULT'
67220    );
67221 
67222 l_array_ledgers :=
67223    xla_ae_journal_entry_pkg.GetAlternateCurrencyLedger
67224       (p_base_ledger_id  => p_base_ledger_id);
67225 
67226 FOR Idx IN 1 .. l_array_ledgers.COUNT LOOP
67227    l_temp_result :=
67228       XLA_AE_JOURNAL_ENTRY_PKG.GetLedgersInfo
67229          (p_application_id           => p_application_id
67230          ,p_base_ledger_id           => p_base_ledger_id
67231          ,p_target_ledger_id         => l_array_ledgers(Idx)
67232          ,p_primary_ledger_id        => p_primary_ledger_id
67233          ,p_pad_start_date           => p_pad_start_date
67234          ,p_pad_end_date             => p_pad_end_date);
67235 
67236    l_temp_result :=
67237       l_temp_result AND
67238       CreateHeadersAndLines
67239          (p_application_id             => p_application_id
67240          ,p_base_ledger_id             => p_base_ledger_id
67241          ,p_target_ledger_id           => l_array_ledgers(Idx)
67242          ,p_pad_start_date             => p_pad_start_date
67243          ,p_pad_end_date               => p_pad_end_date
67244          ,p_primary_ledger_id          => p_primary_ledger_id
67245          );
67246 END LOOP;
67247 
67248 
67249 IF (g_diagnostics_mode = 'Y' AND
67250     C_LEVEL_UNEXPECTED >= g_log_level AND
67251     xla_environment_pkg.g_Req_Id IS NOT NULL ) THEN
67252 
67253    xla_accounting_dump_pkg.acctg_event_extract_log(
67254     p_application_id  => p_application_id
67255     ,p_request_id     => xla_environment_pkg.g_Req_Id
67256    );
67257 
67258 END IF;
67259 
67260 CASE l_temp_result
67261   WHEN TRUE THEN l_result := 0;
67262   ELSE l_result := 2;
67263 END CASE;
67264 
67265 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
67266    trace
67267       (p_msg      => 'return value. = '||TO_CHAR(l_result)
67268       ,p_level    => C_LEVEL_PROCEDURE
67269       ,p_module   => l_log_module);
67270    trace
67271       (p_msg      => 'END of CreateJournalEntries '
67272       ,p_level    => C_LEVEL_PROCEDURE
67273       ,p_module   => l_log_module);
67274 END IF;
67275 
67276 RETURN l_result;
67277 EXCEPTION
67278 WHEN xla_exceptions_pkg.application_exception THEN
67279    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
67280    trace
67281       (p_msg      => 'ERROR. = '||sqlerrm
67282       ,p_level    => C_LEVEL_PROCEDURE
67283       ,p_module   => l_log_module);
67284    END IF;
67285    RAISE;
67286 WHEN OTHERS THEN
67287    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
67288    trace
67289       (p_msg      => 'ERROR. = '||sqlerrm
67290       ,p_level    => C_LEVEL_PROCEDURE
67291       ,p_module   => l_log_module);
67292    END IF;
67293    xla_exceptions_pkg.raise_message
67294       (p_location => 'XLA_00222_AAD_S_000008_PKG.CreateJournalEntries');
67295 END CreateJournalEntries;
67296 --
67297 --=============================================================================
67298 --
67299 --
67300 --
67301 --
67302 --
67303 --
67304 --
67305 --
67306 --
67307 --
67308 --
67309 --
67310 --
67311 --
67312 --
67313 --
67314 --
67315 --
67316 --
67317 --
67318 --
67319 --
67320 --=============================================================================
67321 --=============================================================================
67322 --          *********** Initialization routine **********
67323 --=============================================================================
67324 
67325 BEGIN
67326    g_log_level      := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
67327    g_log_enabled    := fnd_log.test
67328                           (log_level  => g_log_level
67329                           ,module     => C_DEFAULT_MODULE);
67330 
67331    IF NOT g_log_enabled  THEN
67332       g_log_level := C_LEVEL_LOG_DISABLED;
67333    END IF;
67334 --
67335 END XLA_00222_AAD_S_000008_PKG;
67336 --