DBA Data[Home] [Help]

PACKAGE BODY: APPS.XLA_00222_AAD_S_000004_PKG

Source


1 PACKAGE BODY XLA_00222_AAD_S_000004_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_000004_PKG                                        |
10 |                                                                       |
11 | DESCRIPTION                                                           |
12 |     Package generated From Product Accounting Definition              |
13 |      Name    : Receivables Default Cash Basis Accounting Definition   |
14 |      Code    : AR_DEFAULT_CASH                                        |
15 |      Owner   : PRODUCT                                                |
16 |      Version :                                                        |
17 |      AMB Context Code: DEFAULT                                        |
18 | HISTORY                                                               |
19 |     Generated at 30-03-2009 at 05:03:00 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_000004_PKG';
82 
83 C_CHAR                CONSTANT       VARCHAR2(30) := fnd_global.local_chr(12); -- 4219869 Business flow
84 C_NUM                 CONSTANT       NUMBER       := 9.99E125;                 -- 4219869 Business flow
85 
86 g_log_level           NUMBER;
87 g_log_enabled         BOOLEAN;
88 
89 PROCEDURE trace
90            (p_msg                        IN VARCHAR2
91            ,p_level                      IN NUMBER
92            ,p_module                     IN VARCHAR2 ) IS
93 BEGIN
94 ----------------------------------------------------------------------------
95 -- Following is for FND log.
96 ----------------------------------------------------------------------------
97 IF (p_msg IS NULL AND p_level >= g_log_level) THEN
98           fnd_log.message(p_level, p_module);
99 ELSIF p_level >= g_log_level THEN
100           fnd_log.string(p_level, p_module, p_msg);
101 END IF;
102 
103 EXCEPTION
104        WHEN xla_exceptions_pkg.application_exception THEN
105           RAISE;
106        WHEN OTHERS THEN
107           xla_exceptions_pkg.raise_message
108              (p_location   => 'XLA_00222_AAD_S_000004_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_000004_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_000004_PKG.GetMeaning');
228 END GetMeaning;
229 --
230 
231 ---------------------------------------
232 --
233 -- PRIVATE FUNCTION
234 --         AcctDerRule_1
235 --
236 ---------------------------------------
237 FUNCTION AcctDerRule_1 (
238   p_application_id              IN NUMBER
239 , p_ae_header_id                IN NUMBER
240 , p_side                        IN VARCHAR2 
241 --Distribution GL Account
242  , p_source_1            IN NUMBER
243 , x_transaction_coa_id         OUT NOCOPY NUMBER
244 , x_accounting_coa_id          OUT NOCOPY NUMBER
245 , x_value_type_code            OUT NOCOPY VARCHAR2
246 )
247 RETURN NUMBER
248 IS
249 l_component_type       VARCHAR2(80)  ;
250 l_component_code       VARCHAR2(30)  ;
251 l_component_type_code  VARCHAR2(1)   ;
252 l_component_appl_id    INTEGER       ;
253 l_amb_context_code     VARCHAR2(30)  ;
254 l_log_module           VARCHAR2(240) ;
255 l_output_value         NUMBER        ;
256 BEGIN
257 IF g_log_enabled THEN
258       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_1';
259 END IF;
260 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
261       trace
262          (p_msg      => 'BEGIN of AcctDerRule_1'
263          ,p_level    => C_LEVEL_PROCEDURE
264          ,p_module   => l_log_module);
265 END IF;
266 --
267 l_component_type         := 'AMB_ADR';
268 l_component_code         := 'DIST_CCID';
269 l_component_type_code    := 'S';
270 l_component_appl_id      :=  222;
271 l_amb_context_code       := 'DEFAULT';
272 x_transaction_coa_id     :=  null;
273 x_accounting_coa_id      :=  null;
274 --
275 
276  --
277   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
278       trace
279          (p_msg      => 'END of AcctDerRule_1'
280          ,p_level    => C_LEVEL_PROCEDURE
281          ,p_module   => l_log_module);
282   END IF;
283   x_value_type_code := 'S';
284   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_1));
285   RETURN l_output_value;
286 
287 --
288 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
289       trace
290          (p_msg      => 'END of AcctDerRule_1(invalid)'
291          ,p_level    => C_LEVEL_PROCEDURE
292          ,p_module   => l_log_module);
293 END IF;
294 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
295 x_value_type_code := null;
296 l_output_value    := null;
297 xla_accounting_err_pkg.build_message
298                  (p_appli_s_name            => 'XLA'
299                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
300                  ,p_token_1                 => 'COMPONENT_NAME'
301                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
302                                                             l_component_type
303                                                           , l_component_code
304                                                           , l_component_type_code
305                                                           , l_component_appl_id
306                                                           , l_amb_context_code
307                                                           )
308                  ,p_token_2                 => 'OWNER'
309                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
310                                                         'XLA_OWNER_TYPE'
311                                                         ,l_component_type_code
312                                                         )
313                  ,p_token_3                 => 'PAD_NAME'
314                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
315                  ,p_token_4                 => 'PAD_OWNER'
316                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
317                                                         'XLA_OWNER_TYPE'
318                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
319                                                         )
320                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
321                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
322                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
323                  ,p_ae_header_id            => NULL
324 );
325 RETURN l_output_value;
326 EXCEPTION
327   WHEN xla_exceptions_pkg.application_exception THEN
328       RAISE;
329   WHEN OTHERS THEN
330        xla_exceptions_pkg.raise_message
331            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctDerRule_1');
332 END AcctDerRule_1;
333 --
334 
335 ---------------------------------------
336 --
337 -- PRIVATE FUNCTION
338 --         AcctDerRule_2
339 --
340 ---------------------------------------
341 FUNCTION AcctDerRule_2 (
342   p_application_id              IN NUMBER
343 , p_ae_header_id                IN NUMBER
344 , p_side                        IN VARCHAR2 
345 --Remittance Bank Account Unapplied Account
349 , x_value_type_code            OUT NOCOPY VARCHAR2
346  , p_source_2            IN NUMBER
347 , x_transaction_coa_id         OUT NOCOPY NUMBER
348 , x_accounting_coa_id          OUT NOCOPY NUMBER
350 )
351 RETURN NUMBER
352 IS
353 l_component_type       VARCHAR2(80)  ;
354 l_component_code       VARCHAR2(30)  ;
355 l_component_type_code  VARCHAR2(1)   ;
356 l_component_appl_id    INTEGER       ;
357 l_amb_context_code     VARCHAR2(30)  ;
358 l_log_module           VARCHAR2(240) ;
359 l_output_value         NUMBER        ;
360 BEGIN
361 IF g_log_enabled THEN
362       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_2';
363 END IF;
364 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
365       trace
366          (p_msg      => 'BEGIN of AcctDerRule_2'
367          ,p_level    => C_LEVEL_PROCEDURE
368          ,p_module   => l_log_module);
369 END IF;
370 --
371 l_component_type         := 'AMB_ADR';
372 l_component_code         := 'RMT_BNK_UNAPP_CCID';
373 l_component_type_code    := 'S';
374 l_component_appl_id      :=  222;
375 l_amb_context_code       := 'DEFAULT';
376 x_transaction_coa_id     :=  null;
377 x_accounting_coa_id      :=  null;
378 --
379 
380  --
381   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
382       trace
383          (p_msg      => 'END of AcctDerRule_2'
384          ,p_level    => C_LEVEL_PROCEDURE
385          ,p_module   => l_log_module);
386   END IF;
387   x_value_type_code := 'S';
388   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_2));
389   RETURN l_output_value;
390 
391 --
392 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
393       trace
394          (p_msg      => 'END of AcctDerRule_2(invalid)'
395          ,p_level    => C_LEVEL_PROCEDURE
396          ,p_module   => l_log_module);
397 END IF;
398 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
399 x_value_type_code := null;
400 l_output_value    := null;
401 xla_accounting_err_pkg.build_message
402                  (p_appli_s_name            => 'XLA'
403                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
404                  ,p_token_1                 => 'COMPONENT_NAME'
405                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
406                                                             l_component_type
407                                                           , l_component_code
408                                                           , l_component_type_code
409                                                           , l_component_appl_id
410                                                           , l_amb_context_code
411                                                           )
412                  ,p_token_2                 => 'OWNER'
413                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
414                                                         'XLA_OWNER_TYPE'
415                                                         ,l_component_type_code
416                                                         )
417                  ,p_token_3                 => 'PAD_NAME'
418                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
419                  ,p_token_4                 => 'PAD_OWNER'
420                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
421                                                         'XLA_OWNER_TYPE'
422                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
423                                                         )
424                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
425                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
426                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
427                  ,p_ae_header_id            => NULL
428 );
429 RETURN l_output_value;
430 EXCEPTION
431   WHEN xla_exceptions_pkg.application_exception THEN
432       RAISE;
433   WHEN OTHERS THEN
434        xla_exceptions_pkg.raise_message
435            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctDerRule_2');
436 END AcctDerRule_2;
437 --
438 
439 ---------------------------------------
440 --
441 -- PRIVATE FUNCTION
442 --         AcctDerRule_3
443 --
444 ---------------------------------------
445 FUNCTION AcctDerRule_3 (
446   p_application_id              IN NUMBER
447 , p_ae_header_id                IN NUMBER
448 , p_side                        IN VARCHAR2 
449 --System Gain Account
450  , p_source_3            IN NUMBER
451 , x_transaction_coa_id         OUT NOCOPY NUMBER
452 , x_accounting_coa_id          OUT NOCOPY NUMBER
453 , x_value_type_code            OUT NOCOPY VARCHAR2
454 )
455 RETURN NUMBER
456 IS
457 l_component_type       VARCHAR2(80)  ;
458 l_component_code       VARCHAR2(30)  ;
459 l_component_type_code  VARCHAR2(1)   ;
460 l_component_appl_id    INTEGER       ;
461 l_amb_context_code     VARCHAR2(30)  ;
462 l_log_module           VARCHAR2(240) ;
463 l_output_value         NUMBER        ;
464 BEGIN
465 IF g_log_enabled THEN
466       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_3';
467 END IF;
468 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
472          ,p_module   => l_log_module);
469       trace
470          (p_msg      => 'BEGIN of AcctDerRule_3'
471          ,p_level    => C_LEVEL_PROCEDURE
473 END IF;
474 --
475 l_component_type         := 'AMB_ADR';
476 l_component_code         := 'SYS_GAIN_CCID';
477 l_component_type_code    := 'S';
478 l_component_appl_id      :=  222;
479 l_amb_context_code       := 'DEFAULT';
480 x_transaction_coa_id     :=  null;
481 x_accounting_coa_id      :=  null;
482 --
483 
484  --
485   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
486       trace
487          (p_msg      => 'END of AcctDerRule_3'
488          ,p_level    => C_LEVEL_PROCEDURE
489          ,p_module   => l_log_module);
490   END IF;
491   x_value_type_code := 'S';
492   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_3));
493   RETURN l_output_value;
494 
495 --
496 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
497       trace
498          (p_msg      => 'END of AcctDerRule_3(invalid)'
499          ,p_level    => C_LEVEL_PROCEDURE
500          ,p_module   => l_log_module);
501 END IF;
502 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
503 x_value_type_code := null;
504 l_output_value    := null;
505 xla_accounting_err_pkg.build_message
506                  (p_appli_s_name            => 'XLA'
507                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
508                  ,p_token_1                 => 'COMPONENT_NAME'
509                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
510                                                             l_component_type
511                                                           , l_component_code
512                                                           , l_component_type_code
513                                                           , l_component_appl_id
514                                                           , l_amb_context_code
515                                                           )
516                  ,p_token_2                 => 'OWNER'
517                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
518                                                         'XLA_OWNER_TYPE'
519                                                         ,l_component_type_code
520                                                         )
521                  ,p_token_3                 => 'PAD_NAME'
522                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
523                  ,p_token_4                 => 'PAD_OWNER'
524                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
525                                                         'XLA_OWNER_TYPE'
526                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
527                                                         )
528                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
529                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
530                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
531                  ,p_ae_header_id            => NULL
532 );
533 RETURN l_output_value;
534 EXCEPTION
535   WHEN xla_exceptions_pkg.application_exception THEN
536       RAISE;
537   WHEN OTHERS THEN
538        xla_exceptions_pkg.raise_message
539            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctDerRule_3');
540 END AcctDerRule_3;
541 --
542 
543 ---------------------------------------
544 --
545 -- PRIVATE FUNCTION
546 --         AcctDerRule_4
547 --
548 ---------------------------------------
549 FUNCTION AcctDerRule_4 (
550   p_application_id              IN NUMBER
551 , p_ae_header_id                IN NUMBER
552 , p_side                        IN VARCHAR2 
553 --System Loss Account
554  , p_source_4            IN NUMBER
555 , x_transaction_coa_id         OUT NOCOPY NUMBER
556 , x_accounting_coa_id          OUT NOCOPY NUMBER
557 , x_value_type_code            OUT NOCOPY VARCHAR2
558 )
559 RETURN NUMBER
560 IS
561 l_component_type       VARCHAR2(80)  ;
562 l_component_code       VARCHAR2(30)  ;
563 l_component_type_code  VARCHAR2(1)   ;
564 l_component_appl_id    INTEGER       ;
565 l_amb_context_code     VARCHAR2(30)  ;
566 l_log_module           VARCHAR2(240) ;
567 l_output_value         NUMBER        ;
568 BEGIN
569 IF g_log_enabled THEN
570       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_4';
571 END IF;
572 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
573       trace
574          (p_msg      => 'BEGIN of AcctDerRule_4'
575          ,p_level    => C_LEVEL_PROCEDURE
576          ,p_module   => l_log_module);
577 END IF;
578 --
579 l_component_type         := 'AMB_ADR';
580 l_component_code         := 'SYS_LOSS_CCID';
581 l_component_type_code    := 'S';
582 l_component_appl_id      :=  222;
583 l_amb_context_code       := 'DEFAULT';
584 x_transaction_coa_id     :=  null;
585 x_accounting_coa_id      :=  null;
586 --
587 
588  --
589   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
590       trace
591          (p_msg      => 'END of AcctDerRule_4'
592          ,p_level    => C_LEVEL_PROCEDURE
596   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_4));
593          ,p_module   => l_log_module);
594   END IF;
595   x_value_type_code := 'S';
597   RETURN l_output_value;
598 
599 --
600 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
601       trace
602          (p_msg      => 'END of AcctDerRule_4(invalid)'
603          ,p_level    => C_LEVEL_PROCEDURE
604          ,p_module   => l_log_module);
605 END IF;
606 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
607 x_value_type_code := null;
608 l_output_value    := null;
609 xla_accounting_err_pkg.build_message
610                  (p_appli_s_name            => 'XLA'
611                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
612                  ,p_token_1                 => 'COMPONENT_NAME'
613                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
614                                                             l_component_type
615                                                           , l_component_code
616                                                           , l_component_type_code
617                                                           , l_component_appl_id
618                                                           , l_amb_context_code
619                                                           )
620                  ,p_token_2                 => 'OWNER'
621                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
622                                                         'XLA_OWNER_TYPE'
623                                                         ,l_component_type_code
624                                                         )
625                  ,p_token_3                 => 'PAD_NAME'
626                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
627                  ,p_token_4                 => 'PAD_OWNER'
628                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
629                                                         'XLA_OWNER_TYPE'
630                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
631                                                         )
632                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
633                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
634                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
635                  ,p_ae_header_id            => NULL
636 );
637 RETURN l_output_value;
638 EXCEPTION
639   WHEN xla_exceptions_pkg.application_exception THEN
640       RAISE;
641   WHEN OTHERS THEN
642        xla_exceptions_pkg.raise_message
643            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctDerRule_4');
644 END AcctDerRule_4;
645 --
646 
647 ---------------------------------------
648 --
649 -- PRIVATE FUNCTION
650 --         AcctDerRule_5
651 --
652 ---------------------------------------
653 FUNCTION AcctDerRule_5 (
654   p_application_id              IN NUMBER
655 , p_ae_header_id                IN NUMBER
656 , p_side                        IN VARCHAR2 
657 --Transaction Distribution GL Account
658  , p_source_5            IN NUMBER
659 --Reference distribution GL Account
660  , p_source_6            IN NUMBER
661 , x_transaction_coa_id         OUT NOCOPY NUMBER
662 , x_accounting_coa_id          OUT NOCOPY NUMBER
663 , x_value_type_code            OUT NOCOPY VARCHAR2
664 )
665 RETURN NUMBER
666 IS
667 l_component_type       VARCHAR2(80)  ;
668 l_component_code       VARCHAR2(30)  ;
669 l_component_type_code  VARCHAR2(1)   ;
670 l_component_appl_id    INTEGER       ;
671 l_amb_context_code     VARCHAR2(30)  ;
672 l_log_module           VARCHAR2(240) ;
673 l_output_value         NUMBER        ;
674 BEGIN
675 IF g_log_enabled THEN
676       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_5';
677 END IF;
678 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
679       trace
680          (p_msg      => 'BEGIN of AcctDerRule_5'
681          ,p_level    => C_LEVEL_PROCEDURE
682          ,p_module   => l_log_module);
683 END IF;
684 --
685 l_component_type         := 'AMB_ADR';
686 l_component_code         := 'TRX_REF_DIST_CCID';
687 l_component_type_code    := 'S';
688 l_component_appl_id      :=  222;
689 l_amb_context_code       := 'DEFAULT';
690 x_transaction_coa_id     :=  null;
691 x_accounting_coa_id      :=  null;
692 --
693 
694  --
695   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
696       trace
697          (p_msg      => 'END of AcctDerRule_5'
698          ,p_level    => C_LEVEL_PROCEDURE
699          ,p_module   => l_log_module);
700   END IF;
701   x_value_type_code := 'S';
702   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_5));
703   RETURN l_output_value;
704 
705  --
706   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
707       trace
708          (p_msg      => 'END of AcctDerRule_5'
709          ,p_level    => C_LEVEL_PROCEDURE
710          ,p_module   => l_log_module);
711   END IF;
712   x_value_type_code := 'S';
713   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_6));
714   RETURN l_output_value;
715 
716 --
720          ,p_level    => C_LEVEL_PROCEDURE
717 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
718       trace
719          (p_msg      => 'END of AcctDerRule_5(invalid)'
721          ,p_module   => l_log_module);
722 END IF;
723 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
724 x_value_type_code := null;
725 l_output_value    := null;
726 xla_accounting_err_pkg.build_message
727                  (p_appli_s_name            => 'XLA'
728                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
729                  ,p_token_1                 => 'COMPONENT_NAME'
730                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
731                                                             l_component_type
732                                                           , l_component_code
733                                                           , l_component_type_code
734                                                           , l_component_appl_id
735                                                           , l_amb_context_code
736                                                           )
737                  ,p_token_2                 => 'OWNER'
738                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
739                                                         'XLA_OWNER_TYPE'
740                                                         ,l_component_type_code
741                                                         )
742                  ,p_token_3                 => 'PAD_NAME'
743                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
744                  ,p_token_4                 => 'PAD_OWNER'
745                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
746                                                         'XLA_OWNER_TYPE'
747                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
748                                                         )
749                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
750                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
751                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
752                  ,p_ae_header_id            => NULL
753 );
754 RETURN l_output_value;
755 EXCEPTION
756   WHEN xla_exceptions_pkg.application_exception THEN
757       RAISE;
758   WHEN OTHERS THEN
759        xla_exceptions_pkg.raise_message
760            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctDerRule_5');
761 END AcctDerRule_5;
762 --
763 
764 ---------------------------------------
765 --
766 -- PRIVATE FUNCTION
767 --         AcctLineType_6
768 --
769 ---------------------------------------
770 PROCEDURE AcctLineType_6 (
771   p_application_id        IN NUMBER
772  ,p_event_id              IN NUMBER
773  ,p_calculate_acctd_flag  IN VARCHAR2
774  ,p_calculate_g_l_flag    IN VARCHAR2
775  ,p_actual_flag           IN OUT VARCHAR2
776  ,p_balance_type_code     OUT VARCHAR2
777  ,p_gain_or_loss_ref      OUT VARCHAR2
778  
779 --Distribution GL Account
780  , p_source_1            IN NUMBER
781 --Distribution Source Type
782  , p_source_7            IN VARCHAR2
783 --Distribution Multi Fund Additional Entry
784  , p_source_8            IN VARCHAR2
785 --Distribution Line Identifier
786  , p_source_9            IN NUMBER
787 --Distribution Type
788  , p_source_10            IN VARCHAR2
789 --Entered Amount
790  , p_source_11            IN NUMBER
791 --Currency Code
792  , p_source_12            IN VARCHAR2
793 --Applied To Document Exchange Date
794  , p_source_13            IN DATE
795 --Exchange Rate
796  , p_source_14            IN NUMBER
797 --Exchange Rate Type
798  , p_source_15            IN VARCHAR2
799 --Applied To Document Accounting Amount
800  , p_source_16            IN NUMBER
801 )
802 IS
803 
804 l_component_type              VARCHAR2(80);
805 l_component_code              VARCHAR2(30);
806 l_component_type_code         VARCHAR2(1);
807 l_component_appl_id           INTEGER;
808 l_amb_context_code            VARCHAR2(30);
809 l_entity_code                 VARCHAR2(30);
810 l_event_class_code            VARCHAR2(30);
811 l_ae_header_id                NUMBER;
812 l_event_type_code             VARCHAR2(30);
813 l_line_definition_code        VARCHAR2(30);
814 l_line_definition_owner_code  VARCHAR2(1);
815 --
816 -- adr variables
817 l_segment                     VARCHAR2(30);
818 l_ccid                        NUMBER;
819 l_adr_transaction_coa_id      NUMBER;
820 l_adr_accounting_coa_id       NUMBER;
821 l_adr_flexfield_segment_code  VARCHAR2(30);
822 l_adr_flex_value_set_id       NUMBER;
823 l_adr_value_type_code         VARCHAR2(30);
824 l_adr_value_combination_id    NUMBER;
825 l_adr_value_segment_code      VARCHAR2(30);
826 
827 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
828 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
829 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
830 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
831 
835 l_acc_rev_flag                VARCHAR2(1);
832 -- 4262811 Variables ------------------------------------------------------------------------------------------
833 l_entered_amt_idx             NUMBER;
834 l_accted_amt_idx              NUMBER;
836 l_accrual_line_num            NUMBER;
837 l_tmp_amt                     NUMBER;
838 l_acc_rev_natural_side_code   VARCHAR2(1);
839 
840 l_num_entries                 NUMBER;
841 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
842 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
843 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
844 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
845 l_recog_line_1                NUMBER;
846 l_recog_line_2                NUMBER;
847 
848 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
849 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
850 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
851 
852 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
853 
854 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
855 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
856 
857 ---------------------------------------------------------------------------------------------------------------
858 
859 
860 --
861 -- bulk performance
862 --
863 l_balance_type_code           VARCHAR2(1);
864 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
865 l_log_module                  VARCHAR2(240);
866 
867 --
868 -- Upgrade strategy
869 --
870 l_actual_upg_option           VARCHAR2(1);
871 l_enc_upg_option           VARCHAR2(1);
872 
873 --
874 BEGIN
875 --
876 IF g_log_enabled THEN
877       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_6';
878 END IF;
879 --
880 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
881 
882       trace
883          (p_msg      => 'BEGIN of AcctLineType_6'
884          ,p_level    => C_LEVEL_PROCEDURE
885          ,p_module   => l_log_module);
886 
887 END IF;
888 --
889 l_component_type             := 'AMB_JLT';
890 l_component_code             := 'MISC_RCT_BNK_CHG';
891 l_component_type_code        := 'S';
892 l_component_appl_id          :=  222;
893 l_amb_context_code           := 'DEFAULT';
894 l_entity_code                := 'RECEIPTS';
895 l_event_class_code           := 'MISC_RECEIPT';
896 l_event_type_code            := 'MISC_RECEIPT_ALL';
897 l_line_definition_owner_code := 'S';
898 l_line_definition_code       := 'AR_MISC_RECEIPTS';
899 --
900 l_balance_type_code          := 'A';
901 l_segment                     := NULL;
902 l_ccid                        := NULL;
903 l_adr_transaction_coa_id      := NULL;
904 l_adr_accounting_coa_id       := NULL;
905 l_adr_flexfield_segment_code  := NULL;
906 l_adr_flex_value_set_id       := NULL;
907 l_adr_value_type_code         := NULL;
908 l_adr_value_combination_id    := NULL;
909 l_adr_value_segment_code      := NULL;
910 
911 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
912 l_bflow_class_code           := '';    -- 4219869 Business Flow
913 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
914 l_budgetary_control_flag     := 'N';
915 
916 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
917 l_bflow_applied_to_amt       := NULL; -- 5132302
918 l_entered_amt_idx            := NULL;          -- 4262811
919 l_accted_amt_idx             := NULL;          -- 4262811
920 l_acc_rev_flag               := NULL;          -- 4262811
921 l_accrual_line_num           := NULL;          -- 4262811
922 l_tmp_amt                    := NULL;          -- 4262811
923 --
924  
925 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
926     l_balance_type_code <> 'B' THEN
927 IF NVL(p_source_7,'
928 ') =  'BANK_CHARGES' AND 
929 NVL(p_source_8,'
930 ') =  'N'
931  THEN 
932 
933    --
934    XLA_AE_LINES_PKG.SetNewLine;
935 
936    p_balance_type_code          := l_balance_type_code;
937    -- set the flag so later we will know whether the gain loss line needs to be created
938    
939    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
940      p_actual_flag :='A';
941    END IF;
942 
943    --
944    -- bulk performance
945    --
946    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
947                                       p_header_num   => 0); -- 4262811
948    --
949    -- set accounting line options
950    --
951    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
952            p_natural_side_code          => 'C'
953          , p_gain_or_loss_flag          => 'N'
954          , p_gl_transfer_mode_code      => 'S'
955          , p_acct_entry_type_code       => 'A'
956          , p_switch_side_flag           => 'Y'
957          , p_merge_duplicate_code       => 'A'
958          );
959    --
960    l_acc_rev_natural_side_code := 'D';  -- 4262811
961    -- 
962    --
963    -- set accounting line type info
964    --
965    xla_ae_lines_pkg.SetAcctLineType
969       ,p_line_definition_code       => l_line_definition_code
966       (p_component_type             => l_component_type
967       ,p_event_type_code            => l_event_type_code
968       ,p_line_definition_owner_code => l_line_definition_owner_code
970       ,p_accounting_line_code       => l_component_code
971       ,p_accounting_line_type_code  => l_component_type_code
972       ,p_accounting_line_appl_id    => l_component_appl_id
973       ,p_amb_context_code           => l_amb_context_code
974       ,p_entity_code                => l_entity_code
975       ,p_event_class_code           => l_event_class_code);
976    --
977    -- set accounting class
978    --
979    xla_ae_lines_pkg.SetAcctClass(
980            p_accounting_class_code  => 'BANK_CHG'
981          , p_ae_header_id           => l_ae_header_id
982          );
983 
984    --
985    -- set rounding class
986    --
987    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
988                       'RECEIVABLE';
989 
990    --
991    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
992    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
993    --
994    -- bulk performance
995    --
996    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
997 
998    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
999       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
1000 
1001    -- 4955764
1002    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1003       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
1004 
1005    -- 4458381 Public Sector Enh
1006    
1007    --
1008    -- set accounting attributes for the line type
1009    --
1010    l_entered_amt_idx := 3;
1011    l_accted_amt_idx  := 8;
1012    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
1013    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
1014    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
1015    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
1016    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
1017    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
1018    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
1019    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
1020    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
1021    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
1022    l_rec_acct_attrs.array_date_value(5)  := p_source_13;
1023    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
1024    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
1025    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
1026    l_rec_acct_attrs.array_char_value(7)  := p_source_15;
1027    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
1028    l_rec_acct_attrs.array_num_value(8)  := p_source_16;
1029 
1030    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
1031    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
1032 
1033    ---------------------------------------------------------------------------------------------------------------
1034    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
1035    ---------------------------------------------------------------------------------------------------------------
1036    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
1037 
1038    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1039    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1040 
1041    IF xla_accounting_cache_pkg.GetValueChar
1042          (p_source_code         => 'LEDGER_CATEGORY_CODE'
1043          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
1044    AND l_bflow_method_code = 'PRIOR_ENTRY'
1045 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
1046    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
1047          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
1048        )
1049    THEN
1050          xla_ae_lines_pkg.BflowUpgEntry
1051            (p_business_method_code    => l_bflow_method_code
1052            ,p_business_class_code     => l_bflow_class_code
1053            ,p_balance_type            => l_balance_type_code);
1054    ELSE
1055       NULL;
1056 -- No business flow processing for business flow method of NONE.
1057    END IF;
1058 
1059    --
1060    -- call analytical criteria
1061    --
1062    
1063    --
1064    -- call description
1065    --
1066    -- No description or it is inherited.
1067    --
1068    -- call ADRs
1069    -- Bug 4922099
1070    --
1071    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
1072         (NVL(l_actual_upg_option, 'N') = 'O') OR
1073         (NVL(l_enc_upg_option, 'N') = 'O')
1074       )
1075    THEN
1076    NULL;
1077    --
1078    --
1079    
1080   l_ccid := AcctDerRule_1(
1081            p_application_id           => p_application_id
1085          , x_accounting_coa_id        => l_adr_accounting_coa_id
1082          , p_ae_header_id             => l_ae_header_id 
1083 , p_source_1 => p_source_1
1084          , x_transaction_coa_id       => l_adr_transaction_coa_id
1086          , x_value_type_code          => l_adr_value_type_code
1087          , p_side                     => 'NA'
1088    );
1089 
1090    xla_ae_lines_pkg.set_ccid(
1091     p_code_combination_id          => l_ccid
1092   , p_value_type_code              => l_adr_value_type_code
1093   , p_transaction_coa_id           => l_adr_transaction_coa_id
1094   , p_accounting_coa_id            => l_adr_accounting_coa_id
1095   , p_adr_code                     => 'DIST_CCID'
1096   , p_adr_type_code                => 'S'
1097   , p_component_type               => l_component_type
1098   , p_component_code               => l_component_code
1099   , p_component_type_code          => l_component_type_code
1100   , p_component_appl_id            => l_component_appl_id
1101   , p_amb_context_code             => l_amb_context_code
1102   , p_side                         => 'NA'
1103   );
1104 
1105 
1106    --
1107    --
1108    END IF;
1109    --
1110    -- Bug 4922099
1111    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
1112           (NVL(l_enc_upg_option, 'N') = 'O')
1113         ) AND
1114         (l_bflow_method_code = 'PRIOR_ENTRY')
1115       )
1116    THEN
1117       IF
1118       --
1119       1 = 2
1120       --
1121       THEN
1122       xla_accounting_err_pkg.build_message
1123                                     (p_appli_s_name            => 'XLA'
1124                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1125                                     ,p_token_1                 => 'LINE_NUMBER'
1126                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
1127                                     ,p_token_2                 => 'LINE_TYPE_NAME'
1128                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
1129                                                                              l_component_type
1130                                                                             ,l_component_code
1131                                                                             ,l_component_type_code
1132                                                                             ,l_component_appl_id
1133                                                                             ,l_amb_context_code
1134                                                                             ,l_entity_code
1135                                                                             ,l_event_class_code
1136                                                                            )
1137                                     ,p_token_3                 => 'OWNER'
1138                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
1139                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
1140                                                                           ,p_lookup_code    => l_component_type_code
1141                                                                          )
1142                                     ,p_token_4                 => 'PRODUCT_NAME'
1143                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
1144                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
1145                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
1146                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
1147                                     ,p_ae_header_id            =>  NULL
1148                                        );
1149 
1150         IF (C_LEVEL_ERROR>= g_log_level) THEN
1151                  trace
1152                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1153                       ,p_level    => C_LEVEL_ERROR
1154                       ,p_module   => l_log_module);
1155         END IF;
1156       END IF;
1157    END IF;
1158    --
1159    --
1160    ------------------------------------------------------------------------------------------------
1161    -- 4219869 Business Flow
1162    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
1163    -- Prior Entry.  Currently, the following code is always generated.
1164    ------------------------------------------------------------------------------------------------
1165    XLA_AE_LINES_PKG.ValidateCurrentLine;
1166 
1167    ------------------------------------------------------------------------------------
1168    -- 4219869 Business Flow
1169    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
1170    ------------------------------------------------------------------------------------
1171    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1172 
1173    ----------------------------------------------------------------------------------
1174    -- 4219869 Business Flow
1175    -- Update journal entry status -- Need to generate this within IF <condition>
1176    ----------------------------------------------------------------------------------
1177    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1178          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
1179          ,p_balance_type_code => l_balance_type_code
1183    -- 4262811 - Generate the Accrual Reversal lines
1180          );
1181 
1182    -------------------------------------------------------------------------------------------
1184    -------------------------------------------------------------------------------------------
1185    BEGIN
1186       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
1187                               (g_array_event(p_event_id).array_value_num('header_index'));
1188       IF l_acc_rev_flag IS NULL THEN
1189          l_acc_rev_flag := 'N';
1190       END IF;
1191    EXCEPTION
1192       WHEN OTHERS THEN
1193          l_acc_rev_flag := 'N';
1194    END;
1195    --
1196    IF (l_acc_rev_flag = 'Y') THEN
1197 
1198        -- 4645092  ------------------------------------------------------------------------------
1199        -- To allow MPA report to determine if it should generate report process
1200        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
1201        ------------------------------------------------------------------------------------------
1202 
1203        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
1204        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
1205    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
1206    -- call ADRs
1207    -- Bug 4922099
1208    --
1209    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
1210         (NVL(l_actual_upg_option, 'N') = 'O') OR
1211         (NVL(l_enc_upg_option, 'N') = 'O')
1212       )
1213    THEN
1214    NULL;
1215    --
1216    --
1217    
1218   l_ccid := AcctDerRule_1(
1219            p_application_id           => p_application_id
1220          , p_ae_header_id             => l_ae_header_id 
1221 , p_source_1 => p_source_1
1222          , x_transaction_coa_id       => l_adr_transaction_coa_id
1223          , x_accounting_coa_id        => l_adr_accounting_coa_id
1224          , x_value_type_code          => l_adr_value_type_code
1225          , p_side                     => 'NA'
1226    );
1227 
1228    xla_ae_lines_pkg.set_ccid(
1229     p_code_combination_id          => l_ccid
1230   , p_value_type_code              => l_adr_value_type_code
1231   , p_transaction_coa_id           => l_adr_transaction_coa_id
1232   , p_accounting_coa_id            => l_adr_accounting_coa_id
1233   , p_adr_code                     => 'DIST_CCID'
1234   , p_adr_type_code                => 'S'
1235   , p_component_type               => l_component_type
1236   , p_component_code               => l_component_code
1237   , p_component_type_code          => l_component_type_code
1238   , p_component_appl_id            => l_component_appl_id
1239   , p_amb_context_code             => l_amb_context_code
1240   , p_side                         => 'NA'
1241   );
1242 
1243 
1244    --
1245    --
1246    END IF;
1247 
1248        --
1249        -- Update the line information that should be overwritten
1250        --
1251        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
1252                                          p_header_num   => 1);
1253        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
1254 
1255        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
1256 
1257        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
1258           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
1259        END IF;
1260 
1261       --
1262       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
1263       --
1264       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
1265           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
1266       ELSE
1267           ---------------------------------------------------------------------------------------------------
1268           -- 4262811a Switch Sign
1269           ---------------------------------------------------------------------------------------------------
1270           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
1271           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1272                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1273           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1274                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1275           -- 5132302
1276           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
1277                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1278 
1279       END IF;
1280 
1281       -- 4955764
1282       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1283       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
1284 
1285 
1286       XLA_AE_LINES_PKG.ValidateCurrentLine;
1287       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1288 
1289       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1293    END IF;
1290                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
1291                ,p_balance_type_code => l_balance_type_code);
1292 
1294 
1295    -----------------------------------------------------------------------------------------
1296    -- 4262811 Multiperiod Accounting
1297    -----------------------------------------------------------------------------------------
1298      -- No MPA option is assigned.
1299 
1300 
1301 END IF;
1302 END IF;
1303 --
1304 
1305 --
1306 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1307    trace
1308       (p_msg      => 'END of AcctLineType_6'
1309       ,p_level    => C_LEVEL_PROCEDURE
1310       ,p_module   => l_log_module);
1311 END IF;
1312 --
1313 EXCEPTION
1314   WHEN xla_exceptions_pkg.application_exception THEN
1315       RAISE;
1316   WHEN OTHERS THEN
1317        xla_exceptions_pkg.raise_message
1318            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_6');
1319 END AcctLineType_6;
1320 --
1321 
1322 ---------------------------------------
1323 --
1324 -- PRIVATE FUNCTION
1325 --         AcctLineType_7
1326 --
1327 ---------------------------------------
1328 PROCEDURE AcctLineType_7 (
1329   p_application_id        IN NUMBER
1330  ,p_event_id              IN NUMBER
1331  ,p_calculate_acctd_flag  IN VARCHAR2
1332  ,p_calculate_g_l_flag    IN VARCHAR2
1333  ,p_actual_flag           IN OUT VARCHAR2
1334  ,p_balance_type_code     OUT VARCHAR2
1335  ,p_gain_or_loss_ref      OUT VARCHAR2
1336  
1337 --Distribution GL Account
1338  , p_source_1            IN NUMBER
1339 --Distribution Source Type
1340  , p_source_7            IN VARCHAR2
1341 --Distribution Multi Fund Additional Entry
1342  , p_source_8            IN VARCHAR2
1343 --Distribution Line Identifier
1344  , p_source_9            IN NUMBER
1345 --Distribution Type
1346  , p_source_10            IN VARCHAR2
1347 --Entered Amount
1348  , p_source_11            IN NUMBER
1349 --Currency Code
1350  , p_source_12            IN VARCHAR2
1351 --Applied To Document Exchange Date
1352  , p_source_13            IN DATE
1353 --Exchange Rate
1354  , p_source_14            IN NUMBER
1355 --Exchange Rate Type
1356  , p_source_15            IN VARCHAR2
1357 --Applied To Document Accounting Amount
1358  , p_source_16            IN NUMBER
1359 )
1360 IS
1361 
1362 l_component_type              VARCHAR2(80);
1363 l_component_code              VARCHAR2(30);
1364 l_component_type_code         VARCHAR2(1);
1365 l_component_appl_id           INTEGER;
1366 l_amb_context_code            VARCHAR2(30);
1367 l_entity_code                 VARCHAR2(30);
1368 l_event_class_code            VARCHAR2(30);
1369 l_ae_header_id                NUMBER;
1370 l_event_type_code             VARCHAR2(30);
1371 l_line_definition_code        VARCHAR2(30);
1372 l_line_definition_owner_code  VARCHAR2(1);
1373 --
1374 -- adr variables
1375 l_segment                     VARCHAR2(30);
1376 l_ccid                        NUMBER;
1377 l_adr_transaction_coa_id      NUMBER;
1378 l_adr_accounting_coa_id       NUMBER;
1379 l_adr_flexfield_segment_code  VARCHAR2(30);
1380 l_adr_flex_value_set_id       NUMBER;
1381 l_adr_value_type_code         VARCHAR2(30);
1382 l_adr_value_combination_id    NUMBER;
1383 l_adr_value_segment_code      VARCHAR2(30);
1384 
1385 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
1386 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
1387 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
1388 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
1389 
1390 -- 4262811 Variables ------------------------------------------------------------------------------------------
1391 l_entered_amt_idx             NUMBER;
1392 l_accted_amt_idx              NUMBER;
1393 l_acc_rev_flag                VARCHAR2(1);
1394 l_accrual_line_num            NUMBER;
1395 l_tmp_amt                     NUMBER;
1396 l_acc_rev_natural_side_code   VARCHAR2(1);
1397 
1398 l_num_entries                 NUMBER;
1399 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
1400 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
1401 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
1402 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
1403 l_recog_line_1                NUMBER;
1404 l_recog_line_2                NUMBER;
1405 
1406 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
1407 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
1408 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
1409 
1410 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
1411 
1412 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
1413 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
1414 
1415 ---------------------------------------------------------------------------------------------------------------
1416 
1417 
1418 --
1419 -- bulk performance
1420 --
1421 l_balance_type_code           VARCHAR2(1);
1422 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
1423 l_log_module                  VARCHAR2(240);
1424 
1425 --
1426 -- Upgrade strategy
1427 --
1431 --
1428 l_actual_upg_option           VARCHAR2(1);
1429 l_enc_upg_option           VARCHAR2(1);
1430 
1432 BEGIN
1433 --
1434 IF g_log_enabled THEN
1435       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_7';
1436 END IF;
1437 --
1438 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1439 
1440       trace
1441          (p_msg      => 'BEGIN of AcctLineType_7'
1442          ,p_level    => C_LEVEL_PROCEDURE
1443          ,p_module   => l_log_module);
1444 
1445 END IF;
1446 --
1447 l_component_type             := 'AMB_JLT';
1448 l_component_code             := 'MISC_RCT_CASH';
1449 l_component_type_code        := 'S';
1450 l_component_appl_id          :=  222;
1451 l_amb_context_code           := 'DEFAULT';
1452 l_entity_code                := 'RECEIPTS';
1453 l_event_class_code           := 'MISC_RECEIPT';
1454 l_event_type_code            := 'MISC_RECEIPT_ALL';
1455 l_line_definition_owner_code := 'S';
1456 l_line_definition_code       := 'AR_MISC_RECEIPTS';
1457 --
1458 l_balance_type_code          := 'A';
1459 l_segment                     := NULL;
1460 l_ccid                        := NULL;
1461 l_adr_transaction_coa_id      := NULL;
1462 l_adr_accounting_coa_id       := NULL;
1463 l_adr_flexfield_segment_code  := NULL;
1464 l_adr_flex_value_set_id       := NULL;
1465 l_adr_value_type_code         := NULL;
1466 l_adr_value_combination_id    := NULL;
1467 l_adr_value_segment_code      := NULL;
1468 
1469 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
1470 l_bflow_class_code           := '';    -- 4219869 Business Flow
1471 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
1472 l_budgetary_control_flag     := 'N';
1473 
1474 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
1475 l_bflow_applied_to_amt       := NULL; -- 5132302
1476 l_entered_amt_idx            := NULL;          -- 4262811
1477 l_accted_amt_idx             := NULL;          -- 4262811
1478 l_acc_rev_flag               := NULL;          -- 4262811
1479 l_accrual_line_num           := NULL;          -- 4262811
1480 l_tmp_amt                    := NULL;          -- 4262811
1481 --
1482  
1483 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
1484     l_balance_type_code <> 'B' THEN
1485 IF NVL(p_source_7,'
1486 ') =  'CASH' AND 
1487 NVL(p_source_8,'
1488 ') =  'N'
1489  THEN 
1490 
1491    --
1492    XLA_AE_LINES_PKG.SetNewLine;
1493 
1494    p_balance_type_code          := l_balance_type_code;
1495    -- set the flag so later we will know whether the gain loss line needs to be created
1496    
1497    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
1498      p_actual_flag :='A';
1499    END IF;
1500 
1501    --
1502    -- bulk performance
1503    --
1504    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
1505                                       p_header_num   => 0); -- 4262811
1506    --
1507    -- set accounting line options
1508    --
1509    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
1510            p_natural_side_code          => 'C'
1511          , p_gain_or_loss_flag          => 'N'
1512          , p_gl_transfer_mode_code      => 'S'
1513          , p_acct_entry_type_code       => 'A'
1514          , p_switch_side_flag           => 'Y'
1515          , p_merge_duplicate_code       => 'A'
1516          );
1517    --
1518    l_acc_rev_natural_side_code := 'D';  -- 4262811
1519    -- 
1520    --
1521    -- set accounting line type info
1522    --
1523    xla_ae_lines_pkg.SetAcctLineType
1524       (p_component_type             => l_component_type
1525       ,p_event_type_code            => l_event_type_code
1526       ,p_line_definition_owner_code => l_line_definition_owner_code
1527       ,p_line_definition_code       => l_line_definition_code
1528       ,p_accounting_line_code       => l_component_code
1529       ,p_accounting_line_type_code  => l_component_type_code
1530       ,p_accounting_line_appl_id    => l_component_appl_id
1531       ,p_amb_context_code           => l_amb_context_code
1532       ,p_entity_code                => l_entity_code
1533       ,p_event_class_code           => l_event_class_code);
1534    --
1535    -- set accounting class
1536    --
1537    xla_ae_lines_pkg.SetAcctClass(
1538            p_accounting_class_code  => 'CASH'
1539          , p_ae_header_id           => l_ae_header_id
1540          );
1541 
1542    --
1543    -- set rounding class
1544    --
1545    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
1546                       'RECEIVABLE';
1547 
1548    --
1549    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
1550    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
1551    --
1552    -- bulk performance
1553    --
1554    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
1555 
1556    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
1557       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
1558 
1559    -- 4955764
1560    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1564    
1561       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
1562 
1563    -- 4458381 Public Sector Enh
1565    --
1566    -- set accounting attributes for the line type
1567    --
1568    l_entered_amt_idx := 3;
1569    l_accted_amt_idx  := 8;
1570    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
1571    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
1572    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
1573    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
1574    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
1575    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
1576    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
1577    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
1578    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
1579    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
1580    l_rec_acct_attrs.array_date_value(5)  := p_source_13;
1581    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
1582    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
1583    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
1584    l_rec_acct_attrs.array_char_value(7)  := p_source_15;
1585    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
1586    l_rec_acct_attrs.array_num_value(8)  := p_source_16;
1587 
1588    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
1589    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
1590 
1591    ---------------------------------------------------------------------------------------------------------------
1592    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
1593    ---------------------------------------------------------------------------------------------------------------
1594    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
1595 
1596    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1597    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1598 
1599    IF xla_accounting_cache_pkg.GetValueChar
1600          (p_source_code         => 'LEDGER_CATEGORY_CODE'
1601          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
1602    AND l_bflow_method_code = 'PRIOR_ENTRY'
1603 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
1604    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
1605          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
1606        )
1607    THEN
1608          xla_ae_lines_pkg.BflowUpgEntry
1609            (p_business_method_code    => l_bflow_method_code
1610            ,p_business_class_code     => l_bflow_class_code
1611            ,p_balance_type            => l_balance_type_code);
1612    ELSE
1613       NULL;
1614 -- No business flow processing for business flow method of NONE.
1615    END IF;
1616 
1617    --
1618    -- call analytical criteria
1619    --
1620    
1621    --
1622    -- call description
1623    --
1624    -- No description or it is inherited.
1625    --
1626    -- call ADRs
1627    -- Bug 4922099
1628    --
1629    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
1630         (NVL(l_actual_upg_option, 'N') = 'O') OR
1631         (NVL(l_enc_upg_option, 'N') = 'O')
1632       )
1633    THEN
1634    NULL;
1635    --
1636    --
1637    
1638   l_ccid := AcctDerRule_1(
1639            p_application_id           => p_application_id
1640          , p_ae_header_id             => l_ae_header_id 
1641 , p_source_1 => p_source_1
1642          , x_transaction_coa_id       => l_adr_transaction_coa_id
1643          , x_accounting_coa_id        => l_adr_accounting_coa_id
1644          , x_value_type_code          => l_adr_value_type_code
1645          , p_side                     => 'NA'
1646    );
1647 
1648    xla_ae_lines_pkg.set_ccid(
1649     p_code_combination_id          => l_ccid
1650   , p_value_type_code              => l_adr_value_type_code
1651   , p_transaction_coa_id           => l_adr_transaction_coa_id
1652   , p_accounting_coa_id            => l_adr_accounting_coa_id
1653   , p_adr_code                     => 'DIST_CCID'
1654   , p_adr_type_code                => 'S'
1655   , p_component_type               => l_component_type
1656   , p_component_code               => l_component_code
1657   , p_component_type_code          => l_component_type_code
1658   , p_component_appl_id            => l_component_appl_id
1659   , p_amb_context_code             => l_amb_context_code
1660   , p_side                         => 'NA'
1661   );
1662 
1663 
1664    --
1665    --
1666    END IF;
1667    --
1668    -- Bug 4922099
1669    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
1670           (NVL(l_enc_upg_option, 'N') = 'O')
1671         ) AND
1672         (l_bflow_method_code = 'PRIOR_ENTRY')
1673       )
1674    THEN
1675       IF
1676       --
1677       1 = 2
1678       --
1679       THEN
1680       xla_accounting_err_pkg.build_message
1681                                     (p_appli_s_name            => 'XLA'
1682                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1686                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
1683                                     ,p_token_1                 => 'LINE_NUMBER'
1684                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
1685                                     ,p_token_2                 => 'LINE_TYPE_NAME'
1687                                                                              l_component_type
1688                                                                             ,l_component_code
1689                                                                             ,l_component_type_code
1690                                                                             ,l_component_appl_id
1691                                                                             ,l_amb_context_code
1692                                                                             ,l_entity_code
1693                                                                             ,l_event_class_code
1694                                                                            )
1695                                     ,p_token_3                 => 'OWNER'
1696                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
1697                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
1698                                                                           ,p_lookup_code    => l_component_type_code
1699                                                                          )
1700                                     ,p_token_4                 => 'PRODUCT_NAME'
1701                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
1702                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
1703                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
1704                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
1705                                     ,p_ae_header_id            =>  NULL
1706                                        );
1707 
1708         IF (C_LEVEL_ERROR>= g_log_level) THEN
1709                  trace
1710                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1711                       ,p_level    => C_LEVEL_ERROR
1712                       ,p_module   => l_log_module);
1713         END IF;
1714       END IF;
1715    END IF;
1716    --
1717    --
1718    ------------------------------------------------------------------------------------------------
1719    -- 4219869 Business Flow
1720    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
1721    -- Prior Entry.  Currently, the following code is always generated.
1722    ------------------------------------------------------------------------------------------------
1723    XLA_AE_LINES_PKG.ValidateCurrentLine;
1724 
1725    ------------------------------------------------------------------------------------
1726    -- 4219869 Business Flow
1727    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
1728    ------------------------------------------------------------------------------------
1729    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1730 
1731    ----------------------------------------------------------------------------------
1732    -- 4219869 Business Flow
1733    -- Update journal entry status -- Need to generate this within IF <condition>
1734    ----------------------------------------------------------------------------------
1735    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1736          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
1737          ,p_balance_type_code => l_balance_type_code
1738          );
1739 
1740    -------------------------------------------------------------------------------------------
1741    -- 4262811 - Generate the Accrual Reversal lines
1742    -------------------------------------------------------------------------------------------
1743    BEGIN
1744       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
1745                               (g_array_event(p_event_id).array_value_num('header_index'));
1746       IF l_acc_rev_flag IS NULL THEN
1747          l_acc_rev_flag := 'N';
1748       END IF;
1749    EXCEPTION
1750       WHEN OTHERS THEN
1751          l_acc_rev_flag := 'N';
1752    END;
1753    --
1754    IF (l_acc_rev_flag = 'Y') THEN
1755 
1756        -- 4645092  ------------------------------------------------------------------------------
1757        -- To allow MPA report to determine if it should generate report process
1758        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
1759        ------------------------------------------------------------------------------------------
1760 
1761        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
1762        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
1763    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
1764    -- call ADRs
1765    -- Bug 4922099
1766    --
1767    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
1768         (NVL(l_actual_upg_option, 'N') = 'O') OR
1769         (NVL(l_enc_upg_option, 'N') = 'O')
1770       )
1771    THEN
1772    NULL;
1773    --
1774    --
1775    
1776   l_ccid := AcctDerRule_1(
1777            p_application_id           => p_application_id
1778          , p_ae_header_id             => l_ae_header_id 
1779 , p_source_1 => p_source_1
1780          , x_transaction_coa_id       => l_adr_transaction_coa_id
1781          , x_accounting_coa_id        => l_adr_accounting_coa_id
1785 
1782          , x_value_type_code          => l_adr_value_type_code
1783          , p_side                     => 'NA'
1784    );
1786    xla_ae_lines_pkg.set_ccid(
1787     p_code_combination_id          => l_ccid
1788   , p_value_type_code              => l_adr_value_type_code
1789   , p_transaction_coa_id           => l_adr_transaction_coa_id
1790   , p_accounting_coa_id            => l_adr_accounting_coa_id
1791   , p_adr_code                     => 'DIST_CCID'
1792   , p_adr_type_code                => 'S'
1793   , p_component_type               => l_component_type
1794   , p_component_code               => l_component_code
1795   , p_component_type_code          => l_component_type_code
1796   , p_component_appl_id            => l_component_appl_id
1797   , p_amb_context_code             => l_amb_context_code
1798   , p_side                         => 'NA'
1799   );
1800 
1801 
1802    --
1803    --
1804    END IF;
1805 
1806        --
1807        -- Update the line information that should be overwritten
1808        --
1809        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
1810                                          p_header_num   => 1);
1811        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
1812 
1813        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
1814 
1815        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
1816           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
1817        END IF;
1818 
1819       --
1820       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
1821       --
1822       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
1823           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
1824       ELSE
1825           ---------------------------------------------------------------------------------------------------
1826           -- 4262811a Switch Sign
1827           ---------------------------------------------------------------------------------------------------
1828           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
1829           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1830                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1831           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1832                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1833           -- 5132302
1834           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
1835                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1836 
1837       END IF;
1838 
1839       -- 4955764
1840       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1841       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
1842 
1843 
1844       XLA_AE_LINES_PKG.ValidateCurrentLine;
1845       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1846 
1847       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1848                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
1849                ,p_balance_type_code => l_balance_type_code);
1850 
1851    END IF;
1852 
1853    -----------------------------------------------------------------------------------------
1854    -- 4262811 Multiperiod Accounting
1855    -----------------------------------------------------------------------------------------
1856      -- No MPA option is assigned.
1857 
1858 
1859 END IF;
1860 END IF;
1861 --
1862 
1863 --
1864 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1865    trace
1866       (p_msg      => 'END of AcctLineType_7'
1867       ,p_level    => C_LEVEL_PROCEDURE
1868       ,p_module   => l_log_module);
1869 END IF;
1870 --
1871 EXCEPTION
1872   WHEN xla_exceptions_pkg.application_exception THEN
1873       RAISE;
1874   WHEN OTHERS THEN
1875        xla_exceptions_pkg.raise_message
1876            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_7');
1877 END AcctLineType_7;
1878 --
1879 
1880 ---------------------------------------
1881 --
1882 -- PRIVATE FUNCTION
1883 --         AcctLineType_8
1884 --
1885 ---------------------------------------
1886 PROCEDURE AcctLineType_8 (
1887   p_application_id        IN NUMBER
1888  ,p_event_id              IN NUMBER
1889  ,p_calculate_acctd_flag  IN VARCHAR2
1890  ,p_calculate_g_l_flag    IN VARCHAR2
1891  ,p_actual_flag           IN OUT VARCHAR2
1892  ,p_balance_type_code     OUT VARCHAR2
1893  ,p_gain_or_loss_ref      OUT VARCHAR2
1894  
1895 --Distribution GL Account
1896  , p_source_1            IN NUMBER
1897 --Distribution Source Type
1898  , p_source_7            IN VARCHAR2
1899 --Distribution Multi Fund Additional Entry
1900  , p_source_8            IN VARCHAR2
1901 --Distribution Line Identifier
1902  , p_source_9            IN NUMBER
1903 --Distribution Type
1904  , p_source_10            IN VARCHAR2
1905 --Entered Amount
1906  , p_source_11            IN NUMBER
1907 --Currency Code
1911 --Exchange Rate
1908  , p_source_12            IN VARCHAR2
1909 --Applied To Document Exchange Date
1910  , p_source_13            IN DATE
1912  , p_source_14            IN NUMBER
1913 --Exchange Rate Type
1914  , p_source_15            IN VARCHAR2
1915 --Applied To Document Accounting Amount
1916  , p_source_16            IN NUMBER
1917 )
1918 IS
1919 
1920 l_component_type              VARCHAR2(80);
1921 l_component_code              VARCHAR2(30);
1922 l_component_type_code         VARCHAR2(1);
1923 l_component_appl_id           INTEGER;
1924 l_amb_context_code            VARCHAR2(30);
1925 l_entity_code                 VARCHAR2(30);
1926 l_event_class_code            VARCHAR2(30);
1927 l_ae_header_id                NUMBER;
1928 l_event_type_code             VARCHAR2(30);
1929 l_line_definition_code        VARCHAR2(30);
1930 l_line_definition_owner_code  VARCHAR2(1);
1931 --
1932 -- adr variables
1933 l_segment                     VARCHAR2(30);
1934 l_ccid                        NUMBER;
1935 l_adr_transaction_coa_id      NUMBER;
1936 l_adr_accounting_coa_id       NUMBER;
1937 l_adr_flexfield_segment_code  VARCHAR2(30);
1938 l_adr_flex_value_set_id       NUMBER;
1939 l_adr_value_type_code         VARCHAR2(30);
1940 l_adr_value_combination_id    NUMBER;
1941 l_adr_value_segment_code      VARCHAR2(30);
1942 
1943 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
1944 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
1945 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
1946 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
1947 
1948 -- 4262811 Variables ------------------------------------------------------------------------------------------
1949 l_entered_amt_idx             NUMBER;
1950 l_accted_amt_idx              NUMBER;
1951 l_acc_rev_flag                VARCHAR2(1);
1952 l_accrual_line_num            NUMBER;
1953 l_tmp_amt                     NUMBER;
1954 l_acc_rev_natural_side_code   VARCHAR2(1);
1955 
1956 l_num_entries                 NUMBER;
1957 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
1958 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
1959 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
1960 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
1961 l_recog_line_1                NUMBER;
1962 l_recog_line_2                NUMBER;
1963 
1964 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
1965 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
1966 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
1967 
1968 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
1969 
1970 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
1971 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
1972 
1973 ---------------------------------------------------------------------------------------------------------------
1974 
1975 
1976 --
1977 -- bulk performance
1978 --
1979 l_balance_type_code           VARCHAR2(1);
1980 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
1981 l_log_module                  VARCHAR2(240);
1982 
1983 --
1984 -- Upgrade strategy
1985 --
1986 l_actual_upg_option           VARCHAR2(1);
1987 l_enc_upg_option           VARCHAR2(1);
1988 
1989 --
1990 BEGIN
1991 --
1992 IF g_log_enabled THEN
1993       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_8';
1994 END IF;
1995 --
1996 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1997 
1998       trace
1999          (p_msg      => 'BEGIN of AcctLineType_8'
2000          ,p_level    => C_LEVEL_PROCEDURE
2001          ,p_module   => l_log_module);
2002 
2003 END IF;
2004 --
2005 l_component_type             := 'AMB_JLT';
2006 l_component_code             := 'MISC_RCT_CONFIRM';
2007 l_component_type_code        := 'S';
2008 l_component_appl_id          :=  222;
2009 l_amb_context_code           := 'DEFAULT';
2010 l_entity_code                := 'RECEIPTS';
2011 l_event_class_code           := 'MISC_RECEIPT';
2012 l_event_type_code            := 'MISC_RECEIPT_ALL';
2013 l_line_definition_owner_code := 'S';
2014 l_line_definition_code       := 'AR_MISC_RECEIPTS';
2015 --
2016 l_balance_type_code          := 'A';
2017 l_segment                     := NULL;
2018 l_ccid                        := NULL;
2019 l_adr_transaction_coa_id      := NULL;
2020 l_adr_accounting_coa_id       := NULL;
2021 l_adr_flexfield_segment_code  := NULL;
2022 l_adr_flex_value_set_id       := NULL;
2023 l_adr_value_type_code         := NULL;
2024 l_adr_value_combination_id    := NULL;
2025 l_adr_value_segment_code      := NULL;
2026 
2027 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
2028 l_bflow_class_code           := '';    -- 4219869 Business Flow
2029 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
2030 l_budgetary_control_flag     := 'N';
2031 
2032 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
2033 l_bflow_applied_to_amt       := NULL; -- 5132302
2034 l_entered_amt_idx            := NULL;          -- 4262811
2035 l_accted_amt_idx             := NULL;          -- 4262811
2036 l_acc_rev_flag               := NULL;          -- 4262811
2037 l_accrual_line_num           := NULL;          -- 4262811
2038 l_tmp_amt                    := NULL;          -- 4262811
2042     l_balance_type_code <> 'B' THEN
2039 --
2040  
2041 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
2043 IF NVL(p_source_7,'
2044 ') =  'CONFIRMATION' AND 
2045 NVL(p_source_8,'
2046 ') =  'N'
2047  THEN 
2048 
2049    --
2050    XLA_AE_LINES_PKG.SetNewLine;
2051 
2052    p_balance_type_code          := l_balance_type_code;
2053    -- set the flag so later we will know whether the gain loss line needs to be created
2054    
2055    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
2056      p_actual_flag :='A';
2057    END IF;
2058 
2059    --
2060    -- bulk performance
2061    --
2062    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
2063                                       p_header_num   => 0); -- 4262811
2064    --
2065    -- set accounting line options
2066    --
2067    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
2068            p_natural_side_code          => 'C'
2069          , p_gain_or_loss_flag          => 'N'
2070          , p_gl_transfer_mode_code      => 'S'
2071          , p_acct_entry_type_code       => 'A'
2072          , p_switch_side_flag           => 'Y'
2073          , p_merge_duplicate_code       => 'A'
2074          );
2075    --
2076    l_acc_rev_natural_side_code := 'D';  -- 4262811
2077    -- 
2078    --
2079    -- set accounting line type info
2080    --
2081    xla_ae_lines_pkg.SetAcctLineType
2082       (p_component_type             => l_component_type
2083       ,p_event_type_code            => l_event_type_code
2084       ,p_line_definition_owner_code => l_line_definition_owner_code
2085       ,p_line_definition_code       => l_line_definition_code
2086       ,p_accounting_line_code       => l_component_code
2087       ,p_accounting_line_type_code  => l_component_type_code
2088       ,p_accounting_line_appl_id    => l_component_appl_id
2089       ,p_amb_context_code           => l_amb_context_code
2090       ,p_entity_code                => l_entity_code
2091       ,p_event_class_code           => l_event_class_code);
2092    --
2093    -- set accounting class
2094    --
2095    xla_ae_lines_pkg.SetAcctClass(
2096            p_accounting_class_code  => 'CONFIRMATION'
2097          , p_ae_header_id           => l_ae_header_id
2098          );
2099 
2100    --
2101    -- set rounding class
2102    --
2103    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
2104                       'RECEIVABLE';
2105 
2106    --
2107    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
2108    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
2109    --
2110    -- bulk performance
2111    --
2112    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
2113 
2114    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
2115       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
2116 
2117    -- 4955764
2118    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2119       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
2120 
2121    -- 4458381 Public Sector Enh
2122    
2123    --
2124    -- set accounting attributes for the line type
2125    --
2126    l_entered_amt_idx := 3;
2127    l_accted_amt_idx  := 8;
2128    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
2129    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
2130    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
2131    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
2132    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
2133    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
2134    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
2135    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
2136    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
2137    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
2138    l_rec_acct_attrs.array_date_value(5)  := p_source_13;
2139    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
2140    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
2141    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
2142    l_rec_acct_attrs.array_char_value(7)  := p_source_15;
2143    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
2144    l_rec_acct_attrs.array_num_value(8)  := p_source_16;
2145 
2146    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
2147    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
2148 
2149    ---------------------------------------------------------------------------------------------------------------
2150    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
2151    ---------------------------------------------------------------------------------------------------------------
2152    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
2153 
2154    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2158          (p_source_code         => 'LEDGER_CATEGORY_CODE'
2155    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2156 
2157    IF xla_accounting_cache_pkg.GetValueChar
2159          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
2160    AND l_bflow_method_code = 'PRIOR_ENTRY'
2161 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
2162    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
2163          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
2164        )
2165    THEN
2166          xla_ae_lines_pkg.BflowUpgEntry
2167            (p_business_method_code    => l_bflow_method_code
2168            ,p_business_class_code     => l_bflow_class_code
2169            ,p_balance_type            => l_balance_type_code);
2170    ELSE
2171       NULL;
2172 -- No business flow processing for business flow method of NONE.
2173    END IF;
2174 
2175    --
2176    -- call analytical criteria
2177    --
2178    
2179    --
2180    -- call description
2181    --
2182    -- No description or it is inherited.
2183    --
2184    -- call ADRs
2185    -- Bug 4922099
2186    --
2187    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
2188         (NVL(l_actual_upg_option, 'N') = 'O') OR
2189         (NVL(l_enc_upg_option, 'N') = 'O')
2190       )
2191    THEN
2192    NULL;
2193    --
2194    --
2195    
2196   l_ccid := AcctDerRule_1(
2197            p_application_id           => p_application_id
2198          , p_ae_header_id             => l_ae_header_id 
2199 , p_source_1 => p_source_1
2200          , x_transaction_coa_id       => l_adr_transaction_coa_id
2201          , x_accounting_coa_id        => l_adr_accounting_coa_id
2202          , x_value_type_code          => l_adr_value_type_code
2203          , p_side                     => 'NA'
2204    );
2205 
2206    xla_ae_lines_pkg.set_ccid(
2207     p_code_combination_id          => l_ccid
2208   , p_value_type_code              => l_adr_value_type_code
2209   , p_transaction_coa_id           => l_adr_transaction_coa_id
2210   , p_accounting_coa_id            => l_adr_accounting_coa_id
2211   , p_adr_code                     => 'DIST_CCID'
2212   , p_adr_type_code                => 'S'
2213   , p_component_type               => l_component_type
2214   , p_component_code               => l_component_code
2215   , p_component_type_code          => l_component_type_code
2216   , p_component_appl_id            => l_component_appl_id
2217   , p_amb_context_code             => l_amb_context_code
2218   , p_side                         => 'NA'
2219   );
2220 
2221 
2222    --
2223    --
2224    END IF;
2225    --
2226    -- Bug 4922099
2227    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
2228           (NVL(l_enc_upg_option, 'N') = 'O')
2229         ) AND
2230         (l_bflow_method_code = 'PRIOR_ENTRY')
2231       )
2232    THEN
2233       IF
2234       --
2235       1 = 2
2236       --
2237       THEN
2238       xla_accounting_err_pkg.build_message
2239                                     (p_appli_s_name            => 'XLA'
2240                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2241                                     ,p_token_1                 => 'LINE_NUMBER'
2242                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
2243                                     ,p_token_2                 => 'LINE_TYPE_NAME'
2244                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
2245                                                                              l_component_type
2246                                                                             ,l_component_code
2247                                                                             ,l_component_type_code
2248                                                                             ,l_component_appl_id
2249                                                                             ,l_amb_context_code
2250                                                                             ,l_entity_code
2251                                                                             ,l_event_class_code
2252                                                                            )
2253                                     ,p_token_3                 => 'OWNER'
2254                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
2255                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
2256                                                                           ,p_lookup_code    => l_component_type_code
2257                                                                          )
2258                                     ,p_token_4                 => 'PRODUCT_NAME'
2259                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
2260                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
2261                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
2262                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
2263                                     ,p_ae_header_id            =>  NULL
2264                                        );
2265 
2269                       ,p_level    => C_LEVEL_ERROR
2266         IF (C_LEVEL_ERROR>= g_log_level) THEN
2267                  trace
2268                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2270                       ,p_module   => l_log_module);
2271         END IF;
2272       END IF;
2273    END IF;
2274    --
2275    --
2276    ------------------------------------------------------------------------------------------------
2277    -- 4219869 Business Flow
2278    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
2279    -- Prior Entry.  Currently, the following code is always generated.
2280    ------------------------------------------------------------------------------------------------
2281    XLA_AE_LINES_PKG.ValidateCurrentLine;
2282 
2283    ------------------------------------------------------------------------------------
2284    -- 4219869 Business Flow
2285    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
2286    ------------------------------------------------------------------------------------
2287    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2288 
2289    ----------------------------------------------------------------------------------
2290    -- 4219869 Business Flow
2291    -- Update journal entry status -- Need to generate this within IF <condition>
2292    ----------------------------------------------------------------------------------
2293    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2294          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
2295          ,p_balance_type_code => l_balance_type_code
2296          );
2297 
2298    -------------------------------------------------------------------------------------------
2299    -- 4262811 - Generate the Accrual Reversal lines
2300    -------------------------------------------------------------------------------------------
2301    BEGIN
2302       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
2303                               (g_array_event(p_event_id).array_value_num('header_index'));
2304       IF l_acc_rev_flag IS NULL THEN
2305          l_acc_rev_flag := 'N';
2306       END IF;
2307    EXCEPTION
2308       WHEN OTHERS THEN
2309          l_acc_rev_flag := 'N';
2310    END;
2311    --
2312    IF (l_acc_rev_flag = 'Y') THEN
2313 
2314        -- 4645092  ------------------------------------------------------------------------------
2315        -- To allow MPA report to determine if it should generate report process
2316        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
2317        ------------------------------------------------------------------------------------------
2318 
2319        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
2320        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
2321    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
2322    -- call ADRs
2323    -- Bug 4922099
2324    --
2325    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
2326         (NVL(l_actual_upg_option, 'N') = 'O') OR
2327         (NVL(l_enc_upg_option, 'N') = 'O')
2328       )
2329    THEN
2330    NULL;
2331    --
2332    --
2333    
2334   l_ccid := AcctDerRule_1(
2335            p_application_id           => p_application_id
2336          , p_ae_header_id             => l_ae_header_id 
2337 , p_source_1 => p_source_1
2338          , x_transaction_coa_id       => l_adr_transaction_coa_id
2339          , x_accounting_coa_id        => l_adr_accounting_coa_id
2340          , x_value_type_code          => l_adr_value_type_code
2341          , p_side                     => 'NA'
2342    );
2343 
2344    xla_ae_lines_pkg.set_ccid(
2345     p_code_combination_id          => l_ccid
2346   , p_value_type_code              => l_adr_value_type_code
2347   , p_transaction_coa_id           => l_adr_transaction_coa_id
2348   , p_accounting_coa_id            => l_adr_accounting_coa_id
2349   , p_adr_code                     => 'DIST_CCID'
2350   , p_adr_type_code                => 'S'
2351   , p_component_type               => l_component_type
2352   , p_component_code               => l_component_code
2353   , p_component_type_code          => l_component_type_code
2354   , p_component_appl_id            => l_component_appl_id
2355   , p_amb_context_code             => l_amb_context_code
2356   , p_side                         => 'NA'
2357   );
2358 
2359 
2360    --
2361    --
2362    END IF;
2363 
2364        --
2365        -- Update the line information that should be overwritten
2366        --
2367        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
2368                                          p_header_num   => 1);
2369        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
2370 
2371        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
2372 
2373        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
2374           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
2375        END IF;
2376 
2377       --
2378       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
2379       --
2380       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
2384           -- 4262811a Switch Sign
2381           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
2382       ELSE
2383           ---------------------------------------------------------------------------------------------------
2385           ---------------------------------------------------------------------------------------------------
2386           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
2387           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2388                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2389           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2390                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2391           -- 5132302
2392           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
2393                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2394 
2395       END IF;
2396 
2397       -- 4955764
2398       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2399       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
2400 
2401 
2402       XLA_AE_LINES_PKG.ValidateCurrentLine;
2403       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2404 
2405       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2406                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
2407                ,p_balance_type_code => l_balance_type_code);
2408 
2409    END IF;
2410 
2411    -----------------------------------------------------------------------------------------
2412    -- 4262811 Multiperiod Accounting
2413    -----------------------------------------------------------------------------------------
2414      -- No MPA option is assigned.
2415 
2416 
2417 END IF;
2418 END IF;
2419 --
2420 
2421 --
2422 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2423    trace
2424       (p_msg      => 'END of AcctLineType_8'
2425       ,p_level    => C_LEVEL_PROCEDURE
2426       ,p_module   => l_log_module);
2427 END IF;
2428 --
2429 EXCEPTION
2430   WHEN xla_exceptions_pkg.application_exception THEN
2431       RAISE;
2432   WHEN OTHERS THEN
2433        xla_exceptions_pkg.raise_message
2434            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_8');
2435 END AcctLineType_8;
2436 --
2437 
2438 ---------------------------------------
2439 --
2440 -- PRIVATE FUNCTION
2441 --         AcctLineType_9
2442 --
2443 ---------------------------------------
2444 PROCEDURE AcctLineType_9 (
2445   p_application_id        IN NUMBER
2446  ,p_event_id              IN NUMBER
2447  ,p_calculate_acctd_flag  IN VARCHAR2
2448  ,p_calculate_g_l_flag    IN VARCHAR2
2449  ,p_actual_flag           IN OUT VARCHAR2
2450  ,p_balance_type_code     OUT VARCHAR2
2451  ,p_gain_or_loss_ref      OUT VARCHAR2
2452  
2453 --Distribution GL Account
2454  , p_source_1            IN NUMBER
2455 --Distribution Source Type
2456  , p_source_7            IN VARCHAR2
2457 --Distribution Multi Fund Additional Entry
2458  , p_source_8            IN VARCHAR2
2459 --Distribution Line Identifier
2460  , p_source_9            IN NUMBER
2461 --Distribution Type
2462  , p_source_10            IN VARCHAR2
2463 --Entered Amount
2464  , p_source_11            IN NUMBER
2465 --Currency Code
2466  , p_source_12            IN VARCHAR2
2467 --Applied To Document Exchange Date
2468  , p_source_13            IN DATE
2469 --Exchange Rate
2470  , p_source_14            IN NUMBER
2471 --Exchange Rate Type
2472  , p_source_15            IN VARCHAR2
2473 --Applied To Document Accounting Amount
2474  , p_source_16            IN NUMBER
2475 )
2476 IS
2477 
2478 l_component_type              VARCHAR2(80);
2479 l_component_code              VARCHAR2(30);
2480 l_component_type_code         VARCHAR2(1);
2481 l_component_appl_id           INTEGER;
2482 l_amb_context_code            VARCHAR2(30);
2483 l_entity_code                 VARCHAR2(30);
2484 l_event_class_code            VARCHAR2(30);
2485 l_ae_header_id                NUMBER;
2486 l_event_type_code             VARCHAR2(30);
2487 l_line_definition_code        VARCHAR2(30);
2488 l_line_definition_owner_code  VARCHAR2(1);
2489 --
2490 -- adr variables
2491 l_segment                     VARCHAR2(30);
2492 l_ccid                        NUMBER;
2493 l_adr_transaction_coa_id      NUMBER;
2494 l_adr_accounting_coa_id       NUMBER;
2495 l_adr_flexfield_segment_code  VARCHAR2(30);
2496 l_adr_flex_value_set_id       NUMBER;
2497 l_adr_value_type_code         VARCHAR2(30);
2498 l_adr_value_combination_id    NUMBER;
2499 l_adr_value_segment_code      VARCHAR2(30);
2500 
2501 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
2502 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
2503 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
2504 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
2505 
2509 l_acc_rev_flag                VARCHAR2(1);
2506 -- 4262811 Variables ------------------------------------------------------------------------------------------
2507 l_entered_amt_idx             NUMBER;
2508 l_accted_amt_idx              NUMBER;
2510 l_accrual_line_num            NUMBER;
2511 l_tmp_amt                     NUMBER;
2512 l_acc_rev_natural_side_code   VARCHAR2(1);
2513 
2514 l_num_entries                 NUMBER;
2515 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
2516 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
2517 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
2518 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
2519 l_recog_line_1                NUMBER;
2520 l_recog_line_2                NUMBER;
2521 
2522 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
2523 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
2524 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
2525 
2526 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
2527 
2528 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
2529 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
2530 
2531 ---------------------------------------------------------------------------------------------------------------
2532 
2533 
2534 --
2535 -- bulk performance
2536 --
2537 l_balance_type_code           VARCHAR2(1);
2538 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
2539 l_log_module                  VARCHAR2(240);
2540 
2541 --
2542 -- Upgrade strategy
2543 --
2544 l_actual_upg_option           VARCHAR2(1);
2545 l_enc_upg_option           VARCHAR2(1);
2546 
2547 --
2548 BEGIN
2549 --
2550 IF g_log_enabled THEN
2551       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_9';
2552 END IF;
2553 --
2554 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2555 
2556       trace
2557          (p_msg      => 'BEGIN of AcctLineType_9'
2558          ,p_level    => C_LEVEL_PROCEDURE
2559          ,p_module   => l_log_module);
2560 
2561 END IF;
2562 --
2563 l_component_type             := 'AMB_JLT';
2564 l_component_code             := 'MISC_RCT_DEBT';
2565 l_component_type_code        := 'S';
2566 l_component_appl_id          :=  222;
2567 l_amb_context_code           := 'DEFAULT';
2568 l_entity_code                := 'RECEIPTS';
2569 l_event_class_code           := 'MISC_RECEIPT';
2570 l_event_type_code            := 'MISC_RECEIPT_ALL';
2571 l_line_definition_owner_code := 'S';
2572 l_line_definition_code       := 'AR_MISC_RECEIPTS';
2573 --
2574 l_balance_type_code          := 'A';
2575 l_segment                     := NULL;
2576 l_ccid                        := NULL;
2577 l_adr_transaction_coa_id      := NULL;
2578 l_adr_accounting_coa_id       := NULL;
2579 l_adr_flexfield_segment_code  := NULL;
2580 l_adr_flex_value_set_id       := NULL;
2581 l_adr_value_type_code         := NULL;
2582 l_adr_value_combination_id    := NULL;
2583 l_adr_value_segment_code      := NULL;
2584 
2585 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
2586 l_bflow_class_code           := '';    -- 4219869 Business Flow
2587 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
2588 l_budgetary_control_flag     := 'N';
2589 
2590 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
2591 l_bflow_applied_to_amt       := NULL; -- 5132302
2592 l_entered_amt_idx            := NULL;          -- 4262811
2593 l_accted_amt_idx             := NULL;          -- 4262811
2594 l_acc_rev_flag               := NULL;          -- 4262811
2595 l_accrual_line_num           := NULL;          -- 4262811
2596 l_tmp_amt                    := NULL;          -- 4262811
2597 --
2598  
2599 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
2600     l_balance_type_code <> 'B' THEN
2601 IF NVL(p_source_7,'
2602 ') =  'SHORT_TERM_DEBT' AND 
2603 NVL(p_source_8,'
2604 ') =  'N'
2605  THEN 
2606 
2607    --
2608    XLA_AE_LINES_PKG.SetNewLine;
2609 
2610    p_balance_type_code          := l_balance_type_code;
2611    -- set the flag so later we will know whether the gain loss line needs to be created
2612    
2613    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
2614      p_actual_flag :='A';
2615    END IF;
2616 
2617    --
2618    -- bulk performance
2619    --
2620    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
2621                                       p_header_num   => 0); -- 4262811
2622    --
2623    -- set accounting line options
2624    --
2625    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
2626            p_natural_side_code          => 'C'
2627          , p_gain_or_loss_flag          => 'N'
2628          , p_gl_transfer_mode_code      => 'S'
2629          , p_acct_entry_type_code       => 'A'
2630          , p_switch_side_flag           => 'Y'
2631          , p_merge_duplicate_code       => 'A'
2632          );
2633    --
2634    l_acc_rev_natural_side_code := 'D';  -- 4262811
2635    -- 
2636    --
2637    -- set accounting line type info
2638    --
2639    xla_ae_lines_pkg.SetAcctLineType
2640       (p_component_type             => l_component_type
2644       ,p_accounting_line_code       => l_component_code
2641       ,p_event_type_code            => l_event_type_code
2642       ,p_line_definition_owner_code => l_line_definition_owner_code
2643       ,p_line_definition_code       => l_line_definition_code
2645       ,p_accounting_line_type_code  => l_component_type_code
2646       ,p_accounting_line_appl_id    => l_component_appl_id
2647       ,p_amb_context_code           => l_amb_context_code
2648       ,p_entity_code                => l_entity_code
2649       ,p_event_class_code           => l_event_class_code);
2650    --
2651    -- set accounting class
2652    --
2653    xla_ae_lines_pkg.SetAcctClass(
2654            p_accounting_class_code  => 'SHORT_TERM_DEBT'
2655          , p_ae_header_id           => l_ae_header_id
2656          );
2657 
2658    --
2659    -- set rounding class
2660    --
2661    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
2662                       'RECEIVABLE';
2663 
2664    --
2665    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
2666    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
2667    --
2668    -- bulk performance
2669    --
2670    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
2671 
2672    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
2673       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
2674 
2675    -- 4955764
2676    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2677       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
2678 
2679    -- 4458381 Public Sector Enh
2680    
2681    --
2682    -- set accounting attributes for the line type
2683    --
2684    l_entered_amt_idx := 3;
2685    l_accted_amt_idx  := 8;
2686    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
2687    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
2688    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
2689    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
2690    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
2691    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
2692    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
2693    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
2694    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
2695    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
2696    l_rec_acct_attrs.array_date_value(5)  := p_source_13;
2697    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
2698    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
2699    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
2700    l_rec_acct_attrs.array_char_value(7)  := p_source_15;
2701    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
2702    l_rec_acct_attrs.array_num_value(8)  := p_source_16;
2703 
2704    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
2705    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
2706 
2707    ---------------------------------------------------------------------------------------------------------------
2708    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
2709    ---------------------------------------------------------------------------------------------------------------
2710    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
2711 
2712    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2713    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2714 
2715    IF xla_accounting_cache_pkg.GetValueChar
2716          (p_source_code         => 'LEDGER_CATEGORY_CODE'
2717          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
2718    AND l_bflow_method_code = 'PRIOR_ENTRY'
2719 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
2720    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
2721          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
2722        )
2723    THEN
2724          xla_ae_lines_pkg.BflowUpgEntry
2725            (p_business_method_code    => l_bflow_method_code
2726            ,p_business_class_code     => l_bflow_class_code
2727            ,p_balance_type            => l_balance_type_code);
2728    ELSE
2729       NULL;
2730 -- No business flow processing for business flow method of NONE.
2731    END IF;
2732 
2733    --
2734    -- call analytical criteria
2735    --
2736    
2737    --
2738    -- call description
2739    --
2740    -- No description or it is inherited.
2741    --
2742    -- call ADRs
2743    -- Bug 4922099
2744    --
2745    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
2746         (NVL(l_actual_upg_option, 'N') = 'O') OR
2747         (NVL(l_enc_upg_option, 'N') = 'O')
2748       )
2749    THEN
2750    NULL;
2751    --
2752    --
2753    
2754   l_ccid := AcctDerRule_1(
2755            p_application_id           => p_application_id
2759          , x_accounting_coa_id        => l_adr_accounting_coa_id
2756          , p_ae_header_id             => l_ae_header_id 
2757 , p_source_1 => p_source_1
2758          , x_transaction_coa_id       => l_adr_transaction_coa_id
2760          , x_value_type_code          => l_adr_value_type_code
2761          , p_side                     => 'NA'
2762    );
2763 
2764    xla_ae_lines_pkg.set_ccid(
2765     p_code_combination_id          => l_ccid
2766   , p_value_type_code              => l_adr_value_type_code
2767   , p_transaction_coa_id           => l_adr_transaction_coa_id
2768   , p_accounting_coa_id            => l_adr_accounting_coa_id
2769   , p_adr_code                     => 'DIST_CCID'
2770   , p_adr_type_code                => 'S'
2771   , p_component_type               => l_component_type
2772   , p_component_code               => l_component_code
2773   , p_component_type_code          => l_component_type_code
2774   , p_component_appl_id            => l_component_appl_id
2775   , p_amb_context_code             => l_amb_context_code
2776   , p_side                         => 'NA'
2777   );
2778 
2779 
2780    --
2781    --
2782    END IF;
2783    --
2784    -- Bug 4922099
2785    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
2786           (NVL(l_enc_upg_option, 'N') = 'O')
2787         ) AND
2788         (l_bflow_method_code = 'PRIOR_ENTRY')
2789       )
2790    THEN
2791       IF
2792       --
2793       1 = 2
2794       --
2795       THEN
2796       xla_accounting_err_pkg.build_message
2797                                     (p_appli_s_name            => 'XLA'
2798                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2799                                     ,p_token_1                 => 'LINE_NUMBER'
2800                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
2801                                     ,p_token_2                 => 'LINE_TYPE_NAME'
2802                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
2803                                                                              l_component_type
2804                                                                             ,l_component_code
2805                                                                             ,l_component_type_code
2806                                                                             ,l_component_appl_id
2807                                                                             ,l_amb_context_code
2808                                                                             ,l_entity_code
2809                                                                             ,l_event_class_code
2810                                                                            )
2811                                     ,p_token_3                 => 'OWNER'
2812                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
2813                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
2814                                                                           ,p_lookup_code    => l_component_type_code
2815                                                                          )
2816                                     ,p_token_4                 => 'PRODUCT_NAME'
2817                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
2818                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
2819                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
2820                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
2821                                     ,p_ae_header_id            =>  NULL
2822                                        );
2823 
2824         IF (C_LEVEL_ERROR>= g_log_level) THEN
2825                  trace
2826                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2827                       ,p_level    => C_LEVEL_ERROR
2828                       ,p_module   => l_log_module);
2829         END IF;
2830       END IF;
2831    END IF;
2832    --
2833    --
2834    ------------------------------------------------------------------------------------------------
2835    -- 4219869 Business Flow
2836    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
2837    -- Prior Entry.  Currently, the following code is always generated.
2838    ------------------------------------------------------------------------------------------------
2839    XLA_AE_LINES_PKG.ValidateCurrentLine;
2840 
2841    ------------------------------------------------------------------------------------
2842    -- 4219869 Business Flow
2843    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
2844    ------------------------------------------------------------------------------------
2845    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2846 
2847    ----------------------------------------------------------------------------------
2848    -- 4219869 Business Flow
2849    -- Update journal entry status -- Need to generate this within IF <condition>
2850    ----------------------------------------------------------------------------------
2851    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2852          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
2853          ,p_balance_type_code => l_balance_type_code
2857    -- 4262811 - Generate the Accrual Reversal lines
2854          );
2855 
2856    -------------------------------------------------------------------------------------------
2858    -------------------------------------------------------------------------------------------
2859    BEGIN
2860       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
2861                               (g_array_event(p_event_id).array_value_num('header_index'));
2862       IF l_acc_rev_flag IS NULL THEN
2863          l_acc_rev_flag := 'N';
2864       END IF;
2865    EXCEPTION
2866       WHEN OTHERS THEN
2867          l_acc_rev_flag := 'N';
2868    END;
2869    --
2870    IF (l_acc_rev_flag = 'Y') THEN
2871 
2872        -- 4645092  ------------------------------------------------------------------------------
2873        -- To allow MPA report to determine if it should generate report process
2874        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
2875        ------------------------------------------------------------------------------------------
2876 
2877        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
2878        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
2879    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
2880    -- call ADRs
2881    -- Bug 4922099
2882    --
2883    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
2884         (NVL(l_actual_upg_option, 'N') = 'O') OR
2885         (NVL(l_enc_upg_option, 'N') = 'O')
2886       )
2887    THEN
2888    NULL;
2889    --
2890    --
2891    
2892   l_ccid := AcctDerRule_1(
2893            p_application_id           => p_application_id
2894          , p_ae_header_id             => l_ae_header_id 
2895 , p_source_1 => p_source_1
2896          , x_transaction_coa_id       => l_adr_transaction_coa_id
2897          , x_accounting_coa_id        => l_adr_accounting_coa_id
2898          , x_value_type_code          => l_adr_value_type_code
2899          , p_side                     => 'NA'
2900    );
2901 
2902    xla_ae_lines_pkg.set_ccid(
2903     p_code_combination_id          => l_ccid
2904   , p_value_type_code              => l_adr_value_type_code
2905   , p_transaction_coa_id           => l_adr_transaction_coa_id
2906   , p_accounting_coa_id            => l_adr_accounting_coa_id
2907   , p_adr_code                     => 'DIST_CCID'
2908   , p_adr_type_code                => 'S'
2909   , p_component_type               => l_component_type
2910   , p_component_code               => l_component_code
2911   , p_component_type_code          => l_component_type_code
2912   , p_component_appl_id            => l_component_appl_id
2913   , p_amb_context_code             => l_amb_context_code
2914   , p_side                         => 'NA'
2915   );
2916 
2917 
2918    --
2919    --
2920    END IF;
2921 
2922        --
2923        -- Update the line information that should be overwritten
2924        --
2925        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
2926                                          p_header_num   => 1);
2927        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
2928 
2929        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
2930 
2931        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
2932           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
2933        END IF;
2934 
2935       --
2936       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
2937       --
2938       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
2939           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
2940       ELSE
2941           ---------------------------------------------------------------------------------------------------
2942           -- 4262811a Switch Sign
2943           ---------------------------------------------------------------------------------------------------
2944           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
2945           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2946                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2947           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2948                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2949           -- 5132302
2950           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
2951                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2952 
2953       END IF;
2954 
2955       -- 4955764
2956       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2957       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
2958 
2959 
2960       XLA_AE_LINES_PKG.ValidateCurrentLine;
2961       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2962 
2963       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2964                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
2965                ,p_balance_type_code => l_balance_type_code);
2969    -----------------------------------------------------------------------------------------
2966 
2967    END IF;
2968 
2970    -- 4262811 Multiperiod Accounting
2971    -----------------------------------------------------------------------------------------
2972      -- No MPA option is assigned.
2973 
2974 
2975 END IF;
2976 END IF;
2977 --
2978 
2979 --
2980 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2981    trace
2982       (p_msg      => 'END of AcctLineType_9'
2983       ,p_level    => C_LEVEL_PROCEDURE
2984       ,p_module   => l_log_module);
2985 END IF;
2986 --
2987 EXCEPTION
2988   WHEN xla_exceptions_pkg.application_exception THEN
2989       RAISE;
2990   WHEN OTHERS THEN
2991        xla_exceptions_pkg.raise_message
2992            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_9');
2993 END AcctLineType_9;
2994 --
2995 
2996 ---------------------------------------
2997 --
2998 -- PRIVATE FUNCTION
2999 --         AcctLineType_10
3000 --
3001 ---------------------------------------
3002 PROCEDURE AcctLineType_10 (
3003   p_application_id        IN NUMBER
3004  ,p_event_id              IN NUMBER
3005  ,p_calculate_acctd_flag  IN VARCHAR2
3006  ,p_calculate_g_l_flag    IN VARCHAR2
3007  ,p_actual_flag           IN OUT VARCHAR2
3008  ,p_balance_type_code     OUT VARCHAR2
3009  ,p_gain_or_loss_ref      OUT VARCHAR2
3010  
3011 --Distribution GL Account
3012  , p_source_1            IN NUMBER
3013 --Distribution Source Type
3014  , p_source_7            IN VARCHAR2
3015 --Distribution Multi Fund Additional Entry
3016  , p_source_8            IN VARCHAR2
3017 --Distribution Line Identifier
3018  , p_source_9            IN NUMBER
3019 --Distribution Type
3020  , p_source_10            IN VARCHAR2
3021 --Entered Amount
3022  , p_source_11            IN NUMBER
3023 --Currency Code
3024  , p_source_12            IN VARCHAR2
3025 --Applied To Document Exchange Date
3026  , p_source_13            IN DATE
3027 --Exchange Rate
3028  , p_source_14            IN NUMBER
3029 --Exchange Rate Type
3030  , p_source_15            IN VARCHAR2
3031 --Applied To Document Accounting Amount
3032  , p_source_16            IN NUMBER
3033 )
3034 IS
3035 
3036 l_component_type              VARCHAR2(80);
3037 l_component_code              VARCHAR2(30);
3038 l_component_type_code         VARCHAR2(1);
3039 l_component_appl_id           INTEGER;
3040 l_amb_context_code            VARCHAR2(30);
3041 l_entity_code                 VARCHAR2(30);
3042 l_event_class_code            VARCHAR2(30);
3043 l_ae_header_id                NUMBER;
3044 l_event_type_code             VARCHAR2(30);
3045 l_line_definition_code        VARCHAR2(30);
3046 l_line_definition_owner_code  VARCHAR2(1);
3047 --
3048 -- adr variables
3049 l_segment                     VARCHAR2(30);
3050 l_ccid                        NUMBER;
3051 l_adr_transaction_coa_id      NUMBER;
3052 l_adr_accounting_coa_id       NUMBER;
3053 l_adr_flexfield_segment_code  VARCHAR2(30);
3054 l_adr_flex_value_set_id       NUMBER;
3055 l_adr_value_type_code         VARCHAR2(30);
3056 l_adr_value_combination_id    NUMBER;
3057 l_adr_value_segment_code      VARCHAR2(30);
3058 
3059 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
3060 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
3061 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
3062 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
3063 
3064 -- 4262811 Variables ------------------------------------------------------------------------------------------
3065 l_entered_amt_idx             NUMBER;
3066 l_accted_amt_idx              NUMBER;
3067 l_acc_rev_flag                VARCHAR2(1);
3068 l_accrual_line_num            NUMBER;
3069 l_tmp_amt                     NUMBER;
3070 l_acc_rev_natural_side_code   VARCHAR2(1);
3071 
3072 l_num_entries                 NUMBER;
3073 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
3074 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
3075 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
3076 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
3077 l_recog_line_1                NUMBER;
3078 l_recog_line_2                NUMBER;
3079 
3080 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
3081 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
3082 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
3083 
3084 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
3085 
3086 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
3087 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
3088 
3089 ---------------------------------------------------------------------------------------------------------------
3090 
3091 
3092 --
3093 -- bulk performance
3094 --
3095 l_balance_type_code           VARCHAR2(1);
3096 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
3097 l_log_module                  VARCHAR2(240);
3098 
3099 --
3100 -- Upgrade strategy
3101 --
3102 l_actual_upg_option           VARCHAR2(1);
3103 l_enc_upg_option           VARCHAR2(1);
3104 
3105 --
3106 BEGIN
3110 END IF;
3107 --
3108 IF g_log_enabled THEN
3109       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_10';
3111 --
3112 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3113 
3114       trace
3115          (p_msg      => 'BEGIN of AcctLineType_10'
3116          ,p_level    => C_LEVEL_PROCEDURE
3117          ,p_module   => l_log_module);
3118 
3119 END IF;
3120 --
3121 l_component_type             := 'AMB_JLT';
3122 l_component_code             := 'MISC_RCT_FACTOR';
3123 l_component_type_code        := 'S';
3124 l_component_appl_id          :=  222;
3125 l_amb_context_code           := 'DEFAULT';
3126 l_entity_code                := 'RECEIPTS';
3127 l_event_class_code           := 'MISC_RECEIPT';
3128 l_event_type_code            := 'MISC_RECEIPT_ALL';
3129 l_line_definition_owner_code := 'S';
3130 l_line_definition_code       := 'AR_MISC_RECEIPTS';
3131 --
3132 l_balance_type_code          := 'A';
3133 l_segment                     := NULL;
3134 l_ccid                        := NULL;
3135 l_adr_transaction_coa_id      := NULL;
3136 l_adr_accounting_coa_id       := NULL;
3137 l_adr_flexfield_segment_code  := NULL;
3138 l_adr_flex_value_set_id       := NULL;
3139 l_adr_value_type_code         := NULL;
3140 l_adr_value_combination_id    := NULL;
3141 l_adr_value_segment_code      := NULL;
3142 
3143 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
3144 l_bflow_class_code           := '';    -- 4219869 Business Flow
3145 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
3146 l_budgetary_control_flag     := 'N';
3147 
3148 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
3149 l_bflow_applied_to_amt       := NULL; -- 5132302
3150 l_entered_amt_idx            := NULL;          -- 4262811
3151 l_accted_amt_idx             := NULL;          -- 4262811
3152 l_acc_rev_flag               := NULL;          -- 4262811
3153 l_accrual_line_num           := NULL;          -- 4262811
3154 l_tmp_amt                    := NULL;          -- 4262811
3155 --
3156  
3157 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
3158     l_balance_type_code <> 'B' THEN
3159 IF NVL(p_source_7,'
3160 ') =  'FACTOR' AND 
3161 NVL(p_source_8,'
3162 ') =  'N'
3163  THEN 
3164 
3165    --
3166    XLA_AE_LINES_PKG.SetNewLine;
3167 
3168    p_balance_type_code          := l_balance_type_code;
3169    -- set the flag so later we will know whether the gain loss line needs to be created
3170    
3171    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
3172      p_actual_flag :='A';
3173    END IF;
3174 
3175    --
3176    -- bulk performance
3177    --
3178    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
3179                                       p_header_num   => 0); -- 4262811
3180    --
3181    -- set accounting line options
3182    --
3186          , p_gl_transfer_mode_code      => 'S'
3183    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
3184            p_natural_side_code          => 'C'
3185          , p_gain_or_loss_flag          => 'N'
3187          , p_acct_entry_type_code       => 'A'
3188          , p_switch_side_flag           => 'Y'
3189          , p_merge_duplicate_code       => 'A'
3190          );
3191    --
3192    l_acc_rev_natural_side_code := 'D';  -- 4262811
3193    -- 
3194    --
3195    -- set accounting line type info
3196    --
3197    xla_ae_lines_pkg.SetAcctLineType
3198       (p_component_type             => l_component_type
3199       ,p_event_type_code            => l_event_type_code
3200       ,p_line_definition_owner_code => l_line_definition_owner_code
3201       ,p_line_definition_code       => l_line_definition_code
3202       ,p_accounting_line_code       => l_component_code
3203       ,p_accounting_line_type_code  => l_component_type_code
3204       ,p_accounting_line_appl_id    => l_component_appl_id
3205       ,p_amb_context_code           => l_amb_context_code
3206       ,p_entity_code                => l_entity_code
3207       ,p_event_class_code           => l_event_class_code);
3208    --
3209    -- set accounting class
3210    --
3211    xla_ae_lines_pkg.SetAcctClass(
3212            p_accounting_class_code  => 'FACTOR'
3213          , p_ae_header_id           => l_ae_header_id
3214          );
3215 
3216    --
3217    -- set rounding class
3218    --
3219    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
3220                       'RECEIVABLE';
3221 
3222    --
3223    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
3224    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
3225    --
3226    -- bulk performance
3227    --
3228    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
3229 
3230    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
3231       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
3232 
3233    -- 4955764
3234    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3235       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
3236 
3237    -- 4458381 Public Sector Enh
3238    
3239    --
3240    -- set accounting attributes for the line type
3241    --
3242    l_entered_amt_idx := 3;
3243    l_accted_amt_idx  := 8;
3244    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
3245    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
3246    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
3247    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
3248    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
3249    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
3250    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
3251    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
3252    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
3253    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
3254    l_rec_acct_attrs.array_date_value(5)  := p_source_13;
3255    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
3256    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
3257    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
3258    l_rec_acct_attrs.array_char_value(7)  := p_source_15;
3259    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
3260    l_rec_acct_attrs.array_num_value(8)  := p_source_16;
3261 
3262    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
3263    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
3264 
3265    ---------------------------------------------------------------------------------------------------------------
3266    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
3267    ---------------------------------------------------------------------------------------------------------------
3268    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
3269 
3270    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3271    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3272 
3273    IF xla_accounting_cache_pkg.GetValueChar
3274          (p_source_code         => 'LEDGER_CATEGORY_CODE'
3275          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
3276    AND l_bflow_method_code = 'PRIOR_ENTRY'
3277 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
3278    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
3279          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
3280        )
3281    THEN
3282          xla_ae_lines_pkg.BflowUpgEntry
3283            (p_business_method_code    => l_bflow_method_code
3284            ,p_business_class_code     => l_bflow_class_code
3285            ,p_balance_type            => l_balance_type_code);
3286    ELSE
3287       NULL;
3288 -- No business flow processing for business flow method of NONE.
3289    END IF;
3290 
3291    --
3292    -- call analytical criteria
3293    --
3294    
3298    -- No description or it is inherited.
3295    --
3296    -- call description
3297    --
3299    --
3300    -- call ADRs
3301    -- Bug 4922099
3302    --
3303    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
3304         (NVL(l_actual_upg_option, 'N') = 'O') OR
3305         (NVL(l_enc_upg_option, 'N') = 'O')
3306       )
3307    THEN
3308    NULL;
3309    --
3310    --
3311    
3312   l_ccid := AcctDerRule_1(
3313            p_application_id           => p_application_id
3314          , p_ae_header_id             => l_ae_header_id 
3315 , p_source_1 => p_source_1
3316          , x_transaction_coa_id       => l_adr_transaction_coa_id
3317          , x_accounting_coa_id        => l_adr_accounting_coa_id
3318          , x_value_type_code          => l_adr_value_type_code
3319          , p_side                     => 'NA'
3320    );
3321 
3322    xla_ae_lines_pkg.set_ccid(
3323     p_code_combination_id          => l_ccid
3324   , p_value_type_code              => l_adr_value_type_code
3325   , p_transaction_coa_id           => l_adr_transaction_coa_id
3326   , p_accounting_coa_id            => l_adr_accounting_coa_id
3327   , p_adr_code                     => 'DIST_CCID'
3328   , p_adr_type_code                => 'S'
3329   , p_component_type               => l_component_type
3330   , p_component_code               => l_component_code
3331   , p_component_type_code          => l_component_type_code
3332   , p_component_appl_id            => l_component_appl_id
3333   , p_amb_context_code             => l_amb_context_code
3334   , p_side                         => 'NA'
3335   );
3336 
3337 
3338    --
3339    --
3340    END IF;
3341    --
3342    -- Bug 4922099
3343    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
3344           (NVL(l_enc_upg_option, 'N') = 'O')
3345         ) AND
3346         (l_bflow_method_code = 'PRIOR_ENTRY')
3347       )
3348    THEN
3349       IF
3350       --
3351       1 = 2
3352       --
3353       THEN
3354       xla_accounting_err_pkg.build_message
3355                                     (p_appli_s_name            => 'XLA'
3356                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3357                                     ,p_token_1                 => 'LINE_NUMBER'
3358                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
3359                                     ,p_token_2                 => 'LINE_TYPE_NAME'
3360                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
3361                                                                              l_component_type
3362                                                                             ,l_component_code
3363                                                                             ,l_component_type_code
3364                                                                             ,l_component_appl_id
3365                                                                             ,l_amb_context_code
3366                                                                             ,l_entity_code
3367                                                                             ,l_event_class_code
3368                                                                            )
3369                                     ,p_token_3                 => 'OWNER'
3370                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
3371                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
3372                                                                           ,p_lookup_code    => l_component_type_code
3373                                                                          )
3374                                     ,p_token_4                 => 'PRODUCT_NAME'
3375                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
3376                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
3377                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
3378                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
3379                                     ,p_ae_header_id            =>  NULL
3380                                        );
3381 
3382         IF (C_LEVEL_ERROR>= g_log_level) THEN
3383                  trace
3384                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3385                       ,p_level    => C_LEVEL_ERROR
3386                       ,p_module   => l_log_module);
3387         END IF;
3388       END IF;
3389    END IF;
3390    --
3391    --
3392    ------------------------------------------------------------------------------------------------
3393    -- 4219869 Business Flow
3394    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
3395    -- Prior Entry.  Currently, the following code is always generated.
3396    ------------------------------------------------------------------------------------------------
3397    XLA_AE_LINES_PKG.ValidateCurrentLine;
3398 
3399    ------------------------------------------------------------------------------------
3400    -- 4219869 Business Flow
3401    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
3405    ----------------------------------------------------------------------------------
3402    ------------------------------------------------------------------------------------
3403    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3404 
3406    -- 4219869 Business Flow
3407    -- Update journal entry status -- Need to generate this within IF <condition>
3408    ----------------------------------------------------------------------------------
3409    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3410          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
3411          ,p_balance_type_code => l_balance_type_code
3412          );
3413 
3414    -------------------------------------------------------------------------------------------
3415    -- 4262811 - Generate the Accrual Reversal lines
3416    -------------------------------------------------------------------------------------------
3417    BEGIN
3418       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
3419                               (g_array_event(p_event_id).array_value_num('header_index'));
3420       IF l_acc_rev_flag IS NULL THEN
3421          l_acc_rev_flag := 'N';
3422       END IF;
3423    EXCEPTION
3424       WHEN OTHERS THEN
3425          l_acc_rev_flag := 'N';
3426    END;
3427    --
3428    IF (l_acc_rev_flag = 'Y') THEN
3429 
3430        -- 4645092  ------------------------------------------------------------------------------
3431        -- To allow MPA report to determine if it should generate report process
3432        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
3433        ------------------------------------------------------------------------------------------
3434 
3435        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
3436        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
3437    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
3438    -- call ADRs
3439    -- Bug 4922099
3440    --
3441    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
3442         (NVL(l_actual_upg_option, 'N') = 'O') OR
3443         (NVL(l_enc_upg_option, 'N') = 'O')
3444       )
3445    THEN
3446    NULL;
3447    --
3448    --
3449    
3450   l_ccid := AcctDerRule_1(
3451            p_application_id           => p_application_id
3452          , p_ae_header_id             => l_ae_header_id 
3453 , p_source_1 => p_source_1
3454          , x_transaction_coa_id       => l_adr_transaction_coa_id
3455          , x_accounting_coa_id        => l_adr_accounting_coa_id
3456          , x_value_type_code          => l_adr_value_type_code
3457          , p_side                     => 'NA'
3458    );
3459 
3460    xla_ae_lines_pkg.set_ccid(
3461     p_code_combination_id          => l_ccid
3462   , p_value_type_code              => l_adr_value_type_code
3463   , p_transaction_coa_id           => l_adr_transaction_coa_id
3464   , p_accounting_coa_id            => l_adr_accounting_coa_id
3465   , p_adr_code                     => 'DIST_CCID'
3466   , p_adr_type_code                => 'S'
3467   , p_component_type               => l_component_type
3468   , p_component_code               => l_component_code
3469   , p_component_type_code          => l_component_type_code
3470   , p_component_appl_id            => l_component_appl_id
3471   , p_amb_context_code             => l_amb_context_code
3472   , p_side                         => 'NA'
3473   );
3474 
3475 
3476    --
3477    --
3478    END IF;
3479 
3480        --
3481        -- Update the line information that should be overwritten
3482        --
3483        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
3484                                          p_header_num   => 1);
3485        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
3486 
3487        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
3488 
3489        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
3490           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
3491        END IF;
3492 
3493       --
3494       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
3495       --
3496       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
3497           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
3498       ELSE
3499           ---------------------------------------------------------------------------------------------------
3500           -- 4262811a Switch Sign
3501           ---------------------------------------------------------------------------------------------------
3502           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
3503           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3504                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3505           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3506                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3507           -- 5132302
3508           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
3512 
3509                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3510 
3511       END IF;
3513       -- 4955764
3514       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3515       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
3516 
3517 
3518       XLA_AE_LINES_PKG.ValidateCurrentLine;
3519       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3520 
3521       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3522                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
3523                ,p_balance_type_code => l_balance_type_code);
3524 
3525    END IF;
3526 
3527    -----------------------------------------------------------------------------------------
3528    -- 4262811 Multiperiod Accounting
3529    -----------------------------------------------------------------------------------------
3530      -- No MPA option is assigned.
3531 
3532 
3533 END IF;
3534 END IF;
3535 --
3536 
3537 --
3538 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3539    trace
3540       (p_msg      => 'END of AcctLineType_10'
3541       ,p_level    => C_LEVEL_PROCEDURE
3542       ,p_module   => l_log_module);
3543 END IF;
3544 --
3545 EXCEPTION
3546   WHEN xla_exceptions_pkg.application_exception THEN
3547       RAISE;
3548   WHEN OTHERS THEN
3549        xla_exceptions_pkg.raise_message
3550            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_10');
3551 END AcctLineType_10;
3552 --
3553 
3554 ---------------------------------------
3555 --
3556 -- PRIVATE FUNCTION
3557 --         AcctLineType_11
3558 --
3559 ---------------------------------------
3560 PROCEDURE AcctLineType_11 (
3561   p_application_id        IN NUMBER
3562  ,p_event_id              IN NUMBER
3563  ,p_calculate_acctd_flag  IN VARCHAR2
3564  ,p_calculate_g_l_flag    IN VARCHAR2
3565  ,p_actual_flag           IN OUT VARCHAR2
3566  ,p_balance_type_code     OUT VARCHAR2
3567  ,p_gain_or_loss_ref      OUT VARCHAR2
3568  
3569 --Distribution GL Account
3570  , p_source_1            IN NUMBER
3571 --Distribution Source Type
3572  , p_source_7            IN VARCHAR2
3573 --Distribution Multi Fund Additional Entry
3574  , p_source_8            IN VARCHAR2
3575 --Distribution Line Identifier
3576  , p_source_9            IN NUMBER
3577 --Distribution Type
3578  , p_source_10            IN VARCHAR2
3579 --Entered Amount
3580  , p_source_11            IN NUMBER
3581 --Currency Code
3582  , p_source_12            IN VARCHAR2
3583 --Applied To Document Exchange Date
3584  , p_source_13            IN DATE
3585 --Exchange Rate
3586  , p_source_14            IN NUMBER
3587 --Exchange Rate Type
3588  , p_source_15            IN VARCHAR2
3589 --Applied To Document Accounting Amount
3590  , p_source_16            IN NUMBER
3591 )
3592 IS
3593 
3594 l_component_type              VARCHAR2(80);
3595 l_component_code              VARCHAR2(30);
3596 l_component_type_code         VARCHAR2(1);
3597 l_component_appl_id           INTEGER;
3598 l_amb_context_code            VARCHAR2(30);
3599 l_entity_code                 VARCHAR2(30);
3600 l_event_class_code            VARCHAR2(30);
3601 l_ae_header_id                NUMBER;
3602 l_event_type_code             VARCHAR2(30);
3603 l_line_definition_code        VARCHAR2(30);
3604 l_line_definition_owner_code  VARCHAR2(1);
3605 --
3606 -- adr variables
3607 l_segment                     VARCHAR2(30);
3608 l_ccid                        NUMBER;
3609 l_adr_transaction_coa_id      NUMBER;
3610 l_adr_accounting_coa_id       NUMBER;
3611 l_adr_flexfield_segment_code  VARCHAR2(30);
3612 l_adr_flex_value_set_id       NUMBER;
3613 l_adr_value_type_code         VARCHAR2(30);
3614 l_adr_value_combination_id    NUMBER;
3615 l_adr_value_segment_code      VARCHAR2(30);
3616 
3617 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
3618 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
3619 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
3620 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
3621 
3622 -- 4262811 Variables ------------------------------------------------------------------------------------------
3623 l_entered_amt_idx             NUMBER;
3624 l_accted_amt_idx              NUMBER;
3625 l_acc_rev_flag                VARCHAR2(1);
3626 l_accrual_line_num            NUMBER;
3627 l_tmp_amt                     NUMBER;
3628 l_acc_rev_natural_side_code   VARCHAR2(1);
3629 
3630 l_num_entries                 NUMBER;
3631 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
3632 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
3633 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
3634 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
3635 l_recog_line_1                NUMBER;
3636 l_recog_line_2                NUMBER;
3637 
3638 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
3639 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
3640 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
3641 
3642 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
3643 
3644 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
3648 
3645 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
3646 
3647 ---------------------------------------------------------------------------------------------------------------
3649 
3650 --
3651 -- bulk performance
3652 --
3653 l_balance_type_code           VARCHAR2(1);
3654 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
3655 l_log_module                  VARCHAR2(240);
3656 
3657 --
3658 -- Upgrade strategy
3659 --
3660 l_actual_upg_option           VARCHAR2(1);
3661 l_enc_upg_option           VARCHAR2(1);
3662 
3663 --
3664 BEGIN
3665 --
3666 IF g_log_enabled THEN
3667       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_11';
3668 END IF;
3669 --
3670 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3671 
3672       trace
3673          (p_msg      => 'BEGIN of AcctLineType_11'
3674          ,p_level    => C_LEVEL_PROCEDURE
3675          ,p_module   => l_log_module);
3676 
3677 END IF;
3678 --
3679 l_component_type             := 'AMB_JLT';
3680 l_component_code             := 'MISC_RCT_MISCCASH';
3681 l_component_type_code        := 'S';
3682 l_component_appl_id          :=  222;
3683 l_amb_context_code           := 'DEFAULT';
3684 l_entity_code                := 'RECEIPTS';
3685 l_event_class_code           := 'MISC_RECEIPT';
3686 l_event_type_code            := 'MISC_RECEIPT_ALL';
3687 l_line_definition_owner_code := 'S';
3688 l_line_definition_code       := 'AR_MISC_RECEIPTS';
3689 --
3690 l_balance_type_code          := 'A';
3691 l_segment                     := NULL;
3692 l_ccid                        := NULL;
3693 l_adr_transaction_coa_id      := NULL;
3694 l_adr_accounting_coa_id       := NULL;
3695 l_adr_flexfield_segment_code  := NULL;
3696 l_adr_flex_value_set_id       := NULL;
3697 l_adr_value_type_code         := NULL;
3698 l_adr_value_combination_id    := NULL;
3699 l_adr_value_segment_code      := NULL;
3700 
3701 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
3702 l_bflow_class_code           := '';    -- 4219869 Business Flow
3703 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
3704 l_budgetary_control_flag     := 'N';
3705 
3706 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
3707 l_bflow_applied_to_amt       := NULL; -- 5132302
3708 l_entered_amt_idx            := NULL;          -- 4262811
3709 l_accted_amt_idx             := NULL;          -- 4262811
3710 l_acc_rev_flag               := NULL;          -- 4262811
3711 l_accrual_line_num           := NULL;          -- 4262811
3712 l_tmp_amt                    := NULL;          -- 4262811
3713 --
3714  
3715 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
3716     l_balance_type_code <> 'B' THEN
3717 IF NVL(p_source_7,'
3718 ') =  'MISCCASH' AND 
3719 NVL(p_source_8,'
3720 ') =  'N'
3721  THEN 
3722 
3723    --
3724    XLA_AE_LINES_PKG.SetNewLine;
3725 
3726    p_balance_type_code          := l_balance_type_code;
3727    -- set the flag so later we will know whether the gain loss line needs to be created
3728    
3729    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
3730      p_actual_flag :='A';
3731    END IF;
3732 
3733    --
3734    -- bulk performance
3735    --
3736    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
3737                                       p_header_num   => 0); -- 4262811
3738    --
3739    -- set accounting line options
3740    --
3741    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
3742            p_natural_side_code          => 'C'
3743          , p_gain_or_loss_flag          => 'N'
3744          , p_gl_transfer_mode_code      => 'S'
3745          , p_acct_entry_type_code       => 'A'
3746          , p_switch_side_flag           => 'Y'
3747          , p_merge_duplicate_code       => 'A'
3748          );
3749    --
3750    l_acc_rev_natural_side_code := 'D';  -- 4262811
3751    -- 
3752    --
3753    -- set accounting line type info
3754    --
3755    xla_ae_lines_pkg.SetAcctLineType
3756       (p_component_type             => l_component_type
3757       ,p_event_type_code            => l_event_type_code
3758       ,p_line_definition_owner_code => l_line_definition_owner_code
3759       ,p_line_definition_code       => l_line_definition_code
3760       ,p_accounting_line_code       => l_component_code
3761       ,p_accounting_line_type_code  => l_component_type_code
3762       ,p_accounting_line_appl_id    => l_component_appl_id
3763       ,p_amb_context_code           => l_amb_context_code
3764       ,p_entity_code                => l_entity_code
3765       ,p_event_class_code           => l_event_class_code);
3766    --
3767    -- set accounting class
3768    --
3769    xla_ae_lines_pkg.SetAcctClass(
3770            p_accounting_class_code  => 'MISC_CASH'
3771          , p_ae_header_id           => l_ae_header_id
3772          );
3773 
3774    --
3775    -- set rounding class
3776    --
3777    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
3778                       'RECEIVABLE';
3779 
3780    --
3781    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
3782    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
3783    --
3784    -- bulk performance
3785    --
3789       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
3786    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
3787 
3788    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
3790 
3791    -- 4955764
3792    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3793       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
3794 
3795    -- 4458381 Public Sector Enh
3796    
3797    --
3798    -- set accounting attributes for the line type
3799    --
3800    l_entered_amt_idx := 3;
3801    l_accted_amt_idx  := 8;
3802    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
3803    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
3804    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
3805    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
3806    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
3807    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
3808    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
3809    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
3810    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
3811    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
3812    l_rec_acct_attrs.array_date_value(5)  := p_source_13;
3813    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
3814    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
3815    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
3816    l_rec_acct_attrs.array_char_value(7)  := p_source_15;
3817    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
3818    l_rec_acct_attrs.array_num_value(8)  := p_source_16;
3819 
3820    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
3821    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
3822 
3823    ---------------------------------------------------------------------------------------------------------------
3824    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
3825    ---------------------------------------------------------------------------------------------------------------
3826    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
3827 
3828    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3829    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3830 
3831    IF xla_accounting_cache_pkg.GetValueChar
3832          (p_source_code         => 'LEDGER_CATEGORY_CODE'
3833          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
3834    AND l_bflow_method_code = 'PRIOR_ENTRY'
3835 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
3836    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
3837          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
3838        )
3839    THEN
3840          xla_ae_lines_pkg.BflowUpgEntry
3841            (p_business_method_code    => l_bflow_method_code
3842            ,p_business_class_code     => l_bflow_class_code
3843            ,p_balance_type            => l_balance_type_code);
3844    ELSE
3845       NULL;
3846 -- No business flow processing for business flow method of NONE.
3847    END IF;
3848 
3849    --
3850    -- call analytical criteria
3851    --
3852    
3853    --
3854    -- call description
3855    --
3856    -- No description or it is inherited.
3857    --
3858    -- call ADRs
3859    -- Bug 4922099
3860    --
3861    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
3862         (NVL(l_actual_upg_option, 'N') = 'O') OR
3863         (NVL(l_enc_upg_option, 'N') = 'O')
3864       )
3865    THEN
3866    NULL;
3867    --
3868    --
3869    
3870   l_ccid := AcctDerRule_1(
3871            p_application_id           => p_application_id
3872          , p_ae_header_id             => l_ae_header_id 
3873 , p_source_1 => p_source_1
3874          , x_transaction_coa_id       => l_adr_transaction_coa_id
3875          , x_accounting_coa_id        => l_adr_accounting_coa_id
3876          , x_value_type_code          => l_adr_value_type_code
3877          , p_side                     => 'NA'
3878    );
3879 
3880    xla_ae_lines_pkg.set_ccid(
3881     p_code_combination_id          => l_ccid
3882   , p_value_type_code              => l_adr_value_type_code
3883   , p_transaction_coa_id           => l_adr_transaction_coa_id
3884   , p_accounting_coa_id            => l_adr_accounting_coa_id
3885   , p_adr_code                     => 'DIST_CCID'
3886   , p_adr_type_code                => 'S'
3887   , p_component_type               => l_component_type
3888   , p_component_code               => l_component_code
3889   , p_component_type_code          => l_component_type_code
3890   , p_component_appl_id            => l_component_appl_id
3891   , p_amb_context_code             => l_amb_context_code
3892   , p_side                         => 'NA'
3893   );
3894 
3895 
3896    --
3897    --
3898    END IF;
3899    --
3900    -- Bug 4922099
3901    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
3902           (NVL(l_enc_upg_option, 'N') = 'O')
3903         ) AND
3904         (l_bflow_method_code = 'PRIOR_ENTRY')
3905       )
3906    THEN
3907       IF
3908       --
3909       1 = 2
3910       --
3914                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3911       THEN
3912       xla_accounting_err_pkg.build_message
3913                                     (p_appli_s_name            => 'XLA'
3915                                     ,p_token_1                 => 'LINE_NUMBER'
3916                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
3917                                     ,p_token_2                 => 'LINE_TYPE_NAME'
3918                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
3919                                                                              l_component_type
3920                                                                             ,l_component_code
3921                                                                             ,l_component_type_code
3922                                                                             ,l_component_appl_id
3923                                                                             ,l_amb_context_code
3924                                                                             ,l_entity_code
3925                                                                             ,l_event_class_code
3926                                                                            )
3927                                     ,p_token_3                 => 'OWNER'
3928                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
3929                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
3930                                                                           ,p_lookup_code    => l_component_type_code
3931                                                                          )
3932                                     ,p_token_4                 => 'PRODUCT_NAME'
3933                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
3934                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
3935                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
3936                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
3937                                     ,p_ae_header_id            =>  NULL
3938                                        );
3939 
3940         IF (C_LEVEL_ERROR>= g_log_level) THEN
3941                  trace
3942                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3943                       ,p_level    => C_LEVEL_ERROR
3944                       ,p_module   => l_log_module);
3945         END IF;
3946       END IF;
3947    END IF;
3948    --
3949    --
3950    ------------------------------------------------------------------------------------------------
3951    -- 4219869 Business Flow
3952    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
3953    -- Prior Entry.  Currently, the following code is always generated.
3954    ------------------------------------------------------------------------------------------------
3955    XLA_AE_LINES_PKG.ValidateCurrentLine;
3956 
3957    ------------------------------------------------------------------------------------
3958    -- 4219869 Business Flow
3959    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
3960    ------------------------------------------------------------------------------------
3961    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3962 
3963    ----------------------------------------------------------------------------------
3964    -- 4219869 Business Flow
3965    -- Update journal entry status -- Need to generate this within IF <condition>
3966    ----------------------------------------------------------------------------------
3967    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3968          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
3969          ,p_balance_type_code => l_balance_type_code
3970          );
3971 
3972    -------------------------------------------------------------------------------------------
3973    -- 4262811 - Generate the Accrual Reversal lines
3974    -------------------------------------------------------------------------------------------
3975    BEGIN
3976       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
3977                               (g_array_event(p_event_id).array_value_num('header_index'));
3978       IF l_acc_rev_flag IS NULL THEN
3979          l_acc_rev_flag := 'N';
3980       END IF;
3981    EXCEPTION
3982       WHEN OTHERS THEN
3983          l_acc_rev_flag := 'N';
3984    END;
3985    --
3986    IF (l_acc_rev_flag = 'Y') THEN
3987 
3988        -- 4645092  ------------------------------------------------------------------------------
3989        -- To allow MPA report to determine if it should generate report process
3990        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
3991        ------------------------------------------------------------------------------------------
3992 
3993        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
3994        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
3995    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
3996    -- call ADRs
3997    -- Bug 4922099
3998    --
3999    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4000         (NVL(l_actual_upg_option, 'N') = 'O') OR
4004    NULL;
4001         (NVL(l_enc_upg_option, 'N') = 'O')
4002       )
4003    THEN
4005    --
4006    --
4007    
4008   l_ccid := AcctDerRule_1(
4009            p_application_id           => p_application_id
4010          , p_ae_header_id             => l_ae_header_id 
4011 , p_source_1 => p_source_1
4012          , x_transaction_coa_id       => l_adr_transaction_coa_id
4013          , x_accounting_coa_id        => l_adr_accounting_coa_id
4014          , x_value_type_code          => l_adr_value_type_code
4015          , p_side                     => 'NA'
4016    );
4017 
4018    xla_ae_lines_pkg.set_ccid(
4019     p_code_combination_id          => l_ccid
4020   , p_value_type_code              => l_adr_value_type_code
4021   , p_transaction_coa_id           => l_adr_transaction_coa_id
4022   , p_accounting_coa_id            => l_adr_accounting_coa_id
4023   , p_adr_code                     => 'DIST_CCID'
4024   , p_adr_type_code                => 'S'
4025   , p_component_type               => l_component_type
4026   , p_component_code               => l_component_code
4027   , p_component_type_code          => l_component_type_code
4028   , p_component_appl_id            => l_component_appl_id
4029   , p_amb_context_code             => l_amb_context_code
4030   , p_side                         => 'NA'
4031   );
4032 
4033 
4034    --
4035    --
4036    END IF;
4037 
4038        --
4039        -- Update the line information that should be overwritten
4040        --
4041        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
4042                                          p_header_num   => 1);
4043        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
4044 
4045        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
4046 
4047        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
4048           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
4049        END IF;
4050 
4051       --
4052       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
4053       --
4054       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
4055           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
4056       ELSE
4057           ---------------------------------------------------------------------------------------------------
4058           -- 4262811a Switch Sign
4059           ---------------------------------------------------------------------------------------------------
4060           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
4061           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4062                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4063           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4064                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4065           -- 5132302
4066           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
4067                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4068 
4069       END IF;
4070 
4071       -- 4955764
4072       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4073       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
4074 
4075 
4076       XLA_AE_LINES_PKG.ValidateCurrentLine;
4077       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4078 
4079       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4080                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
4081                ,p_balance_type_code => l_balance_type_code);
4082 
4083    END IF;
4084 
4085    -----------------------------------------------------------------------------------------
4086    -- 4262811 Multiperiod Accounting
4087    -----------------------------------------------------------------------------------------
4088      -- No MPA option is assigned.
4089 
4090 
4091 END IF;
4092 END IF;
4093 --
4094 
4095 --
4096 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4097    trace
4098       (p_msg      => 'END of AcctLineType_11'
4099       ,p_level    => C_LEVEL_PROCEDURE
4100       ,p_module   => l_log_module);
4101 END IF;
4102 --
4103 EXCEPTION
4104   WHEN xla_exceptions_pkg.application_exception THEN
4105       RAISE;
4106   WHEN OTHERS THEN
4107        xla_exceptions_pkg.raise_message
4108            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_11');
4109 END AcctLineType_11;
4110 --
4111 
4112 ---------------------------------------
4113 --
4114 -- PRIVATE FUNCTION
4115 --         AcctLineType_12
4116 --
4117 ---------------------------------------
4118 PROCEDURE AcctLineType_12 (
4119   p_application_id        IN NUMBER
4120  ,p_event_id              IN NUMBER
4121  ,p_calculate_acctd_flag  IN VARCHAR2
4122  ,p_calculate_g_l_flag    IN VARCHAR2
4123  ,p_actual_flag           IN OUT VARCHAR2
4124  ,p_balance_type_code     OUT VARCHAR2
4128  , p_source_1            IN NUMBER
4125  ,p_gain_or_loss_ref      OUT VARCHAR2
4126  
4127 --Distribution GL Account
4129 --Distribution Source Type
4130  , p_source_7            IN VARCHAR2
4131 --Distribution Multi Fund Additional Entry
4132  , p_source_8            IN VARCHAR2
4133 --Distribution Line Identifier
4134  , p_source_9            IN NUMBER
4135 --Distribution Type
4136  , p_source_10            IN VARCHAR2
4137 --Entered Amount
4138  , p_source_11            IN NUMBER
4139 --Currency Code
4140  , p_source_12            IN VARCHAR2
4141 --Applied To Document Exchange Date
4142  , p_source_13            IN DATE
4143 --Exchange Rate
4144  , p_source_14            IN NUMBER
4145 --Exchange Rate Type
4146  , p_source_15            IN VARCHAR2
4147 --Applied To Document Accounting Amount
4148  , p_source_16            IN NUMBER
4149 )
4150 IS
4151 
4152 l_component_type              VARCHAR2(80);
4153 l_component_code              VARCHAR2(30);
4154 l_component_type_code         VARCHAR2(1);
4155 l_component_appl_id           INTEGER;
4156 l_amb_context_code            VARCHAR2(30);
4157 l_entity_code                 VARCHAR2(30);
4158 l_event_class_code            VARCHAR2(30);
4159 l_ae_header_id                NUMBER;
4160 l_event_type_code             VARCHAR2(30);
4161 l_line_definition_code        VARCHAR2(30);
4162 l_line_definition_owner_code  VARCHAR2(1);
4163 --
4164 -- adr variables
4165 l_segment                     VARCHAR2(30);
4166 l_ccid                        NUMBER;
4167 l_adr_transaction_coa_id      NUMBER;
4168 l_adr_accounting_coa_id       NUMBER;
4169 l_adr_flexfield_segment_code  VARCHAR2(30);
4170 l_adr_flex_value_set_id       NUMBER;
4171 l_adr_value_type_code         VARCHAR2(30);
4172 l_adr_value_combination_id    NUMBER;
4173 l_adr_value_segment_code      VARCHAR2(30);
4174 
4175 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
4176 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
4177 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
4178 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
4179 
4180 -- 4262811 Variables ------------------------------------------------------------------------------------------
4181 l_entered_amt_idx             NUMBER;
4182 l_accted_amt_idx              NUMBER;
4183 l_acc_rev_flag                VARCHAR2(1);
4184 l_accrual_line_num            NUMBER;
4185 l_tmp_amt                     NUMBER;
4186 l_acc_rev_natural_side_code   VARCHAR2(1);
4187 
4188 l_num_entries                 NUMBER;
4189 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
4190 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
4191 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
4192 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
4193 l_recog_line_1                NUMBER;
4194 l_recog_line_2                NUMBER;
4195 
4196 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
4197 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
4198 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
4199 
4200 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
4201 
4202 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
4203 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
4204 
4205 ---------------------------------------------------------------------------------------------------------------
4206 
4207 
4208 --
4209 -- bulk performance
4210 --
4211 l_balance_type_code           VARCHAR2(1);
4212 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
4213 l_log_module                  VARCHAR2(240);
4214 
4215 --
4216 -- Upgrade strategy
4217 --
4218 l_actual_upg_option           VARCHAR2(1);
4219 l_enc_upg_option           VARCHAR2(1);
4220 
4221 --
4222 BEGIN
4223 --
4224 IF g_log_enabled THEN
4225       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_12';
4226 END IF;
4227 --
4228 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4229 
4230       trace
4231          (p_msg      => 'BEGIN of AcctLineType_12'
4232          ,p_level    => C_LEVEL_PROCEDURE
4233          ,p_module   => l_log_module);
4234 
4235 END IF;
4236 --
4237 l_component_type             := 'AMB_JLT';
4238 l_component_code             := 'MISC_RCT_REMIT';
4239 l_component_type_code        := 'S';
4240 l_component_appl_id          :=  222;
4241 l_amb_context_code           := 'DEFAULT';
4242 l_entity_code                := 'RECEIPTS';
4243 l_event_class_code           := 'MISC_RECEIPT';
4244 l_event_type_code            := 'MISC_RECEIPT_ALL';
4245 l_line_definition_owner_code := 'S';
4246 l_line_definition_code       := 'AR_MISC_RECEIPTS';
4247 --
4248 l_balance_type_code          := 'A';
4249 l_segment                     := NULL;
4250 l_ccid                        := NULL;
4251 l_adr_transaction_coa_id      := NULL;
4252 l_adr_accounting_coa_id       := NULL;
4253 l_adr_flexfield_segment_code  := NULL;
4254 l_adr_flex_value_set_id       := NULL;
4255 l_adr_value_type_code         := NULL;
4256 l_adr_value_combination_id    := NULL;
4257 l_adr_value_segment_code      := NULL;
4258 
4259 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
4260 l_bflow_class_code           := '';    -- 4219869 Business Flow
4264 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
4261 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
4262 l_budgetary_control_flag     := 'N';
4263 
4265 l_bflow_applied_to_amt       := NULL; -- 5132302
4266 l_entered_amt_idx            := NULL;          -- 4262811
4267 l_accted_amt_idx             := NULL;          -- 4262811
4268 l_acc_rev_flag               := NULL;          -- 4262811
4269 l_accrual_line_num           := NULL;          -- 4262811
4270 l_tmp_amt                    := NULL;          -- 4262811
4271 --
4272  
4273 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
4274     l_balance_type_code <> 'B' THEN
4275 IF NVL(p_source_7,'
4276 ') =  'REMITTANCE' AND 
4277 NVL(p_source_8,'
4278 ') =  'N'
4279  THEN 
4280 
4281    --
4282    XLA_AE_LINES_PKG.SetNewLine;
4283 
4284    p_balance_type_code          := l_balance_type_code;
4285    -- set the flag so later we will know whether the gain loss line needs to be created
4286    
4287    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
4288      p_actual_flag :='A';
4289    END IF;
4290 
4291    --
4292    -- bulk performance
4293    --
4294    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
4295                                       p_header_num   => 0); -- 4262811
4296    --
4297    -- set accounting line options
4298    --
4299    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
4300            p_natural_side_code          => 'C'
4301          , p_gain_or_loss_flag          => 'N'
4302          , p_gl_transfer_mode_code      => 'S'
4303          , p_acct_entry_type_code       => 'A'
4304          , p_switch_side_flag           => 'Y'
4305          , p_merge_duplicate_code       => 'A'
4306          );
4307    --
4308    l_acc_rev_natural_side_code := 'D';  -- 4262811
4309    -- 
4310    --
4311    -- set accounting line type info
4312    --
4313    xla_ae_lines_pkg.SetAcctLineType
4314       (p_component_type             => l_component_type
4315       ,p_event_type_code            => l_event_type_code
4316       ,p_line_definition_owner_code => l_line_definition_owner_code
4317       ,p_line_definition_code       => l_line_definition_code
4318       ,p_accounting_line_code       => l_component_code
4319       ,p_accounting_line_type_code  => l_component_type_code
4320       ,p_accounting_line_appl_id    => l_component_appl_id
4321       ,p_amb_context_code           => l_amb_context_code
4322       ,p_entity_code                => l_entity_code
4323       ,p_event_class_code           => l_event_class_code);
4324    --
4325    -- set accounting class
4326    --
4327    xla_ae_lines_pkg.SetAcctClass(
4328            p_accounting_class_code  => 'REMITTANCE'
4329          , p_ae_header_id           => l_ae_header_id
4330          );
4331 
4332    --
4333    -- set rounding class
4334    --
4335    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
4336                       'RECEIVABLE';
4337 
4338    --
4339    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
4340    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
4341    --
4342    -- bulk performance
4343    --
4344    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
4345 
4346    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
4347       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
4348 
4349    -- 4955764
4350    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4351       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
4352 
4353    -- 4458381 Public Sector Enh
4354    
4355    --
4356    -- set accounting attributes for the line type
4357    --
4358    l_entered_amt_idx := 3;
4359    l_accted_amt_idx  := 8;
4360    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
4361    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
4362    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
4363    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
4364    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
4365    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
4366    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
4367    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
4368    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
4369    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
4370    l_rec_acct_attrs.array_date_value(5)  := p_source_13;
4371    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
4372    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
4373    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
4374    l_rec_acct_attrs.array_char_value(7)  := p_source_15;
4375    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
4376    l_rec_acct_attrs.array_num_value(8)  := p_source_16;
4377 
4378    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
4379    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
4380 
4381    ---------------------------------------------------------------------------------------------------------------
4385 
4382    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
4383    ---------------------------------------------------------------------------------------------------------------
4384    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
4386    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4387    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4388 
4389    IF xla_accounting_cache_pkg.GetValueChar
4390          (p_source_code         => 'LEDGER_CATEGORY_CODE'
4391          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
4392    AND l_bflow_method_code = 'PRIOR_ENTRY'
4393 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
4394    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
4395          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
4396        )
4397    THEN
4398          xla_ae_lines_pkg.BflowUpgEntry
4399            (p_business_method_code    => l_bflow_method_code
4400            ,p_business_class_code     => l_bflow_class_code
4401            ,p_balance_type            => l_balance_type_code);
4402    ELSE
4403       NULL;
4404 -- No business flow processing for business flow method of NONE.
4405    END IF;
4406 
4407    --
4408    -- call analytical criteria
4409    --
4410    
4411    --
4412    -- call description
4413    --
4414    -- No description or it is inherited.
4415    --
4416    -- call ADRs
4417    -- Bug 4922099
4418    --
4419    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4420         (NVL(l_actual_upg_option, 'N') = 'O') OR
4421         (NVL(l_enc_upg_option, 'N') = 'O')
4422       )
4423    THEN
4424    NULL;
4425    --
4426    --
4427    
4428   l_ccid := AcctDerRule_1(
4429            p_application_id           => p_application_id
4430          , p_ae_header_id             => l_ae_header_id 
4431 , p_source_1 => p_source_1
4432          , x_transaction_coa_id       => l_adr_transaction_coa_id
4433          , x_accounting_coa_id        => l_adr_accounting_coa_id
4434          , x_value_type_code          => l_adr_value_type_code
4435          , p_side                     => 'NA'
4436    );
4437 
4438    xla_ae_lines_pkg.set_ccid(
4439     p_code_combination_id          => l_ccid
4440   , p_value_type_code              => l_adr_value_type_code
4441   , p_transaction_coa_id           => l_adr_transaction_coa_id
4442   , p_accounting_coa_id            => l_adr_accounting_coa_id
4443   , p_adr_code                     => 'DIST_CCID'
4444   , p_adr_type_code                => 'S'
4445   , p_component_type               => l_component_type
4446   , p_component_code               => l_component_code
4447   , p_component_type_code          => l_component_type_code
4448   , p_component_appl_id            => l_component_appl_id
4449   , p_amb_context_code             => l_amb_context_code
4450   , p_side                         => 'NA'
4451   );
4452 
4453 
4454    --
4455    --
4456    END IF;
4457    --
4458    -- Bug 4922099
4459    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
4460           (NVL(l_enc_upg_option, 'N') = 'O')
4461         ) AND
4462         (l_bflow_method_code = 'PRIOR_ENTRY')
4463       )
4464    THEN
4465       IF
4466       --
4467       1 = 2
4468       --
4469       THEN
4470       xla_accounting_err_pkg.build_message
4471                                     (p_appli_s_name            => 'XLA'
4472                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4473                                     ,p_token_1                 => 'LINE_NUMBER'
4474                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
4475                                     ,p_token_2                 => 'LINE_TYPE_NAME'
4476                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
4477                                                                              l_component_type
4478                                                                             ,l_component_code
4479                                                                             ,l_component_type_code
4480                                                                             ,l_component_appl_id
4481                                                                             ,l_amb_context_code
4482                                                                             ,l_entity_code
4483                                                                             ,l_event_class_code
4484                                                                            )
4485                                     ,p_token_3                 => 'OWNER'
4486                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
4487                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
4488                                                                           ,p_lookup_code    => l_component_type_code
4489                                                                          )
4490                                     ,p_token_4                 => 'PRODUCT_NAME'
4491                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
4495                                     ,p_ae_header_id            =>  NULL
4492                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
4493                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
4494                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
4496                                        );
4497 
4498         IF (C_LEVEL_ERROR>= g_log_level) THEN
4499                  trace
4500                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4501                       ,p_level    => C_LEVEL_ERROR
4502                       ,p_module   => l_log_module);
4503         END IF;
4504       END IF;
4505    END IF;
4506    --
4507    --
4508    ------------------------------------------------------------------------------------------------
4509    -- 4219869 Business Flow
4510    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
4511    -- Prior Entry.  Currently, the following code is always generated.
4512    ------------------------------------------------------------------------------------------------
4513    XLA_AE_LINES_PKG.ValidateCurrentLine;
4514 
4515    ------------------------------------------------------------------------------------
4516    -- 4219869 Business Flow
4517    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
4518    ------------------------------------------------------------------------------------
4519    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4520 
4521    ----------------------------------------------------------------------------------
4522    -- 4219869 Business Flow
4523    -- Update journal entry status -- Need to generate this within IF <condition>
4524    ----------------------------------------------------------------------------------
4525    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4526          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
4527          ,p_balance_type_code => l_balance_type_code
4528          );
4529 
4530    -------------------------------------------------------------------------------------------
4531    -- 4262811 - Generate the Accrual Reversal lines
4532    -------------------------------------------------------------------------------------------
4533    BEGIN
4534       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
4535                               (g_array_event(p_event_id).array_value_num('header_index'));
4536       IF l_acc_rev_flag IS NULL THEN
4537          l_acc_rev_flag := 'N';
4538       END IF;
4539    EXCEPTION
4540       WHEN OTHERS THEN
4541          l_acc_rev_flag := 'N';
4542    END;
4543    --
4544    IF (l_acc_rev_flag = 'Y') THEN
4545 
4546        -- 4645092  ------------------------------------------------------------------------------
4547        -- To allow MPA report to determine if it should generate report process
4548        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
4549        ------------------------------------------------------------------------------------------
4550 
4551        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
4552        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
4553    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
4554    -- call ADRs
4555    -- Bug 4922099
4556    --
4557    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4558         (NVL(l_actual_upg_option, 'N') = 'O') OR
4559         (NVL(l_enc_upg_option, 'N') = 'O')
4560       )
4561    THEN
4562    NULL;
4563    --
4564    --
4565    
4566   l_ccid := AcctDerRule_1(
4567            p_application_id           => p_application_id
4568          , p_ae_header_id             => l_ae_header_id 
4569 , p_source_1 => p_source_1
4570          , x_transaction_coa_id       => l_adr_transaction_coa_id
4571          , x_accounting_coa_id        => l_adr_accounting_coa_id
4572          , x_value_type_code          => l_adr_value_type_code
4573          , p_side                     => 'NA'
4574    );
4575 
4576    xla_ae_lines_pkg.set_ccid(
4577     p_code_combination_id          => l_ccid
4578   , p_value_type_code              => l_adr_value_type_code
4579   , p_transaction_coa_id           => l_adr_transaction_coa_id
4580   , p_accounting_coa_id            => l_adr_accounting_coa_id
4581   , p_adr_code                     => 'DIST_CCID'
4582   , p_adr_type_code                => 'S'
4583   , p_component_type               => l_component_type
4584   , p_component_code               => l_component_code
4585   , p_component_type_code          => l_component_type_code
4586   , p_component_appl_id            => l_component_appl_id
4587   , p_amb_context_code             => l_amb_context_code
4588   , p_side                         => 'NA'
4589   );
4590 
4591 
4592    --
4593    --
4594    END IF;
4595 
4596        --
4597        -- Update the line information that should be overwritten
4598        --
4599        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
4600                                          p_header_num   => 1);
4601        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
4602 
4603        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
4604 
4608 
4605        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
4606           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
4607        END IF;
4609       --
4610       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
4611       --
4612       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
4613           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
4614       ELSE
4615           ---------------------------------------------------------------------------------------------------
4616           -- 4262811a Switch Sign
4617           ---------------------------------------------------------------------------------------------------
4618           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
4619           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4620                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4621           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4622                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4623           -- 5132302
4624           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
4625                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4626 
4627       END IF;
4628 
4629       -- 4955764
4630       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4631       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
4632 
4633 
4634       XLA_AE_LINES_PKG.ValidateCurrentLine;
4635       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4636 
4637       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4638                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
4639                ,p_balance_type_code => l_balance_type_code);
4640 
4641    END IF;
4642 
4643    -----------------------------------------------------------------------------------------
4644    -- 4262811 Multiperiod Accounting
4645    -----------------------------------------------------------------------------------------
4646      -- No MPA option is assigned.
4647 
4648 
4649 END IF;
4650 END IF;
4651 --
4652 
4653 --
4654 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4655    trace
4656       (p_msg      => 'END of AcctLineType_12'
4657       ,p_level    => C_LEVEL_PROCEDURE
4658       ,p_module   => l_log_module);
4659 END IF;
4660 --
4661 EXCEPTION
4662   WHEN xla_exceptions_pkg.application_exception THEN
4663       RAISE;
4664   WHEN OTHERS THEN
4665        xla_exceptions_pkg.raise_message
4666            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_12');
4667 END AcctLineType_12;
4668 --
4669 
4670 ---------------------------------------
4671 --
4672 -- PRIVATE FUNCTION
4673 --         AcctLineType_13
4674 --
4675 ---------------------------------------
4676 PROCEDURE AcctLineType_13 (
4677   p_application_id        IN NUMBER
4678  ,p_event_id              IN NUMBER
4679  ,p_calculate_acctd_flag  IN VARCHAR2
4680  ,p_calculate_g_l_flag    IN VARCHAR2
4681  ,p_actual_flag           IN OUT VARCHAR2
4682  ,p_balance_type_code     OUT VARCHAR2
4683  ,p_gain_or_loss_ref      OUT VARCHAR2
4684  
4685 --Distribution GL Account
4686  , p_source_1            IN NUMBER
4687 --Distribution Source Type
4688  , p_source_7            IN VARCHAR2
4689 --Distribution Multi Fund Additional Entry
4690  , p_source_8            IN VARCHAR2
4691 --Distribution Line Identifier
4692  , p_source_9            IN NUMBER
4693 --Distribution Type
4694  , p_source_10            IN VARCHAR2
4695 --Entered Amount
4696  , p_source_11            IN NUMBER
4697 --Currency Code
4698  , p_source_12            IN VARCHAR2
4699 --Applied To Document Exchange Date
4700  , p_source_13            IN DATE
4701 --Exchange Rate
4702  , p_source_14            IN NUMBER
4703 --Exchange Rate Type
4704  , p_source_15            IN VARCHAR2
4705 --Applied To Document Accounting Amount
4706  , p_source_16            IN NUMBER
4707 )
4708 IS
4709 
4710 l_component_type              VARCHAR2(80);
4711 l_component_code              VARCHAR2(30);
4712 l_component_type_code         VARCHAR2(1);
4713 l_component_appl_id           INTEGER;
4714 l_amb_context_code            VARCHAR2(30);
4715 l_entity_code                 VARCHAR2(30);
4716 l_event_class_code            VARCHAR2(30);
4717 l_ae_header_id                NUMBER;
4718 l_event_type_code             VARCHAR2(30);
4719 l_line_definition_code        VARCHAR2(30);
4720 l_line_definition_owner_code  VARCHAR2(1);
4721 --
4722 -- adr variables
4723 l_segment                     VARCHAR2(30);
4724 l_ccid                        NUMBER;
4725 l_adr_transaction_coa_id      NUMBER;
4726 l_adr_accounting_coa_id       NUMBER;
4727 l_adr_flexfield_segment_code  VARCHAR2(30);
4728 l_adr_flex_value_set_id       NUMBER;
4729 l_adr_value_type_code         VARCHAR2(30);
4730 l_adr_value_combination_id    NUMBER;
4731 l_adr_value_segment_code      VARCHAR2(30);
4732 
4736 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
4733 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
4734 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
4735 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
4737 
4738 -- 4262811 Variables ------------------------------------------------------------------------------------------
4739 l_entered_amt_idx             NUMBER;
4740 l_accted_amt_idx              NUMBER;
4741 l_acc_rev_flag                VARCHAR2(1);
4742 l_accrual_line_num            NUMBER;
4743 l_tmp_amt                     NUMBER;
4744 l_acc_rev_natural_side_code   VARCHAR2(1);
4745 
4746 l_num_entries                 NUMBER;
4747 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
4748 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
4749 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
4750 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
4751 l_recog_line_1                NUMBER;
4752 l_recog_line_2                NUMBER;
4753 
4754 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
4755 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
4756 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
4757 
4758 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
4759 
4760 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
4761 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
4762 
4763 ---------------------------------------------------------------------------------------------------------------
4764 
4765 
4766 --
4767 -- bulk performance
4768 --
4769 l_balance_type_code           VARCHAR2(1);
4770 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
4771 l_log_module                  VARCHAR2(240);
4772 
4773 --
4774 -- Upgrade strategy
4775 --
4776 l_actual_upg_option           VARCHAR2(1);
4777 l_enc_upg_option           VARCHAR2(1);
4778 
4779 --
4780 BEGIN
4781 --
4782 IF g_log_enabled THEN
4783       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_13';
4784 END IF;
4785 --
4786 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4787 
4788       trace
4789          (p_msg      => 'BEGIN of AcctLineType_13'
4790          ,p_level    => C_LEVEL_PROCEDURE
4791          ,p_module   => l_log_module);
4792 
4793 END IF;
4794 --
4795 l_component_type             := 'AMB_JLT';
4796 l_component_code             := 'MISC_RCT_TAX';
4797 l_component_type_code        := 'S';
4798 l_component_appl_id          :=  222;
4799 l_amb_context_code           := 'DEFAULT';
4800 l_entity_code                := 'RECEIPTS';
4801 l_event_class_code           := 'MISC_RECEIPT';
4802 l_event_type_code            := 'MISC_RECEIPT_ALL';
4803 l_line_definition_owner_code := 'S';
4804 l_line_definition_code       := 'AR_MISC_RECEIPTS';
4805 --
4806 l_balance_type_code          := 'A';
4807 l_segment                     := NULL;
4808 l_ccid                        := NULL;
4809 l_adr_transaction_coa_id      := NULL;
4810 l_adr_accounting_coa_id       := NULL;
4811 l_adr_flexfield_segment_code  := NULL;
4812 l_adr_flex_value_set_id       := NULL;
4813 l_adr_value_type_code         := NULL;
4814 l_adr_value_combination_id    := NULL;
4815 l_adr_value_segment_code      := NULL;
4816 
4817 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
4818 l_bflow_class_code           := '';    -- 4219869 Business Flow
4819 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
4820 l_budgetary_control_flag     := 'N';
4821 
4822 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
4823 l_bflow_applied_to_amt       := NULL; -- 5132302
4824 l_entered_amt_idx            := NULL;          -- 4262811
4825 l_accted_amt_idx             := NULL;          -- 4262811
4826 l_acc_rev_flag               := NULL;          -- 4262811
4827 l_accrual_line_num           := NULL;          -- 4262811
4828 l_tmp_amt                    := NULL;          -- 4262811
4829 --
4830  
4831 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
4832     l_balance_type_code <> 'B' THEN
4833 IF NVL(p_source_7,'
4834 ') =  'TAX' AND 
4835 NVL(p_source_8,'
4836 ') =  'N'
4837  THEN 
4838 
4839    --
4840    XLA_AE_LINES_PKG.SetNewLine;
4841 
4842    p_balance_type_code          := l_balance_type_code;
4843    -- set the flag so later we will know whether the gain loss line needs to be created
4844    
4845    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
4846      p_actual_flag :='A';
4847    END IF;
4848 
4849    --
4850    -- bulk performance
4851    --
4852    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
4853                                       p_header_num   => 0); -- 4262811
4854    --
4855    -- set accounting line options
4856    --
4857    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
4858            p_natural_side_code          => 'C'
4859          , p_gain_or_loss_flag          => 'N'
4860          , p_gl_transfer_mode_code      => 'S'
4861          , p_acct_entry_type_code       => 'A'
4862          , p_switch_side_flag           => 'Y'
4863          , p_merge_duplicate_code       => 'A'
4864          );
4865    --
4866    l_acc_rev_natural_side_code := 'D';  -- 4262811
4867    -- 
4871    xla_ae_lines_pkg.SetAcctLineType
4868    --
4869    -- set accounting line type info
4870    --
4872       (p_component_type             => l_component_type
4873       ,p_event_type_code            => l_event_type_code
4874       ,p_line_definition_owner_code => l_line_definition_owner_code
4875       ,p_line_definition_code       => l_line_definition_code
4876       ,p_accounting_line_code       => l_component_code
4877       ,p_accounting_line_type_code  => l_component_type_code
4878       ,p_accounting_line_appl_id    => l_component_appl_id
4879       ,p_amb_context_code           => l_amb_context_code
4880       ,p_entity_code                => l_entity_code
4881       ,p_event_class_code           => l_event_class_code);
4882    --
4883    -- set accounting class
4884    --
4885    xla_ae_lines_pkg.SetAcctClass(
4886            p_accounting_class_code  => 'TAX'
4887          , p_ae_header_id           => l_ae_header_id
4888          );
4889 
4890    --
4891    -- set rounding class
4892    --
4893    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
4894                       'RECEIVABLE';
4895 
4896    --
4897    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
4898    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
4899    --
4900    -- bulk performance
4901    --
4902    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
4903 
4904    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
4905       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
4906 
4907    -- 4955764
4908    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4909       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
4910 
4911    -- 4458381 Public Sector Enh
4912    
4913    --
4914    -- set accounting attributes for the line type
4915    --
4916    l_entered_amt_idx := 3;
4917    l_accted_amt_idx  := 8;
4918    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
4919    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
4920    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
4921    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
4922    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
4923    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
4924    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
4925    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
4926    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
4927    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_DATE';
4928    l_rec_acct_attrs.array_date_value(5)  := p_source_13;
4929    l_rec_acct_attrs.array_acct_attr_code(6) := 'EXCHANGE_RATE';
4930    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
4931    l_rec_acct_attrs.array_acct_attr_code(7) := 'EXCHANGE_RATE_TYPE';
4932    l_rec_acct_attrs.array_char_value(7)  := p_source_15;
4933    l_rec_acct_attrs.array_acct_attr_code(8) := 'LEDGER_AMOUNT';
4934    l_rec_acct_attrs.array_num_value(8)  := p_source_16;
4935 
4936    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
4937    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
4938 
4939    ---------------------------------------------------------------------------------------------------------------
4940    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
4941    ---------------------------------------------------------------------------------------------------------------
4942    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
4943 
4944    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4945    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4946 
4947    IF xla_accounting_cache_pkg.GetValueChar
4948          (p_source_code         => 'LEDGER_CATEGORY_CODE'
4949          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
4950    AND l_bflow_method_code = 'PRIOR_ENTRY'
4951 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
4952    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
4953          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
4954        )
4955    THEN
4956          xla_ae_lines_pkg.BflowUpgEntry
4957            (p_business_method_code    => l_bflow_method_code
4958            ,p_business_class_code     => l_bflow_class_code
4959            ,p_balance_type            => l_balance_type_code);
4960    ELSE
4961       NULL;
4962 -- No business flow processing for business flow method of NONE.
4963    END IF;
4964 
4965    --
4966    -- call analytical criteria
4967    --
4968    
4969    --
4970    -- call description
4971    --
4972    -- No description or it is inherited.
4973    --
4974    -- call ADRs
4975    -- Bug 4922099
4976    --
4977    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4978         (NVL(l_actual_upg_option, 'N') = 'O') OR
4979         (NVL(l_enc_upg_option, 'N') = 'O')
4980       )
4981    THEN
4982    NULL;
4983    --
4984    --
4985    
4986   l_ccid := AcctDerRule_1(
4987            p_application_id           => p_application_id
4991          , x_accounting_coa_id        => l_adr_accounting_coa_id
4988          , p_ae_header_id             => l_ae_header_id 
4989 , p_source_1 => p_source_1
4990          , x_transaction_coa_id       => l_adr_transaction_coa_id
4992          , x_value_type_code          => l_adr_value_type_code
4993          , p_side                     => 'NA'
4994    );
4995 
4996    xla_ae_lines_pkg.set_ccid(
4997     p_code_combination_id          => l_ccid
4998   , p_value_type_code              => l_adr_value_type_code
4999   , p_transaction_coa_id           => l_adr_transaction_coa_id
5000   , p_accounting_coa_id            => l_adr_accounting_coa_id
5001   , p_adr_code                     => 'DIST_CCID'
5002   , p_adr_type_code                => 'S'
5003   , p_component_type               => l_component_type
5004   , p_component_code               => l_component_code
5005   , p_component_type_code          => l_component_type_code
5006   , p_component_appl_id            => l_component_appl_id
5007   , p_amb_context_code             => l_amb_context_code
5008   , p_side                         => 'NA'
5009   );
5010 
5011 
5012    --
5013    --
5014    END IF;
5015    --
5016    -- Bug 4922099
5017    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
5018           (NVL(l_enc_upg_option, 'N') = 'O')
5019         ) AND
5020         (l_bflow_method_code = 'PRIOR_ENTRY')
5021       )
5022    THEN
5023       IF
5024       --
5025       1 = 2
5026       --
5027       THEN
5028       xla_accounting_err_pkg.build_message
5029                                     (p_appli_s_name            => 'XLA'
5030                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5031                                     ,p_token_1                 => 'LINE_NUMBER'
5032                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
5033                                     ,p_token_2                 => 'LINE_TYPE_NAME'
5034                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
5035                                                                              l_component_type
5036                                                                             ,l_component_code
5037                                                                             ,l_component_type_code
5038                                                                             ,l_component_appl_id
5039                                                                             ,l_amb_context_code
5040                                                                             ,l_entity_code
5041                                                                             ,l_event_class_code
5042                                                                            )
5043                                     ,p_token_3                 => 'OWNER'
5044                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
5045                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
5046                                                                           ,p_lookup_code    => l_component_type_code
5047                                                                          )
5048                                     ,p_token_4                 => 'PRODUCT_NAME'
5049                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
5050                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
5051                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
5052                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
5053                                     ,p_ae_header_id            =>  NULL
5054                                        );
5055 
5056         IF (C_LEVEL_ERROR>= g_log_level) THEN
5057                  trace
5058                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5059                       ,p_level    => C_LEVEL_ERROR
5060                       ,p_module   => l_log_module);
5061         END IF;
5062       END IF;
5063    END IF;
5064    --
5065    --
5066    ------------------------------------------------------------------------------------------------
5067    -- 4219869 Business Flow
5068    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
5069    -- Prior Entry.  Currently, the following code is always generated.
5070    ------------------------------------------------------------------------------------------------
5071    XLA_AE_LINES_PKG.ValidateCurrentLine;
5072 
5073    ------------------------------------------------------------------------------------
5074    -- 4219869 Business Flow
5075    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
5076    ------------------------------------------------------------------------------------
5077    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5078 
5079    ----------------------------------------------------------------------------------
5080    -- 4219869 Business Flow
5081    -- Update journal entry status -- Need to generate this within IF <condition>
5082    ----------------------------------------------------------------------------------
5083    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5087 
5084          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
5085          ,p_balance_type_code => l_balance_type_code
5086          );
5088    -------------------------------------------------------------------------------------------
5089    -- 4262811 - Generate the Accrual Reversal lines
5090    -------------------------------------------------------------------------------------------
5091    BEGIN
5092       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
5093                               (g_array_event(p_event_id).array_value_num('header_index'));
5094       IF l_acc_rev_flag IS NULL THEN
5095          l_acc_rev_flag := 'N';
5096       END IF;
5097    EXCEPTION
5098       WHEN OTHERS THEN
5099          l_acc_rev_flag := 'N';
5100    END;
5101    --
5102    IF (l_acc_rev_flag = 'Y') THEN
5103 
5104        -- 4645092  ------------------------------------------------------------------------------
5105        -- To allow MPA report to determine if it should generate report process
5106        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
5107        ------------------------------------------------------------------------------------------
5108 
5109        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
5110        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
5111    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
5112    -- call ADRs
5113    -- Bug 4922099
5114    --
5115    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5116         (NVL(l_actual_upg_option, 'N') = 'O') OR
5117         (NVL(l_enc_upg_option, 'N') = 'O')
5118       )
5119    THEN
5120    NULL;
5121    --
5122    --
5123    
5124   l_ccid := AcctDerRule_1(
5125            p_application_id           => p_application_id
5126          , p_ae_header_id             => l_ae_header_id 
5127 , p_source_1 => p_source_1
5128          , x_transaction_coa_id       => l_adr_transaction_coa_id
5129          , x_accounting_coa_id        => l_adr_accounting_coa_id
5130          , x_value_type_code          => l_adr_value_type_code
5131          , p_side                     => 'NA'
5132    );
5133 
5134    xla_ae_lines_pkg.set_ccid(
5135     p_code_combination_id          => l_ccid
5136   , p_value_type_code              => l_adr_value_type_code
5137   , p_transaction_coa_id           => l_adr_transaction_coa_id
5138   , p_accounting_coa_id            => l_adr_accounting_coa_id
5139   , p_adr_code                     => 'DIST_CCID'
5140   , p_adr_type_code                => 'S'
5141   , p_component_type               => l_component_type
5142   , p_component_code               => l_component_code
5143   , p_component_type_code          => l_component_type_code
5144   , p_component_appl_id            => l_component_appl_id
5145   , p_amb_context_code             => l_amb_context_code
5146   , p_side                         => 'NA'
5147   );
5148 
5149 
5150    --
5151    --
5152    END IF;
5153 
5154        --
5155        -- Update the line information that should be overwritten
5156        --
5157        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
5158                                          p_header_num   => 1);
5159        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
5160 
5161        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
5162 
5163        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
5164           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
5165        END IF;
5166 
5167       --
5168       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
5169       --
5170       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
5171           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
5172       ELSE
5173           ---------------------------------------------------------------------------------------------------
5174           -- 4262811a Switch Sign
5175           ---------------------------------------------------------------------------------------------------
5176           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
5177           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5178                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5179           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5180                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5181           -- 5132302
5182           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
5183                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5184 
5185       END IF;
5186 
5187       -- 4955764
5188       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5189       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
5190 
5191 
5192       XLA_AE_LINES_PKG.ValidateCurrentLine;
5193       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5194 
5195       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5199    END IF;
5196                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
5197                ,p_balance_type_code => l_balance_type_code);
5198 
5200 
5201    -----------------------------------------------------------------------------------------
5202    -- 4262811 Multiperiod Accounting
5203    -----------------------------------------------------------------------------------------
5204      -- No MPA option is assigned.
5205 
5206 
5207 END IF;
5208 END IF;
5209 --
5210 
5211 --
5212 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5213    trace
5214       (p_msg      => 'END of AcctLineType_13'
5215       ,p_level    => C_LEVEL_PROCEDURE
5216       ,p_module   => l_log_module);
5217 END IF;
5218 --
5219 EXCEPTION
5220   WHEN xla_exceptions_pkg.application_exception THEN
5221       RAISE;
5222   WHEN OTHERS THEN
5223        xla_exceptions_pkg.raise_message
5224            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_13');
5225 END AcctLineType_13;
5226 --
5227 
5228 ---------------------------------------
5229 --
5230 -- PRIVATE FUNCTION
5231 --         AcctLineType_14
5232 --
5233 ---------------------------------------
5234 PROCEDURE AcctLineType_14 (
5235   p_application_id        IN NUMBER
5236  ,p_event_id              IN NUMBER
5237  ,p_calculate_acctd_flag  IN VARCHAR2
5238  ,p_calculate_g_l_flag    IN VARCHAR2
5239  ,p_actual_flag           IN OUT VARCHAR2
5240  ,p_balance_type_code     OUT VARCHAR2
5241  ,p_gain_or_loss_ref      OUT VARCHAR2
5242  
5243 --Distribution GL Account
5244  , p_source_1            IN NUMBER
5245 --Distribution Source Type
5246  , p_source_7            IN VARCHAR2
5247 --Distribution Multi Fund Additional Entry
5248  , p_source_8            IN VARCHAR2
5249 --Distribution Line Identifier
5250  , p_source_9            IN NUMBER
5251 --Distribution Type
5252  , p_source_10            IN VARCHAR2
5253 --Exchange Rate
5254  , p_source_14            IN NUMBER
5255 --Exchange Rate Type
5256  , p_source_15            IN VARCHAR2
5257 --Receipt Applied To Application Identifier
5258  , p_source_17            IN NUMBER
5259 --Transaction Distribution Type
5260  , p_source_18            IN VARCHAR2
5261 --Transaction Entity Code
5262  , p_source_19            IN VARCHAR2
5263 --Transaction Distribution Identifier
5264  , p_source_20            IN NUMBER
5265 --Transaction Identifier
5266  , p_source_21            IN NUMBER
5267 --DIST_ENT_AMT_FROM
5268  , p_source_22            IN NUMBER
5269 --Applying Document Currency Code
5270  , p_source_23            IN VARCHAR2
5271 --Exchange Date
5272  , p_source_24            IN DATE
5273 --Accounting Amount
5274  , p_source_25            IN NUMBER
5275 --Distribution Party Identifier
5276  , p_source_26            IN NUMBER
5277 --Distribution Party Site Id
5278  , p_source_27            IN NUMBER
5279 --Distribution Party Type
5280  , p_source_28            IN VARCHAR2
5281 )
5282 IS
5283 
5284 l_component_type              VARCHAR2(80);
5285 l_component_code              VARCHAR2(30);
5286 l_component_type_code         VARCHAR2(1);
5287 l_component_appl_id           INTEGER;
5288 l_amb_context_code            VARCHAR2(30);
5289 l_entity_code                 VARCHAR2(30);
5290 l_event_class_code            VARCHAR2(30);
5291 l_ae_header_id                NUMBER;
5292 l_event_type_code             VARCHAR2(30);
5293 l_line_definition_code        VARCHAR2(30);
5294 l_line_definition_owner_code  VARCHAR2(1);
5295 --
5296 -- adr variables
5297 l_segment                     VARCHAR2(30);
5298 l_ccid                        NUMBER;
5299 l_adr_transaction_coa_id      NUMBER;
5300 l_adr_accounting_coa_id       NUMBER;
5301 l_adr_flexfield_segment_code  VARCHAR2(30);
5302 l_adr_flex_value_set_id       NUMBER;
5303 l_adr_value_type_code         VARCHAR2(30);
5304 l_adr_value_combination_id    NUMBER;
5305 l_adr_value_segment_code      VARCHAR2(30);
5306 
5307 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
5308 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
5309 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
5310 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
5311 
5312 -- 4262811 Variables ------------------------------------------------------------------------------------------
5313 l_entered_amt_idx             NUMBER;
5314 l_accted_amt_idx              NUMBER;
5315 l_acc_rev_flag                VARCHAR2(1);
5316 l_accrual_line_num            NUMBER;
5317 l_tmp_amt                     NUMBER;
5318 l_acc_rev_natural_side_code   VARCHAR2(1);
5319 
5320 l_num_entries                 NUMBER;
5321 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
5322 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
5323 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
5324 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
5325 l_recog_line_1                NUMBER;
5326 l_recog_line_2                NUMBER;
5327 
5328 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
5329 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
5330 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
5331 
5335 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
5332 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
5333 
5334 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
5336 
5337 ---------------------------------------------------------------------------------------------------------------
5338 
5339 
5340 --
5341 -- bulk performance
5342 --
5343 l_balance_type_code           VARCHAR2(1);
5344 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
5345 l_log_module                  VARCHAR2(240);
5346 
5347 --
5348 -- Upgrade strategy
5349 --
5350 l_actual_upg_option           VARCHAR2(1);
5351 l_enc_upg_option           VARCHAR2(1);
5352 
5353 --
5354 BEGIN
5355 --
5356 IF g_log_enabled THEN
5357       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_14';
5358 END IF;
5359 --
5360 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5361 
5362       trace
5363          (p_msg      => 'BEGIN of AcctLineType_14'
5364          ,p_level    => C_LEVEL_PROCEDURE
5365          ,p_module   => l_log_module);
5366 
5367 END IF;
5368 --
5369 l_component_type             := 'AMB_JLT';
5370 l_component_code             := 'RCT_ACC';
5371 l_component_type_code        := 'S';
5372 l_component_appl_id          :=  222;
5373 l_amb_context_code           := 'DEFAULT';
5374 l_entity_code                := 'RECEIPTS';
5375 l_event_class_code           := 'RECEIPT';
5376 l_event_type_code            := 'RECEIPT_ALL';
5377 l_line_definition_owner_code := 'S';
5378 l_line_definition_code       := 'RCT_CASH_JLD';
5379 --
5380 l_balance_type_code          := 'A';
5381 l_segment                     := NULL;
5382 l_ccid                        := NULL;
5383 l_adr_transaction_coa_id      := NULL;
5384 l_adr_accounting_coa_id       := NULL;
5385 l_adr_flexfield_segment_code  := NULL;
5386 l_adr_flex_value_set_id       := NULL;
5387 l_adr_value_type_code         := NULL;
5388 l_adr_value_combination_id    := NULL;
5389 l_adr_value_segment_code      := NULL;
5390 
5391 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
5392 l_bflow_class_code           := '';    -- 4219869 Business Flow
5393 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
5394 l_budgetary_control_flag     := 'N';
5395 
5396 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
5397 l_bflow_applied_to_amt       := NULL; -- 5132302
5398 l_entered_amt_idx            := NULL;          -- 4262811
5399 l_accted_amt_idx             := NULL;          -- 4262811
5400 l_acc_rev_flag               := NULL;          -- 4262811
5401 l_accrual_line_num           := NULL;          -- 4262811
5402 l_tmp_amt                    := NULL;          -- 4262811
5403 --
5404  
5405 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
5406     l_balance_type_code <> 'B' THEN
5407 IF NVL(p_source_7,'
5408 ') =  'ACC' AND 
5409 NVL(p_source_8,'
5410 ') =  'N'
5411  THEN 
5412 
5413    --
5414    XLA_AE_LINES_PKG.SetNewLine;
5415 
5416    p_balance_type_code          := l_balance_type_code;
5417    -- set the flag so later we will know whether the gain loss line needs to be created
5418    
5419    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
5420      p_actual_flag :='A';
5421    END IF;
5422 
5423    --
5424    -- bulk performance
5425    --
5426    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
5427                                       p_header_num   => 0); -- 4262811
5428    --
5429    -- set accounting line options
5430    --
5431    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
5432            p_natural_side_code          => 'C'
5433          , p_gain_or_loss_flag          => 'N'
5434          , p_gl_transfer_mode_code      => 'S'
5435          , p_acct_entry_type_code       => 'A'
5436          , p_switch_side_flag           => 'Y'
5437          , p_merge_duplicate_code       => 'A'
5438          );
5439    --
5440    l_acc_rev_natural_side_code := 'D';  -- 4262811
5441    -- 
5442    --
5443    -- set accounting line type info
5444    --
5445    xla_ae_lines_pkg.SetAcctLineType
5446       (p_component_type             => l_component_type
5447       ,p_event_type_code            => l_event_type_code
5448       ,p_line_definition_owner_code => l_line_definition_owner_code
5449       ,p_line_definition_code       => l_line_definition_code
5450       ,p_accounting_line_code       => l_component_code
5451       ,p_accounting_line_type_code  => l_component_type_code
5452       ,p_accounting_line_appl_id    => l_component_appl_id
5453       ,p_amb_context_code           => l_amb_context_code
5454       ,p_entity_code                => l_entity_code
5455       ,p_event_class_code           => l_event_class_code);
5456    --
5457    -- set accounting class
5458    --
5459    xla_ae_lines_pkg.SetAcctClass(
5460            p_accounting_class_code  => 'ACC'
5461          , p_ae_header_id           => l_ae_header_id
5462          );
5463 
5464    --
5465    -- set rounding class
5466    --
5467    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
5468                       'RECEIVABLE';
5469 
5470    --
5471    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
5475    --
5472    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
5473    --
5474    -- bulk performance
5476    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
5477 
5478    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
5479       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
5480 
5481    -- 4955764
5482    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5483       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
5484 
5485    -- 4458381 Public Sector Enh
5486    
5487    --
5488    -- set accounting attributes for the line type
5489    --
5490    l_entered_amt_idx := 8;
5491    l_accted_amt_idx  := 13;
5492    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
5493    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
5494    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
5495    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
5496    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
5497    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
5498    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
5499    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
5500    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
5501    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
5502    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
5503    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
5504    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
5505    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
5506    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
5507    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
5508    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
5509    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
5510    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
5511    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
5512    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
5513    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
5514    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
5515    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
5516    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
5517    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
5518    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
5519    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
5520    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
5521    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
5522    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
5523    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
5524    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
5525 
5526    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
5527    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
5528 
5529    ---------------------------------------------------------------------------------------------------------------
5530    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
5531    ---------------------------------------------------------------------------------------------------------------
5532    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
5533 
5534    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5535    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5536 
5537    IF xla_accounting_cache_pkg.GetValueChar
5538          (p_source_code         => 'LEDGER_CATEGORY_CODE'
5539          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
5540    AND l_bflow_method_code = 'PRIOR_ENTRY'
5541 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
5542    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
5543          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
5544        )
5545    THEN
5546          xla_ae_lines_pkg.BflowUpgEntry
5547            (p_business_method_code    => l_bflow_method_code
5548            ,p_business_class_code     => l_bflow_class_code
5549            ,p_balance_type            => l_balance_type_code);
5550    ELSE
5551       NULL;
5552 -- No business flow processing for business flow method of NONE.
5553    END IF;
5554 
5555    --
5556    -- call analytical criteria
5557    --
5558    
5559    --
5560    -- call description
5561    --
5562    -- No description or it is inherited.
5563    --
5564    -- call ADRs
5565    -- Bug 4922099
5566    --
5567    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5568         (NVL(l_actual_upg_option, 'N') = 'O') OR
5569         (NVL(l_enc_upg_option, 'N') = 'O')
5570       )
5571    THEN
5572    NULL;
5573    --
5574    --
5575    
5576   l_ccid := AcctDerRule_1(
5577            p_application_id           => p_application_id
5578          , p_ae_header_id             => l_ae_header_id 
5579 , p_source_1 => p_source_1
5580          , x_transaction_coa_id       => l_adr_transaction_coa_id
5581          , x_accounting_coa_id        => l_adr_accounting_coa_id
5585 
5582          , x_value_type_code          => l_adr_value_type_code
5583          , p_side                     => 'NA'
5584    );
5586    xla_ae_lines_pkg.set_ccid(
5587     p_code_combination_id          => l_ccid
5588   , p_value_type_code              => l_adr_value_type_code
5589   , p_transaction_coa_id           => l_adr_transaction_coa_id
5590   , p_accounting_coa_id            => l_adr_accounting_coa_id
5591   , p_adr_code                     => 'DIST_CCID'
5592   , p_adr_type_code                => 'S'
5593   , p_component_type               => l_component_type
5594   , p_component_code               => l_component_code
5595   , p_component_type_code          => l_component_type_code
5596   , p_component_appl_id            => l_component_appl_id
5597   , p_amb_context_code             => l_amb_context_code
5598   , p_side                         => 'NA'
5599   );
5600 
5601 
5602    --
5603    --
5604    END IF;
5605    --
5606    -- Bug 4922099
5607    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
5608           (NVL(l_enc_upg_option, 'N') = 'O')
5609         ) AND
5610         (l_bflow_method_code = 'PRIOR_ENTRY')
5611       )
5612    THEN
5613       IF
5614       --
5615       1 = 2
5616       --
5617       THEN
5618       xla_accounting_err_pkg.build_message
5619                                     (p_appli_s_name            => 'XLA'
5620                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5621                                     ,p_token_1                 => 'LINE_NUMBER'
5622                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
5623                                     ,p_token_2                 => 'LINE_TYPE_NAME'
5624                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
5625                                                                              l_component_type
5626                                                                             ,l_component_code
5627                                                                             ,l_component_type_code
5628                                                                             ,l_component_appl_id
5629                                                                             ,l_amb_context_code
5630                                                                             ,l_entity_code
5631                                                                             ,l_event_class_code
5632                                                                            )
5633                                     ,p_token_3                 => 'OWNER'
5634                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
5635                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
5636                                                                           ,p_lookup_code    => l_component_type_code
5637                                                                          )
5638                                     ,p_token_4                 => 'PRODUCT_NAME'
5639                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
5640                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
5641                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
5642                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
5643                                     ,p_ae_header_id            =>  NULL
5644                                        );
5645 
5646         IF (C_LEVEL_ERROR>= g_log_level) THEN
5647                  trace
5648                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5649                       ,p_level    => C_LEVEL_ERROR
5650                       ,p_module   => l_log_module);
5651         END IF;
5652       END IF;
5653    END IF;
5654    --
5655    --
5656    ------------------------------------------------------------------------------------------------
5657    -- 4219869 Business Flow
5658    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
5659    -- Prior Entry.  Currently, the following code is always generated.
5660    ------------------------------------------------------------------------------------------------
5661    XLA_AE_LINES_PKG.ValidateCurrentLine;
5662 
5663    ------------------------------------------------------------------------------------
5664    -- 4219869 Business Flow
5665    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
5666    ------------------------------------------------------------------------------------
5667    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5668 
5669    ----------------------------------------------------------------------------------
5670    -- 4219869 Business Flow
5671    -- Update journal entry status -- Need to generate this within IF <condition>
5672    ----------------------------------------------------------------------------------
5673    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5674          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
5675          ,p_balance_type_code => l_balance_type_code
5676          );
5677 
5681    BEGIN
5678    -------------------------------------------------------------------------------------------
5679    -- 4262811 - Generate the Accrual Reversal lines
5680    -------------------------------------------------------------------------------------------
5682       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
5683                               (g_array_event(p_event_id).array_value_num('header_index'));
5684       IF l_acc_rev_flag IS NULL THEN
5685          l_acc_rev_flag := 'N';
5686       END IF;
5687    EXCEPTION
5688       WHEN OTHERS THEN
5689          l_acc_rev_flag := 'N';
5690    END;
5691    --
5692    IF (l_acc_rev_flag = 'Y') THEN
5693 
5694        -- 4645092  ------------------------------------------------------------------------------
5695        -- To allow MPA report to determine if it should generate report process
5696        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
5697        ------------------------------------------------------------------------------------------
5698 
5699        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
5700        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
5701    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
5702    -- call ADRs
5703    -- Bug 4922099
5704    --
5705    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5706         (NVL(l_actual_upg_option, 'N') = 'O') OR
5707         (NVL(l_enc_upg_option, 'N') = 'O')
5708       )
5709    THEN
5710    NULL;
5711    --
5712    --
5713    
5714   l_ccid := AcctDerRule_1(
5715            p_application_id           => p_application_id
5716          , p_ae_header_id             => l_ae_header_id 
5717 , p_source_1 => p_source_1
5718          , x_transaction_coa_id       => l_adr_transaction_coa_id
5719          , x_accounting_coa_id        => l_adr_accounting_coa_id
5720          , x_value_type_code          => l_adr_value_type_code
5721          , p_side                     => 'NA'
5722    );
5723 
5724    xla_ae_lines_pkg.set_ccid(
5725     p_code_combination_id          => l_ccid
5726   , p_value_type_code              => l_adr_value_type_code
5727   , p_transaction_coa_id           => l_adr_transaction_coa_id
5728   , p_accounting_coa_id            => l_adr_accounting_coa_id
5729   , p_adr_code                     => 'DIST_CCID'
5730   , p_adr_type_code                => 'S'
5731   , p_component_type               => l_component_type
5732   , p_component_code               => l_component_code
5733   , p_component_type_code          => l_component_type_code
5734   , p_component_appl_id            => l_component_appl_id
5735   , p_amb_context_code             => l_amb_context_code
5736   , p_side                         => 'NA'
5737   );
5738 
5739 
5740    --
5741    --
5742    END IF;
5743 
5744        --
5745        -- Update the line information that should be overwritten
5746        --
5747        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
5748                                          p_header_num   => 1);
5749        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
5750 
5751        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
5752 
5753        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
5754           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
5755        END IF;
5756 
5757       --
5758       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
5759       --
5760       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
5761           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
5762       ELSE
5763           ---------------------------------------------------------------------------------------------------
5764           -- 4262811a Switch Sign
5765           ---------------------------------------------------------------------------------------------------
5766           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
5767           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5768                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5769           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5770                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5771           -- 5132302
5772           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
5773                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5774 
5775       END IF;
5776 
5777       -- 4955764
5778       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5779       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
5780 
5781 
5782       XLA_AE_LINES_PKG.ValidateCurrentLine;
5783       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5784 
5785       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5786                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
5787                ,p_balance_type_code => l_balance_type_code);
5788 
5789    END IF;
5793    -----------------------------------------------------------------------------------------
5790 
5791    -----------------------------------------------------------------------------------------
5792    -- 4262811 Multiperiod Accounting
5794      -- No MPA option is assigned.
5795 
5796 
5797 END IF;
5798 END IF;
5799 --
5800 
5801 --
5802 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5803    trace
5804       (p_msg      => 'END of AcctLineType_14'
5805       ,p_level    => C_LEVEL_PROCEDURE
5806       ,p_module   => l_log_module);
5807 END IF;
5808 --
5809 EXCEPTION
5810   WHEN xla_exceptions_pkg.application_exception THEN
5811       RAISE;
5812   WHEN OTHERS THEN
5813        xla_exceptions_pkg.raise_message
5814            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_14');
5815 END AcctLineType_14;
5816 --
5817 
5818 ---------------------------------------
5819 --
5820 -- PRIVATE FUNCTION
5821 --         AcctLineType_15
5822 --
5823 ---------------------------------------
5824 PROCEDURE AcctLineType_15 (
5825   p_application_id        IN NUMBER
5826  ,p_event_id              IN NUMBER
5827  ,p_calculate_acctd_flag  IN VARCHAR2
5828  ,p_calculate_g_l_flag    IN VARCHAR2
5829  ,p_actual_flag           IN OUT VARCHAR2
5830  ,p_balance_type_code     OUT VARCHAR2
5831  ,p_gain_or_loss_ref      OUT VARCHAR2
5832  
5833 --Transaction Distribution GL Account
5834  , p_source_5            IN NUMBER
5835 --Reference distribution GL Account
5836  , p_source_6            IN NUMBER
5837 --Distribution Source Type
5838  , p_source_7            IN VARCHAR2
5839 --Distribution Line Identifier
5840  , p_source_9            IN NUMBER
5841 --Distribution Type
5842  , p_source_10            IN VARCHAR2
5843 --Entered Amount
5844  , p_source_11            IN NUMBER
5845 --Currency Code
5846  , p_source_12            IN VARCHAR2
5847 --Applied To Document Exchange Date
5848  , p_source_13            IN DATE
5849 --Applied To Document Accounting Amount
5850  , p_source_16            IN NUMBER
5851 --Receipt Applied To Application Identifier
5852  , p_source_17            IN NUMBER
5853 --Transaction Distribution Type
5854  , p_source_18            IN VARCHAR2
5855 --Transaction Entity Code
5856  , p_source_19            IN VARCHAR2
5857 --Transaction Distribution Identifier
5858  , p_source_20            IN NUMBER
5859 --Transaction Identifier
5860  , p_source_21            IN NUMBER
5861 --Distribution Party Identifier
5862  , p_source_26            IN NUMBER
5863 --Distribution Party Site Id
5864  , p_source_27            IN NUMBER
5865 --Distribution Party Type
5866  , p_source_28            IN VARCHAR2
5867 --Transaction Distribution Account Class
5868  , p_source_29            IN VARCHAR2
5869 --Applied To Document Exchange Rate
5870  , p_source_30            IN NUMBER
5871 --Applied To Document Exchange Rate Type
5872  , p_source_31            IN VARCHAR2
5873 )
5874 IS
5875 
5876 l_component_type              VARCHAR2(80);
5877 l_component_code              VARCHAR2(30);
5878 l_component_type_code         VARCHAR2(1);
5879 l_component_appl_id           INTEGER;
5880 l_amb_context_code            VARCHAR2(30);
5881 l_entity_code                 VARCHAR2(30);
5882 l_event_class_code            VARCHAR2(30);
5883 l_ae_header_id                NUMBER;
5884 l_event_type_code             VARCHAR2(30);
5885 l_line_definition_code        VARCHAR2(30);
5886 l_line_definition_owner_code  VARCHAR2(1);
5887 --
5888 -- adr variables
5889 l_segment                     VARCHAR2(30);
5890 l_ccid                        NUMBER;
5891 l_adr_transaction_coa_id      NUMBER;
5892 l_adr_accounting_coa_id       NUMBER;
5893 l_adr_flexfield_segment_code  VARCHAR2(30);
5894 l_adr_flex_value_set_id       NUMBER;
5895 l_adr_value_type_code         VARCHAR2(30);
5896 l_adr_value_combination_id    NUMBER;
5897 l_adr_value_segment_code      VARCHAR2(30);
5898 
5899 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
5900 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
5901 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
5902 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
5903 
5904 -- 4262811 Variables ------------------------------------------------------------------------------------------
5905 l_entered_amt_idx             NUMBER;
5906 l_accted_amt_idx              NUMBER;
5907 l_acc_rev_flag                VARCHAR2(1);
5908 l_accrual_line_num            NUMBER;
5909 l_tmp_amt                     NUMBER;
5910 l_acc_rev_natural_side_code   VARCHAR2(1);
5911 
5912 l_num_entries                 NUMBER;
5913 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
5914 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
5915 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
5916 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
5917 l_recog_line_1                NUMBER;
5918 l_recog_line_2                NUMBER;
5919 
5920 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
5921 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
5922 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
5923 
5924 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
5925 
5929 ---------------------------------------------------------------------------------------------------------------
5926 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
5927 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
5928 
5930 
5931 
5932 --
5933 -- bulk performance
5934 --
5935 l_balance_type_code           VARCHAR2(1);
5936 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
5937 l_log_module                  VARCHAR2(240);
5938 
5939 --
5940 -- Upgrade strategy
5941 --
5942 l_actual_upg_option           VARCHAR2(1);
5943 l_enc_upg_option           VARCHAR2(1);
5944 
5945 --
5946 BEGIN
5947 --
5948 IF g_log_enabled THEN
5949       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_15';
5950 END IF;
5951 --
5952 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5953 
5954       trace
5955          (p_msg      => 'BEGIN of AcctLineType_15'
5956          ,p_level    => C_LEVEL_PROCEDURE
5957          ,p_module   => l_log_module);
5958 
5959 END IF;
5960 --
5961 l_component_type             := 'AMB_JLT';
5962 l_component_code             := 'RCT_APP_FREIGHT';
5963 l_component_type_code        := 'S';
5964 l_component_appl_id          :=  222;
5965 l_amb_context_code           := 'DEFAULT';
5966 l_entity_code                := 'RECEIPTS';
5967 l_event_class_code           := 'RECEIPT';
5968 l_event_type_code            := 'RECEIPT_ALL';
5969 l_line_definition_owner_code := 'S';
5970 l_line_definition_code       := 'RCT_CASH_JLD';
5971 --
5972 l_balance_type_code          := 'A';
5973 l_segment                     := NULL;
5974 l_ccid                        := NULL;
5975 l_adr_transaction_coa_id      := NULL;
5976 l_adr_accounting_coa_id       := NULL;
5977 l_adr_flexfield_segment_code  := NULL;
5978 l_adr_flex_value_set_id       := NULL;
5979 l_adr_value_type_code         := NULL;
5980 l_adr_value_combination_id    := NULL;
5981 l_adr_value_segment_code      := NULL;
5982 
5983 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
5984 l_bflow_class_code           := '';    -- 4219869 Business Flow
5985 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
5986 l_budgetary_control_flag     := 'N';
5987 
5988 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
5989 l_bflow_applied_to_amt       := NULL; -- 5132302
5990 l_entered_amt_idx            := NULL;          -- 4262811
5991 l_accted_amt_idx             := NULL;          -- 4262811
5992 l_acc_rev_flag               := NULL;          -- 4262811
5993 l_accrual_line_num           := NULL;          -- 4262811
5994 l_tmp_amt                    := NULL;          -- 4262811
5995 --
5996  
5997 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
5998     l_balance_type_code <> 'B' THEN
5999 IF (NVL(p_source_7,'
6000 ') =  'REC' AND 
6001 NVL(p_source_29,'
6002 ') =  'FREIGHT')
6003  THEN 
6004 
6005    --
6006    XLA_AE_LINES_PKG.SetNewLine;
6007 
6008    p_balance_type_code          := l_balance_type_code;
6009    -- set the flag so later we will know whether the gain loss line needs to be created
6010    
6011    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
6012      p_actual_flag :='A';
6013    END IF;
6014 
6015    --
6016    -- bulk performance
6017    --
6018    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
6019                                       p_header_num   => 0); -- 4262811
6020    --
6021    -- set accounting line options
6022    --
6023    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
6024            p_natural_side_code          => 'C'
6025          , p_gain_or_loss_flag          => 'N'
6026          , p_gl_transfer_mode_code      => 'S'
6027          , p_acct_entry_type_code       => 'A'
6028          , p_switch_side_flag           => 'Y'
6029          , p_merge_duplicate_code       => 'A'
6030          );
6031    --
6032    l_acc_rev_natural_side_code := 'D';  -- 4262811
6033    -- 
6034    --
6035    -- set accounting line type info
6036    --
6037    xla_ae_lines_pkg.SetAcctLineType
6038       (p_component_type             => l_component_type
6039       ,p_event_type_code            => l_event_type_code
6040       ,p_line_definition_owner_code => l_line_definition_owner_code
6041       ,p_line_definition_code       => l_line_definition_code
6042       ,p_accounting_line_code       => l_component_code
6043       ,p_accounting_line_type_code  => l_component_type_code
6044       ,p_accounting_line_appl_id    => l_component_appl_id
6045       ,p_amb_context_code           => l_amb_context_code
6046       ,p_entity_code                => l_entity_code
6047       ,p_event_class_code           => l_event_class_code);
6048    --
6049    -- set accounting class
6050    --
6051    xla_ae_lines_pkg.SetAcctClass(
6052            p_accounting_class_code  => 'FREIGHT'
6053          , p_ae_header_id           => l_ae_header_id
6054          );
6055 
6056    --
6057    -- set rounding class
6058    --
6059    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
6060                       'RECEIVABLE';
6061 
6062    --
6063    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
6064    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
6065    --
6066    -- bulk performance
6067    --
6071       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
6068    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
6069 
6070    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
6072 
6073    -- 4955764
6074    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6075       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
6076 
6077    -- 4458381 Public Sector Enh
6078    
6079    --
6080    -- set accounting attributes for the line type
6081    --
6082    l_entered_amt_idx := 8;
6083    l_accted_amt_idx  := 13;
6084    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
6085    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
6086    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
6087    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
6088    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
6089    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
6090    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
6091    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
6092    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
6093    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
6094    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
6095    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
6096    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
6097    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
6098    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
6099    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
6100    l_rec_acct_attrs.array_num_value(8)  := p_source_11;
6101    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
6102    l_rec_acct_attrs.array_char_value(9)  := p_source_12;
6103    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
6104    l_rec_acct_attrs.array_date_value(10)  := p_source_13;
6105    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
6106    l_rec_acct_attrs.array_num_value(11)  := p_source_30;
6107    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
6108    l_rec_acct_attrs.array_char_value(12)  := p_source_31;
6109    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
6110    l_rec_acct_attrs.array_num_value(13)  := p_source_16;
6111    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
6112    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
6113    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
6114    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
6115    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
6116    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
6117 
6118    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
6119    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
6120 
6121    ---------------------------------------------------------------------------------------------------------------
6122    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
6123    ---------------------------------------------------------------------------------------------------------------
6124    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
6125 
6126    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6127    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6128 
6129    IF xla_accounting_cache_pkg.GetValueChar
6130          (p_source_code         => 'LEDGER_CATEGORY_CODE'
6131          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
6132    AND l_bflow_method_code = 'PRIOR_ENTRY'
6133 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
6134    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
6135          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
6136        )
6137    THEN
6138          xla_ae_lines_pkg.BflowUpgEntry
6139            (p_business_method_code    => l_bflow_method_code
6140            ,p_business_class_code     => l_bflow_class_code
6141            ,p_balance_type            => l_balance_type_code);
6142    ELSE
6143       NULL;
6144 -- No business flow processing for business flow method of NONE.
6145    END IF;
6146 
6147    --
6148    -- call analytical criteria
6149    --
6150    
6151    --
6152    -- call description
6153    --
6154    -- No description or it is inherited.
6155    --
6156    -- call ADRs
6157    -- Bug 4922099
6158    --
6159    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
6160         (NVL(l_actual_upg_option, 'N') = 'O') OR
6161         (NVL(l_enc_upg_option, 'N') = 'O')
6162       )
6163    THEN
6164    NULL;
6165    --
6166    --
6167    
6168   l_ccid := AcctDerRule_5(
6169            p_application_id           => p_application_id
6170          , p_ae_header_id             => l_ae_header_id 
6171 , p_source_5 => p_source_5
6172 , p_source_6 => p_source_6
6173          , x_transaction_coa_id       => l_adr_transaction_coa_id
6174          , x_accounting_coa_id        => l_adr_accounting_coa_id
6175          , x_value_type_code          => l_adr_value_type_code
6179    xla_ae_lines_pkg.set_ccid(
6176          , p_side                     => 'NA'
6177    );
6178 
6180     p_code_combination_id          => l_ccid
6181   , p_value_type_code              => l_adr_value_type_code
6182   , p_transaction_coa_id           => l_adr_transaction_coa_id
6183   , p_accounting_coa_id            => l_adr_accounting_coa_id
6184   , p_adr_code                     => 'TRX_REF_DIST_CCID'
6185   , p_adr_type_code                => 'S'
6186   , p_component_type               => l_component_type
6187   , p_component_code               => l_component_code
6188   , p_component_type_code          => l_component_type_code
6189   , p_component_appl_id            => l_component_appl_id
6190   , p_amb_context_code             => l_amb_context_code
6191   , p_side                         => 'NA'
6192   );
6193 
6194 
6195    --
6196    --
6197    END IF;
6198    --
6199    -- Bug 4922099
6200    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
6201           (NVL(l_enc_upg_option, 'N') = 'O')
6202         ) AND
6203         (l_bflow_method_code = 'PRIOR_ENTRY')
6204       )
6205    THEN
6206       IF
6207       --
6208       1 = 2
6209       --
6210       THEN
6211       xla_accounting_err_pkg.build_message
6212                                     (p_appli_s_name            => 'XLA'
6213                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6214                                     ,p_token_1                 => 'LINE_NUMBER'
6215                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
6216                                     ,p_token_2                 => 'LINE_TYPE_NAME'
6217                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
6218                                                                              l_component_type
6219                                                                             ,l_component_code
6220                                                                             ,l_component_type_code
6221                                                                             ,l_component_appl_id
6222                                                                             ,l_amb_context_code
6223                                                                             ,l_entity_code
6224                                                                             ,l_event_class_code
6225                                                                            )
6226                                     ,p_token_3                 => 'OWNER'
6227                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
6228                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
6229                                                                           ,p_lookup_code    => l_component_type_code
6230                                                                          )
6231                                     ,p_token_4                 => 'PRODUCT_NAME'
6232                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
6233                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
6234                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
6235                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
6236                                     ,p_ae_header_id            =>  NULL
6237                                        );
6238 
6239         IF (C_LEVEL_ERROR>= g_log_level) THEN
6240                  trace
6241                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6242                       ,p_level    => C_LEVEL_ERROR
6243                       ,p_module   => l_log_module);
6244         END IF;
6245       END IF;
6246    END IF;
6247    --
6248    --
6249    ------------------------------------------------------------------------------------------------
6250    -- 4219869 Business Flow
6251    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
6252    -- Prior Entry.  Currently, the following code is always generated.
6253    ------------------------------------------------------------------------------------------------
6254    XLA_AE_LINES_PKG.ValidateCurrentLine;
6255 
6256    ------------------------------------------------------------------------------------
6257    -- 4219869 Business Flow
6258    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
6259    ------------------------------------------------------------------------------------
6260    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6261 
6262    ----------------------------------------------------------------------------------
6263    -- 4219869 Business Flow
6264    -- Update journal entry status -- Need to generate this within IF <condition>
6265    ----------------------------------------------------------------------------------
6266    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6267          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
6268          ,p_balance_type_code => l_balance_type_code
6269          );
6270 
6271    -------------------------------------------------------------------------------------------
6272    -- 4262811 - Generate the Accrual Reversal lines
6276                               (g_array_event(p_event_id).array_value_num('header_index'));
6273    -------------------------------------------------------------------------------------------
6274    BEGIN
6275       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
6277       IF l_acc_rev_flag IS NULL THEN
6278          l_acc_rev_flag := 'N';
6279       END IF;
6280    EXCEPTION
6281       WHEN OTHERS THEN
6282          l_acc_rev_flag := 'N';
6283    END;
6284    --
6285    IF (l_acc_rev_flag = 'Y') THEN
6286 
6287        -- 4645092  ------------------------------------------------------------------------------
6288        -- To allow MPA report to determine if it should generate report process
6289        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
6290        ------------------------------------------------------------------------------------------
6291 
6292        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
6293        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
6294    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
6295    -- call ADRs
6296    -- Bug 4922099
6297    --
6298    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
6299         (NVL(l_actual_upg_option, 'N') = 'O') OR
6300         (NVL(l_enc_upg_option, 'N') = 'O')
6301       )
6302    THEN
6303    NULL;
6304    --
6305    --
6306    
6307   l_ccid := AcctDerRule_5(
6308            p_application_id           => p_application_id
6309          , p_ae_header_id             => l_ae_header_id 
6310 , p_source_5 => p_source_5
6311 , p_source_6 => p_source_6
6312          , x_transaction_coa_id       => l_adr_transaction_coa_id
6313          , x_accounting_coa_id        => l_adr_accounting_coa_id
6314          , x_value_type_code          => l_adr_value_type_code
6315          , p_side                     => 'NA'
6316    );
6317 
6318    xla_ae_lines_pkg.set_ccid(
6319     p_code_combination_id          => l_ccid
6320   , p_value_type_code              => l_adr_value_type_code
6321   , p_transaction_coa_id           => l_adr_transaction_coa_id
6322   , p_accounting_coa_id            => l_adr_accounting_coa_id
6323   , p_adr_code                     => 'TRX_REF_DIST_CCID'
6324   , p_adr_type_code                => 'S'
6325   , p_component_type               => l_component_type
6326   , p_component_code               => l_component_code
6327   , p_component_type_code          => l_component_type_code
6328   , p_component_appl_id            => l_component_appl_id
6329   , p_amb_context_code             => l_amb_context_code
6330   , p_side                         => 'NA'
6331   );
6332 
6333 
6334    --
6335    --
6336    END IF;
6337 
6338        --
6339        -- Update the line information that should be overwritten
6340        --
6341        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
6342                                          p_header_num   => 1);
6343        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
6344 
6345        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
6346 
6347        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
6348           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
6349        END IF;
6350 
6351       --
6352       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
6353       --
6354       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
6355           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
6356       ELSE
6357           ---------------------------------------------------------------------------------------------------
6358           -- 4262811a Switch Sign
6359           ---------------------------------------------------------------------------------------------------
6360           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
6361           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6362                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6363           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6364                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6365           -- 5132302
6366           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
6367                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6368 
6369       END IF;
6370 
6371       -- 4955764
6372       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6373       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
6374 
6375 
6376       XLA_AE_LINES_PKG.ValidateCurrentLine;
6377       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6378 
6379       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6380                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
6381                ,p_balance_type_code => l_balance_type_code);
6382 
6383    END IF;
6384 
6385    -----------------------------------------------------------------------------------------
6389 
6386    -- 4262811 Multiperiod Accounting
6387    -----------------------------------------------------------------------------------------
6388      -- No MPA option is assigned.
6390 
6391 END IF;
6392 END IF;
6393 --
6394 
6395 --
6396 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6397    trace
6398       (p_msg      => 'END of AcctLineType_15'
6399       ,p_level    => C_LEVEL_PROCEDURE
6400       ,p_module   => l_log_module);
6401 END IF;
6402 --
6403 EXCEPTION
6404   WHEN xla_exceptions_pkg.application_exception THEN
6405       RAISE;
6406   WHEN OTHERS THEN
6407        xla_exceptions_pkg.raise_message
6408            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_15');
6409 END AcctLineType_15;
6410 --
6411 
6412 ---------------------------------------
6413 --
6414 -- PRIVATE FUNCTION
6415 --         AcctLineType_16
6416 --
6417 ---------------------------------------
6418 PROCEDURE AcctLineType_16 (
6419   p_application_id        IN NUMBER
6420  ,p_event_id              IN NUMBER
6421  ,p_calculate_acctd_flag  IN VARCHAR2
6422  ,p_calculate_g_l_flag    IN VARCHAR2
6423  ,p_actual_flag           IN OUT VARCHAR2
6424  ,p_balance_type_code     OUT VARCHAR2
6425  ,p_gain_or_loss_ref      OUT VARCHAR2
6426  
6427 --Transaction Distribution GL Account
6428  , p_source_5            IN NUMBER
6429 --Reference distribution GL Account
6430  , p_source_6            IN NUMBER
6431 --Distribution Source Type
6432  , p_source_7            IN VARCHAR2
6433 --Distribution Line Identifier
6434  , p_source_9            IN NUMBER
6435 --Distribution Type
6436  , p_source_10            IN VARCHAR2
6437 --Entered Amount
6438  , p_source_11            IN NUMBER
6439 --Currency Code
6440  , p_source_12            IN VARCHAR2
6441 --Applied To Document Exchange Date
6442  , p_source_13            IN DATE
6443 --Applied To Document Accounting Amount
6444  , p_source_16            IN NUMBER
6445 --Receipt Applied To Application Identifier
6446  , p_source_17            IN NUMBER
6447 --Transaction Distribution Type
6448  , p_source_18            IN VARCHAR2
6449 --Transaction Entity Code
6450  , p_source_19            IN VARCHAR2
6451 --Transaction Distribution Identifier
6452  , p_source_20            IN NUMBER
6453 --Transaction Identifier
6454  , p_source_21            IN NUMBER
6455 --Distribution Party Identifier
6456  , p_source_26            IN NUMBER
6457 --Distribution Party Site Id
6458  , p_source_27            IN NUMBER
6459 --Distribution Party Type
6460  , p_source_28            IN VARCHAR2
6461 --Transaction Distribution Account Class
6462  , p_source_29            IN VARCHAR2
6463 --Applied To Document Exchange Rate
6464  , p_source_30            IN NUMBER
6465 --Applied To Document Exchange Rate Type
6466  , p_source_31            IN VARCHAR2
6467 )
6468 IS
6469 
6470 l_component_type              VARCHAR2(80);
6471 l_component_code              VARCHAR2(30);
6472 l_component_type_code         VARCHAR2(1);
6473 l_component_appl_id           INTEGER;
6474 l_amb_context_code            VARCHAR2(30);
6475 l_entity_code                 VARCHAR2(30);
6476 l_event_class_code            VARCHAR2(30);
6477 l_ae_header_id                NUMBER;
6478 l_event_type_code             VARCHAR2(30);
6479 l_line_definition_code        VARCHAR2(30);
6480 l_line_definition_owner_code  VARCHAR2(1);
6481 --
6482 -- adr variables
6483 l_segment                     VARCHAR2(30);
6484 l_ccid                        NUMBER;
6485 l_adr_transaction_coa_id      NUMBER;
6486 l_adr_accounting_coa_id       NUMBER;
6487 l_adr_flexfield_segment_code  VARCHAR2(30);
6488 l_adr_flex_value_set_id       NUMBER;
6489 l_adr_value_type_code         VARCHAR2(30);
6490 l_adr_value_combination_id    NUMBER;
6491 l_adr_value_segment_code      VARCHAR2(30);
6492 
6493 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
6494 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
6495 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
6496 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
6497 
6498 -- 4262811 Variables ------------------------------------------------------------------------------------------
6499 l_entered_amt_idx             NUMBER;
6500 l_accted_amt_idx              NUMBER;
6501 l_acc_rev_flag                VARCHAR2(1);
6502 l_accrual_line_num            NUMBER;
6503 l_tmp_amt                     NUMBER;
6504 l_acc_rev_natural_side_code   VARCHAR2(1);
6505 
6506 l_num_entries                 NUMBER;
6507 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
6508 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
6509 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
6510 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
6511 l_recog_line_1                NUMBER;
6512 l_recog_line_2                NUMBER;
6513 
6514 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
6515 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
6516 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
6517 
6518 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
6519 
6520 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
6524 
6521 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
6522 
6523 ---------------------------------------------------------------------------------------------------------------
6525 
6526 --
6527 -- bulk performance
6528 --
6529 l_balance_type_code           VARCHAR2(1);
6530 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
6531 l_log_module                  VARCHAR2(240);
6532 
6533 --
6534 -- Upgrade strategy
6535 --
6536 l_actual_upg_option           VARCHAR2(1);
6537 l_enc_upg_option           VARCHAR2(1);
6538 
6539 --
6540 BEGIN
6541 --
6542 IF g_log_enabled THEN
6543       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_16';
6544 END IF;
6545 --
6546 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6547 
6548       trace
6549          (p_msg      => 'BEGIN of AcctLineType_16'
6550          ,p_level    => C_LEVEL_PROCEDURE
6551          ,p_module   => l_log_module);
6552 
6553 END IF;
6554 --
6555 l_component_type             := 'AMB_JLT';
6556 l_component_code             := 'RCT_APP_REV';
6557 l_component_type_code        := 'S';
6558 l_component_appl_id          :=  222;
6559 l_amb_context_code           := 'DEFAULT';
6560 l_entity_code                := 'RECEIPTS';
6561 l_event_class_code           := 'RECEIPT';
6562 l_event_type_code            := 'RECEIPT_ALL';
6563 l_line_definition_owner_code := 'S';
6564 l_line_definition_code       := 'RCT_CASH_JLD';
6565 --
6566 l_balance_type_code          := 'A';
6567 l_segment                     := NULL;
6568 l_ccid                        := NULL;
6569 l_adr_transaction_coa_id      := NULL;
6570 l_adr_accounting_coa_id       := NULL;
6571 l_adr_flexfield_segment_code  := NULL;
6572 l_adr_flex_value_set_id       := NULL;
6573 l_adr_value_type_code         := NULL;
6574 l_adr_value_combination_id    := NULL;
6575 l_adr_value_segment_code      := NULL;
6576 
6577 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
6578 l_bflow_class_code           := '';    -- 4219869 Business Flow
6579 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
6580 l_budgetary_control_flag     := 'N';
6581 
6582 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
6583 l_bflow_applied_to_amt       := NULL; -- 5132302
6584 l_entered_amt_idx            := NULL;          -- 4262811
6585 l_accted_amt_idx             := NULL;          -- 4262811
6586 l_acc_rev_flag               := NULL;          -- 4262811
6587 l_accrual_line_num           := NULL;          -- 4262811
6588 l_tmp_amt                    := NULL;          -- 4262811
6589 --
6590  
6591 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
6592     l_balance_type_code <> 'B' THEN
6593 IF NVL(p_source_7,'
6594 ') =  'REC' AND 
6595 NVL(p_source_29,'
6596 ') =  'REV'
6597  THEN 
6598 
6599    --
6600    XLA_AE_LINES_PKG.SetNewLine;
6601 
6602    p_balance_type_code          := l_balance_type_code;
6603    -- set the flag so later we will know whether the gain loss line needs to be created
6604    
6605    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
6606      p_actual_flag :='A';
6607    END IF;
6608 
6609    --
6610    -- bulk performance
6611    --
6612    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
6613                                       p_header_num   => 0); -- 4262811
6614    --
6615    -- set accounting line options
6616    --
6617    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
6618            p_natural_side_code          => 'C'
6619          , p_gain_or_loss_flag          => 'N'
6620          , p_gl_transfer_mode_code      => 'S'
6621          , p_acct_entry_type_code       => 'A'
6622          , p_switch_side_flag           => 'Y'
6623          , p_merge_duplicate_code       => 'A'
6624          );
6625    --
6626    l_acc_rev_natural_side_code := 'D';  -- 4262811
6627    -- 
6628    --
6629    -- set accounting line type info
6630    --
6631    xla_ae_lines_pkg.SetAcctLineType
6632       (p_component_type             => l_component_type
6633       ,p_event_type_code            => l_event_type_code
6634       ,p_line_definition_owner_code => l_line_definition_owner_code
6635       ,p_line_definition_code       => l_line_definition_code
6636       ,p_accounting_line_code       => l_component_code
6637       ,p_accounting_line_type_code  => l_component_type_code
6638       ,p_accounting_line_appl_id    => l_component_appl_id
6639       ,p_amb_context_code           => l_amb_context_code
6640       ,p_entity_code                => l_entity_code
6641       ,p_event_class_code           => l_event_class_code);
6642    --
6643    -- set accounting class
6644    --
6645    xla_ae_lines_pkg.SetAcctClass(
6646            p_accounting_class_code  => 'REVENUE'
6647          , p_ae_header_id           => l_ae_header_id
6648          );
6649 
6650    --
6651    -- set rounding class
6652    --
6653    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
6654                       'RECEIVABLE';
6655 
6656    --
6657    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
6658    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
6659    --
6660    -- bulk performance
6661    --
6665       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
6662    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
6663 
6664    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
6666 
6667    -- 4955764
6668    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6669       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
6670 
6671    -- 4458381 Public Sector Enh
6672    
6673    --
6674    -- set accounting attributes for the line type
6675    --
6676    l_entered_amt_idx := 8;
6677    l_accted_amt_idx  := 13;
6678    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
6679    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
6680    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
6681    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
6682    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
6683    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
6684    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
6685    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
6686    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
6687    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
6688    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
6689    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
6690    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
6691    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
6692    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
6693    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
6694    l_rec_acct_attrs.array_num_value(8)  := p_source_11;
6695    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
6696    l_rec_acct_attrs.array_char_value(9)  := p_source_12;
6697    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
6698    l_rec_acct_attrs.array_date_value(10)  := p_source_13;
6699    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
6700    l_rec_acct_attrs.array_num_value(11)  := p_source_30;
6701    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
6702    l_rec_acct_attrs.array_char_value(12)  := p_source_31;
6703    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
6704    l_rec_acct_attrs.array_num_value(13)  := p_source_16;
6705    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
6706    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
6707    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
6708    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
6709    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
6710    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
6711 
6712    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
6713    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
6714 
6715    ---------------------------------------------------------------------------------------------------------------
6716    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
6717    ---------------------------------------------------------------------------------------------------------------
6718    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
6719 
6720    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6721    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6722 
6723    IF xla_accounting_cache_pkg.GetValueChar
6724          (p_source_code         => 'LEDGER_CATEGORY_CODE'
6725          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
6726    AND l_bflow_method_code = 'PRIOR_ENTRY'
6727 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
6728    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
6729          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
6730        )
6731    THEN
6732          xla_ae_lines_pkg.BflowUpgEntry
6733            (p_business_method_code    => l_bflow_method_code
6734            ,p_business_class_code     => l_bflow_class_code
6735            ,p_balance_type            => l_balance_type_code);
6736    ELSE
6737       NULL;
6738 -- No business flow processing for business flow method of NONE.
6739    END IF;
6740 
6741    --
6742    -- call analytical criteria
6743    --
6744    
6745    --
6746    -- call description
6747    --
6748    -- No description or it is inherited.
6749    --
6750    -- call ADRs
6751    -- Bug 4922099
6752    --
6753    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
6754         (NVL(l_actual_upg_option, 'N') = 'O') OR
6755         (NVL(l_enc_upg_option, 'N') = 'O')
6756       )
6757    THEN
6758    NULL;
6759    --
6760    --
6761    
6762   l_ccid := AcctDerRule_5(
6763            p_application_id           => p_application_id
6764          , p_ae_header_id             => l_ae_header_id 
6765 , p_source_5 => p_source_5
6766 , p_source_6 => p_source_6
6767          , x_transaction_coa_id       => l_adr_transaction_coa_id
6768          , x_accounting_coa_id        => l_adr_accounting_coa_id
6769          , x_value_type_code          => l_adr_value_type_code
6770          , p_side                     => 'NA'
6771    );
6775   , p_value_type_code              => l_adr_value_type_code
6772 
6773    xla_ae_lines_pkg.set_ccid(
6774     p_code_combination_id          => l_ccid
6776   , p_transaction_coa_id           => l_adr_transaction_coa_id
6777   , p_accounting_coa_id            => l_adr_accounting_coa_id
6778   , p_adr_code                     => 'TRX_REF_DIST_CCID'
6779   , p_adr_type_code                => 'S'
6780   , p_component_type               => l_component_type
6781   , p_component_code               => l_component_code
6782   , p_component_type_code          => l_component_type_code
6783   , p_component_appl_id            => l_component_appl_id
6784   , p_amb_context_code             => l_amb_context_code
6785   , p_side                         => 'NA'
6786   );
6787 
6788 
6789    --
6790    --
6791    END IF;
6792    --
6793    -- Bug 4922099
6794    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
6795           (NVL(l_enc_upg_option, 'N') = 'O')
6796         ) AND
6797         (l_bflow_method_code = 'PRIOR_ENTRY')
6798       )
6799    THEN
6800       IF
6801       --
6802       1 = 2
6803       --
6804       THEN
6805       xla_accounting_err_pkg.build_message
6806                                     (p_appli_s_name            => 'XLA'
6807                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6808                                     ,p_token_1                 => 'LINE_NUMBER'
6809                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
6810                                     ,p_token_2                 => 'LINE_TYPE_NAME'
6811                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
6812                                                                              l_component_type
6813                                                                             ,l_component_code
6814                                                                             ,l_component_type_code
6815                                                                             ,l_component_appl_id
6816                                                                             ,l_amb_context_code
6817                                                                             ,l_entity_code
6818                                                                             ,l_event_class_code
6819                                                                            )
6820                                     ,p_token_3                 => 'OWNER'
6821                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
6822                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
6823                                                                           ,p_lookup_code    => l_component_type_code
6824                                                                          )
6825                                     ,p_token_4                 => 'PRODUCT_NAME'
6826                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
6827                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
6828                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
6829                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
6830                                     ,p_ae_header_id            =>  NULL
6831                                        );
6832 
6833         IF (C_LEVEL_ERROR>= g_log_level) THEN
6834                  trace
6835                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6836                       ,p_level    => C_LEVEL_ERROR
6837                       ,p_module   => l_log_module);
6838         END IF;
6839       END IF;
6840    END IF;
6841    --
6842    --
6843    ------------------------------------------------------------------------------------------------
6844    -- 4219869 Business Flow
6845    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
6846    -- Prior Entry.  Currently, the following code is always generated.
6847    ------------------------------------------------------------------------------------------------
6848    XLA_AE_LINES_PKG.ValidateCurrentLine;
6849 
6850    ------------------------------------------------------------------------------------
6851    -- 4219869 Business Flow
6852    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
6853    ------------------------------------------------------------------------------------
6854    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6855 
6856    ----------------------------------------------------------------------------------
6857    -- 4219869 Business Flow
6858    -- Update journal entry status -- Need to generate this within IF <condition>
6862          ,p_balance_type_code => l_balance_type_code
6859    ----------------------------------------------------------------------------------
6860    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6861          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
6863          );
6864 
6865    -------------------------------------------------------------------------------------------
6866    -- 4262811 - Generate the Accrual Reversal lines
6867    -------------------------------------------------------------------------------------------
6868    BEGIN
6869       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
6870                               (g_array_event(p_event_id).array_value_num('header_index'));
6871       IF l_acc_rev_flag IS NULL THEN
6872          l_acc_rev_flag := 'N';
6873       END IF;
6874    EXCEPTION
6875       WHEN OTHERS THEN
6876          l_acc_rev_flag := 'N';
6877    END;
6878    --
6879    IF (l_acc_rev_flag = 'Y') THEN
6880 
6881        -- 4645092  ------------------------------------------------------------------------------
6882        -- To allow MPA report to determine if it should generate report process
6883        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
6884        ------------------------------------------------------------------------------------------
6885 
6886        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
6887        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
6888    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
6889    -- call ADRs
6890    -- Bug 4922099
6891    --
6892    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
6893         (NVL(l_actual_upg_option, 'N') = 'O') OR
6894         (NVL(l_enc_upg_option, 'N') = 'O')
6895       )
6896    THEN
6897    NULL;
6898    --
6899    --
6900    
6901   l_ccid := AcctDerRule_5(
6902            p_application_id           => p_application_id
6903          , p_ae_header_id             => l_ae_header_id 
6904 , p_source_5 => p_source_5
6905 , p_source_6 => p_source_6
6906          , x_transaction_coa_id       => l_adr_transaction_coa_id
6907          , x_accounting_coa_id        => l_adr_accounting_coa_id
6908          , x_value_type_code          => l_adr_value_type_code
6909          , p_side                     => 'NA'
6910    );
6911 
6912    xla_ae_lines_pkg.set_ccid(
6913     p_code_combination_id          => l_ccid
6914   , p_value_type_code              => l_adr_value_type_code
6915   , p_transaction_coa_id           => l_adr_transaction_coa_id
6916   , p_accounting_coa_id            => l_adr_accounting_coa_id
6917   , p_adr_code                     => 'TRX_REF_DIST_CCID'
6918   , p_adr_type_code                => 'S'
6919   , p_component_type               => l_component_type
6920   , p_component_code               => l_component_code
6921   , p_component_type_code          => l_component_type_code
6922   , p_component_appl_id            => l_component_appl_id
6923   , p_amb_context_code             => l_amb_context_code
6924   , p_side                         => 'NA'
6925   );
6926 
6927 
6928    --
6929    --
6930    END IF;
6931 
6932        --
6933        -- Update the line information that should be overwritten
6934        --
6935        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
6936                                          p_header_num   => 1);
6937        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
6938 
6939        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
6940 
6941        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
6942           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
6943        END IF;
6944 
6945       --
6946       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
6947       --
6948       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
6949           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
6950       ELSE
6951           ---------------------------------------------------------------------------------------------------
6952           -- 4262811a Switch Sign
6953           ---------------------------------------------------------------------------------------------------
6954           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
6955           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6956                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6957           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6958                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6959           -- 5132302
6960           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
6961                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6962 
6963       END IF;
6964 
6965       -- 4955764
6966       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6967       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
6968 
6972 
6969 
6970       XLA_AE_LINES_PKG.ValidateCurrentLine;
6971       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6973       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6974                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
6975                ,p_balance_type_code => l_balance_type_code);
6976 
6977    END IF;
6978 
6979    -----------------------------------------------------------------------------------------
6980    -- 4262811 Multiperiod Accounting
6981    -----------------------------------------------------------------------------------------
6982      -- No MPA option is assigned.
6983 
6984 
6985 END IF;
6986 END IF;
6987 --
6988 
6989 --
6990 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6991    trace
6992       (p_msg      => 'END of AcctLineType_16'
6993       ,p_level    => C_LEVEL_PROCEDURE
6994       ,p_module   => l_log_module);
6995 END IF;
6996 --
6997 EXCEPTION
6998   WHEN xla_exceptions_pkg.application_exception THEN
6999       RAISE;
7000   WHEN OTHERS THEN
7001        xla_exceptions_pkg.raise_message
7002            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_16');
7003 END AcctLineType_16;
7004 --
7005 
7006 ---------------------------------------
7007 --
7008 -- PRIVATE FUNCTION
7009 --         AcctLineType_17
7010 --
7011 ---------------------------------------
7012 PROCEDURE AcctLineType_17 (
7013   p_application_id        IN NUMBER
7014  ,p_event_id              IN NUMBER
7015  ,p_calculate_acctd_flag  IN VARCHAR2
7016  ,p_calculate_g_l_flag    IN VARCHAR2
7017  ,p_actual_flag           IN OUT VARCHAR2
7018  ,p_balance_type_code     OUT VARCHAR2
7019  ,p_gain_or_loss_ref      OUT VARCHAR2
7020  
7021 --Transaction Distribution GL Account
7022  , p_source_5            IN NUMBER
7023 --Reference distribution GL Account
7024  , p_source_6            IN NUMBER
7025 --Distribution Source Type
7026  , p_source_7            IN VARCHAR2
7027 --Distribution Line Identifier
7028  , p_source_9            IN NUMBER
7029 --Distribution Type
7030  , p_source_10            IN VARCHAR2
7031 --Entered Amount
7032  , p_source_11            IN NUMBER
7033 --Currency Code
7034  , p_source_12            IN VARCHAR2
7035 --Applied To Document Exchange Date
7036  , p_source_13            IN DATE
7037 --Applied To Document Accounting Amount
7038  , p_source_16            IN NUMBER
7039 --Receipt Applied To Application Identifier
7040  , p_source_17            IN NUMBER
7041 --Transaction Distribution Type
7042  , p_source_18            IN VARCHAR2
7043 --Transaction Entity Code
7044  , p_source_19            IN VARCHAR2
7045 --Transaction Distribution Identifier
7046  , p_source_20            IN NUMBER
7047 --Transaction Identifier
7048  , p_source_21            IN NUMBER
7049 --Distribution Party Identifier
7050  , p_source_26            IN NUMBER
7051 --Distribution Party Site Id
7052  , p_source_27            IN NUMBER
7053 --Distribution Party Type
7054  , p_source_28            IN VARCHAR2
7055 --Transaction Distribution Account Class
7056  , p_source_29            IN VARCHAR2
7057 --Applied To Document Exchange Rate
7058  , p_source_30            IN NUMBER
7059 --Applied To Document Exchange Rate Type
7060  , p_source_31            IN VARCHAR2
7061 )
7062 IS
7063 
7064 l_component_type              VARCHAR2(80);
7065 l_component_code              VARCHAR2(30);
7066 l_component_type_code         VARCHAR2(1);
7067 l_component_appl_id           INTEGER;
7068 l_amb_context_code            VARCHAR2(30);
7069 l_entity_code                 VARCHAR2(30);
7070 l_event_class_code            VARCHAR2(30);
7071 l_ae_header_id                NUMBER;
7072 l_event_type_code             VARCHAR2(30);
7073 l_line_definition_code        VARCHAR2(30);
7074 l_line_definition_owner_code  VARCHAR2(1);
7075 --
7076 -- adr variables
7077 l_segment                     VARCHAR2(30);
7078 l_ccid                        NUMBER;
7079 l_adr_transaction_coa_id      NUMBER;
7080 l_adr_accounting_coa_id       NUMBER;
7081 l_adr_flexfield_segment_code  VARCHAR2(30);
7082 l_adr_flex_value_set_id       NUMBER;
7083 l_adr_value_type_code         VARCHAR2(30);
7084 l_adr_value_combination_id    NUMBER;
7085 l_adr_value_segment_code      VARCHAR2(30);
7086 
7087 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
7088 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
7089 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
7090 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
7091 
7092 -- 4262811 Variables ------------------------------------------------------------------------------------------
7093 l_entered_amt_idx             NUMBER;
7094 l_accted_amt_idx              NUMBER;
7095 l_acc_rev_flag                VARCHAR2(1);
7096 l_accrual_line_num            NUMBER;
7097 l_tmp_amt                     NUMBER;
7098 l_acc_rev_natural_side_code   VARCHAR2(1);
7099 
7100 l_num_entries                 NUMBER;
7101 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
7102 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
7103 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
7104 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
7105 l_recog_line_1                NUMBER;
7106 l_recog_line_2                NUMBER;
7107 
7111 
7108 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
7109 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
7110 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
7112 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
7113 
7114 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
7115 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
7116 
7117 ---------------------------------------------------------------------------------------------------------------
7118 
7119 
7120 --
7121 -- bulk performance
7122 --
7123 l_balance_type_code           VARCHAR2(1);
7124 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
7125 l_log_module                  VARCHAR2(240);
7126 
7127 --
7128 -- Upgrade strategy
7129 --
7130 l_actual_upg_option           VARCHAR2(1);
7131 l_enc_upg_option           VARCHAR2(1);
7132 
7133 --
7134 BEGIN
7135 --
7136 IF g_log_enabled THEN
7137       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_17';
7138 END IF;
7139 --
7140 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7141 
7142       trace
7143          (p_msg      => 'BEGIN of AcctLineType_17'
7144          ,p_level    => C_LEVEL_PROCEDURE
7145          ,p_module   => l_log_module);
7146 
7147 END IF;
7148 --
7149 l_component_type             := 'AMB_JLT';
7150 l_component_code             := 'RCT_APP_ROUND';
7151 l_component_type_code        := 'S';
7152 l_component_appl_id          :=  222;
7153 l_amb_context_code           := 'DEFAULT';
7154 l_entity_code                := 'RECEIPTS';
7155 l_event_class_code           := 'RECEIPT';
7156 l_event_type_code            := 'RECEIPT_ALL';
7157 l_line_definition_owner_code := 'S';
7158 l_line_definition_code       := 'RCT_CASH_JLD';
7159 --
7160 l_balance_type_code          := 'A';
7161 l_segment                     := NULL;
7162 l_ccid                        := NULL;
7163 l_adr_transaction_coa_id      := NULL;
7164 l_adr_accounting_coa_id       := NULL;
7165 l_adr_flexfield_segment_code  := NULL;
7166 l_adr_flex_value_set_id       := NULL;
7167 l_adr_value_type_code         := NULL;
7168 l_adr_value_combination_id    := NULL;
7169 l_adr_value_segment_code      := NULL;
7170 
7171 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
7172 l_bflow_class_code           := '';    -- 4219869 Business Flow
7173 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
7174 l_budgetary_control_flag     := 'N';
7175 
7176 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
7177 l_bflow_applied_to_amt       := NULL; -- 5132302
7178 l_entered_amt_idx            := NULL;          -- 4262811
7179 l_accted_amt_idx             := NULL;          -- 4262811
7180 l_acc_rev_flag               := NULL;          -- 4262811
7181 l_accrual_line_num           := NULL;          -- 4262811
7182 l_tmp_amt                    := NULL;          -- 4262811
7183 --
7184  
7185 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
7186     l_balance_type_code <> 'B' THEN
7187 IF (NVL(p_source_7,'
7188 ') =  'REC' AND 
7189 NVL(p_source_29,'
7190 ') =  'ROUND')
7191  THEN 
7192 
7193    --
7194    XLA_AE_LINES_PKG.SetNewLine;
7195 
7196    p_balance_type_code          := l_balance_type_code;
7197    -- set the flag so later we will know whether the gain loss line needs to be created
7198    
7199    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
7200      p_actual_flag :='A';
7201    END IF;
7202 
7203    --
7204    -- bulk performance
7205    --
7206    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
7207                                       p_header_num   => 0); -- 4262811
7208    --
7209    -- set accounting line options
7210    --
7211    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
7212            p_natural_side_code          => 'C'
7213          , p_gain_or_loss_flag          => 'N'
7214          , p_gl_transfer_mode_code      => 'S'
7215          , p_acct_entry_type_code       => 'A'
7216          , p_switch_side_flag           => 'Y'
7217          , p_merge_duplicate_code       => 'A'
7218          );
7219    --
7220    l_acc_rev_natural_side_code := 'D';  -- 4262811
7221    -- 
7222    --
7223    -- set accounting line type info
7224    --
7225    xla_ae_lines_pkg.SetAcctLineType
7226       (p_component_type             => l_component_type
7227       ,p_event_type_code            => l_event_type_code
7228       ,p_line_definition_owner_code => l_line_definition_owner_code
7229       ,p_line_definition_code       => l_line_definition_code
7230       ,p_accounting_line_code       => l_component_code
7231       ,p_accounting_line_type_code  => l_component_type_code
7232       ,p_accounting_line_appl_id    => l_component_appl_id
7233       ,p_amb_context_code           => l_amb_context_code
7234       ,p_entity_code                => l_entity_code
7235       ,p_event_class_code           => l_event_class_code);
7236    --
7237    -- set accounting class
7238    --
7239    xla_ae_lines_pkg.SetAcctClass(
7240            p_accounting_class_code  => 'ROUNDING'
7241          , p_ae_header_id           => l_ae_header_id
7242          );
7243 
7244    --
7245    -- set rounding class
7246    --
7250    --
7247    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
7248                       'RECEIVABLE';
7249 
7251    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
7252    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
7253    --
7254    -- bulk performance
7255    --
7256    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
7257 
7258    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
7259       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
7260 
7261    -- 4955764
7262    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
7263       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
7264 
7265    -- 4458381 Public Sector Enh
7266    
7267    --
7268    -- set accounting attributes for the line type
7269    --
7270    l_entered_amt_idx := 8;
7271    l_accted_amt_idx  := 13;
7272    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
7273    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
7274    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
7275    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
7276    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
7277    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
7278    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
7279    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
7280    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
7281    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
7282    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
7283    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
7284    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
7285    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
7286    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
7287    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
7288    l_rec_acct_attrs.array_num_value(8)  := p_source_11;
7289    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
7290    l_rec_acct_attrs.array_char_value(9)  := p_source_12;
7291    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
7292    l_rec_acct_attrs.array_date_value(10)  := p_source_13;
7293    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
7294    l_rec_acct_attrs.array_num_value(11)  := p_source_30;
7295    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
7296    l_rec_acct_attrs.array_char_value(12)  := p_source_31;
7297    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
7298    l_rec_acct_attrs.array_num_value(13)  := p_source_16;
7299    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
7300    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
7301    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
7302    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
7303    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
7304    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
7305 
7306    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
7307    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
7308 
7309    ---------------------------------------------------------------------------------------------------------------
7310    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
7311    ---------------------------------------------------------------------------------------------------------------
7312    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
7313 
7314    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
7315    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
7316 
7317    IF xla_accounting_cache_pkg.GetValueChar
7318          (p_source_code         => 'LEDGER_CATEGORY_CODE'
7319          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
7320    AND l_bflow_method_code = 'PRIOR_ENTRY'
7321 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
7322    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
7323          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
7324        )
7325    THEN
7326          xla_ae_lines_pkg.BflowUpgEntry
7327            (p_business_method_code    => l_bflow_method_code
7328            ,p_business_class_code     => l_bflow_class_code
7329            ,p_balance_type            => l_balance_type_code);
7330    ELSE
7331       NULL;
7332 -- No business flow processing for business flow method of NONE.
7333    END IF;
7334 
7335    --
7336    -- call analytical criteria
7337    --
7338    
7339    --
7340    -- call description
7341    --
7342    -- No description or it is inherited.
7343    --
7344    -- call ADRs
7345    -- Bug 4922099
7346    --
7347    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
7348         (NVL(l_actual_upg_option, 'N') = 'O') OR
7349         (NVL(l_enc_upg_option, 'N') = 'O')
7350       )
7351    THEN
7352    NULL;
7353    --
7354    --
7355    
7356   l_ccid := AcctDerRule_5(
7357            p_application_id           => p_application_id
7361          , x_transaction_coa_id       => l_adr_transaction_coa_id
7358          , p_ae_header_id             => l_ae_header_id 
7359 , p_source_5 => p_source_5
7360 , p_source_6 => p_source_6
7362          , x_accounting_coa_id        => l_adr_accounting_coa_id
7363          , x_value_type_code          => l_adr_value_type_code
7364          , p_side                     => 'NA'
7365    );
7366 
7367    xla_ae_lines_pkg.set_ccid(
7368     p_code_combination_id          => l_ccid
7369   , p_value_type_code              => l_adr_value_type_code
7370   , p_transaction_coa_id           => l_adr_transaction_coa_id
7371   , p_accounting_coa_id            => l_adr_accounting_coa_id
7372   , p_adr_code                     => 'TRX_REF_DIST_CCID'
7373   , p_adr_type_code                => 'S'
7374   , p_component_type               => l_component_type
7375   , p_component_code               => l_component_code
7376   , p_component_type_code          => l_component_type_code
7377   , p_component_appl_id            => l_component_appl_id
7378   , p_amb_context_code             => l_amb_context_code
7379   , p_side                         => 'NA'
7380   );
7381 
7382 
7383    --
7384    --
7385    END IF;
7386    --
7387    -- Bug 4922099
7388    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
7389           (NVL(l_enc_upg_option, 'N') = 'O')
7390         ) AND
7391         (l_bflow_method_code = 'PRIOR_ENTRY')
7392       )
7393    THEN
7394       IF
7395       --
7396       1 = 2
7397       --
7398       THEN
7399       xla_accounting_err_pkg.build_message
7400                                     (p_appli_s_name            => 'XLA'
7401                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
7402                                     ,p_token_1                 => 'LINE_NUMBER'
7403                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
7404                                     ,p_token_2                 => 'LINE_TYPE_NAME'
7405                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
7406                                                                              l_component_type
7407                                                                             ,l_component_code
7408                                                                             ,l_component_type_code
7409                                                                             ,l_component_appl_id
7410                                                                             ,l_amb_context_code
7411                                                                             ,l_entity_code
7412                                                                             ,l_event_class_code
7413                                                                            )
7414                                     ,p_token_3                 => 'OWNER'
7415                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
7416                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
7417                                                                           ,p_lookup_code    => l_component_type_code
7418                                                                          )
7419                                     ,p_token_4                 => 'PRODUCT_NAME'
7420                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
7421                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
7422                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
7423                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
7424                                     ,p_ae_header_id            =>  NULL
7425                                        );
7426 
7427         IF (C_LEVEL_ERROR>= g_log_level) THEN
7428                  trace
7429                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
7430                       ,p_level    => C_LEVEL_ERROR
7431                       ,p_module   => l_log_module);
7432         END IF;
7433       END IF;
7434    END IF;
7435    --
7436    --
7437    ------------------------------------------------------------------------------------------------
7438    -- 4219869 Business Flow
7439    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
7440    -- Prior Entry.  Currently, the following code is always generated.
7441    ------------------------------------------------------------------------------------------------
7442    XLA_AE_LINES_PKG.ValidateCurrentLine;
7443 
7444    ------------------------------------------------------------------------------------
7445    -- 4219869 Business Flow
7446    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
7447    ------------------------------------------------------------------------------------
7448    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
7449 
7450    ----------------------------------------------------------------------------------
7451    -- 4219869 Business Flow
7452    -- Update journal entry status -- Need to generate this within IF <condition>
7453    ----------------------------------------------------------------------------------
7454    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
7458 
7455          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
7456          ,p_balance_type_code => l_balance_type_code
7457          );
7459    -------------------------------------------------------------------------------------------
7460    -- 4262811 - Generate the Accrual Reversal lines
7461    -------------------------------------------------------------------------------------------
7462    BEGIN
7463       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
7464                               (g_array_event(p_event_id).array_value_num('header_index'));
7465       IF l_acc_rev_flag IS NULL THEN
7466          l_acc_rev_flag := 'N';
7467       END IF;
7468    EXCEPTION
7469       WHEN OTHERS THEN
7470          l_acc_rev_flag := 'N';
7471    END;
7472    --
7473    IF (l_acc_rev_flag = 'Y') THEN
7474 
7475        -- 4645092  ------------------------------------------------------------------------------
7476        -- To allow MPA report to determine if it should generate report process
7477        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
7478        ------------------------------------------------------------------------------------------
7479 
7480        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
7481        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
7482    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
7483    -- call ADRs
7484    -- Bug 4922099
7485    --
7486    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
7487         (NVL(l_actual_upg_option, 'N') = 'O') OR
7488         (NVL(l_enc_upg_option, 'N') = 'O')
7489       )
7490    THEN
7491    NULL;
7492    --
7493    --
7494    
7495   l_ccid := AcctDerRule_5(
7496            p_application_id           => p_application_id
7497          , p_ae_header_id             => l_ae_header_id 
7498 , p_source_5 => p_source_5
7499 , p_source_6 => p_source_6
7500          , x_transaction_coa_id       => l_adr_transaction_coa_id
7501          , x_accounting_coa_id        => l_adr_accounting_coa_id
7502          , x_value_type_code          => l_adr_value_type_code
7503          , p_side                     => 'NA'
7504    );
7505 
7506    xla_ae_lines_pkg.set_ccid(
7507     p_code_combination_id          => l_ccid
7508   , p_value_type_code              => l_adr_value_type_code
7509   , p_transaction_coa_id           => l_adr_transaction_coa_id
7510   , p_accounting_coa_id            => l_adr_accounting_coa_id
7511   , p_adr_code                     => 'TRX_REF_DIST_CCID'
7512   , p_adr_type_code                => 'S'
7513   , p_component_type               => l_component_type
7514   , p_component_code               => l_component_code
7515   , p_component_type_code          => l_component_type_code
7516   , p_component_appl_id            => l_component_appl_id
7517   , p_amb_context_code             => l_amb_context_code
7518   , p_side                         => 'NA'
7519   );
7520 
7521 
7522    --
7523    --
7524    END IF;
7525 
7526        --
7527        -- Update the line information that should be overwritten
7528        --
7529        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
7530                                          p_header_num   => 1);
7531        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
7532 
7533        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
7534 
7535        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
7536           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
7537        END IF;
7538 
7539       --
7540       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
7541       --
7542       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
7543           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
7544       ELSE
7545           ---------------------------------------------------------------------------------------------------
7546           -- 4262811a Switch Sign
7547           ---------------------------------------------------------------------------------------------------
7548           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
7549           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
7550                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7551           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
7552                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7553           -- 5132302
7554           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
7555                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
7556 
7557       END IF;
7558 
7559       -- 4955764
7560       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
7561       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
7562 
7563 
7564       XLA_AE_LINES_PKG.ValidateCurrentLine;
7565       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
7566 
7570 
7567       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
7568                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
7569                ,p_balance_type_code => l_balance_type_code);
7571    END IF;
7572 
7573    -----------------------------------------------------------------------------------------
7574    -- 4262811 Multiperiod Accounting
7575    -----------------------------------------------------------------------------------------
7576      -- No MPA option is assigned.
7577 
7578 
7579 END IF;
7580 END IF;
7581 --
7582 
7583 --
7584 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7585    trace
7586       (p_msg      => 'END of AcctLineType_17'
7587       ,p_level    => C_LEVEL_PROCEDURE
7588       ,p_module   => l_log_module);
7589 END IF;
7590 --
7591 EXCEPTION
7592   WHEN xla_exceptions_pkg.application_exception THEN
7593       RAISE;
7594   WHEN OTHERS THEN
7595        xla_exceptions_pkg.raise_message
7596            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_17');
7597 END AcctLineType_17;
7598 --
7599 
7600 ---------------------------------------
7601 --
7602 -- PRIVATE FUNCTION
7603 --         AcctLineType_18
7604 --
7605 ---------------------------------------
7606 PROCEDURE AcctLineType_18 (
7607   p_application_id        IN NUMBER
7608  ,p_event_id              IN NUMBER
7609  ,p_calculate_acctd_flag  IN VARCHAR2
7610  ,p_calculate_g_l_flag    IN VARCHAR2
7611  ,p_actual_flag           IN OUT VARCHAR2
7612  ,p_balance_type_code     OUT VARCHAR2
7613  ,p_gain_or_loss_ref      OUT VARCHAR2
7614  
7615 --Transaction Distribution GL Account
7616  , p_source_5            IN NUMBER
7617 --Reference distribution GL Account
7618  , p_source_6            IN NUMBER
7619 --Distribution Source Type
7620  , p_source_7            IN VARCHAR2
7621 --Distribution Line Identifier
7622  , p_source_9            IN NUMBER
7623 --Distribution Type
7624  , p_source_10            IN VARCHAR2
7625 --Entered Amount
7626  , p_source_11            IN NUMBER
7627 --Currency Code
7628  , p_source_12            IN VARCHAR2
7629 --Applied To Document Exchange Date
7630  , p_source_13            IN DATE
7631 --Applied To Document Accounting Amount
7632  , p_source_16            IN NUMBER
7633 --Receipt Applied To Application Identifier
7634  , p_source_17            IN NUMBER
7635 --Transaction Distribution Type
7636  , p_source_18            IN VARCHAR2
7637 --Transaction Entity Code
7638  , p_source_19            IN VARCHAR2
7639 --Transaction Distribution Identifier
7640  , p_source_20            IN NUMBER
7641 --Transaction Identifier
7642  , p_source_21            IN NUMBER
7643 --Distribution Party Identifier
7644  , p_source_26            IN NUMBER
7645 --Distribution Party Site Id
7646  , p_source_27            IN NUMBER
7647 --Distribution Party Type
7648  , p_source_28            IN VARCHAR2
7649 --Transaction Distribution Account Class
7650  , p_source_29            IN VARCHAR2
7651 --Applied To Document Exchange Rate
7652  , p_source_30            IN NUMBER
7653 --Applied To Document Exchange Rate Type
7654  , p_source_31            IN VARCHAR2
7655 )
7656 IS
7657 
7658 l_component_type              VARCHAR2(80);
7659 l_component_code              VARCHAR2(30);
7660 l_component_type_code         VARCHAR2(1);
7661 l_component_appl_id           INTEGER;
7662 l_amb_context_code            VARCHAR2(30);
7663 l_entity_code                 VARCHAR2(30);
7664 l_event_class_code            VARCHAR2(30);
7665 l_ae_header_id                NUMBER;
7666 l_event_type_code             VARCHAR2(30);
7667 l_line_definition_code        VARCHAR2(30);
7668 l_line_definition_owner_code  VARCHAR2(1);
7669 --
7670 -- adr variables
7671 l_segment                     VARCHAR2(30);
7672 l_ccid                        NUMBER;
7673 l_adr_transaction_coa_id      NUMBER;
7674 l_adr_accounting_coa_id       NUMBER;
7675 l_adr_flexfield_segment_code  VARCHAR2(30);
7676 l_adr_flex_value_set_id       NUMBER;
7677 l_adr_value_type_code         VARCHAR2(30);
7678 l_adr_value_combination_id    NUMBER;
7679 l_adr_value_segment_code      VARCHAR2(30);
7680 
7681 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
7682 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
7683 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
7684 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
7685 
7686 -- 4262811 Variables ------------------------------------------------------------------------------------------
7687 l_entered_amt_idx             NUMBER;
7688 l_accted_amt_idx              NUMBER;
7689 l_acc_rev_flag                VARCHAR2(1);
7690 l_accrual_line_num            NUMBER;
7691 l_tmp_amt                     NUMBER;
7692 l_acc_rev_natural_side_code   VARCHAR2(1);
7693 
7694 l_num_entries                 NUMBER;
7695 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
7696 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
7697 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
7698 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
7699 l_recog_line_1                NUMBER;
7700 l_recog_line_2                NUMBER;
7701 
7702 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
7703 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
7707 
7704 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
7705 
7706 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
7708 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
7709 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
7710 
7711 ---------------------------------------------------------------------------------------------------------------
7712 
7713 
7714 --
7715 -- bulk performance
7716 --
7717 l_balance_type_code           VARCHAR2(1);
7718 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
7719 l_log_module                  VARCHAR2(240);
7720 
7721 --
7722 -- Upgrade strategy
7723 --
7724 l_actual_upg_option           VARCHAR2(1);
7725 l_enc_upg_option           VARCHAR2(1);
7726 
7727 --
7728 BEGIN
7729 --
7730 IF g_log_enabled THEN
7731       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_18';
7732 END IF;
7733 --
7734 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7735 
7736       trace
7737          (p_msg      => 'BEGIN of AcctLineType_18'
7738          ,p_level    => C_LEVEL_PROCEDURE
7739          ,p_module   => l_log_module);
7740 
7741 END IF;
7742 --
7743 l_component_type             := 'AMB_JLT';
7744 l_component_code             := 'RCT_APP_SUSPENSE';
7745 l_component_type_code        := 'S';
7746 l_component_appl_id          :=  222;
7747 l_amb_context_code           := 'DEFAULT';
7748 l_entity_code                := 'RECEIPTS';
7749 l_event_class_code           := 'RECEIPT';
7750 l_event_type_code            := 'RECEIPT_ALL';
7751 l_line_definition_owner_code := 'S';
7752 l_line_definition_code       := 'RCT_CASH_JLD';
7753 --
7754 l_balance_type_code          := 'A';
7755 l_segment                     := NULL;
7756 l_ccid                        := NULL;
7757 l_adr_transaction_coa_id      := NULL;
7758 l_adr_accounting_coa_id       := NULL;
7759 l_adr_flexfield_segment_code  := NULL;
7760 l_adr_flex_value_set_id       := NULL;
7761 l_adr_value_type_code         := NULL;
7762 l_adr_value_combination_id    := NULL;
7763 l_adr_value_segment_code      := NULL;
7764 
7765 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
7766 l_bflow_class_code           := '';    -- 4219869 Business Flow
7767 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
7768 l_budgetary_control_flag     := 'N';
7769 
7770 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
7771 l_bflow_applied_to_amt       := NULL; -- 5132302
7772 l_entered_amt_idx            := NULL;          -- 4262811
7773 l_accted_amt_idx             := NULL;          -- 4262811
7774 l_acc_rev_flag               := NULL;          -- 4262811
7775 l_accrual_line_num           := NULL;          -- 4262811
7776 l_tmp_amt                    := NULL;          -- 4262811
7777 --
7778  
7779 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
7780     l_balance_type_code <> 'B' THEN
7781 IF NVL(p_source_7,'
7782 ') =  'REC' AND 
7783 NVL(p_source_29,'
7784 ') =  'SUSPENSE'
7785  THEN 
7786 
7787    --
7788    XLA_AE_LINES_PKG.SetNewLine;
7789 
7790    p_balance_type_code          := l_balance_type_code;
7791    -- set the flag so later we will know whether the gain loss line needs to be created
7792    
7793    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
7794      p_actual_flag :='A';
7795    END IF;
7796 
7797    --
7798    -- bulk performance
7799    --
7800    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
7801                                       p_header_num   => 0); -- 4262811
7802    --
7803    -- set accounting line options
7804    --
7805    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
7806            p_natural_side_code          => 'C'
7807          , p_gain_or_loss_flag          => 'N'
7808          , p_gl_transfer_mode_code      => 'S'
7809          , p_acct_entry_type_code       => 'A'
7810          , p_switch_side_flag           => 'Y'
7811          , p_merge_duplicate_code       => 'A'
7812          );
7813    --
7814    l_acc_rev_natural_side_code := 'D';  -- 4262811
7815    -- 
7816    --
7817    -- set accounting line type info
7818    --
7819    xla_ae_lines_pkg.SetAcctLineType
7820       (p_component_type             => l_component_type
7821       ,p_event_type_code            => l_event_type_code
7822       ,p_line_definition_owner_code => l_line_definition_owner_code
7823       ,p_line_definition_code       => l_line_definition_code
7824       ,p_accounting_line_code       => l_component_code
7825       ,p_accounting_line_type_code  => l_component_type_code
7826       ,p_accounting_line_appl_id    => l_component_appl_id
7827       ,p_amb_context_code           => l_amb_context_code
7828       ,p_entity_code                => l_entity_code
7829       ,p_event_class_code           => l_event_class_code);
7830    --
7831    -- set accounting class
7832    --
7833    xla_ae_lines_pkg.SetAcctClass(
7834            p_accounting_class_code  => 'UNEARNED_REVENUE'
7835          , p_ae_header_id           => l_ae_header_id
7836          );
7837 
7838    --
7839    -- set rounding class
7840    --
7841    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
7842                       'RECEIVABLE';
7843 
7844    --
7848    -- bulk performance
7845    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
7846    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
7847    --
7849    --
7850    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
7851 
7852    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
7853       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
7854 
7855    -- 4955764
7856    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
7857       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
7858 
7859    -- 4458381 Public Sector Enh
7860    
7861    --
7862    -- set accounting attributes for the line type
7863    --
7864    l_entered_amt_idx := 8;
7865    l_accted_amt_idx  := 13;
7866    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
7867    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
7868    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
7869    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
7870    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
7871    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
7872    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
7873    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
7874    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
7875    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
7876    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
7877    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
7878    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
7879    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
7880    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
7881    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
7882    l_rec_acct_attrs.array_num_value(8)  := p_source_11;
7883    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
7884    l_rec_acct_attrs.array_char_value(9)  := p_source_12;
7885    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
7886    l_rec_acct_attrs.array_date_value(10)  := p_source_13;
7887    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
7888    l_rec_acct_attrs.array_num_value(11)  := p_source_30;
7889    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
7890    l_rec_acct_attrs.array_char_value(12)  := p_source_31;
7891    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
7892    l_rec_acct_attrs.array_num_value(13)  := p_source_16;
7893    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
7894    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
7895    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
7896    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
7897    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
7898    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
7899 
7900    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
7901    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
7902 
7903    ---------------------------------------------------------------------------------------------------------------
7904    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
7905    ---------------------------------------------------------------------------------------------------------------
7906    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
7907 
7908    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
7909    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
7910 
7911    IF xla_accounting_cache_pkg.GetValueChar
7912          (p_source_code         => 'LEDGER_CATEGORY_CODE'
7913          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
7914    AND l_bflow_method_code = 'PRIOR_ENTRY'
7915 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
7916    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
7917          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
7918        )
7919    THEN
7920          xla_ae_lines_pkg.BflowUpgEntry
7921            (p_business_method_code    => l_bflow_method_code
7922            ,p_business_class_code     => l_bflow_class_code
7923            ,p_balance_type            => l_balance_type_code);
7924    ELSE
7925       NULL;
7926 -- No business flow processing for business flow method of NONE.
7927    END IF;
7928 
7929    --
7930    -- call analytical criteria
7931    --
7932    
7933    --
7934    -- call description
7935    --
7936    -- No description or it is inherited.
7937    --
7938    -- call ADRs
7939    -- Bug 4922099
7940    --
7941    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
7942         (NVL(l_actual_upg_option, 'N') = 'O') OR
7943         (NVL(l_enc_upg_option, 'N') = 'O')
7944       )
7945    THEN
7946    NULL;
7947    --
7948    --
7949    
7950   l_ccid := AcctDerRule_5(
7951            p_application_id           => p_application_id
7952          , p_ae_header_id             => l_ae_header_id 
7953 , p_source_5 => p_source_5
7957          , x_value_type_code          => l_adr_value_type_code
7954 , p_source_6 => p_source_6
7955          , x_transaction_coa_id       => l_adr_transaction_coa_id
7956          , x_accounting_coa_id        => l_adr_accounting_coa_id
7958          , p_side                     => 'NA'
7959    );
7960 
7961    xla_ae_lines_pkg.set_ccid(
7962     p_code_combination_id          => l_ccid
7963   , p_value_type_code              => l_adr_value_type_code
7964   , p_transaction_coa_id           => l_adr_transaction_coa_id
7965   , p_accounting_coa_id            => l_adr_accounting_coa_id
7966   , p_adr_code                     => 'TRX_REF_DIST_CCID'
7967   , p_adr_type_code                => 'S'
7968   , p_component_type               => l_component_type
7969   , p_component_code               => l_component_code
7970   , p_component_type_code          => l_component_type_code
7971   , p_component_appl_id            => l_component_appl_id
7972   , p_amb_context_code             => l_amb_context_code
7973   , p_side                         => 'NA'
7974   );
7975 
7976 
7977    --
7978    --
7979    END IF;
7980    --
7981    -- Bug 4922099
7982    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
7983           (NVL(l_enc_upg_option, 'N') = 'O')
7984         ) AND
7985         (l_bflow_method_code = 'PRIOR_ENTRY')
7986       )
7987    THEN
7988       IF
7989       --
7990       1 = 2
7991       --
7992       THEN
7993       xla_accounting_err_pkg.build_message
7994                                     (p_appli_s_name            => 'XLA'
7995                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
7996                                     ,p_token_1                 => 'LINE_NUMBER'
7997                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
7998                                     ,p_token_2                 => 'LINE_TYPE_NAME'
7999                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
8000                                                                              l_component_type
8001                                                                             ,l_component_code
8002                                                                             ,l_component_type_code
8003                                                                             ,l_component_appl_id
8004                                                                             ,l_amb_context_code
8005                                                                             ,l_entity_code
8006                                                                             ,l_event_class_code
8007                                                                            )
8008                                     ,p_token_3                 => 'OWNER'
8009                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
8010                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
8011                                                                           ,p_lookup_code    => l_component_type_code
8012                                                                          )
8013                                     ,p_token_4                 => 'PRODUCT_NAME'
8014                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
8015                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
8016                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
8017                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
8018                                     ,p_ae_header_id            =>  NULL
8019                                        );
8020 
8021         IF (C_LEVEL_ERROR>= g_log_level) THEN
8022                  trace
8023                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
8024                       ,p_level    => C_LEVEL_ERROR
8025                       ,p_module   => l_log_module);
8026         END IF;
8027       END IF;
8028    END IF;
8029    --
8030    --
8031    ------------------------------------------------------------------------------------------------
8032    -- 4219869 Business Flow
8033    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
8034    -- Prior Entry.  Currently, the following code is always generated.
8035    ------------------------------------------------------------------------------------------------
8036    XLA_AE_LINES_PKG.ValidateCurrentLine;
8037 
8038    ------------------------------------------------------------------------------------
8039    -- 4219869 Business Flow
8040    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
8041    ------------------------------------------------------------------------------------
8042    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
8043 
8044    ----------------------------------------------------------------------------------
8045    -- 4219869 Business Flow
8046    -- Update journal entry status -- Need to generate this within IF <condition>
8047    ----------------------------------------------------------------------------------
8048    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
8049          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
8050          ,p_balance_type_code => l_balance_type_code
8051          );
8055    -------------------------------------------------------------------------------------------
8052 
8053    -------------------------------------------------------------------------------------------
8054    -- 4262811 - Generate the Accrual Reversal lines
8056    BEGIN
8057       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
8058                               (g_array_event(p_event_id).array_value_num('header_index'));
8059       IF l_acc_rev_flag IS NULL THEN
8060          l_acc_rev_flag := 'N';
8061       END IF;
8062    EXCEPTION
8063       WHEN OTHERS THEN
8064          l_acc_rev_flag := 'N';
8065    END;
8066    --
8067    IF (l_acc_rev_flag = 'Y') THEN
8068 
8069        -- 4645092  ------------------------------------------------------------------------------
8070        -- To allow MPA report to determine if it should generate report process
8071        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
8072        ------------------------------------------------------------------------------------------
8073 
8074        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
8075        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
8076    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
8077    -- call ADRs
8078    -- Bug 4922099
8079    --
8080    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
8081         (NVL(l_actual_upg_option, 'N') = 'O') OR
8082         (NVL(l_enc_upg_option, 'N') = 'O')
8083       )
8084    THEN
8085    NULL;
8086    --
8087    --
8088    
8089   l_ccid := AcctDerRule_5(
8090            p_application_id           => p_application_id
8091          , p_ae_header_id             => l_ae_header_id 
8092 , p_source_5 => p_source_5
8093 , p_source_6 => p_source_6
8094          , x_transaction_coa_id       => l_adr_transaction_coa_id
8095          , x_accounting_coa_id        => l_adr_accounting_coa_id
8096          , x_value_type_code          => l_adr_value_type_code
8097          , p_side                     => 'NA'
8098    );
8099 
8100    xla_ae_lines_pkg.set_ccid(
8101     p_code_combination_id          => l_ccid
8102   , p_value_type_code              => l_adr_value_type_code
8103   , p_transaction_coa_id           => l_adr_transaction_coa_id
8104   , p_accounting_coa_id            => l_adr_accounting_coa_id
8105   , p_adr_code                     => 'TRX_REF_DIST_CCID'
8106   , p_adr_type_code                => 'S'
8107   , p_component_type               => l_component_type
8108   , p_component_code               => l_component_code
8109   , p_component_type_code          => l_component_type_code
8110   , p_component_appl_id            => l_component_appl_id
8111   , p_amb_context_code             => l_amb_context_code
8112   , p_side                         => 'NA'
8113   );
8114 
8115 
8116    --
8117    --
8118    END IF;
8119 
8120        --
8121        -- Update the line information that should be overwritten
8122        --
8123        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
8124                                          p_header_num   => 1);
8125        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
8126 
8127        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
8128 
8129        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
8130           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
8131        END IF;
8132 
8133       --
8134       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
8135       --
8136       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
8137           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
8138       ELSE
8139           ---------------------------------------------------------------------------------------------------
8140           -- 4262811a Switch Sign
8141           ---------------------------------------------------------------------------------------------------
8142           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
8143           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
8144                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8145           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
8146                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8147           -- 5132302
8148           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
8149                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8150 
8151       END IF;
8152 
8153       -- 4955764
8154       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
8155       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
8156 
8157 
8158       XLA_AE_LINES_PKG.ValidateCurrentLine;
8159       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
8160 
8161       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
8162                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
8166 
8163                ,p_balance_type_code => l_balance_type_code);
8164 
8165    END IF;
8167    -----------------------------------------------------------------------------------------
8168    -- 4262811 Multiperiod Accounting
8169    -----------------------------------------------------------------------------------------
8170      -- No MPA option is assigned.
8171 
8172 
8173 END IF;
8174 END IF;
8175 --
8176 
8177 --
8178 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8179    trace
8180       (p_msg      => 'END of AcctLineType_18'
8181       ,p_level    => C_LEVEL_PROCEDURE
8182       ,p_module   => l_log_module);
8183 END IF;
8184 --
8185 EXCEPTION
8186   WHEN xla_exceptions_pkg.application_exception THEN
8187       RAISE;
8188   WHEN OTHERS THEN
8189        xla_exceptions_pkg.raise_message
8190            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_18');
8191 END AcctLineType_18;
8192 --
8193 
8194 ---------------------------------------
8195 --
8196 -- PRIVATE FUNCTION
8197 --         AcctLineType_19
8198 --
8199 ---------------------------------------
8200 PROCEDURE AcctLineType_19 (
8201   p_application_id        IN NUMBER
8202  ,p_event_id              IN NUMBER
8203  ,p_calculate_acctd_flag  IN VARCHAR2
8204  ,p_calculate_g_l_flag    IN VARCHAR2
8205  ,p_actual_flag           IN OUT VARCHAR2
8206  ,p_balance_type_code     OUT VARCHAR2
8207  ,p_gain_or_loss_ref      OUT VARCHAR2
8208  
8209 --Transaction Distribution GL Account
8210  , p_source_5            IN NUMBER
8211 --Reference distribution GL Account
8212  , p_source_6            IN NUMBER
8213 --Distribution Source Type
8214  , p_source_7            IN VARCHAR2
8215 --Distribution Line Identifier
8216  , p_source_9            IN NUMBER
8217 --Distribution Type
8218  , p_source_10            IN VARCHAR2
8219 --Entered Amount
8220  , p_source_11            IN NUMBER
8221 --Currency Code
8222  , p_source_12            IN VARCHAR2
8223 --Applied To Document Exchange Date
8224  , p_source_13            IN DATE
8225 --Applied To Document Accounting Amount
8226  , p_source_16            IN NUMBER
8227 --Receipt Applied To Application Identifier
8228  , p_source_17            IN NUMBER
8229 --Transaction Distribution Type
8230  , p_source_18            IN VARCHAR2
8231 --Transaction Entity Code
8232  , p_source_19            IN VARCHAR2
8233 --Transaction Distribution Identifier
8234  , p_source_20            IN NUMBER
8235 --Transaction Identifier
8236  , p_source_21            IN NUMBER
8237 --Distribution Party Identifier
8238  , p_source_26            IN NUMBER
8239 --Distribution Party Site Id
8240  , p_source_27            IN NUMBER
8241 --Distribution Party Type
8242  , p_source_28            IN VARCHAR2
8243 --Transaction Distribution Account Class
8244  , p_source_29            IN VARCHAR2
8245 --Applied To Document Exchange Rate
8246  , p_source_30            IN NUMBER
8247 --Applied To Document Exchange Rate Type
8248  , p_source_31            IN VARCHAR2
8249 )
8250 IS
8251 
8252 l_component_type              VARCHAR2(80);
8253 l_component_code              VARCHAR2(30);
8254 l_component_type_code         VARCHAR2(1);
8255 l_component_appl_id           INTEGER;
8256 l_amb_context_code            VARCHAR2(30);
8257 l_entity_code                 VARCHAR2(30);
8258 l_event_class_code            VARCHAR2(30);
8259 l_ae_header_id                NUMBER;
8260 l_event_type_code             VARCHAR2(30);
8261 l_line_definition_code        VARCHAR2(30);
8262 l_line_definition_owner_code  VARCHAR2(1);
8263 --
8264 -- adr variables
8265 l_segment                     VARCHAR2(30);
8266 l_ccid                        NUMBER;
8267 l_adr_transaction_coa_id      NUMBER;
8268 l_adr_accounting_coa_id       NUMBER;
8269 l_adr_flexfield_segment_code  VARCHAR2(30);
8270 l_adr_flex_value_set_id       NUMBER;
8271 l_adr_value_type_code         VARCHAR2(30);
8272 l_adr_value_combination_id    NUMBER;
8273 l_adr_value_segment_code      VARCHAR2(30);
8274 
8275 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
8276 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
8277 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
8278 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
8279 
8280 -- 4262811 Variables ------------------------------------------------------------------------------------------
8281 l_entered_amt_idx             NUMBER;
8282 l_accted_amt_idx              NUMBER;
8283 l_acc_rev_flag                VARCHAR2(1);
8284 l_accrual_line_num            NUMBER;
8285 l_tmp_amt                     NUMBER;
8286 l_acc_rev_natural_side_code   VARCHAR2(1);
8287 
8288 l_num_entries                 NUMBER;
8289 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
8290 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
8291 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
8292 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
8293 l_recog_line_1                NUMBER;
8294 l_recog_line_2                NUMBER;
8295 
8296 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
8297 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
8298 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
8299 
8300 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
8301 
8305 ---------------------------------------------------------------------------------------------------------------
8302 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
8303 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
8304 
8306 
8307 
8308 --
8309 -- bulk performance
8310 --
8311 l_balance_type_code           VARCHAR2(1);
8312 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
8313 l_log_module                  VARCHAR2(240);
8314 
8315 --
8316 -- Upgrade strategy
8317 --
8318 l_actual_upg_option           VARCHAR2(1);
8319 l_enc_upg_option           VARCHAR2(1);
8320 
8321 --
8322 BEGIN
8323 --
8324 IF g_log_enabled THEN
8325       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_19';
8326 END IF;
8327 --
8328 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8329 
8330       trace
8331          (p_msg      => 'BEGIN of AcctLineType_19'
8332          ,p_level    => C_LEVEL_PROCEDURE
8333          ,p_module   => l_log_module);
8334 
8335 END IF;
8336 --
8337 l_component_type             := 'AMB_JLT';
8338 l_component_code             := 'RCT_APP_TAX';
8339 l_component_type_code        := 'S';
8340 l_component_appl_id          :=  222;
8341 l_amb_context_code           := 'DEFAULT';
8342 l_entity_code                := 'RECEIPTS';
8343 l_event_class_code           := 'RECEIPT';
8344 l_event_type_code            := 'RECEIPT_ALL';
8345 l_line_definition_owner_code := 'S';
8346 l_line_definition_code       := 'RCT_CASH_JLD';
8347 --
8348 l_balance_type_code          := 'A';
8349 l_segment                     := NULL;
8350 l_ccid                        := NULL;
8351 l_adr_transaction_coa_id      := NULL;
8352 l_adr_accounting_coa_id       := NULL;
8353 l_adr_flexfield_segment_code  := NULL;
8354 l_adr_flex_value_set_id       := NULL;
8355 l_adr_value_type_code         := NULL;
8356 l_adr_value_combination_id    := NULL;
8357 l_adr_value_segment_code      := NULL;
8358 
8359 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
8360 l_bflow_class_code           := '';    -- 4219869 Business Flow
8361 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
8362 l_budgetary_control_flag     := 'N';
8363 
8364 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
8365 l_bflow_applied_to_amt       := NULL; -- 5132302
8366 l_entered_amt_idx            := NULL;          -- 4262811
8367 l_accted_amt_idx             := NULL;          -- 4262811
8368 l_acc_rev_flag               := NULL;          -- 4262811
8369 l_accrual_line_num           := NULL;          -- 4262811
8370 l_tmp_amt                    := NULL;          -- 4262811
8371 --
8372  
8373 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
8374     l_balance_type_code <> 'B' THEN
8375 IF (NVL(p_source_7,'
8376 ') =  'REC' AND 
8377 NVL(p_source_29,'
8378 ') =  'TAX')
8379  THEN 
8380 
8381    --
8382    XLA_AE_LINES_PKG.SetNewLine;
8383 
8384    p_balance_type_code          := l_balance_type_code;
8385    -- set the flag so later we will know whether the gain loss line needs to be created
8386    
8387    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
8388      p_actual_flag :='A';
8389    END IF;
8390 
8391    --
8392    -- bulk performance
8393    --
8394    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
8395                                       p_header_num   => 0); -- 4262811
8396    --
8397    -- set accounting line options
8398    --
8399    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
8400            p_natural_side_code          => 'C'
8401          , p_gain_or_loss_flag          => 'N'
8402          , p_gl_transfer_mode_code      => 'S'
8403          , p_acct_entry_type_code       => 'A'
8404          , p_switch_side_flag           => 'Y'
8405          , p_merge_duplicate_code       => 'A'
8406          );
8407    --
8408    l_acc_rev_natural_side_code := 'D';  -- 4262811
8409    -- 
8410    --
8411    -- set accounting line type info
8412    --
8413    xla_ae_lines_pkg.SetAcctLineType
8414       (p_component_type             => l_component_type
8415       ,p_event_type_code            => l_event_type_code
8416       ,p_line_definition_owner_code => l_line_definition_owner_code
8417       ,p_line_definition_code       => l_line_definition_code
8418       ,p_accounting_line_code       => l_component_code
8419       ,p_accounting_line_type_code  => l_component_type_code
8420       ,p_accounting_line_appl_id    => l_component_appl_id
8421       ,p_amb_context_code           => l_amb_context_code
8422       ,p_entity_code                => l_entity_code
8423       ,p_event_class_code           => l_event_class_code);
8424    --
8425    -- set accounting class
8426    --
8427    xla_ae_lines_pkg.SetAcctClass(
8428            p_accounting_class_code  => 'TAX'
8429          , p_ae_header_id           => l_ae_header_id
8430          );
8431 
8432    --
8433    -- set rounding class
8434    --
8435    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
8436                       'RECEIVABLE';
8437 
8438    --
8439    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
8440    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
8444    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
8441    --
8442    -- bulk performance
8443    --
8445 
8446    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
8447       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
8448 
8449    -- 4955764
8450    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
8451       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
8452 
8453    -- 4458381 Public Sector Enh
8454    
8455    --
8456    -- set accounting attributes for the line type
8457    --
8458    l_entered_amt_idx := 8;
8459    l_accted_amt_idx  := 13;
8460    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
8461    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
8462    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
8463    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
8464    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
8465    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
8466    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
8467    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
8468    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
8469    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
8470    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
8471    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
8472    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
8473    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
8474    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
8475    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
8476    l_rec_acct_attrs.array_num_value(8)  := p_source_11;
8477    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
8478    l_rec_acct_attrs.array_char_value(9)  := p_source_12;
8479    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
8480    l_rec_acct_attrs.array_date_value(10)  := p_source_13;
8481    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
8482    l_rec_acct_attrs.array_num_value(11)  := p_source_30;
8483    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
8484    l_rec_acct_attrs.array_char_value(12)  := p_source_31;
8485    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
8486    l_rec_acct_attrs.array_num_value(13)  := p_source_16;
8487    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
8488    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
8489    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
8490    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
8491    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
8492    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
8493 
8494    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
8495    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
8496 
8497    ---------------------------------------------------------------------------------------------------------------
8498    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
8499    ---------------------------------------------------------------------------------------------------------------
8500    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
8501 
8502    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
8503    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
8504 
8505    IF xla_accounting_cache_pkg.GetValueChar
8506          (p_source_code         => 'LEDGER_CATEGORY_CODE'
8507          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
8508    AND l_bflow_method_code = 'PRIOR_ENTRY'
8509 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
8510    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
8511          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
8512        )
8513    THEN
8514          xla_ae_lines_pkg.BflowUpgEntry
8515            (p_business_method_code    => l_bflow_method_code
8516            ,p_business_class_code     => l_bflow_class_code
8517            ,p_balance_type            => l_balance_type_code);
8518    ELSE
8519       NULL;
8520 -- No business flow processing for business flow method of NONE.
8521    END IF;
8522 
8523    --
8524    -- call analytical criteria
8525    --
8526    
8527    --
8528    -- call description
8529    --
8530    -- No description or it is inherited.
8531    --
8532    -- call ADRs
8533    -- Bug 4922099
8534    --
8535    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
8536         (NVL(l_actual_upg_option, 'N') = 'O') OR
8537         (NVL(l_enc_upg_option, 'N') = 'O')
8538       )
8539    THEN
8540    NULL;
8541    --
8542    --
8543    
8544   l_ccid := AcctDerRule_5(
8545            p_application_id           => p_application_id
8546          , p_ae_header_id             => l_ae_header_id 
8547 , p_source_5 => p_source_5
8548 , p_source_6 => p_source_6
8549          , x_transaction_coa_id       => l_adr_transaction_coa_id
8550          , x_accounting_coa_id        => l_adr_accounting_coa_id
8554 
8551          , x_value_type_code          => l_adr_value_type_code
8552          , p_side                     => 'NA'
8553    );
8555    xla_ae_lines_pkg.set_ccid(
8556     p_code_combination_id          => l_ccid
8557   , p_value_type_code              => l_adr_value_type_code
8558   , p_transaction_coa_id           => l_adr_transaction_coa_id
8559   , p_accounting_coa_id            => l_adr_accounting_coa_id
8560   , p_adr_code                     => 'TRX_REF_DIST_CCID'
8561   , p_adr_type_code                => 'S'
8562   , p_component_type               => l_component_type
8563   , p_component_code               => l_component_code
8564   , p_component_type_code          => l_component_type_code
8565   , p_component_appl_id            => l_component_appl_id
8566   , p_amb_context_code             => l_amb_context_code
8567   , p_side                         => 'NA'
8568   );
8569 
8570 
8571    --
8572    --
8573    END IF;
8574    --
8575    -- Bug 4922099
8576    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
8577           (NVL(l_enc_upg_option, 'N') = 'O')
8578         ) AND
8579         (l_bflow_method_code = 'PRIOR_ENTRY')
8580       )
8581    THEN
8582       IF
8583       --
8584       1 = 2
8585       --
8586       THEN
8587       xla_accounting_err_pkg.build_message
8588                                     (p_appli_s_name            => 'XLA'
8589                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
8590                                     ,p_token_1                 => 'LINE_NUMBER'
8591                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
8592                                     ,p_token_2                 => 'LINE_TYPE_NAME'
8593                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
8594                                                                              l_component_type
8595                                                                             ,l_component_code
8596                                                                             ,l_component_type_code
8597                                                                             ,l_component_appl_id
8598                                                                             ,l_amb_context_code
8599                                                                             ,l_entity_code
8600                                                                             ,l_event_class_code
8601                                                                            )
8602                                     ,p_token_3                 => 'OWNER'
8603                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
8604                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
8605                                                                           ,p_lookup_code    => l_component_type_code
8606                                                                          )
8607                                     ,p_token_4                 => 'PRODUCT_NAME'
8608                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
8609                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
8610                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
8611                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
8612                                     ,p_ae_header_id            =>  NULL
8613                                        );
8614 
8615         IF (C_LEVEL_ERROR>= g_log_level) THEN
8616                  trace
8617                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
8618                       ,p_level    => C_LEVEL_ERROR
8619                       ,p_module   => l_log_module);
8620         END IF;
8621       END IF;
8622    END IF;
8623    --
8624    --
8625    ------------------------------------------------------------------------------------------------
8626    -- 4219869 Business Flow
8627    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
8628    -- Prior Entry.  Currently, the following code is always generated.
8629    ------------------------------------------------------------------------------------------------
8630    XLA_AE_LINES_PKG.ValidateCurrentLine;
8631 
8632    ------------------------------------------------------------------------------------
8633    -- 4219869 Business Flow
8634    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
8635    ------------------------------------------------------------------------------------
8636    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
8637 
8638    ----------------------------------------------------------------------------------
8639    -- 4219869 Business Flow
8640    -- Update journal entry status -- Need to generate this within IF <condition>
8641    ----------------------------------------------------------------------------------
8642    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
8643          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
8644          ,p_balance_type_code => l_balance_type_code
8645          );
8646 
8647    -------------------------------------------------------------------------------------------
8651       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
8648    -- 4262811 - Generate the Accrual Reversal lines
8649    -------------------------------------------------------------------------------------------
8650    BEGIN
8652                               (g_array_event(p_event_id).array_value_num('header_index'));
8653       IF l_acc_rev_flag IS NULL THEN
8654          l_acc_rev_flag := 'N';
8655       END IF;
8656    EXCEPTION
8657       WHEN OTHERS THEN
8658          l_acc_rev_flag := 'N';
8659    END;
8660    --
8661    IF (l_acc_rev_flag = 'Y') THEN
8662 
8663        -- 4645092  ------------------------------------------------------------------------------
8664        -- To allow MPA report to determine if it should generate report process
8665        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
8666        ------------------------------------------------------------------------------------------
8667 
8668        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
8669        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
8670    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
8671    -- call ADRs
8672    -- Bug 4922099
8673    --
8674    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
8675         (NVL(l_actual_upg_option, 'N') = 'O') OR
8676         (NVL(l_enc_upg_option, 'N') = 'O')
8677       )
8678    THEN
8679    NULL;
8680    --
8681    --
8682    
8683   l_ccid := AcctDerRule_5(
8684            p_application_id           => p_application_id
8685          , p_ae_header_id             => l_ae_header_id 
8686 , p_source_5 => p_source_5
8687 , p_source_6 => p_source_6
8688          , x_transaction_coa_id       => l_adr_transaction_coa_id
8689          , x_accounting_coa_id        => l_adr_accounting_coa_id
8690          , x_value_type_code          => l_adr_value_type_code
8691          , p_side                     => 'NA'
8692    );
8693 
8694    xla_ae_lines_pkg.set_ccid(
8695     p_code_combination_id          => l_ccid
8696   , p_value_type_code              => l_adr_value_type_code
8697   , p_transaction_coa_id           => l_adr_transaction_coa_id
8698   , p_accounting_coa_id            => l_adr_accounting_coa_id
8699   , p_adr_code                     => 'TRX_REF_DIST_CCID'
8700   , p_adr_type_code                => 'S'
8701   , p_component_type               => l_component_type
8702   , p_component_code               => l_component_code
8703   , p_component_type_code          => l_component_type_code
8704   , p_component_appl_id            => l_component_appl_id
8705   , p_amb_context_code             => l_amb_context_code
8706   , p_side                         => 'NA'
8707   );
8708 
8709 
8710    --
8711    --
8712    END IF;
8713 
8714        --
8715        -- Update the line information that should be overwritten
8716        --
8717        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
8718                                          p_header_num   => 1);
8719        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
8720 
8721        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
8722 
8723        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
8724           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
8725        END IF;
8726 
8727       --
8728       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
8729       --
8730       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
8731           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
8732       ELSE
8733           ---------------------------------------------------------------------------------------------------
8734           -- 4262811a Switch Sign
8735           ---------------------------------------------------------------------------------------------------
8736           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
8737           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
8738                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8739           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
8740                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8741           -- 5132302
8742           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
8743                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
8744 
8745       END IF;
8746 
8747       -- 4955764
8748       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
8749       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
8750 
8751 
8752       XLA_AE_LINES_PKG.ValidateCurrentLine;
8753       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
8754 
8755       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
8756                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
8757                ,p_balance_type_code => l_balance_type_code);
8758 
8759    END IF;
8760 
8764      -- No MPA option is assigned.
8761    -----------------------------------------------------------------------------------------
8762    -- 4262811 Multiperiod Accounting
8763    -----------------------------------------------------------------------------------------
8765 
8766 
8767 END IF;
8768 END IF;
8769 --
8770 
8771 --
8772 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8773    trace
8774       (p_msg      => 'END of AcctLineType_19'
8775       ,p_level    => C_LEVEL_PROCEDURE
8776       ,p_module   => l_log_module);
8777 END IF;
8778 --
8779 EXCEPTION
8780   WHEN xla_exceptions_pkg.application_exception THEN
8781       RAISE;
8782   WHEN OTHERS THEN
8783        xla_exceptions_pkg.raise_message
8784            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_19');
8785 END AcctLineType_19;
8786 --
8787 
8788 ---------------------------------------
8789 --
8790 -- PRIVATE FUNCTION
8791 --         AcctLineType_20
8792 --
8793 ---------------------------------------
8794 PROCEDURE AcctLineType_20 (
8795   p_application_id        IN NUMBER
8796  ,p_event_id              IN NUMBER
8797  ,p_calculate_acctd_flag  IN VARCHAR2
8798  ,p_calculate_g_l_flag    IN VARCHAR2
8799  ,p_actual_flag           IN OUT VARCHAR2
8800  ,p_balance_type_code     OUT VARCHAR2
8801  ,p_gain_or_loss_ref      OUT VARCHAR2
8802  
8803 --Transaction Distribution GL Account
8804  , p_source_5            IN NUMBER
8805 --Reference distribution GL Account
8806  , p_source_6            IN NUMBER
8807 --Distribution Source Type
8808  , p_source_7            IN VARCHAR2
8809 --Distribution Line Identifier
8810  , p_source_9            IN NUMBER
8811 --Distribution Type
8812  , p_source_10            IN VARCHAR2
8813 --Entered Amount
8814  , p_source_11            IN NUMBER
8815 --Currency Code
8816  , p_source_12            IN VARCHAR2
8817 --Applied To Document Exchange Date
8818  , p_source_13            IN DATE
8819 --Applied To Document Accounting Amount
8820  , p_source_16            IN NUMBER
8821 --Receipt Applied To Application Identifier
8822  , p_source_17            IN NUMBER
8823 --Transaction Distribution Type
8824  , p_source_18            IN VARCHAR2
8825 --Transaction Entity Code
8826  , p_source_19            IN VARCHAR2
8827 --Transaction Distribution Identifier
8828  , p_source_20            IN NUMBER
8829 --Transaction Identifier
8830  , p_source_21            IN NUMBER
8831 --Distribution Party Identifier
8832  , p_source_26            IN NUMBER
8833 --Distribution Party Site Id
8834  , p_source_27            IN NUMBER
8835 --Distribution Party Type
8836  , p_source_28            IN VARCHAR2
8837 --Transaction Distribution Account Class
8838  , p_source_29            IN VARCHAR2
8839 --Applied To Document Exchange Rate
8840  , p_source_30            IN NUMBER
8841 --Applied To Document Exchange Rate Type
8842  , p_source_31            IN VARCHAR2
8843 )
8844 IS
8845 
8846 l_component_type              VARCHAR2(80);
8847 l_component_code              VARCHAR2(30);
8848 l_component_type_code         VARCHAR2(1);
8849 l_component_appl_id           INTEGER;
8850 l_amb_context_code            VARCHAR2(30);
8851 l_entity_code                 VARCHAR2(30);
8852 l_event_class_code            VARCHAR2(30);
8853 l_ae_header_id                NUMBER;
8854 l_event_type_code             VARCHAR2(30);
8855 l_line_definition_code        VARCHAR2(30);
8856 l_line_definition_owner_code  VARCHAR2(1);
8857 --
8858 -- adr variables
8859 l_segment                     VARCHAR2(30);
8860 l_ccid                        NUMBER;
8861 l_adr_transaction_coa_id      NUMBER;
8862 l_adr_accounting_coa_id       NUMBER;
8863 l_adr_flexfield_segment_code  VARCHAR2(30);
8864 l_adr_flex_value_set_id       NUMBER;
8865 l_adr_value_type_code         VARCHAR2(30);
8866 l_adr_value_combination_id    NUMBER;
8867 l_adr_value_segment_code      VARCHAR2(30);
8868 
8869 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
8870 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
8871 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
8872 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
8873 
8874 -- 4262811 Variables ------------------------------------------------------------------------------------------
8875 l_entered_amt_idx             NUMBER;
8876 l_accted_amt_idx              NUMBER;
8877 l_acc_rev_flag                VARCHAR2(1);
8878 l_accrual_line_num            NUMBER;
8879 l_tmp_amt                     NUMBER;
8880 l_acc_rev_natural_side_code   VARCHAR2(1);
8881 
8882 l_num_entries                 NUMBER;
8883 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
8884 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
8885 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
8886 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
8887 l_recog_line_1                NUMBER;
8888 l_recog_line_2                NUMBER;
8889 
8893 
8890 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
8891 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
8892 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
8894 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
8895 
8896 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
8897 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
8898 
8899 ---------------------------------------------------------------------------------------------------------------
8900 
8901 
8902 --
8903 -- bulk performance
8904 --
8905 l_balance_type_code           VARCHAR2(1);
8906 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
8907 l_log_module                  VARCHAR2(240);
8908 
8909 --
8910 -- Upgrade strategy
8911 --
8912 l_actual_upg_option           VARCHAR2(1);
8913 l_enc_upg_option           VARCHAR2(1);
8914 
8915 --
8916 BEGIN
8917 --
8918 IF g_log_enabled THEN
8919       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_20';
8920 END IF;
8921 --
8922 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8923 
8924       trace
8925          (p_msg      => 'BEGIN of AcctLineType_20'
8926          ,p_level    => C_LEVEL_PROCEDURE
8927          ,p_module   => l_log_module);
8928 
8929 END IF;
8930 --
8931 l_component_type             := 'AMB_JLT';
8932 l_component_code             := 'RCT_APP_UNBILL';
8933 l_component_type_code        := 'S';
8934 l_component_appl_id          :=  222;
8935 l_amb_context_code           := 'DEFAULT';
8936 l_entity_code                := 'RECEIPTS';
8937 l_event_class_code           := 'RECEIPT';
8938 l_event_type_code            := 'RECEIPT_ALL';
8939 l_line_definition_owner_code := 'S';
8940 l_line_definition_code       := 'RCT_CASH_JLD';
8941 --
8942 l_balance_type_code          := 'A';
8943 l_segment                     := NULL;
8944 l_ccid                        := NULL;
8945 l_adr_transaction_coa_id      := NULL;
8946 l_adr_accounting_coa_id       := NULL;
8947 l_adr_flexfield_segment_code  := NULL;
8948 l_adr_flex_value_set_id       := NULL;
8949 l_adr_value_type_code         := NULL;
8950 l_adr_value_combination_id    := NULL;
8951 l_adr_value_segment_code      := NULL;
8952 
8953 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
8954 l_bflow_class_code           := '';    -- 4219869 Business Flow
8955 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
8956 l_budgetary_control_flag     := 'N';
8957 
8958 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
8959 l_bflow_applied_to_amt       := NULL; -- 5132302
8960 l_entered_amt_idx            := NULL;          -- 4262811
8961 l_accted_amt_idx             := NULL;          -- 4262811
8962 l_acc_rev_flag               := NULL;          -- 4262811
8963 l_accrual_line_num           := NULL;          -- 4262811
8964 l_tmp_amt                    := NULL;          -- 4262811
8965 --
8966  
8967 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
8968     l_balance_type_code <> 'B' THEN
8969 IF NVL(p_source_7,'
8970 ') =  'REC' AND 
8971 NVL(p_source_29,'
8972 ') =  'UNBILL'
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  => 'UNBILL'
9023          , p_ae_header_id           => l_ae_header_id
9024          );
9025 
9026    --
9027    -- set rounding class
9028    --
9032    --
9029    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
9030                       'RECEIVABLE';
9031 
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 := 8;
9053    l_accted_amt_idx  := 13;
9054    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
9055    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
9056    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
9057    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
9058    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
9059    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
9060    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
9061    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
9062    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
9063    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
9064    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
9065    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
9066    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
9067    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
9068    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
9069    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
9070    l_rec_acct_attrs.array_num_value(8)  := p_source_11;
9071    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
9072    l_rec_acct_attrs.array_char_value(9)  := p_source_12;
9073    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
9074    l_rec_acct_attrs.array_date_value(10)  := p_source_13;
9075    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
9076    l_rec_acct_attrs.array_num_value(11)  := p_source_30;
9077    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
9078    l_rec_acct_attrs.array_char_value(12)  := p_source_31;
9079    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
9080    l_rec_acct_attrs.array_num_value(13)  := p_source_16;
9081    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
9082    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
9083    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
9084    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
9085    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
9086    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
9087 
9088    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
9089    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
9090 
9091    ---------------------------------------------------------------------------------------------------------------
9092    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
9093    ---------------------------------------------------------------------------------------------------------------
9094    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
9095 
9096    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
9097    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
9098 
9099    IF xla_accounting_cache_pkg.GetValueChar
9100          (p_source_code         => 'LEDGER_CATEGORY_CODE'
9101          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
9102    AND l_bflow_method_code = 'PRIOR_ENTRY'
9103 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
9104    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
9105          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
9106        )
9107    THEN
9108          xla_ae_lines_pkg.BflowUpgEntry
9109            (p_business_method_code    => l_bflow_method_code
9110            ,p_business_class_code     => l_bflow_class_code
9111            ,p_balance_type            => l_balance_type_code);
9112    ELSE
9113       NULL;
9114 -- No business flow processing for business flow method of NONE.
9115    END IF;
9116 
9117    --
9118    -- call analytical criteria
9119    --
9120    
9121    --
9122    -- call description
9123    --
9124    -- No description or it is inherited.
9125    --
9126    -- call ADRs
9127    -- Bug 4922099
9128    --
9129    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
9130         (NVL(l_actual_upg_option, 'N') = 'O') OR
9131         (NVL(l_enc_upg_option, 'N') = 'O')
9132       )
9133    THEN
9134    NULL;
9135    --
9136    --
9137    
9141 , p_source_5 => p_source_5
9138   l_ccid := AcctDerRule_5(
9139            p_application_id           => p_application_id
9140          , p_ae_header_id             => l_ae_header_id 
9142 , p_source_6 => p_source_6
9143          , x_transaction_coa_id       => l_adr_transaction_coa_id
9144          , x_accounting_coa_id        => l_adr_accounting_coa_id
9145          , x_value_type_code          => l_adr_value_type_code
9146          , p_side                     => 'NA'
9147    );
9148 
9149    xla_ae_lines_pkg.set_ccid(
9150     p_code_combination_id          => l_ccid
9151   , p_value_type_code              => l_adr_value_type_code
9152   , p_transaction_coa_id           => l_adr_transaction_coa_id
9153   , p_accounting_coa_id            => l_adr_accounting_coa_id
9154   , p_adr_code                     => 'TRX_REF_DIST_CCID'
9155   , p_adr_type_code                => 'S'
9156   , p_component_type               => l_component_type
9157   , p_component_code               => l_component_code
9158   , p_component_type_code          => l_component_type_code
9159   , p_component_appl_id            => l_component_appl_id
9160   , p_amb_context_code             => l_amb_context_code
9161   , p_side                         => 'NA'
9162   );
9163 
9164 
9165    --
9166    --
9167    END IF;
9168    --
9169    -- Bug 4922099
9170    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
9171           (NVL(l_enc_upg_option, 'N') = 'O')
9172         ) AND
9173         (l_bflow_method_code = 'PRIOR_ENTRY')
9174       )
9175    THEN
9176       IF
9177       --
9178       1 = 2
9179       --
9180       THEN
9181       xla_accounting_err_pkg.build_message
9182                                     (p_appli_s_name            => 'XLA'
9183                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
9184                                     ,p_token_1                 => 'LINE_NUMBER'
9185                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
9186                                     ,p_token_2                 => 'LINE_TYPE_NAME'
9187                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
9188                                                                              l_component_type
9189                                                                             ,l_component_code
9190                                                                             ,l_component_type_code
9191                                                                             ,l_component_appl_id
9192                                                                             ,l_amb_context_code
9193                                                                             ,l_entity_code
9194                                                                             ,l_event_class_code
9195                                                                            )
9196                                     ,p_token_3                 => 'OWNER'
9197                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
9198                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
9199                                                                           ,p_lookup_code    => l_component_type_code
9200                                                                          )
9201                                     ,p_token_4                 => 'PRODUCT_NAME'
9202                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
9203                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
9204                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
9205                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
9206                                     ,p_ae_header_id            =>  NULL
9207                                        );
9208 
9209         IF (C_LEVEL_ERROR>= g_log_level) THEN
9210                  trace
9211                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
9212                       ,p_level    => C_LEVEL_ERROR
9213                       ,p_module   => l_log_module);
9214         END IF;
9215       END IF;
9216    END IF;
9217    --
9218    --
9219    ------------------------------------------------------------------------------------------------
9220    -- 4219869 Business Flow
9221    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
9222    -- Prior Entry.  Currently, the following code is always generated.
9223    ------------------------------------------------------------------------------------------------
9224    XLA_AE_LINES_PKG.ValidateCurrentLine;
9225 
9226    ------------------------------------------------------------------------------------
9227    -- 4219869 Business Flow
9228    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
9229    ------------------------------------------------------------------------------------
9230    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
9231 
9232    ----------------------------------------------------------------------------------
9233    -- 4219869 Business Flow
9234    -- Update journal entry status -- Need to generate this within IF <condition>
9238          ,p_balance_type_code => l_balance_type_code
9235    ----------------------------------------------------------------------------------
9236    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
9237          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
9239          );
9240 
9241    -------------------------------------------------------------------------------------------
9242    -- 4262811 - Generate the Accrual Reversal lines
9243    -------------------------------------------------------------------------------------------
9244    BEGIN
9245       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
9246                               (g_array_event(p_event_id).array_value_num('header_index'));
9247       IF l_acc_rev_flag IS NULL THEN
9248          l_acc_rev_flag := 'N';
9249       END IF;
9250    EXCEPTION
9251       WHEN OTHERS THEN
9252          l_acc_rev_flag := 'N';
9253    END;
9254    --
9255    IF (l_acc_rev_flag = 'Y') THEN
9256 
9257        -- 4645092  ------------------------------------------------------------------------------
9258        -- To allow MPA report to determine if it should generate report process
9259        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
9260        ------------------------------------------------------------------------------------------
9261 
9262        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
9263        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
9264    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
9265    -- call ADRs
9266    -- Bug 4922099
9267    --
9268    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
9269         (NVL(l_actual_upg_option, 'N') = 'O') OR
9270         (NVL(l_enc_upg_option, 'N') = 'O')
9271       )
9272    THEN
9273    NULL;
9274    --
9275    --
9276    
9277   l_ccid := AcctDerRule_5(
9278            p_application_id           => p_application_id
9279          , p_ae_header_id             => l_ae_header_id 
9280 , p_source_5 => p_source_5
9281 , p_source_6 => p_source_6
9282          , x_transaction_coa_id       => l_adr_transaction_coa_id
9283          , x_accounting_coa_id        => l_adr_accounting_coa_id
9284          , x_value_type_code          => l_adr_value_type_code
9285          , p_side                     => 'NA'
9286    );
9287 
9288    xla_ae_lines_pkg.set_ccid(
9289     p_code_combination_id          => l_ccid
9290   , p_value_type_code              => l_adr_value_type_code
9291   , p_transaction_coa_id           => l_adr_transaction_coa_id
9292   , p_accounting_coa_id            => l_adr_accounting_coa_id
9293   , p_adr_code                     => 'TRX_REF_DIST_CCID'
9294   , p_adr_type_code                => 'S'
9295   , p_component_type               => l_component_type
9296   , p_component_code               => l_component_code
9297   , p_component_type_code          => l_component_type_code
9298   , p_component_appl_id            => l_component_appl_id
9299   , p_amb_context_code             => l_amb_context_code
9300   , p_side                         => 'NA'
9301   );
9302 
9303 
9304    --
9305    --
9306    END IF;
9307 
9308        --
9309        -- Update the line information that should be overwritten
9310        --
9311        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
9312                                          p_header_num   => 1);
9313        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
9314 
9315        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
9316 
9317        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
9318           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
9319        END IF;
9320 
9321       --
9322       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
9323       --
9324       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
9325           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
9326       ELSE
9327           ---------------------------------------------------------------------------------------------------
9328           -- 4262811a Switch Sign
9329           ---------------------------------------------------------------------------------------------------
9330           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
9331           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
9332                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
9333           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
9334                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
9335           -- 5132302
9336           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
9337                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
9338 
9339       END IF;
9340 
9341       -- 4955764
9342       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
9343       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
9344 
9345 
9349       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
9346       XLA_AE_LINES_PKG.ValidateCurrentLine;
9347       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
9348 
9350                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
9351                ,p_balance_type_code => l_balance_type_code);
9352 
9353    END IF;
9354 
9355    -----------------------------------------------------------------------------------------
9356    -- 4262811 Multiperiod Accounting
9357    -----------------------------------------------------------------------------------------
9358      -- No MPA option is assigned.
9359 
9360 
9361 END IF;
9362 END IF;
9363 --
9364 
9365 --
9366 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9367    trace
9368       (p_msg      => 'END of AcctLineType_20'
9369       ,p_level    => C_LEVEL_PROCEDURE
9370       ,p_module   => l_log_module);
9371 END IF;
9372 --
9373 EXCEPTION
9374   WHEN xla_exceptions_pkg.application_exception THEN
9375       RAISE;
9376   WHEN OTHERS THEN
9377        xla_exceptions_pkg.raise_message
9378            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_20');
9379 END AcctLineType_20;
9380 --
9381 
9382 ---------------------------------------
9383 --
9384 -- PRIVATE FUNCTION
9385 --         AcctLineType_21
9386 --
9387 ---------------------------------------
9388 PROCEDURE AcctLineType_21 (
9389   p_application_id        IN NUMBER
9390  ,p_event_id              IN NUMBER
9391  ,p_calculate_acctd_flag  IN VARCHAR2
9392  ,p_calculate_g_l_flag    IN VARCHAR2
9393  ,p_actual_flag           IN OUT VARCHAR2
9394  ,p_balance_type_code     OUT VARCHAR2
9395  ,p_gain_or_loss_ref      OUT VARCHAR2
9396  
9397 --Transaction Distribution GL Account
9398  , p_source_5            IN NUMBER
9399 --Reference distribution GL Account
9400  , p_source_6            IN NUMBER
9401 --Distribution Source Type
9402  , p_source_7            IN VARCHAR2
9403 --Distribution Line Identifier
9404  , p_source_9            IN NUMBER
9405 --Distribution Type
9406  , p_source_10            IN VARCHAR2
9407 --Entered Amount
9408  , p_source_11            IN NUMBER
9409 --Currency Code
9410  , p_source_12            IN VARCHAR2
9411 --Applied To Document Exchange Date
9412  , p_source_13            IN DATE
9413 --Applied To Document Accounting Amount
9414  , p_source_16            IN NUMBER
9415 --Receipt Applied To Application Identifier
9416  , p_source_17            IN NUMBER
9417 --Transaction Distribution Type
9418  , p_source_18            IN VARCHAR2
9419 --Transaction Entity Code
9420  , p_source_19            IN VARCHAR2
9421 --Transaction Distribution Identifier
9422  , p_source_20            IN NUMBER
9423 --Transaction Identifier
9424  , p_source_21            IN NUMBER
9425 --Distribution Party Identifier
9426  , p_source_26            IN NUMBER
9427 --Distribution Party Site Id
9428  , p_source_27            IN NUMBER
9429 --Distribution Party Type
9430  , p_source_28            IN VARCHAR2
9431 --Transaction Distribution Account Class
9432  , p_source_29            IN VARCHAR2
9433 --Applied To Document Exchange Rate
9434  , p_source_30            IN NUMBER
9435 --Applied To Document Exchange Rate Type
9436  , p_source_31            IN VARCHAR2
9437 )
9438 IS
9439 
9440 l_component_type              VARCHAR2(80);
9441 l_component_code              VARCHAR2(30);
9442 l_component_type_code         VARCHAR2(1);
9443 l_component_appl_id           INTEGER;
9444 l_amb_context_code            VARCHAR2(30);
9445 l_entity_code                 VARCHAR2(30);
9446 l_event_class_code            VARCHAR2(30);
9447 l_ae_header_id                NUMBER;
9448 l_event_type_code             VARCHAR2(30);
9449 l_line_definition_code        VARCHAR2(30);
9450 l_line_definition_owner_code  VARCHAR2(1);
9451 --
9452 -- adr variables
9453 l_segment                     VARCHAR2(30);
9454 l_ccid                        NUMBER;
9455 l_adr_transaction_coa_id      NUMBER;
9456 l_adr_accounting_coa_id       NUMBER;
9457 l_adr_flexfield_segment_code  VARCHAR2(30);
9458 l_adr_flex_value_set_id       NUMBER;
9459 l_adr_value_type_code         VARCHAR2(30);
9460 l_adr_value_combination_id    NUMBER;
9461 l_adr_value_segment_code      VARCHAR2(30);
9462 
9463 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
9464 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
9465 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
9466 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
9467 
9468 -- 4262811 Variables ------------------------------------------------------------------------------------------
9469 l_entered_amt_idx             NUMBER;
9470 l_accted_amt_idx              NUMBER;
9471 l_acc_rev_flag                VARCHAR2(1);
9472 l_accrual_line_num            NUMBER;
9473 l_tmp_amt                     NUMBER;
9474 l_acc_rev_natural_side_code   VARCHAR2(1);
9475 
9476 l_num_entries                 NUMBER;
9477 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
9478 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
9479 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
9480 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
9481 l_recog_line_1                NUMBER;
9482 l_recog_line_2                NUMBER;
9483 
9484 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
9488 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
9485 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
9486 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
9487 
9489 
9490 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
9491 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
9492 
9493 ---------------------------------------------------------------------------------------------------------------
9494 
9495 
9496 --
9497 -- bulk performance
9498 --
9499 l_balance_type_code           VARCHAR2(1);
9500 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
9501 l_log_module                  VARCHAR2(240);
9502 
9503 --
9504 -- Upgrade strategy
9505 --
9506 l_actual_upg_option           VARCHAR2(1);
9507 l_enc_upg_option           VARCHAR2(1);
9508 
9509 --
9510 BEGIN
9511 --
9512 IF g_log_enabled THEN
9513       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_21';
9514 END IF;
9515 --
9516 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9517 
9518       trace
9519          (p_msg      => 'BEGIN of AcctLineType_21'
9520          ,p_level    => C_LEVEL_PROCEDURE
9521          ,p_module   => l_log_module);
9522 
9523 END IF;
9524 --
9525 l_component_type             := 'AMB_JLT';
9526 l_component_code             := 'RCT_APP_UNEARN';
9527 l_component_type_code        := 'S';
9528 l_component_appl_id          :=  222;
9529 l_amb_context_code           := 'DEFAULT';
9530 l_entity_code                := 'RECEIPTS';
9531 l_event_class_code           := 'RECEIPT';
9532 l_event_type_code            := 'RECEIPT_ALL';
9533 l_line_definition_owner_code := 'S';
9534 l_line_definition_code       := 'RCT_CASH_JLD';
9535 --
9536 l_balance_type_code          := 'A';
9537 l_segment                     := NULL;
9538 l_ccid                        := NULL;
9539 l_adr_transaction_coa_id      := NULL;
9540 l_adr_accounting_coa_id       := NULL;
9541 l_adr_flexfield_segment_code  := NULL;
9542 l_adr_flex_value_set_id       := NULL;
9543 l_adr_value_type_code         := NULL;
9544 l_adr_value_combination_id    := NULL;
9545 l_adr_value_segment_code      := NULL;
9546 
9547 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
9548 l_bflow_class_code           := '';    -- 4219869 Business Flow
9549 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
9550 l_budgetary_control_flag     := 'N';
9551 
9552 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
9553 l_bflow_applied_to_amt       := NULL; -- 5132302
9554 l_entered_amt_idx            := NULL;          -- 4262811
9555 l_accted_amt_idx             := NULL;          -- 4262811
9556 l_acc_rev_flag               := NULL;          -- 4262811
9557 l_accrual_line_num           := NULL;          -- 4262811
9558 l_tmp_amt                    := NULL;          -- 4262811
9559 --
9560  
9561 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
9562     l_balance_type_code <> 'B' THEN
9563 IF NVL(p_source_7,'
9564 ') =  'REC' AND 
9565 NVL(p_source_29,'
9566 ') =  'UNEARN'
9567  THEN 
9568 
9569    --
9570    XLA_AE_LINES_PKG.SetNewLine;
9571 
9572    p_balance_type_code          := l_balance_type_code;
9573    -- set the flag so later we will know whether the gain loss line needs to be created
9574    
9575    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
9576      p_actual_flag :='A';
9577    END IF;
9578 
9579    --
9580    -- bulk performance
9581    --
9582    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
9583                                       p_header_num   => 0); -- 4262811
9584    --
9585    -- set accounting line options
9586    --
9587    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
9588            p_natural_side_code          => 'C'
9589          , p_gain_or_loss_flag          => 'N'
9590          , p_gl_transfer_mode_code      => 'S'
9591          , p_acct_entry_type_code       => 'A'
9592          , p_switch_side_flag           => 'Y'
9593          , p_merge_duplicate_code       => 'A'
9594          );
9595    --
9596    l_acc_rev_natural_side_code := 'D';  -- 4262811
9597    -- 
9598    --
9599    -- set accounting line type info
9600    --
9601    xla_ae_lines_pkg.SetAcctLineType
9602       (p_component_type             => l_component_type
9603       ,p_event_type_code            => l_event_type_code
9604       ,p_line_definition_owner_code => l_line_definition_owner_code
9605       ,p_line_definition_code       => l_line_definition_code
9606       ,p_accounting_line_code       => l_component_code
9607       ,p_accounting_line_type_code  => l_component_type_code
9608       ,p_accounting_line_appl_id    => l_component_appl_id
9609       ,p_amb_context_code           => l_amb_context_code
9610       ,p_entity_code                => l_entity_code
9611       ,p_event_class_code           => l_event_class_code);
9612    --
9613    -- set accounting class
9614    --
9615    xla_ae_lines_pkg.SetAcctClass(
9616            p_accounting_class_code  => 'UNEARNED_REVENUE'
9617          , p_ae_header_id           => l_ae_header_id
9618          );
9619 
9620    --
9621    -- set rounding class
9622    --
9623    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
9627    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
9624                       'RECEIVABLE';
9625 
9626    --
9628    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
9629    --
9630    -- bulk performance
9631    --
9632    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
9633 
9634    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
9635       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
9636 
9637    -- 4955764
9638    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
9639       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
9640 
9641    -- 4458381 Public Sector Enh
9642    
9643    --
9644    -- set accounting attributes for the line type
9645    --
9646    l_entered_amt_idx := 8;
9647    l_accted_amt_idx  := 13;
9648    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
9649    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
9650    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
9651    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
9652    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
9653    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
9654    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
9655    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
9656    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
9657    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
9658    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
9659    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
9660    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
9661    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
9662    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
9663    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
9664    l_rec_acct_attrs.array_num_value(8)  := p_source_11;
9665    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
9666    l_rec_acct_attrs.array_char_value(9)  := p_source_12;
9667    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
9668    l_rec_acct_attrs.array_date_value(10)  := p_source_13;
9669    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
9670    l_rec_acct_attrs.array_num_value(11)  := p_source_30;
9671    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
9672    l_rec_acct_attrs.array_char_value(12)  := p_source_31;
9673    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
9674    l_rec_acct_attrs.array_num_value(13)  := p_source_16;
9675    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
9676    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
9677    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
9678    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
9679    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
9680    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
9681 
9682    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
9683    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
9684 
9685    ---------------------------------------------------------------------------------------------------------------
9686    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
9687    ---------------------------------------------------------------------------------------------------------------
9688    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
9689 
9690    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
9691    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
9692 
9693    IF xla_accounting_cache_pkg.GetValueChar
9694          (p_source_code         => 'LEDGER_CATEGORY_CODE'
9695          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
9696    AND l_bflow_method_code = 'PRIOR_ENTRY'
9697 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
9698    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
9699          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
9700        )
9701    THEN
9702          xla_ae_lines_pkg.BflowUpgEntry
9703            (p_business_method_code    => l_bflow_method_code
9704            ,p_business_class_code     => l_bflow_class_code
9705            ,p_balance_type            => l_balance_type_code);
9706    ELSE
9707       NULL;
9708 -- No business flow processing for business flow method of NONE.
9709    END IF;
9710 
9711    --
9712    -- call analytical criteria
9713    --
9714    
9715    --
9716    -- call description
9717    --
9718    -- No description or it is inherited.
9719    --
9720    -- call ADRs
9721    -- Bug 4922099
9722    --
9723    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
9724         (NVL(l_actual_upg_option, 'N') = 'O') OR
9725         (NVL(l_enc_upg_option, 'N') = 'O')
9726       )
9727    THEN
9728    NULL;
9729    --
9730    --
9731    
9732   l_ccid := AcctDerRule_5(
9736 , p_source_6 => p_source_6
9733            p_application_id           => p_application_id
9734          , p_ae_header_id             => l_ae_header_id 
9735 , p_source_5 => p_source_5
9737          , x_transaction_coa_id       => l_adr_transaction_coa_id
9738          , x_accounting_coa_id        => l_adr_accounting_coa_id
9739          , x_value_type_code          => l_adr_value_type_code
9740          , p_side                     => 'NA'
9741    );
9742 
9743    xla_ae_lines_pkg.set_ccid(
9744     p_code_combination_id          => l_ccid
9745   , p_value_type_code              => l_adr_value_type_code
9746   , p_transaction_coa_id           => l_adr_transaction_coa_id
9747   , p_accounting_coa_id            => l_adr_accounting_coa_id
9748   , p_adr_code                     => 'TRX_REF_DIST_CCID'
9749   , p_adr_type_code                => 'S'
9750   , p_component_type               => l_component_type
9751   , p_component_code               => l_component_code
9752   , p_component_type_code          => l_component_type_code
9753   , p_component_appl_id            => l_component_appl_id
9754   , p_amb_context_code             => l_amb_context_code
9755   , p_side                         => 'NA'
9756   );
9757 
9758 
9759    --
9760    --
9761    END IF;
9762    --
9763    -- Bug 4922099
9764    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
9765           (NVL(l_enc_upg_option, 'N') = 'O')
9766         ) AND
9767         (l_bflow_method_code = 'PRIOR_ENTRY')
9768       )
9769    THEN
9770       IF
9771       --
9772       1 = 2
9773       --
9774       THEN
9775       xla_accounting_err_pkg.build_message
9776                                     (p_appli_s_name            => 'XLA'
9777                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
9778                                     ,p_token_1                 => 'LINE_NUMBER'
9779                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
9780                                     ,p_token_2                 => 'LINE_TYPE_NAME'
9781                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
9782                                                                              l_component_type
9783                                                                             ,l_component_code
9784                                                                             ,l_component_type_code
9785                                                                             ,l_component_appl_id
9786                                                                             ,l_amb_context_code
9787                                                                             ,l_entity_code
9788                                                                             ,l_event_class_code
9789                                                                            )
9790                                     ,p_token_3                 => 'OWNER'
9791                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
9792                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
9793                                                                           ,p_lookup_code    => l_component_type_code
9794                                                                          )
9795                                     ,p_token_4                 => 'PRODUCT_NAME'
9796                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
9797                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
9798                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
9799                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
9800                                     ,p_ae_header_id            =>  NULL
9801                                        );
9802 
9803         IF (C_LEVEL_ERROR>= g_log_level) THEN
9804                  trace
9805                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
9806                       ,p_level    => C_LEVEL_ERROR
9807                       ,p_module   => l_log_module);
9808         END IF;
9809       END IF;
9810    END IF;
9811    --
9812    --
9813    ------------------------------------------------------------------------------------------------
9814    -- 4219869 Business Flow
9815    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
9816    -- Prior Entry.  Currently, the following code is always generated.
9817    ------------------------------------------------------------------------------------------------
9818    XLA_AE_LINES_PKG.ValidateCurrentLine;
9819 
9820    ------------------------------------------------------------------------------------
9821    -- 4219869 Business Flow
9822    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
9823    ------------------------------------------------------------------------------------
9824    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
9825 
9826    ----------------------------------------------------------------------------------
9827    -- 4219869 Business Flow
9828    -- Update journal entry status -- Need to generate this within IF <condition>
9832          ,p_balance_type_code => l_balance_type_code
9829    ----------------------------------------------------------------------------------
9830    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
9831          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
9833          );
9834 
9835    -------------------------------------------------------------------------------------------
9836    -- 4262811 - Generate the Accrual Reversal lines
9837    -------------------------------------------------------------------------------------------
9838    BEGIN
9839       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
9840                               (g_array_event(p_event_id).array_value_num('header_index'));
9841       IF l_acc_rev_flag IS NULL THEN
9842          l_acc_rev_flag := 'N';
9843       END IF;
9844    EXCEPTION
9845       WHEN OTHERS THEN
9846          l_acc_rev_flag := 'N';
9847    END;
9848    --
9849    IF (l_acc_rev_flag = 'Y') THEN
9850 
9851        -- 4645092  ------------------------------------------------------------------------------
9852        -- To allow MPA report to determine if it should generate report process
9853        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
9854        ------------------------------------------------------------------------------------------
9855 
9856        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
9857        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
9858    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
9859    -- call ADRs
9860    -- Bug 4922099
9861    --
9862    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
9863         (NVL(l_actual_upg_option, 'N') = 'O') OR
9864         (NVL(l_enc_upg_option, 'N') = 'O')
9865       )
9866    THEN
9867    NULL;
9868    --
9869    --
9870    
9871   l_ccid := AcctDerRule_5(
9872            p_application_id           => p_application_id
9873          , p_ae_header_id             => l_ae_header_id 
9874 , p_source_5 => p_source_5
9875 , p_source_6 => p_source_6
9876          , x_transaction_coa_id       => l_adr_transaction_coa_id
9877          , x_accounting_coa_id        => l_adr_accounting_coa_id
9878          , x_value_type_code          => l_adr_value_type_code
9879          , p_side                     => 'NA'
9880    );
9881 
9882    xla_ae_lines_pkg.set_ccid(
9883     p_code_combination_id          => l_ccid
9884   , p_value_type_code              => l_adr_value_type_code
9885   , p_transaction_coa_id           => l_adr_transaction_coa_id
9886   , p_accounting_coa_id            => l_adr_accounting_coa_id
9887   , p_adr_code                     => 'TRX_REF_DIST_CCID'
9888   , p_adr_type_code                => 'S'
9889   , p_component_type               => l_component_type
9890   , p_component_code               => l_component_code
9891   , p_component_type_code          => l_component_type_code
9892   , p_component_appl_id            => l_component_appl_id
9893   , p_amb_context_code             => l_amb_context_code
9894   , p_side                         => 'NA'
9895   );
9896 
9897 
9898    --
9899    --
9900    END IF;
9901 
9902        --
9903        -- Update the line information that should be overwritten
9904        --
9905        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
9906                                          p_header_num   => 1);
9907        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
9908 
9909        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
9910 
9911        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
9912           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
9913        END IF;
9914 
9915       --
9916       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
9917       --
9918       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
9919           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
9920       ELSE
9921           ---------------------------------------------------------------------------------------------------
9922           -- 4262811a Switch Sign
9923           ---------------------------------------------------------------------------------------------------
9924           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
9925           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
9926                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
9927           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
9928                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
9929           -- 5132302
9930           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
9931                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
9932 
9933       END IF;
9934 
9935       -- 4955764
9936       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
9937       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
9938 
9939 
9940       XLA_AE_LINES_PKG.ValidateCurrentLine;
9944                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
9941       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
9942 
9943       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
9945                ,p_balance_type_code => l_balance_type_code);
9946 
9947    END IF;
9948 
9949    -----------------------------------------------------------------------------------------
9950    -- 4262811 Multiperiod Accounting
9951    -----------------------------------------------------------------------------------------
9952      -- No MPA option is assigned.
9953 
9954 
9955 END IF;
9956 END IF;
9957 --
9958 
9959 --
9960 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9961    trace
9962       (p_msg      => 'END of AcctLineType_21'
9963       ,p_level    => C_LEVEL_PROCEDURE
9964       ,p_module   => l_log_module);
9965 END IF;
9966 --
9967 EXCEPTION
9968   WHEN xla_exceptions_pkg.application_exception THEN
9969       RAISE;
9970   WHEN OTHERS THEN
9971        xla_exceptions_pkg.raise_message
9972            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_21');
9973 END AcctLineType_21;
9974 --
9975 
9976 ---------------------------------------
9977 --
9978 -- PRIVATE FUNCTION
9979 --         AcctLineType_22
9980 --
9981 ---------------------------------------
9982 PROCEDURE AcctLineType_22 (
9983   p_application_id        IN NUMBER
9984  ,p_event_id              IN NUMBER
9985  ,p_calculate_acctd_flag  IN VARCHAR2
9986  ,p_calculate_g_l_flag    IN VARCHAR2
9987  ,p_actual_flag           IN OUT VARCHAR2
9988  ,p_balance_type_code     OUT VARCHAR2
9989  ,p_gain_or_loss_ref      OUT VARCHAR2
9990  
9991 --Distribution GL Account
9992  , p_source_1            IN NUMBER
9993 --Distribution Source Type
9994  , p_source_7            IN VARCHAR2
9995 --Distribution Multi Fund Additional Entry
9996  , p_source_8            IN VARCHAR2
9997 --Distribution Line Identifier
9998  , p_source_9            IN NUMBER
9999 --Distribution Type
10000  , p_source_10            IN VARCHAR2
10001 --Exchange Rate
10002  , p_source_14            IN NUMBER
10003 --Exchange Rate Type
10004  , p_source_15            IN VARCHAR2
10005 --Receipt Applied To Application Identifier
10006  , p_source_17            IN NUMBER
10007 --Transaction Distribution Type
10008  , p_source_18            IN VARCHAR2
10009 --Transaction Entity Code
10010  , p_source_19            IN VARCHAR2
10011 --Transaction Distribution Identifier
10012  , p_source_20            IN NUMBER
10013 --Transaction Identifier
10014  , p_source_21            IN NUMBER
10015 --DIST_ENT_AMT_FROM
10016  , p_source_22            IN NUMBER
10017 --Applying Document Currency Code
10018  , p_source_23            IN VARCHAR2
10019 --Exchange Date
10020  , p_source_24            IN DATE
10021 --Accounting Amount
10022  , p_source_25            IN NUMBER
10023 --Distribution Party Identifier
10024  , p_source_26            IN NUMBER
10025 --Distribution Party Site Id
10026  , p_source_27            IN NUMBER
10027 --Distribution Party Type
10028  , p_source_28            IN VARCHAR2
10029 )
10030 IS
10031 
10032 l_component_type              VARCHAR2(80);
10033 l_component_code              VARCHAR2(30);
10034 l_component_type_code         VARCHAR2(1);
10035 l_component_appl_id           INTEGER;
10036 l_amb_context_code            VARCHAR2(30);
10037 l_entity_code                 VARCHAR2(30);
10038 l_event_class_code            VARCHAR2(30);
10039 l_ae_header_id                NUMBER;
10040 l_event_type_code             VARCHAR2(30);
10041 l_line_definition_code        VARCHAR2(30);
10042 l_line_definition_owner_code  VARCHAR2(1);
10043 --
10044 -- adr variables
10045 l_segment                     VARCHAR2(30);
10046 l_ccid                        NUMBER;
10047 l_adr_transaction_coa_id      NUMBER;
10048 l_adr_accounting_coa_id       NUMBER;
10049 l_adr_flexfield_segment_code  VARCHAR2(30);
10050 l_adr_flex_value_set_id       NUMBER;
10051 l_adr_value_type_code         VARCHAR2(30);
10052 l_adr_value_combination_id    NUMBER;
10053 l_adr_value_segment_code      VARCHAR2(30);
10054 
10055 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
10056 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
10057 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
10058 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
10059 
10060 -- 4262811 Variables ------------------------------------------------------------------------------------------
10061 l_entered_amt_idx             NUMBER;
10062 l_accted_amt_idx              NUMBER;
10063 l_acc_rev_flag                VARCHAR2(1);
10064 l_accrual_line_num            NUMBER;
10065 l_tmp_amt                     NUMBER;
10066 l_acc_rev_natural_side_code   VARCHAR2(1);
10067 
10068 l_num_entries                 NUMBER;
10069 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
10070 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
10071 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
10072 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
10073 l_recog_line_1                NUMBER;
10074 l_recog_line_2                NUMBER;
10075 
10076 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
10077 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
10081 
10078 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
10079 
10080 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
10082 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
10083 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
10084 
10085 ---------------------------------------------------------------------------------------------------------------
10086 
10087 
10088 --
10089 -- bulk performance
10090 --
10091 l_balance_type_code           VARCHAR2(1);
10092 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
10093 l_log_module                  VARCHAR2(240);
10094 
10095 --
10096 -- Upgrade strategy
10097 --
10098 l_actual_upg_option           VARCHAR2(1);
10099 l_enc_upg_option           VARCHAR2(1);
10100 
10101 --
10102 BEGIN
10103 --
10104 IF g_log_enabled THEN
10105       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_22';
10106 END IF;
10107 --
10108 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10109 
10110       trace
10111          (p_msg      => 'BEGIN of AcctLineType_22'
10112          ,p_level    => C_LEVEL_PROCEDURE
10113          ,p_module   => l_log_module);
10114 
10115 END IF;
10116 --
10117 l_component_type             := 'AMB_JLT';
10118 l_component_code             := 'RCT_BNK_CHG';
10119 l_component_type_code        := 'S';
10120 l_component_appl_id          :=  222;
10121 l_amb_context_code           := 'DEFAULT';
10122 l_entity_code                := 'RECEIPTS';
10123 l_event_class_code           := 'RECEIPT';
10124 l_event_type_code            := 'RECEIPT_ALL';
10125 l_line_definition_owner_code := 'S';
10126 l_line_definition_code       := 'RCT_CASH_JLD';
10127 --
10128 l_balance_type_code          := 'A';
10129 l_segment                     := NULL;
10130 l_ccid                        := NULL;
10131 l_adr_transaction_coa_id      := NULL;
10132 l_adr_accounting_coa_id       := NULL;
10133 l_adr_flexfield_segment_code  := NULL;
10134 l_adr_flex_value_set_id       := NULL;
10135 l_adr_value_type_code         := NULL;
10136 l_adr_value_combination_id    := NULL;
10137 l_adr_value_segment_code      := NULL;
10138 
10139 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
10140 l_bflow_class_code           := '';    -- 4219869 Business Flow
10141 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
10142 l_budgetary_control_flag     := 'N';
10143 
10144 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
10145 l_bflow_applied_to_amt       := NULL; -- 5132302
10146 l_entered_amt_idx            := NULL;          -- 4262811
10147 l_accted_amt_idx             := NULL;          -- 4262811
10148 l_acc_rev_flag               := NULL;          -- 4262811
10149 l_accrual_line_num           := NULL;          -- 4262811
10150 l_tmp_amt                    := NULL;          -- 4262811
10151 --
10152  
10153 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
10154     l_balance_type_code <> 'B' THEN
10155 IF NVL(p_source_7,'
10156 ') =  'BANK_CHARGES' AND 
10157 NVL(p_source_8,'
10158 ') =  'N'
10159  THEN 
10160 
10161    --
10162    XLA_AE_LINES_PKG.SetNewLine;
10163 
10164    p_balance_type_code          := l_balance_type_code;
10165    -- set the flag so later we will know whether the gain loss line needs to be created
10166    
10167    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
10168      p_actual_flag :='A';
10169    END IF;
10170 
10171    --
10172    -- bulk performance
10173    --
10174    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
10175                                       p_header_num   => 0); -- 4262811
10176    --
10177    -- set accounting line options
10178    --
10179    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
10180            p_natural_side_code          => 'C'
10181          , p_gain_or_loss_flag          => 'N'
10182          , p_gl_transfer_mode_code      => 'S'
10183          , p_acct_entry_type_code       => 'A'
10184          , p_switch_side_flag           => 'Y'
10185          , p_merge_duplicate_code       => 'A'
10186          );
10187    --
10188    l_acc_rev_natural_side_code := 'D';  -- 4262811
10189    -- 
10190    --
10191    -- set accounting line type info
10192    --
10193    xla_ae_lines_pkg.SetAcctLineType
10194       (p_component_type             => l_component_type
10195       ,p_event_type_code            => l_event_type_code
10196       ,p_line_definition_owner_code => l_line_definition_owner_code
10197       ,p_line_definition_code       => l_line_definition_code
10198       ,p_accounting_line_code       => l_component_code
10199       ,p_accounting_line_type_code  => l_component_type_code
10200       ,p_accounting_line_appl_id    => l_component_appl_id
10201       ,p_amb_context_code           => l_amb_context_code
10202       ,p_entity_code                => l_entity_code
10203       ,p_event_class_code           => l_event_class_code);
10204    --
10205    -- set accounting class
10206    --
10207    xla_ae_lines_pkg.SetAcctClass(
10208            p_accounting_class_code  => 'BANK_CHG'
10209          , p_ae_header_id           => l_ae_header_id
10210          );
10211 
10212    --
10213    -- set rounding class
10214    --
10218    --
10215    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
10216                       'RECEIVABLE';
10217 
10219    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
10220    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
10221    --
10222    -- bulk performance
10223    --
10224    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
10225 
10226    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
10227       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
10228 
10229    -- 4955764
10230    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
10231       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
10232 
10233    -- 4458381 Public Sector Enh
10234    
10235    --
10236    -- set accounting attributes for the line type
10237    --
10238    l_entered_amt_idx := 8;
10239    l_accted_amt_idx  := 13;
10240    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
10241    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
10242    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
10243    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
10244    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
10245    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
10246    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
10247    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
10248    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
10249    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
10250    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
10251    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
10252    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
10253    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
10254    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
10255    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
10256    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
10257    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
10258    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
10259    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
10260    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
10261    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
10262    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
10263    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
10264    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
10265    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
10266    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
10267    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
10268    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
10269    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
10270    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
10271    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
10272    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
10273 
10274    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
10275    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
10276 
10277    ---------------------------------------------------------------------------------------------------------------
10278    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
10279    ---------------------------------------------------------------------------------------------------------------
10280    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
10281 
10282    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
10283    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
10284 
10285    IF xla_accounting_cache_pkg.GetValueChar
10286          (p_source_code         => 'LEDGER_CATEGORY_CODE'
10287          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
10288    AND l_bflow_method_code = 'PRIOR_ENTRY'
10289 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
10290    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
10291          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
10292        )
10293    THEN
10294          xla_ae_lines_pkg.BflowUpgEntry
10295            (p_business_method_code    => l_bflow_method_code
10296            ,p_business_class_code     => l_bflow_class_code
10297            ,p_balance_type            => l_balance_type_code);
10298    ELSE
10299       NULL;
10300 -- No business flow processing for business flow method of NONE.
10301    END IF;
10302 
10303    --
10304    -- call analytical criteria
10305    --
10306    
10307    --
10308    -- call description
10309    --
10310    -- No description or it is inherited.
10311    --
10312    -- call ADRs
10313    -- Bug 4922099
10314    --
10315    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
10316         (NVL(l_actual_upg_option, 'N') = 'O') OR
10317         (NVL(l_enc_upg_option, 'N') = 'O')
10321    --
10318       )
10319    THEN
10320    NULL;
10322    --
10323    
10324   l_ccid := AcctDerRule_1(
10325            p_application_id           => p_application_id
10326          , p_ae_header_id             => l_ae_header_id 
10327 , p_source_1 => p_source_1
10328          , x_transaction_coa_id       => l_adr_transaction_coa_id
10329          , x_accounting_coa_id        => l_adr_accounting_coa_id
10330          , x_value_type_code          => l_adr_value_type_code
10331          , p_side                     => 'NA'
10332    );
10333 
10334    xla_ae_lines_pkg.set_ccid(
10335     p_code_combination_id          => l_ccid
10336   , p_value_type_code              => l_adr_value_type_code
10337   , p_transaction_coa_id           => l_adr_transaction_coa_id
10338   , p_accounting_coa_id            => l_adr_accounting_coa_id
10339   , p_adr_code                     => 'DIST_CCID'
10340   , p_adr_type_code                => 'S'
10341   , p_component_type               => l_component_type
10342   , p_component_code               => l_component_code
10343   , p_component_type_code          => l_component_type_code
10344   , p_component_appl_id            => l_component_appl_id
10345   , p_amb_context_code             => l_amb_context_code
10346   , p_side                         => 'NA'
10347   );
10348 
10349 
10350    --
10351    --
10352    END IF;
10353    --
10354    -- Bug 4922099
10355    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
10356           (NVL(l_enc_upg_option, 'N') = 'O')
10357         ) AND
10358         (l_bflow_method_code = 'PRIOR_ENTRY')
10359       )
10360    THEN
10361       IF
10362       --
10363       1 = 2
10364       --
10365       THEN
10366       xla_accounting_err_pkg.build_message
10367                                     (p_appli_s_name            => 'XLA'
10368                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
10369                                     ,p_token_1                 => 'LINE_NUMBER'
10370                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
10371                                     ,p_token_2                 => 'LINE_TYPE_NAME'
10372                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
10373                                                                              l_component_type
10374                                                                             ,l_component_code
10375                                                                             ,l_component_type_code
10376                                                                             ,l_component_appl_id
10377                                                                             ,l_amb_context_code
10378                                                                             ,l_entity_code
10379                                                                             ,l_event_class_code
10380                                                                            )
10381                                     ,p_token_3                 => 'OWNER'
10382                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
10383                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
10384                                                                           ,p_lookup_code    => l_component_type_code
10385                                                                          )
10386                                     ,p_token_4                 => 'PRODUCT_NAME'
10387                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
10388                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
10389                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
10390                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
10391                                     ,p_ae_header_id            =>  NULL
10392                                        );
10393 
10394         IF (C_LEVEL_ERROR>= g_log_level) THEN
10395                  trace
10396                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
10397                       ,p_level    => C_LEVEL_ERROR
10398                       ,p_module   => l_log_module);
10399         END IF;
10400       END IF;
10401    END IF;
10402    --
10403    --
10404    ------------------------------------------------------------------------------------------------
10405    -- 4219869 Business Flow
10406    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
10407    -- Prior Entry.  Currently, the following code is always generated.
10408    ------------------------------------------------------------------------------------------------
10409    XLA_AE_LINES_PKG.ValidateCurrentLine;
10410 
10411    ------------------------------------------------------------------------------------
10412    -- 4219869 Business Flow
10413    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
10417    ----------------------------------------------------------------------------------
10414    ------------------------------------------------------------------------------------
10415    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
10416 
10418    -- 4219869 Business Flow
10419    -- Update journal entry status -- Need to generate this within IF <condition>
10420    ----------------------------------------------------------------------------------
10421    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
10422          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
10423          ,p_balance_type_code => l_balance_type_code
10424          );
10425 
10426    -------------------------------------------------------------------------------------------
10427    -- 4262811 - Generate the Accrual Reversal lines
10428    -------------------------------------------------------------------------------------------
10429    BEGIN
10430       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
10431                               (g_array_event(p_event_id).array_value_num('header_index'));
10432       IF l_acc_rev_flag IS NULL THEN
10433          l_acc_rev_flag := 'N';
10434       END IF;
10435    EXCEPTION
10436       WHEN OTHERS THEN
10437          l_acc_rev_flag := 'N';
10438    END;
10439    --
10440    IF (l_acc_rev_flag = 'Y') THEN
10441 
10442        -- 4645092  ------------------------------------------------------------------------------
10443        -- To allow MPA report to determine if it should generate report process
10444        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
10445        ------------------------------------------------------------------------------------------
10446 
10447        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
10448        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
10449    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
10450    -- call ADRs
10451    -- Bug 4922099
10452    --
10453    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
10454         (NVL(l_actual_upg_option, 'N') = 'O') OR
10455         (NVL(l_enc_upg_option, 'N') = 'O')
10456       )
10457    THEN
10458    NULL;
10459    --
10460    --
10461    
10462   l_ccid := AcctDerRule_1(
10463            p_application_id           => p_application_id
10464          , p_ae_header_id             => l_ae_header_id 
10465 , p_source_1 => p_source_1
10466          , x_transaction_coa_id       => l_adr_transaction_coa_id
10467          , x_accounting_coa_id        => l_adr_accounting_coa_id
10468          , x_value_type_code          => l_adr_value_type_code
10469          , p_side                     => 'NA'
10470    );
10471 
10472    xla_ae_lines_pkg.set_ccid(
10473     p_code_combination_id          => l_ccid
10474   , p_value_type_code              => l_adr_value_type_code
10475   , p_transaction_coa_id           => l_adr_transaction_coa_id
10476   , p_accounting_coa_id            => l_adr_accounting_coa_id
10477   , p_adr_code                     => 'DIST_CCID'
10478   , p_adr_type_code                => 'S'
10479   , p_component_type               => l_component_type
10480   , p_component_code               => l_component_code
10481   , p_component_type_code          => l_component_type_code
10482   , p_component_appl_id            => l_component_appl_id
10483   , p_amb_context_code             => l_amb_context_code
10484   , p_side                         => 'NA'
10485   );
10486 
10487 
10488    --
10489    --
10490    END IF;
10491 
10492        --
10493        -- Update the line information that should be overwritten
10494        --
10495        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
10496                                          p_header_num   => 1);
10497        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
10498 
10499        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
10500 
10501        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
10502           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
10503        END IF;
10504 
10505       --
10506       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
10507       --
10508       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
10509           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
10510       ELSE
10511           ---------------------------------------------------------------------------------------------------
10512           -- 4262811a Switch Sign
10513           ---------------------------------------------------------------------------------------------------
10514           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
10515           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
10516                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
10517           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
10518                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
10519           -- 5132302
10520           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
10521                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
10522 
10526       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
10523       END IF;
10524 
10525       -- 4955764
10527       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
10528 
10529 
10530       XLA_AE_LINES_PKG.ValidateCurrentLine;
10531       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
10532 
10533       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
10534                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
10535                ,p_balance_type_code => l_balance_type_code);
10536 
10537    END IF;
10538 
10539    -----------------------------------------------------------------------------------------
10540    -- 4262811 Multiperiod Accounting
10541    -----------------------------------------------------------------------------------------
10542      -- No MPA option is assigned.
10543 
10544 
10545 END IF;
10546 END IF;
10547 --
10548 
10549 --
10550 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10551    trace
10552       (p_msg      => 'END of AcctLineType_22'
10553       ,p_level    => C_LEVEL_PROCEDURE
10554       ,p_module   => l_log_module);
10555 END IF;
10556 --
10557 EXCEPTION
10558   WHEN xla_exceptions_pkg.application_exception THEN
10559       RAISE;
10560   WHEN OTHERS THEN
10561        xla_exceptions_pkg.raise_message
10562            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_22');
10563 END AcctLineType_22;
10564 --
10565 
10566 ---------------------------------------
10567 --
10568 -- PRIVATE FUNCTION
10569 --         AcctLineType_23
10570 --
10571 ---------------------------------------
10572 PROCEDURE AcctLineType_23 (
10573   p_application_id        IN NUMBER
10574  ,p_event_id              IN NUMBER
10575  ,p_calculate_acctd_flag  IN VARCHAR2
10576  ,p_calculate_g_l_flag    IN VARCHAR2
10577  ,p_actual_flag           IN OUT VARCHAR2
10578  ,p_balance_type_code     OUT VARCHAR2
10579  ,p_gain_or_loss_ref      OUT VARCHAR2
10580  
10581 --Distribution GL Account
10582  , p_source_1            IN NUMBER
10583 --Distribution Source Type
10584  , p_source_7            IN VARCHAR2
10585 --Distribution Multi Fund Additional Entry
10586  , p_source_8            IN VARCHAR2
10587 --Distribution Line Identifier
10588  , p_source_9            IN NUMBER
10589 --Distribution Type
10590  , p_source_10            IN VARCHAR2
10591 --Exchange Rate
10592  , p_source_14            IN NUMBER
10593 --Exchange Rate Type
10594  , p_source_15            IN VARCHAR2
10595 --Receipt Applied To Application Identifier
10596  , p_source_17            IN NUMBER
10597 --Transaction Distribution Type
10598  , p_source_18            IN VARCHAR2
10599 --Transaction Entity Code
10600  , p_source_19            IN VARCHAR2
10601 --Transaction Distribution Identifier
10602  , p_source_20            IN NUMBER
10603 --Transaction Identifier
10604  , p_source_21            IN NUMBER
10605 --DIST_ENT_AMT_FROM
10606  , p_source_22            IN NUMBER
10607 --Applying Document Currency Code
10608  , p_source_23            IN VARCHAR2
10609 --Exchange Date
10610  , p_source_24            IN DATE
10611 --Accounting Amount
10612  , p_source_25            IN NUMBER
10613 --Distribution Party Identifier
10614  , p_source_26            IN NUMBER
10615 --Distribution Party Site Id
10616  , p_source_27            IN NUMBER
10617 --Distribution Party Type
10618  , p_source_28            IN VARCHAR2
10619 )
10620 IS
10621 
10622 l_component_type              VARCHAR2(80);
10623 l_component_code              VARCHAR2(30);
10624 l_component_type_code         VARCHAR2(1);
10625 l_component_appl_id           INTEGER;
10626 l_amb_context_code            VARCHAR2(30);
10627 l_entity_code                 VARCHAR2(30);
10628 l_event_class_code            VARCHAR2(30);
10629 l_ae_header_id                NUMBER;
10630 l_event_type_code             VARCHAR2(30);
10631 l_line_definition_code        VARCHAR2(30);
10632 l_line_definition_owner_code  VARCHAR2(1);
10633 --
10634 -- adr variables
10635 l_segment                     VARCHAR2(30);
10636 l_ccid                        NUMBER;
10637 l_adr_transaction_coa_id      NUMBER;
10638 l_adr_accounting_coa_id       NUMBER;
10639 l_adr_flexfield_segment_code  VARCHAR2(30);
10640 l_adr_flex_value_set_id       NUMBER;
10641 l_adr_value_type_code         VARCHAR2(30);
10642 l_adr_value_combination_id    NUMBER;
10643 l_adr_value_segment_code      VARCHAR2(30);
10644 
10645 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
10646 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
10647 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
10648 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
10649 
10650 -- 4262811 Variables ------------------------------------------------------------------------------------------
10651 l_entered_amt_idx             NUMBER;
10652 l_accted_amt_idx              NUMBER;
10653 l_acc_rev_flag                VARCHAR2(1);
10654 l_accrual_line_num            NUMBER;
10655 l_tmp_amt                     NUMBER;
10656 l_acc_rev_natural_side_code   VARCHAR2(1);
10657 
10658 l_num_entries                 NUMBER;
10659 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
10663 l_recog_line_1                NUMBER;
10660 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
10661 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
10662 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
10664 l_recog_line_2                NUMBER;
10665 
10666 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
10667 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
10668 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
10669 
10670 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
10671 
10672 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
10673 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
10674 
10675 ---------------------------------------------------------------------------------------------------------------
10676 
10677 
10678 --
10679 -- bulk performance
10680 --
10681 l_balance_type_code           VARCHAR2(1);
10682 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
10683 l_log_module                  VARCHAR2(240);
10684 
10685 --
10686 -- Upgrade strategy
10687 --
10688 l_actual_upg_option           VARCHAR2(1);
10689 l_enc_upg_option           VARCHAR2(1);
10690 
10691 --
10692 BEGIN
10693 --
10694 IF g_log_enabled THEN
10695       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_23';
10696 END IF;
10697 --
10698 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10699 
10700       trace
10701          (p_msg      => 'BEGIN of AcctLineType_23'
10702          ,p_level    => C_LEVEL_PROCEDURE
10703          ,p_module   => l_log_module);
10704 
10705 END IF;
10706 --
10707 l_component_type             := 'AMB_JLT';
10708 l_component_code             := 'RCT_CASH';
10709 l_component_type_code        := 'S';
10710 l_component_appl_id          :=  222;
10711 l_amb_context_code           := 'DEFAULT';
10712 l_entity_code                := 'RECEIPTS';
10713 l_event_class_code           := 'RECEIPT';
10714 l_event_type_code            := 'RECEIPT_ALL';
10715 l_line_definition_owner_code := 'S';
10716 l_line_definition_code       := 'RCT_CASH_JLD';
10717 --
10718 l_balance_type_code          := 'A';
10719 l_segment                     := NULL;
10720 l_ccid                        := NULL;
10721 l_adr_transaction_coa_id      := NULL;
10722 l_adr_accounting_coa_id       := NULL;
10723 l_adr_flexfield_segment_code  := NULL;
10724 l_adr_flex_value_set_id       := NULL;
10725 l_adr_value_type_code         := NULL;
10726 l_adr_value_combination_id    := NULL;
10727 l_adr_value_segment_code      := NULL;
10728 
10729 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
10730 l_bflow_class_code           := '';    -- 4219869 Business Flow
10731 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
10732 l_budgetary_control_flag     := 'N';
10733 
10734 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
10735 l_bflow_applied_to_amt       := NULL; -- 5132302
10736 l_entered_amt_idx            := NULL;          -- 4262811
10737 l_accted_amt_idx             := NULL;          -- 4262811
10738 l_acc_rev_flag               := NULL;          -- 4262811
10739 l_accrual_line_num           := NULL;          -- 4262811
10740 l_tmp_amt                    := NULL;          -- 4262811
10741 --
10742  
10743 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
10744     l_balance_type_code <> 'B' THEN
10745 IF NVL(p_source_7,'
10746 ') =  'CASH' AND 
10747 NVL(p_source_8,'
10748 ') =  'N'
10749  THEN 
10750 
10751    --
10752    XLA_AE_LINES_PKG.SetNewLine;
10753 
10754    p_balance_type_code          := l_balance_type_code;
10755    -- set the flag so later we will know whether the gain loss line needs to be created
10756    
10757    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
10758      p_actual_flag :='A';
10759    END IF;
10760 
10761    --
10762    -- bulk performance
10763    --
10764    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
10765                                       p_header_num   => 0); -- 4262811
10766    --
10767    -- set accounting line options
10768    --
10769    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
10770            p_natural_side_code          => 'C'
10771          , p_gain_or_loss_flag          => 'N'
10772          , p_gl_transfer_mode_code      => 'S'
10773          , p_acct_entry_type_code       => 'A'
10774          , p_switch_side_flag           => 'Y'
10775          , p_merge_duplicate_code       => 'A'
10776          );
10777    --
10778    l_acc_rev_natural_side_code := 'D';  -- 4262811
10779    -- 
10780    --
10781    -- set accounting line type info
10782    --
10783    xla_ae_lines_pkg.SetAcctLineType
10784       (p_component_type             => l_component_type
10785       ,p_event_type_code            => l_event_type_code
10786       ,p_line_definition_owner_code => l_line_definition_owner_code
10787       ,p_line_definition_code       => l_line_definition_code
10788       ,p_accounting_line_code       => l_component_code
10789       ,p_accounting_line_type_code  => l_component_type_code
10790       ,p_accounting_line_appl_id    => l_component_appl_id
10791       ,p_amb_context_code           => l_amb_context_code
10795    -- set accounting class
10792       ,p_entity_code                => l_entity_code
10793       ,p_event_class_code           => l_event_class_code);
10794    --
10796    --
10797    xla_ae_lines_pkg.SetAcctClass(
10798            p_accounting_class_code  => 'CASH'
10799          , p_ae_header_id           => l_ae_header_id
10800          );
10801 
10802    --
10803    -- set rounding class
10804    --
10805    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
10806                       'RECEIVABLE';
10807 
10808    --
10809    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
10810    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
10811    --
10812    -- bulk performance
10813    --
10814    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
10815 
10816    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
10817       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
10818 
10819    -- 4955764
10820    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
10821       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
10822 
10823    -- 4458381 Public Sector Enh
10824    
10825    --
10826    -- set accounting attributes for the line type
10827    --
10828    l_entered_amt_idx := 8;
10829    l_accted_amt_idx  := 13;
10830    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
10831    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
10832    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
10833    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
10834    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
10835    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
10836    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
10837    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
10838    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
10839    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
10840    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
10841    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
10842    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
10843    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
10844    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
10845    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
10846    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
10847    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
10848    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
10849    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
10850    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
10851    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
10852    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
10853    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
10854    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
10855    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
10856    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
10857    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
10858    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
10859    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
10860    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
10861    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
10862    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
10863 
10864    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
10865    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
10866 
10867    ---------------------------------------------------------------------------------------------------------------
10868    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
10869    ---------------------------------------------------------------------------------------------------------------
10870    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
10871 
10872    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
10873    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
10874 
10875    IF xla_accounting_cache_pkg.GetValueChar
10876          (p_source_code         => 'LEDGER_CATEGORY_CODE'
10877          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
10878    AND l_bflow_method_code = 'PRIOR_ENTRY'
10879 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
10880    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
10881          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
10882        )
10883    THEN
10884          xla_ae_lines_pkg.BflowUpgEntry
10885            (p_business_method_code    => l_bflow_method_code
10886            ,p_business_class_code     => l_bflow_class_code
10887            ,p_balance_type            => l_balance_type_code);
10888    ELSE
10889       NULL;
10890 -- No business flow processing for business flow method of NONE.
10894    -- call analytical criteria
10891    END IF;
10892 
10893    --
10895    --
10896    
10897    --
10898    -- call description
10899    --
10900    -- No description or it is inherited.
10901    --
10902    -- call ADRs
10903    -- Bug 4922099
10904    --
10905    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
10906         (NVL(l_actual_upg_option, 'N') = 'O') OR
10907         (NVL(l_enc_upg_option, 'N') = 'O')
10908       )
10909    THEN
10910    NULL;
10911    --
10912    --
10913    
10914   l_ccid := AcctDerRule_1(
10915            p_application_id           => p_application_id
10916          , p_ae_header_id             => l_ae_header_id 
10917 , p_source_1 => p_source_1
10918          , x_transaction_coa_id       => l_adr_transaction_coa_id
10919          , x_accounting_coa_id        => l_adr_accounting_coa_id
10920          , x_value_type_code          => l_adr_value_type_code
10921          , p_side                     => 'NA'
10922    );
10923 
10924    xla_ae_lines_pkg.set_ccid(
10925     p_code_combination_id          => l_ccid
10926   , p_value_type_code              => l_adr_value_type_code
10927   , p_transaction_coa_id           => l_adr_transaction_coa_id
10928   , p_accounting_coa_id            => l_adr_accounting_coa_id
10929   , p_adr_code                     => 'DIST_CCID'
10930   , p_adr_type_code                => 'S'
10931   , p_component_type               => l_component_type
10932   , p_component_code               => l_component_code
10933   , p_component_type_code          => l_component_type_code
10934   , p_component_appl_id            => l_component_appl_id
10935   , p_amb_context_code             => l_amb_context_code
10936   , p_side                         => 'NA'
10937   );
10938 
10939 
10940    --
10941    --
10942    END IF;
10943    --
10944    -- Bug 4922099
10945    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
10946           (NVL(l_enc_upg_option, 'N') = 'O')
10947         ) AND
10948         (l_bflow_method_code = 'PRIOR_ENTRY')
10949       )
10950    THEN
10951       IF
10952       --
10953       1 = 2
10954       --
10955       THEN
10956       xla_accounting_err_pkg.build_message
10957                                     (p_appli_s_name            => 'XLA'
10958                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
10959                                     ,p_token_1                 => 'LINE_NUMBER'
10960                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
10961                                     ,p_token_2                 => 'LINE_TYPE_NAME'
10962                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
10963                                                                              l_component_type
10964                                                                             ,l_component_code
10965                                                                             ,l_component_type_code
10966                                                                             ,l_component_appl_id
10967                                                                             ,l_amb_context_code
10968                                                                             ,l_entity_code
10969                                                                             ,l_event_class_code
10970                                                                            )
10971                                     ,p_token_3                 => 'OWNER'
10972                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
10973                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
10974                                                                           ,p_lookup_code    => l_component_type_code
10975                                                                          )
10976                                     ,p_token_4                 => 'PRODUCT_NAME'
10977                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
10978                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
10979                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
10980                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
10981                                     ,p_ae_header_id            =>  NULL
10982                                        );
10983 
10984         IF (C_LEVEL_ERROR>= g_log_level) THEN
10985                  trace
10986                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
10987                       ,p_level    => C_LEVEL_ERROR
10988                       ,p_module   => l_log_module);
10989         END IF;
10990       END IF;
10991    END IF;
10992    --
10993    --
10994    ------------------------------------------------------------------------------------------------
10995    -- 4219869 Business Flow
10996    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
10997    -- Prior Entry.  Currently, the following code is always generated.
10998    ------------------------------------------------------------------------------------------------
10999    XLA_AE_LINES_PKG.ValidateCurrentLine;
11000 
11004    ------------------------------------------------------------------------------------
11001    ------------------------------------------------------------------------------------
11002    -- 4219869 Business Flow
11003    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
11005    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
11006 
11007    ----------------------------------------------------------------------------------
11008    -- 4219869 Business Flow
11009    -- Update journal entry status -- Need to generate this within IF <condition>
11010    ----------------------------------------------------------------------------------
11011    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
11012          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
11013          ,p_balance_type_code => l_balance_type_code
11014          );
11015 
11016    -------------------------------------------------------------------------------------------
11017    -- 4262811 - Generate the Accrual Reversal lines
11018    -------------------------------------------------------------------------------------------
11019    BEGIN
11020       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
11021                               (g_array_event(p_event_id).array_value_num('header_index'));
11022       IF l_acc_rev_flag IS NULL THEN
11023          l_acc_rev_flag := 'N';
11024       END IF;
11025    EXCEPTION
11026       WHEN OTHERS THEN
11027          l_acc_rev_flag := 'N';
11028    END;
11029    --
11030    IF (l_acc_rev_flag = 'Y') THEN
11031 
11032        -- 4645092  ------------------------------------------------------------------------------
11033        -- To allow MPA report to determine if it should generate report process
11034        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
11035        ------------------------------------------------------------------------------------------
11036 
11037        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
11038        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
11039    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
11040    -- call ADRs
11041    -- Bug 4922099
11042    --
11043    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
11044         (NVL(l_actual_upg_option, 'N') = 'O') OR
11045         (NVL(l_enc_upg_option, 'N') = 'O')
11046       )
11047    THEN
11048    NULL;
11049    --
11050    --
11051    
11052   l_ccid := AcctDerRule_1(
11053            p_application_id           => p_application_id
11054          , p_ae_header_id             => l_ae_header_id 
11055 , p_source_1 => p_source_1
11056          , x_transaction_coa_id       => l_adr_transaction_coa_id
11057          , x_accounting_coa_id        => l_adr_accounting_coa_id
11058          , x_value_type_code          => l_adr_value_type_code
11059          , p_side                     => 'NA'
11060    );
11061 
11062    xla_ae_lines_pkg.set_ccid(
11063     p_code_combination_id          => l_ccid
11064   , p_value_type_code              => l_adr_value_type_code
11065   , p_transaction_coa_id           => l_adr_transaction_coa_id
11066   , p_accounting_coa_id            => l_adr_accounting_coa_id
11067   , p_adr_code                     => 'DIST_CCID'
11068   , p_adr_type_code                => 'S'
11069   , p_component_type               => l_component_type
11070   , p_component_code               => l_component_code
11071   , p_component_type_code          => l_component_type_code
11072   , p_component_appl_id            => l_component_appl_id
11073   , p_amb_context_code             => l_amb_context_code
11074   , p_side                         => 'NA'
11075   );
11076 
11077 
11078    --
11079    --
11080    END IF;
11081 
11082        --
11083        -- Update the line information that should be overwritten
11084        --
11085        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
11086                                          p_header_num   => 1);
11087        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
11088 
11089        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
11090 
11091        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
11092           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
11093        END IF;
11094 
11095       --
11096       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
11097       --
11098       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
11099           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
11100       ELSE
11101           ---------------------------------------------------------------------------------------------------
11102           -- 4262811a Switch Sign
11103           ---------------------------------------------------------------------------------------------------
11104           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
11105           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
11106                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11107           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
11108                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11109           -- 5132302
11110           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
11111                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11112 
11113       END IF;
11114 
11115       -- 4955764
11116       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
11117       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
11118 
11119 
11120       XLA_AE_LINES_PKG.ValidateCurrentLine;
11121       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
11122 
11123       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
11124                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
11125                ,p_balance_type_code => l_balance_type_code);
11126 
11127    END IF;
11128 
11129    -----------------------------------------------------------------------------------------
11130    -- 4262811 Multiperiod Accounting
11131    -----------------------------------------------------------------------------------------
11132      -- No MPA option is assigned.
11133 
11134 
11135 END IF;
11136 END IF;
11137 --
11138 
11139 --
11140 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11141    trace
11142       (p_msg      => 'END of AcctLineType_23'
11143       ,p_level    => C_LEVEL_PROCEDURE
11144       ,p_module   => l_log_module);
11145 END IF;
11146 --
11147 EXCEPTION
11148   WHEN xla_exceptions_pkg.application_exception THEN
11149       RAISE;
11150   WHEN OTHERS THEN
11151        xla_exceptions_pkg.raise_message
11152            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_23');
11153 END AcctLineType_23;
11154 --
11155 
11156 ---------------------------------------
11157 --
11158 -- PRIVATE FUNCTION
11159 --         AcctLineType_24
11160 --
11161 ---------------------------------------
11162 PROCEDURE AcctLineType_24 (
11163   p_application_id        IN NUMBER
11164  ,p_event_id              IN NUMBER
11165  ,p_calculate_acctd_flag  IN VARCHAR2
11166  ,p_calculate_g_l_flag    IN VARCHAR2
11167  ,p_actual_flag           IN OUT VARCHAR2
11168  ,p_balance_type_code     OUT VARCHAR2
11169  ,p_gain_or_loss_ref      OUT VARCHAR2
11170  
11171 --Distribution GL Account
11172  , p_source_1            IN NUMBER
11173 --Distribution Source Type
11174  , p_source_7            IN VARCHAR2
11175 --Distribution Multi Fund Additional Entry
11176  , p_source_8            IN VARCHAR2
11177 --Distribution Line Identifier
11178  , p_source_9            IN NUMBER
11179 --Distribution Type
11180  , p_source_10            IN VARCHAR2
11181 --Exchange Rate
11182  , p_source_14            IN NUMBER
11183 --Receipt Applied To Application Identifier
11184  , p_source_17            IN NUMBER
11185 --Transaction Distribution Type
11186  , p_source_18            IN VARCHAR2
11187 --Transaction Entity Code
11188  , p_source_19            IN VARCHAR2
11189 --Transaction Distribution Identifier
11190  , p_source_20            IN NUMBER
11191 --Transaction Identifier
11192  , p_source_21            IN NUMBER
11193 --DIST_ENT_AMT_FROM
11194  , p_source_22            IN NUMBER
11195 --Applying Document Currency Code
11196  , p_source_23            IN VARCHAR2
11197 --Exchange Date
11198  , p_source_24            IN DATE
11199 --Accounting Amount
11200  , p_source_25            IN NUMBER
11204  , p_source_27            IN NUMBER
11201 --Distribution Party Identifier
11202  , p_source_26            IN NUMBER
11203 --Distribution Party Site Id
11205 --Distribution Party Type
11206  , p_source_28            IN VARCHAR2
11207 --Applied To Document Exchange Rate Type
11208  , p_source_31            IN VARCHAR2
11209 --Receivable Activity Type
11210  , p_source_32            IN VARCHAR2
11211 )
11212 IS
11213 
11214 l_component_type              VARCHAR2(80);
11215 l_component_code              VARCHAR2(30);
11216 l_component_type_code         VARCHAR2(1);
11217 l_component_appl_id           INTEGER;
11218 l_amb_context_code            VARCHAR2(30);
11219 l_entity_code                 VARCHAR2(30);
11220 l_event_class_code            VARCHAR2(30);
11221 l_ae_header_id                NUMBER;
11222 l_event_type_code             VARCHAR2(30);
11223 l_line_definition_code        VARCHAR2(30);
11224 l_line_definition_owner_code  VARCHAR2(1);
11225 --
11226 -- adr variables
11227 l_segment                     VARCHAR2(30);
11228 l_ccid                        NUMBER;
11229 l_adr_transaction_coa_id      NUMBER;
11230 l_adr_accounting_coa_id       NUMBER;
11231 l_adr_flexfield_segment_code  VARCHAR2(30);
11232 l_adr_flex_value_set_id       NUMBER;
11233 l_adr_value_type_code         VARCHAR2(30);
11234 l_adr_value_combination_id    NUMBER;
11235 l_adr_value_segment_code      VARCHAR2(30);
11236 
11237 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
11238 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
11239 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
11240 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
11241 
11242 -- 4262811 Variables ------------------------------------------------------------------------------------------
11243 l_entered_amt_idx             NUMBER;
11244 l_accted_amt_idx              NUMBER;
11245 l_acc_rev_flag                VARCHAR2(1);
11246 l_accrual_line_num            NUMBER;
11247 l_tmp_amt                     NUMBER;
11248 l_acc_rev_natural_side_code   VARCHAR2(1);
11249 
11250 l_num_entries                 NUMBER;
11251 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
11252 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
11253 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
11254 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
11255 l_recog_line_1                NUMBER;
11256 l_recog_line_2                NUMBER;
11257 
11258 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
11259 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
11260 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
11261 
11262 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
11263 
11264 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
11265 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
11266 
11267 ---------------------------------------------------------------------------------------------------------------
11268 
11269 
11270 --
11271 -- bulk performance
11272 --
11273 l_balance_type_code           VARCHAR2(1);
11274 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
11275 l_log_module                  VARCHAR2(240);
11276 
11277 --
11278 -- Upgrade strategy
11279 --
11280 l_actual_upg_option           VARCHAR2(1);
11281 l_enc_upg_option           VARCHAR2(1);
11282 
11283 --
11284 BEGIN
11285 --
11286 IF g_log_enabled THEN
11287       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_24';
11288 END IF;
11289 --
11290 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11291 
11292       trace
11293          (p_msg      => 'BEGIN of AcctLineType_24'
11294          ,p_level    => C_LEVEL_PROCEDURE
11295          ,p_module   => l_log_module);
11296 
11297 END IF;
11298 --
11299 l_component_type             := 'AMB_JLT';
11300 l_component_code             := 'RCT_CLAIM';
11301 l_component_type_code        := 'S';
11302 l_component_appl_id          :=  222;
11303 l_amb_context_code           := 'DEFAULT';
11304 l_entity_code                := 'RECEIPTS';
11305 l_event_class_code           := 'RECEIPT';
11306 l_event_type_code            := 'RECEIPT_ALL';
11307 l_line_definition_owner_code := 'S';
11308 l_line_definition_code       := 'RCT_CASH_JLD';
11309 --
11310 l_balance_type_code          := 'A';
11311 l_segment                     := NULL;
11312 l_ccid                        := NULL;
11313 l_adr_transaction_coa_id      := NULL;
11314 l_adr_accounting_coa_id       := NULL;
11315 l_adr_flexfield_segment_code  := NULL;
11316 l_adr_flex_value_set_id       := NULL;
11317 l_adr_value_type_code         := NULL;
11318 l_adr_value_combination_id    := NULL;
11319 l_adr_value_segment_code      := NULL;
11320 
11321 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
11322 l_bflow_class_code           := '';    -- 4219869 Business Flow
11323 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
11324 l_budgetary_control_flag     := 'N';
11325 
11326 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
11327 l_bflow_applied_to_amt       := NULL; -- 5132302
11328 l_entered_amt_idx            := NULL;          -- 4262811
11332 l_tmp_amt                    := NULL;          -- 4262811
11329 l_accted_amt_idx             := NULL;          -- 4262811
11330 l_acc_rev_flag               := NULL;          -- 4262811
11331 l_accrual_line_num           := NULL;          -- 4262811
11333 --
11334  
11335 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
11336     l_balance_type_code <> 'B' THEN
11337 IF NVL(p_source_7,'
11338 ') =  'OTHER ACC' AND 
11339 NVL(p_source_32,'
11340 ') =  'CLAIM_INVESTIGATION' AND 
11341 NVL(p_source_8,'
11342 ') =  'N'
11343  THEN 
11344 
11345    --
11346    XLA_AE_LINES_PKG.SetNewLine;
11347 
11348    p_balance_type_code          := l_balance_type_code;
11349    -- set the flag so later we will know whether the gain loss line needs to be created
11350    
11351    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
11352      p_actual_flag :='A';
11353    END IF;
11354 
11355    --
11356    -- bulk performance
11357    --
11358    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
11359                                       p_header_num   => 0); -- 4262811
11360    --
11361    -- set accounting line options
11362    --
11363    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
11364            p_natural_side_code          => 'C'
11365          , p_gain_or_loss_flag          => 'N'
11366          , p_gl_transfer_mode_code      => 'S'
11367          , p_acct_entry_type_code       => 'A'
11368          , p_switch_side_flag           => 'Y'
11369          , p_merge_duplicate_code       => 'A'
11370          );
11371    --
11372    l_acc_rev_natural_side_code := 'D';  -- 4262811
11373    -- 
11374    --
11375    -- set accounting line type info
11376    --
11377    xla_ae_lines_pkg.SetAcctLineType
11378       (p_component_type             => l_component_type
11379       ,p_event_type_code            => l_event_type_code
11380       ,p_line_definition_owner_code => l_line_definition_owner_code
11381       ,p_line_definition_code       => l_line_definition_code
11382       ,p_accounting_line_code       => l_component_code
11383       ,p_accounting_line_type_code  => l_component_type_code
11384       ,p_accounting_line_appl_id    => l_component_appl_id
11385       ,p_amb_context_code           => l_amb_context_code
11386       ,p_entity_code                => l_entity_code
11387       ,p_event_class_code           => l_event_class_code);
11388    --
11389    -- set accounting class
11390    --
11391    xla_ae_lines_pkg.SetAcctClass(
11392            p_accounting_class_code  => 'CLAIM'
11393          , p_ae_header_id           => l_ae_header_id
11394          );
11395 
11396    --
11397    -- set rounding class
11398    --
11399    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
11400                       'RECEIVABLE';
11401 
11402    --
11403    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
11404    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
11405    --
11406    -- bulk performance
11407    --
11408    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
11409 
11410    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
11411       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
11412 
11413    -- 4955764
11414    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
11415       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
11416 
11417    -- 4458381 Public Sector Enh
11418    
11419    --
11420    -- set accounting attributes for the line type
11421    --
11422    l_entered_amt_idx := 8;
11423    l_accted_amt_idx  := 13;
11424    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
11425    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
11426    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
11427    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
11428    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
11429    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
11430    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
11431    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
11432    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
11433    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
11434    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
11435    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
11436    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
11437    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
11438    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
11439    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
11440    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
11441    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
11442    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
11443    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
11444    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
11445    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
11449    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
11446    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
11447    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
11448    l_rec_acct_attrs.array_char_value(12)  := p_source_31;
11450    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
11451    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
11452    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
11453    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
11454    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
11455    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
11456    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
11457 
11458    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
11459    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
11460 
11461    ---------------------------------------------------------------------------------------------------------------
11462    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
11463    ---------------------------------------------------------------------------------------------------------------
11464    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
11465 
11466    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
11467    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
11468 
11469    IF xla_accounting_cache_pkg.GetValueChar
11470          (p_source_code         => 'LEDGER_CATEGORY_CODE'
11471          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
11472    AND l_bflow_method_code = 'PRIOR_ENTRY'
11473 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
11474    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
11475          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
11476        )
11477    THEN
11478          xla_ae_lines_pkg.BflowUpgEntry
11479            (p_business_method_code    => l_bflow_method_code
11480            ,p_business_class_code     => l_bflow_class_code
11481            ,p_balance_type            => l_balance_type_code);
11482    ELSE
11483       NULL;
11484 -- No business flow processing for business flow method of NONE.
11485    END IF;
11486 
11487    --
11488    -- call analytical criteria
11489    --
11490    
11491    --
11492    -- call description
11493    --
11494    -- No description or it is inherited.
11495    --
11496    -- call ADRs
11497    -- Bug 4922099
11498    --
11499    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
11500         (NVL(l_actual_upg_option, 'N') = 'O') OR
11501         (NVL(l_enc_upg_option, 'N') = 'O')
11502       )
11503    THEN
11504    NULL;
11505    --
11506    --
11507    
11508   l_ccid := AcctDerRule_1(
11509            p_application_id           => p_application_id
11510          , p_ae_header_id             => l_ae_header_id 
11511 , p_source_1 => p_source_1
11512          , x_transaction_coa_id       => l_adr_transaction_coa_id
11513          , x_accounting_coa_id        => l_adr_accounting_coa_id
11514          , x_value_type_code          => l_adr_value_type_code
11515          , p_side                     => 'NA'
11516    );
11517 
11518    xla_ae_lines_pkg.set_ccid(
11519     p_code_combination_id          => l_ccid
11520   , p_value_type_code              => l_adr_value_type_code
11521   , p_transaction_coa_id           => l_adr_transaction_coa_id
11522   , p_accounting_coa_id            => l_adr_accounting_coa_id
11523   , p_adr_code                     => 'DIST_CCID'
11524   , p_adr_type_code                => 'S'
11525   , p_component_type               => l_component_type
11526   , p_component_code               => l_component_code
11527   , p_component_type_code          => l_component_type_code
11528   , p_component_appl_id            => l_component_appl_id
11529   , p_amb_context_code             => l_amb_context_code
11530   , p_side                         => 'NA'
11531   );
11532 
11533 
11534    --
11535    --
11536    END IF;
11537    --
11538    -- Bug 4922099
11539    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
11540           (NVL(l_enc_upg_option, 'N') = 'O')
11541         ) AND
11542         (l_bflow_method_code = 'PRIOR_ENTRY')
11543       )
11544    THEN
11545       IF
11546       --
11547       1 = 2
11548       --
11549       THEN
11550       xla_accounting_err_pkg.build_message
11551                                     (p_appli_s_name            => 'XLA'
11552                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
11553                                     ,p_token_1                 => 'LINE_NUMBER'
11554                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
11555                                     ,p_token_2                 => 'LINE_TYPE_NAME'
11556                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
11557                                                                              l_component_type
11558                                                                             ,l_component_code
11559                                                                             ,l_component_type_code
11563                                                                             ,l_event_class_code
11560                                                                             ,l_component_appl_id
11561                                                                             ,l_amb_context_code
11562                                                                             ,l_entity_code
11564                                                                            )
11565                                     ,p_token_3                 => 'OWNER'
11566                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
11567                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
11568                                                                           ,p_lookup_code    => l_component_type_code
11569                                                                          )
11570                                     ,p_token_4                 => 'PRODUCT_NAME'
11571                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
11572                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
11573                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
11574                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
11575                                     ,p_ae_header_id            =>  NULL
11576                                        );
11577 
11578         IF (C_LEVEL_ERROR>= g_log_level) THEN
11579                  trace
11580                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
11581                       ,p_level    => C_LEVEL_ERROR
11582                       ,p_module   => l_log_module);
11583         END IF;
11584       END IF;
11585    END IF;
11586    --
11587    --
11588    ------------------------------------------------------------------------------------------------
11589    -- 4219869 Business Flow
11590    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
11591    -- Prior Entry.  Currently, the following code is always generated.
11592    ------------------------------------------------------------------------------------------------
11593    XLA_AE_LINES_PKG.ValidateCurrentLine;
11594 
11595    ------------------------------------------------------------------------------------
11596    -- 4219869 Business Flow
11597    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
11598    ------------------------------------------------------------------------------------
11599    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
11600 
11601    ----------------------------------------------------------------------------------
11602    -- 4219869 Business Flow
11603    -- Update journal entry status -- Need to generate this within IF <condition>
11604    ----------------------------------------------------------------------------------
11605    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
11606          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
11607          ,p_balance_type_code => l_balance_type_code
11608          );
11609 
11610    -------------------------------------------------------------------------------------------
11611    -- 4262811 - Generate the Accrual Reversal lines
11612    -------------------------------------------------------------------------------------------
11613    BEGIN
11614       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
11615                               (g_array_event(p_event_id).array_value_num('header_index'));
11616       IF l_acc_rev_flag IS NULL THEN
11617          l_acc_rev_flag := 'N';
11618       END IF;
11619    EXCEPTION
11620       WHEN OTHERS THEN
11621          l_acc_rev_flag := 'N';
11622    END;
11623    --
11624    IF (l_acc_rev_flag = 'Y') THEN
11625 
11626        -- 4645092  ------------------------------------------------------------------------------
11627        -- To allow MPA report to determine if it should generate report process
11628        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
11629        ------------------------------------------------------------------------------------------
11630 
11631        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
11632        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
11633    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
11634    -- call ADRs
11635    -- Bug 4922099
11636    --
11637    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
11638         (NVL(l_actual_upg_option, 'N') = 'O') OR
11639         (NVL(l_enc_upg_option, 'N') = 'O')
11640       )
11641    THEN
11642    NULL;
11643    --
11644    --
11645    
11646   l_ccid := AcctDerRule_1(
11647            p_application_id           => p_application_id
11648          , p_ae_header_id             => l_ae_header_id 
11649 , p_source_1 => p_source_1
11650          , x_transaction_coa_id       => l_adr_transaction_coa_id
11651          , x_accounting_coa_id        => l_adr_accounting_coa_id
11652          , x_value_type_code          => l_adr_value_type_code
11653          , p_side                     => 'NA'
11654    );
11655 
11656    xla_ae_lines_pkg.set_ccid(
11657     p_code_combination_id          => l_ccid
11658   , p_value_type_code              => l_adr_value_type_code
11659   , p_transaction_coa_id           => l_adr_transaction_coa_id
11660   , p_accounting_coa_id            => l_adr_accounting_coa_id
11664   , p_component_code               => l_component_code
11661   , p_adr_code                     => 'DIST_CCID'
11662   , p_adr_type_code                => 'S'
11663   , p_component_type               => l_component_type
11665   , p_component_type_code          => l_component_type_code
11666   , p_component_appl_id            => l_component_appl_id
11667   , p_amb_context_code             => l_amb_context_code
11668   , p_side                         => 'NA'
11669   );
11670 
11671 
11672    --
11673    --
11674    END IF;
11675 
11676        --
11677        -- Update the line information that should be overwritten
11678        --
11679        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
11680                                          p_header_num   => 1);
11681        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
11682 
11683        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
11684 
11685        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
11686           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
11687        END IF;
11688 
11689       --
11690       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
11691       --
11692       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
11693           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
11694       ELSE
11695           ---------------------------------------------------------------------------------------------------
11696           -- 4262811a Switch Sign
11697           ---------------------------------------------------------------------------------------------------
11698           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
11699           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
11700                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11701           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
11702                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11703           -- 5132302
11704           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
11705                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
11706 
11707       END IF;
11708 
11709       -- 4955764
11710       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
11711       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
11712 
11713 
11714       XLA_AE_LINES_PKG.ValidateCurrentLine;
11715       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
11716 
11717       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
11718                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
11719                ,p_balance_type_code => l_balance_type_code);
11720 
11721    END IF;
11722 
11723    -----------------------------------------------------------------------------------------
11724    -- 4262811 Multiperiod Accounting
11725    -----------------------------------------------------------------------------------------
11726      -- No MPA option is assigned.
11727 
11728 
11729 END IF;
11730 END IF;
11731 --
11732 
11733 --
11734 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11735    trace
11736       (p_msg      => 'END of AcctLineType_24'
11737       ,p_level    => C_LEVEL_PROCEDURE
11738       ,p_module   => l_log_module);
11739 END IF;
11740 --
11741 EXCEPTION
11742   WHEN xla_exceptions_pkg.application_exception THEN
11743       RAISE;
11744   WHEN OTHERS THEN
11745        xla_exceptions_pkg.raise_message
11746            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_24');
11747 END AcctLineType_24;
11748 --
11749 
11750 ---------------------------------------
11751 --
11752 -- PRIVATE FUNCTION
11753 --         AcctLineType_25
11754 --
11755 ---------------------------------------
11756 PROCEDURE AcctLineType_25 (
11757   p_application_id        IN NUMBER
11758  ,p_event_id              IN NUMBER
11759  ,p_calculate_acctd_flag  IN VARCHAR2
11760  ,p_calculate_g_l_flag    IN VARCHAR2
11761  ,p_actual_flag           IN OUT VARCHAR2
11762  ,p_balance_type_code     OUT VARCHAR2
11763  ,p_gain_or_loss_ref      OUT VARCHAR2
11764  
11765 --Distribution GL Account
11766  , p_source_1            IN NUMBER
11767 --Distribution Source Type
11768  , p_source_7            IN VARCHAR2
11769 --Distribution Multi Fund Additional Entry
11770  , p_source_8            IN VARCHAR2
11771 --Distribution Line Identifier
11772  , p_source_9            IN NUMBER
11773 --Distribution Type
11774  , p_source_10            IN VARCHAR2
11775 --Exchange Rate
11776  , p_source_14            IN NUMBER
11777 --Exchange Rate Type
11778  , p_source_15            IN VARCHAR2
11779 --Receipt Applied To Application Identifier
11780  , p_source_17            IN NUMBER
11781 --Transaction Distribution Type
11782  , p_source_18            IN VARCHAR2
11783 --Transaction Entity Code
11784  , p_source_19            IN VARCHAR2
11785 --Transaction Distribution Identifier
11789 --DIST_ENT_AMT_FROM
11786  , p_source_20            IN NUMBER
11787 --Transaction Identifier
11788  , p_source_21            IN NUMBER
11790  , p_source_22            IN NUMBER
11791 --Applying Document Currency Code
11792  , p_source_23            IN VARCHAR2
11793 --Exchange Date
11794  , p_source_24            IN DATE
11795 --Accounting Amount
11796  , p_source_25            IN NUMBER
11797 --Distribution Party Identifier
11798  , p_source_26            IN NUMBER
11799 --Distribution Party Site Id
11800  , p_source_27            IN NUMBER
11801 --Distribution Party Type
11802  , p_source_28            IN VARCHAR2
11803 )
11804 IS
11805 
11806 l_component_type              VARCHAR2(80);
11807 l_component_code              VARCHAR2(30);
11808 l_component_type_code         VARCHAR2(1);
11809 l_component_appl_id           INTEGER;
11810 l_amb_context_code            VARCHAR2(30);
11811 l_entity_code                 VARCHAR2(30);
11812 l_event_class_code            VARCHAR2(30);
11813 l_ae_header_id                NUMBER;
11814 l_event_type_code             VARCHAR2(30);
11815 l_line_definition_code        VARCHAR2(30);
11816 l_line_definition_owner_code  VARCHAR2(1);
11817 --
11818 -- adr variables
11819 l_segment                     VARCHAR2(30);
11820 l_ccid                        NUMBER;
11821 l_adr_transaction_coa_id      NUMBER;
11822 l_adr_accounting_coa_id       NUMBER;
11823 l_adr_flexfield_segment_code  VARCHAR2(30);
11824 l_adr_flex_value_set_id       NUMBER;
11825 l_adr_value_type_code         VARCHAR2(30);
11826 l_adr_value_combination_id    NUMBER;
11827 l_adr_value_segment_code      VARCHAR2(30);
11828 
11829 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
11830 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
11831 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
11832 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
11833 
11834 -- 4262811 Variables ------------------------------------------------------------------------------------------
11835 l_entered_amt_idx             NUMBER;
11836 l_accted_amt_idx              NUMBER;
11837 l_acc_rev_flag                VARCHAR2(1);
11838 l_accrual_line_num            NUMBER;
11839 l_tmp_amt                     NUMBER;
11840 l_acc_rev_natural_side_code   VARCHAR2(1);
11841 
11842 l_num_entries                 NUMBER;
11843 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
11844 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
11845 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
11846 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
11847 l_recog_line_1                NUMBER;
11848 l_recog_line_2                NUMBER;
11849 
11850 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
11851 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
11852 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
11853 
11854 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
11855 
11856 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
11857 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
11858 
11859 ---------------------------------------------------------------------------------------------------------------
11860 
11861 
11862 --
11863 -- bulk performance
11864 --
11865 l_balance_type_code           VARCHAR2(1);
11866 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
11867 l_log_module                  VARCHAR2(240);
11868 
11869 --
11870 -- Upgrade strategy
11871 --
11872 l_actual_upg_option           VARCHAR2(1);
11873 l_enc_upg_option           VARCHAR2(1);
11874 
11875 --
11876 BEGIN
11877 --
11878 IF g_log_enabled THEN
11879       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_25';
11880 END IF;
11881 --
11882 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11883 
11884       trace
11885          (p_msg      => 'BEGIN of AcctLineType_25'
11886          ,p_level    => C_LEVEL_PROCEDURE
11887          ,p_module   => l_log_module);
11888 
11889 END IF;
11890 --
11891 l_component_type             := 'AMB_JLT';
11892 l_component_code             := 'RCT_CONFIRM';
11893 l_component_type_code        := 'S';
11894 l_component_appl_id          :=  222;
11895 l_amb_context_code           := 'DEFAULT';
11896 l_entity_code                := 'RECEIPTS';
11897 l_event_class_code           := 'RECEIPT';
11898 l_event_type_code            := 'RECEIPT_ALL';
11899 l_line_definition_owner_code := 'S';
11900 l_line_definition_code       := 'RCT_CASH_JLD';
11901 --
11902 l_balance_type_code          := 'A';
11903 l_segment                     := NULL;
11904 l_ccid                        := NULL;
11905 l_adr_transaction_coa_id      := NULL;
11906 l_adr_accounting_coa_id       := NULL;
11907 l_adr_flexfield_segment_code  := NULL;
11908 l_adr_flex_value_set_id       := NULL;
11909 l_adr_value_type_code         := NULL;
11910 l_adr_value_combination_id    := NULL;
11911 l_adr_value_segment_code      := NULL;
11912 
11913 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
11914 l_bflow_class_code           := '';    -- 4219869 Business Flow
11915 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
11919 l_bflow_applied_to_amt       := NULL; -- 5132302
11916 l_budgetary_control_flag     := 'N';
11917 
11918 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
11920 l_entered_amt_idx            := NULL;          -- 4262811
11921 l_accted_amt_idx             := NULL;          -- 4262811
11922 l_acc_rev_flag               := NULL;          -- 4262811
11923 l_accrual_line_num           := NULL;          -- 4262811
11924 l_tmp_amt                    := NULL;          -- 4262811
11925 --
11926  
11927 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
11928     l_balance_type_code <> 'B' THEN
11929 IF NVL(p_source_7,'
11930 ') =  'CONFIRMATION' AND 
11931 NVL(p_source_8,'
11932 ') =  'N'
11933  THEN 
11934 
11935    --
11936    XLA_AE_LINES_PKG.SetNewLine;
11937 
11938    p_balance_type_code          := l_balance_type_code;
11939    -- set the flag so later we will know whether the gain loss line needs to be created
11940    
11941    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
11942      p_actual_flag :='A';
11943    END IF;
11944 
11945    --
11946    -- bulk performance
11947    --
11948    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
11949                                       p_header_num   => 0); -- 4262811
11950    --
11951    -- set accounting line options
11952    --
11953    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
11954            p_natural_side_code          => 'C'
11955          , p_gain_or_loss_flag          => 'N'
11956          , p_gl_transfer_mode_code      => 'S'
11957          , p_acct_entry_type_code       => 'A'
11958          , p_switch_side_flag           => 'Y'
11959          , p_merge_duplicate_code       => 'A'
11960          );
11961    --
11962    l_acc_rev_natural_side_code := 'D';  -- 4262811
11963    -- 
11964    --
11965    -- set accounting line type info
11966    --
11967    xla_ae_lines_pkg.SetAcctLineType
11968       (p_component_type             => l_component_type
11969       ,p_event_type_code            => l_event_type_code
11970       ,p_line_definition_owner_code => l_line_definition_owner_code
11971       ,p_line_definition_code       => l_line_definition_code
11972       ,p_accounting_line_code       => l_component_code
11973       ,p_accounting_line_type_code  => l_component_type_code
11974       ,p_accounting_line_appl_id    => l_component_appl_id
11975       ,p_amb_context_code           => l_amb_context_code
11976       ,p_entity_code                => l_entity_code
11977       ,p_event_class_code           => l_event_class_code);
11978    --
11979    -- set accounting class
11980    --
11981    xla_ae_lines_pkg.SetAcctClass(
11982            p_accounting_class_code  => 'CONFIRMATION'
11983          , p_ae_header_id           => l_ae_header_id
11984          );
11985 
11986    --
11987    -- set rounding class
11988    --
11989    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
11990                       'RECEIVABLE';
11991 
11992    --
11993    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
11994    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
11995    --
11996    -- bulk performance
11997    --
11998    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
11999 
12000    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
12001       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
12002 
12003    -- 4955764
12004    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
12005       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
12006 
12007    -- 4458381 Public Sector Enh
12008    
12009    --
12010    -- set accounting attributes for the line type
12011    --
12012    l_entered_amt_idx := 8;
12013    l_accted_amt_idx  := 13;
12014    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
12015    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
12016    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
12017    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
12018    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
12019    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
12020    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
12021    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
12022    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
12023    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
12024    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
12025    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
12026    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
12027    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
12028    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
12029    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
12030    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
12031    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
12032    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
12033    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
12037    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
12034    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
12035    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
12036    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
12038    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
12039    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
12040    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
12041    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
12042    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
12043    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
12044    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
12045    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
12046    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
12047 
12048    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
12049    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
12050 
12051    ---------------------------------------------------------------------------------------------------------------
12052    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
12053    ---------------------------------------------------------------------------------------------------------------
12054    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
12055 
12056    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
12057    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
12058 
12059    IF xla_accounting_cache_pkg.GetValueChar
12060          (p_source_code         => 'LEDGER_CATEGORY_CODE'
12061          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
12062    AND l_bflow_method_code = 'PRIOR_ENTRY'
12063 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
12064    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
12065          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
12066        )
12067    THEN
12068          xla_ae_lines_pkg.BflowUpgEntry
12069            (p_business_method_code    => l_bflow_method_code
12070            ,p_business_class_code     => l_bflow_class_code
12071            ,p_balance_type            => l_balance_type_code);
12072    ELSE
12073       NULL;
12074 -- No business flow processing for business flow method of NONE.
12075    END IF;
12076 
12077    --
12078    -- call analytical criteria
12079    --
12080    
12081    --
12082    -- call description
12083    --
12084    -- No description or it is inherited.
12085    --
12086    -- call ADRs
12087    -- Bug 4922099
12088    --
12089    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
12090         (NVL(l_actual_upg_option, 'N') = 'O') OR
12091         (NVL(l_enc_upg_option, 'N') = 'O')
12092       )
12093    THEN
12094    NULL;
12095    --
12096    --
12097    
12098   l_ccid := AcctDerRule_1(
12099            p_application_id           => p_application_id
12100          , p_ae_header_id             => l_ae_header_id 
12101 , p_source_1 => p_source_1
12102          , x_transaction_coa_id       => l_adr_transaction_coa_id
12103          , x_accounting_coa_id        => l_adr_accounting_coa_id
12104          , x_value_type_code          => l_adr_value_type_code
12105          , p_side                     => 'NA'
12106    );
12107 
12108    xla_ae_lines_pkg.set_ccid(
12109     p_code_combination_id          => l_ccid
12110   , p_value_type_code              => l_adr_value_type_code
12111   , p_transaction_coa_id           => l_adr_transaction_coa_id
12112   , p_accounting_coa_id            => l_adr_accounting_coa_id
12113   , p_adr_code                     => 'DIST_CCID'
12114   , p_adr_type_code                => 'S'
12115   , p_component_type               => l_component_type
12116   , p_component_code               => l_component_code
12117   , p_component_type_code          => l_component_type_code
12118   , p_component_appl_id            => l_component_appl_id
12119   , p_amb_context_code             => l_amb_context_code
12120   , p_side                         => 'NA'
12121   );
12122 
12123 
12124    --
12125    --
12126    END IF;
12127    --
12128    -- Bug 4922099
12129    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
12130           (NVL(l_enc_upg_option, 'N') = 'O')
12131         ) AND
12132         (l_bflow_method_code = 'PRIOR_ENTRY')
12133       )
12134    THEN
12135       IF
12136       --
12137       1 = 2
12138       --
12139       THEN
12140       xla_accounting_err_pkg.build_message
12141                                     (p_appli_s_name            => 'XLA'
12142                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
12143                                     ,p_token_1                 => 'LINE_NUMBER'
12144                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
12145                                     ,p_token_2                 => 'LINE_TYPE_NAME'
12146                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
12147                                                                              l_component_type
12148                                                                             ,l_component_code
12152                                                                             ,l_entity_code
12149                                                                             ,l_component_type_code
12150                                                                             ,l_component_appl_id
12151                                                                             ,l_amb_context_code
12153                                                                             ,l_event_class_code
12154                                                                            )
12155                                     ,p_token_3                 => 'OWNER'
12156                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
12157                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
12158                                                                           ,p_lookup_code    => l_component_type_code
12159                                                                          )
12160                                     ,p_token_4                 => 'PRODUCT_NAME'
12161                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
12162                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
12163                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
12164                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
12165                                     ,p_ae_header_id            =>  NULL
12166                                        );
12167 
12168         IF (C_LEVEL_ERROR>= g_log_level) THEN
12169                  trace
12170                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
12171                       ,p_level    => C_LEVEL_ERROR
12172                       ,p_module   => l_log_module);
12173         END IF;
12174       END IF;
12175    END IF;
12176    --
12177    --
12178    ------------------------------------------------------------------------------------------------
12179    -- 4219869 Business Flow
12180    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
12181    -- Prior Entry.  Currently, the following code is always generated.
12182    ------------------------------------------------------------------------------------------------
12183    XLA_AE_LINES_PKG.ValidateCurrentLine;
12184 
12185    ------------------------------------------------------------------------------------
12186    -- 4219869 Business Flow
12187    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
12188    ------------------------------------------------------------------------------------
12189    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
12190 
12191    ----------------------------------------------------------------------------------
12192    -- 4219869 Business Flow
12193    -- Update journal entry status -- Need to generate this within IF <condition>
12194    ----------------------------------------------------------------------------------
12195    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
12196          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
12197          ,p_balance_type_code => l_balance_type_code
12198          );
12199 
12200    -------------------------------------------------------------------------------------------
12201    -- 4262811 - Generate the Accrual Reversal lines
12202    -------------------------------------------------------------------------------------------
12203    BEGIN
12204       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
12205                               (g_array_event(p_event_id).array_value_num('header_index'));
12206       IF l_acc_rev_flag IS NULL THEN
12207          l_acc_rev_flag := 'N';
12208       END IF;
12209    EXCEPTION
12210       WHEN OTHERS THEN
12211          l_acc_rev_flag := 'N';
12212    END;
12213    --
12214    IF (l_acc_rev_flag = 'Y') THEN
12215 
12216        -- 4645092  ------------------------------------------------------------------------------
12217        -- To allow MPA report to determine if it should generate report process
12218        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
12219        ------------------------------------------------------------------------------------------
12220 
12221        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
12222        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
12223    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
12224    -- call ADRs
12225    -- Bug 4922099
12226    --
12227    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
12228         (NVL(l_actual_upg_option, 'N') = 'O') OR
12229         (NVL(l_enc_upg_option, 'N') = 'O')
12230       )
12231    THEN
12232    NULL;
12233    --
12234    --
12235    
12236   l_ccid := AcctDerRule_1(
12237            p_application_id           => p_application_id
12238          , p_ae_header_id             => l_ae_header_id 
12239 , p_source_1 => p_source_1
12240          , x_transaction_coa_id       => l_adr_transaction_coa_id
12241          , x_accounting_coa_id        => l_adr_accounting_coa_id
12242          , x_value_type_code          => l_adr_value_type_code
12243          , p_side                     => 'NA'
12244    );
12245 
12246    xla_ae_lines_pkg.set_ccid(
12247     p_code_combination_id          => l_ccid
12248   , p_value_type_code              => l_adr_value_type_code
12252   , p_adr_type_code                => 'S'
12249   , p_transaction_coa_id           => l_adr_transaction_coa_id
12250   , p_accounting_coa_id            => l_adr_accounting_coa_id
12251   , p_adr_code                     => 'DIST_CCID'
12253   , p_component_type               => l_component_type
12254   , p_component_code               => l_component_code
12255   , p_component_type_code          => l_component_type_code
12256   , p_component_appl_id            => l_component_appl_id
12257   , p_amb_context_code             => l_amb_context_code
12258   , p_side                         => 'NA'
12259   );
12260 
12261 
12262    --
12263    --
12264    END IF;
12265 
12266        --
12267        -- Update the line information that should be overwritten
12268        --
12269        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
12270                                          p_header_num   => 1);
12271        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
12272 
12273        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
12274 
12275        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
12276           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
12277        END IF;
12278 
12279       --
12280       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
12281       --
12282       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
12283           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
12284       ELSE
12285           ---------------------------------------------------------------------------------------------------
12286           -- 4262811a Switch Sign
12287           ---------------------------------------------------------------------------------------------------
12288           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
12289           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
12290                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12291           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
12292                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12293           -- 5132302
12294           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
12295                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12296 
12297       END IF;
12298 
12299       -- 4955764
12300       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
12301       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
12302 
12303 
12304       XLA_AE_LINES_PKG.ValidateCurrentLine;
12305       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
12306 
12307       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
12308                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
12309                ,p_balance_type_code => l_balance_type_code);
12310 
12311    END IF;
12312 
12313    -----------------------------------------------------------------------------------------
12314    -- 4262811 Multiperiod Accounting
12315    -----------------------------------------------------------------------------------------
12316      -- No MPA option is assigned.
12317 
12318 
12319 END IF;
12320 END IF;
12321 --
12322 
12323 --
12324 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12325    trace
12326       (p_msg      => 'END of AcctLineType_25'
12327       ,p_level    => C_LEVEL_PROCEDURE
12328       ,p_module   => l_log_module);
12329 END IF;
12330 --
12331 EXCEPTION
12332   WHEN xla_exceptions_pkg.application_exception THEN
12333       RAISE;
12334   WHEN OTHERS THEN
12335        xla_exceptions_pkg.raise_message
12336            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_25');
12337 END AcctLineType_25;
12338 --
12339 
12340 ---------------------------------------
12341 --
12342 -- PRIVATE FUNCTION
12343 --         AcctLineType_26
12344 --
12345 ---------------------------------------
12346 PROCEDURE AcctLineType_26 (
12347   p_application_id        IN NUMBER
12348  ,p_event_id              IN NUMBER
12349  ,p_calculate_acctd_flag  IN VARCHAR2
12350  ,p_calculate_g_l_flag    IN VARCHAR2
12351  ,p_actual_flag           IN OUT VARCHAR2
12352  ,p_balance_type_code     OUT VARCHAR2
12353  ,p_gain_or_loss_ref      OUT VARCHAR2
12354  
12355 --Distribution GL Account
12356  , p_source_1            IN NUMBER
12357 --Distribution Source Type
12358  , p_source_7            IN VARCHAR2
12359 --Distribution Multi Fund Additional Entry
12360  , p_source_8            IN VARCHAR2
12361 --Distribution Line Identifier
12362  , p_source_9            IN NUMBER
12363 --Distribution Type
12364  , p_source_10            IN VARCHAR2
12365 --Exchange Rate
12366  , p_source_14            IN NUMBER
12367 --Exchange Rate Type
12368  , p_source_15            IN VARCHAR2
12369 --Receipt Applied To Application Identifier
12370  , p_source_17            IN NUMBER
12371 --Transaction Distribution Type
12372  , p_source_18            IN VARCHAR2
12373 --Transaction Entity Code
12377 --Transaction Identifier
12374  , p_source_19            IN VARCHAR2
12375 --Transaction Distribution Identifier
12376  , p_source_20            IN NUMBER
12378  , p_source_21            IN NUMBER
12379 --DIST_ENT_AMT_FROM
12380  , p_source_22            IN NUMBER
12381 --Applying Document Currency Code
12382  , p_source_23            IN VARCHAR2
12383 --Exchange Date
12384  , p_source_24            IN DATE
12385 --Accounting Amount
12386  , p_source_25            IN NUMBER
12387 --Distribution Party Identifier
12388  , p_source_26            IN NUMBER
12389 --Distribution Party Site Id
12390  , p_source_27            IN NUMBER
12391 --Distribution Party Type
12392  , p_source_28            IN VARCHAR2
12393 )
12394 IS
12395 
12396 l_component_type              VARCHAR2(80);
12397 l_component_code              VARCHAR2(30);
12398 l_component_type_code         VARCHAR2(1);
12399 l_component_appl_id           INTEGER;
12400 l_amb_context_code            VARCHAR2(30);
12401 l_entity_code                 VARCHAR2(30);
12402 l_event_class_code            VARCHAR2(30);
12403 l_ae_header_id                NUMBER;
12404 l_event_type_code             VARCHAR2(30);
12405 l_line_definition_code        VARCHAR2(30);
12406 l_line_definition_owner_code  VARCHAR2(1);
12407 --
12408 -- adr variables
12409 l_segment                     VARCHAR2(30);
12410 l_ccid                        NUMBER;
12411 l_adr_transaction_coa_id      NUMBER;
12412 l_adr_accounting_coa_id       NUMBER;
12413 l_adr_flexfield_segment_code  VARCHAR2(30);
12414 l_adr_flex_value_set_id       NUMBER;
12415 l_adr_value_type_code         VARCHAR2(30);
12416 l_adr_value_combination_id    NUMBER;
12417 l_adr_value_segment_code      VARCHAR2(30);
12418 
12419 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
12420 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
12421 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
12422 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
12423 
12424 -- 4262811 Variables ------------------------------------------------------------------------------------------
12425 l_entered_amt_idx             NUMBER;
12426 l_accted_amt_idx              NUMBER;
12427 l_acc_rev_flag                VARCHAR2(1);
12428 l_accrual_line_num            NUMBER;
12429 l_tmp_amt                     NUMBER;
12430 l_acc_rev_natural_side_code   VARCHAR2(1);
12431 
12432 l_num_entries                 NUMBER;
12433 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
12434 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
12435 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
12436 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
12437 l_recog_line_1                NUMBER;
12438 l_recog_line_2                NUMBER;
12439 
12440 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
12441 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
12442 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
12443 
12444 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
12445 
12446 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
12447 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
12448 
12449 ---------------------------------------------------------------------------------------------------------------
12450 
12451 
12452 --
12453 -- bulk performance
12454 --
12455 l_balance_type_code           VARCHAR2(1);
12456 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
12457 l_log_module                  VARCHAR2(240);
12458 
12459 --
12460 -- Upgrade strategy
12461 --
12462 l_actual_upg_option           VARCHAR2(1);
12463 l_enc_upg_option           VARCHAR2(1);
12464 
12465 --
12466 BEGIN
12467 --
12468 IF g_log_enabled THEN
12469       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_26';
12470 END IF;
12471 --
12472 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12473 
12474       trace
12475          (p_msg      => 'BEGIN of AcctLineType_26'
12476          ,p_level    => C_LEVEL_PROCEDURE
12477          ,p_module   => l_log_module);
12478 
12479 END IF;
12480 --
12481 l_component_type             := 'AMB_JLT';
12482 l_component_code             := 'RCT_CURR_ROUND';
12483 l_component_type_code        := 'S';
12484 l_component_appl_id          :=  222;
12485 l_amb_context_code           := 'DEFAULT';
12486 l_entity_code                := 'RECEIPTS';
12487 l_event_class_code           := 'RECEIPT';
12488 l_event_type_code            := 'RECEIPT_ALL';
12489 l_line_definition_owner_code := 'S';
12490 l_line_definition_code       := 'RCT_CASH_JLD';
12491 --
12492 l_balance_type_code          := 'A';
12493 l_segment                     := NULL;
12494 l_ccid                        := NULL;
12495 l_adr_transaction_coa_id      := NULL;
12496 l_adr_accounting_coa_id       := NULL;
12497 l_adr_flexfield_segment_code  := NULL;
12498 l_adr_flex_value_set_id       := NULL;
12499 l_adr_value_type_code         := NULL;
12500 l_adr_value_combination_id    := NULL;
12501 l_adr_value_segment_code      := NULL;
12502 
12503 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
12504 l_bflow_class_code           := '';    -- 4219869 Business Flow
12508 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
12505 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
12506 l_budgetary_control_flag     := 'N';
12507 
12509 l_bflow_applied_to_amt       := NULL; -- 5132302
12510 l_entered_amt_idx            := NULL;          -- 4262811
12511 l_accted_amt_idx             := NULL;          -- 4262811
12512 l_acc_rev_flag               := NULL;          -- 4262811
12513 l_accrual_line_num           := NULL;          -- 4262811
12514 l_tmp_amt                    := NULL;          -- 4262811
12515 --
12516  
12517 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
12518     l_balance_type_code <> 'B' THEN
12519 IF NVL(p_source_7,'
12520 ') =  'CURR_ROUND' AND 
12521 NVL(p_source_8,'
12522 ') =  'N'
12523  THEN 
12524 
12525    --
12526    XLA_AE_LINES_PKG.SetNewLine;
12527 
12528    p_balance_type_code          := l_balance_type_code;
12529    -- set the flag so later we will know whether the gain loss line needs to be created
12530    
12531    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
12532      p_actual_flag :='A';
12533    END IF;
12534 
12535    --
12536    -- bulk performance
12537    --
12538    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
12539                                       p_header_num   => 0); -- 4262811
12540    --
12541    -- set accounting line options
12542    --
12543    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
12544            p_natural_side_code          => 'C'
12545          , p_gain_or_loss_flag          => 'N'
12546          , p_gl_transfer_mode_code      => 'S'
12547          , p_acct_entry_type_code       => 'A'
12548          , p_switch_side_flag           => 'Y'
12549          , p_merge_duplicate_code       => 'A'
12550          );
12551    --
12552    l_acc_rev_natural_side_code := 'D';  -- 4262811
12553    -- 
12554    --
12555    -- set accounting line type info
12556    --
12557    xla_ae_lines_pkg.SetAcctLineType
12558       (p_component_type             => l_component_type
12559       ,p_event_type_code            => l_event_type_code
12560       ,p_line_definition_owner_code => l_line_definition_owner_code
12561       ,p_line_definition_code       => l_line_definition_code
12562       ,p_accounting_line_code       => l_component_code
12563       ,p_accounting_line_type_code  => l_component_type_code
12564       ,p_accounting_line_appl_id    => l_component_appl_id
12565       ,p_amb_context_code           => l_amb_context_code
12566       ,p_entity_code                => l_entity_code
12567       ,p_event_class_code           => l_event_class_code);
12568    --
12569    -- set accounting class
12570    --
12571    xla_ae_lines_pkg.SetAcctClass(
12572            p_accounting_class_code  => 'ROUNDING'
12573          , p_ae_header_id           => l_ae_header_id
12574          );
12575 
12576    --
12577    -- set rounding class
12578    --
12579    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
12580                       'RECEIVABLE';
12581 
12582    --
12583    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
12584    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
12585    --
12586    -- bulk performance
12587    --
12588    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
12589 
12590    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
12591       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
12592 
12593    -- 4955764
12594    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
12595       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
12596 
12597    -- 4458381 Public Sector Enh
12598    
12599    --
12600    -- set accounting attributes for the line type
12601    --
12602    l_entered_amt_idx := 8;
12603    l_accted_amt_idx  := 13;
12604    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
12605    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
12606    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
12607    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
12608    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
12609    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
12610    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
12611    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
12612    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
12613    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
12614    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
12615    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
12616    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
12617    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
12618    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
12619    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
12620    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
12621    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
12622    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
12626    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
12623    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
12624    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
12625    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
12627    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
12628    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
12629    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
12630    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
12631    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
12632    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
12633    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
12634    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
12635    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
12636    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
12637 
12638    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
12639    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
12640 
12641    ---------------------------------------------------------------------------------------------------------------
12642    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
12643    ---------------------------------------------------------------------------------------------------------------
12644    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
12645 
12646    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
12647    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
12648 
12649    IF xla_accounting_cache_pkg.GetValueChar
12650          (p_source_code         => 'LEDGER_CATEGORY_CODE'
12651          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
12652    AND l_bflow_method_code = 'PRIOR_ENTRY'
12653 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
12654    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
12655          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
12656        )
12657    THEN
12658          xla_ae_lines_pkg.BflowUpgEntry
12659            (p_business_method_code    => l_bflow_method_code
12660            ,p_business_class_code     => l_bflow_class_code
12661            ,p_balance_type            => l_balance_type_code);
12662    ELSE
12663       NULL;
12664 -- No business flow processing for business flow method of NONE.
12665    END IF;
12666 
12667    --
12668    -- call analytical criteria
12669    --
12670    
12671    --
12672    -- call description
12673    --
12674    -- No description or it is inherited.
12675    --
12676    -- call ADRs
12677    -- Bug 4922099
12678    --
12679    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
12680         (NVL(l_actual_upg_option, 'N') = 'O') OR
12681         (NVL(l_enc_upg_option, 'N') = 'O')
12682       )
12683    THEN
12684    NULL;
12685    --
12686    --
12687    
12688   l_ccid := AcctDerRule_1(
12689            p_application_id           => p_application_id
12690          , p_ae_header_id             => l_ae_header_id 
12691 , p_source_1 => p_source_1
12692          , x_transaction_coa_id       => l_adr_transaction_coa_id
12693          , x_accounting_coa_id        => l_adr_accounting_coa_id
12694          , x_value_type_code          => l_adr_value_type_code
12695          , p_side                     => 'NA'
12696    );
12697 
12698    xla_ae_lines_pkg.set_ccid(
12699     p_code_combination_id          => l_ccid
12700   , p_value_type_code              => l_adr_value_type_code
12701   , p_transaction_coa_id           => l_adr_transaction_coa_id
12702   , p_accounting_coa_id            => l_adr_accounting_coa_id
12703   , p_adr_code                     => 'DIST_CCID'
12704   , p_adr_type_code                => 'S'
12705   , p_component_type               => l_component_type
12706   , p_component_code               => l_component_code
12707   , p_component_type_code          => l_component_type_code
12708   , p_component_appl_id            => l_component_appl_id
12709   , p_amb_context_code             => l_amb_context_code
12710   , p_side                         => 'NA'
12711   );
12712 
12713 
12714    --
12715    --
12716    END IF;
12717    --
12718    -- Bug 4922099
12719    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
12720           (NVL(l_enc_upg_option, 'N') = 'O')
12721         ) AND
12722         (l_bflow_method_code = 'PRIOR_ENTRY')
12723       )
12724    THEN
12725       IF
12726       --
12727       1 = 2
12728       --
12729       THEN
12730       xla_accounting_err_pkg.build_message
12731                                     (p_appli_s_name            => 'XLA'
12732                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
12733                                     ,p_token_1                 => 'LINE_NUMBER'
12734                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
12735                                     ,p_token_2                 => 'LINE_TYPE_NAME'
12736                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
12737                                                                              l_component_type
12738                                                                             ,l_component_code
12742                                                                             ,l_entity_code
12739                                                                             ,l_component_type_code
12740                                                                             ,l_component_appl_id
12741                                                                             ,l_amb_context_code
12743                                                                             ,l_event_class_code
12744                                                                            )
12745                                     ,p_token_3                 => 'OWNER'
12746                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
12747                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
12748                                                                           ,p_lookup_code    => l_component_type_code
12749                                                                          )
12750                                     ,p_token_4                 => 'PRODUCT_NAME'
12751                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
12752                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
12753                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
12754                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
12755                                     ,p_ae_header_id            =>  NULL
12756                                        );
12757 
12758         IF (C_LEVEL_ERROR>= g_log_level) THEN
12759                  trace
12760                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
12761                       ,p_level    => C_LEVEL_ERROR
12762                       ,p_module   => l_log_module);
12763         END IF;
12764       END IF;
12765    END IF;
12766    --
12767    --
12768    ------------------------------------------------------------------------------------------------
12769    -- 4219869 Business Flow
12770    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
12771    -- Prior Entry.  Currently, the following code is always generated.
12772    ------------------------------------------------------------------------------------------------
12773    XLA_AE_LINES_PKG.ValidateCurrentLine;
12774 
12775    ------------------------------------------------------------------------------------
12776    -- 4219869 Business Flow
12777    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
12778    ------------------------------------------------------------------------------------
12779    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
12780 
12781    ----------------------------------------------------------------------------------
12782    -- 4219869 Business Flow
12783    -- Update journal entry status -- Need to generate this within IF <condition>
12784    ----------------------------------------------------------------------------------
12785    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
12786          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
12787          ,p_balance_type_code => l_balance_type_code
12788          );
12789 
12790    -------------------------------------------------------------------------------------------
12791    -- 4262811 - Generate the Accrual Reversal lines
12792    -------------------------------------------------------------------------------------------
12793    BEGIN
12794       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
12795                               (g_array_event(p_event_id).array_value_num('header_index'));
12796       IF l_acc_rev_flag IS NULL THEN
12797          l_acc_rev_flag := 'N';
12798       END IF;
12799    EXCEPTION
12800       WHEN OTHERS THEN
12801          l_acc_rev_flag := 'N';
12802    END;
12803    --
12804    IF (l_acc_rev_flag = 'Y') THEN
12805 
12806        -- 4645092  ------------------------------------------------------------------------------
12807        -- To allow MPA report to determine if it should generate report process
12808        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
12809        ------------------------------------------------------------------------------------------
12810 
12811        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
12812        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
12813    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
12814    -- call ADRs
12815    -- Bug 4922099
12816    --
12817    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
12818         (NVL(l_actual_upg_option, 'N') = 'O') OR
12819         (NVL(l_enc_upg_option, 'N') = 'O')
12820       )
12821    THEN
12822    NULL;
12823    --
12824    --
12825    
12826   l_ccid := AcctDerRule_1(
12827            p_application_id           => p_application_id
12828          , p_ae_header_id             => l_ae_header_id 
12829 , p_source_1 => p_source_1
12830          , x_transaction_coa_id       => l_adr_transaction_coa_id
12831          , x_accounting_coa_id        => l_adr_accounting_coa_id
12832          , x_value_type_code          => l_adr_value_type_code
12833          , p_side                     => 'NA'
12834    );
12835 
12836    xla_ae_lines_pkg.set_ccid(
12837     p_code_combination_id          => l_ccid
12841   , p_adr_code                     => 'DIST_CCID'
12838   , p_value_type_code              => l_adr_value_type_code
12839   , p_transaction_coa_id           => l_adr_transaction_coa_id
12840   , p_accounting_coa_id            => l_adr_accounting_coa_id
12842   , p_adr_type_code                => 'S'
12843   , p_component_type               => l_component_type
12844   , p_component_code               => l_component_code
12845   , p_component_type_code          => l_component_type_code
12846   , p_component_appl_id            => l_component_appl_id
12847   , p_amb_context_code             => l_amb_context_code
12848   , p_side                         => 'NA'
12849   );
12850 
12851 
12852    --
12853    --
12854    END IF;
12855 
12856        --
12857        -- Update the line information that should be overwritten
12858        --
12859        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
12860                                          p_header_num   => 1);
12861        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
12862 
12863        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
12864 
12865        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
12866           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
12867        END IF;
12868 
12869       --
12870       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
12871       --
12872       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
12873           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
12874       ELSE
12875           ---------------------------------------------------------------------------------------------------
12876           -- 4262811a Switch Sign
12877           ---------------------------------------------------------------------------------------------------
12878           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
12879           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
12880                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12881           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
12882                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12883           -- 5132302
12884           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
12885                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
12886 
12887       END IF;
12888 
12889       -- 4955764
12890       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
12891       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
12892 
12893 
12894       XLA_AE_LINES_PKG.ValidateCurrentLine;
12895       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
12896 
12897       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
12898                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
12899                ,p_balance_type_code => l_balance_type_code);
12900 
12901    END IF;
12902 
12903    -----------------------------------------------------------------------------------------
12904    -- 4262811 Multiperiod Accounting
12905    -----------------------------------------------------------------------------------------
12906      -- No MPA option is assigned.
12907 
12908 
12909 END IF;
12910 END IF;
12911 --
12912 
12913 --
12914 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12915    trace
12916       (p_msg      => 'END of AcctLineType_26'
12917       ,p_level    => C_LEVEL_PROCEDURE
12918       ,p_module   => l_log_module);
12919 END IF;
12920 --
12921 EXCEPTION
12922   WHEN xla_exceptions_pkg.application_exception THEN
12923       RAISE;
12924   WHEN OTHERS THEN
12925        xla_exceptions_pkg.raise_message
12926            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_26');
12927 END AcctLineType_26;
12928 --
12929 
12930 ---------------------------------------
12931 --
12932 -- PRIVATE FUNCTION
12933 --         AcctLineType_27
12934 --
12935 ---------------------------------------
12936 PROCEDURE AcctLineType_27 (
12937   p_application_id        IN NUMBER
12938  ,p_event_id              IN NUMBER
12939  ,p_calculate_acctd_flag  IN VARCHAR2
12940  ,p_calculate_g_l_flag    IN VARCHAR2
12941  ,p_actual_flag           IN OUT VARCHAR2
12942  ,p_balance_type_code     OUT VARCHAR2
12943  ,p_gain_or_loss_ref      OUT VARCHAR2
12944  
12945 --Distribution GL Account
12946  , p_source_1            IN NUMBER
12947 --Distribution Source Type
12948  , p_source_7            IN VARCHAR2
12949 --Distribution Multi Fund Additional Entry
12950  , p_source_8            IN VARCHAR2
12951 --Distribution Line Identifier
12952  , p_source_9            IN NUMBER
12953 --Distribution Type
12954  , p_source_10            IN VARCHAR2
12955 --Exchange Rate
12956  , p_source_14            IN NUMBER
12957 --Exchange Rate Type
12958  , p_source_15            IN VARCHAR2
12959 --Receipt Applied To Application Identifier
12960  , p_source_17            IN NUMBER
12964  , p_source_19            IN VARCHAR2
12961 --Transaction Distribution Type
12962  , p_source_18            IN VARCHAR2
12963 --Transaction Entity Code
12965 --Transaction Distribution Identifier
12966  , p_source_20            IN NUMBER
12967 --Transaction Identifier
12968  , p_source_21            IN NUMBER
12969 --DIST_ENT_AMT_FROM
12970  , p_source_22            IN NUMBER
12971 --Applying Document Currency Code
12972  , p_source_23            IN VARCHAR2
12973 --Exchange Date
12974  , p_source_24            IN DATE
12975 --Accounting Amount
12976  , p_source_25            IN NUMBER
12977 --Distribution Party Identifier
12978  , p_source_26            IN NUMBER
12979 --Distribution Party Site Id
12980  , p_source_27            IN NUMBER
12981 --Distribution Party Type
12982  , p_source_28            IN VARCHAR2
12983 )
12984 IS
12985 
12986 l_component_type              VARCHAR2(80);
12987 l_component_code              VARCHAR2(30);
12988 l_component_type_code         VARCHAR2(1);
12989 l_component_appl_id           INTEGER;
12990 l_amb_context_code            VARCHAR2(30);
12991 l_entity_code                 VARCHAR2(30);
12992 l_event_class_code            VARCHAR2(30);
12993 l_ae_header_id                NUMBER;
12994 l_event_type_code             VARCHAR2(30);
12995 l_line_definition_code        VARCHAR2(30);
12996 l_line_definition_owner_code  VARCHAR2(1);
12997 --
12998 -- adr variables
12999 l_segment                     VARCHAR2(30);
13000 l_ccid                        NUMBER;
13001 l_adr_transaction_coa_id      NUMBER;
13002 l_adr_accounting_coa_id       NUMBER;
13003 l_adr_flexfield_segment_code  VARCHAR2(30);
13004 l_adr_flex_value_set_id       NUMBER;
13005 l_adr_value_type_code         VARCHAR2(30);
13006 l_adr_value_combination_id    NUMBER;
13007 l_adr_value_segment_code      VARCHAR2(30);
13008 
13009 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
13010 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
13011 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
13012 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
13013 
13014 -- 4262811 Variables ------------------------------------------------------------------------------------------
13015 l_entered_amt_idx             NUMBER;
13016 l_accted_amt_idx              NUMBER;
13017 l_acc_rev_flag                VARCHAR2(1);
13018 l_accrual_line_num            NUMBER;
13019 l_tmp_amt                     NUMBER;
13020 l_acc_rev_natural_side_code   VARCHAR2(1);
13021 
13022 l_num_entries                 NUMBER;
13023 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
13024 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
13025 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
13026 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
13027 l_recog_line_1                NUMBER;
13028 l_recog_line_2                NUMBER;
13029 
13030 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
13031 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
13032 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
13033 
13034 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
13035 
13036 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
13037 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
13038 
13039 ---------------------------------------------------------------------------------------------------------------
13040 
13041 
13042 --
13043 -- bulk performance
13044 --
13045 l_balance_type_code           VARCHAR2(1);
13046 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
13047 l_log_module                  VARCHAR2(240);
13048 
13049 --
13050 -- Upgrade strategy
13051 --
13052 l_actual_upg_option           VARCHAR2(1);
13053 l_enc_upg_option           VARCHAR2(1);
13054 
13055 --
13056 BEGIN
13057 --
13058 IF g_log_enabled THEN
13059       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_27';
13060 END IF;
13061 --
13062 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13063 
13064       trace
13065          (p_msg      => 'BEGIN of AcctLineType_27'
13066          ,p_level    => C_LEVEL_PROCEDURE
13067          ,p_module   => l_log_module);
13068 
13069 END IF;
13070 --
13071 l_component_type             := 'AMB_JLT';
13072 l_component_code             := 'RCT_DEBT';
13073 l_component_type_code        := 'S';
13074 l_component_appl_id          :=  222;
13075 l_amb_context_code           := 'DEFAULT';
13076 l_entity_code                := 'RECEIPTS';
13077 l_event_class_code           := 'RECEIPT';
13078 l_event_type_code            := 'RECEIPT_ALL';
13079 l_line_definition_owner_code := 'S';
13080 l_line_definition_code       := 'RCT_CASH_JLD';
13081 --
13082 l_balance_type_code          := 'A';
13083 l_segment                     := NULL;
13084 l_ccid                        := NULL;
13085 l_adr_transaction_coa_id      := NULL;
13086 l_adr_accounting_coa_id       := NULL;
13087 l_adr_flexfield_segment_code  := NULL;
13088 l_adr_flex_value_set_id       := NULL;
13089 l_adr_value_type_code         := NULL;
13090 l_adr_value_combination_id    := NULL;
13091 l_adr_value_segment_code      := NULL;
13092 
13096 l_budgetary_control_flag     := 'N';
13093 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
13094 l_bflow_class_code           := '';    -- 4219869 Business Flow
13095 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
13097 
13098 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
13099 l_bflow_applied_to_amt       := NULL; -- 5132302
13100 l_entered_amt_idx            := NULL;          -- 4262811
13101 l_accted_amt_idx             := NULL;          -- 4262811
13102 l_acc_rev_flag               := NULL;          -- 4262811
13103 l_accrual_line_num           := NULL;          -- 4262811
13104 l_tmp_amt                    := NULL;          -- 4262811
13105 --
13106  
13107 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
13108     l_balance_type_code <> 'B' THEN
13109 IF NVL(p_source_7,'
13110 ') =  'SHORT_TERM_DEBT' AND 
13111 NVL(p_source_8,'
13112 ') =  'N'
13113  THEN 
13114 
13115    --
13116    XLA_AE_LINES_PKG.SetNewLine;
13117 
13118    p_balance_type_code          := l_balance_type_code;
13119    -- set the flag so later we will know whether the gain loss line needs to be created
13120    
13121    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
13122      p_actual_flag :='A';
13123    END IF;
13124 
13125    --
13126    -- bulk performance
13127    --
13128    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
13129                                       p_header_num   => 0); -- 4262811
13130    --
13131    -- set accounting line options
13132    --
13133    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
13134            p_natural_side_code          => 'C'
13135          , p_gain_or_loss_flag          => 'N'
13136          , p_gl_transfer_mode_code      => 'S'
13137          , p_acct_entry_type_code       => 'A'
13138          , p_switch_side_flag           => 'Y'
13139          , p_merge_duplicate_code       => 'A'
13140          );
13141    --
13142    l_acc_rev_natural_side_code := 'D';  -- 4262811
13143    -- 
13144    --
13145    -- set accounting line type info
13146    --
13147    xla_ae_lines_pkg.SetAcctLineType
13148       (p_component_type             => l_component_type
13149       ,p_event_type_code            => l_event_type_code
13150       ,p_line_definition_owner_code => l_line_definition_owner_code
13151       ,p_line_definition_code       => l_line_definition_code
13152       ,p_accounting_line_code       => l_component_code
13153       ,p_accounting_line_type_code  => l_component_type_code
13154       ,p_accounting_line_appl_id    => l_component_appl_id
13155       ,p_amb_context_code           => l_amb_context_code
13156       ,p_entity_code                => l_entity_code
13157       ,p_event_class_code           => l_event_class_code);
13158    --
13159    -- set accounting class
13160    --
13161    xla_ae_lines_pkg.SetAcctClass(
13162            p_accounting_class_code  => 'SHORT_TERM_DEBT'
13163          , p_ae_header_id           => l_ae_header_id
13164          );
13165 
13166    --
13167    -- set rounding class
13168    --
13169    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
13170                       'RECEIVABLE';
13171 
13172    --
13173    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
13174    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
13175    --
13176    -- bulk performance
13177    --
13178    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
13179 
13180    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
13181       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
13182 
13183    -- 4955764
13184    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
13185       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
13186 
13187    -- 4458381 Public Sector Enh
13188    
13189    --
13190    -- set accounting attributes for the line type
13191    --
13192    l_entered_amt_idx := 8;
13193    l_accted_amt_idx  := 13;
13194    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
13195    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
13196    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
13197    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
13198    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
13199    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
13200    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
13201    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
13202    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
13203    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
13204    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
13205    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
13206    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
13207    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
13208    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
13209    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
13210    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
13214    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
13211    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
13212    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
13213    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
13215    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
13216    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
13217    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
13218    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
13219    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
13220    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
13221    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
13222    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
13223    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
13224    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
13225    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
13226    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
13227 
13228    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
13229    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
13230 
13231    ---------------------------------------------------------------------------------------------------------------
13232    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
13233    ---------------------------------------------------------------------------------------------------------------
13234    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
13235 
13236    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
13237    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
13238 
13239    IF xla_accounting_cache_pkg.GetValueChar
13240          (p_source_code         => 'LEDGER_CATEGORY_CODE'
13241          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
13242    AND l_bflow_method_code = 'PRIOR_ENTRY'
13243 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
13244    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
13245          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
13246        )
13247    THEN
13248          xla_ae_lines_pkg.BflowUpgEntry
13249            (p_business_method_code    => l_bflow_method_code
13250            ,p_business_class_code     => l_bflow_class_code
13251            ,p_balance_type            => l_balance_type_code);
13252    ELSE
13253       NULL;
13254 -- No business flow processing for business flow method of NONE.
13255    END IF;
13256 
13257    --
13258    -- call analytical criteria
13259    --
13260    
13261    --
13262    -- call description
13263    --
13264    -- No description or it is inherited.
13265    --
13266    -- call ADRs
13267    -- Bug 4922099
13268    --
13269    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
13270         (NVL(l_actual_upg_option, 'N') = 'O') OR
13271         (NVL(l_enc_upg_option, 'N') = 'O')
13272       )
13273    THEN
13274    NULL;
13275    --
13276    --
13277    
13278   l_ccid := AcctDerRule_1(
13279            p_application_id           => p_application_id
13280          , p_ae_header_id             => l_ae_header_id 
13281 , p_source_1 => p_source_1
13282          , x_transaction_coa_id       => l_adr_transaction_coa_id
13283          , x_accounting_coa_id        => l_adr_accounting_coa_id
13284          , x_value_type_code          => l_adr_value_type_code
13285          , p_side                     => 'NA'
13286    );
13287 
13288    xla_ae_lines_pkg.set_ccid(
13289     p_code_combination_id          => l_ccid
13290   , p_value_type_code              => l_adr_value_type_code
13291   , p_transaction_coa_id           => l_adr_transaction_coa_id
13292   , p_accounting_coa_id            => l_adr_accounting_coa_id
13293   , p_adr_code                     => 'DIST_CCID'
13294   , p_adr_type_code                => 'S'
13295   , p_component_type               => l_component_type
13296   , p_component_code               => l_component_code
13297   , p_component_type_code          => l_component_type_code
13298   , p_component_appl_id            => l_component_appl_id
13299   , p_amb_context_code             => l_amb_context_code
13300   , p_side                         => 'NA'
13301   );
13302 
13303 
13304    --
13305    --
13306    END IF;
13307    --
13308    -- Bug 4922099
13309    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
13310           (NVL(l_enc_upg_option, 'N') = 'O')
13311         ) AND
13312         (l_bflow_method_code = 'PRIOR_ENTRY')
13313       )
13314    THEN
13315       IF
13316       --
13317       1 = 2
13318       --
13319       THEN
13320       xla_accounting_err_pkg.build_message
13321                                     (p_appli_s_name            => 'XLA'
13322                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
13323                                     ,p_token_1                 => 'LINE_NUMBER'
13324                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
13325                                     ,p_token_2                 => 'LINE_TYPE_NAME'
13326                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
13327                                                                              l_component_type
13331                                                                             ,l_amb_context_code
13328                                                                             ,l_component_code
13329                                                                             ,l_component_type_code
13330                                                                             ,l_component_appl_id
13332                                                                             ,l_entity_code
13333                                                                             ,l_event_class_code
13334                                                                            )
13335                                     ,p_token_3                 => 'OWNER'
13336                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
13337                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
13338                                                                           ,p_lookup_code    => l_component_type_code
13339                                                                          )
13340                                     ,p_token_4                 => 'PRODUCT_NAME'
13341                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
13342                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
13343                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
13344                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
13345                                     ,p_ae_header_id            =>  NULL
13346                                        );
13347 
13348         IF (C_LEVEL_ERROR>= g_log_level) THEN
13349                  trace
13350                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
13351                       ,p_level    => C_LEVEL_ERROR
13352                       ,p_module   => l_log_module);
13353         END IF;
13354       END IF;
13355    END IF;
13356    --
13357    --
13358    ------------------------------------------------------------------------------------------------
13359    -- 4219869 Business Flow
13360    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
13361    -- Prior Entry.  Currently, the following code is always generated.
13362    ------------------------------------------------------------------------------------------------
13363    XLA_AE_LINES_PKG.ValidateCurrentLine;
13364 
13365    ------------------------------------------------------------------------------------
13366    -- 4219869 Business Flow
13367    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
13368    ------------------------------------------------------------------------------------
13369    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
13370 
13371    ----------------------------------------------------------------------------------
13372    -- 4219869 Business Flow
13373    -- Update journal entry status -- Need to generate this within IF <condition>
13374    ----------------------------------------------------------------------------------
13375    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
13376          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
13377          ,p_balance_type_code => l_balance_type_code
13378          );
13379 
13380    -------------------------------------------------------------------------------------------
13381    -- 4262811 - Generate the Accrual Reversal lines
13382    -------------------------------------------------------------------------------------------
13383    BEGIN
13384       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
13385                               (g_array_event(p_event_id).array_value_num('header_index'));
13386       IF l_acc_rev_flag IS NULL THEN
13387          l_acc_rev_flag := 'N';
13388       END IF;
13389    EXCEPTION
13390       WHEN OTHERS THEN
13391          l_acc_rev_flag := 'N';
13392    END;
13393    --
13394    IF (l_acc_rev_flag = 'Y') THEN
13395 
13396        -- 4645092  ------------------------------------------------------------------------------
13397        -- To allow MPA report to determine if it should generate report process
13398        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
13399        ------------------------------------------------------------------------------------------
13400 
13401        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
13402        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
13403    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
13404    -- call ADRs
13405    -- Bug 4922099
13406    --
13407    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
13408         (NVL(l_actual_upg_option, 'N') = 'O') OR
13409         (NVL(l_enc_upg_option, 'N') = 'O')
13410       )
13411    THEN
13412    NULL;
13413    --
13414    --
13415    
13416   l_ccid := AcctDerRule_1(
13417            p_application_id           => p_application_id
13418          , p_ae_header_id             => l_ae_header_id 
13419 , p_source_1 => p_source_1
13420          , x_transaction_coa_id       => l_adr_transaction_coa_id
13421          , x_accounting_coa_id        => l_adr_accounting_coa_id
13422          , x_value_type_code          => l_adr_value_type_code
13423          , p_side                     => 'NA'
13424    );
13428   , p_value_type_code              => l_adr_value_type_code
13425 
13426    xla_ae_lines_pkg.set_ccid(
13427     p_code_combination_id          => l_ccid
13429   , p_transaction_coa_id           => l_adr_transaction_coa_id
13430   , p_accounting_coa_id            => l_adr_accounting_coa_id
13431   , p_adr_code                     => 'DIST_CCID'
13432   , p_adr_type_code                => 'S'
13433   , p_component_type               => l_component_type
13434   , p_component_code               => l_component_code
13435   , p_component_type_code          => l_component_type_code
13436   , p_component_appl_id            => l_component_appl_id
13437   , p_amb_context_code             => l_amb_context_code
13438   , p_side                         => 'NA'
13439   );
13440 
13441 
13442    --
13443    --
13444    END IF;
13445 
13446        --
13447        -- Update the line information that should be overwritten
13448        --
13449        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
13450                                          p_header_num   => 1);
13451        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
13452 
13453        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
13454 
13455        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
13456           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
13457        END IF;
13458 
13459       --
13460       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
13461       --
13462       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
13463           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
13464       ELSE
13465           ---------------------------------------------------------------------------------------------------
13466           -- 4262811a Switch Sign
13467           ---------------------------------------------------------------------------------------------------
13468           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
13469           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
13470                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
13471           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
13472                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
13473           -- 5132302
13474           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
13475                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
13476 
13477       END IF;
13478 
13479       -- 4955764
13480       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
13481       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
13482 
13483 
13484       XLA_AE_LINES_PKG.ValidateCurrentLine;
13485       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
13486 
13487       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
13488                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
13489                ,p_balance_type_code => l_balance_type_code);
13490 
13491    END IF;
13492 
13493    -----------------------------------------------------------------------------------------
13494    -- 4262811 Multiperiod Accounting
13495    -----------------------------------------------------------------------------------------
13496      -- No MPA option is assigned.
13497 
13498 
13499 END IF;
13500 END IF;
13501 --
13502 
13503 --
13504 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13505    trace
13506       (p_msg      => 'END of AcctLineType_27'
13507       ,p_level    => C_LEVEL_PROCEDURE
13508       ,p_module   => l_log_module);
13509 END IF;
13510 --
13511 EXCEPTION
13512   WHEN xla_exceptions_pkg.application_exception THEN
13513       RAISE;
13514   WHEN OTHERS THEN
13515        xla_exceptions_pkg.raise_message
13516            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_27');
13517 END AcctLineType_27;
13518 --
13519 
13520 ---------------------------------------
13521 --
13522 -- PRIVATE FUNCTION
13523 --         AcctLineType_28
13524 --
13525 ---------------------------------------
13526 PROCEDURE AcctLineType_28 (
13527   p_application_id        IN NUMBER
13528  ,p_event_id              IN NUMBER
13529  ,p_calculate_acctd_flag  IN VARCHAR2
13530  ,p_calculate_g_l_flag    IN VARCHAR2
13531  ,p_actual_flag           IN OUT VARCHAR2
13532  ,p_balance_type_code     OUT VARCHAR2
13533  ,p_gain_or_loss_ref      OUT VARCHAR2
13534  
13535 --System Gain Account
13536  , p_source_3            IN NUMBER
13537 --System Loss Account
13538  , p_source_4            IN NUMBER
13539 --Distribution Line Identifier
13540  , p_source_9            IN NUMBER
13541 --Distribution Type
13542  , p_source_10            IN VARCHAR2
13543 --Accounting Amount
13544  , p_source_25            IN NUMBER
13545 --Distribution Party Identifier
13546  , p_source_26            IN NUMBER
13547 --Distribution Party Site Id
13551 )
13548  , p_source_27            IN NUMBER
13549 --Distribution Party Type
13550  , p_source_28            IN VARCHAR2
13552 IS
13553 
13554 l_component_type              VARCHAR2(80);
13555 l_component_code              VARCHAR2(30);
13556 l_component_type_code         VARCHAR2(1);
13557 l_component_appl_id           INTEGER;
13558 l_amb_context_code            VARCHAR2(30);
13559 l_entity_code                 VARCHAR2(30);
13560 l_event_class_code            VARCHAR2(30);
13561 l_ae_header_id                NUMBER;
13562 l_event_type_code             VARCHAR2(30);
13563 l_line_definition_code        VARCHAR2(30);
13564 l_line_definition_owner_code  VARCHAR2(1);
13565 --
13566 -- adr variables
13567 l_segment                     VARCHAR2(30);
13568 l_ccid                        NUMBER;
13569 l_adr_transaction_coa_id      NUMBER;
13570 l_adr_accounting_coa_id       NUMBER;
13571 l_adr_flexfield_segment_code  VARCHAR2(30);
13572 l_adr_flex_value_set_id       NUMBER;
13573 l_adr_value_type_code         VARCHAR2(30);
13574 l_adr_value_combination_id    NUMBER;
13575 l_adr_value_segment_code      VARCHAR2(30);
13576 
13577 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
13578 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
13579 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
13580 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
13581 
13582 -- 4262811 Variables ------------------------------------------------------------------------------------------
13583 l_entered_amt_idx             NUMBER;
13584 l_accted_amt_idx              NUMBER;
13585 l_acc_rev_flag                VARCHAR2(1);
13586 l_accrual_line_num            NUMBER;
13587 l_tmp_amt                     NUMBER;
13588 l_acc_rev_natural_side_code   VARCHAR2(1);
13589 
13590 l_num_entries                 NUMBER;
13591 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
13592 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
13593 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
13594 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
13595 l_recog_line_1                NUMBER;
13596 l_recog_line_2                NUMBER;
13597 
13598 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
13599 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
13600 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
13601 
13602 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
13603 
13604 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
13605 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
13606 
13607 ---------------------------------------------------------------------------------------------------------------
13608 
13609 
13610 --
13611 -- bulk performance
13612 --
13613 l_balance_type_code           VARCHAR2(1);
13614 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
13615 l_log_module                  VARCHAR2(240);
13616 
13617 --
13618 -- Upgrade strategy
13619 --
13620 l_actual_upg_option           VARCHAR2(1);
13621 l_enc_upg_option           VARCHAR2(1);
13622 
13623 --
13624 BEGIN
13625 --
13626 IF g_log_enabled THEN
13627       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_28';
13628 END IF;
13629 --
13630 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
13631 
13632       trace
13633          (p_msg      => 'BEGIN of AcctLineType_28'
13634          ,p_level    => C_LEVEL_PROCEDURE
13635          ,p_module   => l_log_module);
13636 
13637 END IF;
13638 --
13639 l_component_type             := 'AMB_JLT';
13640 l_component_code             := 'RCT_EXCH_GAIN_LOSS';
13641 l_component_type_code        := 'S';
13642 l_component_appl_id          :=  222;
13643 l_amb_context_code           := 'DEFAULT';
13644 l_entity_code                := 'RECEIPTS';
13645 l_event_class_code           := 'RECEIPT';
13646 l_event_type_code            := 'RECEIPT_ALL';
13647 l_line_definition_owner_code := 'S';
13648 l_line_definition_code       := 'RCT_CASH_JLD';
13649 --
13650 l_balance_type_code          := 'A';
13651 l_segment                     := NULL;
13652 l_ccid                        := NULL;
13653 l_adr_transaction_coa_id      := NULL;
13654 l_adr_accounting_coa_id       := NULL;
13655 l_adr_flexfield_segment_code  := NULL;
13656 l_adr_flex_value_set_id       := NULL;
13657 l_adr_value_type_code         := NULL;
13658 l_adr_value_combination_id    := NULL;
13659 l_adr_value_segment_code      := NULL;
13660 
13661 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
13662 l_bflow_class_code           := '';    -- 4219869 Business Flow
13663 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
13664 l_budgetary_control_flag     := 'N';
13665 
13666 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
13667 l_bflow_applied_to_amt       := NULL; -- 5132302
13668 l_entered_amt_idx            := NULL;          -- 4262811
13669 l_accted_amt_idx             := NULL;          -- 4262811
13670 l_acc_rev_flag               := NULL;          -- 4262811
13671 l_accrual_line_num           := NULL;          -- 4262811
13672 l_tmp_amt                    := NULL;          -- 4262811
13673 --
13677   END IF;
13674 IF NOT ((p_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
13675             (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
13676                return;
13678   
13679 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
13680     l_balance_type_code <> 'B' THEN
13681 
13682    --
13683    XLA_AE_LINES_PKG.SetNewLine;
13684 
13685    p_balance_type_code          := l_balance_type_code;
13686    -- set the flag so later we will know whether the gain loss line needs to be created
13687    
13688    IF(l_balance_type_code = 'A' ) THEN
13689      p_actual_flag :='G';
13690    END IF;
13691 
13692    --
13693    -- bulk performance
13694    --
13695    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
13696                                       p_header_num   => 0); -- 4262811
13697    --
13698    -- set accounting line options
13699    --
13700    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
13701            p_natural_side_code          => 'G'
13702          , p_gain_or_loss_flag          => 'N'
13703          , p_gl_transfer_mode_code      => 'S'
13704          , p_acct_entry_type_code       => 'A'
13705          , p_switch_side_flag           => ''
13706          , p_merge_duplicate_code       => 'A'
13707          );
13708    --
13709    l_acc_rev_natural_side_code := 'C';  -- 4262811
13710    -- 
13711    --
13712    -- set accounting line type info
13713    --
13714    xla_ae_lines_pkg.SetAcctLineType
13715       (p_component_type             => l_component_type
13716       ,p_event_type_code            => l_event_type_code
13717       ,p_line_definition_owner_code => l_line_definition_owner_code
13718       ,p_line_definition_code       => l_line_definition_code
13719       ,p_accounting_line_code       => l_component_code
13720       ,p_accounting_line_type_code  => l_component_type_code
13721       ,p_accounting_line_appl_id    => l_component_appl_id
13722       ,p_amb_context_code           => l_amb_context_code
13723       ,p_entity_code                => l_entity_code
13724       ,p_event_class_code           => l_event_class_code);
13725    --
13726    -- set accounting class
13727    --
13728    xla_ae_lines_pkg.SetAcctClass(
13729            p_accounting_class_code  => 'EXCHANGE_GAIN_LOSS'
13730          , p_ae_header_id           => l_ae_header_id
13731          );
13732 
13733    --
13734    -- set rounding class
13735    --
13736    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
13737                       'EXCHANGE_GAIN_LOSS';
13738 
13739    --
13740    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
13741    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
13742    --
13743    -- bulk performance
13744    --
13745    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
13746 
13747    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
13748       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
13749 
13750    -- 4955764
13751    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
13752       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
13753 
13754    -- 4458381 Public Sector Enh
13755    
13756    --
13757    -- set accounting attributes for the line type
13758    --
13759    l_entered_amt_idx := NULL;
13760    l_accted_amt_idx  := 3;
13761    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
13762    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
13763    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
13764    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
13765    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
13766    l_rec_acct_attrs.array_acct_attr_code(3) := 'LEDGER_AMOUNT';
13767    l_rec_acct_attrs.array_num_value(3)  := p_source_25;
13768    l_rec_acct_attrs.array_acct_attr_code(4) := 'PARTY_ID';
13769    l_rec_acct_attrs.array_num_value(4)  := p_source_26;
13770    l_rec_acct_attrs.array_acct_attr_code(5) := 'PARTY_SITE_ID';
13771    l_rec_acct_attrs.array_num_value(5)  := p_source_27;
13772    l_rec_acct_attrs.array_acct_attr_code(6) := 'PARTY_TYPE';
13773    l_rec_acct_attrs.array_char_value(6)  := p_source_28;
13774 
13775    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
13776    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
13777 
13778    ---------------------------------------------------------------------------------------------------------------
13779    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
13780    ---------------------------------------------------------------------------------------------------------------
13781    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
13782 
13783    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
13784    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
13785 
13786    IF xla_accounting_cache_pkg.GetValueChar
13790 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
13787          (p_source_code         => 'LEDGER_CATEGORY_CODE'
13788          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
13789    AND l_bflow_method_code = 'PRIOR_ENTRY'
13791    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
13792          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
13793        )
13794    THEN
13795          xla_ae_lines_pkg.BflowUpgEntry
13796            (p_business_method_code    => l_bflow_method_code
13797            ,p_business_class_code     => l_bflow_class_code
13798            ,p_balance_type            => l_balance_type_code);
13799    ELSE
13800       NULL;
13801 -- No business flow processing for business flow method of NONE.
13802    END IF;
13803 
13804    --
13805    -- call analytical criteria
13806    --
13807    
13808    --
13809    -- call description
13810    --
13811    -- No description or it is inherited.
13812    --
13813    -- call ADRs
13814    -- Bug 4922099
13815    --
13816    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
13817         (NVL(l_actual_upg_option, 'N') = 'O') OR
13818         (NVL(l_enc_upg_option, 'N') = 'O')
13819       )
13820    THEN
13821    NULL;
13822    --
13823    --
13824    
13825   l_ccid := AcctDerRule_3(
13826            p_application_id           => p_application_id
13827          , p_ae_header_id             => l_ae_header_id 
13828 , p_source_3 => p_source_3
13829          , x_transaction_coa_id       => l_adr_transaction_coa_id
13830          , x_accounting_coa_id        => l_adr_accounting_coa_id
13831          , x_value_type_code          => l_adr_value_type_code
13832          , p_side                     => 'CREDIT'
13833    );
13834 
13835    xla_ae_lines_pkg.set_ccid(
13836     p_code_combination_id          => l_ccid
13837   , p_value_type_code              => l_adr_value_type_code
13838   , p_transaction_coa_id           => l_adr_transaction_coa_id
13839   , p_accounting_coa_id            => l_adr_accounting_coa_id
13840   , p_adr_code                     => 'SYS_GAIN_CCID'
13841   , p_adr_type_code                => 'S'
13842   , p_component_type               => l_component_type
13843   , p_component_code               => l_component_code
13844   , p_component_type_code          => l_component_type_code
13845   , p_component_appl_id            => l_component_appl_id
13846   , p_amb_context_code             => l_amb_context_code
13847   , p_side                         => 'CREDIT'
13848   );
13849 
13850 
13851   l_ccid := AcctDerRule_4(
13852            p_application_id           => p_application_id
13853          , p_ae_header_id             => l_ae_header_id 
13854 , p_source_4 => p_source_4
13855          , x_transaction_coa_id       => l_adr_transaction_coa_id
13856          , x_accounting_coa_id        => l_adr_accounting_coa_id
13857          , x_value_type_code          => l_adr_value_type_code
13858          , p_side                     => 'DEBIT'
13859    );
13860 
13861    xla_ae_lines_pkg.set_ccid(
13862     p_code_combination_id          => l_ccid
13863   , p_value_type_code              => l_adr_value_type_code
13864   , p_transaction_coa_id           => l_adr_transaction_coa_id
13865   , p_accounting_coa_id            => l_adr_accounting_coa_id
13866   , p_adr_code                     => 'SYS_LOSS_CCID'
13867   , p_adr_type_code                => 'S'
13868   , p_component_type               => l_component_type
13869   , p_component_code               => l_component_code
13870   , p_component_type_code          => l_component_type_code
13871   , p_component_appl_id            => l_component_appl_id
13872   , p_amb_context_code             => l_amb_context_code
13873   , p_side                         => 'DEBIT'
13874   );
13875 
13876 
13877    --
13878    --
13879    END IF;
13880    --
13881    -- Bug 4922099
13882    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
13883           (NVL(l_enc_upg_option, 'N') = 'O')
13884         ) AND
13885         (l_bflow_method_code = 'PRIOR_ENTRY')
13886       )
13887    THEN
13888       IF
13889       --
13890       1 = 2
13891       --
13892       THEN
13893       xla_accounting_err_pkg.build_message
13894                                     (p_appli_s_name            => 'XLA'
13895                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
13896                                     ,p_token_1                 => 'LINE_NUMBER'
13897                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
13898                                     ,p_token_2                 => 'LINE_TYPE_NAME'
13899                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
13900                                                                              l_component_type
13901                                                                             ,l_component_code
13902                                                                             ,l_component_type_code
13903                                                                             ,l_component_appl_id
13904                                                                             ,l_amb_context_code
13905                                                                             ,l_entity_code
13906                                                                             ,l_event_class_code
13910                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
13907                                                                            )
13908                                     ,p_token_3                 => 'OWNER'
13909                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
13911                                                                           ,p_lookup_code    => l_component_type_code
13912                                                                          )
13913                                     ,p_token_4                 => 'PRODUCT_NAME'
13914                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
13915                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
13916                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
13917                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
13918                                     ,p_ae_header_id            =>  NULL
13919                                        );
13920 
13921         IF (C_LEVEL_ERROR>= g_log_level) THEN
13922                  trace
13923                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
13924                       ,p_level    => C_LEVEL_ERROR
13925                       ,p_module   => l_log_module);
13926         END IF;
13927       END IF;
13928    END IF;
13929    --
13930    --
13931    ------------------------------------------------------------------------------------------------
13932    -- 4219869 Business Flow
13933    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
13934    -- Prior Entry.  Currently, the following code is always generated.
13935    ------------------------------------------------------------------------------------------------
13936    XLA_AE_LINES_PKG.ValidateCurrentLine;
13937 
13938    ------------------------------------------------------------------------------------
13939    -- 4219869 Business Flow
13940    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
13941    ------------------------------------------------------------------------------------
13942    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
13943 
13944    ----------------------------------------------------------------------------------
13945    -- 4219869 Business Flow
13946    -- Update journal entry status -- Need to generate this within IF <condition>
13947    ----------------------------------------------------------------------------------
13948    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
13949          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
13950          ,p_balance_type_code => l_balance_type_code
13951          );
13952 
13953    -------------------------------------------------------------------------------------------
13954    -- 4262811 - Generate the Accrual Reversal lines
13955    -------------------------------------------------------------------------------------------
13956    BEGIN
13957       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
13958                               (g_array_event(p_event_id).array_value_num('header_index'));
13959       IF l_acc_rev_flag IS NULL THEN
13960          l_acc_rev_flag := 'N';
13961       END IF;
13962    EXCEPTION
13963       WHEN OTHERS THEN
13964          l_acc_rev_flag := 'N';
13965    END;
13966    --
13967    IF (l_acc_rev_flag = 'Y') THEN
13968 
13969        -- 4645092  ------------------------------------------------------------------------------
13970        -- To allow MPA report to determine if it should generate report process
13971        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
13972        ------------------------------------------------------------------------------------------
13973 
13974        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
13975        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
13976    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
13977    -- call ADRs
13978    -- Bug 4922099
13979    --
13980    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
13981         (NVL(l_actual_upg_option, 'N') = 'O') OR
13982         (NVL(l_enc_upg_option, 'N') = 'O')
13983       )
13984    THEN
13985    NULL;
13986    --
13987    --
13988    
13989   l_ccid := AcctDerRule_3(
13990            p_application_id           => p_application_id
13991          , p_ae_header_id             => l_ae_header_id 
13992 , p_source_3 => p_source_3
13993          , x_transaction_coa_id       => l_adr_transaction_coa_id
13994          , x_accounting_coa_id        => l_adr_accounting_coa_id
13995          , x_value_type_code          => l_adr_value_type_code
13996          , p_side                     => 'CREDIT'
13997    );
13998 
13999    xla_ae_lines_pkg.set_ccid(
14000     p_code_combination_id          => l_ccid
14001   , p_value_type_code              => l_adr_value_type_code
14002   , p_transaction_coa_id           => l_adr_transaction_coa_id
14003   , p_accounting_coa_id            => l_adr_accounting_coa_id
14004   , p_adr_code                     => 'SYS_GAIN_CCID'
14005   , p_adr_type_code                => 'S'
14006   , p_component_type               => l_component_type
14007   , p_component_code               => l_component_code
14008   , p_component_type_code          => l_component_type_code
14012   );
14009   , p_component_appl_id            => l_component_appl_id
14010   , p_amb_context_code             => l_amb_context_code
14011   , p_side                         => 'CREDIT'
14013 
14014 
14015   l_ccid := AcctDerRule_4(
14016            p_application_id           => p_application_id
14017          , p_ae_header_id             => l_ae_header_id 
14018 , p_source_4 => p_source_4
14019          , x_transaction_coa_id       => l_adr_transaction_coa_id
14020          , x_accounting_coa_id        => l_adr_accounting_coa_id
14021          , x_value_type_code          => l_adr_value_type_code
14022          , p_side                     => 'DEBIT'
14023    );
14024 
14025    xla_ae_lines_pkg.set_ccid(
14026     p_code_combination_id          => l_ccid
14027   , p_value_type_code              => l_adr_value_type_code
14028   , p_transaction_coa_id           => l_adr_transaction_coa_id
14029   , p_accounting_coa_id            => l_adr_accounting_coa_id
14030   , p_adr_code                     => 'SYS_LOSS_CCID'
14031   , p_adr_type_code                => 'S'
14032   , p_component_type               => l_component_type
14033   , p_component_code               => l_component_code
14034   , p_component_type_code          => l_component_type_code
14035   , p_component_appl_id            => l_component_appl_id
14036   , p_amb_context_code             => l_amb_context_code
14037   , p_side                         => 'DEBIT'
14038   );
14039 
14040 
14041    --
14042    --
14043    END IF;
14044 
14045        --
14046        -- Update the line information that should be overwritten
14047        --
14048        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
14049                                          p_header_num   => 1);
14050        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
14051 
14052        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
14053 
14054        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
14055           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
14056        END IF;
14057 
14058       --
14059       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
14060       --
14061       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
14062           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
14063       ELSE
14064           ---------------------------------------------------------------------------------------------------
14065           -- 4262811a Switch Sign
14066           ---------------------------------------------------------------------------------------------------
14067           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
14068           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
14069                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
14070           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
14071                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
14072           -- 5132302
14073           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
14074                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
14075 
14076       END IF;
14077 
14078       -- 4955764
14079       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
14080       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
14081 
14082 
14083       XLA_AE_LINES_PKG.ValidateCurrentLine;
14084       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
14085 
14086       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
14087                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
14088                ,p_balance_type_code => l_balance_type_code);
14089 
14090    END IF;
14091 
14092    -----------------------------------------------------------------------------------------
14093    -- 4262811 Multiperiod Accounting
14094    -----------------------------------------------------------------------------------------
14095      -- No MPA option is assigned.
14096 
14097 
14098 END IF;
14099 --
14100 
14101 --
14102 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14103    trace
14104       (p_msg      => 'END of AcctLineType_28'
14105       ,p_level    => C_LEVEL_PROCEDURE
14106       ,p_module   => l_log_module);
14107 END IF;
14108 --
14109 EXCEPTION
14110   WHEN xla_exceptions_pkg.application_exception THEN
14111       RAISE;
14112   WHEN OTHERS THEN
14113        xla_exceptions_pkg.raise_message
14114            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_28');
14115 END AcctLineType_28;
14116 --
14117 
14118 ---------------------------------------
14119 --
14120 -- PRIVATE FUNCTION
14121 --         AcctLineType_29
14122 --
14123 ---------------------------------------
14124 PROCEDURE AcctLineType_29 (
14125   p_application_id        IN NUMBER
14126  ,p_event_id              IN NUMBER
14127  ,p_calculate_acctd_flag  IN VARCHAR2
14131  ,p_gain_or_loss_ref      OUT VARCHAR2
14128  ,p_calculate_g_l_flag    IN VARCHAR2
14129  ,p_actual_flag           IN OUT VARCHAR2
14130  ,p_balance_type_code     OUT VARCHAR2
14132  
14133 --Distribution GL Account
14134  , p_source_1            IN NUMBER
14135 --Distribution Source Type
14136  , p_source_7            IN VARCHAR2
14137 --Distribution Multi Fund Additional Entry
14138  , p_source_8            IN VARCHAR2
14139 --Distribution Line Identifier
14140  , p_source_9            IN NUMBER
14141 --Distribution Type
14142  , p_source_10            IN VARCHAR2
14143 --Exchange Rate
14144  , p_source_14            IN NUMBER
14145 --Exchange Rate Type
14146  , p_source_15            IN VARCHAR2
14147 --Receipt Applied To Application Identifier
14148  , p_source_17            IN NUMBER
14149 --Transaction Distribution Type
14150  , p_source_18            IN VARCHAR2
14151 --Transaction Entity Code
14152  , p_source_19            IN VARCHAR2
14153 --Transaction Distribution Identifier
14154  , p_source_20            IN NUMBER
14155 --Transaction Identifier
14156  , p_source_21            IN NUMBER
14157 --DIST_ENT_AMT_FROM
14158  , p_source_22            IN NUMBER
14159 --Applying Document Currency Code
14160  , p_source_23            IN VARCHAR2
14161 --Exchange Date
14162  , p_source_24            IN DATE
14163 --Accounting Amount
14164  , p_source_25            IN NUMBER
14165 --Distribution Party Identifier
14166  , p_source_26            IN NUMBER
14167 --Distribution Party Site Id
14168  , p_source_27            IN NUMBER
14169 --Distribution Party Type
14170  , p_source_28            IN VARCHAR2
14171 --Distribution Source Table
14172  , p_source_33            IN VARCHAR2
14173 )
14174 IS
14175 
14176 l_component_type              VARCHAR2(80);
14177 l_component_code              VARCHAR2(30);
14178 l_component_type_code         VARCHAR2(1);
14179 l_component_appl_id           INTEGER;
14180 l_amb_context_code            VARCHAR2(30);
14181 l_entity_code                 VARCHAR2(30);
14182 l_event_class_code            VARCHAR2(30);
14183 l_ae_header_id                NUMBER;
14184 l_event_type_code             VARCHAR2(30);
14185 l_line_definition_code        VARCHAR2(30);
14186 l_line_definition_owner_code  VARCHAR2(1);
14187 --
14188 -- adr variables
14189 l_segment                     VARCHAR2(30);
14190 l_ccid                        NUMBER;
14191 l_adr_transaction_coa_id      NUMBER;
14192 l_adr_accounting_coa_id       NUMBER;
14193 l_adr_flexfield_segment_code  VARCHAR2(30);
14194 l_adr_flex_value_set_id       NUMBER;
14195 l_adr_value_type_code         VARCHAR2(30);
14196 l_adr_value_combination_id    NUMBER;
14197 l_adr_value_segment_code      VARCHAR2(30);
14198 
14199 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
14200 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
14201 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
14202 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
14203 
14204 -- 4262811 Variables ------------------------------------------------------------------------------------------
14205 l_entered_amt_idx             NUMBER;
14206 l_accted_amt_idx              NUMBER;
14207 l_acc_rev_flag                VARCHAR2(1);
14208 l_accrual_line_num            NUMBER;
14209 l_tmp_amt                     NUMBER;
14210 l_acc_rev_natural_side_code   VARCHAR2(1);
14211 
14212 l_num_entries                 NUMBER;
14213 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
14214 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
14215 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
14216 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
14217 l_recog_line_1                NUMBER;
14218 l_recog_line_2                NUMBER;
14219 
14220 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
14221 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
14222 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
14223 
14224 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
14225 
14226 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
14227 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
14228 
14229 ---------------------------------------------------------------------------------------------------------------
14230 
14231 
14232 --
14233 -- bulk performance
14234 --
14235 l_balance_type_code           VARCHAR2(1);
14236 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
14237 l_log_module                  VARCHAR2(240);
14238 
14239 --
14240 -- Upgrade strategy
14241 --
14242 l_actual_upg_option           VARCHAR2(1);
14243 l_enc_upg_option           VARCHAR2(1);
14244 
14245 --
14246 BEGIN
14247 --
14248 IF g_log_enabled THEN
14249       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_29';
14250 END IF;
14251 --
14252 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14253 
14254       trace
14255          (p_msg      => 'BEGIN of AcctLineType_29'
14256          ,p_level    => C_LEVEL_PROCEDURE
14257          ,p_module   => l_log_module);
14258 
14259 END IF;
14260 --
14264 l_component_appl_id          :=  222;
14261 l_component_type             := 'AMB_JLT';
14262 l_component_code             := 'RCT_FACTOR';
14263 l_component_type_code        := 'S';
14265 l_amb_context_code           := 'DEFAULT';
14266 l_entity_code                := 'RECEIPTS';
14267 l_event_class_code           := 'RECEIPT';
14268 l_event_type_code            := 'RECEIPT_ALL';
14269 l_line_definition_owner_code := 'S';
14270 l_line_definition_code       := 'RCT_CASH_JLD';
14271 --
14272 l_balance_type_code          := 'A';
14273 l_segment                     := NULL;
14274 l_ccid                        := NULL;
14275 l_adr_transaction_coa_id      := NULL;
14276 l_adr_accounting_coa_id       := NULL;
14277 l_adr_flexfield_segment_code  := NULL;
14278 l_adr_flex_value_set_id       := NULL;
14279 l_adr_value_type_code         := NULL;
14280 l_adr_value_combination_id    := NULL;
14281 l_adr_value_segment_code      := NULL;
14282 
14283 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
14284 l_bflow_class_code           := '';    -- 4219869 Business Flow
14285 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
14286 l_budgetary_control_flag     := 'N';
14287 
14288 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
14289 l_bflow_applied_to_amt       := NULL; -- 5132302
14290 l_entered_amt_idx            := NULL;          -- 4262811
14291 l_accted_amt_idx             := NULL;          -- 4262811
14292 l_acc_rev_flag               := NULL;          -- 4262811
14293 l_accrual_line_num           := NULL;          -- 4262811
14294 l_tmp_amt                    := NULL;          -- 4262811
14295 --
14296  
14297 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
14298     l_balance_type_code <> 'B' THEN
14299 IF NVL(p_source_7,'
14300 ') =  'FACTOR' AND 
14301 NVL(p_source_33,'
14302 ') =  'CRH' AND 
14303 NVL(p_source_8,'
14304 ') =  'N'
14305  THEN 
14306 
14307    --
14308    XLA_AE_LINES_PKG.SetNewLine;
14309 
14310    p_balance_type_code          := l_balance_type_code;
14311    -- set the flag so later we will know whether the gain loss line needs to be created
14312    
14313    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
14314      p_actual_flag :='A';
14315    END IF;
14316 
14317    --
14318    -- bulk performance
14319    --
14320    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
14321                                       p_header_num   => 0); -- 4262811
14322    --
14323    -- set accounting line options
14324    --
14325    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
14326            p_natural_side_code          => 'C'
14327          , p_gain_or_loss_flag          => 'N'
14328          , p_gl_transfer_mode_code      => 'S'
14329          , p_acct_entry_type_code       => 'A'
14330          , p_switch_side_flag           => 'Y'
14331          , p_merge_duplicate_code       => 'A'
14332          );
14333    --
14334    l_acc_rev_natural_side_code := 'D';  -- 4262811
14335    -- 
14336    --
14337    -- set accounting line type info
14338    --
14339    xla_ae_lines_pkg.SetAcctLineType
14340       (p_component_type             => l_component_type
14341       ,p_event_type_code            => l_event_type_code
14342       ,p_line_definition_owner_code => l_line_definition_owner_code
14343       ,p_line_definition_code       => l_line_definition_code
14344       ,p_accounting_line_code       => l_component_code
14345       ,p_accounting_line_type_code  => l_component_type_code
14346       ,p_accounting_line_appl_id    => l_component_appl_id
14347       ,p_amb_context_code           => l_amb_context_code
14348       ,p_entity_code                => l_entity_code
14349       ,p_event_class_code           => l_event_class_code);
14350    --
14351    -- set accounting class
14352    --
14353    xla_ae_lines_pkg.SetAcctClass(
14354            p_accounting_class_code  => 'FACTOR'
14355          , p_ae_header_id           => l_ae_header_id
14356          );
14357 
14358    --
14359    -- set rounding class
14360    --
14361    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
14362                       'RECEIVABLE';
14363 
14364    --
14365    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
14366    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
14367    --
14368    -- bulk performance
14369    --
14370    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
14371 
14372    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
14373       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
14374 
14375    -- 4955764
14376    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
14377       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
14378 
14379    -- 4458381 Public Sector Enh
14380    
14381    --
14382    -- set accounting attributes for the line type
14383    --
14384    l_entered_amt_idx := 8;
14385    l_accted_amt_idx  := 13;
14386    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
14387    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
14388    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
14389    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
14393    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
14390    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
14391    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
14392    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
14394    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
14395    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
14396    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
14397    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
14398    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
14399    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
14400    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
14401    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
14402    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
14403    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
14404    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
14405    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
14406    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
14407    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
14408    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
14409    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
14410    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
14411    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
14412    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
14413    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
14414    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
14415    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
14416    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
14417    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
14418    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
14419 
14420    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
14421    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
14422 
14423    ---------------------------------------------------------------------------------------------------------------
14424    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
14425    ---------------------------------------------------------------------------------------------------------------
14426    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
14427 
14428    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
14429    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
14430 
14431    IF xla_accounting_cache_pkg.GetValueChar
14432          (p_source_code         => 'LEDGER_CATEGORY_CODE'
14433          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
14434    AND l_bflow_method_code = 'PRIOR_ENTRY'
14435 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
14436    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
14437          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
14438        )
14439    THEN
14440          xla_ae_lines_pkg.BflowUpgEntry
14441            (p_business_method_code    => l_bflow_method_code
14442            ,p_business_class_code     => l_bflow_class_code
14443            ,p_balance_type            => l_balance_type_code);
14444    ELSE
14445       NULL;
14446 -- No business flow processing for business flow method of NONE.
14447    END IF;
14448 
14449    --
14450    -- call analytical criteria
14451    --
14452    
14453    --
14454    -- call description
14455    --
14456    -- No description or it is inherited.
14457    --
14458    -- call ADRs
14459    -- Bug 4922099
14460    --
14461    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
14462         (NVL(l_actual_upg_option, 'N') = 'O') OR
14463         (NVL(l_enc_upg_option, 'N') = 'O')
14464       )
14465    THEN
14466    NULL;
14467    --
14468    --
14469    
14470   l_ccid := AcctDerRule_1(
14471            p_application_id           => p_application_id
14472          , p_ae_header_id             => l_ae_header_id 
14473 , p_source_1 => p_source_1
14474          , x_transaction_coa_id       => l_adr_transaction_coa_id
14475          , x_accounting_coa_id        => l_adr_accounting_coa_id
14476          , x_value_type_code          => l_adr_value_type_code
14477          , p_side                     => 'NA'
14478    );
14479 
14480    xla_ae_lines_pkg.set_ccid(
14481     p_code_combination_id          => l_ccid
14482   , p_value_type_code              => l_adr_value_type_code
14483   , p_transaction_coa_id           => l_adr_transaction_coa_id
14484   , p_accounting_coa_id            => l_adr_accounting_coa_id
14485   , p_adr_code                     => 'DIST_CCID'
14486   , p_adr_type_code                => 'S'
14487   , p_component_type               => l_component_type
14488   , p_component_code               => l_component_code
14489   , p_component_type_code          => l_component_type_code
14490   , p_component_appl_id            => l_component_appl_id
14491   , p_amb_context_code             => l_amb_context_code
14492   , p_side                         => 'NA'
14493   );
14494 
14495 
14496    --
14497    --
14498    END IF;
14499    --
14500    -- Bug 4922099
14504         (l_bflow_method_code = 'PRIOR_ENTRY')
14501    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
14502           (NVL(l_enc_upg_option, 'N') = 'O')
14503         ) AND
14505       )
14506    THEN
14507       IF
14508       --
14509       1 = 2
14510       --
14511       THEN
14512       xla_accounting_err_pkg.build_message
14513                                     (p_appli_s_name            => 'XLA'
14514                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
14515                                     ,p_token_1                 => 'LINE_NUMBER'
14516                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
14517                                     ,p_token_2                 => 'LINE_TYPE_NAME'
14518                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
14519                                                                              l_component_type
14520                                                                             ,l_component_code
14521                                                                             ,l_component_type_code
14522                                                                             ,l_component_appl_id
14523                                                                             ,l_amb_context_code
14524                                                                             ,l_entity_code
14525                                                                             ,l_event_class_code
14526                                                                            )
14527                                     ,p_token_3                 => 'OWNER'
14528                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
14529                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
14530                                                                           ,p_lookup_code    => l_component_type_code
14531                                                                          )
14532                                     ,p_token_4                 => 'PRODUCT_NAME'
14533                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
14534                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
14535                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
14536                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
14537                                     ,p_ae_header_id            =>  NULL
14538                                        );
14539 
14540         IF (C_LEVEL_ERROR>= g_log_level) THEN
14541                  trace
14542                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
14543                       ,p_level    => C_LEVEL_ERROR
14544                       ,p_module   => l_log_module);
14545         END IF;
14546       END IF;
14547    END IF;
14548    --
14549    --
14550    ------------------------------------------------------------------------------------------------
14551    -- 4219869 Business Flow
14552    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
14553    -- Prior Entry.  Currently, the following code is always generated.
14554    ------------------------------------------------------------------------------------------------
14555    XLA_AE_LINES_PKG.ValidateCurrentLine;
14556 
14557    ------------------------------------------------------------------------------------
14558    -- 4219869 Business Flow
14559    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
14560    ------------------------------------------------------------------------------------
14561    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
14562 
14563    ----------------------------------------------------------------------------------
14564    -- 4219869 Business Flow
14565    -- Update journal entry status -- Need to generate this within IF <condition>
14566    ----------------------------------------------------------------------------------
14567    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
14568          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
14569          ,p_balance_type_code => l_balance_type_code
14570          );
14571 
14572    -------------------------------------------------------------------------------------------
14573    -- 4262811 - Generate the Accrual Reversal lines
14574    -------------------------------------------------------------------------------------------
14575    BEGIN
14576       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
14577                               (g_array_event(p_event_id).array_value_num('header_index'));
14578       IF l_acc_rev_flag IS NULL THEN
14579          l_acc_rev_flag := 'N';
14580       END IF;
14581    EXCEPTION
14582       WHEN OTHERS THEN
14583          l_acc_rev_flag := 'N';
14584    END;
14585    --
14586    IF (l_acc_rev_flag = 'Y') THEN
14587 
14588        -- 4645092  ------------------------------------------------------------------------------
14589        -- To allow MPA report to determine if it should generate report process
14590        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
14591        ------------------------------------------------------------------------------------------
14592 
14593        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
14597    -- Bug 4922099
14594        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
14595    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
14596    -- call ADRs
14598    --
14599    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
14600         (NVL(l_actual_upg_option, 'N') = 'O') OR
14601         (NVL(l_enc_upg_option, 'N') = 'O')
14602       )
14603    THEN
14604    NULL;
14605    --
14606    --
14607    
14608   l_ccid := AcctDerRule_1(
14609            p_application_id           => p_application_id
14610          , p_ae_header_id             => l_ae_header_id 
14611 , p_source_1 => p_source_1
14612          , x_transaction_coa_id       => l_adr_transaction_coa_id
14613          , x_accounting_coa_id        => l_adr_accounting_coa_id
14614          , x_value_type_code          => l_adr_value_type_code
14615          , p_side                     => 'NA'
14616    );
14617 
14618    xla_ae_lines_pkg.set_ccid(
14619     p_code_combination_id          => l_ccid
14620   , p_value_type_code              => l_adr_value_type_code
14621   , p_transaction_coa_id           => l_adr_transaction_coa_id
14622   , p_accounting_coa_id            => l_adr_accounting_coa_id
14623   , p_adr_code                     => 'DIST_CCID'
14624   , p_adr_type_code                => 'S'
14625   , p_component_type               => l_component_type
14626   , p_component_code               => l_component_code
14627   , p_component_type_code          => l_component_type_code
14628   , p_component_appl_id            => l_component_appl_id
14629   , p_amb_context_code             => l_amb_context_code
14630   , p_side                         => 'NA'
14631   );
14632 
14633 
14634    --
14635    --
14636    END IF;
14637 
14638        --
14639        -- Update the line information that should be overwritten
14640        --
14641        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
14642                                          p_header_num   => 1);
14643        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
14644 
14645        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
14646 
14647        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
14648           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
14649        END IF;
14650 
14651       --
14652       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
14653       --
14654       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
14655           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
14656       ELSE
14657           ---------------------------------------------------------------------------------------------------
14658           -- 4262811a Switch Sign
14659           ---------------------------------------------------------------------------------------------------
14660           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
14661           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
14662                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
14663           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
14664                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
14665           -- 5132302
14666           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
14667                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
14668 
14669       END IF;
14670 
14671       -- 4955764
14672       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
14673       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
14674 
14675 
14676       XLA_AE_LINES_PKG.ValidateCurrentLine;
14677       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
14678 
14679       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
14680                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
14681                ,p_balance_type_code => l_balance_type_code);
14682 
14683    END IF;
14684 
14685    -----------------------------------------------------------------------------------------
14686    -- 4262811 Multiperiod Accounting
14687    -----------------------------------------------------------------------------------------
14688      -- No MPA option is assigned.
14689 
14690 
14691 END IF;
14692 END IF;
14693 --
14694 
14695 --
14696 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14697    trace
14698       (p_msg      => 'END of AcctLineType_29'
14699       ,p_level    => C_LEVEL_PROCEDURE
14700       ,p_module   => l_log_module);
14701 END IF;
14702 --
14703 EXCEPTION
14704   WHEN xla_exceptions_pkg.application_exception THEN
14705       RAISE;
14706   WHEN OTHERS THEN
14707        xla_exceptions_pkg.raise_message
14708            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_29');
14709 END AcctLineType_29;
14710 --
14711 
14712 ---------------------------------------
14713 --
14714 -- PRIVATE FUNCTION
14718 PROCEDURE AcctLineType_30 (
14715 --         AcctLineType_30
14716 --
14717 ---------------------------------------
14719   p_application_id        IN NUMBER
14720  ,p_event_id              IN NUMBER
14721  ,p_calculate_acctd_flag  IN VARCHAR2
14722  ,p_calculate_g_l_flag    IN VARCHAR2
14723  ,p_actual_flag           IN OUT VARCHAR2
14724  ,p_balance_type_code     OUT VARCHAR2
14725  ,p_gain_or_loss_ref      OUT VARCHAR2
14726  
14727 --Distribution GL Account
14728  , p_source_1            IN NUMBER
14729 --Distribution Source Type
14730  , p_source_7            IN VARCHAR2
14731 --Distribution Multi Fund Additional Entry
14732  , p_source_8            IN VARCHAR2
14733 --Distribution Line Identifier
14734  , p_source_9            IN NUMBER
14735 --Distribution Type
14736  , p_source_10            IN VARCHAR2
14737 --Exchange Rate
14738  , p_source_14            IN NUMBER
14739 --Exchange Rate Type
14740  , p_source_15            IN VARCHAR2
14741 --Receipt Applied To Application Identifier
14742  , p_source_17            IN NUMBER
14743 --Transaction Distribution Type
14744  , p_source_18            IN VARCHAR2
14745 --Transaction Entity Code
14746  , p_source_19            IN VARCHAR2
14747 --Transaction Distribution Identifier
14748  , p_source_20            IN NUMBER
14749 --Transaction Identifier
14750  , p_source_21            IN NUMBER
14751 --DIST_ENT_AMT_FROM
14752  , p_source_22            IN NUMBER
14753 --Applying Document Currency Code
14754  , p_source_23            IN VARCHAR2
14755 --Exchange Date
14756  , p_source_24            IN DATE
14757 --Accounting Amount
14758  , p_source_25            IN NUMBER
14759 --Distribution Party Identifier
14760  , p_source_26            IN NUMBER
14761 --Distribution Party Site Id
14762  , p_source_27            IN NUMBER
14763 --Distribution Party Type
14764  , p_source_28            IN VARCHAR2
14765 --Distribution Source Table
14766  , p_source_33            IN VARCHAR2
14767 )
14768 IS
14769 
14770 l_component_type              VARCHAR2(80);
14771 l_component_code              VARCHAR2(30);
14772 l_component_type_code         VARCHAR2(1);
14773 l_component_appl_id           INTEGER;
14774 l_amb_context_code            VARCHAR2(30);
14775 l_entity_code                 VARCHAR2(30);
14776 l_event_class_code            VARCHAR2(30);
14777 l_ae_header_id                NUMBER;
14778 l_event_type_code             VARCHAR2(30);
14779 l_line_definition_code        VARCHAR2(30);
14780 l_line_definition_owner_code  VARCHAR2(1);
14781 --
14782 -- adr variables
14783 l_segment                     VARCHAR2(30);
14784 l_ccid                        NUMBER;
14785 l_adr_transaction_coa_id      NUMBER;
14786 l_adr_accounting_coa_id       NUMBER;
14787 l_adr_flexfield_segment_code  VARCHAR2(30);
14788 l_adr_flex_value_set_id       NUMBER;
14789 l_adr_value_type_code         VARCHAR2(30);
14790 l_adr_value_combination_id    NUMBER;
14791 l_adr_value_segment_code      VARCHAR2(30);
14792 
14793 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
14794 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
14795 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
14796 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
14797 
14798 -- 4262811 Variables ------------------------------------------------------------------------------------------
14799 l_entered_amt_idx             NUMBER;
14800 l_accted_amt_idx              NUMBER;
14801 l_acc_rev_flag                VARCHAR2(1);
14802 l_accrual_line_num            NUMBER;
14803 l_tmp_amt                     NUMBER;
14804 l_acc_rev_natural_side_code   VARCHAR2(1);
14805 
14806 l_num_entries                 NUMBER;
14807 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
14808 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
14809 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
14810 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
14811 l_recog_line_1                NUMBER;
14812 l_recog_line_2                NUMBER;
14813 
14814 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
14815 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
14816 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
14817 
14818 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
14819 
14820 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
14821 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
14822 
14823 ---------------------------------------------------------------------------------------------------------------
14824 
14825 
14826 --
14827 -- bulk performance
14828 --
14829 l_balance_type_code           VARCHAR2(1);
14830 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
14831 l_log_module                  VARCHAR2(240);
14832 
14833 --
14834 -- Upgrade strategy
14835 --
14836 l_actual_upg_option           VARCHAR2(1);
14837 l_enc_upg_option           VARCHAR2(1);
14838 
14839 --
14840 BEGIN
14841 --
14842 IF g_log_enabled THEN
14843       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_30';
14844 END IF;
14845 --
14846 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
14847 
14848       trace
14852 
14849          (p_msg      => 'BEGIN of AcctLineType_30'
14850          ,p_level    => C_LEVEL_PROCEDURE
14851          ,p_module   => l_log_module);
14853 END IF;
14854 --
14855 l_component_type             := 'AMB_JLT';
14856 l_component_code             := 'RCT_FACTOR_BR';
14857 l_component_type_code        := 'S';
14858 l_component_appl_id          :=  222;
14859 l_amb_context_code           := 'DEFAULT';
14860 l_entity_code                := 'RECEIPTS';
14861 l_event_class_code           := 'RECEIPT';
14862 l_event_type_code            := 'RECEIPT_ALL';
14863 l_line_definition_owner_code := 'S';
14864 l_line_definition_code       := 'RCT_CASH_JLD';
14865 --
14866 l_balance_type_code          := 'A';
14867 l_segment                     := NULL;
14868 l_ccid                        := NULL;
14869 l_adr_transaction_coa_id      := NULL;
14870 l_adr_accounting_coa_id       := NULL;
14871 l_adr_flexfield_segment_code  := NULL;
14872 l_adr_flex_value_set_id       := NULL;
14873 l_adr_value_type_code         := NULL;
14874 l_adr_value_combination_id    := NULL;
14875 l_adr_value_segment_code      := NULL;
14876 
14877 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
14878 l_bflow_class_code           := '';    -- 4219869 Business Flow
14879 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
14880 l_budgetary_control_flag     := 'N';
14881 
14882 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
14883 l_bflow_applied_to_amt       := NULL; -- 5132302
14884 l_entered_amt_idx            := NULL;          -- 4262811
14885 l_accted_amt_idx             := NULL;          -- 4262811
14886 l_acc_rev_flag               := NULL;          -- 4262811
14887 l_accrual_line_num           := NULL;          -- 4262811
14888 l_tmp_amt                    := NULL;          -- 4262811
14889 --
14890  
14891 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
14892     l_balance_type_code <> 'B' THEN
14893 IF NVL(p_source_7,'
14894 ') =  'FACTOR' AND 
14895 NVL(p_source_33,'
14896 ') =  'RA' AND 
14897 NVL(p_source_8,'
14898 ') =  'N'
14899  THEN 
14900 
14901    --
14902    XLA_AE_LINES_PKG.SetNewLine;
14903 
14904    p_balance_type_code          := l_balance_type_code;
14905    -- set the flag so later we will know whether the gain loss line needs to be created
14906    
14907    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
14908      p_actual_flag :='A';
14909    END IF;
14910 
14911    --
14912    -- bulk performance
14913    --
14914    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
14915                                       p_header_num   => 0); -- 4262811
14916    --
14917    -- set accounting line options
14918    --
14919    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
14920            p_natural_side_code          => 'C'
14921          , p_gain_or_loss_flag          => 'N'
14922          , p_gl_transfer_mode_code      => 'S'
14923          , p_acct_entry_type_code       => 'A'
14924          , p_switch_side_flag           => 'Y'
14925          , p_merge_duplicate_code       => 'A'
14926          );
14927    --
14928    l_acc_rev_natural_side_code := 'D';  -- 4262811
14929    -- 
14930    --
14931    -- set accounting line type info
14932    --
14933    xla_ae_lines_pkg.SetAcctLineType
14934       (p_component_type             => l_component_type
14935       ,p_event_type_code            => l_event_type_code
14936       ,p_line_definition_owner_code => l_line_definition_owner_code
14937       ,p_line_definition_code       => l_line_definition_code
14938       ,p_accounting_line_code       => l_component_code
14939       ,p_accounting_line_type_code  => l_component_type_code
14940       ,p_accounting_line_appl_id    => l_component_appl_id
14941       ,p_amb_context_code           => l_amb_context_code
14942       ,p_entity_code                => l_entity_code
14943       ,p_event_class_code           => l_event_class_code);
14944    --
14945    -- set accounting class
14946    --
14947    xla_ae_lines_pkg.SetAcctClass(
14948            p_accounting_class_code  => 'FAC_BR'
14949          , p_ae_header_id           => l_ae_header_id
14950          );
14951 
14952    --
14953    -- set rounding class
14954    --
14955    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
14956                       'RECEIVABLE';
14957 
14958    --
14959    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
14960    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
14961    --
14962    -- bulk performance
14963    --
14964    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
14965 
14966    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
14967       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
14968 
14969    -- 4955764
14970    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
14971       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
14972 
14973    -- 4458381 Public Sector Enh
14974    
14975    --
14976    -- set accounting attributes for the line type
14977    --
14978    l_entered_amt_idx := 8;
14979    l_accted_amt_idx  := 13;
14980    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
14984    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
14981    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
14982    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
14983    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
14985    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
14986    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
14987    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
14988    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
14989    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
14990    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
14991    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
14992    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
14993    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
14994    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
14995    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
14996    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
14997    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
14998    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
14999    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
15000    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
15001    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
15002    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
15003    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
15004    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
15005    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
15006    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
15007    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
15008    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
15009    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
15010    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
15011    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
15012    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
15013 
15014    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
15015    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
15016 
15017    ---------------------------------------------------------------------------------------------------------------
15018    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
15019    ---------------------------------------------------------------------------------------------------------------
15020    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
15021 
15022    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
15023    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
15024 
15025    IF xla_accounting_cache_pkg.GetValueChar
15026          (p_source_code         => 'LEDGER_CATEGORY_CODE'
15027          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
15028    AND l_bflow_method_code = 'PRIOR_ENTRY'
15029 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
15030    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
15031          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
15032        )
15033    THEN
15034          xla_ae_lines_pkg.BflowUpgEntry
15035            (p_business_method_code    => l_bflow_method_code
15036            ,p_business_class_code     => l_bflow_class_code
15037            ,p_balance_type            => l_balance_type_code);
15038    ELSE
15039       NULL;
15040 -- No business flow processing for business flow method of NONE.
15041    END IF;
15042 
15043    --
15044    -- call analytical criteria
15045    --
15046    
15047    --
15048    -- call description
15049    --
15050    -- No description or it is inherited.
15051    --
15052    -- call ADRs
15053    -- Bug 4922099
15054    --
15055    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
15056         (NVL(l_actual_upg_option, 'N') = 'O') OR
15057         (NVL(l_enc_upg_option, 'N') = 'O')
15058       )
15059    THEN
15060    NULL;
15061    --
15062    --
15063    
15064   l_ccid := AcctDerRule_1(
15065            p_application_id           => p_application_id
15066          , p_ae_header_id             => l_ae_header_id 
15067 , p_source_1 => p_source_1
15068          , x_transaction_coa_id       => l_adr_transaction_coa_id
15069          , x_accounting_coa_id        => l_adr_accounting_coa_id
15070          , x_value_type_code          => l_adr_value_type_code
15071          , p_side                     => 'NA'
15072    );
15073 
15074    xla_ae_lines_pkg.set_ccid(
15075     p_code_combination_id          => l_ccid
15076   , p_value_type_code              => l_adr_value_type_code
15077   , p_transaction_coa_id           => l_adr_transaction_coa_id
15078   , p_accounting_coa_id            => l_adr_accounting_coa_id
15079   , p_adr_code                     => 'DIST_CCID'
15080   , p_adr_type_code                => 'S'
15081   , p_component_type               => l_component_type
15082   , p_component_code               => l_component_code
15083   , p_component_type_code          => l_component_type_code
15084   , p_component_appl_id            => l_component_appl_id
15088 
15085   , p_amb_context_code             => l_amb_context_code
15086   , p_side                         => 'NA'
15087   );
15089 
15090    --
15091    --
15092    END IF;
15093    --
15094    -- Bug 4922099
15095    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
15096           (NVL(l_enc_upg_option, 'N') = 'O')
15097         ) AND
15098         (l_bflow_method_code = 'PRIOR_ENTRY')
15099       )
15100    THEN
15101       IF
15102       --
15103       1 = 2
15104       --
15105       THEN
15106       xla_accounting_err_pkg.build_message
15107                                     (p_appli_s_name            => 'XLA'
15108                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
15109                                     ,p_token_1                 => 'LINE_NUMBER'
15110                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
15111                                     ,p_token_2                 => 'LINE_TYPE_NAME'
15112                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
15113                                                                              l_component_type
15114                                                                             ,l_component_code
15115                                                                             ,l_component_type_code
15116                                                                             ,l_component_appl_id
15117                                                                             ,l_amb_context_code
15118                                                                             ,l_entity_code
15119                                                                             ,l_event_class_code
15120                                                                            )
15121                                     ,p_token_3                 => 'OWNER'
15122                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
15123                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
15124                                                                           ,p_lookup_code    => l_component_type_code
15125                                                                          )
15126                                     ,p_token_4                 => 'PRODUCT_NAME'
15127                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
15128                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
15129                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
15130                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
15131                                     ,p_ae_header_id            =>  NULL
15132                                        );
15133 
15134         IF (C_LEVEL_ERROR>= g_log_level) THEN
15135                  trace
15136                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
15137                       ,p_level    => C_LEVEL_ERROR
15138                       ,p_module   => l_log_module);
15139         END IF;
15140       END IF;
15141    END IF;
15142    --
15143    --
15144    ------------------------------------------------------------------------------------------------
15145    -- 4219869 Business Flow
15146    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
15147    -- Prior Entry.  Currently, the following code is always generated.
15148    ------------------------------------------------------------------------------------------------
15149    XLA_AE_LINES_PKG.ValidateCurrentLine;
15150 
15151    ------------------------------------------------------------------------------------
15152    -- 4219869 Business Flow
15153    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
15154    ------------------------------------------------------------------------------------
15155    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
15156 
15157    ----------------------------------------------------------------------------------
15158    -- 4219869 Business Flow
15159    -- Update journal entry status -- Need to generate this within IF <condition>
15160    ----------------------------------------------------------------------------------
15161    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
15162          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
15163          ,p_balance_type_code => l_balance_type_code
15164          );
15165 
15166    -------------------------------------------------------------------------------------------
15167    -- 4262811 - Generate the Accrual Reversal lines
15168    -------------------------------------------------------------------------------------------
15169    BEGIN
15170       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
15171                               (g_array_event(p_event_id).array_value_num('header_index'));
15172       IF l_acc_rev_flag IS NULL THEN
15173          l_acc_rev_flag := 'N';
15174       END IF;
15175    EXCEPTION
15176       WHEN OTHERS THEN
15177          l_acc_rev_flag := 'N';
15178    END;
15179    --
15180    IF (l_acc_rev_flag = 'Y') THEN
15181 
15182        -- 4645092  ------------------------------------------------------------------------------
15186 
15183        -- To allow MPA report to determine if it should generate report process
15184        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
15185        ------------------------------------------------------------------------------------------
15187        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
15188        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
15189    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
15190    -- call ADRs
15191    -- Bug 4922099
15192    --
15193    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
15194         (NVL(l_actual_upg_option, 'N') = 'O') OR
15195         (NVL(l_enc_upg_option, 'N') = 'O')
15196       )
15197    THEN
15198    NULL;
15199    --
15200    --
15201    
15202   l_ccid := AcctDerRule_1(
15203            p_application_id           => p_application_id
15204          , p_ae_header_id             => l_ae_header_id 
15205 , p_source_1 => p_source_1
15206          , x_transaction_coa_id       => l_adr_transaction_coa_id
15207          , x_accounting_coa_id        => l_adr_accounting_coa_id
15208          , x_value_type_code          => l_adr_value_type_code
15209          , p_side                     => 'NA'
15210    );
15211 
15212    xla_ae_lines_pkg.set_ccid(
15213     p_code_combination_id          => l_ccid
15214   , p_value_type_code              => l_adr_value_type_code
15215   , p_transaction_coa_id           => l_adr_transaction_coa_id
15216   , p_accounting_coa_id            => l_adr_accounting_coa_id
15217   , p_adr_code                     => 'DIST_CCID'
15218   , p_adr_type_code                => 'S'
15219   , p_component_type               => l_component_type
15220   , p_component_code               => l_component_code
15221   , p_component_type_code          => l_component_type_code
15222   , p_component_appl_id            => l_component_appl_id
15223   , p_amb_context_code             => l_amb_context_code
15224   , p_side                         => 'NA'
15225   );
15226 
15227 
15228    --
15229    --
15230    END IF;
15231 
15232        --
15233        -- Update the line information that should be overwritten
15234        --
15235        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
15236                                          p_header_num   => 1);
15237        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
15238 
15239        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
15240 
15241        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
15242           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
15243        END IF;
15244 
15245       --
15246       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
15247       --
15248       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
15249           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
15250       ELSE
15251           ---------------------------------------------------------------------------------------------------
15252           -- 4262811a Switch Sign
15253           ---------------------------------------------------------------------------------------------------
15254           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
15255           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
15256                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15257           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
15258                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15259           -- 5132302
15260           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
15261                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15262 
15263       END IF;
15264 
15265       -- 4955764
15266       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
15267       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
15268 
15269 
15270       XLA_AE_LINES_PKG.ValidateCurrentLine;
15271       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
15272 
15273       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
15274                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
15275                ,p_balance_type_code => l_balance_type_code);
15276 
15277    END IF;
15278 
15279    -----------------------------------------------------------------------------------------
15280    -- 4262811 Multiperiod Accounting
15281    -----------------------------------------------------------------------------------------
15282      -- No MPA option is assigned.
15283 
15284 
15285 END IF;
15286 END IF;
15287 --
15288 
15289 --
15290 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15291    trace
15292       (p_msg      => 'END of AcctLineType_30'
15293       ,p_level    => C_LEVEL_PROCEDURE
15294       ,p_module   => l_log_module);
15295 END IF;
15296 --
15297 EXCEPTION
15298   WHEN xla_exceptions_pkg.application_exception THEN
15302            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_30');
15299       RAISE;
15300   WHEN OTHERS THEN
15301        xla_exceptions_pkg.raise_message
15303 END AcctLineType_30;
15304 --
15305 
15306 ---------------------------------------
15307 --
15308 -- PRIVATE FUNCTION
15309 --         AcctLineType_31
15310 --
15311 ---------------------------------------
15312 PROCEDURE AcctLineType_31 (
15313   p_application_id        IN NUMBER
15314  ,p_event_id              IN NUMBER
15315  ,p_calculate_acctd_flag  IN VARCHAR2
15316  ,p_calculate_g_l_flag    IN VARCHAR2
15317  ,p_actual_flag           IN OUT VARCHAR2
15318  ,p_balance_type_code     OUT VARCHAR2
15319  ,p_gain_or_loss_ref      OUT VARCHAR2
15320  
15321 --Distribution GL Account
15322  , p_source_1            IN NUMBER
15323 --Distribution Source Type
15324  , p_source_7            IN VARCHAR2
15325 --Distribution Multi Fund Additional Entry
15326  , p_source_8            IN VARCHAR2
15327 --Distribution Line Identifier
15328  , p_source_9            IN NUMBER
15329 --Distribution Type
15330  , p_source_10            IN VARCHAR2
15331 --Exchange Rate
15332  , p_source_14            IN NUMBER
15333 --Exchange Rate Type
15334  , p_source_15            IN VARCHAR2
15335 --Applied To Document Accounting Amount
15336  , p_source_16            IN NUMBER
15337 --Receipt Applied To Application Identifier
15338  , p_source_17            IN NUMBER
15339 --Transaction Distribution Type
15340  , p_source_18            IN VARCHAR2
15341 --Transaction Entity Code
15342  , p_source_19            IN VARCHAR2
15343 --Transaction Distribution Identifier
15344  , p_source_20            IN NUMBER
15345 --Transaction Identifier
15346  , p_source_21            IN NUMBER
15347 --DIST_ENT_AMT_FROM
15348  , p_source_22            IN NUMBER
15349 --Applying Document Currency Code
15350  , p_source_23            IN VARCHAR2
15351 --Exchange Date
15352  , p_source_24            IN DATE
15353 --Distribution Party Identifier
15354  , p_source_26            IN NUMBER
15355 --Distribution Party Site Id
15356  , p_source_27            IN NUMBER
15357 --Distribution Party Type
15358  , p_source_28            IN VARCHAR2
15359 --Receivable Activity Type
15360  , p_source_32            IN VARCHAR2
15361 )
15362 IS
15363 
15364 l_component_type              VARCHAR2(80);
15365 l_component_code              VARCHAR2(30);
15366 l_component_type_code         VARCHAR2(1);
15367 l_component_appl_id           INTEGER;
15368 l_amb_context_code            VARCHAR2(30);
15369 l_entity_code                 VARCHAR2(30);
15370 l_event_class_code            VARCHAR2(30);
15371 l_ae_header_id                NUMBER;
15372 l_event_type_code             VARCHAR2(30);
15373 l_line_definition_code        VARCHAR2(30);
15374 l_line_definition_owner_code  VARCHAR2(1);
15375 --
15376 -- adr variables
15377 l_segment                     VARCHAR2(30);
15378 l_ccid                        NUMBER;
15379 l_adr_transaction_coa_id      NUMBER;
15380 l_adr_accounting_coa_id       NUMBER;
15381 l_adr_flexfield_segment_code  VARCHAR2(30);
15382 l_adr_flex_value_set_id       NUMBER;
15383 l_adr_value_type_code         VARCHAR2(30);
15384 l_adr_value_combination_id    NUMBER;
15385 l_adr_value_segment_code      VARCHAR2(30);
15386 
15387 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
15388 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
15389 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
15390 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
15391 
15392 -- 4262811 Variables ------------------------------------------------------------------------------------------
15393 l_entered_amt_idx             NUMBER;
15394 l_accted_amt_idx              NUMBER;
15395 l_acc_rev_flag                VARCHAR2(1);
15396 l_accrual_line_num            NUMBER;
15397 l_tmp_amt                     NUMBER;
15398 l_acc_rev_natural_side_code   VARCHAR2(1);
15399 
15400 l_num_entries                 NUMBER;
15401 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
15402 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
15403 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
15404 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
15405 l_recog_line_1                NUMBER;
15406 l_recog_line_2                NUMBER;
15407 
15408 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
15409 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
15410 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
15411 
15412 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
15413 
15414 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
15415 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
15416 
15417 ---------------------------------------------------------------------------------------------------------------
15418 
15419 
15420 --
15421 -- bulk performance
15422 --
15423 l_balance_type_code           VARCHAR2(1);
15424 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
15425 l_log_module                  VARCHAR2(240);
15426 
15427 --
15428 -- Upgrade strategy
15429 --
15430 l_actual_upg_option           VARCHAR2(1);
15434 BEGIN
15431 l_enc_upg_option           VARCHAR2(1);
15432 
15433 --
15435 --
15436 IF g_log_enabled THEN
15437       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_31';
15438 END IF;
15439 --
15440 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15441 
15442       trace
15443          (p_msg      => 'BEGIN of AcctLineType_31'
15444          ,p_level    => C_LEVEL_PROCEDURE
15445          ,p_module   => l_log_module);
15446 
15447 END IF;
15448 --
15449 l_component_type             := 'AMB_JLT';
15450 l_component_code             := 'RCT_PMT_NET';
15451 l_component_type_code        := 'S';
15452 l_component_appl_id          :=  222;
15453 l_amb_context_code           := 'DEFAULT';
15454 l_entity_code                := 'RECEIPTS';
15455 l_event_class_code           := 'RECEIPT';
15456 l_event_type_code            := 'RECEIPT_ALL';
15457 l_line_definition_owner_code := 'S';
15458 l_line_definition_code       := 'RCT_CASH_JLD';
15459 --
15460 l_balance_type_code          := 'A';
15461 l_segment                     := NULL;
15462 l_ccid                        := NULL;
15463 l_adr_transaction_coa_id      := NULL;
15464 l_adr_accounting_coa_id       := NULL;
15465 l_adr_flexfield_segment_code  := NULL;
15466 l_adr_flex_value_set_id       := NULL;
15467 l_adr_value_type_code         := NULL;
15468 l_adr_value_combination_id    := NULL;
15469 l_adr_value_segment_code      := NULL;
15470 
15471 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
15472 l_bflow_class_code           := '';    -- 4219869 Business Flow
15473 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
15474 l_budgetary_control_flag     := 'N';
15475 
15476 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
15477 l_bflow_applied_to_amt       := NULL; -- 5132302
15478 l_entered_amt_idx            := NULL;          -- 4262811
15479 l_accted_amt_idx             := NULL;          -- 4262811
15480 l_acc_rev_flag               := NULL;          -- 4262811
15481 l_accrual_line_num           := NULL;          -- 4262811
15482 l_tmp_amt                    := NULL;          -- 4262811
15483 --
15484  
15485 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
15486     l_balance_type_code <> 'B' THEN
15487 IF (NVL(p_source_7,'
15488 ') =  'OTHER_ACC' OR 
15489 NVL(p_source_7,'
15490 ') =  'ACTIVITY') AND 
15491 NVL(p_source_32,'
15492 ') =  'NETTING' AND 
15493 NVL(p_source_8,'
15494 ') =  'N'
15495  THEN 
15496 
15497    --
15498    XLA_AE_LINES_PKG.SetNewLine;
15499 
15500    p_balance_type_code          := l_balance_type_code;
15501    -- set the flag so later we will know whether the gain loss line needs to be created
15502    
15503    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
15504      p_actual_flag :='A';
15505    END IF;
15506 
15507    --
15508    -- bulk performance
15509    --
15510    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
15511                                       p_header_num   => 0); -- 4262811
15512    --
15513    -- set accounting line options
15514    --
15515    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
15516            p_natural_side_code          => 'C'
15517          , p_gain_or_loss_flag          => 'N'
15518          , p_gl_transfer_mode_code      => 'S'
15519          , p_acct_entry_type_code       => 'A'
15520          , p_switch_side_flag           => 'Y'
15521          , p_merge_duplicate_code       => 'A'
15522          );
15523    --
15524    l_acc_rev_natural_side_code := 'D';  -- 4262811
15525    -- 
15526    --
15527    -- set accounting line type info
15528    --
15529    xla_ae_lines_pkg.SetAcctLineType
15530       (p_component_type             => l_component_type
15531       ,p_event_type_code            => l_event_type_code
15532       ,p_line_definition_owner_code => l_line_definition_owner_code
15533       ,p_line_definition_code       => l_line_definition_code
15534       ,p_accounting_line_code       => l_component_code
15535       ,p_accounting_line_type_code  => l_component_type_code
15536       ,p_accounting_line_appl_id    => l_component_appl_id
15537       ,p_amb_context_code           => l_amb_context_code
15538       ,p_entity_code                => l_entity_code
15539       ,p_event_class_code           => l_event_class_code);
15540    --
15541    -- set accounting class
15542    --
15543    xla_ae_lines_pkg.SetAcctClass(
15544            p_accounting_class_code  => 'PMT_NET'
15545          , p_ae_header_id           => l_ae_header_id
15546          );
15547 
15548    --
15549    -- set rounding class
15550    --
15551    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
15552                       'RECEIVABLE';
15553 
15554    --
15555    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
15556    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
15557    --
15558    -- bulk performance
15559    --
15560    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
15561 
15562    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
15563       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
15564 
15565    -- 4955764
15566    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
15570    
15567       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
15568 
15569    -- 4458381 Public Sector Enh
15571    --
15572    -- set accounting attributes for the line type
15573    --
15574    l_entered_amt_idx := 8;
15575    l_accted_amt_idx  := 13;
15576    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
15577    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
15578    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
15579    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
15580    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
15581    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
15582    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
15583    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
15584    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
15585    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
15586    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
15587    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
15588    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
15589    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
15590    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
15591    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
15592    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
15593    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
15594    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
15595    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
15596    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
15597    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
15598    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
15599    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
15600    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
15601    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
15602    l_rec_acct_attrs.array_num_value(13)  := p_source_16;
15603    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
15604    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
15605    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
15606    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
15607    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
15608    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
15609 
15610    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
15611    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
15612 
15613    ---------------------------------------------------------------------------------------------------------------
15614    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
15615    ---------------------------------------------------------------------------------------------------------------
15616    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
15617 
15618    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
15619    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
15620 
15621    IF xla_accounting_cache_pkg.GetValueChar
15622          (p_source_code         => 'LEDGER_CATEGORY_CODE'
15623          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
15624    AND l_bflow_method_code = 'PRIOR_ENTRY'
15625 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
15626    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
15627          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
15628        )
15629    THEN
15630          xla_ae_lines_pkg.BflowUpgEntry
15631            (p_business_method_code    => l_bflow_method_code
15632            ,p_business_class_code     => l_bflow_class_code
15633            ,p_balance_type            => l_balance_type_code);
15634    ELSE
15635       NULL;
15636 -- No business flow processing for business flow method of NONE.
15637    END IF;
15638 
15639    --
15640    -- call analytical criteria
15641    --
15642    
15643    --
15644    -- call description
15645    --
15646    -- No description or it is inherited.
15647    --
15648    -- call ADRs
15649    -- Bug 4922099
15650    --
15651    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
15652         (NVL(l_actual_upg_option, 'N') = 'O') OR
15653         (NVL(l_enc_upg_option, 'N') = 'O')
15654       )
15655    THEN
15656    NULL;
15657    --
15658    --
15659    
15660   l_ccid := AcctDerRule_1(
15661            p_application_id           => p_application_id
15662          , p_ae_header_id             => l_ae_header_id 
15663 , p_source_1 => p_source_1
15664          , x_transaction_coa_id       => l_adr_transaction_coa_id
15665          , x_accounting_coa_id        => l_adr_accounting_coa_id
15666          , x_value_type_code          => l_adr_value_type_code
15667          , p_side                     => 'NA'
15668    );
15669 
15670    xla_ae_lines_pkg.set_ccid(
15671     p_code_combination_id          => l_ccid
15672   , p_value_type_code              => l_adr_value_type_code
15673   , p_transaction_coa_id           => l_adr_transaction_coa_id
15674   , p_accounting_coa_id            => l_adr_accounting_coa_id
15675   , p_adr_code                     => 'DIST_CCID'
15679   , p_component_type_code          => l_component_type_code
15676   , p_adr_type_code                => 'S'
15677   , p_component_type               => l_component_type
15678   , p_component_code               => l_component_code
15680   , p_component_appl_id            => l_component_appl_id
15681   , p_amb_context_code             => l_amb_context_code
15682   , p_side                         => 'NA'
15683   );
15684 
15685 
15686    --
15687    --
15688    END IF;
15689    --
15690    -- Bug 4922099
15691    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
15692           (NVL(l_enc_upg_option, 'N') = 'O')
15693         ) AND
15694         (l_bflow_method_code = 'PRIOR_ENTRY')
15695       )
15696    THEN
15697       IF
15698       --
15699       1 = 2
15700       --
15701       THEN
15702       xla_accounting_err_pkg.build_message
15703                                     (p_appli_s_name            => 'XLA'
15704                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
15705                                     ,p_token_1                 => 'LINE_NUMBER'
15706                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
15707                                     ,p_token_2                 => 'LINE_TYPE_NAME'
15708                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
15709                                                                              l_component_type
15710                                                                             ,l_component_code
15711                                                                             ,l_component_type_code
15712                                                                             ,l_component_appl_id
15713                                                                             ,l_amb_context_code
15714                                                                             ,l_entity_code
15715                                                                             ,l_event_class_code
15716                                                                            )
15717                                     ,p_token_3                 => 'OWNER'
15718                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
15719                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
15720                                                                           ,p_lookup_code    => l_component_type_code
15721                                                                          )
15722                                     ,p_token_4                 => 'PRODUCT_NAME'
15723                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
15724                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
15725                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
15726                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
15727                                     ,p_ae_header_id            =>  NULL
15728                                        );
15729 
15730         IF (C_LEVEL_ERROR>= g_log_level) THEN
15731                  trace
15732                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
15733                       ,p_level    => C_LEVEL_ERROR
15734                       ,p_module   => l_log_module);
15735         END IF;
15736       END IF;
15737    END IF;
15738    --
15739    --
15740    ------------------------------------------------------------------------------------------------
15741    -- 4219869 Business Flow
15742    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
15743    -- Prior Entry.  Currently, the following code is always generated.
15744    ------------------------------------------------------------------------------------------------
15745    XLA_AE_LINES_PKG.ValidateCurrentLine;
15746 
15747    ------------------------------------------------------------------------------------
15748    -- 4219869 Business Flow
15749    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
15750    ------------------------------------------------------------------------------------
15751    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
15752 
15753    ----------------------------------------------------------------------------------
15754    -- 4219869 Business Flow
15755    -- Update journal entry status -- Need to generate this within IF <condition>
15756    ----------------------------------------------------------------------------------
15757    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
15758          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
15759          ,p_balance_type_code => l_balance_type_code
15760          );
15761 
15762    -------------------------------------------------------------------------------------------
15763    -- 4262811 - Generate the Accrual Reversal lines
15764    -------------------------------------------------------------------------------------------
15765    BEGIN
15766       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
15767                               (g_array_event(p_event_id).array_value_num('header_index'));
15768       IF l_acc_rev_flag IS NULL THEN
15769          l_acc_rev_flag := 'N';
15770       END IF;
15774    END;
15771    EXCEPTION
15772       WHEN OTHERS THEN
15773          l_acc_rev_flag := 'N';
15775    --
15776    IF (l_acc_rev_flag = 'Y') THEN
15777 
15778        -- 4645092  ------------------------------------------------------------------------------
15779        -- To allow MPA report to determine if it should generate report process
15780        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
15781        ------------------------------------------------------------------------------------------
15782 
15783        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
15784        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
15785    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
15786    -- call ADRs
15787    -- Bug 4922099
15788    --
15789    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
15790         (NVL(l_actual_upg_option, 'N') = 'O') OR
15791         (NVL(l_enc_upg_option, 'N') = 'O')
15792       )
15793    THEN
15794    NULL;
15795    --
15796    --
15797    
15798   l_ccid := AcctDerRule_1(
15799            p_application_id           => p_application_id
15800          , p_ae_header_id             => l_ae_header_id 
15801 , p_source_1 => p_source_1
15802          , x_transaction_coa_id       => l_adr_transaction_coa_id
15803          , x_accounting_coa_id        => l_adr_accounting_coa_id
15804          , x_value_type_code          => l_adr_value_type_code
15805          , p_side                     => 'NA'
15806    );
15807 
15808    xla_ae_lines_pkg.set_ccid(
15809     p_code_combination_id          => l_ccid
15810   , p_value_type_code              => l_adr_value_type_code
15811   , p_transaction_coa_id           => l_adr_transaction_coa_id
15812   , p_accounting_coa_id            => l_adr_accounting_coa_id
15813   , p_adr_code                     => 'DIST_CCID'
15814   , p_adr_type_code                => 'S'
15815   , p_component_type               => l_component_type
15816   , p_component_code               => l_component_code
15817   , p_component_type_code          => l_component_type_code
15818   , p_component_appl_id            => l_component_appl_id
15819   , p_amb_context_code             => l_amb_context_code
15820   , p_side                         => 'NA'
15821   );
15822 
15823 
15824    --
15825    --
15826    END IF;
15827 
15828        --
15829        -- Update the line information that should be overwritten
15830        --
15831        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
15832                                          p_header_num   => 1);
15833        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
15834 
15835        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
15836 
15837        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
15838           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
15839        END IF;
15840 
15841       --
15842       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
15843       --
15844       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
15845           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
15846       ELSE
15847           ---------------------------------------------------------------------------------------------------
15848           -- 4262811a Switch Sign
15849           ---------------------------------------------------------------------------------------------------
15850           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
15851           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
15852                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15853           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
15854                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15855           -- 5132302
15856           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
15857                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
15858 
15859       END IF;
15860 
15861       -- 4955764
15862       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
15863       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
15864 
15865 
15866       XLA_AE_LINES_PKG.ValidateCurrentLine;
15867       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
15868 
15869       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
15870                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
15871                ,p_balance_type_code => l_balance_type_code);
15872 
15873    END IF;
15874 
15875    -----------------------------------------------------------------------------------------
15876    -- 4262811 Multiperiod Accounting
15877    -----------------------------------------------------------------------------------------
15878      -- No MPA option is assigned.
15879 
15880 
15881 END IF;
15882 END IF;
15883 --
15884 
15885 --
15889       ,p_level    => C_LEVEL_PROCEDURE
15886 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
15887    trace
15888       (p_msg      => 'END of AcctLineType_31'
15890       ,p_module   => l_log_module);
15891 END IF;
15892 --
15893 EXCEPTION
15894   WHEN xla_exceptions_pkg.application_exception THEN
15895       RAISE;
15896   WHEN OTHERS THEN
15897        xla_exceptions_pkg.raise_message
15898            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_31');
15899 END AcctLineType_31;
15900 --
15901 
15902 ---------------------------------------
15903 --
15904 -- PRIVATE FUNCTION
15905 --         AcctLineType_32
15906 --
15907 ---------------------------------------
15908 PROCEDURE AcctLineType_32 (
15909   p_application_id        IN NUMBER
15910  ,p_event_id              IN NUMBER
15911  ,p_calculate_acctd_flag  IN VARCHAR2
15912  ,p_calculate_g_l_flag    IN VARCHAR2
15913  ,p_actual_flag           IN OUT VARCHAR2
15914  ,p_balance_type_code     OUT VARCHAR2
15915  ,p_gain_or_loss_ref      OUT VARCHAR2
15916  
15917 --Distribution GL Account
15918  , p_source_1            IN NUMBER
15919 --Distribution Source Type
15920  , p_source_7            IN VARCHAR2
15921 --Distribution Multi Fund Additional Entry
15922  , p_source_8            IN VARCHAR2
15923 --Distribution Line Identifier
15924  , p_source_9            IN NUMBER
15925 --Distribution Type
15926  , p_source_10            IN VARCHAR2
15927 --Exchange Rate
15928  , p_source_14            IN NUMBER
15929 --Exchange Rate Type
15930  , p_source_15            IN VARCHAR2
15931 --Receipt Applied To Application Identifier
15932  , p_source_17            IN NUMBER
15933 --Transaction Distribution Type
15934  , p_source_18            IN VARCHAR2
15935 --Transaction Entity Code
15936  , p_source_19            IN VARCHAR2
15937 --Transaction Distribution Identifier
15938  , p_source_20            IN NUMBER
15939 --Transaction Identifier
15940  , p_source_21            IN NUMBER
15941 --DIST_ENT_AMT_FROM
15942  , p_source_22            IN NUMBER
15943 --Applying Document Currency Code
15944  , p_source_23            IN VARCHAR2
15945 --Exchange Date
15946  , p_source_24            IN DATE
15947 --Accounting Amount
15948  , p_source_25            IN NUMBER
15949 --Distribution Party Identifier
15950  , p_source_26            IN NUMBER
15951 --Distribution Party Site Id
15952  , p_source_27            IN NUMBER
15953 --Distribution Party Type
15954  , p_source_28            IN VARCHAR2
15955 --Receivable Activity Type
15956  , p_source_32            IN VARCHAR2
15957 )
15958 IS
15959 
15960 l_component_type              VARCHAR2(80);
15961 l_component_code              VARCHAR2(30);
15962 l_component_type_code         VARCHAR2(1);
15963 l_component_appl_id           INTEGER;
15964 l_amb_context_code            VARCHAR2(30);
15965 l_entity_code                 VARCHAR2(30);
15966 l_event_class_code            VARCHAR2(30);
15967 l_ae_header_id                NUMBER;
15968 l_event_type_code             VARCHAR2(30);
15969 l_line_definition_code        VARCHAR2(30);
15970 l_line_definition_owner_code  VARCHAR2(1);
15971 --
15972 -- adr variables
15973 l_segment                     VARCHAR2(30);
15974 l_ccid                        NUMBER;
15975 l_adr_transaction_coa_id      NUMBER;
15976 l_adr_accounting_coa_id       NUMBER;
15977 l_adr_flexfield_segment_code  VARCHAR2(30);
15978 l_adr_flex_value_set_id       NUMBER;
15979 l_adr_value_type_code         VARCHAR2(30);
15980 l_adr_value_combination_id    NUMBER;
15981 l_adr_value_segment_code      VARCHAR2(30);
15982 
15983 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
15984 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
15985 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
15986 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
15987 
15988 -- 4262811 Variables ------------------------------------------------------------------------------------------
15989 l_entered_amt_idx             NUMBER;
15990 l_accted_amt_idx              NUMBER;
15991 l_acc_rev_flag                VARCHAR2(1);
15992 l_accrual_line_num            NUMBER;
15993 l_tmp_amt                     NUMBER;
15994 l_acc_rev_natural_side_code   VARCHAR2(1);
15995 
15996 l_num_entries                 NUMBER;
15997 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
15998 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
15999 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
16000 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
16001 l_recog_line_1                NUMBER;
16002 l_recog_line_2                NUMBER;
16003 
16004 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
16005 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
16006 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
16007 
16008 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
16009 
16010 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
16011 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
16012 
16013 ---------------------------------------------------------------------------------------------------------------
16014 
16015 
16016 --
16017 -- bulk performance
16018 --
16019 l_balance_type_code           VARCHAR2(1);
16023 --
16020 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
16021 l_log_module                  VARCHAR2(240);
16022 
16024 -- Upgrade strategy
16025 --
16026 l_actual_upg_option           VARCHAR2(1);
16027 l_enc_upg_option           VARCHAR2(1);
16028 
16029 --
16030 BEGIN
16031 --
16032 IF g_log_enabled THEN
16033       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_32';
16034 END IF;
16035 --
16036 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16037 
16038       trace
16039          (p_msg      => 'BEGIN of AcctLineType_32'
16040          ,p_level    => C_LEVEL_PROCEDURE
16041          ,p_module   => l_log_module);
16042 
16043 END IF;
16044 --
16045 l_component_type             := 'AMB_JLT';
16046 l_component_code             := 'RCT_PREPAYMENT';
16047 l_component_type_code        := 'S';
16048 l_component_appl_id          :=  222;
16049 l_amb_context_code           := 'DEFAULT';
16050 l_entity_code                := 'RECEIPTS';
16051 l_event_class_code           := 'RECEIPT';
16052 l_event_type_code            := 'RECEIPT_ALL';
16053 l_line_definition_owner_code := 'S';
16054 l_line_definition_code       := 'RCT_CASH_JLD';
16055 --
16056 l_balance_type_code          := 'A';
16057 l_segment                     := NULL;
16058 l_ccid                        := NULL;
16059 l_adr_transaction_coa_id      := NULL;
16060 l_adr_accounting_coa_id       := NULL;
16061 l_adr_flexfield_segment_code  := NULL;
16062 l_adr_flex_value_set_id       := NULL;
16063 l_adr_value_type_code         := NULL;
16064 l_adr_value_combination_id    := NULL;
16065 l_adr_value_segment_code      := NULL;
16066 
16067 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
16068 l_bflow_class_code           := '';    -- 4219869 Business Flow
16069 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
16070 l_budgetary_control_flag     := 'N';
16071 
16072 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
16073 l_bflow_applied_to_amt       := NULL; -- 5132302
16074 l_entered_amt_idx            := NULL;          -- 4262811
16075 l_accted_amt_idx             := NULL;          -- 4262811
16076 l_acc_rev_flag               := NULL;          -- 4262811
16077 l_accrual_line_num           := NULL;          -- 4262811
16078 l_tmp_amt                    := NULL;          -- 4262811
16079 --
16080  
16081 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
16082     l_balance_type_code <> 'B' THEN
16083 IF NVL(p_source_7,'
16084 ') =  'OTHER ACC' AND 
16085 NVL(p_source_32,'
16086 ') =  'PREPAYMENT' AND 
16087 NVL(p_source_8,'
16088 ') =  'N'
16089  THEN 
16090 
16091    --
16092    XLA_AE_LINES_PKG.SetNewLine;
16093 
16094    p_balance_type_code          := l_balance_type_code;
16095    -- set the flag so later we will know whether the gain loss line needs to be created
16096    
16097    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
16098      p_actual_flag :='A';
16099    END IF;
16100 
16101    --
16102    -- bulk performance
16103    --
16104    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
16105                                       p_header_num   => 0); -- 4262811
16106    --
16107    -- set accounting line options
16108    --
16109    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
16110            p_natural_side_code          => 'C'
16111          , p_gain_or_loss_flag          => 'N'
16112          , p_gl_transfer_mode_code      => 'S'
16113          , p_acct_entry_type_code       => 'A'
16114          , p_switch_side_flag           => 'Y'
16115          , p_merge_duplicate_code       => 'A'
16116          );
16117    --
16118    l_acc_rev_natural_side_code := 'D';  -- 4262811
16119    -- 
16120    --
16121    -- set accounting line type info
16122    --
16123    xla_ae_lines_pkg.SetAcctLineType
16124       (p_component_type             => l_component_type
16125       ,p_event_type_code            => l_event_type_code
16126       ,p_line_definition_owner_code => l_line_definition_owner_code
16127       ,p_line_definition_code       => l_line_definition_code
16128       ,p_accounting_line_code       => l_component_code
16129       ,p_accounting_line_type_code  => l_component_type_code
16130       ,p_accounting_line_appl_id    => l_component_appl_id
16131       ,p_amb_context_code           => l_amb_context_code
16132       ,p_entity_code                => l_entity_code
16133       ,p_event_class_code           => l_event_class_code);
16134    --
16135    -- set accounting class
16136    --
16137    xla_ae_lines_pkg.SetAcctClass(
16138            p_accounting_class_code  => 'PREPAY'
16139          , p_ae_header_id           => l_ae_header_id
16140          );
16141 
16142    --
16143    -- set rounding class
16144    --
16145    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
16146                       'RECEIVABLE';
16147 
16148    --
16149    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
16150    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
16151    --
16152    -- bulk performance
16153    --
16154    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
16155 
16156    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
16160    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
16157       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
16158 
16159    -- 4955764
16161       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
16162 
16163    -- 4458381 Public Sector Enh
16164    
16165    --
16166    -- set accounting attributes for the line type
16167    --
16168    l_entered_amt_idx := 8;
16169    l_accted_amt_idx  := 13;
16170    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
16171    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
16172    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
16173    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
16174    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
16175    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
16176    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
16177    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
16178    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
16179    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
16180    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
16181    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
16182    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
16183    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
16184    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
16185    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
16186    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
16187    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
16188    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
16189    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
16190    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
16191    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
16192    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
16193    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
16194    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
16195    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
16196    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
16197    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
16198    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
16199    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
16200    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
16201    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
16202    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
16203 
16204    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
16205    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
16206 
16207    ---------------------------------------------------------------------------------------------------------------
16208    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
16209    ---------------------------------------------------------------------------------------------------------------
16210    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
16211 
16212    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
16213    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
16214 
16215    IF xla_accounting_cache_pkg.GetValueChar
16216          (p_source_code         => 'LEDGER_CATEGORY_CODE'
16217          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
16218    AND l_bflow_method_code = 'PRIOR_ENTRY'
16219 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
16220    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
16221          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
16222        )
16223    THEN
16224          xla_ae_lines_pkg.BflowUpgEntry
16225            (p_business_method_code    => l_bflow_method_code
16226            ,p_business_class_code     => l_bflow_class_code
16227            ,p_balance_type            => l_balance_type_code);
16228    ELSE
16229       NULL;
16230 -- No business flow processing for business flow method of NONE.
16231    END IF;
16232 
16233    --
16234    -- call analytical criteria
16235    --
16236    
16237    --
16238    -- call description
16239    --
16240    -- No description or it is inherited.
16241    --
16242    -- call ADRs
16243    -- Bug 4922099
16244    --
16245    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
16246         (NVL(l_actual_upg_option, 'N') = 'O') OR
16247         (NVL(l_enc_upg_option, 'N') = 'O')
16248       )
16249    THEN
16250    NULL;
16251    --
16252    --
16253    
16254   l_ccid := AcctDerRule_1(
16255            p_application_id           => p_application_id
16256          , p_ae_header_id             => l_ae_header_id 
16257 , p_source_1 => p_source_1
16258          , x_transaction_coa_id       => l_adr_transaction_coa_id
16259          , x_accounting_coa_id        => l_adr_accounting_coa_id
16260          , x_value_type_code          => l_adr_value_type_code
16261          , p_side                     => 'NA'
16262    );
16263 
16264    xla_ae_lines_pkg.set_ccid(
16265     p_code_combination_id          => l_ccid
16266   , p_value_type_code              => l_adr_value_type_code
16270   , p_adr_type_code                => 'S'
16267   , p_transaction_coa_id           => l_adr_transaction_coa_id
16268   , p_accounting_coa_id            => l_adr_accounting_coa_id
16269   , p_adr_code                     => 'DIST_CCID'
16271   , p_component_type               => l_component_type
16272   , p_component_code               => l_component_code
16273   , p_component_type_code          => l_component_type_code
16274   , p_component_appl_id            => l_component_appl_id
16275   , p_amb_context_code             => l_amb_context_code
16276   , p_side                         => 'NA'
16277   );
16278 
16279 
16280    --
16281    --
16282    END IF;
16283    --
16284    -- Bug 4922099
16285    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
16286           (NVL(l_enc_upg_option, 'N') = 'O')
16287         ) AND
16288         (l_bflow_method_code = 'PRIOR_ENTRY')
16289       )
16290    THEN
16291       IF
16292       --
16293       1 = 2
16294       --
16295       THEN
16296       xla_accounting_err_pkg.build_message
16297                                     (p_appli_s_name            => 'XLA'
16298                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
16299                                     ,p_token_1                 => 'LINE_NUMBER'
16300                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
16301                                     ,p_token_2                 => 'LINE_TYPE_NAME'
16302                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
16303                                                                              l_component_type
16304                                                                             ,l_component_code
16305                                                                             ,l_component_type_code
16306                                                                             ,l_component_appl_id
16307                                                                             ,l_amb_context_code
16308                                                                             ,l_entity_code
16309                                                                             ,l_event_class_code
16310                                                                            )
16311                                     ,p_token_3                 => 'OWNER'
16312                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
16313                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
16314                                                                           ,p_lookup_code    => l_component_type_code
16315                                                                          )
16316                                     ,p_token_4                 => 'PRODUCT_NAME'
16317                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
16318                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
16319                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
16320                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
16321                                     ,p_ae_header_id            =>  NULL
16322                                        );
16323 
16324         IF (C_LEVEL_ERROR>= g_log_level) THEN
16325                  trace
16326                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
16327                       ,p_level    => C_LEVEL_ERROR
16328                       ,p_module   => l_log_module);
16329         END IF;
16330       END IF;
16331    END IF;
16332    --
16333    --
16334    ------------------------------------------------------------------------------------------------
16335    -- 4219869 Business Flow
16336    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
16337    -- Prior Entry.  Currently, the following code is always generated.
16338    ------------------------------------------------------------------------------------------------
16339    XLA_AE_LINES_PKG.ValidateCurrentLine;
16340 
16341    ------------------------------------------------------------------------------------
16342    -- 4219869 Business Flow
16343    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
16344    ------------------------------------------------------------------------------------
16345    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
16346 
16347    ----------------------------------------------------------------------------------
16348    -- 4219869 Business Flow
16349    -- Update journal entry status -- Need to generate this within IF <condition>
16350    ----------------------------------------------------------------------------------
16351    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
16352          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
16353          ,p_balance_type_code => l_balance_type_code
16354          );
16355 
16356    -------------------------------------------------------------------------------------------
16357    -- 4262811 - Generate the Accrual Reversal lines
16358    -------------------------------------------------------------------------------------------
16359    BEGIN
16360       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
16364       END IF;
16361                               (g_array_event(p_event_id).array_value_num('header_index'));
16362       IF l_acc_rev_flag IS NULL THEN
16363          l_acc_rev_flag := 'N';
16365    EXCEPTION
16366       WHEN OTHERS THEN
16367          l_acc_rev_flag := 'N';
16368    END;
16369    --
16370    IF (l_acc_rev_flag = 'Y') THEN
16371 
16372        -- 4645092  ------------------------------------------------------------------------------
16373        -- To allow MPA report to determine if it should generate report process
16374        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
16375        ------------------------------------------------------------------------------------------
16376 
16377        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
16378        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
16379    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
16380    -- call ADRs
16381    -- Bug 4922099
16382    --
16383    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
16384         (NVL(l_actual_upg_option, 'N') = 'O') OR
16385         (NVL(l_enc_upg_option, 'N') = 'O')
16386       )
16387    THEN
16388    NULL;
16389    --
16390    --
16391    
16392   l_ccid := AcctDerRule_1(
16393            p_application_id           => p_application_id
16394          , p_ae_header_id             => l_ae_header_id 
16395 , p_source_1 => p_source_1
16396          , x_transaction_coa_id       => l_adr_transaction_coa_id
16397          , x_accounting_coa_id        => l_adr_accounting_coa_id
16398          , x_value_type_code          => l_adr_value_type_code
16399          , p_side                     => 'NA'
16400    );
16401 
16402    xla_ae_lines_pkg.set_ccid(
16403     p_code_combination_id          => l_ccid
16404   , p_value_type_code              => l_adr_value_type_code
16405   , p_transaction_coa_id           => l_adr_transaction_coa_id
16406   , p_accounting_coa_id            => l_adr_accounting_coa_id
16407   , p_adr_code                     => 'DIST_CCID'
16408   , p_adr_type_code                => 'S'
16409   , p_component_type               => l_component_type
16410   , p_component_code               => l_component_code
16411   , p_component_type_code          => l_component_type_code
16412   , p_component_appl_id            => l_component_appl_id
16413   , p_amb_context_code             => l_amb_context_code
16414   , p_side                         => 'NA'
16415   );
16416 
16417 
16418    --
16419    --
16420    END IF;
16421 
16422        --
16423        -- Update the line information that should be overwritten
16424        --
16425        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
16426                                          p_header_num   => 1);
16427        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
16428 
16429        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
16430 
16431        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
16432           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
16433        END IF;
16434 
16435       --
16436       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
16437       --
16438       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
16439           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
16440       ELSE
16441           ---------------------------------------------------------------------------------------------------
16442           -- 4262811a Switch Sign
16443           ---------------------------------------------------------------------------------------------------
16444           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
16445           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
16446                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
16447           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
16448                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
16449           -- 5132302
16450           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
16451                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
16452 
16453       END IF;
16454 
16455       -- 4955764
16456       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
16457       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
16458 
16459 
16460       XLA_AE_LINES_PKG.ValidateCurrentLine;
16461       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
16462 
16463       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
16464                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
16465                ,p_balance_type_code => l_balance_type_code);
16466 
16467    END IF;
16468 
16469    -----------------------------------------------------------------------------------------
16470    -- 4262811 Multiperiod Accounting
16474 
16471    -----------------------------------------------------------------------------------------
16472      -- No MPA option is assigned.
16473 
16475 END IF;
16476 END IF;
16477 --
16478 
16479 --
16480 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16481    trace
16482       (p_msg      => 'END of AcctLineType_32'
16483       ,p_level    => C_LEVEL_PROCEDURE
16484       ,p_module   => l_log_module);
16485 END IF;
16486 --
16487 EXCEPTION
16488   WHEN xla_exceptions_pkg.application_exception THEN
16489       RAISE;
16490   WHEN OTHERS THEN
16491        xla_exceptions_pkg.raise_message
16492            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_32');
16493 END AcctLineType_32;
16494 --
16495 
16496 ---------------------------------------
16497 --
16498 -- PRIVATE FUNCTION
16499 --         AcctLineType_33
16500 --
16501 ---------------------------------------
16502 PROCEDURE AcctLineType_33 (
16503   p_application_id        IN NUMBER
16504  ,p_event_id              IN NUMBER
16505  ,p_calculate_acctd_flag  IN VARCHAR2
16506  ,p_calculate_g_l_flag    IN VARCHAR2
16507  ,p_actual_flag           IN OUT VARCHAR2
16508  ,p_balance_type_code     OUT VARCHAR2
16509  ,p_gain_or_loss_ref      OUT VARCHAR2
16510  
16511 --Distribution GL Account
16512  , p_source_1            IN NUMBER
16513 --Distribution Source Type
16514  , p_source_7            IN VARCHAR2
16515 --Distribution Multi Fund Additional Entry
16516  , p_source_8            IN VARCHAR2
16517 --Distribution Line Identifier
16518  , p_source_9            IN NUMBER
16519 --Distribution Type
16520  , p_source_10            IN VARCHAR2
16521 --Exchange Rate
16522  , p_source_14            IN NUMBER
16523 --Exchange Rate Type
16524  , p_source_15            IN VARCHAR2
16525 --Receipt Applied To Application Identifier
16526  , p_source_17            IN NUMBER
16527 --Transaction Distribution Type
16528  , p_source_18            IN VARCHAR2
16529 --Transaction Entity Code
16530  , p_source_19            IN VARCHAR2
16531 --Transaction Distribution Identifier
16532  , p_source_20            IN NUMBER
16533 --Transaction Identifier
16534  , p_source_21            IN NUMBER
16535 --DIST_ENT_AMT_FROM
16536  , p_source_22            IN NUMBER
16537 --Applying Document Currency Code
16538  , p_source_23            IN VARCHAR2
16539 --Exchange Date
16540  , p_source_24            IN DATE
16541 --Accounting Amount
16542  , p_source_25            IN NUMBER
16543 --Distribution Party Identifier
16544  , p_source_26            IN NUMBER
16545 --Distribution Party Site Id
16546  , p_source_27            IN NUMBER
16547 --Distribution Party Type
16548  , p_source_28            IN VARCHAR2
16549 --Receivable Activity Type
16550  , p_source_32            IN VARCHAR2
16551 )
16552 IS
16553 
16554 l_component_type              VARCHAR2(80);
16555 l_component_code              VARCHAR2(30);
16556 l_component_type_code         VARCHAR2(1);
16557 l_component_appl_id           INTEGER;
16558 l_amb_context_code            VARCHAR2(30);
16559 l_entity_code                 VARCHAR2(30);
16560 l_event_class_code            VARCHAR2(30);
16561 l_ae_header_id                NUMBER;
16562 l_event_type_code             VARCHAR2(30);
16563 l_line_definition_code        VARCHAR2(30);
16564 l_line_definition_owner_code  VARCHAR2(1);
16565 --
16566 -- adr variables
16567 l_segment                     VARCHAR2(30);
16568 l_ccid                        NUMBER;
16569 l_adr_transaction_coa_id      NUMBER;
16570 l_adr_accounting_coa_id       NUMBER;
16571 l_adr_flexfield_segment_code  VARCHAR2(30);
16572 l_adr_flex_value_set_id       NUMBER;
16573 l_adr_value_type_code         VARCHAR2(30);
16574 l_adr_value_combination_id    NUMBER;
16575 l_adr_value_segment_code      VARCHAR2(30);
16576 
16577 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
16578 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
16579 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
16580 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
16581 
16582 -- 4262811 Variables ------------------------------------------------------------------------------------------
16583 l_entered_amt_idx             NUMBER;
16584 l_accted_amt_idx              NUMBER;
16585 l_acc_rev_flag                VARCHAR2(1);
16586 l_accrual_line_num            NUMBER;
16587 l_tmp_amt                     NUMBER;
16588 l_acc_rev_natural_side_code   VARCHAR2(1);
16589 
16590 l_num_entries                 NUMBER;
16591 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
16592 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
16593 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
16594 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
16595 l_recog_line_1                NUMBER;
16596 l_recog_line_2                NUMBER;
16597 
16598 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
16599 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
16600 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
16601 
16602 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
16603 
16604 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
16605 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
16606 
16610 --
16607 ---------------------------------------------------------------------------------------------------------------
16608 
16609 
16611 -- bulk performance
16612 --
16613 l_balance_type_code           VARCHAR2(1);
16614 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
16615 l_log_module                  VARCHAR2(240);
16616 
16617 --
16618 -- Upgrade strategy
16619 --
16620 l_actual_upg_option           VARCHAR2(1);
16621 l_enc_upg_option           VARCHAR2(1);
16622 
16623 --
16624 BEGIN
16625 --
16626 IF g_log_enabled THEN
16627       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_33';
16628 END IF;
16629 --
16630 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
16631 
16632       trace
16633          (p_msg      => 'BEGIN of AcctLineType_33'
16634          ,p_level    => C_LEVEL_PROCEDURE
16635          ,p_module   => l_log_module);
16636 
16637 END IF;
16638 --
16639 l_component_type             := 'AMB_JLT';
16640 l_component_code             := 'RCT_REFUND';
16641 l_component_type_code        := 'S';
16642 l_component_appl_id          :=  222;
16643 l_amb_context_code           := 'DEFAULT';
16644 l_entity_code                := 'RECEIPTS';
16645 l_event_class_code           := 'RECEIPT';
16646 l_event_type_code            := 'RECEIPT_ALL';
16647 l_line_definition_owner_code := 'S';
16648 l_line_definition_code       := 'RCT_CASH_JLD';
16649 --
16650 l_balance_type_code          := 'A';
16651 l_segment                     := NULL;
16652 l_ccid                        := NULL;
16653 l_adr_transaction_coa_id      := NULL;
16654 l_adr_accounting_coa_id       := NULL;
16655 l_adr_flexfield_segment_code  := NULL;
16656 l_adr_flex_value_set_id       := NULL;
16657 l_adr_value_type_code         := NULL;
16658 l_adr_value_combination_id    := NULL;
16659 l_adr_value_segment_code      := NULL;
16660 
16661 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
16662 l_bflow_class_code           := '';    -- 4219869 Business Flow
16663 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
16664 l_budgetary_control_flag     := 'N';
16665 
16666 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
16667 l_bflow_applied_to_amt       := NULL; -- 5132302
16668 l_entered_amt_idx            := NULL;          -- 4262811
16669 l_accted_amt_idx             := NULL;          -- 4262811
16670 l_acc_rev_flag               := NULL;          -- 4262811
16671 l_accrual_line_num           := NULL;          -- 4262811
16672 l_tmp_amt                    := NULL;          -- 4262811
16673 --
16674  
16675 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
16676     l_balance_type_code <> 'B' THEN
16677 IF (NVL(p_source_7,'
16678 ') =  'ACTIVITY' AND 
16679 NVL(p_source_32,'
16680 ') =  'CCREFUND' AND 
16681 NVL(p_source_8,'
16682 ') =  'N') OR 
16683 (NVL(p_source_7,'
16684 ') =  'ACTIVITY' AND 
16685 NVL(p_source_32,'
16686 ') =  'CM_REFUND' AND 
16687 NVL(p_source_8,'
16688 ') =  'N')
16689  THEN 
16690 
16691    --
16692    XLA_AE_LINES_PKG.SetNewLine;
16693 
16694    p_balance_type_code          := l_balance_type_code;
16695    -- set the flag so later we will know whether the gain loss line needs to be created
16696    
16697    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
16698      p_actual_flag :='A';
16699    END IF;
16700 
16701    --
16702    -- bulk performance
16703    --
16704    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
16705                                       p_header_num   => 0); -- 4262811
16706    --
16707    -- set accounting line options
16708    --
16709    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
16710            p_natural_side_code          => 'C'
16711          , p_gain_or_loss_flag          => 'N'
16712          , p_gl_transfer_mode_code      => 'S'
16713          , p_acct_entry_type_code       => 'A'
16714          , p_switch_side_flag           => 'Y'
16715          , p_merge_duplicate_code       => 'A'
16716          );
16717    --
16718    l_acc_rev_natural_side_code := 'D';  -- 4262811
16719    -- 
16720    --
16721    -- set accounting line type info
16722    --
16723    xla_ae_lines_pkg.SetAcctLineType
16724       (p_component_type             => l_component_type
16725       ,p_event_type_code            => l_event_type_code
16726       ,p_line_definition_owner_code => l_line_definition_owner_code
16727       ,p_line_definition_code       => l_line_definition_code
16728       ,p_accounting_line_code       => l_component_code
16729       ,p_accounting_line_type_code  => l_component_type_code
16730       ,p_accounting_line_appl_id    => l_component_appl_id
16731       ,p_amb_context_code           => l_amb_context_code
16732       ,p_entity_code                => l_entity_code
16733       ,p_event_class_code           => l_event_class_code);
16734    --
16735    -- set accounting class
16736    --
16737    xla_ae_lines_pkg.SetAcctClass(
16738            p_accounting_class_code  => 'REFUND'
16739          , p_ae_header_id           => l_ae_header_id
16740          );
16741 
16742    --
16743    -- set rounding class
16744    --
16745    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
16746                       'RECEIVABLE';
16747 
16748    --
16752    -- bulk performance
16749    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
16750    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
16751    --
16753    --
16754    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
16755 
16756    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
16757       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
16758 
16759    -- 4955764
16760    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
16761       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
16762 
16763    -- 4458381 Public Sector Enh
16764    
16765    --
16766    -- set accounting attributes for the line type
16767    --
16768    l_entered_amt_idx := 8;
16769    l_accted_amt_idx  := 13;
16770    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
16771    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
16772    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
16773    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
16774    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
16775    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
16776    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
16777    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
16778    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
16779    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
16780    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
16781    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
16782    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
16783    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
16784    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
16785    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
16786    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
16787    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
16788    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
16789    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
16790    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
16791    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
16792    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
16793    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
16794    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
16795    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
16796    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
16797    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
16798    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
16799    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
16800    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
16801    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
16802    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
16803 
16804    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
16805    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
16806 
16807    ---------------------------------------------------------------------------------------------------------------
16808    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
16809    ---------------------------------------------------------------------------------------------------------------
16810    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
16811 
16812    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
16813    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
16814 
16815    IF xla_accounting_cache_pkg.GetValueChar
16816          (p_source_code         => 'LEDGER_CATEGORY_CODE'
16817          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
16818    AND l_bflow_method_code = 'PRIOR_ENTRY'
16819 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
16820    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
16821          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
16822        )
16823    THEN
16824          xla_ae_lines_pkg.BflowUpgEntry
16825            (p_business_method_code    => l_bflow_method_code
16826            ,p_business_class_code     => l_bflow_class_code
16827            ,p_balance_type            => l_balance_type_code);
16828    ELSE
16829       NULL;
16830 -- No business flow processing for business flow method of NONE.
16831    END IF;
16832 
16833    --
16834    -- call analytical criteria
16835    --
16836    
16837    --
16838    -- call description
16839    --
16840    -- No description or it is inherited.
16841    --
16842    -- call ADRs
16843    -- Bug 4922099
16844    --
16845    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
16846         (NVL(l_actual_upg_option, 'N') = 'O') OR
16847         (NVL(l_enc_upg_option, 'N') = 'O')
16848       )
16849    THEN
16850    NULL;
16851    --
16852    --
16853    
16854   l_ccid := AcctDerRule_1(
16855            p_application_id           => p_application_id
16859          , x_accounting_coa_id        => l_adr_accounting_coa_id
16856          , p_ae_header_id             => l_ae_header_id 
16857 , p_source_1 => p_source_1
16858          , x_transaction_coa_id       => l_adr_transaction_coa_id
16860          , x_value_type_code          => l_adr_value_type_code
16861          , p_side                     => 'NA'
16862    );
16863 
16864    xla_ae_lines_pkg.set_ccid(
16865     p_code_combination_id          => l_ccid
16866   , p_value_type_code              => l_adr_value_type_code
16867   , p_transaction_coa_id           => l_adr_transaction_coa_id
16868   , p_accounting_coa_id            => l_adr_accounting_coa_id
16869   , p_adr_code                     => 'DIST_CCID'
16870   , p_adr_type_code                => 'S'
16871   , p_component_type               => l_component_type
16872   , p_component_code               => l_component_code
16873   , p_component_type_code          => l_component_type_code
16874   , p_component_appl_id            => l_component_appl_id
16875   , p_amb_context_code             => l_amb_context_code
16876   , p_side                         => 'NA'
16877   );
16878 
16879 
16880    --
16881    --
16882    END IF;
16883    --
16884    -- Bug 4922099
16885    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
16886           (NVL(l_enc_upg_option, 'N') = 'O')
16887         ) AND
16888         (l_bflow_method_code = 'PRIOR_ENTRY')
16889       )
16890    THEN
16891       IF
16892       --
16893       1 = 2
16894       --
16895       THEN
16896       xla_accounting_err_pkg.build_message
16897                                     (p_appli_s_name            => 'XLA'
16898                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
16899                                     ,p_token_1                 => 'LINE_NUMBER'
16900                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
16901                                     ,p_token_2                 => 'LINE_TYPE_NAME'
16902                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
16903                                                                              l_component_type
16904                                                                             ,l_component_code
16905                                                                             ,l_component_type_code
16906                                                                             ,l_component_appl_id
16907                                                                             ,l_amb_context_code
16908                                                                             ,l_entity_code
16909                                                                             ,l_event_class_code
16910                                                                            )
16911                                     ,p_token_3                 => 'OWNER'
16912                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
16913                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
16914                                                                           ,p_lookup_code    => l_component_type_code
16915                                                                          )
16916                                     ,p_token_4                 => 'PRODUCT_NAME'
16917                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
16918                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
16919                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
16920                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
16921                                     ,p_ae_header_id            =>  NULL
16922                                        );
16923 
16924         IF (C_LEVEL_ERROR>= g_log_level) THEN
16925                  trace
16926                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
16927                       ,p_level    => C_LEVEL_ERROR
16928                       ,p_module   => l_log_module);
16929         END IF;
16930       END IF;
16931    END IF;
16932    --
16933    --
16934    ------------------------------------------------------------------------------------------------
16935    -- 4219869 Business Flow
16936    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
16937    -- Prior Entry.  Currently, the following code is always generated.
16938    ------------------------------------------------------------------------------------------------
16939    XLA_AE_LINES_PKG.ValidateCurrentLine;
16940 
16941    ------------------------------------------------------------------------------------
16942    -- 4219869 Business Flow
16943    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
16944    ------------------------------------------------------------------------------------
16945    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
16946 
16947    ----------------------------------------------------------------------------------
16948    -- 4219869 Business Flow
16949    -- Update journal entry status -- Need to generate this within IF <condition>
16950    ----------------------------------------------------------------------------------
16954          );
16951    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
16952          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
16953          ,p_balance_type_code => l_balance_type_code
16955 
16956    -------------------------------------------------------------------------------------------
16957    -- 4262811 - Generate the Accrual Reversal lines
16958    -------------------------------------------------------------------------------------------
16959    BEGIN
16960       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
16961                               (g_array_event(p_event_id).array_value_num('header_index'));
16962       IF l_acc_rev_flag IS NULL THEN
16963          l_acc_rev_flag := 'N';
16964       END IF;
16965    EXCEPTION
16966       WHEN OTHERS THEN
16967          l_acc_rev_flag := 'N';
16968    END;
16969    --
16970    IF (l_acc_rev_flag = 'Y') THEN
16971 
16972        -- 4645092  ------------------------------------------------------------------------------
16973        -- To allow MPA report to determine if it should generate report process
16974        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
16975        ------------------------------------------------------------------------------------------
16976 
16977        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
16978        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
16979    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
16980    -- call ADRs
16981    -- Bug 4922099
16982    --
16983    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
16984         (NVL(l_actual_upg_option, 'N') = 'O') OR
16985         (NVL(l_enc_upg_option, 'N') = 'O')
16986       )
16987    THEN
16988    NULL;
16989    --
16990    --
16991    
16992   l_ccid := AcctDerRule_1(
16993            p_application_id           => p_application_id
16994          , p_ae_header_id             => l_ae_header_id 
16995 , p_source_1 => p_source_1
16996          , x_transaction_coa_id       => l_adr_transaction_coa_id
16997          , x_accounting_coa_id        => l_adr_accounting_coa_id
16998          , x_value_type_code          => l_adr_value_type_code
16999          , p_side                     => 'NA'
17000    );
17001 
17002    xla_ae_lines_pkg.set_ccid(
17003     p_code_combination_id          => l_ccid
17004   , p_value_type_code              => l_adr_value_type_code
17005   , p_transaction_coa_id           => l_adr_transaction_coa_id
17006   , p_accounting_coa_id            => l_adr_accounting_coa_id
17007   , p_adr_code                     => 'DIST_CCID'
17008   , p_adr_type_code                => 'S'
17009   , p_component_type               => l_component_type
17010   , p_component_code               => l_component_code
17011   , p_component_type_code          => l_component_type_code
17012   , p_component_appl_id            => l_component_appl_id
17013   , p_amb_context_code             => l_amb_context_code
17014   , p_side                         => 'NA'
17015   );
17016 
17017 
17018    --
17019    --
17020    END IF;
17021 
17022        --
17023        -- Update the line information that should be overwritten
17024        --
17025        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
17026                                          p_header_num   => 1);
17027        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
17028 
17029        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
17030 
17031        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
17032           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
17033        END IF;
17034 
17035       --
17036       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
17037       --
17038       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
17039           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
17040       ELSE
17041           ---------------------------------------------------------------------------------------------------
17042           -- 4262811a Switch Sign
17043           ---------------------------------------------------------------------------------------------------
17044           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
17045           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
17046                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
17047           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
17048                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
17049           -- 5132302
17050           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
17051                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
17052 
17053       END IF;
17054 
17055       -- 4955764
17056       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
17057       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
17058 
17059 
17060       XLA_AE_LINES_PKG.ValidateCurrentLine;
17064                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
17061       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
17062 
17063       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
17065                ,p_balance_type_code => l_balance_type_code);
17066 
17067    END IF;
17068 
17069    -----------------------------------------------------------------------------------------
17070    -- 4262811 Multiperiod Accounting
17071    -----------------------------------------------------------------------------------------
17072      -- No MPA option is assigned.
17073 
17074 
17075 END IF;
17076 END IF;
17077 --
17078 
17079 --
17080 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17081    trace
17082       (p_msg      => 'END of AcctLineType_33'
17083       ,p_level    => C_LEVEL_PROCEDURE
17084       ,p_module   => l_log_module);
17085 END IF;
17086 --
17087 EXCEPTION
17088   WHEN xla_exceptions_pkg.application_exception THEN
17089       RAISE;
17090   WHEN OTHERS THEN
17091        xla_exceptions_pkg.raise_message
17092            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_33');
17093 END AcctLineType_33;
17094 --
17095 
17096 ---------------------------------------
17097 --
17098 -- PRIVATE FUNCTION
17099 --         AcctLineType_34
17100 --
17101 ---------------------------------------
17102 PROCEDURE AcctLineType_34 (
17103   p_application_id        IN NUMBER
17104  ,p_event_id              IN NUMBER
17105  ,p_calculate_acctd_flag  IN VARCHAR2
17106  ,p_calculate_g_l_flag    IN VARCHAR2
17107  ,p_actual_flag           IN OUT VARCHAR2
17108  ,p_balance_type_code     OUT VARCHAR2
17109  ,p_gain_or_loss_ref      OUT VARCHAR2
17110  
17111 --Distribution GL Account
17112  , p_source_1            IN NUMBER
17113 --Distribution Source Type
17114  , p_source_7            IN VARCHAR2
17115 --Distribution Multi Fund Additional Entry
17116  , p_source_8            IN VARCHAR2
17117 --Distribution Line Identifier
17118  , p_source_9            IN NUMBER
17119 --Distribution Type
17120  , p_source_10            IN VARCHAR2
17121 --Exchange Rate
17122  , p_source_14            IN NUMBER
17123 --Exchange Rate Type
17124  , p_source_15            IN VARCHAR2
17125 --Receipt Applied To Application Identifier
17126  , p_source_17            IN NUMBER
17127 --Transaction Distribution Type
17128  , p_source_18            IN VARCHAR2
17129 --Transaction Entity Code
17130  , p_source_19            IN VARCHAR2
17131 --Transaction Distribution Identifier
17132  , p_source_20            IN NUMBER
17133 --Transaction Identifier
17134  , p_source_21            IN NUMBER
17135 --DIST_ENT_AMT_FROM
17136  , p_source_22            IN NUMBER
17137 --Applying Document Currency Code
17138  , p_source_23            IN VARCHAR2
17139 --Exchange Date
17140  , p_source_24            IN DATE
17141 --Accounting Amount
17142  , p_source_25            IN NUMBER
17143 --Distribution Party Identifier
17144  , p_source_26            IN NUMBER
17145 --Distribution Party Site Id
17146  , p_source_27            IN NUMBER
17147 --Distribution Party Type
17148  , p_source_28            IN VARCHAR2
17149 --Distribution Source Table
17150  , p_source_33            IN VARCHAR2
17151 )
17152 IS
17153 
17154 l_component_type              VARCHAR2(80);
17155 l_component_code              VARCHAR2(30);
17156 l_component_type_code         VARCHAR2(1);
17157 l_component_appl_id           INTEGER;
17158 l_amb_context_code            VARCHAR2(30);
17159 l_entity_code                 VARCHAR2(30);
17160 l_event_class_code            VARCHAR2(30);
17161 l_ae_header_id                NUMBER;
17162 l_event_type_code             VARCHAR2(30);
17163 l_line_definition_code        VARCHAR2(30);
17164 l_line_definition_owner_code  VARCHAR2(1);
17165 --
17166 -- adr variables
17167 l_segment                     VARCHAR2(30);
17168 l_ccid                        NUMBER;
17169 l_adr_transaction_coa_id      NUMBER;
17170 l_adr_accounting_coa_id       NUMBER;
17171 l_adr_flexfield_segment_code  VARCHAR2(30);
17172 l_adr_flex_value_set_id       NUMBER;
17173 l_adr_value_type_code         VARCHAR2(30);
17174 l_adr_value_combination_id    NUMBER;
17175 l_adr_value_segment_code      VARCHAR2(30);
17176 
17177 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
17178 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
17179 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
17180 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
17181 
17182 -- 4262811 Variables ------------------------------------------------------------------------------------------
17183 l_entered_amt_idx             NUMBER;
17184 l_accted_amt_idx              NUMBER;
17185 l_acc_rev_flag                VARCHAR2(1);
17186 l_accrual_line_num            NUMBER;
17187 l_tmp_amt                     NUMBER;
17188 l_acc_rev_natural_side_code   VARCHAR2(1);
17189 
17190 l_num_entries                 NUMBER;
17191 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
17192 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
17193 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
17194 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
17195 l_recog_line_1                NUMBER;
17196 l_recog_line_2                NUMBER;
17197 
17201 
17198 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
17199 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
17200 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
17202 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
17203 
17204 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
17205 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
17206 
17207 ---------------------------------------------------------------------------------------------------------------
17208 
17209 
17210 --
17211 -- bulk performance
17212 --
17213 l_balance_type_code           VARCHAR2(1);
17214 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
17215 l_log_module                  VARCHAR2(240);
17216 
17217 --
17218 -- Upgrade strategy
17219 --
17220 l_actual_upg_option           VARCHAR2(1);
17221 l_enc_upg_option           VARCHAR2(1);
17222 
17223 --
17224 BEGIN
17225 --
17226 IF g_log_enabled THEN
17227       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_34';
17228 END IF;
17229 --
17230 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17231 
17232       trace
17233          (p_msg      => 'BEGIN of AcctLineType_34'
17234          ,p_level    => C_LEVEL_PROCEDURE
17235          ,p_module   => l_log_module);
17236 
17237 END IF;
17238 --
17239 l_component_type             := 'AMB_JLT';
17240 l_component_code             := 'RCT_REMIT';
17241 l_component_type_code        := 'S';
17242 l_component_appl_id          :=  222;
17243 l_amb_context_code           := 'DEFAULT';
17244 l_entity_code                := 'RECEIPTS';
17245 l_event_class_code           := 'RECEIPT';
17246 l_event_type_code            := 'RECEIPT_ALL';
17247 l_line_definition_owner_code := 'S';
17248 l_line_definition_code       := 'RCT_CASH_JLD';
17249 --
17250 l_balance_type_code          := 'A';
17251 l_segment                     := NULL;
17252 l_ccid                        := NULL;
17253 l_adr_transaction_coa_id      := NULL;
17254 l_adr_accounting_coa_id       := NULL;
17255 l_adr_flexfield_segment_code  := NULL;
17256 l_adr_flex_value_set_id       := NULL;
17257 l_adr_value_type_code         := NULL;
17258 l_adr_value_combination_id    := NULL;
17259 l_adr_value_segment_code      := NULL;
17260 
17261 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
17262 l_bflow_class_code           := '';    -- 4219869 Business Flow
17263 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
17264 l_budgetary_control_flag     := 'N';
17265 
17266 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
17267 l_bflow_applied_to_amt       := NULL; -- 5132302
17268 l_entered_amt_idx            := NULL;          -- 4262811
17269 l_accted_amt_idx             := NULL;          -- 4262811
17270 l_acc_rev_flag               := NULL;          -- 4262811
17271 l_accrual_line_num           := NULL;          -- 4262811
17272 l_tmp_amt                    := NULL;          -- 4262811
17273 --
17274  
17275 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
17276     l_balance_type_code <> 'B' THEN
17277 IF NVL(p_source_7,'
17278 ') =  'REMITTANCE' AND 
17279 NVL(p_source_33,'
17280 ') =  'CRH' AND 
17281 NVL(p_source_8,'
17282 ') =  'N'
17283  THEN 
17284 
17285    --
17286    XLA_AE_LINES_PKG.SetNewLine;
17287 
17288    p_balance_type_code          := l_balance_type_code;
17289    -- set the flag so later we will know whether the gain loss line needs to be created
17290    
17291    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
17292      p_actual_flag :='A';
17293    END IF;
17294 
17295    --
17296    -- bulk performance
17297    --
17298    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
17299                                       p_header_num   => 0); -- 4262811
17300    --
17301    -- set accounting line options
17302    --
17303    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
17304            p_natural_side_code          => 'C'
17305          , p_gain_or_loss_flag          => 'N'
17306          , p_gl_transfer_mode_code      => 'S'
17307          , p_acct_entry_type_code       => 'A'
17308          , p_switch_side_flag           => 'Y'
17309          , p_merge_duplicate_code       => 'A'
17310          );
17311    --
17312    l_acc_rev_natural_side_code := 'D';  -- 4262811
17313    -- 
17314    --
17315    -- set accounting line type info
17316    --
17317    xla_ae_lines_pkg.SetAcctLineType
17318       (p_component_type             => l_component_type
17319       ,p_event_type_code            => l_event_type_code
17320       ,p_line_definition_owner_code => l_line_definition_owner_code
17321       ,p_line_definition_code       => l_line_definition_code
17322       ,p_accounting_line_code       => l_component_code
17323       ,p_accounting_line_type_code  => l_component_type_code
17324       ,p_accounting_line_appl_id    => l_component_appl_id
17325       ,p_amb_context_code           => l_amb_context_code
17326       ,p_entity_code                => l_entity_code
17327       ,p_event_class_code           => l_event_class_code);
17328    --
17329    -- set accounting class
17330    --
17331    xla_ae_lines_pkg.SetAcctClass(
17332            p_accounting_class_code  => 'REMITTANCE'
17336    --
17333          , p_ae_header_id           => l_ae_header_id
17334          );
17335 
17337    -- set rounding class
17338    --
17339    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
17340                       'RECEIVABLE';
17341 
17342    --
17343    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
17344    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
17345    --
17346    -- bulk performance
17347    --
17348    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
17349 
17350    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
17351       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
17352 
17353    -- 4955764
17354    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
17355       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
17356 
17357    -- 4458381 Public Sector Enh
17358    
17359    --
17360    -- set accounting attributes for the line type
17361    --
17362    l_entered_amt_idx := 8;
17363    l_accted_amt_idx  := 13;
17364    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
17365    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
17366    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
17367    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
17368    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
17369    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
17370    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
17371    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
17372    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
17373    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
17374    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
17375    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
17376    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
17377    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
17378    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
17379    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
17380    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
17381    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
17382    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
17383    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
17384    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
17385    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
17386    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
17387    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
17388    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
17389    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
17390    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
17391    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
17392    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
17393    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
17394    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
17395    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
17396    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
17397 
17398    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
17399    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
17400 
17401    ---------------------------------------------------------------------------------------------------------------
17402    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
17403    ---------------------------------------------------------------------------------------------------------------
17404    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
17405 
17406    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
17407    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
17408 
17409    IF xla_accounting_cache_pkg.GetValueChar
17410          (p_source_code         => 'LEDGER_CATEGORY_CODE'
17411          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
17412    AND l_bflow_method_code = 'PRIOR_ENTRY'
17413 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
17414    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
17415          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
17416        )
17417    THEN
17418          xla_ae_lines_pkg.BflowUpgEntry
17419            (p_business_method_code    => l_bflow_method_code
17420            ,p_business_class_code     => l_bflow_class_code
17421            ,p_balance_type            => l_balance_type_code);
17422    ELSE
17423       NULL;
17424 -- No business flow processing for business flow method of NONE.
17425    END IF;
17426 
17427    --
17428    -- call analytical criteria
17429    --
17430    
17431    --
17432    -- call description
17433    --
17434    -- No description or it is inherited.
17435    --
17436    -- call ADRs
17437    -- Bug 4922099
17438    --
17442       )
17439    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
17440         (NVL(l_actual_upg_option, 'N') = 'O') OR
17441         (NVL(l_enc_upg_option, 'N') = 'O')
17443    THEN
17444    NULL;
17445    --
17446    --
17447    
17448   l_ccid := AcctDerRule_1(
17449            p_application_id           => p_application_id
17450          , p_ae_header_id             => l_ae_header_id 
17451 , p_source_1 => p_source_1
17452          , x_transaction_coa_id       => l_adr_transaction_coa_id
17453          , x_accounting_coa_id        => l_adr_accounting_coa_id
17454          , x_value_type_code          => l_adr_value_type_code
17455          , p_side                     => 'NA'
17456    );
17457 
17458    xla_ae_lines_pkg.set_ccid(
17459     p_code_combination_id          => l_ccid
17460   , p_value_type_code              => l_adr_value_type_code
17461   , p_transaction_coa_id           => l_adr_transaction_coa_id
17462   , p_accounting_coa_id            => l_adr_accounting_coa_id
17463   , p_adr_code                     => 'DIST_CCID'
17464   , p_adr_type_code                => 'S'
17465   , p_component_type               => l_component_type
17466   , p_component_code               => l_component_code
17467   , p_component_type_code          => l_component_type_code
17468   , p_component_appl_id            => l_component_appl_id
17469   , p_amb_context_code             => l_amb_context_code
17470   , p_side                         => 'NA'
17471   );
17472 
17473 
17474    --
17475    --
17476    END IF;
17477    --
17478    -- Bug 4922099
17479    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
17480           (NVL(l_enc_upg_option, 'N') = 'O')
17481         ) AND
17482         (l_bflow_method_code = 'PRIOR_ENTRY')
17483       )
17484    THEN
17485       IF
17486       --
17487       1 = 2
17488       --
17489       THEN
17490       xla_accounting_err_pkg.build_message
17491                                     (p_appli_s_name            => 'XLA'
17492                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
17493                                     ,p_token_1                 => 'LINE_NUMBER'
17494                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
17495                                     ,p_token_2                 => 'LINE_TYPE_NAME'
17496                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
17497                                                                              l_component_type
17498                                                                             ,l_component_code
17499                                                                             ,l_component_type_code
17500                                                                             ,l_component_appl_id
17501                                                                             ,l_amb_context_code
17502                                                                             ,l_entity_code
17503                                                                             ,l_event_class_code
17504                                                                            )
17505                                     ,p_token_3                 => 'OWNER'
17506                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
17507                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
17508                                                                           ,p_lookup_code    => l_component_type_code
17509                                                                          )
17510                                     ,p_token_4                 => 'PRODUCT_NAME'
17511                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
17512                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
17513                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
17514                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
17515                                     ,p_ae_header_id            =>  NULL
17516                                        );
17517 
17518         IF (C_LEVEL_ERROR>= g_log_level) THEN
17519                  trace
17520                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
17521                       ,p_level    => C_LEVEL_ERROR
17522                       ,p_module   => l_log_module);
17523         END IF;
17524       END IF;
17525    END IF;
17526    --
17527    --
17528    ------------------------------------------------------------------------------------------------
17529    -- 4219869 Business Flow
17530    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
17531    -- Prior Entry.  Currently, the following code is always generated.
17532    ------------------------------------------------------------------------------------------------
17533    XLA_AE_LINES_PKG.ValidateCurrentLine;
17534 
17535    ------------------------------------------------------------------------------------
17536    -- 4219869 Business Flow
17537    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
17538    ------------------------------------------------------------------------------------
17542    -- 4219869 Business Flow
17539    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
17540 
17541    ----------------------------------------------------------------------------------
17543    -- Update journal entry status -- Need to generate this within IF <condition>
17544    ----------------------------------------------------------------------------------
17545    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
17546          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
17547          ,p_balance_type_code => l_balance_type_code
17548          );
17549 
17550    -------------------------------------------------------------------------------------------
17551    -- 4262811 - Generate the Accrual Reversal lines
17552    -------------------------------------------------------------------------------------------
17553    BEGIN
17554       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
17555                               (g_array_event(p_event_id).array_value_num('header_index'));
17556       IF l_acc_rev_flag IS NULL THEN
17557          l_acc_rev_flag := 'N';
17558       END IF;
17559    EXCEPTION
17560       WHEN OTHERS THEN
17561          l_acc_rev_flag := 'N';
17562    END;
17563    --
17564    IF (l_acc_rev_flag = 'Y') THEN
17565 
17566        -- 4645092  ------------------------------------------------------------------------------
17567        -- To allow MPA report to determine if it should generate report process
17568        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
17569        ------------------------------------------------------------------------------------------
17570 
17571        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
17572        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
17573    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
17574    -- call ADRs
17575    -- Bug 4922099
17576    --
17577    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
17578         (NVL(l_actual_upg_option, 'N') = 'O') OR
17579         (NVL(l_enc_upg_option, 'N') = 'O')
17580       )
17581    THEN
17582    NULL;
17583    --
17584    --
17585    
17586   l_ccid := AcctDerRule_1(
17587            p_application_id           => p_application_id
17588          , p_ae_header_id             => l_ae_header_id 
17589 , p_source_1 => p_source_1
17590          , x_transaction_coa_id       => l_adr_transaction_coa_id
17591          , x_accounting_coa_id        => l_adr_accounting_coa_id
17592          , x_value_type_code          => l_adr_value_type_code
17593          , p_side                     => 'NA'
17594    );
17595 
17596    xla_ae_lines_pkg.set_ccid(
17597     p_code_combination_id          => l_ccid
17598   , p_value_type_code              => l_adr_value_type_code
17599   , p_transaction_coa_id           => l_adr_transaction_coa_id
17600   , p_accounting_coa_id            => l_adr_accounting_coa_id
17601   , p_adr_code                     => 'DIST_CCID'
17602   , p_adr_type_code                => 'S'
17603   , p_component_type               => l_component_type
17604   , p_component_code               => l_component_code
17605   , p_component_type_code          => l_component_type_code
17606   , p_component_appl_id            => l_component_appl_id
17607   , p_amb_context_code             => l_amb_context_code
17608   , p_side                         => 'NA'
17609   );
17610 
17611 
17612    --
17613    --
17614    END IF;
17615 
17616        --
17617        -- Update the line information that should be overwritten
17618        --
17619        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
17620                                          p_header_num   => 1);
17621        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
17622 
17623        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
17624 
17625        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
17626           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
17627        END IF;
17628 
17629       --
17630       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
17631       --
17632       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
17633           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
17634       ELSE
17635           ---------------------------------------------------------------------------------------------------
17636           -- 4262811a Switch Sign
17637           ---------------------------------------------------------------------------------------------------
17638           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
17639           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
17640                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
17641           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
17642                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
17643           -- 5132302
17644           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
17645                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
17646 
17647       END IF;
17648 
17652 
17649       -- 4955764
17650       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
17651       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
17653 
17654       XLA_AE_LINES_PKG.ValidateCurrentLine;
17655       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
17656 
17657       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
17658                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
17659                ,p_balance_type_code => l_balance_type_code);
17660 
17661    END IF;
17662 
17663    -----------------------------------------------------------------------------------------
17664    -- 4262811 Multiperiod Accounting
17665    -----------------------------------------------------------------------------------------
17666      -- No MPA option is assigned.
17667 
17668 
17669 END IF;
17670 END IF;
17671 --
17672 
17673 --
17674 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17675    trace
17676       (p_msg      => 'END of AcctLineType_34'
17677       ,p_level    => C_LEVEL_PROCEDURE
17678       ,p_module   => l_log_module);
17679 END IF;
17680 --
17681 EXCEPTION
17682   WHEN xla_exceptions_pkg.application_exception THEN
17683       RAISE;
17684   WHEN OTHERS THEN
17685        xla_exceptions_pkg.raise_message
17686            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_34');
17687 END AcctLineType_34;
17688 --
17689 
17690 ---------------------------------------
17691 --
17692 -- PRIVATE FUNCTION
17693 --         AcctLineType_35
17694 --
17695 ---------------------------------------
17696 PROCEDURE AcctLineType_35 (
17697   p_application_id        IN NUMBER
17698  ,p_event_id              IN NUMBER
17699  ,p_calculate_acctd_flag  IN VARCHAR2
17700  ,p_calculate_g_l_flag    IN VARCHAR2
17701  ,p_actual_flag           IN OUT VARCHAR2
17702  ,p_balance_type_code     OUT VARCHAR2
17703  ,p_gain_or_loss_ref      OUT VARCHAR2
17704  
17705 --Distribution GL Account
17706  , p_source_1            IN NUMBER
17707 --Distribution Source Type
17708  , p_source_7            IN VARCHAR2
17709 --Distribution Multi Fund Additional Entry
17710  , p_source_8            IN VARCHAR2
17711 --Distribution Line Identifier
17712  , p_source_9            IN NUMBER
17713 --Distribution Type
17714  , p_source_10            IN VARCHAR2
17715 --Exchange Rate
17716  , p_source_14            IN NUMBER
17717 --Exchange Rate Type
17718  , p_source_15            IN VARCHAR2
17719 --Receipt Applied To Application Identifier
17720  , p_source_17            IN NUMBER
17721 --Transaction Distribution Type
17722  , p_source_18            IN VARCHAR2
17723 --Transaction Entity Code
17724  , p_source_19            IN VARCHAR2
17725 --Transaction Distribution Identifier
17726  , p_source_20            IN NUMBER
17727 --Transaction Identifier
17728  , p_source_21            IN NUMBER
17729 --DIST_ENT_AMT_FROM
17730  , p_source_22            IN NUMBER
17731 --Applying Document Currency Code
17732  , p_source_23            IN VARCHAR2
17733 --Exchange Date
17734  , p_source_24            IN DATE
17735 --Accounting Amount
17736  , p_source_25            IN NUMBER
17737 --Distribution Party Identifier
17738  , p_source_26            IN NUMBER
17739 --Distribution Party Site Id
17740  , p_source_27            IN NUMBER
17741 --Distribution Party Type
17742  , p_source_28            IN VARCHAR2
17743 --Distribution Source Table
17744  , p_source_33            IN VARCHAR2
17745 )
17746 IS
17747 
17748 l_component_type              VARCHAR2(80);
17749 l_component_code              VARCHAR2(30);
17750 l_component_type_code         VARCHAR2(1);
17751 l_component_appl_id           INTEGER;
17752 l_amb_context_code            VARCHAR2(30);
17753 l_entity_code                 VARCHAR2(30);
17754 l_event_class_code            VARCHAR2(30);
17755 l_ae_header_id                NUMBER;
17756 l_event_type_code             VARCHAR2(30);
17757 l_line_definition_code        VARCHAR2(30);
17758 l_line_definition_owner_code  VARCHAR2(1);
17759 --
17760 -- adr variables
17761 l_segment                     VARCHAR2(30);
17762 l_ccid                        NUMBER;
17763 l_adr_transaction_coa_id      NUMBER;
17764 l_adr_accounting_coa_id       NUMBER;
17765 l_adr_flexfield_segment_code  VARCHAR2(30);
17766 l_adr_flex_value_set_id       NUMBER;
17767 l_adr_value_type_code         VARCHAR2(30);
17768 l_adr_value_combination_id    NUMBER;
17769 l_adr_value_segment_code      VARCHAR2(30);
17770 
17771 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
17772 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
17773 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
17774 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
17775 
17776 -- 4262811 Variables ------------------------------------------------------------------------------------------
17777 l_entered_amt_idx             NUMBER;
17778 l_accted_amt_idx              NUMBER;
17779 l_acc_rev_flag                VARCHAR2(1);
17780 l_accrual_line_num            NUMBER;
17781 l_tmp_amt                     NUMBER;
17782 l_acc_rev_natural_side_code   VARCHAR2(1);
17783 
17784 l_num_entries                 NUMBER;
17785 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
17786 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
17790 l_recog_line_2                NUMBER;
17787 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
17788 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
17789 l_recog_line_1                NUMBER;
17791 
17792 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
17793 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
17794 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
17795 
17796 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
17797 
17798 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
17799 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
17800 
17801 ---------------------------------------------------------------------------------------------------------------
17802 
17803 
17804 --
17805 -- bulk performance
17806 --
17807 l_balance_type_code           VARCHAR2(1);
17808 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
17809 l_log_module                  VARCHAR2(240);
17810 
17811 --
17812 -- Upgrade strategy
17813 --
17814 l_actual_upg_option           VARCHAR2(1);
17815 l_enc_upg_option           VARCHAR2(1);
17816 
17817 --
17818 BEGIN
17819 --
17820 IF g_log_enabled THEN
17821       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_35';
17822 END IF;
17823 --
17824 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
17825 
17826       trace
17827          (p_msg      => 'BEGIN of AcctLineType_35'
17828          ,p_level    => C_LEVEL_PROCEDURE
17829          ,p_module   => l_log_module);
17830 
17831 END IF;
17832 --
17833 l_component_type             := 'AMB_JLT';
17834 l_component_code             := 'RCT_REMIT_BR';
17835 l_component_type_code        := 'S';
17836 l_component_appl_id          :=  222;
17837 l_amb_context_code           := 'DEFAULT';
17838 l_entity_code                := 'RECEIPTS';
17839 l_event_class_code           := 'RECEIPT';
17840 l_event_type_code            := 'RECEIPT_ALL';
17841 l_line_definition_owner_code := 'S';
17842 l_line_definition_code       := 'RCT_CASH_JLD';
17843 --
17844 l_balance_type_code          := 'A';
17845 l_segment                     := NULL;
17846 l_ccid                        := NULL;
17847 l_adr_transaction_coa_id      := NULL;
17848 l_adr_accounting_coa_id       := NULL;
17849 l_adr_flexfield_segment_code  := NULL;
17850 l_adr_flex_value_set_id       := NULL;
17851 l_adr_value_type_code         := NULL;
17852 l_adr_value_combination_id    := NULL;
17853 l_adr_value_segment_code      := NULL;
17854 
17855 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
17856 l_bflow_class_code           := '';    -- 4219869 Business Flow
17857 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
17858 l_budgetary_control_flag     := 'N';
17859 
17860 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
17861 l_bflow_applied_to_amt       := NULL; -- 5132302
17862 l_entered_amt_idx            := NULL;          -- 4262811
17863 l_accted_amt_idx             := NULL;          -- 4262811
17864 l_acc_rev_flag               := NULL;          -- 4262811
17865 l_accrual_line_num           := NULL;          -- 4262811
17866 l_tmp_amt                    := NULL;          -- 4262811
17867 --
17868  
17869 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
17870     l_balance_type_code <> 'B' THEN
17871 IF NVL(p_source_7,'
17872 ') =  'REMITTANCE' AND 
17873 NVL(p_source_33,'
17874 ') =  'RA' AND 
17875 NVL(p_source_8,'
17876 ') =  'N'
17877  THEN 
17878 
17879    --
17880    XLA_AE_LINES_PKG.SetNewLine;
17881 
17882    p_balance_type_code          := l_balance_type_code;
17883    -- set the flag so later we will know whether the gain loss line needs to be created
17884    
17885    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
17886      p_actual_flag :='A';
17887    END IF;
17888 
17889    --
17890    -- bulk performance
17891    --
17892    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
17893                                       p_header_num   => 0); -- 4262811
17894    --
17895    -- set accounting line options
17896    --
17897    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
17898            p_natural_side_code          => 'C'
17899          , p_gain_or_loss_flag          => 'N'
17900          , p_gl_transfer_mode_code      => 'S'
17901          , p_acct_entry_type_code       => 'A'
17902          , p_switch_side_flag           => 'Y'
17903          , p_merge_duplicate_code       => 'A'
17904          );
17905    --
17906    l_acc_rev_natural_side_code := 'D';  -- 4262811
17907    -- 
17908    --
17909    -- set accounting line type info
17910    --
17911    xla_ae_lines_pkg.SetAcctLineType
17912       (p_component_type             => l_component_type
17913       ,p_event_type_code            => l_event_type_code
17914       ,p_line_definition_owner_code => l_line_definition_owner_code
17915       ,p_line_definition_code       => l_line_definition_code
17916       ,p_accounting_line_code       => l_component_code
17917       ,p_accounting_line_type_code  => l_component_type_code
17918       ,p_accounting_line_appl_id    => l_component_appl_id
17919       ,p_amb_context_code           => l_amb_context_code
17920       ,p_entity_code                => l_entity_code
17924    --
17921       ,p_event_class_code           => l_event_class_code);
17922    --
17923    -- set accounting class
17925    xla_ae_lines_pkg.SetAcctClass(
17926            p_accounting_class_code  => 'REM_BR'
17927          , p_ae_header_id           => l_ae_header_id
17928          );
17929 
17930    --
17931    -- set rounding class
17932    --
17933    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
17934                       'RECEIVABLE';
17935 
17936    --
17937    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
17938    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
17939    --
17940    -- bulk performance
17941    --
17942    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
17943 
17944    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
17945       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
17946 
17947    -- 4955764
17948    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
17949       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
17950 
17951    -- 4458381 Public Sector Enh
17952    
17953    --
17954    -- set accounting attributes for the line type
17955    --
17956    l_entered_amt_idx := 8;
17957    l_accted_amt_idx  := 13;
17958    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
17959    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
17960    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
17961    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
17962    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
17963    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
17964    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
17965    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
17966    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
17967    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
17968    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
17969    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
17970    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
17971    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
17972    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
17973    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
17974    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
17975    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
17976    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
17977    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
17978    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
17979    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
17980    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
17981    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
17982    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
17983    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
17984    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
17985    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
17986    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
17987    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
17988    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
17989    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
17990    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
17991 
17992    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
17993    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
17994 
17995    ---------------------------------------------------------------------------------------------------------------
17996    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
17997    ---------------------------------------------------------------------------------------------------------------
17998    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
17999 
18000    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
18001    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
18002 
18003    IF xla_accounting_cache_pkg.GetValueChar
18004          (p_source_code         => 'LEDGER_CATEGORY_CODE'
18005          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
18006    AND l_bflow_method_code = 'PRIOR_ENTRY'
18007 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
18008    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
18009          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
18010        )
18011    THEN
18012          xla_ae_lines_pkg.BflowUpgEntry
18013            (p_business_method_code    => l_bflow_method_code
18014            ,p_business_class_code     => l_bflow_class_code
18015            ,p_balance_type            => l_balance_type_code);
18016    ELSE
18017       NULL;
18018 -- No business flow processing for business flow method of NONE.
18019    END IF;
18020 
18021    --
18022    -- call analytical criteria
18026    -- call description
18023    --
18024    
18025    --
18027    --
18028    -- No description or it is inherited.
18029    --
18030    -- call ADRs
18031    -- Bug 4922099
18032    --
18033    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
18034         (NVL(l_actual_upg_option, 'N') = 'O') OR
18035         (NVL(l_enc_upg_option, 'N') = 'O')
18036       )
18037    THEN
18038    NULL;
18039    --
18040    --
18041    
18042   l_ccid := AcctDerRule_1(
18043            p_application_id           => p_application_id
18044          , p_ae_header_id             => l_ae_header_id 
18045 , p_source_1 => p_source_1
18046          , x_transaction_coa_id       => l_adr_transaction_coa_id
18047          , x_accounting_coa_id        => l_adr_accounting_coa_id
18048          , x_value_type_code          => l_adr_value_type_code
18049          , p_side                     => 'NA'
18050    );
18051 
18052    xla_ae_lines_pkg.set_ccid(
18053     p_code_combination_id          => l_ccid
18054   , p_value_type_code              => l_adr_value_type_code
18055   , p_transaction_coa_id           => l_adr_transaction_coa_id
18056   , p_accounting_coa_id            => l_adr_accounting_coa_id
18057   , p_adr_code                     => 'DIST_CCID'
18058   , p_adr_type_code                => 'S'
18059   , p_component_type               => l_component_type
18060   , p_component_code               => l_component_code
18061   , p_component_type_code          => l_component_type_code
18062   , p_component_appl_id            => l_component_appl_id
18063   , p_amb_context_code             => l_amb_context_code
18064   , p_side                         => 'NA'
18065   );
18066 
18067 
18068    --
18069    --
18070    END IF;
18071    --
18072    -- Bug 4922099
18073    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
18074           (NVL(l_enc_upg_option, 'N') = 'O')
18075         ) AND
18076         (l_bflow_method_code = 'PRIOR_ENTRY')
18077       )
18078    THEN
18079       IF
18080       --
18081       1 = 2
18082       --
18083       THEN
18084       xla_accounting_err_pkg.build_message
18085                                     (p_appli_s_name            => 'XLA'
18086                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
18087                                     ,p_token_1                 => 'LINE_NUMBER'
18088                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
18089                                     ,p_token_2                 => 'LINE_TYPE_NAME'
18090                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
18091                                                                              l_component_type
18092                                                                             ,l_component_code
18093                                                                             ,l_component_type_code
18094                                                                             ,l_component_appl_id
18095                                                                             ,l_amb_context_code
18096                                                                             ,l_entity_code
18097                                                                             ,l_event_class_code
18098                                                                            )
18099                                     ,p_token_3                 => 'OWNER'
18100                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
18101                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
18102                                                                           ,p_lookup_code    => l_component_type_code
18103                                                                          )
18104                                     ,p_token_4                 => 'PRODUCT_NAME'
18105                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
18106                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
18107                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
18108                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
18109                                     ,p_ae_header_id            =>  NULL
18110                                        );
18111 
18112         IF (C_LEVEL_ERROR>= g_log_level) THEN
18113                  trace
18114                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
18115                       ,p_level    => C_LEVEL_ERROR
18116                       ,p_module   => l_log_module);
18117         END IF;
18118       END IF;
18119    END IF;
18120    --
18121    --
18122    ------------------------------------------------------------------------------------------------
18123    -- 4219869 Business Flow
18124    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
18125    -- Prior Entry.  Currently, the following code is always generated.
18126    ------------------------------------------------------------------------------------------------
18127    XLA_AE_LINES_PKG.ValidateCurrentLine;
18128 
18129    ------------------------------------------------------------------------------------
18133    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
18130    -- 4219869 Business Flow
18131    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
18132    ------------------------------------------------------------------------------------
18134 
18135    ----------------------------------------------------------------------------------
18136    -- 4219869 Business Flow
18137    -- Update journal entry status -- Need to generate this within IF <condition>
18138    ----------------------------------------------------------------------------------
18139    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
18140          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
18141          ,p_balance_type_code => l_balance_type_code
18142          );
18143 
18144    -------------------------------------------------------------------------------------------
18145    -- 4262811 - Generate the Accrual Reversal lines
18146    -------------------------------------------------------------------------------------------
18147    BEGIN
18148       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
18149                               (g_array_event(p_event_id).array_value_num('header_index'));
18150       IF l_acc_rev_flag IS NULL THEN
18151          l_acc_rev_flag := 'N';
18152       END IF;
18153    EXCEPTION
18154       WHEN OTHERS THEN
18155          l_acc_rev_flag := 'N';
18156    END;
18157    --
18158    IF (l_acc_rev_flag = 'Y') THEN
18159 
18160        -- 4645092  ------------------------------------------------------------------------------
18161        -- To allow MPA report to determine if it should generate report process
18162        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
18163        ------------------------------------------------------------------------------------------
18164 
18165        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
18166        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
18167    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
18168    -- call ADRs
18169    -- Bug 4922099
18170    --
18171    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
18172         (NVL(l_actual_upg_option, 'N') = 'O') OR
18173         (NVL(l_enc_upg_option, 'N') = 'O')
18174       )
18175    THEN
18176    NULL;
18177    --
18178    --
18179    
18180   l_ccid := AcctDerRule_1(
18181            p_application_id           => p_application_id
18182          , p_ae_header_id             => l_ae_header_id 
18183 , p_source_1 => p_source_1
18184          , x_transaction_coa_id       => l_adr_transaction_coa_id
18185          , x_accounting_coa_id        => l_adr_accounting_coa_id
18186          , x_value_type_code          => l_adr_value_type_code
18187          , p_side                     => 'NA'
18188    );
18189 
18190    xla_ae_lines_pkg.set_ccid(
18191     p_code_combination_id          => l_ccid
18192   , p_value_type_code              => l_adr_value_type_code
18193   , p_transaction_coa_id           => l_adr_transaction_coa_id
18194   , p_accounting_coa_id            => l_adr_accounting_coa_id
18195   , p_adr_code                     => 'DIST_CCID'
18196   , p_adr_type_code                => 'S'
18197   , p_component_type               => l_component_type
18198   , p_component_code               => l_component_code
18199   , p_component_type_code          => l_component_type_code
18200   , p_component_appl_id            => l_component_appl_id
18201   , p_amb_context_code             => l_amb_context_code
18202   , p_side                         => 'NA'
18203   );
18204 
18205 
18206    --
18207    --
18208    END IF;
18209 
18210        --
18211        -- Update the line information that should be overwritten
18212        --
18213        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
18214                                          p_header_num   => 1);
18215        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
18216 
18217        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
18218 
18219        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
18220           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
18221        END IF;
18222 
18223       --
18224       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
18225       --
18226       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
18227           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
18228       ELSE
18229           ---------------------------------------------------------------------------------------------------
18230           -- 4262811a Switch Sign
18231           ---------------------------------------------------------------------------------------------------
18232           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
18233           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
18234                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
18235           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
18236                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
18237           -- 5132302
18241       END IF;
18238           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
18239                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
18240 
18242 
18243       -- 4955764
18244       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
18245       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
18246 
18247 
18248       XLA_AE_LINES_PKG.ValidateCurrentLine;
18249       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
18250 
18251       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
18252                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
18253                ,p_balance_type_code => l_balance_type_code);
18254 
18255    END IF;
18256 
18257    -----------------------------------------------------------------------------------------
18258    -- 4262811 Multiperiod Accounting
18259    -----------------------------------------------------------------------------------------
18260      -- No MPA option is assigned.
18261 
18262 
18263 END IF;
18264 END IF;
18265 --
18266 
18267 --
18268 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18269    trace
18270       (p_msg      => 'END of AcctLineType_35'
18271       ,p_level    => C_LEVEL_PROCEDURE
18272       ,p_module   => l_log_module);
18273 END IF;
18274 --
18275 EXCEPTION
18276   WHEN xla_exceptions_pkg.application_exception THEN
18277       RAISE;
18278   WHEN OTHERS THEN
18279        xla_exceptions_pkg.raise_message
18280            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_35');
18281 END AcctLineType_35;
18282 --
18283 
18284 ---------------------------------------
18285 --
18286 -- PRIVATE FUNCTION
18287 --         AcctLineType_36
18288 --
18289 ---------------------------------------
18290 PROCEDURE AcctLineType_36 (
18291   p_application_id        IN NUMBER
18292  ,p_event_id              IN NUMBER
18293  ,p_calculate_acctd_flag  IN VARCHAR2
18294  ,p_calculate_g_l_flag    IN VARCHAR2
18295  ,p_actual_flag           IN OUT VARCHAR2
18296  ,p_balance_type_code     OUT VARCHAR2
18297  ,p_gain_or_loss_ref      OUT VARCHAR2
18298  
18299 --Remittance Bank Account Unapplied Account
18300  , p_source_2            IN NUMBER
18301 --Distribution Source Type
18302  , p_source_7            IN VARCHAR2
18303 --Distribution Multi Fund Additional Entry
18304  , p_source_8            IN VARCHAR2
18305 --Distribution Line Identifier
18306  , p_source_9            IN NUMBER
18307 --Distribution Type
18308  , p_source_10            IN VARCHAR2
18309 --Exchange Rate
18310  , p_source_14            IN NUMBER
18311 --Exchange Rate Type
18312  , p_source_15            IN VARCHAR2
18313 --Receipt Applied To Application Identifier
18314  , p_source_17            IN NUMBER
18315 --Transaction Distribution Type
18316  , p_source_18            IN VARCHAR2
18317 --Transaction Entity Code
18318  , p_source_19            IN VARCHAR2
18319 --Transaction Distribution Identifier
18320  , p_source_20            IN NUMBER
18321 --Transaction Identifier
18322  , p_source_21            IN NUMBER
18323 --DIST_ENT_AMT_FROM
18324  , p_source_22            IN NUMBER
18325 --Applying Document Currency Code
18326  , p_source_23            IN VARCHAR2
18327 --Exchange Date
18328  , p_source_24            IN DATE
18329 --Accounting Amount
18330  , p_source_25            IN NUMBER
18331 --Distribution Party Type
18332  , p_source_28            IN VARCHAR2
18333 --Receivable Activity Type
18334  , p_source_32            IN VARCHAR2
18335 --Distribution Source Table
18336  , p_source_33            IN VARCHAR2
18337 --Receipt Pay From Customer
18338  , p_source_34            IN NUMBER
18339 --Receipt Customer Site Use Identifier
18340  , p_source_35            IN NUMBER
18341 )
18342 IS
18343 
18344 l_component_type              VARCHAR2(80);
18345 l_component_code              VARCHAR2(30);
18346 l_component_type_code         VARCHAR2(1);
18347 l_component_appl_id           INTEGER;
18348 l_amb_context_code            VARCHAR2(30);
18349 l_entity_code                 VARCHAR2(30);
18350 l_event_class_code            VARCHAR2(30);
18351 l_ae_header_id                NUMBER;
18352 l_event_type_code             VARCHAR2(30);
18353 l_line_definition_code        VARCHAR2(30);
18354 l_line_definition_owner_code  VARCHAR2(1);
18355 --
18356 -- adr variables
18357 l_segment                     VARCHAR2(30);
18358 l_ccid                        NUMBER;
18359 l_adr_transaction_coa_id      NUMBER;
18360 l_adr_accounting_coa_id       NUMBER;
18361 l_adr_flexfield_segment_code  VARCHAR2(30);
18362 l_adr_flex_value_set_id       NUMBER;
18363 l_adr_value_type_code         VARCHAR2(30);
18364 l_adr_value_combination_id    NUMBER;
18365 l_adr_value_segment_code      VARCHAR2(30);
18366 
18367 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
18368 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
18369 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
18370 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
18371 
18372 -- 4262811 Variables ------------------------------------------------------------------------------------------
18373 l_entered_amt_idx             NUMBER;
18377 l_tmp_amt                     NUMBER;
18374 l_accted_amt_idx              NUMBER;
18375 l_acc_rev_flag                VARCHAR2(1);
18376 l_accrual_line_num            NUMBER;
18378 l_acc_rev_natural_side_code   VARCHAR2(1);
18379 
18380 l_num_entries                 NUMBER;
18381 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
18382 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
18383 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
18384 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
18385 l_recog_line_1                NUMBER;
18386 l_recog_line_2                NUMBER;
18387 
18388 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
18389 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
18390 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
18391 
18392 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
18393 
18394 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
18395 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
18396 
18397 ---------------------------------------------------------------------------------------------------------------
18398 
18399 
18400 --
18401 -- bulk performance
18402 --
18403 l_balance_type_code           VARCHAR2(1);
18404 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
18405 l_log_module                  VARCHAR2(240);
18406 
18407 --
18408 -- Upgrade strategy
18409 --
18410 l_actual_upg_option           VARCHAR2(1);
18411 l_enc_upg_option           VARCHAR2(1);
18412 
18413 --
18414 BEGIN
18415 --
18416 IF g_log_enabled THEN
18417       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_36';
18418 END IF;
18419 --
18420 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18421 
18422       trace
18423          (p_msg      => 'BEGIN of AcctLineType_36'
18424          ,p_level    => C_LEVEL_PROCEDURE
18425          ,p_module   => l_log_module);
18426 
18427 END IF;
18428 --
18429 l_component_type             := 'AMB_JLT';
18430 l_component_code             := 'RCT_UNAPP';
18431 l_component_type_code        := 'S';
18432 l_component_appl_id          :=  222;
18433 l_amb_context_code           := 'DEFAULT';
18434 l_entity_code                := 'RECEIPTS';
18435 l_event_class_code           := 'RECEIPT';
18436 l_event_type_code            := 'RECEIPT_ALL';
18437 l_line_definition_owner_code := 'S';
18438 l_line_definition_code       := 'RCT_CASH_JLD';
18439 --
18440 l_balance_type_code          := 'A';
18441 l_segment                     := NULL;
18442 l_ccid                        := NULL;
18443 l_adr_transaction_coa_id      := NULL;
18444 l_adr_accounting_coa_id       := NULL;
18445 l_adr_flexfield_segment_code  := NULL;
18446 l_adr_flex_value_set_id       := NULL;
18447 l_adr_value_type_code         := NULL;
18448 l_adr_value_combination_id    := NULL;
18449 l_adr_value_segment_code      := NULL;
18450 
18451 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
18452 l_bflow_class_code           := '';    -- 4219869 Business Flow
18453 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
18454 l_budgetary_control_flag     := 'N';
18455 
18456 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
18457 l_bflow_applied_to_amt       := NULL; -- 5132302
18458 l_entered_amt_idx            := NULL;          -- 4262811
18459 l_accted_amt_idx             := NULL;          -- 4262811
18460 l_acc_rev_flag               := NULL;          -- 4262811
18461 l_accrual_line_num           := NULL;          -- 4262811
18462 l_tmp_amt                    := NULL;          -- 4262811
18463 --
18464  
18465 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
18466     l_balance_type_code <> 'B' THEN
18467 IF (NVL(p_source_7,'
18468 ') =  'OTHER ACC' AND 
18469 NVL(p_source_32,'
18470 ') =  'CLAIM_INVESTIGATION' AND 
18471 NVL(p_source_8,'
18472 ') =  'N') OR 
18473 (NVL(p_source_7,'
18474 ') =  'FACTOR' AND 
18475 NVL(p_source_33,'
18476 ') =  'RA' AND 
18477 NVL(p_source_8,'
18478 ') =  'N') OR 
18479 (NVL(p_source_7,'
18480 ') =  'OTHER ACC' AND 
18481 NVL(p_source_8,'
18482 ') =  'N' AND 
18483 NVL(p_source_32,'
18484 ') =  'NETTING') OR 
18485 (NVL(p_source_7,'
18486 ') =  'OTHER ACC' AND 
18487 NVL(p_source_8,'
18488 ') =  'N' AND 
18489 NVL(p_source_32,'
18490 ') =  'PREPAYMENT') OR 
18491 (NVL(p_source_7,'
18492 ') =  'ACTIVITY' AND 
18493 NVL(p_source_8,'
18494 ') =  'N' AND 
18495 NVL(p_source_32,'
18496 ') =  'CCREFUND') OR 
18497 (NVL(p_source_7,'
18498 ') =  'REMITTANCE' AND 
18499 NVL(p_source_8,'
18500 ') =  'N' AND 
18501 NVL(p_source_33,'
18502 ') =  'RA') OR 
18503 (NVL(p_source_7,'
18504 ') =  'ACTIVITY' AND 
18505 NVL(p_source_8,'
18506 ') =  'N' AND 
18507 NVL(p_source_32,'
18508 ') =  'WRITEOFF') OR 
18509 (NVL(p_source_7,'
18510 ') =  'ACTIVITY' AND 
18511 NVL(p_source_8,'
18512 ') =  'N' AND 
18513 NVL(p_source_32,'
18514 ') =  'CM_REFUND') OR 
18515 (NVL(p_source_7,'
18516 ') =  'ACTIVITY' AND 
18517 NVL(p_source_32,'
18518 ') =  'ADJUST' AND 
18522 ') =  'ACTIVITY' AND 
18519 NVL(p_source_8,'
18520 ') =  'N') OR 
18521 (NVL(p_source_7,'
18523 NVL(p_source_8,'
18524 ') =  'N' AND 
18525 NVL(p_source_32,'
18526 ') =  'CC_CHARGEBACK') OR 
18527 (NVL(p_source_7,'
18528 ') =  'ACTIVITY' AND 
18529 NVL(p_source_8,'
18530 ') =  'N' AND 
18531 NVL(p_source_32,'
18532 ') =  'NETTING')
18533  THEN 
18534 
18535    --
18536    XLA_AE_LINES_PKG.SetNewLine;
18537 
18538    p_balance_type_code          := l_balance_type_code;
18539    -- set the flag so later we will know whether the gain loss line needs to be created
18540    
18541    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
18542      p_actual_flag :='A';
18543    END IF;
18544 
18545    --
18546    -- bulk performance
18547    --
18548    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
18549                                       p_header_num   => 0); -- 4262811
18550    --
18551    -- set accounting line options
18552    --
18553    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
18554            p_natural_side_code          => 'D'
18555          , p_gain_or_loss_flag          => 'N'
18556          , p_gl_transfer_mode_code      => 'S'
18557          , p_acct_entry_type_code       => 'A'
18558          , p_switch_side_flag           => 'Y'
18559          , p_merge_duplicate_code       => 'A'
18560          );
18561    --
18562    l_acc_rev_natural_side_code := 'C';  -- 4262811
18563    -- 
18564    --
18565    -- set accounting line type info
18566    --
18567    xla_ae_lines_pkg.SetAcctLineType
18568       (p_component_type             => l_component_type
18569       ,p_event_type_code            => l_event_type_code
18570       ,p_line_definition_owner_code => l_line_definition_owner_code
18571       ,p_line_definition_code       => l_line_definition_code
18572       ,p_accounting_line_code       => l_component_code
18573       ,p_accounting_line_type_code  => l_component_type_code
18574       ,p_accounting_line_appl_id    => l_component_appl_id
18575       ,p_amb_context_code           => l_amb_context_code
18576       ,p_entity_code                => l_entity_code
18577       ,p_event_class_code           => l_event_class_code);
18578    --
18579    -- set accounting class
18580    --
18581    xla_ae_lines_pkg.SetAcctClass(
18582            p_accounting_class_code  => 'UNAPP'
18583          , p_ae_header_id           => l_ae_header_id
18584          );
18585 
18586    --
18587    -- set rounding class
18588    --
18589    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
18590                       'RECEIVABLE';
18591 
18592    --
18593    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
18594    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
18595    --
18596    -- bulk performance
18597    --
18598    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
18599 
18600    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
18601       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
18602 
18603    -- 4955764
18604    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
18605       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
18606 
18607    -- 4458381 Public Sector Enh
18608    
18609    --
18610    -- set accounting attributes for the line type
18611    --
18612    l_entered_amt_idx := 8;
18613    l_accted_amt_idx  := 13;
18614    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
18615    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
18616    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
18617    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
18618    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
18619    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
18620    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
18621    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
18622    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
18623    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
18624    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
18625    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
18626    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
18627    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
18628    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
18629    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
18630    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
18631    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
18632    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
18633    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
18634    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
18635    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
18636    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
18637    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
18638    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
18642    l_rec_acct_attrs.array_num_value(14)  := p_source_34;
18639    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
18640    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
18641    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
18643    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
18644    l_rec_acct_attrs.array_num_value(15)  := p_source_35;
18645    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
18646    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
18647 
18648    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
18649    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
18650 
18651    ---------------------------------------------------------------------------------------------------------------
18652    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
18653    ---------------------------------------------------------------------------------------------------------------
18654    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
18655 
18656    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
18657    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
18658 
18659    IF xla_accounting_cache_pkg.GetValueChar
18660          (p_source_code         => 'LEDGER_CATEGORY_CODE'
18661          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
18662    AND l_bflow_method_code = 'PRIOR_ENTRY'
18663 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
18664    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
18665          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
18666        )
18667    THEN
18668          xla_ae_lines_pkg.BflowUpgEntry
18669            (p_business_method_code    => l_bflow_method_code
18670            ,p_business_class_code     => l_bflow_class_code
18671            ,p_balance_type            => l_balance_type_code);
18672    ELSE
18673       NULL;
18674 -- No business flow processing for business flow method of NONE.
18675    END IF;
18676 
18677    --
18678    -- call analytical criteria
18679    --
18680    
18681    --
18682    -- call description
18683    --
18684    -- No description or it is inherited.
18685    --
18686    -- call ADRs
18687    -- Bug 4922099
18688    --
18689    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
18690         (NVL(l_actual_upg_option, 'N') = 'O') OR
18691         (NVL(l_enc_upg_option, 'N') = 'O')
18692       )
18693    THEN
18694    NULL;
18695    --
18696    --
18697    
18698   l_ccid := AcctDerRule_2(
18699            p_application_id           => p_application_id
18700          , p_ae_header_id             => l_ae_header_id 
18701 , p_source_2 => p_source_2
18702          , x_transaction_coa_id       => l_adr_transaction_coa_id
18703          , x_accounting_coa_id        => l_adr_accounting_coa_id
18704          , x_value_type_code          => l_adr_value_type_code
18705          , p_side                     => 'NA'
18706    );
18707 
18708    xla_ae_lines_pkg.set_ccid(
18709     p_code_combination_id          => l_ccid
18710   , p_value_type_code              => l_adr_value_type_code
18711   , p_transaction_coa_id           => l_adr_transaction_coa_id
18712   , p_accounting_coa_id            => l_adr_accounting_coa_id
18713   , p_adr_code                     => 'RMT_BNK_UNAPP_CCID'
18714   , p_adr_type_code                => 'S'
18715   , p_component_type               => l_component_type
18716   , p_component_code               => l_component_code
18717   , p_component_type_code          => l_component_type_code
18718   , p_component_appl_id            => l_component_appl_id
18719   , p_amb_context_code             => l_amb_context_code
18720   , p_side                         => 'NA'
18721   );
18722 
18723 
18724    --
18725    --
18726    END IF;
18727    --
18728    -- Bug 4922099
18729    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
18730           (NVL(l_enc_upg_option, 'N') = 'O')
18731         ) AND
18732         (l_bflow_method_code = 'PRIOR_ENTRY')
18733       )
18734    THEN
18735       IF
18736       --
18737       1 = 2
18738       --
18739       THEN
18740       xla_accounting_err_pkg.build_message
18741                                     (p_appli_s_name            => 'XLA'
18742                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
18743                                     ,p_token_1                 => 'LINE_NUMBER'
18744                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
18745                                     ,p_token_2                 => 'LINE_TYPE_NAME'
18746                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
18747                                                                              l_component_type
18748                                                                             ,l_component_code
18749                                                                             ,l_component_type_code
18750                                                                             ,l_component_appl_id
18751                                                                             ,l_amb_context_code
18752                                                                             ,l_entity_code
18756                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
18753                                                                             ,l_event_class_code
18754                                                                            )
18755                                     ,p_token_3                 => 'OWNER'
18757                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
18758                                                                           ,p_lookup_code    => l_component_type_code
18759                                                                          )
18760                                     ,p_token_4                 => 'PRODUCT_NAME'
18761                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
18762                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
18763                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
18764                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
18765                                     ,p_ae_header_id            =>  NULL
18766                                        );
18767 
18768         IF (C_LEVEL_ERROR>= g_log_level) THEN
18769                  trace
18770                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
18771                       ,p_level    => C_LEVEL_ERROR
18772                       ,p_module   => l_log_module);
18773         END IF;
18774       END IF;
18775    END IF;
18776    --
18777    --
18778    ------------------------------------------------------------------------------------------------
18779    -- 4219869 Business Flow
18780    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
18781    -- Prior Entry.  Currently, the following code is always generated.
18782    ------------------------------------------------------------------------------------------------
18783    XLA_AE_LINES_PKG.ValidateCurrentLine;
18784 
18785    ------------------------------------------------------------------------------------
18786    -- 4219869 Business Flow
18787    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
18788    ------------------------------------------------------------------------------------
18789    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
18790 
18791    ----------------------------------------------------------------------------------
18792    -- 4219869 Business Flow
18793    -- Update journal entry status -- Need to generate this within IF <condition>
18794    ----------------------------------------------------------------------------------
18795    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
18796          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
18797          ,p_balance_type_code => l_balance_type_code
18798          );
18799 
18800    -------------------------------------------------------------------------------------------
18801    -- 4262811 - Generate the Accrual Reversal lines
18802    -------------------------------------------------------------------------------------------
18803    BEGIN
18804       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
18805                               (g_array_event(p_event_id).array_value_num('header_index'));
18806       IF l_acc_rev_flag IS NULL THEN
18807          l_acc_rev_flag := 'N';
18808       END IF;
18809    EXCEPTION
18810       WHEN OTHERS THEN
18811          l_acc_rev_flag := 'N';
18812    END;
18813    --
18814    IF (l_acc_rev_flag = 'Y') THEN
18815 
18816        -- 4645092  ------------------------------------------------------------------------------
18817        -- To allow MPA report to determine if it should generate report process
18818        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
18819        ------------------------------------------------------------------------------------------
18820 
18821        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
18822        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
18823    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
18824    -- call ADRs
18825    -- Bug 4922099
18826    --
18827    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
18828         (NVL(l_actual_upg_option, 'N') = 'O') OR
18829         (NVL(l_enc_upg_option, 'N') = 'O')
18830       )
18831    THEN
18832    NULL;
18833    --
18834    --
18835    
18836   l_ccid := AcctDerRule_2(
18837            p_application_id           => p_application_id
18838          , p_ae_header_id             => l_ae_header_id 
18839 , p_source_2 => p_source_2
18840          , x_transaction_coa_id       => l_adr_transaction_coa_id
18841          , x_accounting_coa_id        => l_adr_accounting_coa_id
18842          , x_value_type_code          => l_adr_value_type_code
18843          , p_side                     => 'NA'
18844    );
18845 
18846    xla_ae_lines_pkg.set_ccid(
18847     p_code_combination_id          => l_ccid
18848   , p_value_type_code              => l_adr_value_type_code
18849   , p_transaction_coa_id           => l_adr_transaction_coa_id
18850   , p_accounting_coa_id            => l_adr_accounting_coa_id
18851   , p_adr_code                     => 'RMT_BNK_UNAPP_CCID'
18852   , p_adr_type_code                => 'S'
18853   , p_component_type               => l_component_type
18854   , p_component_code               => l_component_code
18858   , p_side                         => 'NA'
18855   , p_component_type_code          => l_component_type_code
18856   , p_component_appl_id            => l_component_appl_id
18857   , p_amb_context_code             => l_amb_context_code
18859   );
18860 
18861 
18862    --
18863    --
18864    END IF;
18865 
18866        --
18867        -- Update the line information that should be overwritten
18868        --
18869        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
18870                                          p_header_num   => 1);
18871        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
18872 
18873        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
18874 
18875        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
18876           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
18877        END IF;
18878 
18879       --
18880       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
18881       --
18882       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
18883           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
18884       ELSE
18885           ---------------------------------------------------------------------------------------------------
18886           -- 4262811a Switch Sign
18887           ---------------------------------------------------------------------------------------------------
18888           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
18889           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
18890                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
18891           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
18892                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
18893           -- 5132302
18894           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
18895                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
18896 
18897       END IF;
18898 
18899       -- 4955764
18900       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
18901       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
18902 
18903 
18904       XLA_AE_LINES_PKG.ValidateCurrentLine;
18905       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
18906 
18907       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
18908                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
18909                ,p_balance_type_code => l_balance_type_code);
18910 
18911    END IF;
18912 
18913    -----------------------------------------------------------------------------------------
18914    -- 4262811 Multiperiod Accounting
18915    -----------------------------------------------------------------------------------------
18916      -- No MPA option is assigned.
18917 
18918 
18919 END IF;
18920 END IF;
18921 --
18922 
18923 --
18924 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
18925    trace
18926       (p_msg      => 'END of AcctLineType_36'
18927       ,p_level    => C_LEVEL_PROCEDURE
18928       ,p_module   => l_log_module);
18929 END IF;
18930 --
18931 EXCEPTION
18932   WHEN xla_exceptions_pkg.application_exception THEN
18933       RAISE;
18934   WHEN OTHERS THEN
18935        xla_exceptions_pkg.raise_message
18936            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_36');
18937 END AcctLineType_36;
18938 --
18939 
18940 ---------------------------------------
18941 --
18942 -- PRIVATE FUNCTION
18943 --         AcctLineType_37
18944 --
18945 ---------------------------------------
18946 PROCEDURE AcctLineType_37 (
18947   p_application_id        IN NUMBER
18948  ,p_event_id              IN NUMBER
18949  ,p_calculate_acctd_flag  IN VARCHAR2
18950  ,p_calculate_g_l_flag    IN VARCHAR2
18951  ,p_actual_flag           IN OUT VARCHAR2
18952  ,p_balance_type_code     OUT VARCHAR2
18953  ,p_gain_or_loss_ref      OUT VARCHAR2
18954  
18955 --Remittance Bank Account Unapplied Account
18956  , p_source_2            IN NUMBER
18957 --Distribution Source Type
18958  , p_source_7            IN VARCHAR2
18959 --Distribution Multi Fund Additional Entry
18960  , p_source_8            IN VARCHAR2
18961 --Distribution Line Identifier
18962  , p_source_9            IN NUMBER
18963 --Distribution Type
18964  , p_source_10            IN VARCHAR2
18965 --Exchange Rate
18966  , p_source_14            IN NUMBER
18967 --Exchange Rate Type
18968  , p_source_15            IN VARCHAR2
18969 --Receipt Applied To Application Identifier
18970  , p_source_17            IN NUMBER
18971 --Transaction Distribution Type
18972  , p_source_18            IN VARCHAR2
18973 --Transaction Entity Code
18974  , p_source_19            IN VARCHAR2
18975 --Transaction Distribution Identifier
18976  , p_source_20            IN NUMBER
18977 --Transaction Identifier
18978  , p_source_21            IN NUMBER
18979 --DIST_ENT_AMT_FROM
18983 --Exchange Date
18980  , p_source_22            IN NUMBER
18981 --Applying Document Currency Code
18982  , p_source_23            IN VARCHAR2
18984  , p_source_24            IN DATE
18985 --Accounting Amount
18986  , p_source_25            IN NUMBER
18987 --Distribution Party Type
18988  , p_source_28            IN VARCHAR2
18989 --Distribution Source Table
18990  , p_source_33            IN VARCHAR2
18991 --Receipt Pay From Customer
18992  , p_source_34            IN NUMBER
18993 --Receipt Customer Site Use Identifier
18994  , p_source_35            IN NUMBER
18995 --Receipt Application Status
18996  , p_source_36            IN VARCHAR2
18997 )
18998 IS
18999 
19000 l_component_type              VARCHAR2(80);
19001 l_component_code              VARCHAR2(30);
19002 l_component_type_code         VARCHAR2(1);
19003 l_component_appl_id           INTEGER;
19004 l_amb_context_code            VARCHAR2(30);
19005 l_entity_code                 VARCHAR2(30);
19006 l_event_class_code            VARCHAR2(30);
19007 l_ae_header_id                NUMBER;
19008 l_event_type_code             VARCHAR2(30);
19009 l_line_definition_code        VARCHAR2(30);
19010 l_line_definition_owner_code  VARCHAR2(1);
19011 --
19012 -- adr variables
19013 l_segment                     VARCHAR2(30);
19014 l_ccid                        NUMBER;
19015 l_adr_transaction_coa_id      NUMBER;
19016 l_adr_accounting_coa_id       NUMBER;
19017 l_adr_flexfield_segment_code  VARCHAR2(30);
19018 l_adr_flex_value_set_id       NUMBER;
19019 l_adr_value_type_code         VARCHAR2(30);
19020 l_adr_value_combination_id    NUMBER;
19021 l_adr_value_segment_code      VARCHAR2(30);
19022 
19023 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
19024 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
19025 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
19026 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
19027 
19028 -- 4262811 Variables ------------------------------------------------------------------------------------------
19029 l_entered_amt_idx             NUMBER;
19030 l_accted_amt_idx              NUMBER;
19031 l_acc_rev_flag                VARCHAR2(1);
19032 l_accrual_line_num            NUMBER;
19033 l_tmp_amt                     NUMBER;
19034 l_acc_rev_natural_side_code   VARCHAR2(1);
19035 
19036 l_num_entries                 NUMBER;
19037 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
19038 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
19039 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
19040 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
19041 l_recog_line_1                NUMBER;
19042 l_recog_line_2                NUMBER;
19043 
19044 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
19045 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
19046 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
19047 
19048 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
19049 
19050 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
19051 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
19052 
19053 ---------------------------------------------------------------------------------------------------------------
19054 
19055 
19056 --
19057 -- bulk performance
19058 --
19059 l_balance_type_code           VARCHAR2(1);
19060 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
19061 l_log_module                  VARCHAR2(240);
19062 
19063 --
19064 -- Upgrade strategy
19065 --
19066 l_actual_upg_option           VARCHAR2(1);
19067 l_enc_upg_option           VARCHAR2(1);
19068 
19069 --
19070 BEGIN
19071 --
19072 IF g_log_enabled THEN
19073       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_37';
19074 END IF;
19075 --
19076 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19077 
19078       trace
19079          (p_msg      => 'BEGIN of AcctLineType_37'
19080          ,p_level    => C_LEVEL_PROCEDURE
19081          ,p_module   => l_log_module);
19082 
19083 END IF;
19084 --
19085 l_component_type             := 'AMB_JLT';
19086 l_component_code             := 'RCT_UNAPP_DEBIT';
19087 l_component_type_code        := 'S';
19088 l_component_appl_id          :=  222;
19089 l_amb_context_code           := 'DEFAULT';
19090 l_entity_code                := 'RECEIPTS';
19091 l_event_class_code           := 'RECEIPT';
19092 l_event_type_code            := 'RECEIPT_ALL';
19093 l_line_definition_owner_code := 'S';
19094 l_line_definition_code       := 'RCT_CASH_JLD';
19095 --
19096 l_balance_type_code          := 'A';
19097 l_segment                     := NULL;
19098 l_ccid                        := NULL;
19099 l_adr_transaction_coa_id      := NULL;
19100 l_adr_accounting_coa_id       := NULL;
19101 l_adr_flexfield_segment_code  := NULL;
19102 l_adr_flex_value_set_id       := NULL;
19103 l_adr_value_type_code         := NULL;
19104 l_adr_value_combination_id    := NULL;
19105 l_adr_value_segment_code      := NULL;
19106 
19107 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
19108 l_bflow_class_code           := '';    -- 4219869 Business Flow
19112 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
19109 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
19110 l_budgetary_control_flag     := 'N';
19111 
19113 l_bflow_applied_to_amt       := NULL; -- 5132302
19114 l_entered_amt_idx            := NULL;          -- 4262811
19115 l_accted_amt_idx             := NULL;          -- 4262811
19116 l_acc_rev_flag               := NULL;          -- 4262811
19117 l_accrual_line_num           := NULL;          -- 4262811
19118 l_tmp_amt                    := NULL;          -- 4262811
19119 --
19120  
19121 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
19122     l_balance_type_code <> 'B' THEN
19123 IF ((NVL(p_source_7,'
19124 ') =  'REC' AND 
19125 NVL(p_source_8,'
19126 ') =  'N') OR 
19127 (NVL(p_source_8,'
19128 ') =  'N' AND 
19129 NVL(p_source_7,'
19130 ') =  'CASH') OR 
19131 (NVL(p_source_8,'
19132 ') =  'N' AND 
19133 NVL(p_source_7,'
19134 ') =  'CONFIRMATION') OR 
19135 (NVL(p_source_8,'
19136 ') =  'N' AND 
19137 NVL(p_source_7,'
19138 ') =  'CURR_ROUND') OR 
19139 (NVL(p_source_8,'
19140 ') =  'N' AND 
19141 NVL(p_source_7,'
19142 ') =  'DEFERRED_TAX') OR 
19143 (NVL(p_source_8,'
19144 ') =  'N' AND 
19145 NVL(p_source_33,'
19146 ') =  'CRH' AND 
19147 NVL(p_source_7,'
19148 ') =  'FACTOR') OR 
19149 (NVL(p_source_8,'
19150 ') =  'N' AND 
19151 NVL(p_source_7,'
19152 ') =  'ACC') OR 
19153 (NVL(p_source_8,'
19154 ') =  'N' AND 
19155 NVL(p_source_7,'
19156 ') =  'REMITTANCE' AND 
19157 NVL(p_source_33,'
19158 ') =  'CRH') OR 
19159 (NVL(p_source_8,'
19160 ') =  'N' AND 
19161 NVL(p_source_7,'
19162 ') =  'SHORT_TERM_DEBT') OR 
19163 (NVL(p_source_8,'
19164 ') =  'N' AND 
19165 NVL(p_source_7,'
19166 ') =  'TAX') OR 
19167 (NVL(p_source_8,'
19168 ') =  'N' AND 
19169 NVL(p_source_7,'
19170 ') =  'UNID') OR 
19171 (NVL(p_source_8,'
19172 ') =  'N' AND 
19173 NVL(p_source_7,'
19174 ') =  'BANK_CHARGES') OR 
19175 (NVL(p_source_8,'
19176 ') =  'N' AND 
19177 NVL(p_source_7,'
19178 ') =  'EDISC') OR 
19179 (NVL(p_source_8,'
19180 ') =  'N' AND 
19181 NVL(p_source_7,'
19182 ') =  'UNEDISC')
19183 ) AND NVL(p_source_36,'
19184 ') <>  'UNID'
19185  THEN 
19186 
19187    --
19188    XLA_AE_LINES_PKG.SetNewLine;
19189 
19190    p_balance_type_code          := l_balance_type_code;
19191    -- set the flag so later we will know whether the gain loss line needs to be created
19192    
19193    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
19194      p_actual_flag :='A';
19195    END IF;
19196 
19197    --
19198    -- bulk performance
19199    --
19200    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
19201                                       p_header_num   => 0); -- 4262811
19202    --
19203    -- set accounting line options
19204    --
19205    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
19206            p_natural_side_code          => 'D'
19207          , p_gain_or_loss_flag          => 'N'
19208          , p_gl_transfer_mode_code      => 'S'
19209          , p_acct_entry_type_code       => 'A'
19210          , p_switch_side_flag           => 'Y'
19211          , p_merge_duplicate_code       => 'A'
19212          );
19213    --
19214    l_acc_rev_natural_side_code := 'C';  -- 4262811
19215    -- 
19216    --
19217    -- set accounting line type info
19218    --
19219    xla_ae_lines_pkg.SetAcctLineType
19220       (p_component_type             => l_component_type
19221       ,p_event_type_code            => l_event_type_code
19222       ,p_line_definition_owner_code => l_line_definition_owner_code
19223       ,p_line_definition_code       => l_line_definition_code
19224       ,p_accounting_line_code       => l_component_code
19225       ,p_accounting_line_type_code  => l_component_type_code
19226       ,p_accounting_line_appl_id    => l_component_appl_id
19227       ,p_amb_context_code           => l_amb_context_code
19228       ,p_entity_code                => l_entity_code
19229       ,p_event_class_code           => l_event_class_code);
19230    --
19231    -- set accounting class
19232    --
19233    xla_ae_lines_pkg.SetAcctClass(
19234            p_accounting_class_code  => 'UNAPP'
19235          , p_ae_header_id           => l_ae_header_id
19236          );
19237 
19238    --
19239    -- set rounding class
19240    --
19241    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
19242                       'RECEIVABLE';
19243 
19244    --
19245    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
19246    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
19247    --
19248    -- bulk performance
19249    --
19250    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
19251 
19252    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
19253       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
19254 
19255    -- 4955764
19256    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
19257       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
19261    --
19258 
19259    -- 4458381 Public Sector Enh
19260    
19262    -- set accounting attributes for the line type
19263    --
19264    l_entered_amt_idx := 8;
19265    l_accted_amt_idx  := 13;
19266    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
19267    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
19268    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
19269    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
19270    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
19271    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
19272    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
19273    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
19274    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
19275    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
19276    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
19277    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
19278    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
19279    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
19280    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
19281    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
19282    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
19283    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
19284    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
19285    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
19286    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
19287    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
19288    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
19289    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
19290    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
19291    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
19292    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
19293    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
19294    l_rec_acct_attrs.array_num_value(14)  := p_source_34;
19295    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
19296    l_rec_acct_attrs.array_num_value(15)  := p_source_35;
19297    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
19298    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
19299 
19300    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
19301    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
19302 
19303    ---------------------------------------------------------------------------------------------------------------
19304    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
19305    ---------------------------------------------------------------------------------------------------------------
19306    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
19307 
19308    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
19309    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
19310 
19311    IF xla_accounting_cache_pkg.GetValueChar
19312          (p_source_code         => 'LEDGER_CATEGORY_CODE'
19313          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
19314    AND l_bflow_method_code = 'PRIOR_ENTRY'
19315 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
19316    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
19317          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
19318        )
19319    THEN
19320          xla_ae_lines_pkg.BflowUpgEntry
19321            (p_business_method_code    => l_bflow_method_code
19322            ,p_business_class_code     => l_bflow_class_code
19323            ,p_balance_type            => l_balance_type_code);
19324    ELSE
19325       NULL;
19326 -- No business flow processing for business flow method of NONE.
19327    END IF;
19328 
19329    --
19330    -- call analytical criteria
19331    --
19332    
19333    --
19334    -- call description
19335    --
19336    -- No description or it is inherited.
19337    --
19338    -- call ADRs
19339    -- Bug 4922099
19340    --
19341    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
19342         (NVL(l_actual_upg_option, 'N') = 'O') OR
19343         (NVL(l_enc_upg_option, 'N') = 'O')
19344       )
19345    THEN
19346    NULL;
19347    --
19348    --
19349    
19350   l_ccid := AcctDerRule_2(
19351            p_application_id           => p_application_id
19352          , p_ae_header_id             => l_ae_header_id 
19353 , p_source_2 => p_source_2
19354          , x_transaction_coa_id       => l_adr_transaction_coa_id
19355          , x_accounting_coa_id        => l_adr_accounting_coa_id
19356          , x_value_type_code          => l_adr_value_type_code
19357          , p_side                     => 'NA'
19358    );
19359 
19360    xla_ae_lines_pkg.set_ccid(
19361     p_code_combination_id          => l_ccid
19362   , p_value_type_code              => l_adr_value_type_code
19363   , p_transaction_coa_id           => l_adr_transaction_coa_id
19364   , p_accounting_coa_id            => l_adr_accounting_coa_id
19365   , p_adr_code                     => 'RMT_BNK_UNAPP_CCID'
19366   , p_adr_type_code                => 'S'
19367   , p_component_type               => l_component_type
19371   , p_amb_context_code             => l_amb_context_code
19368   , p_component_code               => l_component_code
19369   , p_component_type_code          => l_component_type_code
19370   , p_component_appl_id            => l_component_appl_id
19372   , p_side                         => 'NA'
19373   );
19374 
19375 
19376    --
19377    --
19378    END IF;
19379    --
19380    -- Bug 4922099
19381    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
19382           (NVL(l_enc_upg_option, 'N') = 'O')
19383         ) AND
19384         (l_bflow_method_code = 'PRIOR_ENTRY')
19385       )
19386    THEN
19387       IF
19388       --
19389       1 = 2
19390       --
19391       THEN
19392       xla_accounting_err_pkg.build_message
19393                                     (p_appli_s_name            => 'XLA'
19394                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
19395                                     ,p_token_1                 => 'LINE_NUMBER'
19396                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
19397                                     ,p_token_2                 => 'LINE_TYPE_NAME'
19398                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
19399                                                                              l_component_type
19400                                                                             ,l_component_code
19401                                                                             ,l_component_type_code
19402                                                                             ,l_component_appl_id
19403                                                                             ,l_amb_context_code
19404                                                                             ,l_entity_code
19405                                                                             ,l_event_class_code
19406                                                                            )
19407                                     ,p_token_3                 => 'OWNER'
19408                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
19409                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
19410                                                                           ,p_lookup_code    => l_component_type_code
19411                                                                          )
19412                                     ,p_token_4                 => 'PRODUCT_NAME'
19413                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
19414                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
19415                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
19416                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
19417                                     ,p_ae_header_id            =>  NULL
19418                                        );
19419 
19420         IF (C_LEVEL_ERROR>= g_log_level) THEN
19421                  trace
19422                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
19423                       ,p_level    => C_LEVEL_ERROR
19424                       ,p_module   => l_log_module);
19425         END IF;
19426       END IF;
19427    END IF;
19428    --
19429    --
19430    ------------------------------------------------------------------------------------------------
19431    -- 4219869 Business Flow
19432    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
19433    -- Prior Entry.  Currently, the following code is always generated.
19434    ------------------------------------------------------------------------------------------------
19435    XLA_AE_LINES_PKG.ValidateCurrentLine;
19436 
19437    ------------------------------------------------------------------------------------
19438    -- 4219869 Business Flow
19439    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
19440    ------------------------------------------------------------------------------------
19441    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
19442 
19443    ----------------------------------------------------------------------------------
19444    -- 4219869 Business Flow
19445    -- Update journal entry status -- Need to generate this within IF <condition>
19446    ----------------------------------------------------------------------------------
19447    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
19448          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
19449          ,p_balance_type_code => l_balance_type_code
19450          );
19451 
19452    -------------------------------------------------------------------------------------------
19453    -- 4262811 - Generate the Accrual Reversal lines
19454    -------------------------------------------------------------------------------------------
19455    BEGIN
19456       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
19457                               (g_array_event(p_event_id).array_value_num('header_index'));
19458       IF l_acc_rev_flag IS NULL THEN
19459          l_acc_rev_flag := 'N';
19460       END IF;
19461    EXCEPTION
19462       WHEN OTHERS THEN
19463          l_acc_rev_flag := 'N';
19464    END;
19465    --
19466    IF (l_acc_rev_flag = 'Y') THEN
19467 
19471        ------------------------------------------------------------------------------------------
19468        -- 4645092  ------------------------------------------------------------------------------
19469        -- To allow MPA report to determine if it should generate report process
19470        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
19472 
19473        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
19474        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
19475    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
19476    -- call ADRs
19477    -- Bug 4922099
19478    --
19479    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
19480         (NVL(l_actual_upg_option, 'N') = 'O') OR
19481         (NVL(l_enc_upg_option, 'N') = 'O')
19482       )
19483    THEN
19484    NULL;
19485    --
19486    --
19487    
19488   l_ccid := AcctDerRule_2(
19489            p_application_id           => p_application_id
19490          , p_ae_header_id             => l_ae_header_id 
19491 , p_source_2 => p_source_2
19492          , x_transaction_coa_id       => l_adr_transaction_coa_id
19493          , x_accounting_coa_id        => l_adr_accounting_coa_id
19494          , x_value_type_code          => l_adr_value_type_code
19495          , p_side                     => 'NA'
19496    );
19497 
19498    xla_ae_lines_pkg.set_ccid(
19499     p_code_combination_id          => l_ccid
19500   , p_value_type_code              => l_adr_value_type_code
19501   , p_transaction_coa_id           => l_adr_transaction_coa_id
19502   , p_accounting_coa_id            => l_adr_accounting_coa_id
19503   , p_adr_code                     => 'RMT_BNK_UNAPP_CCID'
19504   , p_adr_type_code                => 'S'
19505   , p_component_type               => l_component_type
19506   , p_component_code               => l_component_code
19507   , p_component_type_code          => l_component_type_code
19508   , p_component_appl_id            => l_component_appl_id
19509   , p_amb_context_code             => l_amb_context_code
19510   , p_side                         => 'NA'
19511   );
19512 
19513 
19514    --
19515    --
19516    END IF;
19517 
19518        --
19519        -- Update the line information that should be overwritten
19520        --
19521        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
19522                                          p_header_num   => 1);
19523        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
19524 
19525        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
19526 
19527        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
19528           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
19529        END IF;
19530 
19531       --
19532       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
19533       --
19534       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
19535           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
19536       ELSE
19537           ---------------------------------------------------------------------------------------------------
19538           -- 4262811a Switch Sign
19539           ---------------------------------------------------------------------------------------------------
19540           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
19541           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
19542                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19543           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
19544                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19545           -- 5132302
19546           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
19547                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
19548 
19549       END IF;
19550 
19551       -- 4955764
19552       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
19553       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
19554 
19555 
19556       XLA_AE_LINES_PKG.ValidateCurrentLine;
19557       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
19558 
19559       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
19560                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
19561                ,p_balance_type_code => l_balance_type_code);
19562 
19563    END IF;
19564 
19565    -----------------------------------------------------------------------------------------
19566    -- 4262811 Multiperiod Accounting
19567    -----------------------------------------------------------------------------------------
19568      -- No MPA option is assigned.
19569 
19570 
19571 END IF;
19572 END IF;
19573 --
19574 
19575 --
19576 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19577    trace
19578       (p_msg      => 'END of AcctLineType_37'
19579       ,p_level    => C_LEVEL_PROCEDURE
19580       ,p_module   => l_log_module);
19581 END IF;
19585       RAISE;
19582 --
19583 EXCEPTION
19584   WHEN xla_exceptions_pkg.application_exception THEN
19586   WHEN OTHERS THEN
19587        xla_exceptions_pkg.raise_message
19588            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_37');
19589 END AcctLineType_37;
19590 --
19591 
19592 ---------------------------------------
19593 --
19594 -- PRIVATE FUNCTION
19595 --         AcctLineType_38
19596 --
19597 ---------------------------------------
19598 PROCEDURE AcctLineType_38 (
19599   p_application_id        IN NUMBER
19600  ,p_event_id              IN NUMBER
19601  ,p_calculate_acctd_flag  IN VARCHAR2
19602  ,p_calculate_g_l_flag    IN VARCHAR2
19603  ,p_actual_flag           IN OUT VARCHAR2
19604  ,p_balance_type_code     OUT VARCHAR2
19605  ,p_gain_or_loss_ref      OUT VARCHAR2
19606  
19607 --Distribution GL Account
19608  , p_source_1            IN NUMBER
19609 --Distribution Source Type
19610  , p_source_7            IN VARCHAR2
19611 --Distribution Multi Fund Additional Entry
19612  , p_source_8            IN VARCHAR2
19613 --Distribution Line Identifier
19614  , p_source_9            IN NUMBER
19615 --Distribution Type
19616  , p_source_10            IN VARCHAR2
19617 --Exchange Rate
19618  , p_source_14            IN NUMBER
19619 --Exchange Rate Type
19620  , p_source_15            IN VARCHAR2
19621 --Receipt Applied To Application Identifier
19622  , p_source_17            IN NUMBER
19623 --Transaction Distribution Type
19624  , p_source_18            IN VARCHAR2
19625 --Transaction Entity Code
19626  , p_source_19            IN VARCHAR2
19627 --Transaction Distribution Identifier
19628  , p_source_20            IN NUMBER
19629 --Transaction Identifier
19630  , p_source_21            IN NUMBER
19631 --DIST_ENT_AMT_FROM
19632  , p_source_22            IN NUMBER
19633 --Applying Document Currency Code
19634  , p_source_23            IN VARCHAR2
19635 --Exchange Date
19636  , p_source_24            IN DATE
19637 --Accounting Amount
19638  , p_source_25            IN NUMBER
19639 --Distribution Party Identifier
19640  , p_source_26            IN NUMBER
19641 --Distribution Party Site Id
19642  , p_source_27            IN NUMBER
19643 --Distribution Party Type
19644  , p_source_28            IN VARCHAR2
19645 )
19646 IS
19647 
19648 l_component_type              VARCHAR2(80);
19649 l_component_code              VARCHAR2(30);
19650 l_component_type_code         VARCHAR2(1);
19651 l_component_appl_id           INTEGER;
19652 l_amb_context_code            VARCHAR2(30);
19653 l_entity_code                 VARCHAR2(30);
19654 l_event_class_code            VARCHAR2(30);
19655 l_ae_header_id                NUMBER;
19656 l_event_type_code             VARCHAR2(30);
19657 l_line_definition_code        VARCHAR2(30);
19658 l_line_definition_owner_code  VARCHAR2(1);
19659 --
19660 -- adr variables
19661 l_segment                     VARCHAR2(30);
19662 l_ccid                        NUMBER;
19663 l_adr_transaction_coa_id      NUMBER;
19664 l_adr_accounting_coa_id       NUMBER;
19665 l_adr_flexfield_segment_code  VARCHAR2(30);
19666 l_adr_flex_value_set_id       NUMBER;
19667 l_adr_value_type_code         VARCHAR2(30);
19668 l_adr_value_combination_id    NUMBER;
19669 l_adr_value_segment_code      VARCHAR2(30);
19670 
19671 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
19672 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
19673 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
19674 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
19675 
19676 -- 4262811 Variables ------------------------------------------------------------------------------------------
19677 l_entered_amt_idx             NUMBER;
19678 l_accted_amt_idx              NUMBER;
19679 l_acc_rev_flag                VARCHAR2(1);
19680 l_accrual_line_num            NUMBER;
19681 l_tmp_amt                     NUMBER;
19682 l_acc_rev_natural_side_code   VARCHAR2(1);
19683 
19684 l_num_entries                 NUMBER;
19685 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
19686 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
19687 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
19688 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
19689 l_recog_line_1                NUMBER;
19690 l_recog_line_2                NUMBER;
19691 
19692 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
19693 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
19694 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
19695 
19696 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
19697 
19698 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
19699 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
19700 
19701 ---------------------------------------------------------------------------------------------------------------
19702 
19703 
19704 --
19705 -- bulk performance
19706 --
19707 l_balance_type_code           VARCHAR2(1);
19708 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
19709 l_log_module                  VARCHAR2(240);
19710 
19711 --
19712 -- Upgrade strategy
19713 --
19717 --
19714 l_actual_upg_option           VARCHAR2(1);
19715 l_enc_upg_option           VARCHAR2(1);
19716 
19718 BEGIN
19719 --
19720 IF g_log_enabled THEN
19721       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_38';
19722 END IF;
19723 --
19724 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
19725 
19726       trace
19727          (p_msg      => 'BEGIN of AcctLineType_38'
19728          ,p_level    => C_LEVEL_PROCEDURE
19729          ,p_module   => l_log_module);
19730 
19731 END IF;
19732 --
19733 l_component_type             := 'AMB_JLT';
19734 l_component_code             := 'RCT_UNID';
19735 l_component_type_code        := 'S';
19736 l_component_appl_id          :=  222;
19737 l_amb_context_code           := 'DEFAULT';
19738 l_entity_code                := 'RECEIPTS';
19739 l_event_class_code           := 'RECEIPT';
19740 l_event_type_code            := 'RECEIPT_ALL';
19741 l_line_definition_owner_code := 'S';
19742 l_line_definition_code       := 'RCT_CASH_JLD';
19743 --
19744 l_balance_type_code          := 'A';
19745 l_segment                     := NULL;
19746 l_ccid                        := NULL;
19747 l_adr_transaction_coa_id      := NULL;
19748 l_adr_accounting_coa_id       := NULL;
19749 l_adr_flexfield_segment_code  := NULL;
19750 l_adr_flex_value_set_id       := NULL;
19751 l_adr_value_type_code         := NULL;
19752 l_adr_value_combination_id    := NULL;
19753 l_adr_value_segment_code      := NULL;
19754 
19755 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
19756 l_bflow_class_code           := '';    -- 4219869 Business Flow
19757 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
19758 l_budgetary_control_flag     := 'N';
19759 
19760 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
19761 l_bflow_applied_to_amt       := NULL; -- 5132302
19762 l_entered_amt_idx            := NULL;          -- 4262811
19763 l_accted_amt_idx             := NULL;          -- 4262811
19764 l_acc_rev_flag               := NULL;          -- 4262811
19765 l_accrual_line_num           := NULL;          -- 4262811
19766 l_tmp_amt                    := NULL;          -- 4262811
19767 --
19768  
19769 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
19770     l_balance_type_code <> 'B' THEN
19771 IF NVL(p_source_7,'
19772 ') =  'UNID' AND 
19773 NVL(p_source_8,'
19774 ') =  'N'
19775  THEN 
19776 
19777    --
19778    XLA_AE_LINES_PKG.SetNewLine;
19779 
19780    p_balance_type_code          := l_balance_type_code;
19781    -- set the flag so later we will know whether the gain loss line needs to be created
19782    
19783    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
19784      p_actual_flag :='A';
19785    END IF;
19786 
19787    --
19788    -- bulk performance
19789    --
19790    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
19791                                       p_header_num   => 0); -- 4262811
19792    --
19793    -- set accounting line options
19794    --
19795    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
19796            p_natural_side_code          => 'C'
19797          , p_gain_or_loss_flag          => 'N'
19798          , p_gl_transfer_mode_code      => 'S'
19799          , p_acct_entry_type_code       => 'A'
19800          , p_switch_side_flag           => 'Y'
19801          , p_merge_duplicate_code       => 'A'
19802          );
19803    --
19804    l_acc_rev_natural_side_code := 'D';  -- 4262811
19805    -- 
19806    --
19807    -- set accounting line type info
19808    --
19809    xla_ae_lines_pkg.SetAcctLineType
19810       (p_component_type             => l_component_type
19811       ,p_event_type_code            => l_event_type_code
19812       ,p_line_definition_owner_code => l_line_definition_owner_code
19813       ,p_line_definition_code       => l_line_definition_code
19814       ,p_accounting_line_code       => l_component_code
19815       ,p_accounting_line_type_code  => l_component_type_code
19816       ,p_accounting_line_appl_id    => l_component_appl_id
19817       ,p_amb_context_code           => l_amb_context_code
19818       ,p_entity_code                => l_entity_code
19819       ,p_event_class_code           => l_event_class_code);
19820    --
19821    -- set accounting class
19822    --
19823    xla_ae_lines_pkg.SetAcctClass(
19824            p_accounting_class_code  => 'UNID'
19825          , p_ae_header_id           => l_ae_header_id
19826          );
19827 
19828    --
19829    -- set rounding class
19830    --
19831    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
19832                       'RECEIVABLE';
19833 
19834    --
19835    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
19836    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
19837    --
19838    -- bulk performance
19839    --
19840    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
19841 
19842    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
19843       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
19844 
19845    -- 4955764
19846    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
19847       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
19851    --
19848 
19849    -- 4458381 Public Sector Enh
19850    
19852    -- set accounting attributes for the line type
19853    --
19854    l_entered_amt_idx := 8;
19855    l_accted_amt_idx  := 13;
19856    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
19857    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
19858    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
19859    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
19860    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
19861    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
19862    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
19863    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
19864    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
19865    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
19866    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
19867    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
19868    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
19869    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
19870    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
19871    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
19872    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
19873    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
19874    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
19875    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
19876    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
19877    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
19878    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
19879    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
19880    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
19881    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
19882    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
19883    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
19884    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
19885    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
19886    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
19887    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
19888    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
19889 
19890    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
19891    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
19892 
19893    ---------------------------------------------------------------------------------------------------------------
19894    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
19895    ---------------------------------------------------------------------------------------------------------------
19896    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
19897 
19898    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
19899    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
19900 
19901    IF xla_accounting_cache_pkg.GetValueChar
19902          (p_source_code         => 'LEDGER_CATEGORY_CODE'
19903          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
19904    AND l_bflow_method_code = 'PRIOR_ENTRY'
19905 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
19906    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
19907          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
19908        )
19909    THEN
19910          xla_ae_lines_pkg.BflowUpgEntry
19911            (p_business_method_code    => l_bflow_method_code
19912            ,p_business_class_code     => l_bflow_class_code
19913            ,p_balance_type            => l_balance_type_code);
19914    ELSE
19915       NULL;
19916 -- No business flow processing for business flow method of NONE.
19917    END IF;
19918 
19919    --
19920    -- call analytical criteria
19921    --
19922    
19923    --
19924    -- call description
19925    --
19926    -- No description or it is inherited.
19927    --
19928    -- call ADRs
19929    -- Bug 4922099
19930    --
19931    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
19932         (NVL(l_actual_upg_option, 'N') = 'O') OR
19933         (NVL(l_enc_upg_option, 'N') = 'O')
19934       )
19935    THEN
19936    NULL;
19937    --
19938    --
19939    
19940   l_ccid := AcctDerRule_1(
19941            p_application_id           => p_application_id
19942          , p_ae_header_id             => l_ae_header_id 
19943 , p_source_1 => p_source_1
19944          , x_transaction_coa_id       => l_adr_transaction_coa_id
19945          , x_accounting_coa_id        => l_adr_accounting_coa_id
19946          , x_value_type_code          => l_adr_value_type_code
19947          , p_side                     => 'NA'
19948    );
19949 
19950    xla_ae_lines_pkg.set_ccid(
19951     p_code_combination_id          => l_ccid
19952   , p_value_type_code              => l_adr_value_type_code
19953   , p_transaction_coa_id           => l_adr_transaction_coa_id
19954   , p_accounting_coa_id            => l_adr_accounting_coa_id
19955   , p_adr_code                     => 'DIST_CCID'
19956   , p_adr_type_code                => 'S'
19960   , p_component_appl_id            => l_component_appl_id
19957   , p_component_type               => l_component_type
19958   , p_component_code               => l_component_code
19959   , p_component_type_code          => l_component_type_code
19961   , p_amb_context_code             => l_amb_context_code
19962   , p_side                         => 'NA'
19963   );
19964 
19965 
19966    --
19967    --
19968    END IF;
19969    --
19970    -- Bug 4922099
19971    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
19972           (NVL(l_enc_upg_option, 'N') = 'O')
19973         ) AND
19974         (l_bflow_method_code = 'PRIOR_ENTRY')
19975       )
19976    THEN
19977       IF
19978       --
19979       1 = 2
19980       --
19981       THEN
19982       xla_accounting_err_pkg.build_message
19983                                     (p_appli_s_name            => 'XLA'
19984                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
19985                                     ,p_token_1                 => 'LINE_NUMBER'
19986                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
19987                                     ,p_token_2                 => 'LINE_TYPE_NAME'
19988                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
19989                                                                              l_component_type
19990                                                                             ,l_component_code
19991                                                                             ,l_component_type_code
19992                                                                             ,l_component_appl_id
19993                                                                             ,l_amb_context_code
19994                                                                             ,l_entity_code
19995                                                                             ,l_event_class_code
19996                                                                            )
19997                                     ,p_token_3                 => 'OWNER'
19998                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
19999                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
20000                                                                           ,p_lookup_code    => l_component_type_code
20001                                                                          )
20002                                     ,p_token_4                 => 'PRODUCT_NAME'
20003                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
20004                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
20005                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
20006                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
20007                                     ,p_ae_header_id            =>  NULL
20008                                        );
20009 
20010         IF (C_LEVEL_ERROR>= g_log_level) THEN
20011                  trace
20012                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
20013                       ,p_level    => C_LEVEL_ERROR
20014                       ,p_module   => l_log_module);
20015         END IF;
20016       END IF;
20017    END IF;
20018    --
20019    --
20020    ------------------------------------------------------------------------------------------------
20021    -- 4219869 Business Flow
20022    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
20023    -- Prior Entry.  Currently, the following code is always generated.
20024    ------------------------------------------------------------------------------------------------
20025    XLA_AE_LINES_PKG.ValidateCurrentLine;
20026 
20027    ------------------------------------------------------------------------------------
20028    -- 4219869 Business Flow
20029    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
20030    ------------------------------------------------------------------------------------
20031    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
20032 
20033    ----------------------------------------------------------------------------------
20034    -- 4219869 Business Flow
20035    -- Update journal entry status -- Need to generate this within IF <condition>
20036    ----------------------------------------------------------------------------------
20037    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
20038          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
20039          ,p_balance_type_code => l_balance_type_code
20040          );
20041 
20042    -------------------------------------------------------------------------------------------
20043    -- 4262811 - Generate the Accrual Reversal lines
20044    -------------------------------------------------------------------------------------------
20045    BEGIN
20046       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
20047                               (g_array_event(p_event_id).array_value_num('header_index'));
20048       IF l_acc_rev_flag IS NULL THEN
20049          l_acc_rev_flag := 'N';
20050       END IF;
20054    END;
20051    EXCEPTION
20052       WHEN OTHERS THEN
20053          l_acc_rev_flag := 'N';
20055    --
20056    IF (l_acc_rev_flag = 'Y') THEN
20057 
20058        -- 4645092  ------------------------------------------------------------------------------
20059        -- To allow MPA report to determine if it should generate report process
20060        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
20061        ------------------------------------------------------------------------------------------
20062 
20063        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
20064        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
20065    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
20066    -- call ADRs
20067    -- Bug 4922099
20068    --
20069    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
20070         (NVL(l_actual_upg_option, 'N') = 'O') OR
20071         (NVL(l_enc_upg_option, 'N') = 'O')
20072       )
20073    THEN
20074    NULL;
20075    --
20076    --
20077    
20078   l_ccid := AcctDerRule_1(
20079            p_application_id           => p_application_id
20080          , p_ae_header_id             => l_ae_header_id 
20081 , p_source_1 => p_source_1
20082          , x_transaction_coa_id       => l_adr_transaction_coa_id
20083          , x_accounting_coa_id        => l_adr_accounting_coa_id
20084          , x_value_type_code          => l_adr_value_type_code
20085          , p_side                     => 'NA'
20086    );
20087 
20088    xla_ae_lines_pkg.set_ccid(
20089     p_code_combination_id          => l_ccid
20090   , p_value_type_code              => l_adr_value_type_code
20091   , p_transaction_coa_id           => l_adr_transaction_coa_id
20092   , p_accounting_coa_id            => l_adr_accounting_coa_id
20093   , p_adr_code                     => 'DIST_CCID'
20094   , p_adr_type_code                => 'S'
20095   , p_component_type               => l_component_type
20096   , p_component_code               => l_component_code
20097   , p_component_type_code          => l_component_type_code
20098   , p_component_appl_id            => l_component_appl_id
20099   , p_amb_context_code             => l_amb_context_code
20100   , p_side                         => 'NA'
20101   );
20102 
20103 
20104    --
20105    --
20106    END IF;
20107 
20108        --
20109        -- Update the line information that should be overwritten
20110        --
20111        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
20112                                          p_header_num   => 1);
20113        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
20114 
20115        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
20116 
20117        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
20118           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
20119        END IF;
20120 
20121       --
20122       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
20123       --
20124       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
20125           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
20126       ELSE
20127           ---------------------------------------------------------------------------------------------------
20128           -- 4262811a Switch Sign
20129           ---------------------------------------------------------------------------------------------------
20130           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
20131           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
20132                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20133           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
20134                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20135           -- 5132302
20136           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
20137                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20138 
20139       END IF;
20140 
20141       -- 4955764
20142       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
20143       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
20144 
20145 
20146       XLA_AE_LINES_PKG.ValidateCurrentLine;
20147       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
20148 
20149       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
20150                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
20151                ,p_balance_type_code => l_balance_type_code);
20152 
20153    END IF;
20154 
20155    -----------------------------------------------------------------------------------------
20156    -- 4262811 Multiperiod Accounting
20157    -----------------------------------------------------------------------------------------
20158      -- No MPA option is assigned.
20159 
20160 
20161 END IF;
20162 END IF;
20163 --
20164 
20165 --
20169       ,p_level    => C_LEVEL_PROCEDURE
20166 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
20167    trace
20168       (p_msg      => 'END of AcctLineType_38'
20170       ,p_module   => l_log_module);
20171 END IF;
20172 --
20173 EXCEPTION
20174   WHEN xla_exceptions_pkg.application_exception THEN
20175       RAISE;
20176   WHEN OTHERS THEN
20177        xla_exceptions_pkg.raise_message
20178            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_38');
20179 END AcctLineType_38;
20180 --
20181 
20182 ---------------------------------------
20183 --
20184 -- PRIVATE FUNCTION
20185 --         AcctLineType_39
20186 --
20187 ---------------------------------------
20188 PROCEDURE AcctLineType_39 (
20189   p_application_id        IN NUMBER
20190  ,p_event_id              IN NUMBER
20191  ,p_calculate_acctd_flag  IN VARCHAR2
20192  ,p_calculate_g_l_flag    IN VARCHAR2
20193  ,p_actual_flag           IN OUT VARCHAR2
20194  ,p_balance_type_code     OUT VARCHAR2
20195  ,p_gain_or_loss_ref      OUT VARCHAR2
20196  
20197 --Distribution GL Account
20198  , p_source_1            IN NUMBER
20199 --Distribution Source Type
20200  , p_source_7            IN VARCHAR2
20201 --Distribution Multi Fund Additional Entry
20202  , p_source_8            IN VARCHAR2
20203 --Distribution Line Identifier
20204  , p_source_9            IN NUMBER
20205 --Distribution Type
20206  , p_source_10            IN VARCHAR2
20207 --Exchange Rate
20208  , p_source_14            IN NUMBER
20209 --Exchange Rate Type
20210  , p_source_15            IN VARCHAR2
20211 --Receipt Applied To Application Identifier
20212  , p_source_17            IN NUMBER
20213 --Transaction Distribution Type
20214  , p_source_18            IN VARCHAR2
20215 --Transaction Entity Code
20216  , p_source_19            IN VARCHAR2
20217 --Transaction Distribution Identifier
20218  , p_source_20            IN NUMBER
20219 --Transaction Identifier
20220  , p_source_21            IN NUMBER
20221 --DIST_ENT_AMT_FROM
20222  , p_source_22            IN NUMBER
20223 --Applying Document Currency Code
20224  , p_source_23            IN VARCHAR2
20225 --Exchange Date
20226  , p_source_24            IN DATE
20227 --Accounting Amount
20228  , p_source_25            IN NUMBER
20229 --Distribution Party Identifier
20230  , p_source_26            IN NUMBER
20231 --Distribution Party Site Id
20232  , p_source_27            IN NUMBER
20233 --Distribution Party Type
20234  , p_source_28            IN VARCHAR2
20235 --Receivable Activity Type
20236  , p_source_32            IN VARCHAR2
20237 )
20238 IS
20239 
20240 l_component_type              VARCHAR2(80);
20241 l_component_code              VARCHAR2(30);
20242 l_component_type_code         VARCHAR2(1);
20243 l_component_appl_id           INTEGER;
20244 l_amb_context_code            VARCHAR2(30);
20245 l_entity_code                 VARCHAR2(30);
20246 l_event_class_code            VARCHAR2(30);
20247 l_ae_header_id                NUMBER;
20248 l_event_type_code             VARCHAR2(30);
20249 l_line_definition_code        VARCHAR2(30);
20250 l_line_definition_owner_code  VARCHAR2(1);
20251 --
20252 -- adr variables
20253 l_segment                     VARCHAR2(30);
20254 l_ccid                        NUMBER;
20255 l_adr_transaction_coa_id      NUMBER;
20256 l_adr_accounting_coa_id       NUMBER;
20257 l_adr_flexfield_segment_code  VARCHAR2(30);
20258 l_adr_flex_value_set_id       NUMBER;
20259 l_adr_value_type_code         VARCHAR2(30);
20260 l_adr_value_combination_id    NUMBER;
20261 l_adr_value_segment_code      VARCHAR2(30);
20262 
20263 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
20264 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
20265 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
20266 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
20267 
20268 -- 4262811 Variables ------------------------------------------------------------------------------------------
20269 l_entered_amt_idx             NUMBER;
20270 l_accted_amt_idx              NUMBER;
20271 l_acc_rev_flag                VARCHAR2(1);
20272 l_accrual_line_num            NUMBER;
20273 l_tmp_amt                     NUMBER;
20274 l_acc_rev_natural_side_code   VARCHAR2(1);
20275 
20276 l_num_entries                 NUMBER;
20277 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
20278 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
20279 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
20280 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
20281 l_recog_line_1                NUMBER;
20282 l_recog_line_2                NUMBER;
20283 
20284 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
20285 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
20286 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
20287 
20288 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
20289 
20290 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
20291 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
20292 
20293 ---------------------------------------------------------------------------------------------------------------
20294 
20295 
20296 --
20297 -- bulk performance
20298 --
20299 l_balance_type_code           VARCHAR2(1);
20303 --
20300 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
20301 l_log_module                  VARCHAR2(240);
20302 
20304 -- Upgrade strategy
20305 --
20306 l_actual_upg_option           VARCHAR2(1);
20307 l_enc_upg_option           VARCHAR2(1);
20308 
20309 --
20310 BEGIN
20311 --
20312 IF g_log_enabled THEN
20313       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_39';
20314 END IF;
20315 --
20316 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
20317 
20318       trace
20319          (p_msg      => 'BEGIN of AcctLineType_39'
20320          ,p_level    => C_LEVEL_PROCEDURE
20321          ,p_module   => l_log_module);
20322 
20323 END IF;
20324 --
20325 l_component_type             := 'AMB_JLT';
20326 l_component_code             := 'RCT_WRITEOFF';
20327 l_component_type_code        := 'S';
20328 l_component_appl_id          :=  222;
20329 l_amb_context_code           := 'DEFAULT';
20330 l_entity_code                := 'RECEIPTS';
20331 l_event_class_code           := 'RECEIPT';
20332 l_event_type_code            := 'RECEIPT_ALL';
20333 l_line_definition_owner_code := 'S';
20334 l_line_definition_code       := 'RCT_CASH_JLD';
20335 --
20336 l_balance_type_code          := 'A';
20337 l_segment                     := NULL;
20338 l_ccid                        := NULL;
20339 l_adr_transaction_coa_id      := NULL;
20340 l_adr_accounting_coa_id       := NULL;
20341 l_adr_flexfield_segment_code  := NULL;
20342 l_adr_flex_value_set_id       := NULL;
20343 l_adr_value_type_code         := NULL;
20344 l_adr_value_combination_id    := NULL;
20345 l_adr_value_segment_code      := NULL;
20346 
20347 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
20348 l_bflow_class_code           := '';    -- 4219869 Business Flow
20349 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
20350 l_budgetary_control_flag     := 'N';
20351 
20352 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
20353 l_bflow_applied_to_amt       := NULL; -- 5132302
20354 l_entered_amt_idx            := NULL;          -- 4262811
20355 l_accted_amt_idx             := NULL;          -- 4262811
20356 l_acc_rev_flag               := NULL;          -- 4262811
20357 l_accrual_line_num           := NULL;          -- 4262811
20358 l_tmp_amt                    := NULL;          -- 4262811
20359 --
20360  
20361 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
20362     l_balance_type_code <> 'B' THEN
20363 IF NVL(p_source_7,'
20364 ') =  'ACTIVITY' AND 
20365 NVL(p_source_32,'
20366 ') =  'WRITEOFF' AND 
20367 NVL(p_source_8,'
20368 ') =  'N'
20369  THEN 
20370 
20371    --
20372    XLA_AE_LINES_PKG.SetNewLine;
20373 
20374    p_balance_type_code          := l_balance_type_code;
20375    -- set the flag so later we will know whether the gain loss line needs to be created
20376    
20377    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
20378      p_actual_flag :='A';
20379    END IF;
20380 
20381    --
20382    -- bulk performance
20383    --
20384    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
20385                                       p_header_num   => 0); -- 4262811
20386    --
20387    -- set accounting line options
20388    --
20389    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
20390            p_natural_side_code          => 'C'
20391          , p_gain_or_loss_flag          => 'N'
20392          , p_gl_transfer_mode_code      => 'S'
20393          , p_acct_entry_type_code       => 'A'
20394          , p_switch_side_flag           => 'Y'
20395          , p_merge_duplicate_code       => 'A'
20396          );
20397    --
20398    l_acc_rev_natural_side_code := 'D';  -- 4262811
20399    -- 
20400    --
20401    -- set accounting line type info
20402    --
20403    xla_ae_lines_pkg.SetAcctLineType
20404       (p_component_type             => l_component_type
20405       ,p_event_type_code            => l_event_type_code
20406       ,p_line_definition_owner_code => l_line_definition_owner_code
20407       ,p_line_definition_code       => l_line_definition_code
20408       ,p_accounting_line_code       => l_component_code
20409       ,p_accounting_line_type_code  => l_component_type_code
20410       ,p_accounting_line_appl_id    => l_component_appl_id
20411       ,p_amb_context_code           => l_amb_context_code
20412       ,p_entity_code                => l_entity_code
20413       ,p_event_class_code           => l_event_class_code);
20414    --
20415    -- set accounting class
20416    --
20417    xla_ae_lines_pkg.SetAcctClass(
20418            p_accounting_class_code  => 'WRITE_OFF'
20419          , p_ae_header_id           => l_ae_header_id
20420          );
20421 
20422    --
20423    -- set rounding class
20424    --
20425    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
20426                       'RECEIVABLE';
20427 
20428    --
20429    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
20430    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
20431    --
20432    -- bulk performance
20433    --
20434    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
20435 
20439    -- 4955764
20436    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
20437       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
20438 
20440    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
20441       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
20442 
20443    -- 4458381 Public Sector Enh
20444    
20445    --
20446    -- set accounting attributes for the line type
20447    --
20448    l_entered_amt_idx := 8;
20449    l_accted_amt_idx  := 13;
20450    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
20451    l_rec_acct_attrs.array_acct_attr_code(1) := 'APPLIED_TO_APPLICATION_ID';
20452    l_rec_acct_attrs.array_num_value(1)  := p_source_17;
20453    l_rec_acct_attrs.array_acct_attr_code(2) := 'APPLIED_TO_DISTRIBUTION_TYPE';
20454    l_rec_acct_attrs.array_char_value(2)  := p_source_18;
20455    l_rec_acct_attrs.array_acct_attr_code(3) := 'APPLIED_TO_ENTITY_CODE';
20456    l_rec_acct_attrs.array_char_value(3)  := p_source_19;
20457    l_rec_acct_attrs.array_acct_attr_code(4) := 'APPLIED_TO_FIRST_DIST_ID';
20458    l_rec_acct_attrs.array_num_value(4)  :=  to_char(p_source_20);
20459    l_rec_acct_attrs.array_acct_attr_code(5) := 'APPLIED_TO_FIRST_SYS_TRAN_ID';
20460    l_rec_acct_attrs.array_num_value(5)  :=  to_char(p_source_21);
20461    l_rec_acct_attrs.array_acct_attr_code(6) := 'DISTRIBUTION_IDENTIFIER_1';
20462    l_rec_acct_attrs.array_num_value(6)  :=  to_char(p_source_9);
20463    l_rec_acct_attrs.array_acct_attr_code(7) := 'DISTRIBUTION_TYPE';
20464    l_rec_acct_attrs.array_char_value(7)  := p_source_10;
20465    l_rec_acct_attrs.array_acct_attr_code(8) := 'ENTERED_CURRENCY_AMOUNT';
20466    l_rec_acct_attrs.array_num_value(8)  := p_source_22;
20467    l_rec_acct_attrs.array_acct_attr_code(9) := 'ENTERED_CURRENCY_CODE';
20468    l_rec_acct_attrs.array_char_value(9)  := p_source_23;
20469    l_rec_acct_attrs.array_acct_attr_code(10) := 'EXCHANGE_DATE';
20470    l_rec_acct_attrs.array_date_value(10)  := p_source_24;
20471    l_rec_acct_attrs.array_acct_attr_code(11) := 'EXCHANGE_RATE';
20472    l_rec_acct_attrs.array_num_value(11)  := p_source_14;
20473    l_rec_acct_attrs.array_acct_attr_code(12) := 'EXCHANGE_RATE_TYPE';
20474    l_rec_acct_attrs.array_char_value(12)  := p_source_15;
20475    l_rec_acct_attrs.array_acct_attr_code(13) := 'LEDGER_AMOUNT';
20476    l_rec_acct_attrs.array_num_value(13)  := p_source_25;
20477    l_rec_acct_attrs.array_acct_attr_code(14) := 'PARTY_ID';
20478    l_rec_acct_attrs.array_num_value(14)  := p_source_26;
20479    l_rec_acct_attrs.array_acct_attr_code(15) := 'PARTY_SITE_ID';
20480    l_rec_acct_attrs.array_num_value(15)  := p_source_27;
20481    l_rec_acct_attrs.array_acct_attr_code(16) := 'PARTY_TYPE';
20482    l_rec_acct_attrs.array_char_value(16)  := p_source_28;
20483 
20484    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
20485    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
20486 
20487    ---------------------------------------------------------------------------------------------------------------
20488    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
20489    ---------------------------------------------------------------------------------------------------------------
20490    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
20491 
20492    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
20493    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
20494 
20495    IF xla_accounting_cache_pkg.GetValueChar
20496          (p_source_code         => 'LEDGER_CATEGORY_CODE'
20497          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
20498    AND l_bflow_method_code = 'PRIOR_ENTRY'
20499 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
20500    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
20501          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
20502        )
20503    THEN
20504          xla_ae_lines_pkg.BflowUpgEntry
20505            (p_business_method_code    => l_bflow_method_code
20506            ,p_business_class_code     => l_bflow_class_code
20507            ,p_balance_type            => l_balance_type_code);
20508    ELSE
20509       NULL;
20510 -- No business flow processing for business flow method of NONE.
20511    END IF;
20512 
20513    --
20514    -- call analytical criteria
20515    --
20516    
20517    --
20518    -- call description
20519    --
20520    -- No description or it is inherited.
20521    --
20522    -- call ADRs
20523    -- Bug 4922099
20524    --
20525    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
20526         (NVL(l_actual_upg_option, 'N') = 'O') OR
20527         (NVL(l_enc_upg_option, 'N') = 'O')
20528       )
20529    THEN
20530    NULL;
20531    --
20532    --
20533    
20534   l_ccid := AcctDerRule_1(
20535            p_application_id           => p_application_id
20536          , p_ae_header_id             => l_ae_header_id 
20537 , p_source_1 => p_source_1
20538          , x_transaction_coa_id       => l_adr_transaction_coa_id
20539          , x_accounting_coa_id        => l_adr_accounting_coa_id
20540          , x_value_type_code          => l_adr_value_type_code
20541          , p_side                     => 'NA'
20542    );
20543 
20547   , p_transaction_coa_id           => l_adr_transaction_coa_id
20544    xla_ae_lines_pkg.set_ccid(
20545     p_code_combination_id          => l_ccid
20546   , p_value_type_code              => l_adr_value_type_code
20548   , p_accounting_coa_id            => l_adr_accounting_coa_id
20549   , p_adr_code                     => 'DIST_CCID'
20550   , p_adr_type_code                => 'S'
20551   , p_component_type               => l_component_type
20552   , p_component_code               => l_component_code
20553   , p_component_type_code          => l_component_type_code
20554   , p_component_appl_id            => l_component_appl_id
20555   , p_amb_context_code             => l_amb_context_code
20556   , p_side                         => 'NA'
20557   );
20558 
20559 
20560    --
20561    --
20562    END IF;
20563    --
20564    -- Bug 4922099
20565    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
20566           (NVL(l_enc_upg_option, 'N') = 'O')
20567         ) AND
20568         (l_bflow_method_code = 'PRIOR_ENTRY')
20569       )
20570    THEN
20571       IF
20572       --
20573       1 = 2
20574       --
20575       THEN
20576       xla_accounting_err_pkg.build_message
20577                                     (p_appli_s_name            => 'XLA'
20578                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
20579                                     ,p_token_1                 => 'LINE_NUMBER'
20580                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
20581                                     ,p_token_2                 => 'LINE_TYPE_NAME'
20582                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
20583                                                                              l_component_type
20584                                                                             ,l_component_code
20585                                                                             ,l_component_type_code
20586                                                                             ,l_component_appl_id
20587                                                                             ,l_amb_context_code
20588                                                                             ,l_entity_code
20589                                                                             ,l_event_class_code
20590                                                                            )
20591                                     ,p_token_3                 => 'OWNER'
20592                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
20593                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
20594                                                                           ,p_lookup_code    => l_component_type_code
20595                                                                          )
20596                                     ,p_token_4                 => 'PRODUCT_NAME'
20597                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
20598                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
20599                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
20600                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
20601                                     ,p_ae_header_id            =>  NULL
20602                                        );
20603 
20604         IF (C_LEVEL_ERROR>= g_log_level) THEN
20605                  trace
20606                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
20607                       ,p_level    => C_LEVEL_ERROR
20608                       ,p_module   => l_log_module);
20609         END IF;
20610       END IF;
20611    END IF;
20612    --
20613    --
20614    ------------------------------------------------------------------------------------------------
20615    -- 4219869 Business Flow
20616    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
20617    -- Prior Entry.  Currently, the following code is always generated.
20618    ------------------------------------------------------------------------------------------------
20619    XLA_AE_LINES_PKG.ValidateCurrentLine;
20620 
20621    ------------------------------------------------------------------------------------
20622    -- 4219869 Business Flow
20623    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
20624    ------------------------------------------------------------------------------------
20625    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
20626 
20627    ----------------------------------------------------------------------------------
20628    -- 4219869 Business Flow
20629    -- Update journal entry status -- Need to generate this within IF <condition>
20630    ----------------------------------------------------------------------------------
20631    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
20632          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
20633          ,p_balance_type_code => l_balance_type_code
20634          );
20635 
20636    -------------------------------------------------------------------------------------------
20637    -- 4262811 - Generate the Accrual Reversal lines
20641                               (g_array_event(p_event_id).array_value_num('header_index'));
20638    -------------------------------------------------------------------------------------------
20639    BEGIN
20640       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
20642       IF l_acc_rev_flag IS NULL THEN
20643          l_acc_rev_flag := 'N';
20644       END IF;
20645    EXCEPTION
20646       WHEN OTHERS THEN
20647          l_acc_rev_flag := 'N';
20648    END;
20649    --
20650    IF (l_acc_rev_flag = 'Y') THEN
20651 
20652        -- 4645092  ------------------------------------------------------------------------------
20653        -- To allow MPA report to determine if it should generate report process
20654        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
20655        ------------------------------------------------------------------------------------------
20656 
20657        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
20658        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
20659    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
20660    -- call ADRs
20661    -- Bug 4922099
20662    --
20663    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
20664         (NVL(l_actual_upg_option, 'N') = 'O') OR
20665         (NVL(l_enc_upg_option, 'N') = 'O')
20666       )
20667    THEN
20668    NULL;
20669    --
20670    --
20671    
20672   l_ccid := AcctDerRule_1(
20673            p_application_id           => p_application_id
20674          , p_ae_header_id             => l_ae_header_id 
20675 , p_source_1 => p_source_1
20676          , x_transaction_coa_id       => l_adr_transaction_coa_id
20677          , x_accounting_coa_id        => l_adr_accounting_coa_id
20678          , x_value_type_code          => l_adr_value_type_code
20679          , p_side                     => 'NA'
20680    );
20681 
20682    xla_ae_lines_pkg.set_ccid(
20683     p_code_combination_id          => l_ccid
20684   , p_value_type_code              => l_adr_value_type_code
20685   , p_transaction_coa_id           => l_adr_transaction_coa_id
20686   , p_accounting_coa_id            => l_adr_accounting_coa_id
20687   , p_adr_code                     => 'DIST_CCID'
20688   , p_adr_type_code                => 'S'
20689   , p_component_type               => l_component_type
20690   , p_component_code               => l_component_code
20691   , p_component_type_code          => l_component_type_code
20692   , p_component_appl_id            => l_component_appl_id
20693   , p_amb_context_code             => l_amb_context_code
20694   , p_side                         => 'NA'
20695   );
20696 
20697 
20698    --
20699    --
20700    END IF;
20701 
20702        --
20703        -- Update the line information that should be overwritten
20704        --
20705        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
20706                                          p_header_num   => 1);
20707        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
20708 
20709        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
20710 
20711        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
20712           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
20713        END IF;
20714 
20715       --
20716       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
20717       --
20718       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
20719           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
20720       ELSE
20721           ---------------------------------------------------------------------------------------------------
20722           -- 4262811a Switch Sign
20723           ---------------------------------------------------------------------------------------------------
20724           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
20725           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
20726                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20727           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
20728                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20729           -- 5132302
20730           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
20731                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
20732 
20733       END IF;
20734 
20735       -- 4955764
20736       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
20737       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
20738 
20739 
20740       XLA_AE_LINES_PKG.ValidateCurrentLine;
20741       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
20742 
20743       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
20744                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
20745                ,p_balance_type_code => l_balance_type_code);
20746 
20747    END IF;
20748 
20752      -- No MPA option is assigned.
20749    -----------------------------------------------------------------------------------------
20750    -- 4262811 Multiperiod Accounting
20751    -----------------------------------------------------------------------------------------
20753 
20754 
20755 END IF;
20756 END IF;
20757 --
20758 
20759 --
20760 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
20761    trace
20762       (p_msg      => 'END of AcctLineType_39'
20763       ,p_level    => C_LEVEL_PROCEDURE
20764       ,p_module   => l_log_module);
20765 END IF;
20766 --
20767 EXCEPTION
20768   WHEN xla_exceptions_pkg.application_exception THEN
20769       RAISE;
20770   WHEN OTHERS THEN
20771        xla_exceptions_pkg.raise_message
20772            (p_location => 'XLA_00222_AAD_S_000004_PKG.AcctLineType_39');
20773 END AcctLineType_39;
20774 --
20775 
20776 ---------------------------------------
20777 --
20778 -- PRIVATE PROCEDURE
20779 --         insert_sources_40
20780 --
20781 ----------------------------------------
20782 --
20783 PROCEDURE insert_sources_40(
20784                                 p_target_ledger_id       IN NUMBER
20785                               , p_language               IN VARCHAR2
20786                               , p_sla_ledger_id          IN NUMBER
20787                               , p_pad_start_date         IN DATE
20788                               , p_pad_end_date           IN DATE
20789                          )
20790 IS
20791 
20792 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'MISC_RECEIPT_ALL';
20793 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'MISC_RECEIPT';
20794 p_apps_owner                   VARCHAR2(30);
20795 l_log_module                   VARCHAR2(240);
20796 BEGIN
20797 IF g_log_enabled THEN
20798       l_log_module := C_DEFAULT_MODULE||'.insert_sources_40';
20799 END IF;
20800 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
20801 
20802       trace
20803          (p_msg      => 'BEGIN of insert_sources_40'
20804          ,p_level    => C_LEVEL_PROCEDURE
20805          ,p_module   => l_log_module);
20806 
20807 END IF;
20808 
20809 -- select APPS owner
20810 SELECT oracle_username
20811   INTO p_apps_owner
20812   FROM fnd_oracle_userid
20813  WHERE read_only_flag = 'U'
20814 ;
20815 
20816 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
20817       trace
20818          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
20819                         ' - p_language = '||p_language||
20820                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
20821                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
20822                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
20823                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
20824          ,p_level    => C_LEVEL_STATEMENT
20825          ,p_module   => l_log_module);
20826 END IF;
20827 
20828 
20829 --
20830 INSERT INTO xla_diag_sources --hdr2
20831 (
20832         event_id
20833       , ledger_id
20834       , sla_ledger_id
20835       , description_language
20836       , object_name
20837       , object_type_code
20838       , line_number
20839       , source_application_id
20840       , source_type_code
20841       , source_code
20842       , source_value
20843       , source_meaning
20844       , created_by
20845       , creation_date
20846       , last_update_date
20847       , last_updated_by
20848       , last_update_login
20849       , program_update_date
20850       , program_application_id
20851       , program_id
20852       , request_id
20853 )
20854 SELECT
20855         event_id
20856       , p_target_ledger_id
20857       , p_sla_ledger_id
20858       , p_language
20859       , object_name
20860       , object_type_code
20861       , line_number
20862       , source_application_id
20863       , source_type_code
20864       , source_code
20865       , SUBSTR(source_value ,1,1996)
20866       , SUBSTR(source_meaning ,1,200)
20867       , xla_environment_pkg.g_Usr_Id
20868       , TRUNC(SYSDATE)
20869       , TRUNC(SYSDATE)
20870       , xla_environment_pkg.g_Usr_Id
20871       , xla_environment_pkg.g_Login_Id
20872       , TRUNC(SYSDATE)
20873       , xla_environment_pkg.g_Prog_Appl_Id
20874       , xla_environment_pkg.g_Prog_Id
20875       , xla_environment_pkg.g_Req_Id
20876   FROM (
20877        SELECT xet.event_id                  event_id
20878             , 0                          line_number
20879             , CASE r
20880                WHEN 1 THEN 'AR_CASH_RECEIPTS_H_V' 
20881                 WHEN 2 THEN 'AR_CASH_RECEIPTS_H_V' 
20882                 WHEN 3 THEN 'AR_CASH_RECEIPTS_H_V' 
20883                 WHEN 4 THEN 'AR_CASH_RECEIPTS_H_V' 
20884                 
20885                ELSE null
20886               END                           object_name
20887             , CASE r
20888                 WHEN 1 THEN 'HEADER' 
20889                 WHEN 2 THEN 'HEADER' 
20890                 WHEN 3 THEN 'HEADER' 
20891                 WHEN 4 THEN 'HEADER' 
20892                 
20893                 ELSE null
20894               END                           object_type_code
20895             , CASE r
20896                 WHEN 1 THEN '222' 
20897                 WHEN 2 THEN '222' 
20898                 WHEN 3 THEN '222' 
20899                 WHEN 4 THEN '222' 
20900                 
20904             , CASE r
20901                 ELSE null
20902               END                           source_application_id
20903             , 'S'             source_type_code
20905                 WHEN 1 THEN 'RCT_DOC_SEQUENCE_CATEGORY' 
20906                 WHEN 2 THEN 'RCT_DOC_SEQUENCE_ID' 
20907                 WHEN 3 THEN 'RCT_DOC_SEQUENCE_VALUE' 
20908                 WHEN 4 THEN 'RCT_TRX_ACCT_REVERSAL' 
20909                 
20910                 ELSE null
20911               END                           source_code
20912             , CASE r
20913                 WHEN 1 THEN TO_CHAR(h1.RCT_DOC_SEQUENCE_CATEGORY)
20914                 WHEN 2 THEN TO_CHAR(h1.RCT_DOC_SEQUENCE_ID)
20915                 WHEN 3 THEN TO_CHAR(h1.RCT_DOC_SEQUENCE_VALUE)
20916                 WHEN 4 THEN TO_CHAR(h1.RCT_TRX_ACCT_REVERSAL)
20917                 
20918                 ELSE null
20919               END                           source_value
20920             , null              source_meaning
20921          FROM xla_events_gt     xet  
20922       , AR_CASH_RECEIPTS_H_V  h1
20923              ,(select rownum r from all_objects where rownum <= 4 and owner = p_apps_owner)
20924          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
20925            AND xet.event_class_code = C_EVENT_CLASS_CODE
20926             
20927 )
20928 ;
20929 --
20930 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
20931 
20932       trace
20933          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
20934          ,p_level    => C_LEVEL_STATEMENT
20935          ,p_module   => l_log_module);
20936 
20937 END IF;
20938 --
20939 
20940 
20941 
20942 --
20943 INSERT INTO xla_diag_sources  --line2
20944 (
20945         event_id
20946       , ledger_id
20947       , sla_ledger_id
20948       , description_language
20949       , object_name
20950       , object_type_code
20951       , line_number
20952       , source_application_id
20953       , source_type_code
20954       , source_code
20955       , source_value
20956       , source_meaning
20957       , created_by
20958       , creation_date
20959       , last_update_date
20960       , last_updated_by
20961       , last_update_login
20962       , program_update_date
20963       , program_application_id
20964       , program_id
20965       , request_id
20966 )
20967 SELECT  event_id
20968       , p_target_ledger_id
20969       , p_sla_ledger_id
20970       , p_language
20971       , object_name
20972       , object_type_code
20973       , line_number
20974       , source_application_id
20975       , source_type_code
20976       , source_code
20977       , SUBSTR(source_value,1,1996)
20978       , SUBSTR(source_meaning ,1,200)
20979       , xla_environment_pkg.g_Usr_Id
20980       , TRUNC(SYSDATE)
20981       , TRUNC(SYSDATE)
20982       , xla_environment_pkg.g_Usr_Id
20983       , xla_environment_pkg.g_Login_Id
20984       , TRUNC(SYSDATE)
20985       , xla_environment_pkg.g_Prog_Appl_Id
20986       , xla_environment_pkg.g_Prog_Id
20987       , xla_environment_pkg.g_Req_Id
20988   FROM (
20989        SELECT xet.event_id                  event_id
20990             , l3.line_number                 line_number
20991             , CASE r
20992                WHEN 1 THEN 'AR_DISTRIBUTIONS_L_V' 
20993                 WHEN 2 THEN 'AR_DISTRIBUTIONS_L_V' 
20994                 WHEN 3 THEN 'AR_DISTRIBUTIONS_L_V' 
20995                 WHEN 4 THEN 'AR_DISTRIBUTIONS_L_V' 
20996                 WHEN 5 THEN 'AR_DISTRIBUTIONS_L_V' 
20997                 WHEN 6 THEN 'AR_DISTRIBUTIONS_L_V' 
20998                 WHEN 7 THEN 'AR_DISTRIBUTIONS_L_V' 
20999                 WHEN 8 THEN 'AR_DISTRIBUTIONS_BASE_V' 
21000                 WHEN 9 THEN 'AR_DISTRIBUTIONS_BASE_V' 
21001                 WHEN 10 THEN 'AR_DISTRIBUTIONS_BASE_V' 
21002                 WHEN 11 THEN 'AR_DISTRIBUTIONS_BASE_V' 
21003                 
21004                ELSE null
21005               END                           object_name
21006             , CASE r
21007                 WHEN 1 THEN 'LINE' 
21008                 WHEN 2 THEN 'LINE' 
21009                 WHEN 3 THEN 'LINE' 
21010                 WHEN 4 THEN 'LINE' 
21011                 WHEN 5 THEN 'LINE' 
21012                 WHEN 6 THEN 'LINE' 
21013                 WHEN 7 THEN 'LINE' 
21014                 WHEN 8 THEN 'LINE' 
21015                 WHEN 9 THEN 'LINE' 
21016                 WHEN 10 THEN 'LINE' 
21017                 WHEN 11 THEN 'LINE' 
21018                 
21019                 ELSE null
21020               END                           object_type_code
21021             , CASE r
21022                 WHEN 1 THEN '222' 
21023                 WHEN 2 THEN '222' 
21024                 WHEN 3 THEN '222' 
21025                 WHEN 4 THEN '222' 
21026                 WHEN 5 THEN '222' 
21027                 WHEN 6 THEN '222' 
21028                 WHEN 7 THEN '222' 
21029                 WHEN 8 THEN '222' 
21030                 WHEN 9 THEN '222' 
21031                 WHEN 10 THEN '222' 
21032                 WHEN 11 THEN '222' 
21033                 
21034                 ELSE null
21035               END                           source_application_id
21036             , 'S'             source_type_code
21037             , CASE r
21038                 WHEN 1 THEN 'DIST_CODE_COMBINATION_ID' 
21042                 WHEN 5 THEN 'DISTRIBUTION_TYPE' 
21039                 WHEN 2 THEN 'DIST_SOURCE_TYPE' 
21040                 WHEN 3 THEN 'DIST_MFAR_ADDITIONAL_ENTRY' 
21041                 WHEN 4 THEN 'DIST_LINE_ID' 
21043                 WHEN 6 THEN 'DIST_ENT_AMT' 
21044                 WHEN 7 THEN 'DIST_CURRENCY_CODE' 
21045                 WHEN 8 THEN 'DIST_TO_CUR_CONVERSION_DATE' 
21046                 WHEN 9 THEN 'DIST_CUR_CONVERSION_RATE' 
21047                 WHEN 10 THEN 'DIST_CUR_CONVERSION_TYPE' 
21048                 WHEN 11 THEN 'DIST_TO_ACCTD_AMT' 
21049                 
21050                 ELSE null
21051               END                           source_code
21052             , CASE r
21053                 WHEN 1 THEN TO_CHAR(l3.DIST_CODE_COMBINATION_ID)
21054                 WHEN 2 THEN TO_CHAR(l3.DIST_SOURCE_TYPE)
21055                 WHEN 3 THEN TO_CHAR(l3.DIST_MFAR_ADDITIONAL_ENTRY)
21056                 WHEN 4 THEN TO_CHAR(l3.DIST_LINE_ID)
21057                 WHEN 5 THEN TO_CHAR(l3.DISTRIBUTION_TYPE)
21058                 WHEN 6 THEN TO_CHAR(l3.DIST_ENT_AMT)
21059                 WHEN 7 THEN TO_CHAR(l3.DIST_CURRENCY_CODE)
21060                 WHEN 8 THEN TO_CHAR(l2.DIST_TO_CUR_CONVERSION_DATE)
21061                 WHEN 9 THEN TO_CHAR(l2.DIST_CUR_CONVERSION_RATE)
21062                 WHEN 10 THEN TO_CHAR(l2.DIST_CUR_CONVERSION_TYPE)
21063                 WHEN 11 THEN TO_CHAR(l2.DIST_TO_ACCTD_AMT)
21064                 
21065                 ELSE null
21066               END                           source_value
21067             , null              source_meaning
21068          FROM  xla_events_gt     xet  
21069         , AR_DISTRIBUTIONS_BASE_V  l2
21070         , AR_DISTRIBUTIONS_L_V  l3
21071             , (select rownum r from all_objects where rownum <= 11 and owner = p_apps_owner)
21072         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
21073           AND xet.event_class_code = C_EVENT_CLASS_CODE
21074             AND l2.event_id          = xet.event_id
21075   AND l3.event_id    = l2.event_id
21076   AND l3.line_number = l2.line_number
21077 
21078 )
21079 ;
21080 --
21081 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
21082 
21083       trace
21084          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
21085          ,p_level    => C_LEVEL_STATEMENT
21086          ,p_module   => l_log_module);
21087 
21088 END IF;
21089 
21090 
21091 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
21092       trace
21093          (p_msg      => 'END of insert_sources_40'
21094          ,p_level    => C_LEVEL_PROCEDURE
21095          ,p_module   => l_log_module);
21096 END IF;
21097 EXCEPTION
21098   WHEN xla_exceptions_pkg.application_exception THEN
21099       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
21100             trace
21101                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
21102                ,p_level    => C_LEVEL_EXCEPTION
21103                ,p_module   => l_log_module);
21104       END IF;
21105       RAISE;
21106   WHEN OTHERS THEN
21107       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
21108             trace
21109                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
21110                ,p_level    => C_LEVEL_EXCEPTION
21111                ,p_module   => l_log_module);
21112        END IF;
21113        xla_exceptions_pkg.raise_message
21114            (p_location => 'XLA_00222_AAD_S_000004_PKG.insert_sources_40');
21115 END insert_sources_40;
21116 --
21117 
21118 ---------------------------------------
21119 --
21120 -- PRIVATE FUNCTION
21121 --         EventClass_40
21122 --
21123 ----------------------------------------
21124 --
21125 FUNCTION EventClass_40
21126        (p_application_id         IN NUMBER
21127        ,p_base_ledger_id         IN NUMBER
21128        ,p_target_ledger_id       IN NUMBER
21129        ,p_language               IN VARCHAR2
21130        ,p_currency_code          IN VARCHAR2
21131        ,p_sla_ledger_id          IN NUMBER
21132        ,p_pad_start_date         IN DATE
21133        ,p_pad_end_date           IN DATE
21134        ,p_primary_ledger_id      IN NUMBER)
21135 RETURN BOOLEAN IS
21136 --
21137 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'MISC_RECEIPT_ALL';
21138 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'MISC_RECEIPT';
21139 
21140 l_calculate_acctd_flag   VARCHAR2(1) :='N';
21141 l_calculate_g_l_flag     VARCHAR2(1) :='N';
21142 --
21143 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
21144 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
21145 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
21146 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
21147 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
21148 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
21149 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
21150 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
21151 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
21152 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
21153 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
21154 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
21155 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
21159 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
21156 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
21157 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
21158 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
21160 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
21161 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
21162 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
21163 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
21164 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
21165 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
21166 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
21167 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
21168 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
21169 
21170 l_event_id                             NUMBER;
21171 l_previous_event_id                    NUMBER;
21172 l_first_event_id                       NUMBER;
21173 l_last_event_id                        NUMBER;
21174 
21175 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
21176 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
21177 --
21178 --
21179 l_result                    BOOLEAN := TRUE;
21180 l_rows                      NUMBER  := 1000;
21181 l_event_type_name           VARCHAR2(80) := 'All';
21182 l_event_class_name          VARCHAR2(80) := 'Miscellaneous Receipt';
21183 l_description               VARCHAR2(4000);
21184 l_transaction_reversal      NUMBER;
21185 l_ae_header_id              NUMBER;
21186 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
21187 l_log_module                VARCHAR2(240);
21188 --
21189 l_acct_reversal_source      VARCHAR2(30);
21190 l_trx_reversal_source       VARCHAR2(30);
21191 
21192 l_continue_with_lines       BOOLEAN := TRUE;
21193 --
21194 l_acc_rev_gl_date_source    DATE;                      -- 4262811
21195 --
21196 type t_array_event_id is table of number index by binary_integer;
21197 
21198 l_rec_array_event                    t_rec_array_event;
21199 l_null_rec_array_event               t_rec_array_event;
21200 l_array_ae_header_id                 xla_number_array_type;
21201 l_actual_flag                        VARCHAR2(1) := NULL;
21202 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
21203 l_balance_type_code                  VARCHAR2(1) :=NULL;
21204 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
21205 
21206 --
21207 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
21208 --
21209 
21210 TYPE t_array_source_37 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
21211 TYPE t_array_source_38 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
21212 TYPE t_array_source_39 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
21213 TYPE t_array_source_41 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_TRX_ACCT_REVERSAL%TYPE INDEX BY BINARY_INTEGER;
21214 
21215 TYPE t_array_source_1 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CODE_COMBINATION_ID%TYPE INDEX BY BINARY_INTEGER;
21216 TYPE t_array_source_7 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_SOURCE_TYPE%TYPE INDEX BY BINARY_INTEGER;
21217 TYPE t_array_source_8 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_MFAR_ADDITIONAL_ENTRY%TYPE INDEX BY BINARY_INTEGER;
21218 TYPE t_array_source_9 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
21219 TYPE t_array_source_10 IS TABLE OF AR_DISTRIBUTIONS_L_V.DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
21220 TYPE t_array_source_11 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_ENT_AMT%TYPE INDEX BY BINARY_INTEGER;
21221 TYPE t_array_source_12 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
21222 TYPE t_array_source_13 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
21223 TYPE t_array_source_14 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
21224 TYPE t_array_source_15 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
21225 TYPE t_array_source_16 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
21226 
21227 l_array_source_37              t_array_source_37;
21228 l_array_source_38              t_array_source_38;
21229 l_array_source_39              t_array_source_39;
21230 l_array_source_41              t_array_source_41;
21231 
21232 l_array_source_1      t_array_source_1;
21233 l_array_source_7      t_array_source_7;
21234 l_array_source_8      t_array_source_8;
21235 l_array_source_9      t_array_source_9;
21236 l_array_source_10      t_array_source_10;
21237 l_array_source_11      t_array_source_11;
21238 l_array_source_12      t_array_source_12;
21239 l_array_source_13      t_array_source_13;
21240 l_array_source_14      t_array_source_14;
21241 l_array_source_15      t_array_source_15;
21242 l_array_source_16      t_array_source_16;
21243 
21244 --
21245 CURSOR header_cur
21246 IS
21247 SELECT /*+ leading(xet) cardinality(xet,1) */
21248 -- Event Class Code: MISC_RECEIPT
21249     xet.entity_id
21250    ,xet.legal_entity_id
21251    ,xet.entity_code
21252    ,xet.transaction_number
21253    ,xet.event_id
21254    ,xet.event_class_code
21255    ,xet.event_type_code
21259    ,xet.reference_num_1
21256    ,xet.event_number
21257    ,xet.event_date
21258    ,xet.transaction_date
21260    ,xet.reference_num_2
21261    ,xet.reference_num_3
21262    ,xet.reference_num_4
21263    ,xet.reference_char_1
21264    ,xet.reference_char_2
21265    ,xet.reference_char_3
21266    ,xet.reference_char_4
21267    ,xet.reference_date_1
21268    ,xet.reference_date_2
21269    ,xet.reference_date_3
21270    ,xet.reference_date_4
21271    ,xet.event_created_by
21272    ,xet.budgetary_control_flag 
21273   , h1.RCT_DOC_SEQUENCE_CATEGORY    source_37
21274   , h1.RCT_DOC_SEQUENCE_ID    source_38
21275   , h1.RCT_DOC_SEQUENCE_VALUE    source_39
21276   , h1.RCT_TRX_ACCT_REVERSAL    source_41
21277   FROM xla_events_gt     xet 
21278   , AR_CASH_RECEIPTS_H_V  h1
21279  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
21280    and xet.event_class_code = C_EVENT_CLASS_CODE
21281    and xet.event_status_code <> 'N'   AND h1.event_id (+) = xet.event_id
21282 
21283  ORDER BY event_id
21284 ;
21285 
21286 
21287 --
21288 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
21289 IS
21290 SELECT  /*+ leading(xet) cardinality(xet,1) */
21291 -- Event Class Code: MISC_RECEIPT
21292     xet.entity_id
21293    ,xet.legal_entity_id
21294    ,xet.entity_code
21295    ,xet.transaction_number
21296    ,xet.event_id
21297    ,xet.event_class_code
21298    ,xet.event_type_code
21299    ,xet.event_number
21300    ,xet.event_date
21301    ,xet.transaction_date
21302    ,xet.reference_num_1
21303    ,xet.reference_num_2
21304    ,xet.reference_num_3
21305    ,xet.reference_num_4
21306    ,xet.reference_char_1
21307    ,xet.reference_char_2
21308    ,xet.reference_char_3
21309    ,xet.reference_char_4
21310    ,xet.reference_date_1
21311    ,xet.reference_date_2
21312    ,xet.reference_date_3
21313    ,xet.reference_date_4
21314    ,xet.event_created_by
21315    ,xet.budgetary_control_flag
21316  , l2.LINE_NUMBER  
21317   , l3.DIST_CODE_COMBINATION_ID    source_1
21318   , l3.DIST_SOURCE_TYPE    source_7
21319   , l3.DIST_MFAR_ADDITIONAL_ENTRY    source_8
21320   , l3.DIST_LINE_ID    source_9
21321   , l3.DISTRIBUTION_TYPE    source_10
21322   , l3.DIST_ENT_AMT    source_11
21323   , l3.DIST_CURRENCY_CODE    source_12
21324   , l2.DIST_TO_CUR_CONVERSION_DATE    source_13
21325   , l2.DIST_CUR_CONVERSION_RATE    source_14
21326   , l2.DIST_CUR_CONVERSION_TYPE    source_15
21327   , l2.DIST_TO_ACCTD_AMT    source_16
21328   FROM xla_events_gt     xet 
21329   , AR_DISTRIBUTIONS_BASE_V  l2
21330   , AR_DISTRIBUTIONS_L_V  l3
21331  WHERE xet.event_id between x_first_event_id and x_last_event_id
21332    and xet.event_date between p_pad_start_date and p_pad_end_date
21333    and xet.event_class_code = C_EVENT_CLASS_CODE
21334    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
21335   AND l3.event_id    = l2.event_id
21336   AND l3.line_number = l2.line_number
21337 ;
21338 
21339 --
21340 BEGIN
21341 IF g_log_enabled THEN
21342    l_log_module := C_DEFAULT_MODULE||'.EventClass_40';
21343 END IF;
21344 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
21345    trace
21346       (p_msg      => 'BEGIN of EventClass_40'
21347       ,p_level    => C_LEVEL_PROCEDURE
21348       ,p_module   => l_log_module);
21349 END IF;
21350 
21351 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
21352    trace
21353       (p_msg      => 'p_application_id = '||p_application_id||
21354                      ' - p_base_ledger_id = '||p_base_ledger_id||
21355                      ' - p_target_ledger_id  = '||p_target_ledger_id||
21356                      ' - p_language = '||p_language||
21357                      ' - p_currency_code = '||p_currency_code||
21358                      ' - p_sla_ledger_id = '||p_sla_ledger_id
21359       ,p_level    => C_LEVEL_STATEMENT
21360       ,p_module   => l_log_module);
21361 END IF;
21362 --
21363 -- initialze arrays
21364 --
21365 g_array_event.DELETE;
21366 l_rec_array_event := l_null_rec_array_event;
21367 --
21368 --------------------------------------
21369 -- 4262811 Initialze MPA Line Number
21370 --------------------------------------
21371 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
21372 
21373 --
21374 
21375 --
21376 OPEN header_cur;
21377 --
21378 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
21379    trace
21380    (p_msg      => 'SQL - FETCH header_cur'
21381    ,p_level    => C_LEVEL_STATEMENT
21382    ,p_module   => l_log_module);
21383 END IF;
21384 --
21385 LOOP
21386 FETCH header_cur BULK COLLECT INTO
21387         l_array_entity_id
21388       , l_array_legal_entity_id
21389       , l_array_entity_code
21390       , l_array_transaction_num
21391       , l_array_event_id
21392       , l_array_class_code
21393       , l_array_event_type
21394       , l_array_event_number
21395       , l_array_event_date
21396       , l_array_transaction_date
21397       , l_array_reference_num_1
21398       , l_array_reference_num_2
21399       , l_array_reference_num_3
21400       , l_array_reference_num_4
21401       , l_array_reference_char_1
21402       , l_array_reference_char_2
21403       , l_array_reference_char_3
21404       , l_array_reference_char_4
21405       , l_array_reference_date_1
21406       , l_array_reference_date_2
21407       , l_array_reference_date_3
21408       , l_array_reference_date_4
21412       , l_array_source_38
21409       , l_array_event_created_by
21410       , l_array_budgetary_control_flag 
21411       , l_array_source_37
21413       , l_array_source_39
21414       , l_array_source_41
21415       LIMIT l_rows;
21416 --
21417 IF (C_LEVEL_EVENT >= g_log_level) THEN
21418    trace
21419    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
21420    ,p_level    => C_LEVEL_EVENT
21421    ,p_module   => l_log_module);
21422 END IF;
21423 --
21424 EXIT WHEN l_array_entity_id.COUNT = 0;
21425 
21426 -- initialize arrays
21427 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
21428 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
21429 
21430 --
21431 -- Bug 4458708
21432 --
21433 XLA_AE_LINES_PKG.g_LineNumber := 0;
21434 
21435 
21436 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
21437 g_last_hdr_idx := l_array_event_id.LAST;
21438 --
21439 -- loop for the headers. Each iteration is for each header extract row
21440 -- fetched in header cursor
21441 --
21442 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
21443 
21444 --
21445 -- set event info as cache for other routines to refer event attributes
21446 --
21447 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
21448    (p_application_id           => p_application_id
21449    ,p_primary_ledger_id        => p_primary_ledger_id
21450    ,p_base_ledger_id           => p_base_ledger_id
21451    ,p_target_ledger_id         => p_target_ledger_id
21452    ,p_entity_id                => l_array_entity_id(hdr_idx)
21453    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
21454    ,p_entity_code              => l_array_entity_code(hdr_idx)
21455    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
21456    ,p_event_id                 => l_array_event_id(hdr_idx)
21457    ,p_event_class_code         => l_array_class_code(hdr_idx)
21458    ,p_event_type_code          => l_array_event_type(hdr_idx)
21459    ,p_event_number             => l_array_event_number(hdr_idx)
21460    ,p_event_date               => l_array_event_date(hdr_idx)
21461    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
21462    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
21463    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
21464    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
21465    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
21466    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
21467    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
21468    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
21469    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
21470    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
21471    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
21472    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
21473    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
21474    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
21475    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
21476 
21477 --
21478 -- set the status of entry to C_VALID (0)
21479 --
21480 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
21481 
21482 --
21483 -- initialize a row for ae header
21484 --
21485 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
21486 
21487 l_event_id := l_array_event_id(hdr_idx);
21488 
21489 --
21490 -- storing the hdr_idx for event. May be used by line cursor.
21491 --
21492 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
21493 
21494 --
21495 -- store sources from header extract. This can be improved to
21496 -- store only those sources from header extract that may be used in lines
21497 --
21498 
21499 g_array_event(l_event_id).array_value_char('source_37') := l_array_source_37(hdr_idx);
21500 g_array_event(l_event_id).array_value_num('source_38') := l_array_source_38(hdr_idx);
21501 g_array_event(l_event_id).array_value_num('source_39') := l_array_source_39(hdr_idx);
21502 g_array_event(l_event_id).array_value_char('source_41') := l_array_source_41(hdr_idx);
21503 
21504 --
21505 -- initilaize the status of ae headers for diffrent balance types
21506 -- the status is initialised to C_NOT_CREATED (2)
21507 --
21508 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
21509 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
21510 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
21511 
21512 --
21513 -- call api to validate and store accounting attributes for header
21514 --
21515 
21516 ------------------------------------------------------------
21517 -- Accrual Reversal : to get date for Standard Source (NONE)
21518 ------------------------------------------------------------
21519 l_acc_rev_gl_date_source := NULL;
21520 
21521      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
21522       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_37');
21523      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
21524       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_38');
21528       l_rec_acct_attrs.array_date_value(4) := 
21525      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
21526       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_39');
21527      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
21529 xla_ae_sources_pkg.GetSystemSourceDate(
21530    p_source_code           => 'XLA_EVENT_DATE'
21531  , p_source_type_code      => 'Y'
21532  , p_source_application_id =>  602
21533 );
21534      l_rec_acct_attrs.array_acct_attr_code(5)   := 'TRX_ACCT_REVERSAL_OPTION';
21535       l_rec_acct_attrs.array_char_value(5) := g_array_event(l_event_id).array_value_char('source_41');
21536 
21537 
21538 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
21539 
21540 XLA_AE_HEADER_PKG.SetJeCategoryName;
21541 
21542 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
21543 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
21544 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
21545 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
21546 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
21547 
21548 
21549 -- No header level analytical criteria
21550 
21551 --
21552 --accounting attribute enhancement, bug 3612931
21553 --
21554 l_trx_reversal_source := SUBSTR(g_array_event(l_event_id).array_value_char('source_41'), 1,30);
21555 
21556 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
21557    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
21558 
21559    xla_accounting_err_pkg.build_message
21560       (p_appli_s_name            => 'XLA'
21561       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
21562       ,p_token_1                 => 'ACCT_ATTR_NAME'
21563       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
21564       ,p_token_2                 => 'PRODUCT_NAME'
21565       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
21566       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
21567       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
21568       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
21569 
21570 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
21571    --
21572    -- following sets the accounting attributes needed to reverse
21573    -- accounting for a distributeion
21574    --
21575    xla_ae_lines_pkg.SetTrxReversalAttrs
21576       (p_event_id              => l_event_id
21577       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
21578       ,p_trx_reversal_source   => l_trx_reversal_source);
21579 
21580 END IF;
21581 
21582 
21583 ----------------------------------------------------------------
21584 -- 4262811 -  update the header statuses to invalid in need be
21585 ----------------------------------------------------------------
21586 --
21587 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
21588 
21589 
21590   -----------------------------------------------
21591   -- No accrual reversal for the event class/type
21592   -----------------------------------------------
21593 ----------------------------------------------------------------
21594 
21595 --
21596 -- this ends the header loop iteration for one bulk fetch
21597 --
21598 END LOOP;
21599 
21600 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
21601 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
21602 
21603 --
21604 -- insert dummy rows into lines gt table that were created due to
21605 -- transaction reversals
21606 --
21607 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
21608    l_result := XLA_AE_LINES_PKG.InsertLines;
21609 END IF;
21610 
21611 --
21612 -- reset the temp_line_num for each set of events fetched from header
21613 -- cursor rather than doing it for each new event in line cursor
21614 -- Bug 3939231
21615 --
21616 xla_ae_lines_pkg.g_temp_line_num := 0;
21617 
21618 
21619 
21620 --
21621 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
21622 --
21623 --
21624 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
21625 
21626       trace
21627          (p_msg      => 'SQL - FETCH line_cur'
21628          ,p_level    => C_LEVEL_STATEMENT
21629          ,p_module   => l_log_module);
21630 
21631 END IF;
21632 --
21633 --
21634 LOOP
21635   --
21636   FETCH line_cur BULK COLLECT INTO
21637         l_array_entity_id
21638       , l_array_legal_entity_id
21639       , l_array_entity_code
21640       , l_array_transaction_num
21641       , l_array_event_id
21642       , l_array_class_code
21643       , l_array_event_type
21644       , l_array_event_number
21645       , l_array_event_date
21646       , l_array_transaction_date
21647       , l_array_reference_num_1
21648       , l_array_reference_num_2
21649       , l_array_reference_num_3
21650       , l_array_reference_num_4
21651       , l_array_reference_char_1
21652       , l_array_reference_char_2
21653       , l_array_reference_char_3
21654       , l_array_reference_char_4
21658       , l_array_reference_date_4
21655       , l_array_reference_date_1
21656       , l_array_reference_date_2
21657       , l_array_reference_date_3
21659       , l_array_event_created_by
21660       , l_array_budgetary_control_flag
21661       , l_array_extract_line_num 
21662       , l_array_source_1
21663       , l_array_source_7
21664       , l_array_source_8
21665       , l_array_source_9
21666       , l_array_source_10
21667       , l_array_source_11
21668       , l_array_source_12
21669       , l_array_source_13
21670       , l_array_source_14
21671       , l_array_source_15
21672       , l_array_source_16
21673       LIMIT l_rows;
21674 
21675   --
21676   IF (C_LEVEL_EVENT >= g_log_level) THEN
21677             trace
21678                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
21679                ,p_level    => C_LEVEL_EVENT
21680                ,p_module   => l_log_module);
21681   END IF;
21682   --
21683   EXIT WHEN l_array_entity_id.count = 0;
21684 
21685   XLA_AE_LINES_PKG.g_rec_lines := null;
21686 
21687 --
21688 -- Bug 4458708
21689 --
21690 XLA_AE_LINES_PKG.g_LineNumber := 0;
21691 --
21692 --
21693 
21694 FOR Idx IN 1..l_array_event_id.count LOOP
21695    --
21696    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
21697    --
21698    l_event_id := l_array_event_id(idx);  -- 5648433
21699 
21700    --
21701    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
21702    --
21703 
21704    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
21705              (g_array_event(l_event_id).array_value_num('header_index'))
21706          ,'N'
21707          ) <> 'Y'
21708    THEN
21709       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
21710          trace
21711             (p_msg      => 'Trancaction revesal option is not Y '
21712             ,p_level    => C_LEVEL_STATEMENT
21713             ,p_module   => l_log_module);
21714       END IF;
21715 
21716 --
21717 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
21718 --
21719 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
21720 --
21721 -- set event info as cache for other routines to refer event attributes
21722 --
21723 
21724 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
21725    l_previous_event_id := l_event_id;
21726 
21727    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
21728       (p_application_id           => p_application_id
21729       ,p_primary_ledger_id        => p_primary_ledger_id
21730       ,p_base_ledger_id           => p_base_ledger_id
21731       ,p_target_ledger_id         => p_target_ledger_id
21732       ,p_entity_id                => l_array_entity_id(Idx)
21733       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
21734       ,p_entity_code              => l_array_entity_code(Idx)
21735       ,p_transaction_num          => l_array_transaction_num(Idx)
21736       ,p_event_id                 => l_array_event_id(Idx)
21737       ,p_event_class_code         => l_array_class_code(Idx)
21738       ,p_event_type_code          => l_array_event_type(Idx)
21739       ,p_event_number             => l_array_event_number(Idx)
21740       ,p_event_date               => l_array_event_date(Idx)
21741       ,p_transaction_date         => l_array_transaction_date(Idx)
21742       ,p_reference_num_1          => l_array_reference_num_1(Idx)
21743       ,p_reference_num_2          => l_array_reference_num_2(Idx)
21744       ,p_reference_num_3          => l_array_reference_num_3(Idx)
21745       ,p_reference_num_4          => l_array_reference_num_4(Idx)
21746       ,p_reference_char_1         => l_array_reference_char_1(Idx)
21747       ,p_reference_char_2         => l_array_reference_char_2(Idx)
21748       ,p_reference_char_3         => l_array_reference_char_3(Idx)
21749       ,p_reference_char_4         => l_array_reference_char_4(Idx)
21750       ,p_reference_date_1         => l_array_reference_date_1(Idx)
21751       ,p_reference_date_2         => l_array_reference_date_2(Idx)
21752       ,p_reference_date_3         => l_array_reference_date_3(Idx)
21753       ,p_reference_date_4         => l_array_reference_date_4(Idx)
21754       ,p_event_created_by         => l_array_event_created_by(Idx)
21755       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
21756        --
21757 END IF;
21758 
21759 
21760 
21761 --
21762 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
21763 
21764 l_acct_reversal_source := SUBSTR(NULL, 1,30);
21765 
21766 IF l_continue_with_lines THEN
21767    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
21768       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
21769 
21770       xla_accounting_err_pkg.build_message
21771          (p_appli_s_name            => 'XLA'
21772          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
21773          ,p_token_1                 => 'LINE_NUMBER'
21774          ,p_value_1                 => l_array_extract_line_num(Idx)
21775          ,p_token_2                 => 'PRODUCT_NAME'
21776          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
21777          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
21781    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
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 
21782       --
21783       -- following sets the accounting attributes needed to reverse
21784       -- accounting for a distributeion
21785       --
21786 
21787       --
21788       -- 5217187
21789       --
21790       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
21791       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
21792                                        g_array_event(l_event_id).array_value_num('header_index'));
21793       --
21794       --
21795 
21796       -- No reversal code generated
21797 
21798       xla_ae_lines_pkg.SetAcctReversalAttrs
21799          (p_event_id             => l_event_id
21800          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
21801          ,p_calculate_acctd_flag => l_calculate_acctd_flag
21802          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
21803    END IF;
21804 
21805    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
21806        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
21807 
21808 --
21809 AcctLineType_6 (
21810  p_application_id  => p_application_id
21811  ,p_event_id     => l_event_id
21812  ,p_calculate_acctd_flag => l_calculate_acctd_flag
21813  ,p_calculate_g_l_flag => l_calculate_g_l_flag
21814  ,p_actual_flag => l_actual_flag
21815  ,p_balance_type_code => l_balance_type_code
21816  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
21817  
21818  , p_source_1 => l_array_source_1(Idx)
21819  , p_source_7 => l_array_source_7(Idx)
21820  , p_source_8 => l_array_source_8(Idx)
21821  , p_source_9 => l_array_source_9(Idx)
21822  , p_source_10 => l_array_source_10(Idx)
21823  , p_source_11 => l_array_source_11(Idx)
21824  , p_source_12 => l_array_source_12(Idx)
21825  , p_source_13 => l_array_source_13(Idx)
21826  , p_source_14 => l_array_source_14(Idx)
21827  , p_source_15 => l_array_source_15(Idx)
21828  , p_source_16 => l_array_source_16(Idx)
21829  );
21830 If(l_balance_type_code = 'A') THEN
21831   l_actual_gain_loss_ref := l_gain_or_loss_ref;
21832 END IF;
21833 
21834 --
21835 
21836 
21837 --
21838 AcctLineType_7 (
21839  p_application_id  => p_application_id
21840  ,p_event_id     => l_event_id
21841  ,p_calculate_acctd_flag => l_calculate_acctd_flag
21842  ,p_calculate_g_l_flag => l_calculate_g_l_flag
21843  ,p_actual_flag => l_actual_flag
21844  ,p_balance_type_code => l_balance_type_code
21845  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
21846  
21847  , p_source_1 => l_array_source_1(Idx)
21848  , p_source_7 => l_array_source_7(Idx)
21849  , p_source_8 => l_array_source_8(Idx)
21850  , p_source_9 => l_array_source_9(Idx)
21851  , p_source_10 => l_array_source_10(Idx)
21852  , p_source_11 => l_array_source_11(Idx)
21853  , p_source_12 => l_array_source_12(Idx)
21854  , p_source_13 => l_array_source_13(Idx)
21855  , p_source_14 => l_array_source_14(Idx)
21856  , p_source_15 => l_array_source_15(Idx)
21857  , p_source_16 => l_array_source_16(Idx)
21858  );
21859 If(l_balance_type_code = 'A') THEN
21860   l_actual_gain_loss_ref := l_gain_or_loss_ref;
21861 END IF;
21862 
21863 --
21864 
21865 
21866 --
21867 AcctLineType_8 (
21868  p_application_id  => p_application_id
21869  ,p_event_id     => l_event_id
21870  ,p_calculate_acctd_flag => l_calculate_acctd_flag
21871  ,p_calculate_g_l_flag => l_calculate_g_l_flag
21872  ,p_actual_flag => l_actual_flag
21873  ,p_balance_type_code => l_balance_type_code
21874  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
21875  
21876  , p_source_1 => l_array_source_1(Idx)
21877  , p_source_7 => l_array_source_7(Idx)
21878  , p_source_8 => l_array_source_8(Idx)
21879  , p_source_9 => l_array_source_9(Idx)
21880  , p_source_10 => l_array_source_10(Idx)
21881  , p_source_11 => l_array_source_11(Idx)
21882  , p_source_12 => l_array_source_12(Idx)
21883  , p_source_13 => l_array_source_13(Idx)
21884  , p_source_14 => l_array_source_14(Idx)
21885  , p_source_15 => l_array_source_15(Idx)
21886  , p_source_16 => l_array_source_16(Idx)
21887  );
21888 If(l_balance_type_code = 'A') THEN
21889   l_actual_gain_loss_ref := l_gain_or_loss_ref;
21890 END IF;
21891 
21892 --
21893 
21894 
21895 --
21896 AcctLineType_9 (
21897  p_application_id  => p_application_id
21898  ,p_event_id     => l_event_id
21899  ,p_calculate_acctd_flag => l_calculate_acctd_flag
21900  ,p_calculate_g_l_flag => l_calculate_g_l_flag
21901  ,p_actual_flag => l_actual_flag
21902  ,p_balance_type_code => l_balance_type_code
21903  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
21904  
21905  , p_source_1 => l_array_source_1(Idx)
21906  , p_source_7 => l_array_source_7(Idx)
21907  , p_source_8 => l_array_source_8(Idx)
21908  , p_source_9 => l_array_source_9(Idx)
21909  , p_source_10 => l_array_source_10(Idx)
21910  , p_source_11 => l_array_source_11(Idx)
21911  , p_source_12 => l_array_source_12(Idx)
21912  , p_source_13 => l_array_source_13(Idx)
21913  , p_source_14 => l_array_source_14(Idx)
21914  , p_source_15 => l_array_source_15(Idx)
21915  , p_source_16 => l_array_source_16(Idx)
21916  );
21917 If(l_balance_type_code = 'A') THEN
21918   l_actual_gain_loss_ref := l_gain_or_loss_ref;
21919 END IF;
21920 
21921 --
21922 
21923 
21927  ,p_event_id     => l_event_id
21924 --
21925 AcctLineType_10 (
21926  p_application_id  => p_application_id
21928  ,p_calculate_acctd_flag => l_calculate_acctd_flag
21929  ,p_calculate_g_l_flag => l_calculate_g_l_flag
21930  ,p_actual_flag => l_actual_flag
21931  ,p_balance_type_code => l_balance_type_code
21932  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
21933  
21934  , p_source_1 => l_array_source_1(Idx)
21935  , p_source_7 => l_array_source_7(Idx)
21936  , p_source_8 => l_array_source_8(Idx)
21937  , p_source_9 => l_array_source_9(Idx)
21938  , p_source_10 => l_array_source_10(Idx)
21939  , p_source_11 => l_array_source_11(Idx)
21940  , p_source_12 => l_array_source_12(Idx)
21941  , p_source_13 => l_array_source_13(Idx)
21942  , p_source_14 => l_array_source_14(Idx)
21943  , p_source_15 => l_array_source_15(Idx)
21944  , p_source_16 => l_array_source_16(Idx)
21945  );
21946 If(l_balance_type_code = 'A') THEN
21947   l_actual_gain_loss_ref := l_gain_or_loss_ref;
21948 END IF;
21949 
21950 --
21951 
21952 
21953 --
21954 AcctLineType_11 (
21955  p_application_id  => p_application_id
21956  ,p_event_id     => l_event_id
21957  ,p_calculate_acctd_flag => l_calculate_acctd_flag
21958  ,p_calculate_g_l_flag => l_calculate_g_l_flag
21959  ,p_actual_flag => l_actual_flag
21960  ,p_balance_type_code => l_balance_type_code
21961  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
21962  
21963  , p_source_1 => l_array_source_1(Idx)
21964  , p_source_7 => l_array_source_7(Idx)
21965  , p_source_8 => l_array_source_8(Idx)
21966  , p_source_9 => l_array_source_9(Idx)
21967  , p_source_10 => l_array_source_10(Idx)
21968  , p_source_11 => l_array_source_11(Idx)
21969  , p_source_12 => l_array_source_12(Idx)
21970  , p_source_13 => l_array_source_13(Idx)
21971  , p_source_14 => l_array_source_14(Idx)
21972  , p_source_15 => l_array_source_15(Idx)
21973  , p_source_16 => l_array_source_16(Idx)
21974  );
21975 If(l_balance_type_code = 'A') THEN
21976   l_actual_gain_loss_ref := l_gain_or_loss_ref;
21977 END IF;
21978 
21979 --
21980 
21981 
21982 --
21983 AcctLineType_12 (
21984  p_application_id  => p_application_id
21985  ,p_event_id     => l_event_id
21986  ,p_calculate_acctd_flag => l_calculate_acctd_flag
21987  ,p_calculate_g_l_flag => l_calculate_g_l_flag
21988  ,p_actual_flag => l_actual_flag
21989  ,p_balance_type_code => l_balance_type_code
21990  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
21991  
21992  , p_source_1 => l_array_source_1(Idx)
21993  , p_source_7 => l_array_source_7(Idx)
21994  , p_source_8 => l_array_source_8(Idx)
21995  , p_source_9 => l_array_source_9(Idx)
21996  , p_source_10 => l_array_source_10(Idx)
21997  , p_source_11 => l_array_source_11(Idx)
21998  , p_source_12 => l_array_source_12(Idx)
21999  , p_source_13 => l_array_source_13(Idx)
22000  , p_source_14 => l_array_source_14(Idx)
22001  , p_source_15 => l_array_source_15(Idx)
22002  , p_source_16 => l_array_source_16(Idx)
22003  );
22004 If(l_balance_type_code = 'A') THEN
22005   l_actual_gain_loss_ref := l_gain_or_loss_ref;
22006 END IF;
22007 
22008 --
22009 
22010 
22011 --
22012 AcctLineType_13 (
22013  p_application_id  => p_application_id
22014  ,p_event_id     => l_event_id
22015  ,p_calculate_acctd_flag => l_calculate_acctd_flag
22016  ,p_calculate_g_l_flag => l_calculate_g_l_flag
22017  ,p_actual_flag => l_actual_flag
22018  ,p_balance_type_code => l_balance_type_code
22019  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
22020  
22021  , p_source_1 => l_array_source_1(Idx)
22022  , p_source_7 => l_array_source_7(Idx)
22023  , p_source_8 => l_array_source_8(Idx)
22024  , p_source_9 => l_array_source_9(Idx)
22025  , p_source_10 => l_array_source_10(Idx)
22026  , p_source_11 => l_array_source_11(Idx)
22027  , p_source_12 => l_array_source_12(Idx)
22028  , p_source_13 => l_array_source_13(Idx)
22029  , p_source_14 => l_array_source_14(Idx)
22030  , p_source_15 => l_array_source_15(Idx)
22031  , p_source_16 => l_array_source_16(Idx)
22032  );
22033 If(l_balance_type_code = 'A') THEN
22034   l_actual_gain_loss_ref := l_gain_or_loss_ref;
22035 END IF;
22036 
22037 --
22038 
22039       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
22040       -- or secondary ledger that has different currency with primary
22041       -- or alc that is calculated by sla
22042       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
22043             (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'))
22044 
22045 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
22046 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
22047           AND (l_actual_flag = 'A')) THEN
22048         XLA_AE_LINES_PKG.CreateGainOrLossLines(
22049           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
22050          ,p_application_id   => p_application_id
22051          ,p_amb_context_code => 'DEFAULT'
22052          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
22053          ,p_event_class_code => C_EVENT_CLASS_CODE
22054          ,p_event_type_code  => C_EVENT_TYPE_CODE
22055          
22056          ,p_gain_ccid        => -1
22057          ,p_loss_ccid        => -1
22058 
22059          ,p_actual_flag      => l_actual_flag
22063          );
22060          ,p_enc_flag         => null
22061          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
22062          ,p_enc_g_l_ref      => null
22064       END IF;
22065    END IF;
22066 END IF;
22067 
22068    ELSE
22069       --
22070       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
22071       --
22072       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
22073          trace
22074             (p_msg      => 'Trancaction revesal option is Y'
22075             ,p_level    => C_LEVEL_STATEMENT
22076             ,p_module   => l_log_module);
22077       END IF;
22078    END IF;
22079 
22080 END LOOP;
22081 l_result := XLA_AE_LINES_PKG.InsertLines ;
22082 end loop;
22083 close line_cur;
22084 
22085 
22086 --
22087 -- insert headers into xla_ae_headers_gt table
22088 --
22089 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
22090 
22091 -- insert into errors table here.
22092 
22093 END LOOP;
22094 
22095 --
22096 -- 4865292
22097 --
22098 -- Compare g_hdr_extract_count with event count in
22099 -- CreateHeadersAndLines.
22100 --
22101 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
22102 
22103 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
22104    trace (p_msg     => '# rows extracted from header extract objects '
22105                     || ' (running total): '
22106                     || g_hdr_extract_count
22107          ,p_level   => C_LEVEL_STATEMENT
22108          ,p_module  => l_log_module);
22109 END IF;
22110 
22111 CLOSE header_cur;
22112 --
22113 
22114 --
22115 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
22116    trace
22117       (p_msg      => 'END of EventClass_40'
22118       ,p_level    => C_LEVEL_PROCEDURE
22119       ,p_module   => l_log_module);
22120 END IF;
22121 --
22122 RETURN l_result;
22123 EXCEPTION
22124 WHEN xla_exceptions_pkg.application_exception THEN
22125    
22126 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
22127 
22128    
22129 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
22130 
22131    RAISE;
22132 
22133 WHEN NO_DATA_FOUND THEN
22134 
22135 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
22136 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
22137 
22138 FOR header_record IN header_cur
22139 LOOP
22140     l_array_header_events(header_record.event_id) := header_record.event_id;
22141 END LOOP;
22142 
22143 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
22144 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
22145 
22146 fnd_file.put_line(fnd_file.LOG, '                    ');
22147 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
22148 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
22149 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
22150 
22151 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
22152 LOOP
22153 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
22154 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
22155         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
22156 	END IF;
22157 END LOOP;
22158 
22159 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
22160 fnd_file.put_line(fnd_file.LOG, '                    ');
22161 
22162 
22163 xla_exceptions_pkg.raise_message
22164       (p_location => 'XLA_00222_AAD_S_000004_PKG.EventClass_40');
22165 
22166 
22167 WHEN OTHERS THEN
22168    xla_exceptions_pkg.raise_message
22169       (p_location => 'XLA_00222_AAD_S_000004_PKG.EventClass_40');
22170 END EventClass_40;
22171 --
22172 
22173 ---------------------------------------
22174 --
22175 -- PRIVATE PROCEDURE
22176 --         insert_sources_41
22177 --
22178 ----------------------------------------
22179 --
22180 PROCEDURE insert_sources_41(
22181                                 p_target_ledger_id       IN NUMBER
22182                               , p_language               IN VARCHAR2
22183                               , p_sla_ledger_id          IN NUMBER
22184                               , p_pad_start_date         IN DATE
22185                               , p_pad_end_date           IN DATE
22186                          )
22187 IS
22188 
22189 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'RECEIPT_ALL';
22190 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'RECEIPT';
22191 p_apps_owner                   VARCHAR2(30);
22192 l_log_module                   VARCHAR2(240);
22193 BEGIN
22194 IF g_log_enabled THEN
22195       l_log_module := C_DEFAULT_MODULE||'.insert_sources_41';
22196 END IF;
22197 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
22198 
22199       trace
22200          (p_msg      => 'BEGIN of insert_sources_41'
22201          ,p_level    => C_LEVEL_PROCEDURE
22202          ,p_module   => l_log_module);
22203 
22204 END IF;
22205 
22206 -- select APPS owner
22207 SELECT oracle_username
22208   INTO p_apps_owner
22209   FROM fnd_oracle_userid
22210  WHERE read_only_flag = 'U'
22211 ;
22212 
22216                         ' - p_language = '||p_language||
22213 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
22214       trace
22215          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
22217                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
22218                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
22219                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
22220                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
22221          ,p_level    => C_LEVEL_STATEMENT
22222          ,p_module   => l_log_module);
22223 END IF;
22224 
22225 
22226 --
22227 INSERT INTO xla_diag_sources --hdr2
22228 (
22229         event_id
22230       , ledger_id
22231       , sla_ledger_id
22232       , description_language
22233       , object_name
22234       , object_type_code
22235       , line_number
22236       , source_application_id
22237       , source_type_code
22238       , source_code
22239       , source_value
22240       , source_meaning
22241       , created_by
22242       , creation_date
22243       , last_update_date
22244       , last_updated_by
22245       , last_update_login
22246       , program_update_date
22247       , program_application_id
22248       , program_id
22249       , request_id
22250 )
22251 SELECT
22252         event_id
22253       , p_target_ledger_id
22254       , p_sla_ledger_id
22255       , p_language
22256       , object_name
22257       , object_type_code
22258       , line_number
22259       , source_application_id
22260       , source_type_code
22261       , source_code
22262       , SUBSTR(source_value ,1,1996)
22263       , SUBSTR(source_meaning ,1,200)
22264       , xla_environment_pkg.g_Usr_Id
22265       , TRUNC(SYSDATE)
22266       , TRUNC(SYSDATE)
22267       , xla_environment_pkg.g_Usr_Id
22268       , xla_environment_pkg.g_Login_Id
22269       , TRUNC(SYSDATE)
22270       , xla_environment_pkg.g_Prog_Appl_Id
22271       , xla_environment_pkg.g_Prog_Id
22272       , xla_environment_pkg.g_Req_Id
22273   FROM (
22274        SELECT xet.event_id                  event_id
22275             , 0                          line_number
22276             , CASE r
22277                WHEN 1 THEN 'AR_REMIT_BANK_ACCT_H_V' 
22278                 WHEN 2 THEN 'AR_SYSTEM_PARAM_H_V' 
22279                 WHEN 3 THEN 'AR_SYSTEM_PARAM_H_V' 
22280                 WHEN 4 THEN 'AR_CASH_RECEIPTS_H_V' 
22281                 WHEN 5 THEN 'AR_CASH_RECEIPTS_H_V' 
22282                 WHEN 6 THEN 'AR_RCT_SITE_USES_H_V' 
22283                 WHEN 7 THEN 'AR_CASH_RECEIPTS_H_V' 
22284                 WHEN 8 THEN 'AR_CASH_RECEIPTS_H_V' 
22285                 WHEN 9 THEN 'AR_CASH_RECEIPTS_H_V' 
22286                 WHEN 10 THEN 'AR_CASH_RECEIPTS_H_V' 
22287                 WHEN 11 THEN 'AR_CASH_RECEIPTS_H_V' 
22288                 
22289                ELSE null
22290               END                           object_name
22291             , CASE r
22292                 WHEN 1 THEN 'HEADER' 
22293                 WHEN 2 THEN 'HEADER' 
22294                 WHEN 3 THEN 'HEADER' 
22295                 WHEN 4 THEN 'HEADER' 
22296                 WHEN 5 THEN 'HEADER' 
22297                 WHEN 6 THEN 'HEADER' 
22298                 WHEN 7 THEN 'HEADER' 
22299                 WHEN 8 THEN 'HEADER' 
22300                 WHEN 9 THEN 'HEADER' 
22301                 WHEN 10 THEN 'HEADER' 
22302                 WHEN 11 THEN 'HEADER' 
22303                 
22304                 ELSE null
22305               END                           object_type_code
22306             , CASE r
22307                 WHEN 1 THEN '222' 
22308                 WHEN 2 THEN '222' 
22309                 WHEN 3 THEN '222' 
22310                 WHEN 4 THEN '222' 
22311                 WHEN 5 THEN '222' 
22312                 WHEN 6 THEN '222' 
22313                 WHEN 7 THEN '222' 
22314                 WHEN 8 THEN '222' 
22315                 WHEN 9 THEN '222' 
22316                 WHEN 10 THEN '222' 
22317                 WHEN 11 THEN '222' 
22318                 
22319                 ELSE null
22320               END                           source_application_id
22321             , 'S'             source_type_code
22322             , CASE r
22323                 WHEN 1 THEN 'RMT_BNK_UNAPPLIED_CCID' 
22324                 WHEN 2 THEN 'CODE_COMBINATION_ID_GAIN' 
22325                 WHEN 3 THEN 'CODE_COMBINATION_ID_LOSS' 
22326                 WHEN 4 THEN 'RCT_XLA_APPLIED_TO_APP_ID' 
22327                 WHEN 5 THEN 'RCT_PAY_FROM_CUSTOMER' 
22328                 WHEN 6 THEN 'RCT_SITE_SITE_USE_ID' 
22329                 WHEN 7 THEN 'RCT_APP_STATUS' 
22330                 WHEN 8 THEN 'RCT_DOC_SEQUENCE_CATEGORY' 
22331                 WHEN 9 THEN 'RCT_DOC_SEQUENCE_ID' 
22332                 WHEN 10 THEN 'RCT_DOC_SEQUENCE_VALUE' 
22333                 WHEN 11 THEN 'RCT_TRX_ACCT_REVERSAL' 
22334                 
22335                 ELSE null
22336               END                           source_code
22337             , CASE r
22338                 WHEN 1 THEN TO_CHAR(h7.RMT_BNK_UNAPPLIED_CCID)
22339                 WHEN 2 THEN TO_CHAR(h8.CODE_COMBINATION_ID_GAIN)
22340                 WHEN 3 THEN TO_CHAR(h8.CODE_COMBINATION_ID_LOSS)
22341                 WHEN 4 THEN TO_CHAR(h1.RCT_XLA_APPLIED_TO_APP_ID)
22345                 WHEN 8 THEN TO_CHAR(h1.RCT_DOC_SEQUENCE_CATEGORY)
22342                 WHEN 5 THEN TO_CHAR(h1.RCT_PAY_FROM_CUSTOMER)
22343                 WHEN 6 THEN TO_CHAR(h5.RCT_SITE_SITE_USE_ID)
22344                 WHEN 7 THEN TO_CHAR(h1.RCT_APP_STATUS)
22346                 WHEN 9 THEN TO_CHAR(h1.RCT_DOC_SEQUENCE_ID)
22347                 WHEN 10 THEN TO_CHAR(h1.RCT_DOC_SEQUENCE_VALUE)
22348                 WHEN 11 THEN TO_CHAR(h1.RCT_TRX_ACCT_REVERSAL)
22349                 
22350                 ELSE null
22351               END                           source_value
22352             , null              source_meaning
22353          FROM xla_events_gt     xet  
22354       , AR_CASH_RECEIPTS_H_V  h1
22355       , AR_RCT_SITE_USES_H_V  h5
22356       , AR_REMIT_BANK_ACCT_H_V  h7
22357       , AR_SYSTEM_PARAM_H_V  h8
22358              ,(select rownum r from all_objects where rownum <= 11 and owner = p_apps_owner)
22359          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
22360            AND xet.event_class_code = C_EVENT_CLASS_CODE
22361               AND h1.event_id = xet.event_id
22362   AND h5.event_id (+) = h1.event_id
22363   AND h7.event_id (+) = h1.event_id
22364   AND h8.event_id (+) = h1.event_id
22365 
22366 )
22367 ;
22368 --
22369 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
22370 
22371       trace
22372          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
22373          ,p_level    => C_LEVEL_STATEMENT
22374          ,p_module   => l_log_module);
22375 
22376 END IF;
22377 --
22378 
22379 
22380 
22381 --
22382 INSERT INTO xla_diag_sources  --line2
22383 (
22384         event_id
22385       , ledger_id
22386       , sla_ledger_id
22387       , description_language
22388       , object_name
22389       , object_type_code
22390       , line_number
22391       , source_application_id
22392       , source_type_code
22393       , source_code
22394       , source_value
22395       , source_meaning
22396       , created_by
22397       , creation_date
22398       , last_update_date
22399       , last_updated_by
22400       , last_update_login
22401       , program_update_date
22402       , program_application_id
22403       , program_id
22404       , request_id
22405 )
22406 SELECT  event_id
22407       , p_target_ledger_id
22408       , p_sla_ledger_id
22409       , p_language
22410       , object_name
22411       , object_type_code
22412       , line_number
22413       , source_application_id
22414       , source_type_code
22415       , source_code
22416       , SUBSTR(source_value,1,1996)
22417       , SUBSTR(source_meaning ,1,200)
22418       , xla_environment_pkg.g_Usr_Id
22419       , TRUNC(SYSDATE)
22420       , TRUNC(SYSDATE)
22421       , xla_environment_pkg.g_Usr_Id
22422       , xla_environment_pkg.g_Login_Id
22423       , TRUNC(SYSDATE)
22424       , xla_environment_pkg.g_Prog_Appl_Id
22425       , xla_environment_pkg.g_Prog_Id
22426       , xla_environment_pkg.g_Req_Id
22427   FROM (
22428        SELECT xet.event_id                  event_id
22429             , l4.line_number                 line_number
22430             , CASE r
22431                WHEN 1 THEN 'AR_DISTRIBUTIONS_L_V' 
22432                 WHEN 2 THEN 'AR_CUST_TRX_LINES_L_V' 
22433                 WHEN 3 THEN 'AR_DISTRIBUTIONS_L_V' 
22434                 WHEN 4 THEN 'AR_DISTRIBUTIONS_L_V' 
22435                 WHEN 5 THEN 'AR_DISTRIBUTIONS_L_V' 
22436                 WHEN 6 THEN 'AR_DISTRIBUTIONS_L_V' 
22437                 WHEN 7 THEN 'AR_DISTRIBUTIONS_L_V' 
22438                 WHEN 8 THEN 'AR_DISTRIBUTIONS_L_V' 
22439                 WHEN 9 THEN 'AR_DISTRIBUTIONS_L_V' 
22440                 WHEN 10 THEN 'AR_DISTRIBUTIONS_BASE_V' 
22441                 WHEN 11 THEN 'AR_DISTRIBUTIONS_BASE_V' 
22442                 WHEN 12 THEN 'AR_DISTRIBUTIONS_BASE_V' 
22443                 WHEN 13 THEN 'AR_DISTRIBUTIONS_BASE_V' 
22444                 WHEN 14 THEN 'AR_CUST_TRX_LINES_L_V' 
22445                 WHEN 15 THEN 'AR_TRANSACTIONS_S_V' 
22446                 WHEN 16 THEN 'AR_CUST_TRX_LINES_L_V' 
22447                 WHEN 17 THEN 'AR_TRANSACTIONS_S_V' 
22448                 WHEN 18 THEN 'AR_DISTRIBUTIONS_L_V' 
22449                 WHEN 19 THEN 'AR_DISTRIBUTIONS_L_V' 
22450                 WHEN 20 THEN 'AR_DISTRIBUTIONS_BASE_V' 
22451                 WHEN 21 THEN 'AR_DISTRIBUTIONS_BASE_V' 
22452                 WHEN 22 THEN 'AR_DISTRIBUTIONS_L_V' 
22453                 WHEN 23 THEN 'AR_DISTRIBUTIONS_L_V' 
22454                 WHEN 24 THEN 'AR_DISTRIBUTIONS_L_V' 
22455                 WHEN 25 THEN 'AR_CUST_TRX_LINES_L_V' 
22456                 WHEN 26 THEN 'AR_DISTRIBUTIONS_BASE_V' 
22457                 WHEN 27 THEN 'AR_DISTRIBUTIONS_BASE_V' 
22458                 WHEN 28 THEN 'AR_RECEIVABLES_TRX_ACT_S_V' 
22459                 WHEN 29 THEN 'AR_DISTRIBUTIONS_L_V' 
22460                 
22461                ELSE null
22462               END                           object_name
22463             , CASE r
22464                 WHEN 1 THEN 'LINE' 
22465                 WHEN 2 THEN 'LINE' 
22466                 WHEN 3 THEN 'LINE' 
22467                 WHEN 4 THEN 'LINE' 
22468                 WHEN 5 THEN 'LINE' 
22469                 WHEN 6 THEN 'LINE' 
22470                 WHEN 7 THEN 'LINE' 
22471                 WHEN 8 THEN 'LINE' 
22472                 WHEN 9 THEN 'LINE' 
22476                 WHEN 13 THEN 'LINE' 
22473                 WHEN 10 THEN 'LINE' 
22474                 WHEN 11 THEN 'LINE' 
22475                 WHEN 12 THEN 'LINE' 
22477                 WHEN 14 THEN 'LINE' 
22478                 WHEN 15 THEN 'LINE' 
22479                 WHEN 16 THEN 'LINE' 
22480                 WHEN 17 THEN 'LINE' 
22481                 WHEN 18 THEN 'LINE' 
22482                 WHEN 19 THEN 'LINE' 
22483                 WHEN 20 THEN 'LINE' 
22484                 WHEN 21 THEN 'LINE' 
22485                 WHEN 22 THEN 'LINE' 
22486                 WHEN 23 THEN 'LINE' 
22487                 WHEN 24 THEN 'LINE' 
22488                 WHEN 25 THEN 'LINE' 
22489                 WHEN 26 THEN 'LINE' 
22490                 WHEN 27 THEN 'LINE' 
22491                 WHEN 28 THEN 'LINE' 
22492                 WHEN 29 THEN 'LINE' 
22493                 
22494                 ELSE null
22495               END                           object_type_code
22496             , CASE r
22497                 WHEN 1 THEN '222' 
22498                 WHEN 2 THEN '222' 
22499                 WHEN 3 THEN '222' 
22500                 WHEN 4 THEN '222' 
22501                 WHEN 5 THEN '222' 
22502                 WHEN 6 THEN '222' 
22503                 WHEN 7 THEN '222' 
22504                 WHEN 8 THEN '222' 
22505                 WHEN 9 THEN '222' 
22506                 WHEN 10 THEN '222' 
22507                 WHEN 11 THEN '222' 
22508                 WHEN 12 THEN '222' 
22509                 WHEN 13 THEN '222' 
22510                 WHEN 14 THEN '222' 
22511                 WHEN 15 THEN '222' 
22512                 WHEN 16 THEN '222' 
22513                 WHEN 17 THEN '222' 
22514                 WHEN 18 THEN '222' 
22515                 WHEN 19 THEN '222' 
22516                 WHEN 20 THEN '222' 
22517                 WHEN 21 THEN '222' 
22518                 WHEN 22 THEN '222' 
22519                 WHEN 23 THEN '222' 
22520                 WHEN 24 THEN '222' 
22521                 WHEN 25 THEN '222' 
22522                 WHEN 26 THEN '222' 
22523                 WHEN 27 THEN '222' 
22524                 WHEN 28 THEN '222' 
22525                 WHEN 29 THEN '222' 
22526                 
22527                 ELSE null
22528               END                           source_application_id
22529             , 'S'             source_type_code
22530             , CASE r
22531                 WHEN 1 THEN 'DIST_CODE_COMBINATION_ID' 
22532                 WHEN 2 THEN 'TRX_LINE_DIST_CCID' 
22533                 WHEN 3 THEN 'DIST_REF_DIST_CCID' 
22534                 WHEN 4 THEN 'DIST_SOURCE_TYPE' 
22535                 WHEN 5 THEN 'DIST_MFAR_ADDITIONAL_ENTRY' 
22536                 WHEN 6 THEN 'DIST_LINE_ID' 
22537                 WHEN 7 THEN 'DISTRIBUTION_TYPE' 
22538                 WHEN 8 THEN 'DIST_ENT_AMT' 
22539                 WHEN 9 THEN 'DIST_CURRENCY_CODE' 
22540                 WHEN 10 THEN 'DIST_TO_CUR_CONVERSION_DATE' 
22541                 WHEN 11 THEN 'DIST_CUR_CONVERSION_RATE' 
22542                 WHEN 12 THEN 'DIST_CUR_CONVERSION_TYPE' 
22543                 WHEN 13 THEN 'DIST_TO_ACCTD_AMT' 
22544                 WHEN 14 THEN 'TRX_DISTRIBUTION_TYPE' 
22545                 WHEN 15 THEN 'TRX_ENTITY_CODE' 
22546                 WHEN 16 THEN 'TRX_LINE_DIST_ID' 
22547                 WHEN 17 THEN 'TRX_CUSTOMER_TRX_ID' 
22548                 WHEN 18 THEN 'DIST_ENT_AMT_FROM' 
22549                 WHEN 19 THEN 'DIST_CURRENCY_CODE_FROM' 
22550                 WHEN 20 THEN 'DIST_CUR_CONVERSION_DATE' 
22551                 WHEN 21 THEN 'DIST_ACCTD_AMT' 
22552                 WHEN 22 THEN 'DIST_PARTY_ID' 
22553                 WHEN 23 THEN 'DIST_PARTY_SITE_ID' 
22554                 WHEN 24 THEN 'DIST_PARTY_TYPE' 
22555                 WHEN 25 THEN 'TRX_LINE_DIST_ACCOUNT_CLASS' 
22556                 WHEN 26 THEN 'DIST_TO_CUR_CONVERSION_RATE' 
22557                 WHEN 27 THEN 'DIST_TO_CUR_CONVERSION_TYPE' 
22558                 WHEN 28 THEN 'REC_ACT_TYPE' 
22559                 WHEN 29 THEN 'DIST_SOURCE_TABLE' 
22560                 
22561                 ELSE null
22562               END                           source_code
22563             , CASE r
22564                 WHEN 1 THEN TO_CHAR(l4.DIST_CODE_COMBINATION_ID)
22565                 WHEN 2 THEN TO_CHAR(l2.TRX_LINE_DIST_CCID)
22566                 WHEN 3 THEN TO_CHAR(l4.DIST_REF_DIST_CCID)
22567                 WHEN 4 THEN TO_CHAR(l4.DIST_SOURCE_TYPE)
22568                 WHEN 5 THEN TO_CHAR(l4.DIST_MFAR_ADDITIONAL_ENTRY)
22569                 WHEN 6 THEN TO_CHAR(l4.DIST_LINE_ID)
22570                 WHEN 7 THEN TO_CHAR(l4.DISTRIBUTION_TYPE)
22571                 WHEN 8 THEN TO_CHAR(l4.DIST_ENT_AMT)
22572                 WHEN 9 THEN TO_CHAR(l4.DIST_CURRENCY_CODE)
22573                 WHEN 10 THEN TO_CHAR(l3.DIST_TO_CUR_CONVERSION_DATE)
22574                 WHEN 11 THEN TO_CHAR(l3.DIST_CUR_CONVERSION_RATE)
22575                 WHEN 12 THEN TO_CHAR(l3.DIST_CUR_CONVERSION_TYPE)
22576                 WHEN 13 THEN TO_CHAR(l3.DIST_TO_ACCTD_AMT)
22577                 WHEN 14 THEN TO_CHAR(l2.TRX_DISTRIBUTION_TYPE)
22578                 WHEN 15 THEN TO_CHAR(l9.TRX_ENTITY_CODE)
22579                 WHEN 16 THEN TO_CHAR(l2.TRX_LINE_DIST_ID)
22580                 WHEN 17 THEN TO_CHAR(l9.TRX_CUSTOMER_TRX_ID)
22581                 WHEN 18 THEN TO_CHAR(l4.DIST_ENT_AMT_FROM)
22582                 WHEN 19 THEN TO_CHAR(l4.DIST_CURRENCY_CODE_FROM)
22583                 WHEN 20 THEN TO_CHAR(l3.DIST_CUR_CONVERSION_DATE)
22587                 WHEN 24 THEN TO_CHAR(l4.DIST_PARTY_TYPE)
22584                 WHEN 21 THEN TO_CHAR(l3.DIST_ACCTD_AMT)
22585                 WHEN 22 THEN TO_CHAR(l4.DIST_PARTY_ID)
22586                 WHEN 23 THEN TO_CHAR(l4.DIST_PARTY_SITE_ID)
22588                 WHEN 25 THEN TO_CHAR(l2.TRX_LINE_DIST_ACCOUNT_CLASS)
22589                 WHEN 26 THEN TO_CHAR(l3.DIST_TO_CUR_CONVERSION_RATE)
22590                 WHEN 27 THEN TO_CHAR(l3.DIST_TO_CUR_CONVERSION_TYPE)
22591                 WHEN 28 THEN TO_CHAR(l6.REC_ACT_TYPE)
22592                 WHEN 29 THEN TO_CHAR(l4.DIST_SOURCE_TABLE)
22593                 
22594                 ELSE null
22595               END                           source_value
22596             , null              source_meaning
22597          FROM  xla_events_gt     xet  
22598         , AR_CUST_TRX_LINES_L_V  l2
22599         , AR_DISTRIBUTIONS_BASE_V  l3
22600         , AR_DISTRIBUTIONS_L_V  l4
22601         , AR_RECEIVABLES_TRX_ACT_S_V  l6
22602         , AR_TRANSACTIONS_S_V  l9
22603             , (select rownum r from all_objects where rownum <= 29 and owner = p_apps_owner)
22604         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
22605           AND xet.event_class_code = C_EVENT_CLASS_CODE
22606             AND l3.event_id          = xet.event_id
22607   AND l2.event_id (+)    = l3.event_id
22608   AND l2.line_number (+) = l3.line_number
22609   AND l4.event_id    = l3.event_id
22610   AND l4.line_number = l3.line_number
22611   AND l6.event_id (+)    = l3.event_id
22612   AND l6.line_number (+) = l3.line_number
22613   AND l9.event_id (+)    = l3.event_id
22614   AND l9.line_number (+) = l3.line_number
22615 
22616 )
22617 ;
22618 --
22619 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
22620 
22621       trace
22622          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
22623          ,p_level    => C_LEVEL_STATEMENT
22624          ,p_module   => l_log_module);
22625 
22626 END IF;
22627 
22628 
22629 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
22630       trace
22631          (p_msg      => 'END of insert_sources_41'
22632          ,p_level    => C_LEVEL_PROCEDURE
22633          ,p_module   => l_log_module);
22634 END IF;
22635 EXCEPTION
22636   WHEN xla_exceptions_pkg.application_exception THEN
22637       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
22638             trace
22639                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
22640                ,p_level    => C_LEVEL_EXCEPTION
22641                ,p_module   => l_log_module);
22642       END IF;
22643       RAISE;
22644   WHEN OTHERS THEN
22645       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
22646             trace
22647                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
22648                ,p_level    => C_LEVEL_EXCEPTION
22649                ,p_module   => l_log_module);
22650        END IF;
22651        xla_exceptions_pkg.raise_message
22652            (p_location => 'XLA_00222_AAD_S_000004_PKG.insert_sources_41');
22653 END insert_sources_41;
22654 --
22655 
22656 ---------------------------------------
22657 --
22658 -- PRIVATE FUNCTION
22659 --         EventClass_41
22660 --
22661 ----------------------------------------
22662 --
22663 FUNCTION EventClass_41
22664        (p_application_id         IN NUMBER
22665        ,p_base_ledger_id         IN NUMBER
22666        ,p_target_ledger_id       IN NUMBER
22667        ,p_language               IN VARCHAR2
22668        ,p_currency_code          IN VARCHAR2
22669        ,p_sla_ledger_id          IN NUMBER
22670        ,p_pad_start_date         IN DATE
22671        ,p_pad_end_date           IN DATE
22672        ,p_primary_ledger_id      IN NUMBER)
22673 RETURN BOOLEAN IS
22674 --
22675 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'RECEIPT_ALL';
22676 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'RECEIPT';
22677 
22678 l_calculate_acctd_flag   VARCHAR2(1) :='N';
22679 l_calculate_g_l_flag     VARCHAR2(1) :='Y';
22680 --
22681 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
22682 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
22683 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
22684 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
22685 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
22686 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
22687 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
22688 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
22689 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
22690 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
22691 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
22692 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
22693 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
22694 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
22695 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
22696 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
22697 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
22698 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
22702 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
22699 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
22700 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
22701 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
22703 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
22704 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
22705 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
22706 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
22707 
22708 l_event_id                             NUMBER;
22709 l_previous_event_id                    NUMBER;
22710 l_first_event_id                       NUMBER;
22711 l_last_event_id                        NUMBER;
22712 
22713 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
22714 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
22715 --
22716 --
22717 l_result                    BOOLEAN := TRUE;
22718 l_rows                      NUMBER  := 1000;
22719 l_event_type_name           VARCHAR2(80) := 'All';
22720 l_event_class_name          VARCHAR2(80) := 'Receipt';
22721 l_description               VARCHAR2(4000);
22722 l_transaction_reversal      NUMBER;
22723 l_ae_header_id              NUMBER;
22724 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
22725 l_log_module                VARCHAR2(240);
22726 --
22727 l_acct_reversal_source      VARCHAR2(30);
22728 l_trx_reversal_source       VARCHAR2(30);
22729 
22730 l_continue_with_lines       BOOLEAN := TRUE;
22731 --
22732 l_acc_rev_gl_date_source    DATE;                      -- 4262811
22733 --
22734 type t_array_event_id is table of number index by binary_integer;
22735 
22736 l_rec_array_event                    t_rec_array_event;
22737 l_null_rec_array_event               t_rec_array_event;
22738 l_array_ae_header_id                 xla_number_array_type;
22739 l_actual_flag                        VARCHAR2(1) := NULL;
22740 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
22741 l_balance_type_code                  VARCHAR2(1) :=NULL;
22742 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
22743 
22744 --
22745 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
22746 --
22747 
22748 TYPE t_array_source_2 IS TABLE OF AR_REMIT_BANK_ACCT_H_V.RMT_BNK_UNAPPLIED_CCID%TYPE INDEX BY BINARY_INTEGER;
22749 TYPE t_array_source_3 IS TABLE OF AR_SYSTEM_PARAM_H_V.CODE_COMBINATION_ID_GAIN%TYPE INDEX BY BINARY_INTEGER;
22750 TYPE t_array_source_4 IS TABLE OF AR_SYSTEM_PARAM_H_V.CODE_COMBINATION_ID_LOSS%TYPE INDEX BY BINARY_INTEGER;
22751 TYPE t_array_source_17 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_XLA_APPLIED_TO_APP_ID%TYPE INDEX BY BINARY_INTEGER;
22752 TYPE t_array_source_34 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_PAY_FROM_CUSTOMER%TYPE INDEX BY BINARY_INTEGER;
22753 TYPE t_array_source_35 IS TABLE OF AR_RCT_SITE_USES_H_V.RCT_SITE_SITE_USE_ID%TYPE INDEX BY BINARY_INTEGER;
22754 TYPE t_array_source_36 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_APP_STATUS%TYPE INDEX BY BINARY_INTEGER;
22755 TYPE t_array_source_37 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_CATEGORY%TYPE INDEX BY BINARY_INTEGER;
22756 TYPE t_array_source_38 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_ID%TYPE INDEX BY BINARY_INTEGER;
22757 TYPE t_array_source_39 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_DOC_SEQUENCE_VALUE%TYPE INDEX BY BINARY_INTEGER;
22758 TYPE t_array_source_41 IS TABLE OF AR_CASH_RECEIPTS_H_V.RCT_TRX_ACCT_REVERSAL%TYPE INDEX BY BINARY_INTEGER;
22759 
22760 TYPE t_array_source_1 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CODE_COMBINATION_ID%TYPE INDEX BY BINARY_INTEGER;
22761 TYPE t_array_source_5 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
22762 TYPE t_array_source_6 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_REF_DIST_CCID%TYPE INDEX BY BINARY_INTEGER;
22763 TYPE t_array_source_7 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_SOURCE_TYPE%TYPE INDEX BY BINARY_INTEGER;
22764 TYPE t_array_source_8 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_MFAR_ADDITIONAL_ENTRY%TYPE INDEX BY BINARY_INTEGER;
22765 TYPE t_array_source_9 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_LINE_ID%TYPE INDEX BY BINARY_INTEGER;
22766 TYPE t_array_source_10 IS TABLE OF AR_DISTRIBUTIONS_L_V.DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
22767 TYPE t_array_source_11 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_ENT_AMT%TYPE INDEX BY BINARY_INTEGER;
22768 TYPE t_array_source_12 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
22769 TYPE t_array_source_13 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
22770 TYPE t_array_source_14 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
22771 TYPE t_array_source_15 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
22772 TYPE t_array_source_16 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
22773 TYPE t_array_source_18 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
22774 TYPE t_array_source_19 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_ENTITY_CODE%TYPE INDEX BY BINARY_INTEGER;
22775 TYPE t_array_source_20 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ID%TYPE INDEX BY BINARY_INTEGER;
22776 TYPE t_array_source_21 IS TABLE OF AR_TRANSACTIONS_S_V.TRX_CUSTOMER_TRX_ID%TYPE INDEX BY BINARY_INTEGER;
22777 TYPE t_array_source_22 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_ENT_AMT_FROM%TYPE INDEX BY BINARY_INTEGER;
22778 TYPE t_array_source_23 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_CURRENCY_CODE_FROM%TYPE INDEX BY BINARY_INTEGER;
22782 TYPE t_array_source_27 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_PARTY_SITE_ID%TYPE INDEX BY BINARY_INTEGER;
22779 TYPE t_array_source_24 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_CUR_CONVERSION_DATE%TYPE INDEX BY BINARY_INTEGER;
22780 TYPE t_array_source_25 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_ACCTD_AMT%TYPE INDEX BY BINARY_INTEGER;
22781 TYPE t_array_source_26 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_PARTY_ID%TYPE INDEX BY BINARY_INTEGER;
22783 TYPE t_array_source_28 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
22784 TYPE t_array_source_29 IS TABLE OF AR_CUST_TRX_LINES_L_V.TRX_LINE_DIST_ACCOUNT_CLASS%TYPE INDEX BY BINARY_INTEGER;
22785 TYPE t_array_source_30 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_CUR_CONVERSION_RATE%TYPE INDEX BY BINARY_INTEGER;
22786 TYPE t_array_source_31 IS TABLE OF AR_DISTRIBUTIONS_BASE_V.DIST_TO_CUR_CONVERSION_TYPE%TYPE INDEX BY BINARY_INTEGER;
22787 TYPE t_array_source_32 IS TABLE OF AR_RECEIVABLES_TRX_ACT_S_V.REC_ACT_TYPE%TYPE INDEX BY BINARY_INTEGER;
22788 TYPE t_array_source_33 IS TABLE OF AR_DISTRIBUTIONS_L_V.DIST_SOURCE_TABLE%TYPE INDEX BY BINARY_INTEGER;
22789 
22790 l_array_source_2              t_array_source_2;
22791 l_array_source_3              t_array_source_3;
22792 l_array_source_4              t_array_source_4;
22793 l_array_source_17              t_array_source_17;
22794 l_array_source_34              t_array_source_34;
22795 l_array_source_35              t_array_source_35;
22796 l_array_source_36              t_array_source_36;
22797 l_array_source_37              t_array_source_37;
22798 l_array_source_38              t_array_source_38;
22799 l_array_source_39              t_array_source_39;
22800 l_array_source_41              t_array_source_41;
22801 
22802 l_array_source_1      t_array_source_1;
22803 l_array_source_5      t_array_source_5;
22804 l_array_source_6      t_array_source_6;
22805 l_array_source_7      t_array_source_7;
22806 l_array_source_8      t_array_source_8;
22807 l_array_source_9      t_array_source_9;
22808 l_array_source_10      t_array_source_10;
22809 l_array_source_11      t_array_source_11;
22810 l_array_source_12      t_array_source_12;
22811 l_array_source_13      t_array_source_13;
22812 l_array_source_14      t_array_source_14;
22813 l_array_source_15      t_array_source_15;
22814 l_array_source_16      t_array_source_16;
22815 l_array_source_18      t_array_source_18;
22816 l_array_source_19      t_array_source_19;
22817 l_array_source_20      t_array_source_20;
22818 l_array_source_21      t_array_source_21;
22819 l_array_source_22      t_array_source_22;
22820 l_array_source_23      t_array_source_23;
22821 l_array_source_24      t_array_source_24;
22822 l_array_source_25      t_array_source_25;
22823 l_array_source_26      t_array_source_26;
22824 l_array_source_27      t_array_source_27;
22825 l_array_source_28      t_array_source_28;
22826 l_array_source_29      t_array_source_29;
22827 l_array_source_30      t_array_source_30;
22828 l_array_source_31      t_array_source_31;
22829 l_array_source_32      t_array_source_32;
22830 l_array_source_33      t_array_source_33;
22831 
22832 --
22833 CURSOR header_cur
22834 IS
22835 SELECT /*+ leading(xet) cardinality(xet,1) */
22836 -- Event Class Code: RECEIPT
22837     xet.entity_id
22838    ,xet.legal_entity_id
22839    ,xet.entity_code
22840    ,xet.transaction_number
22841    ,xet.event_id
22842    ,xet.event_class_code
22843    ,xet.event_type_code
22844    ,xet.event_number
22845    ,xet.event_date
22846    ,xet.transaction_date
22847    ,xet.reference_num_1
22848    ,xet.reference_num_2
22849    ,xet.reference_num_3
22850    ,xet.reference_num_4
22851    ,xet.reference_char_1
22852    ,xet.reference_char_2
22853    ,xet.reference_char_3
22854    ,xet.reference_char_4
22855    ,xet.reference_date_1
22856    ,xet.reference_date_2
22857    ,xet.reference_date_3
22858    ,xet.reference_date_4
22859    ,xet.event_created_by
22860    ,xet.budgetary_control_flag 
22861   , h7.RMT_BNK_UNAPPLIED_CCID    source_2
22862   , h8.CODE_COMBINATION_ID_GAIN    source_3
22863   , h8.CODE_COMBINATION_ID_LOSS    source_4
22864   , h1.RCT_XLA_APPLIED_TO_APP_ID    source_17
22865   , h1.RCT_PAY_FROM_CUSTOMER    source_34
22866   , h5.RCT_SITE_SITE_USE_ID    source_35
22867   , h1.RCT_APP_STATUS    source_36
22868   , h1.RCT_DOC_SEQUENCE_CATEGORY    source_37
22869   , h1.RCT_DOC_SEQUENCE_ID    source_38
22870   , h1.RCT_DOC_SEQUENCE_VALUE    source_39
22871   , h1.RCT_TRX_ACCT_REVERSAL    source_41
22872   FROM xla_events_gt     xet 
22873   , AR_CASH_RECEIPTS_H_V  h1
22874   , AR_RCT_SITE_USES_H_V  h5
22875   , AR_REMIT_BANK_ACCT_H_V  h7
22876   , AR_SYSTEM_PARAM_H_V  h8
22877  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
22878    and xet.event_class_code = C_EVENT_CLASS_CODE
22879    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
22880   AND h5.event_id (+) = h1.event_id
22881   AND h7.event_id (+) = h1.event_id
22882   AND h8.event_id (+) = h1.event_id
22883 
22884  ORDER BY event_id
22885 ;
22886 
22887 
22888 --
22889 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
22890 IS
22891 SELECT  /*+ leading(xet) cardinality(xet,1) */
22892 -- Event Class Code: RECEIPT
22893     xet.entity_id
22894    ,xet.legal_entity_id
22895    ,xet.entity_code
22896    ,xet.transaction_number
22897    ,xet.event_id
22898    ,xet.event_class_code
22902    ,xet.transaction_date
22899    ,xet.event_type_code
22900    ,xet.event_number
22901    ,xet.event_date
22903    ,xet.reference_num_1
22904    ,xet.reference_num_2
22905    ,xet.reference_num_3
22906    ,xet.reference_num_4
22907    ,xet.reference_char_1
22908    ,xet.reference_char_2
22909    ,xet.reference_char_3
22910    ,xet.reference_char_4
22911    ,xet.reference_date_1
22912    ,xet.reference_date_2
22913    ,xet.reference_date_3
22914    ,xet.reference_date_4
22915    ,xet.event_created_by
22916    ,xet.budgetary_control_flag
22917  , l3.LINE_NUMBER  
22918   , l4.DIST_CODE_COMBINATION_ID    source_1
22919   , l2.TRX_LINE_DIST_CCID    source_5
22920   , l4.DIST_REF_DIST_CCID    source_6
22921   , l4.DIST_SOURCE_TYPE    source_7
22922   , l4.DIST_MFAR_ADDITIONAL_ENTRY    source_8
22923   , l4.DIST_LINE_ID    source_9
22924   , l4.DISTRIBUTION_TYPE    source_10
22925   , l4.DIST_ENT_AMT    source_11
22926   , l4.DIST_CURRENCY_CODE    source_12
22927   , l3.DIST_TO_CUR_CONVERSION_DATE    source_13
22928   , l3.DIST_CUR_CONVERSION_RATE    source_14
22929   , l3.DIST_CUR_CONVERSION_TYPE    source_15
22930   , l3.DIST_TO_ACCTD_AMT    source_16
22931   , l2.TRX_DISTRIBUTION_TYPE    source_18
22932   , l9.TRX_ENTITY_CODE    source_19
22933   , l2.TRX_LINE_DIST_ID    source_20
22934   , l9.TRX_CUSTOMER_TRX_ID    source_21
22935   , l4.DIST_ENT_AMT_FROM    source_22
22936   , l4.DIST_CURRENCY_CODE_FROM    source_23
22937   , l3.DIST_CUR_CONVERSION_DATE    source_24
22938   , l3.DIST_ACCTD_AMT    source_25
22939   , l4.DIST_PARTY_ID    source_26
22940   , l4.DIST_PARTY_SITE_ID    source_27
22941   , l4.DIST_PARTY_TYPE    source_28
22942   , l2.TRX_LINE_DIST_ACCOUNT_CLASS    source_29
22943   , l3.DIST_TO_CUR_CONVERSION_RATE    source_30
22944   , l3.DIST_TO_CUR_CONVERSION_TYPE    source_31
22945   , l6.REC_ACT_TYPE    source_32
22946   , l4.DIST_SOURCE_TABLE    source_33
22947   FROM xla_events_gt     xet 
22948   , AR_CUST_TRX_LINES_L_V  l2
22949   , AR_DISTRIBUTIONS_BASE_V  l3
22950   , AR_DISTRIBUTIONS_L_V  l4
22951   , AR_RECEIVABLES_TRX_ACT_S_V  l6
22952   , AR_TRANSACTIONS_S_V  l9
22953  WHERE xet.event_id between x_first_event_id and x_last_event_id
22954    and xet.event_date between p_pad_start_date and p_pad_end_date
22955    and xet.event_class_code = C_EVENT_CLASS_CODE
22956    and xet.event_status_code <> 'N'   AND l3.event_id      = xet.event_id
22957   AND l2.event_id (+)    = l3.event_id
22958   AND l2.line_number (+) = l3.line_number
22959   AND l4.event_id    = l3.event_id
22960   AND l4.line_number = l3.line_number
22961   AND l6.event_id (+)    = l3.event_id
22962   AND l6.line_number (+) = l3.line_number
22963   AND l9.event_id (+)    = l3.event_id
22964   AND l9.line_number (+) = l3.line_number
22965 ;
22966 
22967 --
22968 BEGIN
22969 IF g_log_enabled THEN
22970    l_log_module := C_DEFAULT_MODULE||'.EventClass_41';
22971 END IF;
22972 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
22973    trace
22974       (p_msg      => 'BEGIN of EventClass_41'
22975       ,p_level    => C_LEVEL_PROCEDURE
22976       ,p_module   => l_log_module);
22977 END IF;
22978 
22979 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
22980    trace
22981       (p_msg      => 'p_application_id = '||p_application_id||
22982                      ' - p_base_ledger_id = '||p_base_ledger_id||
22983                      ' - p_target_ledger_id  = '||p_target_ledger_id||
22984                      ' - p_language = '||p_language||
22985                      ' - p_currency_code = '||p_currency_code||
22986                      ' - p_sla_ledger_id = '||p_sla_ledger_id
22987       ,p_level    => C_LEVEL_STATEMENT
22988       ,p_module   => l_log_module);
22989 END IF;
22990 --
22991 -- initialze arrays
22992 --
22993 g_array_event.DELETE;
22994 l_rec_array_event := l_null_rec_array_event;
22995 --
22996 --------------------------------------
22997 -- 4262811 Initialze MPA Line Number
22998 --------------------------------------
22999 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
23000 
23001 --
23002 
23003 --
23004 OPEN header_cur;
23005 --
23006 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
23007    trace
23008    (p_msg      => 'SQL - FETCH header_cur'
23009    ,p_level    => C_LEVEL_STATEMENT
23010    ,p_module   => l_log_module);
23011 END IF;
23012 --
23013 LOOP
23014 FETCH header_cur BULK COLLECT INTO
23015         l_array_entity_id
23016       , l_array_legal_entity_id
23017       , l_array_entity_code
23018       , l_array_transaction_num
23019       , l_array_event_id
23020       , l_array_class_code
23021       , l_array_event_type
23022       , l_array_event_number
23023       , l_array_event_date
23024       , l_array_transaction_date
23025       , l_array_reference_num_1
23026       , l_array_reference_num_2
23027       , l_array_reference_num_3
23028       , l_array_reference_num_4
23029       , l_array_reference_char_1
23030       , l_array_reference_char_2
23031       , l_array_reference_char_3
23032       , l_array_reference_char_4
23033       , l_array_reference_date_1
23034       , l_array_reference_date_2
23035       , l_array_reference_date_3
23036       , l_array_reference_date_4
23037       , l_array_event_created_by
23038       , l_array_budgetary_control_flag 
23039       , l_array_source_2
23040       , l_array_source_3
23041       , l_array_source_4
23042       , l_array_source_17
23046       , l_array_source_37
23043       , l_array_source_34
23044       , l_array_source_35
23045       , l_array_source_36
23047       , l_array_source_38
23048       , l_array_source_39
23049       , l_array_source_41
23050       LIMIT l_rows;
23051 --
23052 IF (C_LEVEL_EVENT >= g_log_level) THEN
23053    trace
23054    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
23055    ,p_level    => C_LEVEL_EVENT
23056    ,p_module   => l_log_module);
23057 END IF;
23058 --
23059 EXIT WHEN l_array_entity_id.COUNT = 0;
23060 
23061 -- initialize arrays
23062 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
23063 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
23064 
23065 --
23066 -- Bug 4458708
23067 --
23068 XLA_AE_LINES_PKG.g_LineNumber := 0;
23069 
23070 
23071 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
23072 g_last_hdr_idx := l_array_event_id.LAST;
23073 --
23074 -- loop for the headers. Each iteration is for each header extract row
23075 -- fetched in header cursor
23076 --
23077 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
23078 
23079 --
23080 -- set event info as cache for other routines to refer event attributes
23081 --
23082 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
23083    (p_application_id           => p_application_id
23084    ,p_primary_ledger_id        => p_primary_ledger_id
23085    ,p_base_ledger_id           => p_base_ledger_id
23086    ,p_target_ledger_id         => p_target_ledger_id
23087    ,p_entity_id                => l_array_entity_id(hdr_idx)
23088    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
23089    ,p_entity_code              => l_array_entity_code(hdr_idx)
23090    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
23091    ,p_event_id                 => l_array_event_id(hdr_idx)
23092    ,p_event_class_code         => l_array_class_code(hdr_idx)
23093    ,p_event_type_code          => l_array_event_type(hdr_idx)
23094    ,p_event_number             => l_array_event_number(hdr_idx)
23095    ,p_event_date               => l_array_event_date(hdr_idx)
23096    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
23097    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
23098    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
23099    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
23100    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
23101    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
23102    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
23103    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
23104    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
23105    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
23106    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
23107    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
23108    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
23109    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
23110    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
23111 
23112 --
23113 -- set the status of entry to C_VALID (0)
23114 --
23115 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
23116 
23117 --
23118 -- initialize a row for ae header
23119 --
23120 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
23121 
23122 l_event_id := l_array_event_id(hdr_idx);
23123 
23124 --
23125 -- storing the hdr_idx for event. May be used by line cursor.
23126 --
23127 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
23128 
23129 --
23130 -- store sources from header extract. This can be improved to
23131 -- store only those sources from header extract that may be used in lines
23132 --
23133 
23134 g_array_event(l_event_id).array_value_num('source_2') := l_array_source_2(hdr_idx);
23135 g_array_event(l_event_id).array_value_num('source_3') := l_array_source_3(hdr_idx);
23136 g_array_event(l_event_id).array_value_num('source_4') := l_array_source_4(hdr_idx);
23137 g_array_event(l_event_id).array_value_num('source_17') := l_array_source_17(hdr_idx);
23138 g_array_event(l_event_id).array_value_num('source_34') := l_array_source_34(hdr_idx);
23139 g_array_event(l_event_id).array_value_num('source_35') := l_array_source_35(hdr_idx);
23140 g_array_event(l_event_id).array_value_char('source_36') := l_array_source_36(hdr_idx);
23141 g_array_event(l_event_id).array_value_char('source_37') := l_array_source_37(hdr_idx);
23142 g_array_event(l_event_id).array_value_num('source_38') := l_array_source_38(hdr_idx);
23143 g_array_event(l_event_id).array_value_num('source_39') := l_array_source_39(hdr_idx);
23144 g_array_event(l_event_id).array_value_char('source_41') := l_array_source_41(hdr_idx);
23145 
23146 --
23147 -- initilaize the status of ae headers for diffrent balance types
23148 -- the status is initialised to C_NOT_CREATED (2)
23149 --
23150 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
23151 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
23152 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
23153 
23154 --
23155 -- call api to validate and store accounting attributes for header
23156 --
23157 
23158 ------------------------------------------------------------
23159 -- Accrual Reversal : to get date for Standard Source (NONE)
23160 ------------------------------------------------------------
23161 l_acc_rev_gl_date_source := NULL;
23162 
23163      l_rec_acct_attrs.array_acct_attr_code(1)   := 'DOC_CATEGORY_CODE';
23164       l_rec_acct_attrs.array_char_value(1) := g_array_event(l_event_id).array_value_char('source_37');
23165      l_rec_acct_attrs.array_acct_attr_code(2)   := 'DOC_SEQUENCE_ID';
23166       l_rec_acct_attrs.array_num_value(2) := g_array_event(l_event_id).array_value_num('source_38');
23167      l_rec_acct_attrs.array_acct_attr_code(3)   := 'DOC_SEQUENCE_VALUE';
23168       l_rec_acct_attrs.array_num_value(3) := g_array_event(l_event_id).array_value_num('source_39');
23169      l_rec_acct_attrs.array_acct_attr_code(4)   := 'GL_DATE';
23170       l_rec_acct_attrs.array_date_value(4) := 
23171 xla_ae_sources_pkg.GetSystemSourceDate(
23172    p_source_code           => 'XLA_EVENT_DATE'
23173  , p_source_type_code      => 'Y'
23174  , p_source_application_id =>  602
23175 );
23176      l_rec_acct_attrs.array_acct_attr_code(5)   := 'TRX_ACCT_REVERSAL_OPTION';
23177       l_rec_acct_attrs.array_char_value(5) := g_array_event(l_event_id).array_value_char('source_41');
23178 
23179 
23180 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
23181 
23182 XLA_AE_HEADER_PKG.SetJeCategoryName;
23183 
23184 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
23185 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
23186 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
23187 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
23188 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
23189 
23190 
23191 -- No header level analytical criteria
23192 
23193 --
23194 --accounting attribute enhancement, bug 3612931
23195 --
23196 l_trx_reversal_source := SUBSTR(g_array_event(l_event_id).array_value_char('source_41'), 1,30);
23197 
23198 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
23199    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
23200 
23201    xla_accounting_err_pkg.build_message
23202       (p_appli_s_name            => 'XLA'
23203       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
23204       ,p_token_1                 => 'ACCT_ATTR_NAME'
23205       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
23206       ,p_token_2                 => 'PRODUCT_NAME'
23207       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
23208       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
23209       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
23210       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
23211 
23212 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
23213    --
23214    -- following sets the accounting attributes needed to reverse
23215    -- accounting for a distributeion
23216    --
23217    xla_ae_lines_pkg.SetTrxReversalAttrs
23218       (p_event_id              => l_event_id
23219       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
23220       ,p_trx_reversal_source   => l_trx_reversal_source);
23221 
23222 END IF;
23223 
23224 
23225 ----------------------------------------------------------------
23226 -- 4262811 -  update the header statuses to invalid in need be
23227 ----------------------------------------------------------------
23228 --
23229 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
23230 
23231 
23235 ----------------------------------------------------------------
23232   -----------------------------------------------
23233   -- No accrual reversal for the event class/type
23234   -----------------------------------------------
23236 
23237 --
23238 -- this ends the header loop iteration for one bulk fetch
23239 --
23240 END LOOP;
23241 
23242 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
23243 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
23244 
23245 --
23246 -- insert dummy rows into lines gt table that were created due to
23247 -- transaction reversals
23248 --
23249 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
23250    l_result := XLA_AE_LINES_PKG.InsertLines;
23251 END IF;
23252 
23253 --
23254 -- reset the temp_line_num for each set of events fetched from header
23255 -- cursor rather than doing it for each new event in line cursor
23256 -- Bug 3939231
23257 --
23258 xla_ae_lines_pkg.g_temp_line_num := 0;
23259 
23260 
23261 
23262 --
23263 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
23264 --
23265 --
23266 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
23267 
23268       trace
23269          (p_msg      => 'SQL - FETCH line_cur'
23270          ,p_level    => C_LEVEL_STATEMENT
23271          ,p_module   => l_log_module);
23272 
23273 END IF;
23274 --
23275 --
23276 LOOP
23277   --
23278   FETCH line_cur BULK COLLECT INTO
23279         l_array_entity_id
23280       , l_array_legal_entity_id
23281       , l_array_entity_code
23282       , l_array_transaction_num
23283       , l_array_event_id
23284       , l_array_class_code
23285       , l_array_event_type
23286       , l_array_event_number
23287       , l_array_event_date
23288       , l_array_transaction_date
23289       , l_array_reference_num_1
23290       , l_array_reference_num_2
23291       , l_array_reference_num_3
23292       , l_array_reference_num_4
23293       , l_array_reference_char_1
23294       , l_array_reference_char_2
23295       , l_array_reference_char_3
23296       , l_array_reference_char_4
23297       , l_array_reference_date_1
23298       , l_array_reference_date_2
23299       , l_array_reference_date_3
23300       , l_array_reference_date_4
23301       , l_array_event_created_by
23302       , l_array_budgetary_control_flag
23303       , l_array_extract_line_num 
23304       , l_array_source_1
23305       , l_array_source_5
23306       , l_array_source_6
23307       , l_array_source_7
23308       , l_array_source_8
23309       , l_array_source_9
23310       , l_array_source_10
23311       , l_array_source_11
23312       , l_array_source_12
23313       , l_array_source_13
23314       , l_array_source_14
23315       , l_array_source_15
23316       , l_array_source_16
23317       , l_array_source_18
23318       , l_array_source_19
23319       , l_array_source_20
23320       , l_array_source_21
23321       , l_array_source_22
23322       , l_array_source_23
23323       , l_array_source_24
23324       , l_array_source_25
23325       , l_array_source_26
23326       , l_array_source_27
23327       , l_array_source_28
23328       , l_array_source_29
23329       , l_array_source_30
23330       , l_array_source_31
23331       , l_array_source_32
23332       , l_array_source_33
23333       LIMIT l_rows;
23334 
23335   --
23336   IF (C_LEVEL_EVENT >= g_log_level) THEN
23337             trace
23338                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
23339                ,p_level    => C_LEVEL_EVENT
23340                ,p_module   => l_log_module);
23341   END IF;
23342   --
23343   EXIT WHEN l_array_entity_id.count = 0;
23344 
23345   XLA_AE_LINES_PKG.g_rec_lines := null;
23346 
23347 --
23348 -- Bug 4458708
23349 --
23350 XLA_AE_LINES_PKG.g_LineNumber := 0;
23351 --
23352 --
23353 
23354 FOR Idx IN 1..l_array_event_id.count LOOP
23355    --
23356    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
23357    --
23358    l_event_id := l_array_event_id(idx);  -- 5648433
23359 
23360    --
23361    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
23362    --
23363 
23364    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
23365              (g_array_event(l_event_id).array_value_num('header_index'))
23366          ,'N'
23367          ) <> 'Y'
23368    THEN
23369       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
23370          trace
23371             (p_msg      => 'Trancaction revesal option is not Y '
23372             ,p_level    => C_LEVEL_STATEMENT
23373             ,p_module   => l_log_module);
23374       END IF;
23375 
23376 --
23377 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
23378 --
23379 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
23380 --
23381 -- set event info as cache for other routines to refer event attributes
23382 --
23383 
23384 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
23385    l_previous_event_id := l_event_id;
23386 
23387    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
23388       (p_application_id           => p_application_id
23389       ,p_primary_ledger_id        => p_primary_ledger_id
23390       ,p_base_ledger_id           => p_base_ledger_id
23391       ,p_target_ledger_id         => p_target_ledger_id
23392       ,p_entity_id                => l_array_entity_id(Idx)
23393       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
23394       ,p_entity_code              => l_array_entity_code(Idx)
23398       ,p_event_type_code          => l_array_event_type(Idx)
23395       ,p_transaction_num          => l_array_transaction_num(Idx)
23396       ,p_event_id                 => l_array_event_id(Idx)
23397       ,p_event_class_code         => l_array_class_code(Idx)
23399       ,p_event_number             => l_array_event_number(Idx)
23400       ,p_event_date               => l_array_event_date(Idx)
23401       ,p_transaction_date         => l_array_transaction_date(Idx)
23402       ,p_reference_num_1          => l_array_reference_num_1(Idx)
23403       ,p_reference_num_2          => l_array_reference_num_2(Idx)
23404       ,p_reference_num_3          => l_array_reference_num_3(Idx)
23405       ,p_reference_num_4          => l_array_reference_num_4(Idx)
23406       ,p_reference_char_1         => l_array_reference_char_1(Idx)
23407       ,p_reference_char_2         => l_array_reference_char_2(Idx)
23408       ,p_reference_char_3         => l_array_reference_char_3(Idx)
23409       ,p_reference_char_4         => l_array_reference_char_4(Idx)
23410       ,p_reference_date_1         => l_array_reference_date_1(Idx)
23411       ,p_reference_date_2         => l_array_reference_date_2(Idx)
23412       ,p_reference_date_3         => l_array_reference_date_3(Idx)
23413       ,p_reference_date_4         => l_array_reference_date_4(Idx)
23414       ,p_event_created_by         => l_array_event_created_by(Idx)
23415       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
23416        --
23417 END IF;
23418 
23419 
23420 
23421 --
23422 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
23423 
23424 l_acct_reversal_source := SUBSTR(NULL, 1,30);
23425 
23426 IF l_continue_with_lines THEN
23427    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
23428       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
23429 
23430       xla_accounting_err_pkg.build_message
23431          (p_appli_s_name            => 'XLA'
23432          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
23433          ,p_token_1                 => 'LINE_NUMBER'
23434          ,p_value_1                 => l_array_extract_line_num(Idx)
23435          ,p_token_2                 => 'PRODUCT_NAME'
23436          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
23437          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
23438          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
23439          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
23440 
23441    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
23442       --
23443       -- following sets the accounting attributes needed to reverse
23444       -- accounting for a distributeion
23445       --
23446 
23447       --
23448       -- 5217187
23449       --
23450       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
23451       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
23452                                        g_array_event(l_event_id).array_value_num('header_index'));
23453       --
23454       --
23455 
23456       -- No reversal code generated
23457 
23458       xla_ae_lines_pkg.SetAcctReversalAttrs
23459          (p_event_id             => l_event_id
23460          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
23461          ,p_calculate_acctd_flag => l_calculate_acctd_flag
23462          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
23463    END IF;
23464 
23465    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
23466        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
23467 
23468 --
23469 AcctLineType_14 (
23470  p_application_id  => p_application_id
23471  ,p_event_id     => l_event_id
23472  ,p_calculate_acctd_flag => l_calculate_acctd_flag
23473  ,p_calculate_g_l_flag => l_calculate_g_l_flag
23474  ,p_actual_flag => l_actual_flag
23475  ,p_balance_type_code => l_balance_type_code
23476  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
23477  
23478  , p_source_1 => l_array_source_1(Idx)
23479  , p_source_7 => l_array_source_7(Idx)
23480  , p_source_8 => l_array_source_8(Idx)
23481  , p_source_9 => l_array_source_9(Idx)
23482  , p_source_10 => l_array_source_10(Idx)
23483  , p_source_14 => l_array_source_14(Idx)
23484  , p_source_15 => l_array_source_15(Idx)
23485  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
23486  , p_source_18 => l_array_source_18(Idx)
23487  , p_source_19 => l_array_source_19(Idx)
23488  , p_source_20 => l_array_source_20(Idx)
23489  , p_source_21 => l_array_source_21(Idx)
23490  , p_source_22 => l_array_source_22(Idx)
23491  , p_source_23 => l_array_source_23(Idx)
23492  , p_source_24 => l_array_source_24(Idx)
23493  , p_source_25 => l_array_source_25(Idx)
23494  , p_source_26 => l_array_source_26(Idx)
23495  , p_source_27 => l_array_source_27(Idx)
23496  , p_source_28 => l_array_source_28(Idx)
23497  );
23498 If(l_balance_type_code = 'A') THEN
23499   l_actual_gain_loss_ref := l_gain_or_loss_ref;
23500 END IF;
23501 
23502 --
23503 
23504 
23505 --
23506 AcctLineType_15 (
23507  p_application_id  => p_application_id
23508  ,p_event_id     => l_event_id
23509  ,p_calculate_acctd_flag => l_calculate_acctd_flag
23510  ,p_calculate_g_l_flag => l_calculate_g_l_flag
23511  ,p_actual_flag => l_actual_flag
23512  ,p_balance_type_code => l_balance_type_code
23513  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
23514  
23515  , p_source_5 => l_array_source_5(Idx)
23516  , p_source_6 => l_array_source_6(Idx)
23517  , p_source_7 => l_array_source_7(Idx)
23518  , p_source_9 => l_array_source_9(Idx)
23519  , p_source_10 => l_array_source_10(Idx)
23520  , p_source_11 => l_array_source_11(Idx)
23521  , p_source_12 => l_array_source_12(Idx)
23522  , p_source_13 => l_array_source_13(Idx)
23526  , p_source_19 => l_array_source_19(Idx)
23523  , p_source_16 => l_array_source_16(Idx)
23524  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
23525  , p_source_18 => l_array_source_18(Idx)
23527  , p_source_20 => l_array_source_20(Idx)
23528  , p_source_21 => l_array_source_21(Idx)
23529  , p_source_26 => l_array_source_26(Idx)
23530  , p_source_27 => l_array_source_27(Idx)
23531  , p_source_28 => l_array_source_28(Idx)
23532  , p_source_29 => l_array_source_29(Idx)
23533  , p_source_30 => l_array_source_30(Idx)
23534  , p_source_31 => l_array_source_31(Idx)
23535  );
23536 If(l_balance_type_code = 'A') THEN
23537   l_actual_gain_loss_ref := l_gain_or_loss_ref;
23538 END IF;
23539 
23540 --
23541 
23542 
23543 --
23544 AcctLineType_16 (
23545  p_application_id  => p_application_id
23546  ,p_event_id     => l_event_id
23547  ,p_calculate_acctd_flag => l_calculate_acctd_flag
23548  ,p_calculate_g_l_flag => l_calculate_g_l_flag
23549  ,p_actual_flag => l_actual_flag
23550  ,p_balance_type_code => l_balance_type_code
23551  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
23552  
23553  , p_source_5 => l_array_source_5(Idx)
23554  , p_source_6 => l_array_source_6(Idx)
23555  , p_source_7 => l_array_source_7(Idx)
23556  , p_source_9 => l_array_source_9(Idx)
23557  , p_source_10 => l_array_source_10(Idx)
23558  , p_source_11 => l_array_source_11(Idx)
23559  , p_source_12 => l_array_source_12(Idx)
23560  , p_source_13 => l_array_source_13(Idx)
23561  , p_source_16 => l_array_source_16(Idx)
23562  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
23563  , p_source_18 => l_array_source_18(Idx)
23564  , p_source_19 => l_array_source_19(Idx)
23565  , p_source_20 => l_array_source_20(Idx)
23566  , p_source_21 => l_array_source_21(Idx)
23567  , p_source_26 => l_array_source_26(Idx)
23568  , p_source_27 => l_array_source_27(Idx)
23569  , p_source_28 => l_array_source_28(Idx)
23570  , p_source_29 => l_array_source_29(Idx)
23571  , p_source_30 => l_array_source_30(Idx)
23572  , p_source_31 => l_array_source_31(Idx)
23573  );
23574 If(l_balance_type_code = 'A') THEN
23575   l_actual_gain_loss_ref := l_gain_or_loss_ref;
23576 END IF;
23577 
23578 --
23579 
23580 
23581 --
23582 AcctLineType_17 (
23583  p_application_id  => p_application_id
23584  ,p_event_id     => l_event_id
23585  ,p_calculate_acctd_flag => l_calculate_acctd_flag
23586  ,p_calculate_g_l_flag => l_calculate_g_l_flag
23587  ,p_actual_flag => l_actual_flag
23588  ,p_balance_type_code => l_balance_type_code
23589  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
23590  
23591  , p_source_5 => l_array_source_5(Idx)
23592  , p_source_6 => l_array_source_6(Idx)
23593  , p_source_7 => l_array_source_7(Idx)
23594  , p_source_9 => l_array_source_9(Idx)
23595  , p_source_10 => l_array_source_10(Idx)
23596  , p_source_11 => l_array_source_11(Idx)
23597  , p_source_12 => l_array_source_12(Idx)
23598  , p_source_13 => l_array_source_13(Idx)
23599  , p_source_16 => l_array_source_16(Idx)
23600  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
23601  , p_source_18 => l_array_source_18(Idx)
23602  , p_source_19 => l_array_source_19(Idx)
23603  , p_source_20 => l_array_source_20(Idx)
23604  , p_source_21 => l_array_source_21(Idx)
23605  , p_source_26 => l_array_source_26(Idx)
23606  , p_source_27 => l_array_source_27(Idx)
23607  , p_source_28 => l_array_source_28(Idx)
23608  , p_source_29 => l_array_source_29(Idx)
23609  , p_source_30 => l_array_source_30(Idx)
23610  , p_source_31 => l_array_source_31(Idx)
23611  );
23612 If(l_balance_type_code = 'A') THEN
23613   l_actual_gain_loss_ref := l_gain_or_loss_ref;
23614 END IF;
23615 
23616 --
23617 
23618 
23619 --
23620 AcctLineType_18 (
23621  p_application_id  => p_application_id
23622  ,p_event_id     => l_event_id
23623  ,p_calculate_acctd_flag => l_calculate_acctd_flag
23624  ,p_calculate_g_l_flag => l_calculate_g_l_flag
23625  ,p_actual_flag => l_actual_flag
23626  ,p_balance_type_code => l_balance_type_code
23627  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
23628  
23629  , p_source_5 => l_array_source_5(Idx)
23630  , p_source_6 => l_array_source_6(Idx)
23631  , p_source_7 => l_array_source_7(Idx)
23632  , p_source_9 => l_array_source_9(Idx)
23633  , p_source_10 => l_array_source_10(Idx)
23634  , p_source_11 => l_array_source_11(Idx)
23635  , p_source_12 => l_array_source_12(Idx)
23636  , p_source_13 => l_array_source_13(Idx)
23637  , p_source_16 => l_array_source_16(Idx)
23638  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
23639  , p_source_18 => l_array_source_18(Idx)
23640  , p_source_19 => l_array_source_19(Idx)
23641  , p_source_20 => l_array_source_20(Idx)
23642  , p_source_21 => l_array_source_21(Idx)
23643  , p_source_26 => l_array_source_26(Idx)
23644  , p_source_27 => l_array_source_27(Idx)
23645  , p_source_28 => l_array_source_28(Idx)
23646  , p_source_29 => l_array_source_29(Idx)
23647  , p_source_30 => l_array_source_30(Idx)
23648  , p_source_31 => l_array_source_31(Idx)
23649  );
23650 If(l_balance_type_code = 'A') THEN
23651   l_actual_gain_loss_ref := l_gain_or_loss_ref;
23652 END IF;
23653 
23654 --
23655 
23656 
23657 --
23658 AcctLineType_19 (
23659  p_application_id  => p_application_id
23660  ,p_event_id     => l_event_id
23661  ,p_calculate_acctd_flag => l_calculate_acctd_flag
23662  ,p_calculate_g_l_flag => l_calculate_g_l_flag
23663  ,p_actual_flag => l_actual_flag
23664  ,p_balance_type_code => l_balance_type_code
23665  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
23666  
23667  , p_source_5 => l_array_source_5(Idx)
23668  , p_source_6 => l_array_source_6(Idx)
23669  , p_source_7 => l_array_source_7(Idx)
23670  , p_source_9 => l_array_source_9(Idx)
23671  , p_source_10 => l_array_source_10(Idx)
23675  , p_source_16 => l_array_source_16(Idx)
23672  , p_source_11 => l_array_source_11(Idx)
23673  , p_source_12 => l_array_source_12(Idx)
23674  , p_source_13 => l_array_source_13(Idx)
23676  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
23677  , p_source_18 => l_array_source_18(Idx)
23678  , p_source_19 => l_array_source_19(Idx)
23679  , p_source_20 => l_array_source_20(Idx)
23680  , p_source_21 => l_array_source_21(Idx)
23681  , p_source_26 => l_array_source_26(Idx)
23682  , p_source_27 => l_array_source_27(Idx)
23683  , p_source_28 => l_array_source_28(Idx)
23684  , p_source_29 => l_array_source_29(Idx)
23685  , p_source_30 => l_array_source_30(Idx)
23686  , p_source_31 => l_array_source_31(Idx)
23687  );
23688 If(l_balance_type_code = 'A') THEN
23689   l_actual_gain_loss_ref := l_gain_or_loss_ref;
23690 END IF;
23691 
23692 --
23693 
23694 
23695 --
23696 AcctLineType_20 (
23697  p_application_id  => p_application_id
23698  ,p_event_id     => l_event_id
23699  ,p_calculate_acctd_flag => l_calculate_acctd_flag
23700  ,p_calculate_g_l_flag => l_calculate_g_l_flag
23701  ,p_actual_flag => l_actual_flag
23702  ,p_balance_type_code => l_balance_type_code
23703  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
23704  
23705  , p_source_5 => l_array_source_5(Idx)
23706  , p_source_6 => l_array_source_6(Idx)
23707  , p_source_7 => l_array_source_7(Idx)
23708  , p_source_9 => l_array_source_9(Idx)
23709  , p_source_10 => l_array_source_10(Idx)
23710  , p_source_11 => l_array_source_11(Idx)
23711  , p_source_12 => l_array_source_12(Idx)
23712  , p_source_13 => l_array_source_13(Idx)
23713  , p_source_16 => l_array_source_16(Idx)
23714  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
23715  , p_source_18 => l_array_source_18(Idx)
23716  , p_source_19 => l_array_source_19(Idx)
23717  , p_source_20 => l_array_source_20(Idx)
23718  , p_source_21 => l_array_source_21(Idx)
23719  , p_source_26 => l_array_source_26(Idx)
23720  , p_source_27 => l_array_source_27(Idx)
23721  , p_source_28 => l_array_source_28(Idx)
23722  , p_source_29 => l_array_source_29(Idx)
23723  , p_source_30 => l_array_source_30(Idx)
23724  , p_source_31 => l_array_source_31(Idx)
23725  );
23726 If(l_balance_type_code = 'A') THEN
23727   l_actual_gain_loss_ref := l_gain_or_loss_ref;
23728 END IF;
23729 
23730 --
23731 
23732 
23733 --
23734 AcctLineType_21 (
23735  p_application_id  => p_application_id
23736  ,p_event_id     => l_event_id
23737  ,p_calculate_acctd_flag => l_calculate_acctd_flag
23738  ,p_calculate_g_l_flag => l_calculate_g_l_flag
23739  ,p_actual_flag => l_actual_flag
23740  ,p_balance_type_code => l_balance_type_code
23741  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
23742  
23743  , p_source_5 => l_array_source_5(Idx)
23744  , p_source_6 => l_array_source_6(Idx)
23745  , p_source_7 => l_array_source_7(Idx)
23746  , p_source_9 => l_array_source_9(Idx)
23747  , p_source_10 => l_array_source_10(Idx)
23748  , p_source_11 => l_array_source_11(Idx)
23749  , p_source_12 => l_array_source_12(Idx)
23750  , p_source_13 => l_array_source_13(Idx)
23751  , p_source_16 => l_array_source_16(Idx)
23752  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
23753  , p_source_18 => l_array_source_18(Idx)
23754  , p_source_19 => l_array_source_19(Idx)
23755  , p_source_20 => l_array_source_20(Idx)
23756  , p_source_21 => l_array_source_21(Idx)
23757  , p_source_26 => l_array_source_26(Idx)
23758  , p_source_27 => l_array_source_27(Idx)
23759  , p_source_28 => l_array_source_28(Idx)
23760  , p_source_29 => l_array_source_29(Idx)
23761  , p_source_30 => l_array_source_30(Idx)
23762  , p_source_31 => l_array_source_31(Idx)
23763  );
23764 If(l_balance_type_code = 'A') THEN
23765   l_actual_gain_loss_ref := l_gain_or_loss_ref;
23766 END IF;
23767 
23768 --
23769 
23770 
23771 --
23772 AcctLineType_22 (
23773  p_application_id  => p_application_id
23774  ,p_event_id     => l_event_id
23775  ,p_calculate_acctd_flag => l_calculate_acctd_flag
23776  ,p_calculate_g_l_flag => l_calculate_g_l_flag
23777  ,p_actual_flag => l_actual_flag
23778  ,p_balance_type_code => l_balance_type_code
23779  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
23780  
23781  , p_source_1 => l_array_source_1(Idx)
23782  , p_source_7 => l_array_source_7(Idx)
23783  , p_source_8 => l_array_source_8(Idx)
23784  , p_source_9 => l_array_source_9(Idx)
23785  , p_source_10 => l_array_source_10(Idx)
23786  , p_source_14 => l_array_source_14(Idx)
23787  , p_source_15 => l_array_source_15(Idx)
23788  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
23789  , p_source_18 => l_array_source_18(Idx)
23790  , p_source_19 => l_array_source_19(Idx)
23791  , p_source_20 => l_array_source_20(Idx)
23792  , p_source_21 => l_array_source_21(Idx)
23793  , p_source_22 => l_array_source_22(Idx)
23794  , p_source_23 => l_array_source_23(Idx)
23795  , p_source_24 => l_array_source_24(Idx)
23796  , p_source_25 => l_array_source_25(Idx)
23797  , p_source_26 => l_array_source_26(Idx)
23798  , p_source_27 => l_array_source_27(Idx)
23799  , p_source_28 => l_array_source_28(Idx)
23800  );
23801 If(l_balance_type_code = 'A') THEN
23802   l_actual_gain_loss_ref := l_gain_or_loss_ref;
23803 END IF;
23804 
23805 --
23806 
23807 
23808 --
23809 AcctLineType_23 (
23810  p_application_id  => p_application_id
23811  ,p_event_id     => l_event_id
23812  ,p_calculate_acctd_flag => l_calculate_acctd_flag
23813  ,p_calculate_g_l_flag => l_calculate_g_l_flag
23814  ,p_actual_flag => l_actual_flag
23815  ,p_balance_type_code => l_balance_type_code
23816  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
23817  
23818  , p_source_1 => l_array_source_1(Idx)
23819  , p_source_7 => l_array_source_7(Idx)
23820  , p_source_8 => l_array_source_8(Idx)
23824  , p_source_15 => l_array_source_15(Idx)
23821  , p_source_9 => l_array_source_9(Idx)
23822  , p_source_10 => l_array_source_10(Idx)
23823  , p_source_14 => l_array_source_14(Idx)
23825  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
23826  , p_source_18 => l_array_source_18(Idx)
23827  , p_source_19 => l_array_source_19(Idx)
23828  , p_source_20 => l_array_source_20(Idx)
23829  , p_source_21 => l_array_source_21(Idx)
23830  , p_source_22 => l_array_source_22(Idx)
23831  , p_source_23 => l_array_source_23(Idx)
23832  , p_source_24 => l_array_source_24(Idx)
23833  , p_source_25 => l_array_source_25(Idx)
23834  , p_source_26 => l_array_source_26(Idx)
23835  , p_source_27 => l_array_source_27(Idx)
23836  , p_source_28 => l_array_source_28(Idx)
23837  );
23838 If(l_balance_type_code = 'A') THEN
23839   l_actual_gain_loss_ref := l_gain_or_loss_ref;
23840 END IF;
23841 
23842 --
23843 
23844 
23845 --
23846 AcctLineType_24 (
23847  p_application_id  => p_application_id
23848  ,p_event_id     => l_event_id
23849  ,p_calculate_acctd_flag => l_calculate_acctd_flag
23850  ,p_calculate_g_l_flag => l_calculate_g_l_flag
23851  ,p_actual_flag => l_actual_flag
23852  ,p_balance_type_code => l_balance_type_code
23853  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
23854  
23855  , p_source_1 => l_array_source_1(Idx)
23856  , p_source_7 => l_array_source_7(Idx)
23857  , p_source_8 => l_array_source_8(Idx)
23858  , p_source_9 => l_array_source_9(Idx)
23859  , p_source_10 => l_array_source_10(Idx)
23860  , p_source_14 => l_array_source_14(Idx)
23861  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
23862  , p_source_18 => l_array_source_18(Idx)
23863  , p_source_19 => l_array_source_19(Idx)
23864  , p_source_20 => l_array_source_20(Idx)
23865  , p_source_21 => l_array_source_21(Idx)
23866  , p_source_22 => l_array_source_22(Idx)
23867  , p_source_23 => l_array_source_23(Idx)
23868  , p_source_24 => l_array_source_24(Idx)
23869  , p_source_25 => l_array_source_25(Idx)
23870  , p_source_26 => l_array_source_26(Idx)
23871  , p_source_27 => l_array_source_27(Idx)
23872  , p_source_28 => l_array_source_28(Idx)
23873  , p_source_31 => l_array_source_31(Idx)
23874  , p_source_32 => l_array_source_32(Idx)
23875  );
23876 If(l_balance_type_code = 'A') THEN
23877   l_actual_gain_loss_ref := l_gain_or_loss_ref;
23878 END IF;
23879 
23880 --
23881 
23882 
23883 --
23884 AcctLineType_25 (
23885  p_application_id  => p_application_id
23886  ,p_event_id     => l_event_id
23887  ,p_calculate_acctd_flag => l_calculate_acctd_flag
23888  ,p_calculate_g_l_flag => l_calculate_g_l_flag
23889  ,p_actual_flag => l_actual_flag
23890  ,p_balance_type_code => l_balance_type_code
23891  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
23892  
23893  , p_source_1 => l_array_source_1(Idx)
23894  , p_source_7 => l_array_source_7(Idx)
23895  , p_source_8 => l_array_source_8(Idx)
23896  , p_source_9 => l_array_source_9(Idx)
23897  , p_source_10 => l_array_source_10(Idx)
23898  , p_source_14 => l_array_source_14(Idx)
23899  , p_source_15 => l_array_source_15(Idx)
23900  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
23901  , p_source_18 => l_array_source_18(Idx)
23902  , p_source_19 => l_array_source_19(Idx)
23903  , p_source_20 => l_array_source_20(Idx)
23904  , p_source_21 => l_array_source_21(Idx)
23905  , p_source_22 => l_array_source_22(Idx)
23906  , p_source_23 => l_array_source_23(Idx)
23907  , p_source_24 => l_array_source_24(Idx)
23908  , p_source_25 => l_array_source_25(Idx)
23909  , p_source_26 => l_array_source_26(Idx)
23910  , p_source_27 => l_array_source_27(Idx)
23911  , p_source_28 => l_array_source_28(Idx)
23912  );
23913 If(l_balance_type_code = 'A') THEN
23914   l_actual_gain_loss_ref := l_gain_or_loss_ref;
23915 END IF;
23916 
23917 --
23918 
23919 
23920 --
23921 AcctLineType_26 (
23922  p_application_id  => p_application_id
23923  ,p_event_id     => l_event_id
23924  ,p_calculate_acctd_flag => l_calculate_acctd_flag
23925  ,p_calculate_g_l_flag => l_calculate_g_l_flag
23926  ,p_actual_flag => l_actual_flag
23927  ,p_balance_type_code => l_balance_type_code
23928  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
23929  
23930  , p_source_1 => l_array_source_1(Idx)
23931  , p_source_7 => l_array_source_7(Idx)
23932  , p_source_8 => l_array_source_8(Idx)
23933  , p_source_9 => l_array_source_9(Idx)
23934  , p_source_10 => l_array_source_10(Idx)
23935  , p_source_14 => l_array_source_14(Idx)
23936  , p_source_15 => l_array_source_15(Idx)
23937  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
23938  , p_source_18 => l_array_source_18(Idx)
23939  , p_source_19 => l_array_source_19(Idx)
23940  , p_source_20 => l_array_source_20(Idx)
23941  , p_source_21 => l_array_source_21(Idx)
23942  , p_source_22 => l_array_source_22(Idx)
23943  , p_source_23 => l_array_source_23(Idx)
23944  , p_source_24 => l_array_source_24(Idx)
23945  , p_source_25 => l_array_source_25(Idx)
23946  , p_source_26 => l_array_source_26(Idx)
23947  , p_source_27 => l_array_source_27(Idx)
23948  , p_source_28 => l_array_source_28(Idx)
23949  );
23950 If(l_balance_type_code = 'A') THEN
23951   l_actual_gain_loss_ref := l_gain_or_loss_ref;
23952 END IF;
23953 
23954 --
23955 
23956 
23957 --
23958 AcctLineType_27 (
23959  p_application_id  => p_application_id
23960  ,p_event_id     => l_event_id
23961  ,p_calculate_acctd_flag => l_calculate_acctd_flag
23962  ,p_calculate_g_l_flag => l_calculate_g_l_flag
23963  ,p_actual_flag => l_actual_flag
23964  ,p_balance_type_code => l_balance_type_code
23965  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
23966  
23967  , p_source_1 => l_array_source_1(Idx)
23968  , p_source_7 => l_array_source_7(Idx)
23969  , p_source_8 => l_array_source_8(Idx)
23973  , p_source_15 => l_array_source_15(Idx)
23970  , p_source_9 => l_array_source_9(Idx)
23971  , p_source_10 => l_array_source_10(Idx)
23972  , p_source_14 => l_array_source_14(Idx)
23974  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
23975  , p_source_18 => l_array_source_18(Idx)
23976  , p_source_19 => l_array_source_19(Idx)
23977  , p_source_20 => l_array_source_20(Idx)
23978  , p_source_21 => l_array_source_21(Idx)
23979  , p_source_22 => l_array_source_22(Idx)
23980  , p_source_23 => l_array_source_23(Idx)
23981  , p_source_24 => l_array_source_24(Idx)
23982  , p_source_25 => l_array_source_25(Idx)
23983  , p_source_26 => l_array_source_26(Idx)
23984  , p_source_27 => l_array_source_27(Idx)
23985  , p_source_28 => l_array_source_28(Idx)
23986  );
23987 If(l_balance_type_code = 'A') THEN
23988   l_actual_gain_loss_ref := l_gain_or_loss_ref;
23989 END IF;
23990 
23991 --
23992 
23993 
23994 --
23995 AcctLineType_28 (
23996  p_application_id  => p_application_id
23997  ,p_event_id     => l_event_id
23998  ,p_calculate_acctd_flag => l_calculate_acctd_flag
23999  ,p_calculate_g_l_flag => l_calculate_g_l_flag
24000  ,p_actual_flag => l_actual_flag
24001  ,p_balance_type_code => l_balance_type_code
24002  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
24003  
24004  , p_source_3 => g_array_event(l_event_id).array_value_num('source_3')
24005  , p_source_4 => g_array_event(l_event_id).array_value_num('source_4')
24006  , p_source_9 => l_array_source_9(Idx)
24007  , p_source_10 => l_array_source_10(Idx)
24008  , p_source_25 => l_array_source_25(Idx)
24009  , p_source_26 => l_array_source_26(Idx)
24010  , p_source_27 => l_array_source_27(Idx)
24011  , p_source_28 => l_array_source_28(Idx)
24012  );
24013 If(l_balance_type_code = 'A') THEN
24014   l_actual_gain_loss_ref := l_gain_or_loss_ref;
24015 END IF;
24016 
24017 --
24018 
24019 
24020 --
24021 AcctLineType_29 (
24022  p_application_id  => p_application_id
24023  ,p_event_id     => l_event_id
24024  ,p_calculate_acctd_flag => l_calculate_acctd_flag
24025  ,p_calculate_g_l_flag => l_calculate_g_l_flag
24026  ,p_actual_flag => l_actual_flag
24027  ,p_balance_type_code => l_balance_type_code
24028  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
24029  
24030  , p_source_1 => l_array_source_1(Idx)
24031  , p_source_7 => l_array_source_7(Idx)
24032  , p_source_8 => l_array_source_8(Idx)
24033  , p_source_9 => l_array_source_9(Idx)
24034  , p_source_10 => l_array_source_10(Idx)
24035  , p_source_14 => l_array_source_14(Idx)
24036  , p_source_15 => l_array_source_15(Idx)
24037  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
24038  , p_source_18 => l_array_source_18(Idx)
24039  , p_source_19 => l_array_source_19(Idx)
24040  , p_source_20 => l_array_source_20(Idx)
24041  , p_source_21 => l_array_source_21(Idx)
24042  , p_source_22 => l_array_source_22(Idx)
24043  , p_source_23 => l_array_source_23(Idx)
24044  , p_source_24 => l_array_source_24(Idx)
24045  , p_source_25 => l_array_source_25(Idx)
24046  , p_source_26 => l_array_source_26(Idx)
24047  , p_source_27 => l_array_source_27(Idx)
24048  , p_source_28 => l_array_source_28(Idx)
24049  , p_source_33 => l_array_source_33(Idx)
24050  );
24051 If(l_balance_type_code = 'A') THEN
24052   l_actual_gain_loss_ref := l_gain_or_loss_ref;
24053 END IF;
24054 
24055 --
24056 
24057 
24058 --
24059 AcctLineType_30 (
24060  p_application_id  => p_application_id
24061  ,p_event_id     => l_event_id
24062  ,p_calculate_acctd_flag => l_calculate_acctd_flag
24063  ,p_calculate_g_l_flag => l_calculate_g_l_flag
24064  ,p_actual_flag => l_actual_flag
24065  ,p_balance_type_code => l_balance_type_code
24066  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
24067  
24068  , p_source_1 => l_array_source_1(Idx)
24069  , p_source_7 => l_array_source_7(Idx)
24070  , p_source_8 => l_array_source_8(Idx)
24071  , p_source_9 => l_array_source_9(Idx)
24072  , p_source_10 => l_array_source_10(Idx)
24073  , p_source_14 => l_array_source_14(Idx)
24074  , p_source_15 => l_array_source_15(Idx)
24075  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
24076  , p_source_18 => l_array_source_18(Idx)
24077  , p_source_19 => l_array_source_19(Idx)
24078  , p_source_20 => l_array_source_20(Idx)
24079  , p_source_21 => l_array_source_21(Idx)
24080  , p_source_22 => l_array_source_22(Idx)
24081  , p_source_23 => l_array_source_23(Idx)
24082  , p_source_24 => l_array_source_24(Idx)
24083  , p_source_25 => l_array_source_25(Idx)
24084  , p_source_26 => l_array_source_26(Idx)
24085  , p_source_27 => l_array_source_27(Idx)
24086  , p_source_28 => l_array_source_28(Idx)
24087  , p_source_33 => l_array_source_33(Idx)
24088  );
24089 If(l_balance_type_code = 'A') THEN
24090   l_actual_gain_loss_ref := l_gain_or_loss_ref;
24091 END IF;
24092 
24093 --
24094 
24095 
24096 --
24097 AcctLineType_31 (
24098  p_application_id  => p_application_id
24099  ,p_event_id     => l_event_id
24100  ,p_calculate_acctd_flag => l_calculate_acctd_flag
24101  ,p_calculate_g_l_flag => l_calculate_g_l_flag
24102  ,p_actual_flag => l_actual_flag
24103  ,p_balance_type_code => l_balance_type_code
24104  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
24105  
24106  , p_source_1 => l_array_source_1(Idx)
24107  , p_source_7 => l_array_source_7(Idx)
24108  , p_source_8 => l_array_source_8(Idx)
24109  , p_source_9 => l_array_source_9(Idx)
24110  , p_source_10 => l_array_source_10(Idx)
24111  , p_source_14 => l_array_source_14(Idx)
24112  , p_source_15 => l_array_source_15(Idx)
24113  , p_source_16 => l_array_source_16(Idx)
24114  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
24115  , p_source_18 => l_array_source_18(Idx)
24116  , p_source_19 => l_array_source_19(Idx)
24117  , p_source_20 => l_array_source_20(Idx)
24121  , p_source_24 => l_array_source_24(Idx)
24118  , p_source_21 => l_array_source_21(Idx)
24119  , p_source_22 => l_array_source_22(Idx)
24120  , p_source_23 => l_array_source_23(Idx)
24122  , p_source_26 => l_array_source_26(Idx)
24123  , p_source_27 => l_array_source_27(Idx)
24124  , p_source_28 => l_array_source_28(Idx)
24125  , p_source_32 => l_array_source_32(Idx)
24126  );
24127 If(l_balance_type_code = 'A') THEN
24128   l_actual_gain_loss_ref := l_gain_or_loss_ref;
24129 END IF;
24130 
24131 --
24132 
24133 
24134 --
24135 AcctLineType_32 (
24136  p_application_id  => p_application_id
24137  ,p_event_id     => l_event_id
24138  ,p_calculate_acctd_flag => l_calculate_acctd_flag
24139  ,p_calculate_g_l_flag => l_calculate_g_l_flag
24140  ,p_actual_flag => l_actual_flag
24141  ,p_balance_type_code => l_balance_type_code
24142  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
24143  
24144  , p_source_1 => l_array_source_1(Idx)
24145  , p_source_7 => l_array_source_7(Idx)
24146  , p_source_8 => l_array_source_8(Idx)
24147  , p_source_9 => l_array_source_9(Idx)
24148  , p_source_10 => l_array_source_10(Idx)
24149  , p_source_14 => l_array_source_14(Idx)
24150  , p_source_15 => l_array_source_15(Idx)
24151  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
24152  , p_source_18 => l_array_source_18(Idx)
24153  , p_source_19 => l_array_source_19(Idx)
24154  , p_source_20 => l_array_source_20(Idx)
24155  , p_source_21 => l_array_source_21(Idx)
24156  , p_source_22 => l_array_source_22(Idx)
24157  , p_source_23 => l_array_source_23(Idx)
24158  , p_source_24 => l_array_source_24(Idx)
24159  , p_source_25 => l_array_source_25(Idx)
24160  , p_source_26 => l_array_source_26(Idx)
24161  , p_source_27 => l_array_source_27(Idx)
24162  , p_source_28 => l_array_source_28(Idx)
24163  , p_source_32 => l_array_source_32(Idx)
24164  );
24165 If(l_balance_type_code = 'A') THEN
24166   l_actual_gain_loss_ref := l_gain_or_loss_ref;
24167 END IF;
24168 
24169 --
24170 
24171 
24172 --
24173 AcctLineType_33 (
24174  p_application_id  => p_application_id
24175  ,p_event_id     => l_event_id
24176  ,p_calculate_acctd_flag => l_calculate_acctd_flag
24177  ,p_calculate_g_l_flag => l_calculate_g_l_flag
24178  ,p_actual_flag => l_actual_flag
24179  ,p_balance_type_code => l_balance_type_code
24180  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
24181  
24182  , p_source_1 => l_array_source_1(Idx)
24183  , p_source_7 => l_array_source_7(Idx)
24184  , p_source_8 => l_array_source_8(Idx)
24185  , p_source_9 => l_array_source_9(Idx)
24186  , p_source_10 => l_array_source_10(Idx)
24187  , p_source_14 => l_array_source_14(Idx)
24188  , p_source_15 => l_array_source_15(Idx)
24189  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
24190  , p_source_18 => l_array_source_18(Idx)
24191  , p_source_19 => l_array_source_19(Idx)
24192  , p_source_20 => l_array_source_20(Idx)
24193  , p_source_21 => l_array_source_21(Idx)
24194  , p_source_22 => l_array_source_22(Idx)
24195  , p_source_23 => l_array_source_23(Idx)
24196  , p_source_24 => l_array_source_24(Idx)
24197  , p_source_25 => l_array_source_25(Idx)
24198  , p_source_26 => l_array_source_26(Idx)
24199  , p_source_27 => l_array_source_27(Idx)
24200  , p_source_28 => l_array_source_28(Idx)
24201  , p_source_32 => l_array_source_32(Idx)
24202  );
24203 If(l_balance_type_code = 'A') THEN
24204   l_actual_gain_loss_ref := l_gain_or_loss_ref;
24205 END IF;
24206 
24207 --
24208 
24209 
24210 --
24211 AcctLineType_34 (
24212  p_application_id  => p_application_id
24213  ,p_event_id     => l_event_id
24214  ,p_calculate_acctd_flag => l_calculate_acctd_flag
24215  ,p_calculate_g_l_flag => l_calculate_g_l_flag
24216  ,p_actual_flag => l_actual_flag
24217  ,p_balance_type_code => l_balance_type_code
24218  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
24219  
24220  , p_source_1 => l_array_source_1(Idx)
24221  , p_source_7 => l_array_source_7(Idx)
24222  , p_source_8 => l_array_source_8(Idx)
24223  , p_source_9 => l_array_source_9(Idx)
24224  , p_source_10 => l_array_source_10(Idx)
24225  , p_source_14 => l_array_source_14(Idx)
24226  , p_source_15 => l_array_source_15(Idx)
24227  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
24228  , p_source_18 => l_array_source_18(Idx)
24229  , p_source_19 => l_array_source_19(Idx)
24230  , p_source_20 => l_array_source_20(Idx)
24231  , p_source_21 => l_array_source_21(Idx)
24232  , p_source_22 => l_array_source_22(Idx)
24233  , p_source_23 => l_array_source_23(Idx)
24234  , p_source_24 => l_array_source_24(Idx)
24235  , p_source_25 => l_array_source_25(Idx)
24236  , p_source_26 => l_array_source_26(Idx)
24237  , p_source_27 => l_array_source_27(Idx)
24238  , p_source_28 => l_array_source_28(Idx)
24239  , p_source_33 => l_array_source_33(Idx)
24240  );
24241 If(l_balance_type_code = 'A') THEN
24242   l_actual_gain_loss_ref := l_gain_or_loss_ref;
24243 END IF;
24244 
24245 --
24246 
24247 
24248 --
24249 AcctLineType_35 (
24250  p_application_id  => p_application_id
24251  ,p_event_id     => l_event_id
24252  ,p_calculate_acctd_flag => l_calculate_acctd_flag
24253  ,p_calculate_g_l_flag => l_calculate_g_l_flag
24254  ,p_actual_flag => l_actual_flag
24255  ,p_balance_type_code => l_balance_type_code
24256  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
24257  
24258  , p_source_1 => l_array_source_1(Idx)
24259  , p_source_7 => l_array_source_7(Idx)
24260  , p_source_8 => l_array_source_8(Idx)
24261  , p_source_9 => l_array_source_9(Idx)
24262  , p_source_10 => l_array_source_10(Idx)
24263  , p_source_14 => l_array_source_14(Idx)
24264  , p_source_15 => l_array_source_15(Idx)
24265  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
24266  , p_source_18 => l_array_source_18(Idx)
24270  , p_source_22 => l_array_source_22(Idx)
24267  , p_source_19 => l_array_source_19(Idx)
24268  , p_source_20 => l_array_source_20(Idx)
24269  , p_source_21 => l_array_source_21(Idx)
24271  , p_source_23 => l_array_source_23(Idx)
24272  , p_source_24 => l_array_source_24(Idx)
24273  , p_source_25 => l_array_source_25(Idx)
24274  , p_source_26 => l_array_source_26(Idx)
24275  , p_source_27 => l_array_source_27(Idx)
24276  , p_source_28 => l_array_source_28(Idx)
24277  , p_source_33 => l_array_source_33(Idx)
24278  );
24279 If(l_balance_type_code = 'A') THEN
24280   l_actual_gain_loss_ref := l_gain_or_loss_ref;
24281 END IF;
24282 
24283 --
24284 
24285 
24286 --
24287 AcctLineType_36 (
24288  p_application_id  => p_application_id
24289  ,p_event_id     => l_event_id
24290  ,p_calculate_acctd_flag => l_calculate_acctd_flag
24291  ,p_calculate_g_l_flag => l_calculate_g_l_flag
24292  ,p_actual_flag => l_actual_flag
24293  ,p_balance_type_code => l_balance_type_code
24294  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
24295  
24296  , p_source_2 => g_array_event(l_event_id).array_value_num('source_2')
24297  , p_source_7 => l_array_source_7(Idx)
24298  , p_source_8 => l_array_source_8(Idx)
24299  , p_source_9 => l_array_source_9(Idx)
24300  , p_source_10 => l_array_source_10(Idx)
24301  , p_source_14 => l_array_source_14(Idx)
24302  , p_source_15 => l_array_source_15(Idx)
24303  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
24304  , p_source_18 => l_array_source_18(Idx)
24305  , p_source_19 => l_array_source_19(Idx)
24306  , p_source_20 => l_array_source_20(Idx)
24307  , p_source_21 => l_array_source_21(Idx)
24308  , p_source_22 => l_array_source_22(Idx)
24309  , p_source_23 => l_array_source_23(Idx)
24310  , p_source_24 => l_array_source_24(Idx)
24311  , p_source_25 => l_array_source_25(Idx)
24312  , p_source_28 => l_array_source_28(Idx)
24313  , p_source_32 => l_array_source_32(Idx)
24314  , p_source_33 => l_array_source_33(Idx)
24315  , p_source_34 => g_array_event(l_event_id).array_value_num('source_34')
24316  , p_source_35 => g_array_event(l_event_id).array_value_num('source_35')
24317  );
24318 If(l_balance_type_code = 'A') THEN
24319   l_actual_gain_loss_ref := l_gain_or_loss_ref;
24320 END IF;
24321 
24322 --
24323 
24324 
24325 --
24326 AcctLineType_37 (
24327  p_application_id  => p_application_id
24328  ,p_event_id     => l_event_id
24329  ,p_calculate_acctd_flag => l_calculate_acctd_flag
24330  ,p_calculate_g_l_flag => l_calculate_g_l_flag
24331  ,p_actual_flag => l_actual_flag
24332  ,p_balance_type_code => l_balance_type_code
24333  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
24334  
24335  , p_source_2 => g_array_event(l_event_id).array_value_num('source_2')
24336  , p_source_7 => l_array_source_7(Idx)
24337  , p_source_8 => l_array_source_8(Idx)
24338  , p_source_9 => l_array_source_9(Idx)
24339  , p_source_10 => l_array_source_10(Idx)
24340  , p_source_14 => l_array_source_14(Idx)
24341  , p_source_15 => l_array_source_15(Idx)
24342  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
24343  , p_source_18 => l_array_source_18(Idx)
24344  , p_source_19 => l_array_source_19(Idx)
24345  , p_source_20 => l_array_source_20(Idx)
24346  , p_source_21 => l_array_source_21(Idx)
24347  , p_source_22 => l_array_source_22(Idx)
24348  , p_source_23 => l_array_source_23(Idx)
24349  , p_source_24 => l_array_source_24(Idx)
24350  , p_source_25 => l_array_source_25(Idx)
24351  , p_source_28 => l_array_source_28(Idx)
24352  , p_source_33 => l_array_source_33(Idx)
24353  , p_source_34 => g_array_event(l_event_id).array_value_num('source_34')
24354  , p_source_35 => g_array_event(l_event_id).array_value_num('source_35')
24355  , p_source_36 => g_array_event(l_event_id).array_value_char('source_36')
24356  );
24357 If(l_balance_type_code = 'A') THEN
24358   l_actual_gain_loss_ref := l_gain_or_loss_ref;
24359 END IF;
24360 
24361 --
24362 
24363 
24364 --
24365 AcctLineType_38 (
24366  p_application_id  => p_application_id
24367  ,p_event_id     => l_event_id
24368  ,p_calculate_acctd_flag => l_calculate_acctd_flag
24369  ,p_calculate_g_l_flag => l_calculate_g_l_flag
24370  ,p_actual_flag => l_actual_flag
24371  ,p_balance_type_code => l_balance_type_code
24372  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
24373  
24374  , p_source_1 => l_array_source_1(Idx)
24375  , p_source_7 => l_array_source_7(Idx)
24376  , p_source_8 => l_array_source_8(Idx)
24377  , p_source_9 => l_array_source_9(Idx)
24378  , p_source_10 => l_array_source_10(Idx)
24379  , p_source_14 => l_array_source_14(Idx)
24380  , p_source_15 => l_array_source_15(Idx)
24381  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
24382  , p_source_18 => l_array_source_18(Idx)
24383  , p_source_19 => l_array_source_19(Idx)
24384  , p_source_20 => l_array_source_20(Idx)
24385  , p_source_21 => l_array_source_21(Idx)
24386  , p_source_22 => l_array_source_22(Idx)
24387  , p_source_23 => l_array_source_23(Idx)
24388  , p_source_24 => l_array_source_24(Idx)
24389  , p_source_25 => l_array_source_25(Idx)
24390  , p_source_26 => l_array_source_26(Idx)
24391  , p_source_27 => l_array_source_27(Idx)
24392  , p_source_28 => l_array_source_28(Idx)
24393  );
24394 If(l_balance_type_code = 'A') THEN
24395   l_actual_gain_loss_ref := l_gain_or_loss_ref;
24396 END IF;
24397 
24398 --
24399 
24400 
24401 --
24402 AcctLineType_39 (
24403  p_application_id  => p_application_id
24404  ,p_event_id     => l_event_id
24405  ,p_calculate_acctd_flag => l_calculate_acctd_flag
24406  ,p_calculate_g_l_flag => l_calculate_g_l_flag
24407  ,p_actual_flag => l_actual_flag
24408  ,p_balance_type_code => l_balance_type_code
24409  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
24410  
24411  , p_source_1 => l_array_source_1(Idx)
24415  , p_source_10 => l_array_source_10(Idx)
24412  , p_source_7 => l_array_source_7(Idx)
24413  , p_source_8 => l_array_source_8(Idx)
24414  , p_source_9 => l_array_source_9(Idx)
24416  , p_source_14 => l_array_source_14(Idx)
24417  , p_source_15 => l_array_source_15(Idx)
24418  , p_source_17 => g_array_event(l_event_id).array_value_num('source_17')
24419  , p_source_18 => l_array_source_18(Idx)
24420  , p_source_19 => l_array_source_19(Idx)
24421  , p_source_20 => l_array_source_20(Idx)
24422  , p_source_21 => l_array_source_21(Idx)
24423  , p_source_22 => l_array_source_22(Idx)
24424  , p_source_23 => l_array_source_23(Idx)
24425  , p_source_24 => l_array_source_24(Idx)
24426  , p_source_25 => l_array_source_25(Idx)
24427  , p_source_26 => l_array_source_26(Idx)
24428  , p_source_27 => l_array_source_27(Idx)
24429  , p_source_28 => l_array_source_28(Idx)
24430  , p_source_32 => l_array_source_32(Idx)
24431  );
24432 If(l_balance_type_code = 'A') THEN
24433   l_actual_gain_loss_ref := l_gain_or_loss_ref;
24434 END IF;
24435 
24436 --
24437 
24438       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
24439       -- or secondary ledger that has different currency with primary
24440       -- or alc that is calculated by sla
24441       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
24442             (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'))
24443 
24444 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
24445 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
24446           AND (l_actual_flag = 'A')) THEN
24447         XLA_AE_LINES_PKG.CreateGainOrLossLines(
24448           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
24449          ,p_application_id   => p_application_id
24450          ,p_amb_context_code => 'DEFAULT'
24451          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
24452          ,p_event_class_code => C_EVENT_CLASS_CODE
24453          ,p_event_type_code  => C_EVENT_TYPE_CODE
24454          
24455          ,p_gain_ccid        => TO_NUMBER(g_array_event(l_event_id).array_value_num('source_3'))
24456          ,p_loss_ccid        => TO_NUMBER(g_array_event(l_event_id).array_value_num('source_4'))
24457 
24458          ,p_actual_flag      => l_actual_flag
24459          ,p_enc_flag         => null
24460          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
24461          ,p_enc_g_l_ref      => null
24462          );
24463       END IF;
24464    END IF;
24465 END IF;
24466 
24467    ELSE
24468       --
24469       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
24470       --
24471       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
24472          trace
24473             (p_msg      => 'Trancaction revesal option is Y'
24474             ,p_level    => C_LEVEL_STATEMENT
24475             ,p_module   => l_log_module);
24476       END IF;
24477    END IF;
24478 
24479 END LOOP;
24480 l_result := XLA_AE_LINES_PKG.InsertLines ;
24481 end loop;
24482 close line_cur;
24483 
24484 
24485 --
24486 -- insert headers into xla_ae_headers_gt table
24487 --
24488 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
24489 
24490 -- insert into errors table here.
24491 
24492 END LOOP;
24493 
24494 --
24495 -- 4865292
24496 --
24497 -- Compare g_hdr_extract_count with event count in
24498 -- CreateHeadersAndLines.
24499 --
24500 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
24501 
24502 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
24503    trace (p_msg     => '# rows extracted from header extract objects '
24504                     || ' (running total): '
24505                     || g_hdr_extract_count
24506          ,p_level   => C_LEVEL_STATEMENT
24507          ,p_module  => l_log_module);
24508 END IF;
24509 
24510 CLOSE header_cur;
24511 --
24512 
24513 --
24514 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24515    trace
24516       (p_msg      => 'END of EventClass_41'
24517       ,p_level    => C_LEVEL_PROCEDURE
24518       ,p_module   => l_log_module);
24519 END IF;
24520 --
24521 RETURN l_result;
24522 EXCEPTION
24523 WHEN xla_exceptions_pkg.application_exception THEN
24524    
24525 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
24526 
24527    
24528 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
24529 
24530    RAISE;
24531 
24532 WHEN NO_DATA_FOUND THEN
24533 
24534 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
24535 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
24536 
24537 FOR header_record IN header_cur
24538 LOOP
24539     l_array_header_events(header_record.event_id) := header_record.event_id;
24540 END LOOP;
24541 
24542 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
24543 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
24544 
24545 fnd_file.put_line(fnd_file.LOG, '                    ');
24546 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
24547 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
24548 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
24549 
24550 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
24551 LOOP
24552 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
24553 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
24557 
24554         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
24555 	END IF;
24556 END LOOP;
24558 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
24559 fnd_file.put_line(fnd_file.LOG, '                    ');
24560 
24561 
24562 xla_exceptions_pkg.raise_message
24563       (p_location => 'XLA_00222_AAD_S_000004_PKG.EventClass_41');
24564 
24565 
24566 WHEN OTHERS THEN
24567    xla_exceptions_pkg.raise_message
24568       (p_location => 'XLA_00222_AAD_S_000004_PKG.EventClass_41');
24569 END EventClass_41;
24570 --
24571 
24572 --
24573 --+============================================+
24574 --|                                            |
24575 --|  PRIVATE FUNCTION                          |
24576 --|                                            |
24577 --+============================================+
24578 --
24579 FUNCTION CreateHeadersAndLines
24580        (p_application_id         IN NUMBER
24581        ,p_base_ledger_id         IN NUMBER
24582        ,p_target_ledger_id       IN NUMBER
24583        ,p_pad_start_date         IN DATE
24584        ,p_pad_end_date           IN DATE
24585        ,p_primary_ledger_id      IN NUMBER)
24586 RETURN BOOLEAN IS
24587 l_created                   BOOLEAN:=FALSE;
24588 l_event_id                  NUMBER;
24589 l_event_date                DATE;
24590 l_language                  VARCHAR2(30);
24591 l_currency_code             VARCHAR2(30);
24592 l_sla_ledger_id             NUMBER;
24593 l_log_module                VARCHAR2(240);
24594 
24595 BEGIN
24596 --
24597 IF g_log_enabled THEN
24598    l_log_module := C_DEFAULT_MODULE||'.CreateHeadersAndLines';
24599 END IF;
24600 --
24601 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24602    trace
24603       (p_msg      => 'BEGIN of CreateHeadersAndLines'
24604       ,p_level    => C_LEVEL_PROCEDURE
24605       ,p_module   => l_log_module);
24606 END IF;
24607 
24608 l_language         := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
24609 l_currency_code    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.currency_code;
24610 l_sla_ledger_id    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.sla_ledger_id;
24611 
24612 --
24613 -- initialize array of lines with NULL
24614 --
24615 xla_ae_lines_pkg.SetNullLine;
24616 
24617 --
24618 -- initialize header extract count -- Bug 4865292
24619 --
24620 g_hdr_extract_count:= 0;
24621 
24622 
24623 l_created := EventClass_40(
24624    p_application_id         => p_application_id
24625  , p_base_ledger_id         => p_base_ledger_id
24626  , p_target_ledger_id       => p_target_ledger_id
24627  , p_language               => l_language
24628  , p_currency_code          => l_currency_code
24629  , p_sla_ledger_id          => l_sla_ledger_id
24630  , p_pad_start_date         => p_pad_start_date
24631  , p_pad_end_date           => p_pad_end_date
24632  , p_primary_ledger_id      => p_primary_ledger_id
24633 );
24634 
24635 
24636 
24637      IF ( g_diagnostics_mode ='Y' ) THEN
24638 
24639          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
24640           trace
24641               (p_msg      => 'CALL Transaction Objects Diagnostics'
24642               ,p_level    => C_LEVEL_STATEMENT
24643               ,p_module   => l_log_module);
24644 
24645          END IF;
24646 
24647          insert_sources_40(
24648                           p_target_ledger_id => p_target_ledger_id
24649                         , p_language         => l_language
24650                         , p_sla_ledger_id    => l_sla_ledger_id
24651                         , p_pad_start_date   => p_pad_start_date
24652                         , p_pad_end_date     => p_pad_end_date
24653                           );
24654 
24655      END IF;
24656 
24657 l_created := EventClass_41(
24658    p_application_id         => p_application_id
24659  , p_base_ledger_id         => p_base_ledger_id
24660  , p_target_ledger_id       => p_target_ledger_id
24661  , p_language               => l_language
24662  , p_currency_code          => l_currency_code
24663  , p_sla_ledger_id          => l_sla_ledger_id
24664  , p_pad_start_date         => p_pad_start_date
24665  , p_pad_end_date           => p_pad_end_date
24666  , p_primary_ledger_id      => p_primary_ledger_id
24667 );
24668 
24669 
24670 
24671      IF ( g_diagnostics_mode ='Y' ) THEN
24672 
24673          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
24674           trace
24675               (p_msg      => 'CALL Transaction Objects Diagnostics'
24676               ,p_level    => C_LEVEL_STATEMENT
24677               ,p_module   => l_log_module);
24678 
24679          END IF;
24680 
24681          insert_sources_41(
24682                           p_target_ledger_id => p_target_ledger_id
24683                         , p_language         => l_language
24684                         , p_sla_ledger_id    => l_sla_ledger_id
24685                         , p_pad_start_date   => p_pad_start_date
24686                         , p_pad_end_date     => p_pad_end_date
24687                           );
24688 
24689      END IF;
24690 
24691 
24692  --
24693  -- Bug 4865292
24694  -- When the number of events and that of header extract do not match,
24695  -- set the no header extract flag to indicate there are some issues
24696  -- in header extract.
24697  --
24698  -- Event count context is set in xla_accounting_pkg.unit_processor.
24699  -- Build_Message for this error is called in xla_accounting_pkg.post_accounting
24700  -- to report it as a general error.
24701  --
24702  IF  xla_context_pkg.get_event_count_context <> g_hdr_extract_count
24703  AND xla_context_pkg.get_event_nohdr_context <> 'Y' THEN
24704 
24708           ,p_level    => C_LEVEL_STATEMENT
24705      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
24706         trace
24707           (p_msg      => '# of extracted headers and events does not match'
24709           ,p_module   => l_log_module);
24710 
24711         trace
24712           (p_msg      => '# of extracted headers: '
24713                          ||g_hdr_extract_count
24714           ,p_level    => C_LEVEL_STATEMENT
24715           ,p_module   => l_log_module);
24716 
24717         trace
24718           (p_msg      => '# of events in xla_events_gt: '
24719                          ||xla_context_pkg.get_event_count_context
24720           ,p_level    => C_LEVEL_STATEMENT
24721           ,p_module   => l_log_module);
24722 
24723         trace
24724           (p_msg      => 'Event No Header Extract Context: '
24725                          ||xla_context_pkg.get_event_nohdr_context
24726           ,p_level    => C_LEVEL_STATEMENT
24727           ,p_module   => l_log_module);
24728 
24729      END IF;
24730 
24731 
24732      xla_context_pkg.set_event_nohdr_context
24733        (p_nohdr_extract_flag => 'Y'
24734        ,p_client_id => sys_context('USERENV','CLIENT_IDENTIFIER'));
24735 
24736      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
24737         trace
24738           (p_msg      => 'No Header Extract Flag is set to Y'
24739           ,p_level    => C_LEVEL_STATEMENT
24740           ,p_module   => l_log_module);
24741      END IF;
24742 
24743  END IF;
24744 
24745 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24746    trace
24747       (p_msg      => 'END of CreateHeadersAndLines'
24748       ,p_level    => C_LEVEL_PROCEDURE
24749       ,p_module   => l_log_module);
24750 END IF;
24751 
24752 RETURN l_created;
24753 EXCEPTION
24754 WHEN xla_exceptions_pkg.application_exception THEN
24755    RAISE;
24756 WHEN OTHERS THEN
24757    xla_exceptions_pkg.raise_message
24758       (p_location => 'XLA_00222_AAD_S_000004_PKG.CreateHeadersAndLines');
24759 END CreateHeadersAndLines;
24760 --
24761 --
24762 
24763 --
24764 --+============================================+
24765 --|                                            |
24766 --|  PUBLIC FUNCTION                           |
24767 --|                                            |
24768 --+============================================+
24769 --
24770 FUNCTION CreateJournalEntries
24771        (p_application_id         IN NUMBER
24772        ,p_base_ledger_id         IN NUMBER
24773        ,p_pad_start_date         IN DATE
24774        ,p_pad_end_date           IN DATE
24775        ,p_primary_ledger_id      IN NUMBER)
24776 RETURN NUMBER IS
24777 l_log_module                   VARCHAR2(240);
24778 l_array_ledgers                xla_accounting_cache_pkg.t_array_ledger_id;
24779 l_temp_result                  BOOLEAN;
24780 l_result                       NUMBER;
24781 BEGIN
24782 --
24783 IF g_log_enabled THEN
24784    l_log_module := C_DEFAULT_MODULE||'.CreateJournalEntries';
24785 END IF;
24786 --
24787 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24788    trace
24789       (p_msg      => 'BEGIN of CreateJournalEntries'||
24790                      ' - p_base_ledger_id = '||TO_CHAR(p_base_ledger_id)
24791       ,p_level    => C_LEVEL_PROCEDURE
24792       ,p_module   => l_log_module);
24793 
24794 END IF;
24795 
24796 --
24797 g_diagnostics_mode:= xla_accounting_engine_pkg.g_diagnostics_mode;
24798 
24799 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
24800    trace
24801       (p_msg      => 'g_diagnostics_mode = '||g_diagnostics_mode
24802       ,p_level    => C_LEVEL_STATEMENT
24803       ,p_module   => l_log_module);
24804 END IF;
24805 --
24806 xla_ae_journal_entry_pkg.SetProductAcctDefinition
24807    (p_product_rule_code      => 'AR_DEFAULT_CASH'
24808    ,p_product_rule_type_code => 'S'
24809    ,p_product_rule_version   => ''
24810    ,p_product_rule_name      => 'Receivables Default Cash Basis Accounting Definition'
24811    ,p_amb_context_code       => 'DEFAULT'
24812    );
24813 
24814 l_array_ledgers :=
24815    xla_ae_journal_entry_pkg.GetAlternateCurrencyLedger
24816       (p_base_ledger_id  => p_base_ledger_id);
24817 
24818 FOR Idx IN 1 .. l_array_ledgers.COUNT LOOP
24819    l_temp_result :=
24820       XLA_AE_JOURNAL_ENTRY_PKG.GetLedgersInfo
24821          (p_application_id           => p_application_id
24822          ,p_base_ledger_id           => p_base_ledger_id
24823          ,p_target_ledger_id         => l_array_ledgers(Idx)
24824          ,p_primary_ledger_id        => p_primary_ledger_id
24825          ,p_pad_start_date           => p_pad_start_date
24826          ,p_pad_end_date             => p_pad_end_date);
24827 
24828    l_temp_result :=
24829       l_temp_result AND
24830       CreateHeadersAndLines
24831          (p_application_id             => p_application_id
24832          ,p_base_ledger_id             => p_base_ledger_id
24833          ,p_target_ledger_id           => l_array_ledgers(Idx)
24834          ,p_pad_start_date             => p_pad_start_date
24835          ,p_pad_end_date               => p_pad_end_date
24836          ,p_primary_ledger_id          => p_primary_ledger_id
24837          );
24838 END LOOP;
24839 
24840 
24841 IF (g_diagnostics_mode = 'Y' AND
24842     C_LEVEL_UNEXPECTED >= g_log_level AND
24843     xla_environment_pkg.g_Req_Id IS NOT NULL ) THEN
24844 
24845    xla_accounting_dump_pkg.acctg_event_extract_log(
24846     p_application_id  => p_application_id
24847     ,p_request_id     => xla_environment_pkg.g_Req_Id
24848    );
24849 
24850 END IF;
24851 
24852 CASE l_temp_result
24853   WHEN TRUE THEN l_result := 0;
24854   ELSE l_result := 2;
24855 END CASE;
24856 
24857 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24858    trace
24859       (p_msg      => 'return value. = '||TO_CHAR(l_result)
24860       ,p_level    => C_LEVEL_PROCEDURE
24861       ,p_module   => l_log_module);
24862    trace
24863       (p_msg      => 'END of CreateJournalEntries '
24864       ,p_level    => C_LEVEL_PROCEDURE
24865       ,p_module   => l_log_module);
24866 END IF;
24867 
24868 RETURN l_result;
24869 EXCEPTION
24870 WHEN xla_exceptions_pkg.application_exception THEN
24871    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24872    trace
24873       (p_msg      => 'ERROR. = '||sqlerrm
24874       ,p_level    => C_LEVEL_PROCEDURE
24875       ,p_module   => l_log_module);
24876    END IF;
24877    RAISE;
24878 WHEN OTHERS THEN
24879    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
24880    trace
24881       (p_msg      => 'ERROR. = '||sqlerrm
24882       ,p_level    => C_LEVEL_PROCEDURE
24883       ,p_module   => l_log_module);
24884    END IF;
24885    xla_exceptions_pkg.raise_message
24886       (p_location => 'XLA_00222_AAD_S_000004_PKG.CreateJournalEntries');
24887 END CreateJournalEntries;
24888 --
24889 --=============================================================================
24890 --
24891 --
24892 --
24893 --
24894 --
24895 --
24896 --
24897 --
24898 --
24899 --
24900 --
24901 --
24902 --
24903 --
24904 --
24905 --
24906 --
24907 --
24908 --
24909 --
24910 --
24911 --
24912 --=============================================================================
24913 --=============================================================================
24914 --          *********** Initialization routine **********
24915 --=============================================================================
24916 
24917 BEGIN
24918    g_log_level      := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
24919    g_log_enabled    := fnd_log.test
24920                           (log_level  => g_log_level
24921                           ,module     => C_DEFAULT_MODULE);
24922 
24923    IF NOT g_log_enabled  THEN
24924       g_log_level := C_LEVEL_LOG_DISABLED;
24925    END IF;
24926 --
24927 END XLA_00222_AAD_S_000004_PKG;
24928 --